Skip to content

Commit

Permalink
Update to tfpdf 1.33 - Fix of links and others- New example
Browse files Browse the repository at this point in the history
  • Loading branch information
lamuzzachiodi committed Mar 11, 2023
1 parent a106a9c commit 3c75b85
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 54 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# **TCLFPDF 1.5 (2022)** #
# **TCLFPDF 1.6 (2023)** #
## *Port of tFPDF (PHP) by by Ian Back and Tycho Veltmeijer (modified version of FPDF by Olivier Plathey) to TCL* ##

----------
Expand All @@ -8,23 +8,23 @@

#### English #####

This work aims to port [tFPDF]("http://www.fpdf.org/en/script/script92.php") (1.32) from PHP to TCL. This is a modified class of [FPDF]("http://www.fpdf.org/") (1.82) that adds support for UTF-8.
This work aims to port [tFPDF]("http://www.fpdf.org/en/script/script92.php") (1.33) from PHP to TCL. This is a modified class of [FPDF]("http://www.fpdf.org/") (1.85) that adds support for UTF-8.
It is, therefore, a complete update of the previous version of 2014, which maintains backward compatibility, but adds full support for UTF-8.
I have tried to be as faithful as possible to the original, keeping the names and structure of programs.This way it should be possible to port the examples or addons with minimal effort.

Your comments or suggestions are always welcome.

#### Spanish ####

Este trabajo pretende portar [tFPDF]("http://www.fpdf.org/en/script/script92.php") (1.32) de PHP a TCL. tFPDF es una clase modificada de [FPDF]("http://www.fpdf.org/") (1.82) que incorpora soporte para UTF-8.
Este trabajo pretende portar [tFPDF]("http://www.fpdf.org/en/script/script92.php") (1.33) de PHP a TCL. tFPDF es una clase modificada de [FPDF]("http://www.fpdf.org/") (1.85) que incorpora soporte para UTF-8.
Por tanto, es una completa actualización de la versión previa de 2014 que mantiene la compatibilidad pero agrega completo soporte para UTF-8.
He tratado de ser lo más fiel posible al original en PHP, manteniendo los nombres y la estructura de los programas. De esta manera debería ser posible portar los ejemplos o extensiones con un mínimo esfuerzo.

Sus comentarios o sugerencias serán bienvenidos.



__*Luis Alejandro Muzzachiodi (2022)*__
__*Luis Alejandro Muzzachiodi (2023)*__


----------
Expand Down
122 changes: 122 additions & 0 deletions examples/links_and_flowing_text.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package require tclfpdf
namespace import ::tclfpdf::*

set B 0
set I 0
set U 0
set HREF ""

proc WriteHTML { html } {
global HREF
# HTML parser
set html [ string map {\n "" } $html ]
set a0 {}
regsub -all "<(.*?)>" $html "»&»" a0
set a1 [split $a0 »]
foreach i0 $a1 {
lappend a [string map { < "" > "" } $i0 ]
}
set i -1
foreach e $a {
incr i
if { [expr $i%2] == 0 } {
# Text
if {$HREF ne ""} {
PutLink $HREF $e
} else {
Write 5 $e
}
} else {
# Tag
if { [string index $e 0] eq "/" } {
CloseTag [string toupper [string range $e 1 end]];
} else {
# Extract attributes
set a2 [split $e " " ]
set tag {}
set tag [string toupper [lindex $a2 0]]
set a2 [lreplace $a2 0 0]
array set attr {}
set a3 ""
foreach v $a2 {
set a3 [regexp -inline {([^=]*)=["\']?([^"\']*)} $v ]
if { $a3 ne ""} {
set attr([string toupper [lindex $a3 1]]) [lindex $a3 2]
}
}
OpenTag $tag [array get attr]
}
}
}
}

proc OpenTag { tag attr0 } {
global HREF
array set attr $attr0
# Opening tag
if {$tag=="B" || $tag=="I" || $tag=="U" } {
SetStyle $tag 1
}
if {$tag=="A" } {
set HREF $attr(HREF)
}
if { $tag=="BR" } {
Ln 5
}
}

proc CloseTag { tag } {
global HREF
# Closing tag
if { $tag=="B" || $tag=="I" || $tag=="U" } {
SetStyle $tag 0
}
if { $tag == "A" } {
set HREF ""
}
}

proc SetStyle { tag enable } {
# Modify style and select corresponding font
global B I U
set $tag [expr [set $tag] + ($enable ? 1 : -1)]
set style ""
set lis_tag [list B I U]
foreach s $lis_tag {
if { [set $s] >0 } {
set style $style$s;
}
}
SetFont "" $style
}

proc PutLink { URL txt } {
#Put a hyperlink
SetTextColor 0 0 255
SetStyle U 1
Write 5 $txt $URL
SetStyle U 0
SetTextColor 0
}

set html "You can now easily print text mixing different styles: <b>bold</b>, <i>italic</i>,
<u>underlined</u>, or <b><i><u>all at once</u></i></b>!<br><br>You can also insert links on
text, such as <a href=\"http://www.fpdf.org\">www.fpdf.org</a>, or on an image: click on the logo."

# First page
Init
AddPage
SetFont "Arial" "" 20
Write 5 "To find out what's cool in this example, click "
SetFont "" "U"
set link [AddLink]
Write 5 "here" $link
SetFont ""
# Second page
AddPage
SetLink $link
Image "logo.gif" 10 12 30 0 "" "http://www.fpdf.org"
SetLeftMargin 45
SetFontSize 14
WriteHTML $html
Output "flow.pdf"
Binary file added examples/logo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed examples/utf8.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion makefont/makefont.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ proc Message { txt {severity ""} } {
tk_messageBox -icon error -message $txt -title "$severity";
}
std {
puts "$severity $msg";
puts "$severity $txt";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion manual/setfont.htm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>Description</h2>
<br>
<strong>Note:</strong> the font definition files must be accessible. They are searched successively in:
<ul>
<li>The directory defined by the <code>TCLFPDF_FONTPATH</code> constant (this constant is defined for default to the <code>font</code> directory located in the same directory as <code>tclfpdf.tcl</code> /li>
<li>The directory defined by the <code>TCLFPDF_FONTPATH</code> constant (this constant is defined for default to the <code>font</code> directory located in the same directory as <code>tclfpdf.tcl</code> </li>
<li>The directory <code> fonts </code> of the system </li>
</ul>
Example using <code>TCLFPDF_FONTPATH</code>:
Expand Down
2 changes: 1 addition & 1 deletion pkgIndex.tcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package ifneeded tclfpdf 1.5 [list source [file join $dir tclfpdf.1.5.tcl]]
package ifneeded tclfpdf 1.6 [list source [file join $dir tclfpdf.1.6.tcl]]
Loading

0 comments on commit 3c75b85

Please sign in to comment.