Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a...

12
Pslib Manual Pslib Manual

Transcript of Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a...

Page 1: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

Pslib ManualPslib Manual

Page 2: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

2

PSlibPSlib

• Pslib is a library for making “postscript (ps)” file. • Postscript is a language for supporting the high-quality

printer. • Postscript language is developed by Adobe Inc.

Page 3: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

3

Postscript LanguagePostscript Language

• Postscript language is widely used in many environment to support the printer or for making high-quality documents.

• The syntax of the postscript language is very simple and you can find many on-line tutorial about it.

• You don’t have to learn the postscript language grammar to use the Pslib, but, if you are interested in the syntax and more about the postscript, you can refer to the following links: – http://www.cs.indiana.edu/docproject/programming/postscript/postscr

ipt.html

– http://www-ph.postech.ac.kr/material/comp/Software/POSTSCRIPT/

– http://astronomy.swin.edu.au/~pbourke/geomformats/postscript/

– http://www.mactech.com/articles/mactech/Vol.09/09.04/PostscriptTutorial/

– postscript language cookbook pdf ( I think this is illegal because the book is a commercial product, but, anyway, if you want…): http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF

Page 4: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

4

Viewing Postscript FileViewing Postscript File

• For viewing or printing a postscript file, you should install the following products:– Ghostscript– GSview– The above two software products can be freely downloaded fr

om: http://www.cs.wisc.edu/~ghost/– Note that the latetest version of the Ghostscript is 8.11 and th

at of GSview is 4.4 (Sep. 23, 2003).

• After the installations, you can test your “Gsview” by double-clicking “demo1/test.ps” file.

• If you have any problem to install the above two softwares, please let me know ([email protected])

Page 5: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

5

DEMO1DEMO1

• Demo1 for Pslib is a “console” program. • You don’t have to add any extra include directories or l

ink any extra libraries. • Start the demo1 project by clicking Pslib.dsw file.

Page 6: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

6

Source FilesSource Files

• Demo1 project consists of one header file (pslib.h) and two cpp files (demo.cpp and pslib.cpp).

• pslib.h and pslib.cpp– library source– You don’t have to change anything in these two files.

• demo.cpp– explaining how to use the pslib functions.

Page 7: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

7

demo.cpp - 1demo.cpp - 1

#include <iostream.h>#include "pslib.h"

int main(){

cPSLib myps("test.ps");

• You should include “pslib.h”• The cPSLib instance is made by using a constructor w

hich is called with a “ps file name” parameter. • Now, your further output in the program will be written i

nto the ps file “test.ps”.

Page 8: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

8

demo.cpp - 2demo.cpp - 2

float minx, miny, maxx, maxy; minx = -100.0f;

maxx = 400.0f; miny = -100.0f; maxy = 700.0f;

// fit the regions to A4myps.FitA4(minx, miny, maxx, maxy);

• At first, we define the boundary of the drawings. • We can make the boundary using PSlib::FitA4(…) func

tion.• Parameters: minx, miny, maxx, maxy• Then, the drawing area is scaled to the given boundar

y.

Page 9: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

9

demo.cpp - 3demo.cpp - 3

• Why A4Fit?– Sometimes, you want to draw some objects (lines, circles, …)

having very general coordinates. – The default size of A4 paper for the postscript is 595 x 842.– That is, the default x coordinate range is [0..595], and y coordi

nate range is [0..842]. – If you want to draw some point set in [-300..900] x [300..120

0], then you can fit the drawing area into the A4 paper using the function call:

myps.FitA4(-300, 300, 900, 1200);

– Note that this “FitA4” call should be made BEFORE ANY OTHER DRAWINGS in the ps file.

Page 10: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

10

demo.cpp - 4demo.cpp - 4

• DrawPolygon(xarray, yarray, num_points, fill_tag, width, color) – can draw the the “closed polygon” – Use “fill_tag = 1” for filling the polygon (if fill_tag = 0, no filling)– Use “width” for controlling the width of the line (any positive real val)– Use “color” for controlling the gray level of the color

• 0: black, 1: white, 0~1: gray value

// bounding box

float tx[4], ty[4];

tx[0] = minx;

ty[0] = miny;

tx[1] = minx;

ty[1] = maxy;

tx[2] = maxx;

ty[2] = maxy;

tx[3] = maxx;

ty[3] = miny;

myps.DrawPolygon(tx, ty, 4, 0, 1.0f);

Page 11: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

11

demo.cpp - 5demo.cpp - 5

• Draw a line (x1,y1) – (x2,y2)DrawLine(float x1, float y1, float x2, float y2,

float width=1.0f, float color=0.0f);

• Draw a circle at center (cx, cy) with radius “radius”. DrawCircle(float cx, float cy, float radius,

int fill=0, float width=1.0f, float color=0.0f);

• Show a test string “Text” at (x, y) DrawText(float x, float y, char *Text, int Scale=12,

float color=0.0f);

Page 12: Pslib Manual. 2 PSlib Pslib is a library for making “postscript (ps)” file. Postscript is a language for supporting the high-quality printer. Postscript.

12

demo.cpp - 6demo.cpp - 6

• After all drawings, you should call “myps.CloseFile()”.