Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_type3glyphmap.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
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_type3glyphmap.h"
8
9#include <math.h>
10
11#include <algorithm>
12#include <utility>
13
14#include "core/fxcrt/fx_system.h"
15#include "core/fxge/cfx_glyphbitmap.h"
16#include "core/fxge/fx_font.h"
17
18namespace {
19
20constexpr int kType3MaxBlues = 16;
21
22int AdjustBlueHelper(float pos, std::vector<int>* blues) {
23 float min_distance = 1000000.0f;
24 int closest_pos = -1;
25 for (int i = 0; i < static_cast<int>(blues->size()); ++i) {
26 float distance = fabs(pos - static_cast<float>(blues->at(i)));
27 if (distance < std::min(0.8f, min_distance)) {
28 min_distance = distance;
29 closest_pos = i;
30 }
31 }
32 if (closest_pos >= 0)
33 return blues->at(closest_pos);
34 int new_pos = FXSYS_roundf(pos);
35 if (blues->size() < kType3MaxBlues)
36 blues->push_back(new_pos);
37 return new_pos;
38}
39
40} // namespace
41
43
45
46std::pair<int, int> CPDF_Type3GlyphMap::AdjustBlue(float top, float bottom) {
47 return std::make_pair(AdjustBlueHelper(top, &m_TopBlue),
48 AdjustBlueHelper(bottom, &m_BottomBlue));
49}
50
51const CFX_GlyphBitmap* CPDF_Type3GlyphMap::GetBitmap(uint32_t charcode) const {
52 auto it = m_GlyphMap.find(charcode);
53 return it != m_GlyphMap.end() ? it->second.get() : nullptr;
54}
55
56void CPDF_Type3GlyphMap::SetBitmap(uint32_t charcode,
57 std::unique_ptr<CFX_GlyphBitmap> pMap) {
58 m_GlyphMap[charcode] = std::move(pMap);
59}
void SetBitmap(uint32_t charcode, std::unique_ptr< CFX_GlyphBitmap > pMap)
const CFX_GlyphBitmap * GetBitmap(uint32_t charcode) const
std::pair< int, int > AdjustBlue(float top, float bottom)
int FXSYS_roundf(float f)
Definition fx_system.cpp:92