wdvi

network DVI viewer
Log | Files | Refs

commit 36853a4166145f9724a6c6b88f67f6bc97a2e23d
parent f945d5e7020fa4b805ac1bbc4fb0bb86a3f32553
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Sun, 12 Mar 2023 22:50:28 +0000

move font does not exist case out of for loop

The way this loop was written was funny. Instead, first loop over all fonts
we have loaded, and if our font was not found, then create a new one.

Diffstat:
Mdvi-init.c | 71+++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/dvi-init.c b/dvi-init.c @@ -404,44 +404,9 @@ define_font(FILE *file, unsigned char cmnd, struct font *vfparent, /* * reuse font if possible */ - for (fontp = font_head;; fontp = fontp->next) { - if (fontp == NULL) { - /* font doesn't exist yet */ - if (resource._list_fonts) - printf("%s at %d dpi\n", n, size); - fontp = xmalloc(sizeof(struct font)); - fontp->fontname = n; - fontp->fsize = fsize; - fontp->magstepval = magstepval; - fontp->file = NULL; /* needed for virtual/freetype fonts */ - fontp->filename = NULL; /* needed for freetype fonts */ - fontp->checksum = c; - fontp->flags = FONT_IN_USE; - fontp->dimconv = s * scale_dimconv / (1 << 20); - fontp->set_char_p = load_n_set_char; - fontp->ft = NULL; - /* spsize = scaled size of the font in spell units, - * = scale * [vfparent->]dimconv. - */ - fontp->spsize = - (vfparent != NULL ? vfparent->dimconv : dimconv) * s; - if (vfparent == NULL) - if (!load_font(fontp)) { - if (ev_flags & EV_GE_NEWDOC) { - /* aborting */ - free(n); - free(fontp); - return NULL; - } - font_not_found = True; - } - fontp->next = font_head; - font_head = fontp; - break; - } + for (fontp = font_head; fontp != NULL; fontp = fontp->next) { if (strcmp(n, fontp->fontname) == 0 && size == (int) (fontp->fsize + 0.5)) { - printf(">>> fsize = %f, fontp->fsize = %f\n", fsize, fontp->fsize); /* if font already in use */ reuse_font(fontp); free(n); @@ -449,6 +414,40 @@ define_font(FILE *file, unsigned char cmnd, struct font *vfparent, } } + if (fontp == NULL) { + /* font doesn't exist yet */ + if (resource._list_fonts) + printf("%s at %d dpi\n", n, size); + fontp = xmalloc(sizeof(struct font)); + fontp->fontname = n; + fontp->fsize = fsize; + fontp->magstepval = magstepval; + fontp->file = NULL; /* needed for virtual/freetype fonts */ + fontp->filename = NULL; /* needed for freetype fonts */ + fontp->checksum = c; + fontp->flags = FONT_IN_USE; + fontp->dimconv = s * scale_dimconv / (1 << 20); + fontp->set_char_p = load_n_set_char; + fontp->ft = NULL; + /* spsize = scaled size of the font in spell units, + * = scale * [vfparent->]dimconv. + */ + fontp->spsize = + (vfparent != NULL ? vfparent->dimconv : dimconv) * s; + if (vfparent == NULL) + if (!load_font(fontp)) { + if (ev_flags & EV_GE_NEWDOC) { + /* aborting */ + free(n); + free(fontp); + return NULL; + } + font_not_found = True; + } + fontp->next = font_head; + font_head = fontp; + } + if (TeXnumber < tn_table_len) tntable[TeXnumber] = fontp; else {