FastLED 3.9.15
Loading...
Searching...
No Matches

◆ renderGlyph() [2/2]

GlyphBitmap fl::FontImpl::renderGlyph ( i32 codepoint,
float scale,
i32 oversampleX,
i32 oversampleY ) const
inlineoverridevirtual

Implements fl::Font.

Definition at line 88 of file truetype.cpp.hpp.

89 {
90 GlyphBitmap result;
91 if (!mValid) return result;
92
93 if (oversampleX <= 1 && oversampleY <= 1) {
94 // Simple rendering without oversampling
96 &mFontInfo, scale, scale, codepoint,
97 &result.width, &result.height,
98 &result.xOffset, &result.yOffset
99 );
100
101 if (bitmap && result.width > 0 && result.height > 0) {
102 size_t size = static_cast<size_t>(result.width) * static_cast<size_t>(result.height);
103 result.data.resize(size);
104 for (size_t i = 0; i < size; ++i) {
105 result.data[i] = bitmap[i];
106 }
108 }
109 } else {
110 // Rendering with oversampling for smoother antialiasing
112 &mFontInfo,
113 scale * static_cast<float>(oversampleX),
114 scale * static_cast<float>(oversampleY),
115 0.0f, 0.0f,
116 codepoint,
117 &result.width, &result.height,
118 &result.xOffset, &result.yOffset
119 );
120
121 if (bitmap && result.width > 0 && result.height > 0) {
122 // Downsample to final size
123 i32 finalWidth = (result.width + oversampleX - 1) / oversampleX;
124 i32 finalHeight = (result.height + oversampleY - 1) / oversampleY;
125
126 result.data.resize(
127 static_cast<size_t>(finalWidth) * static_cast<size_t>(finalHeight)
128 );
129
130 for (i32 y = 0; y < finalHeight; ++y) {
131 for (i32 x = 0; x < finalWidth; ++x) {
132 i32 sum = 0;
133 i32 count = 0;
134
135 for (i32 oy = 0; oy < oversampleY; ++oy) {
136 i32 srcY = y * oversampleY + oy;
137 if (srcY >= result.height) break;
138
139 for (i32 ox = 0; ox < oversampleX; ++ox) {
140 i32 srcX = x * oversampleX + ox;
141 if (srcX >= result.width) break;
142
143 sum += bitmap[srcY * result.width + srcX];
144 ++count;
145 }
146 }
147
148 result.data[y * finalWidth + x] = static_cast<u8>(
149 count > 0 ? sum / count : 0
150 );
151 }
152 }
153
154 result.width = finalWidth;
155 result.height = finalHeight;
156 result.xOffset = result.xOffset / oversampleX;
157 result.yOffset = result.yOffset / oversampleY;
158
160 }
161 }
162
163 return result;
164 }
fl::UISlider scale("Scale", 4,.1, 4,.1)
third_party::truetype::stbtt_fontinfo mFontInfo
unsigned char * stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int32_t codepoint, int32_t *width, int32_t *height, int32_t *xoff, int32_t *yoff) FL_NOEXCEPT
void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata) FL_NOEXCEPT
unsigned char * stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int32_t codepoint, int32_t *width, int32_t *height, int32_t *xoff, int32_t *yoff) FL_NOEXCEPT
unsigned char u8
Definition stdint.h:131
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References mFontInfo, mValid, scale, fl::third_party::truetype::stbtt_FreeBitmap(), fl::third_party::truetype::stbtt_GetCodepointBitmap(), fl::third_party::truetype::stbtt_GetCodepointBitmapSubpixel(), fl::x, and fl::y.

+ Here is the call graph for this function: