summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--def.go2
-rw-r--r--fpdf.go15
-rw-r--r--template.go2
3 files changed, 10 insertions, 9 deletions
diff --git a/def.go b/def.go
index 3c4d902..1187c8f 100644
--- a/def.go
+++ b/def.go
@@ -681,9 +681,9 @@ type fontDefType struct {
File string // "Redressed.z"
Size1, Size2 int // Type1 values
OriginalSize int // Size of uncompressed font file
- I int // 1-based position in font list, set by font loader, not this program
N int // Set by font loader
DiffN int // Position of diff in app array, set by font loader
+ i string // 1-based position in font list, set by font loader, not this program
}
type fontInfoType struct {
diff --git a/fpdf.go b/fpdf.go
index 46fe007..400c83f 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -23,6 +23,7 @@ package gofpdf
import (
"bytes"
+ "crypto/sha1"
"encoding/binary"
"encoding/json"
"fmt"
@@ -1578,7 +1579,7 @@ func (f *Fpdf) AddFontFromBytes(familyStr, styleStr string, jsonFileBytes, zFile
}
// search existing encodings
- info.I = len(f.fonts)
+ info.i = fmt.Sprintf("%x", sha1.Sum(jsonFileBytes))
if len(info.Diff) > 0 {
n := -1
@@ -1648,7 +1649,6 @@ func (f *Fpdf) AddFontFromReader(familyStr, styleStr string, r io.Reader) {
if f.err != nil {
return
}
- info.I = len(f.fonts)
if len(info.Diff) > 0 {
// Search existing encodings
n := -1
@@ -1783,7 +1783,7 @@ func (f *Fpdf) SetFont(familyStr, styleStr string, size float64) {
f.fontSize = size / f.k
f.currentFont = f.fonts[fontkey]
if f.page > 0 {
- f.outf("BT /F%d %.2f Tf ET", f.currentFont.I, f.fontSizePt)
+ f.outf("BT /F%s %.2f Tf ET", f.currentFont.i, f.fontSizePt)
}
return
}
@@ -1797,7 +1797,7 @@ func (f *Fpdf) SetFontSize(size float64) {
f.fontSizePt = size
f.fontSize = size / f.k
if f.page > 0 {
- f.outf("BT /F%d %.2f Tf ET", f.currentFont.I, f.fontSizePt)
+ f.outf("BT /F%s %.2f Tf ET", f.currentFont.i, f.fontSizePt)
}
}
@@ -1810,7 +1810,7 @@ func (f *Fpdf) SetFontUnitSize(size float64) {
f.fontSizePt = size * f.k
f.fontSize = size
if f.page > 0 {
- f.outf("BT /F%d %.2f Tf ET", f.currentFont.I, f.fontSizePt)
+ f.outf("BT /F%s %.2f Tf ET", f.currentFont.i, f.fontSizePt)
}
}
@@ -2953,6 +2953,7 @@ func (f *Fpdf) loadfont(r io.Reader) (def fontDefType) {
if err != nil {
f.err = err
}
+ def.i = fmt.Sprintf("%x", sha1.Sum(buf.Bytes()))
// dump(def)
return
}
@@ -3585,11 +3586,11 @@ func (f *Fpdf) putresourcedict() {
keyList = append(keyList, key)
}
if f.catalogSort {
- sort.SliceStable(keyList, func(i, j int) bool { return f.fonts[keyList[i]].I < f.fonts[keyList[j]].I })
+ sort.SliceStable(keyList, func(i, j int) bool { return f.fonts[keyList[i]].i < f.fonts[keyList[j]].i })
}
for _, key = range keyList {
font = f.fonts[key]
- f.outf("/F%d %d 0 R", font.I, font.N)
+ f.outf("/F%s %d 0 R", font.i, font.N)
}
}
f.out(">>")
diff --git a/template.go b/template.go
index fc6e29c..e3e4fe5 100644
--- a/template.go
+++ b/template.go
@@ -128,7 +128,7 @@ func (f *Fpdf) templateFontCatalog() {
}
for _, key = range keyList {
font = f.fonts[key]
- f.outf("/F%d %d 0 R", font.I, font.N)
+ f.outf("/F%s %d 0 R", font.i, font.N)
}
f.out(">>")
}