unipdf/internal/textencoding/simple_pdf.go
2019-05-16 20:44:51 +00:00

119 lines
5.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
package textencoding
const (
basePdfDoc = "PdfDocEncoding"
baseStandard = "StandardEncoding"
)
var (
pdfDoc = newSimpleMapping(basePdfDoc, pdfDocCharToRune)
standard = newSimpleMapping(baseStandard, standardCharToRune)
)
func init() {
RegisterSimpleEncoding(basePdfDoc, NewPdfDocEncoder)
RegisterSimpleEncoding(baseStandard, NewStandardEncoder)
}
// NewPdfDocEncoder returns a SimpleEncoder that implements PdfDocEncoding.
func NewPdfDocEncoder() SimpleEncoder {
return pdfDoc.NewEncoder()
}
// NewStandardEncoder returns a SimpleEncoder that implements StandardEncoding.
func NewStandardEncoder() SimpleEncoder {
return standard.NewEncoder()
}
var pdfDocCharToRune = map[byte]rune{ // 252 entries
0x1: '\x01', 0x2: '\x02', 0x3: '\x03', 0x4: '\x04', 0x5: '\x05',
0x6: '\x06', 0x7: '\a', 0x8: '\b', 0x9: '\t', 0xa: '\n',
0xb: '\v', 0xc: '\f', 0xd: '\r', 0xe: '\x0e', 0xf: '\x0f',
0x10: '\x10', 0x11: '\x11', 0x12: '\x12', 0x13: '\x13', 0x14: '\x14',
0x15: '\x15', 0x16: '\x17', 0x17: '\x17', 0x18: '˘', 0x19: 'ˇ',
0x1a: 'ˆ', 0x1b: '˙', 0x1c: '˝', 0x1d: '˛', 0x1e: '˚',
0x1f: '˜', 0x20: ' ', 0x21: '!', 0x22: '"', 0x23: '#',
0x24: '$', 0x25: '%', 0x26: '&', 0x27: '\'', 0x28: '(',
0x29: ')', 0x2a: '*', 0x2b: '+', 0x2c: ',', 0x2d: '-',
0x2e: '.', 0x2f: '/', 0x30: '0', 0x31: '1', 0x32: '2',
0x33: '3', 0x34: '4', 0x35: '5', 0x36: '6', 0x37: '7',
0x38: '8', 0x39: '9', 0x3a: ':', 0x3b: ';', 0x3c: '<',
0x3d: '=', 0x3e: '>', 0x3f: '?', 0x40: '@', 0x41: 'A',
0x42: 'B', 0x43: 'C', 0x44: 'D', 0x45: 'E', 0x46: 'F',
0x47: 'G', 0x48: 'H', 0x49: 'I', 0x4a: 'J', 0x4b: 'K',
0x4c: 'L', 0x4d: 'M', 0x4e: 'N', 0x4f: 'O', 0x50: 'P',
0x51: 'Q', 0x52: 'R', 0x53: 'S', 0x54: 'T', 0x55: 'U',
0x56: 'V', 0x57: 'W', 0x58: 'X', 0x59: 'Y', 0x5a: 'Z',
0x5b: '[', 0x5c: '\\', 0x5d: ']', 0x5e: '^', 0x5f: '_',
0x60: '`', 0x61: 'a', 0x62: 'b', 0x63: 'c', 0x64: 'd',
0x65: 'e', 0x66: 'f', 0x67: 'g', 0x68: 'h', 0x69: 'i',
0x6a: 'j', 0x6b: 'k', 0x6c: 'l', 0x6d: 'm', 0x6e: 'n',
0x6f: 'o', 0x70: 'p', 0x71: 'q', 0x72: 'r', 0x73: 's',
0x74: 't', 0x75: 'u', 0x76: 'v', 0x77: 'w', 0x78: 'x',
0x79: 'y', 0x7a: 'z', 0x7b: '{', 0x7c: '|', 0x7d: '}',
0x7e: '~', 0x80: '•', 0x81: '†', 0x82: '‡', 0x83: '…',
0x84: '—', 0x85: '', 0x86: 'ƒ', 0x87: '', 0x88: '',
0x89: '', 0x8a: '', 0x8b: '‰', 0x8c: '„', 0x8d: '“',
0x8e: '”', 0x8f: '', 0x90: '', 0x91: '', 0x92: '™',
0x93: 'fi', 0x94: 'fl', 0x95: 'Ł', 0x96: 'Œ', 0x97: 'Š',
0x98: 'Ÿ', 0x99: 'Ž', 0x9a: 'ı', 0x9b: 'ł', 0x9c: 'œ',
0x9d: 'š', 0x9e: 'ž', 0xa0: '€', 0xa1: '¡', 0xa2: '¢',
0xa3: '£', 0xa4: '¤', 0xa5: '¥', 0xa6: '¦', 0xa7: '§',
0xa8: '¨', 0xa9: '©', 0xaa: 'ª', 0xab: '«', 0xac: '¬',
0xae: '®', 0xaf: '¯', 0xb0: '°', 0xb1: '±', 0xb2: '²',
0xb3: '³', 0xb4: '´', 0xb5: 'µ', 0xb6: '¶', 0xb7: '·',
0xb8: '¸', 0xb9: '¹', 0xba: 'º', 0xbb: '»', 0xbc: '¼',
0xbd: '½', 0xbe: '¾', 0xbf: '¿', 0xc0: 'À', 0xc1: 'Á',
0xc2: 'Â', 0xc3: 'Ã', 0xc4: 'Ä', 0xc5: 'Å', 0xc6: 'Æ',
0xc7: 'Ç', 0xc8: 'È', 0xc9: 'É', 0xca: 'Ê', 0xcb: 'Ë',
0xcc: 'Ì', 0xcd: 'Í', 0xce: 'Î', 0xcf: 'Ï', 0xd0: 'Ð',
0xd1: 'Ñ', 0xd2: 'Ò', 0xd3: 'Ó', 0xd4: 'Ô', 0xd5: 'Õ',
0xd6: 'Ö', 0xd7: '×', 0xd8: 'Ø', 0xd9: 'Ù', 0xda: 'Ú',
0xdb: 'Û', 0xdc: 'Ü', 0xdd: 'Ý', 0xde: 'Þ', 0xdf: 'ß',
0xe0: 'à', 0xe1: 'á', 0xe2: 'â', 0xe3: 'ã', 0xe4: 'ä',
0xe5: 'å', 0xe6: 'æ', 0xe7: 'ç', 0xe8: 'è', 0xe9: 'é',
0xea: 'ê', 0xeb: 'ë', 0xec: 'ì', 0xed: 'í', 0xee: 'î',
0xef: 'ï', 0xf0: 'ð', 0xf1: 'ñ', 0xf2: 'ò', 0xf3: 'ó',
0xf4: 'ô', 0xf5: 'õ', 0xf6: 'ö', 0xf7: '÷', 0xf8: 'ø',
0xf9: 'ù', 0xfa: 'ú', 0xfb: 'û', 0xfc: 'ü', 0xfd: 'ý',
0xfe: 'þ', 0xff: 'ÿ',
}
var standardCharToRune = map[byte]rune{ // 149 entries
0x20: ' ', 0x21: '!', 0x22: '"', 0x23: '#', 0x24: '$',
0x25: '%', 0x26: '&', 0x27: '', 0x28: '(', 0x29: ')',
0x2a: '*', 0x2b: '+', 0x2c: ',', 0x2d: '-', 0x2e: '.',
0x2f: '/', 0x30: '0', 0x31: '1', 0x32: '2', 0x33: '3',
0x34: '4', 0x35: '5', 0x36: '6', 0x37: '7', 0x38: '8',
0x39: '9', 0x3a: ':', 0x3b: ';', 0x3c: '<', 0x3d: '=',
0x3e: '>', 0x3f: '?', 0x40: '@', 0x41: 'A', 0x42: 'B',
0x43: 'C', 0x44: 'D', 0x45: 'E', 0x46: 'F', 0x47: 'G',
0x48: 'H', 0x49: 'I', 0x4a: 'J', 0x4b: 'K', 0x4c: 'L',
0x4d: 'M', 0x4e: 'N', 0x4f: 'O', 0x50: 'P', 0x51: 'Q',
0x52: 'R', 0x53: 'S', 0x54: 'T', 0x55: 'U', 0x56: 'V',
0x57: 'W', 0x58: 'X', 0x59: 'Y', 0x5a: 'Z', 0x5b: '[',
0x5c: '\\', 0x5d: ']', 0x5e: '^', 0x5f: '_', 0x60: '',
0x61: 'a', 0x62: 'b', 0x63: 'c', 0x64: 'd', 0x65: 'e',
0x66: 'f', 0x67: 'g', 0x68: 'h', 0x69: 'i', 0x6a: 'j',
0x6b: 'k', 0x6c: 'l', 0x6d: 'm', 0x6e: 'n', 0x6f: 'o',
0x70: 'p', 0x71: 'q', 0x72: 'r', 0x73: 's', 0x74: 't',
0x75: 'u', 0x76: 'v', 0x77: 'w', 0x78: 'x', 0x79: 'y',
0x7a: 'z', 0x7b: '{', 0x7c: '|', 0x7d: '}', 0x7e: '~',
0xa1: '¡', 0xa2: '¢', 0xa3: '£', 0xa4: '', 0xa5: '¥',
0xa6: 'ƒ', 0xa7: '§', 0xa8: '¤', 0xa9: '\'', 0xaa: '“',
0xab: '«', 0xac: '', 0xad: '', 0xae: 'fi', 0xaf: 'fl',
0xb1: '', 0xb2: '†', 0xb3: '‡', 0xb4: '·', 0xb6: '¶',
0xb7: '•', 0xb8: '', 0xb9: '„', 0xba: '”', 0xbb: '»',
0xbc: '…', 0xbd: '‰', 0xbf: '¿', 0xc1: '`', 0xc2: '´',
0xc3: 'ˆ', 0xc4: '˜', 0xc5: '¯', 0xc6: '˘', 0xc7: '˙',
0xc8: '¨', 0xca: '˚', 0xcb: '¸', 0xcc: '˝', 0xcd: '˛',
0xce: 'ˇ', 0xcf: '—', 0xe1: 'Æ', 0xe3: 'ª', 0xe8: 'Ł',
0xe9: 'Ø', 0xea: 'Œ', 0xeb: 'º', 0xf1: 'æ', 0xf5: 'ı',
0xf8: 'ł', 0xf9: 'ø', 0xfa: 'œ', 0xfb: 'ß',
}