@@ -24,6 +24,16 @@ const subsetFont = "SubsetFont"
2424// the default margin if no margins are set
2525const 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
2838type 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
581591func (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)
17911801func (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