wdvi

network DVI viewer
Log | Files | Refs

commit de057f9ef5a4c3a1d553133a1d8606601090b639
parent 755dee630cebe5610e5200ebc42c3789d41dd3a4
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Sun, 12 Mar 2023 23:40:45 +0000

nuke one more global

font_not_found was used to when a font could not be loaded. it was used by
define_font() and read_postamble(), where the first is called by the second.

Instead, use a local variable and change the conditions of return in define_font()
such that it returns NULL when a font cannot be loaded. It almost did this before,
but was conditioned on the document being reloaded. Assume we do not care about
exiting font loading while the document is being reloaded.

The other caller of define_font() in vf.c does not use font_not_found, nor does it
check the return code.

Diffstat:
Mdvi-init.c | 34++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/dvi-init.c b/dvi-init.c @@ -51,7 +51,6 @@ NOTE: #define VF_ID_BYTE 202 #define VF_MAGIC ((VF_PRE << 8) | VF_ID_BYTE) -static Boolean font_not_found; static Boolean dvi_is_valid = False; /* if not initializing */ /* @@ -352,6 +351,8 @@ reuse_font(struct font *fontp) * tntable; table for low TeXnumbers * tn_table_len; length of table for TeXnumbers * tn_headpp; addr of head of list of TeXnumbers + * + * returns NULL when a font cannot be loaded, non NULL otherwise. */ struct font * define_font(FILE *file, unsigned char cmnd, struct font *vfparent, @@ -436,13 +437,9 @@ define_font(FILE *file, unsigned char cmnd, struct font *vfparent, 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; + free(n); + free(fontp); + return NULL; } fontp->next = font_head; font_head = fontp; @@ -564,6 +561,7 @@ static Boolean read_postamble(long *last_page_offset, long numerator, long denominator) { unsigned char cmnd; + Boolean font_not_found; struct font *fontp; struct font **fontpp; @@ -589,17 +587,25 @@ read_postamble(long *last_page_offset, long numerator, long denominator) dvi_unshrunk_page_w = unshrunk_paper_w; (void) two(dvi_file); /* max stack size */ total_pages = two(dvi_file); + + /* + * Attempt to load all fonts for the file. If one is not found, + * keep searching such that we can show all fonts that are missing. + */ font_not_found = False; - while ((cmnd = one(dvi_file)) >= FNTDEF1 && cmnd <= FNTDEF4) - if (define_font(dvi_file, cmnd, (struct font *) NULL, - tn_table, TNTABLELEN, &tn_head) == NULL) + while (1) { + cmnd = one(dvi_file); + if (cmnd < FNTDEF1 || cmnd > FNTDEF4) + break; + if (define_font(dvi_file, cmnd, NULL, tn_table, TNTABLELEN, &tn_head) + == NULL) + font_not_found = True; + } + if (font_not_found == True) return False; if (cmnd != POSTPOST) /* Non-fntdef command found in postamble */ return False; - if (font_not_found) - /* Not all pixel files were found */ - return False; /* * free up fonts no longer in use */