Index: apps/diagram-viewer.man ================================================================== --- apps/diagram-viewer.man +++ apps/diagram-viewer.man @@ -75,11 +75,14 @@ [arg_def (handle) format in] This argument specifies the image format to convert the diagrams into when processing the input. The application recognizes all formats supported by the [package Img] package, i.e. for which it can load a -package [package img::[var format]] +package [package img::[var format]] (together with [package canvas::snap]), +and all formats for which it can load a package +[package canvas::[var format]]. These are (currently) [const mvg], +and [const pdf]. [arg_def path inputfile in] This argument specifies the path to the diagram file to process. It has to exist, must be readable, and written in [term diagram] format. ADDED modules/canvas/canvas_pdf.man Index: modules/canvas/canvas_pdf.man ================================================================== --- /dev/null +++ modules/canvas/canvas_pdf.man @@ -0,0 +1,36 @@ +[comment {-*- tcl -*- doctools manpage}] +[manpage_begin canvas::pdf n 1] +[keywords canvas] +[keywords graphics] +[keywords imagemagick] +[keywords {portable document format}] +[keywords pdf] +[keywords {print screen}] +[keywords serialization] +[keywords {vector graphics}] +[copyright {2014 Andreas Kupries, Arjen Markus}] +[copyright {2014 Documentation, Andreas Kupries}] +[moddesc {Variations on a canvas}] +[titledesc {Canvas to PDF}] +[require Tcl 8.5] +[require Tk 8.5] +[require canvas::pdf [opt 1]] +[require pdf4tcl] +[description] + +This package provides a command to convert a canvas' contents to +Adobe's PDF vector format. + +[section API] + +[list_begin definitions] + +[call [cmd ::canvas::pdf] [arg pathName]] + +Dump the contents of the canvas [arg pathName]. The result is a string +in Adobe's PDF. + +[list_end] +[vset CATEGORY canvas] +[include ../../support/devel/doc/feedback.inc] +[manpage_end] ADDED modules/canvas/canvas_pdf.tcl Index: modules/canvas/canvas_pdf.tcl ================================================================== --- /dev/null +++ modules/canvas/canvas_pdf.tcl @@ -0,0 +1,51 @@ +# *- tcl -*- +# ### ### ### ######### ######### ######### + +# Copyright (c) 2014 andreas Kupries, Arjen Markus +# OLL licensed (http://wiki.tcl.tk/10892). + +# ### ### ### ######### ######### ######### +## Requisites + +package require Tcl 8.5 +package require Tk 8.5 +package require pdf4tcl +package require fileutil + +namespace eval ::canvas {} + +# ### ### ### ######### ######### ######### +## Implementation. + +proc ::canvas::pdf {canvas} { + #raise [winfo toplevel $canvas] + #update + + set tmp [fileutil::tempfile canvas_pdf_] + + # Note: The paper dimensions are hardcoded. A bit less than A7, + # looks like. This looks to be something which could be improved + # on. + + # Note 2: We go through a temp file to write the pdf, and load it + # back into memory for the caller to use. + + set pdf [::pdf4tcl::new %AUTO% -paper {9.5c 6.0c}] + $pdf canvas $canvas -width 9.2c + $pdf write -file $tmp + $pdf destroy + + set data [fileutil::cat $tmp] + file delete $tmp + + return $data +} + +# ### ### ### ######### ######### ######### +## Helper commands. Internal. + +# ### ### ### ######### ######### ######### +## Ready + +package provide canvas::pdf 1.0.1 +return Index: modules/canvas/pkgIndex.tcl ================================================================== --- modules/canvas/pkgIndex.tcl +++ modules/canvas/pkgIndex.tcl @@ -7,8 +7,9 @@ package ifneeded canvas::edit::polyline 0.1 [list source [file join $dir canvas_epolyline.tcl]] package ifneeded canvas::edit::quadrilateral 0.1 [list source [file join $dir canvas_equad.tcl]] package ifneeded canvas::gradient 0.2 [list source [file join $dir canvas_gradient.tcl]] package ifneeded canvas::highlight 0.1 [list source [file join $dir canvas_highlight.tcl]] package ifneeded canvas::mvg 1 [list source [file join $dir canvas_mvg.tcl]] +package ifneeded canvas::pdf 1.0.1 [list source [file join $dir canvas_pdf.tcl]] package ifneeded canvas::snap 1.0.1 [list source [file join $dir canvas_snap.tcl]] package ifneeded canvas::tag 0.1 [list source [file join $dir canvas_tags.tcl]] package ifneeded canvas::track::lines 0.1 [list source [file join $dir canvas_trlines.tcl]] Index: modules/diagrams/application.tcl ================================================================== --- modules/diagrams/application.tcl +++ modules/diagrams/application.tcl @@ -46,11 +46,17 @@ return } proc ::diagram::application::showerror {text} { global argv0 - puts stderr "$argv0: $text" + if {[catch {package present Tk}]} { + puts stderr "$argv0: $text" + } else { + tk_messageBox -type ok -icon error \ + -title "Error in application" \ + -message "$argv0: $text" + } exit 1 } # # ## ### ##### ######## ############# ##################### ## Internal data and status @@ -464,7 +470,7 @@ after 100 return $dip } # # ## ### ##### ######## ############# ##################### -package provide diagram::application 1.2 +package provide diagram::application 1.3 return Index: modules/diagrams/pkgIndex.tcl ================================================================== --- modules/diagrams/pkgIndex.tcl +++ modules/diagrams/pkgIndex.tcl @@ -9,7 +9,7 @@ package ifneeded diagram::point 1 [list source [file join $dir point.tcl]] package ifneeded diagram::core 1 [list source [file join $dir core.tcl]] package ifneeded diagram::basic 1.0.1 [list source [file join $dir basic.tcl]] package ifneeded diagram 1 [list source [file join $dir diagram.tcl]] -package ifneeded diagram::application 1.2 [list source [file join $dir application.tcl]] +package ifneeded diagram::application 1.3 [list source [file join $dir application.tcl]]