Changeset 78 in projects for paper-tape-project/trunk


Ignore:
Timestamp:
Jul 27, 2013, 8:49:16 AM (11 years ago)
Author:
sven
Message:

Major improvements in making the Paper Tape Projects ready for deploying:

  • Written a 21 page manual in German (LaTeX, PDF)
  • Visualisator is running, export works, lesser bugs
  • some new perl-tools
  • a bin directory with softlinks
  • You can "install" the paper tape projects right now.
Location:
paper-tape-project/trunk
Files:
36 added
22 edited

Legend:

Unmodified
Added
Removed
  • paper-tape-project/trunk/perl-tools/hex-meter

    r1 r78  
    33#
    44
    5 for($x=0; $x < $ARGV[0]; $x++) {
     5for($x=0; $x < (@ARGV ? $ARGV[0] : 1); $x++) {
    66        for($y=0; $y<2**8; $y++) {
    77                print pack('C', $y);
  • paper-tape-project/trunk/perl-tools/how-long-is-this-papertape

    r1 r78  
    66#
    77
     8# if called with no argument: use stdin
     9unless(@ARGV) {
     10        my $slurp = do { local $/; <STDIN> };
     11        my $l = length($slurp);
     12        print "stdin: $l bytes = ".bytes2cm($l)." cm\n";
     13}
     14
    815my $total_l = 0; my $l;
    916foreach (@ARGV) {
     
    1219    $total_l += $l;
    1320}
     21
    1422print "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.
    1624
    1725sub bytes2cm {
  • paper-tape-project/trunk/visualisator/cli.c

    r76 r78  
    4242
    4343LOCHSTREIFEN *l;
    44 enum _surface_type {
    45         PNG_SURFACE,
    46         SVG_SURFACE
    47 } surface_type;
     44lochstreifen_export_type surface_type;
    4845char *output_file;
    4946int verbosity = 0;
     
    147144                        // set file format
    148145                        if(strcasecmp(arg, "png") == 0)
    149                                 surface_type = PNG_SURFACE;
     146                                surface_type = LOCHSTREIFEN_FORMAT_PNG;
    150147                        else if(strcasecmp(arg, "svg") == 0)
    151                                 surface_type = SVG_SURFACE;
     148                                surface_type = LOCHSTREIFEN_FORMAT_SVG;
    152149                        else
    153150                                argp_error(state, "Only PNG and SVG are supported as file formats.\n");
     
    337334}
    338335
    339 /**
    340  * Helper function: A simple closure for a cairo_surface_t (PNG and SVG) to write out data
    341  * 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 schreiben
    345         fwrite(data, length, 1, (FILE *)closure);
    346         return CAIRO_STATUS_SUCCESS;
    347 }
    348336
    349337/**
     
    351339 **/
    352340int main(int argc, char *argv[]) {
    353         cairo_t *cr;                ///< A cairo context, given from...
    354         cairo_surface_t *surface;   ///< ...this generic cairo surface
    355341        byte_t *data;               ///< the data array, will be filled by file_get_contents
    356342        int length;                 ///< the length of that data array
     
    415401        }
    416402       
    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));
    448410} // main
  • paper-tape-project/trunk/visualisator/gtk.cc

    r77 r78  
    1111        Gtk::Window win;
    1212        win.set_title("Paper-Tape Viewer");
     13        win.set_icon_from_file("shared/blue-icon.svg");
    1314       
    1415        PaperTape tape(win);
  • paper-tape-project/trunk/visualisator/gtkpapertape.cc

    r77 r78  
    2323"  <menubar name='MenuBar'>"
    2424"    <menu action='FileMenu'>"
    25 "      <menuitem action='New'/>"
    26 "      <menuitem action='NewFont'/>"
     25"      <menuitem action='NewWin'/>"
    2726"      <separator/>"
    2827"      <menuitem action='Open'/>"
    29 "      <menuitem action='Reload'/>"
    3028"      <menuitem action='SetNullBytes'/>"
    31 "      <separator/>"
    32 "      <menuitem action='Save'/>"
    33 "      <menuitem action='SaveAs'/>"
    3429"      <separator/>"
    3530"      <menuitem action='Export'/>"
     
    3732"      <menuitem action='Close'/>"
    3833"      <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'/>"
    5834"    </menu>"
    5935"    <menu action='ViewMenu'>"
     
    7551"      <separator/>"
    7652"      <menuitem action='SetQuality'/>"
    77 "    </menu>"
    78 "    <menu action='WindowMenu'>"
    79 "      <menuitem action='NewWin'/>"
    8053"      <separator/>"
    8154"      <menuitem action='EnableStatusbar'/>"
     
    10376"  </menubar>"
    10477"  <toolbar name='ToolBar'>"
    105 "    <toolitem action='New'/>"
    10678"    <toolitem action='Open'/>"
    10779"    <toolitem action='Export'/>"
     
    10981"    <toolitem action='ZoomIn'/>"
    11082"    <toolitem action='ZoomOut'/>"
    111 "    <separator expand='true'/>"
    112 "    <toolitem action='EnableEditor'/>"
    11383"  </toolbar>"
    11484"  <popup name='PopUp'>"
     
    298268                // * The driver frontend, aka
    299269                //   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                */
    300279        } else if(name == "FileMenu") {
    301280                // Menuklick ist egal
     
    345324}
    346325
     326void 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
    347333PaperTape::PaperTape(Window& parent_window) {
    348334        // set up nested objects
     
    368354        win->add(*view);
    369355        view->set_redraw_on_allocate(true);
     356       
     357        // set up connections
     358        model->data_changed.connect(sigc::mem_fun(*this, &PaperTape::on_data_change));
    370359               
    371360        // set up ourself (we are a container)
  • paper-tape-project/trunk/visualisator/gtkpapertape.h

    r76 r78  
    5656        }
    5757
    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);
    7860};
    7961
  • paper-tape-project/trunk/visualisator/gtkpapertapeexporter.cc

    r77 r78  
    5858        extra_widget.add(*file_types_expander);
    5959
    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);
    6263        extra_widget.show_all();
    6364
     
    7273        // supposed to be called after run() returned with a valid file.
    7374        set_sensitive(false);
    74         // this doesn't work
    75         //set_response_sensitive(RESPONSE_CANCEL, true);
    76         // so:
    77        
    7875        cancel_button->set_sensitive(true); // doesn't work, too! :/
    7976        // enable cancel action
     
    123120                }
    124121        }
    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        /*
    126155        // query width/height from LOCHSTREIFEN
    127156        double width, height;
     
    134163                // width = 72 * width / Gdk::Screen::get_default().get_resolution();
    135164
    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);
    137166                Cairo::RefPtr<Context> cr = Context::create(surface);
    138167               
    139168                lochstreifen_draw(l, cr->cobj());
     169               
     170                surface->flush();
    140171               
    141172                // c'est ca.
     
    143174        } else if(type_png.get_active()) {
    144175                // we make a PNG picture.
    145                 /*
     176                *
    146177                PNG only Always produces:
    147178                        glibmm-ERROR **:
     
    149180                        what: St9bad_alloc
    150181
    151                 */
     182                *
    152183                // TODO: Stuerzt zuverlaessig ab.
    153184               
     185                std::cout << "Target Cairo: wxh=" << width << " x " << height << "\n";
    154186                Cairo::RefPtr<ImageSurface> surface = ImageSurface::create(FORMAT_ARGB32, (int)width, (int)height);
    155187                Cairo::RefPtr<Context> cr = Context::create(surface);
     
    157189                lochstreifen_draw(l, cr->cobj());
    158190               
    159                 surface->write_to_png(get_filename());
     191                surface->write_to_png_stream(PaperTapeExporter_cairo_write_closure);
    160192                return true;
    161193        } else {
    162194                std::cout << "File type not detectable\n";
    163195                return false;
    164         }
    165 }
     196        }*/
     197       
     198        return true;
     199}
     200
    166201
    167202void PaperTapeExporter::update_gui(const row_t* current_row, cairo_t* context, void* user_data) {
    168203        // yes, we must do some ugly C casting ;-)
    169         printf("CALLBACK! BIG CALLBACK!\n");
    170204        PaperTapeExporter* obj = (PaperTapeExporter*) user_data;
    171205       
     
    174208        // this g_strdup_printf string is never given back -- memory leck!
    175209        // 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)) );
    179211
    180212        // make Gtk happy
     
    183215
    184216        // 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.   
    189223}
    190224
  • paper-tape-project/trunk/visualisator/gtkpapertapeexporter.h

    r77 r78  
    1515#include <gtkmm/main.h>
    1616
     17#include <cstdio>
    1718
    1819namespace Gtk
     
    4142        RadioButton type_svg;
    4243        RadioButton type_png;
     44        //CheckButton current_view;
     45       
     46        FILE* output_file;
    4347       
    4448public:
  • paper-tape-project/trunk/visualisator/gtkpapertapefile.cc

    r76 r78  
    5555void PaperTapeFile::open(const std::string& filename) {
    5656        //std::string Glib::file_get_contents(filename);
     57        this->filename = filename;
     58       
    5759        GError *err = NULL;
    5860        if(g_file_get_contents(filename.c_str(), (gchar**)&data, (gsize*)&data_len, &err) == FALSE) {
     
    6062        }
    6163        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}
    7565
    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 */
     66const std::string& PaperTapeFile::get_filename() {
     67        return this->filename;
    8568}
    8669
  • paper-tape-project/trunk/visualisator/gtkpapertapefile.h

    r76 r78  
    2626        byte_t *data;
    2727        int data_len;
     28        std::string filename;
    2829       
    2930public:
     
    8283        /// close(); new Model(same_file_name);
    8384        void reload();
     85       
     86        // information purpoe
     87        const std::string& get_filename();
    8488
    8589};
  • paper-tape-project/trunk/visualisator/gtkpapertapeview.cc

    r77 r78  
    2323       
    2424        // 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);
    2626       
    2727        // the controller connects the on_data_change for us.
     
    4343
    4444        lochstreifen_set_data(lochstreifen, new_data_len, new_data);
     45       
     46        // Clipping zuruecksetzen
     47        lochstreifen_remove_clip(lochstreifen);
     48       
    4549       
    4650        set_size_request(
     
    109113bool PaperTapeView::on_scroll_event(GdkEventScroll* event) {
    110114        std::cout << "Mouse Scrolling.\n";
    111 
    112115        return true;
    113116}
     
    144147        track_t new_track;
    145148        lochstreifen_get_target_bit_from_point(lochstreifen, &new_row, &new_track, event->x, event->y);
     149       
     150        // TODO: deaktiviert.
     151        return true;
    146152
    147153        // repaint bits, if neccessary
  • paper-tape-project/trunk/visualisator/gtkpapertapezoom.cc

    r76 r78  
    2222        { "Zoom50", NULL, "Zoom to 50%" },
    2323        { "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" }
    3232};
    3333
     
    4545                // set up the matrix_dialog.
    4646                matrix_dialog = new Dialog("Set papertape view");
     47                matrix_dialog->set_modal(false);
    4748                // Frame.
    4849                Frame* matrix_frame = manage(new Frame());
     
    179180        if(!this->is_controlled_manually()) {
    180181                *this = default_matrix;
     182                std::cout << "Default: " << *this << "\n";
     183
    181184                cairo_matrix_scale(this, zoom_factor, zoom_factor);
     185                std::cout << "After Scale: " << *this << "\n";
    182186                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               
    184201                zoom_changed.emit();
    185202        }
     
    216233}
    217234
    218 void PaperTapeZoom::set_flip(PaperTapeFlip flip, bool relative) {
    219         // not implemented yet
     235void 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        }
    220243}
    221244
     
    264287                set_rotate(-G_PI, true);
    265288        } else if(name == "FlipHoriz") {
    266                 //set_flip();
     289                set_flip(FLIP_HOR);
    267290        } else if(name == "FlipVert") {
    268                 // same here...
     291                set_flip(FLIP_VER);
    269292        } else {
    270293                std::cout << "PaperTapeZoom: Action " << name << " not supported!\n";
  • paper-tape-project/trunk/visualisator/gtkpapertapezoom.h

    r76 r78  
    116116}; // class
    117117
     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
    118125}; // namespace Gtk
    119126
  • paper-tape-project/trunk/visualisator/lochstreifen.c

    r77 r78  
    8282 **/
    8383LOCHSTREIFEN* lochstreifen_copy(const LOCHSTREIFEN* template) {
    84         LOCHSTREIFEN *l = malloc (sizeof(LOCHSTREIFEN));
     84        LOCHSTREIFEN *l = lochstreifen_new();
     85       
    8586        #define COPY_RGBA_PATTERN(name) { double r,g,b,a; \
    8687                if(template->name != NULL && \
     
    9394        l->highlight_region_start     = template->highlight_region_start;
    9495        l->highlight_region_end       = template->highlight_region_end;
    95         printf("Copy1\n");
    9696        COPY_RGBA_PATTERN(highlight_region_color);
    97         printf("Copy2\n");
    9897        l->highlight_row_number       = template->highlight_row_number;
    9998        COPY_RGBA_PATTERN(highlight_row_color);
     
    457456 **/
    458457void lochstreifen_remove_clip(LOCHSTREIFEN *l) {
    459         free(l->clip);
     458        if(l->clip != NULL)
     459                free(l->clip);
    460460        l->clip = NULL; // not neccessary, I suppose.
    461461}
     
    469469void lochstreifen_set_scaling_by_length(LOCHSTREIFEN *l, int length) {
    470470        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",
    472472                length, LOCHSTREIFEN_LENGTH, scale_factor);
    473473        cairo_matrix_scale(&l->matrix, scale_factor, scale_factor);
     474        l->matrix.x0 *= scale_factor; l->matrix.y0 *= scale_factor;
    474475        lochstreifen_check_matrix(l);
    475476}
     
    478479        double scale_factor = ((double)width) / LOCHSTREIFEN_WIDTH;
    479480        cairo_matrix_scale(&l->matrix, scale_factor, scale_factor);
     481        l->matrix.x0 *= scale_factor; l->matrix.y0 *= scale_factor;
    480482        lochstreifen_check_matrix(l);
    481483}
     
    484486        double scale_factor = ((double)diameter)/2 / LOCHSTREIFEN_RADIUS_CODE_HOLE;
    485487        cairo_matrix_scale(&l->matrix, scale_factor, scale_factor);
     488        l->matrix.x0 *= scale_factor; l->matrix.y0 *= scale_factor;
    486489        lochstreifen_check_matrix(l);
    487490}
     
    749752                        // standard
    750753                case LOCHSTREIFEN_MOVEMENT_TO_TOP:
    751                         //cairo_matrix_rotate();
     754                       
    752755                case LOCHSTREIFEN_MOVEMENT_TO_RIGHT:
    753756                       
    754757                case LOCHSTREIFEN_MOVEMENT_TO_BOTTOM:
    755                
     758                       
    756759                case LOCHSTREIFEN_MOVEMENT_NONE:
    757760                default:
     
    941944                cairo_user_to_device(cr, &x, &y);
    942945                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);
    946949       
    947950        // loop all the rows (bytes)
     
    10301033        } // for rows (bytes)
    10311034} // 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 **/
     1041cairo_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 **/
     1057cairo_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  
    162162        LOCHSTREIFEN_ROTATION_ANTICLOCKWISE = 5
    163163} lochstreifen_direction_t;
     164
     165typedef enum _lochstreifen_export_type {
     166        LOCHSTREIFEN_FORMAT_PNG,
     167        LOCHSTREIFEN_FORMAT_SVG
     168} lochstreifen_export_type;
    164169
    165170
     
    200205void lochstreifen_set_rotation(LOCHSTREIFEN *l, enum lochstreifen_direction direction);
    201206void lochstreifen_draw(LOCHSTREIFEN *l, cairo_t *cr);
     207cairo_status_t lochstreifen_export(LOCHSTREIFEN *l, lochstreifen_export_type file_type, FILE *out_stream);
    202208
    203209#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License