summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/render')
-rw-r--r--core/fpdfapi/render/cpdf_type3cache.cpp9
-rw-r--r--core/fpdfapi/render/cpdf_type3glyphs.cpp36
-rw-r--r--core/fpdfapi/render/cpdf_type3glyphs.h15
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<CFX_GlyphBitmap> 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<int>(image_matrix.a),
static_cast<int>(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 <algorithm>
#include <map>
#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<int>* blues) {
float min_distance = 1000000.0f;
int closest_pos = -1;
- for (int i = 0; i < count; i++) {
- float distance = fabs(pos - static_cast<float>(blues[i]));
- if (distance < 1.0f * 80.0f / 100.0f && distance < min_distance) {
+ for (int i = 0; i < static_cast<int>(blues->size()); ++i) {
+ float distance = fabs(pos - static_cast<float>(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<int, int> 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 <map>
#include <memory>
+#include <utility>
+#include <vector>
#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<int, int> AdjustBlue(float top, float bottom);
std::map<uint32_t, std::unique_ptr<CFX_GlyphBitmap>> m_GlyphMap;
- int m_TopBlueCount;
- int m_BottomBlueCount;
- int m_TopBlue[TYPE3_MAX_BLUES];
- int m_BottomBlue[TYPE3_MAX_BLUES];
+
+ private:
+ std::vector<int> m_TopBlue;
+ std::vector<int> m_BottomBlue;
};
#endif // CORE_FPDFAPI_RENDER_CPDF_TYPE3GLYPHS_H_