Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glyph Shaping #81

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a43f7ce
[wip] integrating harfbuzz and introducing text shaping API
martinfouilleul Oct 22, 2024
debf99e
[wip] implement explicit text run shaping API
martinfouilleul Oct 22, 2024
6cfea0e
move harfbuzz drawFuncs creation to context init
martinfouilleul Oct 22, 2024
673f728
add fill rule attribute and fix fill rule for text
martinfouilleul Oct 22, 2024
c160072
commit test fonts for arabic and japanese
martinfouilleul Oct 22, 2024
b1fe8ac
- Text API: point to/from codepoint index conversions
martinfouilleul Oct 24, 2024
2e25084
[wip] moving fonts and text shaping in a separate tier that can be ha…
martinfouilleul Oct 25, 2024
7ed4b33
[wip] exposing harfbuzz backend to wasm-side via bridged imports
martinfouilleul Oct 29, 2024
7b3fcd3
compute ink bounding box when shaping run
martinfouilleul Oct 30, 2024
7d20155
build harfbuzz as part of platform layer build, embed harfbuzz dylib
martinfouilleul Oct 30, 2024
a38d903
build/bundle harfbuzz on windows
martinfouilleul Oct 30, 2024
d575ed9
fix off by on in oc_glyph_run_find_grapheme_index_greater_or_equal()
martinfouilleul Oct 31, 2024
4d887a7
try fixing os.makedirs(..., exist_ok=True) failing with FileExists ex…
martinfouilleul Oct 31, 2024
9055b2b
run docsite generation (but do not deploy) on PRs to main
martinfouilleul Oct 31, 2024
d6ccae0
add new fill rule and text APIs to api.json
martinfouilleul Oct 31, 2024
0b9f526
add some docstrings to new text API
martinfouilleul Oct 31, 2024
eef9473
remove oc_set_font/oc_set_font_size now that we use font and size exp…
martinfouilleul Oct 31, 2024
e2edfb2
draw ui text box as a single run for now
martinfouilleul Nov 1, 2024
cd4c210
cache fribidi and harfbuzz builds
martinfouilleul Nov 5, 2024
62172b7
fix libfribidi install name on macOS
martinfouilleul Nov 5, 2024
13f537f
try fixing CI build of fribidi
martinfouilleul Nov 5, 2024
88869f7
tmp
martinfouilleul Nov 5, 2024
403434a
tmp
martinfouilleul Nov 5, 2024
b981751
tmp
martinfouilleul Nov 5, 2024
0d5788c
[wip] breaking text into bidi runs. Extract script info from unicode …
martinfouilleul Nov 5, 2024
e9c8834
fix unicode script x macro
martinfouilleul Nov 5, 2024
5f74184
store metrics for glyphs and graphemes in glyph run
martinfouilleul Nov 6, 2024
6c9ff6e
fixed glyph run point to cursor
martinfouilleul Nov 6, 2024
f664682
oc_text_line position to/from codepoint index conversions
martinfouilleul Nov 6, 2024
de53322
replace glyph run API with text line API in UI widgets
martinfouilleul Nov 6, 2024
0ac55cd
update api.json with new text line API
martinfouilleul Nov 6, 2024
290d785
compile fribidi on Windows as part of platform layer build
martinfouilleul Nov 6, 2024
d8b9c95
update tool on windows
martinfouilleul Nov 6, 2024
7defa20
fix wasm bridging of oc_glyph_run
martinfouilleul Nov 6, 2024
715be29
reverse script runs produced by splitting RTL segments
martinfouilleul Nov 7, 2024
bb486e5
[wip] map of logical to graphical glyph runs order
martinfouilleul Nov 11, 2024
c3c7a7d
[wip] tweaking example
martinfouilleul Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/build-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ jobs:
with:
python-version: '3.10'

- name: install autotools
run: |
brew install autoconf automake libtool

- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
Expand Down Expand Up @@ -122,6 +126,10 @@ jobs:
with:
python-version: '3.10'

- name: install autotools
run: |
brew install autoconf automake libtool

- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build-doc-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -31,6 +35,7 @@ jobs:
path: "./doc/mkdocs/site"

deploy:
if: ${{ github.ref_name == 'main'}}
runs-on: ubuntu-latest
needs: build

Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ scripts/files
# explicitly abandon old ext dir
/ext
src/ext/angle
src/ext/harfbuzz
src/ext/fribidi

