Compare commits
3 Commits
e1082f25cb
...
2ee0eb030e
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ee0eb030e | |||
| 9972fba20f | |||
| 8c95b8dad0 |
@ -94,9 +94,9 @@ pub fn build(b: *std.Build) void {
|
|||||||
|
|
||||||
client.root_module.addImport("freetype", freetype_module);
|
client.root_module.addImport("freetype", freetype_module);
|
||||||
|
|
||||||
client.root_module.addCSourceFile(.{ .file = b.path("src/kb/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
|
client.root_module.addCSourceFile(.{ .file = b.path("vendor/kb_text_shape/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
|
||||||
const kb_text_shape = b.addTranslateC(.{
|
const kb_text_shape = b.addTranslateC(.{
|
||||||
.root_source_file = b.path("src/kb/kb_text_shape.h"),
|
.root_source_file = b.path("vendor/kb_text_shape/kb_text_shape.h"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|||||||
19
vendor/kb_text_shape/LICENSE
vendored
Normal file
19
vendor/kb_text_shape/LICENSE
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
zlib License
|
||||||
|
|
||||||
|
(C) Copyright 2024-2025 Jimmy Lefevre
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
70
vendor/kb_text_shape/README.md
vendored
Normal file
70
vendor/kb_text_shape/README.md
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# kb
|
||||||
|
|
||||||
|
[Single-header](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt) permissively-licensed libraries for C/C++.
|
||||||
|
|
||||||
|
## Libraries
|
||||||
|
|
||||||
|
- [kb\_text\_shape.h](./kb_text_shape.h): Unicode text segmentation and OpenType shaping
|
||||||
|
|
||||||
|
## kb_text_shape.h
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
[kb\_text\_shape.h](./kb_text_shape.h) provides:
|
||||||
|
- ICU-like text segmentation (i.e. breaking Unicode text by direction, line, script, word and grapheme).
|
||||||
|
- Harfbuzz-like text shaping for OpenType fonts, which means it is capable of handling complex script layout and ligatures, among other things.
|
||||||
|
- Font coverage checking: know if a font can display a given string.
|
||||||
|
|
||||||
|
It does **not** handle rasterization. It does **not** handle paragraph layout. It does **not** handle selection and loading of system fonts. It will only help you know which glyphs to display where on a single, infinitely-long line, using the fonts you have provided!
|
||||||
|
|
||||||
|
(See https://www.newroadoldway.com/text1.html for an explanation of the different steps of text processing.)
|
||||||
|
|
||||||
|
For an in-depth usage example, check out [refpad](https://github.com/JimmyLefevre/refpad).
|
||||||
|
|
||||||
|
```c
|
||||||
|
// Yours to provide:
|
||||||
|
void DrawGlyph(kbts_u16 GlyphId, kbts_s32 GlyphOffsetX, kbts_s32 GlyphOffsetY, kbts_s32 GlyphAdvanceX, kbts_s32 GlyphAdvanceY,
|
||||||
|
kbts_direction ParagraphDirection, kbts_direction RunDirection, kbts_script Script, kbts_font *Font);
|
||||||
|
void NextLine(void);
|
||||||
|
void *CreateRenderFont(const char *FontPath);
|
||||||
|
|
||||||
|
void HandleText(kbts_shape_context *Context, const char *Text, kbts_language Language)
|
||||||
|
{
|
||||||
|
kbts_ShapeBegin(Context, KBTS_DIRECTION_DONT_KNOW, Language);
|
||||||
|
kbts_ShapeUtf8(Context, Text, (int)strlen(Text), KBTS_USER_ID_GENERATION_MODE_CODEPOINT_INDEX);
|
||||||
|
kbts_ShapeEnd(Context);
|
||||||
|
|
||||||
|
kbts_run Run;
|
||||||
|
while(kbts_ShapeRun(Context, &Run))
|
||||||
|
{
|
||||||
|
if(Run.Flags & KBTS_BREAK_FLAG_LINE_HARD)
|
||||||
|
{
|
||||||
|
NextLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
kbts_glyph *Glyph;
|
||||||
|
while(kbts_GlyphIteratorNext(&Run.Glyphs, &Glyph))
|
||||||
|
{
|
||||||
|
DrawGlyph(Glyph->Id, Glyph->OffsetX, Glyph->OffsetY, Glyph->AdvanceX, Glyph->AdvanceY,
|
||||||
|
Run.ParagraphDirection, Run.Direction, Run.Script, Run.Font);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Example(void)
|
||||||
|
{
|
||||||
|
kbts_shape_context *Context = kbts_CreateShapeContext(0, 0);
|
||||||
|
kbts_font *FontA = kbts_ShapePushFontFromFile(Context, "NotoSansMyanmar-Regular.ttf", 0);
|
||||||
|
kbts_font *FontB = kbts_ShapePushFontFromFile(Context, "NotoSansArabic-Regular.ttf", 0);
|
||||||
|
|
||||||
|
FontA->UserData = CreateRenderFont("NotoSansMyanmar-Regular.ttf");
|
||||||
|
FontB->UserData = CreateRenderFont("NotoSansArabic-Regular.ttf");
|
||||||
|
|
||||||
|
HandleText(Context, (const char *)u8"یکအမည်မရှိیک", KBTS_LANGUAGE_ARABIC);
|
||||||
|
}
|
||||||
|
```
|
||||||
BIN
vendor/kb_text_shape/images/arabic.png
vendored
Normal file
BIN
vendor/kb_text_shape/images/arabic.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
BIN
vendor/kb_text_shape/images/gunjala_gondi.png
vendored
Normal file
BIN
vendor/kb_text_shape/images/gunjala_gondi.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
vendor/kb_text_shape/images/hindi.png
vendored
Normal file
BIN
vendor/kb_text_shape/images/hindi.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
BIN
vendor/kb_text_shape/images/khmer.png
vendored
Normal file
BIN
vendor/kb_text_shape/images/khmer.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.5 KiB |
BIN
vendor/kb_text_shape/images/myanmar.png
vendored
Normal file
BIN
vendor/kb_text_shape/images/myanmar.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
BIN
vendor/kb_text_shape/images/smallcaps.png
vendored
Normal file
BIN
vendor/kb_text_shape/images/smallcaps.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.5 KiB |
30737
vendor/kb_text_shape/kb_text_shape.h
vendored
Normal file
30737
vendor/kb_text_shape/kb_text_shape.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user