]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/BGB/Draw.pm
added PDF/SVG export to BGB
[biopieces.git] / code_perl / Maasha / BGB / Draw.pm
index 1a76cd5620c8a8f4a0d5dada62e7f8309dfa6466..2f0577a6ac639f95771aa263242f67f72193a09a 100644 (file)
@@ -253,6 +253,100 @@ sub palette
 }   
 
 
+sub render_png
+{
+    # Martin A. Hansen, March 2010.
+
+    # Given a list of BGB tracks, render the
+    # PNG surface stream and return the base64
+    # encoded PNG data.
+
+    my ( $width,    # image width
+         $height,   # image height
+         $tracks,   # list of BGB tracks to render
+       ) = @_;
+
+    # Returns a string.
+
+    my ( $surface, $cr, $track, $png_data );
+
+    $surface = Cairo::ImageSurface->create( 'argb32', $width, $height );
+    $cr      = Cairo::Context->create( $surface );
+
+    $cr->rectangle( 0, 0, $width, $height );
+    $cr->set_source_rgb( 1, 1, 1 );
+    $cr->fill;
+
+    foreach $track ( @{ $tracks } ) {
+        draw_feature( $cr, $track ) if $track;
+    }
+
+    $png_data = base64_png( $surface );
+
+    return $png_data;
+}
+
+
+sub render_pdf_file
+{
+    # Martin A. Hansen, March 2010.
+
+    # Given a list of BGB tracks, render these and save
+    # to a PDF file.
+
+    my ( $file,     # path to PDF file
+         $width,    # image width
+         $height,   # image height
+         $tracks,   # list of BGB tracks to render
+       ) = @_;
+
+    # Returns nothing.
+
+    my ( $surface, $cr, $track );
+
+    $surface = Cairo::PdfSurface->create ( $file, $width, $height );
+    $cr      = Cairo::Context->create( $surface );
+
+    $cr->rectangle( 0, 0, $width, $height );
+    $cr->set_source_rgb( 1, 1, 1 );
+    $cr->fill;
+
+    foreach $track ( @{ $tracks } ) {
+        draw_feature( $cr, $track ) if $track;
+    }
+}
+
+
+sub render_svg_file
+{
+    # Martin A. Hansen, March 2010.
+
+    # Given a list of BGB tracks, render these and save
+    # to a SVG file.
+
+    my ( $file,     # path to PDF file
+         $width,    # image width
+         $height,   # image height
+         $tracks,   # list of BGB tracks to render
+       ) = @_;
+
+    # Returns nothing.
+
+    my ( $surface, $cr, $track );
+
+    $surface = Cairo::SvgSurface->create ( $file, $width, $height );
+    $cr      = Cairo::Context->create( $surface );
+
+    $cr->rectangle( 0, 0, $width, $height );
+    $cr->set_source_rgb( 1, 1, 1 );
+    $cr->fill;
+
+    foreach $track ( @{ $tracks } ) {
+        draw_feature( $cr, $track ) if $track;
+    }
+}
+
+
 sub file_png
 {
     # Martin A. Hansen, October 2009.