summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFelipe Corr??a da Silva Sanches <juca@members.fsf.org>2011-05-22 21:11:19 +0000
committerFelipe C. da S. Sanches <juca@members.fsf.org>2011-05-22 21:11:19 +0000
commit3adbef99b318bd361c429b470a5f38cf21e8000a (patch)
tree0d807a5025490ca36b4cc75235cbbd6bd5a71d55 /src
parentMerge fix for bug #781244 from Martin Owens - wrong conversion (diff)
downloadinkscape-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)
Diffstat (limited to 'src')
-rw-r--r--src/display/nr-svgfonts.cpp30
-rw-r--r--src/display/nr-svgfonts.h2
-rw-r--r--src/ui/dialog/svg-fonts-dialog.cpp28
-rw-r--r--src/ui/dialog/svg-fonts-dialog.h2
4 files changed, 57 insertions, 5 deletions
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