summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-04-15 10:51:39 -0400
committerJan Holesovsky <kendy@collabora.com>2018-05-22 12:17:16 +0200
commit26e37f98b08ce59a0feb93a8d2a8fbc982cfc103 (patch)
treec09e934e16eea88b96c6fd00d8cacebe8d1eee56
parentd583d4635f165a788c12ef336a25377239049253 (diff)
svx: support color text for imported PDFs
Change-Id: I01cba9456b37bd7a63c823bbe332d686f7ede389
-rw-r--r--external/pdfium/edit.patch.1134
-rw-r--r--svx/source/svdraw/svdpdf.cxx44
2 files changed, 138 insertions, 40 deletions
diff --git a/external/pdfium/edit.patch.1 b/external/pdfium/edit.patch.1
index 96e0fa4f9725..02e0b44c3e87 100644
--- a/external/pdfium/edit.patch.1
+++ b/external/pdfium/edit.patch.1
@@ -1,12 +1,73 @@
+diff --git a/core/fpdfapi/page/cpdf_colorstate.cpp b/core/fpdfapi/page/cpdf_colorstate.cpp
+index 693fcf1..d3e1202 100644
+--- a/core/fpdfapi/page/cpdf_colorstate.cpp
++++ b/core/fpdfapi/page/cpdf_colorstate.cpp
+@@ -74,6 +74,8 @@ void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS,
+ uint32_t nValues) {
+ ColorData* pData = m_Ref.GetPrivateCopy();
+ SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues);
++ if (pData->m_FillRGB != 0 && pData->m_FillRGB != 0xFFFFFFFF)
++ fprintf(stderr, "COLOR FILL!!!!> %x\n", pData->m_FillRGB);
+ }
+
+ void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS,
+@@ -81,6 +83,8 @@ void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS,
+ uint32_t nValues) {
+ ColorData* pData = m_Ref.GetPrivateCopy();
+ SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues);
++ if (pData->m_StrokeRGB != 0 && pData->m_StrokeRGB != 0xFFFFFFFF)
++ fprintf(stderr, "COLOR STROkE!!!!> %x\n", pData->m_StrokeRGB);
+ }
+
+ void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern,
+@@ -99,6 +103,8 @@ void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern,
+ }
+ }
+ pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : 0xFFFFFFFF;
++ if (pData->m_FillRGB != 0 && pData->m_FillRGB != 0xFFFFFFFF)
++ fprintf(stderr, "COLOR FILL!!!!> %x\n", pData->m_FillRGB);
+ }
+
+ void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern,
+@@ -118,13 +124,15 @@ void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern,
+ }
+ pData->m_StrokeRGB =
+ pData->m_StrokeColor.GetRGB(&R, &G, &B) ? FXSYS_RGB(R, G, B) : 0xFFFFFFFF;
++ if (pData->m_StrokeRGB != 0 && pData->m_StrokeRGB != 0xFFFFFFFF)
++ fprintf(stderr, "COLOR STROkE!!!!> %x\n", pData->m_StrokeRGB);
+ }
+
+ void CPDF_ColorState::SetColor(CPDF_Color& color,
+ uint32_t& rgb,
+ CPDF_ColorSpace* pCS,
+ float* pValue,
+- uint32_t nValues) {
++ uint32_t nValues) const {
+ if (pCS)
+ color.SetColorSpace(pCS);
+ else if (color.IsNull())
+diff --git a/core/fpdfapi/page/cpdf_colorstate.h b/core/fpdfapi/page/cpdf_colorstate.h
+index 9619051..dbe9c47 100644
+--- a/core/fpdfapi/page/cpdf_colorstate.h
++++ b/core/fpdfapi/page/cpdf_colorstate.h
+@@ -64,7 +64,7 @@ class CPDF_ColorState {
+ uint32_t& rgb,
+ CPDF_ColorSpace* pCS,
+ float* pValue,
+- uint32_t nValues);
++ uint32_t nValues) const;
+
+ SharedCopyOnWrite<ColorData> m_Ref;
+ };
diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp
-index 3b5a740..58ef90a 100644
+index 3b5a740..416d82d 100644
--- a/core/fpdfapi/page/cpdf_imageobject.cpp
+++ b/core/fpdfapi/page/cpdf_imageobject.cpp
@@ -43,6 +43,7 @@ const CPDF_ImageObject* CPDF_ImageObject::AsImage() const {
void CPDF_ImageObject::CalcBoundingBox() {
std::tie(m_Left, m_Right, m_Top, m_Bottom) =
m_Matrix.TransformRect(0.f, 1.f, 1.f, 0.f);
-+ fprintf(stderr, "Image BB: %f, %f, %f, %f\n", m_Left, m_Right, m_Top, m_Bottom);
++ // fprintf(stderr, "Image BB: %f, %f, %f, %f\n", m_Left, m_Right, m_Top, m_Bottom);
}
void CPDF_ImageObject::SetImage(const RetainPtr<CPDF_Image>& pImage) {
@@ -62,14 +123,14 @@ index 0a01ae0..6947e3a 100644
DrawTextPathWithPattern(textobj, pObj2Device, pFont, font_size,
&text_matrix, bFill, bStroke);
diff --git a/core/fxge/cfx_pathdata.cpp b/core/fxge/cfx_pathdata.cpp
-index 4ac5cf6..28ea81f 100644
+index 4ac5cf6..4286de4 100644
--- a/core/fxge/cfx_pathdata.cpp
+++ b/core/fxge/cfx_pathdata.cpp
@@ -199,6 +199,7 @@ void CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_Matrix* pMatrix) {
void CFX_PathData::AppendPoint(const CFX_PointF& point,
FXPT_TYPE type,
bool closeFigure) {
-+ fprintf(stderr, "Append: %f, %f (%s)\n", point.x, point.y, closeFigure ? "CLOSE" : "OPEN");
++// fprintf(stderr, "Append: %f, %f (%s)\n", point.x, point.y, closeFigure ? "CLOSE" : "OPEN");
m_Points.push_back(FX_PATHPOINT(point, type, closeFigure));
}
@@ -77,7 +138,7 @@ index 4ac5cf6..28ea81f 100644
void CFX_PathData::Transform(const CFX_Matrix* pMatrix) {
if (!pMatrix)
return;
-+ fprintf(stderr, "XForm: %f, %f %f, %f, %f, %f\n", pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, pMatrix->e, pMatrix->f);
++// fprintf(stderr, "XForm: %f, %f %f, %f, %f, %f\n", pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, pMatrix->e, pMatrix->f);
for (auto& point : m_Points)
point.m_Point = pMatrix->Transform(point.m_Point);
}
@@ -113,7 +174,7 @@ index 0d7ba56..37bdf99 100644
FPDFImageObj_GetImageDataDecoded(FPDF_PAGEOBJECT image_object,
void* buffer,
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
-index ca2cf3f..e7d633f 100644
+index ca2cf3f..f86201d 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -11,12 +11,14 @@
@@ -131,7 +192,7 @@ index ca2cf3f..e7d633f 100644
#include "core/fpdfapi/page/cpdf_shadingobject.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
-@@ -363,3 +365,128 @@ FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject,
+@@ -363,3 +365,157 @@ FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject,
*top = bbox.top;
return true;
}
@@ -242,22 +303,51 @@ index ca2cf3f..e7d633f 100644
+}
+
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
-+FPDFTextObj_GetStrokeColor(FPDF_PAGEOBJECT text_object,
-+ unsigned int* R,
-+ unsigned int* G,
-+ unsigned int* B,
-+ unsigned int* A)
++FPDFTextObj_GetColor(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);
++ bool bFill = false;
++ bool bStroke = false;
++ CPDF_Font* pFont = pTxtObj->m_TextState.GetFont();
++ const TextRenderingMode text_render_mode = pTxtObj->m_TextState.GetTextMode();
++ switch (text_render_mode)
++ {
++ case TextRenderingMode::MODE_FILL:
++ case TextRenderingMode::MODE_FILL_CLIP:
++ bFill = true;
++ break;
++ case TextRenderingMode::MODE_STROKE:
++ case TextRenderingMode::MODE_STROKE_CLIP:
++ if (pFont->GetFace())
++ bStroke = true;
++ else
++ bFill = true;
++ break;
++ case TextRenderingMode::MODE_FILL_STROKE:
++ case TextRenderingMode::MODE_FILL_STROKE_CLIP:
++ bFill = true;
++ if (pFont->GetFace())
++ bStroke = true;
++ break;
++ case TextRenderingMode::MODE_INVISIBLE:
++ case TextRenderingMode::MODE_CLIP:
++ return false;
++ }
++
++ const uint32_t RGB = bStroke ? pTxtObj->m_ColorState.GetStrokeRGB() : pTxtObj->m_ColorState.GetFillRGB();
++ *R = FXSYS_GetRValue(RGB);
++ *G = FXSYS_GetGValue(RGB);
++ *B = FXSYS_GetBValue(RGB);
+ *A = static_cast<unsigned int>(
+ (pTxtObj->m_GeneralState.GetStrokeAlpha() * 255.f) + 0.5f);
++
+ return true;
+}
diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
@@ -409,7 +499,7 @@ index 77c2315..db3e734 100644
CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
-index 54735a3..c86b638 100644
+index 54735a3..c0231c2 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -520,6 +520,15 @@ FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path,
@@ -534,11 +624,11 @@ index 54735a3..c86b638 100644
+//
+// 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);
++FPDFTextObj_GetColor(FPDF_PAGEOBJECT text_object,
++ unsigned int* R,
++ unsigned int* G,
++ unsigned int* B,
++ unsigned int* A);
+
#ifdef __cplusplus
} // extern "C"
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 32672d7223e1..f0674ca9a694 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1030,7 +1030,7 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
return;
}
- const tools::Rectangle aRect = PointsToLogic(left, right, top, bottom);
+ const Rectangle aRect = PointsToLogic(left, right, top, bottom);
const int nChars = FPDFTextObj_CountChars(pPageObject);
std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nChars + 1]); // + terminating null
@@ -1066,13 +1066,25 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
dFontSizeV = lcl_ToLogic(dFontSizeV);
SAL_WARN("sd.filter", "Got Logic Font Size H: " << dFontSizeH << ", V: " << dFontSizeV);
+ const Size aFontSize(dFontSizeH, dFontSizeV);
+ vcl::Font aFnt = mpVD->GetFont();
+ if (aFontSize != aFnt.GetFontSize())
+ {
+ aFnt.SetFontSize(aFontSize);
+ mpVD->SetFont(aFnt);
+ mbFntDirty = true;
+ }
+
+ Color aTextColor(COL_TRANSPARENT);
unsigned int nR, nG, nB, nA;
- if (FPDFTextObj_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA))
- mpVD->SetTextColor(Color(nR, nG, nB));
+ if (FPDFTextObj_GetColor(pPageObject, &nR, &nG, &nB, &nA))
+ aTextColor = Color(nR, nG, nB);
- vcl::Font aFnt = mpVD->GetFont();
- aFnt.SetFontSize(Size(dFontSizeH, dFontSizeV));
- mpVD->SetFont(aFnt);
+ if (aTextColor != mpVD->GetTextColor())
+ {
+ mpVD->SetTextColor(aTextColor);
+ mbFntDirty = true;
+ }
ImportText(aRect.TopLeft(), aRect.GetSize(), sText);
}
@@ -1375,14 +1387,14 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
Point ImpSdrPdfImport::PointsToLogic(double x, double y) const
{
y = correctVertOrigin(y);
- SAL_WARN("sd.filter", "Corrected point x: " << x << ", y: " << y);
+ // SAL_WARN("sd.filter", "Corrected point x: " << x << ", y: " << y);
x = lcl_PointToPixel(x);
y = lcl_PointToPixel(y);
- SAL_WARN("sd.filter", "Pixel point x: " << x << ", y: " << y);
+ // SAL_WARN("sd.filter", "Pixel point x: " << x << ", y: " << y);
Point aPos(lcl_ToLogic(x), lcl_ToLogic(y));
- SAL_WARN("sd.filter", "Logical Pos: " << aPos);
+ // SAL_WARN("sd.filter", "Logical Pos: " << aPos);
return aPos;
}
@@ -1392,24 +1404,20 @@ Rectangle ImpSdrPdfImport::PointsToLogic(double left, double right, double top,
{
top = correctVertOrigin(top);
bottom = correctVertOrigin(bottom);
- SAL_WARN("sd.filter", "Corrected bounds left: " << left << ", right: " << right
- << ", top: " << top << ", bottom: " << bottom);
+ // SAL_WARN("sd.filter", "Corrected bounds left: " << left << ", right: " << right
+ // << ", top: " << top << ", bottom: " << bottom);
left = lcl_PointToPixel(left);
right = lcl_PointToPixel(right);
top = lcl_PointToPixel(top);
bottom = lcl_PointToPixel(bottom);
- // if (top > bottom)
- // std::swap(top, bottom);
- // if (left > right)
- // std::swap(left, right);
- SAL_WARN("sd.filter", "Pixel bounds left: " << left << ", right: " << right << ", top: " << top
- << ", bottom: " << bottom);
+ // SAL_WARN("sd.filter", "Pixel bounds left: " << left << ", right: " << right << ", top: " << top
+ // << ", bottom: " << bottom);
Point aPos(lcl_ToLogic(left), lcl_ToLogic(top));
Size aSize(lcl_ToLogic(right - left), lcl_ToLogic(bottom - top));
Rectangle aRect(aPos, aSize);
- SAL_WARN("sd.filter", "Logical BBox: " << aRect);
+ // SAL_WARN("sd.filter", "Logical BBox: " << aRect);
return aRect;
}