summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-10-17 17:24:03 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-10-25 15:42:22 +0200
commit530bd29aa61279ce5fe55b240a394cb76a791637 (patch)
treeb6e0a424ca727904237d682024969db1ab94ed7a /xmloff
parent3c341633b1738e01e723b279075e84c6957035aa (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> (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) Reviewed-on: https://gerrit.libreoffice.org/43611 Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/inc/xmlsdtypes.hxx1
-rw-r--r--xmloff/source/draw/sdpropls.cxx71
2 files changed, 63 insertions, 9 deletions
diff --git a/xmloff/inc/xmlsdtypes.hxx b/xmloff/inc/xmlsdtypes.hxx
index 8e388cf032c7..675b16fc1377 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 72d6315fa088..12c900eb50cc 100644
--- a/xmloff/source/draw/sdpropls.cxx
+++ b/xmloff/source/draw/sdpropls.cxx
@@ -131,7 +131,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 ),
@@ -615,12 +616,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 }
};
@@ -633,6 +635,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 },
@@ -853,6 +864,40 @@ bool XMLSdHeaderFooterVisibilityTypeHdl::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 )
{
@@ -1047,19 +1092,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;