diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2015-11-18 14:53:56 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2015-11-18 14:53:56 +0000 |
| commit | bfc8e4559285237d13c45e37240a9561c8af5264 (patch) | |
| tree | f3caa7ee661894070b8414f6b7a6d885e513483a /src/libnrtype | |
| parent | Turn FontMetrics into a class. Add maximum ascent/descent variables. (diff) | |
| download | inkscape-bfc8e4559285237d13c45e37240a9561c8af5264.tar.gz inkscape-bfc8e4559285237d13c45e37240a9561c8af5264.zip | |
Code cleanup. Remove/simplify some functions.
(bzr r14430.1.9)
Diffstat (limited to 'src/libnrtype')
| -rw-r--r-- | src/libnrtype/Layout-TNG-Compute.cpp | 70 | ||||
| -rw-r--r-- | src/libnrtype/Layout-TNG-Input.cpp | 46 | ||||
| -rw-r--r-- | src/libnrtype/Layout-TNG.h | 3 |
3 files changed, 29 insertions, 90 deletions
diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp index 2081b5a6d..05cc638f7 100644 --- a/src/libnrtype/Layout-TNG-Compute.cpp +++ b/src/libnrtype/Layout-TNG-Compute.cpp @@ -194,9 +194,8 @@ class Layout::Calculator void _buildPangoItemizationForPara(ParagraphInfo *para) const; - static void _computeFontLineHeight(font_instance *font, double font_size, - SPStyle const *style, FontMetrics *line_height, - double *line_height_multiplier); + // Returns line_height_multiplier + static double _computeFontLineHeight( SPStyle const *style ); unsigned _buildSpansForPara(ParagraphInfo *para) const; @@ -1106,46 +1105,32 @@ void Layout::Calculator::_buildPangoItemizationForPara(ParagraphInfo *para) con } /** - * Gets the ascent and descent for a font given the 'font-size' propert and finds the value of - * line_height_multiplier given the 'line-height' property. The result of multiplying - * \a l by \a line_height_multiplier is the inline box height as specified in css2 + * Finds the value of line_height_multiplier given the 'line-height' property. The result of + * multiplying \a l by \a line_height_multiplier is the inline box height as specified in css2 * section 10.8. http://www.w3.org/TR/CSS2/visudet.html#line-height + * + * The 'computed' value of 'line-height' does not have a consistent meaning. We need to find the + * 'used' value and divide that by the font size. */ -// THIS FUNCTION SHOULD NOT BE NECESSARY -void Layout::Calculator::_computeFontLineHeight(font_instance *font, double font_size, - SPStyle const *style, FontMetrics *font_metrics, - double *line_height_multiplier) +double Layout::Calculator::_computeFontLineHeight( SPStyle const *style ) { - if (font == NULL) { - font_metrics->setZero(); - *line_height_multiplier = 1.0; - } - else { - font->FontMetrics(font_metrics->ascent, font_metrics->descent, font_metrics->xheight); - } - *font_metrics *= font_size; - // yet another borked SPStyle member that we're going to have to fix ourselves - // To do: check if it really is still borked. + // We shouldn't need to climb the element tree... for ( ; ; ) { if (style->line_height.set && !style->line_height.inherit) { if (style->line_height.normal) break; switch (style->line_height.unit) { case SP_CSS_UNIT_NONE: - *line_height_multiplier = style->line_height.computed; - return; + return style->line_height.computed; case SP_CSS_UNIT_EX: - *line_height_multiplier = style->line_height.value * 0.5; + return style->line_height.value * 0.5; // 0.5 is an approximation of the x-height. Fixme. - return; case SP_CSS_UNIT_EM: case SP_CSS_UNIT_PERCENT: - *line_height_multiplier = style->line_height.value; - return; + return style->line_height.value; default: // absolute values - *line_height_multiplier = style->line_height.computed / font_metrics->emSize(); - return; + return style->line_height.computed / style->font_size.computed; } break; } @@ -1153,7 +1138,7 @@ void Layout::Calculator::_computeFontLineHeight(font_instance *font, double font style = style->object->parent->style; if (style == NULL) break; } - *line_height_multiplier = LINE_HEIGHT_NORMAL; + return (LINE_HEIGHT_NORMAL); } bool compareGlyphWidth(const PangoGlyphInfo &a, const PangoGlyphInfo &b) @@ -1270,7 +1255,7 @@ unsigned Layout::Calculator::_buildSpansForPara(ParagraphInfo *para) const } // now we know the length, do some final calculations and add the UnbrokenSpan to the list - new_span.font_size = text_source->styleComputeFontSize() * _flow.getTextLengthMultiplierDue(); + new_span.font_size = text_source->style->font_size.computed * _flow.getTextLengthMultiplierDue(); if (new_span.text_bytes) { new_span.glyph_string = pango_glyph_string_new(); /* Some assertions intended to help diagnose bug #1277746. */ @@ -1366,7 +1351,9 @@ unsigned Layout::Calculator::_buildSpansForPara(ParagraphInfo *para) const /* glyphs[].x_offset values may be out of order within any log_clusters, apparently harmless */ } new_span.pango_item_index = pango_item_index; - _computeFontLineHeight(para->pango_items[pango_item_index].font, new_span.font_size, text_source->style, &new_span.line_height, &new_span.line_height_multiplier); + new_span.line_height_multiplier = _computeFontLineHeight( text_source->style ); + new_span.line_height.set( para->pango_items[pango_item_index].font ); + new_span.line_height *= new_span.font_size; // At some point we may want to calculate baseline_shift here (to take advantage // of otm features like superscript baseline), but for now we use style baseline_shift. @@ -1381,11 +1368,13 @@ unsigned Layout::Calculator::_buildSpansForPara(ParagraphInfo *para) const new_span.pango_item_index = -1; font_instance *font = text_source->styleGetFontInstance(); if (font) { - _computeFontLineHeight(font, new_span.font_size, text_source->style, &new_span.line_height, &new_span.line_height_multiplier); + new_span.line_height_multiplier = _computeFontLineHeight( text_source->style ); + new_span.line_height.set( font ); + new_span.line_height *= new_span.font_size; font->Unref(); } else { - new_span.line_height.setZero(); - new_span.line_height_multiplier = 1.0; + new_span.line_height *= 0.0; // Set all to zero + new_span.line_height_multiplier = LINE_HEIGHT_NORMAL; } TRACE(("add style init span %lu\n", para->unbroken_spans.size())); } @@ -1451,9 +1440,9 @@ bool Layout::Calculator::_findChunksForLine(ParagraphInfo const ¶, InputStreamTextSource const *text_source = static_cast<InputStreamTextSource const *>(_flow._input_stream.front()); font_instance *font = text_source->styleGetFontInstance(); if (font) { - double font_size = text_source->styleComputeFontSize(); - double multiplier; - _computeFontLineHeight(font, font_size, text_source->style, line_height, &multiplier); + double multiplier = _computeFontLineHeight(text_source->style); + line_height->set( font ); + *line_height *= text_source->style->font_size.computed; font->Unref(); *line_height *= multiplier; _scanline_maker->setNewYCoordinate(_scanline_maker->yCoordinate() - line_height->ascent); @@ -1814,7 +1803,7 @@ void Layout::_calculateCursorShapeForEmpty() InputStreamTextSource const *text_source = static_cast<InputStreamTextSource const *>(_input_stream.front()); font_instance *font = text_source->styleGetFontInstance(); - double font_size = text_source->styleComputeFontSize(); + double font_size = text_source->style->font_size.computed; double caret_slope_run = 0.0, caret_slope_rise = 1.0; FontMetrics line_height; if (font) { @@ -1822,11 +1811,8 @@ void Layout::_calculateCursorShapeForEmpty() font->FontMetrics(line_height.ascent, line_height.descent, line_height.xheight); line_height *= font_size; font->Unref(); - } else { - line_height.ascent = font_size * 0.85; // random guesses - line_height.descent = font_size * 0.15; - line_height.xheight = 0.0; } + double caret_slope = atan2(caret_slope_run, caret_slope_rise); _empty_cursor_shape.height = font_size / cos(caret_slope); _empty_cursor_shape.rotation = caret_slope; diff --git a/src/libnrtype/Layout-TNG-Input.cpp b/src/libnrtype/Layout-TNG-Input.cpp index d99433adf..b66bbb5cd 100644 --- a/src/libnrtype/Layout-TNG-Input.cpp +++ b/src/libnrtype/Layout-TNG-Input.cpp @@ -126,52 +126,6 @@ int Layout::_enum_converter(int input, EnumConversionItem const *conversion_tabl return conversion_table[0].output; } -// ***** the style format interface -// this doesn't include all accesses to SPStyle, only the ones that are non-trivial - -static const float medium_font_size = 12.0; // more of a default if all else fails than anything else -float Layout::InputStreamTextSource::styleComputeFontSize() const -{ - return style->font_size.computed; - - // in case the computed value's not good enough, here's some manual code held in reserve: - SPStyle const *this_style = style; - float inherit_multiplier = 1.0; - - for ( ; ; ) { - if (this_style->font_size.set && !this_style->font_size.inherit) { - switch (this_style->font_size.type) { - case SP_FONT_SIZE_LITERAL: { - switch(this_style->font_size.literal) { // these multipliers are straight out of the CSS spec - case SP_CSS_FONT_SIZE_XX_SMALL: return medium_font_size * inherit_multiplier * (3.0/5.0); - case SP_CSS_FONT_SIZE_X_SMALL: return medium_font_size * inherit_multiplier * (3.0/4.0); - case SP_CSS_FONT_SIZE_SMALL: return medium_font_size * inherit_multiplier * (8.0/9.0); - default: - case SP_CSS_FONT_SIZE_MEDIUM: return medium_font_size * inherit_multiplier; - case SP_CSS_FONT_SIZE_LARGE: return medium_font_size * inherit_multiplier * (6.0/5.0); - case SP_CSS_FONT_SIZE_X_LARGE: return medium_font_size * inherit_multiplier * (3.0/2.0); - case SP_CSS_FONT_SIZE_XX_LARGE: return medium_font_size * inherit_multiplier * 2.0; - case SP_CSS_FONT_SIZE_SMALLER: inherit_multiplier *= 0.84; break; //not exactly according to spec - case SP_CSS_FONT_SIZE_LARGER: inherit_multiplier *= 1.26; break; //not exactly according to spec - } - break; - } - case SP_FONT_SIZE_PERCENTAGE: { // 'em' units should be in here, but aren't. Fix in style.cpp. - inherit_multiplier *= this_style->font_size.value; - break; - } - case SP_FONT_SIZE_LENGTH: { - return this_style->font_size.value * inherit_multiplier; - } - } - } - if (this_style->object == NULL || this_style->object->parent == NULL) break; - this_style = this_style->object->parent->style; - if (this_style == NULL) break; - } - return medium_font_size * inherit_multiplier; -} - Layout::Direction Layout::InputStreamTextSource::styleGetBlockProgression() const { switch( style->writing_mode.computed ) { diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h index ccf4bbe43..c923cc0dc 100644 --- a/src/libnrtype/Layout-TNG.h +++ b/src/libnrtype/Layout-TNG.h @@ -635,7 +635,7 @@ public: descent_max = 0.2; } - inline void set( font_instance *font ); + void set( font_instance *font ); // CSS 2.1 dictates that font-size is based on em-size which is defined as ascent + descent inline double emSize() const {return ascent + descent;} @@ -718,7 +718,6 @@ private: LengthAdjust lengthAdjust; // a few functions for some of the more complicated style accesses - float styleComputeFontSize() const; /// The return value must be freed with pango_font_description_free() PangoFontDescription *styleGetFontDescription() const; font_instance *styleGetFontInstance() const; |
