summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdf.go15
-rw-r--r--fpdf_test.go4
-rw-r--r--template.go29
3 files changed, 32 insertions, 16 deletions
diff --git a/fpdf.go b/fpdf.go
index 08bcb2e..74489de 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -3367,21 +3367,10 @@ func (f *Fpdf) putxobjectdict() {
}
}
{
- var key int64
var keyList []int64
+ var key int64
var tpl Template
- for key = range f.templates {
- keyList = append(keyList, key)
- }
- if f.catalogSort {
- gensort(len(keyList),
- func(a, b int) bool {
- return keyList[a] < keyList[b]
- },
- func(a, b int) {
- keyList[a], keyList[b] = keyList[b], keyList[a]
- })
- }
+ keyList = templateKeyList(f.templates, f.catalogSort)
for _, key = range keyList {
tpl = f.templates[key]
// for _, tpl := range f.templates {
diff --git a/fpdf_test.go b/fpdf_test.go
index a0eaec1..7b56fab 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -1734,8 +1734,8 @@ func ExampleFpdf_CreateTemplate() {
pdf.AddPage()
pdf.UseTemplate(template)
- pdf.UseTemplateScaled(template, gofpdf.PointType{0, 30}, tplSize)
- pdf.UseTemplateScaled(template, gofpdf.PointType{0, 60}, tplSize.ScaleBy(1.4))
+ pdf.UseTemplateScaled(template, gofpdf.PointType{X: 0, Y: 30}, tplSize)
+ pdf.UseTemplateScaled(template, gofpdf.PointType{X: 0, Y: 60}, tplSize.ScaleBy(1.4))
pdf.Line(40, 210, 60, 210)
pdf.Text(40, 200, "Template example page 1")
diff --git a/template.go b/template.go
index bf25c9f..cdb1428 100644
--- a/template.go
+++ b/template.go
@@ -178,12 +178,34 @@ func (f *Fpdf) putTemplates() {
}
}
+func templateKeyList(mp map[int64]Template, sort bool) (keyList []int64) {
+ var key int64
+ for key = range mp {
+ keyList = append(keyList, key)
+ }
+ if sort {
+ gensort(len(keyList),
+ func(a, b int) bool {
+ return keyList[a] < keyList[b]
+ },
+ func(a, b int) {
+ keyList[a], keyList[b] = keyList[b], keyList[a]
+ })
+ }
+ return
+}
+
// sortTemplates puts templates in a suitable order based on dependices
func sortTemplates(templates map[int64]Template) []Template {
chain := make([]Template, 0, len(templates)*2)
// build a full set of dependency chains
- for _, t := range templates {
+ var keyList []int64
+ var key int64
+ var t Template
+ keyList = templateKeyList(templates, true) // FIXME
+ for _, key = range keyList {
+ t = templates[key]
tlist := templateChainDependencies(t)
for _, tt := range tlist {
if tt != nil {
@@ -219,3 +241,8 @@ func templateChainDependencies(template Template) []Template {
chain = append(chain, template)
return chain
}
+
+// < 0002640 31 20 31 32 20 30 20 52 0a 2f 54 50 4c 32 20 31 |1 12 0 R./TPL2 1|
+// > 0002640 31 20 31 32 20 30 20 52 0a 2f 54 50 4c 31 20 31 |1 12 0 R./TPL1 1|
+// < 0002650 35 20 30 20 52 0a 2f 54 50 4c 31 20 31 34 20 30 |5 0 R./TPL1 14 0|
+// > 0002650 34 20 30 20 52 0a 2f 54 50 4c 32 20 31 35 20 30 |4 0 R./TPL2 15 0|