From 25d0813f8f9210fcaf3a5797d72756a332ef2dbe Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Fri, 9 Oct 2015 15:52:07 -0400 Subject: Implement PDF comparison with rudimentary byte-difference display. If a reference file exists, it will be compared with its associated example file. If the reference file is missing, the associated example file is considered to be without differences. PDF files in any subdirectory named reference are not deleted when the test begins. This commit is broken -- it illustrates how the use of maps for fonts, images and other resources lead to different dictionary tables in the PDF document. --- fpdf_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index 966767f..e45f966 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -40,9 +40,14 @@ func init() { func cleanup() { filepath.Walk(example.PdfDir(), func(path string, info os.FileInfo, err error) (reterr error) { - if len(path) > 3 { - if path[len(path)-4:] == ".pdf" { - os.Remove(path) + if info.Mode().IsRegular() { + dir, _ := filepath.Split(path) + if "reference" != filepath.Base(dir) { + if len(path) > 3 { + if path[len(path)-4:] == ".pdf" { + os.Remove(path) + } + } } } return -- cgit v1.2.1-24-ge1ad From e924055b983321336e31f556f5235ea79fe72134 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Sat, 10 Oct 2015 09:11:53 -0400 Subject: Implement conditional catalog sort feature --- fpdf_test.go | 1 + 1 file changed, 1 insertion(+) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index e45f966..39cebc0 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -110,6 +110,7 @@ func Example() { // This example demonsrates the generation of headers, footers and page breaks. func ExampleFpdf_AddPage() { pdf := gofpdf.New("P", "mm", "A4", "") + pdf.SetCatalogSort(true) pdf.SetHeaderFunc(func() { pdf.Image(example.ImageFile("logo.png"), 10, 6, 30, 0, false, "", 0, "") pdf.SetY(5) -- cgit v1.2.1-24-ge1ad From 5847afd8a205853a7effbf749b7a388ae325eb24 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Sat, 10 Oct 2015 14:16:23 -0400 Subject: Introduce helper functions to set default catalog sort flag and creation date value. Remove regular expression scheme that effectively ignored the embedded creation date when comparing PDFs. --- fpdf_test.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index 39cebc0..cc0b91c 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -28,6 +28,7 @@ import ( "path/filepath" "strconv" "strings" + "time" "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/internal/example" @@ -35,6 +36,8 @@ import ( func init() { cleanup() + gofpdf.SetDefaultCatalogSort(true) + gofpdf.SetDefaultCreationDate(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)) } func cleanup() { -- cgit v1.2.1-24-ge1ad 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. --- fpdf_test.go | 1 - 1 file changed, 1 deletion(-) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index cc0b91c..2238ccd 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -113,7 +113,6 @@ func Example() { // This example demonsrates the generation of headers, footers and page breaks. func ExampleFpdf_AddPage() { pdf := gofpdf.New("P", "mm", "A4", "") - pdf.SetCatalogSort(true) pdf.SetHeaderFunc(func() { pdf.Image(example.ImageFile("logo.png"), 10, 6, 30, 0, false, "", 0, "") pdf.SetY(5) -- cgit v1.2.1-24-ge1ad From eca9f96fbf9b6be62915d111546f4798ce3fac62 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Sun, 11 Oct 2015 09:16:21 -0400 Subject: Move default assignments to init function of example file from various test files. Now any package that imports the example package will generate PDFs with sorted catalogs and a fixed creation timestamp. --- fpdf_test.go | 3 --- 1 file changed, 3 deletions(-) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index 2238ccd..e45f966 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -28,7 +28,6 @@ import ( "path/filepath" "strconv" "strings" - "time" "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/internal/example" @@ -36,8 +35,6 @@ import ( func init() { cleanup() - gofpdf.SetDefaultCatalogSort(true) - gofpdf.SetDefaultCreationDate(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)) } func cleanup() { -- cgit v1.2.1-24-ge1ad From 08c842eee7361c4d515301a5d84d246a0b0a9462 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Sun, 11 Oct 2015 09:43:23 -0400 Subject: Investigate missing spaces between words --- fpdf_test.go | 1 + 1 file changed, 1 insertion(+) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index e45f966..a0eaec1 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -1140,6 +1140,7 @@ func ExampleFpdf_SVGBasicWrite() { err error ) pdf := gofpdf.New("P", "mm", "A4", "") // A4 210.0 x 297.0 + pdf.SetCompression(false) pdf.SetFont("Times", "", fontPtSize) lineHt := pdf.PointConvert(fontPtSize) pdf.AddPage() -- 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. --- fpdf_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'fpdf_test.go') 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") -- cgit v1.2.1-24-ge1ad From 0e7f14245b3a89fe3e1aa59814b080b65b58ee08 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Mon, 12 Oct 2015 11:00:21 -0400 Subject: Allow SVG example to be compressed --- fpdf_test.go | 1 - 1 file changed, 1 deletion(-) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index 7b56fab..596816c 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -1140,7 +1140,6 @@ func ExampleFpdf_SVGBasicWrite() { err error ) pdf := gofpdf.New("P", "mm", "A4", "") // A4 210.0 x 297.0 - pdf.SetCompression(false) pdf.SetFont("Times", "", fontPtSize) lineHt := pdf.PointConvert(fontPtSize) pdf.AddPage() -- cgit v1.2.1-24-ge1ad