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.

Change-Id: I458184778c5e9e115d1a4eac749ecb6991b227a8
Reviewed-on: https://gerrit.libreoffice.org/24648
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
This commit is contained in:
Mike Kaganski 2016-04-13 20:07:52 +10:00 committed by Miklos Vajna
parent cbb6367e75
commit 940b21a87c
4 changed files with 78 additions and 28 deletions

View File

@ -893,7 +893,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 :
@ -903,20 +902,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;
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 :
{
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;
}
break;
default:
break;
}
nMinFrameWidth = rTextRect.GetWidth() - ( nTextLeft + nTextRight );
}
@ -949,7 +948,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 :
@ -959,20 +957,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;
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 :
{
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;
}
break;
default:
break;
}
nMinFrameHeight = rTextRect.GetHeight() - ( nTextTop + nTextBottom );
}

View File

@ -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 \

Binary file not shown.

View File

@ -42,6 +42,7 @@
#include <sax/tools/converter.hxx>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/drawing/GraphicExportFilter.hpp>
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
@ -64,6 +65,9 @@
#include <com/sun/star/table/XTableRows.hpp>
#include <stlpool.hxx>
#include <comphelper/processfactory.hxx>
#include <vcl/pngread.hxx>
#include <vcl/bitmapaccess.hxx>
using namespace ::com::sun::star;
@ -112,6 +116,7 @@ public:
void testTdf93830();
void testTdf93097();
void testTdf62255();
void testTdf93124();
void testTdf89927();
void testTdf93868();
void testTdf95932();
@ -160,6 +165,7 @@ public:
CPPUNIT_TEST(testTdf93830);
CPPUNIT_TEST(testTdf93097);
CPPUNIT_TEST(testTdf62255);
CPPUNIT_TEST(testTdf93124);
CPPUNIT_TEST(testTdf89927);
CPPUNIT_TEST(testTdf93868);
CPPUNIT_TEST(testTdf95932);
@ -1259,6 +1265,51 @@ void SdImportTest::testTdf62255()
xDocShRef->DoClose();
}
void SdImportTest::testTdf93124()
{
sd::DrawDocShellRef xDocShRef = loadURL(m_directories.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();
}
void SdImportTest::testTdf89927()
{
sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf89927.pptx"), PPTX);