diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2016-07-10 14:51:02 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2016-07-10 14:51:02 +0000 |
| commit | dca182031f3a9c95ae6a1f06c139a89c298846a1 (patch) | |
| tree | 2c356950ae2658ca10d01234c5774a5abe2dba01 /src/display/nr-svgfonts.cpp | |
| parent | Dutch translation update (diff) | |
| download | inkscape-dca182031f3a9c95ae6a1f06c139a89c298846a1.tar.gz inkscape-dca182031f3a9c95ae6a1f06c139a89c298846a1.zip | |
Improve font editing dialog:
1. Allow for fonts with other than 1000 units per em.
2. Allow setting 'ascent', 'descent', etc.
3. Allow setting individual glyph horizontal advances.
4. Fix bug where 'units-per-em' was not read correctly.
(bzr r15014.1.1)
Diffstat (limited to 'src/display/nr-svgfonts.cpp')
| -rw-r--r-- | src/display/nr-svgfonts.cpp | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp index 011f51977..3f8113de8 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++){ @@ -207,11 +208,11 @@ 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 + 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 + y -= (vkern->k / font_height); } } previous_unicode = const_cast<char*>(this->glyphs[i]->unicode.c_str());//used for kerning checking @@ -221,8 +222,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; @@ -235,8 +243,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 } @@ -252,9 +260,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); @@ -270,11 +276,11 @@ 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 (SPObject *obj = spfont->children; obj; obj = obj->next){ 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); + sp_repr_get_double(obj->getRepr(), "units-per-em", &units_per_em); } } @@ -395,6 +401,20 @@ void SvgFont::refresh(){ this->userfont = NULL; } +double SvgFont::units_per_em() { + double units_per_em = 1024; + for (SPObject *obj = font->children; obj; obj = obj->next){ + 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++ |
