123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- #include "sys-defines.h"
- #include "extern.h"
- #define INITIAL_OUTBUF_LEN 8192
- #define NEW_OUTBUF_LEN(old_outbuf_len) ((old_outbuf_len) < 10000000 ? 2 * (old_outbuf_len) : (old_outbuf_len) + 10000000)
- plOutbuf *
- _new_outbuf (void)
- {
- plOutbuf *bufp;
- bufp = (plOutbuf *)_pl_xmalloc(sizeof(plOutbuf));
- bufp->header = (plOutbuf *)NULL;
- bufp->trailer = (plOutbuf *)NULL;
- bufp->base = (char *)_pl_xmalloc(INITIAL_OUTBUF_LEN * sizeof(char));
- bufp->len = (unsigned long)INITIAL_OUTBUF_LEN;
- bufp->next = NULL;
- bufp->reset_point = bufp->base;
- bufp->reset_contents = (unsigned long)0L;
- _reset_outbuf (bufp);
- return bufp;
- }
- void
- _reset_outbuf (plOutbuf *bufp)
- {
- int i;
- *(bufp->reset_point) = '\0';
- bufp->point = bufp->reset_point;
- bufp->contents = bufp->reset_contents;
-
-
- bufp->xrange_min = DBL_MAX;
- bufp->xrange_max = -(DBL_MAX);
- bufp->yrange_min = DBL_MAX;
- bufp->yrange_max = -(DBL_MAX);
-
- for (i = 0; i < PL_NUM_PS_FONTS; i++)
- bufp->ps_font_used[i] = false;
- for (i = 0; i < PL_NUM_PCL_FONTS; i++)
- bufp->pcl_font_used[i] = false;
- }
- void
- _freeze_outbuf (plOutbuf *bufp)
- {
- bufp->reset_point = bufp->point;
- bufp->reset_contents = bufp->contents;
- }
- void
- _delete_outbuf (plOutbuf *bufp)
- {
- if (bufp)
- {
- free (bufp->base);
- free (bufp);
- }
- }
- void
- _update_buffer (plOutbuf *bufp)
- {
- int additional;
-
- additional = strlen (bufp->point);
- bufp->point += additional;
- bufp->contents += additional;
-
- if (bufp->contents + 1 > bufp->len)
-
- {
- fprintf (stderr, "libplot: output buffer overrun\n");
- exit (EXIT_FAILURE);
- }
- if (bufp->contents > (bufp->len >> 1))
-
- {
- unsigned long oldlen, newlen;
- oldlen = bufp->len;
- newlen = NEW_OUTBUF_LEN(oldlen);
- bufp->base =
- (char *)_pl_xrealloc (bufp->base, newlen * sizeof(char));
- bufp->len = newlen;
- bufp->point = bufp->base + bufp->contents;
- bufp->reset_point = bufp->base + bufp->reset_contents;
- }
- }
- void
- _update_buffer_by_added_bytes (plOutbuf *bufp, int additional)
- {
- bufp->point += additional;
- bufp->contents += additional;
-
- if (bufp->contents + 1 > bufp->len)
-
- {
- fprintf (stderr, "libplot: output buffer overrun\n");
- exit (EXIT_FAILURE);
- }
- if (bufp->contents > (bufp->len >> 1))
-
- {
- unsigned long oldlen, newlen;
- oldlen = bufp->len;
- newlen = NEW_OUTBUF_LEN(oldlen);
- bufp->base =
- (char *)_pl_xrealloc (bufp->base, newlen * sizeof(char));
- bufp->len = newlen;
- bufp->point = bufp->base + bufp->contents;
- bufp->reset_point = bufp->base + bufp->reset_contents;
- }
- }
- void
- _update_bbox (plOutbuf *bufp, double x, double y)
- {
- if (x > bufp->xrange_max) bufp->xrange_max = x;
- if (x < bufp->xrange_min) bufp->xrange_min = x;
- if (y > bufp->yrange_max) bufp->yrange_max = y;
- if (y < bufp->yrange_min) bufp->yrange_min = y;
- }
- void
- _bbox_of_outbuf (plOutbuf *bufp, double *xmin, double *xmax, double *ymin, double *ymax)
- {
- double page_x_min = DBL_MAX;
- double page_y_min = DBL_MAX;
- double page_x_max = -(DBL_MAX);
- double page_y_max = -(DBL_MAX);
- if (bufp)
- {
- page_x_max = bufp->xrange_max;
- page_x_min = bufp->xrange_min;
- page_y_max = bufp->yrange_max;
- page_y_min = bufp->yrange_min;
- }
- *xmin = page_x_min;
- *ymin = page_y_min;
- *xmax = page_x_max;
- *ymax = page_y_max;
- }
- void
- _bbox_of_outbufs (plOutbuf *bufp, double *xmin, double *xmax, double *ymin, double *ymax)
- {
- double doc_x_min = DBL_MAX;
- double doc_y_min = DBL_MAX;
- double doc_x_max = -(DBL_MAX);
- double doc_y_max = -(DBL_MAX);
- double page_x_min, page_x_max, page_y_min, page_y_max;
- plOutbuf *page = bufp;
- while (page)
- {
- page_x_max = page->xrange_max;
- page_x_min = page->xrange_min;
- page_y_max = page->yrange_max;
- page_y_min = page->yrange_min;
- if (!((page_x_max < page_x_min || page_y_max < page_y_min)))
-
- {
- if (page_x_max > doc_x_max) doc_x_max = page_x_max;
- if (page_y_max > doc_y_max) doc_y_max = page_y_max;
- if (page_x_min < doc_x_min) doc_x_min = page_x_min;
- if (page_y_min < doc_y_min) doc_y_min = page_y_min;
- }
- page = page->next;
- }
- *xmin = doc_x_min;
- *ymin = doc_y_min;
- *xmax = doc_x_max;
- *ymax = doc_y_max;
- }
|