[OT] Implement fallback positioning

Implemented for Arabic, Hebrew, and generic marks.
Activated if no GPOS table present.
This commit is contained in:
Behdad Esfahbod 2012-08-08 01:20:45 -04:00
parent fb56e76283
commit 21756934a1
6 changed files with 356 additions and 77 deletions

View File

@ -143,7 +143,8 @@ hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
hb_bool_t
hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs);
/* funcs */
/* glyph extents */
typedef struct hb_glyph_extents_t
{

View File

@ -201,7 +201,7 @@ hb_ft_get_glyph_extents (hb_font_t *font HB_UNUSED,
extents->x_bearing = ft_face->glyph->metrics.horiBearingX;
extents->y_bearing = ft_face->glyph->metrics.horiBearingY;
extents->width = ft_face->glyph->metrics.width;
extents->height = ft_face->glyph->metrics.height;
extents->height = -ft_face->glyph->metrics.height;
return true;
}
@ -464,6 +464,7 @@ hb_ft_font_set_funcs (hb_font_t *font)
FT_Select_Charmap (ft_face, FT_ENCODING_UNICODE);
assert (font->y_scale >= 0);
FT_Set_Char_Size (ft_face,
font->x_scale, font->y_scale,
0, 0);

View File

@ -152,7 +152,7 @@ hb_old_getGlyphMetrics (HB_Font old_font,
metrics->x = extents.x_bearing;
metrics->y = extents.y_bearing;
metrics->width = extents.width;
metrics->height = -extents.height;
metrics->height = extents.height;
metrics->xOffset = font->get_glyph_h_advance (glyph);
metrics->yOffset = 0;
}

View File

@ -27,10 +27,11 @@
#include "hb-ot-shape-position-fallback-private.hh"
static void
hb_zero_mark_advances (hb_buffer_t *buffer)
zero_mark_advances (hb_buffer_t *buffer,
unsigned int start,
unsigned int end)
{
unsigned int count = buffer->len;
for (unsigned int i = 0; i < count; i++)
for (unsigned int i = start; i < end; i++)
if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
{
buffer->pos[i].x_advance = 0;
@ -38,10 +39,238 @@ hb_zero_mark_advances (hb_buffer_t *buffer)
}
}
static unsigned int
recategorize_combining_class (unsigned int modified_combining_class)
{
if (modified_combining_class >= 200)
return modified_combining_class;
/* This should be kept in sync with modified combining class mapping
* from hb-unicode.cc. */
switch (modified_combining_class)
{
/* Hebrew */
case HB_MODIFIED_COMBINING_CLASS_CCC10: /* sheva */
case HB_MODIFIED_COMBINING_CLASS_CCC11: /* hataf segol */
case HB_MODIFIED_COMBINING_CLASS_CCC12: /* hataf patah */
case HB_MODIFIED_COMBINING_CLASS_CCC13: /* hataf qamats */
case HB_MODIFIED_COMBINING_CLASS_CCC14: /* hiriq */
case HB_MODIFIED_COMBINING_CLASS_CCC15: /* tsere */
case HB_MODIFIED_COMBINING_CLASS_CCC16: /* segol */
case HB_MODIFIED_COMBINING_CLASS_CCC17: /* patah */
case HB_MODIFIED_COMBINING_CLASS_CCC18: /* qamats */
case HB_MODIFIED_COMBINING_CLASS_CCC20: /* qubuts */
case HB_MODIFIED_COMBINING_CLASS_CCC22: /* meteg */
return HB_UNICODE_COMBINING_CLASS_BELOW;
case HB_MODIFIED_COMBINING_CLASS_CCC23: /* rafe */
return HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE;
case HB_MODIFIED_COMBINING_CLASS_CCC24: /* shin dot */
return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
case HB_MODIFIED_COMBINING_CLASS_CCC25: /* sin dot */
case HB_MODIFIED_COMBINING_CLASS_CCC19: /* holam */
return HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT;
case HB_MODIFIED_COMBINING_CLASS_CCC26: /* point varika */
return HB_UNICODE_COMBINING_CLASS_ABOVE;
case HB_MODIFIED_COMBINING_CLASS_CCC21: /* dagesh */
break;
/* Arabic and Syriac */
case HB_MODIFIED_COMBINING_CLASS_CCC27: /* fathatan */
case HB_MODIFIED_COMBINING_CLASS_CCC28: /* dammatan */
case HB_MODIFIED_COMBINING_CLASS_CCC30: /* fatha */
case HB_MODIFIED_COMBINING_CLASS_CCC31: /* damma */
case HB_MODIFIED_COMBINING_CLASS_CCC33: /* shadda */
case HB_MODIFIED_COMBINING_CLASS_CCC34: /* sukun */
case HB_MODIFIED_COMBINING_CLASS_CCC35: /* superscript alef */
case HB_MODIFIED_COMBINING_CLASS_CCC36: /* superscript alaph */
return HB_UNICODE_COMBINING_CLASS_ABOVE;
case HB_MODIFIED_COMBINING_CLASS_CCC29: /* kasratan */
case HB_MODIFIED_COMBINING_CLASS_CCC32: /* kasra */
return HB_UNICODE_COMBINING_CLASS_BELOW;
/* TODO Thai, Lao, and Tibetan */
}
return modified_combining_class;
}
static inline void
position_mark (const hb_ot_shape_plan_t *plan,
hb_font_t *font,
hb_buffer_t *buffer,
hb_glyph_extents_t &base_extents,
unsigned int i,
unsigned int combining_class)
{
hb_glyph_extents_t mark_extents;
if (!hb_font_get_glyph_extents (font,
buffer->info[i].codepoint,
&mark_extents))
return;
hb_position_t y_gap = font->y_scale / 16;
hb_glyph_position_t &pos = buffer->pos[i];
pos.x_offset = pos.y_offset = 0;
/* We dont position LEFT and RIGHT marks. */
/* X positioning */
switch (combining_class)
{
case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW:
case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE:
/* TODO Do something... For now, fall through. */
case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW:
case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE:
case HB_UNICODE_COMBINING_CLASS_BELOW:
case HB_UNICODE_COMBINING_CLASS_ABOVE:
/* Center align. */
pos.x_offset += base_extents.x_bearing + (base_extents.width - mark_extents.width) / 2 - mark_extents.x_bearing;
break;
case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT:
case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT:
case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT:
/* Left align. */
pos.x_offset += base_extents.x_bearing - mark_extents.x_bearing;
break;
case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT:
case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT:
case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT:
/* Right align. */
pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width - mark_extents.x_bearing;
break;
}
/* Y positioning */
switch (combining_class)
{
case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW:
case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT:
case HB_UNICODE_COMBINING_CLASS_BELOW:
case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT:
/* Add gap, fall-through. */
base_extents.height -= y_gap;
case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT:
case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW:
pos.y_offset += base_extents.y_bearing + base_extents.height - mark_extents.y_bearing;
base_extents.height += mark_extents.height;
break;
case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE:
case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT:
case HB_UNICODE_COMBINING_CLASS_ABOVE:
case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT:
/* Add gap, fall-through. */
base_extents.y_bearing += y_gap;
base_extents.height -= y_gap;
case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE:
case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT:
pos.y_offset += base_extents.y_bearing - (mark_extents.y_bearing + mark_extents.height);
base_extents.y_bearing -= mark_extents.height;
base_extents.height += mark_extents.height;
break;
}
}
static inline void
position_around_base (const hb_ot_shape_plan_t *plan,
hb_font_t *font,
hb_buffer_t *buffer,
unsigned int base,
unsigned int end)
{
hb_glyph_extents_t base_extents;
if (!hb_font_get_glyph_extents (font,
buffer->info[base].codepoint,
&base_extents))
{
/* If extents don't work, zero marks and go home. */
zero_mark_advances (buffer, base + 1, end);
return;
}
base_extents.x_bearing += buffer->pos[base].x_offset;
base_extents.y_bearing += buffer->pos[base].y_offset;
/* XXX Handle ligature component positioning... */
HB_UNUSED bool is_ligature = is_a_ligature (buffer->info[base]);
hb_position_t x_offset = 0, y_offset = 0;
unsigned int last_combining_class = 255;
hb_glyph_extents_t cluster_extents;
for (unsigned int i = base + 1; i < end; i++)
if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
{
unsigned int this_combining_class = recategorize_combining_class (_hb_glyph_info_get_modified_combining_class (&buffer->info[i]));
if (this_combining_class != last_combining_class)
cluster_extents = base_extents;
position_mark (plan, font, buffer, base_extents, i, this_combining_class);
buffer->pos[i].x_advance = 0;
buffer->pos[i].y_advance = 0;
buffer->pos[i].x_offset += x_offset;
buffer->pos[i].y_offset += y_offset;
/* combine cluster extents. */
last_combining_class = this_combining_class;
} else {
x_offset -= buffer->pos[i].x_advance;
y_offset -= buffer->pos[i].y_advance;
}
}
static inline void
position_cluster (const hb_ot_shape_plan_t *plan,
hb_font_t *font,
hb_buffer_t *buffer,
unsigned int start,
unsigned int end)
{
if (end - start < 2)
return;
/* Find the base glyph */
for (unsigned int i = start; i < end; i++)
if (is_a_ligature (buffer->info[i]) ||
!(FLAG (_hb_glyph_info_get_general_category (&buffer->info[i])) &
(FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) |
FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) |
FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))))
{
position_around_base (plan, font, buffer, i, end);
break;
}
}
void
_hb_ot_shape_position_fallback (const hb_ot_shape_plan_t *plan,
hb_font_t *font,
hb_buffer_t *buffer)
{
hb_zero_mark_advances (buffer);
unsigned int start = 0;
unsigned int last_cluster = buffer->info[0].cluster;
unsigned int count = buffer->len;
for (unsigned int i = 1; i < count; i++)
if (buffer->info[i].cluster != last_cluster) {
position_cluster (plan, font, buffer, start, i);
start = i;
last_cluster = buffer->info[i].cluster;
}
position_cluster (plan, font, buffer, start, count);
}

