vcl/inc/font/LogicalFontInstance.hxx           |    4 ++++
 vcl/quartz/ctfonts.cxx                         |    2 +-
 vcl/skia/x11/textrender.cxx                    |    2 +-
 vcl/source/gdi/pdfwriter_impl.cxx              |    2 +-
 vcl/unx/generic/gdi/cairotextrender.cxx        |    2 +-
 vcl/unx/generic/glyphs/freetype_glyphcache.cxx |    4 ++--
 6 files changed, 10 insertions(+), 6 deletions(-)

New commits:
commit f88e7632b745a9b18af36cd901399c40e8b7378f
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Sat Nov 19 20:55:50 2022 +0200
Commit:     خالد حسني <kha...@aliftype.com>
CommitDate: Sun Nov 20 19:45:38 2022 +0100

    vcl: unify skew for artificial italic
    
    Cairo, Skia, Core Text, and PDF all were using slightly different skew
    for artificial italic.
    
    On Windows, we don’t even apply the skew ourselves and let DirectWrite
    apply it.
    
    The value chosen here should be the same as the one applied by
    DirectWrite for consistency (measured manually, and confirmed against:
    
https://source.winehq.org/git/wine.git/blob/5d1820c40bd93e6810f072a39745ee739ba99b81:/dlls/dwrite/freetype.c#l467)
    
    Change-Id: I3ab017b4cd7a3b4dba097cd302333a88e4c16350
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142980
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>

diff --git a/vcl/inc/font/LogicalFontInstance.hxx 
b/vcl/inc/font/LogicalFontInstance.hxx
index 21c09dbafca0..8887a5d77a1d 100644
--- a/vcl/inc/font/LogicalFontInstance.hxx
+++ b/vcl/inc/font/LogicalFontInstance.hxx
@@ -42,6 +42,10 @@
 class ConvertChar;
 class ImplFontCache;
 
+constexpr float ARTIFICIAL_ITALIC_MATRIX_XX = 1 << 16;
+constexpr float ARTIFICIAL_ITALIC_MATRIX_XY = (1 << 16) / 3.f;
+constexpr float ARTIFICIAL_ITALIC_SKEW = ARTIFICIAL_ITALIC_MATRIX_XY / 
ARTIFICIAL_ITALIC_MATRIX_XX;
+
 // extend std namespace to add custom hash needed for LogicalFontInstance
 
 namespace std
diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx
index 92fd35fa2cee..1f7be532db31 100644
--- a/vcl/quartz/ctfonts.cxx
+++ b/vcl/quartz/ctfonts.cxx
@@ -76,7 +76,7 @@ CoreTextFont::CoreTextFont(const CoreTextFontFace& rPFF, 
const vcl::font::FontSe
          (rFSP.GetItalic() == ITALIC_OBLIQUE)) &&
         (rPFF.GetItalic() == ITALIC_NONE))
     {
-        aMatrix = CGAffineTransformConcat(aMatrix, CGAffineTransformMake(1, 0, 
basegfx::deg2rad(12), 1, 0, 0));
+        aMatrix = CGAffineTransformConcat(aMatrix, CGAffineTransformMake(1, 0, 
ARTIFICIAL_ITALIC_SKEW, 1, 0, 0));
     }
 
     CTFontDescriptorRef pFontDesc = rPFF.GetFontDescriptorRef();
diff --git a/vcl/skia/x11/textrender.cxx b/vcl/skia/x11/textrender.cxx
index 153551e12ddd..c97e2b6cf3cb 100644
--- a/vcl/skia/x11/textrender.cxx
+++ b/vcl/skia/x11/textrender.cxx
@@ -51,7 +51,7 @@ void SkiaTextRender::DrawTextLayout(const GenericSalLayout& 
rLayout, const SalGr
     font.setSize(nHeight);
     font.setScaleX(1.0 * nWidth / nHeight);
     if (rFont.NeedsArtificialItalic())
-        font.setSkewX(1.0 * -0x4000L / 0x10000L);
+        font.setSkewX(-1.0 * ARTIFICIAL_ITALIC_SKEW);
     if (rFont.NeedsArtificialBold())
         font.setEmbolden(true);
 
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index b95898f4b2bc..8db18ef6a6ad 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -6504,7 +6504,7 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const 
OUString& rText, bool
            GetFontInstance()->GetFontFace()->GetItalic() != ITALIC_OBLIQUE )
         )
     {
-        fSkew = M_PI/12.0;
+        fSkew = ARTIFICIAL_ITALIC_SKEW;
     }
 
     // if the mapmode is distorted we need to adjust for that also
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx 
b/vcl/unx/generic/gdi/cairotextrender.cxx
index 6f462b4e3377..81d3b532c12a 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -344,7 +344,7 @@ void CairoTextRender::DrawTextLayout(const 
GenericSalLayout& rLayout, const SalG
         {
             cairo_matrix_t shear;
             cairo_matrix_init_identity(&shear);
-            shear.xy = -shear.xx * 0x6000L / 0x10000L;
+            shear.xy = -shear.xx * ARTIFICIAL_ITALIC_SKEW;
             cairo_matrix_multiply(&m, &shear, &m);
         }
 
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx 
b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index 4cc30ea3c21a..d4a50b0f0167 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -858,8 +858,8 @@ bool FreetypeFont::GetGlyphOutline(sal_GlyphId nId, 
basegfx::B2DPolyPolygon& rB2
     if( mbArtItalic )
     {
         FT_Matrix aMatrix;
-        aMatrix.xx = aMatrix.yy = 0x10000L;
-        aMatrix.xy = 0x6000L;
+        aMatrix.xx = aMatrix.yy = ARTIFICIAL_ITALIC_MATRIX_XX;
+        aMatrix.xy = ARTIFICIAL_ITALIC_MATRIX_XY;
         aMatrix.yx = 0;
         FT_Glyph_Transform( pGlyphFT, &aMatrix, nullptr );
     }

Reply via email to