summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-10-17 17:24:03 +0200
committerMichael Stahl <mstahl@redhat.com>2017-10-20 10:59:37 +0200
commit33eb9fdb61033b3fd35d923900b1f5791f4b71c8 (patch)
tree6efe763cc0847653adbb7852e0d7fd6c127cbd19 /xmloff
parent6cb20e0b298f41fe88984aebfe5454f936a0ae3a (diff)
tdf#97630 xmloff: ODF extended draw:fit-to-size mess
The plan: 1. As Regina points out, there is already (in ODF 1.2, but not ODF 1.1) a style:shrink-to-fit attribute for shapes, so use this to represent the AUTOFIT value. The fallback from AUTOFIT to draw:fit-to-size="true" was a stupid idea anyway, probably "false" is less annoying in practice. There are 2 different shapes that implement TextFitToSize property: a) text shapes already interpret ALLLINES and PROPORTIONAL exactly the same b) fontwork custom shapes interpret ALLLINES but do nothing for PROPORTIONAL As Regina points out, there is no shape that needs to distinguish between ALLLINES and PROPORTIONAL, so we do a minor behavioral API CHANGE and from now on interpret PROPORTIONAL as ALLLINES on fontwork custom shapes. This obviates the need to distinguish the values in ODF and so we don't need a new attribute, just use draw:fit-to-size="true" for both. On import, use MID_FLAG_MERGE_PROPERTY to combine the 2 attributes into one value. 2. Restrict the export of draw:fit-to-size to only the standard values "true"/"false". This implements step 1, the step 2 will be done in the future when most users have the import of the style:shrink-to-fit. Change-Id: I4a378aa110fdb82db7a99a839d7ff207248a73e7 Reviewed-on: https://gerrit.libreoffice.org/43521 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/inc/xmlsdtypes.hxx1
-rw-r--r--xmloff/source/draw/sdpropls.cxx67
2 files changed, 61 insertions, 7 deletions
diff --git a/xmloff/inc/xmlsdtypes.hxx b/xmloff/inc/xmlsdtypes.hxx
index 86e81ba3ea5b..b49639d43a94 100644
--- a/xmloff/inc/xmlsdtypes.hxx
+++ b/xmloff/inc/xmlsdtypes.hxx
@@ -67,6 +67,7 @@
#define XML_SD_TYPE_CONTROL_BORDER_COLOR (XML_SD_TYPES_START + 33 )
#define XML_SD_TYPE_IMAGE_SCALE_MODE (XML_SD_TYPES_START + 34 )
#define XML_SD_TYPE_LINECAP (XML_SD_TYPES_START + 35 )
+#define XML_SD_TYPE_FITTOSIZE_AUTOFIT (XML_SD_TYPES_START + 36 )
//////////////////////////////////////////////////////////////////////////////
// 3D property types
diff --git a/xmloff/source/draw/sdpropls.cxx b/xmloff/source/draw/sdpropls.cxx
index 7e1473199aef..163cc7a6a991 100644
--- a/xmloff/source/draw/sdpropls.cxx
+++ b/xmloff/source/draw/sdpropls.cxx
@@ -129,7 +129,8 @@ const XMLPropertyMapEntry aXMLSDProperties[] =
GMAP( "TextVerticalAdjust", XML_NAMESPACE_DRAW, XML_TEXTAREA_VERTICAL_ALIGN, XML_SD_TYPE_VERTICAL_ALIGN, 0 ),
GMAP( "TextAutoGrowHeight", XML_NAMESPACE_DRAW, XML_AUTO_GROW_HEIGHT, XML_TYPE_BOOL, 0 ),
GMAP( "TextAutoGrowWidth", XML_NAMESPACE_DRAW, XML_AUTO_GROW_WIDTH, XML_TYPE_BOOL, 0 ),
- GMAP( "TextFitToSize", XML_NAMESPACE_DRAW, XML_FIT_TO_SIZE, XML_SD_TYPE_FITTOSIZE, 0 ),
+ GMAP( "TextFitToSize", XML_NAMESPACE_DRAW, XML_FIT_TO_SIZE, XML_SD_TYPE_FITTOSIZE|MID_FLAG_MERGE_PROPERTY, 0),
+ GMAPV( "TextFitToSize", XML_NAMESPACE_STYLE, XML_SHRINK_TO_FIT, XML_SD_TYPE_FITTOSIZE_AUTOFIT|MID_FLAG_MERGE_PROPERTY, 0, SvtSaveOptions::ODFVER_012 ),
GMAP( "TextContourFrame", XML_NAMESPACE_DRAW, XML_FIT_TO_CONTOUR, XML_TYPE_BOOL, 0 ),
GMAP( "TextMaximumFrameHeight", XML_NAMESPACE_FO, XML_MAX_HEIGHT, XML_TYPE_MEASURE, 0 ),
GMAP( "TextMaximumFrameWidth", XML_NAMESPACE_FO, XML_MAX_WIDTH, XML_TYPE_MEASURE, 0 ),
@@ -614,12 +615,13 @@ static SvXMLEnumMapEntry<drawing::TextVerticalAdjust> const pXML_VerticalAlign_E
{ XML_TOKEN_INVALID, (drawing::TextVerticalAdjust)0 }
};
+// note: PROPORTIONAL and ALLLINES are the same thing now!
static SvXMLEnumMapEntry<drawing::TextFitToSizeType> const pXML_FitToSize_Enum_Odf12[] =
{
{ XML_FALSE, drawing::TextFitToSizeType_NONE },
{ XML_TRUE, drawing::TextFitToSizeType_PROPORTIONAL },
{ XML_TRUE, drawing::TextFitToSizeType_ALLLINES },
- { XML_TRUE, drawing::TextFitToSizeType_AUTOFIT },
+ { XML_FALSE, drawing::TextFitToSizeType_AUTOFIT },
{ XML_TOKEN_INVALID, (drawing::TextFitToSizeType)0 }
};
@@ -632,6 +634,15 @@ static SvXMLEnumMapEntry<drawing::TextFitToSizeType> const pXML_FitToSize_Enum[]
{ XML_TOKEN_INVALID, (drawing::TextFitToSizeType)0 }
};
+static SvXMLEnumMapEntry<drawing::TextFitToSizeType> const pXML_ShrinkToFit_Enum[] =
+{
+ { XML_FALSE, drawing::TextFitToSizeType_NONE },
+ { XML_FALSE, drawing::TextFitToSizeType_PROPORTIONAL },
+ { XML_FALSE, drawing::TextFitToSizeType_ALLLINES },
+ { XML_TRUE, drawing::TextFitToSizeType_AUTOFIT },
+ { XML_TOKEN_INVALID, (drawing::TextFitToSizeType)0 }
+};
+
static SvXMLEnumMapEntry<sal_Int32> const pXML_MeasureUnit_Enum[] =
{
{ XML_AUTOMATIC, 0 },
@@ -892,6 +903,38 @@ bool XMLSdRotationAngleTypeHdl::exportXML(
return bRet;
}
+class XMLFitToSizeEnumPropertyHdl : public XMLEnumPropertyHdl
+{
+public:
+ XMLFitToSizeEnumPropertyHdl(
+ const SvXMLEnumMapEntry<drawing::TextFitToSizeType> *const pMap)
+ : XMLEnumPropertyHdl(pMap) {}
+
+ virtual bool importXML(const OUString& rStrImpValue, uno::Any& rValue,
+ const SvXMLUnitConverter& rUC) const override
+ {
+ // we don't know here what the actual attribute name is -
+ // but we can combine the 2 attributes by just taking the
+ // "largest" result value; this can never result in ALLLINES
+ // so the implementation has to interpret PROPORTIONAL as ALLLINES;
+ // both "true" is invalid anyway.
+ Any any;
+ auto const bRet = XMLEnumPropertyHdl::importXML(rStrImpValue, any, rUC);
+ if (!bRet)
+ {
+ return false;
+ }
+ assert(any.hasValue());
+ if (!rValue.hasValue() ||
+ rValue.get<drawing::TextFitToSizeType>() < any.get<drawing::TextFitToSizeType>())
+ {
+ rValue = any;
+ }
+ return true;
+ }
+};
+
+
XMLSdPropHdlFactory::XMLSdPropHdlFactory( uno::Reference< frame::XModel > const & xModel, SvXMLImport& rImport )
: mxModel( xModel ), mpExport(nullptr), mpImport( &rImport )
{
@@ -1086,17 +1129,27 @@ const XMLPropertyHandler* XMLSdPropHdlFactory::GetPropertyHandler( sal_Int32 nTy
break;
case XML_SD_TYPE_FITTOSIZE:
{
- if (mpExport && (mpExport->getDefaultVersion()
- <= SvtSaveOptions::ODFVER_012))
+ if (mpExport
+#if 1
+// TODO: remove in a couple releases, when users have the import of style:shrink-to-fit
+ && (mpExport->getDefaultVersion()
+ <= SvtSaveOptions::ODFVER_012)
+#endif
+ )
{
- pHdl = new XMLEnumPropertyHdl(pXML_FitToSize_Enum_Odf12);
+ pHdl = new XMLFitToSizeEnumPropertyHdl(pXML_FitToSize_Enum_Odf12);
}
else
- {
- pHdl = new XMLEnumPropertyHdl(pXML_FitToSize_Enum);
+ { // import all values written by old LO
+ pHdl = new XMLFitToSizeEnumPropertyHdl(pXML_FitToSize_Enum);
}
}
break;
+ case XML_SD_TYPE_FITTOSIZE_AUTOFIT:
+ {
+ pHdl = new XMLFitToSizeEnumPropertyHdl(pXML_ShrinkToFit_Enum);
+ }
+ break;
case XML_SD_TYPE_MEASURE_UNIT:
pHdl = new XMLEnumPropertyHdl( pXML_MeasureUnit_Enum );
break;