forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFont.h
More file actions
151 lines (110 loc) · 2.8 KB
/
Font.h
File metadata and controls
151 lines (110 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// Font.h
//
// $Id: //poco/Main/PDF/include/Poco/PDF/Font.h#4 $
//
// Library: PDF
// Package: PDFCore
// Module: Font
//
// Definition of the Font class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef PDF_Font_INCLUDED
#define PDF_Font_INCLUDED
#include "Poco/PDF/PDF.h"
#include "Poco/PDF/Resource.h"
namespace Poco {
namespace PDF {
class PDF_API Font: public Resource<HPDF_Font>
/// Font class represents font resource.
{
public:
Font(HPDF_Doc* pPDF, const HPDF_Font& resource);
/// Creates the font.
~Font();
/// Destroys the font.
std::string encodingName() const;
/// Returns the name of the encoding.
int unicodeWidth(Poco::UInt16 ch) const;
/// Returns the screen width of 16-bit Unicode character.
Rectangle boundingBox() const;
/// Returns the font's bounding box.
int ascent() const;
/// Returns the vertical ascent of the font.
int descent() const;
/// Returns the vertical ascent of the font.
int lowerHeight() const;
/// Returns the distance from the baseline of lowercase letters.
int upperHeight() const;
/// Returns the distance from the baseline of uppercase letters.
TextWidth textWidth(const std::string& text);
/// Returns total width of the text, number of characters and number of the words.
int measureText(const std::string& text,
float width,
float fontSize,
float charSpace,
float wordSpace,
bool wordWrap);
/// Calculates the byte length which can be included within the specified width.
};
//
// inlines
//
inline std::string Font::encodingName() const
{
return HPDF_Font_GetEncodingName(handle());
}
inline int Font::unicodeWidth(Poco::UInt16 ch) const
{
return HPDF_Font_GetUnicodeWidth(handle(), ch);
}
inline Rectangle Font::boundingBox() const
{
return HPDF_Font_GetBBox(handle());
}
inline int Font::ascent() const
{
return HPDF_Font_GetAscent(handle());
}
inline int Font::descent() const
{
return HPDF_Font_GetDescent(handle());
}
inline int Font::lowerHeight() const
{
return static_cast<int>(HPDF_Font_GetXHeight(handle()));
}
inline int Font::upperHeight() const
{
return static_cast<int>(HPDF_Font_GetCapHeight(handle()));
}
inline TextWidth Font::textWidth(const std::string& text)
{
return HPDF_Font_TextWidth(handle(),
reinterpret_cast<const HPDF_BYTE*>(text.data()),
static_cast<HPDF_UINT>(text.size()));
}
inline int Font::measureText(const std::string& text,
float width,
float fontSize,
float charSpace,
float wordSpace,
bool wordWrap)
{
return static_cast<int>(HPDF_Font_MeasureText(handle(),
reinterpret_cast<const HPDF_BYTE*>(text.data()),
static_cast<HPDF_UINT>(text.size()),
width,
fontSize,
charSpace,
wordSpace,
wordWrap,
0));
}
} } // namespace Poco::PDF
#endif // PDF_Font_INCLUDED