summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@code.google.com>2013-11-15 08:04:58 -0500
committerKurt Jung <kurt.w.jung@code.google.com>2013-11-15 08:04:58 -0500
commit807441a526f9094d3c099d422542252a4a0ec964 (patch)
treee052b014f848ea09953116449a1c6dfdeab07d44
parent18a535033a6b0b584b7fb1bb6a21a7c980207aa4 (diff)
Brush some lint off using github.com/golang/lint. This includes one breaking change: WriteLinkID instead of WriteLinkId.
-rw-r--r--def.go19
-rw-r--r--font.go26
-rw-r--r--fpdf.go491
-rw-r--r--fpdf_test.go106
-rw-r--r--fpdftrans.go109
-rw-r--r--ttfparser.go20
-rw-r--r--ttfparser_test.go4
-rw-r--r--util.go9
8 files changed, 396 insertions, 388 deletions
diff --git a/def.go b/def.go
index afdc9f2..bf78fea 100644
--- a/def.go
+++ b/def.go
@@ -22,7 +22,7 @@ import (
// Version of FPDF from which this package is derived
const (
- FPDF_VERSION = "1.7"
+ cnFpdfVersion = "1.7"
)
type blendModeType struct {
@@ -37,17 +37,19 @@ type gradientType struct {
objNum int
}
-// Wd and Ht specify the horizontal and vertical extents of a document page.
+// SizeType fields Wd and Ht specify the horizontal and vertical extents of a
+// document element such as a page.
type SizeType struct {
Wd, Ht float64
}
-// X and Y specify the horizontal and vertical coordinates of a point,
-// typically used in drawing.
+// PointType fields X and Y specify the horizontal and vertical coordinates of
+// a point, typically used in drawing.
type PointType struct {
X, Y float64
}
+// ImageInfoType contains size, color and other information about an image
type ImageInfoType struct {
data []byte
smask []byte
@@ -64,17 +66,18 @@ type ImageInfoType struct {
scale float64 // document scaling factor
}
-// The width and height of the image in the units of the Fpdf object.
+// Extent returns the width and height of the image in the units of the Fpdf
+// object.
func (info *ImageInfoType) Extent() (wd, ht float64) {
return info.w / info.scale, info.h / info.scale
}
-// The width of the image in the units of the Fpdf object.
+// Width returns the width of the image in the units of the Fpdf object.
func (info *ImageInfoType) Width() float64 {
return info.w / info.scale
}
-// The height of the image in the units of the Fpdf object.
+// Height returns the height of the image in the units of the Fpdf object.
func (info *ImageInfoType) Height() float64 {
return info.h / info.scale
}
@@ -116,7 +119,7 @@ type InitType struct {
FontDirStr string
}
-// Principal structure for creating a single PDF document
+// Fpdf is the principal structure for creating a single PDF document
type Fpdf struct {
page int // current page number
n int // current object number
diff --git a/font.go b/font.go
index f5cf8c1..cb6ecbb 100644
--- a/font.go
+++ b/font.go
@@ -53,7 +53,7 @@ func loadMap(encodingFileStr string) (encList encListType, err error) {
f, err = os.Open(encodingFileStr)
if err == nil {
defer f.Close()
- for j, _ := range encList {
+ for j := range encList {
encList[j].uv = -1
encList[j].name = ".notdef"
}
@@ -67,7 +67,7 @@ func loadMap(encodingFileStr string) (encList encListType, err error) {
if pos < 256 {
encList[pos] = enc
} else {
- err = fmt.Errorf("Map position 0x%2X exceeds 0xFF", pos)
+ err = fmt.Errorf("map position 0x%2X exceeds 0xFF", pos)
return
}
} else {
@@ -90,7 +90,7 @@ func getInfoFromTrueType(fileStr string, msgWriter io.Writer, embed bool, encLis
}
if embed {
if !ttf.Embeddable {
- err = fmt.Errorf("Font license does not allow embedding")
+ err = fmt.Errorf("font license does not allow embedding")
return
}
info.Data, err = ioutil.ReadFile(fileStr)
@@ -149,7 +149,7 @@ func segmentRead(f *os.File) (s segmentType, err error) {
return
}
if s.marker != 128 {
- err = fmt.Errorf("Font file is not a valid binary Type1")
+ err = fmt.Errorf("font file is not a valid binary Type1")
return
}
if err = binary.Read(f, binary.LittleEndian, &s.tp); err != nil {
@@ -193,10 +193,10 @@ func getInfoFromType1(fileStr string, msgWriter io.Writer, embed bool, encList e
afmFileStr := fileStr[0:len(fileStr)-3] + "afm"
size, ok := fileSize(afmFileStr)
if !ok {
- err = fmt.Errorf("AFM font file %s not found", afmFileStr)
+ err = fmt.Errorf("font file (ATM) %s not found", afmFileStr)
return
} else if size == 0 {
- err = fmt.Errorf("AFM font file %s empty or not readable", afmFileStr)
+ err = fmt.Errorf("font file (AFM) %s empty or not readable", afmFileStr)
return
}
var f *os.File
@@ -260,7 +260,7 @@ func getInfoFromType1(fileStr string, msgWriter io.Writer, embed bool, encList e
return
}
if info.FontName == "" {
- err = fmt.Errorf("FontName missing in AFM file %s", afmFileStr)
+ err = fmt.Errorf("the field FontName missing in AFM file %s", afmFileStr)
return
}
info.Bold = wt == "bold" || wt == "black"
@@ -369,10 +369,10 @@ func makeDefinitionFile(fileStr, tpStr, encodingFileStr string, embed bool, encL
return
}
-// Generate a font definition file in JSON format. A definition file of this
-// type is required to use non-core fonts in the PDF documents that gofpdf
-// generates. See the makefont utility in the gofpdf package for a command line
-// interface to this function.
+// MakeFont generates a font definition file in JSON format. A definition file
+// of this type is required to use non-core fonts in the PDF documents that
+// gofpdf generates. See the makefont utility in the gofpdf package for a
+// command line interface to this function.
//
// fontFileStr is the name of the TrueType (or OpenType based on TrueType) or
// Type1 file from which to generate a definition file.
@@ -392,7 +392,7 @@ func MakeFont(fontFileStr, encodingFileStr, dstDirStr string, msgWriter io.Write
msgWriter = ioutil.Discard
}
if !fileExist(fontFileStr) {
- err = fmt.Errorf("Font file not found: %s", fontFileStr)
+ err = fmt.Errorf("font file not found: %s", fontFileStr)
return
}
extStr := strings.ToLower(fontFileStr[len(fontFileStr)-3:])
@@ -403,7 +403,7 @@ func MakeFont(fontFileStr, encodingFileStr, dstDirStr string, msgWriter io.Write
} else if extStr == "pfb" {
tpStr = "Type1"
} else {
- err = fmt.Errorf("Unrecognized font file extension: %s", extStr)
+ err = fmt.Errorf("unrecognized font file extension: %s", extStr)
return
}
var encList encListType
diff --git a/fpdf.go b/fpdf.go
index e8fbc38..18fabc4 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -107,7 +107,7 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType)
case "in", "inch":
f.k = 72.0
default:
- f.err = fmt.Errorf("Incorrect unit %s", unitStr)
+ f.err = fmt.Errorf("incorrect unit %s", unitStr)
return
}
f.unitStr = unitStr
@@ -140,7 +140,7 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType)
f.w = f.defPageSize.Ht
f.h = f.defPageSize.Wd
default:
- f.err = fmt.Errorf("Incorrect orientation: %s", orientationStr)
+ f.err = fmt.Errorf("incorrect orientation: %s", orientationStr)
return
}
f.curOrientation = f.defOrientation
@@ -204,18 +204,18 @@ func New(orientationStr, unitStr, sizeStr, fontDirStr string) (f *Fpdf) {
return fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr, SizeType{0, 0})
}
-// Returns true if no processing errors have occurred.
+// Ok returns true if no processing errors have occurred.
func (f *Fpdf) Ok() bool {
return f.err == nil
}
-// Returns true if a processing error has occurred.
+// Err returns true if a processing error has occurred.
func (f *Fpdf) Err() bool {
return f.err != nil
}
-// Set the internal Fpdf error with formatted text to halt PDF generation; this
-// may facilitate error handling by application.
+// SetErrorf sets the internal Fpdf error with formatted text to halt PDF
+// generation; this may facilitate error handling by application.
//
// See the documentation for printing in the standard fmt package for details
// about fmtStr and args.
@@ -225,27 +225,28 @@ func (f *Fpdf) SetErrorf(fmtStr string, args ...interface{}) {
}
}
-// Summary of Fpdf instance that satisfies the fmt.Stringer interface.
+// String satisfies the fmt.Stringer interface and summarizes the Fpdf
+// instance.
func (f *Fpdf) String() string {
- return "Fpdf " + FPDF_VERSION
+ return "Fpdf " + cnFpdfVersion
}
-// Set error to halt PDF generation. This may facilitate error handling by
-// application. See also Ok(), Err() and Error().
+// SetError sets an error to halt PDF generation. This may facilitate error
+// handling by application. See also Ok(), Err() and Error().
func (f *Fpdf) SetError(err error) {
if f.err == nil && err != nil {
f.err = err
}
}
-// Returns the internal Fpdf error; this will be nil if no error has occurred.
+// Error returns the internal Fpdf error; this will be nil if no error has occurred.
func (f *Fpdf) Error() error {
return f.err
}
-// Defines the left, top and right margins. By default, they equal 1 cm. Call
-// this method to change them. If the value of the right margin is less than
-// zero, it is set to the same as the left margin.
+// SetMargins defines the left, top and right margins. By default, they equal 1
+// cm. Call this method to change them. If the value of the right margin is
+// less than zero, it is set to the same as the left margin.
func (f *Fpdf) SetMargins(left, top, right float64) {
f.lMargin = left
f.tMargin = top
@@ -255,9 +256,9 @@ func (f *Fpdf) SetMargins(left, top, right float64) {
f.rMargin = right
}
-// Defines the left margin. The method can be called before creating the first
-// page. If the current abscissa gets out of page, it is brought back to the
-// margin.
+// SetLeftMargin defines the left margin. The method can be called before
+// creating the first page. If the current abscissa gets out of page, it is
+// brought back to the margin.
func (f *Fpdf) SetLeftMargin(margin float64) {
f.lMargin = margin
if f.page > 0 && f.x < margin {
@@ -265,58 +266,60 @@ func (f *Fpdf) SetLeftMargin(margin float64) {
}
}
-// Set the location in the file system of the font and font definition files.
+// SetFontLocation sets the location in the file system of the font and font
+// definition files.
func (f *Fpdf) SetFontLocation(fontDirStr string) {
f.fontpath = fontDirStr
}
-// Sets the function that lets the application render the page header. The
-// specified function is automatically called by AddPage() and should not be
-// called directly by the application. The implementation in Fpdf is empty, so
-// you have to provide an appropriate function if you want page headers. fnc
-// will typically be a closure that has access to the Fpdf instance and other
-// document generation variables.
+// SetHeaderFunc sets the function that lets the application render the page
+// header. The specified function is automatically called by AddPage() and
+// should not be called directly by the application. The implementation in Fpdf
+// is empty, so you have to provide an appropriate function if you want page
+// headers. fnc will typically be a closure that has access to the Fpdf
+// instance and other document generation variables.
func (f *Fpdf) SetHeaderFunc(fnc func()) {
f.headerFnc = fnc
}
-// Sets the function that lets the application render the page footer. The
-// specified function is automatically called by AddPage() and Close() and
-// should not be called directly by the application. The implementation in Fpdf
-// is empty, so you have to provide an appropriate function if you want page
-// footers. fnc will typically be a closure that has access to the Fpdf
-// instance and other document generation variables.
+// SetFooterFunc sets the function that lets the application render the page
+// footer. The specified function is automatically called by AddPage() and
+// Close() and should not be called directly by the application. The
+// implementation in Fpdf is empty, so you have to provide an appropriate
+// function if you want page footers. fnc will typically be a closure that has
+// access to the Fpdf instance and other document generation variables.
func (f *Fpdf) SetFooterFunc(fnc func()) {
f.footerFnc = fnc
}
-// Defines the top margin. The method can be called before creating the first
-// page.
+// SetTopMargin defines the top margin. The method can be called before
+// creating the first page.
func (f *Fpdf) SetTopMargin(margin float64) {
f.tMargin = margin
}
-// Defines the right margin. The method can be called before creating the first
-// page.
+// SetRightMargin defines the right margin. The method can be called before
+// creating the first page.
func (f *Fpdf) SetRightMargin(margin float64) {
f.rMargin = margin
}
-// Enables or disables the automatic page breaking mode. When enabling, the
-// second parameter is the distance from the bottom of the page that defines
-// the triggering limit. By default, the mode is on and the margin is 2 cm.
+// SetAutoPageBreak enables or disables the automatic page breaking mode. When
+// enabling, the second parameter is the distance from the bottom of the page
+// that defines the triggering limit. By default, the mode is on and the margin
+// is 2 cm.
func (f *Fpdf) SetAutoPageBreak(auto bool, margin float64) {
f.autoPageBreak = auto
f.bMargin = margin
f.pageBreakTrigger = f.h - margin
}
-// Defines the way the document is to be displayed by the viewer. The zoom
-// level can be set: pages can be displayed entirely on screen, occupy the full
-// width of the window, use real size, be scaled by a specific zooming factor
-// or use viewer default (configured in the Preferences menu of Adobe Reader).
-// The page layout can be specified too: single at once, continuous display,
-// two columns or viewer default.
+// SetDisplayMode defines the way the document is to be displayed by the
+// viewer. The zoom level can be set: pages can be displayed entirely on
+// screen, occupy the full width of the window, use real size, be scaled by a
+// specific zooming factor or use viewer default (configured in the Preferences
+// menu of Adobe Reader). The page layout can be specified too: single at once,
+// continuous display, two columns or viewer default.
//
// zoomStr can be "fullpage" to display the entire page on screen, "fullwidth"
// to use maximum width of window, "real" to use real size (equivalent to 100%
@@ -337,22 +340,22 @@ func (f *Fpdf) SetDisplayMode(zoomStr, layoutStr string) {
// || !is_string($zoom))
f.zoomMode = zoomStr
default:
- f.err = fmt.Errorf("Incorrect zoom display mode: %s", zoomStr)
+ f.err = fmt.Errorf("incorrect zoom display mode: %s", zoomStr)
return
}
switch layoutStr {
case "single", "continuous", "two", "default":
f.layoutMode = layoutStr
default:
- f.err = fmt.Errorf("Incorrect layout display mode: %s", layoutStr)
+ f.err = fmt.Errorf("incorrect layout display mode: %s", layoutStr)
return
}
}
-// Activates or deactivates page compression with zlib. When activated, the
-// internal representation of each page is compressed, which leads to a
-// compression ratio of about 2 for the resulting document. Compression is on
-// by default.
+// SetCompression activates or deactivates page compression with zlib. When
+// activated, the internal representation of each page is compressed, which
+// leads to a compression ratio of about 2 for the resulting document.
+// Compression is on by default.
func (f *Fpdf) SetCompression(compress bool) {
// if(function_exists('gzcompress'))
f.compress = compress
@@ -360,8 +363,8 @@ func (f *Fpdf) SetCompression(compress bool) {
// $this->compress = false;
}
-// Defines the title of the document. isUTF8 indicates if the string is encoded
-// in ISO-8859-1 (false) or UTF-8 (true).
+// SetTitle defines the title of the document. isUTF8 indicates if the string
+// is encoded in ISO-8859-1 (false) or UTF-8 (true).
func (f *Fpdf) SetTitle(titleStr string, isUTF8 bool) {
if isUTF8 {
titleStr = utf8toutf16(titleStr)
@@ -369,8 +372,8 @@ func (f *Fpdf) SetTitle(titleStr string, isUTF8 bool) {
f.title = titleStr
}
-// Defines the subject of the document. isUTF8 indicates if the string is encoded
-// in ISO-8859-1 (false) or UTF-8 (true).
+// SetSubject defines the subject of the document. isUTF8 indicates if the
+// string is encoded in ISO-8859-1 (false) or UTF-8 (true).
func (f *Fpdf) SetSubject(subjectStr string, isUTF8 bool) {
if isUTF8 {
subjectStr = utf8toutf16(subjectStr)
@@ -378,8 +381,8 @@ func (f *Fpdf) SetSubject(subjectStr string, isUTF8 bool) {
f.subject = subjectStr
}
-// Defines the author of the document. isUTF8 indicates if the string is encoded
-// in ISO-8859-1 (false) or UTF-8 (true).
+// SetAuthor defines the author of the document. isUTF8 indicates if the string
+// is encoded in ISO-8859-1 (false) or UTF-8 (true).
func (f *Fpdf) SetAuthor(authorStr string, isUTF8 bool) {
if isUTF8 {
authorStr = utf8toutf16(authorStr)
@@ -387,9 +390,9 @@ func (f *Fpdf) SetAuthor(authorStr string, isUTF8 bool) {
f.author = authorStr
}
-// Defines the keywords of the document. keywordStr is a space-delimited
-// string, for example "invoice August". isUTF8 indicates if the string is
-// encoded
+// SetKeywords defines the keywords of the document. keywordStr is a
+// space-delimited string, for example "invoice August". isUTF8 indicates if
+// the string is encoded
func (f *Fpdf) SetKeywords(keywordsStr string, isUTF8 bool) {
if isUTF8 {
keywordsStr = utf8toutf16(keywordsStr)
@@ -397,8 +400,8 @@ func (f *Fpdf) SetKeywords(keywordsStr string, isUTF8 bool) {
f.keywords = keywordsStr
}
-// Defines the creator of the document. isUTF8 indicates if the string is encoded
-// in ISO-8859-1 (false) or UTF-8 (true).
+// SetCreator defines the creator of the document. isUTF8 indicates if the
+// string is encoded in ISO-8859-1 (false) or UTF-8 (true).
func (f *Fpdf) SetCreator(creatorStr string, isUTF8 bool) {
if isUTF8 {
creatorStr = utf8toutf16(creatorStr)
@@ -406,8 +409,9 @@ func (f *Fpdf) SetCreator(creatorStr string, isUTF8 bool) {
f.creator = creatorStr
}
-// Defines an alias for the total number of pages. It will be substituted as
-// the document is closed. This method is demonstrated in tutorial 2.
+// AliasNbPages defines an alias for the total number of pages. It will be
+// substituted as the document is closed. This method is demonstrated in
+// tutorial 2.
func (f *Fpdf) AliasNbPages(aliasStr string) {
if aliasStr == "" {
aliasStr = "{nb}"
@@ -420,16 +424,16 @@ func (f *Fpdf) open() {
f.state = 1
}
-// Terminates the PDF document. It is not necessary to call this method
+// Close terminates the PDF document. It is not necessary to call this method
// explicitly because Output() and OutputAndClose() do it automatically. If the
// document contains no page, AddPage() is called to prevent the generation of
// an invalid document.
func (f *Fpdf) Close() {
if f.err == nil {
if f.clipNest > 0 {
- f.err = fmt.Errorf("Clip procedure must be explicitly ended")
+ f.err = fmt.Errorf("clip procedure must be explicitly ended")
} else if f.transformNest > 0 {
- f.err = fmt.Errorf("Transformation procedure must be explicitly ended")
+ f.err = fmt.Errorf("transformation procedure must be explicitly ended")
}
}
if f.err != nil {
@@ -457,11 +461,11 @@ func (f *Fpdf) Close() {
return
}
-// Returns the width and height of the specified page in the units 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.
+// PageSize returns the width and height of the specified page in the units
+// 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.
func (f *Fpdf) PageSize(pageNum int) (wd, ht float64, unitStr string) {
sz, ok := f.pageSizes[pageNum]
if ok {
@@ -472,8 +476,8 @@ func (f *Fpdf) PageSize(pageNum int) (wd, ht float64, unitStr string) {
return sz.Wd, sz.Ht, f.unitStr
}
-// Adds a new page with non-default orientation or size. See AddPage() for more
-// details.
+// AddPageFormat adds a new page with non-default orientation or size. See
+// AddPage() for more details.
//
// See New() for a description of orientationStr.
//
@@ -566,10 +570,10 @@ func (f *Fpdf) AddPageFormat(orientationStr string, size SizeType) {
return
}
-// Adds a new page to the document. If a page is already present, the Footer()
-// method is called first to output the footer. Then the page is added, the
-// current position set to the top-left corner according to the left and top
-// margins, and Header() is called to display the header.
+// AddPage adds a new page to the document. If a page is already present, the
+// Footer() method is called first to output the footer. Then the page is
+// added, the current position set to the top-left corner according to the left
+// and top margins, and Header() is called to display the header.
//
// The font which was set before calling is automatically restored. There is no
// need to call SetFont() again if you want to continue with the same font. The
@@ -589,7 +593,7 @@ func (f *Fpdf) AddPage() {
return
}
-// Returns the current page number.
+// PageNo returns the current page number.
func (f *Fpdf) PageNo() int {
return f.page
}
@@ -629,10 +633,10 @@ func colorString(r, g, b int, grayStr, fullStr string) (str string) {
return
}
-// Defines the color used for all drawing operations (lines, rectangles and
-// cell borders). It is expressed in RGB components (0 - 255). The method can
-// be called before the first page is created and the value is retained from
-// page to page.
+// SetDrawColor defines the color used for all drawing operations (lines,
+// rectangles and cell borders). It is expressed in RGB components (0 - 255).
+// The method can be called before the first page is created and the value is
+// retained from page to page.
func (f *Fpdf) SetDrawColor(r, g, b int) {
f.drawColor = colorString(r, g, b, "G", "RG")
if f.page > 0 {
@@ -640,10 +644,10 @@ func (f *Fpdf) SetDrawColor(r, g, b int) {
}
}
-// Defines the color used for all filling operations (filled rectangles and
-// cell backgrounds). It is expressed in RGB components (0 -255). The method
-// can be called before the first page is created and the value is retained
-// from page to page.
+// SetFillColor defines the color used for all filling operations (filled
+// rectangles and cell backgrounds). It is expressed in RGB components (0
+// -255). The method can be called before the first page is created and the
+// value is retained from page to page.
func (f *Fpdf) SetFillColor(r, g, b int) {
f.fillColor = colorString(r, g, b, "g", "rg")
f.colorFlag = f.fillColor != f.textColor
@@ -652,15 +656,16 @@ func (f *Fpdf) SetFillColor(r, g, b int) {
}
}
-// Defines the color used for text. It is expressed in RGB components (0 -
-// 255). The method can be called before the first page is created and the
-// value is retained from page to page.
+// SetTextColor defines the color used for text. It is expressed in RGB
+// components (0 - 255). The method can be called before the first page is
+// created and the value is retained from page to page.
func (f *Fpdf) SetTextColor(r, g, b int) {
f.textColor = colorString(r, g, b, "g", "rg")
f.colorFlag = f.fillColor != f.textColor
}
-// Returns the length of a string in user units. A font must be selected.
+// GetStringWidth returns the length of a string in user units. A font must be
+// currently selected.
func (f *Fpdf) GetStringWidth(s string) float64 {
if f.err != nil {
return 0
@@ -675,9 +680,9 @@ func (f *Fpdf) GetStringWidth(s string) float64 {
return float64(w) * f.fontSize / 1000
}
-// Defines the line width. By default, the value equals 0.2 mm. The method can
-// be called before the first page is created and the value is retained from
-// page to page.
+// SetLineWidth defines the line width. By default, the value equals 0.2 mm.
+// The method can be called before the first page is created and the value is
+// retained from page to page.
func (f *Fpdf) SetLineWidth(width float64) {
f.lineWidth = width
if f.page > 0 {
@@ -685,10 +690,10 @@ func (f *Fpdf) SetLineWidth(width float64) {
}
}
-// Defines the line cap style. styleStr should be "butt", "round" or "square".
-// A square style projects from the end of the line. The method can be called
-// before the first page is created and the value is retained from page to
-// page.
+// SetLineCapStyle defines the line cap style. styleStr should be "butt",
+// "round" or "square". A square style projects from the end of the line. The
+// method can be called before the first page is created and the value is
+// retained from page to page.
func (f *Fpdf) SetLineCapStyle(styleStr string) {
var capStyle int
switch styleStr {
@@ -707,8 +712,8 @@ func (f *Fpdf) SetLineCapStyle(styleStr string) {
}
}
-// Draws a line between points (x1, y1) and (x2, y2) using the current draw
-// color, line width and cap style.
+// Line 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)
}
@@ -725,7 +730,7 @@ func fillDrawOp(styleStr string) (opStr string) {
return
}
-// Outputs a rectangle of width w and height h with the upper left corner
+// Rect 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
@@ -737,7 +742,7 @@ 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.
+// Circle draws 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
@@ -749,8 +754,8 @@ 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.
+// Ellipse draws 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.
@@ -776,9 +781,9 @@ func (f *Fpdf) curve(cx0, cy0, x1, y1, cx1, cy1 float64) {
(f.h-y1)*f.k, cx1*f.k, (f.h-cy1)*f.k)
}
-// Draws a single-segment quadratic Bézier curve. The curve starts at the
-// point (x0, y0) and ends at the point (x1, y1). The control point (cx, cy)
-// specifies the curvature. At the start point, the curve is tangent to the
+// Curve draws a single-segment quadratic Bézier curve. The curve starts at
+// the point (x0, y0) and ends at the point (x1, y1). The control point (cx,
+// cy) 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.
@@ -795,12 +800,12 @@ func (f *Fpdf) Curve(x0, y0, cx, cy, x1, y1 float64, styleStr string) {
fillDrawOp(styleStr))
}
-// Draws a single-segment cubic Bézier curve. The curve starts at the point
-// (x0, y0) and ends at the point (x1, y1). The control points (cx0, cy0) and
-// (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).
+// CurveCubic draws a single-segment cubic Bézier curve. The curve starts at
+// the point (x0, y0) and ends at the point (x1, y1). The control points (cx0,
+// cy0) and (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". Drawing uses
@@ -814,7 +819,7 @@ func (f *Fpdf) CurveCubic(x0, y0, cx0, cy0, cx1, cy1, x1, y1 float64, styleStr s
x1*f.k, (f.h-y1)*f.k, cx1*f.k, (f.h-cy1)*f.k, fillDrawOp(styleStr))
}
-// Draw an elliptical arc centered at point (x, y). rx and ry specify its
+// Arc draws 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
@@ -879,8 +884,8 @@ func (f *Fpdf) Arc(x, y, rx, ry, degRotate, degStart, degEnd float64, styleStr s
}
}
-// Set the alpha blending channel. The blending effect applies to text,
-// drawings and images.
+// SetAlpha sets the alpha blending channel. The blending effect applies to
+// text, drawings and images.
//
// alpha must be a value between 0.0 (fully transparent) to 1.0 (fully opaque).
// Values outside of this range result in an error.
@@ -907,11 +912,11 @@ func (f *Fpdf) SetAlpha(alpha float64, blendModeStr string) {
case "":
bl.modeStr = "Normal"
default:
- f.err = fmt.Errorf("Unrecognized blend mode \"%s\"", blendModeStr)
+ f.err = fmt.Errorf("unrecognized blend mode \"%s\"", blendModeStr)
return
}
if alpha < 0.0 || alpha > 1.0 {
- f.err = fmt.Errorf("Alpha value (0.0 - 1.0) is out of range: %.3f", alpha)
+ f.err = fmt.Errorf("alpha value (0.0 - 1.0) is out of range: %.3f", alpha)
return
}
alphaStr := sprintf("%.3f", alpha)
@@ -944,9 +949,9 @@ func (f *Fpdf) gradient(tp int, r1, g1, b1 int, r2, g2, b2 int, x1, y1 float64,
f.outf("/Sh%d sh", pos)
}
-// Draws a rectangular area with a blending of one color to another. The
-// rectangle is of width w and height h. Its upper left corner is positioned at
-// point (x, y).
+// LinearGradient draws a rectangular area with a blending of one color to
+// another. The rectangle is of width w and height h. Its upper left corner is
+// positioned at point (x, y).
//
// Each color is specified with three component values, one each for red, green
// and blue. The values range from 0 to 255. The first color is specified by
@@ -968,9 +973,9 @@ func (f *Fpdf) LinearGradient(x, y, w, h float64, r1, g1, b1 int, r2, g2, b2 int
f.gradientClipEnd()
}
-// Draws a rectangular area with a blending of one color to another. The
-// rectangle is of width w and height h. Its upper left corner is positioned at
-// point (x, y).
+// RadialGradient draws a rectangular area with a blending of one color to
+// another. The rectangle is of width w and height h. Its upper left corner is
+// positioned at point (x, y).
//
// Each color is specified with three component values, one each for red, green
// and blue. The values range from 0 to 255. The first color is specified by
@@ -992,13 +997,13 @@ func (f *Fpdf) RadialGradient(x, y, w, h float64, r1, g1, b1 int, r2, g2, b2 int
f.gradientClipEnd()
}
-// Begins a rectangular clipping operation. The rectangle is of width w and
-// height h. Its upper left corner is positioned at point (x, y). outline is
-// true to draw a border with the current draw color and line width centered on
-// the rectangle's perimeter. Only the outer half of the border will be shown.
-// After calling this method, all rendering operations (for example, Image(),
-// LinearGradient(), etc) will be clipped by the specified rectangle. Call
-// ClipEnd() to restore unclipped operations.
+// ClipRect begins a rectangular clipping operation. The rectangle is of width
+// w and height h. Its upper left corner is positioned at point (x, y). outline
+// is true to draw a border with the current draw color and line width centered
+// on the rectangle's perimeter. Only the outer half of the border will be
+// shown. After calling this method, all rendering operations (for example,
+// 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.
func (f *Fpdf) ClipRect(x, y, w, h float64, outline bool) {
@@ -1006,14 +1011,14 @@ func (f *Fpdf) ClipRect(x, y, w, h float64, outline bool) {
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"))
}
-// Begins a clipping operation in which rendering is confined to the character
-// string specified by txtStr. The origin (x, y) is on the left of the first
-// character at the baseline. The current font is used. outline is true to draw
-// a border with the current draw color and line width centered on the
-// perimeters of the text characters. Only the outer half of the border will be
-// shown. After calling this method, all rendering operations (for example,
-// Image(), LinearGradient(), etc) will be clipped. Call ClipEnd() to restore
-// unclipped operations.
+// ClipText begins a clipping operation in which rendering is confined to the
+// character string specified by txtStr. The origin (x, y) is on the left of
+// the first character at the baseline. The current font is used. outline is
+// true to draw a border with the current draw color and line width centered on
+// the perimeters of the text characters. Only the outer half of the border
+// 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) {
@@ -1027,11 +1032,11 @@ func (f *Fpdf) clipArc(x1, y1, x2, y2, x3, y3 float64) {
x2*f.k, (h-y2)*f.k, x3*f.k, (h-y3)*f.k)
}
-// Begins a rectangular clipping operation. The rectangle is of width w and
-// height h. Its upper left corner is positioned at point (x, y). The rounded
-// corners of the rectangle are specified by radius r. outline is true to draw
-// a border with the current draw color and line width centered on the
-// rectangle's perimeter. Only the outer half of the border will be shown.
+// ClipRoundedRect begins a rectangular clipping operation. The rectangle is of
+// width w and height h. Its upper left corner is positioned at point (x, y).
+// The rounded corners of the rectangle are specified by radius r. outline is
+// true to draw a border with the current draw color and line width centered on
+// the rectangle's perimeter. Only the outer half of the border will be shown.
// After calling this method, all rendering operations (for example, Image(),
// LinearGradient(), etc) will be clipped by the specified rectangle. Call
// ClipEnd() to restore unclipped operations.
@@ -1062,13 +1067,13 @@ func (f *Fpdf) ClipRoundedRect(x, y, w, h, r float64, outline bool) {
f.outf(" W %s", strIf(outline, "S", "n"))
}
-// Begins an elliptical clipping operation. The ellipse is centered at (x, y).
-// Its horizontal and vertical radii are specified by rx and ry. outline is
-// true to draw a border with the current draw color and line width centered on
-// the ellipse's perimeter. Only the outer half of the border will be shown.
-// After calling this method, all rendering operations (for example, Image(),
-// LinearGradient(), etc) will be clipped by the specified ellipse. Call
-// ClipEnd() to restore unclipped operations.
+// ClipEllipse begins an elliptical clipping operation. The ellipse is centered
+// at (x, y). Its horizontal and vertical radii are specified by rx and ry.
+// outline is true to draw a border with the current draw color and line width
+// centered on the ellipse's perimeter. Only the outer half of the border will
+// be shown. After calling this method, all rendering operations (for example,
+// 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.
func (f *Fpdf) ClipEllipse(x, y, rx, ry float64, outline bool) {
@@ -1097,10 +1102,10 @@ func (f *Fpdf) ClipEllipse(x, y, rx, ry float64, outline bool) {
strIf(outline, "S", "n"))
}
-// Begins a circular clipping operation. The circle is centered at (x, y) and
-// has radius r. outline is true to draw a border with the current draw color
-// and line width centered on the circle's perimeter. Only the outer half of
-// the border will be shown. After calling this method, all rendering
+// ClipCircle begins a circular clipping operation. The circle is centered at
+// (x, y) and has radius r. outline is true to draw a border with the current
+// draw color and line width centered on the circle's perimeter. Only the outer
+// half of the border will be shown. After calling this method, all rendering
// operations (for example, Image(), LinearGradient(), etc) will be clipped by
// the specified circle. Call ClipEnd() to restore unclipped operations.
//
@@ -1109,11 +1114,11 @@ func (f *Fpdf) ClipCircle(x, y, r float64, outline bool) {
f.ClipEllipse(x, y, r, r, outline)
}
-// Begins a clipping operation within a polygon. The figure is defined by a
-// series of vertices specified by points. The x and y fields of the points use
-// the units established in New(). The last point in the slice will be
-// implicitly joined to the first to close the polygon. outline is true to draw
-// a border with the current draw color and line width centered on the
+// ClipPolygon begins a clipping operation within a polygon. The figure is
+// defined by a series of vertices specified by points. The x and y fields of
+// the points use the units established in New(). The last point in the slice
+// will be implicitly joined to the first to close the polygon. outline is true
+// to draw a border with the current draw color and line width centered on the
// polygon's perimeter. Only the outer half of the border will be shown. After
// calling this method, all rendering operations (for example, Image(),
// LinearGradient(), etc) will be clipped by the specified polygon. Call
@@ -1133,10 +1138,10 @@ func (f *Fpdf) ClipPolygon(points []PointType, outline bool) {
f.out(s.String())
}
-// Ends a clipping operation that was started with a call to ClipRect(),
-// ClipRoundedRect(), ClipText(), ClipEllipse(), ClipCircle() or ClipPolygon().
-// Clipping operations can be nested. The document cannot be successfully
-// output while a clipping operation is active.
+// ClipEnd ends a clipping operation that was started with a call to
+// ClipRect(), ClipRoundedRect(), ClipText(), ClipEllipse(), ClipCircle() or
+// 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.
func (f *Fpdf) ClipEnd() {
@@ -1145,13 +1150,13 @@ func (f *Fpdf) ClipEnd() {
f.clipNest--
f.out("Q")
} else {
- f.err = fmt.Errorf("Error attempting to end clip operation out of sequence")
+ f.err = fmt.Errorf("error attempting to end clip operation out of sequence")
}
}
}
-// Imports a TrueType, OpenType or Type1 font and makes it available. It is
-// necessary to generate a font definition file first with the makefont
+// AddFont imports a TrueType, OpenType or Type1 font and makes it available.
+// It is necessary to generate a font definition file first with the makefont
// utility. It is not necessary to call this function for the core PDF fonts
// (courier, helvetica, times, zapfdingbats).
//
@@ -1229,9 +1234,9 @@ func (f *Fpdf) AddFont(familyStr, styleStr, fileStr string) {
return
}
-// Sets the font used to print character strings. It is mandatory to call this
-// method at least once before printing text or the resulting document will not
-// be valid.
+// SetFont sets the font used to print character strings. It is mandatory to
+// call this method at least once before printing text or the resulting
+// document will not be valid.
//
// The font can be either a standard one or a font added via the AddFont()
// method. Standard fonts use the Windows encoding cp1252 (Western Europe).
@@ -1305,7 +1310,7 @@ func (f *Fpdf) SetFont(familyStr, styleStr string, size float64) {
}
}
} else {
- f.err = fmt.Errorf("Undefined font: %s %s", familyStr, styleStr)
+ f.err = fmt.Errorf("undefined font: %s %s", familyStr, styleStr)
return
}
}
@@ -1321,7 +1326,7 @@ func (f *Fpdf) SetFont(familyStr, styleStr string, size float64) {
return
}
-// Defines the size of the current font in points.
+// SetFontSize defines the size of the current font in points.
func (f *Fpdf) SetFontSize(size float64) {
if f.fontSizePt == size {
return
@@ -1333,16 +1338,16 @@ func (f *Fpdf) SetFontSize(size float64) {
}
}
-// Creates a new internal link and returns its identifier. An internal link is
-// a clickable area which directs to another place within the document. The
-// identifier can then be passed to Cell(), Write(), Image() or Link(). The
+// AddLink creates a new internal link and returns its identifier. An internal
+// link is a clickable area which directs to another place within the document.
+// The identifier can then be passed to Cell(), Write(), Image() or Link(). The
// destination is defined with SetLink().
func (f *Fpdf) AddLink() int {
f.links = append(f.links, intLinkType{})
return len(f.links) - 1
}
-// Defines the page and position a link points to. See AddLink().
+// SetLink defines the page and position a link points to. See AddLink().
func (f *Fpdf) SetLink(link int, y float64, page int) {
if y == -1 {
y = f.y
@@ -1364,7 +1369,7 @@ func (f *Fpdf) newLink(x, y, w, h float64, link int, linkStr string) {
linkType{x * f.k, f.hPt - y*f.k, w * f.k, h * f.k, link, linkStr})
}
-// Puts a link on a rectangular area of the page. Text or image links are
+// Link puts a link on a rectangular area of the page. Text or image links are
// generally put via Cell(), Write() or Image(), but this method can be useful
// for instance to define a clickable area inside an image. link is the value
// returned by AddLink().
@@ -1372,17 +1377,17 @@ func (f *Fpdf) Link(x, y, w, h float64, link int) {
f.newLink(x, y, w, h, link, "")
}
-// Puts a link on a rectangular area of the page. Text or image links are
-// generally put via Cell(), Write() or Image(), but this method can be useful
-// for instance to define a clickable area inside an image. linkStr is the
-// target URL.
+// LinkString puts a link on a rectangular area of the page. Text or image
+// links are generally put via Cell(), Write() or Image(), but this method can
+// be useful for instance to define a clickable area inside an image. linkStr
+// is the target URL.
func (f *Fpdf) LinkString(x, y, w, h float64, linkStr string) {
f.newLink(x, y, w, h, 0, linkStr)
}
-// Sets a bookmark that will be displayed in a sidebar outline. txtStr is the
-// title of the bookmark. level specifies the level of the bookmark in the
-// outline; 0 is the top level, 1 is just below, and so on. y specifies the
+// Bookmark sets a bookmark that will be displayed in a sidebar outline. txtStr
+// is the title of the bookmark. level specifies the level of the bookmark in
+// 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.
//
@@ -1394,10 +1399,10 @@ func (f *Fpdf) Bookmark(txtStr string, level int, y float64) {
f.outlines = append(f.outlines, outlineType{text: txtStr, level: level, y: y, p: f.PageNo(), prev: -1, last: -1, next: -1, first: -1})
}
-// Prints a character string. The origin (x, y) is on the left of the first
-// character at the baseline. This method allows to place a string precisely on
-// the page, but it is usually easier to use Cell(), MultiCell() or Write()
-// which are the standard methods to print text.
+// Text prints a character string. The origin (x, y) is on the left of the
+// first character at the baseline. This method allows to place a string
+// precisely on the page, but it is usually easier to use Cell(), MultiCell()
+// or Write() which are the standard methods to print text.
func (f *Fpdf) Text(x, y float64, txtStr string) {
s := sprintf("BT %.2f %.2f Td (%s) Tj ET", x*f.k, (f.h-y)*f.k, f.escape(txtStr))
if f.underline && txtStr != "" {
@@ -1424,8 +1429,8 @@ func (f *Fpdf) SetAcceptPageBreakFunc(fnc func() bool) {
f.acceptPageBreak = fnc
}
-// Prints a cell (rectangular area) with optional borders, background color and
-// character string. The upper-left corner of the cell corresponds to the
+// CellFormat prints a rectangular cell with optional borders, background color
+// and character string. The upper-left corner of the cell corresponds to the
// current position. The text can be aligned or centered. After the call, the
// current position moves to the right or to the next line. It is possible to
// put a link on the text.
@@ -1571,20 +1576,20 @@ func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int,
return
}
-// A simpler version of CellFormat with no fill, border, links or special
-// alignment.
+// Cell is a simpler version of CellFormat with no fill, border, links or
+// special alignment.
func (f *Fpdf) Cell(w, h float64, txtStr string) {
f.CellFormat(w, h, txtStr, "", 0, "L", false, 0, "")
}
-// A simpler printf-style version of CellFormat with no fill, border, links or
-// special alignment. See documentation for the fmt package for details on
-// fmtStr and args.
+// Cellf is a simpler printf-style version of CellFormat with no fill, border,
+// links or special alignment. See documentation for the fmt package for
+// details on fmtStr and args.
func (f *Fpdf) Cellf(w, h float64, fmtStr string, args ...interface{}) {
f.CellFormat(w, h, sprintf(fmtStr, args...), "", 0, "L", false, 0, "")
}
-// This method allows printing text with line breaks. They can be automatic (as
+// MultiCell allows printing text with line breaks. They can be automatic (as
// soon as the text reaches the right border of the cell) or explicit (via the
// \n character). As many cells as necessary are output, one below the other.
//
@@ -1791,7 +1796,7 @@ func (f *Fpdf) write(h float64, txtStr string, link int, linkStr string) {
}
}
-// This method prints text from the current position. When the right margin is
+// Write prints text from the current position. When the right margin is
// reached (or the \n character is met) a line break occurs and text continues
// from the left margin. Upon method exit, the current position is left just at
// the end of the text.
@@ -1803,27 +1808,28 @@ func (f *Fpdf) Write(h float64, txtStr string) {
f.write(h, txtStr, 0, "")
}
-// Like Write but uses printf-style formatting. See the documentation for
-// package fmt for more details on fmtStr and args.
+// Writef is like Write but uses printf-style formatting. See the documentation
+// for package fmt for more details on fmtStr and args.
func (f *Fpdf) Writef(h float64, fmtStr string, args ...interface{}) {
f.write(h, sprintf(fmtStr, args...), 0, "")
}
-// Write text that when clicked launches an external URL. See Write() for
-// argument details.
+// WriteLinkString writes text that when clicked launches an external URL. See
+// Write() for argument details.
func (f *Fpdf) WriteLinkString(h float64, displayStr, targetStr string) {
f.write(h, displayStr, 0, targetStr)
}
-// Write text that when clicked jumps to another location in the PDF. linkId is
-// an identifier returned by AddLink(). See Write() for argument details.
-func (f *Fpdf) WriteLinkId(h float64, displayStr string, linkId int) {
- f.write(h, displayStr, linkId, "")
+// WriteLinkID write text that when clicked jumps to another location in the
+// PDF. linkID is an identifier returned by AddLink(). See Write() for argument
+// details.
+func (f *Fpdf) WriteLinkID(h float64, displayStr string, linkID int) {
+ f.write(h, displayStr, linkID, "")
}
-// Performs a line break. The current abscissa goes back to the left margin and
-// the ordinate increases by the amount passed in parameter. A negative value
-// of h indicates the height of the last printed cell.
+// Ln performs a line break. The current abscissa goes back to the left margin
+// and the ordinate increases by the amount passed in parameter. A negative
+// value of h indicates the height of the last printed cell.
func (f *Fpdf) Ln(h float64) {
f.x = f.lMargin
if h < 0 {
@@ -1833,11 +1839,11 @@ func (f *Fpdf) Ln(h float64) {
}
}
-// Puts a JPEG, PNG or GIF image. The size it will take on the page can be
-// specified in different ways. If both w and h are 0, the image is rendered at
-// 96 dpi. If either w or h is zero, it will be calculated from the other
-// dimension so that the aspect ratio is maintained. If w and h are negative,
-// their absolute values indicate their dpi extents.
+// Image puts a JPEG, PNG or GIF image in the current page. The size it will
+// take on the page can be specified in different ways. If both w and h are 0,
+// the image is rendered at 96 dpi. If either w or h is zero, it will be
+// calculated from the other dimension so that the aspect ratio is maintained.
+// If w and h are negative, their absolute values indicate their dpi extents.
//
// Supported JPEG formats are 24 bit, 32 bit and gray scale. Supported PNG
// formats are 24 bit, indexed color, and 8 bit indexed gray scale. If a GIF
@@ -1910,11 +1916,11 @@ func (f *Fpdf) Image(fileStr string, x, y, w, h float64, flow bool, tp string, l
return
}
-// Registers an image, adding it to the PDF file but not adding it to the page.
-// Use Image() with the same filename to add the image to the 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.
+// RegisterImage registers an image, adding it to the PDF file but not adding
+// it to the page. Use Image() with the same filename to add the image to the
+// 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) {
@@ -1924,7 +1930,7 @@ func (f *Fpdf) RegisterImage(fileStr, tp string) (info *ImageInfoType) {
if tp == "" {
pos := strings.LastIndex(fileStr, ".")
if pos < 0 {
- f.err = fmt.Errorf("Image file has no extension and no type was specified: %s", fileStr)
+ f.err = fmt.Errorf("image file has no extension and no type was specified: %s", fileStr)
return
}
tp = fileStr[pos+1:]
@@ -1941,7 +1947,7 @@ func (f *Fpdf) RegisterImage(fileStr, tp string) (info *ImageInfoType) {
case "gif":
info = f.parsegif(fileStr)
default:
- f.err = fmt.Errorf("Unsupported image type: %s", tp)
+ f.err = fmt.Errorf("unsupported image type: %s", tp)
}
if f.err != nil {
return
@@ -1953,12 +1959,12 @@ func (f *Fpdf) RegisterImage(fileStr, tp string) (info *ImageInfoType) {
return info
}
-// Returns the abscissa of the current position.
+// GetX returns the abscissa of the current position.
func (f *Fpdf) GetX() float64 {
return f.x
}
-// Defines the abscissa of the current position. If the passed value is
+// SetX defines the abscissa of the current position. If the passed value is
// negative, it is relative to the right of the page.
func (f *Fpdf) SetX(x float64) {
if x >= 0 {
@@ -1968,13 +1974,14 @@ func (f *Fpdf) SetX(x float64) {
}
}
-// Returns the ordinate of the current position.
+// GetY returns the ordinate of the current position.
func (f *Fpdf) GetY() float64 {
return f.y
}
-// Moves the current abscissa back to the left margin and sets the ordinate. If
-// the passed value is negative, it is relative to the bottom of the page.
+// SetY moves the current abscissa back to the left margin and sets the
+// ordinate. If the passed value is negative, it is relative to the bottom of
+// the page.
func (f *Fpdf) SetY(y float64) {
// dbg("SetY x %.2f, lMargin %.2f", f.x, f.lMargin)
f.x = f.lMargin
@@ -1985,15 +1992,15 @@ func (f *Fpdf) SetY(y float64) {
}
}
-// Defines the abscissa and ordinate of the current position. If the passed
-// values are negative, they are relative respectively to the right and bottom
-// of the page.
+// SetXY defines the abscissa and ordinate of the current position. If the
+// passed values are negative, they are relative respectively to the right and
+// bottom of the page.
func (f *Fpdf) SetXY(x, y float64) {
f.SetY(y)
f.SetX(x)
}
-// Send the PDF document to the writer specified by w. This method will close
+// OutputAndClose send the PDF document to the writer specified by w. This method will close
// both f and w, even if an error is detected and no document is produced.
func (f *Fpdf) OutputAndClose(w io.WriteCloser) error {
f.Output(w)
@@ -2001,10 +2008,10 @@ func (f *Fpdf) OutputAndClose(w io.WriteCloser) error {
return f.err
}
-// Send the PDF document to the writer specified by w. No output will take
-// place if an error has occured in the document generation process. w remains
-// open after this function returns. After returning, f is in a closed state
-// and its methods should not be called.
+// Output sends the PDF document to the writer specified by w. No output will
+// take place if an error has occured in the document generation process. w
+// remains open after this function returns. After returning, f is in a closed
+// state and its methods should not be called.
func (f *Fpdf) Output(w io.Writer) error {
if f.err != nil {
return f.err
@@ -2034,7 +2041,7 @@ func (f *Fpdf) getpagesizestr(sizeStr string) (size SizeType) {
size.Ht /= f.k
} else {
- f.err = fmt.Errorf("Unknown page size %s", sizeStr)
+ f.err = fmt.Errorf("unknown page size %s", sizeStr)
}
return
}
@@ -2177,7 +2184,7 @@ func (f *Fpdf) parsejpg(fileStr string) (info *ImageInfoType) {
case color.YCbCrModel:
info.cs = "DeviceRGB"
default:
- f.err = fmt.Errorf("JPEG buffer has unsupported color space (%v)", config.ColorModel)
+ f.err = fmt.Errorf("image JPEG buffer has unsupported color space (%v)", config.ColorModel)
return
}
return
@@ -2213,13 +2220,13 @@ func (f *Fpdf) parsepngstream(buf *bytes.Buffer) (info *ImageInfoType) {
info = f.newImageInfo()
// Check signature
if string(buf.Next(8)) != "\x89PNG\x0d\x0a\x1a\x0a" {
- f.err = fmt.Errorf("Not a PNG buffer")
+ f.err = fmt.Errorf("not a PNG buffer")
return
}
// Read header chunk
_ = buf.Next(4)
if string(buf.Next(4)) != "IHDR" {
- f.err = fmt.Errorf("Incorrect PNG buffer")
+ f.err = fmt.Errorf("incorrect PNG buffer")
return
}
w := f.readBeInt32(buf)
@@ -2240,21 +2247,21 @@ func (f *Fpdf) parsepngstream(buf *bytes.Buffer) (info *ImageInfoType) {
case 3:
colspace = "Indexed"
default:
- f.err = fmt.Errorf("Unknown color type in PNG buffer: %d", ct)
+ f.err = fmt.Errorf("unknown color type in PNG buffer: %d", ct)
}
if f.err != nil {
return
}
if f.readByte(buf) != 0 {
- f.err = fmt.Errorf("'Unknown compression method in PNG buffer")
+ f.err = fmt.Errorf("'unknown compression method in PNG buffer")
return
}
if f.readByte(buf) != 0 {
- f.err = fmt.Errorf("'Unknown filter method in PNG buffer")
+ f.err = fmt.Errorf("'unknown filter method in PNG buffer")
return
}
if f.readByte(buf) != 0 {
- f.err = fmt.Errorf("Interlacing not supported in PNG buffer")
+ f.err = fmt.Errorf("interlacing not supported in PNG buffer")
return
}
_ = buf.Next(4)
@@ -2305,7 +2312,7 @@ func (f *Fpdf) parsepngstream(buf *bytes.Buffer) (info *ImageInfoType) {
}
}
if colspace == "Indexed" && len(pal) == 0 {
- f.err = fmt.Errorf("Missing palette in PNG buffer")
+ f.err = fmt.Errorf("missing palette in PNG buffer")
}
info.w = float64(w)
info.h = float64(h)
@@ -2638,7 +2645,7 @@ func (f *Fpdf) putfonts() {
f.out(s.String())
f.out("endobj")
} else {
- f.err = fmt.Errorf("Unsupported font type: %s", tp)
+ f.err = fmt.Errorf("unsupported font type: %s", tp)
return
// Allow for additional types
// $mtd = 'put'.strtolower($type);
@@ -2816,7 +2823,7 @@ func (f *Fpdf) putresources() {
}
func (f *Fpdf) putinfo() {
- f.outf("/Producer %s", f.textstring("FPDF "+FPDF_VERSION))
+ f.outf("/Producer %s", f.textstring("FPDF "+cnFpdfVersion))
if len(f.title) > 0 {
f.outf("/Title %s", f.textstring(f.title))
}
diff --git a/fpdf_test.go b/fpdf_test.go
index b683b9c..5edc6c8 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -29,10 +29,10 @@ import (
// Absolute path needed for gocov tool; relative OK for test
const (
- GOFPDF_DIR = "."
- FONT_DIR = GOFPDF_DIR + "/font"
- IMG_DIR = GOFPDF_DIR + "/image"
- TEXT_DIR = GOFPDF_DIR + "/text"
+ cnGofpdfDir = "."
+ cnFontDir = cnGofpdfDir + "/font"
+ cnImgDir = cnGofpdfDir + "/image"
+ cnTextDir = cnGofpdfDir + "/text"
)
type nullWriter struct {
@@ -79,7 +79,7 @@ func docWriter(pdf *gofpdf.Fpdf, idx int) *pdfWriter {
pw.idx = idx
if pdf.Ok() {
var err error
- fileStr := fmt.Sprintf("%s/pdf/tutorial%02d.pdf", GOFPDF_DIR, idx)
+ 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)
@@ -174,7 +174,7 @@ func lorem() string {
// Hello, world
func ExampleFpdf_tutorial01() {
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
pdf.AddPage()
pdf.SetFont("Arial", "B", 16)
pdf.Cell(40, 10, "Hello World!")
@@ -185,9 +185,9 @@ func ExampleFpdf_tutorial01() {
// Header, footer and page-breaking
func ExampleFpdf_tutorial02() {
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
pdf.SetHeaderFunc(func() {
- pdf.Image(IMG_DIR+"/logo.png", 10, 6, 30, 0, false, "", 0, "")
+ pdf.Image(cnImgDir+"/logo.png", 10, 6, 30, 0, false, "", 0, "")
pdf.SetY(5)
pdf.SetFont("Arial", "B", 15)
pdf.Cell(80, 0, "")
@@ -212,7 +212,7 @@ func ExampleFpdf_tutorial02() {
// Word-wrapping, line justification and page-breaking
func ExampleFpdf_tutorial03() {
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
titleStr := "20000 Leagues Under the Seas"
pdf.SetTitle(titleStr, false)
pdf.SetAuthor("Jules Verne", false)
@@ -274,8 +274,8 @@ func ExampleFpdf_tutorial03() {
chapterTitle(chapNum, titleStr)
chapterBody(fileStr)
}
- printChapter(1, "A RUNAWAY REEF", TEXT_DIR+"/20k_c1.txt")
- printChapter(2, "THE PROS AND CONS", TEXT_DIR+"/20k_c2.txt")
+ printChapter(1, "A RUNAWAY REEF", cnTextDir+"/20k_c1.txt")
+ printChapter(2, "THE PROS AND CONS", cnTextDir+"/20k_c2.txt")
pdf.OutputAndClose(docWriter(pdf, 3))
// Output:
// Successfully generated pdf/tutorial03.pdf
@@ -285,7 +285,7 @@ func ExampleFpdf_tutorial03() {
func ExampleFpdf_tutorial04() {
var y0 float64
var crrntCol int
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
titleStr := "20000 Leagues Under the Seas"
pdf.SetTitle(titleStr, false)
pdf.SetAuthor("Jules Verne", false)
@@ -339,12 +339,11 @@ func ExampleFpdf_tutorial04() {
pdf.SetY(y0)
// Keep on page
return false
- } else {
- // Go back to first column
- setCol(0)
- // Page break
- return true
}
+ // Go back to first column
+ setCol(0)
+ // Page break
+ return true
})
pdf.SetHeaderFunc(func() {
// Arial bold 15
@@ -375,8 +374,8 @@ func ExampleFpdf_tutorial04() {
// Page number
pdf.CellFormat(0, 10, fmt.Sprintf("Page %d", pdf.PageNo()), "", 0, "C", false, 0, "")
})
- printChapter(1, "A RUNAWAY REEF", TEXT_DIR+"/20k_c1.txt")
- printChapter(2, "THE PROS AND CONS", TEXT_DIR+"/20k_c2.txt")
+ printChapter(1, "A RUNAWAY REEF", cnTextDir+"/20k_c1.txt")
+ printChapter(2, "THE PROS AND CONS", cnTextDir+"/20k_c2.txt")
pdf.OutputAndClose(docWriter(pdf, 4))
// Output:
// Successfully generated pdf/tutorial04.pdf
@@ -384,7 +383,7 @@ func ExampleFpdf_tutorial04() {
// Various table styles
func ExampleFpdf_tutorial05() {
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
type countryType struct {
nameStr, capitalStr, areaStr, popStr string
}
@@ -406,12 +405,12 @@ func ExampleFpdf_tutorial05() {
c.popStr = list[3]
countryList = append(countryList, c)
} else {
- err = fmt.Errorf("Error tokenizing %s", lineStr)
+ err = fmt.Errorf("error tokenizing %s", lineStr)
}
}
fl.Close()
if len(countryList) == 0 {
- err = fmt.Errorf("Error loading data from %s", fileStr)
+ err = fmt.Errorf("error loading data from %s", fileStr)
}
}
if err != nil {
@@ -489,7 +488,7 @@ func ExampleFpdf_tutorial05() {
}
pdf.CellFormat(wSum, 0, "", "T", 0, "", false, 0, "")
}
- loadData(TEXT_DIR + "/countries.txt")
+ loadData(cnTextDir + "/countries.txt")
pdf.SetFont("Arial", "", 14)
pdf.AddPage()
basicTable()
@@ -506,7 +505,7 @@ func ExampleFpdf_tutorial05() {
func ExampleFpdf_tutorial06() {
var boldLvl, italicLvl, underscoreLvl int
var hrefStr string
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
setStyle := func(boldAdj, italicAdj, underscoreAdj int) {
styleStr := ""
boldLvl += boldAdj
@@ -532,7 +531,7 @@ func ExampleFpdf_tutorial06() {
pdf.SetTextColor(0, 0, 0)
}
- writeHtml := func(htmlStr string) {
+ writeHTML := func(htmlStr string) {
list := htmlTokenize(htmlStr)
var ok bool
for _, el := range list {
@@ -579,19 +578,19 @@ func ExampleFpdf_tutorial06() {
pdf.Write(5, "To find out what's new in this tutorial, click ")
pdf.SetFont("", "U", 0)
link := pdf.AddLink()
- pdf.WriteLinkId(5, "here", link)
+ pdf.WriteLinkID(5, "here", link)
pdf.SetFont("", "", 0)
// Second page
pdf.AddPage()
pdf.SetLink(link, 0, -1)
- pdf.Image(IMG_DIR+"/logo.png", 10, 12, 30, 0, false, "", 0, "http://www.fpdf.org")
+ pdf.Image(cnImgDir+"/logo.png", 10, 12, 30, 0, false, "", 0, "http://www.fpdf.org")
pdf.SetLeftMargin(45)
pdf.SetFontSize(14)
htmlStr := `You can now easily print text mixing different styles: <b>bold</b>, ` +
`<i>italic</i>, <u>underlined</u>, or <b><i><u>all at once</u></i></b>!<br><br>` +
`You can also insert links on text, such as ` +
`<a href="http://www.fpdf.org">www.fpdf.org</a>, or on an image: click on the logo.`
- writeHtml(htmlStr)
+ writeHTML(htmlStr)
pdf.OutputAndClose(docWriter(pdf, 6))
// Output:
// Successfully generated pdf/tutorial06.pdf
@@ -599,7 +598,7 @@ func ExampleFpdf_tutorial06() {
// Non-standard font
func ExampleFpdf_tutorial07() {
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
pdf.AddFont("Calligrapher", "", "calligra.json")
pdf.AddPage()
pdf.SetFont("Calligrapher", "", 35)
@@ -611,18 +610,18 @@ func ExampleFpdf_tutorial07() {
// Various image types
func ExampleFpdf_tutorial08() {
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
pdf.AddPage()
pdf.SetFont("Arial", "", 11)
- pdf.Image(IMG_DIR+"/logo.png", 10, 10, 30, 0, false, "", 0, "")
+ pdf.Image(cnImgDir+"/logo.png", 10, 10, 30, 0, false, "", 0, "")
pdf.Text(50, 20, "logo.png")
- pdf.Image(IMG_DIR+"/logo.gif", 10, 40, 30, 0, false, "", 0, "")
+ pdf.Image(cnImgDir+"/logo.gif", 10, 40, 30, 0, false, "", 0, "")
pdf.Text(50, 50, "logo.gif")
- pdf.Image(IMG_DIR+"/logo-gray.png", 10, 70, 30, 0, false, "", 0, "")
+ pdf.Image(cnImgDir+"/logo-gray.png", 10, 70, 30, 0, false, "", 0, "")
pdf.Text(50, 80, "logo-gray.png")
- pdf.Image(IMG_DIR+"/logo-rgb.png", 10, 100, 30, 0, false, "", 0, "")
+ pdf.Image(cnImgDir+"/logo-rgb.png", 10, 100, 30, 0, false, "", 0, "")
pdf.Text(50, 110, "logo-rgb.png")
- pdf.Image(IMG_DIR+"/logo.jpg", 10, 130, 30, 0, false, "", 0, "")
+ pdf.Image(cnImgDir+"/logo.jpg", 10, 130, 30, 0, false, "", 0, "")
pdf.Text(50, 140, "logo.jpg")
pdf.OutputAndClose(docWriter(pdf, 8))
// Output:
@@ -634,7 +633,7 @@ func ExampleFpdf_tutorial09() {
var y0 float64
var crrntCol int
loremStr := lorem()
- pdf := gofpdf.New("L", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("L", "mm", "A4", cnFontDir)
const (
pageWd = 297.0 // A4 210.0 x 297.0
margin = 10.0
@@ -666,18 +665,17 @@ func ExampleFpdf_tutorial09() {
pdf.SetY(y0)
// Start new column, not new page
return false
- } else {
- setCol(0)
- return true
}
+ setCol(0)
+ return true
})
pdf.AddPage()
pdf.SetFont("Times", "", 12)
for j := 0; j < 20; j++ {
if j == 1 {
- pdf.Image(IMG_DIR+"/fpdf.png", -1, 0, colWd, 0, true, "", 0, "")
+ pdf.Image(cnImgDir+"/fpdf.png", -1, 0, colWd, 0, true, "", 0, "")
} else if j == 5 {
- pdf.Image(IMG_DIR+"/golang-gopher.png", -1, 0, colWd, 0, true, "", 0, "")
+ pdf.Image(cnImgDir+"/golang-gopher.png", -1, 0, colWd, 0, true, "", 0, "")
}
pdf.MultiCell(colWd, 5, loremStr, "", "", false)
pdf.Ln(-1)
@@ -689,9 +687,9 @@ func ExampleFpdf_tutorial09() {
// Test the corner cases as reported by the gocov tool
func ExampleFpdf_tutorial10() {
- gofpdf.MakeFont(FONT_DIR+"/calligra.ttf", FONT_DIR+"/cp1252.map", FONT_DIR, nil, true)
+ gofpdf.MakeFont(cnFontDir+"/calligra.ttf", cnFontDir+"/cp1252.map", cnFontDir, nil, true)
pdf := gofpdf.New("", "", "", "")
- pdf.SetFontLocation(FONT_DIR)
+ pdf.SetFontLocation(cnFontDir)
pdf.SetTitle("世界", true)
pdf.SetAuthor("世界", true)
pdf.SetSubject("世界", true)
@@ -712,7 +710,7 @@ func ExampleFpdf_tutorial11() {
thin = 0.2
thick = 3.0
)
- pdf := gofpdf.New("", "", "", FONT_DIR)
+ pdf := gofpdf.New("", "", "", cnFontDir)
pdf.SetFont("Helvetica", "", 12)
pdf.SetFillColor(200, 200, 220)
pdf.AddPage()
@@ -800,7 +798,7 @@ func ExampleFpdf_tutorial12() {
modeList := []string{"Normal", "Multiply", "Screen", "Overlay",
"Darken", "Lighten", "ColorDodge", "ColorBurn", "HardLight", "SoftLight",
"Difference", "Exclusion", "Hue", "Saturation", "Color", "Luminosity"}
- pdf := gofpdf.New("", "", "", FONT_DIR)
+ pdf := gofpdf.New("", "", "", cnFontDir)
pdf.SetLineWidth(2)
pdf.SetAutoPageBreak(false, 0)
pdf.AddPage()
@@ -824,7 +822,7 @@ func ExampleFpdf_tutorial12() {
pdf.SetXY(x, y+2)
pdf.CellFormat(rectW, rectH, "A", "", 0, "C", false, 0, "")
pdf.SetAlpha(0.5, modeList[j])
- pdf.Image(IMG_DIR+"/golang-gopher.png", x-gapX, y, rectW+2*gapX, 0, false, "", 0, "")
+ pdf.Image(cnImgDir+"/golang-gopher.png", x-gapX, y, rectW+2*gapX, 0, false, "", 0, "")
pdf.SetAlpha(1.0, "Normal")
x += rectW + gapX
j++
@@ -838,7 +836,7 @@ func ExampleFpdf_tutorial12() {
// Gradients
func ExampleFpdf_tutorial13() {
- pdf := gofpdf.New("", "", "", FONT_DIR)
+ pdf := gofpdf.New("", "", "", cnFontDir)
pdf.SetFont("Helvetica", "", 12)
pdf.AddPage()
pdf.LinearGradient(0, 0, 210, 100, 250, 250, 255, 220, 220, 225, 0, 0, 0, .5)
@@ -857,7 +855,7 @@ func ExampleFpdf_tutorial13() {
// Clipping examples
func ExampleFpdf_tutorial14() {
- pdf := gofpdf.New("", "", "", FONT_DIR)
+ pdf := gofpdf.New("", "", "", cnFontDir)
y := 10.0
pdf.AddPage()
@@ -889,7 +887,7 @@ func ExampleFpdf_tutorial14() {
y += 28
pdf.ClipEllipse(26, y+10, 16, 10, true)
- pdf.Image(IMG_DIR+"/logo.jpg", 10, y, 32, 0, false, "JPG", 0, "")
+ pdf.Image(cnImgDir+"/logo.jpg", 10, y, 32, 0, false, "JPG", 0, "")
pdf.ClipEnd()
pdf.ClipCircle(60, y+10, 10, true)
@@ -920,7 +918,7 @@ func ExampleFpdf_tutorial15() {
pdf := gofpdf.NewCustom(&gofpdf.InitType{
UnitStr: "in",
Size: gofpdf.SizeType{6, 6},
- FontDirStr: FONT_DIR,
+ FontDirStr: cnFontDir,
})
pdf.SetMargins(0.5, 1, 0.5)
pdf.SetFont("Times", "", 14)
@@ -948,7 +946,7 @@ func ExampleFpdf_tutorial15() {
// Bookmark test
func ExampleFpdf_tutorial16() {
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
pdf.AddPage()
pdf.SetFont("Arial", "", 15)
pdf.Bookmark("Page 1", 0, 0)
@@ -975,7 +973,7 @@ func ExampleFpdf_tutorial17() {
)
var refX, refY float64
var refStr string
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
pdf.AddPage()
color := func(val int) {
pdf.SetDrawColor(val, val, val)
@@ -1102,12 +1100,12 @@ func ExampleFpdf_tutorial18() {
var infoPtr *gofpdf.ImageInfoType
var fileStr string
var imgWd, imgHt, lf, tp float64
- pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir)
pdf.AddPage()
pdf.SetMargins(10, 10, 10)
pdf.SetFont("Helvetica", "", 15)
for j, str := range fileList {
- fileStr = filepath.Join(IMG_DIR, str)
+ fileStr = filepath.Join(cnImgDir, str)
infoPtr = pdf.RegisterImage(fileStr, "")
imgWd, imgHt = infoPtr.Extent()
switch j {
diff --git a/fpdftrans.go b/fpdftrans.go
index 86d9de8..b87d9b9 100644
--- a/fpdftrans.go
+++ b/fpdftrans.go
@@ -8,17 +8,18 @@ import (
// Routines in this file are translated from the work of Moritz Wagner and
// Andreas Würmser.
-// The matrix used for generalized transformations of text, drawings and images.
+// TransformMatrix is used for generalized transformations of text, drawings
+// and images.
type TransformMatrix struct {
A, B, C, D, E, F float64
}
-// Set up a transformation context for subsequent text, drawings and images.
-// The typical usage is to immediately follow a call to this method with a call
-// to one or more of the transformation methods such as 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.
+// TransformBegin sets up a transformation context for subsequent text,
+// drawings and images. The typical usage is to immediately follow a call to
+// this method with a call to one or more of the transformation methods such as
+// 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() {
@@ -26,31 +27,32 @@ func (f *Fpdf) TransformBegin() {
f.out("q")
}
-// Scale the width of the following text, drawings and images. scaleWd is the
-// percentage scaling factor. (x, y) is center of scaling.
+// TransformScaleX scales the width of the following text, drawings and images.
+// scaleWd is the percentage scaling factor. (x, y) is center of scaling.
func (f *Fpdf) TransformScaleX(scaleWd, x, y float64) {
f.TransformScale(scaleWd, 100, x, y)
}
-// Scale the height of the following text, drawings and images. scaleHt is the
-// percentage scaling factor. (x, y) is center of scaling.
+// TransformScaleY scales the height of the following text, drawings and
+// images. scaleHt is the percentage scaling factor. (x, y) is center of
+// scaling.
func (f *Fpdf) TransformScaleY(scaleHt, x, y float64) {
f.TransformScale(100, scaleHt, x, y)
}
-// Uniformly scale 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.
+// 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.
func (f *Fpdf) TransformScaleXY(s, x, y float64) {
f.TransformScale(s, s, x, y)
}
-// Generally scale the following text, drawings and images. scaleWd and scaleHt
-// are the percentage scaling factors for width and height. (x, y) is center of
-// scaling.
+// 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.
func (f *Fpdf) TransformScale(scaleWd, scaleHt, x, y float64) {
if scaleWd == 0 || scaleHt == 0 {
- f.err = fmt.Errorf("Scale factor cannot be zero")
+ f.err = fmt.Errorf("scale factor cannot be zero")
return
}
y = (f.h - y) * f.k
@@ -61,53 +63,54 @@ func (f *Fpdf) TransformScale(scaleWd, scaleHt, x, y float64) {
scaleHt, x * (1 - scaleWd), y * (1 - scaleHt)})
}
-// Horizontally mirror the following text, drawings and images. x is the axis
-// of reflection.
+// TransformMirrorHorizontal horizontally mirrors the following text, drawings
+// and images. x is the axis of reflection.
func (f *Fpdf) TransformMirrorHorizontal(x float64) {
f.TransformScale(-100, 100, x, f.y)
}
-// Vertically mirror the following text, drawings and images. y is the axis
-// of reflection.
+// TransformMirrorVertical vertically mirrors the following text, drawings and
+// images. y is the axis of reflection.
func (f *Fpdf) TransformMirrorVertical(y float64) {
f.TransformScale(100, -100, f.x, y)
}
-// Symmetrically mirror the following text, drawings and images on the point
-// specified by (x, y).
+// TransformMirrorPoint symmetrically mirrors the following text, drawings and
+// images on the point specified by (x, y).
func (f *Fpdf) TransformMirrorPoint(x, y float64) {
f.TransformScale(-100, -100, x, y)
}
-// Symmetrically mirror the following text, drawings and 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.
+// TransformMirrorLine symmetrically mirrors the following text, drawings and
+// 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.
func (f *Fpdf) TransformMirrorLine(angle, x, y float64) {
f.TransformScale(-100, 100, x, y)
f.TransformRotate(-2*(angle-90), x, y)
}
-// Move the following text, drawings and images horizontally by the amount
-// specified by tx.
+// TransformTranslateX moves the following text, drawings and images
+// horizontally by the amount specified by tx.
func (f *Fpdf) TransformTranslateX(tx float64) {
f.TransformTranslate(tx, 0)
}
-// Move the following text, drawings and images vertically by the amount
-// specified by ty.
+// TransformTranslateY moves the following text, drawings and images vertically
+// by the amount specified by ty.
func (f *Fpdf) TransformTranslateY(ty float64) {
f.TransformTranslate(0, ty)
}
-// Move the following text, drawings and images horizontally and vertically by
-// the amounts specified by tx and ty.
+// TransformTranslate moves the following text, drawings and images
+// horizontally and vertically by the amounts specified by tx and ty.
func (f *Fpdf) TransformTranslate(tx, ty float64) {
f.Transform(TransformMatrix{1, 0, 0, 1, tx * f.k, -ty * f.k})
}
-// Rotate 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.
+// 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.
func (f *Fpdf) TransformRotate(angle, x, y float64) {
y = (f.h - y) * f.k
x *= f.k
@@ -122,27 +125,27 @@ func (f *Fpdf) TransformRotate(angle, x, y float64) {
f.Transform(tm)
}
-// Horizontally skew 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).
+// 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).
func (f *Fpdf) TransformSkewX(angleX, x, y float64) {
f.TransformSkew(angleX, 0, x, y)
}
-// Vertically skew 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).
+// 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).
func (f *Fpdf) TransformSkewY(angleY, x, y float64) {
f.TransformSkew(0, angleY, x, y)
}
-// Generally skew 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). angleY ranges from -90 degrees (skew to the
-// bottom) to 90 degrees (skew to the top).
+// TransformSkew generally 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). angleY ranges from -90 degrees
+// (skew to the bottom) to 90 degrees (skew to the top).
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°")
+ f.err = fmt.Errorf("skew values must be between -90° and 90°")
return
}
x *= f.k
@@ -157,24 +160,24 @@ func (f *Fpdf) TransformSkew(angleX, angleY, x, y float64) {
f.Transform(tm)
}
-// Generally transform the following text, drawings and images according to the
-// specified matrix. It is typically easier to use the various methods such as
-// TransformRotate() and TransformMirrorVertical() instead.
+// Transform generally transforms the following text, drawings and images
+// according to the specified matrix. It is typically easier to use the various
+// methods such as TransformRotate() and TransformMirrorVertical() instead.
func (f *Fpdf) Transform(tm TransformMatrix) {
if f.transformNest > 0 {
f.outf("%.5f %.5f %.5f %.5f %.5f %.5f cm",
tm.A, tm.B, tm.C, tm.D, tm.E, tm.F)
} else if f.err == nil {
- f.err = fmt.Errorf("Transformation context is not active")
+ f.err = fmt.Errorf("transformation context is not active")
}
}
-// Apply a transformation that was begun with a call to TransformBegin().
+// TransformEnd applies a transformation that was begun with a call to TransformBegin().
func (f *Fpdf) TransformEnd() {
if f.transformNest > 0 {
f.transformNest--
f.out("Q")
} else {
- f.err = fmt.Errorf("Error attempting to end transformation operation out of sequence")
+ f.err = fmt.Errorf("error attempting to end transformation operation out of sequence")
}
}
diff --git a/ttfparser.go b/ttfparser.go
index 41574e2..3df633c 100644
--- a/ttfparser.go
+++ b/ttfparser.go
@@ -30,7 +30,7 @@ import (
"strings"
)
-// This structure contains metrics of a TrueType font.
+// TtfType contains metrics of a TrueType font.
type TtfType struct {
Embeddable bool
UnitsPerEm uint16
@@ -56,7 +56,7 @@ type ttfParser struct {
numGlyphs uint16
}
-// Extract various metrics from a TrueType font file.
+// TtfParse extracts various metrics from a TrueType font file.
func TtfParse(fileStr string) (TtfRec TtfType, err error) {
var t ttfParser
t.f, err = os.Open(fileStr)
@@ -68,11 +68,11 @@ func TtfParse(fileStr string) (TtfRec TtfType, err error) {
return
}
if version == "OTTO" {
- err = fmt.Errorf("OpenType fonts based on PostScript outlines are not supported")
+ err = fmt.Errorf("fonts based on PostScript outlines are not supported")
return
}
if version != "\x00\x01\x00\x00" {
- err = fmt.Errorf("Unrecognized file format")
+ err = fmt.Errorf("unrecognized file format")
return
}
numTables := int(t.ReadUShort())
@@ -123,7 +123,7 @@ func (t *ttfParser) ParseHead() (err error) {
t.Skip(3 * 4) // version, fontRevision, checkSumAdjustment
magicNumber := t.ReadULong()
if magicNumber != 0x5F0F3CF5 {
- err = fmt.Errorf("Incorrect magic number")
+ err = fmt.Errorf("incorrect magic number")
return
}
t.Skip(2) // flags
@@ -189,7 +189,7 @@ func (t *ttfParser) ParseCmap() (err error) {
}
}
if offset31 == 0 {
- err = fmt.Errorf("No Unicode encoding found")
+ err = fmt.Errorf("no Unicode encoding found")
return
}
startCount := make([]uint16, 0, 8)
@@ -200,7 +200,7 @@ func (t *ttfParser) ParseCmap() (err error) {
t.f.Seek(int64(t.tables["cmap"])+offset31, os.SEEK_SET)
format := t.ReadUShort()
if format != 4 {
- err = fmt.Errorf("Unexpected subtable format: %d", format)
+ err = fmt.Errorf("unexpected subtable format: %d", format)
return
}
t.Skip(2 * 2) // length, language
@@ -282,7 +282,7 @@ func (t *ttfParser) ParseName() (err error) {
}
}
if t.rec.PostScriptName == "" {
- err = fmt.Errorf("PostScript name not found")
+ err = fmt.Errorf("the name PostScript was not found")
}
}
return
@@ -329,7 +329,7 @@ func (t *ttfParser) Seek(tag string) (err error) {
if ok {
t.f.Seek(int64(ofs), os.SEEK_SET)
} else {
- err = fmt.Errorf("Table not found: %s", tag)
+ err = fmt.Errorf("table not found: %s", tag)
}
return
}
@@ -346,7 +346,7 @@ func (t *ttfParser) ReadStr(length int) (str string, err error) {
if n == length {
str = string(buf)
} else {
- err = fmt.Errorf("Unable to read %d bytes", length)
+ err = fmt.Errorf("unable to read %d bytes", length)
}
}
return
diff --git a/ttfparser_test.go b/ttfparser_test.go
index 77f2880..6b9b4c1 100644
--- a/ttfparser_test.go
+++ b/ttfparser_test.go
@@ -24,7 +24,7 @@ import (
)
func ExampleTtfParse() {
- ttf, err := gofpdf.TtfParse(FONT_DIR + "/calligra.ttf")
+ ttf, err := gofpdf.TtfParse(cnFontDir + "/calligra.ttf")
if err == nil {
fmt.Printf("Postscript name: %s\n", ttf.PostScriptName)
fmt.Printf("unitsPerEm: %8d\n", ttf.UnitsPerEm)
@@ -55,7 +55,7 @@ func hexStr(s string) string {
}
func ExampleFpdf_GetStringWidth() {
- pdf := gofpdf.New("", "", "", FONT_DIR)
+ pdf := gofpdf.New("", "", "", cnFontDir)
pdf.SetFont("Helvetica", "", 12)
pdf.AddPage()
for _, s := range []string{"Hello", "世界", "\xe7a va?"} {
diff --git a/util.go b/util.go
index 08b9503..b07a37d 100644
--- a/util.go
+++ b/util.go
@@ -28,9 +28,8 @@ import (
func round(f float64) int {
if f < 0 {
return -int(math.Floor(-f + 0.5))
- } else {
- return int(math.Floor(f + 0.5))
}
+ return int(math.Floor(f + 0.5))
}
func sprintf(fmtStr string, args ...interface{}) string {
@@ -131,18 +130,16 @@ func utf8toutf16(s string) string {
func intIf(cnd bool, a, b int) int {
if cnd {
return a
- } else {
- return b
}
+ return b
}
// Return aStr if cnd is true, otherwise bStr
func strIf(cnd bool, aStr, bStr string) string {
if cnd {
return aStr
- } else {
- return bStr
}
+ return bStr
}
// Dump the internals of the specified values