summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_page
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/fpdf_page')
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstate.cpp105
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstate.h36
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp3
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp18
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp2
5 files changed, 121 insertions, 43 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
index a2234378eb..e4e266785a 100644
--- a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
@@ -10,42 +10,83 @@
#include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h"
#include "core/fxge/include/fx_dib.h"
+CPDF_ColorState::CPDF_ColorState() {}
+
+CPDF_ColorState::CPDF_ColorState(const CPDF_ColorState& that)
+ : m_Ref(that.m_Ref) {}
+
+CPDF_ColorState::~CPDF_ColorState() {}
+
+void CPDF_ColorState::Emplace() {
+ m_Ref.Emplace();
+}
+
+void CPDF_ColorState::SetDefault() {
+ m_Ref.GetPrivateCopy()->Default();
+}
+
+uint32_t CPDF_ColorState::GetFillRGB() const {
+ return m_Ref.GetObject()->m_FillRGB;
+}
+
+void CPDF_ColorState::SetFillRGB(uint32_t rgb) {
+ m_Ref.GetPrivateCopy()->m_FillRGB = rgb;
+}
+
+uint32_t CPDF_ColorState::GetStrokeRGB() const {
+ return m_Ref.GetObject()->m_StrokeRGB;
+}
+
+void CPDF_ColorState::SetStrokeRGB(uint32_t rgb) {
+ m_Ref.GetPrivateCopy()->m_StrokeRGB = rgb;
+}
+
+const CPDF_Color* CPDF_ColorState::GetFillColor() const {
+ const CPDF_ColorStateData* pData = m_Ref.GetObject();
+ return pData ? &pData->m_FillColor : nullptr;
+}
+
+CPDF_Color* CPDF_ColorState::GetMutableFillColor() {
+ return &m_Ref.GetPrivateCopy()->m_FillColor;
+}
+
+bool CPDF_ColorState::HasFillColor() const {
+ const CPDF_Color* pColor = GetFillColor();
+ return pColor && !pColor->IsNull();
+}
+
+const CPDF_Color* CPDF_ColorState::GetStrokeColor() const {
+ const CPDF_ColorStateData* pData = m_Ref.GetObject();
+ return pData ? &pData->m_StrokeColor : nullptr;
+}
+
+CPDF_Color* CPDF_ColorState::GetMutableStrokeColor() {
+ return &m_Ref.GetPrivateCopy()->m_StrokeColor;
+}
+
+bool CPDF_ColorState::HasStrokeColor() const {
+ const CPDF_Color* pColor = GetStrokeColor();
+ return pColor && !pColor->IsNull();
+}
+
void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS,
FX_FLOAT* pValue,
uint32_t nValues) {
- CPDF_ColorStateData* pData = GetPrivateCopy();
+ CPDF_ColorStateData* 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 = GetPrivateCopy();
+ CPDF_ColorStateData* pData = m_Ref.GetPrivateCopy();
SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues);
}
-void CPDF_ColorState::SetColor(CPDF_Color& color,
- uint32_t& rgb,
- CPDF_ColorSpace* pCS,
- FX_FLOAT* pValue,
- uint32_t nValues) {
- if (pCS) {
- color.SetColorSpace(pCS);
- } else if (color.IsNull()) {
- color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
- }
- if (color.GetColorSpace()->CountComponents() > nValues)
- return;
-
- color.SetValue(pValue);
- int R, G, B;
- rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1;
-}
-
void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern,
FX_FLOAT* pValue,
uint32_t nValues) {
- CPDF_ColorStateData* pData = GetPrivateCopy();
+ CPDF_ColorStateData* 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);
@@ -61,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 = GetPrivateCopy();
+ CPDF_ColorStateData* 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);
@@ -74,3 +115,23 @@ void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern,
pData->m_StrokeRGB =
pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1;
}
+
+void CPDF_ColorState::SetColor(CPDF_Color& color,
+ uint32_t& rgb,
+ CPDF_ColorSpace* pCS,
+ FX_FLOAT* pValue,
+ uint32_t nValues) {
+ if (pCS)
+ color.SetColorSpace(pCS);
+ else if (color.IsNull())
+ color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
+
+ if (color.GetColorSpace()->CountComponents() > nValues)
+ return;
+
+ color.SetValue(pValue);
+ int R;
+ int G;
+ int B;
+ rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1;
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.h b/core/fpdfapi/fpdf_page/cpdf_colorstate.h
index 128d67558d..d928dbdb2e 100644
--- a/core/fpdfapi/fpdf_page/cpdf_colorstate.h
+++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.h
@@ -16,17 +16,28 @@ class CPDF_Color;
class CPDF_ColorSpace;
class CPDF_Pattern;
-class CPDF_ColorState : public CFX_CountRef<CPDF_ColorStateData> {
+class CPDF_ColorState {
public:
- const CPDF_Color* GetFillColor() const {
- const CPDF_ColorStateData* pData = GetObject();
- return pData ? &pData->m_FillColor : nullptr;
- }
+ CPDF_ColorState();
+ CPDF_ColorState(const CPDF_ColorState& that);
+ ~CPDF_ColorState();
- const CPDF_Color* GetStrokeColor() const {
- const CPDF_ColorStateData* pData = GetObject();
- return pData ? &pData->m_StrokeColor : nullptr;
- }
+ void Emplace();
+ void SetDefault();
+
+ uint32_t GetFillRGB() const;
+ void SetFillRGB(uint32_t rgb);
+
+ uint32_t GetStrokeRGB() const;
+ void SetStrokeRGB(uint32_t rgb);
+
+ const CPDF_Color* GetFillColor() const;
+ CPDF_Color* GetMutableFillColor();
+ bool HasFillColor() const;
+
+ const CPDF_Color* GetStrokeColor() const;
+ CPDF_Color* GetMutableStrokeColor();
+ bool HasStrokeColor() const;
void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, uint32_t nValues);
void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, uint32_t nValues);
@@ -37,12 +48,19 @@ class CPDF_ColorState : public CFX_CountRef<CPDF_ColorStateData> {
FX_FLOAT* pValue,
uint32_t nValues);
+ // TODO(tsepez): Stop leaking ColorStateData outside this class.
+ const CPDF_ColorStateData* GetObject() const { return m_Ref.GetObject(); }
+
+ operator bool() const { return !!m_Ref; }
+
private:
void SetColor(CPDF_Color& color,
uint32_t& rgb,
CPDF_ColorSpace* pCS,
FX_FLOAT* pValue,
uint32_t nValues);
+
+ CFX_CountRef<CPDF_ColorStateData> m_Ref;
};
#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp
index e411b53a51..42f26c1135 100644
--- a/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp
@@ -11,7 +11,8 @@ CPDF_GraphicStates::CPDF_GraphicStates() {}
CPDF_GraphicStates::~CPDF_GraphicStates() {}
void CPDF_GraphicStates::DefaultStates() {
- m_ColorState.Emplace()->Default();
+ m_ColorState.Emplace();
+ m_ColorState.SetDefault();
}
void CPDF_GraphicStates::CopyStates(const CPDF_GraphicStates& src) {
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index 70e1d1aea6..5272a4464b 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -686,21 +686,19 @@ void CPDF_StreamContentParser::Handle_ConcatMatrix() {
}
void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() {
- CFX_ByteString csname = GetString(0);
- CPDF_ColorSpace* pCS = FindColorSpace(csname);
- if (!pCS) {
+ CPDF_ColorSpace* pCS = FindColorSpace(GetString(0));
+ if (!pCS)
return;
- }
- m_pCurStates->m_ColorState.GetPrivateCopy()->m_FillColor.SetColorSpace(pCS);
+
+ m_pCurStates->m_ColorState.GetMutableFillColor()->SetColorSpace(pCS);
}
void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() {
- CFX_ByteString csname = GetString(0);
- CPDF_ColorSpace* pCS = FindColorSpace(csname);
- if (!pCS) {
+ CPDF_ColorSpace* pCS = FindColorSpace(GetString(0));
+ if (!pCS)
return;
- }
- m_pCurStates->m_ColorState.GetPrivateCopy()->m_StrokeColor.SetColorSpace(pCS);
+
+ m_pCurStates->m_ColorState.GetMutableStrokeColor()->SetColorSpace(pCS);
}
void CPDF_StreamContentParser::Handle_SetDash() {
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index e261ce5bb5..92a9d6c92e 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -774,7 +774,7 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) {
m_pObjectHolder->m_pDocument, m_pObjectHolder->m_pPageResources,
nullptr, nullptr, m_pObjectHolder, m_pObjectHolder->m_pResources,
&m_pObjectHolder->m_BBox, nullptr, 0));
- m_pParser->GetCurStates()->m_ColorState.GetPrivateCopy()->Default();
+ m_pParser->GetCurStates()->m_ColorState.SetDefault();
}
if (m_CurrentOffset >= m_Size) {
m_InternalStage = STAGE_CHECKCLIP;