From 377f97cc92fda4c6281dc418d20b9de8479c6996 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Wed, 25 May 2016 16:36:57 +0200 Subject: vcl: replace boost::dynamic_bitset with boost::optional The getTTCoverage either leaves the bitset empty or inits it with 128 bits, so it's not particularly dynamic. Change-Id: Iac0aa6a023acc54da86d681e75ca550faf91ef26 Reviewed-on: https://gerrit.libreoffice.org/25456 Tested-by: Jenkins Reviewed-by: Michael Stahl --- include/vcl/fontcapabilities.hxx | 7 +- svtools/inc/pch/precompiled_svt.hxx | 1 - svtools/source/misc/sampletext.cxx | 114 ++++++++++++++++--------- vcl/inc/pch/precompiled_vcl.hxx | 1 - vcl/inc/sft.hxx | 4 +- vcl/quartz/salgdi.cxx | 8 +- vcl/source/fontsubset/sft.cxx | 27 ++++-- vcl/unx/generic/glyphs/freetype_glyphcache.cxx | 4 +- vcl/win/gdi/salfont.cxx | 6 +- 9 files changed, 107 insertions(+), 65 deletions(-) diff --git a/include/vcl/fontcapabilities.hxx b/include/vcl/fontcapabilities.hxx index 57342603fa8e..c4b58c0b8f4d 100644 --- a/include/vcl/fontcapabilities.hxx +++ b/include/vcl/fontcapabilities.hxx @@ -10,8 +10,9 @@ #ifndef INCLUDED_VCL_FONTCAPABILITIES_HXX #define INCLUDED_VCL_FONTCAPABILITIES_HXX -#include +#include #include +#include #include @@ -195,8 +196,8 @@ namespace vcl struct FontCapabilities { - boost::dynamic_bitset maUnicodeRange; - boost::dynamic_bitset maCodePageRange; + boost::optional> oUnicodeRange; + boost::optional> oCodePageRange; std::vector< sal_uInt32 > maGSUBScriptTags; }; } diff --git a/svtools/inc/pch/precompiled_svt.hxx b/svtools/inc/pch/precompiled_svt.hxx index 275fab4f8f25..f4d7819710b7 100644 --- a/svtools/inc/pch/precompiled_svt.hxx +++ b/svtools/inc/pch/precompiled_svt.hxx @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include diff --git a/svtools/source/misc/sampletext.cxx b/svtools/source/misc/sampletext.cxx index 5b964cbc06af..59bee404c571 100644 --- a/svtools/source/misc/sampletext.cxx +++ b/svtools/source/misc/sampletext.cxx @@ -741,8 +741,14 @@ OUString makeRepresentativeTextForLanguage(LanguageType eLang) namespace { #if OSL_DEBUG_LEVEL > 0 - void lcl_dump_unicode_coverage(const boost::dynamic_bitset &rIn) + void lcl_dump_unicode_coverage(const boost::optional> &roIn) { + if (!roIn) + { + SAL_INFO("svtools", ""); + return; + } + auto & rIn(*roIn); if (rIn.none()) { SAL_INFO("svtools", ""); @@ -1006,8 +1012,14 @@ namespace SAL_INFO("svtools", "RESERVED5"); } - void lcl_dump_codepage_coverage(const boost::dynamic_bitset &rIn) + void lcl_dump_codepage_coverage(const boost::optional> &roIn) { + if (!roIn) + { + SAL_INFO("svtools", ""); + return; + } + auto & rIn(*roIn); if (rIn.none()) { SAL_INFO("svtools", ""); @@ -1078,9 +1090,9 @@ namespace } #endif - boost::dynamic_bitset getMaskByScriptType(sal_Int16 nScriptType) + std::bitset getMaskByScriptType(sal_Int16 nScriptType) { - boost::dynamic_bitset aMask(vcl::UnicodeCoverage::MAX_UC_ENUM); + std::bitset aMask; aMask.set(); for (size_t i = 0; i < vcl::UnicodeCoverage::MAX_UC_ENUM; ++i) @@ -1095,37 +1107,37 @@ namespace } //false for all bits considered "Latin" by LibreOffice - boost::dynamic_bitset getLatinMask() + std::bitset getLatinMask() { - static boost::dynamic_bitset aMask(getMaskByScriptType(css::i18n::ScriptType::LATIN)); - return aMask; + static std::bitset s_Mask(getMaskByScriptType(css::i18n::ScriptType::LATIN)); + return s_Mask; } //false for all bits considered "Asian" by LibreOffice - boost::dynamic_bitset getCJKMask() + std::bitset getCJKMask() { - static boost::dynamic_bitset aMask(getMaskByScriptType(css::i18n::ScriptType::ASIAN)); - return aMask; + static std::bitset s_Mask(getMaskByScriptType(css::i18n::ScriptType::ASIAN)); + return s_Mask; } //false for all bits considered "Complex" by LibreOffice - boost::dynamic_bitset getCTLMask() + std::bitset getCTLMask() { - static boost::dynamic_bitset aMask(getMaskByScriptType(css::i18n::ScriptType::COMPLEX)); - return aMask; + static std::bitset s_Mask(getMaskByScriptType(css::i18n::ScriptType::COMPLEX)); + return s_Mask; } //false for all bits considered "WEAK" by LibreOffice - boost::dynamic_bitset getWeakMask() + std::bitset getWeakMask() { - static boost::dynamic_bitset aMask(getMaskByScriptType(css::i18n::ScriptType::WEAK)); - return aMask; + static std::bitset s_Mask(getMaskByScriptType(css::i18n::ScriptType::WEAK)); + return s_Mask; } //Nearly every font supports some basic Latin - boost::dynamic_bitset getCommonLatnSubsetMask() + std::bitset getCommonLatnSubsetMask() { - boost::dynamic_bitset aMask(vcl::UnicodeCoverage::MAX_UC_ENUM); + std::bitset aMask; aMask.set(); aMask.set(vcl::UnicodeCoverage::BASIC_LATIN, false); aMask.set(vcl::UnicodeCoverage::LATIN_1_SUPPLEMENT, false); @@ -1135,14 +1147,30 @@ namespace return aMask; } + template + size_t find_first(std::bitset const& rSet) + { + for (size_t i = 0; i < N; ++i) + { + if (rSet.test(i)) + return i; + } + assert(false); // see current usage + return N; + } + UScriptCode getScript(const vcl::FontCapabilities &rFontCapabilities) { using vcl::UnicodeCoverage::UnicodeCoverageEnum; - boost::dynamic_bitset aMasked = rFontCapabilities.maUnicodeRange & getWeakMask(); + std::bitset aMasked; + if (rFontCapabilities.oUnicodeRange) + { + aMasked = *rFontCapabilities.oUnicodeRange & getWeakMask(); + } if (aMasked.count() == 1) - return otCoverageToScript(static_cast(aMasked.find_first())); + return otCoverageToScript(static_cast(find_first(aMasked))); if (aMasked[vcl::UnicodeCoverage::ARABIC]) { @@ -1161,13 +1189,13 @@ namespace aMasked.set(vcl::UnicodeCoverage::DEVANAGARI, false); //Probably strongly tuned for a single Indic script if (aMasked.count() == 1) - return otCoverageToScript(static_cast(aMasked.find_first())); + return otCoverageToScript(static_cast(find_first(aMasked))); } aMasked.set(vcl::UnicodeCoverage::GREEK_EXTENDED, false); aMasked.set(vcl::UnicodeCoverage::GREEK_AND_COPTIC, false); if (aMasked.count() == 1) - return otCoverageToScript(static_cast(aMasked.find_first())); + return otCoverageToScript(static_cast(find_first(aMasked))); if (aMasked[vcl::UnicodeCoverage::CYRILLIC]) { @@ -1184,16 +1212,16 @@ namespace aMasked.set(vcl::UnicodeCoverage::PHAGS_PA, false); //So, possibly a CJK font - if (!aMasked.count() && !rFontCapabilities.maCodePageRange.empty()) + if (!aMasked.count() && rFontCapabilities.oCodePageRange) { - boost::dynamic_bitset aCJKCodePageMask(vcl::CodePageCoverage::MAX_CP_ENUM); + std::bitset aCJKCodePageMask; aCJKCodePageMask.set(vcl::CodePageCoverage::CP932); aCJKCodePageMask.set(vcl::CodePageCoverage::CP936); aCJKCodePageMask.set(vcl::CodePageCoverage::CP949); aCJKCodePageMask.set(vcl::CodePageCoverage::CP950); aCJKCodePageMask.set(vcl::CodePageCoverage::CP1361); - boost::dynamic_bitset aMaskedCodePage = - rFontCapabilities.maCodePageRange & aCJKCodePageMask; + std::bitset aMaskedCodePage = + *rFontCapabilities.oCodePageRange & aCJKCodePageMask; //fold Korean if (aMaskedCodePage[vcl::CodePageCoverage::CP1361]) { @@ -1276,11 +1304,12 @@ OUString makeShortRepresentativeTextForSelectedFont(OutputDevice &rDevice) return OUString(); #if OSL_DEBUG_LEVEL > 0 - lcl_dump_unicode_coverage(aFontCapabilities.maUnicodeRange); - lcl_dump_codepage_coverage(aFontCapabilities.maCodePageRange); + lcl_dump_unicode_coverage(aFontCapabilities.oUnicodeRange); + lcl_dump_codepage_coverage(aFontCapabilities.oCodePageRange); #endif - aFontCapabilities.maUnicodeRange &= getCommonLatnSubsetMask(); + if (aFontCapabilities.oUnicodeRange) + *aFontCapabilities.oUnicodeRange &= getCommonLatnSubsetMask(); //If this font is probably tuned to display a single non-Latin //script and the font name is itself in Latin, then show a small @@ -1630,25 +1659,28 @@ OUString makeRepresentativeTextForFont(sal_Int16 nScriptType, const vcl::Font &r if (aDevice->GetFontCapabilities(aFontCapabilities)) { #if OSL_DEBUG_LEVEL > 0 - lcl_dump_unicode_coverage(aFontCapabilities.maUnicodeRange); + lcl_dump_unicode_coverage(aFontCapabilities.oUnicodeRange); #endif - aFontCapabilities.maUnicodeRange &= getWeakMask(); - - if (nScriptType != css::i18n::ScriptType::ASIAN) + if (aFontCapabilities.oUnicodeRange) { - aFontCapabilities.maUnicodeRange &= getCJKMask(); - aFontCapabilities.maCodePageRange.clear(); + *aFontCapabilities.oUnicodeRange &= getWeakMask(); + + if (nScriptType != css::i18n::ScriptType::ASIAN) + { + *aFontCapabilities.oUnicodeRange &= getCJKMask(); + aFontCapabilities.oCodePageRange.reset(); + } + if (nScriptType != css::i18n::ScriptType::LATIN) + *aFontCapabilities.oUnicodeRange &= getLatinMask(); + if (nScriptType != css::i18n::ScriptType::COMPLEX) + *aFontCapabilities.oUnicodeRange &= getCTLMask(); } - if (nScriptType != css::i18n::ScriptType::LATIN) - aFontCapabilities.maUnicodeRange &= getLatinMask(); - if (nScriptType != css::i18n::ScriptType::COMPLEX) - aFontCapabilities.maUnicodeRange &= getCTLMask(); #if OSL_DEBUG_LEVEL > 0 SAL_INFO("svtools", "minimal"); - lcl_dump_unicode_coverage(aFontCapabilities.maUnicodeRange); - lcl_dump_codepage_coverage(aFontCapabilities.maCodePageRange); + lcl_dump_unicode_coverage(aFontCapabilities.oUnicodeRange); + lcl_dump_codepage_coverage(aFontCapabilities.oCodePageRange); #endif UScriptCode eScript = getScript(aFontCapabilities); diff --git a/vcl/inc/pch/precompiled_vcl.hxx b/vcl/inc/pch/precompiled_vcl.hxx index d3ef8195580e..833d73ee8fed 100644 --- a/vcl/inc/pch/precompiled_vcl.hxx +++ b/vcl/inc/pch/precompiled_vcl.hxx @@ -52,7 +52,6 @@ #include #include #include -#include #include #include #include diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx index c4622f7e6d55..80c62c11b878 100644 --- a/vcl/inc/sft.hxx +++ b/vcl/inc/sft.hxx @@ -269,8 +269,8 @@ namespace vcl void getTTScripts(std::vector< sal_uInt32 > &rScriptTags, const unsigned char* pTable, size_t nLength); bool getTTCoverage( - boost::dynamic_bitset &rUnicodeCoverage, - boost::dynamic_bitset &rCodePageCoverage, + boost::optional> & rUnicodeCoverage, + boost::optional> & rCodePageCoverage, const unsigned char* pTable, size_t nLength); /** diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx index 57036dab7111..6c62b810f027 100644 --- a/vcl/quartz/salgdi.cxx +++ b/vcl/quartz/salgdi.cxx @@ -134,7 +134,7 @@ bool CoreTextFontFace::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilit if( mbFontCapabilitiesRead ) { rFontCapabilities = maFontCapabilities; - return !rFontCapabilities.maUnicodeRange.empty() || !rFontCapabilities.maCodePageRange.empty(); + return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange; } mbFontCapabilitiesRead = true; @@ -163,13 +163,13 @@ bool CoreTextFontFace::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilit if( nRawLength > 0 ) { const unsigned char* pOS2Table = &aBuffer[0]; - vcl::getTTCoverage( maFontCapabilities.maUnicodeRange, - maFontCapabilities.maCodePageRange, + vcl::getTTCoverage( maFontCapabilities.oUnicodeRange, + maFontCapabilities.oCodePageRange, pOS2Table, nRawLength); } } rFontCapabilities = maFontCapabilities; - return !rFontCapabilities.maUnicodeRange.empty() || !rFontCapabilities.maCodePageRange.empty(); + return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange; } void CoreTextFontFace::ReadOs2Table() const diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index cee73c0e1bbd..2385d2676033 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -2762,24 +2762,35 @@ void DisposeNameRecords(NameRecord* nr, int n) free(nr); } +template void +append(std::bitset & rSet, size_t const nOffset, sal_uInt32 const nValue) +{ + for (size_t i = 0; i < 32; ++i) + { + rSet.set(nOffset + i, (nValue & (1 << i)) != 0); + } +} + bool getTTCoverage( - boost::dynamic_bitset &rUnicodeRange, - boost::dynamic_bitset &rCodePageRange, + boost::optional> &rUnicodeRange, + boost::optional> &rCodePageRange, const unsigned char* pTable, size_t nLength) { bool bRet = false; // parse OS/2 header if (nLength >= 58) { - rUnicodeRange.append(GetUInt32(pTable, 42, 1)); - rUnicodeRange.append(GetUInt32(pTable, 46, 1)); - rUnicodeRange.append(GetUInt32(pTable, 50, 1)); - rUnicodeRange.append(GetUInt32(pTable, 54, 1)); + rUnicodeRange = std::bitset(); + append(rUnicodeRange.get(), 0, GetUInt32(pTable, 42, 1)); + append(rUnicodeRange.get(), 32, GetUInt32(pTable, 46, 1)); + append(rUnicodeRange.get(), 64, GetUInt32(pTable, 50, 1)); + append(rUnicodeRange.get(), 96, GetUInt32(pTable, 54, 1)); bRet = true; if (nLength >= 86) { - rCodePageRange.append(GetUInt32(pTable, 78, 1)); - rCodePageRange.append(GetUInt32(pTable, 82, 1)); + rCodePageRange = std::bitset(); + append(rCodePageRange.get(), 0, GetUInt32(pTable, 78, 1)); + append(rCodePageRange.get(), 32, GetUInt32(pTable, 82, 1)); } } return bRet; diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx index 933771ca2a5e..e12fcb8332c5 100644 --- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx +++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx @@ -1065,8 +1065,8 @@ bool ServerFont::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) c if (pOS2) { bRet = vcl::getTTCoverage( - rFontCapabilities.maUnicodeRange, - rFontCapabilities.maCodePageRange, + rFontCapabilities.oUnicodeRange, + rFontCapabilities.oCodePageRange, pOS2, nLength); } diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index e72bb1dca4f4..ba922479cf97 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -1128,7 +1128,7 @@ FontCharMapPtr WinFontFace::GetFontCharMap() const bool WinFontFace::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const { rFontCapabilities = maFontCapabilities; - return !rFontCapabilities.maUnicodeRange.empty() || !rFontCapabilities.maCodePageRange.empty(); + return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange; } void WinFontFace::ReadGsubTable( HDC hDC ) const @@ -1231,11 +1231,11 @@ void WinFontFace::GetFontCapabilities( HDC hDC ) const std::vector aTable( nLength ); unsigned char* pTable = &aTable[0]; ::GetFontData( hDC, OS2Tag, 0, pTable, nLength ); - if (vcl::getTTCoverage(maFontCapabilities.maUnicodeRange, maFontCapabilities.maCodePageRange, pTable, nLength)) + if (vcl::getTTCoverage(maFontCapabilities.oUnicodeRange, maFontCapabilities.oCodePageRange, pTable, nLength)) { // Check for CJK capabilities of the current font // TODO, we have this info already from getTT, decode bits to - // a readable dynamic_bitset + // a readable bitset sal_uInt32 ulUnicodeRange1 = GetUInt( pTable + 42 ); sal_uInt32 ulUnicodeRange2 = GetUInt( pTable + 46 ); -- cgit v1.2.3