283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
$pdf setHalf right
for {set i 0} {$i < $linesPerPage && $i2 < $len2} {incr i ; incr i2} {
$pdf drawTextLine [lindex $wraplines2 $i2]
$pdf newLine
}
}
$pdf endPrint
}
# Count the length of a line during a text dump
proc AccumulateMax {key value index} {
set index [lindex [split $index "."] 1]
set len [expr {[string length $value] + $index - 1}]
if {$len > $::eskil(currentCharsPerLine)} {
set ::eskil(currentCharsPerLine) $len
}
}
# Count the longest line length in the current display
proc CountCharsPerLine {top} {
set ::eskil(currentCharsPerLine) 0
$::widgets($top,wDiff1) dump -text -command AccumulateMax 1.0 end
$::widgets($top,wDiff2) dump -text -command AccumulateMax 1.0 end
return $::eskil(currentCharsPerLine)
}
proc BrowsePrintFileName {top entry} {
set prev $::eskil($top,printFile)
set dir [file dirname $prev]
set apa [tk_getSaveFile -initialdir $dir -initialfile [file tail $prev] \
-parent [winfo toplevel $entry] -title "PDF file"]
if {$apa ne ""} {
set ::eskil($top,printFile) $apa
$entry xview end
}
}
# Create a print dialog for PDF.
proc doPrint {top {quiet 0}} {
if {$quiet} {
PrintDiffs $top 1
return
}
destroy .pr
toplevel .pr -padx 3 -pady 3
wm title .pr "Print diffs to PDF"
# Layout
ttk::label .pr.hsl -anchor w -text "Header Size"
tk::spinbox .pr.hss -textvariable ::Pref(printHeaderSize) \
-from 5 -to 16 -width 3
ttk::label .pr.cll -anchor w -text "Chars per line"
ttk::entryX .pr.cle -textvariable ::Pref(printCharsPerLine) -width 4
ttk::frame .pr.clf
set values [list 80]
set cpl [CountCharsPerLine $top]
if {$cpl != 0} {
lappend values $cpl
}
if {[string is digit -strict $::Pref(printCharsPerLine)]} {
lappend values $::Pref(printCharsPerLine)
}
set values [lsort -unique -integer $values]
foreach value $values {
ttk::radiobutton .pr.clf.$value -variable ::Pref(printCharsPerLine) \
-value $value -text $value
pack .pr.clf.$value -side left -padx 3 -pady 3
}
# Select paper size
set paperlist [lsort -dictionary [pdf4tcl::getPaperSizeList]]
ttk::label .pr.psl -anchor w -text "Paper Size"
ttk::combobox .pr.psc -values $paperlist -textvariable ::Pref(printPaper) \
-width 6 -state readonly
# Color
foreach {::TmpPref(chr) ::TmpPref(chg) ::TmpPref(chb)} \
$::Pref(printColorChange) break
foreach {::TmpPref(n1r) ::TmpPref(n1g) ::TmpPref(n1b)} \
$::Pref(printColorNew1) break
foreach {::TmpPref(n2r) ::TmpPref(n2g) ::TmpPref(n2b)} \
$::Pref(printColorNew2) break
trace add variable ::TmpPref write {
set ::Pref(printColorChange) [list $::TmpPref(chr) $::TmpPref(chg) $::TmpPref(chb)]
set ::Pref(printColorNew1) [list $::TmpPref(n1r) $::TmpPref(n1g) $::TmpPref(n1b)]
set ::Pref(printColorNew2) [list $::TmpPref(n2r) $::TmpPref(n2g) $::TmpPref(n2b)]
list}
ttk::labelframe .pr.cf -text "Color" -padding 3
ttk::label .pr.cf.l1 -text "Change"
tk::spinbox .pr.cf.s1r -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(chr)
tk::spinbox .pr.cf.s1g -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(chg)
tk::spinbox .pr.cf.s1b -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(chb)
ttk::label .pr.cf.l2 -text "Old"
tk::spinbox .pr.cf.s2r -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n1r)
tk::spinbox .pr.cf.s2g -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n1g)
tk::spinbox .pr.cf.s2b -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n1b)
ttk::label .pr.cf.l3 -text "New"
tk::spinbox .pr.cf.s3r -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n2r)
tk::spinbox .pr.cf.s3g -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n2g)
tk::spinbox .pr.cf.s3b -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n2b)
grid .pr.cf.l1 .pr.cf.s1r .pr.cf.s1g .pr.cf.s1b -sticky w -padx 3 -pady 3
grid .pr.cf.l2 .pr.cf.s2r .pr.cf.s2g .pr.cf.s2b -sticky w -padx 3 -pady 3
grid .pr.cf.l3 .pr.cf.s3r .pr.cf.s3g .pr.cf.s3b -sticky w -padx 3 -pady 3
# File
ttk::label .pr.fnl -anchor w -text "File name"
|
>
>
>
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
<
<
<
|
<
|
<
<
|
|
>
>
|
>
|
>
|
>
>
>
>
|
|
|
|
|
|
|
|
|
>
|
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
|
$pdf setHalf right
for {set i 0} {$i < $linesPerPage && $i2 < $len2} {incr i ; incr i2} {
$pdf drawTextLine [lindex $wraplines2 $i2]
$pdf newLine
}
}
$pdf endPrint
tk_messageBox -title "Eskil Print" -parent $top \
-message "Printed $npages pages to $pdfFile" -type ok
}
# Count the length of a line during a text dump
proc AccumulateMax {key value index} {
set index [lindex [split $index "."] 1]
set len [expr {[string length $value] + $index - 1}]
if {$len > 0} {
lappend ::eskil(currentCharsPerLine) $len
}
}
# Count the longest line length in the current display
proc CountCharsPerLine {top} {
set ::eskil(currentCharsPerLine) {}
$::widgets($top,wDiff1) dump -text -command AccumulateMax 1.0 end
$::widgets($top,wDiff2) dump -text -command AccumulateMax 1.0 end
set ::eskil(currentCharsPerLine) \
[lsort -integer $::eskil(currentCharsPerLine)]
return [lindex $::eskil(currentCharsPerLine) end]
}
# In a sorted list of integers, figure out where val fits
# In 8.6 this could use lsearch -bisect
proc FindPercentile {l val} {
set len [llength $l]
# No elements, so all are covered in a way
if {$len == 0} { return 100 }
# Above range, so 100%
if {[lindex $l end] <= $val} { return 100 }
# Under range, so 0%
if {[lindex $l 0] > $val} { return 0 }
# Single element should not slip through...
if {$len <= 1} { return 0 }
set i [lsearch -integer -all $l $val]
set i [lindex $i end]
if {$i >= 0} {
return [expr {100 * $i / ($len - 1)}]
}
# To keep search down, just look at multiples of 1%
set prev 0
for {set t 0} {$t <= 100} {incr t} {
set i [expr {$t * ($len - 1) / 100}]
if {$val < [lindex $l $i]} {
return $prev
}
set prev $t
}
return 99
}
# Figure out reasonable selections for line length.
# 80 chars, and longest line used are always included.
proc CharsPerLineOptions {top} {
set values [list 80]
set cpl [CountCharsPerLine $top]
if {$cpl ne "" && $cpl != 0} {
lappend values $cpl
}
if {[string is digit -strict $::Pref(printCharsPerLine)]} {
lappend values $::Pref(printCharsPerLine)
}
# Include 90% if reasonable
set len [llength $::eskil(currentCharsPerLine)]
set cpl [lindex $::eskil(currentCharsPerLine) [expr {9*$len/10}]]
if {$cpl ne "" && $cpl != 0} {
lappend values $cpl
}
set values [lsort -unique -integer $values]
set result {}
foreach value $values {
set p [FindPercentile $::eskil(currentCharsPerLine) $value]
lappend result $value "$value ($p %)" \
"$p % of the lines are within this line length"
}
return $result
}
proc BrowsePrintFileName {top entry} {
set prev $::eskil($top,printFile)
set dir [file dirname $prev]
set apa [tk_getSaveFile -initialdir $dir -initialfile [file tail $prev] \
-parent [winfo toplevel $entry] -title "PDF file"]
if {$apa ne ""} {
set ::eskil($top,printFile) $apa
$entry xview end
}
}
# Fix to give spinbox nicer appearance
proc MySpinBox {w args} {
ttk::spinbox $w -command [list $w selection clear] -state readonly \
{*}$args
}
# Create a print dialog for PDF.
proc doPrint {top {quiet 0}} {
if {$quiet} {
PrintDiffs $top 1
return
}
destroy .pr
toplevel .pr -padx 3 -pady 3
wm title .pr "Print diffs to PDF"
# Layout
ttk::label .pr.hsl -anchor w -text "Header Size"
MySpinBox .pr.hss -textvariable ::Pref(printHeaderSize) \
-from 5 -to 16 -width 3 -format %g
ttk::label .pr.cll -anchor w -text "Chars per line"
ttk::entryX .pr.cle -textvariable ::Pref(printCharsPerLine) -width 4
ttk::frame .pr.clf
set values [CharsPerLineOptions $top]
foreach {value label balloon} $values {
ttk::radiobutton .pr.clf.$value -variable ::Pref(printCharsPerLine) \
-value $value -text $label
addBalloon .pr.clf.$value $balloon
pack .pr.clf.$value -side left -padx 3 -pady 3
}
# Select paper size
set paperlist [lsort -dictionary [pdf4tcl::getPaperSizeList]]
ttk::label .pr.psl -anchor w -text "Paper Size"
ttk::combobox .pr.psc -values $paperlist -textvariable ::Pref(printPaper) \
-width 6 -state readonly
# Color
foreach {::TmpPref(chr) ::TmpPref(chg) ::TmpPref(chb)} \
$::Pref(printColorChange) break
foreach {::TmpPref(n1r) ::TmpPref(n1g) ::TmpPref(n1b)} \
$::Pref(printColorNew1) break
foreach {::TmpPref(n2r) ::TmpPref(n2g) ::TmpPref(n2b)} \
$::Pref(printColorNew2) break
trace add variable ::TmpPref write {
set ::Pref(printColorChange) \
[list $::TmpPref(chr) $::TmpPref(chg) $::TmpPref(chb)]
set ::Pref(printColorNew1) \
[list $::TmpPref(n1r) $::TmpPref(n1g) $::TmpPref(n1b)]
set ::Pref(printColorNew2) \
[list $::TmpPref(n2r) $::TmpPref(n2g) $::TmpPref(n2b)]
list}
ttk::labelframe .pr.cf -text "Color" -padding 3
ttk::label .pr.cf.hr -text "Red"
ttk::label .pr.cf.hg -text "Green"
ttk::label .pr.cf.hb -text "Blue"
ttk::label .pr.cf.l1 -text "Change"
MySpinBox .pr.cf.s1r -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(chr)
MySpinBox .pr.cf.s1g -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(chg)
MySpinBox .pr.cf.s1b -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(chb)
ttk::label .pr.cf.l2 -text "Old"
MySpinBox .pr.cf.s2r -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n1r)
MySpinBox .pr.cf.s2g -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n1g)
MySpinBox .pr.cf.s2b -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n1b)
ttk::label .pr.cf.l3 -text "New"
MySpinBox .pr.cf.s3r -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n2r)
MySpinBox .pr.cf.s3g -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n2g)
MySpinBox .pr.cf.s3b -from 0.0 -to 1.0 -increment 0.1 -format %.1f \
-width 4 -textvariable ::TmpPref(n2b)
grid x .pr.cf.hr .pr.cf.hg .pr.cf.hb -pady 1
grid .pr.cf.l1 .pr.cf.s1r .pr.cf.s1g .pr.cf.s1b -sticky w -padx 3 -pady 3
grid .pr.cf.l2 .pr.cf.s2r .pr.cf.s2g .pr.cf.s2b -sticky w -padx 3 -pady 3
grid .pr.cf.l3 .pr.cf.s3r .pr.cf.s3g .pr.cf.s3b -sticky w -padx 3 -pady 3
# File
ttk::label .pr.fnl -anchor w -text "File name"
|