[Libreoffice-commits] core.git: external/pdfium svx/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 29 06:37:49 UTC 2018


 external/pdfium/0001-Add-FPDFText_GetFontName-API.patch.1               |   87 ++++++++++
 external/pdfium/0002-svx-more-accurate-PDF-text-importing.patch.2       |   10 +
 external/pdfium/0012-svx-import-processed-PDF-text.patch.2              |    4 
 external/pdfium/0015-svx-set-the-font-name-of-imported-PDF-text.patch.2 |   77 --------
 external/pdfium/UnpackedTarball_pdfium.mk                               |    3 
 svx/source/svdraw/svdpdf.cxx                                            |    7 
 6 files changed, 104 insertions(+), 84 deletions(-)

New commits:
commit b4c003397eb29beff055044091c1d088acda2bae
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Tue Aug 28 21:07:05 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Wed Aug 29 08:37:24 2018 +0200

    pdfium: replace FPDFTextObj_GetFontName() patch with backport
    
    Change-Id: I36d86e7ccca66b09f2f49e401d77deb52fbf742a
    Reviewed-on: https://gerrit.libreoffice.org/59738
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/external/pdfium/0001-Add-FPDFText_GetFontName-API.patch.1 b/external/pdfium/0001-Add-FPDFText_GetFontName-API.patch.1
new file mode 100644
index 000000000000..3ddd8e6b8127
--- /dev/null
+++ b/external/pdfium/0001-Add-FPDFText_GetFontName-API.patch.1
@@ -0,0 +1,87 @@
+From 53d4f0a4526ef996caf5005ae84406a9467423f2 Mon Sep 17 00:00:00 2001
+Date: Wed, 1 Aug 2018 01:28:49 +0000
+Subject: [PATCH] Add FPDFText_GetFontName() API
+
+This follows the same pattern as DefaultGetFaceName(), so the client has
+to call this function twice, but allocation of the string buffer happens
+outside pdfium.
+
+Change-Id: I06b7dcd00aca9b9b94799dad3f139617d7f5451e
+Reviewed-on: https://pdfium-review.googlesource.com/38870
+Commit-Queue: Lei Zhang <thestig at chromium.org>
+Reviewed-by: Lei Zhang <thestig at chromium.org>
+Reviewed-by: Henrique Nakashima <hnakashima at chromium.org>
+---
+ fpdfsdk/fpdf_edit_embeddertest.cpp |  28 ++++++++++++++++++++++++++++
+ fpdfsdk/fpdf_edittext.cpp          |  22 ++++++++++++++++++++++
+ fpdfsdk/fpdf_view_c_api_test.c     |   1 +
+ public/fpdf_edit.h                 |  18 ++++++++++++++++++
+ testing/resources/text_font.pdf    | Bin 0 -> 10576 bytes
+ 5 files changed, 69 insertions(+)
+ create mode 100644 testing/resources/text_font.pdf
+
+diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
+index c552d615e..6aa44b3b2 100644
+--- a/fpdfsdk/fpdf_edittext.cpp
++++ b/fpdfsdk/fpdf_edittext.cpp
+@@ -548,6 +548,28 @@ FPDF_EXPORT double FPDF_CALLCONV FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text) {
+   return pTextObj->GetFontSize();
+ }
+ 
++FPDF_EXPORT unsigned long FPDF_CALLCONV
++FPDFTextObj_GetFontName(FPDF_PAGEOBJECT text,
++                        void* buffer,
++                        unsigned long length) {
++  CPDF_TextObject* pTextObj = CPDFTextObjectFromFPDFPageObject(text);
++  if (!pTextObj)
++    return 0;
++
++  CPDF_Font* pPdfFont = pTextObj->GetFont();
++  if (!pPdfFont)
++    return 0;
++
++  CFX_Font* pFont = pPdfFont->GetFont();
++  ASSERT(pFont);
++
++  ByteString name = pFont->GetFamilyName();
++  unsigned long dwStringLen = name.GetLength() + 1;
++  if (buffer && length >= dwStringLen)
++    memcpy(buffer, name.c_str(), dwStringLen);
++  return dwStringLen;
++}
++
+ FPDF_EXPORT void FPDF_CALLCONV FPDFFont_Close(FPDF_FONT font) {
+   CPDF_Font* pFont = CPDFFontFromFPDFFont(font);
+   if (!pFont)
+diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
+index b97a7adbd..4d5aa9c48 100644
+--- a/public/fpdf_edit.h
++++ b/public/fpdf_edit.h
+@@ -1256,6 +1256,24 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
+ // Returns one of the FPDF_TEXTRENDERMODE_* flags on success, -1 on error.
+ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
+ 
++// Experimental API.
++// Get the font name of a text object.
++//
++// text             - the handle to the text object.
++// buffer           - the address of a buffer that receives the font name.
++// length           - the size, in bytes, of |buffer|.
++//
++// Returns the number of bytes in the font name (including the trailing NUL
++// character) on success, 0 on error.
++//
++// Regardless of the platform, the |buffer| is always in UTF-8 encoding.
++// If |length| is less than the returned length, or |buffer| is NULL, |buffer|
++// will not be modified.
++FPDF_EXPORT unsigned long FPDF_CALLCONV
++FPDFTextObj_GetFontName(FPDF_PAGEOBJECT text,
++                        void* buffer,
++                        unsigned long length);
++
+ // Experimental API.
+ // Get number of page objects inside |form_object|.
+ //
+-- 
+2.16.4
+
diff --git a/external/pdfium/0002-svx-more-accurate-PDF-text-importing.patch.2 b/external/pdfium/0002-svx-more-accurate-PDF-text-importing.patch.2
index 473fe55fd2e8..6288dccba6b4 100644
--- a/external/pdfium/0002-svx-more-accurate-PDF-text-importing.patch.2
+++ b/external/pdfium/0002-svx-more-accurate-PDF-text-importing.patch.2
@@ -20,7 +20,15 @@ index 912df63..3244943 100644
  #include "core/fpdfapi/page/cpdf_form.h"
  #include "core/fpdfapi/page/cpdf_formobject.h"
  #include "core/fpdfapi/page/cpdf_imageobject.h"
-@@ -440,6 +441,16 @@ FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
+@@ -26,6 +27,7 @@
+ #include "core/fpdfapi/parser/cpdf_string.h"
+ #include "core/fpdfdoc/cpdf_annot.h"
+ #include "core/fpdfdoc/cpdf_annotlist.h"
++#include "core/fpdfapi/page/cpdf_textobject.h"
+ #include "fpdfsdk/cpdfsdk_helpers.h"
+ #include "public/fpdf_formfill.h"
+ #include "third_party/base/logging.h"
+@@ -457,6 +459,16 @@ FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
    pPageObj->Transform(matrix);
  }
  
