• pdf4tcl fork and unicode

    From rene@user4652@newsgrouper.org.invalid to comp.lang.tcl on Tue Aug 25 13:41:19 2026
    From Newsgroup: comp.lang.tcl


    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
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From greg@gregor.ebbing@gmx.de to comp.lang.tcl on Tue Aug 25 17:08:32 2026
    From Newsgroup: comp.lang.tcl

    Am 25.08.26 um 15:41 schrieb rene:

    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

    Hi Rene,

    pdf4tcl does understand Unicode now, via createFontSpecCID:


    pdf4tcl::loadBaseTrueTypeFont Base "tahoma.ttf"
    pdf4tcl::createFontSpecCID Base Tahoma
    $pdf setFont 14 Tahoma
    $pdf text "\u0394 \u03A6 \u03BC \u03B8 \u2211 \u221E \u03C6"

    No encoding list, no 256-element limit, and the text extracts as the
    right characters rCo which the workaround cannot do, since it declares the bytes as Latin-1.

    But your hack is still the shorter file. pdf4tcl has no subsetting on
    the CID path: createFontSpecEnc embeds a subset, createFontSpecCID
    embeds the whole font.
    Subsetting is on the (rather long) virtual TODO list.


    See:
    demo/demo-unicode-tabelle.tcl
    doc/en/howtos/howto-unicode.md and .tcl doc/en/reference/pdf4tcl-fonts-and-unicode.md doc/en/reference/pdf4tcl-cidfont-manual.md

    If you do embed Tahoma: it is a Microsoft system font and embedding is
    not always permitted by its licence.

    I hope it's okay if I point you to the reference and how-tos for now.


    best regards
    Gregor




    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From rene@user4652@newsgrouper.org.invalid to comp.lang.tcl on Wed Aug 26 08:34:22 2026
    From Newsgroup: comp.lang.tcl


    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

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From greg@gregor.ebbing@gmx.de to comp.lang.tcl on Wed Aug 26 21:37:04 2026
    From Newsgroup: comp.lang.tcl

    Am 26.08.26 um 18:37 schrieb greg:
    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.



    Hi
    I have narrowed it down and it is not pdf4tcl.
    package require Tk plus package require tko and after 400 {destroy .}
    under wish8.6 is enough.
    Not with tclsh, and not with a script ending in exit: both end without a
    full interpreter teardown, so the faulty release never runs.
    That one caught me out for a while.

    Ticket f44b0a49ff has the details and a one-liner.

    Gregor
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From rene@user4652@newsgrouper.org.invalid to comp.lang.tcl on Thu Aug 27 06:31:11 2026
    From Newsgroup: comp.lang.tcl


    greg <gregor.ebbing@gmx.de> posted:

    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.

    Hello Gregor

    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
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From greg@gregor.ebbing@gmx.de to comp.lang.tcl on Fri Aug 28 15:43:26 2026
    From Newsgroup: comp.lang.tcl

    Am 27.08.26 um 11:39 schrieb rene:

    greg <gregor.ebbing@gmx.de> posted:

    Am 27.08.26 um 08:31 schrieb rene:

    greg <gregor.ebbing@gmx.de> posted:

    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. >>>>
    Hello Gregor

    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
    Hello 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

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From rene@user4652@newsgrouper.org.invalid to comp.lang.tcl on Tue Sep 1 14:03:32 2026
    From Newsgroup: comp.lang.tcl


    greg <gregor.ebbing@gmx.de> posted:

    Am 27.08.26 um 11:39 schrieb rene:

    greg <gregor.ebbing@gmx.de> posted:

    Am 27.08.26 um 08:31 schrieb rene:

    greg <gregor.ebbing@gmx.de> posted:

    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. >>>>
    Hello Gregor

    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
    Hello 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

    Hi Gregor

    I'm now using version 0.9.4.62. Everything is working!

    Thank you very much
    Rene
    --- Synchronet 3.22a-Linux NewsLink 1.2