The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Move gradient

These changes was commited to the Birdfont repository Sun, 17 Jul 2016 14:54:05 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 17 Jul 2016 14:54:05 +0000 (16:54 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 17 Jul 2016 14:54:05 +0000 (16:54 +0200)
commit c85ed3307df2cd9b30b155d3aecff231c047daad
tree 06e16b77e547f7c6c902be60da5682c03ddbfcec
parent 72a8c8ed21a1b205ed172dc50dd0fb94cdc374f0
Move gradient

libbirdfont/TextRendering/fontconfig.c
libsvgbird/Gradient.vala
libsvgbird/Object.vala
libsvgbird/text_drawing.c
--- a/libbirdfont/TextRendering/fontconfig.c +++ b/libbirdfont/TextRendering/fontconfig.c @@ -118,7 +118,7 @@ FcPatternAddBool (search_pattern, FC_SCALABLE, FcTrue); FcPatternAddInteger (search_pattern, FC_WEIGHT, FC_WEIGHT_MEDIUM); FcPatternAddInteger (search_pattern, FC_SLANT, FC_SLANT_ROMAN); - + font_properties = FcObjectSetBuild (FC_FILE, NULL); fonts = FcFontList (font_config, search_pattern, font_properties);
--- a/libsvgbird/Gradient.vala +++ b/libsvgbird/Gradient.vala @@ -23,6 +23,7 @@ public string id = ""; public string? href = null; public SvgTransforms transforms; + public Matrix parent_matrix = Matrix.identity (); public Matrix view_matrix = Matrix.identity (); public Gradient () { @@ -34,6 +35,21 @@ foreach (Stop stop in g.stops) { stops.add (stop.copy ()); } + } + + public void move (double dx, double dy) { + double x = dx; + double y = dy; + + Matrix parent = parent_matrix; + parent.invert (); + parent.transform_distance (ref x, ref y); + + Matrix m = Matrix.identity (); + m.translate (-x, -y); + + transforms.transforms.insert (0, new SvgTransform.for_matrix (m)); + transforms.collapse_transforms (); } public Matrix get_matrix () {
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -118,12 +118,26 @@ public abstract bool is_empty (); public virtual void move (double dx, double dy) { + Gradient g; + left += dx; right += dx; top += dy; bottom += dy; + + if (style.fill_gradient != null) { + g = (!) style.fill_gradient; + g.move (dx, dy); + } + + if (style.stroke_gradient != null) { + g = (!) style.stroke_gradient; + g.move (dx, dy); + } + to_object_distance (ref dx, ref dy); transforms.translate (dx, dy); + update_view_matrix (); } @@ -234,6 +248,7 @@ pattern.set_matrix (gradient_matrix); + g.parent_matrix = view_matrix; g.view_matrix = gradient_matrix; foreach (Stop s in g.stops) { @@ -259,7 +274,15 @@ bool has_stroke = style.has_stroke (); apply_transform (context); - + + if (style.fill_gradient != null) { + apply_gradient (context, (!) style.fill_gradient); + } + + if (style.stroke_gradient != null) { + apply_gradient (context, (!) style.stroke_gradient); + } + if (has_stroke) { context.set_line_width (style.stroke_width); } else { @@ -298,10 +321,10 @@ public virtual bool update_boundaries_for_object () { ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1); Context context = new Cairo.Context (surface); + context.set_matrix (parent_matrix); return update_boundaries (context); } - } }
--- a/libsvgbird/text_drawing.c +++ b/libsvgbird/text_drawing.c @@ -233,6 +233,8 @@ // match any font as fallback search_pattern = FcPatternCreate (); + FcPatternAddInteger (search_pattern, FC_SLANT, FC_SLANT_ROMAN); + font_properties = FcObjectSetBuild (FC_FILE, NULL); fonts = FcFontList (font_config, search_pattern, font_properties); @@ -255,6 +257,10 @@ // search for a family name search_pattern = FcPatternCreate (); FcPatternAddString (search_pattern, FC_FAMILY, name); + FcPatternAddInteger (search_pattern, FC_SLANT, FC_SLANT_ROMAN); + FcPatternAddBool (search_pattern, FC_SCALABLE, FcTrue); + FcPatternAddInteger (search_pattern, FC_WEIGHT, FC_WEIGHT_MEDIUM); + fonts = FcFontList (font_config, search_pattern, font_properties); if (fonts->nfont > 0) {