From 8bf5b36ce197d73b8a4c6c46018356b0b59a016b Mon Sep 17 00:00:00 2001 From: Kurt Nordback Date: Fri, 27 Mar 2026 16:45:54 -0600 Subject: [PATCH] tdf#165742 Step 5.9e: Store enumerated geography parameters as enums MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The projection type and region type are described in the OOXML spec as enumerated values. Store them internally as such, converting from string on input and to string on output. Change-Id: I5ee9b6996362bf8cc8db28fc921f3b95bfb7ff46 Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/2065 Tested-by: Jenkins CPCI Reviewed-by: Tomaž Vajngerl (cherry picked from commit 00cb914655c1250656f81eed96ffd9df198387fb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204761 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- .../model/main/DataSeriesProperties.cxx | 4 +- oox/Library_oox.mk | 1 + oox/inc/drawingml/chart/geographymodel.hxx | 32 ++++++- .../drawingml/chart/geographyconverter.cxx | 10 ++- oox/source/drawingml/chart/geographymodel.cxx | 86 +++++++++++++++++++ oox/source/drawingml/chart/seriescontext.cxx | 8 +- oox/source/export/chartgeographyexport.cxx | 17 ++-- 7 files changed, 143 insertions(+), 15 deletions(-) create mode 100644 oox/source/drawingml/chart/geographymodel.cxx diff --git a/chart2/source/model/main/DataSeriesProperties.cxx b/chart2/source/model/main/DataSeriesProperties.cxx index a93a83a26e69..de0acf0dc573 100644 --- a/chart2/source/model/main/DataSeriesProperties.cxx +++ b/chart2/source/model/main/DataSeriesProperties.cxx @@ -150,13 +150,13 @@ void DataSeriesProperties::AddPropertiesToVector( rOutProperties.emplace_back( "GeographyProjectionType", PROP_DATASERIES_GEOGRAPHY_PROJECTION_TYPE, - cppu::UnoType::get(), + cppu::UnoType::get(), // Actually enum GeoProjectionType beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEVOID ); rOutProperties.emplace_back( "GeographyViewedRegionType", PROP_DATASERIES_GEOGRAPHY_VIEWED_REGION_TYPE, - cppu::UnoType::get(), + cppu::UnoType::get(), // Actually enum GeoMappingLevel beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEVOID ); diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk index 4797f75f00a3..66f1ad7256c5 100644 --- a/oox/Library_oox.mk +++ b/oox/Library_oox.mk @@ -109,6 +109,7 @@ $(eval $(call gb_Library_add_exception_objects,oox,\ oox/source/drawingml/chart/datatablecontext \ oox/source/drawingml/chart/geographycontext \ oox/source/drawingml/chart/geographyconverter \ + oox/source/drawingml/chart/geographymodel \ oox/source/drawingml/chart/datatableconverter \ oox/source/drawingml/chart/modelbase \ oox/source/drawingml/chart/objectformatter \ diff --git a/oox/inc/drawingml/chart/geographymodel.hxx b/oox/inc/drawingml/chart/geographymodel.hxx index 774fe32a657a..e653d347cddf 100644 --- a/oox/inc/drawingml/chart/geographymodel.hxx +++ b/oox/inc/drawingml/chart/geographymodel.hxx @@ -12,9 +12,37 @@ #include #include #include +#include namespace oox::drawingml::chart { +// ST_GeoProjectionType +enum class GeoProjectionType : sal_Int32 +{ + Mercator, + Miller, + Robinson, + Albers, +}; + +// ST_GeoMappingLevel +enum class GeoMappingLevel : sal_Int32 +{ + DataOnly, + PostalCode, + County, + State, + CountryRegion, + CountryRegionList, + World, + Autodetect, +}; + +GeoProjectionType geoProjectionTypeFromString(std::u16string_view rStr); +OUString geoProjectionTypeToString(GeoProjectionType eType); + +GeoMappingLevel geoMappingLevelFromString(std::u16string_view rStr); +OUString geoMappingLevelToString(GeoMappingLevel eLevel); struct GeoAddressModel { std::optional mosAddress1; @@ -165,8 +193,8 @@ struct GeoCacheModel struct GeographyModel { - std::optional mosProjectionType; - std::optional mosViewedRegionType; + std::optional moeProjectionType; + std::optional moeViewedRegionType; std::optional mosCultureLanguage; std::optional mosCultureRegion; std::optional mosAttribution; diff --git a/oox/source/drawingml/chart/geographyconverter.cxx b/oox/source/drawingml/chart/geographyconverter.cxx index 72d3772521de..9abfa059eaf8 100644 --- a/oox/source/drawingml/chart/geographyconverter.cxx +++ b/oox/source/drawingml/chart/geographyconverter.cxx @@ -761,10 +761,12 @@ GeoClearModel geoClearFromPropertyValues(const uno::Sequence(*rModel.moeProjectionType)); + if (rModel.moeViewedRegionType.has_value()) + rSeriesProp.setProperty(PROP_GeographyViewedRegionType, + static_cast(*rModel.moeViewedRegionType)); if (rModel.mosCultureLanguage.has_value()) rSeriesProp.setProperty(PROP_GeographyCultureLanguage, *rModel.mosCultureLanguage); if (rModel.mosCultureRegion.has_value()) diff --git a/oox/source/drawingml/chart/geographymodel.cxx b/oox/source/drawingml/chart/geographymodel.cxx new file mode 100644 index 000000000000..27b181c5b6b4 --- /dev/null +++ b/oox/source/drawingml/chart/geographymodel.cxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +namespace oox::drawingml::chart +{ +GeoProjectionType geoProjectionTypeFromString(std::u16string_view rStr) +{ + if (rStr == u"miller") + return GeoProjectionType::Miller; + if (rStr == u"robinson") + return GeoProjectionType::Robinson; + if (rStr == u"albers") + return GeoProjectionType::Albers; + return GeoProjectionType::Mercator; +} + +OUString geoProjectionTypeToString(GeoProjectionType eType) +{ + switch (eType) + { + case GeoProjectionType::Miller: + return u"miller"_ustr; + case GeoProjectionType::Robinson: + return u"robinson"_ustr; + case GeoProjectionType::Albers: + return u"albers"_ustr; + case GeoProjectionType::Mercator: + return u"mercator"_ustr; + } + return u"mercator"_ustr; +} + +GeoMappingLevel geoMappingLevelFromString(std::u16string_view rStr) +{ + if (rStr == u"postalCode") + return GeoMappingLevel::PostalCode; + if (rStr == u"county") + return GeoMappingLevel::County; + if (rStr == u"state") + return GeoMappingLevel::State; + if (rStr == u"countryRegion") + return GeoMappingLevel::CountryRegion; + if (rStr == u"countryRegionList") + return GeoMappingLevel::CountryRegionList; + if (rStr == u"world") + return GeoMappingLevel::World; + if (rStr == u"autodetect") + return GeoMappingLevel::Autodetect; + return GeoMappingLevel::DataOnly; +} + +OUString geoMappingLevelToString(GeoMappingLevel eLevel) +{ + switch (eLevel) + { + case GeoMappingLevel::PostalCode: + return u"postalCode"_ustr; + case GeoMappingLevel::County: + return u"county"_ustr; + case GeoMappingLevel::State: + return u"state"_ustr; + case GeoMappingLevel::CountryRegion: + return u"countryRegion"_ustr; + case GeoMappingLevel::CountryRegionList: + return u"countryRegionList"_ustr; + case GeoMappingLevel::World: + return u"world"_ustr; + case GeoMappingLevel::Autodetect: + return u"autodetect"_ustr; + case GeoMappingLevel::DataOnly: + return u"dataOnly"_ustr; + } + return u"dataOnly"_ustr; +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/seriescontext.cxx b/oox/source/drawingml/chart/seriescontext.cxx index 2a8431d375c4..065d3205d2c7 100644 --- a/oox/source/drawingml/chart/seriescontext.cxx +++ b/oox/source/drawingml/chart/seriescontext.cxx @@ -863,8 +863,12 @@ ContextHandlerRef LayoutPropsContext::onCreateContext( sal_Int32 nElement, const case CX_TOKEN( geography ): { auto& rGeo = mrModel.mxGeography.emplace(); - rGeo.mosProjectionType = rAttribs.getString( XML_projectionType ); - rGeo.mosViewedRegionType = rAttribs.getString( XML_viewedRegionType ); + std::optional sPT = rAttribs.getString( XML_projectionType ); + if (sPT.has_value()) + rGeo.moeProjectionType = geoProjectionTypeFromString( *sPT ); + std::optional sVR = rAttribs.getString( XML_viewedRegionType ); + if (sVR.has_value()) + rGeo.moeViewedRegionType = geoMappingLevelFromString( *sVR ); rGeo.mosCultureLanguage = rAttribs.getString( XML_cultureLanguage ); rGeo.mosCultureRegion = rAttribs.getString( XML_cultureRegion ); rGeo.mosAttribution = rAttribs.getString( XML_attribution ); diff --git a/oox/source/export/chartgeographyexport.cxx b/oox/source/export/chartgeographyexport.cxx index bcd22d9fda3c..2ebf4d059bd7 100644 --- a/oox/source/export/chartgeographyexport.cxx +++ b/oox/source/export/chartgeographyexport.cxx @@ -268,25 +268,32 @@ void exportGeography(const uno::Reference& xSeriesProp, if (!xSeriesProp.is()) return; - OUString sProjectionType, sViewedRegionType, sCultureLanguage, sCultureRegion, sAttribution; + sal_Int32 nProjType = 0, nViewedRegion = 0; + OUString sCultureLanguage, sCultureRegion, sAttribution; uno::Any aPT = xSeriesProp->getPropertyValue(u"GeographyProjectionType"_ustr); uno::Any aVR = xSeriesProp->getPropertyValue(u"GeographyViewedRegionType"_ustr); uno::Any aCL = xSeriesProp->getPropertyValue(u"GeographyCultureLanguage"_ustr); uno::Any aCR = xSeriesProp->getPropertyValue(u"GeographyCultureRegion"_ustr); uno::Any aAT = xSeriesProp->getPropertyValue(u"GeographyAttribution"_ustr); - bool bHasPT = (aPT >>= sProjectionType); - bool bHasVR = (aVR >>= sViewedRegionType); + bool bHasPT = (aPT >>= nProjType); + bool bHasVR = (aVR >>= nViewedRegion); bool bHasCL = (aCL >>= sCultureLanguage); bool bHasCR = (aCR >>= sCultureRegion); bool bHasAT = (aAT >>= sAttribution); + OUString sProjStr, sViewedStr; + if (bHasPT) + sProjStr = geoProjectionTypeToString(static_cast(nProjType)); + if (bHasVR) + sViewedStr = geoMappingLevelToString(static_cast(nViewedRegion)); + if (!bHasPT && !bHasVR && !bHasCL && !bHasCR && !bHasAT) return; pFS->startElement(FSNS(XML_cx, XML_geography), XML_projectionType, - bHasPT ? sProjectionType.toUtf8().getStr() : nullptr, XML_viewedRegionType, - bHasVR ? sViewedRegionType.toUtf8().getStr() : nullptr, XML_cultureLanguage, + bHasPT ? sProjStr.toUtf8().getStr() : nullptr, XML_viewedRegionType, + bHasVR ? sViewedStr.toUtf8().getStr() : nullptr, XML_cultureLanguage, bHasCL ? sCultureLanguage.toUtf8().getStr() : nullptr, XML_cultureRegion, bHasCR ? sCultureRegion.toUtf8().getStr() : nullptr, XML_attribution, bHasAT ? sAttribution.toUtf8().getStr() : nullptr);