From 7bcc18ac67181d10d3479b3100647aceddd86750 Mon Sep 17 00:00:00 2001 From: "Armin Le Grand (Allotropia)" Date: Thu, 18 Nov 2021 18:06:39 +0100 Subject: Qt implement QtFont::GetGlyphOutline Fixes FontWork with QFont based rendering. Change-Id: I294fe89d2753b6e82a559ff847b44126f9ea3bfc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125500 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski --- vcl/qt5/QtFont.cxx | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'vcl') diff --git a/vcl/qt5/QtFont.cxx b/vcl/qt5/QtFont.cxx index a9d84e897c1b..07bf9f541f0b 100644 --- a/vcl/qt5/QtFont.cxx +++ b/vcl/qt5/QtFont.cxx @@ -24,6 +24,7 @@ #include #include +#include static inline void applyWeight(QtFont& rFont, FontWeight eWeight) { @@ -151,7 +152,61 @@ hb_font_t* QtFont::ImplInitHbFont() return InitHbFont(hb_face_create_for_tables(getFontTable, this, nullptr)); } -bool QtFont::GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const { return false; } +bool QtFont::GetGlyphOutline(sal_GlyphId nId, basegfx::B2DPolyPolygon& rB2DPolyPoly, bool) const +{ + rB2DPolyPoly.clear(); + basegfx::B2DPolygon aPart; + QRawFont aRawFont(QRawFont::fromFont(*this)); + QPainterPath aQPath = aRawFont.pathForGlyph(nId); + + for (int a(0); a < aQPath.elementCount(); a++) + { + const QPainterPath::Element aQElement = aQPath.elementAt(a); + + switch (aQElement.type) + { + case QPainterPath::MoveToElement: + { + if (aPart.count()) + { + aPart.setClosed(true); + rB2DPolyPoly.append(aPart); + aPart.clear(); + } + + aPart.append(basegfx::B2DPoint(aQElement.x, aQElement.y)); + break; + } + case QPainterPath::LineToElement: + { + aPart.append(basegfx::B2DPoint(aQElement.x, aQElement.y)); + break; + } + case QPainterPath::CurveToElement: + { + const QPainterPath::Element aQ2 = aQPath.elementAt(++a); + const QPainterPath::Element aQ3 = aQPath.elementAt(++a); + aPart.appendBezierSegment(basegfx::B2DPoint(aQElement.x, aQElement.y), + basegfx::B2DPoint(aQ2.x, aQ2.y), + basegfx::B2DPoint(aQ3.x, aQ3.y)); + break; + } + case QPainterPath::CurveToDataElement: + { + break; + } + } + } + + if (aPart.count()) + { + aPart.setClosed(true); + rB2DPolyPoly.append(aPart); + aPart.clear(); + } + + return true; +} bool QtFont::ImplGetGlyphBoundRect(sal_GlyphId nId, tools::Rectangle& rRect, bool) const { -- cgit