Commit 7e367f8
Add abstract table class
Changed files (31)
modifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/GlyphSequence.valamodifiedlibbirdfont/GridTool.valamodifiedlibbirdfont/KerningList.valamodifiedlibbirdfont/LigatureList.valamodifiedlibbirdfont/Ligatures.valamodifiedlibbirdfont/OpenFontFormat/CffTable.valamodifiedlibbirdfont/OpenFontFormat/Cmap.valamodifiedlibbirdfont/OpenFontFormat/CvtTable.valamodifiedlibbirdfont/OpenFontFormat/DirectoryTable.valamodifiedlibbirdfont/OpenFontFormat/FontData.valamodifiedlibbirdfont/OpenFontFormat/GaspTable.valamodifiedlibbirdfont/OpenFontFormat/GdefTable.valamodifiedlibbirdfont/OpenFontFormat/GlyfTable.valamodifiedlibbirdfont/OpenFontFormat/GposTable.valamodifiedlibbirdfont/OpenFontFormat/GsubTable.valamodifiedlibbirdfont/OpenFontFormat/HeadTable.valamodifiedlibbirdfont/OpenFontFormat/HheaTable.valamodifiedlibbirdfont/OpenFontFormat/HmtxTable.valamodifiedlibbirdfont/OpenFontFormat/KernTable.valamodifiedlibbirdfont/OpenFontFormat/LigatureSet.valamodifiedlibbirdfont/OpenFontFormat/LocaTable.valamodifiedlibbirdfont/OpenFontFormat/MaxpTable.valamodifiedlibbirdfont/OpenFontFormat/NameTable.valamodifiedlibbirdfont/OpenFontFormat/OffsetTable.valamodifiedlibbirdfont/OpenFontFormat/OpenFontFormatWriter.valamodifiedlibbirdfont/OpenFontFormat/Os2Table.valaaddedlibbirdfont/OpenFontFormat/OtfTable.valamodifiedlibbirdfont/OpenFontFormat/PostTable.valadeletedlibbirdfont/OpenFontFormat/Table.valamodifiedlibbirdfont/SpacingClassTab.vala
Diff
@@ -969,7 +969,6 @@ public class Glyph : FontDisplay { double xt, yt; Path np; EditPoint inserted;- PathList pl; if (path_list.size == 0) { np = new Path ();@@ -58,7 +58,7 @@ public class GlyphSequence { }); ligature_sequence.ranges.clear ();- foreach (Glyph? g in ligature_sequence.glyph) {+ for (int i = 0; i < ligature_sequence.glyph.size; i++) { ligature_sequence.ranges.add (null); } @@ -90,17 +90,6 @@ class GridTool : Tool { update_lines (); }- - public static void ttf_grid (ref int pixel_x, ref int pixel_y) {- double coordinate_x = Glyph.path_coordinate_x (pixel_x);- double coordinate_y = Glyph.path_coordinate_y (pixel_y);- - coordinate_x = GlyfData.tie_to_ttf_grid_x (MainWindow.get_current_glyph (), coordinate_x);- coordinate_y = GlyfData.tie_to_ttf_grid_y (BirdFont.get_current_font (), coordinate_y);- - pixel_x = Glyph.reverse_path_coordinate_x (coordinate_x);- pixel_y = Glyph.reverse_path_coordinate_y (coordinate_y);- } public static void ttf_grid_coordinate (ref double x, ref double y) { x = GlyfData.tie_to_ttf_grid_x (MainWindow.get_current_glyph (), x);@@ -177,27 +177,28 @@ public class KerningList : FontDisplay { glyph_range_first = new GlyphRange (); glyph_range_next = new GlyphRange (); - glyph_range_first.parse_ranges (left);- glyph_range_next.parse_ranges (right);- try {- if (left != "" && right != "") {- if (glyph_range_first.is_class () || glyph_range_next.is_class ()) {- - kerning = classes.get_kerning_for_range (glyph_range_first, glyph_range_next);- class_index = classes.get_kerning_item_index (glyph_range_first, glyph_range_next);- - classes.delete_kerning_for_class (left, right);- } else {- kerning = classes.get_kerning (left, right);- classes.delete_kerning_for_pair (left, right);- }+ glyph_range_first.parse_ranges (left);+ glyph_range_next.parse_ranges (right);+ } catch (GLib.MarkupError e) {+ warning (e.message);+ return;+ }++ if (left != "" && right != "") {+ if (glyph_range_first.is_class () || glyph_range_next.is_class ()) {+ + kerning = classes.get_kerning_for_range (glyph_range_first, glyph_range_next);+ class_index = classes.get_kerning_item_index (glyph_range_first, glyph_range_next); - undo_items.add (new UndoItem (left, right, kerning, class_index));- font.touch ();+ classes.delete_kerning_for_class (left, right);+ } else {+ kerning = classes.get_kerning (left, right);+ classes.delete_kerning_for_pair (left, right); }- } catch (MarkupError e) {- warning (e.message);+ + undo_items.add (new UndoItem (left, right, kerning, class_index));+ font.touch (); } } @@ -17,134 +17,77 @@ using Math; namespace BirdFont { -public class LigatureList : FontDisplay {- - int scroll = 0;- int visible_rows = 0;- WidgetAllocation allocation;+public class LigatureList : Table {+ Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> ();++ public const int NEW_LIGATURE = -1; public LigatureList () {- allocation = new WidgetAllocation (); } - public override void draw (WidgetAllocation allocation, Context cr) {- Ligatures ligatures = BirdFont.get_current_font ().get_ligatures ();- int y = 20;- int s = 0;- bool color = (scroll % 2) == 0;- - this.allocation = allocation;- - visible_rows = (int) (allocation.height / 18.0);- - cr.save ();- cr.set_source_rgba (1, 1, 1, 1);- cr.rectangle (0, 0, allocation.width, allocation.height);- cr.fill ();- cr.restore ();- - cr.save ();- cr.set_source_rgba (0.3, 0.3, 0.3, 1);- cr.set_font_size (12);-- ligatures.get_ligatures ((substitution, ligature) => {- if (s++ >= scroll) {- draw_row (allocation, cr, substitution, ligature, y, color);- y += 18;- color = !color;- }- });- - cr.restore ();- } -- private static void draw_row (WidgetAllocation allocation, Context cr,- string substitution, string ligature, int y, bool color) {-- if (color) {- cr.save ();- cr.set_source_rgba (224/255.0, 224/255.0, 224/255.0, 1);- cr.rectangle (0, y - 14, allocation.width, 18);- cr.fill ();- cr.restore ();- }- - cr.move_to (30, y);- cr.show_text (substitution);- cr.move_to (230, y);- cr.show_text (ligature);+ public override Gee.ArrayList<Row> get_rows () {+ return rows; } - public override string get_label () {- return t_("Ligatures");+ void add_ligature (string subst, string liga) {+ Font font = BirdFont.get_current_font ();+ Ligatures ligatures = font.get_ligatures ();+ ligatures.add_ligature (subst, liga); } - public override string get_name () {- return "Ligatures";- }+ public override void selected_row (Row row, int column, bool delete_button) {+ Font font = BirdFont.get_current_font ();+ Ligatures ligatures = font.get_ligatures ();+ + if (row.get_index () == NEW_LIGATURE) {+ add_ligature (t_("substitute"), t_("ligature"));+ MainWindow.native_window.hide_text_input ();+ } else if (ligatures.count () != 0) {+ if (delete_button) {+ return_if_fail (0 <= row.get_index () < ligatures.count ());+ ligatures.remove_at (row.get_index ());+ MainWindow.native_window.hide_text_input ();+ } else if (column == 0) {+ if (!(0 <= row.get_index () < ligatures.count ())) {+ warning (@"Index: $(row.get_index ()) ligatures.count (): $(ligatures.count ())");+ return;+ }+ ligatures.set_ligature (row.get_index ());+ } else if (column == 2) {+ return_if_fail (0 <= row.get_index () < ligatures.count ());+ ligatures.set_substitution (row.get_index ());+ }+ } - public override bool has_scrollbar () {- return true;+ update_rows ();+ update_scrollbar ();+ font.touch (); }- - public override void scroll_wheel_down (double x, double y) {- Ligatures ligatures = BirdFont.get_current_font ().get_ligatures ();- uint liga = ligatures.count ();- scroll += 3; - if (scroll > liga - visible_rows) {- scroll = (int) (liga - visible_rows);- }- - if (visible_rows > liga) {- scroll = 0;- } + public override void update_rows () {+ int i;+ Font font = BirdFont.get_current_font ();+ Ligatures ligatures = font.get_ligatures (); - update_scrollbar ();- redraw_area (0, 0, allocation.width, allocation.height);- }- - public override void scroll_wheel_up (double x, double y) {- scroll -= 3;+ rows.clear ();+ rows.add (new Row (t_("New Ligature"), NEW_LIGATURE, false)); - if (scroll < 0) {- scroll = 0;- }+ i = 0;+ ligatures.get_ligatures ((subst, liga) => {+ rows.add (new Row.columns_3 (@"$subst", "->", @"$liga", i));+ i++;+ }); - update_scrollbar ();- redraw_area (0, 0, allocation.width, allocation.height);- }-- public override void selected_canvas () {- update_scrollbar ();- redraw_area (0, 0, allocation.width, allocation.height);+ GlyphCanvas.redraw (); }- - public void update_scrollbar () {- Ligatures ligatures = BirdFont.get_current_font ().get_ligatures ();- uint rows = ligatures.count (); - if (rows == 0 || visible_rows == 0) {- MainWindow.set_scrollbar_size (0);- MainWindow.set_scrollbar_position (0);- } else {- MainWindow.set_scrollbar_size ((double) visible_rows / rows);- MainWindow.set_scrollbar_position ((double) scroll / rows);- }+ public override string get_label () {+ return t_("Ligatures"); } - public override void scroll_to (double percent) {- Ligatures ligatures = BirdFont.get_current_font ().get_ligatures ();- uint liga = ligatures.count ();- scroll = (int) (percent * liga);- - if (scroll > liga - visible_rows) {- scroll = (int) (liga - visible_rows);- }- - redraw_area (0, 0, allocation.width, allocation.height);+ public override string get_name () {+ return "Ligatures"; } } }-@@ -19,6 +19,9 @@ namespace BirdFont { public class Ligatures : GLib.Object { + public Gee.ArrayList<string> ligature = new Gee.ArrayList<string> ();+ public Gee.ArrayList<string> substitution = new Gee.ArrayList<string> ();+ public delegate void LigatureIterator (string substitution, string ligature); public delegate void SingleLigatureIterator (GlyphSequence substitution, GlyphCollection ligature); @@ -64,10 +67,26 @@ public class Ligatures : GLib.Object { } public int count () {- return 1;+ return ligature.size;+ }+ + public void remove_at (int i) {+ return_if_fail (0 <= i < ligature.size);+ return_if_fail (0 <= i < substitution.size);+ ligature.remove_at (i);+ substitution.remove_at (i); } + public void set_ligature (int index) {+ } + public void set_substitution (int index) {+ } ++ public void add_ligature (string subst, string liga) {+ substitution.insert (0, subst);+ ligature.insert (0, liga);+ } } }@@ -15,7 +15,7 @@ namespace BirdFont { /** Type2, PostScript outlines */-public class CffTable : Table {+public class CffTable : OtfTable { static const uint8 HSTEM = 1; static const uint8 VSTEM = 3;@@ -14,7 +14,7 @@ namespace BirdFont { -public class CmapTable : Table { +public class CmapTable : OtfTable { GlyfTable glyf_table; CmapSubtableFormat4 cmap_format4 = new CmapSubtableFormat4 ();@@ -14,7 +14,7 @@ namespace BirdFont { -public class CvtTable : Table {+public class CvtTable : OtfTable { public CvtTable () { id = "cvt ";@@ -15,7 +15,7 @@ namespace BirdFont { /** Table with list of tables sorted by table tag. */-public class DirectoryTable : Table {+public class DirectoryTable : OtfTable { public CmapTable cmap_table; public CvtTable cvt_table;@@ -36,7 +36,7 @@ public class DirectoryTable : Table { public OffsetTable offset_table; - Gee.ArrayList<Table> tables;+ Gee.ArrayList<OtfTable> tables; public DirectoryTable () { offset_table = new OffsetTable (this);@@ -60,7 +60,7 @@ public class DirectoryTable : Table { id = "Directory table"; - tables = new Gee.ArrayList<Table> ();+ tables = new Gee.ArrayList<OtfTable> (); } public void process () throws GLib.Error {@@ -86,7 +86,7 @@ public class DirectoryTable : Table { process_directory (); // this table } - public Gee.ArrayList<Table> get_tables () {+ public Gee.ArrayList<OtfTable> get_tables () { if (tables.size == 0) { tables.add (offset_table); tables.add (this);@@ -393,7 +393,7 @@ public class DirectoryTable : Table { public long get_font_file_size () { long length = 0; - foreach (Table t in tables) {+ foreach (OtfTable t in tables) { length += t.get_font_data ().length_with_padding (); } @@ -408,7 +408,7 @@ public class DirectoryTable : Table { // Check sum adjustment for the entire font public uint32 get_font_file_checksum () { uint32 check_sum = 0;- foreach (Table t in tables) {+ foreach (OtfTable t in tables) { t.get_font_data ().continous_check_sum (ref check_sum); } return check_sum;@@ -436,7 +436,7 @@ public class DirectoryTable : Table { head_table.process (); // write the directory - foreach (Table t in tables) {+ foreach (OtfTable t in tables) { if (t is DirectoryTable || t is OffsetTable) { continue;@@ -102,7 +102,7 @@ public class FontData : Object { uint l; if (length_with_padding () % 4 != 0) {- warning ("Table is not padded to correct size.");+ warning ("OtfTable is not padded to correct size."); } seek (0);@@ -14,7 +14,7 @@ namespace BirdFont { -public class GaspTable : Table {+public class GaspTable : OtfTable { public const uint16 NONE = 0; public const uint16 GASP_GRIDFIT = 1;@@ -14,7 +14,7 @@ namespace BirdFont { -public class GdefTable : Table {+public class GdefTable : OtfTable { public GdefTable () { id = "GDEF";@@ -14,7 +14,7 @@ namespace BirdFont { -public class GlyfTable : Table {+public class GlyfTable : OtfTable { // Flags for composite glyph static const uint16 BOTH_ARE_WORDS = 1 << 0; static const uint16 BOTH_ARE_XY_VALUES = 1 << 1;@@ -15,7 +15,7 @@ using Math; namespace BirdFont { -public class GposTable : Table {+public class GposTable : OtfTable { GlyfTable glyf_table; KernList pairs;@@ -15,7 +15,7 @@ using Math; namespace BirdFont { -public class GsubTable : Table {+public class GsubTable : OtfTable { GlyfTable glyf_table; @@ -155,7 +155,7 @@ public class GsubTable : Table { warning (@"Bad identifier expecting 1 found $identifier"); } - uint16 coverage_offset = fd.read_ushort ();+ uint16 coverage_offset = fd.read_ushort (); // TODO: read coverage uint16 num_sets = fd.read_ushort (); Gee.ArrayList<int> liga_set_offsets = new Gee.ArrayList<int> ();@@ -14,7 +14,7 @@ namespace BirdFont { -public class HeadTable : Table {+public class HeadTable : OtfTable { public int16 xmin = int16.MIN; public int16 ymin = int16.MIN;@@ -16,7 +16,7 @@ using Math; namespace BirdFont { -public class HheaTable : Table {+public class HheaTable : OtfTable { Fixed version; int16 ascender;@@ -14,7 +14,7 @@ namespace BirdFont { -public class HmtxTable : Table {+public class HmtxTable : OtfTable { uint32 nmetrics; uint32 nmonospaced;@@ -14,7 +14,7 @@ namespace BirdFont { -public class KernTable : Table {+public class KernTable : OtfTable { public static const uint16 HORIZONTAL = 1; public static const uint16 MINIMUM = 1 << 1;@@ -43,7 +43,7 @@ public class LigatureSet : GLib.Object { return (!) ligatures.get (0).substitution.get (0).to_string (); } - public FontData get_set_data () {+ public FontData get_set_data () throws GLib.Error { FontData fd, ligature_data; uint16 o, pos; @@ -14,7 +14,7 @@ namespace BirdFont { -public class LocaTable : Table {+public class LocaTable : OtfTable { uint32* glyph_offsets = null; public uint32 size = 0;@@ -14,7 +14,7 @@ namespace BirdFont { -public class MaxpTable : Table {+public class MaxpTable : OtfTable { GlyfTable glyf_table; @@ -14,7 +14,7 @@ namespace BirdFont { -public class NameTable : Table {+public class NameTable : OtfTable { public static const uint16 COPYRIGHT_NOTICE = 0; public static const uint16 FONT_NAME = 1;@@ -14,7 +14,7 @@ namespace BirdFont { -public class OffsetTable : Table {+public class OffsetTable : OtfTable { DirectoryTable directory_table; public uint16 num_tables = 0;@@ -43,7 +43,7 @@ public class OpenFontFormatWriter : Object { public void write_ttf_font (Font nfont) throws Error { long dl; uint8* data;- Gee.ArrayList<Table> tables;+ Gee.ArrayList<OtfTable> tables; FontData fd; uint l; @@ -59,7 +59,7 @@ public class OpenFontFormatWriter : Object { return; } - foreach (Table t in tables) {+ foreach (OtfTable t in tables) { fd = t.get_font_data (); data = fd.table_data; l = fd.length_with_padding ();@@ -16,7 +16,7 @@ using Math; namespace BirdFont { -public class Os2Table : Table {+public class Os2Table : OtfTable { public static const uint16 ITALIC = 1; public static const uint16 UNDERSCORE = 1 << 1;new file mode 100644@@ -0,0 +1,113 @@++/*+ Copyright (C) 2012, 2013 Johan Mattsson++ This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version.++ This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details.+*/++namespace BirdFont {++public class OtfTable : Object {++ public string id = "NO_ID";++ public uint32 checksum = 0;+ public uint32 offset = 0;+ public uint32 length = 0;++ protected FontData? font_data = null;++ public virtual string get_id () {+ return id;+ }+ + public FontData get_font_data () {+ if (font_data == null) {+ warning (@"No font data for $(id).");+ font_data = new FontData ();+ }+ + return (!) font_data;+ }++ public bool has_data () {+ return length > 0;+ }++ public virtual void parse (FontData dis) throws GLib.Error {+ warning (@"Parse is not implemented for $(id).");+ }++ /** Validate table checksum. */+ public bool validate (FontData dis) {+ bool valid;+ + if (length == 0) {+ stderr.printf (@"OtfTable $id is of zero length.\n"); + valid = false;+ } else {+ valid = OtfTable.validate_table (dis, checksum, offset, length, id);+ }+ + if (!valid) {+ stderr.printf (@"OtfTable $id is invalid.\n");+ }+ + return valid;+ }++ public static bool validate_table (FontData dis, uint32 checksum, uint32 offset, uint32 length, string name) {+ uint32 ch = calculate_checksum (dis, offset, length, name);+ bool c;+ + c = (ch == checksum);+ + if (!c) {+ stderr.printf(@"Checksum does not match data for $(name).\n");+ stderr.printf(@"name: $name, checksum: $checksum, offset: $offset, length: $length\n");+ stderr.printf(@"calculated checksum $(ch)\n");+ }+ + return c; + }+ + public static uint32 calculate_checksum (FontData dis, uint32 offset, uint32 length, string name) {+ uint32 checksum = 0;+ uint32 l;+ + dis.seek (offset);++ l = (length % 4 > 0) ? length / 4 + 1 : length / 4; ++ for (uint32 i = 0; i < l; i++) {+ checksum += dis.read_ulong ();+ }+ + return checksum;+ }+ + public static uint16 max_pow_2_less_than_i (uint16 ind) {+ uint16 last = 0;+ uint16 i = 1;+ + while ((i <<= 1) < ind) {+ last = i;+ }+ + return last;+ }++ public static uint16 max_log_2_less_than_i (uint16 ind) {+ return (uint16) (Math.log (ind) / Math.log (2));+ }+}++}@@ -14,7 +14,7 @@ namespace BirdFont { -public class PostTable : Table {+public class PostTable : OtfTable { GlyfTable glyf_table; deleted file mode 100644@@ -1,113 +0,0 @@--/*- Copyright (C) 2012, 2013 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details.-*/--namespace BirdFont {--public class Table : Object {-- public string id = "NO_ID";-- public uint32 checksum = 0;- public uint32 offset = 0;- public uint32 length = 0;-- protected FontData? font_data = null;-- public virtual string get_id () {- return id;- }- - public FontData get_font_data () {- if (font_data == null) {- warning (@"No font data for $(id).");- font_data = new FontData ();- }- - return (!) font_data;- }-- public bool has_data () {- return length > 0;- }-- public virtual void parse (FontData dis) throws GLib.Error {- warning (@"Parse is not implemented for $(id).");- }-- /** Validate table checksum. */- public bool validate (FontData dis) {- bool valid;- - if (length == 0) {- stderr.printf (@"Table $id is of zero length.\n"); - valid = false;- } else {- valid = Table.validate_table (dis, checksum, offset, length, id);- }- - if (!valid) {- stderr.printf (@"Table $id is invalid.\n");- }- - return valid;- }-- public static bool validate_table (FontData dis, uint32 checksum, uint32 offset, uint32 length, string name) {- uint32 ch = calculate_checksum (dis, offset, length, name);- bool c;- - c = (ch == checksum);- - if (!c) {- stderr.printf(@"Checksum does not match data for $(name).\n");- stderr.printf(@"name: $name, checksum: $checksum, offset: $offset, length: $length\n");- stderr.printf(@"calculated checksum $(ch)\n");- }- - return c; - }- - public static uint32 calculate_checksum (FontData dis, uint32 offset, uint32 length, string name) {- uint32 checksum = 0;- uint32 l;- - dis.seek (offset);-- l = (length % 4 > 0) ? length / 4 + 1 : length / 4; -- for (uint32 i = 0; i < l; i++) {- checksum += dis.read_ulong ();- }- - return checksum;- }- - public static uint16 max_pow_2_less_than_i (uint16 ind) {- uint16 last = 0;- uint16 i = 1;- - while ((i <<= 1) < ind) {- last = i;- }- - return last;- }-- public static uint16 max_log_2_less_than_i (uint16 ind) {- return (uint16) (Math.log (ind) / Math.log (2));- }-}--}@@ -16,22 +16,20 @@ using Math; namespace BirdFont { -public class SpacingClassTab : FontDisplay {-- int scroll = 0;- int visible_rows = 0;- WidgetAllocation allocation = new WidgetAllocation ();- Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> ();+public class SpacingClassTab : Table { public Gee.ArrayList<SpacingClass> classes = new Gee.ArrayList<SpacingClass> ();- public static int NEW_CLASS = -1;- Gee.ArrayList<string> connections = new Gee.ArrayList<string> ();+ Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> (); public SpacingClassTab () { } + public override Gee.ArrayList<Row> get_rows () {+ return rows;+ }+ public static void remove_all_spacing_classes () { if (!is_null (MainWindow.spacing_class_tab)) { MainWindow.spacing_class_tab.classes.clear ();@@ -109,7 +107,7 @@ public class SpacingClassTab : FontDisplay { KerningTools.update_spacing_classes (); } - public void selected_row (Row row, int column, bool delete_button) {+ public override void selected_row (Row row, int column, bool delete_button) { Font font = BirdFont.get_current_font (); if (row.get_index () == -1) {@@ -140,17 +138,12 @@ public class SpacingClassTab : FontDisplay { } } }-- public override void selected_canvas () {- update_rows ();- update_scrollbar ();- } void update_all_rows (SpacingClass s) { update_rows (); } - void update_rows () {+ public override void update_rows () { int i = 0; rows.clear ();@@ -163,109 +156,6 @@ public class SpacingClassTab : FontDisplay { GlyphCanvas.redraw (); }- - public override void draw (WidgetAllocation allocation, Context cr) {- double y = 20 * MainWindow.units;- int s = 0;- bool color = (scroll + 1 % 2) == 0;- - if (allocation.width != this.allocation.width- || allocation.height != this.allocation.height) {- this.allocation = allocation;- update_rows ();- update_scrollbar ();- }- - visible_rows = (int) (allocation.height / 18.0);- - cr.save ();- cr.set_source_rgba (1, 1, 1, 1);- cr.rectangle (0, 0, allocation.width, allocation.height);- cr.fill ();- cr.restore ();- - cr.save ();- cr.set_source_rgba (0.3, 0.3, 0.3, 1);- cr.set_font_size (12);-- foreach (Row r in rows) {- if (s++ >= scroll) {- draw_row (allocation, cr, r, y, color, true);- y += 18 * MainWindow.units;- color = !color;- }- }- - cr.restore ();- } -- private static void draw_row (WidgetAllocation allocation, Context cr,- Row row, double y, bool color, bool dark) {- - double margin;- - if (color) {- cr.save ();- cr.set_source_rgba (224/255.0, 224/255.0, 224/255.0, 1);- cr.rectangle (0, y - 14 * MainWindow.units, allocation.width, 18 * MainWindow.units);- cr.fill ();- cr.restore ();- }-- if (row.has_delete_button ()) {- cr.save ();- cr.set_line_width (1);- cr.move_to (10 * MainWindow.units, y - 8 * MainWindow.units);- cr.line_to (15 * MainWindow.units, y - 3 * MainWindow.units);- cr.move_to (10 * MainWindow.units, y - 3 * MainWindow.units);- cr.line_to (15 * MainWindow.units, y - 8 * MainWindow.units); - cr.stroke ();- cr.restore ();- }- - for (int i = 0; i < row.columns; i++) {- cr.save ();- margin = (row.has_delete_button ()) ? 120 * MainWindow.units : 3* MainWindow.units;- cr.move_to (margin + i * 120 * MainWindow.units, y);- cr.set_font_size (12 * MainWindow.units);- cr.show_text (row.get_column (i));- cr.restore ();- }- }-- public override void button_release (int button, double ex, double ey) {- int s = 0;- double y = 0;- int colum = -1;- Row? selected = null;- bool over_delete = false;-- foreach (Row r in rows) {- if (s++ >= scroll) {- y += 18 * MainWindow.units;- - if (y - 10 * MainWindow.units <= ey * MainWindow.units <= y + 5 * MainWindow.units) {- - if (r.has_delete_button ()) {- colum = (int) ((ex - 120) / 120 * MainWindow.units);- } else {- colum = (int) ((ex) / 120 * MainWindow.units);- }- - over_delete = (ex < 18 && r.has_delete_button ());- selected = r;- break;- }- }- }- - if (selected != null) {- selected_row ((!) selected, colum, over_delete); - }- - update_scrollbar ();- redraw_area (0, 0, allocation.width, allocation.height);- } public override string get_label () { return t_("Spacing Classes");@@ -274,60 +164,6 @@ public class SpacingClassTab : FontDisplay { public override string get_name () { return "SpacingClasses"; }-- public override bool has_scrollbar () {- return true;- }- - public override void scroll_wheel_down (double x, double y) {- int nrows = rows.size;- scroll += 3;-- if (scroll > nrows - visible_rows) {- scroll = (int) (nrows - visible_rows);- }- - if (visible_rows > nrows) {- scroll = 0;- } - - update_scrollbar ();- redraw_area (0, 0, allocation.width, allocation.height);- }- - public override void scroll_wheel_up (double x, double y) {- scroll -= 3;- - if (scroll < 0) {- scroll = 0;- }- - update_scrollbar ();- redraw_area (0, 0, allocation.width, allocation.height);- }- - public void update_scrollbar () {- uint rows = rows.size;-- if (rows == 0 || visible_rows == 0) {- MainWindow.set_scrollbar_size (0);- MainWindow.set_scrollbar_position (0);- } else {- MainWindow.set_scrollbar_size ((double) visible_rows / rows);- MainWindow.set_scrollbar_position ((double) scroll / rows);- }- }-- public override void scroll_to (double percent) {- uint rows = rows.size;- scroll = (int) (percent * rows);- - if (scroll > rows - visible_rows) {- scroll = (int) (rows - visible_rows);- }- - redraw_area (0, 0, allocation.width, allocation.height);- } } }