123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850 |
- #include "sys-defines.h"
- #include "extern.h"
- #ifdef HAVE_CTIME_R
- #undef HAVE_CTIME_R
- #endif
- #ifdef MSDOS
- #include <unistd.h>
- #endif
- #ifdef HAVE_SYS_TYPES_H
- #include <sys/types.h>
- #endif
- #ifdef TIME_WITH_SYS_TIME
- #include <sys/time.h>
- #include <time.h>
- #else
- #ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
- #else
- #include <time.h>
- #endif
- #endif
- #include "p_header.h"
- #ifndef LIBPLOTTER
- const Plotter _pl_p_default_plotter =
- {
-
- _pl_p_initialize, _pl_p_terminate,
-
- _pl_p_begin_page, _pl_p_erase_page, _pl_p_end_page,
-
- _pl_g_push_state, _pl_g_pop_state,
-
- _pl_p_paint_path, _pl_p_paint_paths, _pl_g_path_is_flushable, _pl_g_maybe_prepaint_segments,
-
- _pl_g_paint_marker, _pl_p_paint_point,
-
- _pl_g_paint_text_string_with_escapes, _pl_p_paint_text_string,
- _pl_g_get_text_width,
-
- _pl_g_retrieve_font,
-
- _pl_g_flush_output,
-
- _pl_g_warning,
- _pl_g_error,
- };
- #endif
- void
- _pl_p_initialize (S___(Plotter *_plotter))
- {
- #ifndef LIBPLOTTER
-
- _pl_g_initialize (S___(_plotter));
- #endif
-
- #ifndef LIBPLOTTER
-
- _plotter->data->type = PL_PS;
- #endif
-
- _plotter->data->output_model = PL_OUTPUT_PAGES_ALL_AT_ONCE;
-
-
- _plotter->data->have_wide_lines = 1;
- _plotter->data->have_dash_array = 1;
- _plotter->data->have_solid_fill = 1;
- _plotter->data->have_odd_winding_fill = 1;
- _plotter->data->have_nonzero_winding_fill = 1;
- _plotter->data->have_settable_bg = 0;
- _plotter->data->have_escaped_string_support = 0;
- _plotter->data->have_ps_fonts = 1;
- #ifdef USE_LJ_FONTS_IN_PS
- _plotter->data->have_pcl_fonts = 1;
- #else
- _plotter->data->have_pcl_fonts = 0;
- #endif
- _plotter->data->have_stick_fonts = 0;
- _plotter->data->have_extra_stick_fonts = 0;
- _plotter->data->have_other_fonts = 0;
-
- _plotter->data->default_font_type = PL_F_POSTSCRIPT;
- _plotter->data->pcl_before_ps = false;
- _plotter->data->have_horizontal_justification = false;
- _plotter->data->have_vertical_justification = false;
- _plotter->data->issue_font_warning = true;
-
- _plotter->data->have_mixed_paths = false;
- _plotter->data->allowed_arc_scaling = AS_NONE;
- _plotter->data->allowed_ellarc_scaling = AS_NONE;
- _plotter->data->allowed_quad_scaling = AS_NONE;
- _plotter->data->allowed_cubic_scaling = AS_NONE;
- _plotter->data->allowed_box_scaling = AS_ANY;
- _plotter->data->allowed_circle_scaling = AS_ANY;
- _plotter->data->allowed_ellipse_scaling = AS_ANY;
-
- _plotter->data->emulate_color = false;
-
-
- _plotter->data->display_model_type = (int)DISP_MODEL_PHYSICAL;
- _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_REAL;
- _plotter->data->flipped_y = false;
- _plotter->data->imin = 0;
- _plotter->data->imax = 0;
- _plotter->data->jmin = 0;
- _plotter->data->jmax = 0;
- _plotter->data->xmin = 0.0;
- _plotter->data->xmax = 0.0;
- _plotter->data->ymin = 0.0;
- _plotter->data->ymax = 0.0;
- _plotter->data->page_data = (plPageData *)NULL;
-
-
-
- {
-
- _set_page_type (_plotter->data);
-
-
- _plotter->data->xmin = 72 * (_plotter->data->viewport_xorigin
- + _plotter->data->viewport_xoffset);
- _plotter->data->xmax = 72 * (_plotter->data->viewport_xorigin
- + _plotter->data->viewport_xoffset
- + _plotter->data->viewport_xsize);
- _plotter->data->ymin = 72 * (_plotter->data->viewport_yorigin
- + _plotter->data->viewport_yoffset);
- _plotter->data->ymax = 72 * (_plotter->data->viewport_yorigin
- + _plotter->data->viewport_yoffset
- + _plotter->data->viewport_ysize);
- }
-
- _compute_ndc_to_device_map (_plotter->data);
- }
- void
- _pl_p_terminate (S___(Plotter *_plotter))
- {
- double x_min, x_max, y_min, y_max;
- int i, n;
- time_t clock;
- plOutbuf *doc_header, *doc_trailer, *current_page;
- bool ps_font_used_in_doc[PL_NUM_PS_FONTS];
- #ifdef USE_LJ_FONTS_IN_PS
- bool pcl_font_used_in_doc[PL_NUM_PCL_FONTS];
- #endif
- char *time_string, time_string_buffer[32];
- #ifdef LIBPLOTTER
- if (_plotter->data->outfp || _plotter->data->outstream)
- #else
- if (_plotter->data->outfp)
- #endif
-
- {
- int num_pages = _plotter->data->page_number;
-
- doc_header = _new_outbuf ();
- if (num_pages == 1)
-
- sprintf (doc_header->point, "\
- %%!PS-Adobe-3.0 EPSF-3.0\n");
- else
- sprintf (doc_header->point, "\
- %%!PS-Adobe-3.0\n");
- _update_buffer (doc_header);
-
- time (&clock);
- #ifdef PTHREAD_SUPPORT
- #ifdef HAVE_PTHREAD_H
- #ifdef HAVE_CTIME_R
- ctime_r (&clock, time_string_buffer);
- time_string = time_string_buffer;
- #else
- time_string = ctime (&clock);
- #endif
- #else
- time_string = ctime (&clock);
- #endif
- #else
- time_string = ctime (&clock);
- #endif
- sprintf (doc_header->point, "\
- %%%%Creator: GNU libplot drawing library %s\n\
- %%%%Title: PostScript plot\n\
- %%%%CreationDate: %s\
- %%%%DocumentData: Clean7Bit\n\
- %%%%LanguageLevel: 1\n\
- %%%%Pages: %d\n\
- %%%%PageOrder: Ascend\n\
- %%%%Orientation: Portrait\n",
- PL_LIBPLOT_VER_STRING, time_string, num_pages);
- _update_buffer (doc_header);
-
-
- _bbox_of_outbufs (_plotter->data->first_page, &x_min, &x_max, &y_min, &y_max);
- if (x_min > x_max || y_min > y_max)
-
- sprintf (doc_header->point, "\
- %%%%BoundingBox: 0 0 0 0\n");
- else
- sprintf (doc_header->point, "\
- %%%%BoundingBox: %d %d %d %d\n",
- IROUND(x_min - 0.5), IROUND(y_min - 0.5),
- IROUND(x_max + 0.5), IROUND(y_max + 0.5));
- _update_buffer (doc_header);
-
-
- {
- current_page = _plotter->data->first_page;
-
- for (i = 0; i < PL_NUM_PS_FONTS; i++)
- ps_font_used_in_doc[i] = false;
- #ifdef USE_LJ_FONTS_IN_PS
- for (i = 0; i < PL_NUM_PCL_FONTS; i++)
- pcl_font_used_in_doc[i] = false;
- #endif
- while (current_page)
- {
- for (i = 0; i < PL_NUM_PS_FONTS; i++)
- if (current_page->ps_font_used[i])
- ps_font_used_in_doc[i] = true;
- #ifdef USE_LJ_FONTS_IN_PS
- for (i = 0; i < PL_NUM_PCL_FONTS; i++)
- if (current_page->pcl_font_used[i])
- pcl_font_used_in_doc[i] = true;
- #endif
- current_page = current_page->next;
- }
- }
-
- {
- bool first_font = true;
- strcpy (doc_header->point, "\
- %%DocumentNeededResources: ");
- _update_buffer (doc_header);
- for (i = 0; i < PL_NUM_PS_FONTS; i++)
- {
- if (ps_font_used_in_doc[i])
- {
- if (first_font == false)
- {
- strcpy (doc_header->point, "%%+ ");
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "font ");
- _update_buffer (doc_header);
- strcpy (doc_header->point, _pl_g_ps_font_info[i].ps_name);
- _update_buffer (doc_header);
- strcpy (doc_header->point, "\n");
- _update_buffer (doc_header);
- first_font = false;
- }
- }
- #ifdef USE_LJ_FONTS_IN_PS
- for (i = 0; i < PL_NUM_PCL_FONTS; i++)
- {
- if (pcl_font_used_in_doc[i])
- {
- if (first_font == false)
- {
- strcpy (doc_header->point, "%%+ ");
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "font ");
- _update_buffer (doc_header);
-
- if (_pl_g_pcl_font_info[i].substitute_ps_name)
- strcpy (doc_header->point, _pl_g_pcl_font_info[i].substitute_ps_name);
- else
- strcpy (doc_header->point, _pl_g_pcl_font_info[i].ps_name);
- _update_buffer (doc_header);
- strcpy (doc_header->point, "\n");
- _update_buffer (doc_header);
- first_font = false;
- }
- }
- #endif
- if (first_font)
- {
- strcpy (doc_header->point, "\n");
- _update_buffer (doc_header);
- }
- }
-
- if (num_pages > 0)
- {
- sprintf (doc_header->point, "\
- %%%%DocumentSuppliedResources: procset %s %s 0\n",
- PS_PROCSET_NAME, PS_PROCSET_VERSION);
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "\
- %%EndComments\n\n");
- _update_buffer (doc_header);
-
- {
- bool first_font = true;
- strcpy (doc_header->point, "\
- %%BeginDefaults\n");
- _update_buffer (doc_header);
- strcpy (doc_header->point, "\
- %%PageResources: ");
- _update_buffer (doc_header);
- for (i = 0; i < PL_NUM_PS_FONTS; i++)
- {
- if (ps_font_used_in_doc[i])
- {
- if (first_font == false)
- {
- strcpy (doc_header->point, "%%+ ");
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "font ");
- _update_buffer (doc_header);
- strcpy (doc_header->point, _pl_g_ps_font_info[i].ps_name);
- _update_buffer (doc_header);
- strcpy (doc_header->point, "\n");
- _update_buffer (doc_header);
- first_font = false;
- }
- }
- #ifdef USE_LJ_FONTS_IN_PS
- for (i = 0; i < PL_NUM_PCL_FONTS; i++)
- {
- if (pcl_font_used_in_doc[i])
- {
- if (first_font == false)
- {
- strcpy (doc_header->point, "%%+ ");
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "font ");
- _update_buffer (doc_header);
- if (_pl_g_pcl_font_info[i].substitute_ps_name)
-
- strcpy (doc_header->point, _pl_g_pcl_font_info[i].substitute_ps_name);
- else
- strcpy (doc_header->point, _pl_g_pcl_font_info[i].ps_name);
- _update_buffer (doc_header);
- strcpy (doc_header->point, "\n");
- _update_buffer (doc_header);
- first_font = false;
- }
- }
- #endif
- if (first_font)
- {
- strcpy (doc_header->point, "\n");
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "\
- %%EndDefaults\n\n");
- _update_buffer (doc_header);
- }
-
- strcpy (doc_header->point, "\
- %%BeginProlog\n");
- _update_buffer (doc_header);
- if (num_pages > 1)
-
- {
- sprintf (doc_header->point, "\
- %%%%BeginResource: procset %s %s 0\n",
- PS_PROCSET_NAME, PS_PROCSET_VERSION);
- _update_buffer (doc_header);
-
- for (i=0; *_ps_procset[i]; i++)
- {
- strcpy (doc_header->point, _ps_procset[i]);
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "\
- %%EndResource\n");
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "\
- %%EndProlog\n\n");
- _update_buffer (doc_header);
-
- strcpy (doc_header->point, "\
- %%BeginSetup\n");
- _update_buffer (doc_header);
-
- for (i = 0; i < PL_NUM_PS_FONTS; i++)
- if (ps_font_used_in_doc[i])
- {
- sprintf (doc_header->point, "\
- %%%%IncludeResource: font %s\n", _pl_g_ps_font_info[i].ps_name);
- _update_buffer (doc_header);
- }
- #ifdef USE_LJ_FONTS_IN_PS
- for (i = 0; i < PL_NUM_PCL_FONTS; i++)
- if (pcl_font_used_in_doc[i])
- {
-
- if (_pl_g_pcl_font_info[i].substitute_ps_name)
- sprintf (doc_header->point, "\
- %%%%IncludeResource: font %s\n", _pl_g_pcl_font_info[i].substitute_ps_name);
- else
- sprintf (doc_header->point, "\
- %%%%IncludeResource: font %s\n", _pl_g_pcl_font_info[i].ps_name);
- _update_buffer (doc_header);
- }
- #endif
-
- strcpy (doc_header->point, "\
- /DrawDict 50 dict def\n\
- DrawDict begin\n");
- _update_buffer (doc_header);
-
- {
- bool need_to_reencode = false;
- for (i = 0; i < PL_NUM_PS_FONTS; i++)
- if (ps_font_used_in_doc[i] && _pl_g_ps_font_info[i].iso8859_1)
- {
- need_to_reencode = true;
- break;
- }
- #ifdef USE_LJ_FONTS_IN_PS
- for (i = 0; i < PL_NUM_PCL_FONTS; i++)
- if (pcl_font_used_in_doc[i] && _pl_g_pcl_font_info[i].iso8859_1)
- {
- need_to_reencode = true;
- break;
- }
- #endif
- if (need_to_reencode)
- {
- strcpy (doc_header->point, _ps_fontproc);
- _update_buffer (doc_header);
-
- for (i = 0; i < PL_NUM_PS_FONTS; i++)
- {
- if (ps_font_used_in_doc[i] && _pl_g_ps_font_info[i].iso8859_1)
- {
- sprintf (doc_header->point, "\
- /%s reencodeISO def\n",
- _pl_g_ps_font_info[i].ps_name);
- _update_buffer (doc_header);
- }
- }
- #ifdef USE_LJ_FONTS_IN_PS
- for (i = 0; i < PL_NUM_PCL_FONTS; i++)
- {
- if (pcl_font_used_in_doc[i] && _pl_g_pcl_font_info[i].iso8859_1)
- {
- sprintf (doc_header->point, "\
- /%s reencodeISO def\n",
- _pl_g_pcl_font_info[i].ps_name);
- _update_buffer (doc_header);
- }
- }
- #endif
- }
- }
- if (num_pages == 1)
-
- {
- sprintf (doc_header->point, "\
- %%%%BeginResource: procset %s %s 0\n",
- PS_PROCSET_NAME, PS_PROCSET_VERSION);
- _update_buffer (doc_header);
-
- for (i=0; *_ps_procset[i]; i++)
- {
- strcpy (doc_header->point, _ps_procset[i]);
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "\
- %%EndResource\n");
- _update_buffer (doc_header);
- }
- strcpy (doc_header->point, "\
- %%EndSetup\n\n");
- _update_buffer (doc_header);
-
-
-
- doc_trailer = _new_outbuf ();
- strcpy (doc_trailer->point, "\
- %%Trailer\n\
- end\n\
- %%EOF\n");
- _update_buffer (doc_trailer);
-
- _write_string (_plotter->data, doc_header->base);
- _delete_outbuf (doc_header);
-
- if (num_pages > 0)
- {
- for (current_page = _plotter->data->first_page, n=1;
- current_page;
- current_page = current_page->next, n++)
- {
- plOutbuf *page_header, *page_trailer;
-
- page_header = _new_outbuf ();
- sprintf (page_header->point, "\
- %%%%Page: %d %d\n", n, n);
- _update_buffer (page_header);
-
- {
- bool first_font = true;
- strcpy (page_header->point, "\
- %%PageResources: ");
- _update_buffer (page_header);
- for (i = 0; i < PL_NUM_PS_FONTS; i++)
- {
- if (current_page->ps_font_used[i])
- {
- if (first_font == false)
- {
- strcpy (page_header->point, "%%+ ");
- _update_buffer (page_header);
- }
- strcpy (page_header->point, "font ");
- _update_buffer (page_header);
- strcpy (page_header->point, _pl_g_ps_font_info[i].ps_name);
- _update_buffer (page_header);
- strcpy (page_header->point, "\n");
- _update_buffer (page_header);
- first_font = false;
- }
- }
- #ifdef USE_LJ_FONTS_IN_PS
- for (i = 0; i < PL_NUM_PCL_FONTS; i++)
- {
- if (current_page->pcl_font_used[i])
- {
- if (first_font == false)
- {
- strcpy (page_header->point, "%%+ ");
- _update_buffer (page_header);
- }
- strcpy (page_header->point, "font ");
- _update_buffer (page_header);
- if (_pl_g_pcl_font_info[i].substitute_ps_name)
-
- strcpy (page_header->point, _pl_g_pcl_font_info[i].substitute_ps_name);
- else
- strcpy (page_header->point, _pl_g_pcl_font_info[i].ps_name);
- _update_buffer (page_header);
- strcpy (page_header->point, "\n");
- _update_buffer (page_header);
- first_font = false;
- }
- }
- #endif
- if (first_font)
- {
- strcpy (page_header->point, "\n");
- _update_buffer (page_header);
- }
- }
-
- _bbox_of_outbuf (current_page, &x_min, &x_max, &y_min, &y_max);
- if (x_min > x_max || y_min > y_max)
-
- sprintf (page_header->point, "\
- %%%%PageBoundingBox: 0 0 0 0\n");
- else
- sprintf (page_header->point, "\
- %%%%PageBoundingBox: %d %d %d %d\n",
- IROUND(x_min - 0.5), IROUND(y_min - 0.5),
- IROUND(x_max + 0.5), IROUND(y_max + 0.5));
- _update_buffer (page_header);
-
- strcpy (page_header->point, "\
- %%BeginPageSetup\n");
- _update_buffer (page_header);
-
-
- strcpy (page_header->point, "\
- %I Idraw 8\n\n\
- Begin\n\
- %I b u\n\
- %I cfg u\n\
- %I cbg u\n\
- %I f u\n\
- %I p u\n\
- %I t\n\
- [ 1 0 0 1 0 0 ] concat\n\
- /originalCTM matrix currentmatrix def\n\
- /trueoriginalCTM matrix currentmatrix def\n");
- _update_buffer (page_header);
- strcpy (page_header->point, "\
- %%EndPageSetup\n\n");
- _update_buffer (page_header);
-
- page_trailer = _new_outbuf ();
-
- strcpy (page_trailer->point, "\
- %%PageTrailer\n\
- End %I eop\n\
- showpage\n\n");
- _update_buffer (page_trailer);
-
-
- _write_string (_plotter->data, page_header->base);
- if (current_page->len > 0)
- _write_string (_plotter->data, current_page->base);
- _write_string (_plotter->data, page_trailer->base);
-
- _delete_outbuf (page_trailer);
- _delete_outbuf (page_header);
- }
- }
-
-
- _write_string (_plotter->data, doc_trailer->base);
- _delete_outbuf (doc_trailer);
- }
-
-
- current_page = _plotter->data->first_page;
- while (current_page)
- {
- plOutbuf *next_page;
-
- next_page = current_page->next;
- _delete_outbuf (current_page);
- current_page = next_page;
- }
-
-
- if (_plotter->data->outfp)
- {
- if (fflush(_plotter->data->outfp) < 0
- #ifdef MSDOS
-
- || fsync (_plotter->data->outfp) < 0
- #endif
- )
- _plotter->error (R___(_plotter) "the output stream is jammed");
- }
- #ifdef LIBPLOTTER
- else if (_plotter->data->outstream)
- {
- _plotter->data->outstream->flush ();
- if (!(*(_plotter->data->outstream)))
- _plotter->error (R___(_plotter) "the output stream is jammed");
- }
- #endif
- #ifndef LIBPLOTTER
-
- _pl_g_terminate (S___(_plotter));
- #endif
- }
- #ifdef LIBPLOTTER
- PSPlotter::PSPlotter (FILE *infile, FILE *outfile, FILE *errfile)
- :Plotter (infile, outfile, errfile)
- {
- _pl_p_initialize ();
- }
- PSPlotter::PSPlotter (FILE *outfile)
- :Plotter (outfile)
- {
- _pl_p_initialize ();
- }
- PSPlotter::PSPlotter (istream& in, ostream& out, ostream& err)
- : Plotter (in, out, err)
- {
- _pl_p_initialize ();
- }
- PSPlotter::PSPlotter (ostream& out)
- : Plotter (out)
- {
- _pl_p_initialize ();
- }
- PSPlotter::PSPlotter ()
- {
- _pl_p_initialize ();
- }
- PSPlotter::PSPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams ¶meters)
- :Plotter (infile, outfile, errfile, parameters)
- {
- _pl_p_initialize ();
- }
- PSPlotter::PSPlotter (FILE *outfile, PlotterParams ¶meters)
- :Plotter (outfile, parameters)
- {
- _pl_p_initialize ();
- }
- PSPlotter::PSPlotter (istream& in, ostream& out, ostream& err, PlotterParams ¶meters)
- : Plotter (in, out, err, parameters)
- {
- _pl_p_initialize ();
- }
- PSPlotter::PSPlotter (ostream& out, PlotterParams ¶meters)
- : Plotter (out, parameters)
- {
- _pl_p_initialize ();
- }
- PSPlotter::PSPlotter (PlotterParams ¶meters)
- : Plotter (parameters)
- {
- _pl_p_initialize ();
- }
- PSPlotter::~PSPlotter ()
- {
-
- if (_plotter->data->open)
- _API_closepl ();
- _pl_p_terminate ();
- }
- #endif
|