diff options
author | Kurt <kurt.w.jung@gmail.com> | 2018-11-10 12:07:08 -0500 |
---|---|---|
committer | Kurt <kurt.w.jung@gmail.com> | 2018-11-10 12:07:08 -0500 |
commit | 13c78403a35a19e3943791af9435411c401ab446 (patch) | |
tree | 0ce3865cbd2051a4a6d74e4273ccc3eb2dd7cd24 /def.go | |
parent | e200d3e7c7ef20b29a47b67e58b7561f4099e7ae (diff) | |
parent | 193187d077554b92944a4757e202d1300e1ed1fb (diff) |
Merge branch 'd1ngd0-ftr/gob'
Diffstat (limited to 'def.go')
-rw-r--r-- | def.go | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -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 |