Posted to tcl by chw at Fri Aug 05 21:03:22 GMT 2016view pretty
package require tkpath package require pdf4tcl set textnl \ "\U1F601\U1F602\U1F603\n\U1F604\U1F605\U1F606\n\U1F607\U1F608\U1F609" set text "\U1F601\U1F602\U1F603\U1F604\U1F605\U1F606\U1F607\U1F608\U1F609" # Make font set list proc mkset {text} { set result {} foreach i [split $text {}] { set t 0 scan $i %c t lappend result $t } return $result } # Symbola font for Emojis # undroidwish has it built in, otherwise hopefully somewhere else ... set symttf [file join $tk_library fonts Symbola.ttf] if {![file readable $symttf]} { set symttf [file join ~ .fonts Symbola.ttf] if {![file readable $symttf]} { set symttf Symbola.ttf } } pdf4tcl::loadBaseTrueTypeFont BaseSymbola $symttf pdf4tcl::createFontSpecEnc BaseSymbola Symbola [mkset $text] set w .c pack [tkp::canvas $w -width 400 -height 400 -bg white] $w create prect 10 10 390 390 -fill {} -stroke blue -strokewidth 2 $w create ptext 200 200 -fontfamily Symbola -fontsize 60 \ -fill red2 -stroke black -strokewidth 1 -textanchor c \ -text $textnl pdf4tcl::new mypdf -paper a4 mypdf startPage mypdf canvas $w -fontmap {Symbola Symbola} # rendered directly for comparison mypdf setFont 30 Symbola mypdf text $text -x 50 -y 100 mypdf setFont 30 Helvetica mypdf text "Hello World!" -x 350 -y 100 mypdf write -file out.pdf mypdf destroy