diff --git a/external/pdfium/0012-svx-import-processed-PDF-text.patch.2 b/external/pdfium/0012-svx-import-processed-PDF-text.patch.2
index 24ec2dfc5349..23629184603f 100644
--- a/external/pdfium/0012-svx-import-processed-PDF-text.patch.2
+++ b/external/pdfium/0012-svx-import-processed-PDF-text.patch.2
@@ -64,10 +64,10 @@ diff --git a/pdfium/fpdfsdk/fpdf_editpage.cpp b/pdfium/fpdfsdk/fpdf_editpage.cpp
 index f4a1688..f34d3b5 100644
 --- a/pdfium/fpdfsdk/fpdf_editpage.cpp
 +++ b/pdfium/fpdfsdk/fpdf_editpage.cpp
-@@ -27,6 +27,7 @@
- #include "core/fpdfapi/parser/cpdf_string.h"
+@@ -28,6 +28,7 @@
  #include "core/fpdfdoc/cpdf_annot.h"
  #include "core/fpdfdoc/cpdf_annotlist.h"
+ #include "core/fpdfapi/page/cpdf_textobject.h"
 +#include "core/fpdftext/cpdf_textpage.h"
  #include "fpdfsdk/cpdfsdk_helpers.h"
  #include "public/fpdf_formfill.h"
