/* Riproduce la sequenza dell'app Sailfish: sessione, documento con il CSS * extra del guscio, disegno alla densità del telefono. Se qualcosa va in * panico nel motore, qui si vede (panic attraverso il confine C = abort). */ #include #include #include #include "engine.h" static char *leggi(const char *p) { FILE *f = fopen(p, "rb"); if (!f) { fprintf(stderr, "non apro %s\n", p); return NULL; } fseek(f, 0, SEEK_END); long n = ftell(f); fseek(f, 0, SEEK_SET); char *b = malloc((size_t)n + 1); if (fread(b, 1, (size_t)n, f) != (size_t)n) { fclose(f); free(b); return NULL; } b[n] = 0; fclose(f); return b; } int main(int argc, char **argv) { const char *base = argc > 1 ? argv[1] : "."; char html_path[1024], css_path[1024], font[1024]; snprintf(html_path, sizeof html_path, "%s/demo.html", base); snprintf(css_path, sizeof css_path, "%s/demo.css", base); snprintf(font, sizeof font, "%s/fonts/DejaVuSerif.ttf", base); char *html = leggi(html_path); char *css = leggi(css_path); if (!html || !css) { return 2; } /* la stessa sequenza di EngineView */ EngineSession *s = engine_session_new(); EngineDoc *doc = engine_doc_new_session(s, html, css, base, NULL); if (!doc) { fprintf(stderr, "documento non creato\n"); return 3; } printf("documento creato\n"); fflush(stdout); const float scale = 2.5f; EngineImage *img = engine_doc_render(doc, (uint32_t)(540 * scale), (uint32_t)(900 * scale), scale, 1, font, NULL); if (!img) { fprintf(stderr, "disegno fallito\n"); return 4; } printf("disegnato %ux%u error=%s\n", img->width, img->height, img->error ? img->error : "nessuno"); fflush(stdout); /* un clic su un campo, come al tocco */ engine_doc_click(doc, 40.0f, 200.0f); printf("clic fatto\n"); fflush(stdout); engine_image_free(img); engine_doc_free(doc); engine_session_free(s); free(html); free(css); printf("fine\n"); return 0; }