Hello out there,
wanting to display text in a text widget which is partly italic and /
or bold I am wondering if there is a light weight conversion tool
which converts text like
This is normal text while this is in <i>italic</i>
(or with any other annotation) into the proper text widget 's
pathname tag configure ...
commands?
Any link or tip will be greatly appreciated
Helmut
# Return the text widget tag for html italic or bold textinsertion
#
proc tag {ib} {
switch -exact $ib {
i {
return tagCaptionItalic
}
b {
return tagCaptionBold
}
default {
return ""
}
}
}
# Replace any html character entities with the literal character
#
proc unHtml {text} {
regsub -all {&?} $text {\&} text
regsub -all {<?} $text {<} text
regsub -all {>?} $text {>} text
regsub -all {¢?} $text "\u00a2" text
regsub -all {"?} $text {"} text
regsub -all {'?} $text {'} text
regsub -all { ?} $text "\u00a0" text
return $text
}
# Scan a html text string and break it into {text tag} pairs for
# into the text widget for the caption. The only html tagssupported are
# <i>...</i> and <b>...</b> and they cannot be nested{<{1,1}?([ib])\s*>(.*?)</\1\s*>} $string]
#
proc tagify {string} {
set text [list ]
set ranges [regexp -all -indices -inline
set cursor 0[string index $string [lindex $tag 0]]]
foreach {whole tag content} $ranges {
lassign $whole s e
if { $s > $cursor } {
lappend text [unHtml [string range $string $cursor $s-1]] ""
}
lappend text [unHtml [string range $string {*}$content]] [tag
set cursor [expr {$e+1}]$size 2]]
}
if { $cursor < [string length $string] } {
lappend text [unHtml [string range $string $cursor end]] ""
}
return $text
}
#
# Derive and create fonts
#
array set Constants [list ]
set size [font configure TkCaptionFont -size]
# The fonts for the caption window
set Constants(captionFont) [eval \
font create [font configure TkCaptionFont] -size [incrFontSize
set Constants(captionBoldFont) [eval \$size 2] \
font create [font configure TkCaptionFont] -size [incrFontSize
-weight bold]$size 2] \
set Constants(captionItalicFont) [eval \
font create [font configure TkCaptionFont] -size [incrFontSize
-slant italic]
set Constants(captionMeasure) [font measure $Constants(captionFont) 0]
unset size
proc whatever ... {entities and
:
:
:
# Insert the caption after replacing any html character
# using an italic or bold font for <i> or <b> html tags/ $Constants(captionMeasure) }] \
if { [string length $caption] > 0 } {
text $w.caption -font $Constants(captionFont) \
-borderwidth 0 \
-background white \
-height 1 \
-width [expr { ([image width image$id] - 50)
-relief flat \$Constants(captionItalicFont)
-wrap word
$w.caption tag config tagJustify -justify center
$w.caption tag config tagCaptionItalic -font
$w.caption tag config tagCaptionBold -font$Constants(captionBoldFont)
foreach {text tag} [tagify $caption] {
$w.caption insert end $text $tag
}
$w.caption tag add tagJustify 0.0 end
pack $w.caption -side top \
-pady {0 5}
:
:
:
}
Hello out there,
wanting to display text in a text widget which is partly italic and /
or bold I am wondering if there is a light weight conversion tool
which converts text like
This is normal text while this is in <i>italic</i>
(or with any other annotation) into the proper text widget 's
pathname tag configure ...
commands?
Any link or tip will be greatly appreciated
Helmut
# Do arithmetic on a font size
# If the font size is positive, the size is measured in points
# If the font size is negative, the size is measured in pixels
proc incrFontSize {size delta} {
if { $size >= 0 } {
incr size $delta
} else {
# tk scaling is the number of pixels/point
set size [expr {$size - round([tk scaling] * $delta)}]
}
return $size
}
On 9/3/2021 2:23 PM, Helmut Giese wrote:
Hello out there,
wanting to display text in a text widget which is partly italic and /
or bold I am wondering if there is a light weight conversion tool
which converts text like
This is normal text while this is in <i>italic</i>
(or with any other annotation) into the proper text widget 's
pathname tag configure ...
commands?
Any link or tip will be greatly appreciated
Helmut
Forgot a proc:
# Do arithmetic on a font size
# If the font size is positive, the size is measured in points
# If the font size is negative, the size is measured in pixels
proc incrFontSize {size delta} {
if { $size >= 0 } {
incr size $delta
} else {
# tk scaling is the number of pixels/point
set size [expr {$size - round([tk scaling] * $delta)}]
}
return $size
}
just following the chain . this seems a little simpler
[...]
set example {<h1>The Example</h1>
<h2><u>The Rain</u></h2>
Am 14.09.21 um 20:18 schrieb Bezoar:
just following the chain . this seems a little simpler
[...]
set example {<h1>The Example</h1>It seems you are trying to reinvent tkwebview, which is a basic HTML
<h2><u>The Rain</u></h2>
parser for the text widget. I use it in a few programs to show rich text
in an easy way.
Kevin Walzer seems to have pulled it from the web, unfortunately, but
the wayback machine still has it:
https://web.archive.org/web/20100129063119/http://www.codebykevin.com/opensource/xplat_oss.html
Best regards,
Christian
it is zero bytes when i try to download it Christian... (the tkwebview program??)
On Tuesday, September 14, 2021 at 8:42:49 PM UTC, Christian Gollwitzer wrote:
Am 14.09.21 um 20:18 schrieb Bezoar:
just following the chain . this seems a little simplerIt seems you are trying to reinvent tkwebview, which is a basic HTML
[...]
set example {<h1>The Example</h1>
<h2><u>The Rain</u></h2>
parser for the text widget. I use it in a few programs to show rich text
in an easy way.
Kevin Walzer seems to have pulled it from the web, unfortunately, but
the wayback machine still has it:
https://web.archive.org/web/20100129063119/http://www.codebykevin.com/opensource/xplat_oss.html
Best regards,
Christian
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 285 |
Nodes: | 16 (3 / 13) |
Uptime: | 31:39:51 |
Calls: | 6,449 |
Calls today: | 1 |
Files: | 12,052 |
Messages: | 5,254,768 |