Skip to content

Commit

Permalink
Let people enable font features through fontconfig snippets
Browse files Browse the repository at this point in the history
Like this:

<match target="font">
  <edit name="pangofontfeatures" mode="append">
    <string>smcp</string>
    <string>ss20</string>
  </edit>
</match>

Finally we are starting to see new features coming out of the HarfBuzz integration...
  • Loading branch information
behdad committed Jan 10, 2013
1 parent 0df2e95 commit db410d8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/pango-sections.txt
Expand Up @@ -915,6 +915,7 @@ pango_fc_font_map_find_decoder
pango_fc_font_map_cache_clear
pango_fc_font_map_shutdown
pango_fc_font_description_from_pattern
PANGO_FC_FONT_FEATURES
PANGO_FC_GRAVITY
PANGO_FC_VERSION
PANGO_FC_PRGNAME
Expand Down
24 changes: 23 additions & 1 deletion modules/basic/basic-fc.c
Expand Up @@ -29,6 +29,7 @@

#include "pango-engine.h"
#include "pango-utils.h"
#include "pangofc-fontmap.h"
#include "pangofc-font.h"
#include <hb-ft.h>
#include <hb-glib.h>
Expand Down Expand Up @@ -318,6 +319,8 @@ basic_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED,
int last_cluster;
guint i, num_glyphs;
unsigned int item_offset = item_text - paragraph_text;
hb_feature_t features[8];
unsigned int num_features = 0;

g_return_if_fail (font != NULL);
g_return_if_fail (analysis != NULL);
Expand Down Expand Up @@ -367,7 +370,26 @@ basic_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED,
(item_offset + item_length == paragraph_length ? HB_BUFFER_FLAG_EOT : 0));

hb_buffer_add_utf8 (hb_buffer, paragraph_text, paragraph_length, item_offset, item_length);
hb_shape (hb_font, hb_buffer, NULL, 0);

/* Setup features from fontconfig pattern. */
if (fc_font->font_pattern)
{
char *s;
while (num_features < G_N_ELEMENTS (features) &&
FcResultMatch == FcPatternGetString (fc_font->font_pattern,
PANGO_FC_FONT_FEATURES,
num_features,
(FcChar8 **) &s))
{
features[num_features].tag = hb_tag_from_string (s, -1);
features[num_features].value = 1;
features[num_features].start = 0;
features[num_features].end = (unsigned int) -1;
num_features++;
}
}

hb_shape (hb_font, hb_buffer, features, num_features);

if (PANGO_GRAVITY_IS_IMPROPER (analysis->gravity))
hb_buffer_reverse (hb_buffer);
Expand Down
14 changes: 14 additions & 0 deletions pango/pangofc-fontmap.h
Expand Up @@ -266,6 +266,20 @@ PangoFontDescription *pango_fc_font_description_from_pattern (FcPattern *pattern
*/
#define PANGO_FC_PRGNAME "pangoprgname"

/**
* PANGO_FC_FONT_FEATURES:
*
* String representing a fontconfig property name that Pango reads from font
* patterns to populate list of OpenType features to be enabled for the font
* by default.
*
* The property will have a number of string elements, each of which is the
* OpenType feature tag of one feature to enable.
*
* Since: 1.34
*/
#define PANGO_FC_FONT_FEATURES "pangofontfeatures"

G_END_DECLS

#endif /* __PANGO_FC_FONT_MAP_H__ */

0 comments on commit db410d8

Please sign in to comment.