diff options
| author | Felipe Corr??a da Silva Sanches <juca@members.fsf.org> | 2011-05-22 21:11:19 +0000 |
|---|---|---|
| committer | Felipe C. da S. Sanches <juca@members.fsf.org> | 2011-05-22 21:11:19 +0000 |
| commit | 3adbef99b318bd361c429b470a5f38cf21e8000a (patch) | |
| tree | 0d807a5025490ca36b4cc75235cbbd6bd5a71d55 | |
| parent | Merge fix for bug #781244 from Martin Owens - wrong conversion (diff) | |
| download | inkscape-3adbef99b318bd361c429b470a5f38cf21e8000a.tar.gz inkscape-3adbef99b318bd361c429b470a5f38cf21e8000a.zip | |
actually fontforge flipping of y-axis for svgfont glyphs is compliant with the svg spec. So we need to do it also.
(bzr r10218)
| -rw-r--r-- | share/extensions/layers2svgfont.py | 27 | ||||
| -rw-r--r-- | share/extensions/setup_typography_canvas.inx | 2 | ||||
| -rwxr-xr-x | share/extensions/setup_typography_canvas.py | 6 | ||||
| -rw-r--r-- | src/display/nr-svgfonts.cpp | 30 | ||||
| -rw-r--r-- | src/display/nr-svgfonts.h | 2 | ||||
| -rw-r--r-- | src/ui/dialog/svg-fonts-dialog.cpp | 28 | ||||
| -rw-r--r-- | src/ui/dialog/svg-fonts-dialog.h | 2 |
7 files changed, 83 insertions, 14 deletions
diff --git a/share/extensions/layers2svgfont.py b/share/extensions/layers2svgfont.py index b53cf241c..7921ec233 100644 --- a/share/extensions/layers2svgfont.py +++ b/share/extensions/layers2svgfont.py @@ -23,6 +23,12 @@ logfile = open("/tmp/inkscape-ext-logfile", "wa") def LOG(s): logfile.write(s+"\n") +def flip_cordinate_system(d, units_per_em, baseline): + #todo + return d + +bugged_fontforge_compatibility_mode = True + class Layers2SVGFont(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) @@ -55,11 +61,12 @@ class Layers2SVGFont(inkex.Effect): self.defs = self.get_or_create(self.svg, inkex.addNS('defs', 'svg')) setwidth = int(self.svg.get("width")) + units_per_em = setwidth #TODO: ask the user for this value? baseline = self.guideline_value("baseline", 1) ascender = self.guideline_value("ascender", 1) - baseline caps = self.guideline_value("caps", 1) - baseline xheight = self.guideline_value("xheight", 1) - baseline - descender = self.guideline_value("descender", 1) - baseline + descender = baseline - self.guideline_value("descender", 1) lbearing = self.guideline_value("lbearing", 0) rbearing = setwidth - self.guideline_value("rbearing", 0) @@ -74,8 +81,9 @@ class Layers2SVGFont(inkex.Effect): font = self.get_or_create(self.defs, inkex.addNS('font', 'svg')) font.set("horiz-adv-x", str(setwidth)) + font.set("horiz-origin-y", str(baseline)) - fontface = self.get_or_create(font, inkex.addNS('fontface', 'svg')) + fontface = self.get_or_create(font, inkex.addNS('font-face', 'svg')) fontface.set("units-per-em", str(setwidth)) fontface.set("cap-height", str(caps)) fontface.set("x-height", str(xheight)) @@ -90,9 +98,18 @@ class Layers2SVGFont(inkex.Effect): unicode_char = label.split("GlyphLayer-")[1] glyph = self.get_or_create_glyph(font, unicode_char) glyph.set("unicode", unicode_char) - use = self.get_or_create(glyph, inkex.addNS('use', 'svg')) - use.set(inkex.addNS('href', 'xlink'), "#"+group.get("id")) - #TODO: This code creates nodes but they do not render on svg fonts dialog. why? + + #use = self.get_or_create(glyph, inkex.addNS('use', 'svg')) + #use.set(inkex.addNS('href', 'xlink'), "#"+group.get("id")) + #TODO: This code creates <use> nodes but they do not render on svg fonts dialog. why? + + paths = group.findall(inkex.addNS('path', 'svg')) + for p in paths: + path = inkex.etree.SubElement(glyph, inkex.addNS('path', 'svg')) + d = p.get("d") + if not bugged_fontforge_compatibility_mode: + d = flip_cordinate_system(d, units_per_em, baseline) + path.set("d", d) if __name__ == '__main__': LOG("\n\n"+"*"*80+"\n\n") diff --git a/share/extensions/setup_typography_canvas.inx b/share/extensions/setup_typography_canvas.inx index ed89b71fc..4c8c6499b 100644 --- a/share/extensions/setup_typography_canvas.inx +++ b/share/extensions/setup_typography_canvas.inx @@ -8,7 +8,7 @@ <param name="ascender" type="int" _gui-text="Ascender:" min="0" max="2000">750</param> <param name="caps" type="int" _gui-text="Caps Height:" min="0" max="2000">700</param> <param name="xheight" type="int" _gui-text="X-Height:" min="0" max="2000">500</param> - <param name="descender" type="int" _gui-text="Descender:" min="-1000" max="0">-250</param> + <param name="descender" type="int" _gui-text="Descender:" min="0" max="1000">250</param> <param name="lbearing" type="int" _gui-text="Left Side Bearing:" min="0" max="2000">100</param> <param name="rbearing" type="int" _gui-text="Right Side Bearing:" min="0" max="2000">100</param> <effect> diff --git a/share/extensions/setup_typography_canvas.py b/share/extensions/setup_typography_canvas.py index 4d9dd3d5f..7e4b32603 100755 --- a/share/extensions/setup_typography_canvas.py +++ b/share/extensions/setup_typography_canvas.py @@ -40,7 +40,7 @@ class SetupTypographyCanvas(inkex.Effect): help="x-height") self.OptionParser.add_option("-d", "--descender", action="store", type="int", - dest="descender", default='-250', + dest="descender", default='250', help="Descender") self.OptionParser.add_option("-l", "--lbearing", action="store", type="int", @@ -79,13 +79,13 @@ class SetupTypographyCanvas(inkex.Effect): self.svg.set("width", str(setwidth)) self.svg.set("height", str(setwidth)) - baseline = -descender + baseline = descender # Create guidelines self.create_horizontal_guideline("baseline", baseline) self.create_horizontal_guideline("ascender", baseline+ascender) self.create_horizontal_guideline("caps", baseline+caps) self.create_horizontal_guideline("xheight", baseline+xheight) - self.create_horizontal_guideline("descender", baseline+descender) + self.create_horizontal_guideline("descender", baseline-descender) self.create_vertical_guideline("lbearing", lbearing) self.create_vertical_guideline("rbearing", setwidth-rbearing) diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp index b071ba21b..cf23ee5d5 100644 --- a/src/display/nr-svgfonts.cpp +++ b/src/display/nr-svgfonts.cpp @@ -25,6 +25,9 @@ #include "../sp-use.h" #include "../sp-use-reference.h" #include "curve.h" +#include "xml/repr.h" +#include "sp-font-face.h" + //*************************// // UserFont Implementation // @@ -240,6 +243,24 @@ SvgFont::glyph_modified(SPObject* /* blah */, unsigned int /* bleh */){ //TODO: update rendering on svgfonts preview widget (in the svg fonts dialog) } +Geom::PathVector +SvgFont::flip_coordinate_system(SPFont* spfont, Geom::PathVector pathv){ + double units_per_em = 1000; + SPObject* obj; + for (obj = ((SPObject*) spfont)->children; obj; obj=obj->next){ + if (SP_IS_FONTFACE(obj)){ + //XML Tree being directly used here while it shouldn't be. + sp_repr_get_double(obj->getRepr(), "units_per_em", &units_per_em); + } + } + + double baseline_offset = units_per_em - spfont->horiz_origin_y; + + //This matrix flips y-axis and places the origin at baseline + Geom::Affine m(Geom::Coord(1),Geom::Coord(0),Geom::Coord(0),Geom::Coord(-1),Geom::Coord(0),Geom::Coord(baseline_offset)); + return pathv*m; +} + cairo_status_t SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, unsigned long glyph, @@ -266,15 +287,22 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, return CAIRO_STATUS_SUCCESS; // FIXME: is this the right code to return? } + SPFont* spfont = (SPFont*) node->parent; + if (!spfont) { + return CAIRO_STATUS_SUCCESS; // FIXME: is this the right code to return? + } + //glyphs can be described by arbitrary SVG declared in the childnodes of a glyph node // or using the d attribute of a glyph node. // pathv stores the path description from the d attribute: Geom::PathVector pathv; if (SP_IS_GLYPH(node) && ((SPGlyph*)node)->d) { pathv = sp_svg_read_pathv(((SPGlyph*)node)->d); + pathv = flip_coordinate_system(spfont, pathv); this->render_glyph_path(cr, &pathv); } else if (SP_IS_MISSING_GLYPH(node) && ((SPMissingGlyph*)node)->d) { pathv = sp_svg_read_pathv(((SPMissingGlyph*)node)->d); + pathv = flip_coordinate_system(spfont, pathv); this->render_glyph_path(cr, &pathv); } @@ -283,6 +311,7 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, for(node = node->children; node; node=node->next){ if (SP_IS_PATH(node)){ pathv = ((SPShape*)node)->curve->get_pathvector(); + pathv = flip_coordinate_system(spfont, pathv); this->render_glyph_path(cr, &pathv); } if (SP_IS_OBJECTGROUP(node)){ @@ -292,6 +321,7 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, SPItem* item = SP_USE(node)->ref->getObject(); if (SP_IS_PATH(item)){ pathv = ((SPShape*)item)->curve->get_pathvector(); + pathv = flip_coordinate_system(spfont, pathv); this->render_glyph_path(cr, &pathv); } diff --git a/src/display/nr-svgfonts.h b/src/display/nr-svgfonts.h index b6eaf449d..3cfcbaa72 100644 --- a/src/display/nr-svgfonts.h +++ b/src/display/nr-svgfonts.h @@ -38,6 +38,8 @@ cairo_font_face_t* get_font_face(); cairo_status_t scaled_font_init (cairo_scaled_font_t *scaled_font, cairo_font_extents_t *metrics); cairo_status_t scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font, const char *utf8, int utf8_len, cairo_glyph_t **glyphs, int *num_glyphs, cairo_text_cluster_t **clusters, int *num_clusters, cairo_text_cluster_flags_t *flags); cairo_status_t scaled_font_render_glyph (cairo_scaled_font_t *scaled_font, unsigned long glyph, cairo_t *cr, cairo_text_extents_t *metrics); + +Geom::PathVector flip_coordinate_system(SPFont* spfont, Geom::PathVector pathv); void render_glyph_path(cairo_t* cr, Geom::PathVector* pathv); void glyph_modified(SPObject *, unsigned int); diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index 6bcd5d898..4d53154d8 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -16,7 +16,6 @@ #ifdef ENABLE_SVG_FONTS -#include <2geom/pathvector.h> #include "document-private.h" #include <gtkmm/notebook.h> #include <glibmm/i18n.h> @@ -474,6 +473,24 @@ void SvgFontsDialog::add_glyph(){ update_glyphs(); } +Geom::PathVector +SvgFontsDialog::flip_coordinate_system(Geom::PathVector pathv){ + double units_per_em = 1000; + SPObject* obj; + for (obj = get_selected_spfont()->children; obj; obj=obj->next){ + if (SP_IS_FONTFACE(obj)){ + //XML Tree being directly used here while it shouldn't be. + sp_repr_get_double(obj->getRepr(), "units_per_em", &units_per_em); + } + } + + double baseline_offset = units_per_em - get_selected_spfont()->horiz_origin_y; + + //This matrix flips y-axis and places the origin at baseline + Geom::Affine m(Geom::Coord(1),Geom::Coord(0),Geom::Coord(0),Geom::Coord(-1),Geom::Coord(0),Geom::Coord(baseline_offset)); + return pathv*m; +} + void SvgFontsDialog::set_glyph_description_from_selected_path(){ SPDesktop* desktop = this->getDesktop(); if (!desktop) { @@ -498,16 +515,17 @@ void SvgFontsDialog::set_glyph_description_from_selected_path(){ return; } //TODO: //Is there a better way to tell it to to the user? - Geom::PathVector pathv = sp_svg_read_pathv(node->attribute("d")); - SPGlyph* glyph = get_selected_glyph(); if (!glyph){ char *msg = _("No glyph selected in the SVGFonts dialog."); msgStack->flash(Inkscape::ERROR_MESSAGE, msg); return; } + + Geom::PathVector pathv = sp_svg_read_pathv(node->attribute("d")); + //XML Tree being directly used here while it shouldn't be. - glyph->getRepr()->setAttribute("d", (char*) sp_svg_write_path (pathv)); + glyph->getRepr()->setAttribute("d", (char*) sp_svg_write_path (flip_coordinate_system(pathv))); DocumentUndo::done(doc, SP_VERB_DIALOG_SVG_FONTS, _("Set glyph curves")); update_glyphs(); @@ -544,7 +562,7 @@ void SvgFontsDialog::missing_glyph_description_from_selected_path(){ if (SP_IS_MISSING_GLYPH(obj)){ //XML Tree being directly used here while it shouldn't be. - obj->getRepr()->setAttribute("d", (char*) sp_svg_write_path (pathv)); + obj->getRepr()->setAttribute("d", (char*) sp_svg_write_path (flip_coordinate_system(pathv))); DocumentUndo::done(doc, SP_VERB_DIALOG_SVG_FONTS, _("Set glyph curves")); } } diff --git a/src/ui/dialog/svg-fonts-dialog.h b/src/ui/dialog/svg-fonts-dialog.h index 50821cc6c..8c2bdc1a4 100644 --- a/src/ui/dialog/svg-fonts-dialog.h +++ b/src/ui/dialog/svg-fonts-dialog.h @@ -11,6 +11,7 @@ #ifndef INKSCAPE_UI_DIALOG_SVG_FONTS_H #define INKSCAPE_UI_DIALOG_SVG_FONTS_H +#include <2geom/pathvector.h> #include "ui/widget/panel.h" #include "ui/widget/spinbutton.h" #include "sp-font.h" @@ -78,6 +79,7 @@ public: void on_kerning_value_changed(); void on_setwidth_changed(); void add_font(); + Geom::PathVector flip_coordinate_system(Geom::PathVector pathv); //TODO: AttrEntry is currently unused. Should we remove it? class AttrEntry : public Gtk::HBox |
