| 1 | diff -ruN a/src/direct_write.rs b/src/direct_write.rs |
| 2 | --- a/src/direct_write.rs |
| 3 | +++ b/src/direct_write.rs |
| 4 | @@ -1505,7 +1505,7 @@ |
| 5 | fn DrawGlyphRun( |
| 6 | &self, |
| 7 | clientdrawingcontext: *const ::core::ffi::c_void, |
| 8 | - _baselineoriginx: f32, |
| 9 | + baselineoriginx: f32, |
| 10 | _baselineoriginy: f32, |
| 11 | _measuringmode: DWRITE_MEASURING_MODE, |
| 12 | glyphrun: *const DWRITE_GLYPH_RUN, |
| 13 | @@ -1590,6 +1590,8 @@ |
| 14 | )? |
| 15 | }; |
| 16 | |
| 17 | + let right_to_left = glyphrun.bidiLevel % 2 == 1; |
| 18 | + let mut pen_x = baselineoriginx; |
| 19 | let cluster_analyzer = ClusterAnalyzer::new(cluster_map, glyph_count); |
| 20 | let mut utf16_idx = desc.textPosition as usize; |
| 21 | let mut glyph_idx = 0; |
| 22 | @@ -1606,16 +1608,25 @@ |
| 23 | let is_emoji = |
| 24 | color_font && is_color_glyph(font_face, id, &context.components.factory); |
| 25 | let this_glyph_idx = glyph_idx + cluster_glyph_idx; |
| 26 | + let advance = glyph_advances[this_glyph_idx]; |
| 27 | + let advance_offset = glyph_offsets[this_glyph_idx].advanceOffset; |
| 28 | + // DirectWrite hands right-to-left runs over in logical order, drawn leftwards from the run's visual origin. |
| 29 | + let glyph_x = if right_to_left { |
| 30 | + pen_x - advance - advance_offset |
| 31 | + } else { |
| 32 | + pen_x + advance_offset |
| 33 | + }; |
| 34 | + pen_x += if right_to_left { -advance } else { advance }; |
| 35 | glyphs.push(ShapedGlyph { |
| 36 | id, |
| 37 | position: point( |
| 38 | - px(context.width + glyph_offsets[this_glyph_idx].advanceOffset), |
| 39 | + px(glyph_x), |
| 40 | px(-glyph_offsets[this_glyph_idx].ascenderOffset), |
| 41 | ), |
| 42 | index: context.index_converter.utf8_ix, |
| 43 | is_emoji, |
| 44 | }); |
| 45 | - context.width += glyph_advances[this_glyph_idx]; |
| 46 | + context.width += advance; |
| 47 | } |
| 48 | glyph_idx += cluster_glyph_count; |
| 49 | } |