diff options
| author | Felipe Corr??a da Silva Sanches <juca@members.fsf.org> | 2011-05-19 18:36:51 +0000 |
|---|---|---|
| committer | Felipe C. da S. Sanches <juca@members.fsf.org> | 2011-05-19 18:36:51 +0000 |
| commit | cdddf155baf531b9783c8c5a02ec491a9cde3afc (patch) | |
| tree | 469e07b28498d4b5c74236e089d52da6c7cd9008 /src | |
| parent | Revert version bump so win devlibs can catch up. (diff) | |
| download | inkscape-cdddf155baf531b9783c8c5a02ec491a9cde3afc.tar.gz inkscape-cdddf155baf531b9783c8c5a02ec491a9cde3afc.zip | |
fix rendering of SVG Fonts. Apparently the glyphs were wrongly rendered upside-down since I was trying to make it compatible with fontforge rendering. Now, reading again the SVG spec, it seems to me that it is fontforge that renders it incorrectly.
I have also added support for rendering path tags that are children of glyph and missing-glyph nodes. And also use tags. But fontforge does not seem to understand use tags in glyph descriptions... compatibility issues that we have to figure out how to solve.
(bzr r10211)
Diffstat (limited to 'src')
| -rw-r--r-- | src/display/nr-svgfonts.cpp | 71 | ||||
| -rw-r--r-- | src/display/nr-svgfonts.h | 4 |
2 files changed, 57 insertions, 18 deletions
diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp index 62d52b04b..b071ba21b 100644 --- a/src/display/nr-svgfonts.cpp +++ b/src/display/nr-svgfonts.cpp @@ -20,6 +20,11 @@ #include "svg/svg.h" #include "inkscape-cairo.h" #include "nr-svgfonts.h" +#include "../sp-path.h" +#include "../sp-object-group.h" +#include "../sp-use.h" +#include "../sp-use-reference.h" +#include "curve.h" //*************************// // UserFont Implementation // @@ -212,6 +217,29 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, return CAIRO_STATUS_SUCCESS; } +void +SvgFont::render_glyph_path(cairo_t* cr, Geom::PathVector* pathv){ + if (!pathv->empty()){ + //This glyph has a path description on its d attribute, so we render it: + cairo_new_path(cr); + + //adjust scale of the glyph +// Geom::Scale s(1.0/((SPFont*) node->parent)->horiz_adv_x); + Geom::Scale s(1.0/1000);//TODO: use here the units-per-em attribute? + + Geom::Rect area( Geom::Point(0,0), Geom::Point(1,1) ); //I need help here! (reaction: note that the 'area' parameter is an *optional* rect, so you can pass an empty Geom::OptRect() ) + + feed_pathvector_to_cairo (cr, *pathv, s, area, false, 0); + cairo_fill(cr); + } +} + +void +SvgFont::glyph_modified(SPObject* /* blah */, unsigned int /* bleh */){ + this->refresh(); + //TODO: update rendering on svgfonts preview widget (in the svg fonts dialog) +} + cairo_status_t SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, unsigned long glyph, @@ -234,37 +262,44 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, node = (SPObject*) this->glyphs[glyph]; } + if (!SP_IS_GLYPH(node) && !SP_IS_MISSING_GLYPH(node)) { + 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); + this->render_glyph_path(cr, &pathv); } else if (SP_IS_MISSING_GLYPH(node) && ((SPMissingGlyph*)node)->d) { pathv = sp_svg_read_pathv(((SPMissingGlyph*)node)->d); - } else { - return CAIRO_STATUS_SUCCESS; // FIXME: is this the right code to return? + this->render_glyph_path(cr, &pathv); } - if (!pathv.empty()){ - //This glyph has a path description on its d attribute, so we render it: - cairo_new_path(cr); - //adjust scale of the glyph -// Geom::Scale s(1.0/((SPFont*) node->parent)->horiz_adv_x); - Geom::Scale s(1.0/1000);//TODO: use here the units-per-em attribute? - //This matrix flips the glyph vertically - Geom::Affine m(Geom::Coord(1),Geom::Coord(0),Geom::Coord(0),Geom::Coord(-1),Geom::Coord(0),Geom::Coord(0)); - //then we offset it -// pathv += Geom::Point(Geom::Coord(0),Geom::Coord(-((SPFont*) node->parent)->horiz_adv_x)); - pathv += Geom::Point(Geom::Coord(0),Geom::Coord(-1000));//TODO: use here the units-per-em attribute? - - Geom::Rect area( Geom::Point(0,0), Geom::Point(1,1) ); //I need help here! (reaction: note that the 'area' parameter is an *optional* rect, so you can pass an empty Geom::OptRect() ) + if (node->hasChildren()){ + //render the SVG described on this glyph's child nodes. + for(node = node->children; node; node=node->next){ + if (SP_IS_PATH(node)){ + pathv = ((SPShape*)node)->curve->get_pathvector(); + this->render_glyph_path(cr, &pathv); + } + if (SP_IS_OBJECTGROUP(node)){ + g_warning("TODO: svgfonts: render OBJECTGROUP"); + } + if (SP_IS_USE(node)){ + SPItem* item = SP_USE(node)->ref->getObject(); + if (SP_IS_PATH(item)){ + pathv = ((SPShape*)item)->curve->get_pathvector(); + this->render_glyph_path(cr, &pathv); + } - feed_pathvector_to_cairo (cr, pathv, s*m, area, false, 0); - cairo_fill(cr); + glyph_modified_connection = ((SPObject*) item)->connectModified(sigc::mem_fun(*this, &SvgFont::glyph_modified)); + } + } } - //TODO: render the SVG described on this glyph's child nodes. return CAIRO_STATUS_SUCCESS; } diff --git a/src/display/nr-svgfonts.h b/src/display/nr-svgfonts.h index ddf4ba327..b6eaf449d 100644 --- a/src/display/nr-svgfonts.h +++ b/src/display/nr-svgfonts.h @@ -19,6 +19,7 @@ #include "../sp-missing-glyph.h" #include "../sp-font.h" #include "../sp-glyph-kerning.h" +#include <sigc++/sigc++.h> class SvgFont; struct SPFont; @@ -37,12 +38,15 @@ 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); +void render_glyph_path(cairo_t* cr, Geom::PathVector* pathv); +void glyph_modified(SPObject *, unsigned int); private: SPFont* font; UserFont* userfont; std::vector<SPGlyph*> glyphs; SPMissingGlyph* missingglyph; +sigc::connection glyph_modified_connection; bool drawing_expose_cb (Gtk::Widget *widget, GdkEventExpose *event, gpointer data); }; |
