[Libreoffice-commits] core.git: Branch 'private/Ashod/pdfium' - 5 commits - external/pdfium svx/source
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Tue Apr 10 22:08:03 UTC 2018
external/pdfium/edit.patch.1 | 173 ++++++++++++++++++++++++++++++-
svx/source/svdraw/svdpdf.cxx | 235 +++++++++++++++++++++++++++++--------------
svx/source/svdraw/svdpdf.hxx | 5
3 files changed, 330 insertions(+), 83 deletions(-)
New commits:
commit 4dd309183cb94853be8fa4f7ff8180718260f50f
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Tue Apr 10 18:06:47 2018 -0400
svx: support Paths in PDFs while importing
Change-Id: Idba294cf5a3a8dd00988f94786715b110039e000
diff --git a/external/pdfium/edit.patch.1 b/external/pdfium/edit.patch.1
index 9099a4024b3e..03b4ab221730 100644
--- a/external/pdfium/edit.patch.1
+++ b/external/pdfium/edit.patch.1
@@ -208,6 +208,27 @@ index ca2cf3f..8073a18 100644
+ (pTxtObj->m_GeneralState.GetStrokeAlpha() * 255.f) + 0.5f);
+ return true;
+}
+diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
+index a291987..d3b0bc1 100644
+--- a/fpdfsdk/fpdfeditpath.cpp
++++ b/fpdfsdk/fpdfeditpath.cpp
+@@ -101,6 +101,16 @@ FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width) {
+ return true;
+ }
+
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
++FPDFPath_GetStrokeWidth(FPDF_PAGEOBJECT path, float* width) {
++ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
++ if (!pPathObj || !width)
++ return false;
++
++ *width = pPathObj->m_GraphState.GetLineWidth();
++ return true;
++}
++
+ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetFillColor(FPDF_PAGEOBJECT path,
+ unsigned int R,
+ unsigned int G,
diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index 68bf4f8..e073b20 100644
--- a/fpdfsdk/fpdftext.cpp
@@ -279,10 +300,26 @@ index 77c2315..db3e734 100644
CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
-index 54735a3..15292f5 100644
+index 54735a3..282bcdb 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
-@@ -761,6 +761,73 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
+@@ -520,6 +520,15 @@ FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path,
+ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+ FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width);
+
++// Get the stroke width of a path.
++//
++// path - the handle to the path object.
++// width - the width of the stroke.
++//
++// Returns TRUE on success
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
++FPDFPath_GetStrokeWidth(FPDF_PAGEOBJECT path, float* width);
++
+ // Set the line join of |page_object|.
+ //
+ // page_object - handle to a page object.
+@@ -761,6 +770,73 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
FPDF_FONT font,
float font_size);
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index bccb124eb476..3f585b58fb6b 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -236,7 +236,7 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
ImportText(pPageObject, nPageObjectIndex);
break;
case FPDF_PAGEOBJ_PATH:
- SAL_WARN("sd.filter", "Got page object PATH: " << nPageObjectIndex);
+ ImportPath(pPageObject, nPageObjectIndex);
break;
case FPDF_PAGEOBJ_IMAGE:
ImportImage(pPageObject, nPageObjectIndex);
@@ -1280,6 +1280,95 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn
InsertObj(pGraf);
}
+void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex)
+{
+ SAL_WARN("sd.filter", "Got page object PATH: " << nPageObjectIndex);
+ basegfx::B2DPolygon aPoly;
+ std::vector<basegfx::B2DPoint> aBezier;
+
+ const int nSegments = FPDFPath_CountSegments(pPageObject);
+ for (int nSegmentIndex = 0; nSegmentIndex < nSegments; ++nSegmentIndex)
+ {
+ FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(pPageObject, nSegmentIndex);
+ if (pPathSegment != nullptr)
+ {
+ float x, y;
+ if (!FPDFPathSegment_GetPoint(pPathSegment, &x, &y))
+ {
+ SAL_WARN("sd.filter", "Failed to get PDF path segement point");
+ continue;
+ }
+
+ const bool bClose = FPDFPathSegment_GetClose(pPathSegment);
+ SAL_WARN("sd.filter",
+ "Got (" << x << ", " << y << "): " << (bClose ? "CLOSE" : "OPEN"));
+ Point aPoint = PointsToLogic(x, y);
+ x = aPoint.X();
+ y = aPoint.Y();
+
+ const int nSegmentType = FPDFPathSegment_GetType(pPathSegment);
+ 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)
+ {
+ aPoly.appendBezierSegment(aBezier[0], aBezier[1], aBezier[2]);
+ aBezier.clear();
+ }
+ break;
+
+ case FPDF_SEGMENT_MOVETO:
+ SAL_WARN("sd.filter", "Got MoveTo Segment.");
+ aPoly.append(basegfx::B2DPoint(x, y));
+ break;
+
+ case FPDF_SEGMENT_UNKNOWN:
+ default:
+ SAL_WARN("sd.filter", "Unknown path segment type in PDF: " << nSegmentType);
+ break;
+ }
+ }
+ }
+
+ if (aBezier.size() == 3)
+ {
+ aPoly.appendBezierSegment(aBezier[0], aBezier[1], aBezier[2]);
+ aBezier.clear();
+ }
+
+ const basegfx::B2DHomMatrix aTransform(
+ basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
+ aPoly.transform(aTransform);
+
+ float fWidth = 1;
+ FPDFPath_GetStrokeWidth(pPageObject, &fWidth);
+ mnLineWidth = lcl_ToLogic(lcl_PointToPixel(fWidth));
+
+ unsigned int r;
+ unsigned int g;
+ unsigned int b;
+ unsigned int a;
+ FPDFPath_GetFillColor(pPageObject, &r, &g, &b, &a);
+ mpVD->SetFillColor(Color(r, g, b));
+
+ FPDFPath_GetStrokeColor(pPageObject, &r, &g, &b, &a);
+ mpVD->SetLineColor(Color(r, g, b));
+
+ // if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource)))
+
+ aPoly.setClosed(true); // TODO: Review
+ SdrPathObj* pPath = new SdrPathObj(*mpModel, OBJ_POLY, basegfx::B2DPolyPolygon(aPoly));
+ SetAttributes(pPath);
+ InsertObj(pPath, false);
+}
+
Point ImpSdrPdfImport::PointsToLogic(double x, double y) const
{
y = correctVertOrigin(y);
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index dd4306c738bd..17b926b43619 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -103,6 +103,8 @@ class ImpSdrPdfImport final
void ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
void SetupPageScale(const double dPageWidth, const double dPageHeight);
+ void ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
+
void ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
void ImportText(const Point& rPos, const OUString& rStr);
void SetAttributes(SdrObject* pObj, bool bForceTextAttr = false);
commit a5965f06eba940e2057de8c8e55e7a3c396f73e3
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Tue Apr 10 07:45:06 2018 -0400
svx: support PDF text color
Change-Id: I7fa675c6560504e4fc7917e19cac3cceb2700d8e
diff --git a/external/pdfium/edit.patch.1 b/external/pdfium/edit.patch.1
index da72f96f46fc..9099a4024b3e 100644
--- a/external/pdfium/edit.patch.1
+++ b/external/pdfium/edit.patch.1
@@ -66,7 +66,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..ac36788 100644
+index ca2cf3f..8073a18 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -11,12 +11,14 @@
@@ -84,7 +84,7 @@ index ca2cf3f..ac36788 100644
#include "core/fpdfapi/page/cpdf_shadingobject.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
-@@ -363,3 +365,103 @@ FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject,
+@@ -363,3 +365,123 @@ FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject,
*top = bbox.top;
return true;
}
@@ -95,7 +95,7 @@ index ca2cf3f..ac36788 100644
+ if (!text_object)
+ return 0;
+
-+ CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
++ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
+ return pTxtObj->CountChars();
+}
+
@@ -105,7 +105,7 @@ index ca2cf3f..ac36788 100644
+ if (!text_object)
+ return 0;
+
-+ CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
++ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
+ return pTxtObj->GetFontSize();
+}
+
@@ -118,7 +118,7 @@ index ca2cf3f..ac36788 100644
+ if (!text_object)
+ return;
+
-+ CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
++ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
+ const CFX_Matrix& matrix = pTxtObj->GetTextMatrix();
+ *a = matrix.a;
+ *b = matrix.b;
@@ -132,7 +132,7 @@ index ca2cf3f..ac36788 100644
+ if (!text_object || index < 0)
+ return 0;
+
-+ CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
++ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
+ if (index > pTxtObj->CountChars())
+ return 0;
+
@@ -148,7 +148,7 @@ index ca2cf3f..ac36788 100644
+ if (!text_object || char_start < 0 || char_count < 0 || !result)
+ return 0;
+
-+ CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
++ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
+ int char_available = pTxtObj->CountChars() - char_start;
+ if (char_available <= 0)
+ return 0;
@@ -188,6 +188,26 @@ index ca2cf3f..ac36788 100644
+ memcpy(result, byte_str.GetBuffer(byte_str_len), byte_str_len);
+ return ret_count;
+}
++
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
++FPDFTextObj_GetStrokeColor(FPDF_PAGEOBJECT text_object,
++ unsigned int* R,
++ unsigned int* G,
++ unsigned int* B,
++ unsigned int* A)
++{
++ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
++ if (!pTxtObj || !R || !G || !B || !A)
++ return false;
++
++ const uint32_t strokeRGB = pTxtObj->m_ColorState.GetStrokeRGB();
++ *R = FXSYS_GetRValue(strokeRGB);
++ *G = FXSYS_GetGValue(strokeRGB);
++ *B = FXSYS_GetBValue(strokeRGB);
++ *A = static_cast<unsigned int>(
++ (pTxtObj->m_GeneralState.GetStrokeAlpha() * 255.f) + 0.5f);
++ return true;
++}
diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index 68bf4f8..e073b20 100644
--- a/fpdfsdk/fpdftext.cpp
@@ -221,11 +241,48 @@ index 68bf4f8..e073b20 100644
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetCharBox(FPDF_TEXTPAGE text_page,
int index,
double* left,
+diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
+index e890aa0..709bea3 100644
+--- a/fpdfsdk/fpdfview.cpp
++++ b/fpdfsdk/fpdfview.cpp
+@@ -336,6 +336,11 @@ CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
+ #endif // PDF_ENABLE_XFA
+ }
+
++CPDF_TextObject* CPDFTextObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {
++ auto* obj = CPDFPageObjectFromFPDFPageObject(page_object);
++ return obj ? obj->AsText() : nullptr;
++}
++
+ CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {
+ auto* obj = CPDFPageObjectFromFPDFPageObject(page_object);
+ return obj ? obj->AsPath() : nullptr;
+diff --git a/fpdfsdk/fsdk_define.h b/fpdfsdk/fsdk_define.h
+index 77c2315..db3e734 100644
+--- a/fpdfsdk/fsdk_define.h
++++ b/fpdfsdk/fsdk_define.h
+@@ -25,6 +25,7 @@ class CPDF_Annot;
+ class CPDF_Page;
+ class CPDF_PageObject;
+ class CPDF_PageRenderContext;
++class CPDF_TextObject;
+ class CPDF_PathObject;
+ class CPDF_Stream;
+ class IFSDK_PAUSE_Adapter;
+@@ -65,6 +66,8 @@ FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc);
+
+ CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page);
+
++CPDF_TextObject* CPDFTextObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object);
++
+ CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object);
+
+ CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
-index 54735a3..a9c1a25 100644
+index 54735a3..15292f5 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
-@@ -761,6 +761,57 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
+@@ -761,6 +761,73 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
FPDF_FONT font,
float font_size);
@@ -280,6 +337,22 @@ index 54735a3..a9c1a25 100644
+ int char_count,
+ unsigned short* result);
+
++// Get the stroke RGBA of a text. Range of values: 0 - 255.
++//
++// path - the handle to the path object.
++// R - the red component of the path stroke color.
++// G - the green component of the path stroke color.
++// B - the blue component of the path stroke color.
++// A - the stroke alpha of the path.
++//
++// Returns TRUE on success.
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
++FPDFTextObj_GetStrokeColor(FPDF_PAGEOBJECT text_object,
++ unsigned int* R,
++ unsigned int* G,
++ unsigned int* B,
++ unsigned int* A);
++
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 6dd75b0a293e..bccb124eb476 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -229,8 +229,6 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
if (pPageObject == nullptr)
continue;
- SAL_WARN("sd.filter", "Got page object number: ");
-
const int nPageObjectType = FPDFPageObj_GetType(pPageObject);
switch (nPageObjectType)
{
@@ -1051,6 +1049,11 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
SAL_WARN("sd.filter", "Got Font Pixel Size: " << dFontSize);
dFontSize = lcl_ToLogic(dFontSize);
SAL_WARN("sd.filter", "Got Font Logic Size: " << dFontSize);
+
+ unsigned int nR, nG, nB, nA;
+ if (FPDFTextObj_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA))
+ mpVD->SetTextColor(Color(nR, nG, nB));
+
vcl::Font aFnt = mpVD->GetFont();
aFnt.SetFontSize(Size(dFontSize, dFontSize));
mpVD->SetFont(aFnt);
commit 6fc0b8838a37463886c09fdf7aad1d05f7e58b28
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Mon Apr 9 22:17:49 2018 -0400
svx: more informative logging
Change-Id: Ia9f2fa1fbb24ad3466bd082b778244f451c90745
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index aaa8347f03fd..6dd75b0a293e 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -229,29 +229,29 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
if (pPageObject == nullptr)
continue;
- SAL_WARN("sd.filter", "Got page object number: " << nPageObjectIndex);
+ SAL_WARN("sd.filter", "Got page object number: ");
- // Process everything but text, which is done separately below.
const int nPageObjectType = FPDFPageObj_GetType(pPageObject);
switch (nPageObjectType)
{
case FPDF_PAGEOBJ_TEXT:
- ImportText(pPageObject);
+ ImportText(pPageObject, nPageObjectIndex);
break;
case FPDF_PAGEOBJ_PATH:
- SAL_WARN("sd.filter", "Got page object PATH");
+ SAL_WARN("sd.filter", "Got page object PATH: " << nPageObjectIndex);
break;
case FPDF_PAGEOBJ_IMAGE:
- ImportImage(pPageObject);
+ ImportImage(pPageObject, nPageObjectIndex);
break;
case FPDF_PAGEOBJ_SHADING:
- SAL_WARN("sd.filter", "Got page object SHADING");
+ SAL_WARN("sd.filter", "Got page object SHADING: " << nPageObjectIndex);
break;
case FPDF_PAGEOBJ_FORM:
- SAL_WARN("sd.filter", "Got page object FORM");
+ SAL_WARN("sd.filter", "Got page object FORM: " << nPageObjectIndex);
break;
default:
- SAL_WARN("sd.filter", "Unknown PDF page object type: " << nPageObjectType);
+ SAL_WARN("sd.filter", "Unknown PDF page object type: "
+ << nPageObjectType << ": " << nPageObjectIndex);
break;
}
}
@@ -1014,10 +1014,9 @@ void ImpSdrPdfImport::checkClip()
}
bool ImpSdrPdfImport::isClip() const { return !maClip.getB2DRange().isEmpty(); }
-
-void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject)
+void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex)
{
- SAL_WARN("sd.filter", "Got page object TEXT");
+ SAL_WARN("sd.filter", "Got page object TEXT: " << nPageObjectIndex);
float left;
float bottom;
float right;
@@ -1157,9 +1156,9 @@ void ImpSdrPdfImport::MapScaling()
mnMapScalingOfs = nCount;
}
-void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject)
+void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex)
{
- SAL_WARN("sd.filter", "Got page object IMAGE");
+ SAL_WARN("sd.filter", "Got page object IMAGE: " << nPageObjectIndex);
std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmapBgra(pPageObject));
if (!bitmap)
{
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index 7d458b978c01..dd4306c738bd 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -100,10 +100,10 @@ class ImpSdrPdfImport final
void checkClip();
bool isClip() const;
- void ImportImage(FPDF_PAGEOBJECT pPageObject);
+ void ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
void SetupPageScale(const double dPageWidth, const double dPageHeight);
- void ImportText(FPDF_PAGEOBJECT pPageObject);
+ void ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
void ImportText(const Point& rPos, const OUString& rStr);
void SetAttributes(SdrObject* pObj, bool bForceTextAttr = false);
void InsertObj(SdrObject* pObj, bool bScale = true);
commit 0cda67a10f461b22f44fa3ef873b92cf13f2ba48
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Mon Apr 9 22:16:05 2018 -0400
svx: import PDF images as BGRA
This makes it trivial to support all sort of
odd bit-format and 8-bit paletted images.
Change-Id: I4555794eccd0ee2906f9a39bd93957ad3775432c
diff --git a/external/pdfium/edit.patch.1 b/external/pdfium/edit.patch.1
index b7cd86e5ff2d..da72f96f46fc 100644
--- a/external/pdfium/edit.patch.1
+++ b/external/pdfium/edit.patch.1
@@ -34,6 +34,37 @@ index 0a01ae0..fad2920 100644
if (bPattern) {
DrawTextPathWithPattern(textobj, pObj2Device, pFont, font_size,
&text_matrix, bFill, bStroke);
+diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp
+index 0d7ba56..37bdf99 100644
+--- a/fpdfsdk/fpdfeditimg.cpp
++++ b/fpdfsdk/fpdfeditimg.cpp
+@@ -167,6 +167,26 @@ FPDFImageObj_GetBitmap(FPDF_PAGEOBJECT image_object) {
+ return pBitmap.Leak();
+ }
+
++FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV
++FPDFImageObj_GetBitmapBgra(FPDF_PAGEOBJECT image_object) {
++ CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(image_object);
++ if (!pObj || !pObj->IsImage())
++ return nullptr;
++
++ RetainPtr<CPDF_Image> pImg = pObj->AsImage()->GetImage();
++ if (!pImg)
++ return nullptr;
++
++ RetainPtr<CFX_DIBSource> pSource = pImg->LoadDIBSource();
++ if (!pSource)
++ return nullptr;
++
++ RetainPtr<CFX_DIBitmap> pBitmap;
++ pBitmap = pSource->CloneConvert(FXDIB_Argb);
++
++ return pBitmap.Leak();
++}
++
+ FPDF_EXPORT unsigned long FPDF_CALLCONV
+ FPDFImageObj_GetImageDataDecoded(FPDF_PAGEOBJECT image_object,
+ void* buffer,
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index ca2cf3f..ac36788 100644
--- a/fpdfsdk/fpdfeditpage.cpp
@@ -283,3 +314,17 @@ index 043dc16..fe3b971 100644
// Function: FPDFLink_LoadWebLinks
// Prepare information about weblinks in a page.
// Parameters:
+diff --git a/public/fpdfview.h b/public/fpdfview.h
+index 35e87ae..80ab0ad 100644
+--- a/public/fpdfview.h
++++ b/public/fpdfview.h
+@@ -908,6 +908,9 @@ FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width,
+ // function; see the list of such formats above.
+ FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetFormat(FPDF_BITMAP bitmap);
+
++FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV
++FPDFImageObj_GetBitmapBgra(FPDF_PAGEOBJECT image_object);
++
+ // Function: FPDFBitmap_FillRect
+ // Fill a rectangle in a bitmap.
+ // Parameters:
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index b4b8ca47a54d..aaa8347f03fd 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1160,7 +1160,7 @@ void ImpSdrPdfImport::MapScaling()
void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject)
{
SAL_WARN("sd.filter", "Got page object IMAGE");
- std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmap(pPageObject));
+ std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmapBgra(pPageObject));
if (!bitmap)
{
SAL_WARN("sd.filter", "Failed to get IMAGE");
@@ -1222,7 +1222,7 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject)
for (int nRow = 0; nRow < nHeight; ++nRow)
{
pWriteAccess->CopyScanline(nRow, pBuf + (nStride * nRow),
- ScanlineFormat::N32BitTcBgra, nStride);
+ ScanlineFormat::N32BitTcRgba, nStride);
}
break;
case FPDFBitmap_BGRA:
commit 1b6300f00de97c64d1df1e0ed35af98973a18ee6
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Mon Apr 9 09:08:02 2018 -0400
svx: refactor PDF text importing
Change-Id: Ibe8d794c1d457936c9272bb664a5478d78654dd4
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index d5673a4cf364..b4b8ca47a54d 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -236,67 +236,8 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
switch (nPageObjectType)
{
case FPDF_PAGEOBJ_TEXT:
- {
- SAL_WARN("sd.filter", "Got page object TEXT");
- 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;
+ ImportText(pPageObject);
+ break;
case FPDF_PAGEOBJ_PATH:
SAL_WARN("sd.filter", "Got page object PATH");
break;
@@ -1073,6 +1014,63 @@ void ImpSdrPdfImport::checkClip()
}
bool ImpSdrPdfImport::isClip() const { return !maClip.getB2DRange().isEmpty(); }
+
+void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject)
+{
+ SAL_WARN("sd.filter", "Got page object TEXT");
+ 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 (" << nChars << "): [" << sText << "].");
+
+ ImportText(aRect.TopLeft(), sText);
+}
+
void ImpSdrPdfImport::ImportText(const Point& rPos, const OUString& rStr)
{
// calc text box size, add 5% to make it fit safely
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index 0c462c6fc135..7d458b978c01 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -103,6 +103,7 @@ class ImpSdrPdfImport final
void ImportImage(FPDF_PAGEOBJECT pPageObject);
void SetupPageScale(const double dPageWidth, const double dPageHeight);
+ void ImportText(FPDF_PAGEOBJECT pPageObject);
void ImportText(const Point& rPos, const OUString& rStr);
void SetAttributes(SdrObject* pObj, bool bForceTextAttr = false);
void InsertObj(SdrObject* pObj, bool bScale = true);
More information about the Libreoffice-commits
mailing list