Skip to content

Instantly share code, notes, and snippets.

@rcombs
Last active December 28, 2023 10:53
Show Gist options
  • Save rcombs/69e9e7ec9cea11859855ef255dfe5fb2 to your computer and use it in GitHub Desktop.
Save rcombs/69e9e7ec9cea11859855ef255dfe5fb2 to your computer and use it in GitHub Desktop.
diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c
index f4e7367..a926a2c 100644
--- a/libass/ass_shaper.c
+++ b/libass/ass_shaper.c
@@ -255,8 +255,8 @@ size_t ass_glyph_metrics_construct(void *key, void *value, void *priv)
// if @font rendering is enabled and the glyph should be rotated,
// make cached_h_advance pick up the right advance later
- if (k->vertical)
- v->horiAdvance = v->vertAdvance;
+/* if (k->vertical)
+ v->horiAdvance = v->vertAdvance;*/
return 1;
}
@@ -639,6 +639,9 @@ shape_harfbuzz_process_run(GlyphInfo *glyphs, hb_buffer_t *buf, int offset)
hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buf, NULL);
hb_glyph_position_t *pos = hb_buffer_get_glyph_positions(buf, NULL);
+ bool v = glyphs[offset].font->desc.vertical;
+#define VERT(name, vert) (vert ? (-pos[j].y_ ##name) : (pos[j].x_ ## name))
+
for (j = 0; j < num_glyphs; j++) {
unsigned idx = glyph_info[j].cluster + offset;
GlyphInfo *info = glyphs + idx;
@@ -661,10 +664,10 @@ shape_harfbuzz_process_run(GlyphInfo *glyphs, hb_buffer_t *buf, int offset)
// set position and advance
info->skip = false;
info->glyph_index = glyph_info[j].codepoint;
- info->offset.x = lrint(pos[j].x_offset * info->scale_x);
- info->offset.y = lrint(-pos[j].y_offset * info->scale_y);
- info->advance.x = lrint(pos[j].x_advance * info->scale_x);
- info->advance.y = lrint(-pos[j].y_advance * info->scale_y);
+ info->offset.x = lrint(VERT(offset, v) * info->scale_x);
+ info->offset.y = lrint(VERT(offset, !v) * info->scale_y);
+ info->advance.x = lrint(VERT(advance, v) * info->scale_x);
+ info->advance.y = lrint(VERT(advance, !v) * info->scale_y);
// accumulate advance in the root glyph
root->cluster_advance.x += info->advance.x;
@@ -725,8 +728,10 @@ static bool shape_harfbuzz(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len)
lead_context, i - offset + 1);
}
- props.direction = FRIBIDI_LEVEL_IS_RTL(level) ?
- HB_DIRECTION_RTL : HB_DIRECTION_LTR;
+ props.direction = glyphs[offset].font->desc.vertical ? HB_DIRECTION_TTB : HB_DIRECTION_LTR;
+ if (FRIBIDI_LEVEL_IS_RTL(level))
+ props.direction = HB_DIRECTION_REVERSE(props.direction);
+
props.script = glyphs[offset].script;
props.language = hb_shaper_get_run_language(shaper, props.script);
hb_buffer_set_segment_properties(buf, &props);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment