Kaydet (Commit) 1e6abe31 authored tarafından Szymon Kłos's avatar Szymon Kłos

tdf#113037 create Watermark with correct ratio

Change-Id: I17ab8d98a618cff6e38dad344f4096dc520cce43
Reviewed-on: https://gerrit.libreoffice.org/44228Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarSzymon Kłos <szymon.klos@collabora.com>
üst 1bacce99
......@@ -4419,13 +4419,13 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r
OutputDevice* pOut = Application::GetDefaultDevice();
vcl::Font aFont( pOut->GetFont() );
aFont.SetFamilyName( aFontName );
auto nTextWidth = pOut->GetTextWidth( aObjectText );
tools::Rectangle aBoundingRect;
pOut->GetTextBoundRect( aBoundingRect, aObjectText );
OUString aObjName = GetPropertyString(DFF_Prop_wzName, rSt);
if ( nTextWidth && aObjData.eShapeType == mso_sptTextPlainText && aObjName.match("PowerPlusWaterMarkObject"))
if ( aBoundingRect.GetWidth() && aObjData.eShapeType == mso_sptTextPlainText && aObjName.match( "PowerPlusWaterMarkObject" ) )
{
fRatio = aFont.GetFontSize().Height();
fRatio /= nTextWidth;
fRatio = (double)aBoundingRect.GetHeight() / aBoundingRect.GetWidth();
sal_Int32 nNewHeight = fRatio * aObjData.aBoundRect.getWidth();
sal_Int32 nPaddingY = aObjData.aBoundRect.getHeight() - nNewHeight;
......
......@@ -24,6 +24,7 @@
#include <ftninfo.hxx>
#include <pagedesc.hxx>
#include <editeng/unoprnms.hxx>
class Test : public SwModelTestBase
{
......@@ -269,7 +270,10 @@ DECLARE_WW8EXPORT_TEST(testTdf91687, "tdf91687.doc")
uno::Reference<drawing::XShape> xWatermark = getShape(1);
uno::Reference<beans::XPropertySet> xWatermarkProperties(xWatermark, uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL((sal_Int32)5172, xWatermark->getSize().Height);
sal_Int32 nHeight = 0;
xWatermarkProperties->getPropertyValue(UNO_NAME_TEXT_UPPERDIST) >>= nHeight;
CPPUNIT_ASSERT_EQUAL((sal_Int32)5172, xWatermark->getSize().Height + nHeight);
CPPUNIT_ASSERT_EQUAL((sal_Int32)18105, xWatermark->getSize().Width);
}
......
......@@ -1307,14 +1307,22 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark,
// Calc the ratio.
double fRatio = 0;
double fRatioFrame = 0;
OutputDevice* pOut = Application::GetDefaultDevice();
vcl::Font aFont(pOut->GetFont());
aFont.SetFamilyName(sFont);
auto nTextWidth = pOut->GetTextWidth(rWatermark.GetText());
if (nTextWidth)
tools::Rectangle aBoundingRect;
pOut->GetTextBoundRect(aBoundingRect, rWatermark.GetText());
if (aBoundingRect.GetWidth())
{
fRatio = aFont.GetFontSize().Height();
fRatio /= nTextWidth;
fRatio = (double)aBoundingRect.GetHeight() / aBoundingRect.GetWidth();
auto nTextWidth = pOut->GetTextWidth(rWatermark.GetText());
if (nTextWidth)
{
fRatioFrame = aFont.GetFontSize().Height();
fRatioFrame /= nTextWidth;
}
}
// Calc the size.
......@@ -1339,7 +1347,8 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark,
xPageStyle->getPropertyValue(UNO_NAME_BOTTOM_MARGIN) >>= nBottomMargin;
nWidth = aSize.Height - nTopMargin - nBottomMargin;
}
sal_Int32 nHeight = nWidth * fRatio;
sal_Int32 nHeight = fRatio * nWidth;
sal_Int32 nFrameHeight = fRatioFrame * nWidth;
// Create and insert the shape.
uno::Reference<drawing::XShape> xShape(xMultiServiceFactory->createInstance(aShapeServiceName), uno::UNO_QUERY);
......@@ -1379,6 +1388,7 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark,
xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT_RELATION, uno::makeAny(static_cast<sal_Int16>(text::RelOrientation::PAGE_PRINT_AREA)));
xPropertySet->setPropertyValue(UNO_NAME_CHAR_FONT_NAME, uno::makeAny(sFont));
xPropertySet->setPropertyValue(UNO_NAME_CHAR_HEIGHT, uno::makeAny(WATERMARK_AUTO_SIZE));
xPropertySet->setPropertyValue(UNO_NAME_TEXT_UPPERDIST, uno::makeAny(sal_uInt32(nFrameHeight - nHeight)));
xPropertySet->setPropertyValue("Transformation", uno::makeAny(aMatrix));
xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT, uno::makeAny(static_cast<sal_Int16>(text::HoriOrientation::CENTER)));
xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT, uno::makeAny(static_cast<sal_Int16>(text::VertOrientation::CENTER)));
......
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