roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
smooth_font_v2.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <type_traits>
5
6#include "font.h"
7#include "roo_backport.h"
8#include "roo_backport/byte.h"
10
11namespace roo_display {
12
13/// Smooth font v2 with split cmap and glyph metrics format.
14class SmoothFontV2 : public Font {
15 public:
16 /// Legacy constructor for fonts using `uint8_t` byte data.
17 template <typename U = uint8_t,
18 typename std::enable_if<!std::is_same<U, roo::byte>::value,
19 int>::type = 0>
22
23 /// Construct from PROGMEM font data.
24 SmoothFontV2(const roo::byte* font_data PROGMEM);
25
26 void drawHorizontalString(const Surface& s, const char* utf8_data,
27 uint32_t size, Color color) const override;
28
29 void drawGlyph(const Surface& s, char32_t code, FontLayout layout,
30 Color color) const override;
31
33 GlyphMetrics* result) const override;
34
35 int16_t getKerning(char32_t left, char32_t right) const override;
36
38 uint32_t size) const override;
39
42 uint32_t offset,
43 uint32_t max_count) const override;
44
45 private:
47 class GlyphMetadataReader;
48 struct CmapEntry {
49 uint16_t range_start;
50 uint16_t range_end;
51 uint16_t glyph_id_offset;
52 uint16_t data_entries_count;
53 uint32_t data_offset;
54 uint8_t format;
55 };
56
57 bool rle() const { return compression_method_ > 0; }
58 int16_t kerning(int left_glyph_index, int right_glyph_index) const;
59 int16_t kerningWithClassFormat(int left_glyph_index,
60 int right_glyph_index) const;
61
62 // Lookup the glyph index in the cmap ranges.
63 int findGlyphIndex(char32_t code) const;
64 const roo::byte* PROGMEM findKernPair(char32_t left, char32_t right) const;
65
66 void drawGlyphModeVisible(DisplayOutput& output, int16_t x, int16_t y,
67 const GlyphMetrics& metrics, bool compressed,
68 const roo::byte* PROGMEM data, const Box& clip_box,
69 Color color, Color bgcolor,
71
72 void drawGlyphModeFill(DisplayOutput& output, int16_t x, int16_t y,
73 int16_t bgwidth, const GlyphMetrics& glyph_metrics,
74 bool compressed, const roo::byte* PROGMEM data,
75 int16_t offset, const Box& clip_box, Color color,
76 Color bgColor, BlendingMode blending_mode) const;
77
78 void drawKernedGlyphsModeFill(
79 DisplayOutput& output, int16_t x, int16_t y, int16_t bgwidth,
80 const GlyphMetrics& left_metrics, bool left_compressed,
81 const roo::byte* PROGMEM left_data, int16_t left_offset,
82 const GlyphMetrics& right_metrics, bool right_compressed,
83 const roo::byte* PROGMEM right_data, int16_t right_offset,
84 const Box& clip_box, Color color, Color bgColor,
86
87 void drawBordered(DisplayOutput& output, int16_t x, int16_t y,
88 int16_t bgwidth, const Drawable& glyph, const Box& clip_box,
89 Color bgColor, BlendingMode blending_mode) const;
90
91 int glyph_count_;
92 int glyph_metadata_size_;
93 int alpha_bits_;
94 int encoding_bytes_;
95 int font_metric_bytes_;
96 int offset_bytes_;
97 int glyph_index_bytes_;
98 int compression_method_;
99 int kerning_pairs_count_;
100 int glyph_kerning_size_;
101 uint8_t kerning_format_;
102 uint16_t kerning_class_count_;
103 uint16_t kerning_source_count_;
104 int kerning_source_index_bytes_;
105 int kerning_class_entries_count_;
106 char32_t default_glyph_;
107 int default_space_width_;
108 const roo::byte* font_begin_ PROGMEM;
109 const roo::byte* cmap_entries_begin_ PROGMEM;
110 const roo::byte* glyph_metadata_begin_ PROGMEM;
111 const roo::byte* glyph_kerning_begin_ PROGMEM;
112 const roo::byte* kerning_source_table_begin_ PROGMEM;
113 const roo::byte* kerning_class_table_begin_ PROGMEM;
114 const roo::byte* kerning_class_entries_begin_ PROGMEM;
115 const roo::byte* glyph_data_begin_ PROGMEM;
116 // Cached for performance; improves glyph lookup speed slightly.
117 int cmap_entries_count_;
118 std::unique_ptr<CmapEntry[]> cmap_entries_;
119};
120
121} // namespace roo_display
ARGB8888 color stored as a 32-bit unsigned integer.
Definition color.h:16
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
Smooth font v2 with split cmap and glyph metrics format.
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.
bool getGlyphMetrics(char32_t code, FontLayout layout, GlyphMetrics *result) const override
Retrieve glyph metrics for a code point and layout.
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.
void drawHorizontalString(const Surface &s, const char *utf8_data, uint32_t size, Color color) const override
Draw a UTF-8 string horizontally.
SmoothFontV2(const U *font_data PROGMEM)
Legacy constructor for fonts using uint8_t byte data.
int16_t getKerning(char32_t left, char32_t right) const override
Return kerning adjustment for a pair of code points.
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