[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - 2 commits - include/vcl sd/source svx/source vcl/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Wed Apr 1 18:54:51 UTC 2020
include/vcl/pdfread.hxx | 7 +-----
sd/source/filter/pdf/sdpdffilter.cxx | 17 +++------------
svx/source/svdraw/svdpdf.cxx | 38 ++++++++++++++++++-----------------
svx/source/svdraw/svdpdf.hxx | 4 +--
vcl/source/filter/ipdf/pdfread.cxx | 14 +++++++-----
5 files changed, 36 insertions(+), 44 deletions(-)
New commits:
commit fb68f37251a3203e558e11fc83fc2b0e00ae73f9
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Mar 29 23:05:25 2020 +0200
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Apr 1 20:54:34 2020 +0200
replace usage of Matrix for B2DHomMatrix in ImpSdrPdfImport
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91341
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit c20fa884cf20959dbd65814274e450e1f49cf45e)
Change-Id: I366ee435ddf217c7c078d58f882610df12bec276
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91453
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index d24d85b2205d..6d89c4bf5390 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -768,11 +768,11 @@ void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
int /*nPageObjectIndex*/)
{
// Get the form matrix to perform correct translation/scaling of the form sub-objects.
- const Matrix aOldMatrix = mCurMatrix;
+ const basegfx::B2DHomMatrix aOldMatrix = maCurrentMatrix;
double a, b, c, d, e, f;
FPDFFormObj_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
- mCurMatrix = Matrix(a, b, c, d, e, f);
+ maCurrentMatrix = basegfx::B2DHomMatrix::abcdef(a, b, c, d, e, f);
const int nCount = FPDFFormObj_CountObjects(pPageObject);
for (int nIndex = 0; nIndex < nCount; ++nIndex)
@@ -782,7 +782,7 @@ void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
}
// Restore the old one.
- mCurMatrix = aOldMatrix;
+ maCurrentMatrix = aOldMatrix;
}
void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage,
@@ -802,10 +802,11 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
double a, b, c, d, e, f;
FPDFText_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
- Matrix aTextMatrix(mCurMatrix);
-
- aTextMatrix.Transform(left, right, top, bottom);
- const tools::Rectangle aRect = PointsToLogic(left, right, top, bottom);
+ basegfx::B2DHomMatrix aTextMatrix(maCurrentMatrix);
+ basegfx::B2DRange aTextRect(left, top, right, bottom);
+ aTextRect *= aTextMatrix;
+ const tools::Rectangle aRect = PointsToLogic(aTextRect.getMinX(), aTextRect.getMaxX(),
+ aTextRect.getMinY(), aTextRect.getMaxY());
const int nChars = FPDFTextObj_GetText(pPageObject, pTextPage, nullptr, 0);
std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nChars]);
@@ -1037,8 +1038,9 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
{
double a, b, c, d, e, f;
FPDFPath_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
- Matrix aPathMatrix(a, b, c, d, e, f);
- aPathMatrix.Concatinate(mCurMatrix);
+
+ auto aPathMatrix = basegfx::B2DHomMatrix::abcdef(a, b, c, d, e, f);
+ aPathMatrix *= maCurrentMatrix;
basegfx::B2DPolyPolygon aPolyPoly;
basegfx::B2DPolygon aPoly;
@@ -1057,26 +1059,26 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
continue;
}
- double x = fx;
- double y = fy;
- aPathMatrix.Transform(x, y);
+ basegfx::B2DPoint aB2DPoint(fx, fy);
+ aB2DPoint *= aPathMatrix;
+
const bool bClose = FPDFPathSegment_GetClose(pPathSegment);
if (bClose)
aPoly.setClosed(bClose); // TODO: Review
- Point aPoint = PointsToLogic(x, y);
- x = aPoint.X();
- y = aPoint.Y();
+ Point aPoint = PointsToLogic(aB2DPoint.getX(), aB2DPoint.getY());
+ aB2DPoint.setX(aPoint.X());
+ aB2DPoint.setY(aPoint.Y());
const int nSegmentType = FPDFPathSegment_GetType(pPathSegment);
switch (nSegmentType)
{
case FPDF_SEGMENT_LINETO:
- aPoly.append(basegfx::B2DPoint(x, y));
+ aPoly.append(aB2DPoint);
break;
case FPDF_SEGMENT_BEZIERTO:
- aBezier.emplace_back(x, y);
+ aBezier.emplace_back(aB2DPoint.getX(), aB2DPoint.getY());
if (aBezier.size() == 3)
{
aPoly.appendBezierSegment(aBezier[0], aBezier[1], aBezier[2]);
@@ -1092,7 +1094,7 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
aPoly.clear();
}
- aPoly.append(basegfx::B2DPoint(x, y));
+ aPoly.append(aB2DPoint);
break;
case FPDF_SEGMENT_UNKNOWN:
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index 40e835bb67a4..9dd6626d3318 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -37,7 +37,7 @@
#include <svx/xdash.hxx>
#include <com/sun/star/uno/Sequence.hxx>
-#include <basegfx/matrix/Matrix.hxx>
+#include <basegfx/matrix/b2dhommatrix.hxx>
// Prevent workdir/UnpackedTarball/pdfium/public/fpdfview.h from including windows.h in a way that
// it will define e.g. Yield as a macro:
@@ -95,7 +95,7 @@ class ImpSdrPdfImport final
double mdPageWidthPts;
double mdPageHeightPts;
/// The current transformation matrix, typically used with Form objects.
- Matrix mCurMatrix;
+ basegfx::B2DHomMatrix maCurrentMatrix;
/// Correct the vertical coordinate to start at the top.
/// PDF coordinate system has origin at the bottom right.
commit b0cc614b7119c6933426b5e0cde9628596671bd5
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Mar 29 16:30:19 2020 +0200
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Apr 1 20:54:20 2020 +0200
pdfium: fix setting the size of the document when opening PDF
When loading the pages of PDF, the size of the document was
set to the wrong value. Size returned by ImportPDFUnloaded was
in pixels, which is not really useful considering the svx and
sd core uses 100th mm as the unit and converting it to a device
dependent pixel will just bring grief. Also we don't need to know
the size in pixels until we actually render.
This change removes DPI as the parameter to the ImportPDFUnloaded
and changes the code to get the size of the page from the PDF as
points and converts that to 100th mm.
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91330
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 489b18edd6dc87287f260ba87d95abcc95d87932)
Change-Id: I0c0db23d2775e2897ba7621ef6320a974c0b9275
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91452
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx
index 986c208c25a5..914b714f9f94 100644
--- a/include/vcl/pdfread.hxx
+++ b/include/vcl/pdfread.hxx
@@ -39,13 +39,10 @@ VCL_DLLPUBLIC size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vecto
VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic);
-/// Import PDF as Graphic images (1 per page), all unloaded.
-/// Since Graphic is unloaded, we need to return the page size (in pixels) separately.
-/// Does not set rPdfData if no conversion is done.
+/// Import PDF as Graphic images (1 per page), but not loaded yet.
/// Returns the number of pages read.
VCL_DLLPUBLIC size_t ImportPDFUnloaded(const OUString& rURL,
- std::vector<std::pair<Graphic, Size>>& rGraphics,
- const double fResolutionDPI = 96.);
+ std::vector<std::pair<Graphic, Size>>& rGraphics);
}
#endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 810ee907bbdb..15b4711711cb 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -87,11 +87,8 @@ bool SdPdfFilter::Import()
const OUString aFileName(
mrMedium.GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE));
- // Rendering resolution.
- const double dResolutionDPI = 96.0;
-
std::vector<std::pair<Graphic, Size>> aGraphics;
- if (vcl::ImportPDFUnloaded(aFileName, aGraphics, dResolutionDPI) == 0)
+ if (vcl::ImportPDFUnloaded(aFileName, aGraphics) == 0)
return false;
// Add as many pages as we need up-front.
@@ -104,26 +101,20 @@ bool SdPdfFilter::Import()
for (const std::pair<Graphic, Size>& aPair : aGraphics)
{
const Graphic& rGraphic = aPair.first;
- const Size& aSize = aPair.second;
+ const Size& aSizeHMM = aPair.second;
const sal_Int32 nPageNumber = rGraphic.getPageNumber();
assert(nPageNumber >= 0 && static_cast<size_t>(nPageNumber) < aGraphics.size());
// Create the page and insert the Graphic.
SdPage* pPage = mrDocument.GetSdPage(nPageNumber, PageKind::Standard);
- Size aGraphicSize(OutputDevice::LogicToLogic(aSize, rGraphic.GetPrefMapMode(),
- MapMode(MapUnit::Map100thMM)));
-
- // Resize to original size based on 72 dpi to preserve page size.
- aGraphicSize = Size(aGraphicSize.Width() * 72.0 / dResolutionDPI,
- aGraphicSize.Height() * 72.0 / dResolutionDPI);
// Make the page size match the rendered image.
- pPage->SetSize(aGraphicSize);
+ pPage->SetSize(aSizeHMM);
Point aPosition(0, 0);
SdrGrafObj* pSdrGrafObj = new SdrGrafObj(pPage->getSdrModelFromSdrPage(), rGraphic,
- tools::Rectangle(aPosition, aGraphicSize));
+ tools::Rectangle(aPosition, aSizeHMM));
pPage->InsertObject(pSdrGrafObj);
}
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index 2cb7907ddd5e..ebe6d0db0c03 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -236,8 +236,7 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
return true;
}
-size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Size>>& rGraphics,
- const double fResolutionDPI)
+size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Size>>& rGraphics)
{
#if HAVE_FEATURE_PDFIUM
std::unique_ptr<SvStream> xStream(
@@ -281,9 +280,13 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
if (FPDF_GetPageSizeByIndex(pPdfDocument, nPageIndex, &fPageWidth, &fPageHeight) == 0)
continue;
- // Returned unit is points, convert that to pixel.
- const size_t nPageWidth = pointToPixel(fPageWidth, fResolutionDPI);
- const size_t nPageHeight = pointToPixel(fPageHeight, fResolutionDPI);
+ // Returned unit is points, convert that to 100th mm (hmm).
+ // 1 pt = 20 twips, 1 twip = 1.7638888888888889 hmm
+ // TODO: use some conversion class for that
+ constexpr double pointToHMMconversionRatio = 20.0 * 1.7638888888888889;
+
+ long nPageWidth = fPageWidth * pointToHMMconversionRatio;
+ long nPageHeight = fPageHeight * pointToHMMconversionRatio;
auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(
aPdfDataArray, OUString(), VectorGraphicDataType::Pdf, nPageIndex);
@@ -304,7 +307,6 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
#else
(void)rURL;
(void)rGraphics;
- (void)fResolutionDPI;
return 0;
#endif // HAVE_FEATURE_PDFIUM
}
More information about the Libreoffice-commits
mailing list