summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-04-08 11:37:30 -0400
committerJan Holesovsky <kendy@collabora.com>2018-06-06 12:47:40 +0200
commita3ec3984b105f1983a2ab5a62e0eee5b99337195 (patch)
tree5eb07fec9e50453ce1436881c6cb366d22ff8fcf
parent09f3ac0eb8e2d91c337d1a46501f3feb508f667b (diff)
svx: import images from PDF
Change-Id: If0765aac9f47df73f1021664e13afa15ebf0f9ee
-rw-r--r--svx/source/svdraw/svdpdf.cxx200
-rw-r--r--svx/source/svdraw/svdpdf.hxx3
2 files changed, 125 insertions, 78 deletions
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index f924a2c12f98..2771da544e86 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -174,6 +174,7 @@ ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools:
}
mnPageCount = FPDF_GetPageCount(mpPdfDocument);
+ SAL_WARN("sd.filter", "Scale Rect: " << maScaleRect);
}
ImpSdrPdfImport::~ImpSdrPdfImport()
@@ -190,13 +191,15 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
{
// Render next page.
FPDF_PAGE pPdfPage = FPDF_LoadPage(mpPdfDocument, nPageIndex);
+
if (pPdfPage == nullptr)
break;
const double dPageWidth = FPDF_GetPageWidth(pPdfPage);
- const double dPageHeight = FPDF_GetPageWidth(pPdfPage);
+ const double dPageHeight = FPDF_GetPageHeight(pPdfPage);
SAL_WARN("sd.filter", "Loaded page: " << nPageIndex << ", width: " << dPageWidth
<< ", height: " << dPageHeight);
+ SAL_WARN("sd.filter", "Scale Rect: " << maScaleRect);
const int nPageObjectCount = FPDFPage_CountObject(pPdfPage);
for (int nPageObjectIndex = 0; nPageObjectIndex < nPageObjectCount; ++nPageObjectIndex)
@@ -218,82 +221,8 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
SAL_WARN("sd.filter", "Got page object PATH");
break;
case FPDF_PAGEOBJ_IMAGE:
- {
- SAL_WARN("sd.filter", "Got page object IMAGE");
- std::unique_ptr<void, FPDFBitmapDeleter> bitmap(
- FPDFImageObj_GetBitmap(pPageObject));
- if (!bitmap)
- {
- SAL_WARN("sd.filter", "Failed to get IMAGE");
- continue;
- }
-
- const int format = FPDFBitmap_GetFormat(bitmap.get());
- if (format == FPDFBitmap_Unknown)
- {
- SAL_WARN("sd.filter", "Failed to get IMAGE format");
- continue;
- }
-
- const unsigned char* pBuf
- = static_cast<const unsigned char*>(FPDFBitmap_GetBuffer(bitmap.get()));
- const int nWidth = FPDFBitmap_GetWidth(bitmap.get());
- const int nHeight = FPDFBitmap_GetHeight(bitmap.get());
- const int nStride = FPDFBitmap_GetStride(bitmap.get());
- Bitmap aBitmap(Size(nWidth, nHeight), 24);
-
- switch (format)
- {
- case FPDFBitmap_Gray:
- SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth
- << ", height: " << nHeight
- << ", stride: " << nStride
- << ", format: Gray");
- ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N8BitTcMask, nHeight,
- nStride);
- 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::N32BitTcBgra, 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:
- SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth
- << ", height: " << nHeight
- << ", stride: " << nStride
- << ", format: " << format);
- break;
- }
-
- tools::Rectangle aRect(Point(0, 0), Size(nWidth, nHeight));
- // aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
- SdrGrafObj* pGraf = new SdrGrafObj(*mpModel, Graphic(aBitmap), aRect);
-
- // This action is not creating line and fill, set directly, do not use SetAttributes(..)
- pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
- pGraf->SetMergedItem(XFillStyleItem(drawing::FillStyle_NONE));
- InsertObj(pGraf);
- }
- break;
+ ImportImage(pPageObject);
+ break;
case FPDF_PAGEOBJ_SHADING:
SAL_WARN("sd.filter", "Got page object SHADING");
break;
@@ -306,6 +235,7 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
}
}
+ /*
// Now do the text.
FPDF_TEXTPAGE pTextPage = FPDFText_LoadPage(pPdfPage);
if (pTextPage != nullptr)
@@ -418,6 +348,7 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
}
FPDF_ClosePage(pPdfPage);
+*/
}
// const sal_uLong nCount(rMtf.GetActionSize());
@@ -1013,7 +944,6 @@ void ImpSdrPdfImport::checkClip()
}
bool ImpSdrPdfImport::isClip() const { return !maClip.getB2DRange().isEmpty(); }
-
void ImpSdrPdfImport::ImportText(const Point& rPos, const OUString& rStr)
{
// calc text box size, add 5% to make it fit safely
@@ -1098,4 +1028,118 @@ void ImpSdrPdfImport::MapScaling()
mnMapScalingOfs = nCount;
}
+void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject)
+{
+ SAL_WARN("sd.filter", "Got page object IMAGE");
+ std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmap(pPageObject));
+ if (!bitmap)
+ {
+ SAL_WARN("sd.filter", "Failed to get IMAGE");
+ return;
+ }
+
+ const int format = FPDFBitmap_GetFormat(bitmap.get());
+ if (format == FPDFBitmap_Unknown)
+ {
+ SAL_WARN("sd.filter", "Failed to get IMAGE format");
+ return;
+ }
+
+ const unsigned char* pBuf
+ = static_cast<const unsigned char*>(FPDFBitmap_GetBuffer(bitmap.get()));
+ const int nWidth = FPDFBitmap_GetWidth(bitmap.get());
+ const int nHeight = FPDFBitmap_GetHeight(bitmap.get());
+ const int nStride = FPDFBitmap_GetStride(bitmap.get());
+ Bitmap aBitmap(Size(nWidth, nHeight), 24);
+
+ 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::N32BitTcBgra, 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:
+ SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight
+ << ", stride: " << nStride
+ << ", format: " << format);
+ 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;
+ float top;
+ if (!FPDFPageObj_GetBounds(pPageObject, &left, &bottom, &right, &top))
+ {
+ SAL_WARN("sd.filter", "FAILED to get image bounds");
+ }
+
+ SAL_WARN("sd.filter", "Got IMAGE left: " << left << ", bottom: " << bottom << ", right; "
+ << right << ", top: " << top);
+ tools::Rectangle aRect1(Point(left, top), Size(right - left, top - bottom));
+ SAL_WARN("sd.filter", "Got IMAGE BBox: " << aRect1);
+ tools::Rectangle aLogRect(
+ OutputDevice::LogicToLogic(aRect1, aBitmap.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)));
+ SAL_WARN("sd.filter", "Logical Rect: " << aLogRect);
+ aLogRect.Move(maScaleRect.Left(), maScaleRect.Top() - aLogRect.Top());
+
+ // SAL_WARN("sd.filter", "Bitmap Size: " << aBitmap.GetPrefSize());
+ // SAL_WARN("sd.filter", "Bitmap MapMpde: " << aBitmap.GetPrefMapMode());
+ Size aGrfSize(OutputDevice::LogicToLogic(Size(nWidth, nHeight), aBitmap.GetPrefMapMode(),
+ MapMode(MapUnit::Map100thMM)));
+ SAL_WARN("sd.filter", "Logical Size: " << aGrfSize);
+ // SAL_WARN("sd.filter", "Scaled Logical Size: " << aGrfSize);
+ Point aGrfPos(OutputDevice::LogicToLogic(Point(left, top), aBitmap.GetPrefMapMode(),
+ MapMode(MapUnit::Map100thMM)));
+ SAL_WARN("sd.filter", "Logical Pos: " << aGrfPos);
+
+ SAL_WARN("sd.filter", "Page Logical Height: " << maScaleRect.GetHeight());
+ const auto realTop = maScaleRect.GetHeight() - aGrfPos.Y();
+ SAL_WARN("sd.filter", "Real Logical Top Offset: " << realTop);
+ aGrfPos.Move(maScaleRect.Left(), maScaleRect.Top() - aGrfPos.Y());
+ SAL_WARN("sd.filter", "Adjusted Logical Pos: " << aGrfPos);
+
+ tools::Rectangle aRect(aGrfPos, aGrfSize);
+ SAL_WARN("sd.filter", "Got IMAGE Logical BBox: " << aRect);
+
+ // aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
+ SdrGrafObj* pGraf = new SdrGrafObj(*mpModel, Graphic(aBitmap), aLogRect);
+
+ // This action is not creating line and fill, set directly, do not use SetAttributes(..)
+ pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
+ pGraf->SetMergedItem(XFillStyleItem(drawing::FillStyle_NONE));
+ InsertObj(pGraf);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index 4f382a14a015..4416c48979c8 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -41,6 +41,7 @@ class SdrPage;
class SdrObject;
class SvdProgressInfo;
typedef void* FPDF_DOCUMENT;
+typedef void* FPDF_PAGEOBJECT;
// Helper Class to import PDF
class ImpSdrPdfImport final
@@ -89,6 +90,8 @@ class ImpSdrPdfImport final
void checkClip();
bool isClip() const;
+ void ImportImage(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);