From 08eaf467ed0bed35ecccf370df32b7d51f3bc5fa Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Thu, 31 May 2018 18:30:32 +0000 Subject: Clean up some nits in CPDF_Type3Glyph MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia466bb0119d914794b0d7ed9385547a7be245858 Reviewed-on: https://pdfium-review.googlesource.com/33312 Reviewed-by: Lei Zhang Commit-Queue: Nicolás Peña Moreno --- core/fpdfapi/render/cpdf_type3cache.cpp | 9 +++----- core/fpdfapi/render/cpdf_type3glyphs.cpp | 36 +++++++++++++++++--------------- core/fpdfapi/render/cpdf_type3glyphs.h | 15 ++++++------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/core/fpdfapi/render/cpdf_type3cache.cpp b/core/fpdfapi/render/cpdf_type3cache.cpp index f85e5bbd9f..7d7ede5700 100644 --- a/core/fpdfapi/render/cpdf_type3cache.cpp +++ b/core/fpdfapi/render/cpdf_type3cache.cpp @@ -135,12 +135,9 @@ std::unique_ptr CPDF_Type3Cache::RenderGlyph( float top_y = image_matrix.d + image_matrix.f; float bottom_y = image_matrix.f; bool bFlipped = top_y > bottom_y; - if (bFlipped) { - float temp = top_y; - top_y = bottom_y; - bottom_y = temp; - } - pSize->AdjustBlue(top_y, bottom_y, top_line, bottom_line); + if (bFlipped) + std::swap(top_y, bottom_y); + std::tie(top_line, bottom_line) = pSize->AdjustBlue(top_y, bottom_y); pResBitmap = pBitmap->StretchTo( static_cast(image_matrix.a), static_cast(bFlipped ? top_line - bottom_line diff --git a/core/fpdfapi/render/cpdf_type3glyphs.cpp b/core/fpdfapi/render/cpdf_type3glyphs.cpp index 01b689f80f..ef14d731c4 100644 --- a/core/fpdfapi/render/cpdf_type3glyphs.cpp +++ b/core/fpdfapi/render/cpdf_type3glyphs.cpp @@ -6,38 +6,40 @@ #include "core/fpdfapi/render/cpdf_type3glyphs.h" +#include #include #include "core/fxge/fx_font.h" -CPDF_Type3Glyphs::CPDF_Type3Glyphs() - : m_TopBlueCount(0), m_BottomBlueCount(0) {} +namespace { -CPDF_Type3Glyphs::~CPDF_Type3Glyphs() {} +constexpr int kType3MaxBlues = 16; -static int _AdjustBlue(float pos, int& count, int blues[]) { +int AdjustBlueHelper(float pos, std::vector* blues) { float min_distance = 1000000.0f; int closest_pos = -1; - for (int i = 0; i < count; i++) { - float distance = fabs(pos - static_cast(blues[i])); - if (distance < 1.0f * 80.0f / 100.0f && distance < min_distance) { + for (int i = 0; i < static_cast(blues->size()); ++i) { + float distance = fabs(pos - static_cast(blues->at(i))); + if (distance < std::min(0.8f, min_distance)) { min_distance = distance; closest_pos = i; } } if (closest_pos >= 0) - return blues[closest_pos]; + return blues->at(closest_pos); int new_pos = FXSYS_round(pos); - if (count == TYPE3_MAX_BLUES) - return new_pos; - blues[count++] = new_pos; + if (blues->size() < kType3MaxBlues) + blues->push_back(new_pos); return new_pos; } -void CPDF_Type3Glyphs::AdjustBlue(float top, - float bottom, - int& top_line, - int& bottom_line) { - top_line = _AdjustBlue(top, m_TopBlueCount, m_TopBlue); - bottom_line = _AdjustBlue(bottom, m_BottomBlueCount, m_BottomBlue); +} // namespace + +CPDF_Type3Glyphs::CPDF_Type3Glyphs() {} + +CPDF_Type3Glyphs::~CPDF_Type3Glyphs() {} + +std::pair CPDF_Type3Glyphs::AdjustBlue(float top, float bottom) { + return std::make_pair(AdjustBlueHelper(top, &m_TopBlue), + AdjustBlueHelper(bottom, &m_BottomBlue)); } diff --git a/core/fpdfapi/render/cpdf_type3glyphs.h b/core/fpdfapi/render/cpdf_type3glyphs.h index 7756be309f..09dd70a564 100644 --- a/core/fpdfapi/render/cpdf_type3glyphs.h +++ b/core/fpdfapi/render/cpdf_type3glyphs.h @@ -9,25 +9,26 @@ #include #include +#include +#include #include "core/fxcrt/fx_system.h" class CFX_GlyphBitmap; -#define TYPE3_MAX_BLUES 16 - class CPDF_Type3Glyphs { public: CPDF_Type3Glyphs(); ~CPDF_Type3Glyphs(); - void AdjustBlue(float top, float bottom, int& top_line, int& bottom_line); + // Returns a pair of integers (top_line, bottom_line). + std::pair AdjustBlue(float top, float bottom); std::map> m_GlyphMap; - int m_TopBlueCount; - int m_BottomBlueCount; - int m_TopBlue[TYPE3_MAX_BLUES]; - int m_BottomBlue[TYPE3_MAX_BLUES]; + + private: + std::vector m_TopBlue; + std::vector m_BottomBlue; }; #endif // CORE_FPDFAPI_RENDER_CPDF_TYPE3GLYPHS_H_ -- cgit v1.2.3