OLD | NEW |
| (Empty) |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "core/fpdfapi/fpdf_render/cpdf_type3glyphs.h" | |
8 | |
9 #include <map> | |
10 | |
11 #include "core/fxge/fx_font.h" | |
12 | |
13 CPDF_Type3Glyphs::CPDF_Type3Glyphs() | |
14 : m_TopBlueCount(0), m_BottomBlueCount(0) {} | |
15 | |
16 CPDF_Type3Glyphs::~CPDF_Type3Glyphs() { | |
17 for (const auto& pair : m_GlyphMap) | |
18 delete pair.second; | |
19 } | |
20 | |
21 static int _AdjustBlue(FX_FLOAT pos, int& count, int blues[]) { | |
22 FX_FLOAT min_distance = 1000000.0f; | |
23 int closest_pos = -1; | |
24 for (int i = 0; i < count; i++) { | |
25 FX_FLOAT distance = FXSYS_fabs(pos - static_cast<FX_FLOAT>(blues[i])); | |
26 if (distance < 1.0f * 80.0f / 100.0f && distance < min_distance) { | |
27 min_distance = distance; | |
28 closest_pos = i; | |
29 } | |
30 } | |
31 if (closest_pos >= 0) | |
32 return blues[closest_pos]; | |
33 int new_pos = FXSYS_round(pos); | |
34 if (count == TYPE3_MAX_BLUES) | |
35 return new_pos; | |
36 blues[count++] = new_pos; | |
37 return new_pos; | |
38 } | |
39 | |
40 void CPDF_Type3Glyphs::AdjustBlue(FX_FLOAT top, | |
41 FX_FLOAT bottom, | |
42 int& top_line, | |
43 int& bottom_line) { | |
44 top_line = _AdjustBlue(top, m_TopBlueCount, m_TopBlue); | |
45 bottom_line = _AdjustBlue(bottom, m_BottomBlueCount, m_BottomBlue); | |
46 } | |
OLD | NEW |