vcl/source/gdi/CommonSalLayout.cxx |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

New commits:
commit dd0d0b44fd1c6c0292d7b2eb3f5cf2baa21e4481
Author:     Mark Hung <mark...@gmail.com>
AuthorDate: Sun May 2 15:12:46 2021 +0800
Commit:     Mark Hung <mark...@gmail.com>
CommitDate: Wed May 5 16:06:15 2021 +0200

    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 <mark...@gmail.com>

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
                 {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to