aboutsummaryrefslogtreecommitdiff
path: root/sys/libfont/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/libfont/test.c')
-rw-r--r--sys/libfont/test.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/sys/libfont/test.c b/sys/libfont/test.c
index bd55f33..7ce9dc0 100644
--- a/sys/libfont/test.c
+++ b/sys/libfont/test.c
@@ -5,25 +5,26 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
-#define W 512
-#define H 128
-#define L 64
+#define DIV 2
+#define W 1920/DIV
+#define H 1080
+#define L H/80
-static char *phrase = "the quick brown";
+static char *phrase = "strlen(info)=000";
int
main()
{
- int i, err;
- float x, dx, scale;
- uchar *bitmap;
+ int i, j, k, err;
+ float x, dx, dy, scale, sx, sy;
+ uchar *bitmap, *work;
font·Info *info;
mmap·Reader fontfile;
- int off, y, ascent, descent, baseln;
+ int w, h, off, y, ascent, descent, baseln;
int adv, lsb, r0[2], r1[2];
err = 0;
- fontfile = mmap·open("/home/nolln/root/data/DejaVuSans.ttf");
+ fontfile = mmap·open("/home/nolln/root/data/Inconsolata-Regular.ttf");
if (!fontfile.len) {
err = 1;
goto end;
@@ -39,16 +40,29 @@ main()
font·vmetrics(info, &ascent, &descent, &baseln);
ascent *= scale;
- x = 0.;
+ x = 0.;
+ dy = 0.;
for (i = 0; i < strlen(phrase); i++) {
dx = x - (float)floor(x);
font·code_hmetrics(info, phrase[i], &adv, &lsb);
- font·code_bitmapbox_subpixel(info, phrase[i], scale, scale, dx, 0, r0, r0+1, r1, r1+1);
+ font·code_bbox_subpixel(info, phrase[i], scale, scale, dx, 0, r0, r0+1, r1, r1+1);
y = ascent + r0[1];
- off = (int)floor(x) + (lsb * scale) + y * W;
+ dy = y - (float)floor(y);
- font·code_fillbitmap_subpixel(info, bitmap+off, r1[0]-r0[0], r1[1]-r0[1], W, scale, scale, dx, 0, phrase[i]);
+ w = r1[0]-r0[0];
+ h = r1[1]-r0[1];
+
+ work = calloc(w*h, sizeof(*bitmap));
+ font·code_fillbitmap_subpixel_prefilter(info, work, w, h, w, scale, scale, dx, 0, 1, 1, &sx, &sy, phrase[i]);
+
+ off = (int)floor(x+sx) + r0[0] + ((int)floor(sy)+y) * W;
+ for (j = 0; j < h; j++) {
+ for (k = 0; k < w; k++) {
+ bitmap[off + W*j + k] += work[k + w*j];
+ }
+ }
+ free(work);
x += scale * adv;
if (phrase[i+1])