[autofit] Implement and use `af_get_char_index' with HarfBuzz. * src/autofit/hbshim.c (COVERAGE) [FT_CONFIG_OPTION_USE_HARFBUZZ]: Redefine to construct HarfBuzz features. (af_get_char_index) [FT_CONFIG_OPTION_USE_HARFBUZZ]: Rewritten. * src/autofit/aflatin.c (af_latin_metrics_init_blues): Use `y_offset' to adjust `best_y'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
diff --git a/ChangeLog b/ChangeLog
index 2580884..a6f3390 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2014-01-01 Werner Lemberg <wl@gnu.org>
+
+ [autofit] Implement and use `af_get_char_index' with HarfBuzz.
+
+ * src/autofit/hbshim.c (COVERAGE) [FT_CONFIG_OPTION_USE_HARFBUZZ]:
+ Redefine to construct HarfBuzz features.
+ (af_get_char_index) [FT_CONFIG_OPTION_USE_HARFBUZZ]: Rewritten.
+
+ * src/autofit/aflatin.c (af_latin_metrics_init_blues): Use
+ `y_offset' to adjust `best_y'.
+
2013-12-31 Werner Lemberg <wl@gnu.org>
[autofit] s/AF_STYLE_...._DEFAULT/AF_STYLE_...._DFLT/i.
@@ -2595,7 +2606,7 @@
----------------------------------------------------------------------------
-Copyright 2013 by
+Copyright 2013-2014 by
David Turner, Robert Wilhelm, and Werner Lemberg.
This file is part of the FreeType project, and may only be used, modified,
diff --git a/src/autofit/aflatin.c b/src/autofit/aflatin.c
index fc1d443..8841d94 100644
--- a/src/autofit/aflatin.c
+++ b/src/autofit/aflatin.c
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter hinting routines for latin writing system (body). */
/* */
-/* Copyright 2003-2013 by */
+/* Copyright 2003-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -620,6 +620,12 @@
}
}
+ /* for computing blue zones, we add the y offset as returned */
+ /* by the currently used OpenType feature -- for example, */
+ /* superscript glyphs might be identical to subscript glyphs */
+ /* with a vertical shift */
+ best_y += y_offset;
+
FT_TRACE5(( " U+%04lX: best_y = %5ld", ch, best_y ));
/* now set the `round' flag depending on the segment's kind: */
diff --git a/src/autofit/hbshim.c b/src/autofit/hbshim.c
index d280e55..7dae08f 100644
--- a/src/autofit/hbshim.c
+++ b/src/autofit/hbshim.c
@@ -4,7 +4,7 @@
/* */
/* HarfBuzz interface for accessing OpenType features (body). */
/* */
-/* Copyright 2013 by */
+/* Copyright 2013, 2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -230,22 +230,96 @@
}
+ /* construct HarfBuzz features */
+#undef COVERAGE
+#define COVERAGE( name, NAME, description, \
+ tag1, tag2, tag3, tag4 ) \
+ static const hb_feature_t name ## _feature[] = \
+ { \
+ { \
+ HB_TAG( tag1, tag2, tag3, tag4 ), \
+ 1, 0, -1 \
+ } \
+ };
+
+
+#include "afcover.h"
+
+
+ /* define mapping between HarfBuzz features and AF_Coverage */
+#undef COVERAGE
+#define COVERAGE( name, NAME, description, \
+ tag1, tag2, tag3, tag4 ) \
+ name ## _feature,
+
+
+ static const hb_feature_t* features[] =
+ {
+#include "afcover.h"
+
+ NULL /* AF_COVERAGE_DEFAULT */
+ };
+
+
FT_Error
af_get_char_index( AF_StyleMetrics metrics,
FT_ULong charcode,
FT_ULong *codepoint,
FT_Long *y_offset )
{
- FT_Face face;
+ AF_StyleClass style_class;
+
+ const hb_feature_t* feature;
if ( !metrics )
return FT_THROW( Invalid_Argument );
- face = metrics->globals->face;
+ style_class = metrics->style_class;
- *codepoint = FT_Get_Char_Index( face, charcode );
- *y_offset = 0;
+ feature = features[style_class->coverage];
+
+ if ( feature )
+ {
+ hb_font_t* font = metrics->globals->hb_font;
+ hb_buffer_t* buf = hb_buffer_create();
+
+ uint32_t c = (uint32_t)charcode;
+
+ hb_glyph_info_t* ginfo;
+ hb_glyph_position_t* gpos;
+ unsigned int gcount;
+
+
+ /* XXX: is this sufficient for a single character of any script? */
+ hb_buffer_set_direction( buf, HB_DIRECTION_LTR );
+ hb_buffer_set_script( buf, scripts[style_class->script] );
+
+ /* we add one character to `buf' ... */
+ hb_buffer_add_utf32( buf, &c, 1, 0, 1 );
+
+ /* ... and apply one feature */
+ hb_shape( font, buf, feature, 1 );
+
+ ginfo = hb_buffer_get_glyph_infos( buf, &gcount );
+ gpos = hb_buffer_get_glyph_positions( buf, &gcount );
+
+ *codepoint = ginfo[0].codepoint;
+ *y_offset = gpos[0].y_offset;
+
+ hb_buffer_destroy( buf );
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ if ( gcount > 1 )
+ FT_TRACE1(( "af_get_char_index:"
+ " input character mapped to multiple glyphs\n" ));
+#endif
+ }
+ else
+ {
+ *codepoint = FT_Get_Char_Index( metrics->globals->face, charcode );
+ *y_offset = 0;
+ }
return FT_Err_Ok;
}