diff options
author | thestig <thestig@chromium.org> | 2016-05-11 12:59:16 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-11 12:59:17 -0700 |
commit | a244dfe2ba2cc82ee264475253cc16222e022524 (patch) | |
tree | 3a69928e3c60c5c6f91813aa07518b1af481754b /core/fpdfapi | |
parent | 35c2100a5f6a466635bf99b4e7117d23aeb54d2c (diff) | |
download | pdfium-a244dfe2ba2cc82ee264475253cc16222e022524.tar.xz |
Clean up CPDF_Color and some related code.
- Remove dead code in CPDF_Color.
- Encapsulate member variables.
- Added accessors as need.
- Remove unused CPDF_ColorSpace::GetMaxIndex().
- Remove redundent CPDF_StreamContentParser::GetNumber16().
Review-Url: https://codereview.chromium.org/1965243002
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_color.cpp | 38 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_colorspace.cpp | 8 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_colorstate.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 14 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_color.h | 16 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_colorspace.h | 1 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/pageint.h | 1 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 4 |
8 files changed, 19 insertions, 67 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_color.cpp b/core/fpdfapi/fpdf_page/cpdf_color.cpp index 5536f71f9f..e6fe3e88e9 100644 --- a/core/fpdfapi/fpdf_page/cpdf_color.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_color.cpp @@ -11,24 +11,17 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fxcrt/include/fx_system.h" -CPDF_Color::CPDF_Color(int family) { - m_pCS = CPDF_ColorSpace::GetStockCS(family); - int nComps = 3; - if (family == PDFCS_DEVICEGRAY) - nComps = 1; - else if (family == PDFCS_DEVICECMYK) - nComps = 4; - - m_pBuffer = FX_Alloc(FX_FLOAT, nComps); - for (int i = 0; i < nComps; i++) - m_pBuffer[i] = 0; -} +CPDF_Color::CPDF_Color() : m_pCS(nullptr), m_pBuffer(nullptr) {} CPDF_Color::~CPDF_Color() { ReleaseBuffer(); ReleaseColorSpace(); } +bool CPDF_Color::IsPattern() const { + return m_pCS && m_pCS->GetFamily() == PDFCS_PATTERN; +} + void CPDF_Color::ReleaseBuffer() { if (!m_pBuffer) return; @@ -84,7 +77,7 @@ void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) { if (ncomps > MAX_PATTERN_COLORCOMPS) return; - if (!m_pCS || m_pCS->GetFamily() != PDFCS_PATTERN) { + if (!IsPattern()) { FX_Free(m_pBuffer); m_pCS = CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN); m_pBuffer = m_pCS->CreateBuf(); @@ -159,22 +152,3 @@ CPDF_Pattern* CPDF_Color::GetPattern() const { PatternValue* pvalue = (PatternValue*)m_pBuffer; return pvalue->m_pPattern; } - -CPDF_ColorSpace* CPDF_Color::GetPatternCS() const { - if (!m_pBuffer || m_pCS->GetFamily() != PDFCS_PATTERN) - return nullptr; - return m_pCS->GetBaseCS(); -} - -FX_FLOAT* CPDF_Color::GetPatternColor() const { - if (!m_pBuffer || m_pCS->GetFamily() != PDFCS_PATTERN) - return nullptr; - - PatternValue* pvalue = (PatternValue*)m_pBuffer; - return pvalue->m_nComps ? pvalue->m_Comps : nullptr; -} - -FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const { - return m_pCS && m_pCS == other.m_pCS && - FXSYS_memcmp(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0; -} diff --git a/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp b/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp index 48fdc1c914..77e8c00d20 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp @@ -473,14 +473,6 @@ void CPDF_ColorSpace::GetDefaultColor(FX_FLOAT* buf) const { } } -int CPDF_ColorSpace::GetMaxIndex() const { - if (m_Family != PDFCS_INDEXED) { - return 0; - } - CPDF_IndexedCS* pCS = (CPDF_IndexedCS*)this; - return pCS->m_MaxIndex; -} - void CPDF_ColorSpace::TranslateImageLine(uint8_t* dest_buf, const uint8_t* src_buf, int pixels, diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp index 88e9f561c3..1d422cb061 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp @@ -34,9 +34,9 @@ void CPDF_ColorState::SetColor(CPDF_Color& color, } else if (color.IsNull()) { color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); } - if (color.m_pCS->CountComponents() > nValues) { + 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; diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 7ed485c87c..a13fb5021d 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -386,10 +386,6 @@ FX_FLOAT CPDF_StreamContentParser::GetNumber(uint32_t index) { return 0; } -FX_FLOAT CPDF_StreamContentParser::GetNumber16(uint32_t index) { - return GetNumber(index); -} - void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj, FX_BOOL bColor, FX_BOOL bText, @@ -675,10 +671,8 @@ void CPDF_StreamContentParser::Handle_CurveTo_123() { } void CPDF_StreamContentParser::Handle_ConcatMatrix() { - FX_FLOAT a2 = GetNumber16(5), b2 = GetNumber16(4), c2 = GetNumber16(3), - d2 = GetNumber16(2); - FX_FLOAT e2 = GetNumber(1), f2 = GetNumber(0); - CFX_Matrix new_matrix(a2, b2, c2, d2, e2, f2); + CFX_Matrix new_matrix(GetNumber(5), GetNumber(4), GetNumber(3), GetNumber(2), + GetNumber(1), GetNumber(0)); new_matrix.Concat(m_pCurStates->m_CTM); m_pCurStates->m_CTM = new_matrix; OnChangeTextMatrix(); @@ -1366,8 +1360,8 @@ void CPDF_StreamContentParser::Handle_SetTextLeading() { } void CPDF_StreamContentParser::Handle_SetTextMatrix() { - m_pCurStates->m_TextMatrix.Set(GetNumber16(5), GetNumber16(4), GetNumber16(3), - GetNumber16(2), GetNumber(1), GetNumber(0)); + m_pCurStates->m_TextMatrix.Set(GetNumber(5), GetNumber(4), GetNumber(3), + GetNumber(2), GetNumber(1), GetNumber(0)); OnChangeTextMatrix(); m_pCurStates->m_TextX = 0; m_pCurStates->m_TextY = 0; diff --git a/core/fpdfapi/fpdf_page/include/cpdf_color.h b/core/fpdfapi/fpdf_page/include/cpdf_color.h index 9e20684d83..89c0eac730 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_color.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_color.h @@ -14,15 +14,11 @@ class CPDF_Pattern; class CPDF_Color { public: - CPDF_Color() : m_pCS(nullptr), m_pBuffer(nullptr) {} - explicit CPDF_Color(int family); + CPDF_Color(); ~CPDF_Color(); - FX_BOOL IsNull() const { return !m_pBuffer; } - FX_BOOL IsEqual(const CPDF_Color& other) const; - FX_BOOL IsPattern() const { - return m_pCS && m_pCS->GetFamily() == PDFCS_PATTERN; - } + bool IsNull() const { return !m_pBuffer; } + bool IsPattern() const; void Copy(const CPDF_Color* pSrc); @@ -32,15 +28,13 @@ class CPDF_Color { FX_BOOL GetRGB(int& R, int& G, int& B) const; CPDF_Pattern* GetPattern() const; - CPDF_ColorSpace* GetPatternCS() const; - FX_FLOAT* GetPatternColor() const; - - CPDF_ColorSpace* m_pCS; + const CPDF_ColorSpace* GetColorSpace() const { return m_pCS; } protected: void ReleaseBuffer(); void ReleaseColorSpace(); + CPDF_ColorSpace* m_pCS; FX_FLOAT* m_pBuffer; }; diff --git a/core/fpdfapi/fpdf_page/include/cpdf_colorspace.h b/core/fpdfapi/fpdf_page/include/cpdf_colorspace.h index 6be55f47b9..48ace36835 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_colorspace.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_colorspace.h @@ -79,7 +79,6 @@ class CPDF_ColorSpace { FX_BOOL bTransMask = FALSE) const; CPDF_Array*& GetArray() { return m_pArray; } - int GetMaxIndex() const; virtual CPDF_ColorSpace* GetBaseCS() const { return NULL; } virtual void EnableStdConversion(FX_BOOL bEnabled); diff --git a/core/fpdfapi/fpdf_page/pageint.h b/core/fpdfapi/fpdf_page/pageint.h index 01a28e3b96..e904234e9f 100644 --- a/core/fpdfapi/fpdf_page/pageint.h +++ b/core/fpdfapi/fpdf_page/pageint.h @@ -124,7 +124,6 @@ class CPDF_StreamContentParser { CPDF_Object* GetObject(uint32_t index); CFX_ByteString GetString(uint32_t index); FX_FLOAT GetNumber(uint32_t index); - FX_FLOAT GetNumber16(uint32_t index); int GetInteger(uint32_t index) { return (int32_t)(GetNumber(index)); } void OnOperator(const FX_CHAR* op); void BigCaseCaller(int index); diff --git a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index 0af1175c8e..ef604ec70f 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -1211,14 +1211,14 @@ void CPDF_RenderStatus::ProcessPathPattern(const CPDF_PathObject* pPathObj, FX_BOOL& bStroke) { if (filltype) { CPDF_Color& FillColor = *pPathObj->m_ColorState.GetFillColor(); - if (FillColor.m_pCS && FillColor.m_pCS->GetFamily() == PDFCS_PATTERN) { + if (FillColor.IsPattern()) { DrawPathWithPattern(pPathObj, pObj2Device, &FillColor, FALSE); filltype = 0; } } if (bStroke) { CPDF_Color& StrokeColor = *pPathObj->m_ColorState.GetStrokeColor(); - if (StrokeColor.m_pCS && StrokeColor.m_pCS->GetFamily() == PDFCS_PATTERN) { + if (StrokeColor.IsPattern()) { DrawPathWithPattern(pPathObj, pObj2Device, &StrokeColor, TRUE); bStroke = FALSE; } |