summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-05-20 15:17:16 -0400
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-04 12:36:28 -0400
commit380db6cc1cced6f4dbae7ef86e72c1cc46b380fa (patch)
tree6dbea83c2b596499a1f7db65c47c3fd3a11959f3
parente0614ef61cb25b700a575440c05ca86b57824834 (diff)
svx: set the font name of imported PDF text
Change-Id: I79dde3c8983a70311de2d2a46093fac2722fb372 (cherry picked from commit b29879a233e7cdb4162092483752c2f6d13733aa)
-rw-r--r--external/pdfium/edit.patch.143
-rw-r--r--svx/source/svdraw/svdpdf.cxx14
2 files changed, 52 insertions, 5 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 80419e72a477..d8b4d0a306cf 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -930,6 +930,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))