From d704bfb2cd48ca92cd70ff256a8872e49c20daa3 Mon Sep 17 00:00:00 2001 From: rustrover Date: Sat, 9 Mar 2024 13:41:19 +0800 Subject: [PATCH 1/2] fix some typos Signed-off-by: rustrover --- buff.go | 4 ++-- fontmaker/core/ttfparser.go | 2 +- gopdf.go | 4 ++-- pdf_dictionary_obj.go | 4 ++-- pdf_protection.go | 2 +- subset_font_obj.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/buff.go b/buff.go index d243c24..3544808 100644 --- a/buff.go +++ b/buff.go @@ -31,12 +31,12 @@ func (b *Buff) Bytes() []byte { return b.datas } -// Position : get current postion +// Position : get current position func (b *Buff) Position() int { return b.position } -// SetPosition : set current postion +// SetPosition : set current position func (b *Buff) SetPosition(pos int) { b.position = pos } diff --git a/fontmaker/core/ttfparser.go b/fontmaker/core/ttfparser.go index 6ef5534..894059b 100644 --- a/fontmaker/core/ttfparser.go +++ b/fontmaker/core/ttfparser.go @@ -87,7 +87,7 @@ func (t *TTFParser) Kern() *KernTable { return t.kern } -// UnderlinePosition postion of underline +// UnderlinePosition position of underline func (t *TTFParser) UnderlinePosition() int { return t.underlinePosition } diff --git a/gopdf.go b/gopdf.go index 426775c..10d19c0 100644 --- a/gopdf.go +++ b/gopdf.go @@ -916,7 +916,7 @@ func convertNumericToFloat64(size interface{}) (fontSize float64, err error) { } // SetFontWithStyle : set font style support Regular or Underline -// for Bold|Italic should be loaded apropriate fonts with same styles defined +// for Bold|Italic should be loaded appropriate fonts with same styles defined // size MUST be uint*, int* or float64* func (gp *GoPdf) SetFontWithStyle(family string, style int, size interface{}) error { fontSize, err := convertNumericToFloat64(size) @@ -952,7 +952,7 @@ func (gp *GoPdf) SetFontWithStyle(family string, style int, size interface{}) er } // SetFont : set font style support "" or "U" -// for "B" and "I" should be loaded apropriate fonts with same styles defined +// for "B" and "I" should be loaded appropriate fonts with same styles defined // size MUST be uint*, int* or float64* func (gp *GoPdf) SetFont(family string, style string, size interface{}) error { return gp.SetFontWithStyle(family, getConvertedStyle(style), size) diff --git a/pdf_dictionary_obj.go b/pdf_dictionary_obj.go index f2d55a6..5f771e1 100644 --- a/pdf_dictionary_obj.go +++ b/pdf_dictionary_obj.go @@ -19,8 +19,8 @@ var EntrySelectors = []int{ 4, 4, 4, 4, 4, 4, 4, } -// ErrNotSupportShortIndexYet not suport none short index yet -var ErrNotSupportShortIndexYet = errors.New("not suport none short index yet") +// ErrNotSupportShortIndexYet not support none short index yet +var ErrNotSupportShortIndexYet = errors.New("not support none short index yet") // PdfDictionaryObj pdf dictionary object type PdfDictionaryObj struct { diff --git a/pdf_protection.go b/pdf_protection.go index d4cfeb7..6190938 100644 --- a/pdf_protection.go +++ b/pdf_protection.go @@ -34,7 +34,7 @@ type PDFProtection struct { encryptionKey []byte } -// SetProtection set protection infomation +// SetProtection set protection information func (p *PDFProtection) SetProtection(permissions int, userPass []byte, ownerPass []byte) error { return p.setProtection(permissions, userPass, ownerPass) } diff --git a/subset_font_obj.go b/subset_font_obj.go index eabb5ff..15ed8b7 100644 --- a/subset_font_obj.go +++ b/subset_font_obj.go @@ -326,7 +326,7 @@ func (s *SubsetFontObj) GetUnderlineThicknessPx(fontSize float64) float64 { return (float64(s.ttfp.UnderlineThickness()) / float64(s.ttfp.UnitsPerEm())) * fontSize } -// GetUnderlinePosition underline postion. +// GetUnderlinePosition underline position. func (s *SubsetFontObj) GetUnderlinePosition() int { return s.ttfp.UnderlinePosition() } From 80cf5eae12d57bb7988cadafd4c44ecfedc13c9a Mon Sep 17 00:00:00 2001 From: Myagmartseren Date: Fri, 22 Mar 2024 09:59:44 +0800 Subject: [PATCH 2/2] --- gopdf.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gopdf.go b/gopdf.go index 10d19c0..60a38fa 100644 --- a/gopdf.go +++ b/gopdf.go @@ -6,6 +6,7 @@ import ( "compress/zlib" // for constants "fmt" "image" + "image/jpeg" "image/png" "io" "log" @@ -731,7 +732,7 @@ func (gp *GoPdf) Image(picPath string, x float64, y float64, rect *Rect) error { return gp.imageByHolder(imgh, imageOptions) } -func (gp *GoPdf) ImageFrom(img image.Image, x float64, y float64, rect *Rect) error { +func (gp *GoPdf) ImageFrom(img image.Image, x float64, y float64, rect *Rect, format string) error { if img == nil { return errors.New("Invalid image") } @@ -741,7 +742,15 @@ func (gp *GoPdf) ImageFrom(img image.Image, x float64, y float64, rect *Rect) er r, w := io.Pipe() go func() { bw := bufio.NewWriter(w) - err := png.Encode(bw, img) + var err error + switch format { + case "jpeg": + err = jpeg.Encode(bw, img, nil) + case "png": + err = png.Encode(bw, img) + default: + err = errors.New("Unsupported image format") + } bw.Flush() if err != nil { w.CloseWithError(err)