Hello
I use pdf4tcl 0.9.4 and have the following workaround to print some unicode symbols:
# Pdf4tcl doesn't understand unicode. We have to create our own font here.
# Only 256 elements per font are available.
# So we overwrite not used elements with our used mathematical symbols.
# {delta phi micro theta sum infinity phi 7 .. 255}
::pdf4tcl::createFontSpecEnc Tahoma Tahoma869 [list\
[expr {0x394}] [expr {0x3A6}] [expr {0x3BC}] [expr {0x3B8}]\
[expr {0x2211}] [expr {0x221E}] [expr {0x3C6}] {*}[lseq 7 to 255]]
Can I get rid of these hack with the newer version 0.9.4.55?
Thank you
rene
Am 26.08.26 um 10:34 schrieb rene:
Hello Gregor
- The good new, using pdf4tcl09455 with my old code works.
- Simple tests with my \u values work.
- Then I used the following changes:
-a-a # create the font
-a-a ::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join
$::kkg(libdir) fonts tahoma.ttf]
-a-a ::pdf4tcl::createFontSpecCID TahomaBase Tahoma869
-a-a # create pdf of tko::path
-a-a $pdf canvas-a ... -fontmap {Tahoma Tahoma869}
And it gives these error:
can't read "FontsAttrs(Tahoma869,specialencoding)": no such element in
array
-a-a-a-a while executing
"if {$FontsAttrs($fn,specialencoding)} {
-a-a-a-a-a-a-a-a # Convert using special encoding of font subset:
-a-a-a-a-a-a-a-a set out ""
-a-a-a-a-a-a-a-a set encDict $FontsAttrs($f..."
-a-a-a-a (procedure "CleanText" line 4)
-a-a-a-a invoked from within
"CleanText $line $font"
-a-a-a-a (class "::pdf4tcl::pdf4tcl" method "getTkpptext" line 2)
-a-a-a-a invoked from within
"::oo::Obj225::my getTkpptext Tahoma869 LE05"
-a-a-a-a invoked from within
"$path itempdf $id-a [list $myCb addTkpextgs]-a [list $myCb getTkpptext
$pdf(current_font)]-a $pdf(current_font)"
-a-a-a-a (class "::pdf4tcl::pdf4tcl" method "CanvasDoTkoPathItem" line 10) >> -a-a-a-a invoked from within
"my CanvasDoTkoPathItem $path $id opts"
-a-a-a-a (class "::pdf4tcl::pdf4tcl" method "canvas" line 162)
-a-a-a-a invoked from within
"$pdf canvas $canvas -bbox-a-a [lindex $bboxlist 0] -x-a-a-a-a-a [lindex
$coords 0] -y-a-a-a-a-a [lindex $coords 1] -fontmap-a-a-a $fontmap"
-a-a-a-a (procedure "::kkg::lib::_pdf_canvasPage" line 19)
- Then I tried:
-a-a # create the font
-a-a ::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join
$::kkg(libdir) fonts tahoma.ttf]
-a-a ::pdf4tcl::createFontSpecCID TahomaBase Tahoma
-a-a # create pdf of tko::path without -fontmap
-a-a $pdf canvas-a ...
And it displays in the created pdf a "?" sign for the \u characters.
Any Ideas how to fix it?
Thank you
rene
Hi Rene,
The specialencoding abort came from pdf4tcl -- getTkpptext called the 8-
bit path unconditionally. Fixed in 0.9.4.59, so createFontSpecCID and
the canvas route now work together; they never did before.
The alloc: invalid block could come from either side (1.). I have no
idea what would cause it in pdf4tcl at the moment. What I can say is
that it appears on interpreter teardown. tkpath 0.4.2 does not show it.
1.)
package require Tk
package require tko
package require pdf4tcl
pdf4tcl::loadBaseTrueTypeFont Base "C:/Windows/Fonts/tahoma.ttf"
pdf4tcl::createFontSpecCID Base UniFont
tko::path .p -width 460 -height 160 -background white
pack .p
.p create text 20 40 -fontfamily Helvetica -fontsize 15 -fill black \
-a-a-a-a-a-a-a -text "Greek: \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
.p create text 20 80 -fontfamily Helvetica -fontsize 15 -fill black \
-a-a-a-a-a-a-a -text "Maths: \u0394 \u2211 \u221e \u03c6"
update
set pdf [pdf4tcl::new %AUTO% -paper a4 -margin 40]
$pdf startPage
$pdf canvas .p -bbox [.p bbox all] -x 0 -y 0 -width 460 -height 160 \
-a-a-a-a-a-a-a -fontmap {Helvetica UniFont}
puts "getSubstCount: [$pdf getSubstCount]"
$pdf endPage
$pdf write -file out1.pdf
$pdf destroy
2.)
package require Tk
package require tkpath
package require pdf4tcl
pdf4tcl::loadBaseTrueTypeFont Base "C:/Windows/Fonts/tahoma.ttf"
pdf4tcl::createFontSpecCID Base UniFont
tkp::canvas .p -width 460 -height 160 -bg white
pack .p
.p create ptext 20 40 -fontfamily Helvetica -fontsize 15 -fill black \
-a-a-a-a-a-a-a -text "Greek: \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
.p create ptext 20 80 -fontfamily Helvetica -fontsize 15 -fill black \
-a-a-a-a-a-a-a -text "Maths: \u0394 \u2211 \u221e \u03c6"
update
set pdf [pdf4tcl::new %AUTO% -paper a4 -margin 40]
$pdf startPage
$pdf canvas .p -bbox [.p bbox all] -x 0 -y 0 -width 460 -height 160 \
-a-a-a-a-a-a-a -fontmap {Helvetica UniFont}
puts "getSubstCount: [$pdf getSubstCount]"
$pdf endPage
$pdf write -file out2.pdf
$pdf destroy
best regards
Gregor
ps: since 0.9.4.57 a CID font embeds only the glyphs the document draws.
Am 26.08.26 um 10:34 schrieb rene:
Hello Gregor
- The good new, using pdf4tcl09455 with my old code works.
- Simple tests with my \u values work.
- Then I used the following changes:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma869
# create pdf of tko::path
$pdf canvas ... -fontmap {Tahoma Tahoma869}
And it gives these error:
can't read "FontsAttrs(Tahoma869,specialencoding)": no such element in array
while executing
"if {$FontsAttrs($fn,specialencoding)} {
# Convert using special encoding of font subset:
set out ""
set encDict $FontsAttrs($f..."
(procedure "CleanText" line 4)
invoked from within
"CleanText $line $font"
(class "::pdf4tcl::pdf4tcl" method "getTkpptext" line 2)
invoked from within
"::oo::Obj225::my getTkpptext Tahoma869 LE05"
invoked from within
"$path itempdf $id [list $myCb addTkpextgs] [list $myCb getTkpptext $pdf(current_font)] $pdf(current_font)"
(class "::pdf4tcl::pdf4tcl" method "CanvasDoTkoPathItem" line 10)
invoked from within
"my CanvasDoTkoPathItem $path $id opts"
(class "::pdf4tcl::pdf4tcl" method "canvas" line 162)
invoked from within
"$pdf canvas $canvas -bbox [lindex $bboxlist 0] -x [lindex $coords 0] -y [lindex $coords 1] -fontmap $fontmap"
(procedure "::kkg::lib::_pdf_canvasPage" line 19)
- Then I tried:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma
# create pdf of tko::path without -fontmap
$pdf canvas ...
And it displays in the created pdf a "?" sign for the \u characters.
Any Ideas how to fix it?
Thank you
rene
Hi Rene,
The specialencoding abort came from pdf4tcl -- getTkpptext called the
8-bit path unconditionally. Fixed in 0.9.4.59, so createFontSpecCID and
the canvas route now work together; they never did before.
The alloc: invalid block could come from either side (1.). I have no
idea what would cause it in pdf4tcl at the moment. What I can say is
that it appears on interpreter teardown. tkpath 0.4.2 does not show it.
1.)
package require Tk
package require tko
package require pdf4tcl
pdf4tcl::loadBaseTrueTypeFont Base "C:/Windows/Fonts/tahoma.ttf"
pdf4tcl::createFontSpecCID Base UniFont
tko::path .p -width 460 -height 160 -background white
pack .p
.p create text 20 40 -fontfamily Helvetica -fontsize 15 -fill black \
-text "Greek: \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
.p create text 20 80 -fontfamily Helvetica -fontsize 15 -fill black \
-text "Maths: \u0394 \u2211 \u221e \u03c6"
update
set pdf [pdf4tcl::new %AUTO% -paper a4 -margin 40]
$pdf startPage
$pdf canvas .p -bbox [.p bbox all] -x 0 -y 0 -width 460 -height 160 \
-fontmap {Helvetica UniFont}
puts "getSubstCount: [$pdf getSubstCount]"
$pdf endPage
$pdf write -file out1.pdf
$pdf destroy
2.)
package require Tk
package require tkpath
package require pdf4tcl
pdf4tcl::loadBaseTrueTypeFont Base "C:/Windows/Fonts/tahoma.ttf"
pdf4tcl::createFontSpecCID Base UniFont
tkp::canvas .p -width 460 -height 160 -bg white
pack .p
.p create ptext 20 40 -fontfamily Helvetica -fontsize 15 -fill black \
-text "Greek: \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
.p create ptext 20 80 -fontfamily Helvetica -fontsize 15 -fill black \
-text "Maths: \u0394 \u2211 \u221e \u03c6"
update
set pdf [pdf4tcl::new %AUTO% -paper a4 -margin 40]
$pdf startPage
$pdf canvas .p -bbox [.p bbox all] -x 0 -y 0 -width 460 -height 160 \
-fontmap {Helvetica UniFont}
puts "getSubstCount: [$pdf getSubstCount]"
$pdf endPage
$pdf write -file out2.pdf
$pdf destroy
best regards
Gregor
ps: since 0.9.4.57 a CID font embeds only the glyphs the document draws.
greg <gregor.ebbing@gmx.de> posted:
Am 27.08.26 um 08:31 schrieb rene:Hello Gregor
greg <gregor.ebbing@gmx.de> posted:
Am 26.08.26 um 10:34 schrieb rene:Hello Gregor
Hello Gregor
- The good new, using pdf4tcl09455 with my old code works.
- Simple tests with my \u values work.
- Then I used the following changes:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma869
# create pdf of tko::path
$pdf canvas ... -fontmap {Tahoma Tahoma869}
And it gives these error:
can't read "FontsAttrs(Tahoma869,specialencoding)": no such element in array
while executing
"if {$FontsAttrs($fn,specialencoding)} {
# Convert using special encoding of font subset:
set out ""
set encDict $FontsAttrs($f..."
(procedure "CleanText" line 4)
invoked from within
"CleanText $line $font"
(class "::pdf4tcl::pdf4tcl" method "getTkpptext" line 2)
invoked from within
"::oo::Obj225::my getTkpptext Tahoma869 LE05"
invoked from within
"$path itempdf $id [list $myCb addTkpextgs] [list $myCb getTkpptext $pdf(current_font)] $pdf(current_font)"
(class "::pdf4tcl::pdf4tcl" method "CanvasDoTkoPathItem" line 10) >>>>> invoked from within
"my CanvasDoTkoPathItem $path $id opts"
(class "::pdf4tcl::pdf4tcl" method "canvas" line 162)
invoked from within
"$pdf canvas $canvas -bbox [lindex $bboxlist 0] -x [lindex $coords 0] -y [lindex $coords 1] -fontmap $fontmap"
(procedure "::kkg::lib::_pdf_canvasPage" line 19)
- Then I tried:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma
# create pdf of tko::path without -fontmap
$pdf canvas ...
And it displays in the created pdf a "?" sign for the \u characters. >>>>>
Any Ideas how to fix it?
Thank you
rene
Hi Rene,
The specialencoding abort came from pdf4tcl -- getTkpptext called the
8-bit path unconditionally. Fixed in 0.9.4.59, so createFontSpecCID and >>>> the canvas route now work together; they never did before.
The alloc: invalid block could come from either side (1.). I have no
idea what would cause it in pdf4tcl at the moment. What I can say is
that it appears on interpreter teardown. tkpath 0.4.2 does not show it. >>>>
1.)
package require Tk
package require tko
package require pdf4tcl
pdf4tcl::loadBaseTrueTypeFont Base "C:/Windows/Fonts/tahoma.ttf"
pdf4tcl::createFontSpecCID Base UniFont
tko::path .p -width 460 -height 160 -background white
pack .p
.p create text 20 40 -fontfamily Helvetica -fontsize 15 -fill black \
-text "Greek: \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
.p create text 20 80 -fontfamily Helvetica -fontsize 15 -fill black \
-text "Maths: \u0394 \u2211 \u221e \u03c6"
update
set pdf [pdf4tcl::new %AUTO% -paper a4 -margin 40]
$pdf startPage
$pdf canvas .p -bbox [.p bbox all] -x 0 -y 0 -width 460 -height 160 \
-fontmap {Helvetica UniFont}
puts "getSubstCount: [$pdf getSubstCount]"
$pdf endPage
$pdf write -file out1.pdf
$pdf destroy
2.)
package require Tk
package require tkpath
package require pdf4tcl
pdf4tcl::loadBaseTrueTypeFont Base "C:/Windows/Fonts/tahoma.ttf"
pdf4tcl::createFontSpecCID Base UniFont
tkp::canvas .p -width 460 -height 160 -bg white
pack .p
.p create ptext 20 40 -fontfamily Helvetica -fontsize 15 -fill black \ >>>>
-text "Greek: \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
.p create ptext 20 80 -fontfamily Helvetica -fontsize 15 -fill black \ >>>>
-text "Maths: \u0394 \u2211 \u221e \u03c6"
update
set pdf [pdf4tcl::new %AUTO% -paper a4 -margin 40]
$pdf startPage
$pdf canvas .p -bbox [.p bbox all] -x 0 -y 0 -width 460 -height 160 \
-fontmap {Helvetica UniFont}
puts "getSubstCount: [$pdf getSubstCount]"
$pdf endPage
$pdf write -file out2.pdf
$pdf destroy
best regards
Gregor
ps: since 0.9.4.57 a CID font embeds only the glyphs the document draws. >>>>
Thank you for the reply. Using 0.9.4.59 things look better.
Just one question:
The following code works as expected:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma869
# create pdf of tko::path
$pdf canvas ... -fontmap {Tahoma Tahoma869}
But this gives still the "?" sign:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma
# create pdf of tko::path without -fontmap
$pdf canvas ...
Is there a way to get rid of the -fontmap?
Regards and thank you
rene
Hello Rene,
No, -fontmap is still required. Without it, the export process guesses
from among the 14 standard fonts, and anything unrecognized defaults to
HelveticarCowhich lacks the characters, hence the "?". The fact that a PDF >> font might happen to share the same name as the Tk family is not taken
into account.
Changing this behavior would make sense and is feasible.
It will be implemented in the coming days.
best regards
Gregor
Thank you for the quick response. Keep me posted if you change it.
Best regards
rene
Am 27.08.26 um 11:39 schrieb rene:
greg <gregor.ebbing@gmx.de> posted:
Am 27.08.26 um 08:31 schrieb rene:Hello Gregor
greg <gregor.ebbing@gmx.de> posted:
Am 26.08.26 um 10:34 schrieb rene:Hello Gregor
Hello Gregor
- The good new, using pdf4tcl09455 with my old code works.
- Simple tests with my \u values work.
- Then I used the following changes:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma869
# create pdf of tko::path
$pdf canvas ... -fontmap {Tahoma Tahoma869}
And it gives these error:
can't read "FontsAttrs(Tahoma869,specialencoding)": no such element in array
while executing
"if {$FontsAttrs($fn,specialencoding)} {
# Convert using special encoding of font subset:
set out ""
set encDict $FontsAttrs($f..."
(procedure "CleanText" line 4)
invoked from within
"CleanText $line $font"
(class "::pdf4tcl::pdf4tcl" method "getTkpptext" line 2)
invoked from within
"::oo::Obj225::my getTkpptext Tahoma869 LE05"
invoked from within
"$path itempdf $id [list $myCb addTkpextgs] [list $myCb getTkpptext $pdf(current_font)] $pdf(current_font)"
(class "::pdf4tcl::pdf4tcl" method "CanvasDoTkoPathItem" line 10)
invoked from within
"my CanvasDoTkoPathItem $path $id opts"
(class "::pdf4tcl::pdf4tcl" method "canvas" line 162)
invoked from within
"$pdf canvas $canvas -bbox [lindex $bboxlist 0] -x [lindex $coords 0] -y [lindex $coords 1] -fontmap $fontmap"
(procedure "::kkg::lib::_pdf_canvasPage" line 19)
- Then I tried:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma
# create pdf of tko::path without -fontmap
$pdf canvas ...
And it displays in the created pdf a "?" sign for the \u characters. >>>>>
Any Ideas how to fix it?
Thank you
rene
Hi Rene,
The specialencoding abort came from pdf4tcl -- getTkpptext called the >>>> 8-bit path unconditionally. Fixed in 0.9.4.59, so createFontSpecCID and >>>> the canvas route now work together; they never did before.
The alloc: invalid block could come from either side (1.). I have no >>>> idea what would cause it in pdf4tcl at the moment. What I can say is >>>> that it appears on interpreter teardown. tkpath 0.4.2 does not show it. >>>>
1.)
package require Tk
package require tko
package require pdf4tcl
pdf4tcl::loadBaseTrueTypeFont Base "C:/Windows/Fonts/tahoma.ttf"
pdf4tcl::createFontSpecCID Base UniFont
tko::path .p -width 460 -height 160 -background white
pack .p
.p create text 20 40 -fontfamily Helvetica -fontsize 15 -fill black \ >>>>
-text "Greek: \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
.p create text 20 80 -fontfamily Helvetica -fontsize 15 -fill black \ >>>>
-text "Maths: \u0394 \u2211 \u221e \u03c6"
update
set pdf [pdf4tcl::new %AUTO% -paper a4 -margin 40]
$pdf startPage
$pdf canvas .p -bbox [.p bbox all] -x 0 -y 0 -width 460 -height 160 \ >>>>
-fontmap {Helvetica UniFont}
puts "getSubstCount: [$pdf getSubstCount]"
$pdf endPage
$pdf write -file out1.pdf
$pdf destroy
2.)
package require Tk
package require tkpath
package require pdf4tcl
pdf4tcl::loadBaseTrueTypeFont Base "C:/Windows/Fonts/tahoma.ttf"
pdf4tcl::createFontSpecCID Base UniFont
tkp::canvas .p -width 460 -height 160 -bg white
pack .p
.p create ptext 20 40 -fontfamily Helvetica -fontsize 15 -fill black \ >>>>
-text "Greek: \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
.p create ptext 20 80 -fontfamily Helvetica -fontsize 15 -fill black \ >>>>
-text "Maths: \u0394 \u2211 \u221e \u03c6"
update
set pdf [pdf4tcl::new %AUTO% -paper a4 -margin 40]
$pdf startPage
$pdf canvas .p -bbox [.p bbox all] -x 0 -y 0 -width 460 -height 160 \ >>>>
-fontmap {Helvetica UniFont}
puts "getSubstCount: [$pdf getSubstCount]"
$pdf endPage
$pdf write -file out2.pdf
$pdf destroy
best regards
Gregor
ps: since 0.9.4.57 a CID font embeds only the glyphs the document draws. >>>>
Thank you for the reply. Using 0.9.4.59 things look better.
Just one question:
The following code works as expected:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma869
# create pdf of tko::path
$pdf canvas ... -fontmap {Tahoma Tahoma869}
But this gives still the "?" sign:
# create the font
::pdf4tcl::loadBaseTrueTypeFont TahomaBase [file join $::kkg(libdir) fonts tahoma.ttf]
::pdf4tcl::createFontSpecCID TahomaBase Tahoma
# create pdf of tko::path without -fontmap
$pdf canvas ...
Is there a way to get rid of the -fontmap?
Regards and thank you
rene
Hello Rene,
No, -fontmap is still required. Without it, the export process guesses
from among the 14 standard fonts, and anything unrecognized defaults to
HelveticarCowhich lacks the characters, hence the "?". The fact that a PDF >> font might happen to share the same name as the Tk family is not taken
into account.
Changing this behavior would make sense and is feasible.
It will be implemented in the coming days.
best regards
Gregor
Thank you for the quick response. Keep me posted if you change it.
Best regards
rene
Hi,
Done in 0.9.4.60. Your second example now works as you wrote it:
::pdf4tcl::createFontSpecCID TahomaBase Tahoma ;# = the Tk family
$pdf canvas .p ... ;# no -fontmap
package require Tk
package require tko
package require pdf4tcl
foreach f {
C:/Windows/Fonts/tahoma.ttf
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
} {
if {[file readable $f]} { set ttf $f ; break }
}
pdf4tcl::loadBaseTrueTypeFont Base $ttf
pdf4tcl::createFontSpecCID Base Tahoma ;# named like the Tk family
tko::path .p -width 460 -height 160 -background white
pack .p
.p create text 20 40 -fontfamily Tahoma -fontsize 15 -fill black \
-text "Greek: \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
.p create text 20 80 -fontfamily Tahoma -fontsize 15 -fill black \
-text "Maths: \u0394 \u2211 \u221e \u03c6"
update
set pdf [pdf4tcl::new %AUTO% -paper a4 -margin 40]
$pdf startPage
$pdf canvas .p -bbox [.p bbox all] -x 0 -y 0 -width 460 -height 160
puts "getSubstCount: [$pdf getSubstCount]" ;# 0 = every character had
a glyph
$pdf endPage
$pdf write -file out.pdf
$pdf destroy
exit 0
Gregor
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 74 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 121:11:54 |
| Calls: | 1,194 |
| Files: | 1,352 |
| Messages: | 290,208 |