#!/bin/sh # the next line find out the location of tixwish \ tixwishpath=`/bin/ls /usr/bin/tixwish* | head -n 1` # the next line restarts using tixwish \ exec $tixwishpath "$0" "$@" ### header region ### useful constants set DefaultSourceFontDir "/mnt/cdrom" set TempFile "/tmp/.ttfinst.tmp" set XTTFFontPath "/usr/X11R6/lib/X11/fonts/TrueType" set TargetFontDir "/usr/share/fonts/ttf" set TTFINFOPATH "/usr/X11R6/bin/ttfinfo" set logofile "/mnt/cdrom/logo.gif" # proc set version 0.7 proc copyright_info {} { dialog .about {Copyright (C) 1999. CLE Project.} \ { /* * Copyrighy (c) 1999 CLE Project. All rights reserved. * Copyright (c) 1999 Yuan-Chung Cheng. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by * Yuan-Chung Cheng and contributors for CLE Project * 4. Neither the name of the Author nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */} {} 0 Ok } # proc proc about_this {} { dialog .about {About this program.....} \ { This is the True-Type font installer written by Yuan-Chung Cheng . } {} 0 Ok } proc show_usage {} { dialog .about {USAGE} \ { Click on the entry to select the font you want to install. Double click on the listbox entry to preview the truetype font. When previewing, press '(', ')' to move, 'q' to go back. Press the 'Install' button to start install the selected fonts. Press the 'Cancel' button to abort. } {} 0 Ok } proc show_previewusage {} { dialog .about {Usage of preview program...} \ { Keys: x : fine counter-clockwise rotation c : fine clockwise rotation v : fast counter-clockwise rotation b : fast clockwise rotation + : fast scale up - : fast scale down u : fine scale down j : fine scale up l : go to next glyph k : go to previous glyph o : go to tenth next glyph i : go to tenth previous glyph 0 : go to hundredth next glyph 9 : go to hundredth previous glyph ) : go to 1000th next glyph ( : go to 1000th previous glyph h : toggle hinting q : exit NOTE: This is just a test program that is used to show off.} {} 0 Ok } proc do_install { wl FontData } { global TargetFontDir set selected_elements [$wl curselection] if {$selected_elements == ""} { dialog .about {Error!!} \ {You must select the fonts to be installed!!} {} 0 Back return } progress_create .progress pack .progress -expand yes -fill both -padx 10 -pady 10 for {set i 0} { $i < [llength $selected_elements] } {incr i} { set element_name [$wl get [lindex $selected_elements $i] ] for {set j 0} { $j < [llength $FontData] } {incr j} { set fontfilename [lindex [lindex $FontData $j] 0] set targetname [lindex [lindex $FontData $j] 1] set fontfoundry [lindex [lindex $FontData $j] 2] set fontfamily [lindex [lindex $FontData $j] 3] set fontencoding [lindex [lindex $FontData $j] 4] set fontproperties [lindex [lindex $FontData $j] 5] set fontweight [lindex [lindex $FontData $j] 6] set fontslant [lindex [lindex $FontData $j] 7] set fontwidth [lindex [lindex $FontData $j] 8] set tmpkey "$targetname - $fontfamily - $fontencoding" if { $tmpkey == $element_name } { # install the font,, data in $FontData ($j), # fontname == element_name progress_value .progress "processing $element_name" if { [file isdirectory $TargetFontDir] != 1} { set button_return \ [dialog .about {Warnning!} \ {The default target font directory does \ not exist, should I makdir for you ?} \ {} 0 Yes No] if { $button_return == 0 } { file mkdir $TargetFontDir } else { dialog .about {Error!} \ {No target directory, installation aborted!!}\ {} 0 Exit destroy . } } # copy into $TargetFontDir, overwrite the old one!! if { [file exists $TargetFontDir/$targetname ] != 1 } { file copy -force $fontfilename $TargetFontDir/$targetname } ## install the X font entry install_xfont $fontfilename $TargetFontDir $targetname \ $fontfoundry $fontfamily \ $fontweight $fontslant $fontwidth \ $fontproperties $fontencoding } } } destroy .progress dialog .about {Finish!!} \ {Finish.} info 0 Ok destroy . } proc install_xfont {fontfilename targetfontdir targetname \ fontfoundry fontfamily \ fontweight fontslant fontwidth \ fontproperties fontencoding } { global TempFile XTTFFontPath if { [file isdirectory $XTTFFontPath] != 1} { set button_return \ [dialog .about {Warnning!} \ {The default X TTF font directory does \ not exist, should I makdir for you ?} \ {} 0 Yes No] if { $button_return == 0 } { file mkdir $XTTFFontPath } else { dialog .about {Error!} \ {No X TTF directory, installation aborted!!}\ {} 0 Exit destroy . } } # make a link to $XTTFFontPath exec ln -sf $targetfontdir/$targetname $XTTFFontPath/$targetname # fonts.scale entry file delete -force $TempFile set tmpout [open $TempFile w] if { [file exists $XTTFFontPath/fonts.scale ] == 1 } { set tmpf [open $XTTFFontPath/fonts.scale r] # Drop the first line gets $tmpf tmpdata # copy while { [gets $tmpf tmpdata] >= 0} { set cmd "regexp \{$targetname.*$fontencoding\$\} \$tmpdata" if { [eval $cmd] == 0} { puts $tmpout $tmpdata } } close $tmpf } puts $tmpout "$targetname -$fontfoundry-$fontfamily-$fontweight-$fontslant-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" if {$fontweight == "medium" && $fontslant == "r"} { # normal font,, make i,bold,bold-i from it puts $tmpout "ab=y:$targetname -$fontfoundry-$fontfamily-bold-r-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" puts $tmpout "ai=0.3:$targetname -$fontfoundry-$fontfamily-medium-i-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" puts $tmpout "ab=y:ai=0.3:$targetname -$fontfoundry-$fontfamily-bold-i-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" } flush $tmpout close $tmpout # how many lines in the TempFile ?? set tmpf [open $TempFile r] set i 0 while { [gets $tmpf tmpdata] >= 0} { incr i } close $tmpf set tmpout [open $XTTFFontPath/fonts.scale w] set tmpf [open $TempFile r] puts $tmpout $i while { [gets $tmpf tmpdata] >= 0} { puts $tmpout $tmpdata } close $tmpf flush $tmpout close $tmpout # fonts.dir exec /usr/X11R6/bin/mkfontdir $XTTFFontPath/ # fonts.alias entry file delete -force $TempFile set tmpout [open $TempFile w] if { [file exists $XTTFFontPath/fonts.alias ] == 1 } { set tmpf [open $XTTFFontPath/fonts.alias r] # copy when not $targetname while { [gets $tmpf tmpdata] >= 0} { set cmd "regexp \{added by ttfinst.tk - $targetname $fontencoding\} \$tmpdata" if { [eval $cmd] == 0} { puts $tmpout $tmpdata } } # close the original fonts.alias file close $tmpf } foreach pix {14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 \ 44 46 48 52 56 60 64 68 72} { set pix0 [expr $pix*10] puts $tmpout "\"-alias$fontfoundry-$fontfamily-$fontweight-$fontslant-$fontwidth--$pix-$pix0-0-0-$fontproperties-$pix0-$fontencoding\" \"-$fontfoundry-$fontfamily-$fontweight-$fontslant-$fontwidth--$pix-$pix0-0-0-$fontproperties-$pix0-$fontencoding\" ! added by ttfinst.tk - $targetname $fontencoding" } # if normal font,, make i,bold,bold-i from it if {$fontweight == "medium" && $fontslant == "r"} { foreach pix {14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 \ 44 46 48 52 56 60 64 68 72} { set pix0 [expr $pix*10] puts $tmpout "\"-alias$fontfoundry-$fontfamily-bold-r-$fontwidth--$pix-$pix0-0-0-$fontproperties-$pix0-$fontencoding\" \"-$fontfoundry-$fontfamily-bold-r-$fontwidth--$pix-$pix0-0-0-$fontproperties-$pix0-$fontencoding\" ! added by ttfinst.tk - $targetname $fontencoding" } foreach pix {14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 \ 44 46 48 52 56 60 64 68 72} { set pix0 [expr $pix*10] puts $tmpout "\"-alias$fontfoundry-$fontfamily-medium-i-$fontwidth--$pix-$pix0-0-0-$fontproperties-$pix0-$fontencoding\" \"-$fontfoundry-$fontfamily-medium-i-$fontwidth--$pix-$pix0-0-0-$fontproperties-$pix0-$fontencoding\" ! added by ttfinst.tk - $targetname $fontencoding" } foreach pix {14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 \ 44 46 48 52 56 60 64 68 72} { set pix0 [expr $pix*10] puts $tmpout "\"-alias$fontfoundry-$fontfamily-bold-i-$fontwidth--$pix-$pix0-0-0-$fontproperties-$pix0-$fontencoding\" \"-$fontfoundry-$fontfamily-bold-i-$fontwidth--$pix-$pix0-0-0-$fontproperties-$pix0-$fontencoding\" ! added by ttfinst.tk - $targetname $fontencoding" } } flush $tmpout close $tmpout file copy -force $TempFile $XTTFFontPath/fonts.alias file delete -force $TempFile # xset fp rehash exec xset fp rehash } # some usful widget proc progress_create { win } { frame $win -class Progress canvas $win.display -borderwidth 0 -background white \ -highlightthickness 0 -width 300 -height 20 pack $win.display -expand yes $win.display create text 150 10 \ -anchor c -text "progress..." -tags value return $win } proc progress_value { win valtext } { $win.display itemconfigure value -text $valtext update } proc dialog {w title text bitmap default args} { global button_return toplevel $w -class Dialog wm title $w $title wm iconname $w Dialog frame $w.top -relief raised -bd 1 pack $w.top -side top -fill both frame $w.bot -relief raised -bd 1 pack $w.bot -side bottom -fill both message $w.top.msg -text $text pack $w.top.msg -side right -expand 1 -fill both \ -padx 3m -pady 3m if {$bitmap != ""} { label $w.top.bitmap -bitmap $bitmap pack $w.top.bitmap -side left -padx 3m -pady 3m } set i 0 foreach but $args { button $w.bot.button$i -text $but -command \ "set button_return $i" if {$i == $default} { frame $w.bot.default -relief sunken -bd 1 raise $w.bot.button$i pack $w.bot.default -side left -expand 1 -padx 3m -pady 3m pack $w.bot.button$i -in $w.bot.default -side left \ -padx 2m -pady 2m -ipadx 2m -ipady 1m } else { pack $w.bot.button$i -side left -expand 1 -padx 3m -pady 3m \ -ipadx 2m -ipady 1m } incr i } if {$default >=0 } { bind $w "$w.bot.button$default flash; set button $default" } set oldFocus [focus] # grab set $w focus $w tkwait variable button_return destroy $w focus $oldFocus return $button_return } # DirList from tix widgets proc ddlg:browse { name } { upvar $name varname global ddlg_select_dirname set ddlg_select_dirname $varname set rtnname 1 set dialog .dirdlg_popup if ![winfo exists $dialog] { tixDirSelectDialog $dialog } $dialog config -command "ddlg:select_dir" $dialog subwidget cancel config -command "ddlg:select_cancel $dialog" $dialog popup tkwait variable ddlg_select_dirname set varname $ddlg_select_dirname } proc ddlg:select_cancel {w} { global ddlg_select_dirname set ddlg_select_dirname $ddlg_select_dirname wm withdraw $w } proc ddlg:select_dir {dir} { global ddlg_select_dirname set ddlg_select_dirname $dir } ### ### main program ### #if {[exec id -un] != "root"} { # if {[tk_dialog .new "Wrong User" "You aren't the superuser. You must \ # be root to run this program." "" "0" "Ok"] == "0"} { # exit 0 # } #} # Thanks freetype :) frame .top message .top.msg -width 20c -text \ { This script is for users of X-TrueType font server who want to install and use truetype font under X, especially for CJK users. This script will: 1. Find all .ttf/.ttc files under a directory. 2. Let user select the fonts to be installed. 3. Copy the .ttf/.ttc file to a destination directory. 4. Update the fonts.scale and fonts.dir file in the FontPath. 5. Add entry in fonts.alias to activate it under netscape. Please feel free to use and distribute this script, and report any bug and suggestion to me. Thanks!! This script use ttfinfo to query the TTF information, and you should be able to find it together with this script. The ttfinfo provide the ttf ability of this script, and is modified from ttmkfdir which is a program wrote by Joerg Pommnitz to install ttf fonts for xfsft. Both ttfinfo and ttmkfdir are based on the FreeType library by David Turner, Robert Wilhelm and Werner Lemberg. Thanks to Joerg Pommnitz's ttmkfdir, and to David Turner, Robert Wilhelm and Werner Lemberg. Want more information ? See: X-TrueType Server Project: http://X-TT.dsl.gr.jp/ FreeType Project: http://www.freetype.org/ CLE Project: http://cle.linux.org.tw/CLE/ } pack .top.msg pack .top button .top.b -text Continue -command "destroy .top" pack .top.b -side top tkwait window .top wm title . "Setup FontFilePath" frame .top pack .top label .top.l2 -text "Please modify the arguments" pack .top.l2 frame .top.f1 pack .top.f1 label .top.f1.l3 -width 15 -text "Get fonts from:" entry .top.f1.entry3 -width 35 -relief sunken \ -textvariable DefaultSourceFontDir button .top.f1.btn -text "Browse ..." \ -command "ddlg:browse DefaultSourceFontDir" pack .top.f1.l3 .top.f1.entry3 .top.f1.btn -side left -padx 1m -pady 2m frame .top.f2 pack .top.f2 label .top.f2.l4 -width 15 -text "Install fonts to:" entry .top.f2.entry4 -width 35 -relief sunken -textvariable TargetFontDir button .top.f2.btn -text "Browse ..." \ -command "ddlg:browse TargetFontDir" pack .top.f2.l4 .top.f2.entry4 .top.f2.btn -side left -padx 1m -pady 2m frame .top.f3 pack .top.f3 label .top.f3.l5 -width 15 -text "X FontPath:" entry .top.f3.entry5 -width 35 -relief sunken -textvariable XTTFFontPath button .top.f3.btn -text "Browse ..." \ -command "ddlg:browse XTTFFontPath" pack .top.f3.l5 .top.f3.entry5 .top.f3.btn -side left -padx 1m -pady 2m button .top.b -text Continue -command "destroy .top" button .top.c -text Quit -command "exit" pack .top.b -side left pack .top.c -side right tkwait window .top # show the logo wm title . "Welcome to the ttfinst.tk" frame .top if { [file exists $logofile ] } { image create photo image1 -file $logofile label .top.l1 -image image1 -bd 1 -relief sunken pack .top.l1 -side top -padx .5m -pady .5m -fill x } else { message .top.msg -width 20c -text \ { Welcome to ttfinst!! o Click on the entry to select the fonts which you want to install. o Double click on the entry to preview the truetype font. o When previewing, press '(', ')' to move, 'q' to go back. o Press the 'Install' button to start installing the selected fonts. o Press the 'Cancel' button to abort. } pack .top.msg } pack .top # Get all font file and scan the font data set DefaultFontFileNameFile "|find $DefaultSourceFontDir -name \"*.\[tT\]\[tT\]\[cCfF\]\"" set f_fontfilename [open $DefaultFontFileNameFile r] set FontFileData {} while { [gets $f_fontfilename fontfilename] >= 0 } { if { [file executable $TTFINFOPATH] == 1 } { set tmpf [open "|$TTFINFOPATH -c $fontfilename" r] } elseif { [file executable ./ttfinfo] == 1 } { set tmpf [open "|./ttfinfo -c $fontfilename" r] } else { # try if I can find ttfinfo in the $PATH set tmpf [open "|ttfinfo -c $fontfilename" r] } # get the font name table entries while { [gets $tmpf tmpdata] >= 0 } { set varpair [split $tmpdata "="] set varpairvar [lindex $varpair 0] set varpairvaule [lindex $varpair end] # merge into environment variables set env($varpairvar) $varpairvaule eval "set $varpairvar $varpairvaule" } set targetname [string tolower [ lindex [ split $fontfilename "/" ] end ] ] close $tmpf # font encoding for {set i 1} { $i <= $TTFINFO_MAPNUM } {incr i} { eval "set evalstring \$TTFINFO_FONTMAP$i " eval "set fontslant [ lindex [ split $evalstring - ] 4 ]" eval "set fontproperties [ lindex [ split $evalstring - ] 11 ]" eval "set fontencoding [ join [ lrange [ split $evalstring - ] 13 end ] - ] " lappend FontFileData [list $fontfilename $targetname \ $TTFINFO_FOUNDRY_NAME $TTFINFO_FONT_NAME\ $fontencoding $fontproperties \ $TTFINFO_WEIGHT_NAME $fontslant \ $TTFINFO_WIDTH] } } close $f_fontfilename button .top.b -text Continue -command "destroy .top" pack .top.b -side top tkwait window .top # install GUI wm title . "True-Type Font installer, v$version" frame .top -relief raised -borderwidth 2 pack .top -side top -padx 1 -pady 1 -fill x menubutton .top.helpbutton -text Help -underline 0 -menu \ .top.helpbutton.filemenu menu .top.helpbutton.filemenu .top.helpbutton.filemenu add command -label "About" -command {about_this} .top.helpbutton.filemenu add command -label "Copyright" -command {copyright_info} .top.helpbutton.filemenu add separator .top.helpbutton.filemenu add command -label "Usage" -command {show_usage} .top.helpbutton.filemenu add command -label "Preview mode" -command {show_previewusage} pack .top.helpbutton -side right focus .top.helpbutton.filemenu frame .center -relief raised -borderwidth 2 pack .center -side top -padx 1 -pady 1 -fill x label .center.label -text "Available Font:" -justify center pack .center.label -in .center -side top -fill x listbox .center.fontfiles -width 40 -selectmode multiple -relief groove -borderwidth 2 \ -yscrollcommand ".center.scroll set" pack .center.fontfiles -in .center -side left scrollbar .center.scroll -command ".center.fontfiles yview" pack .center.scroll -in .center -side right -fill y for {set i 0} { $i < [llength $FontFileData] } {incr i} { set targetname [lindex [lindex $FontFileData $i] 1] set fontfamily [lindex [lindex $FontFileData $i] 3] set fontencoding [lindex [lindex $FontFileData $i] 4] .center.fontfiles insert end "$targetname - $fontfamily - $fontencoding" } bind .center.fontfiles { set selected_entry [.center.fontfiles get active] for {set i 0} { $i < [llength $FontFileData] } {incr i} { set targetname [lindex [lindex $FontFileData $i] 1] set fontfamily [lindex [lindex $FontFileData $i] 3] set fontencoding [lindex [lindex $FontFileData $i] 4] set tmpkey "$targetname - $fontfamily - $fontencoding" if { $tmpkey == $selected_entry } { exec ftview 18 [lindex [lindex $FontFileData $i] 0] break } } } frame .down -relief raised -borderwidth 2 pack .down -side top -padx 1 -pady 1 -fill x button .down.install -text Install button .down.cancel -text Cancel -command exit pack .down.install -side left pack .down.cancel -side right bind .down.install { do_install .center.fontfiles $FontFileData } # ChangeLog # # $Log: ttfinst.tk,v $ # Revision 1.1.1.1 2000/12/16 18:56:41 keith # Import of TTFM 0.9.2 # # Revision 1.2 2000/02/10 11:40:14 platin # Log entry was added. # # # * Fri Oct 29 1999 Yuan-Chung Cheng # - some suggestion from Werner LEMBERG # # * Wed Sep 29 1999 Yuan-Chung Cheng # - use ttfinfo instead of ftdump # - code clean up,,drop unnessary exec # - use tixwish instead of wish # - Dir selector from tix # - very many bug fixed # - version 0.7 # # * Thu Jul 15 1999 Yuan-Chung Cheng # - peter 's patch for fontdir selection # - ttc/ttf # # * Wed Jun 30 1999 Yuan-Chung Cheng # - drop "grep -v" !! # # * Tue Jun 29 1999 Yuan-Chung Cheng # - support for .ttc font # - better fontname entry information exaction. #