Skip to content

Commit 915cc7d

Browse files
committed
Export some errors
1 parent be1a680 commit 915cc7d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

cache_content_text.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const ContentTypeCell = 0
1818
// ContentTypeText text
1919
const ContentTypeText = 1
2020

21+
var ErrContentTypeNotFound = errors.New("ErrContentTypeNotFound")
22+
2123
type cacheContentText struct {
2224
//---setup---
2325
rectangle *Rect
@@ -101,7 +103,7 @@ func (c *cacheContentText) calY() (float64, error) {
101103

102104
return y, nil
103105
}
104-
return 0.0, errors.New("contentType not found")
106+
return 0.0, ErrContentTypeNotFound
105107
}
106108

107109
func (c *cacheContentText) calX() (float64, error) {
@@ -118,7 +120,7 @@ func (c *cacheContentText) calX() (float64, error) {
118120
}
119121
return x, nil
120122
}
121-
return 0.0, errors.New("contentType not found")
123+
return 0.0, ErrContentTypeNotFound
122124
}
123125

124126
// FormatFloatTrim converts a float64 into a string, like Sprintf("%.3f")

gopdf.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ const subsetFont = "SubsetFont"
2424
// the default margin if no margins are set
2525
const defaultMargin = 10.0 //for backward compatible
2626

27+
var ErrEmptyString = errors.New("empty string")
28+
29+
var ErrMissingFontFamily = errors.New("font family not found")
30+
31+
var ErrUndefinedCacheContentImage = errors.New("cacheContentImage is undefined")
32+
33+
var ErrInvalidRectangleCoordinates = errors.New("Invalid coordinates for the rectangle")
34+
35+
var ErrInvalidRectangleRadius = errors.New("Radius length cannot exceed rectangle height or width")
36+
2737
// GoPdf : A simple library for generating PDF written in Go lang
2838
type GoPdf struct {
2939

@@ -575,7 +585,7 @@ func (gp *GoPdf) maskHolder(img ImageHolder, opts MaskOptions) (int, error) {
575585
return extGStateInd, nil
576586
}
577587

578-
return 0, errors.New("cacheContentImage is undefined")
588+
return 0, ErrUndefinedCacheContentImage
579589
}
580590

581591
func (gp *GoPdf) createTransparencyXObjectGroup(image *cacheContentImage, opts MaskOptions) (int, error) {
@@ -919,7 +929,7 @@ func (gp *GoPdf) SetFontWithStyle(family string, style int, size interface{}) er
919929
}
920930

921931
if !found {
922-
return errors.New("not found font family")
932+
return ErrMissingFontFamily
923933
}
924934

925935
return nil
@@ -1286,7 +1296,7 @@ func (gp *GoPdf) SplitTextWithOption(text string, width float64, opt *BreakOptio
12861296
utf8Texts := []rune(text)
12871297
utf8TextsLen := len(utf8Texts) // utf8 string quantity
12881298
if utf8TextsLen == 0 {
1289-
return lineTexts, errors.New("empty string")
1299+
return lineTexts, ErrEmptyString
12901300
}
12911301
separatorWidth, err := gp.MeasureTextWidth(opt.Separator)
12921302
if err != nil {
@@ -1629,7 +1639,7 @@ func (gp *GoPdf) KernOverride(family string, fn FuncKernOverride) error {
16291639
}
16301640
i++
16311641
}
1632-
return errors.New("font family not found")
1642+
return ErrMissingFontFamily
16331643
}
16341644

16351645
// SetTextColor : function sets the text color
@@ -1790,7 +1800,7 @@ func (gp *GoPdf) Polygon(points []Point, style string) {
17901800
// pdf.Rectangle(196.6, 336.8, 398.3, 379.3, "DF", 3, 10)
17911801
func (gp *GoPdf) Rectangle(x0 float64, y0 float64, x1 float64, y1 float64, style string, radius float64, radiusPointNum int) error {
17921802
if x1 <= x0 || y1 <= y0 {
1793-
return errors.New("Invalid coordinates for the rectangle")
1803+
return ErrInvalidRectangleCoordinates
17941804
}
17951805
if radiusPointNum <= 0 || radius <= 0 {
17961806
//draw rectangle without round corner
@@ -1804,7 +1814,7 @@ func (gp *GoPdf) Rectangle(x0 float64, y0 float64, x1 float64, y1 float64, style
18041814
} else {
18051815

18061816
if radius > (x1-x0) || radius > (y1-y0) {
1807-
return errors.New("Radius length cannot exceed rectangle height or width")
1817+
return ErrInvalidRectangleCoordinates
18081818
}
18091819

18101820
degrees := []float64{}

0 commit comments

Comments
 (0)