diff --git a/external/pdfium/0015-svx-set-the-font-name-of-imported-PDF-text.patch.2 b/external/pdfium/0015-svx-set-the-font-name-of-imported-PDF-text.patch.2
deleted file mode 100644
index 2dce41ae65aa..000000000000
--- a/external/pdfium/0015-svx-set-the-font-name-of-imported-PDF-text.patch.2
+++ /dev/null
@@ -1,77 +0,0 @@
-From 04f9899ddf5f9691ffaca5091082183f167e95d3 Mon Sep 17 00:00:00 2001
-From: Ashod Nakashian <ashod.nakashian at 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
-@@ -20,6 +20,7 @@
- #include "core/fpdfapi/page/cpdf_pageobject.h"
- #include "core/fpdfapi/page/cpdf_pathobject.h"
- #include "core/fpdfapi/page/cpdf_shadingobject.h"
-+#include "core/fpdfapi/page/cpdf_textobject.h"
- #include "core/fpdfapi/parser/cpdf_array.h"
- #include "core/fpdfapi/parser/cpdf_document.h"
- #include "core/fpdfapi/parser/cpdf_number.h"
-@@ -452,6 +453,29 @@ FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object)
-   return pTxtObj->CountChars();
- }
- 
-+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
- FPDFPageObj_SetBlendMode(FPDF_PAGEOBJECT page_object,
-                          FPDF_BYTESTRING blend_mode) {
-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
-@@ -1165,6 +1165,17 @@ FPDFTextObj_GetTextProcessed(FPDF_PAGEOBJECT text_object,
-                              int char_count,
-                              unsigned short* result);
- 
-+// 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 number of characters from a text object.
- //
- // text_object - Handle of text object returned by FPDFPageObj_NewTextObj
--- 
-2.16.3
-
diff --git a/external/pdfium/UnpackedTarball_pdfium.mk b/external/pdfium/UnpackedTarball_pdfium.mk
index 3506a027a0a0..d5295106db4b 100644
--- a/external/pdfium/UnpackedTarball_pdfium.mk
+++ b/external/pdfium/UnpackedTarball_pdfium.mk
@@ -21,13 +21,14 @@ pdfium_patches += 0001-Add-FPDFText_GetTextRenderMode-API.patch.1
 pdfium_patches += 0001-Add-FPDFFormObj_CountObjects-API.patch.1
 # Backport of <https://pdfium-review.googlesource.com/37890>.
 pdfium_patches += 0001-Add-FPDFFormObj_GetObject-API.patch.1
+# Backport of <https://pdfium-review.googlesource.com/38870>.
+pdfium_patches += 0001-Add-FPDFText_GetFontName-API.patch.1
 pdfium_patches += 0002-svx-more-accurate-PDF-text-importing.patch.2
 pdfium_patches += 0003-svx-import-PDF-images-as-BGRA.patch.2
 pdfium_patches += 0004-svx-support-PDF-text-color.patch.2
 pdfium_patches += 0011-svx-correctly-possition-form-objects-from-PDF.patch.2
 pdfium_patches += 0012-svx-import-processed-PDF-text.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))
 
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 8faf9c6649eb..88e157b696fb 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -853,10 +853,11 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
         mbFntDirty = true;
     }
 
-    std::unique_ptr<char[]> pFontName(new char[80 + 1]); // + terminating null
+    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);
-    if (nFontNameChars > 0)
+    int nFontNameChars = FPDFTextObj_GetFontName(pPageObject, pCharFontName, nFontName);
+    if (nFontName >= nFontNameChars)
     {
         OUString sFontName = OUString::createFromAscii(pFontName.get());
         if (sFontName != aFnt.GetFamilyName())


More information about the Libreoffice-commits mailing list