summaryrefslogtreecommitdiff
path: root/def.go
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2018-11-10 12:07:08 -0500
committerKurt <kurt.w.jung@gmail.com>2018-11-10 12:07:08 -0500
commit13c78403a35a19e3943791af9435411c401ab446 (patch)
tree0ce3865cbd2051a4a6d74e4273ccc3eb2dd7cd24 /def.go
parente200d3e7c7ef20b29a47b67e58b7561f4099e7ae (diff)
parent193187d077554b92944a4757e202d1300e1ed1fb (diff)
Merge branch 'd1ngd0-ftr/gob'
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 b4140a9..605cdbc 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