summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-06-28 13:46:41 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-06-29 23:38:48 +0200
commitaf7b619f2752fcac3492c53444e836371efbd5fe (patch)
treedf5f559b45ce689a1a3740bc9b0d407a0b1b5205 /svx
parentf5124552d87e84b5b6d6707c30b5f8a5defed69e (diff)
pdf: add text page object attribs, refactor ImpSdrPdfImport, tests
This refactors ImpSdrPdfImport to push more functions into the PDFium wrapper. The focus is on text page object attributes. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97366 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 4e9b03d04f740a0cbafa22a4f3cedfae7f37a994) Change-Id: Ie1faf5e3743eec7c77050835651533f9e227c2a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97451 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/inc/svdpdf.hxx4
-rw-r--r--svx/source/svdraw/svdpdf.cxx71
2 files changed, 22 insertions, 53 deletions
diff --git a/svx/source/inc/svdpdf.hxx b/svx/source/inc/svdpdf.hxx
index 49c8d3e1b3c2..b1ad9d69ad12 100644
--- a/svx/source/inc/svdpdf.hxx
+++ b/svx/source/inc/svdpdf.hxx
@@ -120,7 +120,9 @@ class SVXCORE_DLLPUBLIC ImpSdrPdfImport final
int nPageObjectIndex);
void ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
void ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
- void ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage, int nPageObjectIndex);
+ void ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
+ int nPageObjectIndex);
void InsertTextObject(const Point& rPos, const Size& rSize, const OUString& rStr);
void SetupPageScale(const double dPageWidth, const double dPageHeight);
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 066c77f0798f..ff4029a00b54 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -694,7 +694,7 @@ void ImpSdrPdfImport::ImportPdfObject(
switch (nPageObjectType)
{
case FPDF_PAGEOBJ_TEXT:
- ImportText(pPageObject->getPointer(), pTextPage->getPointer(), nPageObjectIndex);
+ ImportText(pPageObject, pTextPage, nPageObjectIndex);
break;
case FPDF_PAGEOBJ_PATH:
ImportPath(pPageObject->getPointer(), nPageObjectIndex);
@@ -736,47 +736,23 @@ void ImpSdrPdfImport::ImportForm(std::unique_ptr<vcl::pdf::PDFiumPageObject> con
maCurrentMatrix = aOldMatrix;
}
-void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage,
+void ImpSdrPdfImport::ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
int /*nPageObjectIndex*/)
{
- 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");
- }
-
- if (left == right || top == bottom)
- return;
-
- double a, b, c, d, e, f;
- FPDFTextObj_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
-
+ basegfx::B2DRectangle aTextRect = pPageObject->getBounds();
+ basegfx::B2DHomMatrix aMatrix = pPageObject->getMatrix();
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 nBytes = FPDFTextObj_GetText(pPageObject, pTextPage, nullptr, 0);
- std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nBytes]);
-
- const int nActualBytes = FPDFTextObj_GetText(pPageObject, pTextPage, pText.get(), nBytes);
- if (nActualBytes <= 0)
- {
- return;
- }
+ OUString sText = pPageObject->getText(pTextPage);
- // Let's rely on null-terminaton for the length of the string. We
- // just know the number of bytes the string takes, but in OUString
- // needs the number of charaters.
- OUString sText(pText.get());
-
- const double dFontSize = FPDFTextObj_GetFontSize(pPageObject);
- double dFontSizeH = fabs(sqrt2(a, c) * dFontSize);
- double dFontSizeV = fabs(sqrt2(b, d) * dFontSize);
+ const double dFontSize = pPageObject->getFontSize();
+ double dFontSizeH = fabs(sqrt2(aMatrix.a(), aMatrix.c()) * dFontSize);
+ double dFontSizeV = fabs(sqrt2(aMatrix.b(), aMatrix.d()) * dFontSize);
dFontSizeH = convertPointToMm100(dFontSizeH);
dFontSizeV = convertPointToMm100(dFontSizeV);
@@ -790,25 +766,18 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
mbFntDirty = true;
}
- const int nFontName = 80 + 1;
- std::unique_ptr<char[]> pFontName(new char[nFontName]); // + terminating null
- char* pCharFontName = reinterpret_cast<char*>(pFontName.get());
- int nFontNameChars = FPDFTextObj_GetFontName(pPageObject, pCharFontName, nFontName);
- if (nFontName >= nFontNameChars)
+ OUString sFontName = pPageObject->getFontName();
+ if (!sFontName.isEmpty() && sFontName != aFnt.GetFamilyName())
{
- OUString sFontName = OUString::createFromAscii(pFontName.get());
- if (sFontName != aFnt.GetFamilyName())
- {
- aFnt.SetFamilyName(sFontName);
- mpVD->SetFont(aFnt);
- mbFntDirty = true;
- }
+ aFnt.SetFamilyName(sFontName);
+ mpVD->SetFont(aFnt);
+ mbFntDirty = true;
}
Color aTextColor(COL_TRANSPARENT);
bool bFill = false;
bool bUse = true;
- switch (FPDFTextObj_GetTextRenderMode(pPageObject))
+ switch (pPageObject->getTextRenderMode())
{
case FPDF_TEXTRENDERMODE_FILL:
case FPDF_TEXTRENDERMODE_FILL_CLIP:
@@ -826,11 +795,9 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
}
if (bUse)
{
- unsigned int nR, nG, nB, nA;
- bool bRet = bFill ? FPDFPageObj_GetFillColor(pPageObject, &nR, &nG, &nB, &nA)
- : FPDFPageObj_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA);
- if (bRet)
- aTextColor = Color(nR, nG, nB);
+ Color aColor = bFill ? pPageObject->getFillColor() : pPageObject->getStrokeColor();
+ if (aColor != COL_TRANSPARENT)
+ aTextColor = aColor.GetRGBColor();
}
if (aTextColor != mpVD->GetTextColor())