From dbe70eb4f4bf0d3016dbde26064c08eb44947a17 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Fri, 6 Dec 2024 22:03:35 +0100 Subject: [PATCH] added library schrift --- .gitignore | 1 + lib/libschrift.c3l/Makefile | 3 ++ lib/libschrift.c3l/libschrift.c3 | 56 ++++++++++++++++++++++ lib/libschrift.c3l/linux-x64/libschrift.a | Bin 0 -> 19078 bytes lib/libschrift.c3l/manifest.json | 9 ++++ lib/libschrift.c3l/project.json | 45 +++++++++++++++++ lib/libschrift.c3l/thirdparty/libschrift | 1 + project.json | 2 +- src/ugui_data.c3 | 1 + src/ugui_font.c3 | 18 +++++++ test/test_font.c3 | 6 +++ 11 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 lib/libschrift.c3l/Makefile create mode 100644 lib/libschrift.c3l/libschrift.c3 create mode 100644 lib/libschrift.c3l/linux-x64/libschrift.a create mode 100644 lib/libschrift.c3l/manifest.json create mode 100644 lib/libschrift.c3l/project.json create mode 160000 lib/libschrift.c3l/thirdparty/libschrift create mode 100644 src/ugui_font.c3 create mode 100644 test/test_font.c3 diff --git a/.gitignore b/.gitignore index 228cff3..87b38e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o build/* +**/.ccls-cache diff --git a/lib/libschrift.c3l/Makefile b/lib/libschrift.c3l/Makefile new file mode 100644 index 0000000..ff62ec4 --- /dev/null +++ b/lib/libschrift.c3l/Makefile @@ -0,0 +1,3 @@ +all: + make -C thirdparty/libschrift + cp thirdparty/libschrift/libschrift.a linux-x64/libschrift.a diff --git a/lib/libschrift.c3l/libschrift.c3 b/lib/libschrift.c3l/libschrift.c3 new file mode 100644 index 0000000..1b0f24b --- /dev/null +++ b/lib/libschrift.c3l/libschrift.c3 @@ -0,0 +1,56 @@ +module schrift; + +def SftFont = void*; +def SftUChar = uint; +def SftGlyph = uint; + +struct Sft +{ + SftFont font; + double xScale; + double yScale; + double xOffset; + double yOffset; + int flags; +} + +struct SftLMetrics +{ + double ascender; + double descender; + double lineGap; +} + +struct SftGMetrics +{ + double advanceWidth; + double leftSideBearing; + int yOffset; + int minWidth; + int minHeight; +} + +struct SftKerning +{ + double xShift; + double yShift; +} + +struct SftImage +{ + void *pixels; + int width; + int height; +} + +extern fn char* sft_version() @extern("sft_version"); + +extern fn SftFont sft_loadmem(void* mem, usz size) @extern("sft_loadmem"); +extern fn SftFont sft_loadfile(char* filename) @extern("sft_loadfile"); +extern fn void sft_freefont(SftFont font) @extern("sft_freefont"); + +extern fn int sft_lmetrics(Sft* sft, SftLMetrics* metrics) @extern("sft_lmetrics"); +extern fn int sft_lookup(Sft* sft, SftUChar codepoint, SftGlyph* glyph) @extern("sft_lookup"); +extern fn int sft_gmetrics(Sft* sft, SftGlyph glyph, SftGMetrics* metrics) @extern("sft_gmetrics"); +extern fn int sft_kerning(Sft* sft, SftGlyph leftGlyph, SftGlyph rightGlyph, SftKerning* kerning) @extern("sft_kerning"); +extern fn int sft_render(Sft* sft, SftGlyph glyph, SftImage image) @extern("sft_render"); diff --git a/lib/libschrift.c3l/linux-x64/libschrift.a b/lib/libschrift.c3l/linux-x64/libschrift.a new file mode 100644 index 0000000000000000000000000000000000000000..e3a042393ad6f6b4e78e5d729a610b74dd03c1b7 GIT binary patch literal 19078 zcmbt+4|r77weLB}00X9T1{-ZeDua%<6AUo}K@$axRzSe2{pRUj_d*} zZg&)%QI_}PdK*^`t{{zVEzeC8b(>VmsGD_#rLudKexR|9x>F-6AoQx_TW~~xLo$W`dj+{~FjjVNkYANYe zm1oW{0c)4su5>p{3USYI=Ob?n<%{}W@q#Y()#a^6cg?+?KH8t}H7d0#t%_pko} z-ge?my+d*jUNYn+-q(V+-Qev`sO5v9%hbX_%Kb%oG|}r>=2_~g_0;&auWOg6+UvV$ z45`u2U4ht*{@8t1y&qzBCEBg9Q1U8xo~oS-Xs6Wph8(?!T8Xz?@UHAWsC`$mVb5M;~u5kmw(2i z*aJ>0J!+hGdel4NsnZhh!g>J8-SFA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G7Elp7W_9R+-(2sj!W2{-qnI4>f7&HXiicS?lcj7!+zGt)RS>*W9qC9)@7B9Uz=34D?9I&^L( z@Z}s|!Jh(ukiU0i;0gZzNCqzU>rZCjU-9=>GH`Le`L_&QoMW2fSdvMcSC*LKL&6<& zLlW_)kYAivK9xZ)&MOaQ;NrZJeu7F#@Db;gH5s@#mwX}v7w03-W#Hm`-L1 za-rtd#^MO}l~VDl#z>=7yfPe?ibHMmLgemZ>}`!#@hol%N3b2{GMG>*sW~kLB;H*R>a~4`J^aiflqnYO}co|G}kkZL^`u|JU7t+T;RbGq_an z_pkZ56~)|L#4C%L$#fM%h>5Pj$t486UokeetZ|82P0+xoC5M)Mz}0?m~Y7sK^j69!3gSdW6@f z*utDdeetCEbF}&iUf*G^j64sMhn`Kmer7vId3_$14sj8Bi)SmZKSaPYXLCjYeAn`|6vr2=D%h0j2d;EG5K#EE>U0j z?`UmP&7I_!NQ+51B-;Ma`j%OLJg`jP1teMd!gV4;u}u5XHfFT?k9diTB>i{eF?7$Y G|9=4{+1>vD literal 0 HcmV?d00001 diff --git a/lib/libschrift.c3l/manifest.json b/lib/libschrift.c3l/manifest.json new file mode 100644 index 0000000..efb7f23 --- /dev/null +++ b/lib/libschrift.c3l/manifest.json @@ -0,0 +1,9 @@ +{ + "provides" : "schrift", + "targets" : { + "linux-x64" : { + "dependencies" : [], + "linked-libraries" : ["schrift", "c"] + } + } +} diff --git a/lib/libschrift.c3l/project.json b/lib/libschrift.c3l/project.json new file mode 100644 index 0000000..573769f --- /dev/null +++ b/lib/libschrift.c3l/project.json @@ -0,0 +1,45 @@ +{ + // Language version of C3. + "langrev": "1", + // Warnings used for all targets. + "warnings": [ "no-unused" ], + // Directories where C3 library files may be found. + "dependency-search-paths": [ ".." ], + // Libraries to use for all targets. + "dependencies": [ "schrift" ], + // Authors, optionally with email. + "authors": [ "Alessandro Mauri