summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-04-01 20:32:15 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-04-03 04:06:39 +0200
commitdb64748f1ee771da9da857f95601b9e08b577166 (patch)
tree2be5e8a13d75e287da95aa5d1b6891c34812875e
parent6fd33d50603c2d12c0a1d88edb04c0890b6a1ef1 (diff)
svx: read font and spacing scaling from oox, add bot as UNO prop.
- Read spacing in oox. - Add spacing scaling as a property. - Rename property "TextFitToSizeScale" to "TextFitToSizeFontScale" - Add property "TextFitToSizeSpacingScale" Change-Id: Icde575e55a3146169d86bb538a57adcf1fa228a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165633 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--include/svl/solar.hrc2
-rw-r--r--include/svx/sdtfsitm.hxx13
-rw-r--r--include/svx/unoshprp.hxx16
-rw-r--r--oox/inc/drawingml/textbodyproperties.hxx1
-rw-r--r--oox/source/drawingml/diagram/diagram.cxx21
-rw-r--r--oox/source/drawingml/textbodypropertiescontext.cxx5
-rw-r--r--oox/source/token/properties.txt2
-rw-r--r--sd/qa/unit/export-tests-ooxml2.cxx16
-rw-r--r--sd/qa/unit/import-tests-smartart.cxx15
-rw-r--r--sd/qa/unit/import-tests2.cxx6
-rw-r--r--svx/source/svdraw/svdattr.cxx5
-rw-r--r--svx/source/svdraw/svdotext.cxx2
-rw-r--r--svx/source/unodraw/unoshape.cxx48
13 files changed, 100 insertions, 52 deletions
diff --git a/include/svl/solar.hrc b/include/svl/solar.hrc
index a3a0ecd0ac0d..288c3073caa0 100644
--- a/include/svl/solar.hrc
+++ b/include/svl/solar.hrc
@@ -23,7 +23,7 @@
// defines ------------------------------------------------------------------
#define OWN_ATTR_VALUE_START 3900
-#define OWN_ATTR_VALUE_END 4009
+#define OWN_ATTR_VALUE_END 4020
#define RID_LIB_START 10000
#define RID_LIB_END 19999
diff --git a/include/svx/sdtfsitm.hxx b/include/svx/sdtfsitm.hxx
index ccdcb7c4dbe9..55fe48a5fc61 100644
--- a/include/svx/sdtfsitm.hxx
+++ b/include/svx/sdtfsitm.hxx
@@ -42,7 +42,8 @@ public:
SdrTextFitToSizeTypeItem(const SdrTextFitToSizeTypeItem& rItem)
: SfxEnumItem(rItem)
- , m_nMaxScale(rItem.GetMaxScale())
+ , mfFontScale(rItem.getFontScale())
+ , mfSpacingScale(rItem.getSpacingScale())
{
}
@@ -59,10 +60,14 @@ public:
virtual bool GetBoolValue() const override;
virtual void SetBoolValue(bool bVal) override;
- void SetMaxScale(double nMaxScale) { m_nMaxScale = nMaxScale; }
- double GetMaxScale() const { return m_nMaxScale; }
+ void setFontScale(double fScale) { mfFontScale = fScale; }
+ double getFontScale() const { return mfFontScale; }
+
+ void setSpacingScale(double fScale) { mfSpacingScale = fScale; }
+ double getSpacingScale() const { return mfSpacingScale; }
private:
- double m_nMaxScale = 0.0;
+ double mfFontScale = 0.0;
+ double mfSpacingScale = 0.0;
};
#endif
diff --git a/include/svx/unoshprp.hxx b/include/svx/unoshprp.hxx
index 9244f719a684..c4fdfafacb2a 100644
--- a/include/svx/unoshprp.hxx
+++ b/include/svx/unoshprp.hxx
@@ -193,12 +193,13 @@
#define OWN_ATTR_SIGNATURELINE_UNSIGNED_IMAGE (OWN_ATTR_VALUE_START+102)
#define OWN_ATTR_SIGNATURELINE_IS_SIGNED (OWN_ATTR_VALUE_START+103)
#define OWN_ATTR_QRCODE (OWN_ATTR_VALUE_START+104)
-#define OWN_ATTR_TEXTFITTOSIZESCALE (OWN_ATTR_VALUE_START+105)
-#define OWN_ATTR_TEXTCOLUMNS (OWN_ATTR_VALUE_START+106)
-#define OWN_ATTR_HYPERLINK (OWN_ATTR_VALUE_START+107)
-#define OWN_ATTR_MISC_OBJ_DECORATIVE (OWN_ATTR_VALUE_START+108)
-#define OWN_ATTR_OBJ_ISEMPTYPRESOBJ (OWN_ATTR_VALUE_START+109)
-// ATTENTION: current maximum is OWN_ATTR_VALUE_START+109 svx; when adding values, update
+#define OWN_ATTR_TEXTFITTOSIZE_FONT_SCALE (OWN_ATTR_VALUE_START+105)
+#define OWN_ATTR_TEXTFITTOSIZE_SPACING_SCALE (OWN_ATTR_VALUE_START+106)
+#define OWN_ATTR_TEXTCOLUMNS (OWN_ATTR_VALUE_START+107)
+#define OWN_ATTR_HYPERLINK (OWN_ATTR_VALUE_START+108)
+#define OWN_ATTR_MISC_OBJ_DECORATIVE (OWN_ATTR_VALUE_START+109)
+#define OWN_ATTR_OBJ_ISEMPTYPRESOBJ (OWN_ATTR_VALUE_START+110)
+// ATTENTION: current maximum is OWN_ATTR_VALUE_START+120 svx; when adding values, update
// OWN_ATTR_VALUE_END in include/svl/solar.hrc accordingly
// #FontWork#
@@ -367,7 +368,8 @@
{ UNO_NAME_MISC_OBJ_SIZEPROTECT, SDRATTR_OBJSIZEPROTECT , cppu::UnoType<bool>::get(), 0, 0},\
{ u"UINameSingular"_ustr, OWN_ATTR_UINAME_SINGULAR , ::cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY, 0}, \
{ u"UINamePlural"_ustr, OWN_ATTR_UINAME_PLURAL , ::cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY, 0}, \
- { u"TextFitToSizeScale"_ustr, OWN_ATTR_TEXTFITTOSIZESCALE, ::cppu::UnoType<double>::get(), 0, 0}, \
+ { u"TextFitToSizeFontScale"_ustr, OWN_ATTR_TEXTFITTOSIZE_FONT_SCALE, ::cppu::UnoType<double>::get(), 0, 0}, \
+ { u"TextFitToSizeSpacingScale"_ustr, OWN_ATTR_TEXTFITTOSIZE_SPACING_SCALE, ::cppu::UnoType<double>::get(), 0, 0}, \
/* #i68101# */ \
{ UNO_NAME_MISC_OBJ_TITLE, OWN_ATTR_MISC_OBJ_TITLE , ::cppu::UnoType<OUString>::get(), 0, 0}, \
{ UNO_NAME_MISC_OBJ_DESCRIPTION, OWN_ATTR_MISC_OBJ_DESCRIPTION , ::cppu::UnoType<OUString>::get(), 0, 0}, \
diff --git a/oox/inc/drawingml/textbodyproperties.hxx b/oox/inc/drawingml/textbodyproperties.hxx
index d935f940638d..46cf99614c56 100644
--- a/oox/inc/drawingml/textbodyproperties.hxx
+++ b/oox/inc/drawingml/textbodyproperties.hxx
@@ -50,6 +50,7 @@ struct TextBodyProperties
OUString msPrst;
/// Normal autofit: font scale (default: 100%).
sal_Int32 mnFontScale = 100000;
+ sal_Int32 mnSpacingScale = 100000;
OUString msHorzOverflow;
std::optional< sal_Int32 > moVertOverflow{};
diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx
index 029c2c56e962..f63185549c23 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -185,30 +185,37 @@ void Diagram::syncDiagramFontHeights()
{
// Find out the minimum scale within this group.
const ShapePairs& rShapePairs = rNameAndPairs.second;
- double nMinScale = 100.0;
+ double fMinFontScale = 100.0;
+ double fMinSpacingScale = 100.0;
for (const auto& rShapePair : rShapePairs)
{
uno::Reference<beans::XPropertySet> xPropertySet(rShapePair.second, uno::UNO_QUERY);
if (xPropertySet.is())
{
- double nTextFitToSizeScale = 0.0;
- xPropertySet->getPropertyValue("TextFitToSizeScale") >>= nTextFitToSizeScale;
- if (nTextFitToSizeScale > 0 && nTextFitToSizeScale < nMinScale)
+ double fFontScale = 0.0;
+ double fSpacingScale = 0.0;
+ xPropertySet->getPropertyValue("TextFitToSizeFontScale") >>= fFontScale;
+ xPropertySet->getPropertyValue("TextFitToSizeSpacingScale") >>= fSpacingScale;
+
+ if (fFontScale > 0 && fSpacingScale > 0
+ && (fFontScale < fMinFontScale || (fFontScale == fMinFontScale && fSpacingScale < fMinSpacingScale)))
{
- nMinScale = nTextFitToSizeScale;
+ fMinFontScale = fFontScale;
+ fMinSpacingScale = fSpacingScale;
}
}
}
// Set that minimum scale for all members of the group.
- if (nMinScale < 100.0)
+ if (fMinFontScale < 100.0 || fMinSpacingScale < 100.0)
{
for (const auto& rShapePair : rShapePairs)
{
uno::Reference<beans::XPropertySet> xPropertySet(rShapePair.second, uno::UNO_QUERY);
if (xPropertySet.is())
{
- xPropertySet->setPropertyValue("TextFitToSizeScale", uno::Any(nMinScale));
+ xPropertySet->setPropertyValue("TextFitToSizeFontScale", uno::Any(fMinFontScale));
+ xPropertySet->setPropertyValue("TextFitToSizeSpacingScale", uno::Any(fMinSpacingScale));
}
}
}
diff --git a/oox/source/drawingml/textbodypropertiescontext.cxx b/oox/source/drawingml/textbodypropertiescontext.cxx
index a08ae8fb9f6d..598bee8daa4e 100644
--- a/oox/source/drawingml/textbodypropertiescontext.cxx
+++ b/oox/source/drawingml/textbodypropertiescontext.cxx
@@ -237,8 +237,11 @@ ContextHandlerRef TextBodyPropertiesContext::onCreateContext( sal_Int32 aElement
case A_TOKEN( normAutofit ): // CT_TextNormalAutofit
{
mrTextBodyProp.maPropertyMap.setProperty( PROP_TextFitToSize, TextFitToSizeType_AUTOFIT);
- mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false);
+ mrTextBodyProp.maPropertyMap.setProperty(PROP_TextAutoGrowHeight, false);
mrTextBodyProp.mnFontScale = rAttribs.getInteger(XML_fontScale, 100000);
+ mrTextBodyProp.mnSpacingScale = rAttribs.getInteger(XML_lnSpcReduction, 100000);
+ mrTextBodyProp.maPropertyMap.setProperty(PROP_TextFitToSizeFontScale, double(mrTextBodyProp.mnFontScale) / 1000.0);
+ mrTextBodyProp.maPropertyMap.setProperty(PROP_TextFitToSizeSpacingScale, 100.0 - double(mrTextBodyProp.mnSpacingScale) / 1000.0);
break;
}
case A_TOKEN( spAutoFit ):
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index 5a0e84708fe3..fd78234fbd0e 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -585,6 +585,8 @@ TextColor
TextColumns
TextContourFrame
TextFitToSize
+TextFitToSizeFontScale
+TextFitToSizeSpacingScale
TextFrames
TextHorizontalAdjust
TextLeftDistance
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx
index ddd272752859..4abd5859aa7d 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -1888,10 +1888,10 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest2, testTextColumns_3columns)
CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(300)),
xColProps->getPropertyValue("AutomaticDistance"));
// Scale value may be unstable; just test that the text is actually scaled
- double fScale;
- CPPUNIT_ASSERT(xProps->getPropertyValue("TextFitToSizeScale") >>= fScale);
- CPPUNIT_ASSERT_GREATER(0.0, fScale);
- CPPUNIT_ASSERT_LESS(100.0, fScale);
+ double fFontScale;
+ CPPUNIT_ASSERT(xProps->getPropertyValue("TextFitToSizeFontScale") >>= fFontScale);
+ CPPUNIT_ASSERT_GREATER(0.0, fFontScale);
+ CPPUNIT_ASSERT_LESS(100.0, fFontScale);
}
save("Impress Office Open XML");
@@ -1908,10 +1908,10 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest2, testTextColumns_3columns)
CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(300)),
xColProps->getPropertyValue("AutomaticDistance"));
// Scale value may be unstable; just test that the text is actually scaled
- double fScale;
- CPPUNIT_ASSERT(xProps->getPropertyValue("TextFitToSizeScale") >>= fScale);
- CPPUNIT_ASSERT_GREATER(0.0, fScale);
- CPPUNIT_ASSERT_LESS(100.0, fScale);
+ double fFontScale;
+ CPPUNIT_ASSERT(xProps->getPropertyValue("TextFitToSizeFontScale") >>= fFontScale);
+ CPPUNIT_ASSERT_GREATER(0.0, fFontScale);
+ CPPUNIT_ASSERT_LESS(100.0, fFontScale);
}
xmlDocUniquePtr pXmlDocRels = parseExport("ppt/slides/slide1.xml");
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 568f0a90efca..84882fba0e79 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -1527,21 +1527,22 @@ CPPUNIT_TEST_FIXTURE(SdImportTestSmartArt, testAutofitSync)
uno::Reference<drawing::XShape> xMiddle = getChildShape(xDiagram, 2);
uno::Reference<beans::XPropertySet> xFirstInner(getChildShape(getChildShape(xMiddle, 0), 0),
uno::UNO_QUERY);
- double nFirstScale = 0;
- CPPUNIT_ASSERT(xFirstInner->getPropertyValue("TextFitToSizeScale") >>= nFirstScale);
- CPPUNIT_ASSERT_GREATER(0.0, nFirstScale);
- CPPUNIT_ASSERT_LESS(100.0, nFirstScale);
+ double fFirstScale = 0;
+ CPPUNIT_ASSERT(xFirstInner->getPropertyValue("TextFitToSizeFontScale") >>= fFirstScale);
+ CPPUNIT_ASSERT_GREATER(0.0, fFirstScale);
+ CPPUNIT_ASSERT_LESS(100.0, fFirstScale);
+
uno::Reference<beans::XPropertySet> xSecondInner(getChildShape(getChildShape(xMiddle, 2), 0),
uno::UNO_QUERY);
- double nSecondScale = 0;
- CPPUNIT_ASSERT(xSecondInner->getPropertyValue("TextFitToSizeScale") >>= nSecondScale);
+ double fSecondScale = 0;
+ CPPUNIT_ASSERT(xSecondInner->getPropertyValue("TextFitToSizeFontScale") >>= fSecondScale);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 56
// - Actual : 100
// i.e. the left shape had no scale-down and the right shape was scaled down, even if it was
// requested that their scaling matches.
- CPPUNIT_ASSERT_EQUAL(nSecondScale, nFirstScale);
+ CPPUNIT_ASSERT_EQUAL(fSecondScale, fFirstScale);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 0 (drawing::TextFitToSizeType_NONE)
diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx
index 9ade40ad1917..5457224bd642 100644
--- a/sd/qa/unit/import-tests2.cxx
+++ b/sd/qa/unit/import-tests2.cxx
@@ -1368,9 +1368,9 @@ CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf120028)
xPropSet->getPropertyValue("CharHeight") >>= fCharHeight;
CPPUNIT_ASSERT_DOUBLES_EQUAL(13.5, fCharHeight, 1E-12);
- double fTextSclale = 0.0;
- xShape->getPropertyValue("TextFitToSizeScale") >>= fTextSclale;
- CPPUNIT_ASSERT_DOUBLES_EQUAL(92.0, fTextSclale, 1E1);
+ double fFontScale = 0.0;
+ xShape->getPropertyValue("TextFitToSizeFontScale") >>= fFontScale;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(92.0, fFontScale, 1E1);
}
CPPUNIT_TEST_FIXTURE(SdImportTest2, testDescriptionImport)
diff --git a/svx/source/svdraw/svdattr.cxx b/svx/source/svdraw/svdattr.cxx
index 19a55c3e810a..914503304bad 100644
--- a/svx/source/svdraw/svdattr.cxx
+++ b/svx/source/svdraw/svdattr.cxx
@@ -1134,8 +1134,9 @@ bool SdrTextFitToSizeTypeItem::operator==(const SfxPoolItem& rItem) const
{
return false;
}
-
- return m_nMaxScale == static_cast<const SdrTextFitToSizeTypeItem&>(rItem).m_nMaxScale;
+ auto& rTextFitToSizeTypeItem = static_cast<const SdrTextFitToSizeTypeItem&>(rItem);
+ return mfFontScale == rTextFitToSizeTypeItem.mfFontScale
+ && mfSpacingScale == rTextFitToSizeTypeItem.mfSpacingScale;
}
sal_uInt16 SdrTextFitToSizeTypeItem::GetValueCount() const { return 4; }
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index 1a2c28b627f9..8e5e1f835542 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -1275,7 +1275,7 @@ void SdrTextObj::autoFitTextForCompatibility(SdrOutliner& rOutliner, const Size&
rOutliner.setRoundFontSizeToPt(true);
const SdrTextFitToSizeTypeItem& rItem = GetObjectItem(SDRATTR_TEXT_FITTOSIZE);
- double fMaxScale = rItem.GetMaxScale();
+ double fMaxScale = rItem.getFontScale();
if (fMaxScale > 0.0)
{
rOutliner.setScalingParameters({ fMaxScale, fMaxScale, 100.0, 100.0 });
diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx
index 12bd86564261..108ded54426b 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -137,22 +137,22 @@ namespace {
/// Calculates what scaling factor will be used for autofit text scaling of this shape.
-double GetTextFitToSizeScale(SdrObject* pObject)
+SdrTextObj* getTextObjectWithFitToSize(SdrObject* pObject)
{
SdrTextObj* pTextObj = DynCastSdrTextObj(pObject);
if (!pTextObj)
{
- return 0;
+ return nullptr;
}
const SfxItemSet& rTextObjSet = pTextObj->GetMergedItemSet();
if (rTextObjSet.GetItem<SdrTextFitToSizeTypeItem>(SDRATTR_TEXT_FITTOSIZE)->GetValue()
!= drawing::TextFitToSizeType_AUTOFIT)
{
- return 0;
+ return nullptr;
}
- return pTextObj->GetFontScale();
+ return pTextObj;
}
}
@@ -2331,13 +2331,26 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertyMapEn
break;
}
- case OWN_ATTR_TEXTFITTOSIZESCALE:
+ case OWN_ATTR_TEXTFITTOSIZE_FONT_SCALE:
{
- double nMaxScale = 0.0;
- if (rValue >>= nMaxScale)
+ double fScale = 0.0;
+ if (rValue >>= fScale)
{
SdrTextFitToSizeTypeItem aItem(pSdrObject->GetMergedItem(SDRATTR_TEXT_FITTOSIZE));
- aItem.SetMaxScale(nMaxScale);
+ aItem.setFontScale(fScale);
+ pSdrObject->SetMergedItem(aItem);
+ return true;
+ }
+ break;
+ }
+
+ case OWN_ATTR_TEXTFITTOSIZE_SPACING_SCALE:
+ {
+ double fScale = 0.0;
+ if (rValue >>= fScale)
+ {
+ SdrTextFitToSizeTypeItem aItem(pSdrObject->GetMergedItem(SDRATTR_TEXT_FITTOSIZE));
+ aItem.setSpacingScale(fScale);
pSdrObject->SetMergedItem(aItem);
return true;
}
@@ -2858,10 +2871,23 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertyMapEn
break;
}
- case OWN_ATTR_TEXTFITTOSIZESCALE:
+ case OWN_ATTR_TEXTFITTOSIZE_FONT_SCALE:
{
- double nScale = GetTextFitToSizeScale(GetSdrObject());
- rValue <<= nScale;
+ auto* pTextObject = getTextObjectWithFitToSize(GetSdrObject());
+ if (pTextObject)
+ {
+ rValue <<= pTextObject->GetFontScale();
+ }
+ break;
+ }
+
+ case OWN_ATTR_TEXTFITTOSIZE_SPACING_SCALE:
+ {
+ auto* pTextObject = getTextObjectWithFitToSize(GetSdrObject());
+ if (pTextObject)
+ {
+ rValue <<= pTextObject->GetSpacingScale();
+ }
break;
}