summaryrefslogtreecommitdiff
path: root/xmloff/source/style
diff options
context:
space:
mode:
authorJonathan Clark <jonathan@libreoffice.org>2024-10-21 11:31:46 -0600
committerJonathan Clark <jonathan@libreoffice.org>2024-11-02 01:09:52 +0100
commit43cd683230bc05d294b1bd64f1e7932feccdd3fb (patch)
tree8490101ef265632d22d3594d926575abfac3c7a5 /xmloff/source/style
parentdb7cd5032068c5b9faa4c707db204b58c1dbf2b2 (diff)
tdf#36709 Add loext:text-indent supporting font-relative units
This change adds an ODF font-relative first-line indent paragraph style attribute as a LibreOffice extension. The corresponding ODF standard change is tracked by OFFICE-4165. This change only implements what is minimally necessary to serialize, deserialize, and check for ODF files containing this attribute. Further changes are necessary. * Added cssLength to schema, which is equivalent to length but also allows ic and em as units. * Added loext:text-indent to schema as a paragraph style attribute. This attribute is equivalent to fo:text-indent, but accepts cssLength instead of length. * Added XML_TYPE_UNIT_MEASURE to the ODF parser, which currently accepts only the font-relative measures and forces fallback in other cases. * Added loext:text-indent to the ODF parser. This attribute accepts font-relative metrics, and will behave as an import-only alias for fo:text-indent in other cases. * Updated SvxFirstLineIndentItem to handle unit-denominated measures. * Added proof-of-concept indentation handler to Writer. This implementation is incomplete and temporary, and will be revised in future changes. Change-Id: I7eb5c7382093cb18a9b0afbf93dacb34ba1d35ef Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175941 Tested-by: Jenkins Reviewed-by: Jonathan Clark <jonathan@libreoffice.org>
Diffstat (limited to 'xmloff/source/style')
-rw-r--r--xmloff/source/style/prhdlfac.cxx3
-rw-r--r--xmloff/source/style/xmlbahdl.cxx53
2 files changed, 56 insertions, 0 deletions
diff --git a/xmloff/source/style/prhdlfac.cxx b/xmloff/source/style/prhdlfac.cxx
index a14d61ea31c2..fd6dae604bf8 100644
--- a/xmloff/source/style/prhdlfac.cxx
+++ b/xmloff/source/style/prhdlfac.cxx
@@ -195,6 +195,9 @@ std::unique_ptr<XMLPropertyHandler> XMLPropertyHandlerFactory::CreatePropertyHan
case XML_TYPE_MEASURE16:
pPropHdl.reset(new XMLMeasurePropHdl( 2 ));
break;
+ case XML_TYPE_UNIT_MEASURE:
+ pPropHdl = std::make_unique<XMLUnitMeasurePropHdl>();
+ break;
case XML_TYPE_PERCENT :
pPropHdl.reset(new XMLPercentPropHdl( 4 ));
break;
diff --git a/xmloff/source/style/xmlbahdl.cxx b/xmloff/source/style/xmlbahdl.cxx
index a0aea8ccb1a4..02c271ad6a2e 100644
--- a/xmloff/source/style/xmlbahdl.cxx
+++ b/xmloff/source/style/xmlbahdl.cxx
@@ -27,6 +27,7 @@
#include <sax/tools/converter.hxx>
#include <xmloff/xmluconv.hxx>
#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/beans/Pair.hpp>
#include <xmloff/xmltoken.hxx>
#include <limits.h>
@@ -207,6 +208,58 @@ bool XMLMeasurePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, co
}
+bool XMLUnitMeasurePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
+{
+ double fValue = 0.0;
+ std::optional<sal_Int16> nValueUnit;
+
+ auto bRet = ::sax::Converter::convertMeasureUnit( fValue, nValueUnit, rStrImpValue );
+
+ if(bRet)
+ {
+ // This importer may only accept font-relative units.
+ // Discard all other units to allow fall-through to other attributes.
+ if (css::util::MeasureUnit::FONT_EM != nValueUnit
+ && css::util::MeasureUnit::FONT_IC != nValueUnit)
+ {
+ return false;
+ }
+
+ css::beans::Pair<double, sal_Int16> stValue{fValue, nValueUnit.value()};
+ rValue <<= stValue;
+ }
+
+ return bRet;
+}
+
+bool XMLUnitMeasurePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
+{
+ bool bRet = false;
+ css::beans::Pair<double, sal_Int16> stValue{0.0, css::util::MeasureUnit::MM_100TH};
+
+ if( rValue >>= stValue )
+ {
+ auto [fValue, nValueUnit] = stValue;
+
+ // This exporter may only produce font-relative units.
+ // Discard all other units to allow fall-through to other attributes.
+ if (css::util::MeasureUnit::FONT_EM != nValueUnit
+ && css::util::MeasureUnit::FONT_IC != nValueUnit)
+ {
+ return false;
+ }
+
+ OUStringBuffer aOut;
+ ::sax::Converter::convertMeasureUnit( aOut, fValue, nValueUnit );
+ rStrExpValue = aOut.makeStringAndClear();
+
+ bRet = true;
+ }
+
+ return bRet;
+}
+
+
XMLBoolFalsePropHdl::~XMLBoolFalsePropHdl()
{
// nothing to do