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/ps.h> 00023 00024 00025 program_card_functor_image_ps::~program_card_functor_image_ps() 00026 { 00027 } 00028 00029 00030 program_card_functor_image::pointer 00031 program_card_functor_image_ps::create(const std::string &fn) 00032 { 00033 return pointer(new program_card_functor_image_ps(fn)); 00034 } 00035 00036 00037 static double page_width = 210 / 25.4 * 72; 00038 static double page_height = 297 / 25.4 * 72; // points 00039 static double card_width = 1360. / 600. * 72.; // points 00040 static double card_height = 4425. / 600. * 72.; 00041 static double gap = 72. / 4; 00042 00043 00044 program_card_functor_image_ps::program_card_functor_image_ps( 00045 const std::string &fn 00046 ) : 00047 filename(fn) 00048 { 00049 img = Cairo::PsSurface::create(filename, page_width, page_height); 00050 cr = Cairo::Context::create(img); 00051 00052 // pcd.set_card_num(card_num); 00053 // pcd.set_card_count(card_count); 00054 // FIXME: add more style options 00055 // what colour? 00056 // with an arrow? 00057 // with instruction disassembly on right hand side? 00058 // white holes or black holes? 00059 // blank or with "perforations"? 00060 } 00061 00062 00063 void 00064 program_card_functor_image_ps::operator()(unsigned card_num, 00065 unsigned card_count, const unsigned char *data, size_t data_size) 00066 { 00067 set_position(card_num, card_count); 00068 00069 assert(card_count > 0); 00070 assert(card_num >= 1); 00071 assert(card_num <= card_count); 00072 --card_num; 00073 00074 int cards_per_page = page_height / (card_width + gap); 00075 int top_margin = (page_height - cards_per_page * (card_width + gap)) / 2; 00076 if (card_num && 0 == (card_num % cards_per_page)) 00077 { 00078 cr->show_page(); 00079 } 00080 card_num %= cards_per_page; 00081 00082 double x = (page_width - card_height) / 2; 00083 double y = top_margin + card_num * (card_width + gap) + card_width; 00084 00085 cr->save(); 00086 cr->translate(x, y); 00087 cr->rotate_degrees(-90); 00088 00089 // 00090 // Draw the card image. 00091 // 00092 draw(cr, data, data_size); 00093 cr->restore(); 00094 }