From 0c4d1236028ec93c65ee1ecf663d1ee75811398d Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Sun, 24 Mar 2013 12:01:51 +0100 Subject: [PATCH] Fix char spacing for scale_factor != 1. --- include/mapnik/text/layout.hpp | 2 +- src/text/layout.cpp | 9 +++++---- src/text/layout_shape_dummy.cpp | 2 +- src/text/layout_shape_hb.cpp | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/mapnik/text/layout.hpp b/include/mapnik/text/layout.hpp index 7f8d35fbc..69a4772e6 100644 --- a/include/mapnik/text/layout.hpp +++ b/include/mapnik/text/layout.hpp @@ -51,7 +51,7 @@ public: typedef std::vector glyph_vector; typedef glyph_vector::const_iterator const_iterator; glyph_vector const& get_glyphs() const { return glyphs_; } - void add_glyph(glyph_info const& glyph); + void add_glyph(glyph_info const& glyph, double scale_factor_); void reserve(glyph_vector::size_type length); const_iterator begin() const; diff --git a/src/text/layout.cpp b/src/text/layout.cpp index e1b4d7cd0..a0a568d57 100644 --- a/src/text/layout.cpp +++ b/src/text/layout.cpp @@ -89,7 +89,7 @@ void text_layout::break_line(text_line_ptr line, double wrap_width, unsigned tex unsigned last_break_position = 0; for (unsigned i=line->get_first_char(); iget_last_char(); i++) { - //TODO: Char spacing + //TODO: character_spacing std::map::const_iterator width_itr = width_map_.find(i); if (width_itr != width_map_.end()) { @@ -192,14 +192,15 @@ text_line::text_line(unsigned first_char, unsigned last_char) { } -void text_line::add_glyph(const glyph_info &glyph) +void text_line::add_glyph(const glyph_info &glyph, double scale_factor_) { line_height_ = std::max(line_height_, glyph.line_height + glyph.format->line_spacing); if (glyphs_.empty()) { width_ = glyph.width; - } else { - width_ += glyph.width + glyphs_.back().format->character_spacing; + } else if (glyph.width) { + //Only add character spacing if the character is not a zero-width part of a cluster. + width_ += glyph.width + glyphs_.back().format->character_spacing * scale_factor_; } glyphs_.push_back(glyph); } diff --git a/src/text/layout_shape_dummy.cpp b/src/text/layout_shape_dummy.cpp index 54a715ecc..afbc0902f 100644 --- a/src/text/layout_shape_dummy.cpp +++ b/src/text/layout_shape_dummy.cpp @@ -59,7 +59,7 @@ void text_layout::shape_text(text_line_ptr line) width_map_[i] += tmp.width; - line->add_glyph(tmp); + line->add_glyph(tmp, scale_factor_); } line->update_max_char_height(face->get_char_height()); } diff --git a/src/text/layout_shape_hb.cpp b/src/text/layout_shape_hb.cpp index 8bce35616..45d5b0d5f 100644 --- a/src/text/layout_shape_hb.cpp +++ b/src/text/layout_shape_hb.cpp @@ -73,7 +73,7 @@ void text_layout::shape_text(text_line_ptr line) width_map_[glyphs[i].cluster] += tmp.width; - line->add_glyph(tmp); + line->add_glyph(tmp, scale_factor_); } line->update_max_char_height(face->get_char_height()); break; //When we reach this point the current font had all glyphs.