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/render/cpdf_type3glyphs.h"
8
9 #include <map>
10
11 #include "core/fxge/fx_font.h"
12
CPDF_Type3Glyphs()13 CPDF_Type3Glyphs::CPDF_Type3Glyphs()
14 : m_TopBlueCount(0), m_BottomBlueCount(0) {}
15
~CPDF_Type3Glyphs()16 CPDF_Type3Glyphs::~CPDF_Type3Glyphs() {}
17
_AdjustBlue(float pos,int & count,int blues[])18 static int _AdjustBlue(float pos, int& count, int blues[]) {
19 float min_distance = 1000000.0f;
20 int closest_pos = -1;
21 for (int i = 0; i < count; i++) {
22 float distance = fabs(pos - static_cast<float>(blues[i]));
23 if (distance < 1.0f * 80.0f / 100.0f && distance < min_distance) {
24 min_distance = distance;
25 closest_pos = i;
26 }
27 }
28 if (closest_pos >= 0)
29 return blues[closest_pos];
30 int new_pos = FXSYS_round(pos);
31 if (count == TYPE3_MAX_BLUES)
32 return new_pos;
33 blues[count++] = new_pos;
34 return new_pos;
35 }
36
AdjustBlue(float top,float bottom,int & top_line,int & bottom_line)37 void CPDF_Type3Glyphs::AdjustBlue(float top,
38 float bottom,
39 int& top_line,
40 int& bottom_line) {
41 top_line = _AdjustBlue(top, m_TopBlueCount, m_TopBlue);
42 bottom_line = _AdjustBlue(bottom, m_BottomBlueCount, m_BottomBlue);
43 }
44