View File

@ -195,4 +195,85 @@ extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil;
#endif
/* Modified combining marks */
/* Hebrew
*
* We permute the "fixed-position" classes 10-26 into the order
* described in the SBL Hebrew manual:
*
* http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf
*
* (as recommended by:
* http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diacritic-ordering-t6751.0.html)
*
* More details here:
* https://bugzilla.mozilla.org/show_bug.cgi?id=662055
*/
#define HB_MODIFIED_COMBINING_CLASS_CCC10 22 /* sheva */
#define HB_MODIFIED_COMBINING_CLASS_CCC11 15 /* hataf segol */
#define HB_MODIFIED_COMBINING_CLASS_CCC12 16 /* hataf patah */
#define HB_MODIFIED_COMBINING_CLASS_CCC13 17 /* hataf qamats */
#define HB_MODIFIED_COMBINING_CLASS_CCC14 23 /* hiriq */
#define HB_MODIFIED_COMBINING_CLASS_CCC15 18 /* tsere */
#define HB_MODIFIED_COMBINING_CLASS_CCC16 19 /* segol */
#define HB_MODIFIED_COMBINING_CLASS_CCC17 20 /* patah */
#define HB_MODIFIED_COMBINING_CLASS_CCC18 21 /* qamats */
#define HB_MODIFIED_COMBINING_CLASS_CCC19 14 /* holam */
#define HB_MODIFIED_COMBINING_CLASS_CCC20 24 /* qubuts */
#define HB_MODIFIED_COMBINING_CLASS_CCC21 12 /* dagesh */
#define HB_MODIFIED_COMBINING_CLASS_CCC22 25 /* meteg */
#define HB_MODIFIED_COMBINING_CLASS_CCC23 13 /* rafe */
#define HB_MODIFIED_COMBINING_CLASS_CCC24 10 /* shin dot */
#define HB_MODIFIED_COMBINING_CLASS_CCC25 11 /* sin dot */
#define HB_MODIFIED_COMBINING_CLASS_CCC26 26 /* point varika */
/*
* Arabic
*
* Modify to move Shadda (ccc=33) before other marks. See:
* http://unicode.org/faq/normalization.html#8
* http://unicode.org/faq/normalization.html#9
*/
#define HB_MODIFIED_COMBINING_CLASS_CCC27 28 /* fathatan */
#define HB_MODIFIED_COMBINING_CLASS_CCC28 29 /* dammatan */
#define HB_MODIFIED_COMBINING_CLASS_CCC29 30 /* kasratan */
#define HB_MODIFIED_COMBINING_CLASS_CCC30 31 /* fatha */
#define HB_MODIFIED_COMBINING_CLASS_CCC31 32 /* damma */
#define HB_MODIFIED_COMBINING_CLASS_CCC32 33 /* kasra */
#define HB_MODIFIED_COMBINING_CLASS_CCC33 27 /* shadda */
#define HB_MODIFIED_COMBINING_CLASS_CCC34 34 /* sukun */
#define HB_MODIFIED_COMBINING_CLASS_CCC35 35 /* superscript alef */
/* Syriac */
#define HB_MODIFIED_COMBINING_CLASS_CCC36 36 /* superscript alaph */
/* Telugu
*
* Modify Telugu length marks (ccc=84, ccc=91).
* These are the only matras in the main Indic scripts range that have
* a non-zero ccc. That makes them reorder with the Halant that is
* ccc=9. Just zero them, we don't need them in our Indic shaper.
*/
#define HB_MODIFIED_COMBINING_CLASS_CCC84 0 /* length mark */
#define HB_MODIFIED_COMBINING_CLASS_CCC91 0 /* ai length mark */
/* Thai
*
* Modify U+0E38 and U+0E39 (ccc=104) to be reordered before U+0E3A (ccc=9).
* Uniscribe does this too.
*/
#define HB_MODIFIED_COMBINING_CLASS_CCC103 3 /* sara u / sara uu */
#define HB_MODIFIED_COMBINING_CLASS_CCC107 107 /* mai * */
/* Lao */
#define HB_MODIFIED_COMBINING_CLASS_CCC118 118 /* sign u / sign uu */
#define HB_MODIFIED_COMBINING_CLASS_CCC122 122 /* mai * */
/* Tibetan */
#define HB_MODIFIED_COMBINING_CLASS_CCC129 129 /* sign aa */
#define HB_MODIFIED_COMBINING_CLASS_CCC130 130 /* sign i */
#define HB_MODIFIED_COMBINING_CLASS_CCC133 132 /* sign u */
#endif /* HB_UNICODE_PRIVATE_HH */

