summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-12-01 15:51:23 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-01 15:51:23 +0000
commit1f0d1fda6db83ee402561902c76ae8a6da124663 (patch)
treeca8054af7bc7d87ad8794bbba5b3aac352fe2e42 /core/fpdfapi
parent1980f10ff2b869f14c409b712eea6744941ebd88 (diff)
downloadpdfium-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')
-rw-r--r--core/fpdfapi/font/cpdf_type3char.cpp32
-rw-r--r--core/fpdfapi/font/cpdf_type3char.h20
-rw-r--r--core/fpdfapi/font/cpdf_type3font.cpp32
-rw-r--r--core/fpdfapi/page/cpdf_contentparser.cpp14
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp58
-rw-r--r--core/fpdfapi/render/cpdf_type3cache.cpp6
6 files changed, 100 insertions, 62 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;
}
diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp
index 7095ff596f..cc93b4df9e 100644
--- a/core/fpdfapi/page/cpdf_contentparser.cpp
+++ b/core/fpdfapi/page/cpdf_contentparser.cpp
@@ -173,18 +173,10 @@ bool CPDF_ContentParser::Continue(IFX_PauseIndicator* pPause) {
}
if (m_InternalStage == STAGE_CHECKCLIP) {
if (m_pType3Char) {
- m_pType3Char->m_bColored = m_pParser->IsColored();
- m_pType3Char->m_Width =
- FXSYS_round(m_pParser->GetType3Data()[0] * 1000);
- m_pType3Char->m_BBox.left =
- FXSYS_round(m_pParser->GetType3Data()[2] * 1000);
- m_pType3Char->m_BBox.bottom =
- FXSYS_round(m_pParser->GetType3Data()[3] * 1000);
- m_pType3Char->m_BBox.right =
- FXSYS_round(m_pParser->GetType3Data()[4] * 1000);
- m_pType3Char->m_BBox.top =
- FXSYS_round(m_pParser->GetType3Data()[5] * 1000);
+ m_pType3Char->InitializeFromStreamData(m_pParser->IsColored(),
+ m_pParser->GetType3Data());
}
+
for (auto& pObj : *m_pObjectHolder->GetPageObjectList()) {
if (!pObj->m_ClipPath.HasRef())
continue;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index b7b37edc4b..3f61358d7f 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -963,6 +963,26 @@ bool IsAvailableMatrix(const CFX_Matrix& matrix) {
return true;
}
+bool MissingFillColor(const CPDF_ColorState* pColorState) {
+ return !pColorState->HasRef() || pColorState->GetFillColor()->IsNull();
+}
+
+bool MissingStrokeColor(const CPDF_ColorState* pColorState) {
+ return !pColorState->HasRef() || pColorState->GetStrokeColor()->IsNull();
+}
+
+bool Type3CharMissingFillColor(const CPDF_Type3Char* pChar,
+ const CPDF_ColorState* pColorState) {
+ return pChar && (!pChar->colored() ||
+ (pChar->colored() && MissingFillColor(pColorState)));
+}
+
+bool Type3CharMissingStrokeColor(const CPDF_Type3Char* pChar,
+ const CPDF_ColorState* pColorState) {
+ return pChar && (!pChar->colored() ||
+ (pChar->colored() && MissingStrokeColor(pColorState)));
+}
+
} // namespace
// static
@@ -1330,13 +1350,10 @@ RetainPtr<CPDF_TransferFunc> CPDF_RenderStatus::GetTransferFunc(
FX_ARGB CPDF_RenderStatus::GetFillArgb(CPDF_PageObject* pObj,
bool bType3) const {
const CPDF_ColorState* pColorState = &pObj->m_ColorState;
- if (m_pType3Char && !bType3 &&
- (!m_pType3Char->m_bColored ||
- (m_pType3Char->m_bColored &&
- (!pColorState->HasRef() || pColorState->GetFillColor()->IsNull())))) {
+ if (!bType3 && Type3CharMissingFillColor(m_pType3Char.Get(), pColorState))
return m_T3FillColor;
- }
- if (!pColorState->HasRef() || pColorState->GetFillColor()->IsNull())
+
+ if (MissingFillColor(pColorState))
pColorState = &m_InitialStates.m_ColorState;
FX_COLORREF rgb = pColorState->GetFillRGB();
@@ -1358,13 +1375,10 @@ FX_ARGB CPDF_RenderStatus::GetFillArgb(CPDF_PageObject* pObj,
FX_ARGB CPDF_RenderStatus::GetStrokeArgb(CPDF_PageObject* pObj) const {
const CPDF_ColorState* pColorState = &pObj->m_ColorState;
- if (m_pType3Char &&
- (!m_pType3Char->m_bColored ||
- (m_pType3Char->m_bColored &&
- (!pColorState->HasRef() || pColorState->GetStrokeColor()->IsNull())))) {
+ if (Type3CharMissingStrokeColor(m_pType3Char.Get(), pColorState))
return m_T3FillColor;
- }
- if (!pColorState->HasRef() || pColorState->GetStrokeColor()->IsNull())
+
+ if (MissingStrokeColor(pColorState))
pColorState = &m_InitialStates.m_ColorState;
FX_COLORREF rgb = pColorState->GetStrokeRGB();
@@ -1887,24 +1901,24 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
options.SetFlags(option_flags);
CPDF_Dictionary* pFormResource = nullptr;
- if (pType3Char->m_pForm && pType3Char->m_pForm->m_pFormDict) {
+ if (pType3Char->form() && pType3Char->form()->m_pFormDict) {
pFormResource =
- pType3Char->m_pForm->m_pFormDict->GetDictFor("Resources");
+ pType3Char->form()->m_pFormDict->GetDictFor("Resources");
}
if (fill_alpha == 255) {
CPDF_RenderStatus status;
status.Initialize(m_pContext.Get(), m_pDevice, nullptr, nullptr, this,
pStates.get(), &options,
- pType3Char->m_pForm->m_iTransparency, m_bDropObjects,
+ pType3Char->form()->m_iTransparency, m_bDropObjects,
pFormResource, false, pType3Char, fill_argb);
status.m_Type3FontCache = m_Type3FontCache;
status.m_Type3FontCache.push_back(pType3Font);
CFX_RenderDevice::StateRestorer restorer(m_pDevice);
- status.RenderObjectList(pType3Char->m_pForm.get(), &matrix);
+ status.RenderObjectList(pType3Char->form(), &matrix);
} else {
FX_RECT rect =
- matrix.TransformRect(pType3Char->m_pForm->CalcBoundingBox())
+ matrix.TransformRect(pType3Char->form()->CalcBoundingBox())
.GetOuterRect();
CFX_DefaultRenderDevice bitmap_device;
if (!bitmap_device.Create((int)(rect.Width() * sa),
@@ -1916,16 +1930,16 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
CPDF_RenderStatus status;
status.Initialize(m_pContext.Get(), &bitmap_device, nullptr, nullptr,
this, pStates.get(), &options,
- pType3Char->m_pForm->m_iTransparency, m_bDropObjects,
+ pType3Char->form()->m_iTransparency, m_bDropObjects,
pFormResource, false, pType3Char, fill_argb);
status.m_Type3FontCache = m_Type3FontCache;
status.m_Type3FontCache.push_back(pType3Font);
matrix.Translate(-rect.left, -rect.top);
matrix.Scale(sa, sd);
- status.RenderObjectList(pType3Char->m_pForm.get(), &matrix);
+ status.RenderObjectList(pType3Char->form(), &matrix);
m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top);
}
- } else if (pType3Char->m_pBitmap) {
+ } else if (pType3Char->GetBitmap()) {
if (device_class == FXDC_DISPLAY) {
RetainPtr<CPDF_Type3Cache> pCache = GetCachedType3(pType3Font);
refTypeCache.m_dwCount++;
@@ -1942,10 +1956,10 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
glyphs[iChar].m_Origin = origin;
}
} else {
- CFX_Matrix image_matrix = pType3Char->m_ImageMatrix;
+ CFX_Matrix image_matrix = pType3Char->matrix();
image_matrix.Concat(matrix);
CPDF_ImageRenderer renderer;
- if (renderer.Start(this, pType3Char->m_pBitmap, fill_argb, 255,
+ if (renderer.Start(this, pType3Char->GetBitmap(), fill_argb, 255,
&image_matrix, 0, false, FXDIB_BLEND_NORMAL)) {
renderer.Continue(nullptr);
}
diff --git a/core/fpdfapi/render/cpdf_type3cache.cpp b/core/fpdfapi/render/cpdf_type3cache.cpp
index 42b11605c5..fe9dfbf9e0 100644
--- a/core/fpdfapi/render/cpdf_type3cache.cpp
+++ b/core/fpdfapi/render/cpdf_type3cache.cpp
@@ -119,14 +119,14 @@ std::unique_ptr<CFX_GlyphBitmap> CPDF_Type3Cache::RenderGlyph(
float retinaScaleX,
float retinaScaleY) {
const CPDF_Type3Char* pChar = m_pFont->LoadChar(charcode);
- if (!pChar || !pChar->m_pBitmap)
+ if (!pChar || !pChar->GetBitmap())
return nullptr;
- RetainPtr<CFX_DIBitmap> pBitmap = pChar->m_pBitmap;
- CFX_Matrix image_matrix = pChar->m_ImageMatrix;
CFX_Matrix text_matrix(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, 0, 0);
+ CFX_Matrix image_matrix = pChar->matrix();
image_matrix.Concat(text_matrix);
+ RetainPtr<CFX_DIBitmap> pBitmap = pChar->GetBitmap();
RetainPtr<CFX_DIBitmap> pResBitmap;
int left = 0;
int top = 0;