|
|
@ -16,10 +16,11 @@ |
|
|
|
|
|
|
|
package gofpdf |
|
|
|
|
|
|
|
// Version: 1.7
|
|
|
|
// Version: 1.7a1
|
|
|
|
// Date: 2011-06-18
|
|
|
|
// Author: Olivier PLATHEY
|
|
|
|
// Port to Go: Kurt Jung, 2013-07-15
|
|
|
|
// Additions: Klaus Wendel, archium GmbH/Gera, 2021-03-02
|
|
|
|
|
|
|
|
import ( |
|
|
|
"bytes" |
|
|
@ -57,7 +58,7 @@ func (b *fmtBuffer) printf(fmtStr string, args ...interface{}) { |
|
|
|
b.Buffer.WriteString(fmt.Sprintf(fmtStr, args...)) |
|
|
|
} |
|
|
|
|
|
|
|
func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) (f *Fpdf) { |
|
|
|
func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType, density float64) (f *Fpdf) { |
|
|
|
f = new(Fpdf) |
|
|
|
if orientationStr == "" { |
|
|
|
orientationStr = "p" |
|
|
@ -74,6 +75,11 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) |
|
|
|
if fontDirStr == "" { |
|
|
|
fontDirStr = "." |
|
|
|
} |
|
|
|
// Page density in dpi
|
|
|
|
if density == 0.0 { |
|
|
|
density = 72.0 |
|
|
|
} |
|
|
|
|
|
|
|
f.page = 0 |
|
|
|
f.n = 2 |
|
|
|
f.pages = make([]*bytes.Buffer, 0, 8) |
|
|
@ -126,11 +132,11 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) |
|
|
|
case "pt", "point": |
|
|
|
f.k = 1.0 |
|
|
|
case "mm": |
|
|
|
f.k = 72.0 / 25.4 |
|
|
|
f.k = density / 25.4 |
|
|
|
case "cm": |
|
|
|
f.k = 72.0 / 2.54 |
|
|
|
f.k = density / 2.54 |
|
|
|
case "in", "inch": |
|
|
|
f.k = 72.0 |
|
|
|
f.k = density |
|
|
|
default: |
|
|
|
f.err = fmt.Errorf("incorrect unit %s", unitStr) |
|
|
|
return |
|
|
@ -3006,7 +3012,14 @@ func (f *Fpdf) ImageTypeFromMime(mimeStr string) (tp string) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func (f *Fpdf) imageOut(info *ImageInfoType, x, y, w, h float64, allowNegativeX, flow bool, link int, linkStr string) { |
|
|
|
func (f *Fpdf) imageOut(info *ImageInfoType, x, y, w, h float64, allowNegativeX, flow bool, link int, linkStr string, density float64) { |
|
|
|
/* |
|
|
|
// density in dpi
|
|
|
|
if density == 0.0 { |
|
|
|
density = 72.0 |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
// Automatic width and height calculation if needed
|
|
|
|
if w == 0 && h == 0 { |
|
|
|
// Put image at 96 dpi
|
|
|
@ -3024,10 +3037,10 @@ func (f *Fpdf) imageOut(info *ImageInfoType, x, y, w, h float64, allowNegativeX, |
|
|
|
h = -info.dpi |
|
|
|
} |
|
|
|
if w < 0 { |
|
|
|
w = -info.w * 72.0 / w / f.k |
|
|
|
w = -info.w * density / w / f.k |
|
|
|
} |
|
|
|
if h < 0 { |
|
|
|
h = -info.h * 72.0 / h / f.k |
|
|
|
h = -info.h * density / h / f.k |
|
|
|
} |
|
|
|
if w == 0 { |
|
|
|
w = h * info.w / info.h |
|
|
@ -3110,7 +3123,7 @@ func (f *Fpdf) Image(imageNameStr string, x, y, w, h float64, flow bool, tp stri |
|
|
|
// If link refers to an internal page anchor (that is, it is non-zero; see
|
|
|
|
// AddLink()), the image will be a clickable internal link. Otherwise, if
|
|
|
|
// linkStr specifies a URL, the image will be a clickable external link.
|
|
|
|
func (f *Fpdf) ImageOptions(imageNameStr string, x, y, w, h float64, flow bool, options ImageOptions, link int, linkStr string) { |
|
|
|
func (f *Fpdf) ImageOptions(imageNameStr string, x, y, w, h float64, flow bool, options ImageOptions, link int, linkStr string, density float64) { |
|
|
|
if f.err != nil { |
|
|
|
return |
|
|
|
} |
|
|
@ -3118,7 +3131,7 @@ func (f *Fpdf) ImageOptions(imageNameStr string, x, y, w, h float64, flow bool, |
|
|
|
if f.err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
f.imageOut(info, x, y, w, h, options.AllowNegativePosition, flow, link, linkStr) |
|
|
|
f.imageOut(info, x, y, w, h, options.AllowNegativePosition, flow, link, linkStr, density) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|