summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-07-12 03:35:16 +0000
committerMatthias Clasen <mclasen@redhat.com>2019-07-12 03:35:16 +0000
commit00233bd8b863a87cbf59344b1aed1feba04c66ca (patch)
tree4f388b57fbd10a79785bf3d829419492d51fd77b
parent5590411f895d9e9bc9edd983c9c8df845ec13018 (diff)
parentec4864eef5f5c067093ac46dd66cc948de3467dc (diff)
downloadpango-00233bd8b863a87cbf59344b1aed1feba04c66ca.tar.gz
Merge branch 'font-features-getter' into 'master'
Font features getter See merge request GNOME/pango!82
-rw-r--r--docs/pango-sections.txt1
-rw-r--r--pango/fonts.c24
-rw-r--r--pango/pango-font-private.h6
-rw-r--r--pango/pango-font.h6
-rw-r--r--pango/pangofc-font.c31
-rw-r--r--pango/pangofc-shape.c101
6 files changed, 111 insertions, 58 deletions
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 0fc648af..9b077f56 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -236,6 +236,7 @@ pango_font_covers
pango_font_get_glyph_extents
pango_font_get_metrics
pango_font_get_font_map
+pango_font_get_features
<SUBSECTION>
PangoFontFamily
PANGO_TYPE_FONT_FAMILY
diff --git a/pango/fonts.c b/pango/fonts.c
index 2dd39f2e..081596df 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -2327,3 +2327,27 @@ pango_font_covers (PangoFont *font,
pango_coverage_unref (coverage);
return result != PANGO_COVERAGE_NONE;
}
+
+/**
+ * pango_font_get_features:
+ * @font: a #PangoFont
+ * @features: (out caller-allocates) (array length=len): Array to features in
+ * @len: the length of @features
+ * @num_features: (inout): the number of used items in @features
+ *
+ * Obtain the OpenType features for this font.
+ *
+ * These are the features used by default for this font,
+ * unless overridden.
+ *
+ * Since: 1.44
+ */
+void
+pango_font_get_features (PangoFont *font,
+ hb_feature_t *features,
+ guint len,
+ guint *num_features)
+{
+ if (PANGO_FONT_GET_CLASS (font)->get_features)
+ PANGO_FONT_GET_CLASS (font)->get_features (font, features, len, num_features);
+}
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index 5d7bb4de..be399d7d 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -175,11 +175,15 @@ struct _PangoFontClass
PangoLanguage *language);
PangoFontMap * (*get_font_map) (PangoFont *font);
PangoFontDescription *(*describe_absolute) (PangoFont *font);
+ void (*get_features) (PangoFont *font,
+ hb_feature_t *features,
+ guint len,
+ guint *num_features);
+
/*< private >*/
/* Padding for future expansion */
void (*_pango_reserved1) (void);
- void (*_pango_reserved2) (void);
};
/* used for very rare and miserable situtations that we cannot even
diff --git a/pango/pango-font.h b/pango/pango-font.h
index 84d4e122..e053875b 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -487,6 +487,12 @@ PangoFontMap *pango_font_get_font_map (PangoFont *font);
PANGO_AVAILABLE_IN_1_44
gboolean pango_font_covers (PangoFont *font,
gunichar unichar);
+PANGO_AVAILABLE_IN_1_44
+void pango_font_get_features (PangoFont *font,
+ hb_feature_t *features,
+ guint len,
+ guint *num_features);
+
/**
* PANGO_GLYPH_EMPTY:
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 79fb07c1..fb51b3c6 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -89,7 +89,10 @@ static PangoFontMetrics * pango_fc_font_get_metrics (PangoFont *font,
static PangoFontMap * pango_fc_font_get_font_map (PangoFont *font);
static PangoFontDescription *pango_fc_font_describe (PangoFont *font);
static PangoFontDescription *pango_fc_font_describe_absolute (PangoFont *font);
-
+static void pango_fc_font_get_features (PangoFont *font,
+ hb_feature_t *features,
+ guint len,
+ guint *num_features);
#define PANGO_FC_FONT_LOCK_FACE(font) (PANGO_FC_FONT_GET_CLASS (font)->lock_face (font))
#define PANGO_FC_FONT_UNLOCK_FACE(font) (PANGO_FC_FONT_GET_CLASS (font)->unlock_face (font))
@@ -116,6 +119,7 @@ pango_fc_font_class_init (PangoFcFontClass *class)
font_class->get_coverage = pango_fc_font_get_coverage;
font_class->get_metrics = pango_fc_font_get_metrics;
font_class->get_font_map = pango_fc_font_get_font_map;
+ font_class->get_features = pango_fc_font_get_features;
g_object_class_install_property (object_class, PROP_PATTERN,
g_param_spec_pointer ("pattern",
@@ -1086,3 +1090,28 @@ pango_fc_font_get_raw_extents (PangoFcFont *fcfont,
PANGO_FC_FONT_UNLOCK_FACE (fcfont);
}
+static void
+pango_fc_font_get_features (PangoFont *font,
+ hb_feature_t *features,
+ guint len,
+ guint *num_features)
+{
+ /* Setup features from fontconfig pattern. */
+ PangoFcFont *fc_font = PANGO_FC_FONT (font);
+ if (fc_font->font_pattern)
+ {
+ char *s;
+ while (*num_features < len &&
+ FcResultMatch == FcPatternGetString (fc_font->font_pattern,
+ PANGO_FC_FONT_FEATURES,
+ *num_features,
+ (FcChar8 **) &s))
+ {
+ gboolean ret = hb_feature_from_string (s, -1, &features[*num_features]);
+ features[*num_features].start = 0;
+ features[*num_features].end = (unsigned int) -1;
+ if (ret)
+ (*num_features)++;
+ }
+ }
+}
diff --git a/pango/pangofc-shape.c b/pango/pangofc-shape.c
index 2846449e..9bedd28a 100644
--- a/pango/pangofc-shape.c
+++ b/pango/pangofc-shape.c
@@ -313,6 +313,49 @@ parse_variations (const char *variations,
*n_variations = n;
}
+static void
+apply_extra_attributes (GSList *attrs,
+ hb_feature_t *features,
+ guint length,
+ guint *num_features)
+{
+ GSList *l;
+
+ for (l = attrs; l && *num_features < length; l = l->next)
+ {
+ PangoAttribute *attr = l->data;
+ if (attr->klass->type == PANGO_ATTR_FONT_FEATURES)
+ {
+ PangoAttrFontFeatures *fattr = (PangoAttrFontFeatures *) attr;
+ const gchar *feat;
+ const gchar *end;
+ int len;
+
+ feat = fattr->features;
+
+ while (feat != NULL && *num_features < length)
+ {
+ end = strchr (feat, ',');
+ if (end)
+ len = end - feat;
+ else
+ len = -1;
+ if (hb_feature_from_string (feat, len, &features[*num_features]))
+ {
+ features[*num_features].start = attr->start_index;
+ features[*num_features].end = attr->end_index;
+ (*num_features)++;
+ }
+
+ if (end == NULL)
+ break;
+
+ feat = end + 1;
+ }
+ }
+ }
+}
+
void
_pango_fc_shape (PangoFont *font,
const char *item_text,
@@ -417,62 +460,8 @@ _pango_fc_shape (PangoFont *font,
hb_buffer_add_utf8 (hb_buffer, paragraph_text, paragraph_length, item_offset, item_length);
- /* 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))
- {
- gboolean ret = hb_feature_from_string (s, -1, &features[num_features]);
- features[num_features].start = 0;
- features[num_features].end = (unsigned int) -1;
- if (ret)
- num_features++;
- }
- }
-
- if (analysis->extra_attrs)
- {
- GSList *tmp_attrs;
-
- for (tmp_attrs = analysis->extra_attrs; tmp_attrs && num_features < G_N_ELEMENTS (features); tmp_attrs = tmp_attrs->next)
- {
- PangoAttribute *attr = tmp_attrs->data;
- if (attr->klass->type == PANGO_ATTR_FONT_FEATURES)
- {
- PangoAttrFontFeatures *fattr = (PangoAttrFontFeatures *) attr;
- const gchar *feat;
- const gchar *end;
- int len;
-
- feat = fattr->features;
-
- while (feat != NULL && num_features < G_N_ELEMENTS (features))
- {
- end = strchr (feat, ',');
- if (end)
- len = end - feat;
- else
- len = -1;
- if (hb_feature_from_string (feat, len, &features[num_features]))
- {
- features[num_features].start = attr->start_index;
- features[num_features].end = attr->end_index;
- num_features++;
- }
-
- if (end == NULL)
- break;
-
- feat = end + 1;
- }
- }
- }
- }
+ pango_font_get_features (font, features, 32, &num_features);
+ apply_extra_attributes (analysis->extra_attrs, features, 32, &num_features);
hb_shape (hb_font, hb_buffer, features, num_features);