int GCgettextsize(Gwidget_t * widget, Gtextline_t * tlp, int n, char *fn, double fs, Gsize_t * gsp) { Gsize_t gs; PIXsize_t ps; GdkFont *font; int i, dir, asc, des, rbearing, lbearing, width; gs.x = 0, gs.y = fs; ps = sdrawtopix(widget, gs); if (!(font = findfont(fn, ps.y))) { gsp->x = 1, gsp->y = 1; return 0; } SETFONT(font); for (ps.x = ps.y = 0, i = 0; i < n; i++) { gdk_text_extents(font, tlp[i].p, tlp[i].n, &lbearing, &rbearing, &width, &asc, &des); ps.x = max(ps.x, width), ps.y += asc + des; } *gsp = spixtodraw(widget, ps); return 0; }
int GPtext ( Gwidget_t *widget, Gtextline_t *tlp, int n, Gpoint_t go, char *fn, double fs, char *justs, Ggattr_t *ap ) { Gsize_t gs; PIXpoint_t po; PIXsize_t ps; PIXrect_t pr; HFONT font; SIZE size; RECT r; int x, y, w, h, i; po = pdrawtopix (widget, go); gs.x = 0, gs.y = fs; ps = sdrawtopix (widget, gs); if (!(font = findfont (fn, ps.y))) { Rectangle (GC, po.x, po.y, po.x + 1, po.y + 1); return 0; } setgattr (widget, ap); if (font != WPU->font) { WPU->font = font; SelectObject (GC, font); } for (w = h = 0, i = 0; i < n; i++) { if (tlp[i].n) GetTextExtentPoint32 (GC, tlp[i].p, (int) tlp[i].n, &size); else GetTextExtentPoint32 (GC, "M", (int) 1, &size); tlp[i].w = size.cx, tlp[i].h = size.cy; w = max (w, size.cx), h += size.cy; } switch (justs[0]) { case 'l': po.x += w / 2; break; case 'r': po.x -= w / 2; break; } switch (justs[1]) { case 'd': po.y -= h; break; case 'c': po.y -= h / 2; break; } pr.o.x = po.x - w / 2, pr.o.y = po.y; pr.c.x = po.x + w / 2, pr.c.y = po.y + h; for (i = 0; i < n; i++) { switch (tlp[i].j) { case 'l': x = po.x - w / 2; break; case 'n': x = po.x - tlp[i].w / 2; break; case 'r': x = po.x - (tlp[i].w - w / 2); break; } y = po.y + i * tlp[i].h; r.left = x, r.top = y; r.right = x + tlp[i].w, r.bottom = y + tlp[i].h; DrawText ( GC, tlp[i].p, (int) tlp[i].n, &r, DT_LEFT | DT_TOP | DT_NOPREFIX ); } return 0; }
int GCtext(Gwidget_t * widget, Gtextline_t * tlp, int n, Gpoint_t go, char *fn, double fs, char *justs, Ggattr_t * ap) { Gsize_t gs; PIXpoint_t po; PIXsize_t ps; PIXrect_t pr; Grect_t gr; GdkFont *font; int dir, asc, des, x = 0, y, w, h, i; int lbearing, rbearing, width; po = pdrawtopix(widget, go); gs.x = 0, gs.y = fs; ps = sdrawtopix(widget, gs); if (!(font = findfont(fn, ps.y))) { printf("NO FONT\n"); gdk_draw_rectangle(widget->w, GC, FALSE, po.x, po.y, 1, 1); return 0; } setgattr(widget, ap); SETFONT(font); for (w = h = 0, i = 0; i < n; i++) { gdk_text_extents(font, tlp[i].p, tlp[i].n, &lbearing, &rbearing, &width, &asc, &des); tlp[i].w = width, tlp[i].h = asc + des; w = max(w, width), h += asc + des; } switch (justs[0]) { case 'l': po.x += w / 2; break; case 'r': po.x -= w / 2; break; } switch (justs[1]) { case 'd': po.y -= h; break; case 'c': po.y -= h / 2; break; } pr.o.x = po.x - w / 2, pr.o.y = po.y; pr.c.x = po.x + w / 2, pr.c.y = po.y + h; gr = rpixtodraw(widget, pr); /* if(!ISVISIBLE(gr)) return 1; */ for (i = 0; i < n; i++) { switch (tlp[i].j) { case 'l': x = po.x - w / 2; break; case 'n': x = po.x - tlp[i].w / 2; break; case 'r': x = po.x - (tlp[i].w - w / 2); break; } y = po.y + (i + 1) * tlp[i].h - des; gdk_draw_text(widget->w->window, font, GC, x, y, tlp[i].p, tlp[i].n); } return 0; }
static void loadnewfont(int fd, char *ifil, int iunit, int hwunit, int no_m, int no_u) { lkfile_t fp; char defname[20]; int height, width, bytewidth, def = 0; char *inbuf, *fontbuf; int inputlth, fontbuflth, fontsize, offset; struct unicode_list *uclistheads; if (!*ifil) { /* try to find some default file */ def = 1; /* maybe also load default unimap */ if (iunit < 0 || iunit > 32) iunit = 0; if (iunit == 0) { if (findfont(ifil = "default", &fp) && findfont(ifil = "default8x16", &fp) && findfont(ifil = "default8x14", &fp) && findfont(ifil = "default8x8", &fp)) { fprintf(stderr, _("Cannot find default font\n")); exit(EX_NOINPUT); } } else { sprintf(defname, "default8x%d", iunit); if (findfont(ifil = defname, &fp) && findfont(ifil = "default", &fp)) { fprintf(stderr, _("Cannot find %s font\n"), ifil); exit(EX_NOINPUT); } } } else { if (findfont(ifil, &fp)) { fprintf(stderr, _("Cannot open font file %s\n"), ifil); exit(EX_NOINPUT); } } if (verbose > 1) printf(_("Reading font file %s\n"), ifil); inbuf = fontbuf = NULL; inputlth = fontbuflth = fontsize = 0; width = 8; uclistheads = NULL; if(readpsffont(fp.fd, &inbuf, &inputlth, &fontbuf, &fontbuflth, &width, &fontsize, 0, no_u ? NULL : &uclistheads) == 0) { lk_fpclose(&fp); /* we've got a psf font */ bytewidth = (width+7) / 8; height = fontbuflth / (bytewidth * fontsize); do_loadfont(fd, fontbuf, width, height, hwunit, fontsize, fp.pathname); if (uclistheads && !no_u) do_loadtable(fd, uclistheads, fontsize); #if 1 if (!uclistheads && !no_u && def) loadunicodemap(fd, "def.uni"); #endif return; } lk_fpclose(&fp); // avoid zombies, [email protected] (#88501) /* instructions to combine fonts? */ { char *combineheader = "# combine partial fonts\n"; int chlth = strlen(combineheader); char *p, *q; if (inputlth >= chlth && !strncmp(inbuf, combineheader, chlth)) { char *ifiles[MAXIFILES]; int ifilct = 0; q = inbuf + chlth; while(q < inbuf + inputlth) { p = q; while (q < inbuf+inputlth && *q != '\n') q++; if (q == inbuf+inputlth) { fprintf(stderr, _("No final newline in combine file\n")); exit(EX_DATAERR); } *q++ = 0; if (ifilct == MAXIFILES) { fprintf(stderr, _("Too many files to combine\n")); exit(EX_DATAERR); } ifiles[ifilct++] = p; } /* recursive call */ loadnewfonts(fd, ifiles, ifilct, iunit, hwunit, no_m, no_u); return; } } /* file with three code pages? */ if (inputlth == 9780) { offset = position_codepage(iunit); height = iunit; fontsize = 256; width = 8; } else if (inputlth == 32768) { /* restorefont -w writes a SVGA font to file restorefont -r restores it These fonts have size 32768, for two 512-char fonts. In fact, when BROKEN_GRAPHICS_PROGRAMS is defined, and it always is, there is no default font that is saved, so probably the second half is always garbage. */ fprintf(stderr, _("Hmm - a font from restorefont? " "Using the first half.\n")); inputlth = 16384; /* ignore rest */ fontsize = 512; offset = 0; width = 8; height = 32; if (!hwunit) hwunit = 16; } else { int rem = (inputlth % 256); if (rem == 0 || rem == 40) { /* 0: bare code page bitmap */ /* 40: preceded by .cp header */ /* we might check some header details */ offset = rem; } else { fprintf(stderr, _("Bad input file size\n")); exit(EX_DATAERR); } fontsize = 256; width = 8; height = inputlth/256; } do_loadfont(fd, inbuf+offset, width, height, hwunit, fontsize, fp.pathname); }
static void loadnewfonts(int fd, char **ifiles, int ifilct, int iunit, int hwunit, int no_m, int no_u) { char *ifil, *inbuf, *fontbuf, *bigfontbuf; int inputlth, fontbuflth, fontsize, height, width, bytewidth; int bigfontbuflth, bigfontsize, bigheight, bigwidth; struct unicode_list *uclistheads; int i; lkfile_t fp; if (ifilct == 1) { loadnewfont(fd, ifiles[0], iunit, hwunit, no_m, no_u); return; } /* several fonts that must be merged */ /* We just concatenate the bitmaps - only allow psf fonts */ bigfontbuf = NULL; bigfontbuflth = 0; bigfontsize = 0; uclistheads = NULL; bigheight = 0; bigwidth = 0; for (i=0; i<ifilct; i++) { ifil = ifiles[i]; if (findfont(ifil, &fp) && findpartialfont(ifil, &fp)) { fprintf(stderr, _("Cannot open font file %s\n"), ifil); exit(EX_NOINPUT); } inbuf = fontbuf = NULL; inputlth = fontbuflth = 0; fontsize = 0; if(readpsffont(fp.fd, &inbuf, &inputlth, &fontbuf, &fontbuflth, &width, &fontsize, bigfontsize, no_u ? NULL : &uclistheads)) { fprintf(stderr, _("When loading several fonts, all " "must be psf fonts - %s isn't\n"), fp.pathname); lk_fpclose(&fp); exit(EX_DATAERR); } lk_fpclose(&fp); // avoid zombies, [email protected] (#88501) bytewidth = (width+7) / 8; height = fontbuflth / (bytewidth * fontsize); if (verbose) printf(_("Read %d-char %dx%d font from file %s\n"), fontsize, width, height, fp.pathname); if (bigheight == 0) bigheight = height; else if (bigheight != height) { fprintf(stderr, _("When loading several fonts, all " "must have the same height\n")); exit(EX_DATAERR); } if (bigwidth == 0) bigwidth = width; else if (bigwidth != width) { fprintf(stderr, _("When loading several fonts, all " "must have the same width\n")); exit(EX_DATAERR); } bigfontsize += fontsize; bigfontbuflth += fontbuflth; bigfontbuf = xrealloc(bigfontbuf, bigfontbuflth); memcpy(bigfontbuf+bigfontbuflth-fontbuflth, fontbuf, fontbuflth); } do_loadfont(fd, bigfontbuf, bigwidth, bigheight, hwunit, bigfontsize, NULL); if (uclistheads && !no_u) do_loadtable(fd, uclistheads, bigfontsize); }
void fontreplace(char *font, int type) { if (!strlen(font)) return; char fontname[256]; char fontpath[1024]; char *sysfont; switch (type) { case MONOF: /* regular or roman */ fontpath[0] = '\0'; strcpy(fontname, font); strcat(fontname, ":style=Regular"); findfont(fontname, fontpath); if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Roman"); findfont(fontname, fontpath); } if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Book"); findfont(fontname, fontpath); } if (strlen(fontpath)) { sysfont = malloc(strlen(fontpath)+1); strcpy(sysfont, fontpath); gli_conf_monor = sysfont; gli_conf_monob = sysfont; gli_conf_monoi = sysfont; gli_conf_monoz = sysfont; } /* bold */ fontpath[0] = '\0'; strcpy(fontname, font); strcat(fontname, ":style=Bold"); findfont(fontname, fontpath); if (strlen(fontpath)) { sysfont = malloc(strlen(fontpath)+1); strcpy(sysfont, fontpath); gli_conf_monob = sysfont; gli_conf_monoz = sysfont; } /* italic or oblique */ fontpath[0] = '\0'; strcpy(fontname, font); strcat(fontname, ":style=Italic"); findfont(fontname, fontpath); if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Oblique"); findfont(fontname, fontpath); } if (strlen(fontpath)) { sysfont = malloc(strlen(fontpath)+1); strcpy(sysfont, fontpath); gli_conf_monoi = sysfont; gli_conf_monoz = sysfont; } /* bold italic or bold oblique */ fontpath[0] = '\0'; strcpy(fontname, font); strcat(fontname, ":style=BoldItalic"); findfont(fontname, fontpath); if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Bold Italic"); findfont(fontname, fontpath); } if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=BoldOblique"); findfont(fontname, fontpath); } if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Bold Oblique"); findfont(fontname, fontpath); } if (strlen(fontpath)) { sysfont = malloc(strlen(fontpath)+1); strcpy(sysfont, fontpath); gli_conf_monoz = sysfont; } return; case PROPF: /* regular or roman */ fontpath[0] = '\0'; strcpy(fontname, font); strcat(fontname, ":style=Regular"); findfont(fontname, fontpath); if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Roman"); findfont(fontname, fontpath); } if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Book"); findfont(fontname, fontpath); } if (strlen(fontpath)) { sysfont = malloc(strlen(fontpath)+1); strcpy(sysfont, fontpath); gli_conf_propr = sysfont; gli_conf_propb = sysfont; gli_conf_propi = sysfont; gli_conf_propz = sysfont; } /* bold */ fontpath[0] = '\0'; strcpy(fontname, font); strcat(fontname, ":style=Bold"); findfont(fontname, fontpath); if (strlen(fontpath)) { sysfont = malloc(strlen(fontpath)+1); strcpy(sysfont, fontpath); gli_conf_propb = sysfont; gli_conf_propz = sysfont; } /* italic or oblique */ fontpath[0] = '\0'; strcpy(fontname, font); strcat(fontname, ":style=Italic"); findfont(fontname, fontpath); if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Oblique"); findfont(fontname, fontpath); } if (strlen(fontpath)) { sysfont = malloc(strlen(fontpath)+1); strcpy(sysfont, fontpath); gli_conf_propi = sysfont; gli_conf_propz = sysfont; } /* bold italic or bold oblique */ fontpath[0] = '\0'; strcpy(fontname, font); strcat(fontname, ":style=BoldItalic"); findfont(fontname, fontpath); if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Bold Italic"); findfont(fontname, fontpath); } if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=BoldOblique"); findfont(fontname, fontpath); } if (!strlen(fontpath)) { strcpy(fontname, font); strcat(fontname, ":style=Bold Oblique"); findfont(fontname, fontpath); } if (strlen(fontpath)) { sysfont = malloc(strlen(fontpath)+1); strcpy(sysfont, fontpath); gli_conf_propz = sysfont; } return; } }