-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: first version of library [a-zA-Z0-9] (#2)
- Loading branch information
1 parent
3fcf51e
commit 4fab8ff
Showing
12 changed files
with
386 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
BasedOnStyle: Mozilla | ||
ColumnLimit: 80 | ||
IndentWidth: 4 | ||
UseTab: Never | ||
--- | ||
Language: Cpp | ||
AllowShortIfStatementsOnASingleLine: Never | ||
BreakBeforeBraces: Attach | ||
AllowShortBlocksOnASingleLine: true | ||
AllowShortCaseLabelsOnASingleLine: true | ||
AllowShortFunctionsOnASingleLine: Inline | ||
DerivePointerAlignment: false | ||
PointerAlignment: Right | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: ci | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
clang-format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
uses: actions/checkout@v2 | ||
- | ||
run: clang-format --dry-run --Werror --verbose gly_type_render.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: docs | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
doxygen: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
uses: actions/checkout@master | ||
- | ||
run: | | ||
docker run --rm -v $(pwd):/app -w /app rodrigodornelles/doxygen doxygen | ||
- | ||
uses: actions/configure-pages@v3 | ||
- | ||
uses: actions/upload-pages-artifact@v2 | ||
with: | ||
path: 'html' | ||
- | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
a.out | ||
*.out | ||
*.exe | ||
*.zip | ||
ascii | ||
segments | ||
html/ | ||
latex/ | ||
DS_Store | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
DOXYFILE_ENCODING = UTF-8 | ||
PROJECT_NAME = "GlyType" | ||
PROJECT_NUMBER = 0.0.7 | ||
PROJECT_BRIEF = "a ultra lightweight font renderer and font" | ||
PROJECT_LOGO = | ||
OUTPUT_DIRECTORY = . | ||
RECURSIVE = YES | ||
CREATE_SUBDIRS = NO | ||
STRIP_CODE_COMMENTS = NO | ||
CALL_GRAPH = YES | ||
HAVE_DOT = YES | ||
EXTRACT_ALL = YES | ||
USE_MATHJAX = YES | ||
EXTRACT_STATIC = YES | ||
SHORT_NAMES = NO | ||
OPTIMIZE_OUTPUT_FOR_C = YES | ||
INLINE_GROUPED_CLASSES = YES | ||
INLINE_SIMPLE_STRUCTS = YES | ||
TYPEDEF_HIDES_STRUCT = YES | ||
SOURCE_BROWSER = NO | ||
VERBATIM_HEADERS = NO | ||
REPEAT_BRIEF = NO | ||
PREDEFINED = DOXYGEN= | ||
PLANTUML_JAR_PATH = $(PLANTUML_JAR_PATH) | ||
PLANTUML_CFG_FILE = | ||
PLANTUML_INCLUDE_PATH = | ||
OUTPUT_LANGUAGE = English | ||
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 | ||
DISABLE_INDEX = NO | ||
FULL_SIDEBAR = NO | ||
HTML_EXTRA_STYLESHEET = $(DOXYGEN_AWESOME_PATH)/doxygen-awesome.css | ||
HTML_COLORSTYLE = LIGHT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
all: segments ascii | ||
@ | ||
|
||
ascii: tools/ascii.c gly_type_render.h | ||
$(CC) -I. -o $@ tools/ascii.c | ||
|
||
segments: tools/segments.c gly_type_render.h | ||
$(CC) -I. -o $@ tools/segments.c | ||
|
||
clear: | ||
rm ascii segments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/** | ||
* @file gly_type_render.h | ||
* @short GlyType Renderer | ||
* @brief a ultra lightweight font renderer and font | ||
* @date 2024 | ||
* @version 0.0.7 | ||
* @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. | ||
* | ||
* @par Style | ||
* The font style is inspired by digital displays, but not outdated, | ||
* with its straight lines and some diagonals, a modernized look, | ||
* and also a nice differentiation between numbers and characters. | ||
* | ||
* @par 7 Segments | ||
* The renderer stores the glyphs as if it were a 7-segment display, | ||
* thus spending only 1 bit for each line, | ||
* which is the trick of being so compact. | ||
* | ||
* The @b 8 bit/segment it is a special line, its size varies, | ||
* from bottom to top it stops when | ||
* it hits the first fixed segment @c G or @c A | ||
* . | ||
* | ||
* There are special characters, which would be @b x , @b v and @b z | ||
* to differentiate them from all other characters, | ||
* they have their own internal rendering function, | ||
* are flagged as segment @c H without segment @c G or @c A | ||
* . | ||
* | ||
* @code | ||
* FAAAAAAAAAAAAB | ||
* FFAAAAAAAAABBB | ||
* FFF........BBB | ||
* FFF........BBB | ||
* FFGGGGGGGGGGBB | ||
* EEGGGGGGGGGGCC | ||
* EEE........CCC | ||
* EEE........CCC | ||
* EEDDDDDDDDDDCC | ||
* EDDDDDDDDDDDDC | ||
* @endcode | ||
*/ | ||
|
||
#ifndef H_GLY_TYPE_RENDER | ||
#define H_GLY_TYPE_RENDER | ||
|
||
/** | ||
* @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 | ||
* @code | ||
* gly_type_render(x, y, size, "hello world", draw_line_func); | ||
* @endcode | ||
*/ | ||
void | ||
gly_type_render(unsigned char x, | ||
unsigned char y, | ||
unsigned char s, | ||
const char *t, | ||
const void *const f) { | ||
const void (*const draw_line)( | ||
unsigned char, unsigned char, unsigned char, unsigned char) = f; | ||
|
||
static const unsigned char number_segments[] = { 0xbf, 0x07, 0x5b, 0x4f, | ||
0x66, 0xec, 0xfc, 0x87, | ||
0xff, 0xef }; | ||
|
||
static const unsigned char alpha_segments[] = { | ||
0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x7d, 0x76, 0x89, | ||
0x1e, 0x30, 0x38, 0xb7, 0x37, 0x3f, 0x73, 0x67, 0xf3, | ||
0x6d, 0x81, 0x3e, 0xa2, 0xbe, 0x80, 0xe2, 0x88 | ||
}; | ||
|
||
unsigned char c, sp2, sm1, x1, x2, x3, y1, y2, y3; | ||
|
||
sp2 = s + 2; | ||
sm1 = s - 1; | ||
x1 = x; | ||
y1 = y; | ||
y2 = y1 + (sm1 / 2); | ||
y3 = y1 + sm1; | ||
|
||
while (*t) { | ||
c = (*t | 0x20) - 'a'; | ||
x2 = x1 + (sm1 / 2); | ||
x3 = x1 + sm1; | ||
if ('0' <= *t && *t <= '9') { | ||
unsigned char m = number_segments[*t - '0']; | ||
unsigned char segment = 0; | ||
while (segment < 8) { | ||
switch (m & (1 << segment) ? segment : 8) { | ||
case 0: draw_line(x2, y1, x3, y1); break; | ||
case 1: draw_line(x3, y1, x3, y2); break; | ||
case 2: draw_line(x3, y2, x3, y3); break; | ||
case 3: draw_line(x1, y3, x3, y3); break; | ||
case 4: draw_line(x1, y2, x1, y3); break; | ||
case 5: draw_line(x1, y1, x1, y2); break; | ||
case 6: draw_line(x1, y2, x3, y2); break; | ||
case 7: draw_line(x1, y1, x2, y1); break; | ||
} | ||
segment++; | ||
} | ||
} | ||
if (c == ('k' - 'a')) { | ||
draw_line(x2, y2, x3, y1); | ||
draw_line(x2, y2, x3, y3); | ||
} | ||
if (c <= ('z' - 'a')) { | ||
unsigned char m = alpha_segments[c]; | ||
unsigned char segment = 0; | ||
while (segment < 8) { | ||
switch (m & (1 << segment) ? segment : 8) { | ||
case 0: draw_line(x1, y1, x3, y1); break; | ||
case 1: draw_line(x3, y1, x3, y2); break; | ||
case 2: draw_line(x3, y2, x3, y3); break; | ||
case 3: draw_line(x1, y3, x3, y3); break; | ||
case 4: draw_line(x1, y2, x1, y3); break; | ||
case 5: draw_line(x1, y1, x1, y2); break; | ||
case 6: draw_line(x1, y2, x3, y2); break; | ||
case 7: { | ||
if (m & (1 << 6)) { | ||
draw_line(x2, y2, x2, y3); | ||
} else if (m & 1 || m & (1 << 4)) { | ||
draw_line(x2, y1, x2, y3); | ||
} else { | ||
switch ((*t - 'v' + 1) >> 1) { | ||
case 0: | ||
draw_line(x1, y2, x2, y3); | ||
draw_line(x2, y3, x3, y2); | ||
break; | ||
case 1: | ||
draw_line(x1, y1, x3, y3); | ||
draw_line(x1, y3, x3, y1); | ||
break; | ||
case 2: | ||
draw_line(x1, y1, x3, y1); | ||
draw_line(x1, y3, x3, y1); | ||
break; | ||
} | ||
} | ||
} | ||
case 8: break; | ||
} | ||
segment++; | ||
} | ||
} | ||
x1 += sp2; | ||
t++; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name = gly type render | ||
version = 0.0.7 | ||
author = Rodrigo Dornelles <[email protected]> | ||
maintainer = Rodrigo Dornelles <[email protected]> | ||
sentence = a ultra lightweight font renderer and font. | ||
paragraph = use this with any GUI interface including TUI. | ||
category = Other | ||
url = https://gamelly.github.io/gly-type | ||
architectures = * | ||
includes = gly_type_render.h |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "gly_type_render.h" | ||
|
||
unsigned int size_by_line; | ||
unsigned char size = 5; | ||
static char* text = "a"; | ||
static char* screen = NULL; | ||
|
||
void draw_line(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2) { | ||
int dx = abs(x2 - x1); | ||
int dy = abs(y2 - y1); | ||
int sx = (x1 < x2) ? 1 : -1; | ||
int sy = (y1 < y2) ? 1 : -1; | ||
int err = dx - dy; | ||
|
||
while (1) { | ||
if (y1 < size && x1 < size_by_line) { | ||
screen[y1 * size_by_line + x1] = '@'; | ||
} | ||
|
||
if (x1 == x2 && y1 == y2) break; | ||
|
||
int err2 = err * 2; | ||
if (err2 > -dy) { | ||
err -= dy; | ||
x1 += sx; | ||
} | ||
if (err2 < dx) { | ||
err += dx; | ||
y1 += sy; | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
if (argc > 1) { | ||
text = argv[1]; | ||
} | ||
if (argc > 2) { | ||
size = strtol(argv[2], NULL, 10); | ||
} | ||
|
||
unsigned int length = strlen(text); | ||
unsigned int skip = length > 1 ? 2 : 0; | ||
size_by_line = length * (skip + size); | ||
unsigned int size_total = size_by_line * size; | ||
|
||
screen = malloc(size_total); | ||
if (!screen) { | ||
perror("Failed to allocate memory"); | ||
return 1; | ||
} | ||
memset(screen, '.', size_total); | ||
|
||
gly_type_render(0, 0, size, text, draw_line); | ||
|
||
for (unsigned char i = 0; i < size; i++) { | ||
printf("%.*s\n", size_by_line - skip, &screen[i * size_by_line]); | ||
} | ||
|
||
free(screen); | ||
return 0; | ||
} |
Oops, something went wrong.