boolean open_input (FILE **f_ptr, int filefmt, const_string fopen_mode) { string fname = NULL; #ifdef FUNNY_CORE_DUMP /* This only applies if a preloaded TeX/Metafont is being made; it allows automatic creation of the core dump (typing ^\ loses since that requires manual intervention). */ if ((filefmt == kpse_tex_format || filefmt == kpse_mf_format || filefmt == kpse_mp_format) && STREQ (nameoffile + 1, "HackyInputFileNameForCoreDump.tex")) funny_core_dump (); #endif /* We havent found anything yet. */ *f_ptr = NULL; if (fullnameoffile) free(fullnameoffile); fullnameoffile = NULL; /* Look in -output-directory first, if the filename is not absolute. This is because .aux and other such files will get written to the output directory, and we have to be able to read them from there. We only look for the name as-is. */ if (output_directory && !kpse_absolute_p (nameoffile+1, false)) { fname = concat3 (output_directory, DIR_SEP_STRING, nameoffile + 1); *f_ptr = fopen (fname, fopen_mode); if (*f_ptr) { free (nameoffile); namelength = strlen (fname); nameoffile = xmalloc (namelength + 2); strcpy (nameoffile + 1, fname); fullnameoffile = fname; } else { free (fname); } } /* No file means do the normal search. */ if (*f_ptr == NULL) { /* A negative FILEFMT means don't use a path. */ if (filefmt < 0) { /* no_file_path, for BibTeX .aux files and MetaPost things. */ *f_ptr = fopen(nameoffile + 1, fopen_mode); /* FIXME... fullnameoffile = xstrdup(nameoffile + 1); */ } else { /* The only exception to `must_exist' being true is \openin, for which we set `tex_input_type' to 0 in the change file. */ /* According to the pdfTeX people, pounding the disk for .vf files is overkill as well. A more general solution would be nice. */ boolean must_exist = (filefmt != kpse_tex_format || texinputtype) && (filefmt != kpse_vf_format); fname = kpse_find_file (nameoffile + 1, (kpse_file_format_type)filefmt, must_exist); if (fname) { fullnameoffile = xstrdup(fname); /* If we found the file in the current directory, don't leave the `./' at the beginning of `nameoffile', since it looks dumb when `tex foo' says `(./foo.tex ... )'. On the other hand, if the user said `tex ./foo', and that's what we opened, then keep it -- the user specified it, so we shouldn't remove it. */ if (fname[0] == '.' && IS_DIR_SEP (fname[1]) && (nameoffile[1] != '.' || !IS_DIR_SEP (nameoffile[2]))) { unsigned i = 0; while (fname[i + 2] != 0) { fname[i] = fname[i + 2]; i++; } fname[i] = 0; } /* kpse_find_file always returns a new string. */ free (nameoffile); namelength = strlen (fname); nameoffile = xmalloc (namelength + 2); strcpy (nameoffile + 1, fname); free (fname); /* This fopen is not allowed to fail. */ #if defined(PTEX) && !defined(WIN32) if (filefmt == kpse_tex_format || filefmt == kpse_bib_format) { *f_ptr = nkf_open (nameoffile + 1, fopen_mode); } else #endif *f_ptr = xfopen (nameoffile + 1, fopen_mode); } } } if (*f_ptr) { recorder_record_input (nameoffile + 1); /* If we just opened a TFM file, we have to read the first byte, to pretend we're Pascal. See tex.ch and mp.ch. Ditto for the ocp/ofm Omega file formats. */ if (filefmt == kpse_tfm_format) { tfmtemp = getc (*f_ptr); /* We intentionally do not check for EOF here, i.e., an empty TFM file. TeX will see the 255 byte and complain about a bad TFM file, which is what we want. */ } else if (filefmt == kpse_ocp_format) { ocptemp = getc (*f_ptr); } else if (filefmt == kpse_ofm_format) { tfmtemp = getc (*f_ptr); } } return *f_ptr != NULL; }
static void FontFind(struct font_entry * tfontptr) { kpse_glyph_file_type font_ret; /* tfontptr->dpi = kpse_magstep_fix (tfontptr->dpi, resolution, NULL); */ DEBUG_PRINT(DEBUG_DVI,("\n FIND FONT:\t%s %d",tfontptr->n,tfontptr->dpi)); tfontptr->name = kpse_find_vf (tfontptr->n); if (tfontptr->name!=NULL) InitVF(tfontptr); #ifdef HAVE_FT2 else if (option_flags & USE_FREETYPE) { tfontptr->psfontmap = FindPSFontMap(tfontptr->n); if (tfontptr->psfontmap!=NULL) tfontptr->name=kpse_find_t1_or_tt(tfontptr->psfontmap->psfile); else tfontptr->name=kpse_find_t1_or_tt(tfontptr->n); if (tfontptr->name!=NULL) { char* tfmname=kpse_find_file(tfontptr->n, kpse_tfm_format, false); if (tfmname!=NULL) { if (!ReadTFM(tfontptr,tfmname)) { Warning("unable to read tfm file %s", tfmname); free(tfontptr->name); tfontptr->name=NULL; } else if ((option_flags & USE_FREETYPE)==0 || !InitFT(tfontptr)) { /* if Freetype loading fails for some reason, fall back to PK font */ free(tfontptr->name); tfontptr->name=NULL; } free(tfmname); } } } #endif /* HAVE_FT2 */ if (tfontptr->name==NULL) { tfontptr->name=kpse_find_pk (tfontptr->n, tfontptr->dpi, &font_ret); if (tfontptr->name!=NULL) { if (!FILESTRCASEEQ (tfontptr->n, font_ret.name)) { page_flags |= PAGE_GAVE_WARN; Warning("font %s not found, using %s at %d dpi instead", tfontptr->n, font_ret.name, font_ret.dpi); tfontptr->c = 0; /* no checksum warning */ } else if (!kpse_bitmap_tolerance ((double)font_ret.dpi, (double) tfontptr->dpi)) { page_flags |= PAGE_GAVE_WARN; Warning("font %s at %d dpi not found, using %d dpi instead", tfontptr->n, tfontptr->dpi, font_ret.dpi); } InitPK(tfontptr); } else { page_flags |= PAGE_GAVE_WARN; Warning("font %s at %d dpi not found, characters will be left blank", tfontptr->n, tfontptr->dpi); #ifndef WIN32 tfontptr->fmmap.fd = 0; #else /* WIN32 */ tfontptr->fmmap.hFile = INVALID_HANDLE_VALUE; #endif tfontptr->magnification = 0; tfontptr->designsize = 0; } } }
boolean open_input (FILE ** f, kpse_file_format_type file_fmt, const char * fopen_mode) { boolean openable = false; char * file_name = NULL; if (return_flag) { if (strcmp(fopen_mode, "r") == 0) fopen_mode = "rb"; } name_of_file[name_length + 1] = '\0'; /* reinsert '~' and ' ' in file names */ if (pseudo_tilde != 0 || pseudo_space != 0) retwiddle(name_of_file + 1); if (shorten_file_name) check_short_name(name_of_file + 1); if (open_trace_flag) printf(" Open `%s' for input ", name_of_file + 1); file_name = kpse_find_file((const_string) name_of_file + 1, file_fmt, false); if (file_name != NULL) { strcpy ((char *) name_of_file + 1, file_name); *f = xfopen((char *) file_name, fopen_mode); #ifdef _WIN32 if (name_of_file[1] == '.' && (name_of_file[2] == PATH_SEP || name_of_file[2] == '\\')) #else if (name_of_file[1] == '.' && name_of_file[2] == PATH_SEP) #endif { unsigned i = 1; while (name_of_file[i + 2] != '\0') { name_of_file[i] = name_of_file[i + 2]; i++; } name_of_file[i] = '\0'; name_length = i - 1; } else name_length = strlen((char *) name_of_file + 1); if (file_fmt == kpse_tfm_format) { fbyte = getc(*f); } if (strstr((char *) name_of_file + 1, ".fmt") != NULL) { if (format_file == NULL) format_file = xstrdup((char *) name_of_file + 1); #ifdef COMPACTFORMAT gz_fmt_file = gzdopen(fileno(*f), "rb9"); #endif } else if (strstr((char *) name_of_file + 1, ".tfm") != NULL) { if (show_tfm_flag && log_opened) { int n; n = strlen((char *) name_of_file + 1); if (file_offset + n > max_print_line) { (void) putc('\n', log_file); file_offset = 0; } else (void) putc(' ', log_file); log_printf("(%s)", name_of_file + 1); file_offset += n + 3; } } else if (source_direct == NULL) { char *s; source_direct = xstrdup((char *) name_of_file + 1); if (trace_flag) printf("Methinks the source %s is `%s'\n", "file", source_direct); if ((s = strrchr(source_direct, '/')) == NULL) *source_direct = '\0'; else *(s + 1) = '\0'; if (trace_flag) printf("Methinks the source %s is `%s'\n", "directory", source_direct); } openable = true; } { unsigned temp_length = strlen((char *) name_of_file + 1); name_of_file[temp_length + 1] = ' '; } return openable; }
void XeTeXFontInst::initialize(const char* pathname, int index, int &status) { TT_Postscript *postTable; TT_OS2* os2Table; FT_Error error; hb_face_t *hbFace; if (!gFreeTypeLibrary) { error = FT_Init_FreeType(&gFreeTypeLibrary); if (error) { fprintf(stderr, "FreeType initialization failed! (%d)\n", error); exit(1); } } error = FT_New_Face(gFreeTypeLibrary, pathname, index, &m_ftFace); if (error) { status = 1; return; } if (!FT_IS_SCALABLE(m_ftFace)) { status = 1; return; } /* for non-sfnt-packaged fonts (presumably Type 1), see if there is an AFM file we can attach */ if (index == 0 && !FT_IS_SFNT(m_ftFace)) { char* afm = xstrdup (xbasename (pathname)); char* p = strrchr (afm, '.'); if (p != NULL && strlen(p) == 4 && tolower(*(p+1)) == 'p' && tolower(*(p+2)) == 'f') strcpy(p, ".afm"); char *fullafm = kpse_find_file (afm, kpse_afm_format, 0); free (afm); if (fullafm) { FT_Attach_File(m_ftFace, fullafm); free (fullafm); } } m_filename = xstrdup(pathname); m_index = index; m_unitsPerEM = m_ftFace->units_per_EM; m_ascent = unitsToPoints(m_ftFace->ascender); m_descent = unitsToPoints(m_ftFace->descender); postTable = (TT_Postscript *) getFontTable(ft_sfnt_post); if (postTable != NULL) { m_italicAngle = Fix2D(postTable->italicAngle); } os2Table = (TT_OS2*) getFontTable(ft_sfnt_os2); if (os2Table) { m_capHeight = unitsToPoints(os2Table->sCapHeight); m_xHeight = unitsToPoints(os2Table->sxHeight); } // Set up HarfBuzz font hbFace = hb_face_create_for_tables(_get_table, m_ftFace, NULL); hb_face_set_index(hbFace, index); hb_face_set_upem(hbFace, m_unitsPerEM); m_hbFont = hb_font_create(hbFace); hb_face_destroy(hbFace); if (hbFontFuncs == NULL) hbFontFuncs = _get_font_funcs(); hb_font_set_funcs(m_hbFont, hbFontFuncs, m_ftFace, NULL); hb_font_set_scale(m_hbFont, m_unitsPerEM, m_unitsPerEM); // We don’t want device tables adjustments hb_font_set_ppem(m_hbFont, 0, 0); return; }
int main (int ac, char **av) { static char execfile[SBUF]; char rbuff[LBUF]; char buff[LBUF]; char cmd[LBUF]; char mfname[TBUF]; char tfname[TBUF]; char pkname[TBUF]; char name[TBUF]; char dpi[TBUF]; char ydpi[TBUF]; char bdpi[TBUF]; char mag[TBUF]; char mode[TBUF]; char destdir[SBUF]; char designsize[64]; char *arg[4]; char currdir[SBUF]; char kpsedot[SBUF]; char *tmp; int cdrive, tdrive; FILE *fr, *fw, *fnul, *tfmfileptr; int i, savo, savi, ret; int style; int issetdest; int app; int oldform; int ps2pkok; char *env; char *p, *fpp; double Xdpi, Ydpi; char texname[TBUF], pfbname[TBUF], slant[TBUF], extend[TBUF], encname[TBUF]; char texbindir[256]; char fullbin[512]; /* * style = 0 : MAKETEXPK_STYLE undefined or other than dosnames * style = 1 : MAKETEXPK_STYLE = dosnames */ /* * issetdest = 0 : no destdir * issetdest = 1 : destdir * issetdest = 2 : current working dir */ /* * app = 0 : mf * app = 1 : ps2pk * app = 2 : gsftopk * app = 3 : ttf2pk * app = 4 : hbf2gf */ /* * oldform = 0 : newform of the command line * oldform = 1 : oldform of the command line */ /* * TEMP | TMP | TMPDIR (necessary) * */ tmp = getenv ("TEMP"); if (!tmp) tmp = getenv ("TMP"); if (!tmp) tmp = getenv ("TMPDIR"); if (!tmp) { tpkerr ("Please define TEMP | TMP | TMPDIR."); return (100); } tmp = xstrdup(tmp); /* * normalize directory separators */ normalize (tmp); for (i = 0; i < 4; i++) arg[i] = (char *) malloc (SBUF); kpse_set_program_name (av[0], NULL); progname = kpse_program_name; /* * get tex binary dir * */ p = kpse_var_value("SELFAUTOLOC"); if(p == 0) { fprintf(stderr, "I cannot get SELFAUTOLOC\n"); exit(100); } strcpy(texbindir, p); free(p); for(p=texbindir; *p; p++) { if(*p == '/') *p = '\\'; } *p = '\\'; *(p+1) = '\0'; if (ac < 2) { usage (); relmem (arg); free(tmp); return (100); } issetdest = 0; ps2pkok = 0; /* * oldform or newform ? * */ if (av[1][0] == '-') oldform = 0; else oldform = 1; /* * Old form of the command line */ if (oldform == 1) { if (ac < 5) { usage (); relmem (arg); free(tmp); return (100); } if((strlen(av[1]) > TBUF -1 ) || (strlen(av[2]) > TBUF -1 ) || (strlen(av[3]) > TBUF -1 ) || (strlen(av[4]) > TBUF -1 )) { fprintf(stderr, "\nToo long a string.\n"); free(tmp); return 100; } strcpy (name, av[1]); strcpy (dpi, av[2]); strcpy (bdpi, av[3]); strcpy (mag, av[4]); if (ac > 5) { if(strlen(av[5]) > TBUF -1) { fprintf(stderr, "\nToo long a string.\n"); free(tmp); return 100; } strcpy (mode, av[5]); } else mode[0] = '\0'; } else { /* * New form of the command line */ name[0] = dpi[0] = bdpi[0] = mag[0] = mode[0] = destdir[0] = '\0'; i = 1; while (i < ac) { if(strlen(av[i]) > TBUF - 1) { fprintf(stderr, "\nToo long a string.\n"); free(tmp); return 100; } if (av[i][0] != '-') { strcpy (name, av[i]); break; } if (!strcmp (av[i], "--dpi") || !strcmp (av[i], "-dpi")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (dpi, av[i]); i++; } else if (!strcmp (av[i], "--bdpi") || !strcmp (av[i], "-bdpi")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (bdpi, av[i]); i++; } else if (!strcmp (av[i], "--mag") || !strcmp (av[i], "-mag")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (mag, av[i]); i++; } else if (!strcmp (av[i], "--mfmode") || !strcmp (av[i], "-mfmode")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (mode, av[i]); i++; } else if (!strcmp (av[i], "--destdir") || !strcmp (av[i], "-destdir")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (destdir, av[i]); issetdest = 1; i++; } else if (!strcmp (av[i], "--version") || !strcmp (av[i], "-version")) { version (); relmem (arg); free(tmp); return (0); } else if (!strcmp (av[i], "--help") || !strcmp (av[i], "-help")) { help (); relmem (arg); free(tmp); return (0); } else { tpkerr ("Argument error."); relmem (arg); free(tmp); return (100); } } } /* End of command line analysis */ env = kpse_var_value ("MAKETEXPK_STYLE"); if ((env == NULL) || !(*env) || (env && strcmp (env, "dosnames"))) { style = 0; } else style = 1; /* * Default program is mf */ app = 0; /* * check if mfmode and bdpi are consistent or not */ if (bdpi[0] && mode[0] && mode[0] != '/') { FILE *frd; char buff[128]; int len; strcpy (fullbin, texbindir); strcat (fullbin, "mf-nowin.exe \"\\mode:="); strcat (fullbin, mode); strcat (fullbin, ";mode_setup;message"); strcat (fullbin, "(decimal round pixels_per_inch);"); strcat (fullbin, "end. <nul\""); frd = popen (fullbin, "r"); if (!frd) { tpkerr ("I cannot find METAFONT.\n"); relmem (arg); free(tmp); return (100); } (void) fgets (buff, 126, frd); (void) fgets (buff, 126, frd); pclose (frd); system("del /Q mfput.*"); len = (int)strlen (buff); if (buff[len - 1] == '\n') { buff[len - 1] = '\0'; if (buff[len - 2] == '\r') buff[len - 2] = '\0'; } if (strcmp (bdpi, buff)) { fprintf(stderr, "mode_dpi %s and bdpi %s are inconsistent.\n", buff, bdpi); fprintf(stderr, "therefore I reset mfmode.\n"); mode[0] = '\0'; } } /* * determine mfmode if not given */ if (mode[0] == 0 || mode[0] == '/') { if (bdpi[0] == 0) { tpkerr ("Cannot determine the mode."); tpkerr ("I will try other possibilities."); app = 1; } else { strcpy (rbuff, "MAKETEXPK_MODE_"); strcat (rbuff, bdpi); if ((env = kpse_var_value ("MAKETEXPK_MODE")) && *env) strcpy (mode, env); else if ((env = kpse_var_value (rbuff))) strcpy (mode, env); else if (!strcmp (bdpi, "85")) strcpy (mode, "sun"); else if (!strcmp (bdpi, "100")) strcpy (mode, "nextscrn"); else if (!strcmp (bdpi, "118")) strcpy (mode, "pcprevw"); else if (!strcmp (bdpi, "160")) strcpy (mode, "nectzo"); else if (!strcmp (bdpi, "180")) strcpy (mode, "toshiba"); else if (!strcmp (bdpi, "200")) strcpy (mode, "highfax"); else if (!strcmp (bdpi, "240")) strcpy (mode, "canonlbp"); else if (!strcmp (bdpi, "300")) strcpy (mode, "cx"); else if (!strcmp (bdpi, "320")) strcpy (mode, "neclm"); else if (!strcmp (bdpi, "360")) strcpy (mode, "epstylus"); else if (!strcmp (bdpi, "400")) strcpy (mode, "nexthi"); else if (!strcmp (bdpi, "600")) strcpy (mode, "ljfour"); else if (!strcmp (bdpi, "720")) strcpy (mode, "epscszz"); else if (!strcmp (bdpi, "800")) strcpy (mode, "lwpro"); else if (!strcmp (bdpi, "1000")) strcpy (mode, "lmaster"); else if (!strcmp (bdpi, "1200")) strcpy (mode, "ultre"); else if (!strcmp (bdpi, "1270")) strcpy (mode, "linoone"); else if (!strcmp (bdpi, "1800")) strcpy (mode, "vtftzz"); else if (!strcmp (bdpi, "2400")) strcpy (mode, "supre"); else if (!strcmp (bdpi, "2540")) strcpy (mode, "linotzzh"); else if (!strcmp (bdpi, "3386")) strcpy (mode, "linolttz"); else if (!strcmp (bdpi, "8000")) strcpy (mode, "dpdfezzz"); else if (!strcmp (bdpi, "9600")) strcpy (mode, "ibx"); else { tpkerr ("Cannot determine the mode."); tpkerr ("I will try other possibilities."); app = 1; } } } if (env) free (env); if (name[0] == 0) { tpkerr ("Font name is not given."); relmem (arg); free(tmp); return (100); } if ((p = strrchr (name, '.'))) *p = '\0'; strcpy (mfname, name); strcat (mfname, ".mf"); if (app == 0) { if (!(p = kpse_var_value ("MFINPUTS"))) { tpkerr ("Cannot get value of MFINPUTS."); relmem (arg); free(tmp); return (100); } free (p); xputenv("MKTEXMF", "1"); if (!(p = kpse_find_file (mfname, kpse_mf_format, 1))) { fprintf (stderr, "Cannot find %s .\n", mfname); tpkerr ("I try ps2pk --> gsftopk --> ttf2pk --> hbf2gf."); app = 1; } } if (app != 0) { strcpy (mode, "modeless"); strcpy (tfname, name); strcat (tfname, ".tfm"); if (!(p = kpse_var_value ("TFMFONTS"))) { tpkerr ("Cannot get value of TFMFONTS."); relmem (arg); free(tmp); return (100); } free (p); /* I don't try to create nonexisting tfm here. */ if (!(p = kpse_find_file (tfname, kpse_tfm_format, 0))) { fprintf (stderr, "Cannot find %s .\n", tfname); relmem (arg); free(tmp); return 100; } tfmfileptr = fopen (p, "rb"); if (!tfmfileptr) { fprintf (stderr, "I cannot open %s.\n", p); relmem (arg); free(tmp); return 100; } i = 256 * getc (tfmfileptr); i += getc (tfmfileptr); fclose (tfmfileptr); if ((i == 9) || (i == 11)) { fprintf (stderr, "Current font seems to be a Japanese one.\n"); fprintf (stderr, "I give up to create a PK font.\n"); relmem (arg); free(tmp); return 100; } } if ((p[0] == '.') && (p[1] == '/') && (issetdest != 1)) issetdest = 2; fpp = _getcwd (currdir, SBUF); if (!fpp) { fprintf (stderr, "Failed to get current working directory.\n"); relmem (arg); free(tmp); return (100); } normalize (currdir); i = (int)strlen (currdir); if (currdir[i - 1] == '/') currdir[i - 1] = '\0'; strcpy (kpsedot, "KPSE_DOT=.;"); strcat (kpsedot, currdir); _putenv (kpsedot); if (issetdest == 2) { strcpy (destdir, currdir); } if (issetdest == 0) { strcpy (arg[0], "Dummy"); strcpy (arg[1], "pk"); strcpy (arg[2], p); strcpy (arg[3], mode); if (!(p = getdestdir (4, arg))) { tpkerr ("Cannot get destination directory name."); relmem (arg); free(tmp); return (100); } strcpy (rbuff, p); } else strcpy (rbuff, destdir); /* * Change backslash into slash */ normalize (rbuff); p = rbuff; i = (int)strlen (p); if (p[i - 1] == '/') p[i - 1] = '\0'; if (issetdest) { if (!is_dir (p)) { fprintf (stderr, "Destination %s is not found.\n", p); relmem (arg); free(tmp); return (100); } } else if (!is_dir (p)) { if (make_dir (p)) { tpkerr ("Error in make_dir."); relmem (arg); free(tmp); return (100); } } strcpy (buff, p); p = buff; i = (int)strlen (p); if (p[i - 1] != '/') strcat (p, "/"); if (dpi[0] == 0) { tpkerr ("Cannot determine DPI."); relmem (arg); free(tmp); return (100); } if (style == 1 && issetdest != 2) { /* dosnames */ strcat (p, "dpi"); strcat (p, dpi); if (!is_dir (p)) { if (make_dir (p)) { tpkerr ("Error in make_dir."); relmem (arg); free(tmp); return (100); } } strcat (p, "/"); } strcat (p, name); strcat (p, "."); if (style != 1 || issetdest == 2) strcat (p, dpi); /* long suffix */ strcat (p, "pk"); /* Now buff and p is the full path name of pk file */ /* check the existence of pk file */ if (_access (p, 0) == 0) { fprintf (stderr, "%s exists.\n", p); relmem (arg); printf ("%s\n", p); free(tmp); return (0); } /* * Go to the temporary directory */ cdrive = _getdrive (); if (tmp[1] == ':') { tdrive = tolower (*tmp) - 'a' + 1; _chdrive (tdrive); } _chdir (tmp); /* * save stdout and stdin */ savo = _dup (fileno (stdout)); savi = _dup (fileno (stdin)); /* * connect stdout to stderr */ _dup2 (fileno (stderr), fileno (stdout)); /* * connect stdin to nul */ if (!(fnul = fopen ("nul", "rb"))) { fprintf (stderr, "Cannot open nul device to read.\n"); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } _dup2 (fileno (fnul), fileno (stdin)); /* * pkname is the filename of PK font */ sprintf (pkname, "%s.%spk", name, dpi); if (app == 0) { /* * METAFONT command line */ if (mag[0] == 0) { tpkerr ("Cannot determine MAG."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } sprintf (cmd, "--progname=mf --base=mf \\mode:=%s; \\mag:=%s; nonstopmode; input %s;", mode, mag, name); strcpy (execfile, "mf-nowin.exe"); fprintf (stderr, "%s %s\n", execfile, cmd); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL); sprintf (cmd, "%s.%sgf", name, dpi); /* * check the consistency */ if (_access (cmd, 0) != 0) { tpkerr ("Failed to make gf font by METAFONT."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } /* * Change gf into pk */ strcpy (execfile, "gftopk.exe"); fprintf (stderr, "%s %s %s\n", execfile, cmd, pkname); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, pkname, NULL); if (_access (pkname, 0) != 0) { tpkerr ("Failed to make pk from gf."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } /* * erase gf file */ remove (cmd); /* * erase log file */ sprintf (cmd, "%s.log", name); remove (cmd); /* * erase tfm file */ sprintf (cmd, "%s.tfm", name); remove (cmd); goto finale; } /* * app = 1 : ps2pk --> gsftopk --> ttf2pk --> hbf2gf */ p = kpse_find_file ("pspksupp.map", kpse_fontmap_format, 0); if(p) { fr = fopen (p, "r"); /* Read pspksupp.map */ free (p); if (!fr) { tpkerr ("Cannot open pspksupp.map to read."); ps2pkok = 0; goto do_ps2pk; } while (fgets (rbuff, SBUF, fr)) { if (rbuff[0] == '%' || rbuff[0] == '#' || rbuff[0] == '\n') continue; texname[0] = pfbname[0] = slant[0] = extend[0] = encname[0] = '\0'; i = sscanf (rbuff, "%s %s %s %s %s", texname, pfbname, slant, extend, encname); if (i == 2 && !strncmp (texname, "AspectRatio", 11)) { if (!sscanf (pfbname, "%lf", &AspectRatio)) { tpkerr ("File format of pspksupp.map is wrong."); fclose (fr); ps2pkok = 0; goto do_ps2pk; } UseAspectRatio = 1; continue; } else if (i > 0 && !stricmp (texname, name)) { p = kpse_var_value ("T1FONTS"); if (!p) { tpkerr ("T1FONTS is not defined."); ps2pkok = 0; break; } free (p); p = kpse_find_file (pfbname, kpse_type1_format, 0); if (!p) { fprintf (stderr, "%s is not found.\n", pfbname); ps2pkok = 0; break; } free (p); ps2pkok = 1; if(bdpi[0] == 0) i--; break; } } fclose (fr); goto do_ps2pk; } else { char *q; char a[SBUF]; char b[SBUF]; char psname[SBUF]; char pscommand[SBUF]; double slantval, extendval; texname[0] = pfbname[0] = encname[0] = '\0'; a[0] = b[0] = psname[0] = pscommand[0] = '\0'; FileName = 0; strcpy(slant, "0"); strcpy(extend, "1"); ps2pkok = 0; p = kpse_find_file ("ps2pk.map", kpse_fontmap_format, 0); if(!p) { tpkerr("Necessary map file for ps2pk is not found."); goto do_ps2pk; } fr = fopen(p,"rb"); free(p); if (!fr) { tpkerr ("Cannot open ps2pk.map to read."); goto do_ps2pk; } while ((ret=ffgets (rbuff, LBUF, fr)) != FFILE_END) { if(ret == BBUFF_FUL) { fprintf(stderr, "A line in ps2pk.map seems to be too long.\n"); fprintf(stderr, "I try to continue. But something may be wrong.\n"); } p = rbuff; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) continue; q = texname; while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; if(stricmp(texname, name)) continue; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) { fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n"); break; } if(FileName) q = a; else q = psname; while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; skipchar(&p); /* skip flag */ if(!FileName) { while(isdigit(*p)) p++; skipchar(&p); } if((*p == '%') || (*p == '#') || (*p == '\n')) { tpkerr("I cannot use ps2pk due to lack of data."); break; } if(*p == '\"') { q = pscommand; *q++ = *p++; while(*p != '\"') *q++ = *p++; *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; } if(FileName && a[0] == '\0') q = a; else if(FileName && b[0] == '\0') q = b; else { tpkerr("Incorrect line in ps2pk.map."); break; } while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; if(*p == '\"') { q = pscommand; *q++ = *p++; while(*p != '\"') *q++ = *p++; *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; } if (FileName && a[0] == '\0') q = a; else if (FileName && b[0] == '\0') q = b; else { fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n"); break; } while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; if(*p == '\"') { q = pscommand; *q++ = *p++; while(*p != '\"') *q++ = *p++; *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; } skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; else { fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n"); break; } } fclose(fr); if(pscommand[0]) { p = strstr(pscommand, "SlantFont"); if(p) { p--; while(*p == ' ' || *p == '\t') p--; while(*p != ' ' && *p != '\t' && *p != '\"') p--; p++; sscanf(p, "%lf SlantFont", &slantval); sprintf(slant, "%lf", slantval); p = slant + strlen(slant) - 1; while(*p == '0') { *p = '\0'; p--; } } p = strstr(pscommand, "ExtendFont"); if(p) { p--; while(*p == ' ' || *p == '\t') p--; while(*p != ' ' && *p != '\t' && *p != '\"') p--; p++; sscanf(p, "%lf ExtendFont", &extendval); sprintf(extend, "%lf", extendval); p = extend + strlen(extend) - 1; while(*p == '0') { *p = '\0'; p--; } } } if(a[0]) { p = strrchr(a, '.'); if(p && !stricmp(p, ".enc")) { *p = '\0'; strcpy(encname, a); } else if(p && !stricmp(p, ".pfb")) { *p = '\0'; strcpy(pfbname, a); } } if(b[0]) { p = strrchr(b, '.'); if(p && !stricmp(p, ".enc")) { *p = '\0'; strcpy(encname, b); } else if(p && !stricmp(p, ".pfb")) { *p = '\0'; strcpy(pfbname, b); } } if(pfbname[0] == '\0') goto do_ps2pk; p = kpse_find_file (pfbname, kpse_type1_format, 0); if(!p) goto do_ps2pk; free(p); ps2pkok = 1; if(encname[0] && bdpi[0]) { i = 5; } else if(!encname[0] && !bdpi[0]) { i = 3; } else { i = 4; } } do_ps2pk: if (ps2pkok) { if (UseAspectRatio) { sscanf (dpi, "%lf", &Xdpi); Ydpi = Xdpi * AspectRatio; sprintf (ydpi, "%d", (int) Ydpi); } else strcpy (ydpi, dpi); strcpy(tfname, name); strcat(tfname, ".tfm"); get_designsize(tfname, designsize); if (i == 3) { sprintf (cmd, "-X%s -Y%s -S%s -E%s -P%s %s %s", dpi, ydpi, slant, extend, designsize, pfbname, pkname); } else if (i == 4 && bdpi[0]) { sprintf (cmd, "-X%s -Y%s -R%s -S%s -E%s -P%s %s %s", dpi, ydpi, bdpi, slant, extend, designsize, pfbname, pkname); } else if (i == 4 && encname[0]) { sprintf (cmd, "-e%s -X%s -Y%s -S%s -E%s -P%s %s %s", encname, dpi, ydpi, slant, extend, designsize, pfbname, pkname); } else if (i == 5) { sprintf (cmd, "-e%s -X%s -Y%s -R%s -S%s -E%s -P%s %s %s", encname, dpi, ydpi, bdpi, slant, extend, designsize, pfbname, pkname); } else { tpkerr ("File format of pspksupp.map is wrong."); goto do_gsftopk; } strcpy (execfile, "ps2pk.exe"); fprintf (stderr, "%s %s\n", execfile, cmd); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL); if (_access (pkname, 0) != 0) { tpkerr ("ps2pk failed to make pk font."); goto do_gsftopk; } goto finale; } /* * ps2pk is impossible to use */ do_gsftopk: tpkerr ("ps2pk cannot be used."); tpkerr ("I try gsftopk."); app = 2; strcpy (execfile, "gsftopk.exe"); fprintf (stderr, "%s %s %s\n", execfile, name, dpi); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, name, dpi, NULL); if (_access (pkname, 0) != 0) { tpkerr ("gsftopk cannot be used."); tpkerr ("Next I try ttf2pk."); app = 3; strcpy (execfile, "ttf2pk.exe"); fprintf (stderr, "%s -q %s %s\n", execfile, name, dpi); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, "-q", name, dpi, NULL); if (_access (pkname, 0) != 0) { tpkerr ("ttf2pk failed."); tpkerr ("Finally I try hbf2gf."); app = 4; strcpy (execfile, "hbf2gf.exe"); fprintf (stderr, "%s -q -p %s %s\n", execfile, name, dpi); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, "-q -p", name, dpi, NULL); sprintf (cmd, "%s.%sgf", name, dpi); if (_access (cmd, 0) != 0) { tpkerr ("All trials failed."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } strcpy (execfile, "gftopk.exe"); fprintf (stderr, "%s %s %s\n", execfile, cmd, pkname); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, pkname, NULL); if (_access (pkname, 0) != 0) { tpkerr ("All trials failed."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } remove (cmd); } } finale: /* * return to original stdout and stdin */ _dup2 (savo, fileno (stdout)); close (savo); _dup2 (savi, fileno (stdin)); close (savi); /* * close nul device */ fclose (fnul); /* * copy the pk file */ if (!(fr = fopen (pkname, "rb"))) { fprintf (stderr, "Cannot open %s to read.\n", pkname); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } if (!(fw = fopen (buff, "wb"))) { fprintf (stderr, "Cannot open %s to write.\n", buff); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } while ((i = (int)fread (rbuff, 1, LBUF, fr))) fwrite (rbuff, 1, i, fw); fclose (fr); fclose (fw); remove (pkname); relmem (arg); /* * update ls-R if it exists */ mktexupd (buff); /* * tell kpathsea */ printf ("%s\n", buff); _chdrive (cdrive); _chdir (currdir); free(tmp); return (0); }
void read_img(image_dict * idict) { char *filepath = NULL; int callback_id; if (img_filename(idict) == NULL) { normal_error("pdf backend","image file name missing"); } callback_id = callback_defined(find_image_file_callback); if (img_filepath(idict) == NULL) { if (callback_id > 0) { /*tex We always callback, also for a mem stream. */ if (run_callback(callback_id, "S->S", img_filename(idict),&filepath)) { if (filepath && (strlen(filepath) > 0)) { img_filepath(idict) = strdup(filepath); } } } if (img_filepath(idict) == NULL && (strstr(img_filename(idict),"data:application/pdf,") != NULL)) { /*tex We need to check here for a pdf memstream. */ img_filepath(idict) = strdup(img_filename(idict)); } else if (callback_id == 0) { /*tex Otherwise we use kpse but only when we don't callback. */ img_filepath(idict) = kpse_find_file(img_filename(idict), kpse_tex_format, true); } if (img_filepath(idict) == NULL) { /*tex In any case we need a name. */ formatted_error("pdf backend","cannot find image file '%s'", img_filename(idict)); } } recorder_record_input(img_filepath(idict)); /*tex A few type checks. */ check_type_by_header(idict); check_type_by_extension(idict); /*tex Now we're ready to read the image. */ switch (img_type(idict)) { case IMG_TYPE_PDFMEMSTREAM: case IMG_TYPE_PDF: read_pdf_info(idict); break; case IMG_TYPE_PNG: read_png_info(idict); break; case IMG_TYPE_JPG: read_jpg_info(idict); break; case IMG_TYPE_JP2: read_jp2_info(idict); break; case IMG_TYPE_JBIG2: read_jbig2_info(idict); break; default: img_type(idict) = IMG_TYPE_NONE; if (pdf_ignore_unknown_images) { normal_warning("pdf backend","internal error: ignoring unknown image type"); } else { normal_error("pdf backend","internal error: unknown image type"); } break; } cur_file_name = NULL; if (img_type(idict) == IMG_TYPE_NONE) { img_state(idict) = DICT_NEW; } else if (img_state(idict) < DICT_FILESCANNED) { img_state(idict) = DICT_FILESCANNED; } }
static PyObject *py_kpse_find_file(PyObject *self, PyObject *args) { char *filename; char *format; char *completefilename; PyObject *returnvalue; kpse_file_format_type kpse_file_format; if (PyArg_ParseTuple(args, "ss", &filename, &format)) { /* if (!strcmp(format, "gf")) kpse_file_format = kpse_gf_format; else */ /* if (!strcmp(format, "pk")) kpse_file_format = kpse_pk_format; else */ /* if (!strcmp(format, "bitmap font")) kpse_file_format = kpse_any_glyph_format; else */ if (!strcmp(format, "tfm")) kpse_file_format = kpse_tfm_format; else if (!strcmp(format, "afm")) kpse_file_format = kpse_afm_format; else /* if (!strcmp(format, "base")) kpse_file_format = kpse_base_format; else */ /* if (!strcmp(format, "bib")) kpse_file_format = kpse_bib_format; else */ /* if (!strcmp(format, "bst")) kpse_file_format = kpse_bst_format; else */ /* if (!strcmp(format, "cnf")) kpse_file_format = kpse_cnf_format; else */ /* if (!strcmp(format, "ls-R")) kpse_file_format = kpse_db_format; else */ /* if (!strcmp(format, "fmt")) kpse_file_format = kpse_fmt_format; else */ if (!strcmp(format, "map")) kpse_file_format = kpse_fontmap_format; else /* if (!strcmp(format, "mem")) kpse_file_format = kpse_mem_format; else */ /* if (!strcmp(format, "mf")) kpse_file_format = kpse_mf_format; else */ /* if (!strcmp(format, "mfpool")) kpse_file_format = kpse_mfpool_format; else */ /* if (!strcmp(format, "mft")) kpse_file_format = kpse_mft_format; else */ /* if (!strcmp(format, "mp")) kpse_file_format = kpse_mp_format; else */ /* if (!strcmp(format, "mppool")) kpse_file_format = kpse_mppool_format; else */ /* if (!strcmp(format, "MetaPost support")) kpse_file_format = kpse_mpsupport_format; else */ /* if (!strcmp(format, "ocp")) kpse_file_format = kpse_ocp_format; else */ /* if (!strcmp(format, "ofm")) kpse_file_format = kpse_ofm_format; else */ /* if (!strcmp(format, "opl")) kpse_file_format = kpse_opl_format; else */ /* if (!strcmp(format, "otp")) kpse_file_format = kpse_otp_format; else */ /* if (!strcmp(format, "ovf")) kpse_file_format = kpse_ovf_format; else */ /* if (!strcmp(format, "ovp")) kpse_file_format = kpse_ovp_format; else */ if (!strcmp(format, "graphic/figure")) kpse_file_format = kpse_pict_format; else /* if (!strcmp(format, "tex")) kpse_file_format = kpse_tex_format; else */ /* if (!strcmp(format, "TeX system documentation")) kpse_file_format = kpse_texdoc_format; else */ /* if (!strcmp(format, "texpool")) kpse_file_format = kpse_texpool_format; else */ /* if (!strcmp(format, "TeX system sources")) kpse_file_format = kpse_texsource_format; else */ if (!strcmp(format, "PostScript header")) kpse_file_format = kpse_tex_ps_header_format; else /* if (!strcmp(format, "Troff fonts")) kpse_file_format = kpse_troff_font_format; else */ if (!strcmp(format, "type1 fonts")) kpse_file_format = kpse_type1_format; else if (!strcmp(format, "vf")) kpse_file_format = kpse_vf_format; else if (!strcmp(format, "dvips config")) kpse_file_format = kpse_dvips_config_format; else /* if (!strcmp(format, "ist")) kpse_file_format = kpse_ist_format; else */ /* if (!strcmp(format, "truetype fonts")) kpse_file_format = kpse_truetype_format; else */ /* if (!strcmp(format, "type42 fonts")) kpse_file_format = kpse_type42_format; else */ /* if (!strcmp(format, "web2c files")) kpse_file_format = kpse_web2c_format; else */ /* if (!strcmp(format, "other text files")) kpse_file_format = kpse_program_text_format; else */ /* if (!strcmp(format, "other binary files")) kpse_file_format = kpse_program_binary_format; else */ /* if (!strcmp(format, "misc fonts")) kpse_file_format = kpse_miscfonts_format; else */ return NULL; completefilename = kpse_find_file(filename, kpse_file_format, 1); returnvalue = Py_BuildValue("s", completefilename); /* XXX: free(completefilename); */ return returnvalue; } return NULL; }
static Boolean create_pixmap(Widget parent, int iconidx, Pixmap *sen, Pixmap *insen) { static Boolean first_time = True; static Window rootWindow; static XpmColorSymbol color[5] = { {"none", "none", 0}, {"iconColor1", NULL, 0}, {"bottomShadowColor", NULL, 0}, {"topShadowColor", NULL, 0}, {"selectColor", NULL, 0} }; static int screenNum; static Pixmap tools_map; static Pixmap tools_mask; static Pixmap shade_map; static Pixmap shade_mask; int status = 0; XpmAttributes attr; Pixmap map; Pixmap mask; static String pixmap_file_path = NULL; /* note: never free()d */ ASSERT(iconidx >= 0, "index must be positive"); if (first_time) { /* FIXME: We use a dummy window here to get the correct depth/visual for the pixmap creation (cant use globals.widgets.top_level since it's not realized yet and realizing it now would result in wrong dimensions) ... */ Widget dummy = XtVaAppCreateShell("xdvi", "Xdvi", transientShellWidgetClass, DISP, XtNdepth, G_depth, XtNvisual, G_visual, XtNcolormap, G_colormap, XtNmappedWhenManaged, False, NULL); XtRealizeWidget(dummy); /* note: doesn't pop it up */ rootWindow = XtWindow(dummy); screenNum = DefaultScreen(XtDisplay(globals.widgets.top_level)); ASSERT(rootWindow != 0, ""); XtVaGetValues(parent, XmNbackground, &color[BACKGROUND].pixel, XmNforeground, &color[FOREGROUND].pixel, XmNbottomShadowColor, &color[BOTTOM_SHADOW].pixel, XmNtopShadowColor, &color[TOP_SHADOW].pixel, XmNhighlightColor, &color[HIGHLIGHT].pixel, NULL); /* try to locate the XPM file with the toolbar pixmaps */ pixmap_file_path = XtResolvePathname(DISP, "pixmaps", resource.toolbar_pixmap_file, (String)NULL, /* suffix */ (String)NULL, /* use default path */ (Substitution)NULL, /* substitutions */ 0, /* number of substitutions */ (XtFilePredicate)NULL); /* return True iff file exists */ TRACE_GUI((stderr, "pixmap file search via XtResolvePathname: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { pixmap_file_path = (String)kpse_find_file(resource.toolbar_pixmap_file, kpse_program_text_format, 0); TRACE_GUI((stderr, "pixmap file search via kpse_find_file: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { TRACE_GUI((stderr, "No installed toolbar pixmap found, using built-in pixmap.")); } } } /* Setup the color subsititution table */ attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; /* Create the "sensitive" pixmap */ if (!tools_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &tools_map, &tools_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &tools_map, &tools_mask, &attr); } } else status = XpmSuccess; map = tools_map; mask = tools_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } XpmFreeAttributes(&attr); if (map != 0) { static GC back_gc, bots_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[BACKGROUND].pixel; back_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); gcvalues.foreground = color[BOTTOM_SHADOW].pixel; bots_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); /* Create the "sensitive" pixmap. */ *sen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *sen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx != -1) XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); else XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); /* Create the "insensitive" pixmap. */ if (insen != NULL) { Pixmap map; Pixmap mask; attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.color_key = XPM_MONO; attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; if (!shade_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &shade_map, &shade_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &shade_map, &shade_mask, &attr); } } else status = XpmSuccess; map = shade_map; mask = shade_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } if (mask != 0) { static GC tops_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[TOP_SHADOW].pixel; tops_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); XSetClipMask(XtDisplay(globals.widgets.top_level), tops_gc, mask); XSetClipOrigin(XtDisplay(globals.widgets.top_level), tops_gc, 1, 1); *insen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, tops_gc, 1, 1, PIXMAP_WIDTH - 1, PIXMAP_HEIGHT - 1); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); } XpmFreeAttributes(&attr); } } first_time = False; return True; }
int main (int ac, char **av) { char rbuff[LBUF]; char buff[SBUF]; char savebuff[SBUF]; char cmd[LBUF]; char mffile[TBUF]; char *arg[4]; static char execfile[SBUF]; char kpsedot[SBUF]; char currdir[SBUF]; char *tmp; int cdrive, tdrive; FILE *fr, *fw, *fnul; int i, savo, savi; char *p, *fp, *fpp; int issetdest; char fontname[SBUF]; char texbindir[256]; char fullbin[512]; progname = av[0]; kpse_set_program_name (av[0], NULL); /* * get tex binary dir * */ p = kpse_var_value("SELFAUTOLOC"); if(p == 0) { fprintf(stderr, "I cannot get SELFAUTOLOC\n"); exit(100); } strcpy(texbindir, p); free(p); for(p=texbindir; *p; p++) { if(*p == '/') *p = '\\'; } *p = '\\'; *(p+1) = '\0'; tmp = getenv ("TEMP"); if (!tmp) getenv ("TMP"); if (!tmp) getenv ("TMPDIR"); if (!tmp) { fprintf (stderr, "Please define TEMP | TMP | TMPDIR.\n"); return (100); } tmp = xstrdup(tmp); for (fpp = tmp; *fpp; fpp++) { if (*fpp == '\\') *fpp = '/'; else if (IS_KANJI(fpp)) fpp++; } /* issetdest = 0 : TDS issetdest = 1 : user setting issetdest = 2 : current directory */ issetdest = 0; if (ac < 2) { usage (); return (100); } if ((!strcmp (av[1], "--version")) || (!strcmp (av[1], "-version"))) { version (); return (100); } if ((!strcmp (av[1], "--help")) || (!strcmp (av[1], "-help"))) { help (); return (100); } for (i = 0; i < 4; i++) arg[i] = (char *) malloc (SBUF); if ((!strcmp (av[1], "--destdir")) || (!strcmp (av[1], "-destdir"))) { if (ac != 4) { usage (); relmem (arg); return (100); } issetdest = 1; strcpy (buff, av[2]); strcpy (fontname, av[3]); for (p = buff; *p; p++) { if (*p == '\\') *p = '/'; else if (IS_KANJI(p)) p++; } } else { strcpy (fontname, av[1]); } /* fontname = font name */ if ((p = strrchr (fontname, '.'))) *p = '\0'; /* mffile is METAFONT file name */ strcpy (mffile, fontname); strcat (mffile, ".mf"); if (!(fp = kpse_var_value ("MFINPUTS"))) { fprintf (stderr, "Cannot get value of MFINPUTS\n"); relmem (arg); return (100); } free (fp); xputenv("MKTEXMF", "1"); if (!(p = kpse_find_file (mffile, kpse_mf_format, 1))) { fprintf (stderr, "Cannot find %s.\n", mffile); relmem (arg); return (100); } fpp = _getcwd (currdir, SBUF); if (!fpp) { fprintf (stderr, "Failed to get current working directory.\n"); relmem (arg); return (100); } for (fpp = currdir; *fpp; fpp++) { if (*fpp == '\\') *fpp = '/'; else if (IS_KANJI(fpp)) fpp++; } i = strlen (currdir); if (currdir[i - 1] == '/') currdir[i - 1] = '\0'; strcpy (kpsedot, "KPSE_DOT=.;"); strcat (kpsedot, currdir); _putenv (kpsedot); if ((p[0] == '.') && (p[1] == '/') && (issetdest != 1)) { issetdest = 2; strcpy (buff, currdir); } if (issetdest == 0) { /* now path of ${name}.mf is in p */ strcpy (arg[0], "Dummy"); strcpy (arg[1], "tfm"); strcpy (arg[2], p); if (!(p = getdestdir (3, arg))) { fprintf (stderr, "Cannot get destination directory name.\n"); relmem (arg); return (100); } strcpy (buff, p); } /* Now buff is the destdir */ p = buff; i = strlen (p); if (p[i - 1] != '/') strcat (p, "/"); strcat (p, fontname); strcat (p, ".tfm"); /* now p (or buff) is the full path name of the tfm font */ /* check if it exists */ if (_access (p, 0) == 0) { fprintf (stderr, "%s exists\n", p); printf ("%s\n", p); relmem (arg); return (0); } cdrive = _getdrive (); if (tmp[1] == ':') { tdrive = tolower (*tmp) - 'a' + 1; _chdrive (tdrive); } _chdir (tmp); /* save stdout and stdin */ savo = _dup (fileno (stdout)); savi = _dup (fileno (stdin)); /* connect stdout to stderr */ _dup2 (fileno (stderr), fileno (stdout)); /* connect stdin to nul device */ if (!(fnul = fopen ("nul", "r"))) { fprintf (stderr, "Cannot open nul device to read\n"); relmem (arg); _chdrive (cdrive); _chdir (currdir); return (100); } _dup2 (fileno (fnul), fileno (stdin)); /* METAFONT command line */ strcpy (cmd, "--progname=mf --base=mf "); strcat (cmd, "\\mode:=ljfour; \\mag:=1; nonstopmode; input "); strcat (cmd, fontname); strcat (cmd, ";"); strcpy (execfile, "mf-nowin.exe"); fprintf (stderr, "%s %s\n", execfile, cmd); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL); /* return to original stdout and stdin */ _dup2 (savo, fileno (stdout)); close (savo); _dup2 (savi, fileno (stdin)); close (savi); /* close nul device */ fclose (fnul); /* check consistency */ strcpy (cmd, fontname); strcat (cmd, ".600gf"); if (_access (cmd, 0) == -1) { fprintf (stderr, "METAFONT failed to make gf font.\n"); relmem (arg); _chdrive (cdrive); _chdir (currdir); return (100); } remove (cmd); strcpy (cmd, fontname); strcat (cmd, ".tfm"); /* copy the tfm file */ if (!(fr = fopen (cmd, "rb"))) { fprintf (stderr, "Cannot open %s to read\n", cmd); _chdrive (cdrive); _chdir (currdir); relmem (arg); return (100); } if (!(fw = fopen (buff, "wb"))) { fprintf (stderr, "Cannot open %s to write\n", buff); _chdrive (cdrive); _chdir (currdir); relmem (arg); return (100); } while ((i = fread (rbuff, 1, LBUF, fr))) fwrite (rbuff, 1, i, fw); fclose (fr); fclose (fw); strcpy(savebuff, buff); /* copy log file into the current directory in the case that issetdest == 2, because feynmf package requires the log file. */ if(issetdest == 2) { i = strlen(buff); if(i > 3) { i -= 4; buff[i] = '\0'; strcat(buff, ".log"); strcpy(cmd, fontname); strcat(cmd, ".log"); if (!(fr = fopen (cmd, "rb"))) { fprintf (stderr, "Cannot open %s to read\n", cmd); _chdrive (cdrive); _chdir (currdir); relmem (arg); return (100); } if (!(fw = fopen (buff, "wb"))) { fprintf (stderr, "Cannot open %s to write\n", buff); _chdrive (cdrive); _chdir (currdir); relmem (arg); return (100); } while ((i = fread (rbuff, 1, LBUF, fr))) fwrite (rbuff, 1, i, fw); fclose (fr); fclose (fw); } } relmem (arg); if(issetdest != 2) mktexupd (savebuff); /* erase files */ strcpy (cmd, fontname); strcat (cmd, ".log"); remove (cmd); strcpy (cmd, fontname); strcat (cmd, ".tfm"); remove (cmd); _chdrive (cdrive); _chdir (currdir); /* send message to Kpathsea */ printf ("%s\n", savebuff); return (0); }
static struct encoding* InitEncoding(char* encoding) { char *pos,*max,*buf,*enc_file; int i; struct encoding* encp=NULL; struct filemmap fmmap; boolean mmapfailed; #ifdef HAVE_KPSE_ENC_FORMATS enc_file=kpse_find_file(encoding,kpse_enc_format,false); #else enc_file=kpse_find_file(encoding,kpse_tex_ps_header_format,false); #endif if (enc_file == NULL) { Warning("encoding file %s could not be found",encoding); return(NULL); } DEBUG_PRINT((DEBUG_FT|DEBUG_ENC),("\n OPEN ENCODING:\t'%s'", enc_file)); mmapfailed = MmapFile(enc_file,&fmmap); free(enc_file); if (mmapfailed) return(NULL); if ((encp = calloc(sizeof(struct encoding)+strlen(encoding)+1 +fmmap.size,1))==NULL) { Warning("cannot alloc space for encoding",encoding); UnMmapFile(&fmmap); return(NULL); } encp->name=(char*)encp+sizeof(struct encoding); strcpy(encp->name,encoding); pos=fmmap.data; max=fmmap.data+fmmap.size; buf=encp->name+strlen(encoding)+1; #define SKIPCOMMENT(x) if (*x=='%') while (x<max && *x!='\r' && *x!='\n') x++; while(pos<max && *pos!='/') { SKIPCOMMENT(pos); pos++; } pos++; encp->charname[256]=buf; while(pos<max && *pos!='[' && *pos!='%' && *pos!=' ' && *pos!='\t' && *pos!='\r' && *pos!='\n') *buf++=*pos++; *buf++='\0'; DEBUG_PRINT(DEBUG_ENC,("\n PS ENCODING '%s'", encp->charname[256])); while (pos < max && *pos!='[') { SKIPCOMMENT(pos); pos++; } while(pos<max && *pos!='/') { SKIPCOMMENT(pos); pos++; } i=0; while(pos<max && *pos!=']') { pos++; encp->charname[i++]=buf; while(pos<max && *pos!='%' && *pos!=' ' \ && *pos!='\t' && *pos!='\r' && *pos!='\n') *buf++=*pos++; *buf++='\0'; DEBUG_PRINT(DEBUG_ENC,("\n PS ENCODING %d '%s'", i-1,encp->charname[i-1])); while(pos<max && *pos!='/' && *pos!=']') { SKIPCOMMENT(pos); pos++; } } UnMmapFile(&fmmap); return(encp); }
static struct colorname* LoadColornameFile(const char* filename) { struct colorname *list=NULL,*tmp=NULL; char *filepath,*pos,*max; const char *prefix=""; char *name,*values,*model; int nprefix=0,nname,nvalues,nmodel; struct filemmap fmmap; boolean mmapfailed; filepath=kpse_find_file(filename,kpse_tex_format,false); if (filepath == NULL) return NULL; DEBUG_PRINT(DEBUG_COLOR,("\n OPEN COLOR NAMES:\t'%s'", filepath)); mmapfailed=MmapFile(filepath,&fmmap); free(filepath); if (mmapfailed) return NULL; pos=fmmap.data; max=fmmap.data+fmmap.size; while (pos<max && *pos!='\\') pos++; while(pos+9<max && strncmp(pos,"\\endinput",9)!=0) { if ((pos+20<max && strncmp(pos,"\\def\\colornameprefix",20)==0) || (pos+32<max && strncmp(pos,"\\providecommand*\\colornameprefix",32)==0)) { DEBUG_PRINT(DEBUG_COLOR,("\n \t'%.20s'", pos)); FINDARG(pos); prefix=pos; FINDNAMEEND(pos,nprefix); DEBUG_PRINT(DEBUG_COLOR,("\n \tCOLOR PREFIX '%.*s'",nprefix,prefix)); } else if (pos+17<max && strncmp(pos,"\\DefineNamedColor",17)==0) { DEBUG_PRINT(DEBUG_COLOR,("\n \t'%.17s'", pos)); model=NULL; nname=nmodel=nvalues=0; FINDARG(pos); /* skip first argument */ FINDARG(pos); /* find second argument: color name */ name=pos; FINDNAMEEND(pos,nname); FINDARG(pos); /* find third argument: color model */ model=pos; FINDMODELEND(pos,nmodel); FINDARG(pos); /* find fourth argument: color values */ values=pos; FINDVALEND(pos,nvalues); tmp=NewColor(prefix,nprefix,name,nname,model,nmodel,values,nvalues); tmp->next=list; list=tmp; } else if ((pos+15<max && strncmp(pos,"\\definecolorset",15)==0) || (pos+16<max && strncmp(pos,"\\preparecolorset",16)==0)) { char *model; DEBUG_PRINT(DEBUG_COLOR,("\n \t'%.15s'", pos)); FINDARG(pos); /* find first argument: color model */ model=pos; FINDMODELEND(pos,nmodel); FINDARG(pos); /* skip second argument */ FINDARG(pos); /* skip third argument */ FINDARG(pos); /* find fourth argument: names, values */ while(pos<max && *pos!='}'){ name=pos; FINDNAMEEND(pos,nname); pos++; values=pos; FINDVALEND(pos,nvalues); FINDLASTVALEND(pos); tmp=NewColor(prefix,nprefix,name,nname,model,nmodel,values,nvalues); tmp->next=list; list=tmp; FINDWORD(pos); } } else { pos++; while (pos<max && *pos!='\\') pos++; } } UnMmapFile(&fmmap); return(list); }