From c2e30949e0fb7c6a73742450f646e0d8d59d5e4f Mon Sep 17 00:00:00 2001 From: Marco Cecchetti Date: Wed, 10 Apr 2019 15:13:53 +0200 Subject: lok: writer: svg export transformed images Change-Id: I908a6e01573c35c0641519f4995730af0b033c33 Reviewed-on: https://gerrit.libreoffice.org/70565 Tested-by: Jenkins Reviewed-by: Marco Cecchetti --- filter/source/svg/svgexport.cxx | 2 +- sd/qa/unit/tiledrendering/tiledrendering.cxx | 36 ++++++++++++++------------- svx/source/svdraw/svdmrkv.cxx | 37 +++++++++++++++++++--------- sw/inc/cmdid.h | 2 ++ sw/inc/unoprnms.hxx | 1 + sw/source/core/draw/dflyobj.cxx | 13 ++++++++++ sw/source/core/inc/dflyobj.hxx | 1 + sw/source/core/unocore/unoframe.cxx | 31 +++++++++++++++++++++++ sw/source/core/unocore/unomap1.cxx | 1 + 9 files changed, 95 insertions(+), 29 deletions(-) diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx index 817c529f69d0..a674456be182 100644 --- a/filter/source/svg/svgexport.cxx +++ b/filter/source/svg/svgexport.cxx @@ -687,7 +687,7 @@ bool SVGFilter::implExportWriterTextGraphic( const Reference< view::XSelectionSu { uno::Reference xPropertySet(xSelection, uno::UNO_QUERY); uno::Reference xGraphic; - xPropertySet->getPropertyValue("Graphic") >>= xGraphic; + xPropertySet->getPropertyValue("TransformedGraphic") >>= xGraphic; if (!xGraphic.is()) return false; diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index a35fdc6bf785..8ac4be6fdd2f 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -871,11 +871,11 @@ void SdTiledRenderingTest::testResizeTable() auto pTableObject = dynamic_cast(pObject); CPPUNIT_ASSERT(pTableObject); - SdrHdlList handleList(nullptr); - pObject->AddToHdlList(handleList); - CPPUNIT_ASSERT_EQUAL(static_cast(14), handleList.GetHdlCount()); - // Take the top left handle - SdrHdl* pHdl = handleList.GetHdl(0); + // Select the table by marking it + starting and ending text edit. + SdrView* pView = pViewShell->GetView(); + pView->MarkObj(pObject, pView->GetSdrPageView()); + pView->SdrBeginTextEdit(pObject); + pView->SdrEndTextEdit(); // Remember the original row heights. uno::Reference xTable(pTableObject->getTable(), uno::UNO_QUERY); @@ -886,14 +886,15 @@ void SdTiledRenderingTest::testResizeTable() sal_Int32 nExpectedRow2 = xRow2->getPropertyValue("Size").get(); // Resize the upper row, decrease its height by 1 cm. - pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_START, convertMm100ToTwip(pHdl->GetPos().getX()), convertMm100ToTwip(pHdl->GetPos().getY())); - pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_END, convertMm100ToTwip(pHdl->GetPos().getX()), convertMm100ToTwip(pHdl->GetPos().getY() + 1000)); + Point aInnerRowEdge = pObject->GetSnapRect().Center(); + pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_START, convertMm100ToTwip(aInnerRowEdge.getX()), convertMm100ToTwip(aInnerRowEdge.getY())); + pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_END, convertMm100ToTwip(aInnerRowEdge.getX()), convertMm100ToTwip(aInnerRowEdge.getY() - 1000)); // Remember the resized row heights. sal_Int32 nResizedRow1 = xRow1->getPropertyValue("Size").get(); CPPUNIT_ASSERT(nResizedRow1 < nExpectedRow1); sal_Int32 nResizedRow2 = xRow2->getPropertyValue("Size").get(); - CPPUNIT_ASSERT(nResizedRow2 < nExpectedRow2); + CPPUNIT_ASSERT_EQUAL(nExpectedRow2, nResizedRow2); // Now undo the resize. pXImpressDocument->GetDocShell()->GetUndoManager()->Undo(); @@ -903,7 +904,7 @@ void SdTiledRenderingTest::testResizeTable() CPPUNIT_ASSERT_EQUAL(nExpectedRow1, nActualRow1); sal_Int32 nActualRow2 = xRow2->getPropertyValue("Size").get(); // Expected was 4000, actual was 4572, i.e. the second row after undo was larger than expected. - CPPUNIT_ASSERT_DOUBLES_EQUAL(nExpectedRow2, nActualRow2, 1.0); + CPPUNIT_ASSERT_EQUAL(nExpectedRow2, nActualRow2); comphelper::LibreOfficeKit::setActive(false); } @@ -918,11 +919,11 @@ void SdTiledRenderingTest::testResizeTableColumn() auto pTableObject = dynamic_cast(pObject); CPPUNIT_ASSERT(pTableObject); - SdrHdlList handleList(nullptr); - pObject->AddToHdlList(handleList); - CPPUNIT_ASSERT_EQUAL(static_cast(14), handleList.GetHdlCount()); - // Take the top left handle - SdrHdl* pHdl = handleList.GetHdl(0); + // Select the table by marking it + starting and ending text edit. + SdrView* pView = pViewShell->GetView(); + pView->MarkObj(pObject, pView->GetSdrPageView()); + pView->SdrBeginTextEdit(pObject); + pView->SdrEndTextEdit(); // Remember the original cell widths. xmlDocPtr pXmlDoc = parseXmlDump(); @@ -933,15 +934,16 @@ void SdTiledRenderingTest::testResizeTableColumn() pXmlDoc = nullptr; // Resize the left column, decrease its width by 1 cm. - pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_START, convertMm100ToTwip(pHdl->GetPos().getX()), convertMm100ToTwip(pHdl->GetPos().getY())); - pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_END, convertMm100ToTwip(pHdl->GetPos().getX() + 1000), convertMm100ToTwip(pHdl->GetPos().getY())); + Point aInnerRowEdge = pObject->GetSnapRect().Center(); + pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_START, convertMm100ToTwip(aInnerRowEdge.getX()), convertMm100ToTwip(aInnerRowEdge.getY())); + pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_END, convertMm100ToTwip(aInnerRowEdge.getX() - 1000), convertMm100ToTwip(aInnerRowEdge.getY())); // Remember the resized column widths. pXmlDoc = parseXmlDump(); sal_Int32 nResizedColumn1 = getXPath(pXmlDoc, aPrefix + "TableLayouter_Layout[1]", "size").toInt32(); CPPUNIT_ASSERT(nResizedColumn1 < nExpectedColumn1); sal_Int32 nResizedColumn2 = getXPath(pXmlDoc, aPrefix + "TableLayouter_Layout[2]", "size").toInt32(); - CPPUNIT_ASSERT(nResizedColumn2 < nExpectedColumn2); + CPPUNIT_ASSERT(nResizedColumn2 > nExpectedColumn2); xmlFreeDoc(pXmlDoc); pXmlDoc = nullptr; diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx index fa4ea376ae90..3bbf3b4a72ed 100644 --- a/svx/source/svdraw/svdmrkv.cxx +++ b/svx/source/svdraw/svdmrkv.cxx @@ -560,13 +560,10 @@ void SdrMarkView::showMarkHandles() bool SdrMarkView::ImpIsFrameHandles() const { - // There can be multiple mark views, but we're only interested in the one that has a window associated. - const bool bTiledRendering = comphelper::LibreOfficeKit::isActive() && GetFirstOutputDevice() && GetFirstOutputDevice()->GetOutDevType() == OUTDEV_WINDOW; - const size_t nMarkCount=GetMarkedObjectCount(); bool bFrmHdl=nMarkCount>static_cast(mnFrameHandlesLimit) || mbForceFrameHandles; bool bStdDrag=meDragMode==SdrDragMode::Move; - if (!bTiledRendering && nMarkCount==1 && bStdDrag && bFrmHdl) + if (nMarkCount==1 && bStdDrag && bFrmHdl) { const SdrObject* pObj=GetMarkedObjectByIndex(0); if (pObj->GetObjInventor()==SdrInventor::Default) @@ -648,7 +645,7 @@ void SdrMarkView::SetMarkHandles(SfxViewShell* pOtherShell) bool bSingleTextObjMark=false; bool bLimitedRotation(false); - if (!bTiledRendering && nMarkCount==1) + if (nMarkCount==1) { mpMarkedObj=GetMarkedObjectByIndex(0); @@ -781,15 +778,33 @@ void SdrMarkView::SetMarkHandles(SfxViewShell* pOtherShell) } if(SfxViewShell* pViewShell = GetSfxViewShell()) { - - long nRotAngle(0); - if(GetMarkedObjectCount()) + if (GetMarkedObjectCount()) { - SdrMark* pM = GetSdrMarkByIndex(0); - SdrObject* pO = pM->GetMarkedSdrObj(); + SdrObject* pO = mpMarkedObj; + long nRotAngle = pO->GetRotateAngle(); + // true if we are delaing with a RotGrfFlyFrame + // (SwVirtFlyDrawObj with a SwGrfNode) + bool bWriterGraphic = pO->HasLimitedRotation(); + + if (bWriterGraphic) + { + nRotAngle *= 10; + } - nRotAngle = pO->GetRotateAngle(); sSelection += OString(", ") + OString::number(nRotAngle); + + OString sProperties; + + if (bWriterGraphic) + { + sProperties = "{ WriterGraphic=true }"; + } + + if (!sProperties.isEmpty()) + { + sSelection += ", "; + sSelection += sProperties; + } } if (pOtherShell) diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h index 9e4794dc7c3a..55ec66b1a116 100644 --- a/sw/inc/cmdid.h +++ b/sw/inc/cmdid.h @@ -608,6 +608,8 @@ #define FN_UNO_VISIBLE_AREA_WIDTH (FN_EXTRA2 + 125) #define FN_UNO_VISIBLE_AREA_HEIGHT (FN_EXTRA2 + 126) +#define FN_UNO_TRANSFORMED_GRAPHIC (FN_EXTRA2 + 125) + // Area: Help // Region: Traveling & Selection #define FN_CHAR_LEFT (FN_SELECTION + 1 ) /* */ diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx index 731c7a719b49..8e03b0bb9c59 100644 --- a/sw/inc/unoprnms.hxx +++ b/sw/inc/unoprnms.hxx @@ -161,6 +161,7 @@ #define UNO_NAME_DROP_CAP_CHAR_STYLE_NAME "DropCapCharStyleName" #define UNO_NAME_FILE_LINK "FileLink" #define UNO_NAME_GRAPHIC "Graphic" +#define UNO_NAME_TRANSFORMED_GRAPHIC "TransformedGraphic" #define UNO_NAME_IS_PROTECTED "IsProtected" #define UNO_NAME_PARA_KEEP_TOGETHER "ParaKeepTogether" #define UNO_NAME_KEEP_TOGETHER "KeepTogether" diff --git a/sw/source/core/draw/dflyobj.cxx b/sw/source/core/draw/dflyobj.cxx index dd73a1d13df2..0b510dd767c9 100644 --- a/sw/source/core/draw/dflyobj.cxx +++ b/sw/source/core/draw/dflyobj.cxx @@ -1171,6 +1171,19 @@ sal_uInt16 SwVirtFlyDrawObj::getPossibleRotationFromFraphicFrame(Size& rSize) co return nRetval; } +long SwVirtFlyDrawObj::GetRotateAngle() const +{ + if(ContainsSwGrfNode()) + { + Size aSize; + return getPossibleRotationFromFraphicFrame(aSize); + } + else + { + return SdrVirtObj::GetRotateAngle(); + } +} + SdrObject* SwVirtFlyDrawObj::getFullDragClone() const { // call parent diff --git a/sw/source/core/inc/dflyobj.hxx b/sw/source/core/inc/dflyobj.hxx index c3acae10198e..5ede9007ec24 100644 --- a/sw/source/core/inc/dflyobj.hxx +++ b/sw/source/core/inc/dflyobj.hxx @@ -96,6 +96,7 @@ public: // we treat the size calculation completely on ourself here virtual const tools::Rectangle& GetCurrentBoundRect() const override; virtual const tools::Rectangle& GetLastBoundRect() const override; + virtual long GetRotateAngle() const override; virtual void RecalcBoundRect() override; virtual void RecalcSnapRect() override; virtual const tools::Rectangle& GetSnapRect() const override; diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index 25e1edcf37d5..b9806727394e 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -2094,6 +2095,36 @@ uno::Any SwXFrame::getPropertyValue(const OUString& rPropertyName) aAny <<= pGrfNode->GetGrf().GetXGraphic(); } } + else if( FN_UNO_TRANSFORMED_GRAPHIC == pEntry->nWID ) + { + const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx(); + if(pIdx) + { + SwNodeIndex aIdx(*pIdx, 1); + SwGrfNode* pGrfNode = aIdx.GetNode().GetGrfNode(); + if(!pGrfNode) + throw uno::RuntimeException(); + + SwDoc* pDoc = pFormat->GetDoc(); + if (pDoc) + { + const SwEditShell* pEditShell = pDoc->GetEditShell(); + if (pEditShell) + { + SwFrame* pCurrFrame = pEditShell->GetCurrFrame(false); + GraphicAttr aGraphicAttr; + pGrfNode->GetGraphicAttr( aGraphicAttr, pCurrFrame ); + const GraphicObject aGraphicObj = pGrfNode->GetGrfObj(); + + awt::Size aFrameSize = getSize(); + Size aSize100thmm(aFrameSize.Width, aFrameSize.Height); + Size aSize = OutputDevice::LogicToLogic(aSize100thmm, MapMode(MapUnit::Map100thMM), aGraphicObj.GetPrefMapMode()); + Graphic aGraphic = aGraphicObj.GetTransformedGraphic(aSize, aGraphicObj.GetPrefMapMode(), aGraphicAttr); + aAny <<= aGraphic.GetXGraphic(); + } + } + } + } else if(FN_UNO_FRAME_STYLE_NAME == pEntry->nWID) { aAny <<= SwStyleNameMapper::GetProgName(pFormat->DerivedFrom()->GetName(), SwGetPoolIdFromName::FrmFmt ); diff --git a/sw/source/core/unocore/unomap1.cxx b/sw/source/core/unocore/unomap1.cxx index 6bb635b0feb2..f5976ca50a4c 100644 --- a/sw/source/core/unocore/unomap1.cxx +++ b/sw/source/core/unocore/unomap1.cxx @@ -852,6 +852,7 @@ const SfxItemPropertyMapEntry* SwUnoPropertyMapProvider::GetGraphicPropertyMap( { OUString(UNO_NAME_GRAPHIC_FILTER), FN_UNO_GRAPHIC_FILTER, cppu::UnoType::get(), 0, 0 }, { OUString(UNO_NAME_GRAPHIC), FN_UNO_GRAPHIC, cppu::UnoType::get(), 0, 0 }, { OUString(UNO_NAME_GRAPHIC_URL), FN_UNO_GRAPHIC_URL, cppu::UnoType::get(), 0, 0 }, + { OUString(UNO_NAME_TRANSFORMED_GRAPHIC), FN_UNO_TRANSFORMED_GRAPHIC, cppu::UnoType::get(), 0, 0 }, { OUString(UNO_NAME_ACTUAL_SIZE), FN_UNO_ACTUAL_SIZE, cppu::UnoType::get(), PropertyAttribute::READONLY, CONVERT_TWIPS}, { OUString(UNO_NAME_CONTOUR_POLY_POLYGON), FN_PARAM_CONTOUR_PP, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, 0 }, { OUString(UNO_NAME_IS_PIXEL_CONTOUR), FN_UNO_IS_PIXEL_CONTOUR, cppu::UnoType::get(), PROPERTY_NONE, 0 }, -- cgit