Skip to content

Commit

Permalink
feat: revision 0.1 (#7)
Browse files Browse the repository at this point in the history
* feat: custom int type
* fix: uppercase #3
* feat: add GLY_TYPE_SAFE
* docs: improve manual
  • Loading branch information
RodrigoDornelles authored Nov 10, 2024
1 parent 4fab8ff commit d944626
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.h linguist-language=C
*.css linguist-generated
*.cpp linguist-generated
6 changes: 6 additions & 0 deletions .github/workflows/DOCS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ jobs:
steps:
-
uses: actions/checkout@master
-
run: |
make doxfilter
-
run: |
docker run --rm -v $(pwd):/app -w /app rodrigodornelles/doxygen doxygen
- run: |
sudo rm html/index.html
sudo mv html/gly__type__render_8h.html html/index.html
-
uses: actions/configure-pages@v3
-
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.zip
ascii
segments
doxfilter
html/
latex/
DS_Store
Expand Down
26 changes: 13 additions & 13 deletions Doxyfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "GlyType"
PROJECT_NUMBER = 0.0.7
PROJECT_NUMBER = 0.1
PROJECT_BRIEF = "a ultra lightweight font renderer and font"
PROJECT_LOGO =
OUTPUT_DIRECTORY = .
RECURSIVE = YES
RECURSIVE = NO
CREATE_SUBDIRS = NO
STRIP_CODE_COMMENTS = NO
CALL_GRAPH = YES
HAVE_DOT = YES
EXTRACT_ALL = YES
USE_MATHJAX = YES
EXTRACT_STATIC = YES
CALL_GRAPH = NO
HAVE_DOT = NO
EXTRACT_ALL = NO
USE_MATHJAX = NO
EXTRACT_STATIC = NO
SHORT_NAMES = NO
OPTIMIZE_OUTPUT_FOR_C = YES
INLINE_GROUPED_CLASSES = YES
INLINE_SIMPLE_STRUCTS = YES
TYPEDEF_HIDES_STRUCT = YES
INLINE_GROUPED_CLASSES = NO
INLINE_SIMPLE_STRUCTS = NO
TYPEDEF_HIDES_STRUCT = NO
SOURCE_BROWSER = NO
VERBATIM_HEADERS = NO
REPEAT_BRIEF = NO
PREDEFINED = DOXYGEN=
INPUT_FILTER = ./doxfilter
PLANTUML_JAR_PATH = $(PLANTUML_JAR_PATH)
PLANTUML_CFG_FILE =
PLANTUML_INCLUDE_PATH =
Expand All @@ -29,9 +30,8 @@ FILE_PATTERNS = *.c *.h
EXTENSION_MAPPING = h=c
INPUT = gly_type_render.h
MARKDOWN_ID_STYLE = GITHUB
# Theme: https://jothepro.github.io/doxygen-awesome-css/
GENERATE_TREEVIEW = YES
GENERATE_TREEVIEW = NO
DISABLE_INDEX = NO
FULL_SIDEBAR = NO
HTML_EXTRA_STYLESHEET = $(DOXYGEN_AWESOME_PATH)/doxygen-awesome.css
HTML_EXTRA_STYLESHEET = zeebo.css
HTML_COLORSTYLE = LIGHT
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
all: segments ascii
@

doxfilter: tools/doxfilter.cpp
$(CXX) -I. -o $@ $< -static

ascii: tools/ascii.c gly_type_render.h
$(CC) -I. -o $@ tools/ascii.c

Expand Down
106 changes: 85 additions & 21 deletions gly_type_render.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* @file gly_type_render.h
* @short GlyType Renderer
* @short gly_type_render.h
* @brief a ultra lightweight font renderer and font
* @date 2024
* @version 0.0.7
* @version 0.1
* @author RodrigoDornelles
* @copyright
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
* as published by Sam Hocevar. @n See http://www.wtfpl.net/ for more details.
*
* @par Style
* The font style is inspired by digital displays, but not outdated,
Expand Down Expand Up @@ -43,36 +43,94 @@
* EEDDDDDDDDDDCC
* EDDDDDDDDDDDDC
* @endcode
*
* @par Source Code
*
* @sourcecode
*/

#ifndef H_GLY_TYPE_RENDER
#define H_GLY_TYPE_RENDER

#ifndef GLY_TYPE_INT
/**
* The @c GLY_TYPE_INT defines the integer type used for coordinates and sizes
* in @ref gly_type_render.
*
* @li @c int but size varies by compiler/architecture. Common in rendering
* libraries.
* @li @c uint8_t suitable for small screens or limited coordinate ranges.
* @li @c uint16_t often ideal for most cases, balancing range and
* memory efficiency.
*
* @par
* @code
* #define GLY_TYPE_INT uint16_t // Recommended for most applications
* @endcode
*/
#define GLY_TYPE_INT unsigned char
#endif

#ifdef DOXYGEN
/**
* @details
* The @c GLY_TYPE_SAFE macro enables a length parameter to ensure safe string
* handling in the @ref gly_type_render function. When defined, it activates an
* additional check to limit the number of processed characters, preventing
* access beyond the string's end.
*/
#define GLY_TYPE_SAFE
#endif

/**
* @param [in] x in pixels
* @param [in] y in pixels
* @param [in] size in pixels
* @param [in] text with null char terminator
* @param [in] fptr clojure to drawn line with interface:
* @n `function(x1, y1, x2, y2)`
*
* @par Total Size
* @li @b width `length(text) * (size+1)`
* @li @b height `min(count(text, 0x0A), 1) * (size+1)`
*
* @par Example
* gly_type_render
*
* The `gly_type_render` function is used to render text at specified
* coordinates using a line-drawing function. It employs segments to display
* characters and allows control over the position and size of the rendered
* characters.
*
* @pre If the optional @c len parameter is used,
* @ref GLY_TYPE_SAFE must be defined with `#define GLY_TYPE_SAFE` prior to
* including this function.
*
* @param [in] x Horizontal coordinate (in pixels).
* @param [in] y Vertical coordinate (in pixels).
* @param [in] size Character size in pixels.
* @param [in] text Text string to be rendered, terminated with a null
* character (`\0`).
* @param [in] fptr Pointer to a line-drawing function, with the interface:
* `function(x1, y1, x2, y2)`
* @n draws a line from `(x1, y1)` to `(x2, y2)`.
*
* Optional Parameter:
* @param [in] len Maximum length of characters to process, applicable only
* if `GLY_TYPE_SAFE` is defined. If `len` is -1, all characters in the string
* are processed until the null terminator.
*
* Total Size:
* @li Width: `length(text) * (size + 1)`
* @li Height: `min(count(text, 0x0A), 1) * (size + 1)`
*
* Example Usage:
* @code
* gly_type_render(x, y, size, "hello world", draw_line_func);
* @endcode
*
* This function will render the text "hello world" at the coordinates `(x, y)`,
* with the specified character size, using `draw_line_func` to draw the lines.
*/
void
gly_type_render(unsigned char x,
unsigned char y,
unsigned char s,
gly_type_render(GLY_TYPE_INT x,
GLY_TYPE_INT y,
GLY_TYPE_INT s,
const char *t,
#ifdef GLY_TYPE_SAFE
signed int len,
#endif
const void *const f) {
const void (*const draw_line)(
unsigned char, unsigned char, unsigned char, unsigned char) = f;
GLY_TYPE_INT, GLY_TYPE_INT, GLY_TYPE_INT, GLY_TYPE_INT) = f;

static const unsigned char number_segments[] = { 0xbf, 0x07, 0x5b, 0x4f,
0x66, 0xec, 0xfc, 0x87,
Expand All @@ -84,7 +142,8 @@ gly_type_render(unsigned char x,
0x6d, 0x81, 0x3e, 0xa2, 0xbe, 0x80, 0xe2, 0x88
};

unsigned char c, sp2, sm1, x1, x2, x3, y1, y2, y3;
unsigned char c;
GLY_TYPE_INT sp2, sm1, x1, x2, x3, y1, y2, y3;

sp2 = s + 2;
sm1 = s - 1;
Expand All @@ -94,6 +153,11 @@ gly_type_render(unsigned char x,
y3 = y1 + sm1;

while (*t) {
#ifdef GLY_TYPE_SAFE
if (len != -1 && len-- <= 0) {
break;
}
#endif
c = (*t | 0x20) - 'a';
x2 = x1 + (sm1 / 2);
x3 = x1 + sm1;
Expand Down Expand Up @@ -136,7 +200,7 @@ gly_type_render(unsigned char x,
} else if (m & 1 || m & (1 << 4)) {
draw_line(x2, y1, x2, y3);
} else {
switch ((*t - 'v' + 1) >> 1) {
switch ((c + 'a' - 'v' + 1) >> 1) {
case 0:
draw_line(x1, y2, x2, y3);
draw_line(x2, y3, x3, y2);
Expand Down
39 changes: 39 additions & 0 deletions tools/doxfilter.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions zeebo.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d944626

Please sign in to comment.