summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-10-17 17:24:03 +0200
committerAndras Timar <andras.timar@collabora.com>2017-10-26 11:21:45 +0200
commit73937cda81142d8a23805e2374a6168ae103b48b (patch)
tree11df2587ba8b404d1d4d3813d740aadc462ae7f5 /xmloff
parent4356afe13c4d5ecf080b09eb38c99ee5fd09bf73 (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. Reviewed-on: https://gerrit.libreoffice.org/43521 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com> (cherry picked from commit 33eb9fdb61033b3fd35d923900b1f5791f4b71c8) Reviewed-on: https://gerrit.libreoffice.org/43596 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> (cherry picked from commit 244dfe2f3fa874d99dacea191e2265a288457a98) Change-Id: I4a378aa110fdb82db7a99a839d7ff207248a73e7
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/inc/xmlsdtypes.hxx1
-rw-r--r--xmloff/source/draw/sdpropls.cxx69
2 files changed, 61 insertions, 9 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 3afbf338176c..83f7ca9297cd 100644
--- a/xmloff/source/draw/sdpropls.cxx
+++ b/xmloff/source/draw/sdpropls.cxx
@@ -133,7 +133,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 ),
@@ -617,12 +618,13 @@ static SvXMLEnumMapEntry const pXML_VerticalAlign_Enum[] =
{ XML_TOKEN_INVALID, 0 }
};
+// note: PROPORTIONAL and ALLLINES are the same thing now!
static SvXMLEnumMapEntry 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, 0 }
};
@@ -635,6 +637,15 @@ static SvXMLEnumMapEntry const pXML_FitToSize_Enum[] =
{ XML_TOKEN_INVALID, 0 }
};
+static SvXMLEnumMapEntry 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 const pXML_MeasureUnit_Enum[] =
{
{ XML_AUTOMATIC, 0 },
@@ -901,6 +912,38 @@ bool XMLSdRotationAngleTypeHdl::exportXML(
return bRet;
}
+class XMLFitToSizeEnumPropertyHdl : public XMLEnumPropertyHdl
+{
+public:
+ XMLFitToSizeEnumPropertyHdl(
+ const SvXMLEnumMapEntry *const pMap)
+ : XMLEnumPropertyHdl(pMap, cppu::UnoType<css::drawing::TextFitToSizeType>::get())
+ {
+ }
+
+ 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 )
{
@@ -1095,19 +1138,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,
- cppu::UnoType<css::drawing::TextFitToSizeType>::get());
+ pHdl = new XMLFitToSizeEnumPropertyHdl(pXML_FitToSize_Enum_Odf12);
}
else
- {
- pHdl = new XMLEnumPropertyHdl(pXML_FitToSize_Enum,
- cppu::UnoType<css::drawing::TextFitToSizeType>::get());
+ { // 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, ::cppu::UnoType<sal_Int32>::get() );
break;