aboutsummaryrefslogtreecommitdiffstats
path: root/demo.c
diff options
context:
space:
mode:
Diffstat (limited to 'demo.c')
-rw-r--r--demo.c63
1 files changed, 29 insertions, 34 deletions
diff --git a/demo.c b/demo.c
index 9157a5c..062f515 100644
--- a/demo.c
+++ b/demo.c
@@ -11,13 +11,14 @@ main(void)
{
LIBSKRIFT_FONT *font;
LIBSKRIFT_CONTEXT *ctx;
- struct libskrift_glyph *glyph;
+ struct libskrift_image image = {LIBSKRIFT_R8G8B8A8, LIBSKRIFT_HOST_SUBPIXEL, 0, 800, 600, NULL, NULL, NULL};
struct libskrift_rendering rendering = LIBSKRIFT_DEFAULT_RENDERING;
- uint16_t i, x, y;
+ struct libskrift_colour colour = LIBSKRIFT_PREMULTIPLY(1, 1, .80f, .50f, .20f);
double height;
+ size_t size, i;
rendering.smoothing = LIBSKRIFT_SUBPIXEL;
- rendering.subpixel_order = LIBSKRIFT_RGB;
+ rendering.subpixel_order = LIBSKRIFT_NONE;
rendering.flags = 0;
if (libskrift_open_font_file(&font, DEMO_FONT)) {
@@ -31,43 +32,37 @@ main(void)
}
libskrift_close_font(font);
-#if 1
- if (libskrift_get_cluster_glyph(ctx, "x̴̑", NULL, 0, 0, &glyph) < 0) {
- perror("libskrift_get_cluster_glyph");
+ size = 4;
+ size *= (size_t)image.width;
+ size *= (size_t)image.height;
+ image.image = malloc(size);
+ if (!image.image) {
+ perror("malloc");
return -1;
}
-#else
- if (libskrift_get_grapheme_glyph(ctx, 197 /* Å */, 0, 0, &glyph)) {
- perror("libskrift_get_grapheme_glyph");
- return -1;
+ for (i = 0; i < size; i += 4) {
+ ((uint8_t *)image.image)[i + 0] = 32U;
+ ((uint8_t *)image.image)[i + 1] = 48U;
+ ((uint8_t *)image.image)[i + 2] = 64U;
+ ((uint8_t *)image.image)[i + 3] = 192U;
}
-#endif
- if (rendering.smoothing == LIBSKRIFT_GREYSCALE) {
- printf("P2\n%u %u\n255\n", glyph->width, glyph->height);
- printf("# x-position: %i\n", glyph->x);
- printf("# y-position: %i\n", glyph->y);
- printf("# advance: %lf\n", glyph->advance);
- for (i = y = 0; y < glyph->height; y++) {
- for (x = 0; x < glyph->width; x++, i++)
- printf("%3u ", glyph->image[i]);
- printf("\n\n");
- }
- fflush(stdout);
- } else {
- printf("P3\n%u %u\n255\n", glyph->width, glyph->height);
- printf("# x-position: %i\n", glyph->x);
- printf("# y-position: %i\n", glyph->y);
- printf("# advance: %lf\n", glyph->advance);
- for (i = y = 0; y < glyph->height; y++) {
- for (x = 0; x < glyph->width * 3; x++, i++)
- printf("%3u ", glyph->image[i]);
- printf("\n\n");
- }
- fflush(stdout);
+ if (libskrift_draw_text(ctx, "hello world", &colour, 0, 300, &image) < 0) {
+ perror("libskrift_draw_text");
+ return -1;
}
- free(glyph);
+ printf("P7\n");
+ printf("WIDTH %u\n", image.width);
+ printf("HEIGHT %u\n", image.height);
+ printf("DEPTH 4\n");
+ printf("MAXVAL 255\n");
+ printf("TUPLTYPE RGB_ALPHA\n");
+ printf("ENDHDR\n");
+ fwrite(image.image, 1, size, stdout);
+ fflush(stdout);
+
+ free(image.image);
libskrift_free_context(ctx);
return 0;
}