11#ifndef OPEN_FONT_RENDER_H
12#define OPEN_FONT_RENDER_H
104 typedef struct FaceRec_ {
133#define setDrawPixel(F) set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { return F(x, y, c); })
149#define setDrawFastHLine(F) set_drawFastHLine([&](int32_t x, int32_t y, int32_t w, uint16_t c) { return F(x, y, w, c); })
160#define setStartWrite(F) set_startWrite([&](void) { return F(); })
171#define setEndWrite(F) set_endWrite([&](void) { return F(); })
181#define setPrintFunc(F) set_printFunc([&](const char *s) { return F(s); })
200 void seekCursor(int32_t delta_x, int32_t delta_y);
204 void setFontColor(uint16_t font_color, uint16_t font_bgcolor);
226 void setCacheSize(
unsigned int max_faces,
unsigned int max_sizes,
unsigned long max_bytes);
228 FT_Error
loadFont(
const unsigned char *data,
size_t size, uint8_t target_face_index = 0);
229 FT_Error
loadFont(
const char *fpath, uint8_t target_face_index = 0);
244 uint16_t fg = 0xFFFF,
245 uint16_t bg = 0x0000,
246 Align align = Align::Left);
250 uint16_t fg = 0xFFFF,
251 uint16_t bg = 0x0000,
252 Layout layout = Layout::Horizontal);
256 uint16_t fg = 0xFFFF,
257 uint16_t bg = 0x0000,
258 Layout layout = Layout::Horizontal);
262 uint16_t fg = 0xFFFF,
263 uint16_t bg = 0x0000,
264 Layout layout = Layout::Horizontal);
266 uint16_t
printf(
const char *fmt, ...);
267 uint16_t
cprintf(
const char *fmt, ...);
268 uint16_t
rprintf(
const char *fmt, ...);
295 template <
typename T>
297 set_drawPixel([&](int32_t x, int32_t y, uint16_t c) {
return drawer.drawPixel(x, y, c); });
298 set_drawFastHLine([&](int32_t x, int32_t y, int32_t w, uint16_t c) {
return drawer.drawFastHLine(x, y, w, c); });
304 void set_drawPixel(std::function<
void(int32_t, int32_t, uint16_t)> user_func);
318 template <
typename T>
320 set_printFunc([&](
const char *s) {
return output.print(s); });
334 FT_Error
loadFont(
enum OFR::LoadFontFrom from);
335 uint32_t getFontMaxHeight();
336 void draw2screen(FT_BitmapGlyph glyph, uint32_t x, uint32_t y, uint16_t fg, uint16_t bg);
337 uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining);
338 uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
339 uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc);
341 std::function<void(int32_t, int32_t, uint16_t)> _drawPixel;
342 std::function<void(int32_t, int32_t, int32_t, uint16_t)> _drawFastHLine;
343 std::function<void(
void)> _startWrite;
344 std::function<void(
void)> _endWrite;
346 FTC_Manager _ftc_manager;
347 FTC_CMapCache _ftc_cmap_cache;
348 FTC_ImageCache _ftc_image_cache;
350 OFR::FaceRec _face_id;
353 bool enable_optimized_drawing;
354 bool support_vertical;
358 struct CacheParameter {
359 unsigned int max_faces;
360 unsigned int max_sizes;
361 unsigned long max_bytes;
363 struct CacheParameter _cache;
365 struct SavedStateVariables {
366 struct Cursor drawn_bg_point;
367 uint32_t prev_max_font_height;
368 unsigned int prev_font_size;
370 struct SavedStateVariables _saved_state;
372 struct TextParameter {
373 double line_space_ratio;
377 struct Cursor cursor;
382 struct TextParameter _text;
384 uint8_t _debug_level;
OFR_DEBUG_LEVEL
An enumeration for specifying the debug log level.
Definition: OpenFontRender.h:44
@ OFR_RAW
Use for internal.
Definition: OpenFontRender.h:49
@ OFR_INFO
Output some informations.
Definition: OpenFontRender.h:47
@ OFR_ERROR
Output only errors.
Definition: OpenFontRender.h:46
@ OFR_DEBUG
Output character rendering result.
Definition: OpenFontRender.h:48
@ OFR_NONE
No output.
Definition: OpenFontRender.h:45
Layout
An enumeration for specifying the direction in which characters are written.
Definition: OpenFontRender.h:83
@ Vertical
Write from top to bottom.
@ Horizontal
Write from left to right.
BgFillMethod
An enumeration for specifying the background drawing method.
Definition: OpenFontRender.h:74
@ None
Does not fill the background.
@ Minimum
Fill in the smallest area that surrounds each character.
@ Block
Fill in the smallest area that surrounds the string.
Align
An enumeration for specifying the text alignment.
Definition: OpenFontRender.h:56
@ MiddleLeft
The cursor position is considered to be the middle-left of the text box.
@ TopRight
The cursor position is considered to be the top-right corner of the text box.
@ MiddleCenter
The cursor position is considered to be the middle-center of the text box.
@ MiddleRight
The cursor position is considered to be the middle-right of the text box.
@ Center
Alias of "TopCenter".
@ BottomRight
The cursor position is considered to be the bottom-right corner of the text box.
@ TopCenter
The cursor position is considered to be the top-center of the text box.
@ Right
Alias of "TopRight".
@ Left
Alias of "TopLeft".
@ BottomLeft
The cursor position is considered to be the bottom-left corner of the text box.
@ TopLeft
The cursor position is considered to be the top-left corner of the text box.
@ BottomCenter
The cursor position is considered to be the bottom-center of the text box.
Drawing
An enumeration for specifying the whether to draw to screen.
Definition: OpenFontRender.h:91
@ Execute
The drawing process is executed and the screen will be updated.
@ Skip
The drawing process is skiped and the screen will not be updated.
Definition: OpenFontRender.h:183
void set_drawPixel(std::function< void(int32_t, int32_t, uint16_t)> user_func)
static const unsigned char FT_VERSION_STRING_SIZE
Minimum string length for FreeType version.
Definition: OpenFontRender.h:190
static void set_printFunc(std::function< void(const char *)> user_func)
void set_startWrite(std::function< void(void)> user_func)
static const unsigned char CACHE_SIZE_NO_LIMIT
FreeType cache size alias.
Definition: OpenFontRender.h:188
static const unsigned char MINOR_VERSION
Open Font Render library minor version.
Definition: OpenFontRender.h:186
OpenFontRender()
Definition: OpenFontRender.cpp:100
static const unsigned char CREDIT_STRING_SIZE
Minimum string length for FreeType credit.
Definition: OpenFontRender.h:191
void set_endWrite(std::function< void(void)> user_func)
static const unsigned char MAIN_VERSION
Open Font Render library main version.
Definition: OpenFontRender.h:185
void set_drawFastHLine(std::function< void(int32_t, int32_t, int32_t, uint16_t)> user_func)
static const unsigned char CACHE_SIZE_MINIMUM
FreeType cache size alias.
Definition: OpenFontRender.h:189
int32_t getCursorX()
Get current cursor x-coordinate.
Definition: OpenFontRender.cpp:184
int32_t getCursorY()
Get current cursor y-coordinate.
Definition: OpenFontRender.cpp:193
void seekCursor(int32_t delta_x, int32_t delta_y)
Move cursor position.
Definition: OpenFontRender.cpp:203
void setCursor(int32_t x, int32_t y)
Set cursor positions.
Definition: OpenFontRender.cpp:175
unsigned int getFontSize()
Get the current font size.
Definition: OpenFontRender.cpp:308
double setLineSpaceRatio(double line_space_ratio)
Adjusts the width between lines of text.
Definition: OpenFontRender.cpp:319
uint16_t getFontColor()
Get the current text color.
Definition: OpenFontRender.cpp:279
void setBackgroundColor(uint16_t font_bgcolor)
Specify the background color.
Definition: OpenFontRender.cpp:222
uint16_t getBackgroundColor()
Get the current background color.
Definition: OpenFontRender.cpp:288
void setFontColor(uint16_t font_color)
Specify the text color.
Definition: OpenFontRender.cpp:213
void setFontSize(unsigned int pixel)
Set the font size for rendering.
Definition: OpenFontRender.cpp:299
double getLineSpaceRatio()
Get the current line space ratio.
Definition: OpenFontRender.cpp:333
Align getAlignment()
Get the current text alignment.
Definition: OpenFontRender.cpp:397
BgFillMethod getBackgroundFillMethod()
Get the current background fill method.
Definition: OpenFontRender.cpp:354
Layout getLayout()
Get the current direction of text writing.
Definition: OpenFontRender.cpp:376
void setAlignment(Align align)
Set the text alignment.
Definition: OpenFontRender.cpp:387
void setBackgroundFillMethod(BgFillMethod method)
Set the background fill method.
Definition: OpenFontRender.cpp:344
void setLayout(Layout layout)
Set the direction of text writing.
Definition: OpenFontRender.cpp:366
void setDrawer(T &drawer)
Collectively set up screen control functions.
Definition: OpenFontRender.h:296
unsigned int calculateFitFontSize(uint32_t limit_width, uint32_t limit_height, Layout layout, const char *str)
Calculates the maximum font size that will fit the specified string and the specified rectangle.
Definition: OpenFontRender.cpp:1150
unsigned int calculateFitFontSizeFmt(uint32_t limit_width, uint32_t limit_height, Layout layout, const char *fmt,...)
Calculates the maximum font size that will fit the specified format string and the specified rectangl...
Definition: OpenFontRender.cpp:1124
void unloadFont()
Unload font data.
Definition: OpenFontRender.cpp:457
uint16_t printf(const char *fmt,...)
Renders text with format specifier.
Definition: OpenFontRender.cpp:950
uint16_t cprintf(const char *fmt,...)
Renders text as Top-Center with format specifier.
Definition: OpenFontRender.cpp:970
uint16_t drawString(const char *str, int32_t x=0, int32_t y=0, uint16_t fg=0xFFFF, uint16_t bg=0x0000, Layout layout=Layout::Horizontal)
Renders text.
Definition: OpenFontRender.cpp:855
uint16_t rdrawString(const char *str, int32_t x=0, int32_t y=0, uint16_t fg=0xFFFF, uint16_t bg=0x0000, Layout layout=Layout::Horizontal)
Renders text as Top-Right.
Definition: OpenFontRender.cpp:923
FT_BBox calculateBoundingBox(int32_t x, int32_t y, unsigned int font_size, Align align, Layout layout, const char *str)
Calculate text bounding box.
Definition: OpenFontRender.cpp:1040
uint16_t rprintf(const char *fmt,...)
Renders text as Top-Right with format specifier.
Definition: OpenFontRender.cpp:990
FT_Error loadFont(const unsigned char *data, size_t size, uint8_t target_face_index=0)
Load font from memory.
Definition: OpenFontRender.cpp:424
uint16_t cdrawString(const char *str, int32_t x=0, int32_t y=0, uint16_t fg=0xFFFF, uint16_t bg=0x0000, Layout layout=Layout::Horizontal)
Renders text as Top-Center.
Definition: OpenFontRender.cpp:889
uint32_t getTextWidth(const char *fmt,...)
Calculate text width.
Definition: OpenFontRender.cpp:1079
FT_BBox calculateBoundingBoxFmt(int32_t x, int32_t y, unsigned int font_size, Align align, Layout layout, const char *fmt,...)
Calculate text bounding box with format specifier.
Definition: OpenFontRender.cpp:1013
uint16_t drawHString(const char *str, int32_t x, int32_t y, uint16_t fg, uint16_t bg, Align align, Drawing drawing, FT_BBox &abbox, FT_Error &error)
Renders text horizontally.
Definition: OpenFontRender.cpp:485
FT_Error drawChar(char character, int32_t x=0, int32_t y=0, uint16_t fg=0xFFFF, uint16_t bg=0x0000, Align align=Align::Left)
Render single character.
Definition: OpenFontRender.cpp:828
void setCacheSize(unsigned int max_faces, unsigned int max_sizes, unsigned long max_bytes)
Set FreeType cache size.
Definition: OpenFontRender.cpp:410
uint32_t getTextHeight(const char *fmt,...)
Calculate text height.
Definition: OpenFontRender.cpp:1099
void setRenderTaskStackSize(unsigned int stack_size)
Specify the stack size for independent rendering tasks.
Definition: OpenFontRender.cpp:163
void setUseRenderTask(bool enable)
Set whether the rendering task should be performed independently or not.
Definition: OpenFontRender.cpp:150
void showCredit()
Show FreeType credit.
Definition: OpenFontRender.cpp:1226
void getFreeTypeVersion(char *str)
Get using FreeType version text.
Definition: OpenFontRender.cpp:1239
void showFreeTypeVersion()
Show using FreeType version.
Definition: OpenFontRender.cpp:1213
void getCredit(char *str)
Get using FreeType credit text.
Definition: OpenFontRender.cpp:1251
void setDebugLevel(uint8_t level)
Set debug output level.
Definition: OpenFontRender.cpp:1264
static void setSerial(T &output)
Set up serial output control functions.
Definition: OpenFontRender.h:319
Structure for handling cursor position.
Definition: OpenFontRender.h:328
int32_t y
y-coordinate
Definition: OpenFontRender.h:330
int32_t x
x-coordinate
Definition: OpenFontRender.h:329