summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@code.google.com>2014-01-29 11:38:29 -0500
committerKurt Jung <kurt.w.jung@code.google.com>2014-01-29 11:38:29 -0500
commit5c3d717c55e3a9cadd924d6b20eab99f8f9615ba (patch)
tree95cb11ab3e8e04200af7014cbd480ac58e1f6082
parent3134bc7e5679c258c6b6f20e4214c75d1314ff48 (diff)
Name changes for Lint conformance. <rant>One key advantage of the camelback naming convention is that a machine can quickly tokenize name segments for indexing and tagging purposes. For example, HtmlWrite easily breaks into Html and Write. By capitalizing all letters in an initialism, this name breaks into H, T, M, L, and Write -- not as useful for tagging purposes. Rather than having to manually filter through the mostly valuable output of golint, I have grudgingly changed names so that golint produces no output.</rant>
-rw-r--r--fpdf_test.go10
-rw-r--r--htmlbasic.go24
-rw-r--r--svgbasic.go32
-rw-r--r--svgwrite.go8
4 files changed, 38 insertions, 36 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index 32e4237..e771ac5 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -471,7 +471,7 @@ func ExampleFpdf_tutorial06() {
`<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.`
- html := pdf.HtmlBasicNew()
+ html := pdf.HTMLBasicNew()
html.Write(lineHt, htmlStr)
pdf.OutputAndClose(docWriter(pdf, 6))
// Output:
@@ -1050,7 +1050,7 @@ func ExampleFpdf_tutorial20() {
sigFileStr = "signature.svg"
)
var (
- sig gofpdf.SvgBasicType
+ sig gofpdf.SVGBasicType
err error
)
pdf := gofpdf.New("P", "mm", "A4", cnFontDir) // A4 210.0 x 297.0
@@ -1065,9 +1065,9 @@ func ExampleFpdf_tutorial20() {
`type of vector graphic returned from a ` +
`<a href="http://willowsystems.github.io/jSignature/#/demo/">jSignature</a> ` +
`web control is supported and is used in this example.`
- html := pdf.HtmlBasicNew()
+ html := pdf.HTMLBasicNew()
html.Write(lineHt, htmlStr)
- sig, err = gofpdf.SvgBasicFileParse(imageFile(sigFileStr))
+ sig, err = gofpdf.SVGBasicFileParse(imageFile(sigFileStr))
if err == nil {
scale := 100 / sig.Wd
scaleY := 30 / sig.Ht
@@ -1078,7 +1078,7 @@ func ExampleFpdf_tutorial20() {
pdf.SetLineWidth(0.25)
pdf.SetDrawColor(0, 0, 128)
pdf.SetXY((210.0-scale*sig.Wd)/2.0, pdf.GetY()+10)
- pdf.SvgBasicWrite(&sig, scale)
+ pdf.SVGBasicWrite(&sig, scale)
} else {
pdf.SetError(err)
}
diff --git a/htmlbasic.go b/htmlbasic.go
index d2c71ea..93e4924 100644
--- a/htmlbasic.go
+++ b/htmlbasic.go
@@ -21,25 +21,27 @@ import (
"strings"
)
-type HtmlBasicSegmentType struct {
+// HTMLBasicSegmentType defines a segment of literal text in which the current
+// attributes do not vary, or an open tag or a close tag.
+type HTMLBasicSegmentType struct {
Cat byte // 'O' open tag, 'C' close tag, 'T' text
Str string // Literal text unchanged, tags are lower case
Attr map[string]string // Attribute keys are lower case
}
-// HtmlBasicTokenize returns a list of HTML tags and literal elements. This is
+// HTMLBasicTokenize returns a list of HTML tags and literal elements. This is
// done with regular expressions, so the result is only marginally better than
// useless.
-func HtmlBasicTokenize(htmlStr string) (list []HtmlBasicSegmentType) {
+func HTMLBasicTokenize(htmlStr string) (list []HTMLBasicSegmentType) {
// This routine is adapted from http://www.fpdf.org/
- list = make([]HtmlBasicSegmentType, 0, 16)
+ list = make([]HTMLBasicSegmentType, 0, 16)
htmlStr = strings.Replace(htmlStr, "\n", " ", -1)
htmlStr = strings.Replace(htmlStr, "\r", "", -1)
tagRe, _ := regexp.Compile(`(?U)<.*>`)
attrRe, _ := regexp.Compile(`([^=]+)=["']?([^"']+)`)
capList := tagRe.FindAllStringIndex(htmlStr, -1)
if capList != nil {
- var seg HtmlBasicSegmentType
+ var seg HTMLBasicSegmentType
var parts []string
pos := 0
for _, cap := range capList {
@@ -87,12 +89,12 @@ func HtmlBasicTokenize(htmlStr string) (list []HtmlBasicSegmentType) {
return
}
-// HtmlBasicType is used for rendering a very basic subset of HTML. It supports
+// HTMLBasicType is used for rendering a very basic subset of HTML. It supports
// only hyperlinks and bold, italic and underscore attributes. In the Link
// structure, the ClrR, ClrG and ClrB fields (0 through 255) define the color
// of hyperlinks. The Bold, Italic and Underscore values define the hyperlink
// style.
-type HtmlBasicType struct {
+type HTMLBasicType struct {
pdf *Fpdf
Link struct {
ClrR, ClrG, ClrB int
@@ -100,9 +102,9 @@ type HtmlBasicType struct {
}
}
-// HtmlBasicNew returns an instance that facilitates writing basic HTML in the
+// HTMLBasicNew returns an instance that facilitates writing basic HTML in the
// specified PDF file.
-func (f *Fpdf) HtmlBasicNew() (html HtmlBasicType) {
+func (f *Fpdf) HTMLBasicNew() (html HTMLBasicType) {
html.pdf = f
html.Link.ClrR, html.Link.ClrG, html.Link.ClrB = 0, 0, 128
html.Link.Bold, html.Link.Italic, html.Link.Underscore = false, false, true
@@ -117,7 +119,7 @@ func (f *Fpdf) HtmlBasicNew() (html HtmlBasicType) {
// of the text.
//
// lineHt indicates the line height in the unit of measure specified in New().
-func (html *HtmlBasicType) Write(lineHt float64, htmlStr string) {
+func (html *HTMLBasicType) Write(lineHt float64, htmlStr string) {
var boldLvl, italicLvl, underscoreLvl, linkBold, linkItalic, linkUnderscore int
var textR, textG, textB = html.pdf.GetTextColor()
var hrefStr string
@@ -154,7 +156,7 @@ func (html *HtmlBasicType) Write(lineHt float64, htmlStr string) {
setStyle(-linkBold, -linkItalic, -linkUnderscore)
html.pdf.SetTextColor(textR, textG, textB)
}
- list := HtmlBasicTokenize(htmlStr)
+ list := HTMLBasicTokenize(htmlStr)
var ok bool
for _, el := range list {
switch el.Cat {
diff --git a/svgbasic.go b/svgbasic.go
index 526f4eb..749933e 100644
--- a/svgbasic.go
+++ b/svgbasic.go
@@ -34,15 +34,15 @@ func init() {
"M", " M ", "m", " m ")
}
-// SvgBasicSegmentType describes a single curve or position segment
-type SvgBasicSegmentType struct {
+// SVGBasicSegmentType describes a single curve or position segment
+type SVGBasicSegmentType struct {
Cmd byte // See http://www.w3.org/TR/SVG/paths.html for path command structure
Arg [6]float64
}
-func absolutizePath(segs []SvgBasicSegmentType) {
+func absolutizePath(segs []SVGBasicSegmentType) {
var x, y float64
- var segPtr *SvgBasicSegmentType
+ var segPtr *SVGBasicSegmentType
adjust := func(pos int, adjX, adjY float64) {
segPtr.Arg[pos] += adjX
segPtr.Arg[pos+1] += adjY
@@ -83,8 +83,8 @@ func absolutizePath(segs []SvgBasicSegmentType) {
}
}
-func pathParse(pathStr string) (segs []SvgBasicSegmentType, err error) {
- var seg SvgBasicSegmentType
+func pathParse(pathStr string) (segs []SVGBasicSegmentType, err error) {
+ var seg SVGBasicSegmentType
var j, argJ, argCount, prevArgCount int
setup := func(n int) {
// It is not strictly necessary to clear arguments, but result may be clearer
@@ -154,20 +154,20 @@ func pathParse(pathStr string) (segs []SvgBasicSegmentType, err error) {
return
}
-// SvgBasicType aggregates the information needed to describe a multi-segment
+// SVGBasicType aggregates the information needed to describe a multi-segment
// basic vector image
-type SvgBasicType struct {
+type SVGBasicType struct {
Wd, Ht float64
- Segments [][]SvgBasicSegmentType
+ Segments [][]SVGBasicSegmentType
}
-// SvgBasicParse parses a simple scalable vector graphics (SVG) buffer into a
+// SVGBasicParse parses a simple scalable vector graphics (SVG) buffer into a
// descriptor. Only a small subset of the SVG standard, in particular the path
// information generated by jSignature, is supported. The returned path data
// includes only the commands 'M' (absolute moveto: x, y), 'L' (absolute
// lineto: x, y), and 'C' (absolute cubic Bézier curve: cx0, cy0, cx1, cy1,
// x1,y1).
-func SvgBasicParse(buf []byte) (sig SvgBasicType, err error) {
+func SVGBasicParse(buf []byte) (sig SVGBasicType, err error) {
type pathType struct {
D string `xml:"d,attr"`
}
@@ -181,7 +181,7 @@ func SvgBasicParse(buf []byte) (sig SvgBasicType, err error) {
if err == nil {
if src.Wd > 0 && src.Ht > 0 {
sig.Wd, sig.Ht = src.Wd, src.Ht
- var segs []SvgBasicSegmentType
+ var segs []SVGBasicSegmentType
for _, path := range src.Paths {
if err == nil {
segs, err = pathParse(path.D)
@@ -198,14 +198,14 @@ func SvgBasicParse(buf []byte) (sig SvgBasicType, err error) {
return
}
-// SvgBasicFileParse parses a simple scalable vector graphics (SVG) file into a
-// basic descriptor. See SvgBasicParse for additional comments and tutorial 20
+// SVGBasicFileParse parses a simple scalable vector graphics (SVG) file into a
+// basic descriptor. See SVGBasicParse for additional comments and tutorial 20
// for an example of this function.
-func SvgBasicFileParse(svgFileStr string) (sig SvgBasicType, err error) {
+func SVGBasicFileParse(svgFileStr string) (sig SVGBasicType, err error) {
var buf []byte
buf, err = ioutil.ReadFile(svgFileStr)
if err == nil {
- sig, err = SvgBasicParse(buf)
+ sig, err = SVGBasicParse(buf)
}
return
}
diff --git a/svgwrite.go b/svgwrite.go
index ea445c1..a2213a2 100644
--- a/svgwrite.go
+++ b/svgwrite.go
@@ -16,7 +16,7 @@
package gofpdf
-// SvgBasicWrite renders the paths encoded in the basic SVG image specified by
+// SVGBasicWrite renders the paths encoded in the basic SVG image specified by
// sb. The scale value is used to convert the coordinates in the path to the
// unit of measure specified in New(). The current position (as set with a call
// to SetXY()) is used as the origin of the image. The current line cap style
@@ -25,12 +25,12 @@ package gofpdf
// paths.
//
// See example 20 for a demonstration of this function.
-func (f *Fpdf) SvgBasicWrite(sb *SvgBasicType, scale float64) {
+func (f *Fpdf) SVGBasicWrite(sb *SVGBasicType, scale float64) {
originX, originY := f.GetXY()
var x, y, newX, newY float64
var cx0, cy0, cx1, cy1 float64
- var path []SvgBasicSegmentType
- var seg SvgBasicSegmentType
+ var path []SVGBasicSegmentType
+ var seg SVGBasicSegmentType
val := func(arg int) (float64, float64) {
return originX + scale*seg.Arg[arg], originY + scale*seg.Arg[arg+1]
}