/* Copyright (C) 2013-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: hbimgdim.ctr */ /** @file hbimgdim.c The hbimgdim module. */ #line 69 "hbimgdim.ctr" #include "dk3all.h" #include "dk3bif.h" #include "htmlbook.h" #line 78 "hbimgdim.ctr" /** File name suffixes used by SVG files. */ static const dkChar * const svg_suffixes[] = { dkT(".svg"), dkT(".svgz"), NULL }; static int is_svg_file(dkChar const *fn) { const dkChar *psuff = NULL; int back = 0; int ind; #line 97 "hbimgdim.ctr" if (NULL != fn) { psuff = dk3str_get_suffix(fn); if (NULL != psuff) { ind = dk3str_array_index(svg_suffixes, psuff, 0); if (-1 < ind) { back = 1; } } } #line 107 "hbimgdim.ctr" return back; } int hbimgdim_compare(void const *l, void const *r, int cr) { int back = 0; hb_img_dim_t *pl; hb_img_dim_t *pr; #line 119 "hbimgdim.ctr" if(l) { if(r) { pl = (hb_img_dim_t *)l; switch(cr) { case 1: { back = dk3str_fncmp(pl->fn, (dkChar const *)r); } break; default: { pr = (hb_img_dim_t *)r; back = dk3str_fncmp(pl->fn, pr->fn); } break; } if(-1 > back) { back = -1; } if( 1 < back) { back = 1; } } else back = 1; } else { if(r) back = -1; } #line 137 "hbimgdim.ctr" return back; } void hbimgdim_delete(hb_img_dim_t *ptr) { #line 146 "hbimgdim.ctr" if(ptr) { dk3_release(ptr->fn); ptr->w = 0UL; ptr->h = 0UL; dk3_delete(ptr); } #line 152 "hbimgdim.ctr" } hb_img_dim_t * hbimgdim_new(dkChar const *fn, unsigned long w, unsigned long h, dk3_app_t *app) { hb_img_dim_t *back = NULL; #line 161 "hbimgdim.ctr" back = dk3_new_app(hb_img_dim_t,1,app); if(back) { back->w = w; back->h = h; back->fn = dk3str_dup_app(fn,app); if(!(back->fn)) { hbimgdim_delete(back); back = NULL; } } #line 171 "hbimgdim.ctr" return back; } int hbimgdim_find( hb_job_t *job, dkChar const *fn, unsigned long *w, unsigned long *h, int save ) { hb_img_dim_t *idptr; /* Image dimension found or new */ dk3_bif_t *bp; /* BIF object for graphics file */ unsigned long xw; /* Width read from file */ unsigned long xh; /* Height read from file */ int back = 0; #line 191 "hbimgdim.ctr" if((job) && (fn) && (w) && (h)) { idptr = (hb_img_dim_t *)dk3sto_it_find_like(job->i_imgdim, fn, 1); if(idptr) { *w = idptr->w; *h = idptr->h; back = 1; } else { if (0 == is_svg_file(fn)) { bp = dk3bif_open_filename_app(fn, DK3_BIF_IMAGE_TYPE_UNKNOWN, job->app); if(bp) { xw = dk3bif_get_width(bp); xh = dk3bif_get_height(bp); dk3bif_close(bp); if((xw) && (xh)) { *w = xw; *h = xh; back = 1; if(save) { idptr = hbimgdim_new(fn, xw, xh, job->app); if(idptr) { if(!(dk3sto_add(job->s_imgdim, idptr))) { hbimgdim_delete(idptr); } } } } } } else { /* TODO: Find SVG width and height */ } } } #line 223 "hbimgdim.ctr" return back; }