• Text tag woes

    From Helmut Giese@21:1/5 to All on Mon Aug 22 22:58:45 2022
    Hello out there,
    I have big problems with the text widget's tags. Look at this example
    ----
    package require Tk
    foreach ch [winfo children .] {destroy $ch}
    catch {font delete h1Font}

    set t [text .txt -height 10]
    pack $t

    font create h1Font -family {"Times New Roman" Times serif} -size 20 \
    -weight bold -slant roman -underline 0 -overstrike 0

    $t insert end "01234567890123456789\n"
    $t insert end "An example H1 header\n" h1Font
    ----
    The output tells me (at least on my machine)
    - it is still a fixed font
    - the size seems to be the original and is certainly not 20 points
    - and it is not bold either.

    I had this almost working: The output was bold, the size was big and
    reacted on manually re-configuring the tag - but then I noticed that
    the font was not 'Times' (it was a non-serif font like Arial or
    Helvetica - nowhere did I configure this).
    So it looks almost as if the text widget has a will of its own: It
    used to follow me a bit but today it decided to ignore me completely.

    Any advice with which voodoo the text widget can be convinced will be
    greatly appreciated.
    Oh, this is on Windows 10 (64 bit) and Tcl8.6.10.
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Helmut Giese on Mon Aug 22 21:07:30 2022
    Helmut Giese <hgiese@ratiosoft.com> wrote:
    Hello out there,
    I have big problems with the text widget's tags. Look at this example
    [snip ... see prior article]
    $t insert end "An example H1 header\n" h1Font
    Any advice with which voodoo the text widget can be convinced will be
    greatly appreciated.

    The text widget "insert" command takes pairs of "characters" and "text
    tags".

    You have a font named h1Font.

    You separately have conjured a text tag name "h1Font" into life in the
    insert command.

    But you've never linked the text's tag named "h1Font" to the separate
    font named "h1Font".

    Make this change (see the + line below):

    font create h1Font -family {"Times New Roman" Times serif} -size 20 \
    -weight bold -slant roman -underline 0 -overstrike 0

    + $t tag configure h1Font -font h1Font

    $t insert end "01234567890123456789\n"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Tue Aug 23 09:14:13 2022
    * Rich <rich@example.invalid>
    | + $t tag configure h1Font -font h1Font

    | $t insert end "01234567890123456789\n"

    I think that last line should be

    $t insert end "01234567890123456789\n" h1font

    in order to have the tag text font take effect?

    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Tue Aug 23 09:23:38 2022
    * Helmut Giese <hgiese@ratiosoft.com>
    | I have big problems with the text widget's tags.

    Rich has already answered the text tag issue, I'd like to point out a
    different issue:

    | font create h1Font -family {"Times New Roman" Times serif} ...

    On Linux, tk 8.6.12 this creates a Helvetica style font.

    Only if I use

    font create h1Font -family "Times" ...

    I get a 'Times' font. Note that the font(n) manpage says:

    -family name
    [...]
    Tk guarantees to support the font families named Courier
    (a monospaced “typewriter” font), Times (a serifed
    “newspaper” font), and Helvetica (a sans-serif “European”
    font).
    [...]
    The name may also be the name of a native,
    platform-specific font family; in that case it will work
    as desired on one platform but may not display correctly
    on other platforms.

    So for better platform interoperability, just use 'Times', not some Windows-centric form of the font name.

    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Tue Aug 23 16:31:07 2022
    Hello Rich and Ralf,
    many thanks to both of you.
    2Rich: To not configure the tag with the font was a blunder I only had
    in the code snippet I posted not in my real application.
    2Ralf: Your tip to only use 'Times' when specifying the font was spot
    on: I now have a bold font in 'Times' of the correct size.
    Thanks again
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)