Commit 2adda08
undo for cut background image
Changed files (9)
modifiedsrc/BackgroundSelection.valamodifiedsrc/BackgroundTool.valamodifiedsrc/CutBackgroundTool.valamodifiedsrc/Glyph.valamodifiedsrc/GlyphBackgroundImage.valamodifiedsrc/OpenFontFormatReader.valamodifiedsrc/Toolbox.valamodifiedwin32/wscriptmodifiedwscript
Diff
@@ -36,9 +36,6 @@ class BackgroundSelection : FontDisplay { i = Icons.get_icon ("add_background_image.png"); return_if_fail (i != null); add_icon = (!) i;-- CutBackgroundTool cb = (CutBackgroundTool) MainWindow.get_toolbox ().get_tool ("cut_background");- cb.set_destination_file_name (glyph.get_name ()); } public override string get_name () {@@ -54,23 +54,28 @@ class BackgroundTool : Tool { press_action.connect((self, b, x, y) => { Glyph g = MainWindow.get_current_glyph (); GlyphBackgroundImage? bg = g.get_background_image ();+ GlyphBackgroundImage background; if (bg == null) { return; } - ((!)bg).handler_press (x, y);+ background = (!) bg;+ + g.store_undo_state ();+ + background.handler_press (x, y); begin_x = x; begin_y = y; - img_offset_x = ((!)bg).img_offset_x;- img_offset_y = ((!)bg).img_offset_y;+ img_offset_x = background.img_offset_x;+ img_offset_y = background.img_offset_y; - img_scale_x = ((!)bg).img_scale_x;+ img_scale_x = background.img_scale_x; - img_width = ((!)bg).get_img ().get_width () * img_scale_x;- img_height = ((!)bg).get_img ().get_height () * ((!)bg).img_scale_y;+ img_width = background.get_img ().get_width () * background.img_scale_x;+ img_height = background.get_img ().get_height () * background.img_scale_y; move_bg = true; });@@ -33,8 +33,6 @@ class CutBackgroundTool : Tool { public signal void new_image (string file); - string? destination_file_name = null;- public CutBackgroundTool (string name) { base (name, "Cut background image"); @@ -91,6 +89,8 @@ class CutBackgroundTool : Tool { Glyph glyph = MainWindow.get_current_glyph (); TabBar tb = MainWindow.get_tab_bar (); + glyph.store_undo_state ();+ glyph.set_background_image (new GlyphBackgroundImage (file)); tb.select_tab_name (glyph.get_name ()); @@ -102,10 +102,6 @@ class CutBackgroundTool : Tool { } - public void set_destination_file_name (string fn) {- destination_file_name = fn;- }- bool is_over_rectangle (double x, double y) { return fmin (x1, x2) < x < fmax (x1, x2) && fmin (y1, y2) < y < fmax (y1, y2); }@@ -171,7 +167,11 @@ class CutBackgroundTool : Tool { sr = new Surface.similar (sg, img.get_content (), w, h); cr = new Context (sr);- ++ cr.set_source_rgba (1, 1, 1, 1);+ cr.rectangle (0, 0, w, h);+ cr.fill ();+ cr.scale (bg.img_scale_x, bg.img_scale_y); cr.set_source_surface (sg, x, y);@@ -181,12 +181,10 @@ class CutBackgroundTool : Tool { cr.restore (); - // - bg.img_offset_x = x + g.view_offset_x; bg.img_offset_y = y + g.view_offset_y; }- + void save_img (Surface sr, Glyph g) { GlyphBackgroundImage newbg; Font f = Supplement.get_current_font ();@@ -195,29 +193,23 @@ class CutBackgroundTool : Tool { string fn; string name; - if (destination_file_name != null) {- name = (!) destination_file_name;- } else {- name = g.get_name ();- }- img_dir = f.get_backgrounds_folder ().get_child ("parts"); if (!img_dir.query_exists ()) { DirUtils.create ((!) img_dir.get_path (), 0xFFFFFF); } - img_file = img_dir.get_child (@"$(name).png");+ img_file = img_dir.get_child (@"NEW_BACKGROUND.png"); fn = (!) img_file.get_path (); sr.write_to_png (fn); newbg = new GlyphBackgroundImage (fn);- g.set_background_image (newbg); - newbg.reset_scale (g);+ fn = newbg.get_sha1 () + ".png";+ img_file.set_display_name (fn); - new_image (fn);+ new_image ((!) f.get_backgrounds_folder ().get_child ("parts").get_child (fn).get_path ()); } } @@ -1552,6 +1552,10 @@ class Glyph : FontDisplay { foreach (Path p in active_paths) { g.active_paths.append (p); }++ if (background_image != null) {+ g.background_image = ((!) background_image).copy ();+ } return g; }@@ -1580,6 +1584,10 @@ class Glyph : FontDisplay { add_help_lines (); + if (g.background_image != null) {+ background_image = ((!) g.background_image).copy ();+ }+ clear_active_paths (); foreach (Path p in g.active_paths) { add_active_path (p);@@ -23,20 +23,18 @@ using Math; namespace Supplement { class GlyphBackgroundImage {- + public double img_x = 0; public double img_y = 0; public double img_scale_x = 1; public double img_scale_y = 1; public double img_rotation = 0;- public int size_margin = 0;+ private int size = -1; public int active_handle = -1; public int selected_handle = -1; - public bool scaled = false;- private ImageSurface? background_image = null; private ImageSurface? original_image = null; @@ -50,14 +48,6 @@ class GlyphBackgroundImage { private bool background_image_is_processing = false; public signal void updated ();- - public GlyphBackgroundImage (string fn) {- path = fn;- - if (fn != "") {- size_margin = (int) (Math.sqrt (Math.pow (get_img ().get_height (), 2) + Math.pow (get_img ().get_width (), 2)) + 0.5);- }- } public double img_offset_x { get { return img_x + Glyph.xc (); }@@ -68,6 +58,38 @@ class GlyphBackgroundImage { get { return Glyph.yc () - img_y; } set { img_y = Glyph.yc () - value; } }+ + public int size_margin {+ get {+ if (unlikely (size == -1)) {+ size = (int) (Math.sqrt (Math.pow (get_img ().get_height (), 2) + Math.pow (get_img ().get_width (), 2)) + 0.5);+ }+ + return size;+ }+ }+ + public GlyphBackgroundImage (string fn) {+ path = fn;+ }++ public GlyphBackgroundImage copy () {+ GlyphBackgroundImage bg = new GlyphBackgroundImage (path);+ + bg.img_x = img_x;+ bg.img_y = img_y;++ bg.img_scale_x = img_scale_x;+ bg.img_scale_y = img_scale_y;+ bg.img_rotation = img_rotation;++ bg.contrast = contrast;+ bg.desaturate = desaturate;+ bg.threshold = threshold;++ return bg;+ + } public void set_img_offset (double x, double y) { img_offset_x = x;@@ -113,10 +135,20 @@ class GlyphBackgroundImage { public string get_sha1 () { try { File file = File.new_for_path (path);- var file_info = file.query_info ("*", FileQueryInfoFlags.NONE);- uint8[] buffer = new uint8[file_info.get_size ()];- FileInputStream file_stream = file.read ();- DataInputStream png_stream = new DataInputStream (file_stream);+ FileInfo file_info;+ uint8[] buffer;+ FileInputStream file_stream;+ DataInputStream png_stream;+ + if (!file.query_exists ()) {+ warning (@"Can't save $path file does not exist.");+ return "";+ }+ + file_info = file.query_info ("*", FileQueryInfoFlags.NONE);+ buffer = new uint8[file_info.get_size ()];+ file_stream = file.read ();+ png_stream = new DataInputStream (file_stream); png_stream.read (buffer); @@ -150,41 +182,6 @@ class GlyphBackgroundImage { path = (!) png_image.get_path (); } - public File get_thumbnail_file () {- Font font = Supplement.get_current_font ();- File folder = font.get_backgrounds_folder ();- File full = File.new_for_path (path);- File thumbnail = folder.get_child (@"thumbnail_$((!)full.get_basename ())");- - if (!thumbnail.query_exists ()) {- create_thumbnail (get_img (), thumbnail);- }- - return thumbnail;- }-- private void create_thumbnail (ImageSurface source, File thumbnail) {- Context c;- Surface s;- double zoom;- ImageSurface img = source;- - zoom = Math.fmin (80.0 / img.get_width(), 80.0 / img.get_height());-- s = new Surface.similar (img, img.get_content (), 80, 80);- c = new Context (s);-- c.set_source_rgba (1, 1, 1, 1);- c.rectangle (0, 0, 80, 80);- c.fill ();- - c.scale (zoom, zoom);- c.set_source_surface (img, 0, 0);- c.paint ();- - c.get_target ().write_to_png ((!) thumbnail.get_path ());- }- public double get_current_width () { return get_img ().get_width () * img_scale_x; }@@ -442,8 +439,6 @@ class GlyphBackgroundImage { double x, y; cr.save (); - // cr.scale (g.view_zoom, g.view_zoom);- cr.set_source_rgba (1, 0, 0.3, 1); x = img_offset_x - g.view_offset_x;@@ -101,6 +101,11 @@ class OpenFontFormatReader : Object { public void set_limits () { Font f = OpenFontFormatWriter.font;+ + if (is_null (f)) {+ f = Supplement.get_current_font ();+ }+ f.top_position = -get_ascender (); f.top_limit = f.top_position - 5; f.xheight_position = f.top_position - 5;@@ -419,29 +419,6 @@ class Toolbox : DrawingArea { }); background_tools.add_tool (show_bg); - Tool background_size_to_boundries = new Tool ("size_to_boundries", "Fit image between margin lines", 'F', SHIFT);- background_size_to_boundries.select_action.connect ((self) => {- Glyph g = MainWindow.get_current_glyph ();- GlyphBackgroundImage? bg = g.get_background_image ();- GlyphBackgroundImage b = (!) bg;- - if (bg != null) {- - if (!b.scaled) {- b.scale_image_proportional_to_boundries (g);- g.set_background_visible (true);- MainWindow.get_glyph_canvas ().redraw ();- } else {- b.reset_scale (g);- g.set_background_visible (true);- MainWindow.get_glyph_canvas ().redraw (); - }- - b.scaled = !b.scaled;- }- });- // Fixa: remove this tool background_tools.add_tool (background_size_to_boundries);- Tool bg_selection = new Tool ("insert_background", "Insert new background image"); bg_selection.select_action.connect((self) => { Glyph? g = null;@@ -89,11 +89,8 @@ def build(bld): bld(rule="windres ${SRC} -O coff -o ${TGT}", source="../win32/icon.rc", target="icon.res", always=True) bld(rule="mv ${SRC} ${TGT}", source="../win32/icon.res", target="../build/", name="icon", always=True) - #bld(rule="rm -f ../build/*.c && rm -f ../build/src/*.o && rm -rf ../build/win32/*", depends_on="libbirdfont", name="clean_src")- bld(rule="""i686-w64-mingw32-gcc -c ./Main.c ./src/*.c ./ \ -I./ \- -s \ -mthreads \ $(i686-w64-mingw32-pkg-config --cflags --libs glib-2.0) \ $(i686-w64-mingw32-pkg-config --cflags --libs libxml-2.0) \@@ -106,7 +103,6 @@ def build(bld): -shared \ ./win32/*.o \ ./icon.res \- -s \ -Wl,-subsystem,windows \ -mthreads \ -L/usr/i686-w64-mingw32/sys-root/mingw/lib \@@ -120,15 +116,14 @@ def build(bld): bld(rule="""i686-w64-mingw32-gcc \ ./win32/Main.o \ ./icon.res \- -s \ -Wl,-subsystem,windows \ -mthreads \ -L./ \ -L/usr/i686-w64-mingw32/sys-root/mingw/lib \ -static -B -static -l birdfont.dll \ -static -B static -lintl.dll -B static -l glib-2.0.dll -B static -l xml2.dll \- -B static -lgio-2.0.dll -B static -l soup-2.4.dll \- -B static -l webkitgtk-1.0.dll -B static -lgtk-win32-2.0.dll -B static -lgdk-win32-2.0.dll -B static -latk-1.0.dll -B static -lgio-2.0.dll -B static -lpangowin32-1.0.dll -B static -lpangocairo-1.0.dll -B static -lgdk_pixbuf-2.0.dll -B static -lpango-1.0.dll -B static -lcairo.dll -B static -lgobject-2.0.dll -B static -lgmodule-2.0.dll -B static -lgthread-2.0.dll -B static -lglib-2.0.dll \+ -B static -l gio-2.0.dll -B static -l soup-2.4.dll \+ -B static -l webkitgtk-1.0.dll -B static -l gtk-win32-2.0.dll -B static -l gdk-win32-2.0.dll -B static -l atk-1.0.dll -B static -l gio-2.0.dll -B static -l pangowin32-1.0.dll -B static -l pangocairo-1.0.dll -B static -l gdk_pixbuf-2.0.dll -B static -l pango-1.0.dll -B static -l cairo.dll -B static -l gobject-2.0.dll -B static -l gmodule-2.0.dll -B static -l gthread-2.0.dll -B static -l glib-2.0.dll \ -static -o birdfont.exe""", source="../build/src/Supplement.c", target="../birdfont.exe", depends_on=['mingw link shared', 'icon'], name="mingw link", always=True) bld(rule="mv birdfont.exe supplement/", depends_on='mingw link', always=True)@@ -140,7 +135,7 @@ def build(bld): fn = "birdfont-" + bld.env.VERSION + ".exe" bld(rule=os.getenv("HOME") + "/.wine/drive_c/Program/NSIS/makensis.exe supplement/birdfont_installer.nsi", source='', target='supplement/' + fn, depends_on='mingw link', name="nsis installer")- bld(rule="mv ./${SRC} ${TGT}", source='supplement/' + fn, target='./', depends_on='nsis installer')+ bld(rule="mv ./${SRC} ${TGT}", source='supplement/' + fn, target='../', depends_on='nsis installer') def generate_nsi(bld): print ('generating build/supplement/birdfont_installer.nsi')@@ -26,15 +26,20 @@ def configure(conf): if conf.options.win32 : conf.recurse('win32') - -def build(bld): - bld.recurse('src') +def pre (bld): bld.env.VERSION = VERSION if not bld.options.noconfig: write_config () + +def build(bld): + bld.env.VERSION = VERSION + bld.add_pre_fun(pre) + + bld.recurse('src') + start_dir = bld.path.find_dir('./') bld.install_files('${PREFIX}/share/birdfont/', start_dir.ant_glob('layout/*'), cwd=start_dir, relative_trick=True) bld.install_files('${PREFIX}/share/birdfont/', start_dir.ant_glob('icons/*'), cwd=start_dir, relative_trick=True)