Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Generating postscript file

0 views
Skip to first unread message

BCC

unread,
Nov 4, 2004, 12:52:54 PM11/4/04
to
Does anyone know of a perl module like GD that will allow me to draw
with colors and shapes and save it as a postscript file? GD doesnt give
me that option unfortunately.

Looked in CPAN and didnt see anything.

Thanks

Ala Qumsieh

unread,
Nov 4, 2004, 1:05:50 PM11/4/04
to
BCC wrote:
> Does anyone know of a perl module like GD that will allow me to draw
> with colors and shapes and save it as a postscript file? GD doesnt give
> me that option unfortunately.

Could be overkill, but a Tk::Canvas allows you to dump the contents of
the canvas as a postscript file. It is part of Tk which is a GUI
toolkit, so you won't find all of the functionality offered by
graphics-specific modules like GD.

--Ala

Jon Ericson

unread,
Nov 4, 2004, 6:24:37 PM11/4/04
to
BCC <br...@akanta.net> writes:

Not a Perl solution, but I use MetaPost
(http://cm.bell-labs.com/who/hobby/MetaPost.html).

It looks like there's a PostScript::Simple module
(http://search.cpan.org/~mcnewton/PostScript-Simple-0.06/).

Jon

Ian Wilson

unread,
Nov 5, 2004, 9:07:31 AM11/5/04
to
BCC wrote:

#!/bin/perl
use warnings;
use strict;

my $text='Why not learn Postscript?';

print <<ENDPS;
%!PS
%
% define a handy subroutine to scale units
%
/inch { 72 mul } def
%
% draw a blue rectangle
%
0 0 1 setrgbcolor
1 inch 8 inch moveto
6 inch 8 inch lineto
6 inch 9 inch lineto
1 inch 9 inch lineto
closepath
fill
%
% write some text
%
1.8 inch 8.4 inch moveto
/Helvetica findfont 22 scalefont setfont
1 setgray
($text) show
%
% emit page
%
showpage
ENDPS

zentara

unread,
Nov 7, 2004, 9:26:51 AM11/7/04
to
On Fri, 5 Nov 2004 14:07:31 +0000 (UTC), Ian Wilson
<scob...@infotop.co.uk> wrote:

>BCC wrote:
>
>> Does anyone know of a perl module like GD that will allow me to draw
>> with colors and shapes and save it as a postscript file? GD doesnt give
>> me that option unfortunately.
>>
>> Looked in CPAN and didnt see anything.

Create a tk Canvas, and create what you want, then use the
postscript method to save it. A typical "save" routine looks something
like this:
##########################################
$main->Button(
-text => "Save",
-command => [sub {
$canvas->update;
my @capture=();
my ($x0,$y0,$x1,$y1)=$canvas->bbox('all');

@capture=('-x'=>$x0,'-y'=>$y0,-height=>$y1-$y0,-width=>$x1-$x0);
$canvas->postscript(-colormode=>'color',
-file=>$0.'.ps',
-rotate=>0,
-width=>800,
-height=>500,
@capture);

}
] )->pack;
###########################################

Now you have a wide variety of options on how to generate
your Canvas. You can do it programatically, or use some sort
of mouse-GUI.
For examples of that,
http://perlmonks.thepen.com/176475.html
or
ged at
http://www.duehl.de/christian/perl/ged.html

The cpan module Tk::WorldCanvas might be helpful too.

--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

0 new messages