summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2017-08-18 14:06:29 -0400
committerKurt <kurt.w.jung@gmail.com>2017-08-18 14:06:29 -0400
commitef5029596657de75a312ed095fd29ec7aacee058 (patch)
tree6da63dfc50b28764859d38403eeaae5a6ae05238
parente79bdb537c4e4e719b91d5f35afa9f54976e0d4d (diff)
Return 'do nothing' function for Unicode translator rather than nil if document is in error state
-rw-r--r--util.go36
1 files changed, 19 insertions, 17 deletions
diff --git a/util.go b/util.go
index 2c8c5bb..dbdaa7c 100644
--- a/util.go
+++ b/util.go
@@ -153,6 +153,11 @@ func strIf(cnd bool, aStr, bStr string) string {
return bStr
}
+// doNothing returns the passed string with no translation.
+func doNothing(s string) string {
+ return s
+}
+
// Dump the internals of the specified values
// func dump(fileStr string, a ...interface{}) {
// fl, err := os.OpenFile(fileStr, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
@@ -219,9 +224,7 @@ func UnicodeTranslator(r io.Reader) (f func(string) string, err error) {
if err == nil {
f = repClosure(m)
} else {
- f = func(s string) string {
- return s
- }
+ f = doNothing
}
return
}
@@ -241,9 +244,7 @@ func UnicodeTranslatorFromFile(fileStr string) (f func(string) string, err error
f, err = UnicodeTranslator(fl)
fl.Close()
} else {
- f = func(s string) string {
- return s
- }
+ f = doNothing
}
return
}
@@ -260,21 +261,22 @@ func UnicodeTranslatorFromFile(fileStr string) (f func(string) string, err error
// If an error occurs reading the descriptor, the returned function is valid
// but does not perform any rune translation.
//
-// The CellFormat (4) example demonstrates this method.
+// The CellFormat_codepage example demonstrates this method.
func (f *Fpdf) UnicodeTranslatorFromDescriptor(cpStr string) (rep func(string) string) {
var str string
var ok bool
- if f.err != nil {
- return
- }
- if len(cpStr) == 0 {
- cpStr = "cp1252"
- }
- str, ok = embeddedMapList[cpStr]
- if ok {
- rep, f.err = UnicodeTranslator(strings.NewReader(str))
+ if f.err == nil {
+ if len(cpStr) == 0 {
+ cpStr = "cp1252"
+ }
+ str, ok = embeddedMapList[cpStr]
+ if ok {
+ rep, f.err = UnicodeTranslator(strings.NewReader(str))
+ } else {
+ rep, f.err = UnicodeTranslatorFromFile(filepath.Join(f.fontpath, cpStr) + ".map")
+ }
} else {
- rep, f.err = UnicodeTranslatorFromFile(filepath.Join(f.fontpath, cpStr) + ".map")
+ rep = doNothing
}
return
}