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

svx: set the font name of imported PDF text

Change-Id: I79dde3c8983a70311de2d2a46093fac2722fb372
üst 92550f9b
From 04f9899ddf5f9691ffaca5091082183f167e95d3 Mon Sep 17 00:00:00 2001
From: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Date: Wed, 6 Jun 2018 06:34:56 +0200
Subject: [PATCH] svx: set the font name of imported PDF text
---
pdfium/fpdfsdk/fpdf_editpage.cpp | 23 +++++++++++++++++++++++
pdfium/public/fpdf_edit.h | 11 +++++++++++
2 files changed, 34 insertions(+)
diff --git a/pdfium/fpdfsdk/fpdf_editpage.cpp b/pdfium/fpdfsdk/fpdf_editpage.cpp
index a52e1a9..9daffc0 100644
--- a/pdfium/fpdfsdk/fpdf_editpage.cpp
+++ b/pdfium/fpdfsdk/fpdf_editpage.cpp
@@ -648,6 +648,29 @@ FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text_object)
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,
diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
index 4351649..f858ab2 100644
--- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h
@@ -1030,6 +1030,17 @@ FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object);
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
--
2.16.3
......@@ -28,6 +28,7 @@ pdfium_patches += 0011-svx-correctly-possition-form-objects-from-PDF.patch.2
pdfium_patches += 0012-svx-import-processed-PDF-text.patch.2
pdfium_patches += 0013-svx-cleanup-pdfium-importer.patch.2
pdfium_patches += 0014-svx-update-PDFium-patch-and-code.patch.2
pdfium_patches += 0015-svx-set-the-font-name-of-imported-PDF-text.patch.2
$(eval $(call gb_UnpackedTarball_UnpackedTarball,pdfium))
......
......@@ -562,7 +562,8 @@ void ImpSdrPdfImport::InsertObj(SdrObject* pObj, bool bScale)
SdrObject* pCandidate = aIter.Next();
OSL_ENSURE(pCandidate && dynamic_cast<SdrObjGroup*>(pCandidate) == nullptr,
"SdrObjListIter with SdrIterMode::DeepNoGroups error (!)");
SdrObject* pNewClone = pCandidate->Clone();
SdrObject* pNewClone(
pCandidate->CloneSdrObject(pCandidate->getSdrModelFromSdrObject()));
if (pNewClone)
{
......@@ -927,6 +928,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))
......
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