summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-09-17 22:25:01 +0200
committerTomaž Vajngerl <quikee@gmail.com>2023-09-18 07:54:27 +0200
commitb839c09760919d4f4a21ed1819885b5385f27e31 (patch)
treed444f24582ed5c247132fa0b6de11cc08b6caba2
parente425c837aec0b11f381ddb49fe651acf5509bd82 (diff)
oox: some more conversions to frozen map and set
Change-Id: Ibe557006ee4393a2cfa2cb600744ca5ba7090ca7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157003 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--oox/source/export/chartexport.cxx72
-rw-r--r--oox/source/export/shapes.cxx235
2 files changed, 159 insertions, 148 deletions
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index c9db6f8cc431..0265c2b7db8d 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -107,6 +107,10 @@
#include <set>
#include <unordered_set>
+#include <frozen/bits/defines.h>
+#include <frozen/bits/elsa_std.h>
+#include <frozen/unordered_map.h>
+
#include <o3tl/temporary.hxx>
#include <o3tl/sorted_vector.hxx>
@@ -440,41 +444,41 @@ static ::std::vector< double > lcl_getAllValuesFromSequence( const Reference< ch
return aResult;
}
-static sal_Int32 lcl_getChartType( std::u16string_view sChartType )
+namespace
+{
+
+constexpr auto constChartTypeMap = frozen::make_unordered_map<std::u16string_view, chart::TypeId>(
+{
+ { u"com.sun.star.chart.BarDiagram", chart::TYPEID_BAR },
+ { u"com.sun.star.chart2.ColumnChartType", chart::TYPEID_BAR },
+ { u"com.sun.star.chart.AreaDiagram", chart::TYPEID_AREA },
+ { u"com.sun.star.chart2.AreaChartType", chart::TYPEID_AREA },
+ { u"com.sun.star.chart.LineDiagram", chart::TYPEID_LINE },
+ { u"com.sun.star.chart2.LineChartType", chart::TYPEID_LINE },
+ { u"com.sun.star.chart.PieDiagram", chart::TYPEID_PIE },
+ { u"com.sun.star.chart2.PieChartType", chart::TYPEID_PIE },
+ { u"com.sun.star.chart.DonutDiagram", chart::TYPEID_DOUGHNUT },
+ { u"com.sun.star.chart2.DonutChartType", chart::TYPEID_DOUGHNUT },
+ { u"com.sun.star.chart.XYDiagram", chart::TYPEID_SCATTER },
+ { u"com.sun.star.chart2.ScatterChartType", chart::TYPEID_SCATTER },
+ { u"com.sun.star.chart.NetDiagram", chart::TYPEID_RADARLINE },
+ { u"com.sun.star.chart2.NetChartType", chart::TYPEID_RADARLINE },
+ { u"com.sun.star.chart.FilledNetDiagram", chart::TYPEID_RADARAREA },
+ { u"com.sun.star.chart2.FilledNetChartType", chart::TYPEID_RADARAREA },
+ { u"com.sun.star.chart.StockDiagram", chart::TYPEID_STOCK },
+ { u"com.sun.star.chart2.CandleStickChartType", chart::TYPEID_STOCK },
+ { u"com.sun.star.chart.BubbleDiagram", chart::TYPEID_BUBBLE },
+ { u"com.sun.star.chart2.BubbleChartType", chart::TYPEID_BUBBLE },
+});
+
+} // end anonymous namespace
+
+static sal_Int32 lcl_getChartType(std::u16string_view sChartType)
{
- chart::TypeId eChartTypeId = chart::TYPEID_UNKNOWN;
- if( sChartType == u"com.sun.star.chart.BarDiagram"
- || sChartType == u"com.sun.star.chart2.ColumnChartType" )
- eChartTypeId = chart::TYPEID_BAR;
- else if( sChartType == u"com.sun.star.chart.AreaDiagram"
- || sChartType == u"com.sun.star.chart2.AreaChartType" )
- eChartTypeId = chart::TYPEID_AREA;
- else if( sChartType == u"com.sun.star.chart.LineDiagram"
- || sChartType == u"com.sun.star.chart2.LineChartType" )
- eChartTypeId = chart::TYPEID_LINE;
- else if( sChartType == u"com.sun.star.chart.PieDiagram"
- || sChartType == u"com.sun.star.chart2.PieChartType" )
- eChartTypeId = chart::TYPEID_PIE;
- else if( sChartType == u"com.sun.star.chart.DonutDiagram"
- || sChartType == u"com.sun.star.chart2.DonutChartType" )
- eChartTypeId = chart::TYPEID_DOUGHNUT;
- else if( sChartType == u"com.sun.star.chart.XYDiagram"
- || sChartType == u"com.sun.star.chart2.ScatterChartType" )
- eChartTypeId = chart::TYPEID_SCATTER;
- else if( sChartType == u"com.sun.star.chart.NetDiagram"
- || sChartType == u"com.sun.star.chart2.NetChartType" )
- eChartTypeId = chart::TYPEID_RADARLINE;
- else if( sChartType == u"com.sun.star.chart.FilledNetDiagram"
- || sChartType == u"com.sun.star.chart2.FilledNetChartType" )
- eChartTypeId = chart::TYPEID_RADARAREA;
- else if( sChartType == u"com.sun.star.chart.StockDiagram"
- || sChartType == u"com.sun.star.chart2.CandleStickChartType" )
- eChartTypeId = chart::TYPEID_STOCK;
- else if( sChartType == u"com.sun.star.chart.BubbleDiagram"
- || sChartType == u"com.sun.star.chart2.BubbleChartType" )
- eChartTypeId = chart::TYPEID_BUBBLE;
-
- return eChartTypeId;
+ auto aIterator = constChartTypeMap.find(sChartType);
+ if (aIterator == constChartTypeMap.end())
+ return chart::TYPEID_UNKNOWN;
+ return aIterator->second;
}
static sal_Int32 lcl_generateRandomValue()
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 78614b7efbcc..08c3c38e4446 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -85,6 +85,12 @@
#include <basegfx/numeric/ftools.hxx>
#include <oox/export/DMLPresetShapeExport.hxx>
+#include <frozen/bits/defines.h>
+#include <frozen/bits/elsa_std.h>
+#include <frozen/set.h>
+#include <frozen/unordered_map.h>
+
+
using namespace ::css;
using namespace ::css::beans;
using namespace ::css::uno;
@@ -551,82 +557,88 @@ ShapeExport& ShapeExport::WriteGroupShape(const uno::Reference<drawing::XShape>&
pFS->endElementNS(mnXmlNamespace, nGroupShapeToken);
return *this;
}
+namespace
+{
-static bool lcl_IsOnDenylist(OUString const & rShapeType)
+constexpr auto constDenySet = frozen::make_set<std::u16string_view>(
{
- static const std::initializer_list<std::u16string_view> vDenylist = {
- u"block-arc",
- u"rectangle",
- u"ellipse",
- u"ring",
- u"can",
- u"cube",
- u"paper",
- u"frame",
- u"forbidden",
- u"smiley",
- u"sun",
- u"flower",
- u"bracket-pair",
- u"brace-pair",
- u"quad-bevel",
- u"round-rectangular-callout",
- u"rectangular-callout",
- u"round-callout",
- u"cloud-callout",
- u"line-callout-1",
- u"line-callout-2",
- u"line-callout-3",
- u"paper",
- u"vertical-scroll",
- u"horizontal-scroll",
- u"mso-spt34",
- u"mso-spt75",
- u"mso-spt164",
- u"mso-spt180",
- u"flowchart-process",
- u"flowchart-alternate-process",
- u"flowchart-decision",
- u"flowchart-data",
- u"flowchart-predefined-process",
- u"flowchart-internal-storage",
- u"flowchart-document",
- u"flowchart-multidocument",
- u"flowchart-terminator",
- u"flowchart-preparation",
- u"flowchart-manual-input",
- u"flowchart-manual-operation",
- u"flowchart-connector",
- u"flowchart-off-page-connector",
- u"flowchart-card",
- u"flowchart-punched-tape",
- u"flowchart-summing-junction",
- u"flowchart-or",
- u"flowchart-collate",
- u"flowchart-sort",
- u"flowchart-extract",
- u"flowchart-merge",
- u"flowchart-stored-data",
- u"flowchart-delay",
- u"flowchart-sequential-access",
- u"flowchart-magnetic-disk",
- u"flowchart-direct-access-storage",
- u"flowchart-display"
- };
+ u"block-arc",
+ u"rectangle",
+ u"ellipse",
+ u"ring",
+ u"can",
+ u"cube",
+ u"paper",
+ u"frame",
+ u"forbidden",
+ u"smiley",
+ u"sun",
+ u"flower",
+ u"bracket-pair",
+ u"brace-pair",
+ u"quad-bevel",
+ u"round-rectangular-callout",
+ u"rectangular-callout",
+ u"round-callout",
+ u"cloud-callout",
+ u"line-callout-1",
+ u"line-callout-2",
+ u"line-callout-3",
+ u"paper",
+ u"vertical-scroll",
+ u"horizontal-scroll",
+ u"mso-spt34",
+ u"mso-spt75",
+ u"mso-spt164",
+ u"mso-spt180",
+ u"flowchart-process",
+ u"flowchart-alternate-process",
+ u"flowchart-decision",
+ u"flowchart-data",
+ u"flowchart-predefined-process",
+ u"flowchart-internal-storage",
+ u"flowchart-document",
+ u"flowchart-multidocument",
+ u"flowchart-terminator",
+ u"flowchart-preparation",
+ u"flowchart-manual-input",
+ u"flowchart-manual-operation",
+ u"flowchart-connector",
+ u"flowchart-off-page-connector",
+ u"flowchart-card",
+ u"flowchart-punched-tape",
+ u"flowchart-summing-junction",
+ u"flowchart-or",
+ u"flowchart-collate",
+ u"flowchart-sort",
+ u"flowchart-extract",
+ u"flowchart-merge",
+ u"flowchart-stored-data",
+ u"flowchart-delay",
+ u"flowchart-sequential-access",
+ u"flowchart-magnetic-disk",
+ u"flowchart-direct-access-storage",
+ u"flowchart-display"
+});
+
+constexpr auto constAllowSet = frozen::make_set<std::u16string_view>(
+{
+ u"heart",
+ u"puzzle",
+ u"col-60da8460",
+ u"col-502ad400"
+});
- return std::find(vDenylist.begin(), vDenylist.end(), rShapeType) != vDenylist.end();
+} // end anonymous namespace
+
+static bool lcl_IsOnDenylist(OUString const & rShapeType)
+{
+ return constDenySet.find(rShapeType) != constDenySet.end();
}
static bool lcl_IsOnAllowlist(OUString const & rShapeType)
{
- static const std::initializer_list<std::u16string_view> vAllowlist = {
- u"heart",
- u"puzzle",
- u"col-60da8460",
- u"col-502ad400"
- };
-
- return std::find(vAllowlist.begin(), vAllowlist.end(), rShapeType) != vAllowlist.end();
+ return constAllowSet.find(rShapeType) != constAllowSet.end();
}
static bool lcl_GetHandlePosition( sal_Int32 &nValue, const EnhancedCustomShapeParameter &rParam, const Sequence< EnhancedCustomShapeAdjustmentValue > &rSeq)
@@ -2026,51 +2038,47 @@ ShapeExport& ShapeExport::WriteRectangleShape( const Reference< XShape >& xShape
return *this;
}
+
typedef ShapeExport& (ShapeExport::*ShapeConverter)( const Reference< XShape >& );
typedef std::unordered_map< const char*, ShapeConverter, rtl::CStringHash, rtl::CStringEqual> NameToConvertMapType;
-static const NameToConvertMapType& lcl_GetConverters()
+namespace
{
- static NameToConvertMapType const shape_converters
- {
- // tdf#98736 export CaptionShape as TextShape, because it is non-ooxml shape and
- // we can't export this shape as CustomShape
- // TODO: WriteCaptionShape
- { "com.sun.star.drawing.CaptionShape" , &ShapeExport::WriteTextShape },
-
- { "com.sun.star.drawing.ClosedBezierShape" , &ShapeExport::WriteClosedPolyPolygonShape },
- { "com.sun.star.drawing.ConnectorShape" , &ShapeExport::WriteConnectorShape },
- { "com.sun.star.drawing.CustomShape" , &ShapeExport::WriteCustomShape },
- { "com.sun.star.drawing.EllipseShape" , &ShapeExport::WriteEllipseShape },
- { "com.sun.star.drawing.GraphicObjectShape" , &ShapeExport::WriteGraphicObjectShape },
- { "com.sun.star.drawing.LineShape" , &ShapeExport::WriteLineShape },
- { "com.sun.star.drawing.MediaShape" , &ShapeExport::WriteGraphicObjectShape },
- { "com.sun.star.drawing.OpenBezierShape" , &ShapeExport::WriteOpenPolyPolygonShape },
- { "com.sun.star.drawing.PolyPolygonShape" , &ShapeExport::WriteClosedPolyPolygonShape },
- { "com.sun.star.drawing.PolyLineShape" , &ShapeExport::WriteOpenPolyPolygonShape },
- { "com.sun.star.drawing.RectangleShape" , &ShapeExport::WriteRectangleShape },
- { "com.sun.star.drawing.OLE2Shape" , &ShapeExport::WriteOLE2Shape },
- { "com.sun.star.drawing.TableShape" , &ShapeExport::WriteTableShape },
- { "com.sun.star.drawing.TextShape" , &ShapeExport::WriteTextShape },
- { "com.sun.star.drawing.GroupShape" , &ShapeExport::WriteGroupShape },
-
- { "com.sun.star.presentation.GraphicObjectShape" , &ShapeExport::WriteGraphicObjectShape },
- { "com.sun.star.presentation.MediaShape" , &ShapeExport::WriteGraphicObjectShape },
- { "com.sun.star.presentation.ChartShape" , &ShapeExport::WriteOLE2Shape },
- { "com.sun.star.presentation.OLE2Shape" , &ShapeExport::WriteOLE2Shape },
- { "com.sun.star.presentation.TableShape" , &ShapeExport::WriteTableShape },
- { "com.sun.star.presentation.TextShape" , &ShapeExport::WriteTextShape },
-
- { "com.sun.star.presentation.DateTimeShape" , &ShapeExport::WriteTextShape },
- { "com.sun.star.presentation.FooterShape" , &ShapeExport::WriteTextShape },
- { "com.sun.star.presentation.HeaderShape" , &ShapeExport::WriteTextShape },
- { "com.sun.star.presentation.NotesShape" , &ShapeExport::WriteTextShape },
- { "com.sun.star.presentation.OutlinerShape" , &ShapeExport::WriteTextShape },
- { "com.sun.star.presentation.SlideNumberShape" , &ShapeExport::WriteTextShape },
- { "com.sun.star.presentation.TitleTextShape" , &ShapeExport::WriteTextShape },
- };
- return shape_converters;
-}
+
+constexpr auto constMap = frozen::make_unordered_map<std::u16string_view, ShapeConverter>(
+{
+ { u"com.sun.star.drawing.CaptionShape", &ShapeExport::WriteTextShape },
+ { u"com.sun.star.drawing.ClosedBezierShape", &ShapeExport::WriteClosedPolyPolygonShape },
+ { u"com.sun.star.drawing.ConnectorShape", &ShapeExport::WriteConnectorShape },
+ { u"com.sun.star.drawing.CustomShape", &ShapeExport::WriteCustomShape },
+ { u"com.sun.star.drawing.EllipseShape", &ShapeExport::WriteEllipseShape },
+ { u"com.sun.star.drawing.GraphicObjectShape", &ShapeExport::WriteGraphicObjectShape },
+ { u"com.sun.star.drawing.LineShape", &ShapeExport::WriteLineShape },
+ { u"com.sun.star.drawing.MediaShape", &ShapeExport::WriteGraphicObjectShape },
+ { u"com.sun.star.drawing.OpenBezierShape", &ShapeExport::WriteOpenPolyPolygonShape },
+ { u"com.sun.star.drawing.PolyPolygonShape", &ShapeExport::WriteClosedPolyPolygonShape },
+ { u"com.sun.star.drawing.PolyLineShape", &ShapeExport::WriteOpenPolyPolygonShape },
+ { u"com.sun.star.drawing.RectangleShape", &ShapeExport::WriteRectangleShape },
+ { u"com.sun.star.drawing.OLE2Shape", &ShapeExport::WriteOLE2Shape },
+ { u"com.sun.star.drawing.TableShape", &ShapeExport::WriteTableShape },
+ { u"com.sun.star.drawing.TextShape", &ShapeExport::WriteTextShape },
+ { u"com.sun.star.drawing.GroupShape", &ShapeExport::WriteGroupShape },
+ { u"com.sun.star.presentation.GraphicObjectShape", &ShapeExport::WriteGraphicObjectShape },
+ { u"com.sun.star.presentation.MediaShape", &ShapeExport::WriteGraphicObjectShape },
+ { u"com.sun.star.presentation.ChartShape", &ShapeExport::WriteOLE2Shape },
+ { u"com.sun.star.presentation.OLE2Shape", &ShapeExport::WriteOLE2Shape },
+ { u"com.sun.star.presentation.TableShape", &ShapeExport::WriteTableShape },
+ { u"com.sun.star.presentation.TextShape", &ShapeExport::WriteTextShape },
+ { u"com.sun.star.presentation.DateTimeShape", &ShapeExport::WriteTextShape },
+ { u"com.sun.star.presentation.FooterShape", &ShapeExport::WriteTextShape },
+ { u"com.sun.star.presentation.HeaderShape", &ShapeExport::WriteTextShape },
+ { u"com.sun.star.presentation.NotesShape", &ShapeExport::WriteTextShape },
+ { u"com.sun.star.presentation.OutlinerShape", &ShapeExport::WriteTextShape },
+ { u"com.sun.star.presentation.SlideNumberShape", &ShapeExport::WriteTextShape },
+ { u"com.sun.star.presentation.TitleTextShape", &ShapeExport::WriteTextShape },
+});
+
+} // end anonymous namespace
ShapeExport& ShapeExport::WriteShape( const Reference< XShape >& xShape )
{
@@ -2079,9 +2087,8 @@ ShapeExport& ShapeExport::WriteShape( const Reference< XShape >& xShape )
OUString sShapeType = xShape->getShapeType();
SAL_INFO("oox.shape", "write shape: " << sShapeType);
- NameToConvertMapType::const_iterator aConverter
- = lcl_GetConverters().find(sShapeType.toUtf8().getStr());
- if (aConverter == lcl_GetConverters().end())
+ auto aConverterIterator = constMap.find(sShapeType);
+ if (aConverterIterator == constMap.end())
{
SAL_INFO("oox.shape", "unknown shape");
return WriteUnknownShape( xShape );
@@ -2096,7 +2103,7 @@ ShapeExport& ShapeExport::WriteShape( const Reference< XShape >& xShape )
mbPlaceholder = xShapeProperties->getPropertyValue("IsPresentationObject").get<bool>();
}
- (this->*(aConverter->second))( xShape );
+ (this->*(aConverterIterator->second))(xShape);
return *this;
}