View File

@ -287,6 +287,7 @@ hb_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs,
}
/* See hb-unicode-private.hh for details. */
const uint8_t
_hb_modified_combining_class[256] =
{
@ -298,58 +299,37 @@ _hb_modified_combining_class[256] =
9, /* HB_UNICODE_COMBINING_CLASS_VIRAMA */
/* Hebrew */
/*
* We permute the "fixed-position" classes 10-26 into the order
* described in the SBL Hebrew manual:
*
* http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf
*
* (as recommended by:
* http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diacritic-ordering-t6751.0.html)
*
* More details here:
* https://bugzilla.mozilla.org/show_bug.cgi?id=662055
*/
22, /* HB_UNICODE_COMBINING_CLASS_CCC10 sheva */
15, /* HB_UNICODE_COMBINING_CLASS_CCC11 hataf segol */
16, /* HB_UNICODE_COMBINING_CLASS_CCC12 hataf patah*/
17, /* HB_UNICODE_COMBINING_CLASS_CCC13 hataf qamats */
23, /* HB_UNICODE_COMBINING_CLASS_CCC14 hiriq */
18, /* HB_UNICODE_COMBINING_CLASS_CCC15 tsere */
19, /* HB_UNICODE_COMBINING_CLASS_CCC16 segol */
20, /* HB_UNICODE_COMBINING_CLASS_CCC17 patah */
21, /* HB_UNICODE_COMBINING_CLASS_CCC18 qamats */
14, /* HB_UNICODE_COMBINING_CLASS_CCC19 holam */
24, /* HB_UNICODE_COMBINING_CLASS_CCC20 qubuts */
12, /* HB_UNICODE_COMBINING_CLASS_CCC21 dagesh */
25, /* HB_UNICODE_COMBINING_CLASS_CCC22 meteg */
13, /* HB_UNICODE_COMBINING_CLASS_CCC23 rafe */
10, /* HB_UNICODE_COMBINING_CLASS_CCC24 shin dot */
11, /* HB_UNICODE_COMBINING_CLASS_CCC25 sin dot */
26, /* HB_UNICODE_COMBINING_CLASS_CCC26 */
HB_MODIFIED_COMBINING_CLASS_CCC10,
HB_MODIFIED_COMBINING_CLASS_CCC11,
HB_MODIFIED_COMBINING_CLASS_CCC12,
HB_MODIFIED_COMBINING_CLASS_CCC13,
HB_MODIFIED_COMBINING_CLASS_CCC14,
HB_MODIFIED_COMBINING_CLASS_CCC15,
HB_MODIFIED_COMBINING_CLASS_CCC16,
HB_MODIFIED_COMBINING_CLASS_CCC17,
HB_MODIFIED_COMBINING_CLASS_CCC18,
HB_MODIFIED_COMBINING_CLASS_CCC19,
HB_MODIFIED_COMBINING_CLASS_CCC20,
HB_MODIFIED_COMBINING_CLASS_CCC21,
HB_MODIFIED_COMBINING_CLASS_CCC22,
HB_MODIFIED_COMBINING_CLASS_CCC23,
HB_MODIFIED_COMBINING_CLASS_CCC24,
HB_MODIFIED_COMBINING_CLASS_CCC25,
HB_MODIFIED_COMBINING_CLASS_CCC26,
/* Arabic */
/*
* Modify to move Shadda (ccc=33) before other marks. See:
* http://unicode.org/faq/normalization.html#8
* http://unicode.org/faq/normalization.html#9
*/
28, /* HB_UNICODE_COMBINING_CLASS_CCC27 */
29, /* HB_UNICODE_COMBINING_CLASS_CCC28 */
30, /* HB_UNICODE_COMBINING_CLASS_CCC29 */
31, /* HB_UNICODE_COMBINING_CLASS_CCC30 */
32, /* HB_UNICODE_COMBINING_CLASS_CCC31 */
33, /* HB_UNICODE_COMBINING_CLASS_CCC32 */
27, /* HB_UNICODE_COMBINING_CLASS_CCC33 shadda */
34, /* HB_UNICODE_COMBINING_CLASS_CCC34 */
35, /* HB_UNICODE_COMBINING_CLASS_CCC35 */
HB_MODIFIED_COMBINING_CLASS_CCC27,
HB_MODIFIED_COMBINING_CLASS_CCC28,
HB_MODIFIED_COMBINING_CLASS_CCC29,
HB_MODIFIED_COMBINING_CLASS_CCC30,
HB_MODIFIED_COMBINING_CLASS_CCC31,
HB_MODIFIED_COMBINING_CLASS_CCC32,
HB_MODIFIED_COMBINING_CLASS_CCC33,
HB_MODIFIED_COMBINING_CLASS_CCC34,
HB_MODIFIED_COMBINING_CLASS_CCC35,
/* Syriac */
36, /* HB_UNICODE_COMBINING_CLASS_CCC36 */
HB_MODIFIED_COMBINING_CLASS_CCC36,
37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
@ -357,41 +337,28 @@ _hb_modified_combining_class[256] =
80, 81, 82, 83,
/* Telugu */
/*
* Modify Telugu length marks (ccc=84, ccc=91).
* These are the only matras in the main Indic scripts range that have
* a non-zero ccc. That makes them reorder with the Halant that is
* ccc=9. Just zero them, we don't need them in our Indic shaper.
*/
0, /* HB_UNICODE_COMBINING_CLASS_CCC84 */
HB_MODIFIED_COMBINING_CLASS_CCC84,
85, 86, 87, 88, 89, 90,
0, /* HB_UNICODE_COMBINING_CLASS_CCC91 */
HB_MODIFIED_COMBINING_CLASS_CCC91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
/* Thai */
/*
* Modify U+0E38 and U+0E39 (ccc=104) to be reordered before U+0E3A (ccc=9).
* Uniscribe does this too.
*/
3, /* HB_UNICODE_COMBINING_CLASS_CCC103 */
HB_MODIFIED_COMBINING_CLASS_CCC103,
104, 105, 106,
107, /* HB_UNICODE_COMBINING_CLASS_CCC107 */
HB_MODIFIED_COMBINING_CLASS_CCC107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
/* Lao */
118, /* HB_UNICODE_COMBINING_CLASS_CCC118 */
HB_MODIFIED_COMBINING_CLASS_CCC118,
119, 120, 121,
122, /* HB_UNICODE_COMBINING_CLASS_CCC122 */
HB_MODIFIED_COMBINING_CLASS_CCC122,
123, 124, 125, 126, 127, 128,
/* Tibetan */
129, /* HB_UNICODE_COMBINING_CLASS_CCC129 */
130, /* HB_UNICODE_COMBINING_CLASS_CCC130 */
HB_MODIFIED_COMBINING_CLASS_CCC129,
HB_MODIFIED_COMBINING_CLASS_CCC130,
131,
132, /* HB_UNICODE_COMBINING_CLASS_CCC133 */
HB_MODIFIED_COMBINING_CLASS_CCC133,
133, 134, 135, 136, 137, 138, 139,