summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Hung <marklh9@gmail.com>2021-05-02 15:12:46 +0800
committerMark Hung <marklh9@gmail.com>2021-05-05 16:06:15 +0200
commitdd0d0b44fd1c6c0292d7b2eb3f5cf2baa21e4481 (patch)
tree4acf78cce5976019116b99cfa4830074eea223ce
parentbb9a3f1cd2912b836deb9f73c2010bf03a1438c9 (diff)
vcl: adjust LayoutText() for vertical writing.
Revert 58af692e2814 "tdf#111967 translate offsets so it is relative to vorigin", which use hb_font_add_glyph_origin_for_direction to change the origin for vertical writing. This caused major problem in Y-axis. For X-axis, align the baseline of the vertical run to the center of the rotated horizontal run, by adding "(ascender + descener) / 2. Besides the alignment mentioned above, underlying text rendering code should be able to render properly based on the positions that Harfbuzz API creates. Change-Id: Ic1ef1f734686d0e61c4b2a6bf7feb7c870bba84f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115014 Tested-by: Jenkins Reviewed-by: Mark Hung <marklh9@gmail.com>
-rw-r--r--vcl/source/gdi/CommonSalLayout.cxx21
1 files changed, 13 insertions, 8 deletions
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index 5565b3eb4d69..801abdd16670 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -325,6 +325,18 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphsIm
pTextLayout = pNewScriptRun.get();
}
+ // nBaseOffset is used to align vertical text to the center of rotated
+ // horizontal text. That is the offset from original baseline to
+ // the center of EM box. Maybe we can use OpenType base table to improve this
+ // in the future.
+ DeviceCoordinate nBaseOffset = 0;
+ if (rArgs.mnFlags & SalLayoutFlags::Vertical)
+ {
+ hb_font_extents_t extents;
+ if (hb_font_get_h_extents(pHbFont, &extents))
+ nBaseOffset = ( extents.ascender + extents.descender ) / 2;
+ }
+
hb_buffer_t* pHbBuffer = hb_buffer_create();
hb_buffer_pre_allocate(pHbBuffer, nGlyphCapacity);
#if !HB_VERSION_ATLEAST(1, 1, 0)
@@ -583,16 +595,9 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphsIm
{
nGlyphFlags |= GlyphItemFlags::IS_VERTICAL;
- // We have glyph offsets that is relative to h origin now,
- // add the origin back so it is relative to v origin.
- hb_font_add_glyph_origin_for_direction(pHbFont,
- nGlyphIndex,
- HB_DIRECTION_TTB,
- &pHbPositions[i].x_offset ,
- &pHbPositions[i].y_offset );
nAdvance = -pHbPositions[i].y_advance;
nXOffset = -pHbPositions[i].y_offset;
- nYOffset = -pHbPositions[i].x_offset;
+ nYOffset = -pHbPositions[i].x_offset - nBaseOffset;
}
else
{