26 #define PT2UNIT(p) ((p)*(double)14.111)
29 #define CX(_x) ((int)(_x))
30 #define CY(_y) ((int)(_y))
39 static char *raw_prefix =
"";
40 static char *raw_suffix =
"";
41 #ifdef NOTUSED_ERG_MUST_KNOW_WHY
42 static char *clr_prefix =
"\033%-12345X@PJL ENTER LANGUAGE = HPGL2\n";
43 static char *clr_suffix =
"\033%-12345X\n";
45 static char *pcl_prefix =
"\033E\n\033%%0B\n";
46 static char *pcl_suffix =
"\033%%0A\n";
53 static int CurrentPen;
54 static int ColorsUsed;
55 static char *Sep =
";";
63 static char *text_hdr =
"LB";
64 static void output(
char *
str)
73 fputs(
"\n", Output_file);
76 fputs(str, Output_file);
77 if ((len > 0) && (*(ptr - 1) ==
'\n'))
83 static void output_text(
char *
str)
89 sprintf(text_tail,
"\03%s\n", Sep);
92 len = (ptr -
str) + strlen(text_tail) + strlen(text_hdr);
94 fputs(
"\n", Output_file);
96 fputs(text_hdr, Output_file);
97 fputs(str, Output_file);
98 fputs(text_tail, Output_file);
106 "SP1SD1,341,2,1,4,14,5,0,6,0,7,5SSLO7PA%d,0LB\001\003IN\n",
112 static void setPen(
int p)
115 sprintf(buffer,
"SP%d%s", p, Sep);
118 fprintf(stderr,
"set pen %d\n", p);
131 static FontInfo dfltFont = { 277, 1, 5, 0, 0, 14.0 };
132 static FontInfo coordFont = { 277, 1, 5, 0, 0, 8.0 };
133 static FontInfo nullFont = { 0, 0, 0, 0, 0, 0.0 };
152 unsigned char r, g, b;
157 return ((c1->
r == c2->
r) && (c1->
g == c2->
g) && (c1->
b == c2->
b));
160 static Color black = { 0, 0, 0 };
161 static Color white = { 255, 255, 255 };
162 static Color *colorlist;
173 static void set_color(
Color * cp)
178 if (eqColor(cp, &curGC->
color))
180 for (i = 0; i < ColorsUsed; i++) {
181 if (eqColor(cp, &colorlist[i]))
184 if (i == ColorsUsed) {
185 if (ColorsUsed ==
NPENS)
189 sprintf(buffer,
"PC%d,%d,%d,%d%s", i, cp->
r, cp->
g, cp->
b, Sep);
193 fprintf(stderr,
"set pen %d color %d %d %d\n", i, cp->
r, cp->
g,
201 static void initColors(
void)
204 colorlist[0] = white;
205 colorlist[1] = black;
209 static void destroyColors(
void)
220 if (eqFontInfo(fi, &fontState.
fonts[fontState.
curfont]))
222 otherfont = (fontState.
curfont ? 0 : 1);
224 if (!eqFontInfo(fi, &fontState.
fonts[otherfont])) {
226 sprintf(buffer,
"%s1,%d,2,1,4,%.1f,5,%d,6,%d,7,%d%s",
227 (otherfont ?
"AD" :
"SD"), fi->
symbol,
231 sprintf(buffer,
"%s1,%d,2,0,3,%.1f,5,%d,6,%d,7,%d%s",
232 (otherfont ?
"AD" :
"SD"), fi->
symbol,
237 sprintf(buffer,
"%s%s\n", (otherfont ?
"SA" :
"SS"), Sep);
240 fontState.
fonts[otherfont] = *fi;
244 static void set_line_bold(
int on)
249 sprintf(buffer,
"PW%.3f%s\n", 2 *
PENW, Sep);
252 sprintf(buffer,
"PW%.3f%s\n",
PENW, Sep);
258 static void set_line_style(
int sty)
278 sprintf(buffer,
"%s%s", opt, Sep);
290 newGC->
font = dfltFont;
296 static void initGC(
void)
303 sprintf(buffer,
"SP1%sPW%.3f%s\n", Sep,
PENW, Sep);
311 static void destroyGC(
void)
314 for (gc = curGC; gc; gc = gc1) {
319 fontState.
fonts[0] = nullFont;
320 fontState.
fonts[1] = nullFont;
325 static void saveGC(
void)
328 newGC = makeGC(curGC);
333 static void restoreGC(
void)
339 set_line_bold(newGC->
bold);
341 set_line_style(newGC->
style);
344 fprintf(stderr,
"restore color\n");
346 set_color(&newGC->
color);
348 if (!eqFontInfo(&gc->
font, &newGC->
font))
349 setFont(&newGC->
font);
354 static int isInvis(
void)
360 static double _Xalign;
361 #define getTextAlign() (_Xalign)
362 static void initTextAlign(
void)
366 sprintf(buffer,
"LO4%s", Sep);
370 static int setTextAlign(
double al)
384 sprintf(buffer,
"LO%c%s", opt, Sep);
391 static void hpgl_reset(
void)
397 hpgl_begin_job(FILE * ofp,
graph_t * g,
const char **lib,
char *
info[],
point pages)
400 N_pages = pages.
x * pages.
y;
407 if (Output_lang ==
PCL) {
416 static void hpgl_set_scale(
double scx,
double scy)
419 sprintf(buffer,
"SC%.4f,%.4f,%.4f,%.4f,2%s\n",
425 static void hpgl_begin_page(
graph_t * g,
point page,
double scale,
int rot,
436 sprintf(buffer,
"BP%sIN%s", Sep, Sep);
450 sprintf(buffer,
"RO90IP%s", Sep);
453 sprintf(buffer,
"PA0,0%sLB(%d,%d)\03%s\n", Sep, page.
x, page.
y,
457 sprintf(buffer,
"ROIP%s", Sep);
468 sprintf(buffer,
"RO90IP%s", Sep);
475 Origin.
x = PB.
LL.
y + scale * offset.
y -
HP_OY;
476 Origin.
y = PageWidth - PB.
LL.
x - scale * offset.
x -
HP_OX;
482 Origin.
x = PB.
LL.
x + scale * offset.
x -
HP_OX;
483 Origin.
y = PB.
LL.
y + scale * offset.
y -
HP_OY;
486 sprintf(buffer,
"IW%d,%d,%d,%d%s\n",
490 hpgl_set_scale(scale, scale);
494 static void hpgl_end_page(
void)
498 sprintf(buffer,
"PU%sSP0%sPG;\n", Sep, Sep);
504 static void hpgl_begin_context(
void)
509 static void hpgl_end_context(
void)
514 static void mkFontCanon(
unsigned char *old,
unsigned char *
new)
517 while ((c = *old++)) {
518 if (isalnum(c) ==
FALSE)
530 static double courierPitch = 110.76923;
531 static double stickPitch = 102.85714;
542 {
"timesroman", 277, 0, 5, 0, 0},
543 {
"timesbold", 277, 0, 5, 0, 3},
544 {
"timesitalic", 277, 0, 5, 1, 0},
545 {
"timesbolditalic", 277, 0, 5, 1, 3},
546 {
"helvetica", 277, 0, 4, 0, 0},
547 {
"helveticabold", 277, 0, 4, 0, 3},
548 {
"helveticaoblique", 277, 0, 4, 1, 0},
549 {
"helveticaboldoblique", 277, 0, 4, 1, 3},
550 {
"courier", 277, &courierPitch, 3, 0, 0},
551 {
"courierbold", 277, &courierPitch, 3, 0, 3},
552 {
"courieroblique", 277, &courierPitch, 3, 1, 0},
553 {
"courierboldoblique", 277, &courierPitch, 3, 1, 3},
554 {
"palatinoroman", 277, 0, 15, 0, 0},
555 {
"palatinobold", 277, 0, 15, 0, 3},
556 {
"palatinoitalic", 277, 0, 15, 1, 0},
557 {
"palatinobolditalic", 277, 0, 15, 1, 3},
558 {
"stickcw", 277, &stickPitch, 48, 0, 0},
559 {
"stick", 277, 0, 48, 0, 0},
560 {
"zapfdingbats", 332, 0, 45, 0, 0},
561 {
"symbol", 173, 0, 5, 0, 0}
564 static void mkFontInfo(
char *name,
double size,
FontInfo * fip)
570 mkFontCanon((
unsigned char *) name, (
unsigned char *) buf);
572 for (i = 0; i <
sizeof(fontIndex) /
sizeof(
FontIndex) - 1; i++) {
590 static void hpgl_set_font(
char *name,
double size)
594 mkFontInfo(name, size, &fi);
598 static void hpgl_set_color(
char *name)
603 fprintf(stderr,
"set color %s\n", name);
609 static void hpgl_set_style(
char **
s)
613 while ((line = *s++)) {
614 if (
streq(line,
"solid"))
615 set_line_style(
SOLID);
616 else if (
streq(line,
"dashed"))
618 else if (
streq(line,
"dotted"))
620 else if (
streq(line,
"invis"))
621 set_line_style(
INVIS);
622 else if (
streq(line,
"bold"))
624 else if (
streq(line,
"filled")) {
625 }
else if (
streq(line,
"unfilled")) {
628 "hpgl_set_style: unsupported style %s - ignoring\n",
634 static void hpgl_textpara(
point p, textpara_t * para)
641 switch (para->just) {
649 p.
x -= para->width / 2;
653 sprintf(buffer,
"PA%d,%d%s",
CX(p.
x),
CY(p.
y), Sep);
655 output_text(para->str);
658 fprintf(stderr,
"text =%s=\n", para->str);
664 static int isFlat(
double x0,
double y0,
double x1,
double y1,
double x2,
665 double y2,
double x3,
double y3)
667 double sa, ca, y, O = y3 - y0, A = x3 - x0, H = sqrt(O * O + A * A);
672 sa = O / H, ca = A / H;
673 y = -sa * (x1 - x0) + ca * (y1 - y0);
676 y = -sa * (x2 - x0) + ca * (y2 - y0);
677 return y <= FLATNESS && y >= -
FLATNESS;
680 static void Bzier(
double x0,
double y0,
double x1,
double y1,
double x2,
681 double y2,
double x3,
double y3)
684 if (isFlat(x0, y0, x1, y1, x2, y2, x3, y3)) {
686 sprintf(buffer,
"%d,%d",
CX(x3),
CY(y3));
689 sprintf(buffer,
",%d,%d",
CX(x3),
CY(y3));
695 (x0 + x1) / 2, (y0 + y1) / 2,
696 (x0 + x2) / 4 + x1 / 2, (y0 + y2) / 4 + y1 / 2,
697 (x0 + x3) / 8 + 3 * (x1 + x2) / 8,
698 (y0 + y3) / 8 + 3 * (y1 + y2) / 8);
699 Bzier((x0 + x3) / 8 + 3 * (x1 + x2) / 8,
700 (y0 + y3) / 8 + 3 * (y1 + y2) / 8, (x1 + x3) / 4 + x2 / 2,
701 (y1 + y3) / 4 + y2 / 2, (x2 + x3) / 2, (y2 + y3) / 2, x3, y3);
705 static void hpgl_bezier(
point * A,
int n,
int arrow_at_start,
706 int arrow_at_end,
int filled)
711 if (arrow_at_start || arrow_at_end)
712 agerr(
AGERR,
"hpgl_bezier illegal arrow args\n");
715 sprintf(buffer,
"PA%d,%d%sPD",
CX(A[0].x),
CY(A[0].y), Sep);
718 for (j = 1; j < n; j += 3)
719 Bzier((
double) A[j - 1].x, (
double) A[j - 1].y,
720 (
double) A[j].x, (
double) A[j].y,
721 (
double) A[j + 1].x, (
double) A[j + 1].y,
722 (
double) A[j + 2].x, (
double) A[j + 2].y);
723 sprintf(buffer,
"%sPU%s\n", Sep, Sep);
727 static void hpgl_polygon(
point * A,
int n,
int filled)
734 sprintf(buffer,
"PA%d,%d%sPM0%sPD",
CX(A[0].x),
CY(A[0].y), Sep, Sep);
736 for (j = 1; j < n - 1; j++) {
737 sprintf(buffer,
"%d,%d,",
CX(A[j].x),
CY(A[j].y));
740 sprintf(buffer,
"%d,%d%sPM2%sPU%s",
CY(A[n - 1].x),
CY(A[n - 1].y),
745 fprintf(stderr,
"fill pen %d\n", CurrentPen);
747 if (CurrentPen == 1) {
748 sprintf(buffer,
"FP%sLT%sEP%sLT99%s\n", Sep, Sep, Sep, Sep);
750 sprintf(buffer,
"FP%sSP1%sLT%sEP%sSP%d%sLT99%s\n",
751 Sep, Sep, Sep, Sep, CurrentPen, Sep, Sep);
754 sprintf(buffer,
"EP%s\n", Sep);
782 static void hpgl_ellipse(
point p,
int rx,
int ry,
int filled)
788 sprintf(buffer,
"PA%d,%d%s", p.
x, p.
y, Sep);
790 hpgl_set_scale(Scale * rx, Scale * ry);
793 sprintf(buffer,
"WG1,0,360%sLT%sEW1,0,360%sLT99%s", Sep, Sep,
796 sprintf(buffer,
"WG1,0,360%sSP1%sLT%sEW1,0,360%sSP%d%sLT99%s",
797 Sep, Sep, Sep, Sep, CurrentPen, Sep, Sep);
799 sprintf(buffer,
"EW1,0,360%s", Sep);
801 hpgl_set_scale(Scale, Scale);
805 static void hpgl_polyline(
point * A,
int n)
812 sprintf(buffer,
"PA%d,%d%sPD",
CX(A[0].x),
CY(A[0].y), Sep);
814 for (j = 1; j < n - 1; j++) {
815 sprintf(buffer,
"%d,%d,",
CX(A[j].x),
CY(A[j].y));
818 sprintf(buffer,
"%d,%d%sPU%s\n",
CX(A[n - 1].x),
CY(A[n - 1].y), Sep,
825 static boolean onetime =
TRUE;
827 agerr(
AGERR,
"custom shapes not available with this driver\n");
836 hpgl_begin_page, hpgl_end_page,
843 hpgl_begin_context, hpgl_end_context,
845 hpgl_set_font, hpgl_textpara,
846 hpgl_set_color, hpgl_set_color, hpgl_set_style,
847 hpgl_ellipse, hpgl_polygon,
848 hpgl_bezier, hpgl_polyline,
int agerr(agerrlevel_t level, const char *fmt,...)
int colorxlate(char *str, gvcolor_t *color, color_type_t target_type)