summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go43
1 files changed, 38 insertions, 5 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index a99fd2d..8959ece 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -18,8 +18,10 @@ package gofpdf_test
import (
"bufio"
+ "bytes"
"fmt"
"github.com/jung-kurt/gofpdf"
+ "io"
"io/ioutil"
"math"
"net/http"
@@ -101,6 +103,19 @@ func textFile(fileStr string) string {
return filepath.Join(cnTextDir, fileStr)
}
+type fontResourceType struct {
+}
+
+func (f fontResourceType) Open(name string) (rdr io.Reader, err error) {
+ var buf []byte
+ buf, err = ioutil.ReadFile(fontFile(name))
+ if err == nil {
+ rdr = bytes.NewReader(buf)
+ fmt.Printf("Generalized font loader reading %s\n", name)
+ }
+ return
+}
+
// Convert 'ABCDEFG' to, for example, 'A,BCD,EFG'
func strDelimit(str string, sepstr string, sepcount int) string {
pos := len(str) - sepcount
@@ -1415,8 +1430,10 @@ func ExampleFpdf_tutorial28() {
srcPrev = src
}
pdf.MultiCell(wd-margin-margin, ln, msgStr, "", "C", false)
- pdf.SetDrawColor(224, 224, 224)
+ pdf.SetDashPattern([]float64{0.8, 0.8}, 0)
+ pdf.SetDrawColor(160, 160, 160)
pdf.Polygon(srcList, "D")
+ pdf.SetDashPattern([]float64{}, 0)
pdf.SetDrawColor(64, 64, 128)
pdf.SetLineWidth(pdf.GetLineWidth() * 3)
pdf.Beziergon(curveList, "D")
@@ -1426,9 +1443,25 @@ func ExampleFpdf_tutorial28() {
}
-// This example demonstrates the Path Drawing functions, such as:
-// MoveTo, LineTo, CurveTo, ..., ClosePath and DrawPath.
+// Non-standard font using generalized font loader
func ExampleFpdf_tutorial29() {
+ var fr fontResourceType
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
+ pdf.SetFontLoader(fr)
+ pdf.AddFont("Calligrapher", "", "calligra.json")
+ pdf.AddPage()
+ pdf.SetFont("Calligrapher", "", 35)
+ pdf.Cell(0, 10, "Load fonts from any source")
+ pdf.OutputAndClose(docWriter(pdf, 29))
+ // Output:
+ // Generalized font loader reading calligra.json
+ // Generalized font loader reading calligra.z
+ // Successfully generated pdf/tutorial29.pdf
+}
+
+// This example demonstrates the Path Drawing functions, such as: MoveTo,
+// LineTo, CurveTo, ..., ClosePath and DrawPath.
+func ExampleFpdf_tutorial30() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.MoveTo(20, 20)
@@ -1439,7 +1472,7 @@ func ExampleFpdf_tutorial29() {
pdf.SetFillColor(200, 200, 200)
pdf.SetLineWidth(3)
pdf.DrawPath("DF")
- pdf.OutputAndClose(docWriter(pdf, 29))
+ pdf.OutputAndClose(docWriter(pdf, 30))
// Output:
- // Successfully generated pdf/tutorial29.pdf
+ // Successfully generated pdf/tutorial30.pdf
}