summaryrefslogtreecommitdiffstats
path: root/src/display/nr-svgfonts.cpp
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2016-09-06 13:07:01 +0000
committertavmjong-free <tavmjong@free.fr>2016-09-06 13:07:01 +0000
commitb8ff8d148d60abacb847b86069b12f63b1e235ec (patch)
tree68c23eea920e9ca2f3203361f6a45989e8d03849 /src/display/nr-svgfonts.cpp
parentImprove pattern rendering with large pattern transform. (diff)
parentImprove font editing dialog: (diff)
downloadinkscape-b8ff8d148d60abacb847b86069b12f63b1e235ec.tar.gz
inkscape-b8ff8d148d60abacb847b86069b12f63b1e235ec.zip
Improve font editing dialog.
(bzr r15109)
Diffstat (limited to 'src/display/nr-svgfonts.cpp')
-rw-r--r--src/display/nr-svgfonts.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp
index 53a5cba49..fd092aed8 100644
--- a/src/display/nr-svgfonts.cpp
+++ b/src/display/nr-svgfonts.cpp
@@ -197,6 +197,7 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/,
bool is_horizontal_text = true; //TODO
_utf8 = (char*) utf8;
+ double font_height = units_per_em();
while(g_utf8_get_char(_utf8)){
len = 0;
for (i=0; i < (unsigned long) this->glyphs.size(); i++){
@@ -210,13 +211,13 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/,
//apply glyph kerning if appropriate
SPHkern *hkern = dynamic_cast<SPHkern *>(&node);
if (hkern && is_horizontal_text &&
- MatchHKerningRule(hkern, this->glyphs[i], previous_unicode, previous_glyph_name)) {
- x -= (hkern->k / 1000.0);//TODO: use here the height of the font
+ MatchHKerningRule(hkern, this->glyphs[i], previous_unicode, previous_glyph_name) ){
+ x -= (hkern->k / font_height);
}
SPVkern *vkern = dynamic_cast<SPVkern *>(&node);
if (vkern && !is_horizontal_text &&
- MatchVKerningRule(vkern, this->glyphs[i], previous_unicode, previous_glyph_name)) {
- y -= (vkern->k / 1000.0);//TODO: use here the "height" of the font
+ MatchVKerningRule(vkern, this->glyphs[i], previous_unicode, previous_glyph_name) ){
+ y -= (vkern->k / font_height);
}
}
previous_unicode = const_cast<char*>(this->glyphs[i]->unicode.c_str());//used for kerning checking
@@ -226,8 +227,15 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/,
(*glyphs)[count++].y = y;
//advance glyph coordinates:
- if (is_horizontal_text) x+=(this->font->horiz_adv_x/1000.0);//TODO: use here the height of the font
- else y+=(this->font->vert_adv_y/1000.0);//TODO: use here the "height" of the font
+ if (is_horizontal_text) {
+ if (this->glyphs[i]->horiz_adv_x != 0) {
+ x+=(this->glyphs[i]->horiz_adv_x/font_height);
+ } else {
+ x+=(this->font->horiz_adv_x/font_height);
+ }
+ } else {
+ y+=(this->font->vert_adv_y/font_height);
+ }
_utf8+=len; //advance 'len' bytes in our string pointer
//continue;
goto raptorz;
@@ -240,8 +248,8 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/,
(*glyphs)[count++].y = y;
//advance glyph coordinates:
- if (is_horizontal_text) x+=(this->font->horiz_adv_x/1000.0);//TODO: use here the height of the font
- else y+=(this->font->vert_adv_y/1000.0);//TODO: use here the "height" of the font
+ if (is_horizontal_text) x+=(this->font->horiz_adv_x/font_height);//TODO: use here the height of the font
+ else y+=(this->font->vert_adv_y/font_height);//TODO: use here the "height" of the font
_utf8 = g_utf8_next_char(_utf8); //advance 1 char in our string pointer
}
@@ -257,9 +265,7 @@ SvgFont::render_glyph_path(cairo_t* cr, Geom::PathVector* pathv){
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::Scale s(1.0/units_per_em());
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);
@@ -275,7 +281,7 @@ SvgFont::glyph_modified(SPObject* /* blah */, unsigned int /* bleh */){
Geom::PathVector
SvgFont::flip_coordinate_system(SPFont* spfont, Geom::PathVector pathv){
- double units_per_em = 1000;
+ double units_per_em = 1024;
for(auto& obj: spfont->children) {
if (dynamic_cast<SPFontFace *>(&obj)) {
//XML Tree being directly used here while it shouldn't be.
@@ -400,6 +406,20 @@ void SvgFont::refresh(){
this->userfont = NULL;
}
+double SvgFont::units_per_em() {
+ double units_per_em = 1024;
+ for (auto& obj: font->children) {
+ if (dynamic_cast<SPFontFace *>(&obj)) {
+ //XML Tree being directly used here while it shouldn't be.
+ sp_repr_get_double(obj.getRepr(), "units-per-em", &units_per_em);
+ }
+ }
+ if (units_per_em <= 0.0) {
+ units_per_em = 1024;
+ }
+ return units_per_em;
+}
+
/*
Local Variables:
mode:c++