From ac2732bdc63fa687909fdf03e2a91081003f109e Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 13 Apr 2016 20:07:52 +1000 Subject: tdf#93124: Fix incorrect text fit in imported PPT - take two This patch just fixes incorrect decision when the block alignment must be applied. Also, unit test is included. Reviewed-on: https://gerrit.libreoffice.org/24648 Tested-by: Jenkins Reviewed-by: Miklos Vajna (cherry picked from commit 940b21a87cffffca0985c33e9ebb78ddf3aa0c3b) Change-Id: I458184778c5e9e115d1a4eac749ecb6991b227a8 Reviewed-on: https://gerrit.libreoffice.org/24678 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- filter/source/msfilter/svdfppt.cxx | 54 ++++++++++++++++++------------------- sd/CppunitTest_sd_import_tests.mk | 1 + sd/qa/unit/data/ppt/tdf93124.ppt | Bin 0 -> 85504 bytes sd/qa/unit/import-tests.cxx | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 sd/qa/unit/data/ppt/tdf93124.ppt diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx index f9d14e830fd7..127e779aab41 100644 --- a/filter/source/msfilter/svdfppt.cxx +++ b/filter/source/msfilter/svdfppt.cxx @@ -889,7 +889,6 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, voi eTHA = SDRTEXTHORZADJUST_LEFT; break; } - // if there is a 100% use of following attributes, the textbox can been aligned also in vertical direction switch ( eTextAnchor ) { case mso_anchorTopCentered : @@ -899,20 +898,20 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, voi case mso_anchorBottomCenteredBaseline: { // check if it is sensible to use the centered alignment - sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT; - if ( ( nTextFlags & nMask ) != nMask ) // if the textobject has left and also right aligned pararagraphs - eTVA = SDRTEXTVERTADJUST_CENTER; // the text has to be displayed using the full width; - } - break; - - default : - { - if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT ) - eTVA = SDRTEXTVERTADJUST_TOP; - else if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT ) - eTVA = SDRTEXTVERTADJUST_BOTTOM; + const sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_CENTER | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_BLOCK; + switch (nTextFlags & nMask) + { + case PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT: + case PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_CENTER: + case PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT: + case PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_BLOCK: + eTVA = SDRTEXTVERTADJUST_CENTER; // If the textobject has only one type of alignment, then the text has not to be displayed using the full width; + break; + } + break; } - break; + default: + break; } nMinFrameWidth = rTextRect.GetWidth() - ( nTextLeft + nTextRight ); } @@ -945,7 +944,6 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, voi eTVA = SDRTEXTVERTADJUST_BOTTOM; break; } - // if there is a 100% usage of following attributes, the textbox can be aligned also in horizontal direction switch ( eTextAnchor ) { case mso_anchorTopCentered : @@ -955,20 +953,20 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, voi case mso_anchorBottomCenteredBaseline: { // check if it is sensible to use the centered alignment - sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT; - if ( ( nTextFlags & nMask ) != nMask ) // if the textobject has left and also right aligned pararagraphs - eTHA = SDRTEXTHORZADJUST_CENTER; // the text has to be displayed using the full width; - } - break; - - default : - { - if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT ) - eTHA = SDRTEXTHORZADJUST_LEFT; - else if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT ) - eTHA = SDRTEXTHORZADJUST_RIGHT; + const sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_CENTER | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_BLOCK; + switch (nTextFlags & nMask) + { + case PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT: + case PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_CENTER: + case PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT: + case PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_BLOCK: + eTHA = SDRTEXTHORZADJUST_CENTER; // If the textobject has only one type of alignment, then the text has not to be displayed using the full width; + break; + } + break; } - break; + default: + break; } nMinFrameHeight = rTextRect.GetHeight() - ( nTextTop + nTextBottom ); } diff --git a/sd/CppunitTest_sd_import_tests.mk b/sd/CppunitTest_sd_import_tests.mk index 6058e8e58cfc..33a7ad28d463 100644 --- a/sd/CppunitTest_sd_import_tests.mk +++ b/sd/CppunitTest_sd_import_tests.mk @@ -96,6 +96,7 @@ $(eval $(call gb_CppunitTest_use_components,sd_import_tests,\ sot/util/sot \ svl/source/fsstor/fsstorage \ svtools/util/svt \ + svx/util/svxcore \ toolkit/util/tk \ ucb/source/core/ucb1 \ ucb/source/ucp/expand/ucpexpand1 \ diff --git a/sd/qa/unit/data/ppt/tdf93124.ppt b/sd/qa/unit/data/ppt/tdf93124.ppt new file mode 100644 index 000000000000..fad847898cc6 Binary files /dev/null and b/sd/qa/unit/data/ppt/tdf93124.ppt differ diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index 4ae4e4ecc8c2..2f74f1339a15 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -61,6 +62,9 @@ #include #include +#include +#include +#include using namespace ::com::sun::star; @@ -107,6 +111,7 @@ public: void testRowHeight(); void testTdf93830(); void testTdf93097(); + void testTdf93124(); CPPUNIT_TEST_SUITE(SdImportTest); @@ -149,6 +154,7 @@ public: CPPUNIT_TEST(testRowHeight); CPPUNIT_TEST(testTdf93830); CPPUNIT_TEST(testTdf93097); + CPPUNIT_TEST(testTdf93124); CPPUNIT_TEST_SUITE_END(); }; @@ -1165,6 +1171,51 @@ void SdImportTest::testTdf93097() xDocShRef->DoClose(); } +void SdImportTest::testTdf93124() +{ + sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/ppt/tdf93124.ppt"), PPT); + uno::Reference < uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); + uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter = drawing::GraphicExportFilter::create(xContext); + + uno::Sequence< beans::PropertyValue > aFilterData(2); + aFilterData[0].Name = "PixelWidth"; + aFilterData[0].Value <<= (sal_Int32)(320); + aFilterData[1].Name = "PixelHeight"; + aFilterData[1].Value <<= (sal_Int32)(180); + + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + + uno::Sequence< beans::PropertyValue > aDescriptor(3); + aDescriptor[0].Name = "URL"; + aDescriptor[0].Value <<= aTempFile.GetURL(); + aDescriptor[1].Name = "FilterName"; + aDescriptor[1].Value <<= OUString("PNG"); + aDescriptor[2].Name = "FilterData"; + aDescriptor[2].Value <<= aFilterData; + + uno::Reference< lang::XComponent > xPage(getPage(0, xDocShRef), uno::UNO_QUERY); + xGraphicExporter->setSourceDocument(xPage); + xGraphicExporter->filter(aDescriptor); + + SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ); + vcl::PNGReader aPNGReader(aFileStream); + BitmapEx aBMPEx = aPNGReader.Read(); + Bitmap aBMP = aBMPEx.GetBitmap(); + BitmapReadAccess* pRead = aBMP.AcquireReadAccess(); + int nNonWhiteCount = 0; + // The word "Top" should be in rectangle 34,4 - 76,30. If text alignment is wrong, the rectangle will be white. + for (long nX = 34; nX < (34 + 43); ++nX) + for (long nY = 4; nY < (4 + 26); ++nY) + { + const Color aColor = pRead->GetColor(nY, nX); + if ((aColor.GetRed() != 0xff) || (aColor.GetGreen() != 0xff) || (aColor.GetBlue() != 0xff)) + ++nNonWhiteCount; + } + CPPUNIT_ASSERT_MESSAGE("Tdf93124: vertical alignment of text is incorrect!", nNonWhiteCount>100); + xDocShRef->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3