summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fonts.c90
1 files changed, 0 insertions, 90 deletions
diff --git a/test/fonts.c b/test/fonts.c
deleted file mode 100644
index cd3b9ff..0000000
--- a/test/fonts.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* Standalone Linux font regression/specimen. See vendor/fonts/README.md. */
-#include "../vendor/text.c"
-#include <assert.h>
-#include <stdio.h>
-
-static unsigned glyphs(PangoLayout *layout) {
- unsigned count = 0;
- PangoLayoutIter *it = pango_layout_get_iter(layout);
- do {
- PangoLayoutRun *run = pango_layout_iter_get_run_readonly(it);
- if (run) count += run->glyphs->num_glyphs;
- } while (pango_layout_iter_next_run(it));
- pango_layout_iter_free(it);
- return count;
-}
-int main(int argc, char **argv) {
- assert(SDL_Init(0));
- SDL_Surface *surface = SDL_CreateSurface(1440, 820, SDL_PIXELFORMAT_ARGB8888);
- SDL_Renderer *r = SDL_CreateSoftwareRenderer(surface);
- assert(r);
- SDL_SetRenderDrawColor(r, 17, 21, 27, 255); SDL_RenderClear(r);
- sk_text_begin_frame(r);
- const char *samples[] = {
- "Go Mono / native shaped text",
- "Pardes / 46.8M accesses / 3.97M calls",
- "0123456789 0x7ffed849acf0 () [] {} <> -> != ==",
- "Latin: cafe\xcc\x81 / café / naïve / fi fl ffi",
- "Greek / Cyrillic: λ → Ω Привет мир",
- "Japanese fallback: 日本語 ひらがな カタカナ",
- "Arabic shaping: العربية لا السلام عليكم",
- "Hebrew bidi: שלום עולם | English 123",
- "Symbols / emoji: ✓ ⌘ ⌥ ⌫ ⌜ ⌟ 😀 ★ ♥",
- "draw.render → body_layer.renderBody → TerminalImages.draw"
- };
- for (unsigned i=0; i<sizeof(samples)/sizeof(*samples); ++i) {
- assert(sk_text_draw(r, 30, 25 + 53*i, i==0?2.2f:1.6f, samples[i], strlen(samples[i]),
- i==0?228:165,i==0?234:178,i==0?242:195,255));
- TextCache *c=cache_for(r);
- assert(pango_layout_get_unknown_glyphs_count(c->layout)==0);
- }
- TextCache *c=cache_for(r);
- assert(sk_text_draw(r,30,575,1.0f,"e\xcc\x81",3,228,234,242,255));
- PangoRectangle combining, plain;
- pango_layout_get_pixel_extents(c->layout,NULL,&combining);
- assert(sk_text_draw(r,50,575,1.0f,"e",1,228,234,242,255));
- pango_layout_get_pixel_extents(c->layout,NULL,&plain);
- assert(combining.width==plain.width);
- assert(sk_text_draw(r,70,575,1.0f,"لا",strlen("لا"),228,234,242,255));
- assert(glyphs(c->layout)==1);
- assert(sk_text_draw(r,120,575,1.0f,"0123456789",10,228,234,242,255));
- PangoRectangle bounds; pango_layout_get_pixel_extents(c->layout,NULL,&bounds);
- assert(bounds.width>=75 && bounds.width<=85 && bounds.height>=13);
- printf("scale 1: 10-digit advance %dpx, line box %dpx\n",bounds.width,bounds.height);
- SDL_Rect clip={30,620,400,30}; SDL_SetRenderClipRect(r,&clip);
- assert(sk_text_draw(r,30,617,1.6f,"Clipping preserves the baseline and glyph edges outside this box",strlen("Clipping preserves the baseline and glyph edges outside this box"),112,183,255,255));
- SDL_SetRenderClipRect(r,NULL);
- assert(sk_text_draw(r,30,680,1.6f,"animated ink",12,240,20,40,255));
- const size_t cached_bytes = c->bytes;
- assert(sk_text_draw(r,30,730,1.6f,"animated ink",12,40,20,240,128));
- assert(c->bytes == cached_bytes); /* Color and opacity reuse the coverage mask. */
- assert(SDL_RenderPresent(r));
- unsigned red_pixels = 0, blue_pixels = 0;
- for (int y=680; y<780; ++y) for (int x=30; x<250; ++x) {
- Uint8 red, green, blue, alpha;
- assert(SDL_ReadSurfacePixel(surface,x,y,&red,&green,&blue,&alpha));
- if (y<710 && red>150 && blue<100) ++red_pixels;
- if (y>=730 && blue>70 && red<70) ++blue_pixels;
- }
- assert(red_pixels>50 && blue_pixels>50);
- if(argc>1) assert(SDL_SavePNG(surface,argv[1]));
- assert(SDL_SetRenderLogicalPresentation(r,720,410,SDL_LOGICAL_PRESENTATION_LETTERBOX));
- assert(fabsf(density(r)-2)<0.01f);
- assert(sk_text_draw(r,10,10,1.0f,"0123456789",10,228,234,242,255));
- pango_layout_get_pixel_extents(c->layout,NULL,&bounds);
- assert(bounds.width>=150 && bounds.width<=170);
- /* Eviction across frames and exhaustion inside one frame both stay bounded. */
- for(unsigned i=0;i<800;i++) {
- if(i%100==0) sk_text_begin_frame(r);
- char text[32]; int n=snprintf(text,sizeof(text),"cache %u",i);
- assert(sk_text_draw(r,0,0,1,text,(size_t)n,255,255,255,255));
- assert(c->bytes<=CACHE_BYTES);
- }
- for(unsigned i=0;i<600;i++) {
- char text[32]; int n=snprintf(text,sizeof(text),"transient %u",i);
- assert(sk_text_draw(r,0,0,1,text,(size_t)n,255,255,255,255));
- assert(c->bytes<=CACHE_BYTES);
- }
- SDL_DestroyRenderer(r); SDL_DestroySurface(surface); SDL_Quit();
- puts("Go Mono, fallback, combining marks, Arabic shaping, 2x DPI, clipping and bounded cache passed");
-}