Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cpdf_type3font.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/font/cpdf_type3font.h"
8
9
#
include
<
algorithm
>
10
#
include
<
iterator
>
11
#
include
<
type_traits
>
12
#
include
<
utility
>
13
14
#
include
"core/fpdfapi/font/cpdf_type3char.h"
15
#
include
"core/fpdfapi/parser/cpdf_array.h"
16
#
include
"core/fpdfapi/parser/cpdf_dictionary.h"
17
#
include
"core/fpdfapi/parser/cpdf_stream.h"
18
#
include
"core/fxcrt/autorestorer.h"
19
#
include
"core/fxcrt/check.h"
20
#
include
"core/fxcrt/fx_system.h"
21
22
namespace
{
23
24
constexpr
int
kMaxType3FormLevel = 4;
25
26
}
// namespace
27
28
CPDF_Type3Font::CPDF_Type3Font(
CPDF_Document
* pDocument,
29
RetainPtr
<
CPDF_Dictionary
> pFontDict,
30
FormFactoryIface
* pFormFactory)
31
:
CPDF_SimpleFont
(pDocument,
std
::move(pFontDict)),
32
m_pFormFactory(pFormFactory) {
33
DCHECK
(GetDocument());
34
}
35
36
CPDF_Type3Font::~
CPDF_Type3Font
() =
default
;
37
38
bool
CPDF_Type3Font::
IsType3Font
()
const
{
39
return
true
;
40
}
41
42
const
CPDF_Type3Font* CPDF_Type3Font::
AsType3Font
()
const
{
43
return
this
;
44
}
45
46
CPDF_Type3Font* CPDF_Type3Font::
AsType3Font
() {
47
return
this
;
48
}
49
50
void
CPDF_Type3Font::
WillBeDestroyed
() {
51
m_bWillBeDestroyed =
true
;
52
53
// Last reference to |this| may be through one of its CPDF_Type3Chars.
54
RetainPtr
<
CPDF_Font
> protector(
this
);
55
for
(
const
auto
& item : m_CacheMap) {
56
if
(item.second) {
57
item.second->WillBeDestroyed();
58
}
59
}
60
}
61
62
bool
CPDF_Type3Font::
Load
() {
63
m_pFontResources = m_pFontDict->GetMutableDictFor(
"Resources"
);
64
RetainPtr
<
const
CPDF_Array
> pMatrix = m_pFontDict->GetArrayFor(
"FontMatrix"
);
65
float
xscale = 1.0f;
66
float
yscale = 1.0f;
67
if
(pMatrix) {
68
m_FontMatrix = pMatrix->GetMatrix();
69
xscale = m_FontMatrix
.
a
;
70
yscale = m_FontMatrix
.
d
;
71
}
72
73
RetainPtr
<
const
CPDF_Array
> pBBox = m_pFontDict->GetArrayFor(
"FontBBox"
);
74
if
(pBBox) {
75
CFX_FloatRect
box(
76
pBBox->GetFloatAt(0) * xscale, pBBox->GetFloatAt(1) * yscale,
77
pBBox->GetFloatAt(2) * xscale, pBBox->GetFloatAt(3) * yscale);
78
CPDF_Type3Char
::
TextUnitRectToGlyphUnitRect
(
&box
)
;
79
m_FontBBox = box.ToFxRect();
80
}
81
82
const
size_t kCharLimit = m_CharWidthL.size();
83
int
StartChar = m_pFontDict->GetIntegerFor(
"FirstChar"
);
84
if
(StartChar >= 0 &&
static_cast
<size_t>(StartChar) < kCharLimit) {
85
RetainPtr
<
const
CPDF_Array
> pWidthArray =
86
m_pFontDict->GetArrayFor(
"Widths"
);
87
if
(pWidthArray) {
88
size_t count =
std
::min(pWidthArray->size(), kCharLimit);
89
count =
std
::min(count, kCharLimit - StartChar);
90
for
(size_t i = 0; i < count; i++) {
91
m_CharWidthL[StartChar + i] =
92
FXSYS_roundf(CPDF_Type3Char::TextUnitToGlyphUnit(
93
pWidthArray->GetFloatAt(i) * xscale));
94
}
95
}
96
}
97
m_pCharProcs = m_pFontDict->GetMutableDictFor(
"CharProcs"
);
98
if
(m_pFontDict->GetDirectObjectFor(
"Encoding"
))
99
LoadPDFEncoding
(
false
,
false
);
100
return
true
;
101
}
102
103
void
CPDF_Type3Font::
LoadGlyphMap
() {}
104
105
void
CPDF_Type3Font::
CheckType3FontMetrics
() {
106
CheckFontMetrics
();
107
}
108
109
CPDF_Type3Char
* CPDF_Type3Font::
LoadChar
(uint32_t charcode) {
110
if
(m_CharLoadingDepth >= kMaxType3FormLevel)
111
return
nullptr
;
112
113
auto
it = m_CacheMap.find(charcode);
114
if
(it != m_CacheMap.end())
115
return
it->second.get();
116
117
const
char
* name = GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode);
118
if
(!name)
119
return
nullptr
;
120
121
if
(!m_pCharProcs)
122
return
nullptr
;
123
124
RetainPtr
<CPDF_Stream> pStream =
125
ToStream(m_pCharProcs->GetMutableDirectObjectFor(name));
126
if
(!pStream)
127
return
nullptr
;
128
129
std::unique_ptr<CPDF_Font::FormIface> pForm = m_pFormFactory->CreateForm(
130
m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources,
131
pStream);
132
133
auto
pNewChar =
std
::make_unique<
CPDF_Type3Char
>();
134
135
// This can trigger recursion into this method. The content of |m_CacheMap|
136
// can change as a result. Thus after it returns, check the cache again for
137
// a cache hit.
138
{
139
AutoRestorer
<
int
> restorer(&m_CharLoadingDepth);
140
m_CharLoadingDepth++;
141
pForm->ParseContentForType3Char(pNewChar.get());
142
}
143
it = m_CacheMap.find(charcode);
144
if
(it != m_CacheMap.end())
145
return
it->second.get();
146
147
pNewChar->Transform(pForm.get(), m_FontMatrix);
148
if
(pForm->HasPageObjects())
149
pNewChar->SetForm(
std
::move(pForm));
150
151
CPDF_Type3Char
* pCachedChar = pNewChar.get();
152
m_CacheMap[charcode] = std::move(pNewChar);
153
return
pCachedChar;
154
}
155
156
int
CPDF_Type3Font::
GetCharWidthF
(uint32_t charcode) {
157
if
(charcode >=
std
::size(m_CharWidthL))
158
charcode = 0;
159
160
if
(m_CharWidthL[charcode])
161
return
m_CharWidthL[charcode];
162
163
const
CPDF_Type3Char
* pChar =
LoadChar
(
charcode
)
;
164
return
pChar ? pChar
->
width
(
)
: 0;
165
}
166
167
FX_RECT
CPDF_Type3Font::
GetCharBBox
(uint32_t charcode) {
168
FX_RECT
ret;
169
const
CPDF_Type3Char
* pChar =
LoadChar
(
charcode
)
;
170
if
(pChar)
171
ret
=
pChar
->
bbox
(
)
;
172
return
ret;
173
}
DCHECK
#define DCHECK
Definition
check.h:33
CFX_FloatRect
Definition
fx_coordinates.h:185
CFX_Matrix::d
float d
Definition
fx_coordinates.h:510
CFX_Matrix::a
float a
Definition
fx_coordinates.h:507
CPDF_Array::const_iterator
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
Definition
cpdf_array.h:29
CPDF_Dictionary::DictMap
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
Definition
cpdf_dictionary.h:31
CPDF_Document
Definition
cpdf_document.h:29
CPDF_Font::FormFactoryIface
Definition
cpdf_font.h:52
CPDF_Font
Definition
cpdf_font.h:37
CPDF_Font::CheckFontMetrics
void CheckFontMetrics()
Definition
cpdf_font.cpp:212
CPDF_SimpleFont
Definition
cpdf_simplefont.h:19
CPDF_SimpleFont::LoadPDFEncoding
void LoadPDFEncoding(bool bEmbedded, bool bTrueType)
Definition
cpdf_simplefont.cpp:154
CPDF_Type3Char
Definition
cpdf_type3char.h:21
CPDF_Type3Char::TextUnitRectToGlyphUnitRect
static void TextUnitRectToGlyphUnitRect(CFX_FloatRect *pRect)
Definition
cpdf_type3char.cpp:31
CPDF_Type3Char::bbox
const FX_RECT & bbox() const
Definition
cpdf_type3char.h:39
CPDF_Type3Char::width
int width() const
Definition
cpdf_type3char.h:37
CPDF_Type3Font::CheckType3FontMetrics
void CheckType3FontMetrics()
Definition
cpdf_type3font.cpp:105
CPDF_Type3Font::AsType3Font
CPDF_Type3Font * AsType3Font() override
Definition
cpdf_type3font.cpp:46
CPDF_Type3Font::WillBeDestroyed
void WillBeDestroyed() override
Definition
cpdf_type3font.cpp:50
CPDF_Type3Font::IsType3Font
bool IsType3Font() const override
Definition
cpdf_type3font.cpp:38
CPDF_Type3Font::LoadChar
CPDF_Type3Char * LoadChar(uint32_t charcode)
Definition
cpdf_type3font.cpp:109
CPDF_Type3Font::LoadGlyphMap
void LoadGlyphMap() override
Definition
cpdf_type3font.cpp:103
CPDF_Type3Font::GetCharBBox
FX_RECT GetCharBBox(uint32_t charcode) override
Definition
cpdf_type3font.cpp:167
CPDF_Type3Font::~CPDF_Type3Font
~CPDF_Type3Font() override
CPDF_Type3Font::GetCharWidthF
int GetCharWidthF(uint32_t charcode) override
Definition
cpdf_type3font.cpp:156
CPDF_Type3Font::AsType3Font
const CPDF_Type3Font * AsType3Font() const override
Definition
cpdf_type3font.cpp:42
CPDF_Type3Font::Load
bool Load() override
Definition
cpdf_type3font.cpp:62
fxcrt::AutoRestorer
Definition
autorestorer.h:14
fxcrt::RetainPtr
Definition
retain_ptr.h:28
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
FX_RECT
Definition
fx_coordinates.h:144
FX_RECT::operator=
FX_RECT & operator=(const FX_RECT &that)=default
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fpdfapi
font
cpdf_type3font.cpp
Generated on
for Qt by
1.18.0