Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add text_layout class.
- Loading branch information
Showing
6 changed files
with
93 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,22 @@ | ||
#include "text_itemizer.hpp" | ||
#include "text_layout.hpp" | ||
#include "text_shaping.hpp" | ||
|
||
#define HAVE_FREETYPE | ||
#include <iostream> | ||
#include <string> | ||
#include <list> | ||
|
||
#include <boost/iostreams/device/mapped_file.hpp> | ||
|
||
using namespace std; | ||
namespace mapnik | ||
{ | ||
|
||
|
||
class text_layout | ||
{ | ||
public: | ||
text_layout(double text_ratio, double wrap_width); | ||
inline void add_text(UnicodeString const& str, char_properties const& format) | ||
{ | ||
itemizer.add_text(str, format); | ||
} | ||
|
||
void break_lines(); | ||
|
||
|
||
private: | ||
text_itemizer itemizer; | ||
double text_ratio_; | ||
double wrap_width_; | ||
}; | ||
|
||
text_layout::text_layout(double text_ratio, double wrap_width) : text_ratio_(text_ratio), wrap_width_(wrap_width) | ||
{ | ||
} | ||
|
||
} //ns mapnik | ||
|
||
int main() | ||
{ | ||
mapnik::text_itemizer itemizer; | ||
mapnik::text_layout layout(0.0, 0.0); | ||
mapnik::char_properties dummy; | ||
itemizer.add_text("Hello ", dummy); | ||
itemizer.add_text("World", dummy); | ||
itemizer.add_text("किகே", dummy); | ||
itemizer.add_text("وگرىmixed", dummy); | ||
itemizer.add_text("وگرى", dummy); | ||
std::list<mapnik::text_item> const& list = itemizer.itemize(); | ||
std::list<mapnik::text_item>::const_iterator itr = list.begin(), end = list.end(); | ||
for (;itr!=end; itr++) | ||
{ | ||
std::string s; | ||
itr->str.toUTF8String(s); | ||
std::cout << "Text item: text: " << s << " rtl: " << itr->rtl << "script: " << uscript_getName(itr->script) << "\n"; | ||
} | ||
mapnik::text_shaping unifont; | ||
std::cout << "Hello World!\n"; | ||
unifont.process_text("Hello World!"); | ||
std::cout << "Complex text:\n"; | ||
unifont.process_text("कि கே કિ ฐู"); | ||
layout.add_text("Hello World", dummy); | ||
layout.add_text("किகே", dummy); | ||
layout.add_text("وگرىmixed", dummy); | ||
layout.add_text("وگرى", dummy); | ||
layout.add_text("German umlauts: äöüß", dummy); | ||
layout.add_text("äöüß", dummy); | ||
layout.shape_text(); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "text_layout.hpp" | ||
#include "text_shaping.hpp" | ||
|
||
//stl | ||
#include <iostream> | ||
|
||
// harf-buzz | ||
#include <harfbuzz/hb.h> | ||
|
||
namespace mapnik | ||
{ | ||
text_layout::text_layout(double text_ratio, double wrap_width) : text_ratio_(text_ratio), wrap_width_(wrap_width) | ||
{ | ||
} | ||
|
||
void text_layout::break_lines() | ||
{ | ||
} | ||
|
||
void text_layout::shape_text() | ||
{ | ||
std::list<text_item> const& list = itemizer.itemize(); | ||
std::list<text_item>::const_iterator itr = list.begin(), end = list.end(); | ||
for (;itr!=end; itr++) | ||
{ | ||
std::string s; | ||
text_shaping shaper; | ||
shaper.process_text(itr->str); | ||
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); | ||
std::cout << "Processing item '" << itr->str.toUTF8String(s) << "' (" << uscript_getName(itr->script) << "," << itr->str.length() << "," << num_glyphs << ")\n"; | ||
|
||
for (unsigned i=0; i<num_glyphs; i++) | ||
{ | ||
std::cout << "glyph codepoint:" << glyphs[i].codepoint << | ||
" cluster: " << glyphs[i].cluster << | ||
" x_advance: "<< positions[i].x_advance << "\n"; | ||
} | ||
} | ||
} | ||
|
||
} //ns mapnik |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef MAPNIK_TEXT_LAYOUT_HPP | ||
#define MAPNIK_TEXT_LAYOUT_HPP | ||
|
||
#include "text_itemizer.hpp" | ||
|
||
namespace mapnik | ||
{ | ||
class text_layout | ||
{ | ||
public: | ||
text_layout(double text_ratio, double wrap_width); | ||
inline void add_text(UnicodeString const& str, char_properties const& format) | ||
{ | ||
itemizer.add_text(str, format); | ||
} | ||
|
||
void break_lines(); | ||
void shape_text(); | ||
|
||
|
||
private: | ||
text_itemizer itemizer; | ||
double text_ratio_; | ||
double wrap_width_; | ||
}; | ||
} | ||
|
||
#endif // TEXT_LAYOUT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters