roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
smooth_font.h
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4
5#include "font.h"
6#include "roo_backport.h"
7#include "roo_backport/byte.h"
9
10namespace roo_display {
11
12/// Anti-aliased font implementation based on PROGMEM data.
13class SmoothFont : public Font {
14 public:
15 /// Legacy constructor for fonts using `uint8_t` byte data.
16 template <typename U = uint8_t,
17 typename std::enable_if<!std::is_same<U, roo::byte>::value,
18 int>::type = 0>
21
22 /// Construct from PROGMEM font data.
23 SmoothFont(const roo::byte* font_data PROGMEM);
24 void drawHorizontalString(const Surface& s, const char* utf8_data,
25 uint32_t size, Color color) const override;
26
27 void drawGlyph(const Surface& s, char32_t code, FontLayout layout,
28 Color color) const override;
29
31 GlyphMetrics* result) const override;
32
33 int16_t getKerning(char32_t left, char32_t right) const override;
34
36 uint32_t size) const override;
37
40 uint32_t offset,
41 uint32_t max_count) const override;
42
43 private:
44 bool rle() const { return compression_method_ > 0; }
45 int16_t kerning(char32_t left, char32_t right) const;
46
47 friend class GlyphPairIterator;
48
50
51 // Binary-search for the glyph data.
52 const roo::byte* PROGMEM findGlyph(char32_t code) const;
53 const roo::byte* PROGMEM findKernPair(char32_t left, char32_t right) const;
54
55 // Helper methods for drawing glyphs.
56 void drawGlyphModeVisible(DisplayOutput& output, int16_t x, int16_t y,
57 const GlyphMetrics& metrics, bool compressed,
58 const roo::byte* PROGMEM data, const Box& clip_box,
61
62 void drawBordered(DisplayOutput& output, int16_t x, int16_t y,
63 int16_t bgwidth, const Drawable& glyph, const Box& clip_box,
65
66 void drawGlyphModeFill(DisplayOutput& output, int16_t x, int16_t y,
68 bool compressed, const roo::byte* PROGMEM data,
69 int16_t offset, const Box& clip_box, Color color,
71
72 void drawKernedGlyphsModeFill(
74 const GlyphMetrics& left_metrics, bool left_compressed,
75 const roo::byte* PROGMEM left_data, int16_t left_offset,
76 const GlyphMetrics& right_metrics, bool right_compressed,
77 const roo::byte* PROGMEM right_data, int16_t right_offset,
78 const Box& clip_box, Color color, Color bgColor,
80
81 int glyph_count_;
82 int glyph_metadata_size_;
83 int alpha_bits_;
84 int encoding_bytes_;
85 int font_metric_bytes_;
86 int offset_bytes_;
87 int compression_method_;
88 int kerning_pairs_count_;
89 int glyph_kerning_size_;
90 char32_t default_glyph_;
91 int default_space_width_;
92 const roo::byte* glyph_metadata_begin_ PROGMEM;
93 const roo::byte* glyph_kerning_begin_ PROGMEM;
94 const roo::byte* glyph_data_begin_ PROGMEM;
95};
96
97} // namespace roo_display
Axis-aligned integer rectangle.
Definition box.h:12
ARGB8888 color stored as a 32-bit unsigned integer.
Definition color.h:16
The abstraction for drawing to a display.
Definition device.h:15
Interface for objects that can be drawn to an output device.
Definition drawable.h:229
Abstract font interface.
Definition font.h:185
const FontMetrics & metrics() const
Return font metrics.
Definition font.h:188
Per-glyph metrics (bounding box and advance).
Definition font.h:139
Anti-aliased font implementation based on PROGMEM data.
Definition smooth_font.h:13
int16_t getKerning(char32_t left, char32_t right) const override
Return kerning adjustment for a pair of code points.
SmoothFont(const U *font_data PROGMEM)
Legacy constructor for fonts using uint8_t byte data.
Definition smooth_font.h:19
void drawHorizontalString(const Surface &s, const char *utf8_data, uint32_t size, Color color) const override
Draw a UTF-8 string horizontally.
uint32_t getHorizontalStringGlyphMetrics(const char *utf8_data, uint32_t size, GlyphMetrics *result, uint32_t offset, uint32_t max_count) const override
Return metrics for consecutive glyphs in the UTF-8 string.
GlyphMetrics getHorizontalStringMetrics(const char *utf8_data, uint32_t size) const override
Return metrics of the specified UTF-8 string as if it were a single glyph.
bool getGlyphMetrics(char32_t code, FontLayout layout, GlyphMetrics *result) const override
Retrieve glyph metrics for a code point and layout.
void drawGlyph(const Surface &s, char32_t code, FontLayout layout, Color color) const override
Draw a single glyph.
Low-level handle used to draw to an underlying device.
Definition drawable.h:60
Defines 140 opaque HTML named colors.
BlendingMode
Porter-Duff style blending modes.
Definition blending.h:17
FontLayout
Glyph layout direction.
Definition font.h:16
#define PROGMEM
Definition progmem.h:10
Color bgcolor
Definition smooth.cpp:889
BlendingMode blending_mode
Definition smooth.cpp:888
#define const
Definition zconf.h:230