summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc.go10
-rw-r--r--fpdf.go84
-rw-r--r--fpdf_test.go10
3 files changed, 74 insertions, 30 deletions
diff --git a/doc.go b/doc.go
index 339534b..abb8518 100644
--- a/doc.go
+++ b/doc.go
@@ -98,11 +98,11 @@ of information. It includes a forum and FAQ.
However, some internal changes have been made. Page content is built up using
buffers (of type bytes.Buffer) rather than repeated string concatenation.
Errors are handled as explained above rather than panicking. Output is
-generated through an interface of type io.WriteCloser. A number of the original
-PHP methods behave differently based on the type of the arguments 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.
+generated through an interface of type io.Writer or io.WriteCloser. A number of
+the original PHP methods behave differently based on the type of the arguments
+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
diff --git a/fpdf.go b/fpdf.go
index dcb5198..2755891 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -639,7 +639,8 @@ func (f *Fpdf) SetLineCapStyle(styleStr string) {
}
}
-// Draws a line between points (x1, y1) and (x2, y2).
+// Draws a line between points (x1, y1) and (x2, y2) using the current draw
+// color, line width and cap style.
func (f *Fpdf) Line(x1, y1, x2, y2 float64) {
f.outf("%.2f %.2f m %.2f %.2f l S", x1*f.k, (f.h-y1)*f.k, x2*f.k, (f.h-y2)*f.k)
}
@@ -656,26 +657,39 @@ func fillDrawOp(styleStr string) (opStr string) {
return
}
-// Outputs a rectangle. It can be drawn (border only), filled (with no border)
-// or both. x and y specify the upper left corner of the rectangle. styleStr
-// can be "F" for filled, "D" for outlined only, or "DF" or "FD" for outlined
-// and filled. An empty string will be replaced with "D".
+// Outputs a rectangle of width w and height h with the upper left corner
+// positioned at point (x, y).
+//
+// It can be drawn (border only), filled (with no border) or both. styleStr can
+// be "F" for filled, "D" for outlined only, or "DF" or "FD" for outlined and
+// filled. An empty string will be replaced with "D". Drawing uses the current
+// draw color and line width. Filling uses the current fill color.
func (f *Fpdf) Rect(x, y, w, h float64, styleStr string) {
f.outf("%.2f %.2f %.2f %.2f re %s", x*f.k, (f.h-y)*f.k, w*f.k, -h*f.k, fillDrawOp(styleStr))
}
-// Draw a circle centered on point (x, y) with radius r. styleStr can be "F"
-// for filled, "D" for outlined only, or "DF" or "FD" for outlined and filled.
-// An empty string will be replaced with "D".
+// Draw a circle centered on point (x, y) with radius r.
+//
+// styleStr can be "F" for filled, "D" for outlined only, or "DF" or "FD" for
+// outlined and filled. An empty string will be replaced with "D". Drawing uses
+// the current draw color and line width. 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)
}
// Draw an ellipse centered at point (x, y). rx and ry specify its horizontal
-// and vertical radii. degRotate specifies the counter-clockwise angle in
-// degrees that the ellipse will be rotated. styleStr can be "F" for filled,
-// "D" for outlined only, or "DF" or "FD" for outlined and filled. An empty
-// string will be replaced with "D".
+// and vertical radii.
+//
+// degRotate specifies the counter-clockwise angle in degrees that the ellipse
+// will be rotated.
+//
+// styleStr can be "F" for filled, "D" for outlined only, or "DF" or "FD" for
+// outlined and filled. An empty string will be replaced with "D". Drawing uses
+// the current draw color and line width. Filling uses the current fill color.
+//
+// See tutorial 11 for an example of this function.
func (f *Fpdf) Ellipse(x, y, rx, ry, degRotate float64, styleStr string) {
f.Arc(x, y, rx, ry, degRotate, 0, 360, styleStr)
}
@@ -696,9 +710,14 @@ func (f *Fpdf) curve(cx0, cy0, x1, y1, cx1, cy1 float64) {
// specifies the curvature. At the start point, the curve is tangent to the
// straight line between the start point and the control point. At the end
// point, the curve is tangent to the straight line between the end point and
-// the control point. styleStr can be "F" for filled, "D" for outlined only, or
-// "DF" or "FD" for outlined and filled. An empty string will be replaced with
-// "D".
+// the control point.
+//
+// styleStr can be "F" for filled, "D" for outlined only, or "DF" or "FD" for
+// outlined and filled. An empty string will be replaced with "D". Drawing uses
+// the current draw color, line width, and cap style. Filling uses the current
+// fill color.
+//
+// See tutorial 11 for an example of this function.
func (f *Fpdf) Curve(x0, y0, cx, cy, x1, y1 float64, styleStr string) {
f.point(x0, y0)
f.outf("%.2f %.2f %.2f %.2f v %s", cx*f.k, (f.h-cy)*f.k, x1*f.k, (f.h-y1)*f.k,
@@ -710,9 +729,14 @@ func (f *Fpdf) Curve(x0, y0, cx, cy, x1, y1 float64, styleStr string) {
// (cx1, cy1) specify the curvature. At the start point, the curve is tangent
// to the straight line between the start point and the control point (cx0,
// cy0). At the end point, the curve is tangent to the straight line between
-// the end point and the control point (cx1, cy1). styleStr can be "F" for
-// filled, "D" for outlined only, or "DF" or "FD" for outlined and filled. An
-// empty string will be replaced with "D".
+// the end point and the control point (cx1, cy1).
+//
+// styleStr can be "F" for filled, "D" for outlined only, or "DF" or "FD" for
+// outlined and filled. An empty string will be replaced with "D". Drawing uses
+// the current draw color, line width, and cap style. Filling uses the current
+// fill color.
+//
+// See tutorial 11 for an example of this function.
func (f *Fpdf) CurveCubic(x0, y0, cx0, cy0, cx1, cy1, x1, y1 float64, styleStr string) {
f.point(x0, y0)
f.outf("%.2f %.2f %.2f %.2f %.2f %.2f c %s", cx0*f.k, (f.h-cy0)*f.k,
@@ -720,12 +744,19 @@ func (f *Fpdf) CurveCubic(x0, y0, cx0, cy0, cx1, cy1, x1, y1 float64, styleStr s
}
// Draw an elliptical arc centered at point (x, y). rx and ry specify its
-// horizontal and vertical radii. degRotate specifies the angle that the arc
-// will be rotated. degStart and degEnd specify the starting and ending angle
-// of the arc. All angles are specified in degrees and measured
-// counter-clockwise from the 3 o'clock position. styleStr can be "F" for
-// filled, "D" for outlined only, or "DF" or "FD" for outlined and filled. An
-// empty string will be replaced with "D".
+// horizontal and vertical radii.
+//
+// degRotate specifies the angle that the arc will be rotated. degStart and
+// degEnd specify the starting and ending angle of the arc. All angles are
+// specified in degrees and measured counter-clockwise from the 3 o'clock
+// position.
+//
+// styleStr can be "F" for filled, "D" for outlined only, or "DF" or "FD" for
+// outlined and filled. An empty string will be replaced with "D". Drawing uses
+// the current draw color, line width, and cap style. Filling uses the current
+// fill color.
+//
+// See tutorial 11 for an example of this function.
func (f *Fpdf) Arc(x, y, rx, ry, degRotate, degStart, degEnd float64, styleStr string) {
x *= f.k
y = (f.h - y) * f.k
@@ -797,6 +828,8 @@ func (f *Fpdf) Arc(x, y, rx, ry, degRotate, degStart, degEnd float64, styleStr s
// 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 f.err != nil {
return
@@ -1029,7 +1062,8 @@ func (f *Fpdf) Text(x, y float64, txtStr string) {
// mode selected by SetAutoPageBreak. The function provided should not be
// called by the application.
//
-// See tutorial 4 for an example of this function.
+// See tutorial 4 for an example of how this function can be used to manage
+// multiple columns.
func (f *Fpdf) SetAcceptPageBreakFunc(fnc func() bool) {
f.acceptPageBreak = fnc
}
diff --git a/fpdf_test.go b/fpdf_test.go
index c8b1ba3..494d281 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -85,6 +85,7 @@ func docWriter(pdf *Fpdf, idx int) *pdfWriter {
return pw
}
+// Hello, world
func ExampleFpdf_tutorial01() {
pdf := New("P", "mm", "A4", FONT_DIR)
pdf.AddPage()
@@ -95,6 +96,7 @@ func ExampleFpdf_tutorial01() {
// Successfully generated pdf/tutorial01.pdf
}
+// Header, footer and page-breaking
func ExampleFpdf_tutorial02() {
pdf := New("P", "mm", "A4", FONT_DIR)
pdf.SetHeaderFunc(func() {
@@ -121,6 +123,7 @@ func ExampleFpdf_tutorial02() {
// Successfully generated pdf/tutorial02.pdf
}
+// Word-wrapping, line justification and page-breaking
func ExampleFpdf_tutorial03() {
pdf := New("P", "mm", "A4", FONT_DIR)
titleStr := "20000 Leagues Under the Seas"
@@ -191,6 +194,7 @@ func ExampleFpdf_tutorial03() {
// Successfully generated pdf/tutorial03.pdf
}
+// Multiple column layout
func ExampleFpdf_tutorial04() {
var y0 float64
var crrntCol int
@@ -291,6 +295,7 @@ func ExampleFpdf_tutorial04() {
// Successfully generated pdf/tutorial04.pdf
}
+// Various table styles
func ExampleFpdf_tutorial05() {
pdf := New("P", "mm", "A4", FONT_DIR)
type countryType struct {
@@ -410,6 +415,7 @@ func ExampleFpdf_tutorial05() {
// Successfully generated pdf/tutorial05.pdf
}
+// Internal and external links
func ExampleFpdf_tutorial06() {
var boldLvl, italicLvl, underscoreLvl int
var hrefStr string
@@ -504,6 +510,7 @@ func ExampleFpdf_tutorial06() {
// Successfully generated pdf/tutorial06.pdf
}
+// Non-standard font
func ExampleFpdf_tutorial07() {
pdf := New("P", "mm", "A4", FONT_DIR)
pdf.AddFont("Calligrapher", "", "calligra.json")
@@ -515,6 +522,7 @@ func ExampleFpdf_tutorial07() {
// Successfully generated pdf/tutorial07.pdf
}
+// Various image types
func ExampleFpdf_tutorial08() {
pdf := New("P", "mm", "A4", FONT_DIR)
pdf.AddPage()
@@ -534,6 +542,7 @@ func ExampleFpdf_tutorial08() {
// Successfully generated pdf/tutorial08.pdf
}
+// Landscape mode with logos
func ExampleFpdf_tutorial09() {
var y0 float64
var crrntCol int
@@ -690,6 +699,7 @@ func ExampleFpdf_tutorial11() {
pdf.Arc(135, y+35, 30, 20, 135, 0, 360, "D")
pdf.SetLineWidth(thin)
pdf.SetLineCapStyle("butt")
+
pdf.OutputAndClose(docWriter(pdf, 11))
// Output:
// Successfully generated pdf/tutorial11.pdf