diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-05-18 09:15:36 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-05-22 12:17:19 +0200 |
commit | 5217375499e314e909d8e1c2a6a815bda46ca5b0 (patch) | |
tree | 3cda99cdc82da5afb203e17e9c1ba5bf1f9209ba | |
parent | svx: transform PDF text rectangles while importing (diff) | |
download | core-5217375499e314e909d8e1c2a6a815bda46ca5b0.tar.gz core-5217375499e314e909d8e1c2a6a815bda46ca5b0.zip |
svx: cleanup pdfium importer
Change-Id: Id925ba7734a2c73270e40f19d3fc50552441c34e
-rw-r--r-- | external/pdfium/edit.patch.1 | 138 | ||||
-rw-r--r-- | svx/source/svdraw/svdpdf.cxx | 305 | ||||
-rw-r--r-- | svx/source/svdraw/svdpdf.hxx | 12 |
3 files changed, 26 insertions, 429 deletions
diff --git a/external/pdfium/edit.patch.1 b/external/pdfium/edit.patch.1 index a110313017da..5b23140c2069 100644 --- a/external/pdfium/edit.patch.1 +++ b/external/pdfium/edit.patch.1 @@ -1,43 +1,8 @@ diff --git a/core/fpdfapi/page/cpdf_colorstate.cpp b/core/fpdfapi/page/cpdf_colorstate.cpp -index 693fcf1..d3e1202 100644 +index 693fcf1..14e883f 100644 --- a/core/fpdfapi/page/cpdf_colorstate.cpp +++ b/core/fpdfapi/page/cpdf_colorstate.cpp -@@ -74,6 +74,8 @@ void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS, - uint32_t nValues) { - ColorData* pData = m_Ref.GetPrivateCopy(); - SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues); -+ if (pData->m_FillRGB != 0 && pData->m_FillRGB != 0xFFFFFFFF) -+ fprintf(stderr, "COLOR FILL!!!!> %x\n", pData->m_FillRGB); - } - - void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS, -@@ -81,6 +83,8 @@ void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS, - uint32_t nValues) { - ColorData* pData = m_Ref.GetPrivateCopy(); - SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues); -+ if (pData->m_StrokeRGB != 0 && pData->m_StrokeRGB != 0xFFFFFFFF) -+ fprintf(stderr, "COLOR STROkE!!!!> %x\n", pData->m_StrokeRGB); - } - - void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, -@@ -99,6 +103,8 @@ void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, - } - } - pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : 0xFFFFFFFF; -+ if (pData->m_FillRGB != 0 && pData->m_FillRGB != 0xFFFFFFFF) -+ fprintf(stderr, "COLOR FILL!!!!> %x\n", pData->m_FillRGB); - } - - void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, -@@ -118,13 +124,15 @@ void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, - } - pData->m_StrokeRGB = - pData->m_StrokeColor.GetRGB(&R, &G, &B) ? FXSYS_RGB(R, G, B) : 0xFFFFFFFF; -+ if (pData->m_StrokeRGB != 0 && pData->m_StrokeRGB != 0xFFFFFFFF) -+ fprintf(stderr, "COLOR STROkE!!!!> %x\n", pData->m_StrokeRGB); - } - - void CPDF_ColorState::SetColor(CPDF_Color& color, +@@ -124,7 +124,7 @@ void CPDF_ColorState::SetColor(CPDF_Color& color, uint32_t& rgb, CPDF_ColorSpace* pCS, float* pValue, @@ -59,57 +24,6 @@ index 9619051..dbe9c47 100644 SharedCopyOnWrite<ColorData> m_Ref; }; -diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp -index 3b5a740..416d82d 100644 ---- a/core/fpdfapi/page/cpdf_imageobject.cpp -+++ b/core/fpdfapi/page/cpdf_imageobject.cpp -@@ -43,6 +43,7 @@ const CPDF_ImageObject* CPDF_ImageObject::AsImage() const { - void CPDF_ImageObject::CalcBoundingBox() { - std::tie(m_Left, m_Right, m_Top, m_Bottom) = - m_Matrix.TransformRect(0.f, 1.f, 1.f, 0.f); -+ // fprintf(stderr, "Image BB: %f, %f, %f, %f\n", m_Left, m_Right, m_Top, m_Bottom); - } - - void CPDF_ImageObject::SetImage(const RetainPtr<CPDF_Image>& pImage) { -diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp -index ba93f4a..70d398b 100644 ---- a/core/fpdfapi/page/cpdf_page.cpp -+++ b/core/fpdfapi/page/cpdf_page.cpp -@@ -35,12 +35,14 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument, - CFX_FloatRect mediabox = GetBox("MediaBox"); - if (mediabox.IsEmpty()) - mediabox = CFX_FloatRect(0, 0, 612, 792); -+ fprintf(stderr, "Page mediabox: %f, %f, %f, %f\n", mediabox.left, mediabox.right, mediabox.top, mediabox.bottom); - - m_BBox = GetBox("CropBox"); - if (m_BBox.IsEmpty()) - m_BBox = mediabox; - else - m_BBox.Intersect(mediabox); -+ fprintf(stderr, "Page cropbox: %f, %f, %f, %f\n", m_BBox.left, m_BBox.right, m_BBox.top, m_BBox.bottom); - - m_PageSize.width = m_BBox.Width(); - m_PageSize.height = m_BBox.Height(); -@@ -48,6 +50,7 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument, - int rotate = GetPageRotation(); - if (rotate % 2) - std::swap(m_PageSize.width, m_PageSize.height); -+ fprintf(stderr, "Page rotate: %d, Page Width: %f, Page Height: %f\n", rotate, m_PageSize.width, m_PageSize.height); - - switch (rotate) { - case 0: -diff --git a/core/fpdfapi/page/cpdf_pageobject.cpp b/core/fpdfapi/page/cpdf_pageobject.cpp -index 8bb5bf5..9b5e2ce 100644 ---- a/core/fpdfapi/page/cpdf_pageobject.cpp -+++ b/core/fpdfapi/page/cpdf_pageobject.cpp -@@ -98,5 +98,7 @@ FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const { - if (pMatrix) - rect = pMatrix->TransformRect(rect); - -+ FX_RECT rc = rect.GetOuterRect(); -+ fprintf(stderr, "PageObject BB: %f, %f, %f, %f\n", rc.left, rc.right, rc.top, rc.bottom); - return rect.GetOuterRect(); - } diff --git a/core/fpdfapi/page/cpdf_pageobjectlist.cpp b/core/fpdfapi/page/cpdf_pageobjectlist.cpp index afd2c98..2c8e061 100644 --- a/core/fpdfapi/page/cpdf_pageobjectlist.cpp @@ -135,18 +49,6 @@ index b450537..77c7d81 100644 }; #endif // CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTLIST_H_ -diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp -index 0a01ae0..6947e3a 100644 ---- a/core/fpdfapi/render/cpdf_renderstatus.cpp -+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp -@@ -1793,6 +1793,7 @@ bool CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj, - return true; - - float font_size = textobj->m_TextState.GetFontSize(); -+// fprintf(stderr, "Font size: %f, matrix a: %f, b: %f, c: %f, d: %f, e: %f, f: %f\n", font_size, text_matrix.a, text_matrix.b, text_matrix.c, text_matrix.d, text_matrix.e, text_matrix.f); - if (bPattern) { - DrawTextPathWithPattern(textobj, pObj2Device, pFont, font_size, - &text_matrix, bFill, bStroke); diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index e712549..a7973f7 100644 --- a/core/fpdftext/cpdf_textpage.cpp @@ -197,26 +99,6 @@ index c87ab00..e5a1ba8 100644 int CountRects(int start, int nCount); bool GetRect(int rectIndex, CFX_FloatRect* pRect) const; -diff --git a/core/fxge/cfx_pathdata.cpp b/core/fxge/cfx_pathdata.cpp -index 4ac5cf6..4286de4 100644 ---- a/core/fxge/cfx_pathdata.cpp -+++ b/core/fxge/cfx_pathdata.cpp -@@ -199,6 +199,7 @@ void CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_Matrix* pMatrix) { - void CFX_PathData::AppendPoint(const CFX_PointF& point, - FXPT_TYPE type, - bool closeFigure) { -+// fprintf(stderr, "Append: %f, %f (%s)\n", point.x, point.y, closeFigure ? "CLOSE" : "OPEN"); - m_Points.push_back(FX_PATHPOINT(point, type, closeFigure)); - } - -@@ -290,6 +291,7 @@ CFX_FloatRect CFX_PathData::GetBoundingBox(float line_width, - void CFX_PathData::Transform(const CFX_Matrix* pMatrix) { - if (!pMatrix) - return; -+// fprintf(stderr, "XForm: %f, %f %f, %f, %f, %f\n", pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, pMatrix->e, pMatrix->f); - for (auto& point : m_Points) - point.m_Point = pMatrix->Transform(point.m_Point); - } diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp index 0d7ba56..37bdf99 100644 --- a/fpdfsdk/fpdfeditimg.cpp @@ -249,7 +131,7 @@ index 0d7ba56..37bdf99 100644 FPDFImageObj_GetImageDataDecoded(FPDF_PAGEOBJECT image_object, void* buffer, diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp -index ca2cf3f..2162625 100644 +index ca2cf3f..1eaa232 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -11,12 +11,14 @@ @@ -275,7 +157,7 @@ index ca2cf3f..2162625 100644 #include "fpdfsdk/fsdk_define.h" #include "public/fpdf_formfill.h" #include "third_party/base/logging.h" -@@ -363,3 +366,252 @@ FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject, +@@ -363,3 +366,240 @@ FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject, *top = bbox.top; return true; } @@ -363,17 +245,6 @@ index ca2cf3f..2162625 100644 + str += pFont->UnicodeFromCharCode(charcode); + } + -+// CFX_WideTextBuf m_TextBuf; -+// WideString str = textpage->GetPageText(char_start, char_count); -+// return WideString(m_TextBuf.AsStringView().Mid( -+// static_cast<size_t>(text_start), static_cast<size_t>(text_count))); -+ -+// if (str.GetLength() > static_cast<size_t>(char_count)) -+// str = str.Left(static_cast<size_t>(char_count)); -+ -+ // Reincode in UTF-16. -+// WideString str = text.UTF8Decode(); -+ + // UFT16LE_Encode doesn't handle surrogate pairs properly, so it is expected + // the number of items to stay the same. + ByteString byte_str = str.UTF16LE_Encode(); @@ -495,7 +366,6 @@ index ca2cf3f..2162625 100644 + if (pFrmObj) + { + const CFX_Matrix& matrix = pFrmObj->form_matrix(); -+ fprintf(stderr, "Form matrix a: %f, b: %f, c: %f, d: %f, e: %f, f: %f\n", matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f); + const CPDF_PageObjectList* pObjectList = pFrmObj->form()->GetPageObjectList(); + if (pObjectList) + return pObjectList->GetPageObjectByIndex(index); diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index 4059a8d8a83d..b0a06abda9e2 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -195,7 +195,6 @@ ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const Rectan } mnPageCount = FPDF_GetPageCount(mpPdfDocument); - SAL_WARN("sd.filter", "Scale Rect: " << maScaleRect); } ImpSdrPdfImport::~ImpSdrPdfImport() @@ -204,11 +203,10 @@ ImpSdrPdfImport::~ImpSdrPdfImport() FPDF_DestroyLibrary(); } -void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport, +void ImpSdrPdfImport::DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport, int nPageIndex) { const int nPageCount = FPDF_GetPageCount(mpPdfDocument); - SAL_WARN("sd.filter", "Importing page " << nPageIndex << " of " << nPageCount); if (nPageCount > 0 && nPageIndex >= 0 && nPageIndex < nPageCount) { // Render next page. @@ -218,187 +216,24 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc const double dPageWidth = FPDF_GetPageWidth(pPdfPage); const double dPageHeight = FPDF_GetPageHeight(pPdfPage); - SAL_WARN("sd.filter", "Loaded page: " << nPageIndex << ", width: " << dPageWidth - << ", height: " << dPageHeight); SetupPageScale(dPageWidth, dPageHeight); // Load the page text to extract it when we get text elements. FPDF_TEXTPAGE pTextPage = FPDFText_LoadPage(pPdfPage); const int nPageObjectCount = FPDFPage_CountObject(pPdfPage); + if (pProgrInfo) + pProgrInfo->SetActionCount(nPageObjectCount); + for (int nPageObjectIndex = 0; nPageObjectIndex < nPageObjectCount; ++nPageObjectIndex) { FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(pPdfPage, nPageObjectIndex); ImportPdfObject(pPageObject, pTextPage, nPageObjectIndex); - } - - FPDFText_ClosePage(pTextPage); - -#if 0 - // Now do the text. - FPDF_TEXTPAGE pTextPage = FPDFText_LoadPage(pPdfPage); - if (pTextPage != nullptr) - { - SAL_WARN("sd.filter", "TEXT TEXT TEXT"); - - const int nChars = FPDFText_CountChars(pTextPage); - SAL_WARN("sd.filter", "Got page chars: " << nChars); - - const int nRects = FPDFText_CountRects(pTextPage, 0, nChars); - SAL_WARN("sd.filter", "Got Rects: " << nRects); - - std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nChars + 1]); // + terminating null - for (int nRectIndex = 0; nRectIndex < nRects; ++nRectIndex) - { - SAL_WARN("sd.filter", - "Processing Text Rect #" << nRectIndex + 1 << " of " << nRects); - - double left = 0; - double top = 0; - double right = 0; - double bottom = 0; - FPDFText_GetRect(pTextPage, nRectIndex, &left, &top, &right, &bottom); - SAL_WARN("sd.filter", "Got Text Rect: " << left << ", " << right << ", " << top - << ", " << bottom); - Rectangle aRect = PointsToLogic(left, right, top, bottom); - - if (right < left) - std::swap(right, left); - if (bottom < top) - std::swap(bottom, top); - - SAL_WARN("sd.filter", "Got Text Rect: " << left << ", " << right << ", " << top - << ", " << bottom); - SAL_WARN("sd.filter", "Logic Text Rect: " << aRect); - - unsigned short* pShortText = reinterpret_cast<unsigned short*>(pText.get()); - const int nBoundedChars = FPDFText_GetBoundedText(pTextPage, left, top, right, - bottom, pShortText, nChars); - OUString sText(pText.get(), nBoundedChars); - SAL_WARN("sd.filter", "Got Text #" << nRectIndex + 1 << " (" << nBoundedChars - << "): [" << sText << "]."); - - const double dHalfCharWidth = (right - left) / nBoundedChars / 2.0; - SAL_WARN("sd.filter", "Half Char Width: " << dHalfCharWidth); - const int nCharIndex = FPDFText_GetCharIndexAtPos(pTextPage, left + dHalfCharWidth, - top + dHalfCharWidth, - dHalfCharWidth, dHalfCharWidth); - SAL_WARN("sd.filter", "Got Char Index: " << nCharIndex); - - // FPDF_FONT pFont = FPDFText_GetFont(pTextPage, nCharIndex); - // const int nFontAscent = FPDFFont_GetAscent(pFont); - // const int nFontDescent = FPDFFont_GetDescent(pFont); - // FPDF_BYTESTRING sFontName = FPDFFont_GetName(pFont); - // SAL_WARN("sd.filter", "Char #" << nCharIndex << ", Got Font [" << sFontName << - // "], Ascent: "<< nFontAscent << ", Descent: " << nFontDescent); - - // FontMetric aFontMetric = mpVD->GetFontMetric(); - // aFontMetric.SetAscent(nFontAscent); - // aFontMetric.SetDescent(nFontDescent); - - double dFontScale = 1.0; - geometry::Matrix2D aMatrix; - if (!FPDFText_GetMatrix(pTextPage, nCharIndex, &aMatrix.m00, &aMatrix.m01, - &aMatrix.m10, &aMatrix.m11)) - { - SAL_WARN("sd.filter", "No font scale matrix, will use heuristic height of " - << aRect.GetHeight() << "."); - dFontScale = aRect.GetHeight(); - } - else 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 = FPDFText_GetFontSize(pTextPage, nCharIndex); - 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); - - double x = 0; - double y = 0; - FPDFText_GetCharOrigin(pTextPage, nCharIndex, &x, &y); - SAL_WARN("sd.filter", "Got Char Origin: " << x << ", " << y); - Point aPos = PointsToLogic(x, y); - SAL_WARN("sd.filter", "Got Char Origin Logic: " << aPos); - // aRect.Move(aPos.X(), aPos.Y()); - - // geometry::RealRectangle2D aRect; - // aRect.X1 = left; - // aRect.Y1 = top; - // aRect.X2 = right; - // aRect.Y2 = bottom; - - // geometry::Matrix2D aMatrix; - // FPDFText_GetMatrix(pTextPage, nCharIndex, &aMatrix.m00, &aMatrix.m01, &aMatrix.m10, &aMatrix.m11); - - // basegfx::B2DHomMatrix fontMatrix( - // aMatrix.m00, aMatrix.m01, 0.0, - // aMatrix.m10, aMatrix.m11, 0.0); - // fontMatrix.scale(dFontSize, dFontSize); - - // x = fontMatrix.get(0, 0) * x + fontMatrix.get(1, 0) * y + x; - // y = fontMatrix.get(0, 1) * x + fontMatrix.get(1, 1) * y + y; - // SAL_WARN("sd.filter", "Char Origin after xform: " << x << ", " << y); - - // basegfx::B2DHomMatrix totalTextMatrix1(fontMatrix); - // basegfx::B2DHomMatrix totalTextMatrix2(fontMatrix); - // totalTextMatrix1.translate(rRect.X1, rRect.Y1); - // totalTextMatrix2.translate(rRect.X2, rRect.Y2); - - // basegfx::B2DHomMatrix corrMatrix; - // corrMatrix.scale(1.0, -1.0); - // // corrMatrix.translate(0.0, ascent); - // totalTextMatrix1 = totalTextMatrix1 * corrMatrix; - // totalTextMatrix2 = totalTextMatrix2 * corrMatrix; - - // totalTextMatrix1 *= getCurrentContext().Transformation; - // totalTextMatrix2 *= getCurrentContext().Transformation; - - // basegfx::B2DHomMatrix invMatrix(totalTextMatrix1); - // basegfx::B2DHomMatrix invPrevMatrix(prevTextMatrix); - // invMatrix.invert(); - // invPrevMatrix.invert(); - // basegfx::B2DHomMatrix offsetMatrix1(totalTextMatrix1); - // basegfx::B2DHomMatrix offsetMatrix2(totalTextMatrix2); - // offsetMatrix1 *= invPrevMatrix; - // offsetMatrix2 *= invMatrix; - - // double charWidth = offsetMatrix2.get(0, 2); - // double prevSpaceWidth = offsetMatrix1.get(0, 2) - prevCharWidth; - - ImportText(aRect.TopLeft(), sText); - } - - FPDFText_ClosePage(pTextPage); - } -#endif - - FPDF_ClosePage(pPdfPage); - } - - // const sal_uLong nCount(rMtf.GetActionSize()); - - for (sal_uLong a(0); a < 0UL; a++) - { if (pProgrInfo && pActionsToReport) { (*pActionsToReport)++; - if (*pActionsToReport >= 16) // update all 16 actions + if (*pActionsToReport >= 16) { if (!pProgrInfo->ReportActions(*pActionsToReport)) break; @@ -407,6 +242,10 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc } } } + + FPDFText_ClosePage(pTextPage); + FPDF_ClosePage(pPdfPage); + } } void ImpSdrPdfImport::SetupPageScale(const double dPageWidth, const double dPageHeight) @@ -419,8 +258,6 @@ void ImpSdrPdfImport::SetupPageScale(const double dPageWidth, const double dPage Size aPageSize(lcl_ToLogic(lcl_PointToPixel(dPageWidth)), lcl_ToLogic(lcl_PointToPixel(dPageHeight))); - SAL_WARN("sd.filter", "Logical Page Size: " << aPageSize); - SAL_WARN("sd.filter", "Scale Rect: " << maScaleRect); if (aPageSize.Width() && aPageSize.Height() && (!maScaleRect.IsEmpty())) { @@ -455,23 +292,15 @@ void ImpSdrPdfImport::SetupPageScale(const double dPageWidth, const double dPage maScaleY = Fraction(maScaleRect.GetHeight() - 1, aPageSize.Height()); mbSize = true; } - - //SAL_WARN("sd.filter", "ScaleX: " << maScaleX << "(" << mfScaleX << "), ScaleY: " << maScaleY - // << "(" << mfScaleY << ")"); } size_t ImpSdrPdfImport::DoImport(SdrObjList& rOL, size_t nInsPos, int nPageNumber, SvdProgressInfo* pProgrInfo) { - if (pProgrInfo) - { - // pProgrInfo->SetActionCount(rMtf.GetActionSize()); - } - sal_uInt32 nActionsToReport(0); // execute - DoLoopActions(pProgrInfo, &nActionsToReport, nPageNumber); + DoObjects(pProgrInfo, &nActionsToReport, nPageNumber); if (pProgrInfo) { @@ -612,7 +441,6 @@ void ImpSdrPdfImport::SetAttributes(SdrObject* pObj, bool bForceTextAttr) { vcl::Font aFnt(mpVD->GetFont()); const sal_uInt32 nHeight(FRound(aFnt.GetFontSize().Height() * mfScaleY)); - SAL_WARN("sd.filter", "Font Height: " << nHeight); mpTextAttr->Put(SvxFontItem(aFnt.GetFamilyType(), aFnt.GetFamilyName(), aFnt.GetStyleName(), aFnt.GetPitch(), aFnt.GetCharSet(), EE_CHAR_FONTINFO)); @@ -1024,10 +852,8 @@ void ImpSdrPdfImport::ImportPdfObject(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE } void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage, - int nPageObjectIndex) + int /*nPageObjectIndex*/) { - SAL_WARN("sd.filter", "Got page object FORM: " << nPageObjectIndex); - // Get the form matrix to perform correct translation/scaling of the form sub-objects. const Matrix aOldMatrix = mCurMatrix; @@ -1047,9 +873,8 @@ void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex } void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage, - int nPageObjectIndex) + int /*nPageObjectIndex*/) { - SAL_WARN("sd.filter", "Got page object TEXT: " << nPageObjectIndex); float left; float bottom; float right; @@ -1060,30 +885,14 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex } if (left == right || top == bottom) - { - SAL_WARN("sd.filter", "Skipping empty TEXT #" << nPageObjectIndex << " left: " << left - << ", right: " << right << ", top: " << top - << ", bottom: " << bottom); return; - } double a, b, c, d, e, f; FPDFTextObj_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f); - // Matrix aTextMatrix(a, b, c, d, e, f); Matrix aTextMatrix(mCurMatrix); - SAL_WARN("sd.filter", "Got text matrix " << aTextMatrix.toString()); - SAL_WARN("sd.filter", "Context matrix " << mCurMatrix.toString()); - // aTextMatrix.Concatinate(mCurMatrix); - // SAL_WARN("sd.filter", "Got text matrix concat " << aTextMatrix.toString()); - Point aPos = PointsToLogic(aTextMatrix.e(), aTextMatrix.f()); - SAL_WARN("sd.filter", "Got TEXT origin: " << aPos); - - const Rectangle aRect2 = PointsToLogic(left, right, top, bottom); - SAL_WARN("sd.filter", "Untransformed TEXT Bounds: " << aRect2); aTextMatrix.Transform(left, right, top, bottom); const Rectangle aRect = PointsToLogic(left, right, top, bottom); - SAL_WARN("sd.filter", "Transformed TEXT Bounds: " << aRect); const int nChars = FPDFTextObj_CountChars(pPageObject) * 2; std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nChars + 1]); // + terminating null @@ -1093,24 +902,18 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex = FPDFTextObj_GetTextProcessed(pPageObject, pTextPage, 0, nChars, pShortText); if (nActualChars <= 0) { - SAL_WARN("sd.filter", "Got no TEXT"); return; } OUString sText(pText.get(), nActualChars); - SAL_WARN("sd.filter", "Got Text (" << nChars << "): [" << sText << "]."); const double dFontSize = FPDFTextObj_GetFontSize(pPageObject); double dFontSizeH = fabs(sqrt2(a, c) * dFontSize); double dFontSizeV = fabs(sqrt2(b, d) * dFontSize); - SAL_WARN("sd.filter", "Got Font Size: " << dFontSize << ", Scaled Font Size H: " << dFontSizeH - << ", V: " << dFontSizeV); dFontSizeH = lcl_PointToPixel(dFontSizeH); dFontSizeV = lcl_PointToPixel(dFontSizeV); - SAL_WARN("sd.filter", "Got Pixel Font Size H: " << dFontSizeH << ", V: " << dFontSizeV); dFontSizeH = lcl_ToLogic(dFontSizeH); dFontSizeV = lcl_ToLogic(dFontSizeV); - SAL_WARN("sd.filter", "Got Logic Font Size H: " << dFontSizeH << ", V: " << dFontSizeV); const Size aFontSize(dFontSizeH, dFontSizeV); vcl::Font aFnt = mpVD->GetFont(); @@ -1143,26 +946,18 @@ void ImpSdrPdfImport::ImportText(const Point& rPos, const Size& rSize, const OUS vcl::Font aFnt(mpVD->GetFont()); FontAlign eAlg(aFnt.GetAlignment()); - sal_Int32 nTextWidth = static_cast<sal_Int32>(mpVD->GetTextWidth(rStr) * mfScaleX); + // sal_Int32 nTextWidth = static_cast<sal_Int32>(mpVD->GetTextWidth(rStr) * mfScaleX); sal_Int32 nTextHeight = static_cast<sal_Int32>(mpVD->GetTextHeight() * mfScaleY); - SAL_WARN("sd.filter", - "Unscaled text size: " << mpVD->GetTextWidth(rStr) << 'x' << mpVD->GetTextHeight() - << ", 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); + Size aSize(FRound(rSize.Width() * mfScaleX), FRound(rSize.Height() * mfScaleY)); if (eAlg == ALIGN_BASELINE) aPos.Y() -= FRound(aFontMetric.GetAscent() * mfScaleY); else if (eAlg == ALIGN_BOTTOM) aPos.Y() -= nTextHeight; - SAL_WARN("sd.filter", "Final POS: " << aPos); - SAL_WARN("sd.filter", "Final Text Size: " << aSize); - SAL_WARN("sd.filter", "Final Bound Size: " << bSize); - Rectangle aTextRect(aPos, bSize); - // SAL_WARN("sd.filter", "Text Rect: " << aTextRect); + Rectangle aTextRect(aPos, aSize); SdrRectObj* pText = new SdrRectObj(OBJ_TEXT, aTextRect); pText->SetModel(mpModel); @@ -1227,9 +1022,8 @@ void ImpSdrPdfImport::MapScaling() mnMapScalingOfs = nCount; } -void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex) +void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/) { - SAL_WARN("sd.filter", "Got page object IMAGE: " << nPageObjectIndex); std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmapBgra(pPageObject)); if (!bitmap) { @@ -1253,27 +1047,13 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn switch (format) { - case FPDFBitmap_Gray: - SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight - << ", stride: " << nStride - << ", format: Gray"); - break; case FPDFBitmap_BGR: - SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight - << ", stride: " << nStride - << ", format: BGR"); ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N24BitTcBgr, nHeight, nStride); break; case FPDFBitmap_BGRx: - SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight - << ", stride: " << nStride - << ", format: BGRx"); ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcRgba, nHeight, nStride); break; case FPDFBitmap_BGRA: - SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight - << ", stride: " << nStride - << ", format: BGRA"); ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcBgra, nHeight, nStride); break; default: @@ -1283,18 +1063,6 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn break; } - // double a, b, c, d, e, f; - // if (!FPDFImageObj_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f)) - // { - // SAL_WARN("sd.filter", "FAILED to get image Matrix"); - // } - // SAL_WARN("sd.filter", "Got image Matrix: " << a << ", " << b << ", " << c << ", " << d << ", " << e << ", " << f); - - // if (!FPDFImageObj_SetMatrix(pPageObject, a, b, c, d, e, f)) - // { - // SAL_WARN("sd.filter", "FAILED to set image Matrix"); - // } - float left; float bottom; float right; @@ -1304,12 +1072,9 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn SAL_WARN("sd.filter", "FAILED to get image bounds"); } - SAL_WARN("sd.filter", "Got IMAGE bounds left: " << left << ", right: " << right - << ", top: " << top << ", bottom: " << bottom); Rectangle aRect = PointsToLogic(left, right, top, bottom); aRect.MoveRight(1); aRect.MoveBottom(1); - SAL_WARN("sd.filter", "IMAGE Logical Rect FINAL: " << aRect); SdrGrafObj* pGraf = new SdrGrafObj(Graphic(aBitmap), aRect); pGraf->SetModel(mpModel); @@ -1320,7 +1085,7 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn InsertObj(pGraf); } -void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex) +void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/) { double a, b, c, d, e, f; FPDFPath_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f); @@ -1332,9 +1097,6 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd std::vector<basegfx::B2DPoint> aBezier; const int nSegments = FPDFPath_CountSegments(pPageObject); - SAL_WARN("sd.filter", - "Got page object PATH: " << nPageObjectIndex << " with " << nSegments << " segments."); - for (int nSegmentIndex = 0; nSegmentIndex < nSegments; ++nSegmentIndex) { FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(pPageObject, nSegmentIndex); @@ -1354,11 +1116,6 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd if (bClose) aPoly.setClosed(bClose); // TODO: Review - SAL_WARN("sd.filter", "Got " << (bClose ? "CLOSE" : "OPEN") << " point (" << fx << ", " - << fy << ") matrix (" << a << ", " << b << ", " << c - << ", " << d << ", " << e << ", " << f << ") -> (" << x - << ", " << y << ")"); - Point aPoint = PointsToLogic(x, y); x = aPoint.X(); y = aPoint.Y(); @@ -1367,12 +1124,10 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd switch (nSegmentType) { case FPDF_SEGMENT_LINETO: - SAL_WARN("sd.filter", "Got LineTo Segment."); aPoly.append(basegfx::B2DPoint(x, y)); break; case FPDF_SEGMENT_BEZIERTO: - SAL_WARN("sd.filter", "Got BezierTo Segment."); aBezier.emplace_back(x, y); if (aBezier.size() == 3) { @@ -1382,7 +1137,6 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd break; case FPDF_SEGMENT_MOVETO: - SAL_WARN("sd.filter", "Got MoveTo Segment."); // New Poly. if (aPoly.count() > 0) { @@ -1421,15 +1175,11 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd FPDFPath_GetStrokeWidth(pPageObject, &fWidth); const double dWidth = 0.5 * fabs(sqrt2(aPathMatrix.a(), aPathMatrix.c()) * fWidth); mnLineWidth = lcl_ToLogic(lcl_PointToPixel(dWidth)); - // mnLineWidth /= 2; - SAL_WARN("sd.filter", "Path Stroke Width: " << fWidth << ", scaled: " << dWidth - << ", Logical: " << mnLineWidth); int nFillMode = FPDF_FILLMODE_ALTERNATE; FPDF_BOOL bStroke = true; if (FPDFPath_GetDrawMode(pPageObject, &nFillMode, &bStroke)) { - SAL_WARN("sd.filter", "Got PATH FillMode: " << nFillMode << ", Storke: " << bStroke); if (nFillMode == FPDF_FILLMODE_ALTERNATE) mpVD->SetDrawMode(DrawModeFlags::Default); else if (nFillMode == FPDF_FILLMODE_WINDING) @@ -1443,39 +1193,32 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd unsigned int nB; unsigned int nA; FPDFPath_GetFillColor(pPageObject, &nR, &nG, &nB, &nA); - SAL_WARN("sd.filter", "Got PATH fill color: " << nR << ", " << nG << ", " << nB << ", " << nA); mpVD->SetFillColor(Color(nR, nG, nB)); if (bStroke) { FPDFPath_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA); - SAL_WARN("sd.filter", - "Got PATH stroke color: " << nR << ", " << nG << ", " << nB << ", " << nA); mpVD->SetLineColor(Color(nR, nG, nB)); } else mpVD->SetLineColor(COL_TRANSPARENT); - // if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource))) - + if (!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aPolyPoly))) + { SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aPolyPoly); pPath->SetModel(mpModel); SetAttributes(pPath); InsertObj(pPath, false); } +} Point ImpSdrPdfImport::PointsToLogic(double x, double y) const { y = correctVertOrigin(y); - // SAL_WARN("sd.filter", "Corrected point x: " << x << ", y: " << y); x = lcl_PointToPixel(x); y = lcl_PointToPixel(y); - // SAL_WARN("sd.filter", "Pixel point x: " << x << ", y: " << y); - Point aPos(lcl_ToLogic(x), lcl_ToLogic(y)); - // SAL_WARN("sd.filter", "Logical Pos: " << aPos); - return aPos; } @@ -1484,21 +1227,15 @@ Rectangle ImpSdrPdfImport::PointsToLogic(double left, double right, double top, { top = correctVertOrigin(top); bottom = correctVertOrigin(bottom); - // SAL_WARN("sd.filter", "Corrected bounds left: " << left << ", right: " << right - // << ", top: " << top << ", bottom: " << bottom); + left = lcl_PointToPixel(left); right = lcl_PointToPixel(right); top = lcl_PointToPixel(top); bottom = lcl_PointToPixel(bottom); - // SAL_WARN("sd.filter", "Pixel bounds left: " << left << ", right: " << right << ", top: " << top - // << ", bottom: " << bottom); - Point aPos(lcl_ToLogic(left), lcl_ToLogic(top)); Size aSize(lcl_ToLogic(right - left), lcl_ToLogic(bottom - top)); Rectangle aRect(aPos, aSize); - // SAL_WARN("sd.filter", "Logical BBox: " << aRect); - return aRect; } diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx index 09d0d680cd7d..e461c1f5e014 100644 --- a/svx/source/svdraw/svdpdf.hxx +++ b/svx/source/svdraw/svdpdf.hxx @@ -109,44 +109,34 @@ class ImpSdrPdfImport final /// Transform the rectangle (left, right, top, bottom) by this Matrix. template <typename T> void Transform(T& left, T& right, T& top, T& bottom) { - SAL_WARN("sd.filter", - "Transforming: " << left << ", " << right << ", " << top << ", " << bottom); T leftTopX = left; T leftTopY = top; Transform(leftTopX, leftTopY); - SAL_WARN("sd.filter", "Left-Top: " << leftTopX << ", " << leftTopY); T leftBottomX = left; T leftBottomY = bottom; Transform(leftBottomX, leftBottomY); - SAL_WARN("sd.filter", "Left-Bottom: " << leftBottomX << ", " << leftBottomY); T rightTopX = right; T rightTopY = top; Transform(rightTopX, rightTopY); - SAL_WARN("sd.filter", "Right-Top: " << rightTopX << ", " << rightTopY); T rightBottomX = right; T rightBottomY = bottom; Transform(rightBottomX, rightBottomY); - SAL_WARN("sd.filter", "Right-Bottom: " << rightBottomX << ", " << rightBottomY); left = std::min(leftTopX, leftBottomX); - SAL_WARN("sd.filter", "left: " << left); right = std::max(rightTopX, rightBottomX); - SAL_WARN("sd.filter", "right: " << right); if (top > bottom) top = std::max(leftTopY, rightTopY); else top = std::min(leftTopY, rightTopY); - SAL_WARN("sd.filter", "top: " << top); if (top > bottom) bottom = std::max(leftBottomY, rightBottomY); else bottom = std::max(leftBottomY, rightBottomY); - SAL_WARN("sd.filter", "bottom: " << bottom); } std::string toString() const @@ -233,7 +223,7 @@ class ImpSdrPdfImport final bool CheckLastLineMerge(const basegfx::B2DPolygon& rSrcPoly); bool CheckLastPolyLineAndFillMerge(const basegfx::B2DPolyPolygon& rPolyPolygon); - void DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport, int nPageIndex); + void DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport, int nPageIndex); // Copy assignment is forbidden and not implemented. ImpSdrPdfImport(const ImpSdrPdfImport&) = delete; |