/* -*- c++ -*- FILE: PostScriptWriter.cpp RCS REVISION: $Revision: 1.3 $ COPYRIGHT: (c) 1999 -- 2003 Melinda Green, Don Hatch, and Jay Berkenbilt - Superliminal Software LICENSE: Free to use and modify for non-commercial purposes as long as the following conditions are adhered to: 1) Obvious credit for the source of this code and the designs it embodies are clearly made, and 2) Ports and derived versions of 4D Magic Cube programs are not distributed without the express written permission of the authors. DESCRIPTION: Implementation of the PostScriptWriter class */ #include "PostScriptWriter.h" #include #include #include #include "Puzzlest.h" #include "PSProlog.h" #include "Preferences.h" PostScriptWriter::PostScriptWriter(Preferences& prefs, PuzzleState& ps, struct frame& uframe) : preferences(prefs), puzzle_state(ps), frame(uframe) { } bool PostScriptWriter::generateOutput(char const* filename) { FILE* file = fopen(filename, "w"); if (file == NULL) { fprintf(stderr, "unable to open %s: %s\n", filename, strerror(errno)); return false; } // Generate image inside a 6'' square. double const sidelength = 72.0 * 6.0; fputs(psp_before, file); // Draw background fprintf(file, "drawBackground\n"); // Draw polygons bool do_outline = preferences.getBoolProperty(M4D_OUTLINE); fprintf(file, "/outlines %s def\n", (do_outline ? "true" : "false")); int i; for (i = 0; i < frame.nquads; ++i) { int j; double x[4]; double y[4]; for (j = 0; j < 4; ++j) { x[j] = sidelength * frame.verts[frame.quads[i][j]][X] / 65536.0; y[j] = sidelength * frame.verts[frame.quads[i][j]][Y] / 65536.0; } real brightness = frame.brightnesses[i]; int color = puzzle_state.idToColor((int)frame.quadids[i] / 6); fprintf(file, "%d %.2f ", color, brightness); for (j = 0; j < 4; ++j) { fprintf(file, "%.2f %.2f ", x[j], y[j]); } fprintf(file, "drawPolygon\n"); } fputs(psp_after, file); fclose(file); return true; } // Local Variables: // c-basic-offset: 4 // c-comment-only-line-offset: 0 // c-file-offsets: ((defun-block-intro . +) (block-open . 0) (substatement-open . 0) (statement-cont . +) (statement-case-open . +4) (arglist-intro . +) (arglist-close . +) (inline-open . 0)) // indent-tabs-mode: nil // End: