summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-05-20 15:17:16 -0400
committerJan Holesovsky <kendy@collabora.com>2018-05-22 12:17:20 +0200
commitb29879a233e7cdb4162092483752c2f6d13733aa (patch)
tree8f230d764ac87e84461c65c6429a6cb6a2e6af2b
parentd4eaa026efde056ad4d429bccaa0b18f0388d6ec (diff)
svx: set the font name of imported PDF text
Change-Id: I79dde3c8983a70311de2d2a46093fac2722fb372
-rw-r--r--external/pdfium/edit.patch.143
-rw-r--r--svx/source/svdraw/svdpdf.cxx24
2 files changed, 57 insertions, 10 deletions
diff --git a/external/pdfium/edit.patch.1 b/external/pdfium/edit.patch.1
index de57d10e1be6..d0d7cb97060e 100644
--- a/external/pdfium/edit.patch.1
+++ b/external/pdfium/edit.patch.1
@@ -111,7 +111,7 @@ index fed1581..968b84a 100644
FPDFImageObj_GetImageDataDecoded(FPDF_PAGEOBJECT image_object,
void* buffer,
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
-index ec29891..a52e1a9 100644
+index ec29891..9daffc0 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -12,12 +12,14 @@
@@ -137,7 +137,7 @@ index ec29891..a52e1a9 100644
#include "fpdfsdk/cpdfsdk_helpers.h"
#include "public/fpdf_formfill.h"
#include "third_party/base/logging.h"
-@@ -624,3 +627,245 @@ FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) {
+@@ -624,3 +627,268 @@ FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) {
pPageObj->SetDirty(true);
return true;
}
@@ -162,6 +162,29 @@ index ec29891..a52e1a9 100644
+ return pTxtObj->GetFontSize();
+}
+
++FPDF_EXPORT int FPDF_CALLCONV
++FPDFTextObj_GetFontName(FPDF_PAGEOBJECT text_object, char* result)
++{
++ if (!text_object)
++ return 0;
++
++ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
++ CPDF_Font* pPdfFont = pTxtObj->GetFont();
++ if (!pPdfFont)
++ return 0;
++
++ CFX_Font* pFont = pPdfFont->GetFont();
++ if (!pFont)
++ return 0;
++
++ ByteString byte_str = pFont->GetFamilyName();
++ const size_t byte_str_len = byte_str.GetLength();
++
++ memcpy(result, byte_str.GetBuffer(byte_str_len).data(), byte_str_len);
++ result[byte_str_len] = '\0';
++ return byte_str_len;
++}
++
+FPDF_EXPORT void FPDF_CALLCONV
+FPDFTextObj_GetMatrix(FPDF_PAGEOBJECT text_object,
+ double* a,
@@ -495,7 +518,7 @@ index a1bbbb4..01b74c9 100644
int index,
double* left,
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
-index c0766a3..4351649 100644
+index c0766a3..75381bb 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -660,6 +660,15 @@ FPDFPageObj_GetStrokeColor(FPDF_PAGEOBJECT page_object,
@@ -551,7 +574,7 @@ index c0766a3..4351649 100644
// Create a new text object using one of the standard PDF fonts.
//
// document - handle to the document.
-@@ -971,6 +1010,125 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
+@@ -971,6 +1010,135 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
FPDF_FONT font,
float font_size);
@@ -564,7 +587,6 @@ index c0766a3..4351649 100644
+FPDF_EXPORT int FPDF_CALLCONV
+FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object);
+
-+
+// Get the font size of a text object.
+//
+// text_object - Handle of text object returned by FPDFPageObj_NewTextObj
@@ -575,6 +597,17 @@ index c0766a3..4351649 100644
+FPDF_EXPORT int FPDF_CALLCONV
+FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text_object);
+
++// Get the font name of a text object.
++//
++// text_object - Handle of text object returned by FPDFPageObj_NewTextObj
++// or FPDFPageObj_NewTextObjEx.
++// result - The result in ascii.
++//
++// Return Value:
++// The number of characters / bytes written in result.
++FPDF_EXPORT int FPDF_CALLCONV
++FPDFTextObj_GetFontName(FPDF_PAGEOBJECT text_object, char* result);
++
+// Get the matrix of a particular text object.
+//
+// text_object - Handle of text object returned by FPDFPageObj_NewTextObj
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 4aa05fb30551..6855395b0ab8 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -924,6 +924,20 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
mbFntDirty = true;
}
+ std::unique_ptr<char[]> pFontName(new char[80 + 1]); // + terminating null
+ char* pCharFontName = reinterpret_cast<char*>(pFontName.get());
+ int nFontNameChars = FPDFTextObj_GetFontName(pPageObject, pCharFontName);
+ if (nFontNameChars > 0)
+ {
+ OUString sFontName = OUString::createFromAscii(pFontName.get());
+ if (sFontName != aFnt.GetFamilyName())
+ {
+ aFnt.SetFamilyName(sFontName);
+ mpVD->SetFont(aFnt);
+ mbFntDirty = true;
+ }
+ }
+
Color aTextColor(COL_TRANSPARENT);
unsigned int nR, nG, nB, nA;
if (FPDFTextObj_GetColor(pPageObject, &nR, &nG, &nB, &nA))
@@ -1206,11 +1220,11 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
if (!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aPolyPoly)))
{
- SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aPolyPoly);
- pPath->SetModel(mpModel);
- SetAttributes(pPath);
- InsertObj(pPath, false);
-}
+ SdrPathObj *pPath = new SdrPathObj(OBJ_POLY, aPolyPoly);
+ pPath->SetModel(mpModel);
+ SetAttributes(pPath);
+ InsertObj(pPath, false);
+ }
}
Point ImpSdrPdfImport::PointsToLogic(double x, double y) const