CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Font.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
11
13
19
26
27namespace CeresEngine {
28
29 using Glyph = UInt32;
30
44
49
51 Rect2 bounds;
52
58 Offset2 advance;
59 };
60
84
86
92 class Font : public TResource<Font> {
93 private:
95 void* handle;
96
99
100 public:
103
104 public:
106 ~Font() override;
107
108 public:
112 [[nodiscard]] double getPointSize() const;
113
119 [[nodiscard]] bool isFixedPitch() const;
120
123
126
129
133
140
148
153
154 public:
165
169
170 [[nodiscard]] Rect2 getUV(Glyph aGlyph) const;
171
178
181
188
191
198
201
214
216
217 public:
219
229 void prepareCharacterSet(StringView characterSet, double pointSize, const AffineTransform& transform);
230 };
231
238
266
267} // namespace CeresEngine
A path that consists of straight and curved line segments that you can render.
Definition BezierPath.hpp:46
Path to file or directory.
Definition FilePath.hpp:37
The representation of a font in the engine.
Definition Font.hpp:92
void getAdvancements(const Span< Glyph > &glyphs, TemporaryVector< Size2 > &advancements)
Glyph getGlyph(StringView glyphName) const
Returns the named encoded glyph, or –1 if the receiver contains no such glyph.
Rect2 getBoundingRect(Glyph aGlyph) const
Returns the bounding rectangle for the specified glyph, scaled to the receiver’s size.
UInt32 getNumberOfGlyphs() const
The number of glyphs in the font. Glyphs are numbered starting at 0.
void * handle
Definition Font.hpp:95
Map< Glyph, Rect2 > uvMap
Definition Font.hpp:101
FontRenderingMode getRenderingMode() const
The rendering mode of the font.
FontProperties mProperties
Definition Font.hpp:98
void prepareCharacterSet(StringView characterSet, double pointSize, const AffineTransform &transform)
Prepares the set of characters in characterSet for rendering.
~Font() override
String getFamilyName() const
The family name of the font—for example, "Times" or "Helvetica.".
String getDisplayName() const
The name of the font, including family and face names, to use when displaying the font information to...
SPtr< Texture > image
Definition Font.hpp:102
double getPointSize() const
The point size of the font.
bool isFixedPitch() const
A Boolean value indicating whether all glyphs in the font have the same advancement.
UInt32 getControlGlyph() const
The reserved code for a control glyph.
Size2 getAdvancement(Glyph aGlyph) const
Returns the nominal spacing for the given glyph—the distance the current point moves after showing th...
Vector< Size2 > getPackedAdvancements(const Span< Glyph > &packedGlyphs) const
Returns an array of the advancements for the specified packed glyphs and rendered by the receiver.
Font(const FilePath &fontFile, FontSize size)
BezierPath getPathForGlyph(Glyph glyph) const
Vector< Size2 > getAdvancements(const Span< Glyph > &glyphs) const
Returns an array of the advancements for the specified glyphs rendered by the receiver.
UInt32 getNullGlyph() const
The reserved code for a null glyph.
void getPackedAdvancements(const Span< Glyph > &packedGlyphs, TemporaryVector< Size2 > &packedAdvancements) const
Rect2 getUV(Glyph aGlyph) const
void prepareCharacterSet(StringView characterSet)
FontSize mSize
Definition Font.hpp:94
Vector2 mFontUnitScale
Definition Font.hpp:97
String getFontName() const
The full name of the font, as used in PostScript language code—for example, "Times-Roman" or "Helveti...
void getBoundingRects(const Span< Glyph > &glyphs, TemporaryVector< Rect2 > &boundingRects) const
Vector< Rect2 > getBoundingRects(const Span< Glyph > &glyphs) const
Returns an array of the bounding rectangles for the specified glyphs rendered by the receiver.
Utility template class that can be extended by Resources to automatically implement methods that are ...
Definition Resource.hpp:272
Definition Application.hpp:19
Vector< T, TemporaryAllocator > TemporaryVector
A special Vector that uses a fast temporary allocator.
Definition Vector.hpp:20
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
double FontSize
Definition Font.hpp:85
UInt32 Glyph
Definition Font.hpp:29
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
std::unordered_map< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMap
HashMap is an associative container that contains key-value pairs with unique keys.
Definition Map.hpp:33
std::int32_t Int32
Definition DataTypes.hpp:21
std::uint32_t UInt32
Definition DataTypes.hpp:23
auto transform(Container &container, Transform &&transform)
Returns an iterable object that iterates over the values of the container and applies transform to ev...
Definition Iterator.hpp:436
tcb ::span< T, Extent > Span
Span describes an object that can refer to a contiguous sequence of objects with the first element of...
Definition Span.hpp:708
FontRenderingMode
Definition Font.hpp:31
@ IntegerAdvancementsRenderingMode
Specifies integer advancements rendering mode.
@ DefaultRenderingMode
Determines the actual mode based on the user preference settings.
@ AntialiasedIntegerAdvancementsRenderingMode
Specifies antialiased, integer advancements rendering mode.
@ AntialiasedRenderingMode
Specifies antialiased, floating-point advancements rendering mode.
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::map< Key, T, Compare, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > Map
Map is a sorted associative container that contains key-value pairs with unique keys.
Definition Map.hpp:24
Definition Font.hpp:61
String styleName
Definition Font.hpp:63
double baseline
Definition Font.hpp:79
double ascender
The top y-coordinate, offset from the baseline, of the font’s longest ascender.
Definition Font.hpp:70
double descender
The bottom y-coordinate, offset from the baseline, of the font’s longest descender.
Definition Font.hpp:77
double height
Definition Font.hpp:78
HashMap< Glyph, GlyphProperties > glyphs
Definition Font.hpp:81
String familyName
Definition Font.hpp:62
HashMap< char32_t, Glyph > charCodeToGlyph
Definition Font.hpp:82
Describes a single character in a font of a specific size.
Definition Font.hpp:240
UInt32 width
Width/height of the character in pixels.
Definition Font.hpp:254
float yOffset
Definition Font.hpp:257
float uvWidth
Width/height of the character in texture coordinates.
Definition Font.hpp:251
UInt32 height
Definition Font.hpp:254
float uvHeight
Definition Font.hpp:251
UInt32 characterID
Character ID, corresponding to a Unicode key.
Definition Font.hpp:242
float yAdvance
Definition Font.hpp:260
UInt32 page
Index of the texture the character is located on.
Definition Font.hpp:245
float xAdvance
Determines how much to advance the pen after writing this character, in pixels.
Definition Font.hpp:260
Vector< KerningPair > kerningPairs
Pairs that determine if certain character pairs should be closer or father together.
Definition Font.hpp:264
float xOffset
Offset for the visible portion of the character in pixels.
Definition Font.hpp:257
float uvX
Texture coordinates of the character in the page texture.
Definition Font.hpp:248
float uvY
Definition Font.hpp:248
Describes a single character in a font.
Definition Font.hpp:46
Rect2 bounds
The bounding rectangle for the specified glyph.
Definition Font.hpp:51
UInt32 characterID
Character ID, corresponding to a Unicode key.
Definition Font.hpp:48
Offset2 advance
The nominal spacing for the given glyph—the distance the current point moves after showing the glyph.
Definition Font.hpp:58
Kerning pair representing larger or smaller offset between a specific pair of characters.
Definition Font.hpp:234
UInt32 otherCharId
Definition Font.hpp:235
Int32 amount
Definition Font.hpp:236