[Libreoffice-commits] core.git: include/vcl svtools/inc svtools/source vcl/inc vcl/quartz vcl/source vcl/unx vcl/win

Michael Stahl mstahl at redhat.com
Wed May 25 20:16:11 UTC 2016


 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(-)

New commits:
commit 377f97cc92fda4c6281dc418d20b9de8479c6996
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed May 25 16:36:57 2016 +0200

    vcl: replace boost::dynamic_bitset with boost::optional<std::bitset>
    
    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 <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/include/vcl/fontcapabilities.hxx b/include/vcl/fontcapabilities.hxx
index 5734260..c4b58c0 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 <boost/dynamic_bitset.hpp>
+#include <boost/optional.hpp>
 #include <vector>
+#include <bitset>
 
 #include <sal/types.h>
 
@@ -195,8 +196,8 @@ namespace vcl
 
     struct FontCapabilities
     {
-        boost::dynamic_bitset<sal_uInt32> maUnicodeRange;
-        boost::dynamic_bitset<sal_uInt32> maCodePageRange;
+        boost::optional<std::bitset<UnicodeCoverage::MAX_UC_ENUM>> oUnicodeRange;
+        boost::optional<std::bitset<CodePageCoverage::MAX_CP_ENUM>> oCodePageRange;
         std::vector< sal_uInt32 > maGSUBScriptTags;
     };
 }
diff --git a/svtools/inc/pch/precompiled_svt.hxx b/svtools/inc/pch/precompiled_svt.hxx
index 275fab4..f4d7819 100644
--- a/svtools/inc/pch/precompiled_svt.hxx
+++ b/svtools/inc/pch/precompiled_svt.hxx
@@ -48,7 +48,6 @@
 #include <unordered_map>
 #include <utility>
 #include <vector>
-#include <boost/dynamic_bitset.hpp>
 #include <boost/intrusive_ptr.hpp>
 #include <boost/optional.hpp>
 #include <osl/conditn.hxx>
