1 package Maasha::KISS::Draw;
3 # Copyright (C) 2009 Martin A. Hansen.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # Routines for creating KISS graphics using Cairo and Pango.
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
37 use vars qw( @ISA @EXPORT );
39 @ISA = qw( Exporter );
42 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
47 # Given a sequence list add this to
48 # a Cairo::Context object.
50 my ( $cr, # Cairo::Context object
51 $text, # List of hashrefs { txt =>, x => y => }
52 $color, # Color of features
57 $cr->set_source_rgb( color_name2rgb( $color ) );
61 $cr->set_font_size( 10 );
63 foreach $txt ( @{ $text } )
65 $cr->move_to( $txt->{ 'x' }, $txt->{ 'y' } );
66 $cr->show_text( $txt->{ 'txt' } );
74 # Given a list of features add these to
75 # a Cairo::Context object.
77 my ( $cr, # Cairo::Context object
78 $features, # List of features
79 $color, # Color of features
86 foreach $feature ( @{ $features } )
88 $cr->set_source_rgb( color_name2rgb( $feature->{ 'color' } ) );
89 $cr->move_to( $feature->{ 'x1' }, $feature->{ 'y1' } );
91 if ( $feature->{ 'type' } eq 'line' )
93 $cr->set_line_width( $feature->{ 'line_width' } );
94 $cr->line_to( $feature->{ 'x2' }, $feature->{ 'y2' } );
96 elsif ( $feature->{ 'type' } eq 'text' )
98 $cr->set_font_size( $feature->{ 'font_size' } );
99 $cr->show_text( $feature->{ 'txt' } );
112 my ( %color_hash, $rgb );
115 'black' => [ 0, 0, 0 ],
116 'red' => [ 255, 0, 0 ],
117 'green' => [ 0, 255, 0 ],
118 'blue' => [ 0, 0, 255 ],
121 if ( exists $color_hash{ $color_name } ) {
122 $rgb = $color_hash{ $color_name };
127 return wantarray ? @{ $rgb } : $rgb;
133 # Martin A. Hansen, October 2009.
135 # Prints a Cairo::Surface object to a PNG file.
137 my ( $surface, # Cairo::Surface object
138 $file, # path to PNG file
143 $surface->write_to_png( $file );
153 @html = "Content-Type: text/html; charset=ISO-8859-1\n\n";
155 push @html, "<pre>\n";
156 push @html, Dumper( $foo );
157 push @html, "</pre>\n";
159 return wantarray ? @html : \@html;
163 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<