Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/analyzer.c | 4 + dlls/dwrite/dwrite_private.h | 2 + dlls/dwrite/opentype.c | 305 +++++++++++++++++++++++++++++++++++ 3 files changed, 311 insertions(+)
diff --git a/dlls/dwrite/analyzer.c b/dlls/dwrite/analyzer.c index 7f15c91279..1fc8f98d16 100644 --- a/dlls/dwrite/analyzer.c +++ b/dlls/dwrite/analyzer.c @@ -1316,7 +1316,9 @@ static HRESULT WINAPI dwritetextanalyzer_GetGlyphPlacements(IDWriteTextAnalyzer2 context.u.pos.glyphs = glyphs; context.u.pos.glyph_props = glyph_props; context.glyph_count = glyph_count; + context.emsize = emSize; context.advances = advances; + context.offsets = offsets; context.language_tag = get_opentype_language(locale);
hr = shape_get_positions(&context, scriptprops->scripttags, scriptprops->ops->gpos_features); @@ -1378,7 +1380,9 @@ static HRESULT WINAPI dwritetextanalyzer_GetGdiCompatibleGlyphPlacements(IDWrite context.u.pos.glyphs = glyphs; context.u.pos.glyph_props = glyph_props; context.glyph_count = glyph_count; + context.emsize = emSize * ppdip; context.advances = advances; + context.offsets = offsets; context.language_tag = get_opentype_language(locale);
hr = shape_get_positions(&context, scriptprops->scripttags, scriptprops->ops->gpos_features); diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index 5a6cd4b16b..355a826563 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -393,7 +393,9 @@ struct scriptshaping_context } u;
unsigned int glyph_count; + float emsize; float *advances; + DWRITE_GLYPH_OFFSET *offsets; };
struct shaping_font_ops diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index 8cc74638b0..8cc45e4c10 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -489,6 +489,18 @@ enum gpos_lookup_type GPOS_LOOKUP_EXTENSION_POSITION = 9, };
+enum gpos_value_format +{ + GPOS_VALUE_X_PLACEMENT = 0x1, + GPOS_VALUE_Y_PLACEMENT = 0x2, + GPOS_VALUE_X_ADVANCE = 0x4, + GPOS_VALUE_Y_ADVANCE = 0x8, + GPOS_VALUE_X_PLACEMENT_DEVICE = 0x10, + GPOS_VALUE_Y_PLACEMENT_DEVICE = 0x20, + GPOS_VALUE_X_ADVANCE_DEVICE = 0x40, + GPOS_VALUE_Y_ADVANCE_DEVICE = 0x80, +}; + enum OPENTYPE_PLATFORM_ID { OPENTYPE_PLATFORM_UNICODE = 0, @@ -526,6 +538,54 @@ struct ot_lookup_table WORD subtable[1]; };
+#define GLYPH_NOT_COVERED ((unsigned int)~0u) + +struct ot_coverage_format1 +{ + WORD format; + WORD glyph_count; + WORD glyphs[1]; +}; + +struct ot_coverage_range +{ + WORD start_glyph; + WORD end_glyph; + WORD startcoverage_index; +}; + +struct ot_coverage_format2 +{ + WORD format; + WORD range_count; + struct ot_coverage_range ranges[1]; +}; + +struct ot_gpos_device_table +{ + WORD start_size; + WORD end_size; + WORD format; + WORD values[1]; +}; + +struct ot_gpos_singlepos_format1 +{ + WORD format; + WORD coverage; + WORD value_format; + WORD value[1]; +}; + +struct ot_gpos_singlepos_format2 +{ + WORD format; + WORD coverage; + WORD value_format; + WORD value_count; + WORD values[1]; +}; + typedef struct { WORD SubstFormat; WORD Coverage; @@ -2635,6 +2695,201 @@ static unsigned int opentype_layout_get_glyph_class(const struct dwrite_fonttabl return glyph_class; }
+struct coverage_compare_format1_context +{ + UINT16 glyph; + const UINT16 *table_base; + unsigned int *coverage_index; +}; + +static int coverage_compare_format1(const void *left, const void *right) +{ + const struct coverage_compare_format1_context *context = left; + UINT16 glyph = GET_BE_WORD(*(UINT16 *)right); + int ret; + + ret = context->glyph - glyph; + if (!ret) + *context->coverage_index = (UINT16 *)right - context->table_base; + + return ret; +} + +static int coverage_compare_format2(const void *g, const void *r) +{ + const struct ot_coverage_range *range = r; + UINT16 glyph = *(UINT16 *)g; + + if (glyph < GET_BE_WORD(range->start_glyph)) + return -1; + else if (glyph > GET_BE_WORD(range->end_glyph)) + return 1; + else + return 0; +} + +static unsigned int opentype_layout_is_glyph_covered(const struct dwrite_fonttable *table, DWORD coverage, + UINT16 glyph) +{ + WORD format = table_read_be_word(table, coverage), count; + + count = table_read_be_word(table, coverage + 2); + + if (format == 1) + { + const struct ot_coverage_format1 *format1 = table_read_ensure(table, coverage, + FIELD_OFFSET(struct ot_coverage_format1, glyphs[count])); + struct coverage_compare_format1_context context; + unsigned int coverage_index = GLYPH_NOT_COVERED; + + if (format1) + { + context.glyph = glyph; + context.table_base = format1->glyphs; + context.coverage_index = &coverage_index; + + bsearch(&context, format1->glyphs, count, sizeof(glyph), coverage_compare_format1); + } + + return coverage_index; + } + else if (format == 2) + { + const struct ot_coverage_format2 *format2 = table_read_ensure(table, coverage, + FIELD_OFFSET(struct ot_coverage_format2, ranges[count])); + if (format2) + { + const struct ot_coverage_range *range = bsearch(&glyph, format2->ranges, count, + sizeof(struct ot_coverage_range), coverage_compare_format2); + return range && glyph <= GET_BE_WORD(range->end_glyph) ? + GET_BE_WORD(range->startcoverage_index) + glyph - GET_BE_WORD(range->start_glyph) : + GLYPH_NOT_COVERED; + } + } + else + WARN("Unknown coverage format %u.\n", format); + + return -1; +} + +static inline unsigned int dwrite_popcount(unsigned int x) +{ +#ifdef HAVE___BUILTIN_POPCOUNT + return __builtin_popcount(x); +#else + x -= x >> 1 & 0x55555555; + x = (x & 0x33333333) + (x >> 2 & 0x33333333); + return ((x + (x >> 4)) & 0x0f0f0f0f) * 0x01010101 >> 24; +#endif +} + +static float opentype_scale_gpos_be_value(WORD value, float emsize, UINT16 upem) +{ + return (short)GET_BE_WORD(value) * emsize / upem; +} + +static int opentype_layout_gpos_get_dev_value(const struct scriptshaping_context *context, unsigned int offset) +{ + const struct scriptshaping_cache *cache = context->cache; + unsigned int start_size, end_size, format, value_word; + unsigned int index, ppem, mask; + int value; + + if (!offset) + return 0; + + start_size = table_read_be_word(&cache->gpos.table, offset); + end_size = table_read_be_word(&cache->gpos.table, offset + FIELD_OFFSET(struct ot_gpos_device_table, end_size)); + + ppem = context->emsize; + if (ppem < start_size || ppem > end_size) + return 0; + + format = table_read_be_word(&cache->gpos.table, offset + FIELD_OFFSET(struct ot_gpos_device_table, format)); + + if (format < 1 || format > 3) + return 0; + + index = ppem - start_size; + + value_word = table_read_be_word(&cache->gpos.table, offset + + FIELD_OFFSET(struct ot_gpos_device_table, values[index >> (4 - format)])); + mask = 0xffff >> (16 - (1 << format)); + + value = (value_word >> ((index % (4 - format)) * (1 << format))) & mask; + + if ((unsigned int)value >= ((mask + 1) >> 1)) + value -= mask + 1; + + return value; +} + +static void opentype_layout_apply_gpos_value(struct scriptshaping_context *context, unsigned int table_offset, + WORD value_format, const WORD *values, unsigned int glyph) +{ + const struct scriptshaping_cache *cache = context->cache; + DWRITE_GLYPH_OFFSET *offset = &context->offsets[glyph]; + float *advance = &context->advances[glyph]; + + if (!value_format) + return; + + if (value_format & GPOS_VALUE_X_PLACEMENT) + { + offset->advanceOffset += opentype_scale_gpos_be_value(*values, context->emsize, cache->upem); + values++; + } + if (value_format & GPOS_VALUE_Y_PLACEMENT) + { + offset->ascenderOffset += opentype_scale_gpos_be_value(*values, context->emsize, cache->upem); + values++; + } + if (value_format & GPOS_VALUE_X_ADVANCE) + { + *advance += opentype_scale_gpos_be_value(*values, context->emsize, cache->upem); + values++; + } + if (value_format & GPOS_VALUE_Y_ADVANCE) + { + values++; + } + if (value_format & GPOS_VALUE_X_PLACEMENT_DEVICE) + { + offset->advanceOffset += opentype_layout_gpos_get_dev_value(context, table_offset + GET_BE_WORD(*values)); + values++; + } + if (value_format & GPOS_VALUE_Y_PLACEMENT_DEVICE) + { + offset->ascenderOffset += opentype_layout_gpos_get_dev_value(context, table_offset + GET_BE_WORD(*values)); + values++; + } + if (value_format & GPOS_VALUE_X_ADVANCE_DEVICE) + { + *advance += opentype_layout_gpos_get_dev_value(context, table_offset + GET_BE_WORD(*values)); + values++; + } + if (value_format & GPOS_VALUE_Y_ADVANCE_DEVICE) + { + values++; + } +} + +static unsigned int opentype_layout_get_gpos_subtable(const struct scriptshaping_cache *cache, + unsigned int lookup_offset, unsigned int subtable) +{ + WORD lookup_type = table_read_be_word(&cache->gpos.table, lookup_offset); + unsigned int subtable_offset = table_read_be_word(&cache->gpos.table, lookup_offset + + FIELD_OFFSET(struct ot_lookup_table, subtable[subtable])); + if (lookup_type == GPOS_LOOKUP_EXTENSION_POSITION) + { + const struct ot_gpos_extensionpos_format1 *format1 = table_read_ensure(&cache->gpos.table, + lookup_offset + subtable_offset, sizeof(*format1)); + subtable_offset += GET_BE_DWORD(format1->extension_offset); + } + + return lookup_offset + subtable_offset; +} + struct lookup { unsigned int offset; @@ -2677,6 +2932,56 @@ static BOOL glyph_iterator_match(const struct glyph_iterator *iter) static BOOL opentype_layout_apply_gpos_single_adjustment(struct scriptshaping_context *context, struct glyph_iterator *iter, const struct lookup *lookup) { + struct scriptshaping_cache *cache = context->cache; + WORD format, value_format, value_len, coverage; + unsigned int i; + + for (i = 0; i < lookup->subtable_count; ++i) + { + unsigned int subtable_offset = opentype_layout_get_gpos_subtable(cache, lookup->offset, i); + unsigned int coverage_index; + + format = table_read_be_word(&cache->gpos.table, subtable_offset); + + coverage = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_singlepos_format1, coverage)); + value_format = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_singlepos_format1, value_format)); + value_len = dwrite_popcount(value_format); + + if (format == 1) + { + const struct ot_gpos_singlepos_format1 *format1 = table_read_ensure(&cache->gpos.table, subtable_offset, + FIELD_OFFSET(struct ot_gpos_singlepos_format1, value[value_len])); + + coverage_index = opentype_layout_is_glyph_covered(&cache->gpos.table, subtable_offset + coverage, + context->u.pos.glyphs[iter->pos]); + if (coverage_index == GLYPH_NOT_COVERED) + continue; + + opentype_layout_apply_gpos_value(context, subtable_offset, value_format, format1->value, iter->pos); + break; + } + else if (format == 2) + { + WORD value_count = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_singlepos_format2, value_count)); + const struct ot_gpos_singlepos_format2 *format2 = table_read_ensure(&cache->gpos.table, subtable_offset, + FIELD_OFFSET(struct ot_gpos_singlepos_format2, values) + value_count * value_len * sizeof(WORD)); + + coverage_index = opentype_layout_is_glyph_covered(&cache->gpos.table, subtable_offset + coverage, + context->u.pos.glyphs[iter->pos]); + if (coverage_index == GLYPH_NOT_COVERED || coverage_index >= value_count) + continue; + + opentype_layout_apply_gpos_value(context, subtable_offset, value_format, + &format2->values[coverage_index * value_len], iter->pos); + break; + } + else + WARN("Unknown single adjustment format %u.\n", format); + } + return FALSE; }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/opentype.c | 201 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+)
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index 8cc45e4c10..f3c2043ae2 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -586,6 +586,41 @@ struct ot_gpos_singlepos_format2 WORD values[1]; };
+struct ot_gpos_pairvalue +{ + WORD second_glyph; + BYTE data[1]; +}; + +struct ot_gpos_pairset +{ + WORD pairvalue_count; + struct ot_gpos_pairvalue pairvalues[1]; +}; + +struct ot_gpos_pairpos_format1 +{ + WORD format; + WORD coverage; + WORD value_format1; + WORD value_format2; + WORD pairset_count; + WORD pairsets[1]; +}; + +struct ot_gpos_pairpos_format2 +{ + WORD format; + WORD coverage; + WORD value_format1; + WORD value_format2; + WORD class_def1; + WORD class_def2; + WORD class1_count; + WORD class2_count; + WORD values[1]; +}; + typedef struct { WORD SubstFormat; WORD Coverage; @@ -2929,6 +2964,21 @@ static BOOL glyph_iterator_match(const struct glyph_iterator *iter) return TRUE; }
+static BOOL glyph_iterator_next(struct glyph_iterator *iter) +{ + while (iter->pos + iter->len < iter->context->glyph_count) + { + ++iter->pos; + if (glyph_iterator_match(iter)) + { + --iter->len; + return TRUE; + } + } + + return FALSE; +} + static BOOL opentype_layout_apply_gpos_single_adjustment(struct scriptshaping_context *context, struct glyph_iterator *iter, const struct lookup *lookup) { @@ -2985,9 +3035,160 @@ static BOOL opentype_layout_apply_gpos_single_adjustment(struct scriptshaping_co return FALSE; }
+static int gpos_pair_adjustment_compare_format1(const void *g, const void *r) +{ + const struct ot_gpos_pairvalue *pairvalue = r; + UINT16 second_glyph = GET_BE_WORD(pairvalue->second_glyph); + return *(UINT16 *)g - second_glyph; +} + static BOOL opentype_layout_apply_gpos_pair_adjustment(struct scriptshaping_context *context, struct glyph_iterator *iter, const struct lookup *lookup) { + struct scriptshaping_cache *cache = context->cache; + unsigned int i, first_glyph, second_glyph; + struct glyph_iterator iter_pair; + WORD format, coverage; + + glyph_iterator_init(context, iter->flags, iter->pos, 1, &iter_pair); + if (!glyph_iterator_next(&iter_pair)) + return FALSE; + + if (context->is_rtl) + { + first_glyph = iter_pair.pos; + second_glyph = iter->pos; + } + else + { + first_glyph = iter->pos; + second_glyph = iter_pair.pos; + } + + for (i = 0; i < lookup->subtable_count; ++i) + { + unsigned int subtable_offset = opentype_layout_get_gpos_subtable(cache, lookup->offset, i); + WORD value_format1, value_format2, value_len1, value_len2; + unsigned int coverage_index; + + format = table_read_be_word(&cache->gpos.table, subtable_offset); + + coverage = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_pairpos_format1, coverage)); + if (!coverage) + continue; + + coverage_index = opentype_layout_is_glyph_covered(&cache->gpos.table, subtable_offset + + coverage, context->u.pos.glyphs[first_glyph]); + if (coverage_index == GLYPH_NOT_COVERED) + continue; + + if (format == 1) + { + const struct ot_gpos_pairpos_format1 *format1; + WORD pairset_count = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_pairpos_format1, pairset_count)); + unsigned int pairvalue_len, pairset_offset; + const struct ot_gpos_pairset *pairset; + const WORD *pairvalue; + WORD pairvalue_count; + + if (!pairset_count || coverage_index >= pairset_count) + continue; + + format1 = table_read_ensure(&cache->gpos.table, subtable_offset, + FIELD_OFFSET(struct ot_gpos_pairpos_format1, pairsets[pairset_count])); + if (!format1) + continue; + + /* Ordered paired values. */ + pairvalue_count = table_read_be_word(&cache->gpos.table, subtable_offset + + GET_BE_WORD(format1->pairsets[coverage_index])); + if (!pairvalue_count) + continue; + + /* Structure length is variable, but does not change across the subtable. */ + value_format1 = GET_BE_WORD(format1->value_format1) & 0xff; + value_format2 = GET_BE_WORD(format1->value_format2) & 0xff; + + value_len1 = dwrite_popcount(value_format1); + value_len2 = dwrite_popcount(value_format2); + pairvalue_len = FIELD_OFFSET(struct ot_gpos_pairvalue, data) + value_len1 * sizeof(WORD) + + value_len2 * sizeof(WORD); + + pairset_offset = subtable_offset + GET_BE_WORD(format1->pairsets[coverage_index]); + pairset = table_read_ensure(&cache->gpos.table, subtable_offset + pairset_offset, + pairvalue_len * pairvalue_count); + if (!pairset) + continue; + + pairvalue = bsearch(&context->u.pos.glyphs[second_glyph], pairset->pairvalues, pairvalue_count, + pairvalue_len, gpos_pair_adjustment_compare_format1); + if (!pairvalue) + continue; + + pairvalue += 1; /* Skip SecondGlyph. */ + opentype_layout_apply_gpos_value(context, pairset_offset, value_format1, pairvalue, first_glyph); + opentype_layout_apply_gpos_value(context, pairset_offset, value_format2, pairvalue + value_len1, + second_glyph); + + iter->pos = iter_pair.pos; + if (value_len2) + iter->pos++; + + return TRUE; + } + else if (format == 2) + { + const struct ot_gpos_pairpos_format2 *format2; + WORD class1_count, class2_count; + unsigned int class1, class2; + + value_format1 = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_pairpos_format2, value_format1)) & 0xff; + value_format2 = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_pairpos_format2, value_format2)) & 0xff; + + class1_count = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_pairpos_format2, class1_count)); + class2_count = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_pairpos_format2, class2_count)); + + value_len1 = dwrite_popcount(value_format1); + value_len2 = dwrite_popcount(value_format2); + + format2 = table_read_ensure(&cache->gpos.table, subtable_offset, + FIELD_OFFSET(struct ot_gpos_pairpos_format2, + values[class1_count * class2_count * (value_len1 + value_len2)])); + if (!format2) + continue; + + class1 = opentype_layout_get_glyph_class(&cache->gpos.table, subtable_offset + GET_BE_WORD(format2->class_def1), + context->u.pos.glyphs[first_glyph]); + class2 = opentype_layout_get_glyph_class(&cache->gpos.table, subtable_offset + GET_BE_WORD(format2->class_def2), + context->u.pos.glyphs[second_glyph]); + + if (class1 < class1_count && class2 < class2_count) + { + const WCHAR *values = &format2->values[(class1 * class2_count + class2) * (value_len1 + value_len2)]; + opentype_layout_apply_gpos_value(context, subtable_offset, value_format1, values, first_glyph); + opentype_layout_apply_gpos_value(context, subtable_offset, value_format2, values + value_len1, + second_glyph); + + iter->pos = iter_pair.pos; + if (value_len2) + iter->pos++; + + return TRUE; + } + } + else + { + WARN("Unknown pair adjustment format %u.\n", format); + continue; + } + } + return FALSE; }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/analyzer.c | 2 + dlls/dwrite/dwrite_private.h | 1 + dlls/dwrite/opentype.c | 185 +++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+)
diff --git a/dlls/dwrite/analyzer.c b/dlls/dwrite/analyzer.c index 1fc8f98d16..0d8305dbef 100644 --- a/dlls/dwrite/analyzer.c +++ b/dlls/dwrite/analyzer.c @@ -1317,6 +1317,7 @@ static HRESULT WINAPI dwritetextanalyzer_GetGlyphPlacements(IDWriteTextAnalyzer2 context.u.pos.glyph_props = glyph_props; context.glyph_count = glyph_count; context.emsize = emSize; + context.measuring_mode = DWRITE_MEASURING_MODE_NATURAL; context.advances = advances; context.offsets = offsets; context.language_tag = get_opentype_language(locale); @@ -1381,6 +1382,7 @@ static HRESULT WINAPI dwritetextanalyzer_GetGdiCompatibleGlyphPlacements(IDWrite context.u.pos.glyph_props = glyph_props; context.glyph_count = glyph_count; context.emsize = emSize * ppdip; + context.measuring_mode = measuring_mode; context.advances = advances; context.offsets = offsets; context.language_tag = get_opentype_language(locale); diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index 355a826563..0451a7e3f0 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -394,6 +394,7 @@ struct scriptshaping_context
unsigned int glyph_count; float emsize; + DWRITE_MEASURING_MODE measuring_mode; float *advances; DWRITE_GLYPH_OFFSET *offsets; }; diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index f3c2043ae2..e9c755e51b 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -621,6 +621,38 @@ struct ot_gpos_pairpos_format2 WORD values[1]; };
+struct ot_gpos_anchor_format1 +{ + WORD format; + short x_coord; + short y_coord; +}; + +struct ot_gpos_anchor_format2 +{ + WORD format; + short x_coord; + short y_coord; + WORD anchor_point; +}; + +struct ot_gpos_anchor_format3 +{ + WORD format; + short x_coord; + short y_coord; + WORD x_dev_offset; + WORD y_dev_offset; +}; + +struct ot_gpos_cursive_format1 +{ + WORD format; + WORD coverage; + WORD count; + WORD anchors[1]; +}; + typedef struct { WORD SubstFormat; WORD Coverage; @@ -2979,6 +3011,24 @@ static BOOL glyph_iterator_next(struct glyph_iterator *iter) return FALSE; }
+static BOOL glyph_iterator_prev(struct glyph_iterator *iter) +{ + if (!iter->pos) + return FALSE; + + while (iter->pos > iter->len - 1) + { + --iter->pos; + if (glyph_iterator_match(iter)) + { + --iter->len; + return TRUE; + } + } + + return FALSE; +} + static BOOL opentype_layout_apply_gpos_single_adjustment(struct scriptshaping_context *context, struct glyph_iterator *iter, const struct lookup *lookup) { @@ -3192,9 +3242,144 @@ static BOOL opentype_layout_apply_gpos_pair_adjustment(struct scriptshaping_cont return FALSE; }
+static void opentype_layout_gpos_get_anchor(const struct scriptshaping_context *context, unsigned int anchor_offset, + unsigned int glyph_index, float *x, float *y) +{ + const struct scriptshaping_cache *cache = context->cache; + + WORD format = table_read_be_word(&cache->gpos.table, anchor_offset); + + *x = *y = 0.0f; + + if (format == 1) + { + const struct ot_gpos_anchor_format1 *format1 = table_read_ensure(&cache->gpos.table, anchor_offset, + sizeof(*format1)); + + if (format1) + { + *x = opentype_scale_gpos_be_value(format1->x_coord, context->emsize, cache->upem); + *y = opentype_scale_gpos_be_value(format1->y_coord, context->emsize, cache->upem); + } + } + else if (format == 2) + { + const struct ot_gpos_anchor_format2 *format2 = table_read_ensure(&cache->gpos.table, anchor_offset, + sizeof(*format2)); + + if (format2) + { + if (context->measuring_mode != DWRITE_MEASURING_MODE_NATURAL) + FIXME("Use outline anchor point for glyph %u.\n", context->u.pos.glyphs[glyph_index]); + + *x = opentype_scale_gpos_be_value(format2->x_coord, context->emsize, cache->upem); + *y = opentype_scale_gpos_be_value(format2->y_coord, context->emsize, cache->upem); + } + } + else if (format == 3) + { + const struct ot_gpos_anchor_format3 *format3 = table_read_ensure(&cache->gpos.table, anchor_offset, + sizeof(*format3)); + + if (format3) + { + *x = opentype_scale_gpos_be_value(format3->x_coord, context->emsize, cache->upem); + *y = opentype_scale_gpos_be_value(format3->y_coord, context->emsize, cache->upem); + + if (context->measuring_mode != DWRITE_MEASURING_MODE_NATURAL) + { + if (format3->x_dev_offset) + *x += opentype_layout_gpos_get_dev_value(context, anchor_offset + GET_BE_WORD(format3->x_dev_offset)); + if (format3->y_dev_offset) + *y += opentype_layout_gpos_get_dev_value(context, anchor_offset + GET_BE_WORD(format3->y_dev_offset)); + } + } + } + else + WARN("Unknown anchor format %u.\n", format); +} + static BOOL opentype_layout_apply_gpos_cursive_attachment(struct scriptshaping_context *context, struct glyph_iterator *iter, const struct lookup *lookup) { + struct scriptshaping_cache *cache = context->cache; + unsigned int i; + + for (i = 0; i < lookup->subtable_count; ++i) + { + unsigned int subtable_offset = opentype_layout_get_gpos_subtable(cache, lookup->offset, i); + WORD format; + + format = table_read_be_word(&cache->gpos.table, subtable_offset); + + if (format == 1) + { + WORD coverage_offset = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_cursive_format1, coverage)); + unsigned int glyph_index, entry_count, entry_anchor, exit_anchor; + float entry_x, entry_y, exit_x, exit_y, delta; + struct glyph_iterator prev_iter; + + if (!coverage_offset) + continue; + + entry_count = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_cursive_format1, count)); + + glyph_index = opentype_layout_is_glyph_covered(&cache->gpos.table, subtable_offset + + coverage_offset, context->u.pos.glyphs[iter->pos]); + if (glyph_index == GLYPH_NOT_COVERED || glyph_index >= entry_count) + continue; + + entry_anchor = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_cursive_format1, anchors[glyph_index * 2])); + if (!entry_anchor) + continue; + + glyph_iterator_init(context, iter->flags, iter->pos, 1, &prev_iter); + if (!glyph_iterator_prev(&prev_iter)) + continue; + + glyph_index = opentype_layout_is_glyph_covered(&cache->gpos.table, subtable_offset + + coverage_offset, context->u.pos.glyphs[prev_iter.pos]); + if (glyph_index == GLYPH_NOT_COVERED || glyph_index >= entry_count) + continue; + + exit_anchor = table_read_be_word(&cache->gpos.table, subtable_offset + + FIELD_OFFSET(struct ot_gpos_cursive_format1, anchors[glyph_index * 2 + 1])); + if (!exit_anchor) + continue; + + opentype_layout_gpos_get_anchor(context, subtable_offset + exit_anchor, prev_iter.pos, &exit_x, &exit_y); + opentype_layout_gpos_get_anchor(context, subtable_offset + entry_anchor, iter->pos, &entry_x, &entry_y); + + if (context->is_rtl) + { + delta = exit_x + context->offsets[prev_iter.pos].advanceOffset; + context->advances[prev_iter.pos] -= delta; + context->advances[iter->pos] = entry_x + context->offsets[iter->pos].advanceOffset; + context->offsets[prev_iter.pos].advanceOffset -= delta; + } + else + { + delta = entry_x + context->offsets[iter->pos].advanceOffset; + context->advances[prev_iter.pos] = exit_x + context->offsets[prev_iter.pos].advanceOffset; + context->advances[iter->pos] -= delta; + context->offsets[iter->pos].advanceOffset -= delta; + } + + if (lookup->flags & LOOKUP_FLAG_RTL) + context->offsets[prev_iter.pos].ascenderOffset = entry_y - exit_y; + else + context->offsets[iter->pos].ascenderOffset = exit_y - entry_y; + + break; + } + else + WARN("Unknown cursive attachment format %u.\n", format); + + } + return FALSE; }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/opentype.c | 105 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+)
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index e9c755e51b..92a5d40dfc 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -653,6 +653,34 @@ struct ot_gpos_cursive_format1 WORD anchors[1]; };
+struct ot_gpos_mark_record +{ + WORD mark_class; + WORD mark_anchor; +}; + +struct ot_gpos_mark_array +{ + WORD count; + struct ot_gpos_mark_record records[1]; +}; + +struct ot_gpos_base_array +{ + WORD count; + WORD offsets[1]; +}; + +struct ot_gpos_mark_to_base_format1 +{ + WORD format; + WORD mark_coverage; + WORD base_coverage; + WORD mark_class_count; + WORD mark_array; + WORD base_array; +}; + typedef struct { WORD SubstFormat; WORD Coverage; @@ -3386,6 +3414,83 @@ static BOOL opentype_layout_apply_gpos_cursive_attachment(struct scriptshaping_c static BOOL opentype_layout_apply_gpos_mark_to_base_attachment(const struct scriptshaping_context *context, struct glyph_iterator *iter, const struct lookup *lookup) { + struct scriptshaping_cache *cache = context->cache; + unsigned int i; + WORD format; + + for (i = 0; i < lookup->subtable_count; ++i) + { + unsigned int subtable_offset = opentype_layout_get_gpos_subtable(cache, lookup->offset, i); + + format = table_read_be_word(&cache->gpos.table, subtable_offset); + + if (format == 1) + { + const struct ot_gpos_mark_to_base_format1 *format1 = table_read_ensure(&cache->gpos.table, subtable_offset, + sizeof(*format1)); + unsigned int mark_class_count, count, mark_array_offset, base_array_offset; + const struct ot_gpos_mark_array *mark_array; + const struct ot_gpos_base_array *base_array; + float mark_x, mark_y, base_x, base_y; + unsigned int base_index, mark_index; + struct glyph_iterator base_iter; + unsigned int base_anchor; + + if (!format1) + continue; + + mark_array_offset = subtable_offset + GET_BE_WORD(format1->mark_array); + if (!(count = table_read_be_word(&cache->gpos.table, mark_array_offset))) + continue; + + mark_array = table_read_ensure(&cache->gpos.table, mark_array_offset, + FIELD_OFFSET(struct ot_gpos_mark_array, records[count])); + if (!mark_array) + continue; + + base_array_offset = subtable_offset + GET_BE_WORD(format1->base_array); + if (!(count = table_read_be_word(&cache->gpos.table, base_array_offset))) + continue; + + base_array = table_read_ensure(&cache->gpos.table, base_array_offset, + FIELD_OFFSET(struct ot_gpos_base_array, offsets[count * GET_BE_WORD(format1->mark_class_count)])); + if (!base_array) + continue; + + mark_class_count = GET_BE_WORD(format1->mark_class_count); + + mark_index = opentype_layout_is_glyph_covered(&cache->gpos.table, subtable_offset + + GET_BE_WORD(format1->mark_coverage), context->u.pos.glyphs[iter->pos]); + + if (mark_index == GLYPH_NOT_COVERED || mark_index >= GET_BE_WORD(mark_array->count)) + continue; + + /* Look back for first base glyph. */ + glyph_iterator_init(context, LOOKUP_FLAG_IGNORE_MARKS, iter->pos, 1, &base_iter); + if (!glyph_iterator_prev(&base_iter)) + continue; + + base_index = opentype_layout_is_glyph_covered(&cache->gpos.table, subtable_offset + + GET_BE_WORD(format1->base_coverage), context->u.pos.glyphs[base_iter.pos]); + if (base_index == GLYPH_NOT_COVERED || base_index >= GET_BE_WORD(base_array->count)) + continue; + + base_anchor = GET_BE_WORD(base_array->offsets[base_index * mark_class_count + + GET_BE_WORD(mark_array->records[mark_index].mark_class)]); + + opentype_layout_gpos_get_anchor(context, mark_array_offset + + GET_BE_WORD(mark_array->records[mark_index].mark_anchor), iter->pos, &mark_x, &mark_y); + opentype_layout_gpos_get_anchor(context, base_array_offset + base_anchor, base_iter.pos, &base_x, &base_y); + + context->offsets[iter->pos].advanceOffset = (context->is_rtl ? -1.0f : 1.0f) * (base_x - mark_x); + context->offsets[iter->pos].ascenderOffset = base_y - mark_y; + + break; + } + else + WARN("Unknown mark-to-base format %u.\n", format); + } + return FALSE; }