Canola
0.8.D001
|
00001 // 00002 // canola - canon canola 1614p emulator 00003 // Copyright (C) 2011 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/ac/math.h> 00019 #include <cairomm/context.h> 00020 #include <cairomm/surface.h> 00021 00022 #include <lib/program_card/functor/image/svg.h> 00023 #include <lib/std_string_printf.h> 00024 00025 00026 program_card_functor_image_svg::~program_card_functor_image_svg() 00027 { 00028 } 00029 00030 00031 program_card_functor_image_svg::program_card_functor_image_svg( 00032 const std::string &fn 00033 ) : 00034 filename(fn) 00035 { 00036 } 00037 00038 00039 program_card_functor_image::pointer 00040 program_card_functor_image_svg::create(const std::string &fn) 00041 { 00042 return pointer(new program_card_functor_image_svg(fn)); 00043 } 00044 00045 00046 void 00047 program_card_functor_image_svg::operator()(unsigned card_num, 00048 unsigned card_count, const unsigned char *data, size_t data_size) 00049 { 00050 set_position(card_num, card_count); 00051 00052 // build the output file name 00053 std::string fn = filename; 00054 if (card_count > 1) 00055 { 00056 if (fn.size() > 4 && fn.substr(fn.size() - 4, 4) == ".svg") 00057 fn = fn.substr(0, fn.size() - 4); 00058 fn += std_string_printf("-%u-of-%u.svg", card_num, card_count); 00059 } 00060 00061 // 00062 // Create an image surface to draw on. 00063 // 00064 double points_per_inch = 72; 00065 int w = floor(0.5 + (1360./600.) * points_per_inch); 00066 int h = floor(0.5 + (4425./600.) * points_per_inch); 00067 Cairo::RefPtr<Cairo::Surface> img = Cairo::SvgSurface::create(fn, w, h); 00068 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(img); 00069 00070 // 00071 // Draw the card image. 00072 // 00073 draw(cr, data, data_size); 00074 }