wdvi

network DVI viewer
Log | Files | Refs

commit f945d5e7020fa4b805ac1bbc4fb0bb86a3f32553
parent 685968969875380ac6eb9b068c29fb4d1d414ede
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Sun, 12 Mar 2023 22:39:45 +0000

start cleaning up define_font()

- use variable names from dvitype.dvi manual
- use proper indentation

Diffstat:
Mdvi-init.c | 132+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 69 insertions(+), 63 deletions(-)

diff --git a/dvi-init.c b/dvi-init.c @@ -362,28 +362,28 @@ define_font(FILE *file, unsigned char cmnd, struct font *vfparent, struct font *fontp; float fsize; double scale_dimconv; - long checksum; - int scale; - int design; + long c, s, d; int magstepval; - int len; - char *fontname; + size_t a, l; + char *n; int size; TeXnumber = num(file, (int) cmnd - FNTDEF1 + 1); - checksum = four(file); - scale = four(file); - design = four(file); - len = one(file); len += one(file); /* sequence point in the middle */ - fontname = xmalloc((unsigned) len + 1); - fread(fontname, sizeof(char), len, file); - fontname[len] = '\0'; - if(debug & DBG_PK) - printf("Define font \"%s\" scale=%d design=%d\n", - fontname, scale, design); + c = four(file); /* checksum */ + s = four(file); /* scale */ + d = four(file); /* design */ + a = one(file); /* area (directory) length */ + l = one(file); /* font name length */ + n = xmalloc(a + l + 1); + fread(n, sizeof(*n), a + l, file); + n[a + l] = '\0'; /* font name */ + + if (debug & DBG_PK) + printf("Define font '%s' scale=%ld design=%ld\n", n, s, d); + if (vfparent == NULL) { - fsize = 0.001 * scale / design * magnification * pixels_per_inch; - scale_dimconv = dimconv; + fsize = 0.001 * s / d * magnification * pixels_per_inch; + scale_dimconv = dimconv; } else { /* @@ -394,64 +394,70 @@ define_font(FILE *file, unsigned char cmnd, struct font *vfparent, * into SPELL units by multiplying by * (pixels_per_inch * 2**16) / (72.27 * 2**20). */ - fsize = (72.27 * (1<<4)) * vfparent->dimconv * scale / design; + fsize = (72.27 * (1<<4)) * vfparent->dimconv * s / d; scale_dimconv = vfparent->dimconv; } + magstepval = magstepvalue(&fsize); size = fsize + 0.5; + /* * reuse font if possible */ for (fontp = font_head;; fontp = fontp->next) { - if (fontp == NULL) { /* if font doesn't exist yet */ - if (resource._list_fonts) - printf("%s at %d dpi\n", fontname, (int) (fsize + 0.5)); - fontp = (struct font *) xmalloc((unsigned) sizeof(struct font)); - fontp->fontname = fontname; - fontp->fsize = fsize; - fontp->magstepval = magstepval; - fontp->file = NULL; /* needed for virtual/freetype fonts */ - fontp->filename = NULL; /* needed for freetype fonts */ - fontp->checksum = checksum; - fontp->flags = FONT_IN_USE; - fontp->dimconv = scale * 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) * scale; - if (vfparent == NULL) - if (!load_font(fontp)) { - if (ev_flags & EV_GE_NEWDOC) { /* if aborting */ - free(fontname); - free(fontp); - return NULL; - } - font_not_found = True; - } - fontp->next = font_head; - font_head = fontp; - break; - } - if (strcmp(fontname, fontp->fontname) == 0 - && size == (int) (fontp->fsize + 0.5)) { + 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; + } + 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(fontname); - break; - } + reuse_font(fontp); + free(n); + break; + } } + if (TeXnumber < tn_table_len) - tntable[TeXnumber] = fontp; + tntable[TeXnumber] = fontp; else { - struct tn *tnp; - tnp = xmalloc((unsigned) sizeof(struct tn)); - tnp->next = *tn_headpp; - *tn_headpp = tnp; - tnp->TeXnumber = TeXnumber; - tnp->fontp = fontp; + struct tn *tnp; + tnp = xmalloc(sizeof(struct tn)); + tnp->next = *tn_headpp; + *tn_headpp = tnp; + tnp->TeXnumber = TeXnumber; + tnp->fontp = fontp; } return fontp; }