From 748cf62de3e0166d8a9962091dc5e5c39c153132 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Sun, 23 Sep 2012 03:19:47 +0200 Subject: [PATCH] Prepare for making HarfBuzz an optional dependency. --- src/build.py | 1 + src/text/layout.cpp | 77 +-------------------------------- src/text/layout_shape_hb.cpp | 83 ++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 75 deletions(-) create mode 100644 src/text/layout_shape_hb.cpp diff --git a/src/build.py b/src/build.py index 26ffc35db..994fc6a14 100644 --- a/src/build.py +++ b/src/build.py @@ -180,6 +180,7 @@ source = Split( text/placements/simple.cpp text/shaping.cpp text/layout.cpp + text/layout_shape_hb.cpp text/itemizer.cpp text/scrptrun.cpp text/face.cpp diff --git a/src/text/layout.cpp b/src/text/layout.cpp index e1879d19e..4f615efad 100644 --- a/src/text/layout.cpp +++ b/src/text/layout.cpp @@ -20,14 +20,8 @@ * *****************************************************************************/ #include -#include #include - -//stl -#include - -// harf-buzz -#include +#include // ICU #include @@ -130,73 +124,6 @@ void text_layout::break_line(text_line_ptr line, double wrap_width, unsigned tex } } -void text_layout::shape_text(text_line_ptr line) -{ - unsigned start = line->get_first_char(); - unsigned end = line->get_last_char(); - UnicodeString const& text = itemizer_.get_text(); - - size_t length = end - start; - - line->reserve(length); //Preallocate memory - - std::list const& list = itemizer_.itemize(start, end); - std::list::const_iterator itr = list.begin(), list_end = list.end(); - for (; itr != list_end; itr++) - { - face_set_ptr face_set = font_manager_.get_face_set(itr->format->face_name, itr->format->fontset); - face_set->set_character_sizes(itr->format->text_size); - font_face_set::iterator face_itr = face_set->begin(), face_end = face_set->end(); - for (; face_itr != face_end; face_itr++) - { - face_ptr face = *face_itr; - text_shaping shaper(face->get_face()); //TODO: Make this more efficient by caching this object in font_face - - shaper.process_text(text, itr->start, itr->end, itr->rtl == UBIDI_RTL, itr->script); - hb_buffer_t *buffer = shaper.get_buffer(); - - unsigned num_glyphs = hb_buffer_get_length(buffer); - - hb_glyph_info_t *glyphs = hb_buffer_get_glyph_infos(buffer, NULL); - hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, NULL); - - bool font_has_all_glyphs = true; - /* Check if all glyphs are valid. */ - for (unsigned i=0; iformat; - face->glyph_dimensions(tmp); - - width_map_[glyphs[i].cluster] += tmp.width; - - line->add_glyph(tmp); - } - line->update_max_char_height(face->get_char_height()); - break; //When we reach this point the current font had all glyphs. - } - } -} - void text_layout::add_line(text_line_ptr line) { if (lines_.empty()) @@ -320,7 +247,7 @@ unsigned text_line::get_last_char() const unsigned text_line::size() const { - glyphs_.size(); + return glyphs_.size(); } } //ns mapnik diff --git a/src/text/layout_shape_hb.cpp b/src/text/layout_shape_hb.cpp new file mode 100644 index 000000000..53099fca6 --- /dev/null +++ b/src/text/layout_shape_hb.cpp @@ -0,0 +1,83 @@ +//mapnik +#include +#include +#include + +//stl +#include + +// harf-buzz +#include + +namespace mapnik +{ + + +void text_layout::shape_text(text_line_ptr line) +{ + unsigned start = line->get_first_char(); + unsigned end = line->get_last_char(); + UnicodeString const& text = itemizer_.get_text(); + + size_t length = end - start; + + line->reserve(length); //Preallocate memory + + std::list const& list = itemizer_.itemize(start, end); + std::list::const_iterator itr = list.begin(), list_end = list.end(); + for (; itr != list_end; itr++) + { + face_set_ptr face_set = font_manager_.get_face_set(itr->format->face_name, itr->format->fontset); + face_set->set_character_sizes(itr->format->text_size); + font_face_set::iterator face_itr = face_set->begin(), face_end = face_set->end(); + for (; face_itr != face_end; face_itr++) + { + face_ptr face = *face_itr; + text_shaping shaper(face->get_face()); //TODO: Make this more efficient by caching this object in font_face + + shaper.process_text(text, itr->start, itr->end, itr->rtl == UBIDI_RTL, itr->script); + hb_buffer_t *buffer = shaper.get_buffer(); + + unsigned num_glyphs = hb_buffer_get_length(buffer); + + hb_glyph_info_t *glyphs = hb_buffer_get_glyph_infos(buffer, NULL); + hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, NULL); + + bool font_has_all_glyphs = true; + /* Check if all glyphs are valid. */ + for (unsigned i=0; iformat; + face->glyph_dimensions(tmp); + + width_map_[glyphs[i].cluster] += tmp.width; + + line->add_glyph(tmp); + } + line->update_max_char_height(face->get_char_height()); + break; //When we reach this point the current font had all glyphs. + } + } +} + +} //ns mapnik