diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-04-08 23:38:55 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-06-01 08:59:14 +0200 |
commit | 1cd2306527e44186eee78147e522e4adab38f862 (patch) | |
tree | 57ee6b2f47a9e7c6353eedf5f1f91dafd6d1a57b /svx | |
parent | fffc15fc36ac9c6b4a609c3d5a7322573d1e3d29 (diff) |
svx: more accurate PDF text importing
Change-Id: If37119510cbc091dc86cb5f699984186167745c7
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/svdraw/svdpdf.cxx | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index 39eeb09809c6..a9cba942973a 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -236,8 +236,67 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc switch (nPageObjectType) { case FPDF_PAGEOBJ_TEXT: + { SAL_WARN("sd.filter", "Got page object TEXT"); - break; + float left; + float bottom; + float right; + float top; + if (!FPDFPageObj_GetBounds(pPageObject, &left, &bottom, &right, &top)) + { + SAL_WARN("sd.filter", "FAILED to get TEXT bounds"); + } + + SAL_WARN("sd.filter", "Got TEXT bounds left: " << left << ", right: " << right + << ", top: " << top + << ", bottom: " << bottom); + tools::Rectangle aRect = PointsToLogic(left, right, top, bottom); + + double dFontScale = 1.0; + geometry::Matrix2D aMatrix; + FPDFTextObj_GetMatrix(pPageObject, &aMatrix.m00, &aMatrix.m01, &aMatrix.m10, + &aMatrix.m11); + if (aMatrix.m00 != aMatrix.m11 || aMatrix.m00 <= 0) + { + SAL_WARN("sd.filter", "Bogus font scale matrix (" + << aMatrix.m00 << ',' << aMatrix.m11 + << "), will use heuristic height of " + << aRect.GetHeight() << "."); + dFontScale = aRect.GetHeight(); + } + else + dFontScale = aMatrix.m00; + + double dFontSize = FPDFTextObj_GetFontSize(pPageObject); + SAL_WARN("sd.filter", "Got Font Size: " << dFontSize); + dFontSize *= dFontScale; + SAL_WARN("sd.filter", "Got Font Size Scaled: " << dFontSize); + dFontSize = lcl_PointToPixel(dFontSize); + SAL_WARN("sd.filter", "Got Font Pixel Size: " << dFontSize); + dFontSize = lcl_ToLogic(dFontSize); + SAL_WARN("sd.filter", "Got Font Logic Size: " << dFontSize); + vcl::Font aFnt = mpVD->GetFont(); + aFnt.SetFontSize(Size(dFontSize, dFontSize)); + mpVD->SetFont(aFnt); + + const int nChars = FPDFTextObj_CountChars(pPageObject); + std::unique_ptr<sal_Unicode[]> pText( + new sal_Unicode[nChars + 1]); // + terminating null + + unsigned short* pShortText = reinterpret_cast<unsigned short*>(pText.get()); + const int nActualChars + = FPDFTextObj_GetText(pPageObject, 0, nChars, pShortText); + OUString sText(pText.get(), nActualChars); + + // for (int nChar = 0; nChar < nChars; ++nChar) + // pText[nChar] = static_cast<sal_Unicode>(FPDFTextObj_GetUnicode(pPageObject, nChar)); + // OUString sText(pText.get(), nChars); + SAL_WARN("sd.filter", "Got Text #" << nPageObjectIndex + 1 << " (" << nChars + << "): [" << sText << "]."); + + ImportText(aRect.TopLeft(), sText); + } + break; case FPDF_PAGEOBJ_PATH: SAL_WARN("sd.filter", "Got page object PATH"); break; @@ -256,6 +315,7 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc } } +#if 0 // Now do the text. FPDF_TEXTPAGE pTextPage = FPDFText_LoadPage(pPdfPage); if (pTextPage != nullptr) @@ -406,6 +466,7 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc FPDFText_ClosePage(pTextPage); } +#endif FPDF_ClosePage(pPdfPage); } |