From 33558d447b489420d1bbc1cb9188f963cb6abda1 Mon Sep 17 00:00:00 2001 From: hyzgh <31174102+hyzgh@users.noreply.github.com> Date: Tue, 20 Aug 2019 19:50:37 +0800 Subject: improve the speed of MultiCell Change-Id: Ieaacbf19acfce1e776eccbfa3bbc030a2ab93d5f --- fpdf.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fpdf.go b/fpdf.go index 377f152..747346f 100644 --- a/fpdf.go +++ b/fpdf.go @@ -2596,11 +2596,12 @@ func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill ls := 0 ns := 0 nl := 1 + srune := []rune(s) for i < nb { // Get next character var c rune if f.isCurrentUTF8 { - c = []rune(s)[i] + c = srune[i] } else { c = rune(byte(s[i])) } @@ -2620,7 +2621,7 @@ func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill newAlignStr = "L" } } - f.CellFormat(w, h, string([]rune(s)[j:i]), b, 2, newAlignStr, fill, 0, "") + f.CellFormat(w, h, string(srune[j:i]), b, 2, newAlignStr, fill, 0, "") } else { f.CellFormat(w, h, s[j:i], b, 2, alignStr, fill, 0, "") } @@ -2656,7 +2657,7 @@ func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill f.out("0 Tw") } if f.isCurrentUTF8 { - f.CellFormat(w, h, string([]rune(s)[j:i]), b, 2, alignStr, fill, 0, "") + f.CellFormat(w, h, string(srune[j:i]), b, 2, alignStr, fill, 0, "") } else { f.CellFormat(w, h, s[j:i], b, 2, alignStr, fill, 0, "") } @@ -2670,7 +2671,7 @@ func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill f.outf("%.3f Tw", f.ws*f.k) } if f.isCurrentUTF8 { - f.CellFormat(w, h, string([]rune(s)[j:sep]), b, 2, alignStr, fill, 0, "") + f.CellFormat(w, h, string(srune[j:sep]), b, 2, alignStr, fill, 0, "") } else { f.CellFormat(w, h, s[j:sep], b, 2, alignStr, fill, 0, "") } @@ -2704,7 +2705,7 @@ func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill alignStr = "" } } - f.CellFormat(w, h, string([]rune(s)[j:i]), b, 2, alignStr, fill, 0, "") + f.CellFormat(w, h, string(srune[j:i]), b, 2, alignStr, fill, 0, "") } else { f.CellFormat(w, h, s[j:i], b, 2, alignStr, fill, 0, "") } -- cgit v1.2.1-24-ge1ad