Kaydet (Commit) 6e1b091f authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Jan Holesovsky

svx: support importing PDF images

Change-Id: Id4524a30b8f9fa4228c4acb4bf8714700da3017c
üst ddb881e2
......@@ -23,6 +23,7 @@
#include <vcl/mapmod.hxx>
#include <vcl/region.hxx>
#include <vcl/alpha.hxx>
#include <vcl/salbtype.hxx>
// predefines
......@@ -55,6 +56,13 @@ bool VCL_DLLPUBLIC ReadDIBV5(
AlphaMask& rTargetAlpha,
SvStream& rIStm);
bool VCL_DLLPUBLIC ReadRawDIB(
Bitmap& rTarget,
const unsigned char* pBuf,
const ScanlineFormat nFormat,
const int nHeight,
const int nStride);
bool VCL_DLLPUBLIC WriteDIB(
const Bitmap& rSource,
......
......@@ -77,7 +77,6 @@
#include <basegfx/polygon/b2dpolygonclipper.hxx>
#include <svx/xbtmpit.hxx>
#include <svx/xfltrit.hxx>
#include <vcl/bitmapaccess.hxx>
#include <svx/xflbmtit.hxx>
#include <svx/xflbstit.hxx>
#include <svx/svdpntv.hxx>
......@@ -85,8 +84,14 @@
#include <svx/svditer.hxx>
#include <svx/svdogrp.hxx>
#include <vcl/BitmapTools.hxx>
#include <vcl/dibtools.hxx>
#include <com/sun/star/geometry/Matrix2D.hpp>
struct FPDFBitmapDeleter
{
inline void operator()(FPDF_BITMAP bitmap) { FPDFBitmap_Destroy(bitmap); }
};
using namespace com::sun::star;
ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools::Rectangle& rRect,
......@@ -213,8 +218,82 @@ 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");
break;
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;
case FPDF_PAGEOBJ_SHADING:
SAL_WARN("sd.filter", "Got page object SHADING");
break;
......
......@@ -1821,6 +1821,22 @@ bool ReadDIBV5(
return ImplReadDIB(rTarget, &rTargetAlpha, rIStm, true);
}
bool ReadRawDIB(
Bitmap& rTarget,
const unsigned char* pBuf,
const ScanlineFormat nFormat,
const int nHeight,
const int nStride)
{
BitmapScopedWriteAccess pWriteAccess(rTarget.AcquireWriteAccess(), rTarget);
for (int nRow = 0; nRow < nHeight; ++nRow)
{
pWriteAccess->CopyScanline(nRow, pBuf + (nStride * nRow), nFormat, nStride);
}
return true;
}
bool WriteDIB(
const Bitmap& rSource,
SvStream& rOStm,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment