diff options
author | Lei Zhang <thestig@chromium.org> | 2017-12-01 15:51:23 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-01 15:51:23 +0000 |
commit | 1f0d1fda6db83ee402561902c76ae8a6da124663 (patch) | |
tree | ca8054af7bc7d87ad8794bbba5b3aac352fe2e42 /core/fpdfapi/font | |
parent | 1980f10ff2b869f14c409b712eea6744941ebd88 (diff) | |
download | pdfium-1f0d1fda6db83ee402561902c76ae8a6da124663.tar.xz |
Encapsulate CPDF_Type3Char members.
Change-Id: Iec4e999d76dabc9b6cd00323881c5c87afc5f629
Reviewed-on: https://pdfium-review.googlesource.com/19930
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/font')
-rw-r--r-- | core/fpdfapi/font/cpdf_type3char.cpp | 32 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_type3char.h | 20 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_type3font.cpp | 32 |
3 files changed, 58 insertions, 26 deletions
diff --git a/core/fpdfapi/font/cpdf_type3char.cpp b/core/fpdfapi/font/cpdf_type3char.cpp index c0ed88d4db..eea3d9a86e 100644 --- a/core/fpdfapi/font/cpdf_type3char.cpp +++ b/core/fpdfapi/font/cpdf_type3char.cpp @@ -15,7 +15,7 @@ #include "core/fxge/fx_dib.h" CPDF_Type3Char::CPDF_Type3Char(std::unique_ptr<CPDF_Form> pForm) - : m_pForm(std::move(pForm)), m_bColored(false) {} + : m_pForm(std::move(pForm)) {} CPDF_Type3Char::~CPDF_Type3Char() {} @@ -49,3 +49,33 @@ bool CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) { m_pForm.reset(); return true; } + +void CPDF_Type3Char::InitializeFromStreamData(bool bColored, + const float* pData) { + m_bColored = bColored; + m_Width = FXSYS_round(pData[0] * 1000); + m_BBox.left = FXSYS_round(pData[2] * 1000); + m_BBox.bottom = FXSYS_round(pData[3] * 1000); + m_BBox.right = FXSYS_round(pData[4] * 1000); + m_BBox.top = FXSYS_round(pData[5] * 1000); +} + +void CPDF_Type3Char::Transform(const CFX_Matrix& matrix) { + m_Width = m_Width * matrix.GetXUnit() + 0.5f; + CFX_FloatRect char_rect(static_cast<float>(m_BBox.left) / 1000.0f, + static_cast<float>(m_BBox.bottom) / 1000.0f, + static_cast<float>(m_BBox.right) / 1000.0f, + static_cast<float>(m_BBox.top) / 1000.0f); + if (m_BBox.right <= m_BBox.left || m_BBox.bottom >= m_BBox.top) + char_rect = form()->CalcBoundingBox(); + + char_rect = matrix.TransformRect(char_rect); + m_BBox.left = FXSYS_round(char_rect.left * 1000); + m_BBox.right = FXSYS_round(char_rect.right * 1000); + m_BBox.top = FXSYS_round(char_rect.top * 1000); + m_BBox.bottom = FXSYS_round(char_rect.bottom * 1000); +} + +void CPDF_Type3Char::ResetForm() { + m_pForm.reset(); +} diff --git a/core/fpdfapi/font/cpdf_type3char.h b/core/fpdfapi/font/cpdf_type3char.h index 444c9930e1..7661817b1f 100644 --- a/core/fpdfapi/font/cpdf_type3char.h +++ b/core/fpdfapi/font/cpdf_type3char.h @@ -24,10 +24,26 @@ class CPDF_Type3Char { bool LoadBitmap(CPDF_RenderContext* pContext); + void InitializeFromStreamData(bool bColored, const float* pData); + void Transform(const CFX_Matrix& matrix); + void ResetForm(); + + RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; } + const RetainPtr<CFX_DIBitmap>& GetBitmap() const { return m_pBitmap; } + + const CPDF_Form* form() const { return m_pForm.get(); } + CPDF_Form* form() { return m_pForm.get(); } + + bool colored() const { return m_bColored; } + int width() const { return m_Width; } + const CFX_Matrix& matrix() const { return m_ImageMatrix; } + const FX_RECT& bbox() const { return m_BBox; } + + private: std::unique_ptr<CPDF_Form> m_pForm; RetainPtr<CFX_DIBitmap> m_pBitmap; - bool m_bColored; - int m_Width; + bool m_bColored = false; + int m_Width = 0; CFX_Matrix m_ImageMatrix; FX_RECT m_BBox; }; diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp index 2af1dac44f..fc2ad0f348 100644 --- a/core/fpdfapi/font/cpdf_type3font.cpp +++ b/core/fpdfapi/font/cpdf_type3font.cpp @@ -114,34 +114,17 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode) { // can change as a result. Thus after it returns, check the cache again for // a cache hit. m_CharLoadingDepth++; - pNewChar->m_pForm->ParseContentWithParams(nullptr, nullptr, pNewChar.get(), - 0); + pNewChar->form()->ParseContentWithParams(nullptr, nullptr, pNewChar.get(), 0); m_CharLoadingDepth--; it = m_CacheMap.find(charcode); if (it != m_CacheMap.end()) return it->second.get(); - float scale = m_FontMatrix.GetXUnit(); - pNewChar->m_Width = static_cast<int32_t>(pNewChar->m_Width * scale + 0.5f); - FX_RECT& rcBBox = pNewChar->m_BBox; - CFX_FloatRect char_rect(static_cast<float>(rcBBox.left) / 1000.0f, - static_cast<float>(rcBBox.bottom) / 1000.0f, - static_cast<float>(rcBBox.right) / 1000.0f, - static_cast<float>(rcBBox.top) / 1000.0f); - if (rcBBox.right <= rcBBox.left || rcBBox.bottom >= rcBBox.top) - char_rect = pNewChar->m_pForm->CalcBoundingBox(); - - char_rect = m_FontMatrix.TransformRect(char_rect); - rcBBox.left = FXSYS_round(char_rect.left * 1000); - rcBBox.right = FXSYS_round(char_rect.right * 1000); - rcBBox.top = FXSYS_round(char_rect.top * 1000); - rcBBox.bottom = FXSYS_round(char_rect.bottom * 1000); - - ASSERT(!pdfium::ContainsKey(m_CacheMap, charcode)); + pNewChar->Transform(m_FontMatrix); m_CacheMap[charcode] = std::move(pNewChar); CPDF_Type3Char* pCachedChar = m_CacheMap[charcode].get(); - if (pCachedChar->m_pForm->GetPageObjectList()->empty()) - pCachedChar->m_pForm.reset(); + if (pCachedChar->form()->GetPageObjectList()->empty()) + pCachedChar->ResetForm(); return pCachedChar; } @@ -153,10 +136,13 @@ int CPDF_Type3Font::GetCharWidthF(uint32_t charcode) { return m_CharWidthL[charcode]; const CPDF_Type3Char* pChar = LoadChar(charcode); - return pChar ? pChar->m_Width : 0; + return pChar ? pChar->width() : 0; } FX_RECT CPDF_Type3Font::GetCharBBox(uint32_t charcode) { + FX_RECT ret; const CPDF_Type3Char* pChar = LoadChar(charcode); - return pChar ? pChar->m_BBox : FX_RECT(); + if (pChar) + ret = pChar->bbox(); + return ret; } |