123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- #include "sys-defines.h"
- #include "libcommon.h"
- #include "plot.h"
- #include "fontlist.h"
- #define MAX_FONTNAME_LEN 36
- static char spaces[MAX_FONTNAME_LEN+1] = " ";
- struct plHersheyFontInfoStruct
- {
- const char *name;
- const char *othername;
- const char *orig_name;
- short chars[256];
- int typeface_index;
- int font_index;
- bool obliquing;
- bool iso8859_1;
- bool visible;
- };
- struct plPSFontInfoStruct
- {
- const char *ps_name;
- const char *ps_name_alt;
- const char *ps_name_alt2;
- const char *x_name;
- const char *x_name_alt;
- const char *x_name_alt2;
- const char *x_name_alt3;
- const char *css_family;
- const char *css_generic_family;
- const char *css_style;
- const char *css_weight;
- const char *css_stretch;
- const char *css_panose;
- int pcl_typeface;
- int hpgl_spacing;
- int hpgl_posture;
- int hpgl_stroke_weight;
- int hpgl_symbol_set;
- int font_ascent;
- int font_descent;
- int font_cap_height;
- int font_x_height;
- short width[256];
- short offset[256];
- int typeface_index;
- int font_index;
- int fig_id;
- bool iso8859_1;
- };
- struct plPCLFontInfoStruct
- {
- const char *ps_name;
- const char *ps_name_alt;
- const char *substitute_ps_name;
- const char *x_name;
- const char *css_family;
- const char *css_generic_family;
- const char *css_style;
- const char *css_weight;
- const char *css_stretch;
- const char *css_panose;
- int pcl_typeface;
- int hpgl_spacing;
- int hpgl_posture;
- int hpgl_stroke_weight;
- int hpgl_symbol_set;
- int font_ascent;
- int font_descent;
- int font_cap_height;
- int font_x_height;
- short width[256];
- short offset[256];
- int typeface_index;
- int font_index;
- bool iso8859_1;
- };
- struct plStickFontInfoStruct
- {
- const char *ps_name;
- bool basic;
- int pcl_typeface;
- int hpgl_spacing;
- int hpgl_posture;
- int hpgl_stroke_weight;
- int hpgl_symbol_set;
- int font_ascent;
- int font_descent;
- int raster_width_lower;
- int raster_height_lower;
- int raster_width_upper;
- int raster_height_upper;
- int hpgl_charset_lower;
- int hpgl_charset_upper;
- int kerning_table_lower;
- int kerning_table_upper;
- char width[256];
- int offset;
- int typeface_index;
- int font_index;
- bool obliquing;
- bool iso8859_1;
- };
- #ifdef INCLUDE_PNG_SUPPORT
- #ifndef X_DISPLAY_MISSING
- static const char *_known_devices[] =
- { "X", "png", "pnm", "gif", "svg", "ai", "ps", "cgm", "fig", "pcl", "hpgl", "regis", "tek", "meta", NULL };
- #else
- static const char *_known_devices[] =
- { "png", "pnm", "gif", "svg", "ai", "ps", "cgm", "fig", "pcl", "hpgl", "regis", "tek", "meta", NULL };
- #endif
- #else
- #ifndef X_DISPLAY_MISSING
- static const char *_known_devices[] =
- { "X", "pnm", "gif", "svg", "ai", "ps", "cgm", "fig", "pcl", "hpgl", "regis", "tek", "meta", NULL };
- #else
- static const char *_known_devices[] =
- { "pnm", "gif", "svg", "ai", "ps", "cgm", "fig", "pcl", "hpgl", "regis", "tek", "meta", NULL };
- #endif
- #endif
- int
- display_fonts (const char *output_format, const char *progname)
- {
- plPlotter *plotter;
- plPlotterParams *plotter_params;
- int numfonts, numpairs, i, j, k;
- bool found = false, odd;
- const char **device_ptr = _known_devices;
- while (*device_ptr)
- if (strcmp (output_format, *device_ptr++) == 0)
- {
- found = true;
- break;
- }
- if (found == false || strcmp (output_format, "meta") == 0)
- {
- #ifdef INCLUDE_PNG_SUPPORT
- #ifndef X_DISPLAY_MISSING
- fprintf (stderr, "\
- To list available fonts, type `%s -T \"format\" --help-fonts',\n\
- where \"format\" is the output format, and is one of:\n\
- X, png, pnm, gif (bitmap formats), or\n\
- svg, ps, ai, cgm, fig, pcl, hpgl, regis, tek (vector formats).\n",
- progname);
- #else
- fprintf (stderr, "\
- To list available fonts, type `%s -T \"format\" --help-fonts',\n\
- where \"format\" is the output format, and is one of:\n\
- png, pnm, gif (bitmap formats), or\n\
- svg, ps, ai, cgm, fig, pcl, hpgl, regis, tek (vector formats).\n",
- progname);
- #endif
- #else
- #ifndef X_DISPLAY_MISSING
- fprintf (stderr, "\
- To list available fonts, type `%s -T \"format\" --help-fonts',\n\
- where \"format\" is the output format, and is one of:\n\
- X, pnm, or gif (bitmap formats), or\n\
- svg, ps, ai, cgm, fig, pcl, hpgl, regis, tek (vector formats).\n",
- progname);
- #else
- fprintf (stderr, "\
- To list available fonts, type `%s -T \"format\" --help-fonts',\n\
- where \"format\" is the output format, and is one of:\n\
- pnm or gif (bitmap formats), or\n\
- svg, ps, ai, cgm, fig, pcl, hpgl, regis, tek (vector formats).\n",
- progname);
- #endif
- #endif
- return 0;
- }
- plotter_params = pl_newplparams ();
- if ((plotter = pl_newpl_r (output_format, NULL, stdout, stderr,
- plotter_params)) == NULL)
- {
- fprintf (stderr,
- "%s: no font information on display device \"%s\" is available\n",
- progname, output_format);
- return 0;
- }
- if (pl_havecap_r (plotter, "HERSHEY_FONTS"))
- {
- const struct plHersheyFontInfoStruct *hershey_font_info =
- (const struct plHersheyFontInfoStruct *)_pl_get_hershey_font_info (plotter);
- int visible_num;
- numfonts = 0;
- for (i=0; hershey_font_info[i].name; i++)
- if (hershey_font_info[i].visible)
- numfonts++;
- odd = (numfonts % 2 == 1 ? true : false);
- numpairs = numfonts / 2;
-
- j = 0;
- k = 0;
- visible_num = -1;
- for (i=0; hershey_font_info[i].name; i++)
- if (hershey_font_info[i].visible)
- {
- visible_num++;
- if (visible_num == 0)
- j = i;
- else if (visible_num == numpairs + (odd ? 1 : 0))
- k = i;
- }
- fprintf (stdout,
- "Names of supported Hershey vector fonts (case-insensitive):\n");
- for (i=0; i < numpairs; i++)
- {
- int len;
-
- len = strlen (hershey_font_info[j].name);
- fprintf (stdout, "\t%s", hershey_font_info[j].name);
- spaces[MAX_FONTNAME_LEN - len] = '\0';
- fputs (spaces, stdout);
- spaces[MAX_FONTNAME_LEN - len] = ' ';
- fprintf (stdout, "%s\n", hershey_font_info[k].name);
-
- do
- j++;
- while (hershey_font_info[j].visible == false);
- if (i < numpairs - 1)
- {
- do
- k++;
- while (hershey_font_info[k].visible == false);
- }
- }
- if (odd)
- fprintf (stdout, "\t%s\n", hershey_font_info[j].name);
- }
- if (pl_havecap_r (plotter, "STICK_FONTS"))
- {
- const struct plStickFontInfoStruct *stick_font_info =
- (const struct plStickFontInfoStruct *)_pl_get_stick_font_info (plotter);
- int extra_fonts, *goodfonts;
- numfonts = 0;
- for (i=0; stick_font_info[i].ps_name; i++)
- numfonts++;
-
- extra_fonts = pl_havecap_r (plotter, "EXTRA_STICK_FONTS");
- goodfonts = (int *)xmalloc (numfonts * sizeof(int));
- for (i=0, j=0; stick_font_info[i].ps_name; i++)
- {
- if (!extra_fonts && stick_font_info[i].basic == false)
- continue;
- goodfonts[j++] = i;
- }
- numfonts = j;
- odd = (numfonts % 2 == 1 ? true : false);
- numpairs = numfonts / 2;
- fprintf (stdout,
- "Names of supported HP vector fonts (case-insensitive):\n");
- for (i=0, j=0, k=numpairs + (odd ? 1 : 0); i < numpairs; i++)
- {
- int len;
-
- len = strlen (stick_font_info[goodfonts[j]].ps_name);
- fprintf (stdout, "\t%s", stick_font_info[goodfonts[j++]].ps_name);
- spaces[MAX_FONTNAME_LEN - len] = '\0';
- fputs (spaces, stdout);
- spaces[MAX_FONTNAME_LEN - len] = ' ';
- fprintf (stdout, "%s\n", stick_font_info[goodfonts[k++]].ps_name);
- }
- if (odd)
- fprintf (stdout, "\t%s\n", stick_font_info[goodfonts[j]].ps_name);
- free (goodfonts);
- }
- if (pl_havecap_r (plotter, "PCL_FONTS"))
- {
- const struct plPCLFontInfoStruct *pcl_font_info =
- (const struct plPCLFontInfoStruct *)_pl_get_pcl_font_info (plotter);
- numfonts = 0;
- for (i=0; pcl_font_info[i].ps_name; i++)
- numfonts++;
- odd = (numfonts % 2 == 1 ? true : false);
- numpairs = numfonts / 2;
- fprintf (stdout,
- "Names of supported PCL fonts (case-insensitive):\n");
- for (i=0, j=0, k=numpairs + (odd ? 1 : 0); i < numpairs; i++)
- {
- int len;
-
- len = strlen (pcl_font_info[j].ps_name);
- fprintf (stdout, "\t%s", pcl_font_info[j++].ps_name);
- spaces[MAX_FONTNAME_LEN - len] = '\0';
- fputs (spaces, stdout);
- spaces[MAX_FONTNAME_LEN - len] = ' ';
- fprintf (stdout, "%s\n", pcl_font_info[k++].ps_name);
- }
- if (odd)
- fprintf (stdout, "\t%s\n", pcl_font_info[j].ps_name);
- }
- if (pl_havecap_r (plotter, "PS_FONTS"))
- {
- const struct plPSFontInfoStruct *ps_font_info =
- (const struct plPSFontInfoStruct *)_pl_get_ps_font_info (plotter);
- numfonts = 0;
- for (i=0; ps_font_info[i].ps_name; i++)
- numfonts++;
- odd = (numfonts % 2 == 1 ? true : false);
- numpairs = numfonts / 2;
- fprintf (stdout,
- "Names of supported Postscript fonts (case-insensitive):\n");
- for (i=0, j=0, k=numpairs + (odd ? 1 : 0); i < numpairs; i++)
- {
- int len;
-
- len = strlen (ps_font_info[j].ps_name);
- fprintf (stdout, "\t%s", ps_font_info[j++].ps_name);
- spaces[MAX_FONTNAME_LEN - len] = '\0';
- fputs (spaces, stdout);
- spaces[MAX_FONTNAME_LEN - len] = ' ';
- fprintf (stdout, "%s\n", ps_font_info[k++].ps_name);
- }
- if (odd)
- fprintf (stdout, "\t%s\n", ps_font_info[j].ps_name);
- }
- if (strcmp (output_format, "X") == 0)
- {
- fprintf (stdout,
- "Most core X Window System fonts, such as charter-medium-r-normal,\n");
- fprintf (stdout,
- "can also be used.\n");
- }
- return 1;
- }
- int
- list_fonts (const char *output_format, const char *progname)
- {
- plPlotter *plotter;
- plPlotterParams *plotter_params;
- bool found = false;
- int i;
- const char **device_ptr = _known_devices;
- while (*device_ptr)
- if (strcmp (output_format, *device_ptr++) == 0)
- {
- found = true;
- break;
- }
- if (found == false)
- {
- fprintf (stderr,
- "%s: no font information on display device \"%s\" is available\n",
- progname, output_format);
- return 0;
- }
- plotter_params = pl_newplparams ();
- if ((plotter = pl_newpl_r (output_format, NULL, stdout, stderr,
- plotter_params)) == NULL)
- {
- fprintf (stderr,
- "%s: no font information on display device \"%s\" is available\n",
- progname, output_format);
- return 0;
- }
- if (pl_havecap_r (plotter, "HERSHEY_FONTS"))
- {
- const struct plHersheyFontInfoStruct *hershey_font_info =
- (const struct plHersheyFontInfoStruct *)_pl_get_hershey_font_info (plotter);
- for (i=0; hershey_font_info[i].name; i++)
- if (hershey_font_info[i].visible)
- fprintf (stdout, "%s\n", hershey_font_info[i].name);
- }
- if (pl_havecap_r (plotter, "STICK_FONTS"))
- {
- const struct plStickFontInfoStruct *stick_font_info =
- (const struct plStickFontInfoStruct *)_pl_get_stick_font_info (plotter);
- int extra_fonts = pl_havecap_r (plotter, "EXTRA_STICK_FONTS");
- for (i=0; stick_font_info[i].ps_name; i++)
- {
- if (!extra_fonts && stick_font_info[i].basic == false)
- continue;
- fprintf (stdout, "%s\n", stick_font_info[i].ps_name);
- }
- }
- if (pl_havecap_r (plotter, "PCL_FONTS"))
- {
- const struct plPCLFontInfoStruct *pcl_font_info =
- (const struct plPCLFontInfoStruct *)_pl_get_pcl_font_info (plotter);
- for (i=0; pcl_font_info[i].ps_name; i++)
- fprintf (stdout, "%s\n", pcl_font_info[i].ps_name);
- }
-
- if (pl_havecap_r (plotter, "PS_FONTS"))
- {
- const struct plPSFontInfoStruct *ps_font_info =
- (const struct plPSFontInfoStruct *)_pl_get_ps_font_info (plotter);
- for (i=0; ps_font_info[i].ps_name; i++)
- fprintf (stdout, "%s\n", ps_font_info[i].ps_name);
- }
- return 1;
- }
|