Changeset 78 in projects for paper-tape-project/trunk
- Timestamp:
- Jul 27, 2013, 8:49:16 AM (11 years ago)
- Location:
- paper-tape-project/trunk
- Files:
-
- 36 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
paper-tape-project/trunk/perl-tools/hex-meter
r1 r78 3 3 # 4 4 5 for($x=0; $x < $ARGV[0]; $x++) {5 for($x=0; $x < (@ARGV ? $ARGV[0] : 1); $x++) { 6 6 for($y=0; $y<2**8; $y++) { 7 7 print pack('C', $y); -
paper-tape-project/trunk/perl-tools/how-long-is-this-papertape
r1 r78 6 6 # 7 7 8 # if called with no argument: use stdin 9 unless(@ARGV) { 10 my $slurp = do { local $/; <STDIN> }; 11 my $l = length($slurp); 12 print "stdin: $l bytes = ".bytes2cm($l)." cm\n"; 13 } 14 8 15 my $total_l = 0; my $l; 9 16 foreach (@ARGV) { … … 12 19 $total_l += $l; 13 20 } 21 14 22 print "total: $total_l bytes = ".bytes2cm($total_l)." cm\n" 15 unless($l eq $total_l ); # nur ein Argument.23 unless($l eq $total_l or !@ARGV); # nur ein Argument. 16 24 17 25 sub bytes2cm { -
paper-tape-project/trunk/visualisator/cli.c
r76 r78 42 42 43 43 LOCHSTREIFEN *l; 44 enum _surface_type { 45 PNG_SURFACE, 46 SVG_SURFACE 47 } surface_type; 44 lochstreifen_export_type surface_type; 48 45 char *output_file; 49 46 int verbosity = 0; … … 147 144 // set file format 148 145 if(strcasecmp(arg, "png") == 0) 149 surface_type = PNG_SURFACE;146 surface_type = LOCHSTREIFEN_FORMAT_PNG; 150 147 else if(strcasecmp(arg, "svg") == 0) 151 surface_type = SVG_SURFACE;148 surface_type = LOCHSTREIFEN_FORMAT_SVG; 152 149 else 153 150 argp_error(state, "Only PNG and SVG are supported as file formats.\n"); … … 337 334 } 338 335 339 /**340 * Helper function: A simple closure for a cairo_surface_t (PNG and SVG) to write out data341 * either to a file or to stdout (given in first parameter)342 **/343 cairo_status_t lochstreifen_out_closure(void *closure, unsigned char *data, unsigned int length) {344 // einfach nur in das uebergebene Dateihandle schreiben345 fwrite(data, length, 1, (FILE *)closure);346 return CAIRO_STATUS_SUCCESS;347 }348 336 349 337 /** … … 351 339 **/ 352 340 int main(int argc, char *argv[]) { 353 cairo_t *cr; ///< A cairo context, given from...354 cairo_surface_t *surface; ///< ...this generic cairo surface355 341 byte_t *data; ///< the data array, will be filled by file_get_contents 356 342 int length; ///< the length of that data array … … 415 401 } 416 402 417 lochstreifen_print_debug(l); 418 exit(0); 419 420 // setting up the surface and painting... 421 if(surface_type == PNG_SURFACE) { 422 cairo_status_t status; 423 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 424 lochstreifen_get_target_width(l), 425 lochstreifen_get_target_height(l) 426 ); 427 cr = cairo_create(surface); 428 lochstreifen_draw(l, cr); 429 430 status = cairo_surface_write_to_png_stream(surface, (cairo_write_func_t)lochstreifen_out_closure, out); 431 DPRINTF("PNG file generated: %s\n", cairo_status_to_string(status)); 432 return 0; 433 } else if(surface_type == SVG_SURFACE) { 434 surface = cairo_svg_surface_create_for_stream( 435 (cairo_write_func_t)lochstreifen_out_closure, out, 436 lochstreifen_get_target_width(l), 437 lochstreifen_get_target_height(l) 438 ); 439 cr = cairo_create(surface); 440 lochstreifen_draw(l, cr); 441 442 DPRINTF("SVG file generated: %s\n", cairo_status_to_string(cairo_surface_status(surface))); 443 return 0; 444 } else { 445 fprintf(stderr, "This surface is not possible, because surface_typ is an enum.\n"); 446 return -42; 447 } // if surface_type 403 if(verbosity!=0) 404 lochstreifen_print_debug(l); 405 406 cairo_status_t status = lochstreifen_export(l, surface_type, out); 407 408 DPRINTF("%s file generated: %s\n", surface_type == LOCHSTREIFEN_FORMAT_PNG ? "PNG" : "SVG", 409 cairo_status_to_string(status)); 448 410 } // main -
paper-tape-project/trunk/visualisator/gtk.cc
r77 r78 11 11 Gtk::Window win; 12 12 win.set_title("Paper-Tape Viewer"); 13 win.set_icon_from_file("shared/blue-icon.svg"); 13 14 14 15 PaperTape tape(win); -
paper-tape-project/trunk/visualisator/gtkpapertape.cc
r77 r78 23 23 " <menubar name='MenuBar'>" 24 24 " <menu action='FileMenu'>" 25 " <menuitem action='New'/>" 26 " <menuitem action='NewFont'/>" 25 " <menuitem action='NewWin'/>" 27 26 " <separator/>" 28 27 " <menuitem action='Open'/>" 29 " <menuitem action='Reload'/>"30 28 " <menuitem action='SetNullBytes'/>" 31 " <separator/>"32 " <menuitem action='Save'/>"33 " <menuitem action='SaveAs'/>"34 29 " <separator/>" 35 30 " <menuitem action='Export'/>" … … 37 32 " <menuitem action='Close'/>" 38 33 " <menuitem action='Quit'/>" 39 " </menu>"40 " <menu action='EditMenu'>"41 " <menuitem action='EnableEditor'/>"42 " <separator/>"43 " <menuitem action='Undo'/>"44 " <menuitem action='Redo'/>"45 " <separator/>"46 " <menuitem action='Cut'/>"47 " <menuitem action='Copy'/>"48 " <menuitem action='Paste'/>"49 " <menuitem action='Delete'/>"50 " <menuitem action='Clear'/>"51 " <separator/>"52 " <menuitem action='SelectAll'/>"53 " <menuitem action='SelectInvert'/>"54 " <menuitem action='SelectNone'/>"55 " <separator/>"56 " <menuitem action='InsertBytes'/>"57 " <menuitem action='InsertFont'/>"58 34 " </menu>" 59 35 " <menu action='ViewMenu'>" … … 75 51 " <separator/>" 76 52 " <menuitem action='SetQuality'/>" 77 " </menu>"78 " <menu action='WindowMenu'>"79 " <menuitem action='NewWin'/>"80 53 " <separator/>" 81 54 " <menuitem action='EnableStatusbar'/>" … … 103 76 " </menubar>" 104 77 " <toolbar name='ToolBar'>" 105 " <toolitem action='New'/>"106 78 " <toolitem action='Open'/>" 107 79 " <toolitem action='Export'/>" … … 109 81 " <toolitem action='ZoomIn'/>" 110 82 " <toolitem action='ZoomOut'/>" 111 " <separator expand='true'/>"112 " <toolitem action='EnableEditor'/>"113 83 " </toolbar>" 114 84 " <popup name='PopUp'>" … … 298 268 // * The driver frontend, aka 299 269 // Paper Tape Suite 270 /* 271 Gtk::AboutDialog* about = new Gtk::AboutDialog(); 272 about->set_version("SVN Trunk 2013"); 273 about->set_license("GPL v2 and following"); 274 about->set_website("http://labs.technikum29.de/"); 275 about->set_website_label("The technikum29 Laboratories"); 276 const gchar** authors = {"Sven Koeppel", 0}; 277 about->set_authors(authors); 278 */ 300 279 } else if(name == "FileMenu") { 301 280 // Menuklick ist egal … … 345 324 } 346 325 326 void PaperTape::on_data_change(byte_t* data, int data_len) { 327 // setup new window title 328 parent_window->set_title( 329 Glib::ustring::compose("Paper-Tape Viewer - %1", model->get_filename()).c_str() 330 ); 331 } 332 347 333 PaperTape::PaperTape(Window& parent_window) { 348 334 // set up nested objects … … 368 354 win->add(*view); 369 355 view->set_redraw_on_allocate(true); 356 357 // set up connections 358 model->data_changed.connect(sigc::mem_fun(*this, &PaperTape::on_data_change)); 370 359 371 360 // set up ourself (we are a container) -
paper-tape-project/trunk/visualisator/gtkpapertape.h
r76 r78 56 56 } 57 57 58 /** 59 * Open a blank file. This will ask if user wants to close 60 * file and open, if yes, a new blank file. 61 **/ 62 //void new_file(); 63 /** 64 * Show a file dialog to open an existing file. This will 65 * ask the user if he wants to close the current file. 66 **/ 67 //void open_file(); 68 /** 69 * Ask the user if he wants to close the current file. If so, 70 * close it, leaving with no file opened (splash screen) 71 **/ 72 //void close_file(); 73 /** 74 * Check if a file is opened. 75 * @returns true if a file is opened. 76 **/ 77 //boolean file_is_open(); 58 // used for setting window title 59 void on_data_change(byte_t* data, int data_len); 78 60 }; 79 61 -
paper-tape-project/trunk/visualisator/gtkpapertapeexporter.cc
r77 r78 58 58 extra_widget.add(*file_types_expander); 59 59 60 CheckButton* keep_selections = manage(new CheckButton("Export with current selection")); 61 extra_widget.add(*keep_selections); 60 //printf("here\n"); 61 //current_view.set_label("Export current visible area"); 62 //extra_widget.add(current_view); 62 63 extra_widget.show_all(); 63 64 … … 72 73 // supposed to be called after run() returned with a valid file. 73 74 set_sensitive(false); 74 // this doesn't work75 //set_response_sensitive(RESPONSE_CANCEL, true);76 // so:77 78 75 cancel_button->set_sensitive(true); // doesn't work, too! :/ 79 76 // enable cancel action … … 123 120 } 124 121 } 125 122 123 // prepare Lochstreifen 124 //if(!current_view.get_active()) { 125 if(1) { 126 // clear any clipping. Paint whole lochstreifen 127 lochstreifen_remove_clip(l); 128 } 129 130 // open output stream 131 output_file = fopen(get_filename().c_str(), "w"); 132 if(output_file == NULL) { 133 MessageDialog err(*this, 134 "File could not be opened", 135 false, // markup 136 MESSAGE_ERROR, 137 BUTTONS_CANCEL, 138 true); 139 err.set_secondary_text("Could not open file <b>"+get_filename()+"</b> " 140 "for writing."); 141 err.run(); 142 } 143 144 lochstreifen_export_type type = type_svg.get_active() ? LOCHSTREIFEN_FORMAT_SVG : LOCHSTREIFEN_FORMAT_PNG; 145 146 printf("Starting export\n"); 147 lochstreifen_print_debug(l); 148 cairo_status_t status = lochstreifen_export(l, type, output_file); 149 150 printf("Export finished with '%s'\n", cairo_status_to_string(status)); 151 152 fclose(output_file); 153 154 /* 126 155 // query width/height from LOCHSTREIFEN 127 156 double width, height; … … 134 163 // width = 72 * width / Gdk::Screen::get_default().get_resolution(); 135 164 136 Cairo::RefPtr<SvgSurface> surface = SvgSurface::create (get_filename(), width, height);165 Cairo::RefPtr<SvgSurface> surface = SvgSurface::create_for_stream(PaperTapeExporter_cairo_write_closure, width, height); 137 166 Cairo::RefPtr<Context> cr = Context::create(surface); 138 167 139 168 lochstreifen_draw(l, cr->cobj()); 169 170 surface->flush(); 140 171 141 172 // c'est ca. … … 143 174 } else if(type_png.get_active()) { 144 175 // we make a PNG picture. 145 /*176 * 146 177 PNG only Always produces: 147 178 glibmm-ERROR **: … … 149 180 what: St9bad_alloc 150 181 151 * /182 * 152 183 // TODO: Stuerzt zuverlaessig ab. 153 184 185 std::cout << "Target Cairo: wxh=" << width << " x " << height << "\n"; 154 186 Cairo::RefPtr<ImageSurface> surface = ImageSurface::create(FORMAT_ARGB32, (int)width, (int)height); 155 187 Cairo::RefPtr<Context> cr = Context::create(surface); … … 157 189 lochstreifen_draw(l, cr->cobj()); 158 190 159 surface->write_to_png (get_filename());191 surface->write_to_png_stream(PaperTapeExporter_cairo_write_closure); 160 192 return true; 161 193 } else { 162 194 std::cout << "File type not detectable\n"; 163 195 return false; 164 } 165 } 196 }*/ 197 198 return true; 199 } 200 166 201 167 202 void PaperTapeExporter::update_gui(const row_t* current_row, cairo_t* context, void* user_data) { 168 203 // yes, we must do some ugly C casting ;-) 169 printf("CALLBACK! BIG CALLBACK!\n");170 204 PaperTapeExporter* obj = (PaperTapeExporter*) user_data; 171 205 … … 174 208 // this g_strdup_printf string is never given back -- memory leck! 175 209 // unfortunately ustring::compose doesn't compile at my site (glibmm too old?) 176 obj->progress.set_text("Test"); 177 //get_text 178 //g_strdup_printf("Exporting... %i%%", (int)(percentage*100) )); 210 obj->progress.set_text( Glib::ustring::compose("Exporting... %1%%", (int)(percentage*100)) ); 179 211 180 212 // make Gtk happy … … 183 215 184 216 // ah, and break the whole thing if not wanted. 185 // if(cancel_export) 186 // return false; 187 188 Glib::usleep(1000*1000); // sleep. 217 // dafuer darf diese funktion nicht void sein, auch in lochstreifen.c :) 218 // aber da cancel-button eh ausgegraut ist, gehts eh nicht :) 219 //if(obj->cancel_export) 220 // return false; 221 222 //Glib::usleep(1000*1000); // sleep. 189 223 } 190 224 -
paper-tape-project/trunk/visualisator/gtkpapertapeexporter.h
r77 r78 15 15 #include <gtkmm/main.h> 16 16 17 #include <cstdio> 17 18 18 19 namespace Gtk … … 41 42 RadioButton type_svg; 42 43 RadioButton type_png; 44 //CheckButton current_view; 45 46 FILE* output_file; 43 47 44 48 public: -
paper-tape-project/trunk/visualisator/gtkpapertapefile.cc
r76 r78 55 55 void PaperTapeFile::open(const std::string& filename) { 56 56 //std::string Glib::file_get_contents(filename); 57 this->filename = filename; 58 57 59 GError *err = NULL; 58 60 if(g_file_get_contents(filename.c_str(), (gchar**)&data, (gsize*)&data_len, &err) == FALSE) { … … 60 62 } 61 63 data_changed.emit(data, data_len); 62 /* 63 if(ret == FALSE) { 64 GtkWidget *error; 65 error = gtk_message_dialog_new (GTK_WINDOW(papertape->parent_window), 66 GTK_DIALOG_DESTROY_WITH_PARENT, 67 GTK_MESSAGE_ERROR, 68 GTK_BUTTONS_OK, 69 "Error loading file '%s': %s", 70 filename, err->message); 71 gtk_dialog_run (GTK_DIALOG (error)); 72 gtk_widget_destroy (error); 73 return FALSE; 74 } 64 } 75 65 76 papertape->name_of_file = g_path_get_basename(filename); // allocates new string 77 papertape->file_opened = TRUE; 78 gtk_window_set_title(GTK_WINDOW(papertape->parent_window), g_strdup_printf( 79 "%s - %s", papertape->window_base_title, papertape->name_of_file 80 )); 81 gtk_paper_tape_set_data(papertape, length, (byte_t *)data); 82 return TRUE; 83 return true; 84 */ 66 const std::string& PaperTapeFile::get_filename() { 67 return this->filename; 85 68 } 86 69 -
paper-tape-project/trunk/visualisator/gtkpapertapefile.h
r76 r78 26 26 byte_t *data; 27 27 int data_len; 28 std::string filename; 28 29 29 30 public: … … 82 83 /// close(); new Model(same_file_name); 83 84 void reload(); 85 86 // information purpoe 87 const std::string& get_filename(); 84 88 85 89 }; -
paper-tape-project/trunk/visualisator/gtkpapertapeview.cc
r77 r78 23 23 24 24 // catch events for callback functions 25 add_events(Gdk::POINTER_MOTION_MASK | Gdk::SCROLL_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);25 //add_events(Gdk::POINTER_MOTION_MASK | Gdk::SCROLL_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); 26 26 27 27 // the controller connects the on_data_change for us. … … 43 43 44 44 lochstreifen_set_data(lochstreifen, new_data_len, new_data); 45 46 // Clipping zuruecksetzen 47 lochstreifen_remove_clip(lochstreifen); 48 45 49 46 50 set_size_request( … … 109 113 bool PaperTapeView::on_scroll_event(GdkEventScroll* event) { 110 114 std::cout << "Mouse Scrolling.\n"; 111 112 115 return true; 113 116 } … … 144 147 track_t new_track; 145 148 lochstreifen_get_target_bit_from_point(lochstreifen, &new_row, &new_track, event->x, event->y); 149 150 // TODO: deaktiviert. 151 return true; 146 152 147 153 // repaint bits, if neccessary -
paper-tape-project/trunk/visualisator/gtkpapertapezoom.cc
r76 r78 22 22 { "Zoom50", NULL, "Zoom to 50%" }, 23 23 { "Zoom200", NULL, "Zoom to 200%" }, 24 { "ZoomWidth", GTK_STOCK_ZOOM_FIT, "Fit to screen", NULL, "Zoom that the papertape width fills the screen" },25 { "ZoomLength", GTK_STOCK_ZOOM_FIT, "Fit all to screen ", NULL, "Zoom that the complete papertape fills in the screen" },26 { "ZoomDialog", GTK_STOCK_PROPERTIES, "Show dialog...", "<ctrl>z", "Set Zoom level and input own Affine Translation Matrix" },27 28 { "Rotate90CW", GTK_STOCK_ORIENTATION_LANDSCAPE, "Rotate clockwise" },29 { "Rotate90CCW", GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE, "Rotate anticlockwise" },30 { "FlipHoriz", GTK_STOCK_ORIENTATION_PORTRAIT, "Flip horizontally" },31 { "FlipVert", GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT, "Flip verticall" }24 { "ZoomWidth", NULL /*GTK_STOCK_ZOOM_FIT*/, "Fit to screen", NULL, "Zoom that the papertape width fills the screen" }, 25 { "ZoomLength", NULL/*GTK_STOCK_ZOOM_FIT*/, "Fit all to screen ", NULL, "Zoom that the complete papertape fills in the screen" }, 26 { "ZoomDialog", NULL /*GTK_STOCK_PROPERTIES*/, "Show dialog...", "<ctrl>z", "Set Zoom level and input own Affine Translation Matrix" }, 27 28 { "Rotate90CW", NULL/*GTK_STOCK_ORIENTATION_LANDSCAPE*/, "Rotate clockwise" }, 29 { "Rotate90CCW", NULL/*GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE*/, "Rotate anticlockwise" }, 30 { "FlipHoriz", NULL /*GTK_STOCK_ORIENTATION_PORTRAIT*/, "Flip horizontally" }, 31 { "FlipVert", NULL/*GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT*/, "Flip verticall" } 32 32 }; 33 33 … … 45 45 // set up the matrix_dialog. 46 46 matrix_dialog = new Dialog("Set papertape view"); 47 matrix_dialog->set_modal(false); 47 48 // Frame. 48 49 Frame* matrix_frame = manage(new Frame()); … … 179 180 if(!this->is_controlled_manually()) { 180 181 *this = default_matrix; 182 std::cout << "Default: " << *this << "\n"; 183 181 184 cairo_matrix_scale(this, zoom_factor, zoom_factor); 185 std::cout << "After Scale: " << *this << "\n"; 182 186 cairo_matrix_rotate(this, rotation); 183 187 std::cout << "After Rotate: " << *this << "\n"; 188 189 // bring back to viewport 190 191 192 if(flip == FLIP_HOR) { 193 this->x0 = this->xx; 194 this->xx = -this->xx; 195 } else if(flip == FLIP_VER) { 196 this->y0 = this->yy; 197 this->yy = -this->yy; 198 } 199 std::cout << "After Flip: " << *this << "\n"; 200 184 201 zoom_changed.emit(); 185 202 } … … 216 233 } 217 234 218 void PaperTapeZoom::set_flip(PaperTapeFlip flip, bool relative) { 219 // not implemented yet 235 void PaperTapeZoom::set_flip(PaperTapeFlip flip, bool relative=false) { 236 if(!is_controlled_manually()) { 237 this->flip = flip; 238 this->calc_matrix(); 239 } else { 240 // change user matrix 241 //cairo_matrix_ 242 } 220 243 } 221 244 … … 264 287 set_rotate(-G_PI, true); 265 288 } else if(name == "FlipHoriz") { 266 //set_flip();289 set_flip(FLIP_HOR); 267 290 } else if(name == "FlipVert") { 268 // same here...291 set_flip(FLIP_VER); 269 292 } else { 270 293 std::cout << "PaperTapeZoom: Action " << name << " not supported!\n"; -
paper-tape-project/trunk/visualisator/gtkpapertapezoom.h
r76 r78 116 116 }; // class 117 117 118 inline std::ostream& operator<<(std::ostream& out, const Cairo::Matrix& s) { 119 out << "Cairo Matrix:\n"; 120 out << "[ xx,xy,x0 = " << s.xx << ", " << s.xy << " , " << s.x0 << "\n"; 121 out << " yx,yy,y0 = " << s.yx << ", " << s.yy << " , " << s.y0 << " ]\n"; 122 return out; 123 } 124 118 125 }; // namespace Gtk 119 126 -
paper-tape-project/trunk/visualisator/lochstreifen.c
r77 r78 82 82 **/ 83 83 LOCHSTREIFEN* lochstreifen_copy(const LOCHSTREIFEN* template) { 84 LOCHSTREIFEN *l = malloc (sizeof(LOCHSTREIFEN)); 84 LOCHSTREIFEN *l = lochstreifen_new(); 85 85 86 #define COPY_RGBA_PATTERN(name) { double r,g,b,a; \ 86 87 if(template->name != NULL && \ … … 93 94 l->highlight_region_start = template->highlight_region_start; 94 95 l->highlight_region_end = template->highlight_region_end; 95 printf("Copy1\n");96 96 COPY_RGBA_PATTERN(highlight_region_color); 97 printf("Copy2\n");98 97 l->highlight_row_number = template->highlight_row_number; 99 98 COPY_RGBA_PATTERN(highlight_row_color); … … 457 456 **/ 458 457 void lochstreifen_remove_clip(LOCHSTREIFEN *l) { 459 free(l->clip); 458 if(l->clip != NULL) 459 free(l->clip); 460 460 l->clip = NULL; // not neccessary, I suppose. 461 461 } … … 469 469 void lochstreifen_set_scaling_by_length(LOCHSTREIFEN *l, int length) { 470 470 double scale_factor = ((double)length) / LOCHSTREIFEN_LENGTH; 471 printf("Scaling to length=%i, having length=%f, getting %f as scale factor\n",471 fprintf(stderr, "Scaling to length=%i, having length=%f, getting %f as scale factor\n", 472 472 length, LOCHSTREIFEN_LENGTH, scale_factor); 473 473 cairo_matrix_scale(&l->matrix, scale_factor, scale_factor); 474 l->matrix.x0 *= scale_factor; l->matrix.y0 *= scale_factor; 474 475 lochstreifen_check_matrix(l); 475 476 } … … 478 479 double scale_factor = ((double)width) / LOCHSTREIFEN_WIDTH; 479 480 cairo_matrix_scale(&l->matrix, scale_factor, scale_factor); 481 l->matrix.x0 *= scale_factor; l->matrix.y0 *= scale_factor; 480 482 lochstreifen_check_matrix(l); 481 483 } … … 484 486 double scale_factor = ((double)diameter)/2 / LOCHSTREIFEN_RADIUS_CODE_HOLE; 485 487 cairo_matrix_scale(&l->matrix, scale_factor, scale_factor); 488 l->matrix.x0 *= scale_factor; l->matrix.y0 *= scale_factor; 486 489 lochstreifen_check_matrix(l); 487 490 } … … 749 752 // standard 750 753 case LOCHSTREIFEN_MOVEMENT_TO_TOP: 751 //cairo_matrix_rotate();754 752 755 case LOCHSTREIFEN_MOVEMENT_TO_RIGHT: 753 756 754 757 case LOCHSTREIFEN_MOVEMENT_TO_BOTTOM: 755 758 756 759 case LOCHSTREIFEN_MOVEMENT_NONE: 757 760 default: … … 941 944 cairo_user_to_device(cr, &x, &y); 942 945 cairo_user_to_device_distance(cr, &width, &height); 943 printf("draw: %i|%i %ix%i ", (int)x, (int)y, (int)width, (int)height);944 } else printf("draw: ");945 printf("row %i->%i track %i->%i\n", row, row_max, track_min, track_max);946 fprintf(stderr, "draw: %i|%i %ix%i ", (int)x, (int)y, (int)width, (int)height); 947 } else fprintf(stderr, "draw: "); 948 fprintf(stderr, "row %i->%i track %i->%i\n", row, row_max, track_min, track_max); 946 949 947 950 // loop all the rows (bytes) … … 1030 1033 } // for rows (bytes) 1031 1034 } // function lochstreifen_draw 1035 1036 1037 /** 1038 * Helper function: A simple closure for a cairo_surface_t (PNG and SVG) to write out data 1039 * to a C file stream. Used internally by lochstreifen_export and is not listened in lochstreifen.h. 1040 **/ 1041 cairo_status_t lochstreifen_export_closure(void *closure, unsigned char *data, unsigned int length) { 1042 unsigned int length_written = fwrite(data, length, 1, (FILE *)closure); 1043 cairo_status_t status = (length != length_written) 1044 ? CAIRO_STATUS_SUCCESS : CAIRO_STATUS_WRITE_ERROR; 1045 //printf("Writing data, length %i=>%i, status %s\n", length, length_written, cairo_status_to_string(status)); 1046 if(status == CAIRO_STATUS_WRITE_ERROR) { 1047 perror("Lochstreifen export closure"); 1048 } 1049 return status; 1050 } 1051 1052 /** 1053 * Exporting the Lochstreifen. This is both done in cli.c 1054 * (actually cli.c is a wrapper around this function) and 1055 * gtkpapertapeexporter.cc, so they both rely on this function 1056 **/ 1057 cairo_status_t lochstreifen_export(LOCHSTREIFEN *l, lochstreifen_export_type file_type, FILE *out_stream) { 1058 cairo_t *cr; ///< A cairo context, given from... 1059 cairo_surface_t *surface; ///< ...this generic cairo surface 1060 1061 fprintf(stderr, "Lochstreifen: Exporting %s with %i x %i px\n", 1062 file_type == LOCHSTREIFEN_FORMAT_PNG ? "PNG" : "SVG", 1063 lochstreifen_get_target_width(l), 1064 lochstreifen_get_target_height(l) 1065 ); 1066 1067 // setting up the surface and painting... 1068 if(file_type == LOCHSTREIFEN_FORMAT_PNG) { 1069 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1070 lochstreifen_get_target_width(l), 1071 lochstreifen_get_target_height(l) 1072 ); 1073 cr = cairo_create(surface); 1074 lochstreifen_draw(l, cr); 1075 cairo_surface_flush(surface); 1076 1077 cairo_status_t status = cairo_surface_write_to_png_stream(surface, (cairo_write_func_t)lochstreifen_export_closure, out_stream); 1078 1079 cairo_destroy(cr); 1080 cairo_surface_destroy(surface); 1081 return status; 1082 } else { // if(file_type == LOCHSTREIFEN_FORMAT_SVG) { // no other case possible 1083 surface = cairo_svg_surface_create_for_stream( 1084 (cairo_write_func_t)lochstreifen_export_closure, out_stream, 1085 lochstreifen_get_target_width(l), 1086 lochstreifen_get_target_height(l) 1087 ); 1088 cr = cairo_create(surface); 1089 lochstreifen_draw(l, cr); 1090 cairo_surface_flush(surface); 1091 1092 cairo_status_t status = cairo_surface_status(surface); 1093 1094 cairo_destroy(cr); 1095 cairo_surface_destroy(surface); 1096 1097 return status; 1098 } // end case file_type 1099 } -
paper-tape-project/trunk/visualisator/lochstreifen.h
r19 r78 162 162 LOCHSTREIFEN_ROTATION_ANTICLOCKWISE = 5 163 163 } lochstreifen_direction_t; 164 165 typedef enum _lochstreifen_export_type { 166 LOCHSTREIFEN_FORMAT_PNG, 167 LOCHSTREIFEN_FORMAT_SVG 168 } lochstreifen_export_type; 164 169 165 170 … … 200 205 void lochstreifen_set_rotation(LOCHSTREIFEN *l, enum lochstreifen_direction direction); 201 206 void lochstreifen_draw(LOCHSTREIFEN *l, cairo_t *cr); 207 cairo_status_t lochstreifen_export(LOCHSTREIFEN *l, lochstreifen_export_type file_type, FILE *out_stream); 202 208 203 209 #ifdef __cplusplus
Note: See TracChangeset
for help on using the changeset viewer.