GhostScript converts PostScript language commands into bitmaps that can be rendered on a screen or a printer. This library translates text and graphics requests to PostScript and sends them to the GhostScript process which returns a bitmap graphics buffer that contains the rendered image.
ps-close terminates the GhostScript process associated with the specified handle and deallocates any associated memory.(set ps-handle (ps-init))
The returned image is tightly cropped to the text, unless False is passed for the crop argument. The font argument is optional, and defaults to "Times" if it is Null or not given. If the specified font cannot be found, the "nearest" font will be used. Italic or bold faces can be specifed after a hyphen in the string, such as "Times-Italic" or "Times-Bold".
The quality argument is also optional and defaults to 3. It can range between 1 (fastest and worst) and 10 (slowest and best).
Below is an example that generates the alpha channel for a piece of text, creates an solid-colored RGB image for the text, and composites that text into a background image.
# initialize the postscript renderer (set ps-handle (ps-init)) # render the alpha (transparency) channel for a piece of text (set alphaimage (ps-best-text ps-handle "Satyricon" 60 "Times")) # display the alpha channel for fun (set xwin (xwin-create Null Null [100 100] (alphaimage buf-dims))) (xwin-display-image xwin alphaimage) # make a yellowish RGB image that will serve as the text color (set rgbimage (new-standard-image 3 (alphaimage buf-dims))) (image-fill-constant 255 (isolate-channel 0 rgbimage)) (image-fill-constant 200 (isolate-channel 1 rgbimage)) (image-fill-constant 0 (isolate-channel 2 rgbimage)) # make a reddish "background image" to composite the text onto (set outimage (new-standard-image 3 (alphaimage buf-dims))) (image-fill-constant 128 (isolate-channel 0 outimage)) (image-fill-constant 0 (isolate-channel 1 outimage)) (image-fill-constant 0 (isolate-channel 2 outimage)) # composite the text using the alpha (image-composite rgbimage alphaimage outimage) # composite the text # display the result (set xwin2 (xwin-create Null Null [100 200] (outimage buf-dims))) (xwin-display-image xwin2 outimage)
Calling ps-render returns an RGB Isis image buffer of the current page size which reflects all of the commands sent since the last render command. The returned image should not be freed--it is reused by the rendering engine. Make a separate copy of the image using image-copy if you intend to keep it for later use.
Here are few low-level examples:
# EXAMPLE 1: Flash "Hello World" in changing colors (set width 700) (set height 100) (set winaddr (xwin-create Null "PostScript Test1" Null [width height])) (set engine (ps-init)) (ps-setpagesize engine [width height]) (ps-setrgbcolor engine [1.0 0.0 0.0]) (ps-scalefont engine 135) (while True (begin (ps-setrgbcolor engine [(/ (real (random)) rand-max) (/ (real (random)) rand-max) (/ (real (random)) rand-max)]) (ps-moveto engine [0 0]) (ps-showtext engine "Hello World") (xwin-display-image winaddr (ps-render engine)))) # EXAMPLE 2: A bunch of random arcs and lines.... (set width 300) (set height 300) (set winaddr (xwin-create Null "PostScript Test2" Null [width height])) (set engine (ps-init)) (ps-setpagesize engine [width height]) (ps-moveto engine [0 0]) (ps-lineto engine [100 100]) (ps-setlinewidth engine 5) (ps-curveto engine [200 200] [100 150] [125 125]) (ps-moveto engine [50 200]) (ps-setlinewidth engine 2) (ps-arc engine [50 200] 25 0 300) (set image (ps-render engine)) (xwin-display-image winaddr image) # EXAMPLE 3: make "Hello" in a circle (set width 300) (set height 300) (set winaddr (xwin-create Null "PostScript Test2" Null [width height])) (set engine (ps-init)) (ps-setpagesize engine [width height]) (ps-scalefont engine 40) (ps-moveto engine [(+ (/ width 2) 40) 40]) (set angle 0) (while (< angle 360) (begin (ps-setrgbcolor engine [(/ (real (random)) rand-max) (/ (real (random)) rand-max) (/ (real (random)) rand-max)]) (ps-rotate engine 40) (set angle (+ angle 40)) (ps-showtext engine "Hello"))) (set image (ps-render engine)) (xwin-display-image winaddr image) ## EXAMPLE 4: mesages around the screen (set rand-color (proc (engine) (ps-setrgbcolor engine [(/ (real (random)) rand-max) (/ (real (random)) rand-max) (/ (real (random)) rand-max)]))) (set width 800) (set height 800) (set winaddr (xwin-create Null "PostScript Test3" Null [width height])) (set engine (ps-init)) (ps-setpagesize engine [width height]) (ps-scalefont engine 30) (ps-moveto engine [(+ 125 (/ width 2)) (+ 50 (/ height 2))]) (set angle 90) (while (> angle 0) (begin (ps-rotate engine angle) (rand-color engine) (ps-showtext engine "In Postscript ") (ps-rotate engine angle) (rand-color engine) (ps-showtext engine "it is easy ") (ps-rotate engine angle) (rand-color engine) (ps-showtext engine "to go around ") (ps-rotate engine angle) (rand-color engine) (ps-showoutline engine "the screen! ") (set angle (- angle 1)))) (set image (ps-render engine)) (xwin-display-image winaddr image)
Scripts: | (load "postscript.isis")
|
Other: | Uses the Ghostscript (gs) postscript interpreter |