38 if (!
mValid)
return metrics;
48 &metrics.
x0, &metrics.
y0,
49 &metrics.
x1, &metrics.
y1
61 if (!
mValid)
return metrics;
71 &metrics.
x0, &metrics.
y0,
72 &metrics.
x1, &metrics.
y1
79 i32
getKerning(i32 codepoint1, i32 codepoint2)
const override {
89 i32 oversampleX, i32 oversampleY)
const override {
93 if (oversampleX <= 1 && oversampleY <= 1) {
102 size_t size =
static_cast<size_t>(
result.width) *
static_cast<size_t>(
result.height);
104 for (
size_t i = 0; i < size; ++i) {
105 result.data[i] = bitmap[i];
113 scale *
static_cast<float>(oversampleX),
114 scale *
static_cast<float>(oversampleY),
123 i32 finalWidth = (
result.width + oversampleX - 1) / oversampleX;
124 i32 finalHeight = (
result.height + oversampleY - 1) / oversampleY;
127 static_cast<size_t>(finalWidth) *
static_cast<size_t>(finalHeight)
130 for (i32
y = 0;
y < finalHeight; ++
y) {
131 for (i32
x = 0;
x < finalWidth; ++
x) {
135 for (i32 oy = 0; oy < oversampleY; ++oy) {
136 i32 srcY =
y * oversampleY + oy;
137 if (srcY >=
result.height)
break;
139 for (i32 ox = 0; ox < oversampleX; ++ox) {
140 i32 srcX =
x * oversampleX + ox;
141 if (srcX >=
result.width)
break;
143 sum += bitmap[srcY *
result.width + srcX];
148 result.data[
y * finalWidth +
x] =
static_cast<u8>(
149 count > 0 ? sum / count : 0
154 result.width = finalWidth;
155 result.height = finalHeight;
180 return load(fontData, 0);
185 if (!impl->isValid()) {
213 return render(codepoint, 2, 2);
218 return mFont->renderGlyph(codepoint,
mScale, oversampleX, oversampleY);
222 return render(codepoint, 1, 1);
226 if (!
mFont)
return 0.0f;
232 if (!
mFont)
return 0.0f;
233 return static_cast<float>(
mFont->getKerning(codepoint1, codepoint2)) *
mScale;
237 if (!str || !
mFont)
return 0.0f;
245 i32 prevCodepoint = 0;
247 for (
size_t i = 0; i < str.
size(); ++i) {
248 i32 codepoint =
static_cast<i32
>(
static_cast<unsigned char>(str[i]));
251 if (prevCodepoint != 0) {
257 prevCodepoint = codepoint;
fl::UISlider scale("Scale", 4,.1, 4,.1)
Font() FL_NOEXCEPT=default
static fl::shared_ptr< Font > load(fl::span< const u8 > fontData)
static fl::shared_ptr< Font > loadDefault()
i32 getNumFonts() const override
~FontImpl() FL_NOEXCEPT override=default
i32 getKerning(i32 codepoint1, i32 codepoint2) const override
GlyphBitmap renderGlyph(i32 codepoint, float scale, i32 oversampleX, i32 oversampleY) const override
float getScaleForPixelHeight(float pixelHeight) const override
third_party::truetype::stbtt_fontinfo mFontInfo
fl::vector< u8 > mFontData
const third_party::truetype::stbtt_fontinfo & getFontInfo() const
GlyphMetrics getGlyphMetrics(i32 codepoint) const override
GlyphBitmap renderGlyph(i32 codepoint, float scale) const override
FontMetrics getMetrics() const override
FontImpl(fl::span< const u8 > fontData, i32 fontIndex=0)
GlyphBitmap render(i32 codepoint) const
float measureString(const char *str) const
FontRenderer(FontPtr font, float pixelHeight)
~FontRenderer() FL_NOEXCEPT
float getKerning(i32 codepoint1, i32 codepoint2) const
float pixelHeight() const
GlyphBitmap renderNoAA(i32 codepoint) const
float getAdvance(i32 codepoint) const
ScaledMetrics getScaledMetrics() const
constexpr bool empty() const FL_NOEXCEPT
constexpr fl::size size() const FL_NOEXCEPT
void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int32_t codepoint, int32_t *advanceWidth, int32_t *leftSideBearing) FL_NOEXCEPT
int32_t stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int32_t ch1, int32_t ch2) FL_NOEXCEPT
float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels) FL_NOEXCEPT
void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int32_t *x0, int32_t *y0, int32_t *x1, int32_t *y1) FL_NOEXCEPT
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_GetFontVMetrics(const stbtt_fontinfo *info, int32_t *ascent, int32_t *descent, int32_t *lineGap) 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
int32_t stbtt_GetNumberOfFonts(const unsigned char *data) FL_NOEXCEPT
int32_t stbtt_GetCodepointBox(const stbtt_fontinfo *info, int32_t codepoint, int32_t *x0, int32_t *y0, int32_t *x1, int32_t *y1) FL_NOEXCEPT
int32_t stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int32_t offset) FL_NOEXCEPT
int32_t stbtt_GetFontOffsetForIndex(const unsigned char *data, int32_t index) FL_NOEXCEPT
fl::span< const u8 > covenant5x5()
fl::shared_ptr< Font > FontPtr
constexpr T * begin(T(&array)[N]) FL_NOEXCEPT
size_t strlen(const char *s) FL_NOEXCEPT
constexpr T * end(T(&array)[N]) FL_NOEXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
Base definition for an LED controller.