Commit 5eabb1f7 authored by Matthias Clasen's avatar Matthias Clasen
Browse files

Show OpenType layout features

Making such font features visible is the first step towards
getting them to be exposed and used in appliations, where
appropriate.

https://bugzilla.gnome.org/show_bug.cgi?id=787759
parent 96a51ff7
This diff is collapsed.
......@@ -34,6 +34,9 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <hb.h>
#include <hb-ot.h>
#include <hb-ft.h>
#include "font-model.h"
#include "sushi-font-widget.h"
......@@ -263,6 +266,126 @@ describe_instance (FT_Face face,
g_free (str);
}
/* OpenType layout features. This list is incomplete. */
static struct {
const char *tag;
const char *name;
} named_features[] = {
{ "aalt", N_("Access All Alternatives") },
{ "ccmp", N_("Glyph Composition/Decomposition") },
{ "dnom", N_("Denominators") },
{ "numr", N_("Numerators") },
{ "ordn", N_("Ordinals") },
{ "mark", N_("Mark Positioning") },
{ "mkmk", N_("Mark to Mark Positioning") },
{ "rvrn", N_("Required Variation Alternates"), },
{ "size", N_("Optical size"), },
{ "opbd", N_("Optical Bounds"), },
{ "lfbd", N_("Left Bounds"), },
{ "rtbd", N_("Right Bounds"), },
{ "rtlm", N_("Right-to-left mirrored forms"), },
{ "mgrk", N_("Mathematical Greek") },
{ "kern", N_("Kerning") },
{ "liga", N_("Common Ligatures") },
{ "dlig", N_("Discretionary Ligatures") },
{ "hlig", N_("Historical Ligatures") },
{ "clig", N_("Contextual Ligatures") },
{ "smcp", N_("Small Caps") },
{ "c2sc", N_("Small Caps from Caps") },
{ "pcap", N_("Petite Caps") },
{ "c2pc", N_("Caps to Petite Caps") },
{ "unic", N_("Unicase") },
{ "cpsp", N_("Capital Spacing") },
{ "case", N_("Case-sensitive Forms") },
{ "lnum", N_("Lining Numbers") },
{ "onum", N_("Old-Style Numbers") },
{ "pnum", N_("Proportional Numbers") },
{ "tnum", N_("Tabular Numbers") },
{ "frac", N_("Normal Fractions") },
{ "afrc", N_("Alternate Fractions") },
{ "zero", N_("Slashed Zero") },
{ "nalt", N_("Alternative Annotations") },
{ "sinf", N_("Scientific Inferiors") },
{ "swsh", N_("Swash Glyphs") },
{ "cswh", N_("Contextual Swash") },
{ "locl", N_("Localized Forms") },
{ "calt", N_("Contextual Alternatives") },
{ "hist", N_("Historical Alternatives") },
{ "salt", N_("Stylistic Alternatives") },
{ "titl", N_("Titling Alternatives") },
{ "rand", N_("Randomize") },
{ "subs", N_("Subscript") },
{ "sups", N_("Superscript") },
{ "init", N_("Initial Forms") },
{ "medi", N_("Medial Forms") },
{ "fina", N_("Final Forms") },
{ "isol", N_("Isolated Forms") },
{ "ss01", N_("Stylistic Set 1") },
{ "ss02", N_("Stylistic Set 2") },
{ "ss03", N_("Stylistic Set 3") },
{ "ss04", N_("Stylistic Set 4") },
{ "ss05", N_("Stylistic Set 5") },
{ "ss06", N_("Stylistic Set 6") },
};
static char *
get_features (FT_Face face)
{
hb_font_t *hb_font;
int i, j;
GString *s;
s = g_string_new ("");
hb_font = hb_ft_font_create (face, NULL);
if (hb_font) {
hb_tag_t tables[2] = { HB_OT_TAG_GSUB, HB_OT_TAG_GPOS };
hb_face_t *hb_face;
hb_face = hb_font_get_face (hb_font);
for (i = 0; i < 2; i++) {
hb_tag_t features[80];
unsigned int count = G_N_ELEMENTS (features);
unsigned int script_index = 0;
unsigned int lang_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
hb_ot_layout_language_get_feature_tags (hb_face,
tables[i],
script_index,
lang_index,
0,
&count,
features);
for (j = 0; j < count; j++) {
char buf[5];
const char *name;
int k;
hb_tag_to_string (features[j], buf); buf[4] = '\0';
name = buf;
for (k = 0; k < G_N_ELEMENTS (named_features); k++) {
if (strcmp (named_features[k].tag, buf) == 0) {
name = _(named_features[k].name);
break;
}
}
if (s->len > 0)
g_string_append (s, ", ");
g_string_append (s, name);
}
}
}
if (s->len > 0)
return g_string_free (s, FALSE);
g_string_free (s, TRUE);
return NULL;
}
static void
populate_grid (FontViewApplication *self,
GtkWidget *grid,
......@@ -398,6 +521,13 @@ populate_grid (FontViewApplication *self,
}
add_row (grid, _("Color Glyphs"), FT_HAS_COLOR (face) ? _("yes") : _("no"), FALSE);
{
char *features = get_features (face);
if (features)
add_row (grid, _("Layout Features"), features, TRUE);
g_free (features);
}
if (FT_Get_MM_Var (face, &ft_mm_var) == 0) {
int i;
for (i = 0; i < ft_mm_var->num_axis; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment