solenv/clang-format/excludelist | 2 - vcl/inc/font/PhysicalFontFace.hxx | 32 +++++++++++--------- vcl/inc/unx/fontmanager.hxx | 4 +- vcl/source/font/PhysicalFontFace.cxx | 43 ++++++++++++++-------------- vcl/unx/generic/fontmanager/fontmanager.cxx | 40 +++++++++----------------- vcl/unx/generic/print/genpspgraphics.cxx | 8 ----- 6 files changed, 59 insertions(+), 70 deletions(-)
New commits: commit 262df14af32be6855b276dcf7548d3b233076ec6 Author: Khaled Hosny <kha...@aliftype.com> AuthorDate: Mon Sep 5 01:35:35 2022 +0200 Commit: خالد حسني <kha...@aliftype.com> CommitDate: Mon Sep 5 06:51:21 2022 +0200 vcl: Format PhysicalFontFace.{cxx,hxx} They are small files, lets format before adding more code. Change-Id: I5e8e7e4031f045cf6e124dd533e37ab67f34e985 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139394 Tested-by: Jenkins Reviewed-by: خالد حسني <kha...@aliftype.com> diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index db4a72c0fe34..bca76db5a595 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -14315,7 +14315,6 @@ vcl/inc/factory.hxx vcl/inc/fltcall.hxx vcl/inc/font/FontSelectPattern.hxx vcl/inc/font/PhysicalFontCollection.hxx -vcl/inc/font/PhysicalFontFace.hxx vcl/inc/fontattributes.hxx vcl/inc/fontinstance.hxx vcl/inc/fontsubset.hxx @@ -14812,7 +14811,6 @@ vcl/source/filter/wmf/wmfwr.hxx vcl/source/font/DirectFontSubstitution.cxx vcl/source/font/FontSelectPattern.cxx vcl/source/font/PhysicalFontCollection.cxx -vcl/source/font/PhysicalFontFace.cxx vcl/source/font/PhysicalFontFamily.cxx vcl/source/font/font.cxx vcl/source/font/fontattributes.cxx diff --git a/vcl/inc/font/PhysicalFontFace.hxx b/vcl/inc/font/PhysicalFontFace.hxx index 52acaacf08ec..ee65766fadbd 100644 --- a/vcl/inc/font/PhysicalFontFace.hxx +++ b/vcl/inc/font/PhysicalFontFace.hxx @@ -51,8 +51,8 @@ class FontSelectPattern; struct FontMatchStatus { public: - int mnFaceMatch; - const OUString* mpTargetStyleName; + int mnFaceMatch; + const OUString* mpTargetStyleName; }; // TODO: no more direct access to members @@ -65,31 +65,35 @@ public: * It acts as a factory for its corresponding LogicalFontInstances and * can be extended to cache device and font instance specific data. */ -class VCL_PLUGIN_PUBLIC PhysicalFontFace : public FontAttributes, public salhelper::SimpleReferenceObject +class VCL_PLUGIN_PUBLIC PhysicalFontFace : public FontAttributes, + public salhelper::SimpleReferenceObject { public: ~PhysicalFontFace(); - virtual rtl::Reference<LogicalFontInstance> CreateFontInstance(const vcl::font::FontSelectPattern&) const = 0; + virtual rtl::Reference<LogicalFontInstance> + CreateFontInstance(const vcl::font::FontSelectPattern&) const = 0; - virtual sal_IntPtr GetFontId() const = 0; - virtual FontCharMapRef GetFontCharMap() const; + virtual sal_IntPtr GetFontId() const = 0; + virtual FontCharMapRef GetFontCharMap() const; virtual bool GetFontCapabilities(vcl::FontCapabilities&) const = 0; - bool IsBetterMatch( const vcl::font::FontSelectPattern&, FontMatchStatus& ) const; - sal_Int32 CompareIgnoreSize( const PhysicalFontFace& ) const; + bool IsBetterMatch(const vcl::font::FontSelectPattern&, FontMatchStatus&) const; + sal_Int32 CompareIgnoreSize(const PhysicalFontFace&) const; - virtual hb_face_t* GetHbFace() const; - virtual hb_blob_t* GetHbTable(hb_tag_t) const { assert(false); return nullptr; } + virtual hb_face_t* GetHbFace() const; + virtual hb_blob_t* GetHbTable(hb_tag_t) const + { + assert(false); + return nullptr; + } protected: - mutable hb_face_t* mpHbFace; - mutable FontCharMapRef mxCharMap; + mutable hb_face_t* mpHbFace; + mutable FontCharMapRef mxCharMap; explicit PhysicalFontFace(const FontAttributes&); }; - } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ - diff --git a/vcl/source/font/PhysicalFontFace.cxx b/vcl/source/font/PhysicalFontFace.cxx index 917295f6b50b..2b095059de6b 100644 --- a/vcl/source/font/PhysicalFontFace.cxx +++ b/vcl/source/font/PhysicalFontFace.cxx @@ -34,15 +34,14 @@ namespace vcl::font { - -PhysicalFontFace::PhysicalFontFace( const FontAttributes& rDFA ) - : FontAttributes( rDFA ) +PhysicalFontFace::PhysicalFontFace(const FontAttributes& rDFA) + : FontAttributes(rDFA) , mpHbFace(nullptr) { // StarSymbol is a unicode font, but it still deserves the symbol flag - if( !IsSymbolFont() ) - if ( IsStarSymbol( GetFamilyName() ) ) - SetSymbolFlag( true ); + if (!IsSymbolFont()) + if (IsStarSymbol(GetFamilyName())) + SetSymbolFlag(true); } PhysicalFontFace::~PhysicalFontFace() @@ -51,29 +50,29 @@ PhysicalFontFace::~PhysicalFontFace() hb_face_destroy(mpHbFace); } -sal_Int32 PhysicalFontFace::CompareIgnoreSize( const PhysicalFontFace& rOther ) const +sal_Int32 PhysicalFontFace::CompareIgnoreSize(const PhysicalFontFace& rOther) const { // compare their width, weight, italic, style name and family name - if( GetWidthType() < rOther.GetWidthType() ) + if (GetWidthType() < rOther.GetWidthType()) return -1; - else if( GetWidthType() > rOther.GetWidthType() ) + else if (GetWidthType() > rOther.GetWidthType()) return 1; - if( GetWeight() < rOther.GetWeight() ) + if (GetWeight() < rOther.GetWeight()) return -1; - else if( GetWeight() > rOther.GetWeight() ) + else if (GetWeight() > rOther.GetWeight()) return 1; - if( GetItalic() < rOther.GetItalic() ) + if (GetItalic() < rOther.GetItalic()) return -1; - else if( GetItalic() > rOther.GetItalic() ) + else if (GetItalic() > rOther.GetItalic()) return 1; - sal_Int32 nRet = GetFamilyName().compareTo( rOther.GetFamilyName() ); + sal_Int32 nRet = GetFamilyName().compareTo(rOther.GetFamilyName()); if (nRet == 0) { - nRet = GetStyleName().compareTo( rOther.GetStyleName() ); + nRet = GetStyleName().compareTo(rOther.GetStyleName()); } return nRet; @@ -91,7 +90,8 @@ static int FamilyNameMatchValue(FontSelectPattern const& rFSP, std::u16string_vi static int StyleNameMatchValue(FontMatchStatus const& rStatus, std::u16string_view rStyle) { - if (rStatus.mpTargetStyleName && o3tl::equalsIgnoreAsciiCase(rStyle, *rStatus.mpTargetStyleName)) + if (rStatus.mpTargetStyleName + && o3tl::equalsIgnoreAsciiCase(rStyle, *rStatus.mpTargetStyleName)) return 120000; return 0; @@ -181,7 +181,7 @@ static int ItalicMatchValue(FontSelectPattern const& rFSP, FontItalic eItalic) return 0; } -bool PhysicalFontFace::IsBetterMatch( const FontSelectPattern& rFSP, FontMatchStatus& rStatus ) const +bool PhysicalFontFace::IsBetterMatch(const FontSelectPattern& rFSP, FontMatchStatus& rStatus) const { int nMatch = FamilyNameMatchValue(rFSP, GetFamilyName()); nMatch += StyleNameMatchValue(rStatus, GetStyleName()); @@ -197,13 +197,13 @@ bool PhysicalFontFace::IsBetterMatch( const FontSelectPattern& rFSP, FontMatchSt else nMatch += 5; - if( rStatus.mnFaceMatch > nMatch ) + if (rStatus.mnFaceMatch > nMatch) { return false; } - else if( rStatus.mnFaceMatch < nMatch ) + else if (rStatus.mnFaceMatch < nMatch) { - rStatus.mnFaceMatch = nMatch; + rStatus.mnFaceMatch = nMatch; return true; } @@ -218,7 +218,8 @@ static hb_blob_t* getTable(hb_face_t*, hb_tag_t nTag, void* pUserData) hb_face_t* PhysicalFontFace::GetHbFace() const { if (mpHbFace == nullptr) - mpHbFace = hb_face_create_for_tables(getTable, const_cast<PhysicalFontFace*>(this), nullptr); + mpHbFace + = hb_face_create_for_tables(getTable, const_cast<PhysicalFontFace*>(this), nullptr); return mpHbFace; } commit 0e2b9be640118cde6bb8dc1350cb619000969683 Author: Khaled Hosny <kha...@aliftype.com> AuthorDate: Sun Sep 4 20:39:30 2022 +0200 Commit: خالد حسني <kha...@aliftype.com> CommitDate: Mon Sep 5 06:51:09 2022 +0200 vcl: Don’t parse cmap in PrintFontManager::getGlyphWidths() Use PhysicalFontFace::GetFontCharMap() instead which has already parsed the cmap table. Change-Id: Ieba7bace65c9c5d85ffb8feb04e99cd826d7ab48 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139341 Tested-by: Jenkins Reviewed-by: خالد حسني <kha...@aliftype.com> diff --git a/vcl/inc/unx/fontmanager.hxx b/vcl/inc/unx/fontmanager.hxx index e7ee08c4c193..7483a86e3d95 100644 --- a/vcl/inc/unx/fontmanager.hxx +++ b/vcl/inc/unx/fontmanager.hxx @@ -28,6 +28,8 @@ #include <com/sun/star/lang/Locale.hpp> #include <unx/fc_fontoptions.hxx> +#include <font/PhysicalFontFace.hxx> + #include <glyphid.hxx> #include <map> @@ -283,7 +285,7 @@ public: sal_Int32* pWidths, int nGlyphs ); - void getGlyphWidths( fontID nFont, + void getGlyphWidths( const vcl::font::PhysicalFontFace* pFace, bool bVertical, std::vector< sal_Int32 >& rWidths, std::map< sal_Unicode, sal_uInt32 >& rUnicodeEnc ); diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx index 46e8ae1624c7..4ede52817180 100644 --- a/vcl/unx/generic/fontmanager/fontmanager.cxx +++ b/vcl/unx/generic/fontmanager/fontmanager.cxx @@ -1081,12 +1081,12 @@ bool PrintFontManager::createFontSubset( return bSuccess; } -void PrintFontManager::getGlyphWidths( fontID nFont, +void PrintFontManager::getGlyphWidths( const vcl::font::PhysicalFontFace* pFace, bool bVertical, std::vector< sal_Int32 >& rWidths, std::map< sal_Unicode, sal_uInt32 >& rUnicodeEnc ) { - PrintFont* pFont = getFont( nFont ); + PrintFont* pFont = getFont( pFace->GetFontId() ); if (!pFont) return; TrueTypeFont* pTTFont = nullptr; @@ -1113,32 +1113,22 @@ void PrintFontManager::getGlyphWidths( fontID nFont, } // fill the unicode map - // TODO: isn't this map already available elsewhere in the fontmanager? - sal_uInt32 nCmapSize = 0; - const sal_uInt8* pCmapData = pTTFont->table(O_cmap, nCmapSize); - if (pCmapData) + FontCharMapRef xFontCharMap = pFace->GetFontCharMap(); + for (sal_uInt32 cOld = 0;;) { - CmapResult aCmapResult; - if (ParseCMAP(pCmapData, nCmapSize, aCmapResult)) - { - FontCharMapRef xFontCharMap(new FontCharMap(aCmapResult)); - for (sal_uInt32 cOld = 0;;) - { - // get next unicode covered by font - const sal_uInt32 c = xFontCharMap->GetNextChar(cOld); - if (c == cOld) - break; - cOld = c; + // get next unicode covered by font + const sal_uInt32 c = xFontCharMap->GetNextChar(cOld); + if (c == cOld) + break; + cOld = c; #if 1 // TODO: remove when sal_Unicode covers all of unicode - if (c > sal_Unicode(~0)) - break; + if (c > sal_Unicode(~0)) + break; #endif - // get the matching glyph index - const sal_GlyphId aGlyphId = xFontCharMap->GetGlyphIndex(c); - // update the requested map - rUnicodeEnc[static_cast<sal_Unicode>(c)] = aGlyphId; - } - } + // get the matching glyph index + const sal_GlyphId aGlyphId = xFontCharMap->GetGlyphIndex(c); + // update the requested map + rUnicodeEnc[static_cast<sal_Unicode>(c)] = aGlyphId; } } CloseTTFont(pTTFont); diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx index b1068082c26d..5b607b44610b 100644 --- a/vcl/unx/generic/print/genpspgraphics.cxx +++ b/vcl/unx/generic/print/genpspgraphics.cxx @@ -356,14 +356,8 @@ void GenPspGraphics::GetGlyphWidthsHelper(const vcl::font::PhysicalFontFace* pFo std::vector<sal_Int32>& rWidths, Ucs2UIntMap& rUnicodeEnc) { - // in this context the pFont->GetFontId() is a valid PSP - // font since they are the only ones left after the PDF - // export has filtered its list of subsettable fonts (for - // which this method was created). The correct way would - // be to have the FreetypeManager search for the PhysicalFontFace pFont - psp::fontID aFont = pFont->GetFontId(); psp::PrintFontManager& rMgr = psp::PrintFontManager::get(); - rMgr.getGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc ); + rMgr.getGlyphWidths( pFont, bVertical, rWidths, rUnicodeEnc ); } FontAttributes GenPspGraphics::Info2FontAttributes( const psp::FastPrintFontInfo& rInfo )