summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@gmail.com>2015-07-04 14:13:12 -0400
committerKurt Jung <kurt.w.jung@gmail.com>2015-07-04 14:13:12 -0400
commitfc0728dfdeebace8a2ea23d62fa05fa2cbadbe98 (patch)
tree7c0004d2a5b684e64f22956d3f06e05453581398 /fpdf_test.go
parent4cdc6183e275dfb2da40b965477900081b8f905e (diff)
Example of Claudio Felber's generalized font loaing implementation
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index bb69569..3439f91 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
@@ -1427,3 +1442,19 @@ func ExampleFpdf_tutorial28() {
// Successfully generated pdf/tutorial28.pdf
}
+
+// 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, "Enjoy new fonts with FPDF!")
+ pdf.OutputAndClose(docWriter(pdf, 29))
+ // Output:
+ // Generalized font loader reading calligra.json
+ // Generalized font loader reading calligra.z
+ // Successfully generated pdf/tutorial29.pdf
+}