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

svx: support PDF text color

Change-Id: I7fa675c6560504e4fc7917e19cac3cceb2700d8e
(cherry picked from commit 3c02b52f)
üst a16dba9b
From 914467a56b9c4cd6a27cfa9b7ed61ebfb5a122d3 Mon Sep 17 00:00:00 2001
From: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Date: Tue, 5 Jun 2018 11:29:49 +0200
Subject: [PATCH 04/14] svx: support PDF text color
---
pdfium/fpdfsdk/cpdfsdk_helpers.h | 5 +++++
pdfium/fpdfsdk/fpdf_editpage.cpp | 30 +++++++++++++++++++++++++-----
pdfium/public/fpdf_edit.h | 16 ++++++++++++++++
3 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/pdfium/fpdfsdk/cpdfsdk_helpers.h b/pdfium/fpdfsdk/cpdfsdk_helpers.h
index d93ecfc..13362cf 100644
--- a/pdfium/fpdfsdk/cpdfsdk_helpers.h
+++ b/pdfium/fpdfsdk/cpdfsdk_helpers.h
@@ -204,6 +204,11 @@ inline CPDF_TextPageFind* CPDFTextPageFindFromFPDFSchHandle(
return reinterpret_cast<CPDF_TextPageFind*>(handle);
}
+inline CPDF_TextObject* CPDFTextObjectFromFPDFPageObject(
+ FPDF_PAGEOBJECT page_object) {
+ return reinterpret_cast<CPDF_TextObject*>(page_object);
+}
+
ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string);
#ifdef PDF_ENABLE_XFA
diff --git a/pdfium/fpdfsdk/fpdf_editpage.cpp b/pdfium/fpdfsdk/fpdf_editpage.cpp
index 3244943..f8e2418 100644
--- a/pdfium/fpdfsdk/fpdf_editpage.cpp
+++ b/pdfium/fpdfsdk/fpdf_editpage.cpp
@@ -633,7 +633,7 @@ FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object)
if (!text_object)
return 0;
- CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
return pTxtObj->CountChars();
}
@@ -643,7 +643,7 @@ FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text_object)
if (!text_object)
return 0;
- CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
return pTxtObj->GetFontSize();
}
@@ -656,7 +656,7 @@ FPDFTextObj_GetMatrix(FPDF_PAGEOBJECT text_object,
if (!text_object)
return;
- CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
const CFX_Matrix& matrix = pTxtObj->GetTextMatrix();
*a = matrix.a;
*b = matrix.b;
@@ -670,7 +670,7 @@ FPDFTextObj_GetUnicode(FPDF_PAGEOBJECT text_object, int index)
if (!text_object || index < 0)
return 0;
- CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
if (index > pTxtObj->CountChars())
return 0;
@@ -686,7 +686,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object,
if (!text_object || char_start < 0 || char_count < 0 || !result)
return 0;
- CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
int char_available = pTxtObj->CountChars() - char_start;
if (char_available <= 0)
return 0;
@@ -726,3 +726,23 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object,
memcpy(result, byte_str.GetBuffer(byte_str_len), byte_str_len);
return ret_count;
}
+
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFTextObj_GetStrokeColor(FPDF_PAGEOBJECT text_object,
+ unsigned int* R,
+ unsigned int* G,
+ unsigned int* B,
+ unsigned int* A)
+{
+ CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
+ if (!pTxtObj || !R || !G || !B || !A)
+ return false;
+
+ const uint32_t strokeRGB = pTxtObj->m_ColorState.GetStrokeRGB();
+ *R = FXSYS_GetRValue(strokeRGB);
+ *G = FXSYS_GetGValue(strokeRGB);
+ *B = FXSYS_GetBValue(strokeRGB);
+ *A = static_cast<unsigned int>(
+ (pTxtObj->m_GeneralState.GetStrokeAlpha() * 255.f) + 0.5f);
+ return true;
+}
diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
index 602849f..fa9902e 100644
--- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h
@@ -1022,6 +1022,22 @@ FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object,
int char_count,
unsigned short* result);
+// Get the stroke RGBA of a text. Range of values: 0 - 255.
+//
+// path - the handle to the path object.
+// R - the red component of the path stroke color.
+// G - the green component of the path stroke color.
+// B - the blue component of the path stroke color.
+// A - the stroke alpha of the path.
+//
+// Returns TRUE on success.
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFTextObj_GetStrokeColor(FPDF_PAGEOBJECT text_object,
+ unsigned int* R,
+ unsigned int* G,
+ unsigned int* B,
+ unsigned int* A);
+
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
--
2.16.3
......@@ -17,6 +17,7 @@ pdfium_patches += build.patch.1
pdfium_patches += 0001-svx-import-PDF-text-using-PDFium.patch.2
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
$(eval $(call gb_UnpackedTarball_UnpackedTarball,pdfium))
......
......@@ -229,8 +229,6 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
if (pPageObject == nullptr)
continue;
SAL_WARN("sd.filter", "Got page object number: ");
const int nPageObjectType = FPDFPageObj_GetType(pPageObject);
switch (nPageObjectType)
{
......@@ -1051,6 +1049,11 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
SAL_WARN("sd.filter", "Got Font Pixel Size: " << dFontSize);
dFontSize = lcl_ToLogic(dFontSize);
SAL_WARN("sd.filter", "Got Font Logic Size: " << dFontSize);
unsigned int nR, nG, nB, nA;
if (FPDFTextObj_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA))
mpVD->SetTextColor(Color(nR, nG, nB));
vcl::Font aFnt = mpVD->GetFont();
aFnt.SetFontSize(Size(dFontSize, dFontSize));
mpVD->SetFont(aFnt);
......
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