Skip to content

Commit

Permalink
fixed warnings gocritic 3.3 (jung-kurt#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
kveselkov authored and jung-kurt committed Sep 15, 2018
1 parent 964b122 commit 7d57599
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 34 deletions.
10 changes: 7 additions & 3 deletions font.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,17 @@ func MakeFont(fontFileStr, encodingFileStr, dstDirStr string, msgWriter io.Write
extStr := strings.ToLower(fontFileStr[len(fontFileStr)-3:])
// printf("Font file extension [%s]\n", extStr)
var tpStr string
if extStr == "ttf" || extStr == "otf" {
switch extStr {
case "ttf":
fallthrough
case "otf":
tpStr = "TrueType"
} else if extStr == "pfb" {
case "pfb":
tpStr = "Type1"
} else {
default:
return fmt.Errorf("unrecognized font file extension: %s", extStr)
}

var info fontInfoType
encList, err := loadMap(encodingFileStr)
if err != nil {
Expand Down
43 changes: 22 additions & 21 deletions fpdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ func (f *Fpdf) gradientClipEnd() {
f.out("Q")
}

func (f *Fpdf) gradient(tp int, r1, g1, b1 int, r2, g2, b2 int, x1, y1 float64, x2, y2 float64, r float64) {
func (f *Fpdf) gradient(tp, r1, g1, b1, r2, g2, b2 int, x1, y1, x2, y2, r float64) {
pos := len(f.gradientList)
clr1 := rgbColorValue(r1, g1, b1, "", "")
clr2 := rgbColorValue(r2, g2, b2, "", "")
Expand All @@ -1254,7 +1254,7 @@ func (f *Fpdf) gradient(tp int, r1, g1, b1 int, r2, g2, b2 int, x1, y1 float64,
// anchored on the rectangle edge. Color 1 is used up to the origin of the
// vector and color 2 is used beyond the vector's end point. Between the points
// the colors are gradually blended.
func (f *Fpdf) LinearGradient(x, y, w, h float64, r1, g1, b1 int, r2, g2, b2 int, x1, y1, x2, y2 float64) {
func (f *Fpdf) LinearGradient(x, y, w, h float64, r1, g1, b1, r2, g2, b2 int, x1, y1, x2, y2 float64) {
f.gradientClipStart(x, y, w, h)
f.gradient(2, r1, g1, b1, r2, g2, b2, x1, y1, x2, y2, 0)
f.gradientClipEnd()
Expand All @@ -1278,7 +1278,7 @@ func (f *Fpdf) LinearGradient(x, y, w, h float64, r1, g1, b1 int, r2, g2, b2 int
// the circle to avoid rendering problems.
//
// The LinearGradient() example demonstrates this method.
func (f *Fpdf) RadialGradient(x, y, w, h float64, r1, g1, b1 int, r2, g2, b2 int, x1, y1, x2, y2, r float64) {
func (f *Fpdf) RadialGradient(x, y, w, h float64, r1, g1, b1, r2, g2, b2 int, x1, y1, x2, y2, r float64) {
f.gradientClipStart(x, y, w, h)
f.gradient(3, r1, g1, b1, r2, g2, b2, x1, y1, x2, y2, r)
f.gradientClipEnd()
Expand Down Expand Up @@ -1502,7 +1502,7 @@ func (f *Fpdf) AddFont(familyStr, styleStr, fileStr string) {
// jsonFileBytes contain all bytes of JSON file.
//
// zFileBytes contain all bytes of Z file.
func (f *Fpdf) AddFontFromBytes(familyStr string, styleStr string, jsonFileBytes []byte, zFileBytes []byte) {
func (f *Fpdf) AddFontFromBytes(familyStr, styleStr string, jsonFileBytes, zFileBytes []byte) {
if f.err != nil {
return
}
Expand Down Expand Up @@ -1900,7 +1900,7 @@ func (f *Fpdf) SetAcceptPageBreakFunc(fnc func() bool) {
//
// linkStr is a target URL or empty for no external link. A non--zero value for
// link takes precedence over linkStr.
func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int,
func (f *Fpdf) CellFormat(w, h float64, txtStr, borderStr string, ln int,
alignStr string, fill bool, link int, linkStr string) {
// dbg("CellFormat. h = %.2f, borderStr = %s", h, borderStr)
if f.err != nil {
Expand Down Expand Up @@ -1978,19 +1978,22 @@ func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int,
if len(txtStr) > 0 {
var dx, dy float64
// Horizontal alignment
if strings.Contains(alignStr, "R") {
switch {
case strings.Contains(alignStr, "R"):
dx = w - f.cMargin - f.GetStringWidth(txtStr)
} else if strings.Contains(alignStr, "C") {
case strings.Contains(alignStr, "C"):
dx = (w - f.GetStringWidth(txtStr)) / 2
} else {
default:
dx = f.cMargin
}

// Vertical alignment
if strings.Contains(alignStr, "T") {
switch {
case strings.Contains(alignStr, "T"):
dy = (f.fontSize - h) / 2.0
} else if strings.Contains(alignStr, "B") {
case strings.Contains(alignStr, "B"):
dy = (h - f.fontSize) / 2.0
} else if strings.Contains(alignStr, "A") {
case strings.Contains(alignStr, "A"):
var descent float64
d := f.currentFont.Desc
if d.Descent == 0 {
Expand All @@ -2000,7 +2003,7 @@ func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int,
descent = float64(d.Descent) * f.fontSize / float64(d.Ascent-d.Descent)
}
dy = (h-f.fontSize)/2.0 - descent
} else {
default:
dy = 0
}
if f.colorFlag {
Expand Down Expand Up @@ -2369,7 +2372,7 @@ func (f *Fpdf) WriteAligned(width, lineHeight float64, textStr, alignStr string)
lines := f.SplitLines([]byte(textStr), width)

for _, lineBt := range lines {
lineStr := string(lineBt[:])
lineStr := string(lineBt)
lineWidth := f.GetStringWidth(lineStr)

switch alignStr {
Expand Down Expand Up @@ -3321,7 +3324,8 @@ func (f *Fpdf) putfonts() {
f.fonts[key] = font
tp := font.Tp
name := font.Name
if tp == "Core" {
switch tp {
case "Core":
// Core font
f.newobj()
f.out("<</Type /Font")
Expand All @@ -3332,7 +3336,9 @@ func (f *Fpdf) putfonts() {
}
f.out(">>")
f.out("endobj")
} else if tp == "Type1" || tp == "TrueType" {
case "Type1":
fallthrough
case "TrueType":
// Additional Type1 or TrueType/OpenType font
f.newobj()
f.out("<</Type /Font")
Expand Down Expand Up @@ -3378,14 +3384,9 @@ func (f *Fpdf) putfonts() {
s.printf("/FontFile%s %d 0 R>>", suffix, f.fontFiles[font.File].n)
f.out(s.String())
f.out("endobj")
} else {
default:
f.err = fmt.Errorf("unsupported font type: %s", tp)
return
// Allow for additional types
// $mtd = 'put'.strtolower($type);
// if(!method_exists($this,$mtd))
// $this->Error('Unsupported font type: '.$type);
// $this->$mtd($font);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions png.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ func (f *Fpdf) parsepngstream(buf *bytes.Buffer, readdpi bool) (info *ImageInfoT
// dbg("tRNS")
// Read transparency info
t := buf.Next(n)
if ct == 0 {
switch ct {
case 0:
trns = []int{int(t[1])} // ord(substr($t,1,1)));
} else if ct == 2 {
case 2:
trns = []int{int(t[1]), int(t[3]), int(t[5])} // array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1)));
} else {
default:
pos := strings.Index(string(t), "\x00")
if pos >= 0 {
trns = []int{pos} // array($pos);
Expand Down
8 changes: 4 additions & 4 deletions protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ func oValueGen(userPass, ownerPass []byte) (v []byte) {
var c *rc4.Cipher
tmp := md5.Sum(ownerPass)
c, _ = rc4.NewCipher(tmp[0:5])
cap := len(userPass)
v = make([]byte, cap, cap)
size := len(userPass)
v = make([]byte, size, size)
c.XORKeyStream(v, userPass)
return
}

func (p *protectType) uValueGen() (v []byte) {
var c *rc4.Cipher
c, _ = rc4.NewCipher(p.encryptionKey)
cap := len(p.padding)
v = make([]byte, cap, cap)
size := len(p.padding)
v = make([]byte, size, size)
c.XORKeyStream(v, p.padding)
return
}
Expand Down
7 changes: 4 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,22 @@ func utf8toutf16(s string) string {
for i < nb {
c1 := byte(s[i])
i++
if c1 >= 224 {
switch {
case c1 >= 224:
// 3-byte character
c2 := byte(s[i])
i++
c3 := byte(s[i])
i++
res = append(res, ((c1&0x0F)<<4)+((c2&0x3C)>>2),
((c2&0x03)<<6)+(c3&0x3F))
} else if c1 >= 192 {
case c1 >= 192:
// 2-byte character
c2 := byte(s[i])
i++
res = append(res, ((c1 & 0x1C) >> 2),
((c1&0x03)<<6)+(c2&0x3F))
} else {
default:
// Single-byte character
res = append(res, 0, c1)
}
Expand Down

0 comments on commit 7d57599

Please sign in to comment.