summaryrefslogtreecommitdiff
path: root/def.go
diff options
context:
space:
mode:
Diffstat (limited to 'def.go')
-rw-r--r--def.go33
1 files changed, 32 insertions, 1 deletions
diff --git a/def.go b/def.go
index db69632..ba96b2a 100644
--- a/def.go
+++ b/def.go
@@ -18,6 +18,7 @@ package gofpdf
import (
"bytes"
+ "encoding/gob"
"io"
"time"
)
@@ -157,7 +158,9 @@ func (p PointType) XY() (float64, float64) {
return p.X, p.Y
}
-// ImageInfoType contains size, color and other information about an image
+// ImageInfoType contains size, color and other information about an image.
+// Changes to this structure should be reflected in its GobEncode and GobDecode
+// methods.
type ImageInfoType struct {
data []byte
smask []byte
@@ -175,6 +178,34 @@ type ImageInfoType struct {
dpi float64
}
+// GobEncode encodes the receiving image to a byte slice.
+func (info *ImageInfoType) GobEncode() (buf []byte, err error) {
+ fields := []interface{}{info.data, info.smask, info.i, info.n, info.w, info.h, info.cs,
+ info.pal, info.bpc, info.f, info.dp, info.trns, info.scale, info.dpi}
+ w := new(bytes.Buffer)
+ encoder := gob.NewEncoder(w)
+ for j := 0; j < len(fields) && err == nil; j++ {
+ err = encoder.Encode(fields[j])
+ }
+ if err == nil {
+ buf = w.Bytes()
+ }
+ return
+}
+
+// GobDecode decodes the specified byte buffer (generated by GobEncode) into
+// the receiving image.
+func (info *ImageInfoType) GobDecode(buf []byte) (err error) {
+ fields := []interface{}{&info.data, &info.smask, &info.i, &info.n, &info.w, &info.h,
+ &info.cs, &info.pal, &info.bpc, &info.f, &info.dp, &info.trns, &info.scale, &info.dpi}
+ r := bytes.NewBuffer(buf)
+ decoder := gob.NewDecoder(r)
+ for j := 0; j < len(fields) && err == nil; j++ {
+ err = decoder.Decode(fields[j])
+ }
+ return
+}
+
// PointConvert returns the value of pt, expressed in points (1/72 inch), as a
// value expressed in the unit of measure specified in New(). Since font
// management in Fpdf uses points, this method can help with line height