Eskil

Check-in [62c8734260]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:*** empty log message ***
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 62c87342604e371a8d2b3d88831844d14eaeb290
User & Date: peter 2007-01-07 00:17:02.000
Context
2007-01-10
21:02
Added merge.tcl source file check-in: b58b587b25 user: peter tags: trunk
2007-01-07
00:17
*** empty log message *** check-in: 62c8734260 user: peter tags: trunk
00:15
Started on PDF printing. check-in: 027595bbd6 user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Added src/printobj.tcl.


























































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#----------------------------------------------------------------------
#  Eskil, Printing object
#
#  Copyright (c) 2006, Peter Spjuth  (peter.spjuth@space.se)
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; see the file COPYING.  If not, write to
#  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#  Boston, MA 02111-1307, USA.
#
#----------------------------------------------------------------------
# $Revision$
#----------------------------------------------------------------------

set ::auto_path [concat /home/spjutp/tools/pdf4tcl/pdf4tcl $::auto_path]
package require pdf4tcl
package require snit

snit::type eskilprint {
    component pdf
    delegate method * to pdf

    delegate option -margin to pdf
    delegate option -paper  to pdf

    option -cpl        -default 80
    option -cpln       -default 5
    option -headsize   -default 8
    option -headleft   -default "Header Text Left"
    option -headright  -default "Header Text Right"
    option -headnpages -default 10
    option -file       -default exp.pdf

    variable width
    variable height
    variable hoy
    variable fontsize
    variable linesize
    variable nlines
    variable ox1
    variable ox2
    variable oy
    variable page

    constructor {args} {
        set tmp(-file) $options(-file)
        catch {array set tmp $args}
        install pdf using pdf4tcl::pdf4tcl %AUTO% \
                -landscape 1 -paper a4 -margin 15mm -file $tmp(-file)
        $self configurelist $args
        $self StartPrint
    }
    destructor {
        catch {$pdf destroy}
    }

    method StartPrint {} {
        # Page size
        foreach {width height} [$pdf getDrawableArea] break

        # Header metrics
        $pdf setFont $options(-headsize) Courier
        set headoffset [expr {$options(-headsize) + [$pdf getFontMetric bboxy]}]
        set hoy $headoffset

        # Figure out font size from number of chars per line
        set charwidthHead [$pdf getCharWidth "0"]
        set charwidth [expr {$width / 2.0 / ($options(-cpl) + $options(-cpln) + 1)}]
        set fontsize [expr {$options(-headsize) * $charwidth / $charwidthHead}]
        $pdf setFont $fontsize

        # Text metrics
        set linesize  $fontsize
        set offset    [expr {$fontsize + [$pdf getFontMetric bboxy]}]
        set charwidth [$pdf getCharWidth "0"]
        set nlinesf [expr {($height - $options(-headsize)) / $linesize}]
        # Number of lines per page
        set nlines  [expr {int($nlinesf - 1.0)}]
        #set nlines 66
        # Offsets to starting points in both subpages.
        set ox1 $charwidth
        set ox2 [expr {$width / 2.0 + $charwidth}]
        set oy  [expr {($nlinesf - $nlines) / 2.0 * $linesize + \
                                     $offset + $options(-headsize)}]

        # Reset current page
        set page 0
    }
    method getNLines {} {
        return $nlines
    }

    # Start a new page
    method newPage {} {
        $pdf startPage
        incr page

        # Draw borders
        $pdf setStrokeColor 0 0 0
        $pdf setFillColor 0.0 0.0 0.0
        $pdf setLineStyle 0.5
        # Outer border
        $pdf rectangle 0 $options(-headsize) \
                $width [expr {$height - $options(-headsize)}]
        # Center line
        $pdf line [expr {$width / 2.0}] $options(-headsize) \
                [expr {$width / 2.0}] $height

        # Header
        $pdf setFont $options(-headsize) Courier
        $pdf text $options(-headleft) -x 0 -y $hoy 
        $pdf text "Page $page of $options(-headnpages)" \
                -x [expr {$width / 2.0}] -y $hoy -align center
        $pdf text $options(-headright) -x $width -y $hoy -align right

        # Normal font
        $pdf setFont $fontsize Courier
    }

    method setHalf {half} {
        if {$half eq "left"} {
            $pdf setTextPosition $ox1 $oy
        } else {
            $pdf setTextPosition $ox2 $oy
        }
    }

    method setTag {tag fill} {
        variable tags
        set tags($tag) $fill
    }

    # Format a line of text/tag pairs
    method drawTextLine {line} {
        variable tags
        foreach {text tag} $line {
            if {$tag eq ""} {
                $self text $text
            } else {
                set fill $tags($tag)
                $self text $text -fill $fill
            }
        }
    }

    # Produce one page
    method onePage {} {

        $self newPage

        # Dummy strings
        set longstr  [string repeat "MifjgqIo" 100]
        set strcpl   [string range $longstr 0 [expr {$options(-cpl) - 1}]]
        set strcpl10 [string range $longstr 0 [expr {$options(-cpl) + 9}]]

        # Text
        for {set line 0} {$line < $nlines} {incr line} {
            if {$line % 2 == 0} {
                $pdf setBgColor 1.0 0.5 0.5
            } else {
                $pdf setBgColor 0.5 1.0 0.5
            }
            $pdf text $line -x $ox1 -y [expr {$oy + $line * $linesize}]
            $pdf text "hejsan" -fill 1
            $pdf text "hoppsan" -fill "0.5 0.5 1.0"
            $pdf text "Miffo"
            #$pdf drawTextAt $ox2 [expr {$oy + $line * $linesize}] "Hejsan" -fill 1
            #$pdf drawTextAt $ox2 [expr {$oy + $line * $linesize}] $strcpl -fill 1
            $pdf text $strcpl -x $ox2 -y [expr {$oy + $line * $linesize}] -fill 1
        }
    }

    # Finish a print job
    method endPrint {} {
        $pdf finish
        $pdf destroy
        $self destroy
    }
}