diff --git a/.gitattributes b/.gitattributes index 08ad6c9..b0d74d5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ *.h linguist-language=C +*.css linguist-generated +*.cpp linguist-generated diff --git a/.github/workflows/DOCS.yml b/.github/workflows/DOCS.yml index c8c329b..c8ed6d9 100644 --- a/.github/workflows/DOCS.yml +++ b/.github/workflows/DOCS.yml @@ -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 - diff --git a/.gitignore b/.gitignore index e289fce..c46cf15 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.zip ascii segments +doxfilter html/ latex/ DS_Store diff --git a/Doxyfile b/Doxyfile index 7a4ef6e..cbe338d 100644 --- a/Doxyfile +++ b/Doxyfile @@ -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 = @@ -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 diff --git a/Makefile b/Makefile index e22a986..8bf39b7 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/gly_type_render.h b/gly_type_render.h index 8281f12..028f759 100644 --- a/gly_type_render.h +++ b/gly_type_render.h @@ -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, @@ -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, @@ -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; @@ -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; @@ -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); diff --git a/tools/doxfilter.cpp b/tools/doxfilter.cpp new file mode 100644 index 0000000..6a4fae4 --- /dev/null +++ b/tools/doxfilter.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +int main(int argc, char* argv[]) { + if (argc != 2) { + return 1; + } + + std::string line; + std::ifstream file(argv[1]); + std::stringstream sourcecode; + std::regex pattern_source("@sourcecode"); + std::regex pattern_comments("^(\\/\\*|\\*\\/|\\s\\*)"); + + if (!file.is_open()) { + return 2; + } + + while (std::getline(file, line)) { + if (!std::regex_search(line, pattern_comments)) { + sourcecode << line << std::endl; + } + } + + file.clear(); + file.seekg(0, std::ios::beg); + + while (std::getline(file, line)) { + if (std::regex_search(line, pattern_source)) { + std::cout << "@code\n" << sourcecode.str() << "\n@endcode" << std::endl; + } else { + std::cout << line << std::endl; + } + } + + file.close(); + return 0; +} diff --git a/zeebo.css b/zeebo.css new file mode 100644 index 0000000..fcbdb52 --- /dev/null +++ b/zeebo.css @@ -0,0 +1,26 @@ +#main-nav { + display: none; +} + +.header { + display: none; +} + +.footer { + display: none; +} + +.contents p:first-of-type a:nth-of-type(2) { + display: none; +} + +#doc-content { + max-width: 822px; + margin: 0 auto; +} + +.memitem, .memdoc, dl.reflist dd { + box-shadow: none !important; + -webkit-box-shadow: none !important; + -moz-box-shadow: none !important; +}