diff options
| author | Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org> | 2017-06-10 04:20:07 +0000 |
|---|---|---|
| committer | Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org> | 2017-06-10 04:20:07 +0000 |
| commit | 8268b0b9173f87ac10995139b28b68908392abb6 (patch) | |
| tree | be4aec76332cb903dac2405370454433a54f3400 /src | |
| parent | Merge branch 'disable_libnrtype_debugging_code' into 'master' (diff) | |
| download | inkscape-8268b0b9173f87ac10995139b28b68908392abb6.tar.gz inkscape-8268b0b9173f87ac10995139b28b68908392abb6.zip | |
libnrtype/Layout-TNG refactoring for better code legibility
Diffstat (limited to 'src')
| -rw-r--r-- | src/libnrtype/Layout-TNG-Input.cpp | 113 | ||||
| -rw-r--r-- | src/libnrtype/Layout-TNG-Output.cpp | 12 | ||||
| -rw-r--r-- | src/libnrtype/Layout-TNG.h | 4 | ||||
| -rw-r--r-- | src/sp-flowtext.cpp | 4 | ||||
| -rw-r--r-- | src/sp-text.cpp | 8 |
5 files changed, 101 insertions, 40 deletions
diff --git a/src/libnrtype/Layout-TNG-Input.cpp b/src/libnrtype/Layout-TNG-Input.cpp index 6f5d4e5f8..98ce7d526 100644 --- a/src/libnrtype/Layout-TNG-Input.cpp +++ b/src/libnrtype/Layout-TNG-Input.cpp @@ -40,7 +40,13 @@ void Layout::_clearInputObjects() } // this function does nothing more than store all its parameters for future reference -void Layout::appendText(Glib::ustring const &text, SPStyle *style, void *source_cookie, OptionalTextTagAttrs const *optional_attributes, unsigned optional_attributes_offset, Glib::ustring::const_iterator text_begin, Glib::ustring::const_iterator text_end) +void Layout::appendText(Glib::ustring const &text, + SPStyle *style, + void *source_cookie, + OptionalTextTagAttrs const *optional_attributes, + unsigned optional_attributes_offset, + Glib::ustring::const_iterator text_begin, + Glib::ustring::const_iterator text_end) { if (style == NULL) return; @@ -120,40 +126,40 @@ void Layout::appendWrapShape(Shape const *shape, DisplayAlign display_align) int Layout::_enum_converter(int input, EnumConversionItem const *conversion_table, unsigned conversion_table_size) { - for (unsigned i = 0 ; i < conversion_table_size ; i++) + for (unsigned i = 0 ; i < conversion_table_size ; i++) { if (conversion_table[i].input == input) return conversion_table[i].output; + } return conversion_table[0].output; } Layout::Direction Layout::InputStreamTextSource::styleGetBlockProgression() const { - switch( style->writing_mode.computed ) { + switch( style->writing_mode.computed ) { + case SP_CSS_WRITING_MODE_LR_TB: + case SP_CSS_WRITING_MODE_RL_TB: + return TOP_TO_BOTTOM; - case SP_CSS_WRITING_MODE_LR_TB: - case SP_CSS_WRITING_MODE_RL_TB: - return TOP_TO_BOTTOM; - - case SP_CSS_WRITING_MODE_TB_RL: - return RIGHT_TO_LEFT; + case SP_CSS_WRITING_MODE_TB_RL: + return RIGHT_TO_LEFT; - case SP_CSS_WRITING_MODE_TB_LR: - return LEFT_TO_RIGHT; + case SP_CSS_WRITING_MODE_TB_LR: + return LEFT_TO_RIGHT; - default: - std::cerr << "Layout::InputTextStream::styleGetBlockProgression: invalid writing mode." << std::endl; - } - return TOP_TO_BOTTOM; + default: + std::cerr << "Layout::InputTextStream::styleGetBlockProgression: invalid writing mode." << std::endl; + } + return TOP_TO_BOTTOM; } SPCSSTextOrientation Layout::InputStreamTextSource::styleGetTextOrientation() const { - return ((SPCSSTextOrientation)style->text_orientation.computed); + return ((SPCSSTextOrientation)style->text_orientation.computed); } SPCSSBaseline Layout::InputStreamTextSource::styleGetDominantBaseline() const { - return ((SPCSSBaseline)style->dominant_baseline.computed); + return ((SPCSSBaseline)style->dominant_baseline.computed); } static Layout::Alignment text_anchor_to_alignment(unsigned anchor, Layout::Direction para_direction) @@ -202,22 +208,24 @@ Layout::Alignment Layout::InputStreamTextSource::styleGetAlignment(Layout::Direc static const Layout::EnumConversionItem enum_convert_spstyle_style_to_pango_style[] = { {SP_CSS_FONT_STYLE_NORMAL, PANGO_STYLE_NORMAL}, {SP_CSS_FONT_STYLE_ITALIC, PANGO_STYLE_ITALIC}, - {SP_CSS_FONT_STYLE_OBLIQUE, PANGO_STYLE_OBLIQUE}}; + {SP_CSS_FONT_STYLE_OBLIQUE, PANGO_STYLE_OBLIQUE} +}; static const Layout::EnumConversionItem enum_convert_spstyle_weight_to_pango_weight[] = { // NB: The Pango web page calls 500 "the normal font" but both CSS2 and the Pango // enumeration define 400 as normal. {SP_CSS_FONT_WEIGHT_NORMAL, PANGO_WEIGHT_NORMAL}, - {SP_CSS_FONT_WEIGHT_BOLD,PANGO_WEIGHT_BOLD}, - {SP_CSS_FONT_WEIGHT_100, PANGO_WEIGHT_THIN}, - {SP_CSS_FONT_WEIGHT_200, PANGO_WEIGHT_ULTRALIGHT}, - {SP_CSS_FONT_WEIGHT_300, PANGO_WEIGHT_LIGHT}, - {SP_CSS_FONT_WEIGHT_400, PANGO_WEIGHT_NORMAL}, - {SP_CSS_FONT_WEIGHT_500, PANGO_WEIGHT_MEDIUM}, - {SP_CSS_FONT_WEIGHT_600, PANGO_WEIGHT_SEMIBOLD}, - {SP_CSS_FONT_WEIGHT_700, PANGO_WEIGHT_BOLD}, - {SP_CSS_FONT_WEIGHT_800, PANGO_WEIGHT_ULTRABOLD}, - {SP_CSS_FONT_WEIGHT_900, PANGO_WEIGHT_HEAVY}}; + {SP_CSS_FONT_WEIGHT_BOLD, PANGO_WEIGHT_BOLD}, + {SP_CSS_FONT_WEIGHT_100, PANGO_WEIGHT_THIN}, + {SP_CSS_FONT_WEIGHT_200, PANGO_WEIGHT_ULTRALIGHT}, + {SP_CSS_FONT_WEIGHT_300, PANGO_WEIGHT_LIGHT}, + {SP_CSS_FONT_WEIGHT_400, PANGO_WEIGHT_NORMAL}, + {SP_CSS_FONT_WEIGHT_500, PANGO_WEIGHT_MEDIUM}, + {SP_CSS_FONT_WEIGHT_600, PANGO_WEIGHT_SEMIBOLD}, + {SP_CSS_FONT_WEIGHT_700, PANGO_WEIGHT_BOLD}, + {SP_CSS_FONT_WEIGHT_800, PANGO_WEIGHT_ULTRABOLD}, + {SP_CSS_FONT_WEIGHT_900, PANGO_WEIGHT_HEAVY} +}; static const Layout::EnumConversionItem enum_convert_spstyle_stretch_to_pango_stretch[] = { {SP_CSS_FONT_STRETCH_NORMAL, PANGO_STRETCH_NORMAL}, @@ -228,11 +236,13 @@ static const Layout::EnumConversionItem enum_convert_spstyle_stretch_to_pango_st {SP_CSS_FONT_STRETCH_SEMI_EXPANDED, PANGO_STRETCH_SEMI_EXPANDED}, {SP_CSS_FONT_STRETCH_EXPANDED, PANGO_STRETCH_EXPANDED}, {SP_CSS_FONT_STRETCH_EXTRA_EXPANDED, PANGO_STRETCH_EXTRA_EXPANDED}, - {SP_CSS_FONT_STRETCH_ULTRA_EXPANDED, PANGO_STRETCH_ULTRA_EXPANDED}}; + {SP_CSS_FONT_STRETCH_ULTRA_EXPANDED, PANGO_STRETCH_ULTRA_EXPANDED} +}; static const Layout::EnumConversionItem enum_convert_spstyle_variant_to_pango_variant[] = { {SP_CSS_FONT_VARIANT_NORMAL, PANGO_VARIANT_NORMAL}, - {SP_CSS_FONT_VARIANT_SMALL_CAPS, PANGO_VARIANT_SMALL_CAPS}}; + {SP_CSS_FONT_VARIANT_SMALL_CAPS, PANGO_VARIANT_SMALL_CAPS} +}; font_instance *Layout::InputStreamTextSource::styleGetFontInstance() const { @@ -265,26 +275,57 @@ PangoFontDescription *Layout::InputStreamTextSource::styleGetFontDescription() c } pango_font_description_set_family(descr,family.c_str()); - pango_font_description_set_weight(descr,(PangoWeight)_enum_converter(style->font_weight.computed, enum_convert_spstyle_weight_to_pango_weight, sizeof(enum_convert_spstyle_weight_to_pango_weight)/sizeof(enum_convert_spstyle_weight_to_pango_weight[0]))); - pango_font_description_set_style(descr,(PangoStyle)_enum_converter(style->font_style.computed, enum_convert_spstyle_style_to_pango_style, sizeof(enum_convert_spstyle_style_to_pango_style)/sizeof(enum_convert_spstyle_style_to_pango_style[0]))); - pango_font_description_set_variant(descr,(PangoVariant)_enum_converter(style->font_variant.computed, enum_convert_spstyle_variant_to_pango_variant, sizeof(enum_convert_spstyle_variant_to_pango_variant)/sizeof(enum_convert_spstyle_variant_to_pango_variant[0]))); + pango_font_description_set_weight( + descr, + (PangoWeight)_enum_converter( + style->font_weight.computed, + enum_convert_spstyle_weight_to_pango_weight, + sizeof(enum_convert_spstyle_weight_to_pango_weight) / sizeof(enum_convert_spstyle_weight_to_pango_weight[0]) + ) + ); + pango_font_description_set_style( + descr, + (PangoStyle)_enum_converter( + style->font_style.computed, + enum_convert_spstyle_style_to_pango_style, + sizeof(enum_convert_spstyle_style_to_pango_style) / sizeof(enum_convert_spstyle_style_to_pango_style[0]) + ) + ); + pango_font_description_set_variant( + descr, + (PangoVariant)_enum_converter( + style->font_variant.computed, + enum_convert_spstyle_variant_to_pango_variant, + sizeof(enum_convert_spstyle_variant_to_pango_variant) / sizeof(enum_convert_spstyle_variant_to_pango_variant[0]) + ) + ); #ifdef USE_PANGO_WIN32 // damn Pango fudges the size, so we need to unfudge. See source of pango_win32_font_map_init() - pango_font_description_set_size(descr, (int) ((font_factory::Default())->fontSize*PANGO_SCALE*72/GetDeviceCaps(pango_win32_get_dc(),LOGPIXELSY))); // mandatory huge size (hinting workaround) + pango_font_description_set_size( + descr, + (int) ((font_factory::Default())->fontSize*PANGO_SCALE*72 / GetDeviceCaps(pango_win32_get_dc(),LOGPIXELSY)) // mandatory huge size (hinting workaround) + ); // we don't set stretch on Win32, because pango-win32 has no concept of it // (Windows doesn't really provide any useful field it could use). // If we did set stretch, then any text with a font-stretch attribute would // end up falling back to Arial. #else pango_font_description_set_size(descr, (int) ((font_factory::Default())->fontSize*PANGO_SCALE)); // mandatory huge size (hinting workaround) - pango_font_description_set_stretch(descr,(PangoStretch)_enum_converter(style->font_stretch.computed, enum_convert_spstyle_stretch_to_pango_stretch, sizeof(enum_convert_spstyle_stretch_to_pango_stretch)/sizeof(enum_convert_spstyle_stretch_to_pango_stretch[0]))); + pango_font_description_set_stretch( + descr, + (PangoStretch)_enum_converter( + style->font_stretch.computed, + enum_convert_spstyle_stretch_to_pango_stretch, + sizeof(enum_convert_spstyle_stretch_to_pango_stretch) / sizeof(enum_convert_spstyle_stretch_to_pango_stretch[0]) + ) + ); #endif return descr; } Layout::InputStreamTextSource::~InputStreamTextSource() { - sp_style_unref(style); + sp_style_unref(style); } }//namespace Text diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp index a1a19f2b3..7f20dee95 100644 --- a/src/libnrtype/Layout-TNG-Output.cpp +++ b/src/libnrtype/Layout-TNG-Output.cpp @@ -515,6 +515,7 @@ void Layout::showGlyphs(CairoRenderContext *ctx) const } #endif +#if DEBUG_TEXTLAYOUT_DUMPASTEXT // these functions are for dumpAsText() only. No need to translate static char const *direction_to_text(Layout::Direction d) { @@ -557,6 +558,7 @@ static char const *weight_to_text(PangoWeight w) } return "???"; } +#endif //DEBUG_TEXTLAYOUT_DUMPASTEXT Glib::ustring Layout::getFontFamily(unsigned span_index) const { @@ -570,6 +572,7 @@ Glib::ustring Layout::getFontFamily(unsigned span_index) const return ""; } +#if DEBUG_TEXTLAYOUT_DUMPASTEXT Glib::ustring Layout::dumpAsText() const { Glib::ustring result; @@ -609,7 +612,13 @@ Glib::ustring Layout::dumpAsText() const _lines[_chunks[_spans[span_index].in_chunk].in_line].in_shape) + Glib::ustring::compose(" in chunk %1 (x=%2, baselineshift=%3)\n", _spans[span_index].in_chunk, _chunks[_spans[span_index].in_chunk].left_x, _spans[span_index].baseline_shift); if (_spans[span_index].font) { - result += Glib::ustring::compose(" font '%1' %2 %3 %4\n", sp_font_description_get_family(_spans[span_index].font->descr), _spans[span_index].font_size, style_to_text(pango_font_description_get_style(_spans[span_index].font->descr)), weight_to_text(pango_font_description_get_weight(_spans[span_index].font->descr))); + result += Glib::ustring::compose( + " font '%1' %2 %3 %4\n", + sp_font_description_get_family(_spans[span_index].font->descr), + _spans[span_index].font_size, + style_to_text( pango_font_description_get_style(_spans[span_index].font->descr) ), + weight_to_text( pango_font_description_get_weight(_spans[span_index].font->descr) ) + ); } result += Glib::ustring::compose(" x_start = %1, x_end = %2\n", _spans[span_index].x_start, _spans[span_index].x_end) + Glib::ustring::compose(" line height: ascent %1, descent %2\n", _spans[span_index].line_height.ascent, _spans[span_index].line_height.descent) @@ -640,6 +649,7 @@ Glib::ustring Layout::dumpAsText() const result += "EOT\n"; return result; } +#endif //DEBUG_TEXTLAYOUT_DUMPASTEXT void Layout::fitToPathAlign(SVGLength const &startOffset, Path const &path) { diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h index c39315106..878c76af8 100644 --- a/src/libnrtype/Layout-TNG.h +++ b/src/libnrtype/Layout-TNG.h @@ -11,6 +11,8 @@ #ifndef __LAYOUT_TNG_H__ #define __LAYOUT_TNG_H__ +//#define DEBUG_TEXTLAYOUT_DUMPASTEXT + #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -402,10 +404,12 @@ public: /** Returns the font family of the indexed span */ Glib::ustring getFontFamily(unsigned span_index) const; +#if DEBUG_TEXTLAYOUT_DUMPASTEXT /** debug and unit test method. Creates a textual representation of the contents of this object. The output is designed to be both human-readable and comprehensible when diffed with a known-good dump. */ Glib::ustring dumpAsText() const; +#endif /** Moves all the glyphs in the structure so that the baseline of all the characters sits neatly along the path specified. If the text has diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index d79652bf4..741ca7886 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -463,7 +463,9 @@ void SPFlowtext::rebuildLayout() _buildLayoutInput(this, exclusion_shape, &shapes, &pending_line_break_object); delete exclusion_shape; layout.calculateFlow(); - //g_print("%s", layout.dumpAsText().c_str()); +#if DEBUG_TEXTLAYOUT_DUMPASTEXT + g_print("%s", layout.dumpAsText().c_str()); +#endif } void SPFlowtext::_clearFlow(Inkscape::DrawingGroup *in_arena) diff --git a/src/sp-text.cpp b/src/sp-text.cpp index b066ca3de..2a88c5009 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -620,12 +620,16 @@ void SPText::rebuildLayout() if (SP_IS_TEXTPATH(&child)) { SPTextPath const *textpath = SP_TEXTPATH(&child); if (textpath->originalPath != NULL) { - //g_print("%s", layout.dumpAsText().c_str()); +#if DEBUG_TEXTLAYOUT_DUMPASTEXT + g_print("%s", layout.dumpAsText().c_str()); +#endif layout.fitToPathAlign(textpath->startOffset, *textpath->originalPath); } } } - //g_print("%s", layout.dumpAsText().c_str()); +#if DEBUG_TEXTLAYOUT_DUMPASTEXT + g_print("%s", layout.dumpAsText().c_str()); +#endif // set the x,y attributes on role:line spans for (auto& child: children) { |
