home *** CD-ROM | disk | FTP | other *** search
- /*ScianPostScript.c
- Eric Pepke
- June 4, 1993
- PostScript pseudorecorder*/
-
- #include "Scian.h"
- #include "ScianTypes.h"
- #include "ScianArrays.h"
- #include "ScianLists.h"
- #include "ScianWindows.h"
- #include "ScianObjWindows.h"
- #include "ScianIcons.h"
- #include "ScianControls.h"
- #include "ScianButtons.h"
- #include "ScianDraw.h"
- #include "ScianIDs.h"
- #include "ScianPostScript.h"
- #include "ScianRecorders.h"
- #include "ScianStyle.h"
- #include "ScianTemplates.h"
- #include "ScianTemplateHelper.h"
- #include "ScianTextBoxes.h"
-
- static long curFrame = 0;
-
- static ObjPtr ReturnTrue(object)
- ObjPtr object;
- /*Returns true*/
- {
- return ObjTrue;
- }
-
- static ObjPtr PrepareToRecordPostScript(object, nFrames)
- ObjPtr object;
- long nFrames;
- /*Prepares to record nframes*/
- {
- curFrame = 0;
- return ObjTrue;
- }
-
- static ObjPtr SnapOneFramePostScript(object)
- ObjPtr object;
- /*Snap a single PostScript frame*/
- {
- int l, b, r, t, w, h;
- ObjPtr var;
- char *name;
- ObjPtr windows;
- ThingListPtr runner;
- real scale;
-
- var = GetVar(object, FRAMEOX);
- if (var)
- {
- l = GetInt(var);
- }
- else
- {
- l = 0;
- }
-
- var = GetVar(object, FRAMEOY);
- if (var)
- {
- b = GetInt(var);
- }
- else
- {
- b = 0;
- }
-
- var = GetVar(object, FRAMEWIDTH);
- if (var)
- {
- w = GetInt(var);
- }
- else
- {
- w = 0;
- }
-
- var = GetVar(object, FRAMEHEIGHT);
- if (var)
- {
- h = GetInt(var);
- }
- else
- {
- h = 0;
- }
-
- r = l + w - 1;
- t = b + h - 1;
- if (GetPredicate(object, SAVEWINDOWFRAME))
- {
- l -= WINBL;
- r += WINBR;
- b -= WINBB;
- t += WINBT;
- }
-
- do
- {
- ++curFrame;
- sprintf(tempStr, "screen%04d.eps", curFrame);
- } while (fopen(tempStr, "r"));
-
- SetVar(object, FILENAME, NewString(tempStr));
-
- var = GetVar(object, IMGQUAL);
- if (var)
- {
- imageSubSample = GetInt(var);
- }
- else
- {
- imageSubSample = 0;
- }
-
- var = GetVar(object, ENLARGEMENT);
- if (var)
- {
- scale = GetReal(var) * 0.01;
- }
- else
- {
- scale = 0.5;
- }
-
- drawFile = fopen(tempStr, "w");
- if (drawFile)
- {
- if (GetPredicate(object, SAVEWINDOWFRAME))
- {
- l -= WINFRAMEWID;
- r += WINFRAMEWID;
- b -= WINFRAMEWID;
- t += WINFRAMEWID + WINTITLEHT;
- }
-
- drawingMode = DRAW_POSTSCRIPT;
- BeginDrawing("screen" , l, r, b, t, scale);
-
- windows = GetVar(object, RECORDWINDOWS);
- if (windows)
- {
- runner = LISTOF(windows);
- while(runner)
- {
- WinInfoPtr window;
- int ox, oy;
- int wl, wr, wb, wt;
-
- window = (WinInfoPtr) (runner -> thing);
-
- SelWindow(window);
-
- GetWindowOrigin(&ox, &oy);
- GetWindowBounds(&wl, &wr, &wb, &wt);
-
- SetDrawingWindow(window);
- BeginDrawSubscreen(ox - l, oy - b);
- DrawWindowInfo(window);
- if (GetPredicate(object, SAVEWINDOWFRAME))
- {
- DrawPSFrame(window -> winTitle, ox - l, ox + wr - wl - l, oy - b, oy + wt - wb - b);
- }
- EndDrawSubscreen(ox - l, oy - b);
- RestoreDrawingWindow();
-
- runner = runner -> next;
- }
- }
- EndDrawing(GetPredicate(object, SHOWPAGE));
- drawingMode = DRAW_SCREEN;
- fclose(drawFile);
- }
-
- return ObjTrue;
- }
-
- static ObjPtr AddPostScriptControls(object, panelContents)
- ObjPtr object, panelContents;
- /*Adds controls appropriate to a PostScript object to panelContents*/
- {
- ObjPtr titleBox, button, radio, var;
- ObjPtr textBox, checkBox;
-
- /*Make title box for quality*/
- titleBox = TemplateTitleBox(PostScriptTemplate, "Image Quality");
- PrefixList(panelContents, titleBox);
- SetVar(titleBox, PARENT, panelContents);
-
- /*Make quality radio button*/
- radio = NewRadioButtonGroup("Quality");
- PrefixList(panelContents, radio);
- SetVar(radio, PARENT, panelContents);
- SetVar(radio, HELPSTRING, NewString("This radio button group sets the quality of \
- the image portions of the PostScript file. Lower numbers give lower quality with a substantial \
- savings in file size."));
-
- /*Make the radios*/
- button = TemplateRadioButton(PostScriptTemplate, "Full Quality");
- AddRadioButton(radio, button);
- SetVar(radio, HELPSTRING, NewString("When this radio button is on, the \
- image portions of the PostScript file are saved at full quality."));
-
- button = TemplateRadioButton(PostScriptTemplate, "1/2 Quality");
- AddRadioButton(radio, button);
- SetVar(radio, HELPSTRING, NewString("When this radio button is on, the \
- image portions of the PostScript file are saved at half quality, resulting in file \
- 1/4 as large."));
-
- button = TemplateRadioButton(PostScriptTemplate, "1/3 Quality");
- AddRadioButton(radio, button);
- SetVar(radio, HELPSTRING, NewString("When this radio button is on, the \
- image portions of the PostScript file are saved at a third quality, resulting in file \
- 1/9 as large."));
-
- button = TemplateRadioButton(PostScriptTemplate, "1/4 Quality");
- AddRadioButton(radio, button);
- SetVar(radio, HELPSTRING, NewString("When this radio button is on, the \
- image portions of the PostScript file are saved at a quarter quality, resulting in file \
- 1/16 as large."));
-
- AssocDirectControlWithVar(radio, object, IMGQUAL);
-
- /*Make enlarge or reduce*/
- textBox = TemplateTextBox(PostScriptTemplate, "Enlarge or reduce", ONE_LINE,
- "Enlarge or Reduce");
- PrefixList(panelContents, textBox);
- SetVar(textBox, PARENT, panelContents);
-
- textBox = TemplateTextBox(PostScriptTemplate, "Enlargement", EDITABLE + WITH_PIT + ONE_LINE,
- "");
- PrefixList(panelContents, textBox);
- SetVar(textBox, PARENT, panelContents);
- AssocTextRealControlWithVar(textBox, object, ENLARGEMENT, 1.0, 1000.0, 0);
- SetVar(textBox, HELPSTRING, NewString("Enter into this text box the amount you would like \
- to enlarge or reduce the image on the screen. 100% is full size."));
-
- textBox = TemplateTextBox(PostScriptTemplate, "%", ONE_LINE, "%");
- PrefixList(panelContents, textBox);
- SetVar(textBox, PARENT, panelContents);
-
- checkBox = TemplateCheckBox(PostScriptTemplate,
- "Include 'showpage' at End", 0);
- PrefixList(panelContents, checkBox);
- SetVar(checkBox, PARENT, panelContents);
- AssocDirectControlWithVar(checkBox, object, SHOWPAGE);
- SetVar(checkBox, HELPSTRING, NewString("When this box is checked, a \
- 'showpage' will appear at the end of the PostScript file. This is correct if \
- the file will be printed directly. Otherwise, no 'showpage' will appear. \
- This is correct when using the file as an embedded PostScript file."));
-
- return ObjTrue;
- }
-
- #ifdef PROTO
- void InitPostScript(void)
- #else
- void InitPostScript()
- #endif
- /*Create a new PostScript ersatz recorder*/
- {
- ObjPtr recorder, icon;
-
- recorder = NewRecorder(NULLOBJ, "PostScript", "Adobe");
- SetMethod(recorder, CONNECT, ReturnTrue);
- SetMethod(recorder, DISCONNECT, ReturnTrue);
- SetMethod(recorder, PREPARETORECORD, PrepareToRecordPostScript);
- SetMethod(recorder, STOPRECORDING, ReturnTrue);
- SetMethod(recorder, SNAPONEFRAME, SnapOneFramePostScript);
- SetVar(recorder, FRAMESOURCE, NewInt(FS_WINDOW));
- SetVar(recorder, ENABLEDSOURCES, NewInt(FB_WINDOW));
- SetVar(recorder, IMGQUAL, NewInt(0));
- SetVar(recorder, SHOWPAGE, ObjTrue);
- SetVar(recorder, ENLARGEMENT, NewReal(50.0));
- AddSnapVar(recorder, IMGQUAL);
- AddSnapVar(recorder, SHOWPAGE);
- AddSnapVar(recorder, ENLARGEMENT);
-
- SetMethod(recorder, ADDCONTROLS, AddPostScriptControls);
- icon = NewIcon(0, 0, ICONRECORDER, "PostScript");
- SetVar(recorder, CONTROLICON, icon);
-
- RegisterRecorder(recorder);
- }
-
- #ifdef PROTO
- void KillPostScript(void)
- #else
- void KillPostScript()
- #endif
- {
- }
-