From c6b082a6263bbfcfab0dcc4f4c4bb2c024c84f10 Mon Sep 17 00:00:00 2001 From: Wang Guoliang Date: Fri, 24 Nov 2017 22:43:25 +0800 Subject: Replace strings.Index with strings.Contains --- fpdf.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'fpdf.go') diff --git a/fpdf.go b/fpdf.go index a590581..1503a4e 100644 --- a/fpdf.go +++ b/fpdf.go @@ -1931,19 +1931,19 @@ 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.Index(alignStr, "R") != -1 { + if strings.Contains(alignStr, "R") { dx = w - f.cMargin - f.GetStringWidth(txtStr) - } else if strings.Index(alignStr, "C") != -1 { + } else if strings.Contains(alignStr, "C") { dx = (w - f.GetStringWidth(txtStr)) / 2 } else { dx = f.cMargin } // Vertical alignment - if strings.Index(alignStr, "T") != -1 { + if strings.Contains(alignStr, "T") { dy = (f.fontSize - h) / 2.0 - } else if strings.Index(alignStr, "B") != -1 { + } else if strings.Contains(alignStr, "B") { dy = (h - f.fontSize) / 2.0 - } else if strings.Index(alignStr, "A") != -1 { + } else if strings.Contains(alignStr, "A") { var descent float64 d := f.currentFont.Desc if d.Descent == 0 { -- cgit v1.2.1-24-ge1ad From 1bef4f81c40b64d68788e590003f4f8fbdc4d296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82omka?= Date: Sat, 2 Dec 2017 20:28:43 +0100 Subject: Add consts for page orientations (#150) --- fpdf.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'fpdf.go') diff --git a/fpdf.go b/fpdf.go index 1503a4e..567311d 100644 --- a/fpdf.go +++ b/fpdf.go @@ -59,7 +59,9 @@ func (b *fmtBuffer) printf(fmtStr string, args ...interface{}) { func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) (f *Fpdf) { f = new(Fpdf) if orientationStr == "" { - orientationStr = "P" + orientationStr = "p" + } else { + orientationStr = strings.ToLower(orientationStr) } if unitStr == "" { unitStr = "mm" @@ -143,7 +145,6 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) } f.curPageSize = f.defPageSize // Page orientation - orientationStr = strings.ToLower(orientationStr) switch orientationStr { case "p", "portrait": f.defOrientation = "P" -- cgit v1.2.1-24-ge1ad