Kaydet (Commit) 14c4e615 authored tarafından Grzegorz Araminowicz's avatar Grzegorz Araminowicz Kaydeden (comit) Miklos Vajna

SmartArt: adjust text size to fit shapes

up to maximal size of primFontSz constraint.
Do not override text size changed by user.

Change-Id: If7ea6bbb96cb839831d877edc274a1b0eefdaf21
Reviewed-on: https://gerrit.libreoffice.org/73050
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
üst a2179fb7
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <drawingml/textrun.hxx> #include <drawingml/textrun.hxx>
#include <drawingml/customshapeproperties.hxx> #include <drawingml/customshapeproperties.hxx>
#include <tools/gen.hxx> #include <tools/gen.hxx>
#include <com/sun/star/drawing/TextFitToSizeType.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
...@@ -1127,6 +1128,7 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, ...@@ -1127,6 +1128,7 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
// adjust text alignment // adjust text alignment
// Parse constraints, only self margins as a start. // Parse constraints, only self margins as a start.
double fFontSize = 0;
for (const auto& rConstr : rConstraints) for (const auto& rConstr : rConstraints)
{ {
if (rConstr.mnRefType == XML_w) if (rConstr.mnRefType == XML_w)
...@@ -1146,9 +1148,10 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, ...@@ -1146,9 +1148,10 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
rShape->getShapeProperties().setProperty(nProperty, nValue); rShape->getShapeProperties().setProperty(nProperty, nValue);
} }
if (rConstr.mnType == XML_primFontSz)
fFontSize = rConstr.mfValue;
} }
// TODO: adjust text size to fit shape
TextBodyPtr pTextBody = rShape->getTextBody(); TextBodyPtr pTextBody = rShape->getTextBody();
if (!pTextBody || if (!pTextBody ||
pTextBody->getParagraphs().empty() || pTextBody->getParagraphs().empty() ||
...@@ -1157,6 +1160,16 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, ...@@ -1157,6 +1160,16 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
break; break;
} }
// adjust text size to fit shape
if (fFontSize != 0)
{
for (auto& aParagraph : pTextBody->getParagraphs())
for (auto& aRun : aParagraph->getRuns())
if (!aRun->getTextCharacterProperties().moHeight.has())
aRun->getTextCharacterProperties().moHeight = fFontSize * 100;
}
pTextBody->getTextProperties().maPropertyMap.setProperty(PROP_TextFitToSize, drawing::TextFitToSizeType_AUTOFIT);
// ECMA-376-1:2016 21.4.7.5 ST_AutoTextRotation (Auto Text Rotation) // ECMA-376-1:2016 21.4.7.5 ST_AutoTextRotation (Auto Text Rotation)
const sal_Int32 nautoTxRot = maMap.count(XML_autoTxRot) ? maMap.find(XML_autoTxRot)->second : XML_upr; const sal_Int32 nautoTxRot = maMap.count(XML_autoTxRot) ? maMap.find(XML_autoTxRot)->second : XML_upr;
sal_Int32 nShapeRot = rShape->getRotation(); sal_Int32 nShapeRot = rShape->getRotation();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/TextFitToSizeType.hpp>
#include <com/sun/star/drawing/XShape.hpp> #include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp>
#include <com/sun/star/text/XText.hpp> #include <com/sun/star/text/XText.hpp>
...@@ -75,6 +76,7 @@ public: ...@@ -75,6 +76,7 @@ public:
void testBackground(); void testBackground();
void testBackgroundDrawingmlFallback(); void testBackgroundDrawingmlFallback();
void testCenterCycle(); void testCenterCycle();
void testFontSize();
CPPUNIT_TEST_SUITE(SdImportTestSmartArt); CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
...@@ -112,6 +114,7 @@ public: ...@@ -112,6 +114,7 @@ public:
CPPUNIT_TEST(testBackground); CPPUNIT_TEST(testBackground);
CPPUNIT_TEST(testBackgroundDrawingmlFallback); CPPUNIT_TEST(testBackgroundDrawingmlFallback);
CPPUNIT_TEST(testCenterCycle); CPPUNIT_TEST(testCenterCycle);
CPPUNIT_TEST(testFontSize);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
...@@ -1166,6 +1169,36 @@ void SdImportTestSmartArt::testCenterCycle() ...@@ -1166,6 +1169,36 @@ void SdImportTestSmartArt::testCenterCycle()
xDocShRef->DoClose(); xDocShRef->DoClose();
} }
void SdImportTestSmartArt::testFontSize()
{
sd::DrawDocShellRef xDocShRef = loadURL(
m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-font-size.pptx"), PPTX);
uno::Reference<drawing::XShapes> xGroup1(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xShape1(xGroup1->getByIndex(1), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xParagraph1(getParagraphFromShape(0, xShape1));
uno::Reference<text::XTextRange> xRun1(getRunFromParagraph(0, xParagraph1));
uno::Reference<beans::XPropertySet> xPropSet1(xRun1, uno::UNO_QUERY);
double fFontSize1 = xPropSet1->getPropertyValue("CharHeight").get<double>();
CPPUNIT_ASSERT_DOUBLES_EQUAL(65.0, fFontSize1, 0.01);
uno::Reference<drawing::XShapes> xGroup2(getShapeFromPage(1, 0, xDocShRef), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xShape2(xGroup2->getByIndex(1), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xParagraph2(getParagraphFromShape(0, xShape2));
uno::Reference<text::XTextRange> xRun2(getRunFromParagraph(0, xParagraph2));
uno::Reference<beans::XPropertySet> xPropSet2(xRun2, uno::UNO_QUERY);
double fFontSize2 = xPropSet2->getPropertyValue("CharHeight").get<double>();
CPPUNIT_ASSERT_EQUAL(32.0, fFontSize2);
uno::Reference<drawing::XShapes> xGroup3(getShapeFromPage(2, 0, xDocShRef), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xShape3(xGroup3->getByIndex(1), uno::UNO_QUERY);
drawing::TextFitToSizeType eTextFitToSize = drawing::TextFitToSizeType_NONE;
xShape3->getPropertyValue("TextFitToSize") >>= eTextFitToSize;
CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_AUTOFIT, eTextFitToSize);
xDocShRef->DoClose();
}
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt); CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment