Skip to content

Commit

Permalink
Add test case for issue jung-kurt#316
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobalberty committed Nov 7, 2019
1 parent 74b3f87 commit d800086
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions fpdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2813,3 +2813,27 @@ func ExampleFpdf_SetTextRenderingMode() {
// Output:
// Successfully generated pdf/Fpdf_TextRenderingMode.pdf
}

// TestIssue0316 addresses issue 316 in which AddUTF8FromBytes modifies its argument
// utf8bytes resulting in a panic if you generate two PDFs wih the "same" font bytes.
func TestIssue0316(t *testing.T) {
pdf := gofpdf.New(gofpdf.OrientationPortrait, "mm", "A4", "")
pdf.AddPage()
fontBytes, _ := ioutil.ReadFile(example.FontFile("DejaVuSansCondensed.ttf"))
ofontBytes := append([]byte{}, fontBytes...)
pdf.AddUTF8FontFromBytes("dejavu", "", fontBytes)
pdf.SetFont("dejavu", "", 16)
pdf.Cell(40, 10, "Hello World!")
fileStr := example.Filename("TestIssue0316")
err := pdf.OutputFileAndClose(fileStr)
example.Summary(err, fileStr)
pdf.AddPage()
if len(fontBytes) != len(ofontBytes) {
t.Fatal("Font data length changed during pdf generation")
}
for i, v := range fontBytes {
if v != ofontBytes[i] {
t.Fatal("Font data changed during pdf generation")
}
}
}

0 comments on commit d800086

Please sign in to comment.