diff options
author | Wilk <flibustenet@users.noreply.github.com> | 2018-11-16 12:21:38 +0100 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@gmail.com> | 2018-11-16 06:21:38 -0500 |
commit | 76dbd3f09366910f918201e7efb42b9da1aaffe4 (patch) | |
tree | 05258ded46e214ac6691a21398786713cb1fb4a3 /fpdf_test.go | |
parent | 2969a68dc5e762d0d5b8aac519058a9f73320316 (diff) |
Make SplitLines and MultiCell split at the same place (#210)
* Make SplitLines and MultiCell split at the same place
* Use integer math for SplitLines and MultiCell
Diffstat (limited to 'fpdf_test.go')
-rw-r--r-- | fpdf_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go index 89c90b6..8f1f700 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -100,6 +100,44 @@ func TestIssue0193(t *testing.T) { } +// TestIssue0209 addresses issue 209 +// make SplitLines and MultiCell split at the same place +func TestIssue0209SplitLinesEqualMultiCell(t *testing.T) { + var pdf *gofpdf.Fpdf + + pdf = gofpdf.New("P", "mm", "A4", "") + pdf.AddPage() + pdf.SetFont("Arial", "", 8) + // this sentence should not be splited + str := "Guochin Amandine" + lines := pdf.SplitLines([]byte(str), 26) + _, FontSize := pdf.GetFontSize() + y_start := pdf.GetY() + pdf.MultiCell(26, FontSize, str, "", "L", false) + y_end := pdf.GetY() + + if len(lines) != 1 { + t.Fatalf("expect SplitLines split in one line") + } + if int(y_end-y_start) != int(FontSize) { + t.Fatalf("expect MultiCell split in one line %.2f != %.2f", y_end-y_start, FontSize) + } + + // this sentence should be splited in two lines + str = "Guiochini Amandine" + lines = pdf.SplitLines([]byte(str), 26) + y_start = pdf.GetY() + pdf.MultiCell(26, FontSize, str, "", "L", false) + y_end = pdf.GetY() + + if len(lines) != 2 { + t.Fatalf("expect SplitLines split in two lines") + } + if int(y_end-y_start) != int(FontSize*2) { + t.Fatalf("expect MultiCell split in two lines %.2f != %.2f", y_end-y_start, FontSize*2) + } +} + // Test to make sure the footer is not call twice and SetFooterFuncLpi can work // without SetFooterFunc. func TestFooterFuncLpi(t *testing.T) { |