summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--def.go174
-rw-r--r--template.go24
-rw-r--r--template_impl.go6
3 files changed, 195 insertions, 9 deletions
diff --git a/def.go b/def.go
index 4b19a06..3c5fa9d 100644
--- a/def.go
+++ b/def.go
@@ -364,6 +364,180 @@ type FontLoader interface {
Open(name string) (io.Reader, error)
}
+// Pdf defines the interface used for various methods. It is implemented by the
+// main FPDF instance as well as templates.
+type Pdf interface {
+ AddFont(familyStr, styleStr, fileStr string)
+ AddFontFromBytes(familyStr, styleStr string, jsonFileBytes, zFileBytes []byte)
+ AddFontFromReader(familyStr, styleStr string, r io.Reader)
+ AddLayer(name string, visible bool) (layerID int)
+ AddLink() int
+ AddPage()
+ AddPageFormat(orientationStr string, size SizeType)
+ AddSpotColor(nameStr string, c, m, y, k byte)
+ AliasNbPages(aliasStr string)
+ Arc(x, y, rx, ry, degRotate, degStart, degEnd float64, styleStr string)
+ ArcTo(x, y, rx, ry, degRotate, degStart, degEnd float64)
+ BeginLayer(id int)
+ Beziergon(points []PointType, styleStr string)
+ Bookmark(txtStr string, level int, y float64)
+ Cell(w, h float64, txtStr string)
+ CellFormat(w, h float64, txtStr, borderStr string, ln int, alignStr string, fill bool, link int, linkStr string)
+ Cellf(w, h float64, fmtStr string, args ...interface{})
+ Circle(x, y, r float64, styleStr string)
+ ClearError()
+ ClipCircle(x, y, r float64, outline bool)
+ ClipEllipse(x, y, rx, ry float64, outline bool)
+ ClipEnd()
+ ClipPolygon(points []PointType, outline bool)
+ ClipRect(x, y, w, h float64, outline bool)
+ ClipRoundedRect(x, y, w, h, r float64, outline bool)
+ ClipText(x, y float64, txtStr string, outline bool)
+ Close()
+ ClosePath()
+ CreateTemplate(fn func(*Tpl)) Template
+ CreateTemplateCustom(corner PointType, size SizeType, fn func(*Tpl)) Template
+ Curve(x0, y0, cx, cy, x1, y1 float64, styleStr string)
+ CurveBezierCubic(x0, y0, cx0, cy0, cx1, cy1, x1, y1 float64, styleStr string)
+ CurveBezierCubicTo(cx0, cy0, cx1, cy1, x, y float64)
+ CurveCubic(x0, y0, cx0, cy0, x1, y1, cx1, cy1 float64, styleStr string)
+ CurveTo(cx, cy, x, y float64)
+ DrawPath(styleStr string)
+ Ellipse(x, y, rx, ry, degRotate float64, styleStr string)
+ EndLayer()
+ Err() bool
+ Error() error
+ GetAlpha() (alpha float64, blendModeStr string)
+ GetAutoPageBreak() (auto bool, margin float64)
+ GetCellMargin() float64
+ GetConversionRatio() float64
+ GetDrawColor() (int, int, int)
+ GetDrawSpotColor() (name string, c, m, y, k byte)
+ GetFillColor() (int, int, int)
+ GetFillSpotColor() (name string, c, m, y, k byte)
+ GetFontDesc(familyStr, styleStr string) FontDescType
+ GetFontSize() (ptSize, unitSize float64)
+ GetImageInfo(imageStr string) (info *ImageInfoType)
+ GetLineWidth() float64
+ GetMargins() (left, top, right, bottom float64)
+ GetPageSize() (width, height float64)
+ GetPageSizeStr(sizeStr string) (size SizeType)
+ GetStringWidth(s string) float64
+ GetTextColor() (int, int, int)
+ GetTextSpotColor() (name string, c, m, y, k byte)
+ GetX() float64
+ GetXY() (float64, float64)
+ GetY() float64
+ HTMLBasicNew() (html HTMLBasicType)
+ Image(imageNameStr string, x, y, w, h float64, flow bool, tp string, link int, linkStr string)
+ ImageOptions(imageNameStr string, x, y, w, h float64, flow bool, options ImageOptions, link int, linkStr string)
+ ImageTypeFromMime(mimeStr string) (tp string)
+ Line(x1, y1, x2, y2 float64)
+ LineTo(x, y float64)
+ LinearGradient(x, y, w, h float64, r1, g1, b1, r2, g2, b2 int, x1, y1, x2, y2 float64)
+ Link(x, y, w, h float64, link int)
+ LinkString(x, y, w, h float64, linkStr string)
+ Ln(h float64)
+ MoveTo(x, y float64)
+ MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill bool)
+ Ok() bool
+ OpenLayerPane()
+ Output(w io.Writer) error
+ OutputAndClose(w io.WriteCloser) error
+ OutputFileAndClose(fileStr string) error
+ PageNo() int
+ PageSize(pageNum int) (wd, ht float64, unitStr string)
+ PointConvert(pt float64) (u float64)
+ PointToUnitConvert(pt float64) (u float64)
+ Polygon(points []PointType, styleStr string)
+ RadialGradient(x, y, w, h float64, r1, g1, b1, r2, g2, b2 int, x1, y1, x2, y2, r float64)
+ RawWriteBuf(r io.Reader)
+ RawWriteStr(str string)
+ Rect(x, y, w, h float64, styleStr string)
+ RegisterAlias(alias, replacement string)
+ RegisterImage(fileStr, tp string) (info *ImageInfoType)
+ RegisterImageOptions(fileStr string, options ImageOptions) (info *ImageInfoType)
+ RegisterImageOptionsReader(imgName string, options ImageOptions, r io.Reader) (info *ImageInfoType)
+ RegisterImageReader(imgName, tp string, r io.Reader) (info *ImageInfoType)
+ SVGBasicWrite(sb *SVGBasicType, scale float64)
+ SetAcceptPageBreakFunc(fnc func() bool)
+ SetAlpha(alpha float64, blendModeStr string)
+ SetAuthor(authorStr string, isUTF8 bool)
+ SetAutoPageBreak(auto bool, margin float64)
+ SetCatalogSort(flag bool)
+ SetCellMargin(margin float64)
+ SetCompression(compress bool)
+ SetCreationDate(tm time.Time)
+ SetCreator(creatorStr string, isUTF8 bool)
+ SetDashPattern(dashArray []float64, dashPhase float64)
+ SetDisplayMode(zoomStr, layoutStr string)
+ SetDrawColor(r, g, b int)
+ SetDrawSpotColor(nameStr string, tint byte)
+ SetError(err error)
+ SetErrorf(fmtStr string, args ...interface{})
+ SetFillColor(r, g, b int)
+ SetFillSpotColor(nameStr string, tint byte)
+ SetFont(familyStr, styleStr string, size float64)
+ SetFontLoader(loader FontLoader)
+ SetFontLocation(fontDirStr string)
+ SetFontSize(size float64)
+ SetFontUnitSize(size float64)
+ SetFooterFunc(fnc func())
+ SetFooterFuncLpi(fnc func(lastPage bool))
+ SetHeaderFunc(fnc func())
+ SetHeaderFuncMode(fnc func(), homeMode bool)
+ SetHomeXY()
+ SetJavascript(script string)
+ SetKeywords(keywordsStr string, isUTF8 bool)
+ SetLeftMargin(margin float64)
+ SetLineCapStyle(styleStr string)
+ SetLineJoinStyle(styleStr string)
+ SetLineWidth(width float64)
+ SetLink(link int, y float64, page int)
+ SetMargins(left, top, right float64)
+ SetProtection(actionFlag byte, userPassStr, ownerPassStr string)
+ SetRightMargin(margin float64)
+ SetSubject(subjectStr string, isUTF8 bool)
+ SetTextColor(r, g, b int)
+ SetTextSpotColor(nameStr string, tint byte)
+ SetTitle(titleStr string, isUTF8 bool)
+ SetTopMargin(margin float64)
+ SetX(x float64)
+ SetXY(x, y float64)
+ SetXmpMetadata(xmpStream []byte)
+ SetY(y float64)
+ SplitLines(txt []byte, w float64) [][]byte
+ String() string
+ Text(x, y float64, txtStr string)
+ Transform(tm TransformMatrix)
+ TransformBegin()
+ TransformEnd()
+ TransformMirrorHorizontal(x float64)
+ TransformMirrorLine(angle, x, y float64)
+ TransformMirrorPoint(x, y float64)
+ TransformMirrorVertical(y float64)
+ TransformRotate(angle, x, y float64)
+ TransformScale(scaleWd, scaleHt, x, y float64)
+ TransformScaleX(scaleWd, x, y float64)
+ TransformScaleXY(s, x, y float64)
+ TransformScaleY(scaleHt, x, y float64)
+ TransformSkew(angleX, angleY, x, y float64)
+ TransformSkewX(angleX, x, y float64)
+ TransformSkewY(angleY, x, y float64)
+ TransformTranslate(tx, ty float64)
+ TransformTranslateX(tx float64)
+ TransformTranslateY(ty float64)
+ UnicodeTranslatorFromDescriptor(cpStr string) (rep func(string) string)
+ UnitToPointConvert(u float64) (pt float64)
+ UseTemplate(t Template)
+ UseTemplateScaled(t Template, corner PointType, size SizeType)
+ Write(h float64, txtStr string)
+ WriteAligned(width, lineHeight float64, textStr, alignStr string)
+ WriteLinkID(h float64, displayStr string, linkID int)
+ WriteLinkString(h float64, displayStr, targetStr string)
+ Writef(h float64, fmtStr string, args ...interface{})
+}
+
// Fpdf is the principal structure for creating a single PDF document
type Fpdf struct {
page int // current page number
diff --git a/template.go b/template.go
index 9abdf62..d27bc40 100644
--- a/template.go
+++ b/template.go
@@ -24,17 +24,33 @@ import (
// CreateTemplate defines a new template using the current page size.
func (f *Fpdf) CreateTemplate(fn func(*Tpl)) Template {
- return newTpl(PointType{0, 0}, f.curPageSize, f.unitStr, f.fontDirStr, fn, f)
+ return newTpl(PointType{0, 0}, f.curPageSize, f.defOrientation, f.unitStr, f.fontDirStr, fn, f)
}
// CreateTemplateCustom starts a template, using the given bounds.
func (f *Fpdf) CreateTemplateCustom(corner PointType, size SizeType, fn func(*Tpl)) Template {
- return newTpl(corner, size, f.unitStr, f.fontDirStr, fn, f)
+ return newTpl(corner, size, f.defOrientation, f.unitStr, f.fontDirStr, fn, f)
}
-// CreateTemplate creates a template not attached to any document
+// CreateTemplate creates a template that is not attached to any document.
+//
+// This function is deprecated; it incorrectly assumes that a page with a width
+// smaller than its height is oriented in portrait mode, otherwise it assumes
+// landscape mode. This causes problems when placing the template in a master
+// document where this condition does not apply. CreateTpl() is a similar
+// function that lets you specify the orientation to avoid this problem.
func CreateTemplate(corner PointType, size SizeType, unitStr, fontDirStr string, fn func(*Tpl)) Template {
- return newTpl(corner, size, unitStr, fontDirStr, fn, nil)
+ orientationStr := "p"
+ if size.Wd > size.Ht {
+ orientationStr = "l"
+ }
+
+ return CreateTpl(corner, size, orientationStr, unitStr, fontDirStr, fn)
+}
+
+// CreateTpl creates a template not attached to any document
+func CreateTpl(corner PointType, size SizeType, orientationStr, unitStr, fontDirStr string, fn func(*Tpl)) Template {
+ return newTpl(corner, size, orientationStr, unitStr, fontDirStr, fn, nil)
}
// UseTemplate adds a template to the current page or another template,
diff --git a/template_impl.go b/template_impl.go
index 9c690c1..1a91112 100644
--- a/template_impl.go
+++ b/template_impl.go
@@ -24,11 +24,7 @@ import (
*/
// newTpl creates a template, copying graphics settings from a template if one is given
-func newTpl(corner PointType, size SizeType, unitStr, fontDirStr string, fn func(*Tpl), copyFrom *Fpdf) Template {
- orientationStr := "p"
- if size.Wd > size.Ht {
- orientationStr = "l"
- }
+func newTpl(corner PointType, size SizeType, orientationStr, unitStr, fontDirStr string, fn func(*Tpl), copyFrom *Fpdf) Template {
sizeStr := ""
fpdf := fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr, size)