Skip to content

Commit

Permalink
Merge pull request #288 from nickjwhite/opentypeligatures
Browse files Browse the repository at this point in the history
Enable all ligatures available in a font for text2image rendering
  • Loading branch information
amitdo committed Jun 19, 2016
2 parents ad66dd2 + 76ed9de commit 13d789d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions training/stringrenderer.cpp
Expand Up @@ -120,6 +120,7 @@ StringRenderer::StringRenderer(const string& font_desc, int page_width,
box_padding_(0),
total_chars_(0),
font_index_(0),
features_(NULL),
last_offset_(0) {
pen_color_[0] = 0.0;
pen_color_[1] = 0.0;
Expand Down Expand Up @@ -149,6 +150,7 @@ void StringRenderer::set_underline_continuation_prob(const double frac) {
}

StringRenderer::~StringRenderer() {
free(features_);
ClearBoxes();
FreePangoCairo();
}
Expand Down Expand Up @@ -204,6 +206,14 @@ void StringRenderer::SetLayoutProperties() {
spacing_attr->end_index = static_cast<guint>(-1);
pango_attr_list_change(attr_list, spacing_attr);
}
#if (PANGO_VERSION_MAJOR == 1 && PANGO_VERSION_MINOR >= 38)
if (add_ligatures_) {
set_features("liga, clig, dlig, hlig");
PangoAttribute* feature_attr =
pango_attr_font_features_new(features_);
pango_attr_list_change(attr_list, feature_attr);
}
#endif
pango_layout_set_attributes(layout_, attr_list);
pango_attr_list_unref(attr_list);
// Adjust line spacing
Expand Down
5 changes: 5 additions & 0 deletions training/stringrenderer.h
Expand Up @@ -90,6 +90,10 @@ class StringRenderer {
void set_underline_style(const PangoUnderline style) {
underline_style_ = style;
}
void set_features(char *features) {
free(features_);
features_ = strdup(features);
}
void set_page(int page) {
page_ = page;
}
Expand Down Expand Up @@ -185,6 +189,7 @@ class StringRenderer {
double underline_start_prob_;
double underline_continuation_prob_;
PangoUnderline underline_style_;
char *features_;
// Text filtering options
bool drop_uncovered_chars_;
bool strip_unrenderable_words_;
Expand Down

0 comments on commit 13d789d

Please sign in to comment.