Skip to content

Commit

Permalink
Name changes for Lint conformance. <rant>One key advantage of the cam…
Browse files Browse the repository at this point in the history
…elback 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>
  • Loading branch information
Kurt Jung committed Jan 29, 2014
1 parent 3134bc7 commit 5c3d717
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
10 changes: 5 additions & 5 deletions fpdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Expand Down
24 changes: 13 additions & 11 deletions htmlbasic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -87,22 +89,22 @@ 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
Bold, Italic, Underscore bool
}
}

// 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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
32 changes: 16 additions & 16 deletions svgbasic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"`
}
Expand All @@ -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)
Expand All @@ -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
}
8 changes: 4 additions & 4 deletions svgwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
}
Expand Down

0 comments on commit 5c3d717

Please sign in to comment.