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
cxfa_font.cpp
Go to the documentation of this file.
1
// Copyright 2017 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
"xfa/fxfa/parser/cxfa_font.h"
8
9
#
include
"fxjs/xfa/cjx_node.h"
10
#
include
"xfa/fxfa/parser/cxfa_document.h"
11
#
include
"xfa/fxfa/parser/cxfa_fill.h"
12
#
include
"xfa/fxfa/parser/cxfa_measurement.h"
13
14
namespace
{
15
16
const
CXFA_Node
::
PropertyData
kFontPropertyData[] = {
17
{
XFA_Element
::Fill, 1, {}},
18
{
XFA_Element
::Extras, 1, {}},
19
};
20
21
const
CXFA_Node
::
AttributeData
kFontAttributeData[] = {
22
{
XFA_Attribute
::Id,
XFA_AttributeType
::
CData
,
nullptr
},
23
{
XFA_Attribute
::LineThrough,
XFA_AttributeType
::
Integer
, (
void
*)0},
24
{
XFA_Attribute
::Typeface,
XFA_AttributeType
::
CData
, (
void
*)L"Courier"},
25
{
XFA_Attribute
::FontHorizontalScale,
XFA_AttributeType
::
CData
,
26
(
void
*)L"100%"},
27
{
XFA_Attribute
::Use,
XFA_AttributeType
::
CData
,
nullptr
},
28
{
XFA_Attribute
::KerningMode,
XFA_AttributeType
::
Enum
,
29
(
void
*)
XFA_AttributeValue
::None},
30
{
XFA_Attribute
::Underline,
XFA_AttributeType
::
Integer
, (
void
*)0},
31
{
XFA_Attribute
::BaselineShift,
XFA_AttributeType
::
Measure
, (
void
*)L"0in"},
32
{
XFA_Attribute
::OverlinePeriod,
XFA_AttributeType
::
Enum
,
33
(
void
*)
XFA_AttributeValue
::All},
34
{
XFA_Attribute
::LetterSpacing,
XFA_AttributeType
::
CData
,
nullptr
},
35
{
XFA_Attribute
::LineThroughPeriod,
XFA_AttributeType
::
Enum
,
36
(
void
*)
XFA_AttributeValue
::All},
37
{
XFA_Attribute
::FontVerticalScale,
XFA_AttributeType
::
CData
,
38
(
void
*)L"100%"},
39
{
XFA_Attribute
::PsName,
XFA_AttributeType
::
CData
,
nullptr
},
40
{
XFA_Attribute
::Size,
XFA_AttributeType
::
Measure
, (
void
*)L"10pt"},
41
{
XFA_Attribute
::Posture,
XFA_AttributeType
::
Enum
,
42
(
void
*)
XFA_AttributeValue
::Normal},
43
{
XFA_Attribute
::Usehref,
XFA_AttributeType
::
CData
,
nullptr
},
44
{
XFA_Attribute
::Weight,
XFA_AttributeType
::
Enum
,
45
(
void
*)
XFA_AttributeValue
::Normal},
46
{
XFA_Attribute
::UnderlinePeriod,
XFA_AttributeType
::
Enum
,
47
(
void
*)
XFA_AttributeValue
::All},
48
{
XFA_Attribute
::Overline,
XFA_AttributeType
::
Integer
, (
void
*)0},
49
{
XFA_Attribute
::GenericFamily,
XFA_AttributeType
::
Enum
,
50
(
void
*)
XFA_AttributeValue
::Serif},
51
};
52
53
}
// namespace
54
55
CXFA_Font::CXFA_Font(CXFA_Document* doc,
XFA_PacketType
packet)
56
: CXFA_Node(doc,
57
packet,
58
{XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kConfig,
59
XFA_XDPPACKET::kForm},
60
XFA_ObjectType::Node,
61
XFA_Element::Font,
62
kFontPropertyData,
63
kFontAttributeData,
64
cppgc::MakeGarbageCollected<CJX_Node>(
65
doc->GetHeap()->GetAllocationHandle(),
66
this
)) {}
67
68
CXFA_Font::~
CXFA_Font
() =
default
;
69
70
float
CXFA_Font::
GetBaselineShift
()
const
{
71
return
JSObject()->GetMeasureInUnit(
XFA_Attribute
::BaselineShift,
72
XFA_Unit
::
Pt
);
73
}
74
75
float
CXFA_Font::
GetHorizontalScale
() {
76
WideString
wsValue = JSObject()->GetCData(
XFA_Attribute
::FontHorizontalScale);
77
int32_t iScale = FXSYS_wtoi(wsValue.c_str());
78
return
iScale > 0 ? (
float
)iScale : 100.0f;
79
}
80
81
float
CXFA_Font::
GetVerticalScale
() {
82
WideString
wsValue = JSObject()->GetCData(
XFA_Attribute
::FontVerticalScale);
83
int32_t iScale = FXSYS_wtoi(wsValue.c_str());
84
return
iScale > 0 ? (
float
)iScale : 100.0f;
85
}
86
87
float
CXFA_Font::
GetLetterSpacing
() {
88
WideString
wsValue = JSObject()->GetCData(
XFA_Attribute
::LetterSpacing);
89
CXFA_Measurement
ms(wsValue.AsStringView());
90
if
(ms
.
GetUnit
(
)
==
XFA_Unit
::
Em
)
91
return
ms
.
GetValue
(
)
*
GetFontSize
(
)
;
92
return
ms
.
ToUnit
(
XFA_Unit
::
Pt
)
;
93
}
94
95
int32_t CXFA_Font::
GetLineThrough
() {
96
return
JSObject()->GetInteger(
XFA_Attribute
::LineThrough);
97
}
98
99
int32_t CXFA_Font::
GetUnderline
() {
100
return
JSObject()->GetInteger(
XFA_Attribute
::Underline);
101
}
102
103
XFA_AttributeValue
CXFA_Font::
GetUnderlinePeriod
() {
104
return
JSObject()
105
->TryEnum(
XFA_Attribute
::UnderlinePeriod,
true
)
106
.value_or(
XFA_AttributeValue
::All);
107
}
108
109
float
CXFA_Font::
GetFontSize
()
const
{
110
return
JSObject()->GetMeasureInUnit(
XFA_Attribute
::Size,
XFA_Unit
::
Pt
);
111
}
112
113
WideString
CXFA_Font::
GetTypeface
() {
114
return
JSObject()->GetCData(
XFA_Attribute
::Typeface);
115
}
116
117
bool
CXFA_Font::
IsBold
() {
118
return
JSObject()->GetEnum(
XFA_Attribute
::Weight) ==
XFA_AttributeValue
::Bold;
119
}
120
121
bool
CXFA_Font::
IsItalic
() {
122
return
JSObject()->GetEnum(
XFA_Attribute
::Posture) ==
123
XFA_AttributeValue
::Italic;
124
}
125
126
void
CXFA_Font::
SetColor
(
FX_ARGB
color) {
127
CXFA_Fill* node =
128
JSObject()->GetOrCreateProperty<CXFA_Fill>(0,
XFA_Element
::Fill);
129
if
(!node)
130
return
;
131
132
node
->
SetColor
(
color
)
;
133
}
134
135
FX_ARGB
CXFA_Font::
GetColor
()
const
{
136
const
auto
* fill = GetChild<CXFA_Fill>(0,
XFA_Element
::Fill,
false
);
137
return
fill ? fill->GetTextColor() : 0xFF000000;
138
}
CXFA_Fill::SetColor
void SetColor(FX_ARGB color)
Definition
cxfa_fill.cpp:64
CXFA_Font::GetVerticalScale
float GetVerticalScale()
Definition
cxfa_font.cpp:81
CXFA_Font::GetBaselineShift
float GetBaselineShift() const
Definition
cxfa_font.cpp:70
CXFA_Font::GetTypeface
WideString GetTypeface()
Definition
cxfa_font.cpp:113
CXFA_Font::IsItalic
bool IsItalic()
Definition
cxfa_font.cpp:121
CXFA_Font::GetColor
FX_ARGB GetColor() const
Definition
cxfa_font.cpp:135
CXFA_Font::IsBold
bool IsBold()
Definition
cxfa_font.cpp:117
CXFA_Font::GetUnderline
int32_t GetUnderline()
Definition
cxfa_font.cpp:99
CXFA_Font::GetLineThrough
int32_t GetLineThrough()
Definition
cxfa_font.cpp:95
CXFA_Font::~CXFA_Font
~CXFA_Font() override
CXFA_Font::GetLetterSpacing
float GetLetterSpacing()
Definition
cxfa_font.cpp:87
CXFA_Font::GetHorizontalScale
float GetHorizontalScale()
Definition
cxfa_font.cpp:75
CXFA_Font::GetFontSize
float GetFontSize() const
Definition
cxfa_font.cpp:109
CXFA_Font::SetColor
void SetColor(FX_ARGB color)
Definition
cxfa_font.cpp:126
CXFA_Font::GetUnderlinePeriod
XFA_AttributeValue GetUnderlinePeriod()
Definition
cxfa_font.cpp:103
CXFA_Measurement
Definition
cxfa_measurement.h:13
CXFA_Measurement::GetValue
float GetValue() const
Definition
cxfa_measurement.h:27
CXFA_Measurement::ToUnit
float ToUnit(XFA_Unit eUnit) const
Definition
cxfa_measurement.cpp:78
CXFA_Measurement::GetUnit
XFA_Unit GetUnit() const
Definition
cxfa_measurement.h:26
CXFA_Node
Definition
cxfa_node.h:94
FX_ARGB
uint32_t FX_ARGB
Definition
fx_dib.h:36
XFA_Unit
XFA_Unit
Definition
fxfa_basic.h:91
XFA_Unit::Em
@ Em
Definition
fxfa_basic.h:93
XFA_Unit::Pt
@ Pt
Definition
fxfa_basic.h:94
XFA_AttributeType
XFA_AttributeType
Definition
fxfa_basic.h:83
XFA_AttributeType::Measure
@ Measure
Definition
fxfa_basic.h:88
XFA_AttributeType::Integer
@ Integer
Definition
fxfa_basic.h:87
XFA_AttributeType::Enum
@ Enum
Definition
fxfa_basic.h:84
XFA_AttributeType::CData
@ CData
Definition
fxfa_basic.h:85
XFA_Attribute
XFA_Attribute
Definition
fxfa_basic.h:67
XFA_Element
XFA_Element
Definition
fxfa_basic.h:75
XFA_AttributeValue
XFA_AttributeValue
Definition
fxfa_basic.h:60
XFA_PacketType
XFA_PacketType
Definition
fxfa_basic.h:44
CXFA_Node::AttributeData
Definition
cxfa_node.h:110
CXFA_Node::PropertyData
Definition
cxfa_node.h:96
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
xfa
fxfa
parser
cxfa_font.cpp
Generated on
for Qt by
1.18.0