From 92858a8b5ff04e4196597d9d517f3b2a0d651579 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Sat, 10 Oct 2015 15:24:43 -0400 Subject: Conditionally sort image catalog. Correct small typos. --- template.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'template.go') diff --git a/template.go b/template.go index 7561ae1..342032e 100644 --- a/template.go +++ b/template.go @@ -36,7 +36,7 @@ func CreateTemplate(corner PointType, size SizeType, unitStr, fontDirStr string, // using the size and position at which it was originally written. func (f *Fpdf) UseTemplate(t Template) { if t == nil { - f.SetErrorf("Template is nil") + f.SetErrorf("template is nil") return } corner, size := t.Size() @@ -47,13 +47,13 @@ func (f *Fpdf) UseTemplate(t Template) { // using the given page coordinates. func (f *Fpdf) UseTemplateScaled(t Template, corner PointType, size SizeType) { if t == nil { - f.SetErrorf("Template is nil") + f.SetErrorf("template is nil") return } // You have to add at least a page first if f.page <= 0 { - f.SetErrorf("Cannot use a template without first adding a page") + f.SetErrorf("cannot use a template without first adding a page") return } -- cgit v1.2.1-24-ge1ad From 13a5fda5f79f2c15eea512e6ec3de2ce60aa29ca Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Sun, 11 Oct 2015 13:23:37 -0400 Subject: Conditionally sort two map iterations in template code; more to come. --- template.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'template.go') diff --git a/template.go b/template.go index 342032e..bf25c9f 100644 --- a/template.go +++ b/template.go @@ -17,6 +17,10 @@ package gofpdf * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +import ( + "sort" +) + // CreateTemplate defines a new template using the current page size. func (f *Fpdf) CreateTemplate(fn func(*Tpl)) Template { return newTpl(PointType{0, 0}, f.curPageSize, f.unitStr, f.fontDirStr, fn, f) @@ -135,8 +139,21 @@ func (f *Fpdf) putTemplates() { tTemplates := t.Templates() if len(tImages) > 0 || len(tTemplates) > 0 { f.out("/XObject <<") - for _, ti := range tImages { - f.outf("/I%d %d 0 R", ti.i, ti.n) + { + var key string + var keyList []string + var ti *ImageInfoType + for key = range tImages { + keyList = append(keyList, key) + } + if gl.catalogSort { + sort.Strings(keyList) + } + for _, key = range keyList { + // for _, ti := range tImages { + ti = tImages[key] + f.outf("/I%d %d 0 R", ti.i, ti.n) + } } for _, tt := range tTemplates { id := tt.ID() -- cgit v1.2.1-24-ge1ad From d51e132c6432f2c1bbff5d9516f77375bb5252e6 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Sun, 11 Oct 2015 21:06:01 -0400 Subject: Conditionally order another map iteration. Fix 'go vet' problem with unkeyed field in composite literal. --- template.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'template.go') 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| -- cgit v1.2.1-24-ge1ad From 31c1da203bd00ff9e9ba602257bab2b4282ca945 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Mon, 12 Oct 2015 10:34:43 -0400 Subject: Add reference PDFs for comparison purposes. Document comparison of example documents. --- template.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'template.go') diff --git a/template.go b/template.go index cdb1428..17354fa 100644 --- a/template.go +++ b/template.go @@ -116,7 +116,7 @@ func (f *Fpdf) putTemplates() { filter = "/Filter /FlateDecode " } - templates := sortTemplates(f.templates) + templates := sortTemplates(f.templates, f.catalogSort) var t Template for _, t = range templates { corner, size := t.Size() @@ -196,14 +196,14 @@ func templateKeyList(mp map[int64]Template, sort bool) (keyList []int64) { } // sortTemplates puts templates in a suitable order based on dependices -func sortTemplates(templates map[int64]Template) []Template { +func sortTemplates(templates map[int64]Template, catalogSort bool) []Template { chain := make([]Template, 0, len(templates)*2) // build a full set of dependency chains var keyList []int64 var key int64 var t Template - keyList = templateKeyList(templates, true) // FIXME + keyList = templateKeyList(templates, catalogSort) for _, key = range keyList { t = templates[key] tlist := templateChainDependencies(t) @@ -243,6 +243,7 @@ func templateChainDependencies(template Template) []Template { } // < 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| + +// > 0002640 31 20 31 32 20 30 20 52 0a 2f 54 50 4c 31 20 31 |1 12 0 R./TPL1 1| // > 0002650 34 20 30 20 52 0a 2f 54 50 4c 32 20 31 35 20 30 |4 0 R./TPL2 15 0| -- cgit v1.2.1-24-ge1ad From 89173160f564ddc0a63efaadf3ae78b0dc9377d2 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Tue, 13 Oct 2015 07:42:35 -0400 Subject: Use %f rather than %F since earlier versions of Go did not support the latter. Thanks, Marcus. --- template.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'template.go') diff --git a/template.go b/template.go index 17354fa..c9a33d5 100644 --- a/template.go +++ b/template.go @@ -79,7 +79,7 @@ func (f *Fpdf) UseTemplateScaled(t Template, corner PointType, size SizeType) { tx := corner.X * f.k ty := (f.curPageSize.Ht - corner.Y - size.Ht) * f.k - f.outf("q %.4F 0 0 %.4F %.4F %.4F cm", scaleX, scaleY, tx, ty) // Translate + f.outf("q %.4f 0 0 %.4f %.4f %.4f cm", scaleX, scaleY, tx, ty) // Translate f.outf("/TPL%d Do Q", t.ID()) } @@ -126,9 +126,9 @@ func (f *Fpdf) putTemplates() { f.outf("<<%s/Type /XObject", filter) f.out("/Subtype /Form") f.out("/Formtype 1") - f.outf("/BBox [%.2F %.2F %.2F %.2F]", corner.X*f.k, corner.Y*f.k, (corner.X+size.Wd)*f.k, (corner.Y+size.Ht)*f.k) + f.outf("/BBox [%.2f %.2f %.2f %.2f]", corner.X*f.k, corner.Y*f.k, (corner.X+size.Wd)*f.k, (corner.Y+size.Ht)*f.k) if corner.X != 0 || corner.Y != 0 { - f.outf("/Matrix [1 0 0 1 %.5F %.5F]", -corner.X*f.k*2, corner.Y*f.k*2) + f.outf("/Matrix [1 0 0 1 %.5f %.5f]", -corner.X*f.k*2, corner.Y*f.k*2) } // Template's resource dictionary -- cgit v1.2.1-24-ge1ad