diff options
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 |