diff options
author | Lei Zhang <thestig@chromium.org> | 2017-12-04 16:41:16 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-04 16:41:16 +0000 |
commit | a6bc91192be6e64a4ff615aba3bd057b3a810e67 (patch) | |
tree | b0032367f39bdb6d08f897c62b5e17510bd57193 /core/fpdfapi | |
parent | ddf945fc297356062eb8ba07b2d58e65a09b152b (diff) | |
download | pdfium-a6bc91192be6e64a4ff615aba3bd057b3a810e67.tar.xz |
Add text unit to glyph unit conversion to CPDF_Type3Char.
Use it in type 3 font code.
Change-Id: I8b0eb462cc0308f1700d21a62efc929babae8e20
Reviewed-on: https://pdfium-review.googlesource.com/20215
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.cpp | 44 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_type3char.h | 3 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_type3font.cpp | 16 |
3 files changed, 39 insertions, 24 deletions
diff --git a/core/fpdfapi/font/cpdf_type3char.cpp b/core/fpdfapi/font/cpdf_type3char.cpp index eea3d9a86e..f1448ab751 100644 --- a/core/fpdfapi/font/cpdf_type3char.cpp +++ b/core/fpdfapi/font/cpdf_type3char.cpp @@ -14,11 +14,27 @@ #include "core/fpdfapi/page/cpdf_pageobject.h" #include "core/fxge/fx_dib.h" +namespace { + +constexpr float kTextUnitInGlyphUnit = 1000.0f; + +} // namespace + CPDF_Type3Char::CPDF_Type3Char(std::unique_ptr<CPDF_Form> pForm) : m_pForm(std::move(pForm)) {} CPDF_Type3Char::~CPDF_Type3Char() {} +// static +float CPDF_Type3Char::TextUnitToGlyphUnit(float fTextUnit) { + return fTextUnit * kTextUnitInGlyphUnit; +} + +// static +void CPDF_Type3Char::TextUnitRectToGlyphUnitRect(CFX_FloatRect* pRect) { + pRect->Scale(kTextUnitInGlyphUnit); +} + bool CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) { if (m_pBitmap || !m_pForm) return true; @@ -53,27 +69,25 @@ bool CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) { 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); + m_Width = FXSYS_round(TextUnitToGlyphUnit(pData[0])); + m_BBox.left = FXSYS_round(TextUnitToGlyphUnit(pData[2])); + m_BBox.bottom = FXSYS_round(TextUnitToGlyphUnit(pData[3])); + m_BBox.right = FXSYS_round(TextUnitToGlyphUnit(pData[4])); + m_BBox.top = FXSYS_round(TextUnitToGlyphUnit(pData[5])); } 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) + + CFX_FloatRect char_rect; + if (m_BBox.right <= m_BBox.left || m_BBox.bottom >= m_BBox.top) { char_rect = form()->CalcBoundingBox(); + TextUnitRectToGlyphUnitRect(&char_rect); + } else { + char_rect = CFX_FloatRect(m_BBox); + } - 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); + m_BBox = matrix.TransformRect(char_rect).ToRoundedFxRect(); } void CPDF_Type3Char::ResetForm() { diff --git a/core/fpdfapi/font/cpdf_type3char.h b/core/fpdfapi/font/cpdf_type3char.h index 7661817b1f..2aec16a0eb 100644 --- a/core/fpdfapi/font/cpdf_type3char.h +++ b/core/fpdfapi/font/cpdf_type3char.h @@ -22,6 +22,9 @@ class CPDF_Type3Char { explicit CPDF_Type3Char(std::unique_ptr<CPDF_Form> pForm); ~CPDF_Type3Char(); + static float TextUnitToGlyphUnit(float fTextUnit); + static void TextUnitRectToGlyphUnitRect(CFX_FloatRect* pRect); + bool LoadBitmap(CPDF_RenderContext* pContext); void InitializeFromStreamData(bool bColored, const float* pData); diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp index 6588493e16..c328c1020d 100644 --- a/core/fpdfapi/font/cpdf_type3font.cpp +++ b/core/fpdfapi/font/cpdf_type3font.cpp @@ -54,14 +54,11 @@ bool CPDF_Type3Font::Load() { CPDF_Array* pBBox = m_pFontDict->GetArrayFor("FontBBox"); if (pBBox) { - m_FontBBox.left = - static_cast<int32_t>(pBBox->GetNumberAt(0) * xscale * 1000); - m_FontBBox.bottom = - static_cast<int32_t>(pBBox->GetNumberAt(1) * yscale * 1000); - m_FontBBox.right = - static_cast<int32_t>(pBBox->GetNumberAt(2) * xscale * 1000); - m_FontBBox.top = - static_cast<int32_t>(pBBox->GetNumberAt(3) * yscale * 1000); + CFX_FloatRect box( + pBBox->GetNumberAt(0) * xscale, pBBox->GetNumberAt(1) * yscale, + pBBox->GetNumberAt(2) * xscale, pBBox->GetNumberAt(3) * yscale); + CPDF_Type3Char::TextUnitRectToGlyphUnitRect(&box); + m_FontBBox = box.ToFxRect(); } static constexpr size_t kCharLimit = FX_ArraySize(m_CharWidthL); @@ -73,7 +70,8 @@ bool CPDF_Type3Font::Load() { count = std::min(count, kCharLimit - StartChar); for (size_t i = 0; i < count; i++) { m_CharWidthL[StartChar + i] = - FXSYS_round(pWidthArray->GetNumberAt(i) * xscale * 1000); + FXSYS_round(CPDF_Type3Char::TextUnitToGlyphUnit( + pWidthArray->GetNumberAt(i) * xscale)); } } } |