diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-09-10 09:31:43 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-09-17 09:46:06 +0200 |
commit | c4ac2aa428e6a39bbf85e6ddac3dab05068c48cb (patch) | |
tree | b30633c226f123d7b58b0a40bab5432ffd2ecda1 /svx | |
parent | 7f1af7501242c799afd35aeed2ab798b431fbdbe (diff) |
Resolves: tdf#162455 svg->curve causes text in objects to disappear
Rather than assuming there is a uniform unchanging MapMode scaling,
follow the same pattern as SVGWriter and map positions/sizes back
relative to the original MapMode.
Examples of #i119125#, tdf#162455 and tdf#160625 work
Change-Id: I8229cebee6173fa4905828afb3b973c80ede3315
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173126
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
(cherry picked from commit 51f25098302e738a7d256620bd8e13bace8d060e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173301
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/svdraw/svdfmtf.cxx | 88 | ||||
-rw-r--r-- | svx/source/svdraw/svdfmtf.hxx | 9 |
2 files changed, 55 insertions, 42 deletions
diff --git a/svx/source/svdraw/svdfmtf.cxx b/svx/source/svdraw/svdfmtf.cxx index 90d2c509f837..a10a5ab234c6 100644 --- a/svx/source/svdraw/svdfmtf.cxx +++ b/svx/source/svdraw/svdfmtf.cxx @@ -82,7 +82,6 @@ ImpSdrGDIMetaFileImport::ImpSdrGDIMetaFileImport( const tools::Rectangle& rRect) : mpVD(VclPtr<VirtualDevice>::Create()), maScaleRect(rRect), - mnMapScalingOfs(0), mpModel(&rModel), mnLayer(nLay), mnLineWidth(0), @@ -210,6 +209,9 @@ size_t ImpSdrGDIMetaFileImport::DoImport( size_t nInsPos, SvdProgressInfo* pProgrInfo) { + maPrefMapMode = rMtf.GetPrefMapMode(); + mpVD->SetMapMode(maPrefMapMode); + // setup some global scale parameter // mfScaleX, mfScaleY, maScaleX, maScaleY, mbMov, mbSize mfScaleX = mfScaleY = 1.0; @@ -263,9 +265,6 @@ size_t ImpSdrGDIMetaFileImport::DoImport( nActionsToReport = 0; } - // MapMode scaling - MapScaling(); - // To calculate the progress meter, we use GetActionSize()*3. // However, maTmpList has a lower entry count limit than GetActionSize(), // so the actions that were assumed were too much have to be re-added. @@ -393,7 +392,7 @@ void ImpSdrGDIMetaFileImport::SetAttributes(SdrObject* pObj, bool bForceTextAttr if(bText && mbFntDirty) { vcl::Font aFnt(mpVD->GetFont()); - const sal_uInt32 nHeight(basegfx::fround(aFnt.GetFontSize().Height() * mfScaleY)); + const sal_uInt32 nHeight(basegfx::fround(implMap(aFnt.GetFontSize()).Height() * mfScaleY)); mpTextAttr->Put( SvxFontItem( aFnt.GetFamilyType(), aFnt.GetFamilyName(), aFnt.GetStyleName(), aFnt.GetPitch(), aFnt.GetCharSet(), EE_CHAR_FONTINFO ) ); mpTextAttr->Put( SvxFontItem( aFnt.GetFamilyType(), aFnt.GetFamilyName(), aFnt.GetStyleName(), aFnt.GetPitch(), aFnt.GetCharSet(), EE_CHAR_FONTINFO_CJK ) ); @@ -660,7 +659,8 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaLineAction const & rAct) return; basegfx::B2DPolygon aLine; - const basegfx::B2DHomMatrix aTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); + const basegfx::B2DHomMatrix aTransform(implMapMatrix() * + basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); aLine.append(aStart); aLine.append(aEnd); @@ -882,6 +882,7 @@ void ImpSdrGDIMetaFileImport::checkClip() if(isClip()) { const basegfx::B2DHomMatrix aTransform( + implMapMatrix() * basegfx::utils::createScaleTranslateB2DHomMatrix( mfScaleX, mfScaleY, @@ -904,7 +905,8 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaPolyLineAction const & rAct ) if(aSource.count()) { - const basegfx::B2DHomMatrix aTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); + const basegfx::B2DHomMatrix aTransform(implMapMatrix() * + basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); aSource.transform(aTransform); } @@ -950,7 +952,8 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaPolygonAction const & rAct ) if(!aSource.count()) return; - const basegfx::B2DHomMatrix aTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); + const basegfx::B2DHomMatrix aTransform(implMapMatrix() * + basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); aSource.transform(aTransform); if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource))) @@ -974,7 +977,8 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaPolyPolygonAction const & rAct) if(!aSource.count()) return; - const basegfx::B2DHomMatrix aTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); + const basegfx::B2DHomMatrix aTransform(implMapMatrix() * + basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); aSource.transform(aTransform); if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource)) @@ -990,6 +994,21 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaPolyPolygonAction const & rAct) } } +Size ImpSdrGDIMetaFileImport::implMap(const Size& rSz) const +{ + return OutputDevice::LogicToLogic(rSz, mpVD->GetMapMode(), maPrefMapMode); +} + +Point ImpSdrGDIMetaFileImport::implMap(const Point& rPt) const +{ + return OutputDevice::LogicToLogic(rPt, mpVD->GetMapMode(), maPrefMapMode); +} + +basegfx::B2DHomMatrix ImpSdrGDIMetaFileImport::implMapMatrix() const +{ + return OutputDevice::LogicToLogic(mpVD->GetMapMode(), maPrefMapMode); +} + void ImpSdrGDIMetaFileImport::ImportText( const Point& rPos, const OUString& rStr, const MetaAction& rAct ) { // calc text box size, add 5% to make it fit safely @@ -998,15 +1017,22 @@ void ImpSdrGDIMetaFileImport::ImportText( const Point& rPos, const OUString& rSt vcl::Font aFnt( mpVD->GetFont() ); TextAlign eAlg( aFnt.GetAlignment() ); - sal_Int32 nTextWidth = static_cast<sal_Int32>( mpVD->GetTextWidth( rStr ) * mfScaleX ); - sal_Int32 nTextHeight = static_cast<sal_Int32>( mpVD->GetTextHeight() * mfScaleY ); + Size aTextSizeMapped(implMap(Size(mpVD->GetTextWidth(rStr), mpVD->GetTextHeight()))); + + sal_Int32 nTextWidth = static_cast<sal_Int32>(aTextSizeMapped.Width() * mfScaleX); + sal_Int32 nTextHeight = static_cast<sal_Int32>(aTextSizeMapped.Height() * mfScaleY); + + Point aPosMapped(implMap(rPos)); - Point aPos(basegfx::fround<tools::Long>(rPos.X() * mfScaleX + maOfs.X()), - basegfx::fround<tools::Long>(rPos.Y() * mfScaleY + maOfs.Y())); + Point aPos(basegfx::fround<tools::Long>(aPosMapped.X() * mfScaleX + maOfs.X()), + basegfx::fround<tools::Long>(aPosMapped.Y() * mfScaleY + maOfs.Y())); Size aSize( nTextWidth, nTextHeight ); if ( eAlg == ALIGN_BASELINE ) - aPos.AdjustY(basegfx::fround<tools::Long>(aFontMetric.GetAscent() * -mfScaleY)); + { + auto nAscent = implMap(Size(0, aFontMetric.GetAscent())).Height(); + aPos.AdjustY(basegfx::fround<tools::Long>(nAscent * -mfScaleY)); + } else if ( eAlg == ALIGN_BOTTOM ) aPos.AdjustY( -nTextHeight ); @@ -1141,7 +1167,8 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaHatchAction const & rAct ) if(!aSource.count()) return; - const basegfx::B2DHomMatrix aTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); + const basegfx::B2DHomMatrix aTransform(implMapMatrix() * + basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); aSource.transform(aTransform); if(mbLastObjWasPolyWithoutLine && CheckLastPolyLineAndFillMerge(aSource)) @@ -1193,33 +1220,11 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaLineColorAction& rAct) void ImpSdrGDIMetaFileImport::DoAction(MetaMapModeAction& rAct) { - MapScaling(); rAct.Execute(mpVD); mbLastObjWasPolyWithoutLine = false; mbLastObjWasLine = false; } -void ImpSdrGDIMetaFileImport::MapScaling() -{ - const size_t nCount(maTmpList.size()); - const MapMode& rMap = mpVD->GetMapMode(); - Point aMapOrg( rMap.GetOrigin() ); - bool bMov2(aMapOrg.X() != 0 || aMapOrg.Y() != 0); - - if(bMov2) - { - for(size_t i = mnMapScalingOfs; i < nCount; i++) - { - SdrObject* pObj = maTmpList[i].get(); - - pObj->NbcMove(Size(aMapOrg.X(), aMapOrg.Y())); - } - } - - mnMapScalingOfs = nCount; -} - - void ImpSdrGDIMetaFileImport::DoAction( MetaCommentAction const & rAct, GDIMetaFile const & rMtf, size_t& a) // GDIMetaFile* pMtf ) { bool aSkipComment = false; @@ -1400,7 +1405,8 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaGradientAction const & rAct) if(aRange.isEmpty()) return; - const basegfx::B2DHomMatrix aTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); + const basegfx::B2DHomMatrix aTransform(implMapMatrix() * + basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); aRange.transform(aTransform); const Gradient& rGradient = rAct.GetGradient(); rtl::Reference<SdrRectObj> pRect = new SdrRectObj( @@ -1441,7 +1447,8 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaTransparentAction const & rAct) if(!aSource.count()) return; - const basegfx::B2DHomMatrix aTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); + const basegfx::B2DHomMatrix aTransform(implMapMatrix() * + basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); aSource.transform(aTransform); aSource.setClosed(true); @@ -1461,7 +1468,8 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaGradientExAction const & rAct) if(!aSource.count()) return; - const basegfx::B2DHomMatrix aTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); + const basegfx::B2DHomMatrix aTransform(implMapMatrix() * + basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); aSource.transform(aTransform); if(mbLastObjWasPolyWithoutLine && CheckLastPolyLineAndFillMerge(aSource)) diff --git a/svx/source/svdraw/svdfmtf.hxx b/svx/source/svdraw/svdfmtf.hxx index 6011293cfe92..5e4c0f0865b1 100644 --- a/svx/source/svdraw/svdfmtf.hxx +++ b/svx/source/svdraw/svdfmtf.hxx @@ -47,8 +47,8 @@ class ImpSdrGDIMetaFileImport final { ::std::vector< rtl::Reference<SdrObject> > maTmpList; ScopedVclPtr<VirtualDevice> mpVD; - tools::Rectangle maScaleRect; - size_t mnMapScalingOfs; // from here on, not edited with MapScaling + MapMode maPrefMapMode; + tools::Rectangle maScaleRect; std::unique_ptr<SfxItemSet> mpLineAttr; std::unique_ptr<SfxItemSet> mpFillAttr; std::unique_ptr<SfxItemSet> mpTextAttr; @@ -151,6 +151,11 @@ class ImpSdrGDIMetaFileImport final void DoLoopActions(GDIMetaFile const & rMtf, SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport); + // map from current virtual device mapmode to original mapmode + Size implMap(const Size& rSz) const; + Point implMap(const Point& rPt) const; + basegfx::B2DHomMatrix implMapMatrix() const; + // Copy assignment is forbidden and not implemented. ImpSdrGDIMetaFileImport (const ImpSdrGDIMetaFileImport &) = delete; ImpSdrGDIMetaFileImport & operator= (const ImpSdrGDIMetaFileImport &) = delete; |