Enable all ligatures available in a font for text2image rendering

This enables all OpenType ligatures for a specific font, where
available. Specifically, it explicitly enables the OpenType
features liga (standard ligatures), hlig (historical ligatures),
clig (contextual ligatures), and dlig (discretionary ligatures).

This feature requires Pango 1.38 or newer.
This commit is contained in:
Nick White 2016-03-21 11:41:36 +00:00 committed by Zdenko Podobný
parent bb00d3b5ae
commit abab5c17fd
2 changed files with 13 additions and 0 deletions

View File

@ -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;
@ -149,6 +150,7 @@ void StringRenderer::set_underline_continuation_prob(const double frac) {
}
StringRenderer::~StringRenderer() {
free(features_);
ClearBoxes();
FreePangoCairo();
}
@ -204,6 +206,12 @@ void StringRenderer::SetLayoutProperties() {
spacing_attr->end_index = static_cast<guint>(-1);
pango_attr_list_change(attr_list, spacing_attr);
}
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);
}
pango_layout_set_attributes(layout_, attr_list);
pango_attr_list_unref(attr_list);
// Adjust line spacing

View File

@ -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;
}
@ -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_;