diff --git a/svtools/source/misc/sampletext.cxx b/svtools/source/misc/sampletext.cxx
index 5b964cb..59bee40 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<sal_uInt32> &rIn)
+    void lcl_dump_unicode_coverage(const boost::optional<std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM>> &roIn)
     {
+        if (!roIn)
+        {
+            SAL_INFO("svtools", "<NOTHING>");
+            return;
+        }
+        auto & rIn(*roIn);
         if (rIn.none())
         {
             SAL_INFO("svtools", "<NONE>");
@@ -1006,8 +1012,14 @@ namespace
             SAL_INFO("svtools", "RESERVED5");
     }
 
-    void lcl_dump_codepage_coverage(const boost::dynamic_bitset<sal_uInt32> &rIn)
+    void lcl_dump_codepage_coverage(const boost::optional<std::bitset<vcl::CodePageCoverage::MAX_CP_ENUM>> &roIn)
     {
+        if (!roIn)
+        {
+            SAL_INFO("svtools", "<NOTHING>");
+            return;
+        }
+        auto & rIn(*roIn);
         if (rIn.none())
         {
             SAL_INFO("svtools", "<NONE>");
@@ -1078,9 +1090,9 @@ namespace
     }
 #endif
 
-    boost::dynamic_bitset<sal_uInt32> getMaskByScriptType(sal_Int16 nScriptType)
+    std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> getMaskByScriptType(sal_Int16 nScriptType)
     {
-        boost::dynamic_bitset<sal_uInt32> aMask(vcl::UnicodeCoverage::MAX_UC_ENUM);
+        std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> 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<sal_uInt32> getLatinMask()
+    std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> getLatinMask()
     {
-        static boost::dynamic_bitset<sal_uInt32> aMask(getMaskByScriptType(css::i18n::ScriptType::LATIN));
-        return aMask;
+        static std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> s_Mask(getMaskByScriptType(css::i18n::ScriptType::LATIN));
+        return s_Mask;
     }
 
     //false for all bits considered "Asian" by LibreOffice
-    boost::dynamic_bitset<sal_uInt32> getCJKMask()
+    std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> getCJKMask()
     {
-        static boost::dynamic_bitset<sal_uInt32> aMask(getMaskByScriptType(css::i18n::ScriptType::ASIAN));
-        return aMask;
+        static std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> s_Mask(getMaskByScriptType(css::i18n::ScriptType::ASIAN));
+        return s_Mask;
     }
 
     //false for all bits considered "Complex" by LibreOffice
-    boost::dynamic_bitset<sal_uInt32> getCTLMask()
+    std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> getCTLMask()
     {
-        static boost::dynamic_bitset<sal_uInt32> aMask(getMaskByScriptType(css::i18n::ScriptType::COMPLEX));
-        return aMask;
+        static std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> s_Mask(getMaskByScriptType(css::i18n::ScriptType::COMPLEX));
+        return s_Mask;
     }
 
     //false for all bits considered "WEAK" by LibreOffice
-    boost::dynamic_bitset<sal_uInt32> getWeakMask()
+    std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> getWeakMask()
     {
-        static boost::dynamic_bitset<sal_uInt32> aMask(getMaskByScriptType(css::i18n::ScriptType::WEAK));
-        return aMask;
+        static std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> s_Mask(getMaskByScriptType(css::i18n::ScriptType::WEAK));
+        return s_Mask;
     }
 
     //Nearly every font supports some basic Latin
-    boost::dynamic_bitset<sal_uInt32> getCommonLatnSubsetMask()
+    std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> getCommonLatnSubsetMask()
     {
-        boost::dynamic_bitset<sal_uInt32> aMask(vcl::UnicodeCoverage::MAX_UC_ENUM);
+        std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> 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 N>
+    size_t find_first(std::bitset<N> 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<sal_uInt32> aMasked = rFontCapabilities.maUnicodeRange & getWeakMask();
+        std::bitset<vcl::UnicodeCoverage::MAX_UC_ENUM> aMasked;
+        if (rFontCapabilities.oUnicodeRange)
+        {
+            aMasked = *rFontCapabilities.oUnicodeRange & getWeakMask();
+        }
 
         if (aMasked.count() == 1)
-            return otCoverageToScript(static_cast<UnicodeCoverageEnum>(aMasked.find_first()));
+            return otCoverageToScript(static_cast<UnicodeCoverageEnum>(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<UnicodeCoverageEnum>(aMasked.find_first()));
+                return otCoverageToScript(static_cast<UnicodeCoverageEnum>(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<UnicodeCoverageEnum>(aMasked.find_first()));
+            return otCoverageToScript(static_cast<UnicodeCoverageEnum>(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<sal_uInt32> aCJKCodePageMask(vcl::CodePageCoverage::MAX_CP_ENUM);
+            std::bitset<vcl::CodePageCoverage::MAX_CP_ENUM> 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<sal_uInt32> aMaskedCodePage =
-                rFontCapabilities.maCodePageRange & aCJKCodePageMask;
+            std::bitset<vcl::CodePageCoverage::MAX_CP_ENUM> 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 d3ef819..833d73e 100644
--- a/vcl/inc/pch/precompiled_vcl.hxx
+++ b/vcl/inc/pch/precompiled_vcl.hxx
@@ -52,7 +52,6 @@
 #include <utility>
 #include <vector>
 #include <window.h>
-#include <boost/dynamic_bitset.hpp>
 #include <boost/functional/hash.hpp>
 #include <boost/intrusive_ptr.hpp>
 #include <boost/math/special_functions/sinc.hpp>
diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx
index c4622f7..80c62c1 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<sal_uInt32> &rUnicodeCoverage,
-        boost::dynamic_bitset<sal_uInt32> &rCodePageCoverage,
+        boost::optional<std::bitset<UnicodeCoverage::MAX_UC_ENUM>> & rUnicodeCoverage,
+        boost::optional<std::bitset<CodePageCoverage::MAX_CP_ENUM>> & rCodePageCoverage,
         const unsigned char* pTable, size_t nLength);
 
 /**
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 57036da..6c62b81 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 cee73c0..2385d26 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<size_t N> void
+append(std::bitset<N> & 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<sal_uInt32> &rUnicodeRange,
-    boost::dynamic_bitset<sal_uInt32> &rCodePageRange,
+    boost::optional<std::bitset<UnicodeCoverage::MAX_UC_ENUM>> &rUnicodeRange,
+    boost::optional<std::bitset<CodePageCoverage::MAX_CP_ENUM>> &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<UnicodeCoverage::MAX_UC_ENUM>();
+        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<CodePageCoverage::MAX_CP_ENUM>();
+            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 933771c..e12fcb8 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 e72bb1d..ba92247 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<unsigned char> 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 );
 


More information about the Libreoffice-commits mailing list