Skip to content

Commit

Permalink
Add reference PDFs for comparison purposes. Document comparison of ex…
Browse files Browse the repository at this point in the history
…ample documents.
  • Loading branch information
jung-kurt committed Oct 12, 2015
1 parent d51e132 commit 31c1da2
Show file tree
Hide file tree
Showing 40 changed files with 36 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
makefont/makefont
pdf/*.pdf
pdf/reference
look
open
pdf.txt
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ Please note that these examples run in the context of a test. In order run an
example as a standalone application, you'll need to examine [fpdf_test.go](https://github.com/jung-kurt/gofpdf/blob/master/fpdf_test.go) for
some helper routines, for example exampleFilename and summary.

Example PDFs can be compared with reference copies in order to verify that they
have been generated as expected. This comparison will be performed if a PDF
with the same name as the example PDF is placed in the gofpdf/pdf/reference
directory. The routine that summarizes an example will look for this file and,
if found, will call the ComparePDFFiles() to check the example PDF for equality
with its reference PDF. If differences exist between the two files they will be
printed to standard output and the test will fail. If the reference file is
missing, the comparison is considered to succeed. In order to successfully
compare two PDFs, the placement of internal resources must be consistent and
the internal creation timestamps must be the same. To do this, the methods
SetCatalogSort() and SetCreationDate() need to be called for both files. This
is done automatically for all examples.

##Nonstandard Fonts


Expand Down
13 changes: 13 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ Please note that these examples run in the context of a test. In order run an
example as a standalone application, you'll need to examine fpdf_test.go for
some helper routines, for example exampleFilename and summary.
Example PDFs can be compared with reference copies in order to verify that they
have been generated as expected. This comparison will be performed if a PDF
with the same name as the example PDF is placed in the gofpdf/pdf/reference
directory. The routine that summarizes an example will look for this file and,
if found, will call the ComparePDFFiles() to check the example PDF for equality
with its reference PDF. If differences exist between the two files they will be
printed to standard output and the test will fail. If the reference file is
missing, the comparison is considered to succeed. In order to successfully
compare two PDFs, the placement of internal resources must be consistent and
the internal creation timestamps must be the same. To do this, the methods
SetCatalogSort() and SetCreationDate() need to be called for both files. This
is done automatically for all examples.
Nonstandard Fonts
Nothing special is required to use the standard PDF fonts (courier, helvetica,
Expand Down
6 changes: 3 additions & 3 deletions fpdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3003,7 +3003,7 @@ func SetDefaultCatalogSort(flag bool) {

// SetCatalogSort sets a flag that will be used, if true, to consistently order
// the document's internal resource catalogs. This method is typically only
// used for test purposes.
// used for test purposes to facilitate PDF comparison.
func (f *Fpdf) SetCatalogSort(flag bool) {
f.catalogSort = flag
}
Expand All @@ -3017,8 +3017,8 @@ func SetDefaultCreationDate(tm time.Time) {

// SetCreationDate fixes the document's internal CreationDate value. By
// default, the time when the document is generated is used for this value.
// This method is typically only used for testing purposes. Specify a
// zero-value time to revert to the default behavior.
// This method is typically only used for testing purposes to facilitate PDF
// comparsion. Specify a zero-value time to revert to the default behavior.
func (f *Fpdf) SetCreationDate(tm time.Time) {
f.creationDate = tm
}
Expand Down
Binary file added pdf/reference/Fpdf_AddFont.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_AddLayer.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_AddPage.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_Beziergon.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_Bookmark.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_CellFormat_1_tables.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_CellFormat_2_align.pdf
Binary file not shown.
Binary file not shown.
Binary file added pdf/reference/Fpdf_CellFormat_4_codepage.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_Circle_figures.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_ClipText.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_CreateTemplate.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_DrawPath_fill.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_HTMLBasicNew.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_Image.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_LinearGradient_gradient.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_MoveTo_path.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_MultiCell.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_PageSize.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_Polygon.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_RegisterImage.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_RegisterImageReader_url.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_SVGBasicWrite.pdf
Binary file not shown.
Binary file not shown.
Binary file added pdf/reference/Fpdf_SetAlpha_transparency.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_SetFontLoader.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_SetKeywords.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_SetLeftMargin_multicolumn.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_SetLineJoinStyle_caps.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_SetProtection.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_Splitlines.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_TransformBegin.pdf
Binary file not shown.
Binary file added pdf/reference/Fpdf_WriteAligned.pdf
Binary file not shown.
Binary file added pdf/reference/basic.pdf
Binary file not shown.
9 changes: 5 additions & 4 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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|
4 changes: 2 additions & 2 deletions template_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func newTpl(corner PointType, size SizeType, unitStr, fontDirStr string, fn func
fn(&tpl)
bytes := tpl.Fpdf.pages[tpl.Fpdf.page].Bytes()
templates := make([]Template, 0, len(tpl.Fpdf.templates))
for _, t := range tpl.Fpdf.templates {
templates = append(templates, t)
for _, key := range templateKeyList(tpl.Fpdf.templates, true) {
templates = append(templates, tpl.Fpdf.templates[key])
}
images := tpl.Fpdf.images

Expand Down

0 comments on commit 31c1da2

Please sign in to comment.