summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Trojahn <paul.trojahn@gmail.com>2017-11-13 18:27:22 +0100
committerTamás Zolnai <tamas.zolnai@collabora.com>2017-12-18 15:46:40 +0100
commit3b4f14f4da046dab25362114db737968634cd720 (patch)
tree1d11378090d4d5d4e8b8a6cfa605c28b7a33830b
parent61b1d631331551b43bc7d619be33bfbfeff7cad6 (diff)
tdf#90626 PPTX: Fix image bullet size
This solution comes with a few limitations. The bullet isn't centered in Powerpoint and has to be between 25% and 400% of the size of the first character in the paragraph. This isn't optimal, but should produce acceptable results under most circumstances. Change-Id: I6c37169282aa351b81d78e06678424203b78f6d7 Reviewed-on: https://gerrit.libreoffice.org/44911 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r--include/oox/export/drawingml.hxx4
-rw-r--r--oox/inc/drawingml/textparagraph.hxx2
-rw-r--r--oox/source/drawingml/textparagraph.cxx14
-rw-r--r--oox/source/drawingml/textparagraphproperties.cxx8
-rw-r--r--oox/source/drawingml/textparagraphpropertiescontext.cxx2
-rw-r--r--oox/source/export/drawingml.cxx30
-rw-r--r--sd/qa/unit/data/odp/tdf90626.odpbin0 -> 12363 bytes
-rw-r--r--sd/qa/unit/data/pptx/tdf90626.pptxbin0 -> 24027 bytes
-rw-r--r--sd/qa/unit/export-tests-ooxml2.cxx17
-rw-r--r--sd/qa/unit/import-tests.cxx19
10 files changed, 74 insertions, 22 deletions
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 69d1d6657fad..14bd8eae4664 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -204,8 +204,8 @@ public:
void WriteText( const css::uno::Reference< css::uno::XInterface >& rXIface, const OUString& presetWarp, bool bBodyPr, bool bText = true, sal_Int32 nXmlNamespace = 0);
void WriteParagraph( const css::uno::Reference< css::text::XTextContent >& rParagraph,
bool& rbOverridingCharHeight, sal_Int32& rnCharHeight );
- void WriteParagraphProperties( const css::uno::Reference< css::text::XTextContent >& rParagraph );
- void WriteParagraphNumbering( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,
+ void WriteParagraphProperties(const css::uno::Reference< css::text::XTextContent >& rParagraph, float fFirstCharHeight);
+ void WriteParagraphNumbering(const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, float fFirstCharHeight,
sal_Int16 nLevel );
void WriteRun( const css::uno::Reference< css::text::XTextRange >& rRun,
bool& rbOverridingCharHeight, sal_Int32& rnCharHeight );
diff --git a/oox/inc/drawingml/textparagraph.hxx b/oox/inc/drawingml/textparagraph.hxx
index 10eb0ee35468..ec0d57686e1b 100644
--- a/oox/inc/drawingml/textparagraph.hxx
+++ b/oox/inc/drawingml/textparagraph.hxx
@@ -29,6 +29,8 @@
#include <drawingml/textliststyle.hxx>
#include <drawingml/textparagraphproperties.hxx>
+// The height the bullet is relative to is different in OOXML
+#define OOX_BULLET_LIST_SCALE_FACTOR 0.7f
namespace oox { namespace formulaimport {
class XmlStreamBuilder;
diff --git a/oox/source/drawingml/textparagraph.cxx b/oox/source/drawingml/textparagraph.cxx
index 02e5efa54f03..8f1e5d1b061c 100644
--- a/oox/source/drawingml/textparagraph.cxx
+++ b/oox/source/drawingml/textparagraph.cxx
@@ -20,6 +20,7 @@
#include <drawingml/textparagraph.hxx>
#include <oox/drawingml/drawingmltypes.hxx>
#include <drawingml/textcharacterproperties.hxx>
+#include <svtools/unitconv.hxx>
#include <rtl/ustring.hxx>
#include <oox/mathml/importutils.hxx>
@@ -133,6 +134,19 @@ void TextParagraph::insertAt(
aioBulletList.setProperty( PROP_BulletColor, (*maRuns.begin())->getTextCharacterProperties().maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
if( !aioBulletList.hasProperty( PROP_BulletColor ) && aTextCharacterStyle.maFillProperties.moFillType.has() )
aioBulletList.setProperty( PROP_BulletColor, aTextCharacterStyle.maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
+ if( !aioBulletList.hasProperty( PROP_GraphicSize ) && maRuns.size() > 0
+ && aParaProp.getBulletList().maGraphic.hasValue())
+ {
+ float fFirstCharHeight = maRuns.front()->getTextCharacterProperties().getCharHeightPoints(12);
+ long nFirstCharHeightMm = TransformMetric(fFirstCharHeight * 100.f, FUNIT_POINT, FUNIT_MM);
+ float fBulletSizeRel = 1.f;
+ if( aParaProp.getBulletList().mnSize.hasValue() )
+ fBulletSizeRel = aParaProp.getBulletList().mnSize.get<sal_Int16>() / 100.f;
+
+ css::awt::Size aBulletSize;
+ aBulletSize.Width = aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR);
+ aioBulletList.setProperty( PROP_GraphicSize, aBulletSize);
+ }
float fCharacterSize = nCharHeight > 0 ? GetFontHeight ( nCharHeight ) : pTextParagraphStyle->getCharHeightPoints( 12 );
aParaProp.pushToPropSet( &rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), true, fCharacterSize, true );
diff --git a/oox/source/drawingml/textparagraphproperties.cxx b/oox/source/drawingml/textparagraphproperties.cxx
index bc523073bfff..c36912bb9dca 100644
--- a/oox/source/drawingml/textparagraphproperties.cxx
+++ b/oox/source/drawingml/textparagraphproperties.cxx
@@ -411,14 +411,6 @@ void TextParagraphProperties::pushToPropSet( const ::oox::core::XmlFilterBase* p
aPropSet.setProperty( PROP_ParaTopMargin, maParaTopMargin.toMargin( fCharacterSize != 0.0 ? fCharacterSize : getCharHeightPoints ( 12.0 ) ) );
if ( maParaBottomMargin.bHasValue || bPushDefaultValues )
aPropSet.setProperty( PROP_ParaBottomMargin, maParaBottomMargin.toMargin( fCharacterSize != 0.0 ? fCharacterSize : getCharHeightPoints ( 12.0 ) ) );
- if ( nNumberingType == NumberingType::BITMAP )
- {
- fCharacterSize = getCharHeightPoints( fCharacterSize );
-
- css::awt::Size aBulletSize;
- aBulletSize.Width = aBulletSize.Height = static_cast< sal_Int32 >( ( fCharacterSize * ( 2540.0 / 72.0 ) * 0.8 ) );
- rioBulletMap.setProperty( PROP_GraphicSize, aBulletSize);
- }
boost::optional< sal_Int32 > noParaLeftMargin( moParaLeftMargin );
boost::optional< sal_Int32 > noFirstLineIndentation( moFirstLineIndentation );
diff --git a/oox/source/drawingml/textparagraphpropertiescontext.cxx b/oox/source/drawingml/textparagraphpropertiescontext.cxx
index 616ec3d3cd0c..fdc9c3f210a9 100644
--- a/oox/source/drawingml/textparagraphpropertiescontext.cxx
+++ b/oox/source/drawingml/textparagraphpropertiescontext.cxx
@@ -182,7 +182,7 @@ ContextHandlerRef TextParagraphPropertiesContext::onCreateContext( sal_Int32 aEl
mrBulletList.setBulletSize(100);
break;
case A_TOKEN( buSzPct ): // CT_TextBulletSizePercent
- mrBulletList.setBulletSize( static_cast<sal_Int16>( GetPercent( rAttribs.getString( XML_val ).get() ) / 1000 ) );
+ mrBulletList.setBulletSize( std::lround( GetPercent( rAttribs.getString( XML_val ).get() ) / 1000.f ) );
break;
case A_TOKEN( buSzPts ): // CT_TextBulletSizePoint
mrBulletList.setBulletSize(0);
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index f500036e1282..9e161bb16615 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -26,10 +26,12 @@
#include <oox/export/utils.hxx>
#include <oox/drawingml/color.hxx>
#include <drawingml/fillproperties.hxx>
+#include <drawingml/textparagraph.hxx>
#include <oox/token/namespaces.hxx>
#include <oox/token/relationship.hxx>
#include <oox/token/tokens.hxx>
#include <oox/drawingml/drawingmltypes.hxx>
+#include <svtools/unitconv.hxx>
#include <cstdio>
#include <com/sun/star/awt/CharSet.hpp>
@@ -1872,7 +1874,7 @@ OUString GetAutoNumType(SvxNumType nNumberingType, bool bSDot, bool bPBehind, bo
return OUString();
}
-void DrawingML::WriteParagraphNumbering( const Reference< XPropertySet >& rXPropSet, sal_Int16 nLevel )
+void DrawingML::WriteParagraphNumbering(const Reference< XPropertySet >& rXPropSet, float fFirstCharHeight, sal_Int16 nLevel )
{
if( nLevel < 0 || !GETA( NumberingRules ) )
return;
@@ -1906,6 +1908,7 @@ void DrawingML::WriteParagraphNumbering( const Reference< XPropertySet >& rXProp
sal_Int16 nStartWith = 1;
sal_uInt32 nBulletColor = 0;
bool bHasBulletColor = false;
+ awt::Size aGraphicSize;
for ( sal_Int32 i = 0; i < nPropertyCount; i++ )
{
@@ -1965,13 +1968,8 @@ void DrawingML::WriteParagraphNumbering( const Reference< XPropertySet >& rXProp
}
else if ( aPropName == "GraphicSize" )
{
- if (auto aSize = o3tl::tryAccess<awt::Size>(pPropValue[i].Value))
- {
- // don't cast awt::Size to Size as on 64-bits they are not the same.
- //aBuGraSize.nA = aSize.Width;
- //aBuGraSize.nB = aSize.Height;
- SAL_INFO("oox.shape", "graphic size: " << aSize->Width << "x" << aSize->Height);
- }
+ aGraphicSize = *o3tl::doAccess<awt::Size>(pPropValue[i].Value);
+ SAL_INFO("oox.shape", "graphic size: " << aGraphicSize.Width << "x" << aGraphicSize.Height);
}
}
@@ -1982,6 +1980,11 @@ void DrawingML::WriteParagraphNumbering( const Reference< XPropertySet >& rXProp
{
OUString sRelId = WriteImage( aGraphicURL );
+ long nFirstCharHeightMm = TransformMetric(fFirstCharHeight * 100.f, FUNIT_POINT, FUNIT_MM);
+ float fBulletSizeRel = aGraphicSize.Height / static_cast<float>(nFirstCharHeightMm) / OOX_BULLET_LIST_SCALE_FACTOR;
+
+ mpFS->singleElementNS( XML_a, XML_buSzPct,
+ XML_val, IS( std::max( static_cast<sal_Int32>(25000), std::min( static_cast<sal_Int32>(400000), static_cast<sal_Int32>( std::lround( 100000.f * fBulletSizeRel ) ) ) ) ), FSEND );
mpFS->startElementNS( XML_a, XML_buBlip, FSEND );
mpFS->singleElementNS( XML_a, XML_blip, FSNS( XML_r, XML_embed ), USS( sRelId ), FSEND );
mpFS->endElementNS( XML_a, XML_buBlip );
@@ -2099,7 +2102,7 @@ void DrawingML::WriteLinespacing( const LineSpacing& rSpacing )
}
}
-void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rParagraph )
+void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rParagraph, float fFirstCharHeight)
{
Reference< XPropertySet > rXPropSet( rParagraph, UNO_QUERY );
Reference< XPropertyState > rXPropState( rParagraph, UNO_QUERY );
@@ -2196,7 +2199,7 @@ void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rPara
mpFS->endElementNS( XML_a, XML_spcAft );
}
- WriteParagraphNumbering( rXPropSet, nLevel );
+ WriteParagraphNumbering( rXPropSet, fFirstCharHeight, nLevel );
mpFS->endElementNS( XML_a, XML_pPr );
}
@@ -2225,7 +2228,12 @@ void DrawingML::WriteParagraph( const Reference< XTextContent >& rParagraph,
{
if( !bPropertiesWritten )
{
- WriteParagraphProperties( rParagraph );
+ float fFirstCharHeight = rnCharHeight / 1000.;
+ Reference< XPropertySet > xFirstRunPropSet (run, UNO_QUERY);
+ Reference< XPropertySetInfo > xFirstRunPropSetInfo = xFirstRunPropSet->getPropertySetInfo();
+ if( xFirstRunPropSetInfo->hasPropertyByName("CharHeight") )
+ fFirstCharHeight = xFirstRunPropSet->getPropertyValue("CharHeight").get<float>();
+ WriteParagraphProperties( rParagraph, fFirstCharHeight );
bPropertiesWritten = true;
}
WriteRun( run, rbOverridingCharHeight, rnCharHeight );
diff --git a/sd/qa/unit/data/odp/tdf90626.odp b/sd/qa/unit/data/odp/tdf90626.odp
new file mode 100644
index 000000000000..cea98fcd7018
--- /dev/null
+++ b/sd/qa/unit/data/odp/tdf90626.odp
Binary files differ
diff --git a/sd/qa/unit/data/pptx/tdf90626.pptx b/sd/qa/unit/data/pptx/tdf90626.pptx
new file mode 100644
index 000000000000..ef31fc92f126
--- /dev/null
+++ b/sd/qa/unit/data/pptx/tdf90626.pptx
Binary files differ
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx
index 2a380b3fc7ab..a3d477d2d1f6 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -124,6 +124,7 @@ public:
void testGroupsRotatedPosition();
void testAccentColor();
void testTdf68759();
+ void testTdf90626();
CPPUNIT_TEST_SUITE(SdOOXMLExportTest2);
@@ -173,6 +174,7 @@ public:
CPPUNIT_TEST(testGroupsRotatedPosition);
CPPUNIT_TEST(testAccentColor);
CPPUNIT_TEST(testTdf68759);
+ CPPUNIT_TEST(testTdf90626);
CPPUNIT_TEST_SUITE_END();
@@ -1319,6 +1321,21 @@ void SdOOXMLExportTest2::testTdf68759()
assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:pic[3]/p:spPr/a:xfrm", "flipH", "1");
assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:pic[3]/p:spPr/a:xfrm/a:off", "x", "5934960");
assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:pic[3]/p:spPr/a:xfrm/a:off", "y", "1615320");
+
+}
+
+void SdOOXMLExportTest2::testTdf90626()
+{
+ ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/odp/tdf90626.odp"), ODP);
+ utl::TempFile tempFile;
+ xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
+ xDocShRef->DoClose();
+
+ xmlDocPtr pXmlDocContent = parseExport(tempFile, "ppt/slides/slide1.xml");
+ assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[2]/p:txBody/a:p[1]/a:pPr/a:buSzPct", "val", "46986");
+ assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[2]/p:txBody/a:p[2]/a:pPr/a:buSzPct", "val", "150568");
+ assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[2]/p:txBody/a:p[3]/a:pPr/a:buSzPct", "val", "46986");
+ assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[2]/p:txBody/a:p[4]/a:pPr/a:buSzPct", "val", "150568");
}
CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest2);
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 0d2ede053bae..5f91f1ad2f75 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -165,6 +165,7 @@ public:
void testTdf109187();
void testTdf108926();
void testTdf100065();
+ void testTdf90626();
bool checkPattern(sd::DrawDocShellRef const & rDocRef, int nShapeNumber, std::vector<sal_uInt8>& rExpected);
void testPatternImport();
@@ -238,6 +239,7 @@ public:
CPPUNIT_TEST(testTdf109187);
CPPUNIT_TEST(testTdf108926);
CPPUNIT_TEST(testTdf100065);
+ CPPUNIT_TEST(testTdf90626);
CPPUNIT_TEST_SUITE_END();
};
@@ -2285,6 +2287,23 @@ void SdImportTest::testTdf100065()
xDocShRef->DoClose();
}
+void SdImportTest::testTdf90626()
+{
+ sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/tdf90626.pptx"), PPTX);
+ const SdrPage *pPage = GetPage(1, xDocShRef);
+ SdrTextObj *pTxtObj = dynamic_cast<SdrTextObj *>(pPage->GetObj(1));
+ CPPUNIT_ASSERT_MESSAGE("No text object", pTxtObj != nullptr);
+ const EditTextObject& aEdit = pTxtObj->GetOutlinerParaObject()->GetTextObject();
+ for(int i = 0; i < 4; i++)
+ {
+ const SvxNumBulletItem *pNumFmt = aEdit.GetParaAttribs(i).GetItem(EE_PARA_NUMBULLET);
+ CPPUNIT_ASSERT(pNumFmt);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(long(371), pNumFmt->GetNumRule()->GetLevel(0).GetGraphicSize().getHeight(), long(1));
+ }
+
+ xDocShRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest);
CPPUNIT_PLUGIN_IMPLEMENT();