/usr/share/texmf-texlive/scripts/epspdf/epspdftk.rb is in texlive-pictures 2009-15.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 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 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | #!/usr/bin/env ruby
# epspdf conversion utility, GUI frontend
#####
# Copyright (C) 2006, 2008, 2009 Siep Kroonenberg
# n dot s dot kroonenberg at rug dot nl
#
# This program is free software, licensed under the GNU GPL, >=2.0.
# This software comes with absolutely NO WARRANTY. Use at your own risk!
#####
#$DEBUG=1
# find other pieces of epspdf
$:.unshift( File.dirname( __FILE__ ) )
##########################################
# load conversion engine. epspdf also loads epspdfrc,
# which detects platform and available converters.
require 'epspdf'
$VERBOSE = nil
#require 'pp'
if $DEBUG
puts ARCH
puts Config::CONFIG['arch']
puts "Ghostscript command #{$settings.gs_prog}"
puts "Pdftops command #{$settings.pdftops_prog}"
end
# is there a viewer for the PsPdf object p?
def viewable( p )
return nil unless p && p.path
return nil if p.type == 'other'
case ARCH
when 'unix'
return true if p.type =~ /e?ps/ and ( not $settings.ps_viewer.empty? )
return true if p.type == 'pdf' and ( not $settings.pdf_viewer.empty? )
else
return true
end # case ARCH
return nil
end # viewable
####################################
# Tk and custom widgets
require 'tk'
require 'tkscrollbox'
# For event field strings, which codify event details, see
# the bind man page from the tk man pages (Ubuntu: tk8.x-doc package)
####################################
# combobox adapted from Takaaki Tateishi <ttate / jaist.ac.jp>
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/18167
# literal content of an xbm file, created e.g. with the GIMP
$DOWN_ARROW_IMG = <<STR
#define dwnarrow.icn_width 15
#define dwnarrow.icn_height 10
static unsigned char dwnarrow.icn_bits[] = {
0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0xf8, 0x0f, 0xf0, 0x07, 0xe0, 0x03,
0xc0, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00 };
STR
BG = 'gray85'
class TkACombobox < TkFrame
include TkComposite
attr_reader :scrollbox, :tframe
attr_accessor :entries, :is_valid
def initialize_composite( params = {} )
@entries = []
@is_valid = proc{ |s| true }
@entry = nil
# entry widget plus arrow for drop-down listbox
@entry = TkEntry.new( @frame,
'width' => 30, 'bd' => 1, 'highlightthickness' => 0 )
image = TkBitmapImage.new( 'data' => $DOWN_ARROW_IMG )
@bt_arrow = TkButton.new( @frame, 'bd' => 1, 'image' => image,
'highlightthickness' => 0, 'command' => proc{ cmd_scrollbox } )
@entry.pack( 'side' => 'left', 'fill' => 'x', 'expand' => 'yes' )
@bt_arrow.pack( 'side' => 'right' )
# drop-down listbox
@tframe = TkToplevel.new( @frame )
@tframe.overrideredirect( 1 ) # no window manager decorations
@tframe.transient
@tframe.withdraw
@scrollbox = TkScrollbox.new( @tframe, 'width' => 30, 'border' => 1 )
@scrollbox.pack( 'fill' => 'both', 'expand' => 'yes' )
@scrollbox.bind( 'Any-Leave', proc{ hide_scrollbox } )
# "%y", "%P": event field string; see bind manual from tk8.x-docs
@scrollbox.bind( 'Double-1', proc{ |y| select_this( y ) }, "%y" )
@scrollbox.bind( 'Return', proc{ |y| select_this( y ) }, "%y" )
@entry.bind( 'FocusOut', proc{ entry_proc } )
@entry.bind( 'Return', proc{ entry_proc } )
@entry.bind( 'Double-1', proc{ entry_proc } )
delegate( :width, @entry, @scrollbox )
configure params if params
end # initialize_composite
def cmd_scrollbox
case @tframe.state
when "withdrawn"
show_scrollbox( @entries )
else
hide_scrollbox
end
end
def show_scrollbox( entries = nil )
width = TkWinfo.width( @frame )
height = 5 * TkWinfo.height( @entry )
rootx = TkWinfo.rootx( @frame )
rooty = TkWinfo.rooty( @frame ).to_i + TkWinfo.height( @frame ).to_i
geometry = "#{width}x#{height}+#{rootx}+#{rooty}"
@tframe.geometry( geometry )
@tframe.deiconify
entries.each{ |entry| @scrollbox.insert( "end", entry ) } if entries
end
def hide_scrollbox
@tframe.withdraw
@scrollbox.delete( 0, "end" )
@entry.focus
end
def select_this( y )
i = @scrollbox.nearest( y )
s = @scrollbox.get( i )
@entry.delete( 0, 'end' )
@entry.insert( 0, s )
@is_valid.call( s ) # activates side effects
hide_scrollbox
end
def entry_proc
#puts @entry.value
if @is_valid.call( @entry.value )
@entries.unshift( @entry.value ).sort! \
unless @entries.index( @entry.value )
@tframe.withdraw unless @tframe.state == 'withdrawn'
else
Tk.bell
@entry.focus( true )
end
end
def get_entry
@entry.value
end
def set_entry( s )
@entry.delete( 0, 'end' )
@entry.insert( 'end', s ) if s
end
end # TkACombobox
####################################
# checkboxes and radioboxes with built-in variables.
# use string- rather than symbol keys when creating these widgets.
def zero_one( v ) # For Tcl/Tk, everything is a string
case v
when /t(rue)?|y(es)?|1/i
'1'
when /f(alse)?|n(o)?|0/i
'0'
when 1
'1'
when 0
'0'
else
nil
end
end
class TkACheck < TkFrame
include TkComposite
def initialize_composite( params = {} )
Kernel::fail StandardError, "TkACheck doesn\'t allow \'variable\' key" \
if params.has_key?( 'variable' )
v = params.delete( 'value' )
@value = TkVariable.new( zero_one( v ) )
@ck = TkCheckButton.new( @frame, :variable => @value \
).pack( :padx => 0, :pady => 0, :ipadx => 0, :ipady => 0 )
delegate( 'DEFAULT', @ck )
configure params unless params.empty?
end # initialize_composite
def value
@value.value
end
def value=( v )
@value.value = zero_one( v )
end
end # TkACheck
class TkRadios < TkFrame
include TkComposite
def initialize_composite( params = {} )
Kernel::fail StandardError, "TkRadios doesn\'t allow \'variable\' key" \
if params.has_key?( 'variable' )
@value = TkVariable.new( params.delete( 'value' ) )
@values = params.delete( 'values' )
@packing = params.delete( 'packing' )
@buttons = []
if ( @values.kind_of? Hash )
@values.each_key { |k|
@buttons << TkRadioButton.new( @frame,
:text => @values[k] || k,
:variable => @value,
:value => k
).pack( @packing )
}
elsif ( @values.kind_of? Array )
@values.each { |k|
@buttons << TkRadioButton.new( @frame,
:text => k,
:variable => @value,
:value => k
).pack( @packing )
}
else
Kernel::fail StandardError, "TkRadios requires a values array or hash"
end
delegate( 'DEFAULT', @frame )
delegate( 'command', *@buttons )
delegate( 'state', *@buttons )
configure( params ) unless params.empty?
end # initialize_composite
def value
@value.value
end
def value=( v )
@value.value = v
end
def get_button_state( v )
@buttons.each { |b|
if b.value == v
return b.cget( 'state' )
end
}
return nil
end
def set_button_state( v, s )
@buttons.each { |b|
if b.value == v
b.configure( 'state' => s )
@value.value = nil if s == 'disabled' and @value.value == v
end
}
end
end # TkRadios
$root = TkRoot.new { title "PostScript- and pdf conversions" }
##################################
# Initial tests: no gs => bail out; no viewers => warning
if not $settings.gs_prog
Tk.messageBox(
:icon=>'error',
:type=>'ok',
:parent=>$root,
:message=>"No Ghostscript found; aborting..."
)
abort
end
if ARCH == 'unix'
if not $settings.pdf_viewer
Tk.messageBox( :icon=>'warning', :type=>'ok', :message =>
"No PostScript- or pdf viewer found" )
elsif not $settings.ps_viewer
Tk.messageBox( :icon=>'warning', :type=>'ok', :message =>
"No PostScript viewer found" )
end
end
########################################
# defaultDir already initialized by epspdfrc
if ((ARGV.length > 0) and (ARGV[0].length > 0) and File.directory?(ARGV[0]))
$settings.defaultDir = ARGV[0]
#print "Default dir set to #{ARGV[0]} by epspdftk"
end
$source = PsPdf.new # currently loaded PsPdf object
$tl_config = nil # configuration screen
# $tl_wait = nil # instead of a wait cursor or progress bar
# widgets which are configured on the fly,
# e.g. by ep_config, get a global name.
# They don't really have to be declared early.
# buttons and option widgets
$view_button = nil
$view_with_button = nil
$page_radio = nil
$page_entry = nil
$type_radio = nil
$bbox_check = nil
# widgets which display file info
$source_dir_label = nil
$source_name_label = nil
$source_type_label = nil
def set_widget_states
# states (normal/disabled) for various widgets.
# their values should already be mutually consistent.
# widgets concerned:
# view / save
# output format / bbox / single page / page no.
$view_button.configure( :state =>
( viewable( $source ) ? 'normal' : 'disabled' ) )
$view_with_button.configure( :state =>
( viewable( $source ) ? 'normal' : 'disabled' ) ) if ARCH == 'w32'
$save_button.configure( :state =>
( ( $source.type and $source.type != 'other' ) ? \
'normal' : 'disabled' ) )
$type_radio.set_button_state( 'ps', ( \
( $settings.pdftops_prog and $settings.use_pdftops and
( $source.type =~ /ps|pdf/ ) ) ? \
'normal' : 'disabled' ) )
$page_radio.set_button_state( 'all', 'normal' )
$page_radio.set_button_state( 'single', 'normal' )
$page_radio.set_button_state( 'all', 'disabled' ) if \
$type_radio.value == 'eps'
$page_radio.set_button_state( 'single', 'disabled' ) if \
$type_radio.value == 'ps'
$page_entry.configure( :state => \
( $page_radio.value == 'all' ? 'disabled' : 'normal' ) )
$bbox_check.configure( :state => \
( $page_radio.value == 'single' or $source.type =~ /eps/ ) \
? 'normal' : 'disabled' )
end # set_widget_states
def load_file( path )
$source = PsPdf.new( 'file' => path )
# write info to labels
$source_dir_label.configure( :text => File.dirname( path ) )
$source_name_label.configure( :text => File.basename( path ) )
$source_type_label.configure( :text => $source.type )
$source.pdf_pages if ( $source.type == 'pdf' )
$source_npages_label.configure( :text => (
case $source.type
when 'pdf' then ( $source.npages ).to_s
when 'eps' then '1'
else ''
end
) )
$page_entry.delete( 0, 'end' )
$page_entry.insert( 'end', '1' )
set_widget_states
end
# ipadx and ipady seem ineffective for frames
FRM_PACK = {
:side => 'top',
:fill => 'x',
:expand => 1,
:padx => 4,
:pady => 4,
:anchor => 'w'
}
##################################
# configuration screen (toplevel widget)
$tl_config = nil
def ep_config
if not $tl_config
$tl_config = TkToplevel.new( $root,
:title => 'Configure epspdf' )
### viewers frame
if ARCH == 'unix'
TkFrame.new( $tl_config ) { |frm|
frm.borderwidth 2
frm.relief 'sunken'
TkLabel.new( frm ) do
text 'Viewers'
font.weight 'bold'
pack( :side => 'top', :padx => 8, :anchor => 'w' )
end
TkFrame.new( frm ) { |fm|
TkLabel.new( fm, :text => 'Pdf viewer' ).grid(
:in => fm, :row => 0, :column => 0,
:sticky => 'w', :padx => 2 )
$pdf_vw_combo = TkACombobox.new( fm, :width => 30 )
$pdf_vw_combo.is_valid = lambda { |s| is_a_program( s ) }
$pdf_vw_combo.grid( :in => fm, :row => 0, :column => 1,
:pady => 2, :padx => 2, :sticky => 'e' )
TkLabel.new( fm, :text => 'PostScript viewer' ).grid(
:in => fm, :row => 1, :column => 0,
:sticky => 'w', :padx => 2 )
$ps_vw_combo = TkACombobox.new( fm, :width => 30 )
$ps_vw_combo.is_valid = lambda { |s| is_a_program( s ) }
$ps_vw_combo.grid( :in => fm, :row => 1, :column => 1,
:pady => 2, :padx => 2, :sticky => 'e' )
}.pack( :side => 'top', :anchor => 'w', :fill => 'x' )
}.pack( FRM_PACK )
end # if unix
### pdf frame
TkFrame.new( $tl_config ){ |frm|
frm.borderwidth 2
frm.relief 'sunken'
TkLabel.new( frm ) do
text 'Conversion to pdf'
font.weight 'bold'
pack( :side => 'top', :padx => 4, :anchor => 'w' )
end
# internal packing
pack_pdf = {
:side => 'left', :padx => 2, :pady => 4, :anchor => 'w' }
TkLabel.new( frm, :text => 'Target use'
).pack( :side => 'top', :padx => 2, :pady => 0, :anchor => 'w' )
$pdf_target_radio = TkRadios.new( frm,
'values' => PDF_TARGETS, 'packing' => pack_pdf
).pack( :side => 'top', :anchor => 'w' )
# dummy widget for extra vertical space
TkLabel.new( frm, :text => ' ' ).pack
TkLabel.new( frm, :text => 'Pdf version'
).pack( :side => 'top', :padx => 2, :pady => 0, :anchor => 'w' )
$pdf_version_radio = TkRadios.new( frm,
'values' => PDF_VERSIONS, 'packing' => pack_pdf
).pack( :side => 'top', :anchor => 'w' )
TkLabel.new( frm, :text => ' ' ).pack
TkLabel.new( frm, :text => 'Custom Ghostscript/ps2pdf parameters'
).pack( :side => 'top', :padx => 2, :pady => 0, :anchor => 'w' )
$pdf_custom_entry = TkEntry.new( frm, :width => 50
).pack( :side => 'top', :padx => 2, :pady => 2, :anchor => 'w' )
}.pack( FRM_PACK )
### postscript frame
TkFrame.new( $tl_config ){ |frm|
frm.borderwidth 2
frm.relief 'sunken'
TkLabel.new( frm ) do
text 'Conversion to EPS and PostScript'
font.weight 'bold'
pack( :side => 'top', :padx => 4, :anchor => 'w' )
end
if ARCH == 'w32' # others: assume pdftops on search path
TkLabel.new( frm, :text => "Find pdftops"
).pack( :side => 'top', :anchor => 'w', :padx => 4 )
TkFrame.new( frm ) { |fm|
$pdftops_entry = TkEntry.new( fm, :width => 20
).pack( 'side'=>'left', :padx => 4 )
TkButton.new( fm,
:text => 'Browse ...',
:command => lambda {
tryprog = Tk.getOpenFile(
:filetypes => [ [ 'Programs', [ '.exe' ] ] ],
:parent => fm
)
if tryprog and ( not tryprog.empty? )
tryprog.sub!( /([\/\\])[^\/\\]+$/, '\1pdftops.exe' )
if test( ?f, tryprog )
$pdftops_entry.delete( 0, 'end' )
$pdftops_entry.insert( 'end', tryprog )
end
end # ifthenelse tryprog
} # command lambda
).pack( :side => 'left' ) # TkButton
}.pack( :side => 'top', :pady => 4, :anchor => 'w' )
end # ARCH == 'w32'
$pdftops_check = TkACheck.new( frm,
'text' => "Use pdftops if available (recommended)"
).pack( :side => 'top', :pady => 4, :anchor => 'w' )
}.pack( FRM_PACK ) # TkFrame |frm|
### boundingbox frame
TkFrame.new( $tl_config ){ |frm|
frm.borderwidth 2
frm.relief 'sunken'
TkLabel.new( frm ) do
text 'Hires BoundingBox'
font.weight 'bold'
pack( :side => 'top', :padx => 4, :anchor => 'w' )
end
TkLabel.new( frm ) do
text "Uncheck to prevent clipping"
pack( :side => 'top', :padx => 4, :anchor => 'w' )
end
$hires_check = TkACheck.new( frm,
'text' => "Use hires boundingbox if possible"
).pack( :side => 'top', :pady => 4, :anchor => 'w' )
}.pack( FRM_PACK ) # TkFrame |frm|
### button frame
TkFrame.new( $tl_config ) { |frm|
#frm.bg = BG
TkButton.new( frm,
:text => 'Cancel',
:command => lambda {
$tl_config.withdraw
$root.focus
}
).pack( :padx => 4, :side => 'left', :anchor => 'e' )
TkButton.new( frm,
:text => 'Done',
:command => lambda {
# copy settings from widgets to $settings
case ARCH
when 'unix' # viewers
$settings.accept_ps_viewer( $ps_vw_combo.get_entry )
$settings.accept_pdf_viewer( $pdf_vw_combo.get_entry )
when 'w32'
$settings.pdftops_prog = $pdftops_entry.get
end
$settings.ignore_hires_bb = ( $hires_check.value == '0' ) ? '1' : '0'
$settings.ignore_pdftops = ( $pdftops_check.value == '0' ) ? '1' : '0'
$settings.pdf_target = $pdf_target_radio.value
$settings.pdf_version = $pdf_version_radio.value
$settings.pdf_custom = $pdf_custom_entry.get
$settings.write_settings
$tl_config.withdraw
$root.focus
set_widget_states
} # lambda
).pack( :side => 'left', :anchor => 'e' )
}.pack( :side => 'bottom', :padx => 4, :pady => 4, :anchor => 'e' )
else
$tl_config.deiconify
end # ifthenelse $tl_config
# copy data from $settings to widgets
if ARCH == 'unix'
$pdf_vw_combo.set_entry( $settings.pdf_viewer )
$pdf_vw_combo.entries = $settings.pdf_viewers[0..-1] # deep copy
$ps_vw_combo.set_entry( $settings.ps_viewer )
$ps_vw_combo.entries = $settings.ps_viewers[0..-1]
elsif ARCH == 'w32'
$pdftops_entry.delete( 0, 'end' )
$pdftops_entry.insert( 'end', $settings.pdftops_prog ) \
if $settings.pdftops_prog and not $settings.pdftops_prog.empty?
end # ifthenelse ARCH
$hires_check.value = $settings.use_hires_bb ? '1' : '0'
$pdftops_check.value = $settings.use_pdftops ? '1' : '0'
$pdf_target_radio.value = $settings.pdf_target
$pdf_version_radio.value = $settings.pdf_version
$pdf_custom_entry.delete( 0, 'end' )
$pdf_custom_entry.insert( 'end', $settings.pdf_custom ) \
if not $settings.pdf_custom.empty?
end # def ep_config
###################################
### makeshift help
$tl_help = nil
def ep_help
if not $tl_help
$tl_help = TkToplevel.new( $root, :title => 'Epspdftk help' )
TkFrame.new( $tl_help ) { |tf|
txt = TkText.new( tf,
'width' => 80,
'height' => 25
) { |t|
TkScrollbar.new( tf,
'command' => lambda{ |*args| t.yview( *args ) } ) { |sc|
t.yscrollcommand( lambda{ |first, last| sc.set first, last } )
}.pack( 'side' => 'right', 'fill' => 'y' )
}.pack( 'expand' => 'yes', 'fill' => 'both' )
txt.delete( '1.0', 'end' )
# LF ok for Win32 and Mac? Otherwise, split and join with $/
File.open( File.dirname( __FILE__ ) + '/epspdf.help', 'r' ) { |f|
$s = f.read
}
txt.insert( '1.0', $s )
}.pack( 'side' => 'top', 'fill' => 'x' )
TkButton.new( $tl_help,
:text => 'Cancel',
:command => lambda{
$tl_help.withdraw
$root.focus
}
).pack( 'anchor' => 'e', 'padx' => 4, 'pady' => 4 )
else
$tl_help.deiconify
end # ifthenelse $tl_help
end # def ep_help
### some buttons
TkFrame.new( $root ) { |frm|
TkButton.new( frm,
:text => "Configure",
:command => lambda { ep_config }
).pack( :side => 'left', :padx => 4, :pady => 4 )
# There is pdf- and html help, and it would be simple enough to invoke
# either file from here, but for TL this would be in an entirely
# different directory, so instead we display an ascified helpfile
# packaged in the same directory as the code.
# TkButton.new( frm,
# :text => 'Help',
# :command => lambda {
# docdir = File.dirname( __FILE__ )
# docdir.sub!( /[\\\/]$/, '' )
# docdir = docdir + '/doc'
# if ARCH == 'w32'
# result = shell_open( docdir + "/epspdf_UG.html" )
# Tk.messageBox(
# 'icon' => 'error',
# 'title' => 'ShellExecute error',
# 'message' => shell_error_string( result )
# ) if result <= 32
# elsif ARCH == 'osx'
# fork { exec "open \"#{docdir}/epspdf_UG.html\"" }
# elsif $settings.pdf_viewer
# fork { exec "\"#{$settings.pdf_viewer}\" \"#{docdir}/epspdf.pdf\"" }
# else
# Tk.messageBox(
# 'icon' => 'warning',
# 'title' => 'No help viewer',
# 'message' => "Please select a pdf viewer in the configuration screen" +
# "\nand restart this program."
# )
# end
# }
# ).pack( :side => 'right', :padx => 4, :pady => 4)
TkButton.new( frm,
:text => 'Help',
:command => lambda { ep_help }
).pack( :side => 'right', :padx => 4, :pady => 4)
}.pack( :side => 'top', :fill => 'x' ) # frm
########################################
### status info
TkFrame.new( $root ){ |frm|
frm.borderwidth 2
frm.relief 'sunken'
### status info
TkFrame.new( frm ) { |fm|
TkLabel.new( fm,
:justify => 'left',
:text => 'Directory'
).grid( :in => fm, :sticky => 'w', :row => 0, :column => 0 )
$source_dir_label = TkLabel.new( fm,
:justify => 'left'
).grid( :in => fm, :sticky => 'w', :row => 0, :column => 1 )
TkLabel.new( fm,
:justify => 'left',
:text => 'File'
).grid( :in => fm, :sticky => 'w', :row => 1, :column => 0 )
$source_name_label = TkLabel.new( frm,
:justify => 'left'
).grid( :in => fm, :sticky => 'w', :row => 1, :column => 1 )
TkLabel.new( fm,
:justify => 'left',
:text => 'Type'
).grid( :in => fm, :sticky => 'w', :row => 2, :column => 0 )
$source_type_label = TkLabel.new( fm,
:justify => 'left'
).grid( :in => fm, :sticky => 'w', :row => 2, :column => 1 )
TkLabel.new( fm,
:justify => 'left',
:text => 'Pages'
).grid( :in => fm, :sticky => 'w', :row => 3, :column => 0 )
$source_npages_label = TkLabel.new( fm,
:justify => 'left'
).grid( :in => fm, :sticky => 'w', :row => 3, :column => 1 )
TkGrid.columnconfigure( fm, 0, :weight => 1, :minsize => 60, :pad =>4 )
TkGrid.columnconfigure( fm, 1, :weight => 3, :minsize => 60, :pad =>4 )
}.pack( :side => 'top', :anchor => 'w', :padx => 4 )
}.pack( FRM_PACK )
########################################
### conversion options: see also $options, defined in epspdf.rb
TkFrame.new( $root ) { |frm|
TkFrame.new( frm ) { |fm| # grayscaling, output format
TkFrame.new( fm ) { |f| # grayscaling
TkLabel.new( f, 'text' => 'Grayscaling'
).pack( :side => 'top', :anchor => 'w' )
gray_options = {
'gRAY' => 'Try harder to grayscale',
'gray' => 'Try to grayscale',
'color' => 'No color conversion'
}
$gray_radio = TkRadios.new( f,
'values' => gray_options,
'value' => 'color',
'packing' => { 'side' => 'top', 'anchor' => 'w' }
).pack( :side => 'bottom', :anchor => 'w' ) # $gray_radio
}.pack( :side => 'left', :padx => 4 ) # f: grayscaling
TkFrame.new( fm ) { |f| # output format
TkLabel.new( f, 'text' => 'Output format'
).pack( :side => 'top', :anchor => 'w' )
$type_radio = TkRadios.new( f,
'values' => [ 'pdf', 'eps', 'ps' ],
'value' => 'pdf',
'command' => lambda {
case 'value'
when 'eps'
$page_radio.value = 'single'
when 'ps'
$page_radio.value = 'all'
$bbox_check.value = '0'
end
set_widget_states
},
'packing' => { 'side' => 'top', 'anchor' => 'w' }
).pack( :side => 'bottom', :anchor => 'w' )
}.pack( :side => 'right', :padx => 4 ) # f: output format
}.pack( :side => 'top', :anchor => 'n', :fill => 'x' )
# dummy widget for extra vertical space
TkLabel.new( frm, :text => ' ' ).pack
$bbox_check = TkACheck.new( frm,
'text' => 'Compute tight boundingbox',
'value' => '0',
'command' => lambda {
$page_radio.value = 'single' if 'value' == '1'
set_widget_states
}
).pack( :side => 'top', :padx => 4, :anchor => 'w' )
TkLabel.new( frm, :text => ' ' ).pack
TkFrame.new( frm ) { |fm|
page_options = { 'all' => 'Convert all pages', 'single' => 'Page:' }
$page_radio = TkRadios.new( fm,
'values' => page_options,
'packing' => { 'side' => 'left', 'padx' => 4 },
'value' => 'single',
'command' => lambda {
$bbox_check.value = '0' if 'value' == 'all'
set_widget_states
}
).pack( 'side' => 'left', :anchor => 'nw' )
$page_entry = TkEntry.new( fm,
:validate => 'focus',
:vcmd => [ lambda { |s|
( s =~ /\d+/ ) and
( s.to_i >= 1 ) and
( $source.type != 'pdf' or s.to_i <= $source.npages )
}, "%P" ],
:invcmd => lambda { Tk.bell; $page_entry.focus },
:width => 5
).pack( :side => 'left' )
$page_entry.delete( 0, 'end' )
$page_entry.insert( 'end', '1' )
}.pack( 'side' => 'left', :anchor => 'nw' )
}.pack( FRM_PACK )
########################################
### wait message packed at bottom
$cnv_label = TkLabel.new( $root, 'text' => ''
).pack( 'side' => 'bottom', 'fill' => 'x', :anchor => 'nw' )
########################################
### view | open | save | done buttons
TkFrame.new( $root ) { |frm|
$view_button = TkButton.new( frm,
:text => 'View',
:state => 'disabled',
:command => lambda {
# start a viewer
if ARCH == 'w32'
result = shell_open( $source.path )
Tk.messageBox(
'icon' => 'error',
'title' => 'ShellExecute error',
'message' => shell_error_string( result )
) if result <= 32
elsif ARCH == 'osx'
fork { exec "open \"#{$source.path}\"" }
elsif viewable( $source )
viewer =
$source.type == 'pdf' ? $settings.pdf_viewer : $settings.ps_viewer
fork { exec "\"#{viewer}\" \"#{$source.path}\"" }
end
}
).pack( :side=>'left', :anchor => 'w', :padx=>4, :pady=>4 )
if ARCH == 'w32'
$view_with_button = TkButton.new( frm,
:text => 'View with...',
:state => 'disabled',
:command => lambda {
result = shell_open_with( $source.path )
Tk.messageBox(
'icon' => 'error',
'title' => 'ShellExecute error',
'message' => shell_error_string( result )
) if result <= 32
}
).pack( :side=>'left', :anchor => 'w', :padx=>4, :pady=>4 )
end # 'w32'
TkFrame.new( frm ) { |fm|
TkButton.new( fm,
:text => 'Open..',
:command => lambda {
path = Tk.getOpenFile(
:initialdir => $settings.defaultDir,
:filetypes => [
['All files', '*'],
['EPS', ['.eps']],
['PDF', ['.pdf']],
['PostScript', ['.ps']]
],
:parent => $root
)
if path and ( not path.empty? )
load_file( path )
$settings.defaultDir = File.expand_path( File.dirname( path ) )
end
}
).pack( :side=>'left', :padx=>4, :pady=>4 )
$save_button = TkButton.new( fm,
:text => "Convert and save..",
:command => lambda {
$options.type = $type_radio.value
$options.page = \
( ( $page_radio.value == 'single' ) ? $page_entry.value : nil )
$options.gray = ($gray_radio.value and $gray_radio.value != 'color' )
$options.gRAY = ($gray_radio.value and $gray_radio.value == 'gRAY' )
$options.bbox = ( ( $bbox_check.value == '1' ) \
and ( $page_radio.value == 'single' ) )
filetypes = case $options.type
when 'pdf' then [ ['Pdf', ['.pdf'] ] ]
when 'ps' then [ ['PostScript', ['.ps'] ] ]
when 'eps' then [ ['EPS (Encapsulated PostScript', ['.eps'] ] ]
end
path = nil
path = Tk.getSaveFile(
:filetypes => filetypes,
:parent => $root,
:initialdir => File.dirname( $source.path ),
:initialfile => File.basename( $source.path, ".*" ) +
'.' + $options.type,
:defaultextension => '.' + $options.type
)
return unless path && ! path.empty?
$settings.defaultDir = File.expand_path( File.dirname( path ) )
$cnv_label.configure(
'text' => "Converting #{File.basename($source.path)}" +
" to #{ File.basename(path)}..."
)
$cnv_label.update
begin
result = $source.any_to_any( $options )
rescue EPCallError => exc
mess = "Wrong method call or conversion not supported" +
" or wrong page number"
write_log( mess + $/ +
exc.message + $/ + exc.backtrace.join( $/ ) )
Tk.messageBox(
'icon' => 'error',
'type' => 'ok',
'parent' => $root,
'message' => "#{mess}\nSee #{LOGFILE} for details."
)
rescue EPBBError => exc
mess = "Boundingbox problem" + $/ +
exc.message
write_log( mess + $/ + exc.backtrace.join( $/ ) )
Tk.messageBox(
'icon' => 'error',
'type' => 'ok',
'parent' => $root,
'message' => "#{mess}\nSee #{LOGFILE} for details."
)
rescue EPSystemError => exc
mess = "Problem with system call" + $/ +
exc.message
write_log( mess + $/ + exc.backtrace.join( $/ ) )
Tk.messageBox(
'icon' => 'error',
'type' => 'ok',
'parent' => $root,
'message' => "#{mess}\nSee #{LOGFILE} for details."
)
ensure
# $tl_wait.withdraw
$cnv_label.configure( 'text' => '' )
$cnv_label.update
end
if result
ccp( result.path, path )
load_file( path )
Tk.messageBox(
'icon' => 'info',
'type' => 'ok',
'parent' => $root,
'message' => "Conversion completed"
)
end
}
).pack( :side=>'left', :padx=>0, :pady=>4 )
TkButton.new( fm,
:text => "Done",
:command => lambda { $root.destroy }
).pack( :side => 'left', :padx => 4, :pady => 4 )
}.pack( :side => 'right', :anchor => 'e' )
}.pack( :side => 'bottom', :fill => 'x' )
set_widget_states
$root.raise
Tk.mainloop
$settings.write_settings
cleantemp
|