/* Test of pswr.h (minus automatic layout) */ /* Last edited on 2004-04-10 22:48:00 by stolfi */ #include #include #include #include #include #include int main (int argc, char **argv); void DoEPSTests(void); void DoPSTests(void); void DrawThings(PSStream *ps); void DrawTexts(PSStream *ps, double xc, double yc); void DrawLines(PSStream *ps, double xc, double yc, bool arrowheads); void DrawFigures(PSStream *ps, double xc, double yc, bool fill, bool draw); int main (int argc, char **argv) { DoEPSTests(); DoPSTests(); return 0; } void DoEPSTests(void) { PSStream *ps = pswr_new_stream(TRUE, "testplot", NULL, NULL, 328.0, 246.0); pswr_new_page(ps, NULL); pswr_set_window ( ps, -22.00, +22.00, -16.50, +16.50, 4.00, 324.00, 3.00, 243.00, 44, 33 ); DrawThings(ps); pswr_close_stream(ps); } void DoPSTests(void) { double hSize, vSize; /* Paper dimensions in pt. */ pswr_get_paper_dimensions("letter", &hSize, &vSize); PSStream *ps = pswr_new_stream(FALSE, "testplot", NULL, "letter", 0, 0); pswr_new_page(ps, "one"); pswr_set_window ( ps, -22.00, +22.00, -16.50, +16.50, 144.00, 464.00, 144.00, 384.00, 44, 33 ); DrawThings(ps); pswr_set_pen(ps, 0.000, 0.000, 1.000, 0.15, 0.0,0.0); pswr_add_caption(ps, "First Line Left Aligned\nSecond Line Left Aligned", 0.0); pswr_add_caption(ps, "Third Line Right Aligned", 1.0); pswr_add_caption(ps, "Fourth Line Centered", 0.5); pswr_set_window ( ps, -22.00, +22.00, -16.50, +16.50, 144.00, 304.00, 432.00, 552.00, 44, 33 ); DrawThings(ps); pswr_add_caption(ps, "This Figure No Caption", 0.5); pswr_new_page(ps, "two"); pswr_set_window ( ps, -22.00, +22.00, -16.50, +16.50, 144.00, 304.00, 432.00, 552.00, 44, 33 ); DrawThings(ps); pswr_close_stream(ps); } void DrawThings(PSStream *ps) { pswr_comment(ps, "Thick solid red frame:"); pswr_set_pen(ps, 1.000, 0.000, 0.000, 0.40, 0.0, 0.0); pswr_frame(ps); pswr_comment(ps, "Thin dashed light yellow gridlines:"); pswr_set_pen(ps, 1.000, 1.000, 0.500, 0.10, 2.0, 1.0); pswr_grid_lines(ps); pswr_comment(ps, "Medium solid black coordinate lines:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); pswr_coord_line(ps, HOR, 0.17); pswr_coord_line(ps, VER, 3.14); pswr_comment(ps, "Text in various positions:"); DrawTexts(ps, -20.0, -15.5); pswr_comment(ps, "Medium solid black segments:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.20, 0.0, 0.0); DrawLines(ps, -6.0, -15.5, FALSE); pswr_comment(ps, "Thicker blue segments with arrowheads:"); pswr_set_pen(ps, 0.000, 0.000, 1.000, 0.40, 0.0, 0.0); DrawLines(ps, +8.0, -15.5, TRUE); pswr_comment(ps, "Thin solid black figures, yellow filled:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.10, 0.0, 0.0); pswr_set_fill_color(ps, 1.000, 1.000, 0.000); pswr_grid_cell(ps, 3, 2, TRUE, TRUE); DrawFigures(ps, -20.0, +0.5, TRUE, TRUE); pswr_comment(ps, "Medium solid red figures, unfilled:"); pswr_set_pen(ps, 1.000, 0.000, 0.000, 0.20, 0.0, 0.0); pswr_set_fill_color(ps, -1.00, -1.00, -1.00); pswr_grid_cell(ps, 5, 2, TRUE, TRUE); DrawFigures(ps, -6.0, +0.5, TRUE, TRUE); pswr_comment(ps, "Unstroked figures, pink filled:"); pswr_set_pen(ps, 0.000, 0.000, 0.000, 0.50, 0.0, 0.0); pswr_set_fill_color(ps, 1.000, 0.800, 0.700); pswr_grid_cell(ps, 7, 2, TRUE, FALSE); DrawFigures(ps, +8.0, +0.5, TRUE, FALSE); } void DrawTexts(PSStream *ps, double xc, double yc) { /* Usable area [0 _ 12]×[0 _ 15] */ pswr_rectangle(ps, 0.25+xc, 11.75+xc, 0.25+yc, 14.75+yc, FALSE, TRUE); auto void do_lab(char *text, double xd, double yd, double xalign, double yalign); void do_lab(char *text, double xd, double yd, double xalign, double yalign) { pswr_set_fill_color(ps, 0.000, 0.700, 1.000); pswr_dot(ps, xd+xc, yd+yc, 0.3, TRUE, FALSE); pswr_label(ps, text, xd+xc, yd+yc, xalign, yalign); } pswr_set_pen(ps, 1.000, 0.000, 0.000, 0.50, 0.0, 0.0); pswr_set_label_font(ps, "Courier", 10.0); do_lab("red C10", +1.00, +3.00, 0.0, 0.0); pswr_set_label_font(ps, "Times-Roman", 12.0); do_lab("red TR12", +6.00, +6.00, 0.5, 0.0); pswr_set_pen(ps, 0.000, 0.000, 1.000, 0.50, 0.0, 0.0); pswr_set_label_font(ps, "Helvetica", 8.0); do_lab("blu H8", +11.00, +9.00, 1.0, 0.5); pswr_set_label_font(ps, "Courier", 12.0); do_lab("blu C12", +1.00, +12.00, 0.0, 0.5); } void DrawLines(PSStream *ps, double xc, double yc, bool arrowheads) { /* Usable area [0 _ 12]×[0 _ 15] */ pswr_rectangle(ps, 0.25+xc, 11.75+xc, 0.25+yc, 14.75+yc, FALSE, TRUE); auto void do_seg(double xa, double ya, double b, double yb); void do_seg(double xa, double ya, double xb, double yb) { pswr_segment(ps, xa+xc, ya+yc, xb+xc, yb+yc); pswr_dot(ps, xa+xc, ya+yc, 1.0, FALSE, TRUE); pswr_dot(ps, xb+xc, yb+yc, 1.0, FALSE, TRUE); if (arrowheads) { pswr_arrowhead(ps, xa+xc, ya+yc, xb+xc, yb+yc, 2.0, 3.0, 0.85, TRUE, TRUE); } } do_seg(1.0, 1.0, 11.0, 3.0); do_seg(1.0, 3.0, 11.0, 1.0); pswr_segment(ps, 1.0+xc, 5.0+yc, 1.0+xc, 13.0+yc); pswr_segment(ps, 11.0+xc, 5.0+yc, 11.0+xc, 13.0+yc); pswr_segment(ps, 2.0+xc, 14.0+yc, 10.0+xc, 14.0+yc); int i; for (i = -7; i <= +7; i++) { double align = ((i % 2) == 0)*0.5 - ((i % 4) == 0)*0.25; double ticksz = 0.5 + ((i % 2) == 0)*0.5 + ((i % 4) == 0)*1.0; pswr_tick(ps, VER, 1.0+xc, 9.0+0.5*i+yc, ticksz, align); pswr_tick(ps, VER, 11.0+xc, 9.0+0.5*i+yc, ticksz, 1-align); pswr_tick(ps, HOR, 6.0 + 0.5*i+xc, 14.0+yc, ticksz, 1-align); } pswr_curve(ps, 4.0+xc, 4.0+yc, 11.0+xc, 14.0+yc, 1.0+xc, 14.0+yc, 8.0+xc, 4.0+yc ); pswr_dot(ps, 4.0+xc, 4.0+yc, 1.0, FALSE, TRUE); pswr_dot(ps, 11.0+xc, 14.0+yc, 0.5, FALSE, TRUE); pswr_dot(ps, 1.0+xc, 14.0+yc, 0.5, FALSE, TRUE); pswr_dot(ps, 8.0+xc, 4.0+yc, 1.0, FALSE, TRUE); } void DrawFigures(PSStream *ps, double xc, double yc, bool fill, bool draw) { /* Usable area [0 _ 12]×[0 _ 15] */ pswr_rectangle(ps, 0.25+xc, 11.75+xc, 0.25+yc, 14.75+yc, FALSE, TRUE); int n = 5; double x[n], y[n]; int i; for (i = 0; i < 5; i++) { double t = 2.0*3.1415926*((double)i)/((double)n); x[i] = xc + 3.0 + 2.0*cos(t); y[i] = yc + 2.0 + 1.5*sin(t); } pswr_rectangle(ps, 7.0+xc, 9.0+xc, 1.5+yc, 3.5+yc, fill, draw); pswr_circle(ps, 3.0+xc, 7.0+yc, 2.0, fill, draw); pswr_dot(ps, 3.0+xc, 7.0+yc, 2.0, fill, draw); pswr_lune(ps, 9.0+xc, 7.0+yc, 1.5, 45.0, fill, draw); pswr_slice(ps, 3.0+xc, 12.0+yc, 2.0, 30.0, 135.0, fill, draw); pswr_polygon(ps, x, y, n, fill, draw); pswr_triangle(ps, 7.0+xc, 10.0+yc, 11.0+xc, 12.0+yc, 9.0+xc, 14.0+yc, fill, draw); }