summaryrefslogtreecommitdiff
path: root/sc/source/filter/oox
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2023-08-10 21:49:59 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2023-08-11 18:11:47 +0200
commitde20853e5243843ac9f4c5927ce0b4cf0e407c15 (patch)
tree639f4aab585d88a83b853b445b0ea819fb700fb5 /sc/source/filter/oox
parent4db0a2c1c3b0a9c9868574b5c538bfd92adfb48a (diff)
xlsx with a lot of comments repeatedly calls OutputDevice::HasGlyphs
on the same font over and over again getting the same results Change-Id: I0c301e3fd4c1838645c25d4f6f7b330acc988135 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155569 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sc/source/filter/oox')
-rw-r--r--sc/source/filter/oox/stylesbuffer.cxx97
-rw-r--r--sc/source/filter/oox/workbookhelper.cxx8
2 files changed, 67 insertions, 38 deletions
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index 25f273b1e1f2..e38b5cd13002 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -793,44 +793,65 @@ void Font::finalizeImport()
if( !maUsedFlags.mbNameUsed )
return;
- PropertySet aDocProps( getDocument() );
- Reference< XDevice > xDevice( aDocProps.getAnyProperty( PROP_ReferenceDevice ), UNO_QUERY );
- if( !xDevice.is() )
- return;
-
- Reference< XFont2 > xFont( xDevice->getFont( maApiData.maDesc ), UNO_QUERY );
- if( !xFont.is() )
- return;
-
- // #91658# CJK fonts
- bool bHasAsian =
- xFont->hasGlyphs( OUString( u'\x3041' ) ) || // 3040-309F: Hiragana
- xFont->hasGlyphs( OUString( u'\x30A1' ) ) || // 30A0-30FF: Katakana
- xFont->hasGlyphs( OUString( u'\x3111' ) ) || // 3100-312F: Bopomofo
- xFont->hasGlyphs( OUString( u'\x3131' ) ) || // 3130-318F: Hangul Compatibility Jamo
- xFont->hasGlyphs( OUString( u'\x3301' ) ) || // 3300-33FF: CJK Compatibility
- xFont->hasGlyphs( OUString( u'\x3401' ) ) || // 3400-4DBF: CJK Unified Ideographs Extension A
- xFont->hasGlyphs( OUString( u'\x4E01' ) ) || // 4E00-9FFF: CJK Unified Ideographs
- xFont->hasGlyphs( OUString( u'\x7E01' ) ) || // 4E00-9FFF: CJK Unified Ideographs
- xFont->hasGlyphs( OUString( u'\xA001' ) ) || // A001-A48F: Yi Syllables
- xFont->hasGlyphs( OUString( u'\xAC01' ) ) || // AC00-D7AF: Hangul Syllables
- xFont->hasGlyphs( OUString( u'\xCC01' ) ) || // AC00-D7AF: Hangul Syllables
- xFont->hasGlyphs( OUString( u'\xF901' ) ) || // F900-FAFF: CJK Compatibility Ideographs
- xFont->hasGlyphs( OUString( u'\xFF71' ) ); // FF00-FFEF: Halfwidth/Fullwidth Forms
- // #113783# CTL fonts
- bool bHasCmplx =
- xFont->hasGlyphs( OUString( u'\x05D1' ) ) || // 0590-05FF: Hebrew
- xFont->hasGlyphs( OUString( u'\x0631' ) ) || // 0600-06FF: Arabic
- xFont->hasGlyphs( OUString( u'\x0721' ) ) || // 0700-074F: Syriac
- xFont->hasGlyphs( OUString( u'\x0911' ) ) || // 0900-0DFF: Indic scripts
- xFont->hasGlyphs( OUString( u'\x0E01' ) ) || // 0E00-0E7F: Thai
- xFont->hasGlyphs( OUString( u'\xFB21' ) ) || // FB1D-FB4F: Hebrew Presentation Forms
- xFont->hasGlyphs( OUString( u'\xFB51' ) ) || // FB50-FDFF: Arabic Presentation Forms-A
- xFont->hasGlyphs( OUString( u'\xFE71' ) ); // FE70-FEFF: Arabic Presentation Forms-B
- // Western fonts
- bool bHasLatin =
- (!bHasAsian && !bHasCmplx) ||
- xFont->hasGlyphs( OUString( 'A' ) );
+ bool bHasAsian(false), bHasCmplx(false), bHasLatin(false);
+ FontClassificationMap& rFontClassificationCache = getFontClassificationCache();
+ if (auto found = rFontClassificationCache.find(maApiData.maDesc); found != rFontClassificationCache.end())
+ {
+ FontClassification eClassification = found->second;
+ bHasAsian = bool(eClassification & FontClassification::Asian);
+ bHasCmplx = bool(eClassification & FontClassification::Cmplx);
+ bHasLatin = bool(eClassification & FontClassification::Latin);
+ }
+ else
+ {
+ PropertySet aDocProps( getDocument() );
+ Reference< XDevice > xDevice( aDocProps.getAnyProperty( PROP_ReferenceDevice ), UNO_QUERY );
+ if( !xDevice.is() )
+ return;
+
+ Reference< XFont2 > xFont( xDevice->getFont( maApiData.maDesc ), UNO_QUERY );
+ if( !xFont.is() )
+ return;
+
+ // #91658# CJK fonts
+ bHasAsian =
+ xFont->hasGlyphs( OUString( u'\x3041' ) ) || // 3040-309F: Hiragana
+ xFont->hasGlyphs( OUString( u'\x30A1' ) ) || // 30A0-30FF: Katakana
+ xFont->hasGlyphs( OUString( u'\x3111' ) ) || // 3100-312F: Bopomofo
+ xFont->hasGlyphs( OUString( u'\x3131' ) ) || // 3130-318F: Hangul Compatibility Jamo
+ xFont->hasGlyphs( OUString( u'\x3301' ) ) || // 3300-33FF: CJK Compatibility
+ xFont->hasGlyphs( OUString( u'\x3401' ) ) || // 3400-4DBF: CJK Unified Ideographs Extension A
+ xFont->hasGlyphs( OUString( u'\x4E01' ) ) || // 4E00-9FFF: CJK Unified Ideographs
+ xFont->hasGlyphs( OUString( u'\x7E01' ) ) || // 4E00-9FFF: CJK Unified Ideographs
+ xFont->hasGlyphs( OUString( u'\xA001' ) ) || // A001-A48F: Yi Syllables
+ xFont->hasGlyphs( OUString( u'\xAC01' ) ) || // AC00-D7AF: Hangul Syllables
+ xFont->hasGlyphs( OUString( u'\xCC01' ) ) || // AC00-D7AF: Hangul Syllables
+ xFont->hasGlyphs( OUString( u'\xF901' ) ) || // F900-FAFF: CJK Compatibility Ideographs
+ xFont->hasGlyphs( OUString( u'\xFF71' ) ); // FF00-FFEF: Halfwidth/Fullwidth Forms
+ // #113783# CTL fonts
+ bHasCmplx =
+ xFont->hasGlyphs( OUString( u'\x05D1' ) ) || // 0590-05FF: Hebrew
+ xFont->hasGlyphs( OUString( u'\x0631' ) ) || // 0600-06FF: Arabic
+ xFont->hasGlyphs( OUString( u'\x0721' ) ) || // 0700-074F: Syriac
+ xFont->hasGlyphs( OUString( u'\x0911' ) ) || // 0900-0DFF: Indic scripts
+ xFont->hasGlyphs( OUString( u'\x0E01' ) ) || // 0E00-0E7F: Thai
+ xFont->hasGlyphs( OUString( u'\xFB21' ) ) || // FB1D-FB4F: Hebrew Presentation Forms
+ xFont->hasGlyphs( OUString( u'\xFB51' ) ) || // FB50-FDFF: Arabic Presentation Forms-A
+ xFont->hasGlyphs( OUString( u'\xFE71' ) ); // FE70-FEFF: Arabic Presentation Forms-B
+ // Western fonts
+ bHasLatin =
+ (!bHasAsian && !bHasCmplx) ||
+ xFont->hasGlyphs( OUString( 'A' ) );
+
+ FontClassification eClassification(FontClassification::None);
+ if (bHasAsian)
+ eClassification = eClassification | FontClassification::Asian;
+ if (bHasCmplx)
+ eClassification = eClassification | FontClassification::Cmplx;
+ if (bHasLatin)
+ eClassification = eClassification | FontClassification::Latin;
+ rFontClassificationCache.emplace(maApiData.maDesc, eClassification);
+ }
lclSetFontName( maApiData.maLatinFont, maApiData.maDesc, bHasLatin );
lclSetFontName( maApiData.maAsianFont, maApiData.maDesc, bHasAsian );
diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx
index be37703908d9..b8a52b09db2c 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -198,6 +198,8 @@ public:
PivotCacheBuffer& getPivotCaches() const { return *mxPivotCaches; }
/** Returns the collection of pivot tables. */
PivotTableBuffer& getPivotTables() { return *mxPivotTables; }
+ /** Shared cache of Font Classifications to avoid repeated lookups */
+ FontClassificationMap& getFontClassificationCache() { return maFontClassificationMap; }
// converters -------------------------------------------------------------
@@ -283,6 +285,7 @@ private:
ConnectionsBfrPtr mxConnections; /// All external data connections.
PivotCacheBfrPtr mxPivotCaches; /// All pivot caches in the document.
PivotTableBfrPtr mxPivotTables; /// All pivot tables in the document.
+ FontClassificationMap maFontClassificationMap; /// Shared to avoid repeated lookups
// converters
FormulaParserPtr mxFmlaParser; /// Import formula parser.
@@ -995,6 +998,11 @@ PivotTableBuffer& WorkbookHelper::getPivotTables() const
return mrBookGlob.getPivotTables();
}
+FontClassificationMap& WorkbookHelper::getFontClassificationCache() const
+{
+ return mrBookGlob.getFontClassificationCache();
+}
+
// converters -----------------------------------------------------------------
FormulaParser& WorkbookHelper::getFormulaParser() const