sketches/*/bin

Expand All @@ -60,4 +62,6 @@ src/ext/curl/winbuild/*.idb
src/ext/zlib/build/

doc/mkdocs/docs/api
doc/mkdocs/mkdocs.yml
doc/mkdocs/mkdocs.yml

.clocignore
1 change: 1 addition & 0 deletions deps/fribidi-commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
68162babff4f39c4e2dc164a5e825af93bda9983
1 change: 1 addition & 0 deletions deps/harfbuzz-commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
825bc1964374eed7d19ffa327989d0ee841dda71
19 changes: 4 additions & 15 deletions samples/breakout/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,7 @@ ORCA_EXPORT void oc_on_init(void)
oc_log_error("couldn't load ball image\n");
}

oc_unicode_range ranges[5] = {
OC_UNICODE_BASIC_LATIN,
OC_UNICODE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT,
OC_UNICODE_LATIN_EXTENDED_A,
OC_UNICODE_LATIN_EXTENDED_B,
OC_UNICODE_SPECIALS
};

font = oc_font_create_from_path(OC_STR8("/Literata-SemiBoldItalic.ttf"), 5, ranges);
font = oc_font_create_from_path(OC_STR8("/Literata-SemiBoldItalic.ttf"));
}

ORCA_EXPORT void oc_on_terminate(void)
Expand Down Expand Up @@ -437,13 +429,11 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
oc_circle_fill(r.x + r.w / 2, r.y + r.h / 2, r.h / 2.5);

oc_set_color_rgba(0, 0, 0, 1);
oc_set_font(font);
oc_set_font_size(18);

oc_move_to(textPos.x, textPos.y);
oc_matrix_multiply_push(flip_y_at(textPos));
{
oc_text_outlines(text);
oc_fill();
oc_text_draw_utf8(text, font, 18);
}
oc_matrix_pop();
}
Expand All @@ -465,8 +455,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
oc_matrix_multiply_push(flip_y_at(textPos));
{
oc_set_color_rgba(0.9, 0.9, 0.9, 1);
oc_text_outlines(text);
oc_fill();
oc_text_draw_utf8(text, font, 18);
}
oc_matrix_pop();
}
Expand Down
36 changes: 25 additions & 11 deletions samples/clock/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
**************************************************************************/
#include <math.h>
#include <orca.h>
#include <fribidi/include/fribidi.h>

const oc_str8 clockNumberStrings[] = {
OC_STR8_LIT("12"),
Expand Down Expand Up @@ -46,15 +47,29 @@ ORCA_EXPORT void oc_on_init(void)
surface = oc_canvas_surface_create(renderer);
context = oc_canvas_context_create();

oc_unicode_range ranges[5] = {
OC_UNICODE_BASIC_LATIN,
OC_UNICODE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT,
OC_UNICODE_LATIN_EXTENDED_A,
OC_UNICODE_LATIN_EXTENDED_B,
OC_UNICODE_SPECIALS
};
font = oc_font_create_from_path(OC_STR8("/segoeui.ttf"));

font = oc_font_create_from_path(OC_STR8("/segoeui.ttf"), 5, ranges);
////////////////////////////////
const char* text = "bahrain مصر kuwait";

oc_arena_scope scratch = oc_scratch_begin();
oc_str32 codepoints = oc_utf8_push_to_codepoints(scratch.arena, OC_STR8(text));

FriBidiParType baseDir = FRIBIDI_TYPE_LTR_VAL;
FriBidiLevel levels[256];

fribidi_log2vis(codepoints.ptr,
codepoints.len,
&baseDir,
0, 0, 0,
levels);

for(u64 i = 0; i < codepoints.len; i++)
{
oc_log_info("%i\n", levels[i]);
}

oc_scratch_end(scratch);
}

ORCA_EXPORT void oc_on_resize(u32 width, u32 height)
Expand Down Expand Up @@ -93,8 +108,6 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
const f32 uiScale = clockRadius / DEFAULT_CLOCK_RADIUS;

const f32 fontSize = 26 * uiScale;
oc_set_font(font);
oc_set_font_size(fontSize);

// clock backing
oc_set_color_rgba(1, 1, 1, 1);
Expand All @@ -113,7 +126,8 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
oc_vec2 pos = oc_mat2x3_mul(transform, (oc_vec2){ clockRadius * 0.8f, 0 });

oc_set_color_srgba(0.2, 0.2, 0.2, 1);
oc_text_fill(pos.x, pos.y, clockNumberStrings[i]);
oc_move_to(pos.x, pos.y);
oc_text_draw_utf8(clockNumberStrings[i], font, fontSize);
}

// hours hand
Expand Down
7 changes: 1 addition & 6 deletions samples/ui/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ ORCA_EXPORT void oc_on_init(void)
char* buffer = (char*)oc_arena_push(scratch.arena, size);
oc_file_read(file, size, buffer);
oc_file_close(file);
oc_unicode_range ranges[5] = { OC_UNICODE_BASIC_LATIN,
OC_UNICODE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT,
OC_UNICODE_LATIN_EXTENDED_A,
OC_UNICODE_LATIN_EXTENDED_B,
OC_UNICODE_SPECIALS };

*fonts[i] = oc_font_create_from_memory(oc_str8_from_buffer(size, buffer), 5, ranges);
*fonts[i] = oc_font_create_from_memory(oc_str8_from_buffer(size, buffer));

oc_scratch_end(scratch);
}
Expand Down
7 changes: 5 additions & 2 deletions scripts/bindgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def bindgen(apiName, spec, **kwargs):
elif retTag == 'S':
s += '*__retPtr = '
elif retTag == 'p':
printError(name + ": pointer return type not supported yet")
s += '*((oc_wasm_addr*)&_returns[0]) = '

s += cname + '('

Expand Down Expand Up @@ -286,7 +286,10 @@ def bindgen(apiName, spec, **kwargs):
return_types = '\t\toc_wasm_valtype returnTypes[1];\n\n'
else:
return_types = '\t\toc_wasm_valtype returnTypes[] = {'
return_types += tag_to_valtype(decl['ret']['tag'], name)
tag = decl['ret']['tag']
if tag == 'p':
tag = 'i'
return_types += tag_to_valtype(tag, name)
return_types += '};\n\n'

s += '\t{\n'
Expand Down
Loading
Loading