summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstate.cpp31
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstate.h21
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp20
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstatedata.h26
-rw-r--r--core/fpdfapi/fpdf_render/fpdf_render.cpp38
5 files changed, 59 insertions, 77 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
index e4e266785a..c6a5254c0f 100644
--- a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
@@ -22,7 +22,7 @@ void CPDF_ColorState::Emplace() {
}
void CPDF_ColorState::SetDefault() {
- m_Ref.GetPrivateCopy()->Default();
+ m_Ref.GetPrivateCopy()->SetDefault();
}
uint32_t CPDF_ColorState::GetFillRGB() const {
@@ -42,7 +42,7 @@ void CPDF_ColorState::SetStrokeRGB(uint32_t rgb) {
}
const CPDF_Color* CPDF_ColorState::GetFillColor() const {
- const CPDF_ColorStateData* pData = m_Ref.GetObject();
+ const ColorData* pData = m_Ref.GetObject();
return pData ? &pData->m_FillColor : nullptr;
}
@@ -56,7 +56,7 @@ bool CPDF_ColorState::HasFillColor() const {
}
const CPDF_Color* CPDF_ColorState::GetStrokeColor() const {
- const CPDF_ColorStateData* pData = m_Ref.GetObject();
+ const ColorData* pData = m_Ref.GetObject();
return pData ? &pData->m_StrokeColor : nullptr;
}
@@ -72,21 +72,21 @@ bool CPDF_ColorState::HasStrokeColor() const {
void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS,
FX_FLOAT* pValue,
uint32_t nValues) {
- CPDF_ColorStateData* pData = m_Ref.GetPrivateCopy();
+ ColorData* pData = m_Ref.GetPrivateCopy();
SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues);
}
void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS,
FX_FLOAT* pValue,
uint32_t nValues) {
- CPDF_ColorStateData* pData = m_Ref.GetPrivateCopy();
+ ColorData* pData = m_Ref.GetPrivateCopy();
SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues);
}
void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern,
FX_FLOAT* pValue,
uint32_t nValues) {
- CPDF_ColorStateData* pData = m_Ref.GetPrivateCopy();
+ ColorData* pData = m_Ref.GetPrivateCopy();
pData->m_FillColor.SetValue(pPattern, pValue, nValues);
int R, G, B;
FX_BOOL ret = pData->m_FillColor.GetRGB(R, G, B);
@@ -102,7 +102,7 @@ void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern,
void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern,
FX_FLOAT* pValue,
uint32_t nValues) {
- CPDF_ColorStateData* pData = m_Ref.GetPrivateCopy();
+ ColorData* pData = m_Ref.GetPrivateCopy();
pData->m_StrokeColor.SetValue(pPattern, pValue, nValues);
int R, G, B;
FX_BOOL ret = pData->m_StrokeColor.GetRGB(R, G, B);
@@ -135,3 +135,20 @@ void CPDF_ColorState::SetColor(CPDF_Color& color,
int B;
rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1;
}
+
+CPDF_ColorState::ColorData::ColorData() : m_FillRGB(0), m_StrokeRGB(0) {}
+
+CPDF_ColorState::ColorData::ColorData(const ColorData& src)
+ : m_FillRGB(src.m_FillRGB), m_StrokeRGB(src.m_StrokeRGB) {
+ m_FillColor.Copy(&src.m_FillColor);
+ m_StrokeColor.Copy(&src.m_StrokeColor);
+}
+
+CPDF_ColorState::ColorData::~ColorData() {}
+
+void CPDF_ColorState::ColorData::SetDefault() {
+ m_FillRGB = 0;
+ m_StrokeRGB = 0;
+ m_FillColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
+ m_StrokeColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.h b/core/fpdfapi/fpdf_page/cpdf_colorstate.h
index a4077d965f..f6f72a2b46 100644
--- a/core/fpdfapi/fpdf_page/cpdf_colorstate.h
+++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.h
@@ -7,7 +7,7 @@
#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_
#define CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_
-#include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_color.h"
#include "core/fxcrt/include/cfx_count_ref.h"
#include "core/fxcrt/include/fx_basic.h"
#include "core/fxcrt/include/fx_system.h"
@@ -48,19 +48,30 @@ class CPDF_ColorState {
FX_FLOAT* pValue,
uint32_t nValues);
- // TODO(tsepez): Stop leaking ColorStateData outside this class.
- const CPDF_ColorStateData* GetObject() const { return m_Ref.GetObject(); }
-
explicit operator bool() const { return !!m_Ref; }
private:
+ class ColorData {
+ public:
+ ColorData();
+ ColorData(const ColorData& src);
+ ~ColorData();
+
+ void SetDefault();
+
+ uint32_t m_FillRGB;
+ uint32_t m_StrokeRGB;
+ CPDF_Color m_FillColor;
+ CPDF_Color m_StrokeColor;
+ };
+
void SetColor(CPDF_Color& color,
uint32_t& rgb,
CPDF_ColorSpace* pCS,
FX_FLOAT* pValue,
uint32_t nValues);
- CFX_CountRef<CPDF_ColorStateData> m_Ref;
+ CFX_CountRef<ColorData> m_Ref;
};
#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp
deleted file mode 100644
index 9dbcdec267..0000000000
--- a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h"
-
-CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) {
- m_FillColor.Copy(&src.m_FillColor);
- m_FillRGB = src.m_FillRGB;
- m_StrokeColor.Copy(&src.m_StrokeColor);
- m_StrokeRGB = src.m_StrokeRGB;
-}
-
-void CPDF_ColorStateData::Default() {
- m_FillRGB = m_StrokeRGB = 0;
- m_FillColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
- m_StrokeColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
-}
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h
deleted file mode 100644
index 6a992ad0b1..0000000000
--- a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_
-#define CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_
-
-#include "core/fpdfapi/fpdf_page/include/cpdf_color.h"
-#include "core/fxcrt/include/fx_system.h"
-
-class CPDF_ColorStateData {
- public:
- CPDF_ColorStateData() : m_FillRGB(0), m_StrokeRGB(0) {}
- CPDF_ColorStateData(const CPDF_ColorStateData& src);
-
- void Default();
-
- CPDF_Color m_FillColor;
- uint32_t m_FillRGB;
- CPDF_Color m_StrokeColor;
- uint32_t m_StrokeRGB;
-};
-
-#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_
diff --git a/core/fpdfapi/fpdf_render/fpdf_render.cpp b/core/fpdfapi/fpdf_render/fpdf_render.cpp
index 27c9fa9bd2..d7c6e2f604 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render.cpp
@@ -10,7 +10,6 @@
#include "core/fpdfapi/fpdf_font/cpdf_type3char.h"
#include "core/fpdfapi/fpdf_font/cpdf_type3font.h"
-#include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h"
#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h"
@@ -510,20 +509,20 @@ CPDF_TransferFunc* CPDF_RenderStatus::GetTransferFunc(CPDF_Object* pObj) const {
FX_ARGB CPDF_RenderStatus::GetFillArgb(CPDF_PageObject* pObj,
FX_BOOL bType3) const {
- const CPDF_ColorStateData* pColorData = pObj->m_ColorState.GetObject();
+ const CPDF_ColorState* pColorState = &pObj->m_ColorState;
if (m_pType3Char && !bType3 &&
(!m_pType3Char->m_bColored ||
(m_pType3Char->m_bColored &&
- (!pColorData || pColorData->m_FillColor.IsNull())))) {
+ (!*pColorState || pColorState->GetFillColor()->IsNull())))) {
return m_T3FillColor;
}
- if (!pColorData || pColorData->m_FillColor.IsNull()) {
- pColorData = m_InitialStates.m_ColorState.GetObject();
- }
- FX_COLORREF rgb = pColorData->m_FillRGB;
- if (rgb == (uint32_t)-1) {
+ if (!*pColorState || pColorState->GetFillColor()->IsNull())
+ pColorState = &m_InitialStates.m_ColorState;
+
+ FX_COLORREF rgb = pColorState->GetFillRGB();
+ if (rgb == (uint32_t)-1)
return 0;
- }
+
int32_t alpha =
static_cast<int32_t>((pObj->m_GeneralState.GetFillAlpha() * 255));
if (pObj->m_GeneralState.GetTR()) {
@@ -538,19 +537,20 @@ FX_ARGB CPDF_RenderStatus::GetFillArgb(CPDF_PageObject* pObj,
}
FX_ARGB CPDF_RenderStatus::GetStrokeArgb(CPDF_PageObject* pObj) const {
- const CPDF_ColorStateData* pColorData = pObj->m_ColorState.GetObject();
- if (m_pType3Char && (!m_pType3Char->m_bColored ||
- (m_pType3Char->m_bColored &&
- (!pColorData || pColorData->m_StrokeColor.IsNull())))) {
+ const CPDF_ColorState* pColorState = &pObj->m_ColorState;
+ if (m_pType3Char &&
+ (!m_pType3Char->m_bColored ||
+ (m_pType3Char->m_bColored &&
+ (!*pColorState || pColorState->GetStrokeColor()->IsNull())))) {
return m_T3FillColor;
}
- if (!pColorData || pColorData->m_StrokeColor.IsNull()) {
- pColorData = m_InitialStates.m_ColorState.GetObject();
- }
- FX_COLORREF rgb = pColorData->m_StrokeRGB;
- if (rgb == (uint32_t)-1) {
+ if (!*pColorState || pColorState->GetStrokeColor()->IsNull())
+ pColorState = &m_InitialStates.m_ColorState;
+
+ FX_COLORREF rgb = pColorState->GetStrokeRGB();
+ if (rgb == (uint32_t)-1)
return 0;
- }
+
int32_t alpha = static_cast<int32_t>(pObj->m_GeneralState.GetStrokeAlpha() *
255); // not rounded.
if (pObj->m_GeneralState.GetTR()) {