From 7884e7a8543cf9c05dea5fcd8bb73f79952bc52e Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Sat, 14 Apr 2018 16:20:11 -0400 Subject: svx: more accurate PDF imported text size Change-Id: I22880afdd9d36d9096003d86bba15098b465e0b3 (cherry picked from commit d583d4635f165a788c12ef336a25377239049253) --- svx/source/svdraw/svdpdf.cxx | 15 +++++++++++---- svx/source/svdraw/svdpdf.hxx | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index 59dc26c8da34..48bceeacc1e5 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -1037,6 +1037,8 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd return; } + const tools::Rectangle aRect = PointsToLogic(left, right, top, bottom); + const int nChars = FPDFTextObj_CountChars(pPageObject); std::unique_ptr pText(new sal_Unicode[nChars + 1]); // + terminating null @@ -1057,6 +1059,7 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd << ", " << e << ", " << f << ')'); Point aPos = PointsToLogic(e, f); SAL_WARN("sd.filter", "Got TEXT origin: " << aPos); + SAL_WARN("sd.filter", "Got TEXT Bounds: " << aRect); const double dFontSize = FPDFTextObj_GetFontSize(pPageObject); double dFontSizeH = fabs(sqrt2(a, c) * dFontSize); @@ -1078,10 +1081,10 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd aFnt.SetFontSize(Size(dFontSizeH, dFontSizeV)); mpVD->SetFont(aFnt); - ImportText(aPos, sText); + ImportText(aRect.TopLeft(), aRect.GetSize(), sText); } -void ImpSdrPdfImport::ImportText(const Point& rPos, const OUString& rStr) +void ImpSdrPdfImport::ImportText(const Point& rPos, const Size& rSize, const OUString& rStr) { // calc text box size, add 5% to make it fit safely @@ -1096,6 +1099,7 @@ void ImpSdrPdfImport::ImportText(const Point& rPos, const OUString& rStr) << ", Scaled: " << nTextWidth << 'x' << nTextHeight); Point aPos(FRound(rPos.X() * mfScaleX + maOfs.X()), FRound(rPos.Y() * mfScaleY + maOfs.Y())); + Size bSize(FRound(rSize.Width() * mfScaleX), FRound(rSize.Height() * mfScaleY)); Size aSize(nTextWidth, nTextHeight); if (eAlg == ALIGN_BASELINE) @@ -1103,8 +1107,11 @@ void ImpSdrPdfImport::ImportText(const Point& rPos, const OUString& rStr) else if (eAlg == ALIGN_BOTTOM) aPos.AdjustY(-nTextHeight); - tools::Rectangle aTextRect(aPos, aSize); - SAL_WARN("sd.filter", "Text Rect: " << aTextRect); + SAL_WARN("sd.filter", "Final POS: " << aPos); + SAL_WARN("sd.filter", "Final Text Size: " << aSize); + SAL_WARN("sd.filter", "Final Bound Size: " << bSize); + tools::Rectangle aTextRect(aPos, bSize); + // SAL_WARN("sd.filter", "Text Rect: " << aTextRect); SdrRectObj* pText = new SdrRectObj(*mpModel, OBJ_TEXT, aTextRect); pText->SetMergedItem(makeSdrTextUpperDistItem(0)); diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx index f8f9f0d0a17f..2adda0ee5e2d 100644 --- a/svx/source/svdraw/svdpdf.hxx +++ b/svx/source/svdraw/svdpdf.hxx @@ -105,7 +105,7 @@ class ImpSdrPdfImport final void ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex); void ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex); - void ImportText(const Point& rPos, const OUString& rStr); + void ImportText(const Point& rPos, const Size& rSize, const OUString& rStr); void SetAttributes(SdrObject* pObj, bool bForceTextAttr = false); void InsertObj(SdrObject* pObj, bool bScale = true); void MapScaling(); -- cgit v1.2.3