Canola  0.8.D001
lib/program_card/functor/image/pixbuf.cc
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include <lib/program_card/functor/image/pixbuf.h>
00019 
00020 
00021 program_card_functor_image_pixbuf::~program_card_functor_image_pixbuf()
00022 {
00023 }
00024 
00025 
00026 program_card_functor_image_pixbuf::program_card_functor_image_pixbuf(
00027     result_t &a_result,
00028     double a_dpi
00029 ) :
00030     result(a_result),
00031     dots_per_inch(a_dpi)
00032 {
00033 }
00034 
00035 
00036 program_card_functor_image_pixbuf::pointer
00037 program_card_functor_image_pixbuf::create(result_t &a_result, double a_dpi)
00038 {
00039     return pointer(new program_card_functor_image_pixbuf(a_result, a_dpi));
00040 }
00041 
00042 
00043 void
00044 program_card_functor_image_pixbuf::operator()(unsigned card_num,
00045     unsigned card_count, const unsigned char *data, size_t data_size)
00046 {
00047     set_position(card_num, card_count);
00048 
00049     //
00050     // Create an image surface to draw on.
00051     //
00052     int w = floor(0.5 + (1360./600.) * dots_per_inch);
00053     int h = floor(0.5 + (4425./600.) * dots_per_inch);
00054     Cairo::RefPtr<Cairo::Surface> img =
00055         Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, w, h);
00056     Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(img);
00057 
00058     // The card drawing functions assume units are in points, just like
00059     // PostScript uses.
00060     double s = dots_per_inch / 72.;
00061     cr->scale(s, s);
00062 
00063     //
00064     // Draw the card image.
00065     //
00066     draw(cr, data, data_size);
00067 
00068     //
00069     // Make a pixbuf out of the cairo image surface.
00070     //
00071     pixbuf_ptr_t p = Gdk::Pixbuf::create(img, 0, 0, w, h);
00072     result.push_back(p);
00073 }