summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@gmail.com>2015-07-07 11:10:07 -0400
committerKurt Jung <kurt.w.jung@gmail.com>2015-07-07 11:10:07 -0400
commitb09a1c5eef4ec4c053c0ec22da4e9f147aae73e4 (patch)
tree182a04fddfa52da1ad5c5c82d8a9338744992ed0
parent8e1fd6fdd35517c1035ff353ca3cdc1e88bb82f9 (diff)
Convert sequential examples to ones that are bound to gofpdf methods.
-rw-r--r--doc.go25
-rw-r--r--fpdf.go79
-rw-r--r--fpdf_test.go338
-rw-r--r--fpdftrans.go34
-rw-r--r--htmlbasic.go2
-rw-r--r--layer.go2
-rw-r--r--svgbasic.go3
-rw-r--r--util.go2
8 files changed, 247 insertions, 238 deletions
diff --git a/doc.go b/doc.go
index b25875d..edfa000 100644
--- a/doc.go
+++ b/doc.go
@@ -95,15 +95,15 @@ Later, to receive updates, run
Quick Start
-The following Go code generates a simple PDF.
+The following Go code generates a simple PDF and writes it to standard output.
- pdf := gofpdf.New("P", "mm", "A4", "../font")
+ pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "B", 16)
pdf.Cell(40, 10, "Hello, world")
pdf.Output(os.Stdout)
-See the tutorials in the fpdf_test.go file (shown as examples in this
+See the functions in the fpdf_test.go file (shown as examples in this
documentation) for more advanced PDF examples.
Errors
@@ -138,17 +138,14 @@ that are passed to them; in these cases additional methods have been exported
to provide similar functionality. Font definition files are produced in JSON
rather than PHP.
-Tutorials
+Example PDFs
-A side effect of running "go test" is the production of the tutorial PDFs.
-These can be found in the gofpdf/pdf directory after the tests complete.
+A side effect of running "go test" is the production of a number of example
+PDFs. These can be found in the gofpdf/pdf directory after the tests complete.
-Please note that these tutorials run in the context of a test. In order run an
+Please note that these examples run in the context of a test. In order run an
example as a standalone application, you'll need to examine fpdf_test.go for
-some helper routines, for example docWriter and strDelimit. In particular,
-docWriter is used as an argument to OutputAndClose in order to reduce the
-boilerplate in each example. In practice, you may be better served by calling
-OutputFileAndClose().
+some helper routines, for example exampleFilename and summary.
Nonstandard Fonts
@@ -166,9 +163,9 @@ the font subdirectory and run the command as in the following example.
./makefont --embed --enc=../font/cp1252.map --dst=../font ../font/calligra.ttf
In your PDF generation code, call AddFont() to load the font and, as with the
-standard fonts, SetFont() to begin using it. See tutorial 7 for an example.
-Good sources of free, open-source fonts include http://www.google.com/fonts/
-and http://dejavu-fonts.org/.
+standard fonts, SetFont() to begin using it. Most examples, including the
+package example, demonstrate this method. Good sources of free, open-source
+fonts include http://www.google.com/fonts/ and http://dejavu-fonts.org/.
Roadmap
diff --git a/fpdf.go b/fpdf.go
index ea7c373..0fcc226 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -180,8 +180,8 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType)
// NewCustom returns a pointer to a new Fpdf instance. Its methods are
// subsequently called to produce a single PDF document. NewCustom() is an
-// alternative to New() that provides additional customization. This function
-// is demonstrated in tutorial 15.
+// alternative to New() that provides additional customization. The PageSize()
+// example demonstrates this method.
func NewCustom(init *InitType) (f *Fpdf) {
return fpdfNew(init.OrientationStr, init.UnitStr, init.SizeStr, init.FontDirStr, init.Size)
}
@@ -318,8 +318,6 @@ func (f *Fpdf) SetFontLocation(fontDirStr string) {
// the named font resources when AddFont() is called. If this operation fails,
// an attempt is made to load the resources from the configured font directory
// (see SetFontLocation()).
-//
-// See tutorial 29 for an example of this method.
func (f *Fpdf) SetFontLoader(loader FontLoader) {
f.fontLoader = loader
}
@@ -472,7 +470,7 @@ func (f *Fpdf) SetCreator(creatorStr string, isUTF8 bool) {
// AliasNbPages defines an alias for the total number of pages. It will be
// substituted as the document is closed. An empty string is replaced with the
-// string "{nb}". This method is demonstrated in tutorial 2.
+// string "{nb}".
//
// See the example for AddPage() for a demonstration of this method.
func (f *Fpdf) AliasNbPages(aliasStr string) {
@@ -528,7 +526,7 @@ func (f *Fpdf) Close() {
// established in New(). These return values are followed by the unit of
// measure itself. If pageNum is zero or otherwise out of bounds, it returns
// the default page size, that is, the size of the page that would be added by
-// AddPage(). This function is demonstrated in tutorial 15.
+// AddPage().
func (f *Fpdf) PageSize(pageNum int) (wd, ht float64, unitStr string) {
sz, ok := f.pageSizes[pageNum]
if ok {
@@ -546,7 +544,7 @@ func (f *Fpdf) PageSize(pageNum int) (wd, ht float64, unitStr string) {
//
// size specifies the size of the new page in the units established in New().
//
-// This function is demonstrated in tutorial 15.
+// The PageSize() example demonstrates this method.
func (f *Fpdf) AddPageFormat(orientationStr string, size SizeType) {
if f.err != nil {
return
@@ -829,7 +827,7 @@ func (f *Fpdf) SetLineJoinStyle(styleStr string) {
// dash pattern is retained from page to page. Call this method with an empty
// array to restore solid line drawing.
//
-// See tutorial 28 for an example of this function.
+// The Beziergon() example demonstrates this method.
func (f *Fpdf) SetDashPattern(dashArray []float64, dashPhase float64) {
scaled := make([]float64, len(dashArray))
for i, value := range dashArray {
@@ -908,8 +906,6 @@ func (f *Fpdf) Rect(x, y, w, h float64, styleStr string) {
// outlined and filled. An empty string will be replaced with "D". Drawing uses
// the current draw color and line width centered on the circle's perimeter.
// Filling uses the current fill color.
-//
-// See tutorial 11 for an example of this function.
func (f *Fpdf) Circle(x, y, r float64, styleStr string) {
f.Ellipse(x, y, r, r, 0, styleStr)
}
@@ -925,7 +921,7 @@ func (f *Fpdf) Circle(x, y, r float64, styleStr string) {
// the current draw color and line width centered on the ellipse's perimeter.
// Filling uses the current fill color.
//
-// See tutorial 11 for an example of this function.
+// The Circle() example demonstrates this method.
func (f *Fpdf) Ellipse(x, y, rx, ry, degRotate float64, styleStr string) {
f.arc(x, y, rx, ry, degRotate, 0, 360, styleStr, false)
}
@@ -939,8 +935,6 @@ func (f *Fpdf) Ellipse(x, y, rx, ry, degRotate float64, styleStr string) {
// outlined and filled. An empty string will be replaced with "D". Drawing uses
// the current draw color and line width centered on the ellipse's perimeter.
// Filling uses the current fill color.
-//
-// See tutorial 25 for an example of this function.
func (f *Fpdf) Polygon(points []PointType, styleStr string) {
if len(points) > 2 {
for j, pt := range points {
@@ -966,8 +960,6 @@ func (f *Fpdf) Polygon(points []PointType, styleStr string) {
// outlined and filled. An empty string will be replaced with "D". Drawing uses
// the current draw color and line width centered on the ellipse's perimeter.
// Filling uses the current fill color.
-//
-// See tutorial 28 for an example of this function.
func (f *Fpdf) Beziergon(points []PointType, styleStr string) {
// Thanks, Robert Lillack, for contributing this function.
@@ -1013,7 +1005,7 @@ func (f *Fpdf) curve(cx0, cy0, cx1, cy1, x, y float64) {
// the current draw color, line width, and cap style centered on the curve's
// path. Filling uses the current fill color.
//
-// See tutorial 11 for an example of this function.
+// The Circle() example demonstrates this method.
func (f *Fpdf) Curve(x0, y0, cx, cy, x1, y1 float64, styleStr string) {
f.point(x0, y0)
f.outf("%.5f %.5f %.5f %.5f v %s", cx*f.k, (f.h-cy)*f.k, x1*f.k, (f.h-y1)*f.k,
@@ -1045,7 +1037,7 @@ func (f *Fpdf) CurveCubic(x0, y0, cx0, cy0, x1, y1, cx1, cy1 float64, styleStr s
// This routine performs the same function as CurveCubic() but uses standard
// argument order.
//
-// See tutorial 11 for examples of this function.
+// The Circle() example demonstrates this method.
func (f *Fpdf) CurveBezierCubic(x0, y0, cx0, cy0, cx1, cy1, x1, y1 float64, styleStr string) {
f.point(x0, y0)
f.outf("%.5f %.5f %.5f %.5f %.5f %.5f c %s", cx0*f.k, (f.h-cy0)*f.k,
@@ -1065,7 +1057,7 @@ func (f *Fpdf) CurveBezierCubic(x0, y0, cx0, cy0, cx1, cy1, x1, y1 float64, styl
// the current draw color, line width, and cap style centered on the arc's
// path. Filling uses the current fill color.
//
-// See tutorial 11 for an example of this function.
+// The Circle() example demonstrates this method.
func (f *Fpdf) Arc(x, y, rx, ry, degRotate, degStart, degEnd float64, styleStr string) {
f.arc(x, y, rx, ry, degRotate, degStart, degEnd, styleStr, false)
}
@@ -1083,8 +1075,6 @@ func (f *Fpdf) Arc(x, y, rx, ry, degRotate, degStart, degEnd float64, styleStr s
//
// To reset normal rendering after applying a blending mode, call this method
// with alpha set to 1.0 and blendModeStr set to "Normal".
-//
-// See tutorial 12 for an example of this function, including samples of each blending mode.
func (f *Fpdf) SetAlpha(alpha float64, blendModeStr string) {
if f.err != nil {
return
@@ -1153,8 +1143,6 @@ func (f *Fpdf) gradient(tp int, r1, g1, b1 int, r2, g2, b2 int, x1, y1 float64,
// anchored on the rectangle edge. Color 1 is used up to the origin of the
// vector and color 2 is used beyond the vector's end point. Between the points
// the colors are gradually blended.
-//
-// See tutorial 13 for an example of this function.
func (f *Fpdf) LinearGradient(x, y, w, h float64, r1, g1, b1 int, r2, g2, b2 int, x1, y1, x2, y2 float64) {
f.gradientClipStart(x, y, w, h)
f.gradient(2, r1, g1, b1, r2, g2, b2, x1, y1, x2, y2, 0)
@@ -1178,7 +1166,7 @@ func (f *Fpdf) LinearGradient(x, y, w, h float64, r1, g1, b1 int, r2, g2, b2 int
// center do not necessarily have to coincide, but the origin must be within
// the circle to avoid rendering problems.
//
-// See tutorial 13 for an example of this function.
+// The LinearGradient() example demonstrates this method.
func (f *Fpdf) RadialGradient(x, y, w, h float64, r1, g1, b1 int, r2, g2, b2 int, x1, y1, x2, y2, r float64) {
f.gradientClipStart(x, y, w, h)
f.gradient(3, r1, g1, b1, r2, g2, b2, x1, y1, x2, y2, r)
@@ -1193,7 +1181,7 @@ func (f *Fpdf) RadialGradient(x, y, w, h float64, r1, g1, b1 int, r2, g2, b2 int
// Image(), LinearGradient(), etc) will be clipped by the specified rectangle.
// Call ClipEnd() to restore unclipped operations.
//
-// See tutorial 14 for an example of this function.
+// This ClipText() example demonstrates this method.
func (f *Fpdf) ClipRect(x, y, w, h float64, outline bool) {
f.clipNest++
f.outf("q %.2f %.2f %.2f %.2f re W %s", x*f.k, (f.h-y)*f.k, w*f.k, -h*f.k, strIf(outline, "S", "n"))
@@ -1207,8 +1195,6 @@ func (f *Fpdf) ClipRect(x, y, w, h float64, outline bool) {
// will be shown. After calling this method, all rendering operations (for
// example, Image(), LinearGradient(), etc) will be clipped. Call ClipEnd() to
// restore unclipped operations.
-//
-// See tutorial 14 for an example of this function.
func (f *Fpdf) ClipText(x, y float64, txtStr string, outline bool) {
f.clipNest++
f.outf("q BT %.5f %.5f Td %d Tr (%s) Tj ET", x*f.k, (f.h-y)*f.k, intIf(outline, 5, 7), f.escape(txtStr))
@@ -1229,7 +1215,7 @@ func (f *Fpdf) clipArc(x1, y1, x2, y2, x3, y3 float64) {
// LinearGradient(), etc) will be clipped by the specified rectangle. Call
// ClipEnd() to restore unclipped operations.
//
-// See tutorial 14 for an example of this function.
+// This ClipText() example demonstrates this method.
func (f *Fpdf) ClipRoundedRect(x, y, w, h, r float64, outline bool) {
f.clipNest++
k := f.k
@@ -1263,7 +1249,7 @@ func (f *Fpdf) ClipRoundedRect(x, y, w, h, r float64, outline bool) {
// Image(), LinearGradient(), etc) will be clipped by the specified ellipse.
// Call ClipEnd() to restore unclipped operations.
//
-// See tutorial 14 for an example of this function.
+// This ClipText() example demonstrates this method.
func (f *Fpdf) ClipEllipse(x, y, rx, ry float64, outline bool) {
f.clipNest++
lx := (4.0 / 3.0) * rx * (math.Sqrt2 - 1)
@@ -1297,7 +1283,7 @@ func (f *Fpdf) ClipEllipse(x, y, rx, ry float64, outline bool) {
// operations (for example, Image(), LinearGradient(), etc) will be clipped by
// the specified circle. Call ClipEnd() to restore unclipped operations.
//
-// See tutorial 14 for an example of this function.
+// The ClipText() example demonstrates this method.
func (f *Fpdf) ClipCircle(x, y, r float64, outline bool) {
f.ClipEllipse(x, y, r, r, outline)
}
@@ -1312,7 +1298,7 @@ func (f *Fpdf) ClipCircle(x, y, r float64, outline bool) {
// LinearGradient(), etc) will be clipped by the specified polygon. Call
// ClipEnd() to restore unclipped operations.
//
-// See tutorial 14 for an example of this function.
+// The ClipText() example demonstrates this method.
func (f *Fpdf) ClipPolygon(points []PointType, outline bool) {
f.clipNest++
var s fmtBuffer
@@ -1331,7 +1317,7 @@ func (f *Fpdf) ClipPolygon(points []PointType, outline bool) {
// ClipPolygon(). Clipping operations can be nested. The document cannot be
// successfully output while a clipping operation is active.
//
-// See tutorial 14 for an example of this function.
+// The ClipText() example demonstrates this method.
func (f *Fpdf) ClipEnd() {
if f.err == nil {
if f.clipNest > 0 {
@@ -1363,8 +1349,6 @@ func (f *Fpdf) ClipEnd() {
// fileStr specifies the base name with ".json" extension of the font
// definition file to be added. The file will be loaded from the font directory
// specified in the call to New() or SetFontLocation().
-//
-// See tutorial 7 for an example of this function.
func (f *Fpdf) AddFont(familyStr, styleStr, fileStr string) {
if fileStr == "" {
fileStr = strings.Replace(familyStr, " ", "", -1) + strings.ToLower(styleStr) + ".json"
@@ -1615,8 +1599,6 @@ func (f *Fpdf) LinkString(x, y, w, h float64, linkStr string) {
// the outline; 0 is the top level, 1 is just below, and so on. y specifies the
// vertical position of the bookmark destination in the current page; -1
// indicates the current position.
-//
-// See tutorial 16 for an bookmark example.
func (f *Fpdf) Bookmark(txtStr string, level int, y float64) {
if y == -1 {
y = f.y
@@ -1690,8 +1672,6 @@ func (f *Fpdf) SetAcceptPageBreakFunc(fnc func() bool) {
//
// linkStr is a target URL or empty for no external link. A non--zero value for
// link takes precedence over linkStr.
-//
-// See tutorial 21 for a demonstration of text alignment within a cell.
func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int, alignStr string, fill bool, link int, linkStr string) {
// dbg("CellFormat. h = %.2f, borderStr = %s", h, borderStr)
if f.err != nil {
@@ -1836,8 +1816,6 @@ func (f *Fpdf) Cellf(w, h float64, fmtStr string, args ...interface{}) {
//
// You can use MultiCell if you want to print a text on several lines in a
// simple way.
-//
-// See tutorial 19 for an example of this function.
func (f *Fpdf) SplitLines(txt []byte, w float64) [][]byte {
// Function contributed by Bruno Michel
lines := [][]byte{}
@@ -2249,9 +2227,6 @@ func (f *Fpdf) Image(imageNameStr string, x, y, w, h float64, flow bool, tp stri
// case.
//
// See Image() for restrictions on the image and the "tp" parameters.
-//
-// See tutorial 27 for an example of how this function can be used to load an
-// image from the web.
func (f *Fpdf) RegisterImageReader(imgName, tp string, r io.Reader) (info *ImageInfoType) {
// Thanks, Ivan Daniluk, for generalizing this code to use the Reader interface.
if f.err != nil {
@@ -2295,8 +2270,6 @@ func (f *Fpdf) RegisterImageReader(imgName, tp string, r io.Reader) (info *Image
// page. Note that Image() calls this function, so this function is only
// necessary if you need information about the image before placing it. See
// Image() for restrictions on the image and the "tp" parameters.
-//
-// See tutorial 18 for an example of this function.
func (f *Fpdf) RegisterImage(fileStr, tp string) (info *ImageInfoType) {
info, ok := f.images[fileStr]
if ok {
@@ -2396,8 +2369,6 @@ func (f *Fpdf) SetXY(x, y float64) {
// full access to the document regardless of the actionFlag value. An empty
// string for this argument will be replaced with a random value, effectively
// prohibiting full access to the document.
-//
-// See tutorial 24 for an example of this function.
func (f *Fpdf) SetProtection(actionFlag byte, userPassStr, ownerPassStr string) {
if f.err != nil {
return
@@ -2418,7 +2389,7 @@ func (f *Fpdf) OutputAndClose(w io.WriteCloser) error {
// writes the PDF document to it. This method will close f and the newly
// written file, even if an error is detected and no document is produced.
//
-// This function is demonstrated in tutorial 1.
+// Most examples demonstrate the use of this method.
func (f *Fpdf) OutputFileAndClose(fileStr string) error {
if f.err == nil {
pdfFile, err := os.Create(fileStr)
@@ -3473,8 +3444,6 @@ func (f *Fpdf) enddoc() {
// using the path drawing routines rather than multiple Fpdf.Line is
// that PDF creates nice line joins at the angles, rather than just
// overlaying the lines.
-//
-// See tutorial 30 for an example of this function.
func (f *Fpdf) MoveTo(x, y float64) {
f.point(x, y)
f.x, f.y = x, y
@@ -3484,7 +3453,7 @@ func (f *Fpdf) MoveTo(x, y float64) {
// becomes the new stylus location. Note that this only creates the line in
// the path; it does not actually draw the line on the page.
//
-// See tutorial 30 for an example of this function.
+// The MoveTo() example demonstrates this method.
func (f *Fpdf) LineTo(x, y float64) {
f.outf("%.2f %.2f l", x*f.k, (f.h-y)*f.k)
f.x, f.y = x, y
@@ -3497,7 +3466,7 @@ func (f *Fpdf) LineTo(x, y float64) {
// point. At the end point, the curve is tangent to the straight line between
// the end point and the control point.
//
-// See tutorial 30 for an example of this function.
+// The MoveTo() example demonstrates this method.
func (f *Fpdf) CurveTo(cx, cy, x, y float64) {
f.outf("%.5f %.5f %.5f %.5f v", cx*f.k, (f.h-cy)*f.k, x*f.k, (f.h-y)*f.k)
f.x, f.y = x, y
@@ -3511,7 +3480,7 @@ func (f *Fpdf) CurveTo(cx, cy, x, y float64) {
// the curve is tangent to the straight line between the end point and the
// control point (cx1, cy1).
//
-// See tutorial 30 for examples of this function.
+// The MoveTo() example demonstrates this method.
func (f *Fpdf) CurveBezierCubicTo(cx0, cy0, cx1, cy1, x, y float64) {
f.curve(cx0, cy0, cx1, cy1, x, y)
f.x, f.y = x, y
@@ -3521,7 +3490,7 @@ func (f *Fpdf) CurveBezierCubicTo(cx0, cy0, cx1, cy1, x, y float64) {
// (if not the same) and mark the path as closed so the first and last lines
// join nicely.
//
-// See tutorial 30 for an example of this function.
+// The MoveTo() example demonstrates this method.
func (f *Fpdf) ClosePath() {
f.outf("h")
}
@@ -3543,7 +3512,7 @@ func (f *Fpdf) ClosePath() {
// centered on the
// path. Filling uses the current fill color.
//
-// See tutorial 30 for an example of this function.
+// The MoveTo() example demonstrates this method.
func (f *Fpdf) DrawPath(styleStr string) {
f.outf(fillDrawOp(styleStr))
}
@@ -3562,7 +3531,7 @@ func (f *Fpdf) DrawPath(styleStr string) {
// the current draw color, line width, and cap style centered on the arc's
// path. Filling uses the current fill color.
//
-// See tutorial 30 for an example of this function.
+// The MoveTo() example demonstrates this method.
func (f *Fpdf) ArcTo(x, y, rx, ry, degRotate, degStart, degEnd float64) {
f.arc(x, y, rx, ry, degRotate, degStart, degEnd, "", true)
}
diff --git a/fpdf_test.go b/fpdf_test.go
index da4b930..c2886fb 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -41,57 +41,17 @@ const (
cnExampleDir = cnGofpdfDir + "/pdf"
)
-type nullWriter struct {
+func init() {
+ cleanup()
}
-func (nw *nullWriter) Write(p []byte) (n int, err error) {
- n = len(p)
- return
-}
-
-func (nw *nullWriter) Close() (err error) {
- return
-}
-
-type pdfWriter struct {
- pdf *gofpdf.Fpdf
- fl *os.File
- idx int
-}
-
-func (pw *pdfWriter) Write(p []byte) (n int, err error) {
- if pw.pdf.Ok() {
- return pw.fl.Write(p)
- }
- return
-}
-
-func (pw *pdfWriter) Close() (err error) {
- if pw.fl != nil {
- pw.fl.Close()
- pw.fl = nil
- }
- if pw.pdf.Ok() {
- fmt.Printf("Successfully generated pdf/tutorial%02d.pdf\n", pw.idx)
- } else {
- fmt.Printf("%s\n", pw.pdf.Error())
- }
- return
-}
-
-func docWriter(pdf *gofpdf.Fpdf, idx int) *pdfWriter {
- pw := new(pdfWriter)
- pw.pdf = pdf
- pw.idx = idx
- if pdf.Ok() {
- var err error
- fileStr := fmt.Sprintf("%s/pdf/tutorial%02d.pdf", cnGofpdfDir, idx)
- pw.fl, err = os.Create(fileStr)
- if err != nil {
- pdf.SetErrorf("Error opening output file %s", fileStr)
+func cleanup() {
+ filepath.Walk(cnExampleDir, func(path string, info os.FileInfo, err error) (reterr error) {
+ if path[len(path)-4:] == ".pdf" {
+ os.Remove(path)
}
- }
- return pw
+ return
+ })
}
func imageFile(fileStr string) string {
@@ -381,8 +341,8 @@ func ExampleFpdf_SetLeftMargin() {
// Successfully generated pdf/multicolumn.pdf
}
-// Various table styles
-func ExampleFpdf_tutorial05() {
+// This example demonstrates various table styles.
+func ExampleFpdf_CellFormat_1() {
pdf := gofpdf.New("P", "mm", "A4", "")
type countryType struct {
nameStr, capitalStr, areaStr, popStr string
@@ -496,14 +456,16 @@ func ExampleFpdf_tutorial05() {
improvedTable()
pdf.AddPage()
fancyTable()
- pdf.OutputAndClose(docWriter(pdf, 5))
+ fileStr := exampleFilename("tables")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial05.pdf
+ // Successfully generated pdf/tables.pdf
}
// This example demonstrates internal and external links with and without basic
// HTML.
-func ExampleFpdf_tutorial06() {
+func ExampleFpdf_HTMLBasicNew() {
pdf := gofpdf.New("P", "mm", "A4", "")
// First page: manual local link
pdf.AddPage()
@@ -527,25 +489,29 @@ func ExampleFpdf_tutorial06() {
`<a href="http://www.fpdf.org">www.fpdf.org</a>, or on an image: click on the logo.`
html := pdf.HTMLBasicNew()
html.Write(lineHt, htmlStr)
- pdf.OutputAndClose(docWriter(pdf, 6))
+ fileStr := exampleFilename("html")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial06.pdf
+ // Successfully generated pdf/html.pdf
}
-// Non-standard font
-func ExampleFpdf_tutorial07() {
+// This example demonstrates the use of a non-standard font.
+func ExampleFpdf_AddFont() {
pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
pdf.AddFont("Calligrapher", "", "calligra.json")
pdf.AddPage()
pdf.SetFont("Calligrapher", "", 35)
pdf.Cell(0, 10, "Enjoy new fonts with FPDF!")
- pdf.OutputAndClose(docWriter(pdf, 7))
+ fileStr := exampleFilename("font")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial07.pdf
+ // Successfully generated pdf/font.pdf
}
-// Various image types
-func ExampleFpdf_tutorial08() {
+// This example demonstrates how images are included in documents.
+func ExampleFpdf_Image() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "", 11)
@@ -559,13 +525,15 @@ func ExampleFpdf_tutorial08() {
pdf.Text(50, 110, "logo-rgb.png")
pdf.Image(imageFile("logo.jpg"), 10, 130, 30, 0, false, "", 0, "")
pdf.Text(50, 140, "logo.jpg")
- pdf.OutputAndClose(docWriter(pdf, 8))
+ fileStr := exampleFilename("image")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial08.pdf
+ // Successfully generated pdf/image.pdf
}
-// Landscape mode with logos
-func ExampleFpdf_tutorial09() {
+// This examples demonstrates Landscape mode with images.
+func ExampleFpdf_SetAcceptPageBreakFunc() {
var y0 float64
var crrntCol int
loremStr := lorem()
@@ -616,13 +584,15 @@ func ExampleFpdf_tutorial09() {
pdf.MultiCell(colWd, 5, loremStr, "", "", false)
pdf.Ln(-1)
}
- pdf.OutputAndClose(docWriter(pdf, 9))
+ fileStr := exampleFilename("landscape")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial09.pdf
+ // Successfully generated pdf/landscape.pdf
}
-// Test the corner cases as reported by the gocov tool
-func ExampleFpdf_tutorial10() {
+// This examples tests corner cases as reported by the gocov tool.
+func ExampleFpdf_SetKeywords() {
gofpdf.MakeFont(fontFile("calligra.ttf"), fontFile("cp1252.map"), cnFontDir, nil, true)
pdf := gofpdf.New("", "", "", "")
pdf.SetFontLocation(cnFontDir)
@@ -635,13 +605,15 @@ func ExampleFpdf_tutorial10() {
pdf.AddPage()
pdf.SetFont("Calligrapher", "", 16)
pdf.Writef(5, "\x95 %s \x95", pdf)
- pdf.OutputAndClose(docWriter(pdf, 10))
+ fileStr := exampleFilename("keywords")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial10.pdf
+ // Successfully generated pdf/keywords.pdf
}
-// Geometric figures
-func ExampleFpdf_tutorial11() {
+// This example demonstrates the construction of various geometric figures,
+func ExampleFpdf_Circle() {
const (
thin = 0.2
thick = 3.0
@@ -716,13 +688,15 @@ func ExampleFpdf_tutorial11() {
pdf.SetLineWidth(thin)
pdf.SetLineCapStyle("butt")
- pdf.OutputAndClose(docWriter(pdf, 11))
+ fileStr := exampleFilename("figures")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial11.pdf
+ // Successfully generated pdf/figures.pdf
}
-// Transparency
-func ExampleFpdf_tutorial12() {
+// This example demonstrates alpha transparency.
+func ExampleFpdf_SetAlpha() {
const (
gapX = 10.0
gapY = 9.0
@@ -765,13 +739,15 @@ func ExampleFpdf_tutorial12() {
}
y += rectH + gapY
}
- pdf.OutputAndClose(docWriter(pdf, 12))
+ fileStr := exampleFilename("transparency")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial12.pdf
+ // Successfully generated pdf/transparency.pdf
}
-// Gradients
-func ExampleFpdf_tutorial13() {
+// This example deomstrates various gradients.
+func ExampleFpdf_LinearGradient() {
pdf := gofpdf.New("", "", "", "")
pdf.SetFont("Helvetica", "", 12)
pdf.AddPage()
@@ -784,13 +760,15 @@ func ExampleFpdf_tutorial13() {
pdf.Rect(20, 120, 75, 75, "D")
pdf.RadialGradient(115, 120, 75, 75, 220, 220, 250, 80, 80, 220, 0.25, 0.75, 0.75, 0.75, 0.75)
pdf.Rect(115, 120, 75, 75, "D")
- pdf.OutputAndClose(docWriter(pdf, 13))
+ fileStr := exampleFilename("gradient")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial13.pdf
+ // Successfully generated pdf/gradient.pdf
}
-// Clipping examples
-func ExampleFpdf_tutorial14() {
+// This example demonstrates clipping.
+func ExampleFpdf_ClipText() {
pdf := gofpdf.New("", "", "", "")
y := 10.0
pdf.AddPage()
@@ -844,13 +822,15 @@ func ExampleFpdf_tutorial14() {
pdf.MultiCell(130, 5, lorem(), "", "", false)
pdf.ClipEnd()
- pdf.OutputAndClose(docWriter(pdf, 14))
+ fileStr := exampleFilename("clip")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial14.pdf
+ // Successfully generated pdf/clip.pdf
}
-// Page size example
-func ExampleFpdf_tutorial15() {
+// This example generates a PDF document with various page sizes.
+func ExampleFpdf_PageSize() {
pdf := gofpdf.NewCustom(&gofpdf.InitType{
UnitStr: "in",
Size: gofpdf.SizeType{Wd: 6, Ht: 6},
@@ -871,17 +851,19 @@ func ExampleFpdf_tutorial15() {
wd, ht, u := pdf.PageSize(j)
fmt.Printf("%d: %6.2f %s, %6.2f %s\n", j, wd, u, ht, u)
}
- pdf.OutputAndClose(docWriter(pdf, 15))
+ fileStr := exampleFilename("pagesize")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
// 0: 6.00 in, 6.00 in
// 1: 12.00 in, 3.00 in
// 2: 6.00 in, 6.00 in
// 3: 3.00 in, 12.00 in
- // Successfully generated pdf/tutorial15.pdf
+ // Successfully generated pdf/pagesize.pdf
}
-// Bookmark test
-func ExampleFpdf_tutorial16() {
+// This example demonstrates the Bookmark method.
+func ExampleFpdf_Bookmark() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "", 15)
@@ -895,14 +877,16 @@ func ExampleFpdf_tutorial16() {
pdf.Bookmark("Page 2", 0, 0)
pdf.Bookmark("Paragraph 3", 1, -1)
pdf.Cell(0, 6, "Paragraph 3")
- pdf.OutputAndClose(docWriter(pdf, 16))
+ fileStr := exampleFilename("bookmark")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial16.pdf
+ // Successfully generated pdf/bookmark.pdf
}
-// Transformation test adapted from an example script by Moritz Wagner and
-// Andreas Würmser.
-func ExampleFpdf_tutorial17() {
+// This example demonstrates various transformations. It is adapted from an
+// example script by Moritz Wagner and Andreas Würmser.
+func ExampleFpdf_TransformBegin() {
const (
light = 200
dark = 0
@@ -1014,13 +998,15 @@ func ExampleFpdf_tutorial17() {
refDupe()
pdf.TransformEnd()
- pdf.OutputAndClose(docWriter(pdf, 17))
+ fileStr := exampleFilename("transform")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial17.pdf
+ // Successfully generated pdf/transform.pdf
}
-// Example to demonstrate Lawrence Kesteloot's image registration code.
-func ExampleFpdf_tutorial18() {
+// This example demonstrates Lawrence Kesteloot's image registration code.
+func ExampleFpdf_RegisterImage() {
const (
margin = 10
wd = 210
@@ -1034,15 +1020,15 @@ func ExampleFpdf_tutorial18() {
"logo-progressive.jpg",
}
var infoPtr *gofpdf.ImageInfoType
- var fileStr string
+ var imageFileStr string
var imgWd, imgHt, lf, tp float64
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetMargins(10, 10, 10)
pdf.SetFont("Helvetica", "", 15)
for j, str := range fileList {
- fileStr = imageFile(str)
- infoPtr = pdf.RegisterImage(fileStr, "")
+ imageFileStr = imageFile(str)
+ infoPtr = pdf.RegisterImage(imageFileStr, "")
imgWd, imgHt = infoPtr.Extent()
switch j {
case 0:
@@ -1061,15 +1047,17 @@ func ExampleFpdf_tutorial18() {
lf = wd - imgWd - margin
tp = ht - imgHt - margin
}
- pdf.Image(fileStr, lf, tp, imgWd, imgHt, false, "", 0, "")
+ pdf.Image(imageFileStr, lf, tp, imgWd, imgHt, false, "", 0, "")
}
- pdf.OutputAndClose(docWriter(pdf, 18))
+ fileStr := exampleFilename("registerimage")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial18.pdf
+ // Successfully generated pdf/registerimage.pdf
}
-// Example to demonstrate Bruno Michel's line splitting function.
-func ExampleFpdf_tutorial19() {
+// This example demonstrates Bruno Michel's line splitting function.
+func ExampleFpdf_SplitLines() {
const (
fontPtSize = 18.0
wd = 100.0
@@ -1090,14 +1078,16 @@ func ExampleFpdf_tutorial19() {
for _, line := range lines {
pdf.CellFormat(190.0, lineHt, string(line), "", 1, "C", false, 0, "")
}
- pdf.OutputAndClose(docWriter(pdf, 19))
+ fileStr := exampleFilename("splitlines")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial19.pdf
+ // Successfully generated pdf/splitlines.pdf
}
// This example demonstrates how to render a simple path-only SVG image of the
// type generated by the jSignature web control.
-func ExampleFpdf_tutorial20() {
+func ExampleFpdf_SVGBasicWrite() {
const (
fontPtSize = 16.0
wd = 100.0
@@ -1136,14 +1126,16 @@ func ExampleFpdf_tutorial20() {
} else {
pdf.SetError(err)
}
- pdf.OutputAndClose(docWriter(pdf, 20))
+ fileStr := exampleFilename("svg")
+ err = pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial20.pdf
+ // Successfully generated pdf/svg.pdf
}
// This example demonstrates Stefan Schroeder's code to control vertical
// alignment.
-func ExampleFpdf_tutorial21() {
+func ExampleFpdf_CellFormat_2() {
type recType struct {
align, txt string
}
@@ -1173,15 +1165,17 @@ func ExampleFpdf_tutorial21() {
}
linkStr = "https://github.com/jung-kurt/gofpdf"
}
- pdf.OutputAndClose(docWriter(pdf, 21))
+ fileStr := exampleFilename("align")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial21.pdf
+ // Successfully generated pdf/align.pdf
}
// This example demonstrates the use of characters in the high range of the
-// Windows-1252 code page (gofdpf default). See the following example (23) for
-// a way to do this automatically.
-func ExampleFpdf_tutorial22() {
+// Windows-1252 code page (gofdpf default). See the example for CellFormat (4)
+// for a way to do this automatically.
+func ExampleFpdf_CellFormat_3() {
pdf := gofpdf.New("P", "mm", "A4", "") // A4 210.0 x 297.0
fontSize := 16.0
pdf.SetFont("Helvetica", "", fontSize)
@@ -1203,14 +1197,16 @@ func ExampleFpdf_tutorial22() {
write("Falsches \xdcben von Xylophonmusik qu\xe4lt jeden gr\xf6\xdferen Zwerg.")
write("Heiz\xf6lr\xfccksto\xdfabd\xe4mpfung")
write("For\xe5rsj\xe6vnd\xf8gn / Efter\xe5rsj\xe6vnd\xf8gn")
- pdf.OutputAndClose(docWriter(pdf, 22))
+ fileStr := exampleFilename("codepageescape")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial22.pdf
+ // Successfully generated pdf/codepageescape.pdf
}
-// This example demonstrates the conversion of UTF-8 strings to an 8-bit font
-// encoding.
-func ExampleFpdf_tutorial23() {
+// This example demonstrates the automatic conversion of UTF-8 strings to an
+// 8-bit font encoding.
+func ExampleFpdf_CellFormat_4() {
pdf := gofpdf.New("P", "mm", "A4", cnFontDir) // A4 210.0 x 297.0
// See documentation for details on how to generate fonts
pdf.AddFont("Helvetica-1251", "", "helvetica_1251.json")
@@ -1241,26 +1237,30 @@ func ExampleFpdf_tutorial23() {
tr = pdf.UnicodeTranslatorFromDescriptor("cp1253")
write("Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)")
- pdf.OutputAndClose(docWriter(pdf, 23))
+ fileStr := exampleFilename("codepage")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial23.pdf
+ // Successfully generated pdf/codepage.pdf
}
-// This example demonstrates document protection.
-func ExampleFpdf_tutorial24() {
+// This example demonstrates password protection for documents.
+func ExampleFpdf_SetProtection() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.SetProtection(gofpdf.CnProtectPrint, "123", "abc")
pdf.AddPage()
pdf.SetFont("Arial", "", 12)
pdf.Write(10, "Password-protected.")
- pdf.OutputAndClose(docWriter(pdf, 24))
+ fileStr := exampleFilename("protection")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial24.pdf
+ // Successfully generated pdf/protection.pdf
}
// This example displays equilateral polygons in a demonstration of the Polygon
// function.
-func ExampleFpdf_tutorial25() {
+func ExampleFpdf_Polygon() {
const rowCount = 5
const colCount = 4
const ptSize = 36
@@ -1299,16 +1299,18 @@ func ExampleFpdf_tutorial25() {
}
y += advance
}
- pdf.OutputAndClose(docWriter(pdf, 25))
+ fileStr := exampleFilename("polygon")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial25.pdf
+ // Successfully generated pdf/polygon.pdf
}
// This example demonstrates document layers. The initial visibility of a layer
// is specified with the second parameter to AddLayer(). The layer list
// displayed by the document reader allows layer visibility to be controlled
// interactively.
-func ExampleFpdf_tutorial26() {
+func ExampleFpdf_AddLayer() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
@@ -1337,15 +1339,17 @@ func ExampleFpdf_tutorial26() {
pdf.Write(8, "This line belongs to layer 1 again.\n")
pdf.EndLayer()
- pdf.OutputAndClose(docWriter(pdf, 26))
+ fileStr := exampleFilename("layer")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial26.pdf
+ // Successfully generated pdf/layer.pdf
}
// This example demonstrates the use of an image that is retrieved from a web
// server.
-func ExampleFpdf_tutorial27() {
+func ExampleFpdf_RegisterImageReader() {
const (
margin = 10
@@ -1378,14 +1382,16 @@ func ExampleFpdf_tutorial27() {
} else {
pdf.SetError(err)
}
- pdf.OutputAndClose(docWriter(pdf, 27))
+ fileStr := exampleFilename("imagemime")
+ err = pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial27.pdf
+ // Successfully generated pdf/imagemime.pdf
}
// This example demonstrates the Beziergon function.
-func ExampleFpdf_tutorial28() {
+func ExampleFpdf_Beziergon() {
const (
margin = 10
@@ -1465,31 +1471,37 @@ func ExampleFpdf_tutorial28() {
pdf.SetDrawColor(64, 64, 128)
pdf.SetLineWidth(pdf.GetLineWidth() * 3)
pdf.Beziergon(curveList, "D")
- pdf.OutputAndClose(docWriter(pdf, 28))
+ fileStr := exampleFilename("beziergon")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial28.pdf
+ // Successfully generated pdf/beziergon.pdf
}
-// Non-standard font using generalized font loader
-func ExampleFpdf_tutorial29() {
+// This example demonstrates loading a non-standard font using a generalized
+// font loader. fontResourceType implements the FontLoader interface and is
+// defined locally in the test source code.
+func ExampleFpdf_SetFontLoader() {
var fr fontResourceType
- pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
+ pdf := gofpdf.New("P", "mm", "A4", "")
pdf.SetFontLoader(fr)
pdf.AddFont("Calligrapher", "", "calligra.json")
pdf.AddPage()
pdf.SetFont("Calligrapher", "", 35)
pdf.Cell(0, 10, "Load fonts from any source")
- pdf.OutputAndClose(docWriter(pdf, 29))
+ fileStr := exampleFilename("fontload")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
// Generalized font loader reading calligra.json
// Generalized font loader reading calligra.z
- // Successfully generated pdf/tutorial29.pdf
+ // Successfully generated pdf/fontload.pdf
}
// This example demonstrates the Path Drawing functions, such as: MoveTo,
// LineTo, CurveTo, ..., ClosePath and DrawPath.
-func ExampleFpdf_tutorial30() {
+func ExampleFpdf_MoveTo() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.MoveTo(20, 20)
@@ -1501,12 +1513,15 @@ func ExampleFpdf_tutorial30() {
pdf.SetFillColor(200, 200, 200)
pdf.SetLineWidth(3)
pdf.DrawPath("DF")
- pdf.OutputAndClose(docWriter(pdf, 30))
+ fileStr := exampleFilename("path")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial30.pdf
+ // Successfully generated pdf/path.pdf
}
-func ExampleFpdf_tutorial31() {
+// This example demonstrates various line cap and line join styles.
+func ExampleFpdf_SetLineJoinStyle() {
const offset = 75.0
pdf := gofpdf.New("L", "mm", "A4", "")
pdf.AddPage()
@@ -1539,14 +1554,15 @@ func ExampleFpdf_tutorial31() {
draw(caps[i], joins[i], x, 50, x, 160)
x += offset
}
- pdf.OutputAndClose(docWriter(pdf, 31))
+ fileStr := exampleFilename("joinstyle")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial31.pdf
+ // Successfully generated pdf/joinstyle.pdf
}
-// This example demonstrates the Path Drawing functions, such as: MoveTo,
-// LineTo, CurveTo, ..., ClosePath and DrawPath.
-func ExampleFpdf_tutorial32() {
+// This example demonstrates various fill modes.
+func ExampleFpdf_DrawPath() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.SetDrawColor(0xff, 0x00, 0x00)
pdf.SetFillColor(0x99, 0x99, 0x99)
@@ -1614,7 +1630,9 @@ func ExampleFpdf_tutorial32() {
pdf.DrawPath("B*")
pdf.Text(115, 290, "B* (even odd)")
- pdf.OutputAndClose(docWriter(pdf, 32))
+ fileStr := exampleFilename("fill")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
// Output:
- // Successfully generated pdf/tutorial32.pdf
+ // Successfully generated pdf/fill.pdf
}
diff --git a/fpdftrans.go b/fpdftrans.go
index b87d9b9..9cda397 100644
--- a/fpdftrans.go
+++ b/fpdftrans.go
@@ -20,8 +20,6 @@ type TransformMatrix struct {
// TransformScale(), TransformSkew(), etc. This is followed by text, drawing or
// image output and finally a call to TransformEnd(). All transformation
// contexts must be properly ended prior to outputting the document.
-//
-// See tutorial 17 for transformation examples.
func (f *Fpdf) TransformBegin() {
f.transformNest++
f.out("q")
@@ -29,6 +27,8 @@ func (f *Fpdf) TransformBegin() {
// TransformScaleX scales the width of the following text, drawings and images.
// scaleWd is the percentage scaling factor. (x, y) is center of scaling.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformScaleX(scaleWd, x, y float64) {
f.TransformScale(scaleWd, 100, x, y)
}
@@ -36,6 +36,8 @@ func (f *Fpdf) TransformScaleX(scaleWd, x, y float64) {
// TransformScaleY scales the height of the following text, drawings and
// images. scaleHt is the percentage scaling factor. (x, y) is center of
// scaling.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformScaleY(scaleHt, x, y float64) {
f.TransformScale(100, scaleHt, x, y)
}
@@ -43,6 +45,8 @@ func (f *Fpdf) TransformScaleY(scaleHt, x, y float64) {
// TransformScaleXY uniformly scales the width and height of the following
// text, drawings and images. s is the percentage scaling factor for both width
// and height. (x, y) is center of scaling.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformScaleXY(s, x, y float64) {
f.TransformScale(s, s, x, y)
}
@@ -50,6 +54,8 @@ func (f *Fpdf) TransformScaleXY(s, x, y float64) {
// TransformScale generally scales the following text, drawings and images.
// scaleWd and scaleHt are the percentage scaling factors for width and height.
// (x, y) is center of scaling.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformScale(scaleWd, scaleHt, x, y float64) {
if scaleWd == 0 || scaleHt == 0 {
f.err = fmt.Errorf("scale factor cannot be zero")
@@ -65,18 +71,24 @@ func (f *Fpdf) TransformScale(scaleWd, scaleHt, x, y float64) {
// TransformMirrorHorizontal horizontally mirrors the following text, drawings
// and images. x is the axis of reflection.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformMirrorHorizontal(x float64) {
f.TransformScale(-100, 100, x, f.y)
}
// TransformMirrorVertical vertically mirrors the following text, drawings and
// images. y is the axis of reflection.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformMirrorVertical(y float64) {
f.TransformScale(100, -100, f.x, y)
}
// TransformMirrorPoint symmetrically mirrors the following text, drawings and
// images on the point specified by (x, y).
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformMirrorPoint(x, y float64) {
f.TransformScale(-100, -100, x, y)
}
@@ -85,6 +97,8 @@ func (f *Fpdf) TransformMirrorPoint(x, y float64) {
// images on the line defined by angle and the point (x, y). angles is
// specified in degrees and measured counter-clockwise from the 3 o'clock
// position.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformMirrorLine(angle, x, y float64) {
f.TransformScale(-100, 100, x, y)
f.TransformRotate(-2*(angle-90), x, y)
@@ -92,18 +106,24 @@ func (f *Fpdf) TransformMirrorLine(angle, x, y float64) {
// TransformTranslateX moves the following text, drawings and images
// horizontally by the amount specified by tx.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformTranslateX(tx float64) {
f.TransformTranslate(tx, 0)
}
// TransformTranslateY moves the following text, drawings and images vertically
// by the amount specified by ty.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformTranslateY(ty float64) {
f.TransformTranslate(0, ty)
}
// TransformTranslate moves the following text, drawings and images
// horizontally and vertically by the amounts specified by tx and ty.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformTranslate(tx, ty float64) {
f.Transform(TransformMatrix{1, 0, 0, 1, tx * f.k, -ty * f.k})
}
@@ -111,6 +131,8 @@ func (f *Fpdf) TransformTranslate(tx, ty float64) {
// TransformRotate rotates the following text, drawings and images around the
// center point (x, y). angle is specified in degrees and measured
// counter-clockwise from the 3 o'clock position.
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformRotate(angle, x, y float64) {
y = (f.h - y) * f.k
x *= f.k
@@ -128,6 +150,8 @@ func (f *Fpdf) TransformRotate(angle, x, y float64) {
// TransformSkewX horizontally skews the following text, drawings and images
// keeping the point (x, y) stationary. angleX ranges from -90 degrees (skew to
// the left) to 90 degrees (skew to the right).
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformSkewX(angleX, x, y float64) {
f.TransformSkew(angleX, 0, x, y)
}
@@ -135,6 +159,8 @@ func (f *Fpdf) TransformSkewX(angleX, x, y float64) {
// TransformSkewY vertically skews the following text, drawings and images
// keeping the point (x, y) stationary. angleY ranges from -90 degrees (skew to
// the bottom) to 90 degrees (skew to the top).
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformSkewY(angleY, x, y float64) {
f.TransformSkew(0, angleY, x, y)
}
@@ -143,6 +169,8 @@ func (f *Fpdf) TransformSkewY(angleY, x, y float64) {
// keeping the point (x, y) stationary. angleX ranges from -90 degrees (skew to
// the left) to 90 degrees (skew to the right). angleY ranges from -90 degrees
// (skew to the bottom) to 90 degrees (skew to the top).
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformSkew(angleX, angleY, x, y float64) {
if angleX <= -90 || angleX >= 90 || angleY <= -90 || angleY >= 90 {
f.err = fmt.Errorf("skew values must be between -90° and 90°")
@@ -173,6 +201,8 @@ func (f *Fpdf) Transform(tm TransformMatrix) {
}
// TransformEnd applies a transformation that was begun with a call to TransformBegin().
+//
+// The TransformBegin() example demonstrates this method.
func (f *Fpdf) TransformEnd() {
if f.transformNest > 0 {
f.transformNest--
diff --git a/htmlbasic.go b/htmlbasic.go
index b7186bc..e602b7d 100644
--- a/htmlbasic.go
+++ b/htmlbasic.go
@@ -106,8 +106,6 @@ type HTMLBasicType struct {
// HTMLBasicNew returns an instance that facilitates writing basic HTML in the
// specified PDF file.
-//
-// This function is demonstrated in tutorial 6.
func (f *Fpdf) HTMLBasicNew() (html HTMLBasicType) {
html.pdf = f
html.Link.ClrR, html.Link.ClrG, html.Link.ClrB = 0, 0, 128
diff --git a/layer.go b/layer.go
index d567e37..bca364f 100644
--- a/layer.go
+++ b/layer.go
@@ -42,8 +42,6 @@ func (f *Fpdf) layerInit() {
// display in the layer list. visible specifies whether the layer will be
// initially visible. The return value is an integer ID that is used in a call
// to BeginLayer().
-//
-// Layers are demonstrated in tutorial 26.
func (f *Fpdf) AddLayer(name string, visible bool) (layerID int) {
layerID = len(f.layer.list)
f.layer.list = append(f.layer.list, layerType{name: name, visible: visible})
diff --git a/svgbasic.go b/svgbasic.go
index 749933e..cb8e91e 100644
--- a/svgbasic.go
+++ b/svgbasic.go
@@ -199,8 +199,7 @@ func SVGBasicParse(buf []byte) (sig SVGBasicType, err error) {
}
// SVGBasicFileParse parses a simple scalable vector graphics (SVG) file into a
-// basic descriptor. See SVGBasicParse for additional comments and tutorial 20
-// for an example of this function.
+// basic descriptor. The SVGBasicWrite() example demonstrates this method.
func SVGBasicFileParse(svgFileStr string) (sig SVGBasicType, err error) {
var buf []byte
buf, err = ioutil.ReadFile(svgFileStr)
diff --git a/util.go b/util.go
index be25f7e..ce391f5 100644
--- a/util.go
+++ b/util.go
@@ -260,7 +260,7 @@ func UnicodeTranslatorFromFile(fileStr string) (f func(string) string, err error
// If an error occurs reading the descriptor, the returned function is valid
// but does not perform any rune translation.
//
-// See tutorial 23 for an example of this function.
+// The CellFormat (4) example demonstrates this method.
func (f *Fpdf) UnicodeTranslatorFromDescriptor(cpStr string) (rep func(string) string) {
var str string
var ok bool