repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
buger/jsonparser
escape.go
decodeSingleUnicodeEscape
func decodeSingleUnicodeEscape(in []byte) (rune, bool) { // We need at least 6 characters total if len(in) < 6 { return utf8.RuneError, false } // Convert hex to decimal h1, h2, h3, h4 := h2I(in[2]), h2I(in[3]), h2I(in[4]), h2I(in[5]) if h1 == badHex || h2 == badHex || h3 == badHex || h4 == badHex { return utf8.RuneError, false } // Compose the hex digits return rune(h1<<12 + h2<<8 + h3<<4 + h4), true }
go
func decodeSingleUnicodeEscape(in []byte) (rune, bool) { // We need at least 6 characters total if len(in) < 6 { return utf8.RuneError, false } // Convert hex to decimal h1, h2, h3, h4 := h2I(in[2]), h2I(in[3]), h2I(in[4]), h2I(in[5]) if h1 == badHex || h2 == badHex || h3 == badHex || h4 == badHex { return utf8.RuneError, false } // Compose the hex digits return rune(h1<<12 + h2<<8 + h3<<4 + h4), true }
[ "func", "decodeSingleUnicodeEscape", "(", "in", "[", "]", "byte", ")", "(", "rune", ",", "bool", ")", "{", "// We need at least 6 characters total", "if", "len", "(", "in", ")", "<", "6", "{", "return", "utf8", ".", "RuneError", ",", "false", "\n", "}", "\n\n", "// Convert hex to decimal", "h1", ",", "h2", ",", "h3", ",", "h4", ":=", "h2I", "(", "in", "[", "2", "]", ")", ",", "h2I", "(", "in", "[", "3", "]", ")", ",", "h2I", "(", "in", "[", "4", "]", ")", ",", "h2I", "(", "in", "[", "5", "]", ")", "\n", "if", "h1", "==", "badHex", "||", "h2", "==", "badHex", "||", "h3", "==", "badHex", "||", "h4", "==", "badHex", "{", "return", "utf8", ".", "RuneError", ",", "false", "\n", "}", "\n\n", "// Compose the hex digits", "return", "rune", "(", "h1", "<<", "12", "+", "h2", "<<", "8", "+", "h3", "<<", "4", "+", "h4", ")", ",", "true", "\n", "}" ]
// decodeSingleUnicodeEscape decodes a single \uXXXX escape sequence. The prefix \u is assumed to be present and // is not checked. // In JSON, these escapes can either come alone or as part of "UTF16 surrogate pairs" that must be handled together. // This function only handles one; decodeUnicodeEscape handles this more complex case.
[ "decodeSingleUnicodeEscape", "decodes", "a", "single", "\\", "uXXXX", "escape", "sequence", ".", "The", "prefix", "\\", "u", "is", "assumed", "to", "be", "present", "and", "is", "not", "checked", ".", "In", "JSON", "these", "escapes", "can", "either", "come", "alone", "or", "as", "part", "of", "UTF16", "surrogate", "pairs", "that", "must", "be", "handled", "together", ".", "This", "function", "only", "handles", "one", ";", "decodeUnicodeEscape", "handles", "this", "more", "complex", "case", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/escape.go#L39-L53
train
buger/jsonparser
bytes.go
parseInt
func parseInt(bytes []byte) (v int64, ok bool, overflow bool) { if len(bytes) == 0 { return 0, false, false } var neg bool = false if bytes[0] == '-' { neg = true bytes = bytes[1:] } var b int64 = 0 for _, c := range bytes { if c >= '0' && c <= '9' { b = (10 * v) + int64(c-'0') } else { return 0, false, false } if overflow = (b < v); overflow { break } v = b } if overflow { if neg && bio.Equal(bytes, []byte(minInt64)) { return b, true, false } return 0, false, true } if neg { return -v, true, false } else { return v, true, false } }
go
func parseInt(bytes []byte) (v int64, ok bool, overflow bool) { if len(bytes) == 0 { return 0, false, false } var neg bool = false if bytes[0] == '-' { neg = true bytes = bytes[1:] } var b int64 = 0 for _, c := range bytes { if c >= '0' && c <= '9' { b = (10 * v) + int64(c-'0') } else { return 0, false, false } if overflow = (b < v); overflow { break } v = b } if overflow { if neg && bio.Equal(bytes, []byte(minInt64)) { return b, true, false } return 0, false, true } if neg { return -v, true, false } else { return v, true, false } }
[ "func", "parseInt", "(", "bytes", "[", "]", "byte", ")", "(", "v", "int64", ",", "ok", "bool", ",", "overflow", "bool", ")", "{", "if", "len", "(", "bytes", ")", "==", "0", "{", "return", "0", ",", "false", ",", "false", "\n", "}", "\n\n", "var", "neg", "bool", "=", "false", "\n", "if", "bytes", "[", "0", "]", "==", "'-'", "{", "neg", "=", "true", "\n", "bytes", "=", "bytes", "[", "1", ":", "]", "\n", "}", "\n\n", "var", "b", "int64", "=", "0", "\n", "for", "_", ",", "c", ":=", "range", "bytes", "{", "if", "c", ">=", "'0'", "&&", "c", "<=", "'9'", "{", "b", "=", "(", "10", "*", "v", ")", "+", "int64", "(", "c", "-", "'0'", ")", "\n", "}", "else", "{", "return", "0", ",", "false", ",", "false", "\n", "}", "\n", "if", "overflow", "=", "(", "b", "<", "v", ")", ";", "overflow", "{", "break", "\n", "}", "\n", "v", "=", "b", "\n", "}", "\n\n", "if", "overflow", "{", "if", "neg", "&&", "bio", ".", "Equal", "(", "bytes", ",", "[", "]", "byte", "(", "minInt64", ")", ")", "{", "return", "b", ",", "true", ",", "false", "\n", "}", "\n", "return", "0", ",", "false", ",", "true", "\n", "}", "\n\n", "if", "neg", "{", "return", "-", "v", ",", "true", ",", "false", "\n", "}", "else", "{", "return", "v", ",", "true", ",", "false", "\n", "}", "\n", "}" ]
// About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON
[ "About", "2x", "faster", "then", "strconv", ".", "ParseInt", "because", "it", "only", "supports", "base", "10", "which", "is", "enough", "for", "JSON" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/bytes.go#L11-L47
train
buger/jsonparser
parser.go
lastToken
func lastToken(data []byte) int { for i := len(data) - 1; i >= 0; i-- { switch data[i] { case ' ', '\n', '\r', '\t': continue default: return i } } return -1 }
go
func lastToken(data []byte) int { for i := len(data) - 1; i >= 0; i-- { switch data[i] { case ' ', '\n', '\r', '\t': continue default: return i } } return -1 }
[ "func", "lastToken", "(", "data", "[", "]", "byte", ")", "int", "{", "for", "i", ":=", "len", "(", "data", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "switch", "data", "[", "i", "]", "{", "case", "' '", ",", "'\\n'", ",", "'\\r'", ",", "'\\t'", ":", "continue", "\n", "default", ":", "return", "i", "\n", "}", "\n", "}", "\n\n", "return", "-", "1", "\n", "}" ]
// Find position of last character which is not whitespace
[ "Find", "position", "of", "last", "character", "which", "is", "not", "whitespace" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L137-L148
train
buger/jsonparser
parser.go
stringEnd
func stringEnd(data []byte) (int, bool) { escaped := false for i, c := range data { if c == '"' { if !escaped { return i + 1, false } else { j := i - 1 for { if j < 0 || data[j] != '\\' { return i + 1, true // even number of backslashes } j-- if j < 0 || data[j] != '\\' { break // odd number of backslashes } j-- } } } else if c == '\\' { escaped = true } } return -1, escaped }
go
func stringEnd(data []byte) (int, bool) { escaped := false for i, c := range data { if c == '"' { if !escaped { return i + 1, false } else { j := i - 1 for { if j < 0 || data[j] != '\\' { return i + 1, true // even number of backslashes } j-- if j < 0 || data[j] != '\\' { break // odd number of backslashes } j-- } } } else if c == '\\' { escaped = true } } return -1, escaped }
[ "func", "stringEnd", "(", "data", "[", "]", "byte", ")", "(", "int", ",", "bool", ")", "{", "escaped", ":=", "false", "\n", "for", "i", ",", "c", ":=", "range", "data", "{", "if", "c", "==", "'\"'", "{", "if", "!", "escaped", "{", "return", "i", "+", "1", ",", "false", "\n", "}", "else", "{", "j", ":=", "i", "-", "1", "\n", "for", "{", "if", "j", "<", "0", "||", "data", "[", "j", "]", "!=", "'\\\\'", "{", "return", "i", "+", "1", ",", "true", "// even number of backslashes", "\n", "}", "\n", "j", "--", "\n", "if", "j", "<", "0", "||", "data", "[", "j", "]", "!=", "'\\\\'", "{", "break", "// odd number of backslashes", "\n", "}", "\n", "j", "--", "\n\n", "}", "\n", "}", "\n", "}", "else", "if", "c", "==", "'\\\\'", "{", "escaped", "=", "true", "\n", "}", "\n", "}", "\n\n", "return", "-", "1", ",", "escaped", "\n", "}" ]
// Tries to find the end of string // Support if string contains escaped quote symbols.
[ "Tries", "to", "find", "the", "end", "of", "string", "Support", "if", "string", "contains", "escaped", "quote", "symbols", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L152-L178
train
buger/jsonparser
parser.go
ArrayEach
func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int, err error), keys ...string) (offset int, err error) { if len(data) == 0 { return -1, MalformedObjectError } offset = 1 if len(keys) > 0 { if offset = searchKeys(data, keys...); offset == -1 { return offset, KeyPathNotFoundError } // Go to closest value nO := nextToken(data[offset:]) if nO == -1 { return offset, MalformedJsonError } offset += nO if data[offset] != '[' { return offset, MalformedArrayError } offset++ } nO := nextToken(data[offset:]) if nO == -1 { return offset, MalformedJsonError } offset += nO if data[offset] == ']' { return offset, nil } for true { v, t, o, e := Get(data[offset:]) if e != nil { return offset, e } if o == 0 { break } if t != NotExist { cb(v, t, offset+o-len(v), e) } if e != nil { break } offset += o skipToToken := nextToken(data[offset:]) if skipToToken == -1 { return offset, MalformedArrayError } offset += skipToToken if data[offset] == ']' { break } if data[offset] != ',' { return offset, MalformedArrayError } offset++ } return offset, nil }
go
func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int, err error), keys ...string) (offset int, err error) { if len(data) == 0 { return -1, MalformedObjectError } offset = 1 if len(keys) > 0 { if offset = searchKeys(data, keys...); offset == -1 { return offset, KeyPathNotFoundError } // Go to closest value nO := nextToken(data[offset:]) if nO == -1 { return offset, MalformedJsonError } offset += nO if data[offset] != '[' { return offset, MalformedArrayError } offset++ } nO := nextToken(data[offset:]) if nO == -1 { return offset, MalformedJsonError } offset += nO if data[offset] == ']' { return offset, nil } for true { v, t, o, e := Get(data[offset:]) if e != nil { return offset, e } if o == 0 { break } if t != NotExist { cb(v, t, offset+o-len(v), e) } if e != nil { break } offset += o skipToToken := nextToken(data[offset:]) if skipToToken == -1 { return offset, MalformedArrayError } offset += skipToToken if data[offset] == ']' { break } if data[offset] != ',' { return offset, MalformedArrayError } offset++ } return offset, nil }
[ "func", "ArrayEach", "(", "data", "[", "]", "byte", ",", "cb", "func", "(", "value", "[", "]", "byte", ",", "dataType", "ValueType", ",", "offset", "int", ",", "err", "error", ")", ",", "keys", "...", "string", ")", "(", "offset", "int", ",", "err", "error", ")", "{", "if", "len", "(", "data", ")", "==", "0", "{", "return", "-", "1", ",", "MalformedObjectError", "\n", "}", "\n\n", "offset", "=", "1", "\n\n", "if", "len", "(", "keys", ")", ">", "0", "{", "if", "offset", "=", "searchKeys", "(", "data", ",", "keys", "...", ")", ";", "offset", "==", "-", "1", "{", "return", "offset", ",", "KeyPathNotFoundError", "\n", "}", "\n\n", "// Go to closest value", "nO", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", "\n", "if", "nO", "==", "-", "1", "{", "return", "offset", ",", "MalformedJsonError", "\n", "}", "\n\n", "offset", "+=", "nO", "\n\n", "if", "data", "[", "offset", "]", "!=", "'['", "{", "return", "offset", ",", "MalformedArrayError", "\n", "}", "\n\n", "offset", "++", "\n", "}", "\n\n", "nO", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", "\n", "if", "nO", "==", "-", "1", "{", "return", "offset", ",", "MalformedJsonError", "\n", "}", "\n\n", "offset", "+=", "nO", "\n\n", "if", "data", "[", "offset", "]", "==", "']'", "{", "return", "offset", ",", "nil", "\n", "}", "\n\n", "for", "true", "{", "v", ",", "t", ",", "o", ",", "e", ":=", "Get", "(", "data", "[", "offset", ":", "]", ")", "\n\n", "if", "e", "!=", "nil", "{", "return", "offset", ",", "e", "\n", "}", "\n\n", "if", "o", "==", "0", "{", "break", "\n", "}", "\n\n", "if", "t", "!=", "NotExist", "{", "cb", "(", "v", ",", "t", ",", "offset", "+", "o", "-", "len", "(", "v", ")", ",", "e", ")", "\n", "}", "\n\n", "if", "e", "!=", "nil", "{", "break", "\n", "}", "\n\n", "offset", "+=", "o", "\n\n", "skipToToken", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", "\n", "if", "skipToToken", "==", "-", "1", "{", "return", "offset", ",", "MalformedArrayError", "\n", "}", "\n", "offset", "+=", "skipToToken", "\n\n", "if", "data", "[", "offset", "]", "==", "']'", "{", "break", "\n", "}", "\n\n", "if", "data", "[", "offset", "]", "!=", "','", "{", "return", "offset", ",", "MalformedArrayError", "\n", "}", "\n\n", "offset", "++", "\n", "}", "\n\n", "return", "offset", ",", "nil", "\n", "}" ]
// ArrayEach is used when iterating arrays, accepts a callback function with the same return arguments as `Get`.
[ "ArrayEach", "is", "used", "when", "iterating", "arrays", "accepts", "a", "callback", "function", "with", "the", "same", "return", "arguments", "as", "Get", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L902-L979
train
buger/jsonparser
parser.go
ObjectEach
func ObjectEach(data []byte, callback func(key []byte, value []byte, dataType ValueType, offset int) error, keys ...string) (err error) { var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings offset := 0 // Descend to the desired key, if requested if len(keys) > 0 { if off := searchKeys(data, keys...); off == -1 { return KeyPathNotFoundError } else { offset = off } } // Validate and skip past opening brace if off := nextToken(data[offset:]); off == -1 { return MalformedObjectError } else if offset += off; data[offset] != '{' { return MalformedObjectError } else { offset++ } // Skip to the first token inside the object, or stop if we find the ending brace if off := nextToken(data[offset:]); off == -1 { return MalformedJsonError } else if offset += off; data[offset] == '}' { return nil } // Loop pre-condition: data[offset] points to what should be either the next entry's key, or the closing brace (if it's anything else, the JSON is malformed) for offset < len(data) { // Step 1: find the next key var key []byte // Check what the the next token is: start of string, end of object, or something else (error) switch data[offset] { case '"': offset++ // accept as string and skip opening quote case '}': return nil // we found the end of the object; stop and return success default: return MalformedObjectError } // Find the end of the key string var keyEscaped bool if off, esc := stringEnd(data[offset:]); off == -1 { return MalformedJsonError } else { key, keyEscaped = data[offset:offset+off-1], esc offset += off } // Unescape the string if needed if keyEscaped { if keyUnescaped, err := Unescape(key, stackbuf[:]); err != nil { return MalformedStringEscapeError } else { key = keyUnescaped } } // Step 2: skip the colon if off := nextToken(data[offset:]); off == -1 { return MalformedJsonError } else if offset += off; data[offset] != ':' { return MalformedJsonError } else { offset++ } // Step 3: find the associated value, then invoke the callback if value, valueType, off, err := Get(data[offset:]); err != nil { return err } else if err := callback(key, value, valueType, offset+off); err != nil { // Invoke the callback here! return err } else { offset += off } // Step 4: skip over the next comma to the following token, or stop if we hit the ending brace if off := nextToken(data[offset:]); off == -1 { return MalformedArrayError } else { offset += off switch data[offset] { case '}': return nil // Stop if we hit the close brace case ',': offset++ // Ignore the comma default: return MalformedObjectError } } // Skip to the next token after the comma if off := nextToken(data[offset:]); off == -1 { return MalformedArrayError } else { offset += off } } return MalformedObjectError // we shouldn't get here; it's expected that we will return via finding the ending brace }
go
func ObjectEach(data []byte, callback func(key []byte, value []byte, dataType ValueType, offset int) error, keys ...string) (err error) { var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings offset := 0 // Descend to the desired key, if requested if len(keys) > 0 { if off := searchKeys(data, keys...); off == -1 { return KeyPathNotFoundError } else { offset = off } } // Validate and skip past opening brace if off := nextToken(data[offset:]); off == -1 { return MalformedObjectError } else if offset += off; data[offset] != '{' { return MalformedObjectError } else { offset++ } // Skip to the first token inside the object, or stop if we find the ending brace if off := nextToken(data[offset:]); off == -1 { return MalformedJsonError } else if offset += off; data[offset] == '}' { return nil } // Loop pre-condition: data[offset] points to what should be either the next entry's key, or the closing brace (if it's anything else, the JSON is malformed) for offset < len(data) { // Step 1: find the next key var key []byte // Check what the the next token is: start of string, end of object, or something else (error) switch data[offset] { case '"': offset++ // accept as string and skip opening quote case '}': return nil // we found the end of the object; stop and return success default: return MalformedObjectError } // Find the end of the key string var keyEscaped bool if off, esc := stringEnd(data[offset:]); off == -1 { return MalformedJsonError } else { key, keyEscaped = data[offset:offset+off-1], esc offset += off } // Unescape the string if needed if keyEscaped { if keyUnescaped, err := Unescape(key, stackbuf[:]); err != nil { return MalformedStringEscapeError } else { key = keyUnescaped } } // Step 2: skip the colon if off := nextToken(data[offset:]); off == -1 { return MalformedJsonError } else if offset += off; data[offset] != ':' { return MalformedJsonError } else { offset++ } // Step 3: find the associated value, then invoke the callback if value, valueType, off, err := Get(data[offset:]); err != nil { return err } else if err := callback(key, value, valueType, offset+off); err != nil { // Invoke the callback here! return err } else { offset += off } // Step 4: skip over the next comma to the following token, or stop if we hit the ending brace if off := nextToken(data[offset:]); off == -1 { return MalformedArrayError } else { offset += off switch data[offset] { case '}': return nil // Stop if we hit the close brace case ',': offset++ // Ignore the comma default: return MalformedObjectError } } // Skip to the next token after the comma if off := nextToken(data[offset:]); off == -1 { return MalformedArrayError } else { offset += off } } return MalformedObjectError // we shouldn't get here; it's expected that we will return via finding the ending brace }
[ "func", "ObjectEach", "(", "data", "[", "]", "byte", ",", "callback", "func", "(", "key", "[", "]", "byte", ",", "value", "[", "]", "byte", ",", "dataType", "ValueType", ",", "offset", "int", ")", "error", ",", "keys", "...", "string", ")", "(", "err", "error", ")", "{", "var", "stackbuf", "[", "unescapeStackBufSize", "]", "byte", "// stack-allocated array for allocation-free unescaping of small strings", "\n", "offset", ":=", "0", "\n\n", "// Descend to the desired key, if requested", "if", "len", "(", "keys", ")", ">", "0", "{", "if", "off", ":=", "searchKeys", "(", "data", ",", "keys", "...", ")", ";", "off", "==", "-", "1", "{", "return", "KeyPathNotFoundError", "\n", "}", "else", "{", "offset", "=", "off", "\n", "}", "\n", "}", "\n\n", "// Validate and skip past opening brace", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedObjectError", "\n", "}", "else", "if", "offset", "+=", "off", ";", "data", "[", "offset", "]", "!=", "'{'", "{", "return", "MalformedObjectError", "\n", "}", "else", "{", "offset", "++", "\n", "}", "\n\n", "// Skip to the first token inside the object, or stop if we find the ending brace", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedJsonError", "\n", "}", "else", "if", "offset", "+=", "off", ";", "data", "[", "offset", "]", "==", "'}'", "{", "return", "nil", "\n", "}", "\n\n", "// Loop pre-condition: data[offset] points to what should be either the next entry's key, or the closing brace (if it's anything else, the JSON is malformed)", "for", "offset", "<", "len", "(", "data", ")", "{", "// Step 1: find the next key", "var", "key", "[", "]", "byte", "\n\n", "// Check what the the next token is: start of string, end of object, or something else (error)", "switch", "data", "[", "offset", "]", "{", "case", "'\"'", ":", "offset", "++", "// accept as string and skip opening quote", "\n", "case", "'}'", ":", "return", "nil", "// we found the end of the object; stop and return success", "\n", "default", ":", "return", "MalformedObjectError", "\n", "}", "\n\n", "// Find the end of the key string", "var", "keyEscaped", "bool", "\n", "if", "off", ",", "esc", ":=", "stringEnd", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedJsonError", "\n", "}", "else", "{", "key", ",", "keyEscaped", "=", "data", "[", "offset", ":", "offset", "+", "off", "-", "1", "]", ",", "esc", "\n", "offset", "+=", "off", "\n", "}", "\n\n", "// Unescape the string if needed", "if", "keyEscaped", "{", "if", "keyUnescaped", ",", "err", ":=", "Unescape", "(", "key", ",", "stackbuf", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "MalformedStringEscapeError", "\n", "}", "else", "{", "key", "=", "keyUnescaped", "\n", "}", "\n", "}", "\n\n", "// Step 2: skip the colon", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedJsonError", "\n", "}", "else", "if", "offset", "+=", "off", ";", "data", "[", "offset", "]", "!=", "':'", "{", "return", "MalformedJsonError", "\n", "}", "else", "{", "offset", "++", "\n", "}", "\n\n", "// Step 3: find the associated value, then invoke the callback", "if", "value", ",", "valueType", ",", "off", ",", "err", ":=", "Get", "(", "data", "[", "offset", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "else", "if", "err", ":=", "callback", "(", "key", ",", "value", ",", "valueType", ",", "offset", "+", "off", ")", ";", "err", "!=", "nil", "{", "// Invoke the callback here!", "return", "err", "\n", "}", "else", "{", "offset", "+=", "off", "\n", "}", "\n\n", "// Step 4: skip over the next comma to the following token, or stop if we hit the ending brace", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedArrayError", "\n", "}", "else", "{", "offset", "+=", "off", "\n", "switch", "data", "[", "offset", "]", "{", "case", "'}'", ":", "return", "nil", "// Stop if we hit the close brace", "\n", "case", "','", ":", "offset", "++", "// Ignore the comma", "\n", "default", ":", "return", "MalformedObjectError", "\n", "}", "\n", "}", "\n\n", "// Skip to the next token after the comma", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedArrayError", "\n", "}", "else", "{", "offset", "+=", "off", "\n", "}", "\n", "}", "\n\n", "return", "MalformedObjectError", "// we shouldn't get here; it's expected that we will return via finding the ending brace", "\n", "}" ]
// ObjectEach iterates over the key-value pairs of a JSON object, invoking a given callback for each such entry
[ "ObjectEach", "iterates", "over", "the", "key", "-", "value", "pairs", "of", "a", "JSON", "object", "invoking", "a", "given", "callback", "for", "each", "such", "entry" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L982-L1086
train
buger/jsonparser
parser.go
GetUnsafeString
func GetUnsafeString(data []byte, keys ...string) (val string, err error) { v, _, _, e := Get(data, keys...) if e != nil { return "", e } return bytesToString(&v), nil }
go
func GetUnsafeString(data []byte, keys ...string) (val string, err error) { v, _, _, e := Get(data, keys...) if e != nil { return "", e } return bytesToString(&v), nil }
[ "func", "GetUnsafeString", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "string", ",", "err", "error", ")", "{", "v", ",", "_", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if", "e", "!=", "nil", "{", "return", "\"", "\"", ",", "e", "\n", "}", "\n\n", "return", "bytesToString", "(", "&", "v", ")", ",", "nil", "\n", "}" ]
// GetUnsafeString returns the value retrieved by `Get`, use creates string without memory allocation by mapping string to slice memory. It does not handle escape symbols.
[ "GetUnsafeString", "returns", "the", "value", "retrieved", "by", "Get", "use", "creates", "string", "without", "memory", "allocation", "by", "mapping", "string", "to", "slice", "memory", ".", "It", "does", "not", "handle", "escape", "symbols", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1089-L1097
train
buger/jsonparser
parser.go
GetString
func GetString(data []byte, keys ...string) (val string, err error) { v, t, _, e := Get(data, keys...) if e != nil { return "", e } if t != String { return "", fmt.Errorf("Value is not a string: %s", string(v)) } // If no escapes return raw conten if bytes.IndexByte(v, '\\') == -1 { return string(v), nil } return ParseString(v) }
go
func GetString(data []byte, keys ...string) (val string, err error) { v, t, _, e := Get(data, keys...) if e != nil { return "", e } if t != String { return "", fmt.Errorf("Value is not a string: %s", string(v)) } // If no escapes return raw conten if bytes.IndexByte(v, '\\') == -1 { return string(v), nil } return ParseString(v) }
[ "func", "GetString", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "string", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if", "e", "!=", "nil", "{", "return", "\"", "\"", ",", "e", "\n", "}", "\n\n", "if", "t", "!=", "String", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "string", "(", "v", ")", ")", "\n", "}", "\n\n", "// If no escapes return raw conten", "if", "bytes", ".", "IndexByte", "(", "v", ",", "'\\\\'", ")", "==", "-", "1", "{", "return", "string", "(", "v", ")", ",", "nil", "\n", "}", "\n\n", "return", "ParseString", "(", "v", ")", "\n", "}" ]
// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols // If key data type do not match, it will return an error.
[ "GetString", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "string", "if", "possible", "trying", "to", "properly", "handle", "escape", "and", "utf8", "symbols", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return", "an", "error", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1101-L1118
train
buger/jsonparser
parser.go
GetFloat
func GetFloat(data []byte, keys ...string) (val float64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseFloat(v) }
go
func GetFloat(data []byte, keys ...string) (val float64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseFloat(v) }
[ "func", "GetFloat", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "float64", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if", "e", "!=", "nil", "{", "return", "0", ",", "e", "\n", "}", "\n\n", "if", "t", "!=", "Number", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "string", "(", "v", ")", ")", "\n", "}", "\n\n", "return", "ParseFloat", "(", "v", ")", "\n", "}" ]
// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible. // The offset is the same as in `Get`. // If key data type do not match, it will return an error.
[ "GetFloat", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "float64", "if", "possible", ".", "The", "offset", "is", "the", "same", "as", "in", "Get", ".", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return", "an", "error", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1123-L1135
train
buger/jsonparser
parser.go
GetInt
func GetInt(data []byte, keys ...string) (val int64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseInt(v) }
go
func GetInt(data []byte, keys ...string) (val int64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseInt(v) }
[ "func", "GetInt", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "int64", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if", "e", "!=", "nil", "{", "return", "0", ",", "e", "\n", "}", "\n\n", "if", "t", "!=", "Number", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "string", "(", "v", ")", ")", "\n", "}", "\n\n", "return", "ParseInt", "(", "v", ")", "\n", "}" ]
// GetInt returns the value retrieved by `Get`, cast to a int64 if possible. // If key data type do not match, it will return an error.
[ "GetInt", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "int64", "if", "possible", ".", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return", "an", "error", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1139-L1151
train
buger/jsonparser
parser.go
GetBoolean
func GetBoolean(data []byte, keys ...string) (val bool, err error) { v, t, _, e := Get(data, keys...) if e != nil { return false, e } if t != Boolean { return false, fmt.Errorf("Value is not a boolean: %s", string(v)) } return ParseBoolean(v) }
go
func GetBoolean(data []byte, keys ...string) (val bool, err error) { v, t, _, e := Get(data, keys...) if e != nil { return false, e } if t != Boolean { return false, fmt.Errorf("Value is not a boolean: %s", string(v)) } return ParseBoolean(v) }
[ "func", "GetBoolean", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "bool", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if", "e", "!=", "nil", "{", "return", "false", ",", "e", "\n", "}", "\n\n", "if", "t", "!=", "Boolean", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "string", "(", "v", ")", ")", "\n", "}", "\n\n", "return", "ParseBoolean", "(", "v", ")", "\n", "}" ]
// GetBoolean returns the value retrieved by `Get`, cast to a bool if possible. // The offset is the same as in `Get`. // If key data type do not match, it will return error.
[ "GetBoolean", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "bool", "if", "possible", ".", "The", "offset", "is", "the", "same", "as", "in", "Get", ".", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return", "error", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1156-L1168
train
buger/jsonparser
parser.go
ParseFloat
func ParseFloat(b []byte) (float64, error) { if v, err := parseFloat(&b); err != nil { return 0, MalformedValueError } else { return v, nil } }
go
func ParseFloat(b []byte) (float64, error) { if v, err := parseFloat(&b); err != nil { return 0, MalformedValueError } else { return v, nil } }
[ "func", "ParseFloat", "(", "b", "[", "]", "byte", ")", "(", "float64", ",", "error", ")", "{", "if", "v", ",", "err", ":=", "parseFloat", "(", "&", "b", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "MalformedValueError", "\n", "}", "else", "{", "return", "v", ",", "nil", "\n", "}", "\n", "}" ]
// ParseNumber parses a Number ValueType into a Go float64
[ "ParseNumber", "parses", "a", "Number", "ValueType", "into", "a", "Go", "float64" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1193-L1199
train
buger/jsonparser
parser.go
ParseInt
func ParseInt(b []byte) (int64, error) { if v, ok, overflow := parseInt(b); !ok { if overflow { return 0, OverflowIntegerError } return 0, MalformedValueError } else { return v, nil } }
go
func ParseInt(b []byte) (int64, error) { if v, ok, overflow := parseInt(b); !ok { if overflow { return 0, OverflowIntegerError } return 0, MalformedValueError } else { return v, nil } }
[ "func", "ParseInt", "(", "b", "[", "]", "byte", ")", "(", "int64", ",", "error", ")", "{", "if", "v", ",", "ok", ",", "overflow", ":=", "parseInt", "(", "b", ")", ";", "!", "ok", "{", "if", "overflow", "{", "return", "0", ",", "OverflowIntegerError", "\n", "}", "\n", "return", "0", ",", "MalformedValueError", "\n", "}", "else", "{", "return", "v", ",", "nil", "\n", "}", "\n", "}" ]
// ParseInt parses a Number ValueType into a Go int64
[ "ParseInt", "parses", "a", "Number", "ValueType", "into", "a", "Go", "int64" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1202-L1211
train
jung-kurt/gofpdf
fpdf.go
SetErrorf
func (f *Fpdf) SetErrorf(fmtStr string, args ...interface{}) { if f.err == nil { f.err = fmt.Errorf(fmtStr, args...) } }
go
func (f *Fpdf) SetErrorf(fmtStr string, args ...interface{}) { if f.err == nil { f.err = fmt.Errorf(fmtStr, args...) } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetErrorf", "(", "fmtStr", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "f", ".", "err", "==", "nil", "{", "f", ".", "err", "=", "fmt", ".", "Errorf", "(", "fmtStr", ",", "args", "...", ")", "\n", "}", "\n", "}" ]
// SetErrorf sets the internal Fpdf error with formatted text to halt PDF // generation; this may facilitate error handling by application. If an error // condition is already set, this call is ignored. // // See the documentation for printing in the standard fmt package for details // about fmtStr and args.
[ "SetErrorf", "sets", "the", "internal", "Fpdf", "error", "with", "formatted", "text", "to", "halt", "PDF", "generation", ";", "this", "may", "facilitate", "error", "handling", "by", "application", ".", "If", "an", "error", "condition", "is", "already", "set", "this", "call", "is", "ignored", ".", "See", "the", "documentation", "for", "printing", "in", "the", "standard", "fmt", "package", "for", "details", "about", "fmtStr", "and", "args", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L259-L263
train
jung-kurt/gofpdf
fpdf.go
SetMargins
func (f *Fpdf) SetMargins(left, top, right float64) { f.lMargin = left f.tMargin = top if right < 0 { right = left } f.rMargin = right }
go
func (f *Fpdf) SetMargins(left, top, right float64) { f.lMargin = left f.tMargin = top if right < 0 { right = left } f.rMargin = right }
[ "func", "(", "f", "*", "Fpdf", ")", "SetMargins", "(", "left", ",", "top", ",", "right", "float64", ")", "{", "f", ".", "lMargin", "=", "left", "\n", "f", ".", "tMargin", "=", "top", "\n", "if", "right", "<", "0", "{", "right", "=", "left", "\n", "}", "\n", "f", ".", "rMargin", "=", "right", "\n", "}" ]
// SetMargins defines the left, top and right margins. By default, they equal 1 // cm. Call this method to change them. If the value of the right margin is // less than zero, it is set to the same as the left margin.
[ "SetMargins", "defines", "the", "left", "top", "and", "right", "margins", ".", "By", "default", "they", "equal", "1", "cm", ".", "Call", "this", "method", "to", "change", "them", ".", "If", "the", "value", "of", "the", "right", "margin", "is", "less", "than", "zero", "it", "is", "set", "to", "the", "same", "as", "the", "left", "margin", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L307-L314
train
jung-kurt/gofpdf
fpdf.go
SetLeftMargin
func (f *Fpdf) SetLeftMargin(margin float64) { f.lMargin = margin if f.page > 0 && f.x < margin { f.x = margin } }
go
func (f *Fpdf) SetLeftMargin(margin float64) { f.lMargin = margin if f.page > 0 && f.x < margin { f.x = margin } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetLeftMargin", "(", "margin", "float64", ")", "{", "f", ".", "lMargin", "=", "margin", "\n", "if", "f", ".", "page", ">", "0", "&&", "f", ".", "x", "<", "margin", "{", "f", ".", "x", "=", "margin", "\n", "}", "\n", "}" ]
// SetLeftMargin defines the left margin. The method can be called before // creating the first page. If the current abscissa gets out of page, it is // brought back to the margin.
[ "SetLeftMargin", "defines", "the", "left", "margin", ".", "The", "method", "can", "be", "called", "before", "creating", "the", "first", "page", ".", "If", "the", "current", "abscissa", "gets", "out", "of", "page", "it", "is", "brought", "back", "to", "the", "margin", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L319-L324
train
jung-kurt/gofpdf
fpdf.go
SetPageBox
func (f *Fpdf) SetPageBox(t string, x, y, wd, ht float64) { f.SetPageBoxRec(t, PageBox{SizeType{Wd: wd, Ht: ht}, PointType{X: x, Y: y}}) }
go
func (f *Fpdf) SetPageBox(t string, x, y, wd, ht float64) { f.SetPageBoxRec(t, PageBox{SizeType{Wd: wd, Ht: ht}, PointType{X: x, Y: y}}) }
[ "func", "(", "f", "*", "Fpdf", ")", "SetPageBox", "(", "t", "string", ",", "x", ",", "y", ",", "wd", ",", "ht", "float64", ")", "{", "f", ".", "SetPageBoxRec", "(", "t", ",", "PageBox", "{", "SizeType", "{", "Wd", ":", "wd", ",", "Ht", ":", "ht", "}", ",", "PointType", "{", "X", ":", "x", ",", "Y", ":", "y", "}", "}", ")", "\n", "}" ]
// SetPageBox sets the page box for the current page, and any following pages. // Allowable types are trim, trimbox, crop, cropbox, bleed, bleedbox, art and // artbox box types are case insensitive.
[ "SetPageBox", "sets", "the", "page", "box", "for", "the", "current", "page", "and", "any", "following", "pages", ".", "Allowable", "types", "are", "trim", "trimbox", "crop", "cropbox", "bleed", "bleedbox", "art", "and", "artbox", "box", "types", "are", "case", "insensitive", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L383-L385
train
jung-kurt/gofpdf
fpdf.go
GetAutoPageBreak
func (f *Fpdf) GetAutoPageBreak() (auto bool, margin float64) { auto = f.autoPageBreak margin = f.bMargin return }
go
func (f *Fpdf) GetAutoPageBreak() (auto bool, margin float64) { auto = f.autoPageBreak margin = f.bMargin return }
[ "func", "(", "f", "*", "Fpdf", ")", "GetAutoPageBreak", "(", ")", "(", "auto", "bool", ",", "margin", "float64", ")", "{", "auto", "=", "f", ".", "autoPageBreak", "\n", "margin", "=", "f", ".", "bMargin", "\n", "return", "\n", "}" ]
// GetAutoPageBreak returns true if automatic pages breaks are enabled, false // otherwise. This is followed by the triggering limit from the bottom of the // page. This value applies only if automatic page breaks are enabled.
[ "GetAutoPageBreak", "returns", "true", "if", "automatic", "pages", "breaks", "are", "enabled", "false", "otherwise", ".", "This", "is", "followed", "by", "the", "triggering", "limit", "from", "the", "bottom", "of", "the", "page", ".", "This", "value", "applies", "only", "if", "automatic", "page", "breaks", "are", "enabled", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L484-L488
train
jung-kurt/gofpdf
fpdf.go
SetAutoPageBreak
func (f *Fpdf) SetAutoPageBreak(auto bool, margin float64) { f.autoPageBreak = auto f.bMargin = margin f.pageBreakTrigger = f.h - margin }
go
func (f *Fpdf) SetAutoPageBreak(auto bool, margin float64) { f.autoPageBreak = auto f.bMargin = margin f.pageBreakTrigger = f.h - margin }
[ "func", "(", "f", "*", "Fpdf", ")", "SetAutoPageBreak", "(", "auto", "bool", ",", "margin", "float64", ")", "{", "f", ".", "autoPageBreak", "=", "auto", "\n", "f", ".", "bMargin", "=", "margin", "\n", "f", ".", "pageBreakTrigger", "=", "f", ".", "h", "-", "margin", "\n", "}" ]
// SetAutoPageBreak enables or disables the automatic page breaking mode. When // enabling, the second parameter is the distance from the bottom of the page // that defines the triggering limit. By default, the mode is on and the margin // is 2 cm.
[ "SetAutoPageBreak", "enables", "or", "disables", "the", "automatic", "page", "breaking", "mode", ".", "When", "enabling", "the", "second", "parameter", "is", "the", "distance", "from", "the", "bottom", "of", "the", "page", "that", "defines", "the", "triggering", "limit", ".", "By", "default", "the", "mode", "is", "on", "and", "the", "margin", "is", "2", "cm", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L494-L498
train
jung-kurt/gofpdf
fpdf.go
SetKeywords
func (f *Fpdf) SetKeywords(keywordsStr string, isUTF8 bool) { if isUTF8 { keywordsStr = utf8toutf16(keywordsStr) } f.keywords = keywordsStr }
go
func (f *Fpdf) SetKeywords(keywordsStr string, isUTF8 bool) { if isUTF8 { keywordsStr = utf8toutf16(keywordsStr) } f.keywords = keywordsStr }
[ "func", "(", "f", "*", "Fpdf", ")", "SetKeywords", "(", "keywordsStr", "string", ",", "isUTF8", "bool", ")", "{", "if", "isUTF8", "{", "keywordsStr", "=", "utf8toutf16", "(", "keywordsStr", ")", "\n", "}", "\n", "f", ".", "keywords", "=", "keywordsStr", "\n", "}" ]
// SetKeywords defines the keywords of the document. keywordStr is a // space-delimited string, for example "invoice August". isUTF8 indicates if // the string is encoded
[ "SetKeywords", "defines", "the", "keywords", "of", "the", "document", ".", "keywordStr", "is", "a", "space", "-", "delimited", "string", "for", "example", "invoice", "August", ".", "isUTF8", "indicates", "if", "the", "string", "is", "encoded" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L588-L593
train
jung-kurt/gofpdf
fpdf.go
GetStringWidth
func (f *Fpdf) GetStringWidth(s string) float64 { if f.err != nil { return 0 } w := 0 for _, ch := range []byte(s) { if ch == 0 { break } w += f.currentFont.Cw[ch] } return float64(w) * f.fontSize / 1000 }
go
func (f *Fpdf) GetStringWidth(s string) float64 { if f.err != nil { return 0 } w := 0 for _, ch := range []byte(s) { if ch == 0 { break } w += f.currentFont.Cw[ch] } return float64(w) * f.fontSize / 1000 }
[ "func", "(", "f", "*", "Fpdf", ")", "GetStringWidth", "(", "s", "string", ")", "float64", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "w", ":=", "0", "\n", "for", "_", ",", "ch", ":=", "range", "[", "]", "byte", "(", "s", ")", "{", "if", "ch", "==", "0", "{", "break", "\n", "}", "\n", "w", "+=", "f", ".", "currentFont", ".", "Cw", "[", "ch", "]", "\n", "}", "\n", "return", "float64", "(", "w", ")", "*", "f", ".", "fontSize", "/", "1000", "\n", "}" ]
// GetStringWidth returns the length of a string in user units. A font must be // currently selected.
[ "GetStringWidth", "returns", "the", "length", "of", "a", "string", "in", "user", "units", ".", "A", "font", "must", "be", "currently", "selected", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L914-L926
train
jung-kurt/gofpdf
fpdf.go
SetLineCapStyle
func (f *Fpdf) SetLineCapStyle(styleStr string) { var capStyle int switch styleStr { case "round": capStyle = 1 case "square": capStyle = 2 default: capStyle = 0 } f.capStyle = capStyle if f.page > 0 { f.outf("%d J", f.capStyle) } }
go
func (f *Fpdf) SetLineCapStyle(styleStr string) { var capStyle int switch styleStr { case "round": capStyle = 1 case "square": capStyle = 2 default: capStyle = 0 } f.capStyle = capStyle if f.page > 0 { f.outf("%d J", f.capStyle) } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetLineCapStyle", "(", "styleStr", "string", ")", "{", "var", "capStyle", "int", "\n", "switch", "styleStr", "{", "case", "\"", "\"", ":", "capStyle", "=", "1", "\n", "case", "\"", "\"", ":", "capStyle", "=", "2", "\n", "default", ":", "capStyle", "=", "0", "\n", "}", "\n", "f", ".", "capStyle", "=", "capStyle", "\n", "if", "f", ".", "page", ">", "0", "{", "f", ".", "outf", "(", "\"", "\"", ",", "f", ".", "capStyle", ")", "\n", "}", "\n", "}" ]
// SetLineCapStyle defines the line cap style. styleStr should be "butt", // "round" or "square". A square style projects from the end of the line. The // method can be called before the first page is created. The value is // retained from page to page.
[ "SetLineCapStyle", "defines", "the", "line", "cap", "style", ".", "styleStr", "should", "be", "butt", "round", "or", "square", ".", "A", "square", "style", "projects", "from", "the", "end", "of", "the", "line", ".", "The", "method", "can", "be", "called", "before", "the", "first", "page", "is", "created", ".", "The", "value", "is", "retained", "from", "page", "to", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L951-L965
train
jung-kurt/gofpdf
fpdf.go
SetLineJoinStyle
func (f *Fpdf) SetLineJoinStyle(styleStr string) { var joinStyle int switch styleStr { case "round": joinStyle = 1 case "bevel": joinStyle = 2 default: joinStyle = 0 } f.joinStyle = joinStyle if f.page > 0 { f.outf("%d j", f.joinStyle) } }
go
func (f *Fpdf) SetLineJoinStyle(styleStr string) { var joinStyle int switch styleStr { case "round": joinStyle = 1 case "bevel": joinStyle = 2 default: joinStyle = 0 } f.joinStyle = joinStyle if f.page > 0 { f.outf("%d j", f.joinStyle) } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetLineJoinStyle", "(", "styleStr", "string", ")", "{", "var", "joinStyle", "int", "\n", "switch", "styleStr", "{", "case", "\"", "\"", ":", "joinStyle", "=", "1", "\n", "case", "\"", "\"", ":", "joinStyle", "=", "2", "\n", "default", ":", "joinStyle", "=", "0", "\n", "}", "\n", "f", ".", "joinStyle", "=", "joinStyle", "\n", "if", "f", ".", "page", ">", "0", "{", "f", ".", "outf", "(", "\"", "\"", ",", "f", ".", "joinStyle", ")", "\n", "}", "\n", "}" ]
// SetLineJoinStyle defines the line cap style. styleStr should be "miter", // "round" or "bevel". The method can be called before the first page // is created. The value is retained from page to page.
[ "SetLineJoinStyle", "defines", "the", "line", "cap", "style", ".", "styleStr", "should", "be", "miter", "round", "or", "bevel", ".", "The", "method", "can", "be", "called", "before", "the", "first", "page", "is", "created", ".", "The", "value", "is", "retained", "from", "page", "to", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L970-L984
train
jung-kurt/gofpdf
fpdf.go
fillDrawOp
func fillDrawOp(styleStr string) (opStr string) { switch strings.ToUpper(styleStr) { case "", "D": // Stroke the path. opStr = "S" case "F": // fill the path, using the nonzero winding number rule opStr = "f" case "F*": // fill the path, using the even-odd rule opStr = "f*" case "FD", "DF": // fill and then stroke the path, using the nonzero winding number rule opStr = "B" case "FD*", "DF*": // fill and then stroke the path, using the even-odd rule opStr = "B*" default: opStr = styleStr } return }
go
func fillDrawOp(styleStr string) (opStr string) { switch strings.ToUpper(styleStr) { case "", "D": // Stroke the path. opStr = "S" case "F": // fill the path, using the nonzero winding number rule opStr = "f" case "F*": // fill the path, using the even-odd rule opStr = "f*" case "FD", "DF": // fill and then stroke the path, using the nonzero winding number rule opStr = "B" case "FD*", "DF*": // fill and then stroke the path, using the even-odd rule opStr = "B*" default: opStr = styleStr } return }
[ "func", "fillDrawOp", "(", "styleStr", "string", ")", "(", "opStr", "string", ")", "{", "switch", "strings", ".", "ToUpper", "(", "styleStr", ")", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "// Stroke the path.", "opStr", "=", "\"", "\"", "\n", "case", "\"", "\"", ":", "// fill the path, using the nonzero winding number rule", "opStr", "=", "\"", "\"", "\n", "case", "\"", "\"", ":", "// fill the path, using the even-odd rule", "opStr", "=", "\"", "\"", "\n", "case", "\"", "\"", ",", "\"", "\"", ":", "// fill and then stroke the path, using the nonzero winding number rule", "opStr", "=", "\"", "\"", "\n", "case", "\"", "\"", ",", "\"", "\"", ":", "// fill and then stroke the path, using the even-odd rule", "opStr", "=", "\"", "\"", "\n", "default", ":", "opStr", "=", "styleStr", "\n", "}", "\n", "return", "\n", "}" ]
// fillDrawOp corrects path painting operators
[ "fillDrawOp", "corrects", "path", "painting", "operators" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1031-L1052
train
jung-kurt/gofpdf
fpdf.go
point
func (f *Fpdf) point(x, y float64) { f.outf("%.2f %.2f m", x*f.k, (f.h-y)*f.k) }
go
func (f *Fpdf) point(x, y float64) { f.outf("%.2f %.2f m", x*f.k, (f.h-y)*f.k) }
[ "func", "(", "f", "*", "Fpdf", ")", "point", "(", "x", ",", "y", "float64", ")", "{", "f", ".", "outf", "(", "\"", "\"", ",", "x", "*", "f", ".", "k", ",", "(", "f", ".", "h", "-", "y", ")", "*", "f", ".", "k", ")", "\n", "}" ]
// point outputs current point
[ "point", "outputs", "current", "point" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1148-L1150
train
jung-kurt/gofpdf
fpdf.go
GetAlpha
func (f *Fpdf) GetAlpha() (alpha float64, blendModeStr string) { return f.alpha, f.blendMode }
go
func (f *Fpdf) GetAlpha() (alpha float64, blendModeStr string) { return f.alpha, f.blendMode }
[ "func", "(", "f", "*", "Fpdf", ")", "GetAlpha", "(", ")", "(", "alpha", "float64", ",", "blendModeStr", "string", ")", "{", "return", "f", ".", "alpha", ",", "f", ".", "blendMode", "\n", "}" ]
// GetAlpha returns the alpha blending channel, which consists of the // alpha transparency value and the blend mode. See SetAlpha for more // details.
[ "GetAlpha", "returns", "the", "alpha", "blending", "channel", "which", "consists", "of", "the", "alpha", "transparency", "value", "and", "the", "blend", "mode", ".", "See", "SetAlpha", "for", "more", "details", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1231-L1233
train
jung-kurt/gofpdf
fpdf.go
getFontKey
func getFontKey(familyStr, styleStr string) string { familyStr = strings.ToLower(familyStr) styleStr = strings.ToUpper(styleStr) if styleStr == "IB" { styleStr = "BI" } return familyStr + styleStr }
go
func getFontKey(familyStr, styleStr string) string { familyStr = strings.ToLower(familyStr) styleStr = strings.ToUpper(styleStr) if styleStr == "IB" { styleStr = "BI" } return familyStr + styleStr }
[ "func", "getFontKey", "(", "familyStr", ",", "styleStr", "string", ")", "string", "{", "familyStr", "=", "strings", ".", "ToLower", "(", "familyStr", ")", "\n", "styleStr", "=", "strings", ".", "ToUpper", "(", "styleStr", ")", "\n", "if", "styleStr", "==", "\"", "\"", "{", "styleStr", "=", "\"", "\"", "\n", "}", "\n", "return", "familyStr", "+", "styleStr", "\n", "}" ]
// getFontKey is used by AddFontFromReader and GetFontDesc
[ "getFontKey", "is", "used", "by", "AddFontFromReader", "and", "GetFontDesc" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1638-L1645
train
jung-kurt/gofpdf
fpdf.go
AddFontFromReader
func (f *Fpdf) AddFontFromReader(familyStr, styleStr string, r io.Reader) { if f.err != nil { return } // dbg("Adding family [%s], style [%s]", familyStr, styleStr) var ok bool fontkey := getFontKey(familyStr, styleStr) _, ok = f.fonts[fontkey] if ok { return } var info fontDefType info = f.loadfont(r) if f.err != nil { return } if len(info.Diff) > 0 { // Search existing encodings n := -1 for j, str := range f.diffs { if str == info.Diff { n = j + 1 break } } if n < 0 { f.diffs = append(f.diffs, info.Diff) n = len(f.diffs) } info.DiffN = n } // dbg("font [%s], type [%s]", info.File, info.Tp) if len(info.File) > 0 { // Embedded font if info.Tp == "TrueType" { f.fontFiles[info.File] = fontFileType{length1: int64(info.OriginalSize)} } else { f.fontFiles[info.File] = fontFileType{length1: int64(info.Size1), length2: int64(info.Size2)} } } f.fonts[fontkey] = info return }
go
func (f *Fpdf) AddFontFromReader(familyStr, styleStr string, r io.Reader) { if f.err != nil { return } // dbg("Adding family [%s], style [%s]", familyStr, styleStr) var ok bool fontkey := getFontKey(familyStr, styleStr) _, ok = f.fonts[fontkey] if ok { return } var info fontDefType info = f.loadfont(r) if f.err != nil { return } if len(info.Diff) > 0 { // Search existing encodings n := -1 for j, str := range f.diffs { if str == info.Diff { n = j + 1 break } } if n < 0 { f.diffs = append(f.diffs, info.Diff) n = len(f.diffs) } info.DiffN = n } // dbg("font [%s], type [%s]", info.File, info.Tp) if len(info.File) > 0 { // Embedded font if info.Tp == "TrueType" { f.fontFiles[info.File] = fontFileType{length1: int64(info.OriginalSize)} } else { f.fontFiles[info.File] = fontFileType{length1: int64(info.Size1), length2: int64(info.Size2)} } } f.fonts[fontkey] = info return }
[ "func", "(", "f", "*", "Fpdf", ")", "AddFontFromReader", "(", "familyStr", ",", "styleStr", "string", ",", "r", "io", ".", "Reader", ")", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "// dbg(\"Adding family [%s], style [%s]\", familyStr, styleStr)", "var", "ok", "bool", "\n", "fontkey", ":=", "getFontKey", "(", "familyStr", ",", "styleStr", ")", "\n", "_", ",", "ok", "=", "f", ".", "fonts", "[", "fontkey", "]", "\n", "if", "ok", "{", "return", "\n", "}", "\n", "var", "info", "fontDefType", "\n", "info", "=", "f", ".", "loadfont", "(", "r", ")", "\n", "if", "f", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "len", "(", "info", ".", "Diff", ")", ">", "0", "{", "// Search existing encodings", "n", ":=", "-", "1", "\n", "for", "j", ",", "str", ":=", "range", "f", ".", "diffs", "{", "if", "str", "==", "info", ".", "Diff", "{", "n", "=", "j", "+", "1", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "n", "<", "0", "{", "f", ".", "diffs", "=", "append", "(", "f", ".", "diffs", ",", "info", ".", "Diff", ")", "\n", "n", "=", "len", "(", "f", ".", "diffs", ")", "\n", "}", "\n", "info", ".", "DiffN", "=", "n", "\n", "}", "\n", "// dbg(\"font [%s], type [%s]\", info.File, info.Tp)", "if", "len", "(", "info", ".", "File", ")", ">", "0", "{", "// Embedded font", "if", "info", ".", "Tp", "==", "\"", "\"", "{", "f", ".", "fontFiles", "[", "info", ".", "File", "]", "=", "fontFileType", "{", "length1", ":", "int64", "(", "info", ".", "OriginalSize", ")", "}", "\n", "}", "else", "{", "f", ".", "fontFiles", "[", "info", ".", "File", "]", "=", "fontFileType", "{", "length1", ":", "int64", "(", "info", ".", "Size1", ")", ",", "length2", ":", "int64", "(", "info", ".", "Size2", ")", "}", "\n", "}", "\n", "}", "\n", "f", ".", "fonts", "[", "fontkey", "]", "=", "info", "\n", "return", "\n", "}" ]
// AddFontFromReader imports a TrueType, OpenType or Type1 font and makes it // available using a reader that satisifies the io.Reader interface. See // AddFont for details about familyStr and styleStr.
[ "AddFontFromReader", "imports", "a", "TrueType", "OpenType", "or", "Type1", "font", "and", "makes", "it", "available", "using", "a", "reader", "that", "satisifies", "the", "io", ".", "Reader", "interface", ".", "See", "AddFont", "for", "details", "about", "familyStr", "and", "styleStr", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1650-L1692
train
jung-kurt/gofpdf
fpdf.go
GetFontDesc
func (f *Fpdf) GetFontDesc(familyStr, styleStr string) FontDescType { if familyStr == "" { return f.currentFont.Desc } return f.fonts[getFontKey(familyStr, styleStr)].Desc }
go
func (f *Fpdf) GetFontDesc(familyStr, styleStr string) FontDescType { if familyStr == "" { return f.currentFont.Desc } return f.fonts[getFontKey(familyStr, styleStr)].Desc }
[ "func", "(", "f", "*", "Fpdf", ")", "GetFontDesc", "(", "familyStr", ",", "styleStr", "string", ")", "FontDescType", "{", "if", "familyStr", "==", "\"", "\"", "{", "return", "f", ".", "currentFont", ".", "Desc", "\n", "}", "\n", "return", "f", ".", "fonts", "[", "getFontKey", "(", "familyStr", ",", "styleStr", ")", "]", ".", "Desc", "\n", "}" ]
// GetFontDesc returns the font descriptor, which can be used for // example to find the baseline of a font. If familyStr is empty // current font descriptor will be returned. // See FontDescType for documentation about the font descriptor. // See AddFont for details about familyStr and styleStr.
[ "GetFontDesc", "returns", "the", "font", "descriptor", "which", "can", "be", "used", "for", "example", "to", "find", "the", "baseline", "of", "a", "font", ".", "If", "familyStr", "is", "empty", "current", "font", "descriptor", "will", "be", "returned", ".", "See", "FontDescType", "for", "documentation", "about", "the", "font", "descriptor", ".", "See", "AddFont", "for", "details", "about", "familyStr", "and", "styleStr", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1699-L1704
train
jung-kurt/gofpdf
fpdf.go
newLink
func (f *Fpdf) newLink(x, y, w, h float64, link int, linkStr string) { // linkList, ok := f.pageLinks[f.page] // if !ok { // linkList = make([]linkType, 0, 8) // f.pageLinks[f.page] = linkList // } f.pageLinks[f.page] = append(f.pageLinks[f.page], linkType{x * f.k, f.hPt - y*f.k, w * f.k, h * f.k, link, linkStr}) }
go
func (f *Fpdf) newLink(x, y, w, h float64, link int, linkStr string) { // linkList, ok := f.pageLinks[f.page] // if !ok { // linkList = make([]linkType, 0, 8) // f.pageLinks[f.page] = linkList // } f.pageLinks[f.page] = append(f.pageLinks[f.page], linkType{x * f.k, f.hPt - y*f.k, w * f.k, h * f.k, link, linkStr}) }
[ "func", "(", "f", "*", "Fpdf", ")", "newLink", "(", "x", ",", "y", ",", "w", ",", "h", "float64", ",", "link", "int", ",", "linkStr", "string", ")", "{", "// linkList, ok := f.pageLinks[f.page]", "// if !ok {", "// linkList = make([]linkType, 0, 8)", "// f.pageLinks[f.page] = linkList", "// }", "f", ".", "pageLinks", "[", "f", ".", "page", "]", "=", "append", "(", "f", ".", "pageLinks", "[", "f", ".", "page", "]", ",", "linkType", "{", "x", "*", "f", ".", "k", ",", "f", ".", "hPt", "-", "y", "*", "f", ".", "k", ",", "w", "*", "f", ".", "k", ",", "h", "*", "f", ".", "k", ",", "link", ",", "linkStr", "}", ")", "\n", "}" ]
// newLink adds a new clickable link on current page
[ "newLink", "adds", "a", "new", "clickable", "link", "on", "current", "page" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1855-L1863
train
jung-kurt/gofpdf
fpdf.go
Bookmark
func (f *Fpdf) Bookmark(txtStr string, level int, y float64) { if y == -1 { y = f.y } f.outlines = append(f.outlines, outlineType{text: txtStr, level: level, y: y, p: f.PageNo(), prev: -1, last: -1, next: -1, first: -1}) }
go
func (f *Fpdf) Bookmark(txtStr string, level int, y float64) { if y == -1 { y = f.y } f.outlines = append(f.outlines, outlineType{text: txtStr, level: level, y: y, p: f.PageNo(), prev: -1, last: -1, next: -1, first: -1}) }
[ "func", "(", "f", "*", "Fpdf", ")", "Bookmark", "(", "txtStr", "string", ",", "level", "int", ",", "y", "float64", ")", "{", "if", "y", "==", "-", "1", "{", "y", "=", "f", ".", "y", "\n", "}", "\n", "f", ".", "outlines", "=", "append", "(", "f", ".", "outlines", ",", "outlineType", "{", "text", ":", "txtStr", ",", "level", ":", "level", ",", "y", ":", "y", ",", "p", ":", "f", ".", "PageNo", "(", ")", ",", "prev", ":", "-", "1", ",", "last", ":", "-", "1", ",", "next", ":", "-", "1", ",", "first", ":", "-", "1", "}", ")", "\n", "}" ]
// Bookmark sets a bookmark that will be displayed in a sidebar outline. txtStr // is the title of the bookmark. level specifies the level of the bookmark in // the outline; 0 is the top level, 1 is just below, and so on. y specifies the // vertical position of the bookmark destination in the current page; -1 // indicates the current position.
[ "Bookmark", "sets", "a", "bookmark", "that", "will", "be", "displayed", "in", "a", "sidebar", "outline", ".", "txtStr", "is", "the", "title", "of", "the", "bookmark", ".", "level", "specifies", "the", "level", "of", "the", "bookmark", "in", "the", "outline", ";", "0", "is", "the", "top", "level", "1", "is", "just", "below", "and", "so", "on", ".", "y", "specifies", "the", "vertical", "position", "of", "the", "bookmark", "destination", "in", "the", "current", "page", ";", "-", "1", "indicates", "the", "current", "position", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1886-L1891
train
jung-kurt/gofpdf
fpdf.go
Cell
func (f *Fpdf) Cell(w, h float64, txtStr string) { f.CellFormat(w, h, txtStr, "", 0, "L", false, 0, "") }
go
func (f *Fpdf) Cell(w, h float64, txtStr string) { f.CellFormat(w, h, txtStr, "", 0, "L", false, 0, "") }
[ "func", "(", "f", "*", "Fpdf", ")", "Cell", "(", "w", ",", "h", "float64", ",", "txtStr", "string", ")", "{", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "txtStr", ",", "\"", "\"", ",", "0", ",", "\"", "\"", ",", "false", ",", "0", ",", "\"", "\"", ")", "\n", "}" ]
// Cell is a simpler version of CellFormat with no fill, border, links or // special alignment.
[ "Cell", "is", "a", "simpler", "version", "of", "CellFormat", "with", "no", "fill", "border", "links", "or", "special", "alignment", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2114-L2116
train
jung-kurt/gofpdf
fpdf.go
Cellf
func (f *Fpdf) Cellf(w, h float64, fmtStr string, args ...interface{}) { f.CellFormat(w, h, sprintf(fmtStr, args...), "", 0, "L", false, 0, "") }
go
func (f *Fpdf) Cellf(w, h float64, fmtStr string, args ...interface{}) { f.CellFormat(w, h, sprintf(fmtStr, args...), "", 0, "L", false, 0, "") }
[ "func", "(", "f", "*", "Fpdf", ")", "Cellf", "(", "w", ",", "h", "float64", ",", "fmtStr", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "sprintf", "(", "fmtStr", ",", "args", "...", ")", ",", "\"", "\"", ",", "0", ",", "\"", "\"", ",", "false", ",", "0", ",", "\"", "\"", ")", "\n", "}" ]
// Cellf is a simpler printf-style version of CellFormat with no fill, border, // links or special alignment. See documentation for the fmt package for // details on fmtStr and args.
[ "Cellf", "is", "a", "simpler", "printf", "-", "style", "version", "of", "CellFormat", "with", "no", "fill", "border", "links", "or", "special", "alignment", ".", "See", "documentation", "for", "the", "fmt", "package", "for", "details", "on", "fmtStr", "and", "args", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2121-L2123
train
jung-kurt/gofpdf
fpdf.go
SplitLines
func (f *Fpdf) SplitLines(txt []byte, w float64) [][]byte { // Function contributed by Bruno Michel lines := [][]byte{} cw := &f.currentFont.Cw wmax := int(math.Ceil((w - 2*f.cMargin) * 1000 / f.fontSize)) s := bytes.Replace(txt, []byte("\r"), []byte{}, -1) nb := len(s) for nb > 0 && s[nb-1] == '\n' { nb-- } s = s[0:nb] sep := -1 i := 0 j := 0 l := 0 for i < nb { c := s[i] l += cw[c] if c == ' ' || c == '\t' || c == '\n' { sep = i } if c == '\n' || l > wmax { if sep == -1 { if i == j { i++ } sep = i } else { i = sep + 1 } lines = append(lines, s[j:sep]) sep = -1 j = i l = 0 } else { i++ } } if i != j { lines = append(lines, s[j:i]) } return lines }
go
func (f *Fpdf) SplitLines(txt []byte, w float64) [][]byte { // Function contributed by Bruno Michel lines := [][]byte{} cw := &f.currentFont.Cw wmax := int(math.Ceil((w - 2*f.cMargin) * 1000 / f.fontSize)) s := bytes.Replace(txt, []byte("\r"), []byte{}, -1) nb := len(s) for nb > 0 && s[nb-1] == '\n' { nb-- } s = s[0:nb] sep := -1 i := 0 j := 0 l := 0 for i < nb { c := s[i] l += cw[c] if c == ' ' || c == '\t' || c == '\n' { sep = i } if c == '\n' || l > wmax { if sep == -1 { if i == j { i++ } sep = i } else { i = sep + 1 } lines = append(lines, s[j:sep]) sep = -1 j = i l = 0 } else { i++ } } if i != j { lines = append(lines, s[j:i]) } return lines }
[ "func", "(", "f", "*", "Fpdf", ")", "SplitLines", "(", "txt", "[", "]", "byte", ",", "w", "float64", ")", "[", "]", "[", "]", "byte", "{", "// Function contributed by Bruno Michel", "lines", ":=", "[", "]", "[", "]", "byte", "{", "}", "\n", "cw", ":=", "&", "f", ".", "currentFont", ".", "Cw", "\n", "wmax", ":=", "int", "(", "math", ".", "Ceil", "(", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", ")", ")", "\n", "s", ":=", "bytes", ".", "Replace", "(", "txt", ",", "[", "]", "byte", "(", "\"", "\\r", "\"", ")", ",", "[", "]", "byte", "{", "}", ",", "-", "1", ")", "\n", "nb", ":=", "len", "(", "s", ")", "\n", "for", "nb", ">", "0", "&&", "s", "[", "nb", "-", "1", "]", "==", "'\\n'", "{", "nb", "--", "\n", "}", "\n", "s", "=", "s", "[", "0", ":", "nb", "]", "\n", "sep", ":=", "-", "1", "\n", "i", ":=", "0", "\n", "j", ":=", "0", "\n", "l", ":=", "0", "\n", "for", "i", "<", "nb", "{", "c", ":=", "s", "[", "i", "]", "\n", "l", "+=", "cw", "[", "c", "]", "\n", "if", "c", "==", "' '", "||", "c", "==", "'\\t'", "||", "c", "==", "'\\n'", "{", "sep", "=", "i", "\n", "}", "\n", "if", "c", "==", "'\\n'", "||", "l", ">", "wmax", "{", "if", "sep", "==", "-", "1", "{", "if", "i", "==", "j", "{", "i", "++", "\n", "}", "\n", "sep", "=", "i", "\n", "}", "else", "{", "i", "=", "sep", "+", "1", "\n", "}", "\n", "lines", "=", "append", "(", "lines", ",", "s", "[", "j", ":", "sep", "]", ")", "\n", "sep", "=", "-", "1", "\n", "j", "=", "i", "\n", "l", "=", "0", "\n", "}", "else", "{", "i", "++", "\n", "}", "\n", "}", "\n", "if", "i", "!=", "j", "{", "lines", "=", "append", "(", "lines", ",", "s", "[", "j", ":", "i", "]", ")", "\n", "}", "\n", "return", "lines", "\n", "}" ]
// SplitLines splits text into several lines using the current font. Each line // has its length limited to a maximum width given by w. This function can be // used to determine the total height of wrapped text for vertical placement // purposes. // // You can use MultiCell if you want to print a text on several lines in a // simple way.
[ "SplitLines", "splits", "text", "into", "several", "lines", "using", "the", "current", "font", ".", "Each", "line", "has", "its", "length", "limited", "to", "a", "maximum", "width", "given", "by", "w", ".", "This", "function", "can", "be", "used", "to", "determine", "the", "total", "height", "of", "wrapped", "text", "for", "vertical", "placement", "purposes", ".", "You", "can", "use", "MultiCell", "if", "you", "want", "to", "print", "a", "text", "on", "several", "lines", "in", "a", "simple", "way", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2132-L2174
train
jung-kurt/gofpdf
fpdf.go
write
func (f *Fpdf) write(h float64, txtStr string, link int, linkStr string) { // dbg("Write") cw := &f.currentFont.Cw w := f.w - f.rMargin - f.x wmax := (w - 2*f.cMargin) * 1000 / f.fontSize s := strings.Replace(txtStr, "\r", "", -1) nb := len(s) sep := -1 i := 0 j := 0 l := 0.0 nl := 1 for i < nb { // Get next character c := []byte(s)[i] if c == '\n' { // Explicit line break f.CellFormat(w, h, s[j:i], "", 2, "", false, link, linkStr) i++ sep = -1 j = i l = 0.0 if nl == 1 { f.x = f.lMargin w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize } nl++ continue } if c == ' ' { sep = i } l += float64(cw[c]) if l > wmax { // Automatic line break if sep == -1 { if f.x > f.lMargin { // Move to next line f.x = f.lMargin f.y += h w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize i++ nl++ continue } if i == j { i++ } f.CellFormat(w, h, s[j:i], "", 2, "", false, link, linkStr) } else { f.CellFormat(w, h, s[j:sep], "", 2, "", false, link, linkStr) i = sep + 1 } sep = -1 j = i l = 0.0 if nl == 1 { f.x = f.lMargin w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize } nl++ } else { i++ } } // Last chunk if i != j { f.CellFormat(l/1000*f.fontSize, h, s[j:], "", 0, "", false, link, linkStr) } }
go
func (f *Fpdf) write(h float64, txtStr string, link int, linkStr string) { // dbg("Write") cw := &f.currentFont.Cw w := f.w - f.rMargin - f.x wmax := (w - 2*f.cMargin) * 1000 / f.fontSize s := strings.Replace(txtStr, "\r", "", -1) nb := len(s) sep := -1 i := 0 j := 0 l := 0.0 nl := 1 for i < nb { // Get next character c := []byte(s)[i] if c == '\n' { // Explicit line break f.CellFormat(w, h, s[j:i], "", 2, "", false, link, linkStr) i++ sep = -1 j = i l = 0.0 if nl == 1 { f.x = f.lMargin w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize } nl++ continue } if c == ' ' { sep = i } l += float64(cw[c]) if l > wmax { // Automatic line break if sep == -1 { if f.x > f.lMargin { // Move to next line f.x = f.lMargin f.y += h w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize i++ nl++ continue } if i == j { i++ } f.CellFormat(w, h, s[j:i], "", 2, "", false, link, linkStr) } else { f.CellFormat(w, h, s[j:sep], "", 2, "", false, link, linkStr) i = sep + 1 } sep = -1 j = i l = 0.0 if nl == 1 { f.x = f.lMargin w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize } nl++ } else { i++ } } // Last chunk if i != j { f.CellFormat(l/1000*f.fontSize, h, s[j:], "", 0, "", false, link, linkStr) } }
[ "func", "(", "f", "*", "Fpdf", ")", "write", "(", "h", "float64", ",", "txtStr", "string", ",", "link", "int", ",", "linkStr", "string", ")", "{", "// dbg(\"Write\")", "cw", ":=", "&", "f", ".", "currentFont", ".", "Cw", "\n", "w", ":=", "f", ".", "w", "-", "f", ".", "rMargin", "-", "f", ".", "x", "\n", "wmax", ":=", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", "\n", "s", ":=", "strings", ".", "Replace", "(", "txtStr", ",", "\"", "\\r", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "nb", ":=", "len", "(", "s", ")", "\n", "sep", ":=", "-", "1", "\n", "i", ":=", "0", "\n", "j", ":=", "0", "\n", "l", ":=", "0.0", "\n", "nl", ":=", "1", "\n", "for", "i", "<", "nb", "{", "// Get next character", "c", ":=", "[", "]", "byte", "(", "s", ")", "[", "i", "]", "\n", "if", "c", "==", "'\\n'", "{", "// Explicit line break", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "s", "[", "j", ":", "i", "]", ",", "\"", "\"", ",", "2", ",", "\"", "\"", ",", "false", ",", "link", ",", "linkStr", ")", "\n", "i", "++", "\n", "sep", "=", "-", "1", "\n", "j", "=", "i", "\n", "l", "=", "0.0", "\n", "if", "nl", "==", "1", "{", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "w", "=", "f", ".", "w", "-", "f", ".", "rMargin", "-", "f", ".", "x", "\n", "wmax", "=", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", "\n", "}", "\n", "nl", "++", "\n", "continue", "\n", "}", "\n", "if", "c", "==", "' '", "{", "sep", "=", "i", "\n", "}", "\n", "l", "+=", "float64", "(", "cw", "[", "c", "]", ")", "\n", "if", "l", ">", "wmax", "{", "// Automatic line break", "if", "sep", "==", "-", "1", "{", "if", "f", ".", "x", ">", "f", ".", "lMargin", "{", "// Move to next line", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "f", ".", "y", "+=", "h", "\n", "w", "=", "f", ".", "w", "-", "f", ".", "rMargin", "-", "f", ".", "x", "\n", "wmax", "=", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", "\n", "i", "++", "\n", "nl", "++", "\n", "continue", "\n", "}", "\n", "if", "i", "==", "j", "{", "i", "++", "\n", "}", "\n", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "s", "[", "j", ":", "i", "]", ",", "\"", "\"", ",", "2", ",", "\"", "\"", ",", "false", ",", "link", ",", "linkStr", ")", "\n", "}", "else", "{", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "s", "[", "j", ":", "sep", "]", ",", "\"", "\"", ",", "2", ",", "\"", "\"", ",", "false", ",", "link", ",", "linkStr", ")", "\n", "i", "=", "sep", "+", "1", "\n", "}", "\n", "sep", "=", "-", "1", "\n", "j", "=", "i", "\n", "l", "=", "0.0", "\n", "if", "nl", "==", "1", "{", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "w", "=", "f", ".", "w", "-", "f", ".", "rMargin", "-", "f", ".", "x", "\n", "wmax", "=", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", "\n", "}", "\n", "nl", "++", "\n", "}", "else", "{", "i", "++", "\n", "}", "\n", "}", "\n", "// Last chunk", "if", "i", "!=", "j", "{", "f", ".", "CellFormat", "(", "l", "/", "1000", "*", "f", ".", "fontSize", ",", "h", ",", "s", "[", "j", ":", "]", ",", "\"", "\"", ",", "0", ",", "\"", "\"", ",", "false", ",", "link", ",", "linkStr", ")", "\n", "}", "\n", "}" ]
// write outputs text in flowing mode
[ "write", "outputs", "text", "in", "flowing", "mode" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2312-L2384
train
jung-kurt/gofpdf
fpdf.go
Writef
func (f *Fpdf) Writef(h float64, fmtStr string, args ...interface{}) { f.write(h, sprintf(fmtStr, args...), 0, "") }
go
func (f *Fpdf) Writef(h float64, fmtStr string, args ...interface{}) { f.write(h, sprintf(fmtStr, args...), 0, "") }
[ "func", "(", "f", "*", "Fpdf", ")", "Writef", "(", "h", "float64", ",", "fmtStr", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "f", ".", "write", "(", "h", ",", "sprintf", "(", "fmtStr", ",", "args", "...", ")", ",", "0", ",", "\"", "\"", ")", "\n", "}" ]
// Writef is like Write but uses printf-style formatting. See the documentation // for package fmt for more details on fmtStr and args.
[ "Writef", "is", "like", "Write", "but", "uses", "printf", "-", "style", "formatting", ".", "See", "the", "documentation", "for", "package", "fmt", "for", "more", "details", "on", "fmtStr", "and", "args", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2400-L2402
train
jung-kurt/gofpdf
fpdf.go
Ln
func (f *Fpdf) Ln(h float64) { f.x = f.lMargin if h < 0 { f.y += f.lasth } else { f.y += h } }
go
func (f *Fpdf) Ln(h float64) { f.x = f.lMargin if h < 0 { f.y += f.lasth } else { f.y += h } }
[ "func", "(", "f", "*", "Fpdf", ")", "Ln", "(", "h", "float64", ")", "{", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "if", "h", "<", "0", "{", "f", ".", "y", "+=", "f", ".", "lasth", "\n", "}", "else", "{", "f", ".", "y", "+=", "h", "\n", "}", "\n", "}" ]
// Ln performs a line break. The current abscissa goes back to the left margin // and the ordinate increases by the amount passed in parameter. A negative // value of h indicates the height of the last printed cell. // // This method is demonstrated in the example for MultiCell.
[ "Ln", "performs", "a", "line", "break", ".", "The", "current", "abscissa", "goes", "back", "to", "the", "left", "margin", "and", "the", "ordinate", "increases", "by", "the", "amount", "passed", "in", "parameter", ".", "A", "negative", "value", "of", "h", "indicates", "the", "height", "of", "the", "last", "printed", "cell", ".", "This", "method", "is", "demonstrated", "in", "the", "example", "for", "MultiCell", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2463-L2470
train
jung-kurt/gofpdf
fpdf.go
RegisterImageReader
func (f *Fpdf) RegisterImageReader(imgName, tp string, r io.Reader) (info *ImageInfoType) { options := ImageOptions{ ReadDpi: false, ImageType: tp, } return f.RegisterImageOptionsReader(imgName, options, r) }
go
func (f *Fpdf) RegisterImageReader(imgName, tp string, r io.Reader) (info *ImageInfoType) { options := ImageOptions{ ReadDpi: false, ImageType: tp, } return f.RegisterImageOptionsReader(imgName, options, r) }
[ "func", "(", "f", "*", "Fpdf", ")", "RegisterImageReader", "(", "imgName", ",", "tp", "string", ",", "r", "io", ".", "Reader", ")", "(", "info", "*", "ImageInfoType", ")", "{", "options", ":=", "ImageOptions", "{", "ReadDpi", ":", "false", ",", "ImageType", ":", "tp", ",", "}", "\n", "return", "f", ".", "RegisterImageOptionsReader", "(", "imgName", ",", "options", ",", "r", ")", "\n", "}" ]
// RegisterImageReader registers an image, reading it from Reader r, adding it // to the PDF file but not adding it to the page. // // This function is now deprecated in favor of RegisterImageOptionsReader
[ "RegisterImageReader", "registers", "an", "image", "reading", "it", "from", "Reader", "r", "adding", "it", "to", "the", "PDF", "file", "but", "not", "adding", "it", "to", "the", "page", ".", "This", "function", "is", "now", "deprecated", "in", "favor", "of", "RegisterImageOptionsReader" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2612-L2618
train
jung-kurt/gofpdf
fpdf.go
GetImageInfo
func (f *Fpdf) GetImageInfo(imageStr string) (info *ImageInfoType) { return f.images[imageStr] }
go
func (f *Fpdf) GetImageInfo(imageStr string) (info *ImageInfoType) { return f.images[imageStr] }
[ "func", "(", "f", "*", "Fpdf", ")", "GetImageInfo", "(", "imageStr", "string", ")", "(", "info", "*", "ImageInfoType", ")", "{", "return", "f", ".", "images", "[", "imageStr", "]", "\n", "}" ]
// GetImageInfo returns information about the registered image specified by // imageStr. If the image has not been registered, nil is returned. The // internal error is not modified by this method.
[ "GetImageInfo", "returns", "information", "about", "the", "registered", "image", "specified", "by", "imageStr", ".", "If", "the", "image", "has", "not", "been", "registered", "nil", "is", "returned", ".", "The", "internal", "error", "is", "not", "modified", "by", "this", "method", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2737-L2739
train
jung-kurt/gofpdf
fpdf.go
SetX
func (f *Fpdf) SetX(x float64) { if x >= 0 { f.x = x } else { f.x = f.w + x } }
go
func (f *Fpdf) SetX(x float64) { if x >= 0 { f.x = x } else { f.x = f.w + x } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetX", "(", "x", "float64", ")", "{", "if", "x", ">=", "0", "{", "f", ".", "x", "=", "x", "\n", "}", "else", "{", "f", ".", "x", "=", "f", ".", "w", "+", "x", "\n", "}", "\n", "}" ]
// SetX defines the abscissa of the current position. If the passed value is // negative, it is relative to the right of the page.
[ "SetX", "defines", "the", "abscissa", "of", "the", "current", "position", ".", "If", "the", "passed", "value", "is", "negative", "it", "is", "relative", "to", "the", "right", "of", "the", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2768-L2774
train
jung-kurt/gofpdf
fpdf.go
SetY
func (f *Fpdf) SetY(y float64) { // dbg("SetY x %.2f, lMargin %.2f", f.x, f.lMargin) f.x = f.lMargin if y >= 0 { f.y = y } else { f.y = f.h + y } }
go
func (f *Fpdf) SetY(y float64) { // dbg("SetY x %.2f, lMargin %.2f", f.x, f.lMargin) f.x = f.lMargin if y >= 0 { f.y = y } else { f.y = f.h + y } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetY", "(", "y", "float64", ")", "{", "// dbg(\"SetY x %.2f, lMargin %.2f\", f.x, f.lMargin)", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "if", "y", ">=", "0", "{", "f", ".", "y", "=", "y", "\n", "}", "else", "{", "f", ".", "y", "=", "f", ".", "h", "+", "y", "\n", "}", "\n", "}" ]
// SetY moves the current abscissa back to the left margin and sets the // ordinate. If the passed value is negative, it is relative to the bottom of // the page.
[ "SetY", "moves", "the", "current", "abscissa", "back", "to", "the", "left", "margin", "and", "sets", "the", "ordinate", ".", "If", "the", "passed", "value", "is", "negative", "it", "is", "relative", "to", "the", "bottom", "of", "the", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2784-L2792
train
jung-kurt/gofpdf
fpdf.go
SetHomeXY
func (f *Fpdf) SetHomeXY() { f.SetY(f.tMargin) f.SetX(f.lMargin) }
go
func (f *Fpdf) SetHomeXY() { f.SetY(f.tMargin) f.SetX(f.lMargin) }
[ "func", "(", "f", "*", "Fpdf", ")", "SetHomeXY", "(", ")", "{", "f", ".", "SetY", "(", "f", ".", "tMargin", ")", "\n", "f", ".", "SetX", "(", "f", ".", "lMargin", ")", "\n", "}" ]
// SetHomeXY is a convenience method that sets the current position to the left // and top margins.
[ "SetHomeXY", "is", "a", "convenience", "method", "that", "sets", "the", "current", "position", "to", "the", "left", "and", "top", "margins", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2796-L2799
train
jung-kurt/gofpdf
fpdf.go
SetXY
func (f *Fpdf) SetXY(x, y float64) { f.SetY(y) f.SetX(x) }
go
func (f *Fpdf) SetXY(x, y float64) { f.SetY(y) f.SetX(x) }
[ "func", "(", "f", "*", "Fpdf", ")", "SetXY", "(", "x", ",", "y", "float64", ")", "{", "f", ".", "SetY", "(", "y", ")", "\n", "f", ".", "SetX", "(", "x", ")", "\n", "}" ]
// SetXY defines the abscissa and ordinate of the current position. If the // passed values are negative, they are relative respectively to the right and // bottom of the page.
[ "SetXY", "defines", "the", "abscissa", "and", "ordinate", "of", "the", "current", "position", ".", "If", "the", "passed", "values", "are", "negative", "they", "are", "relative", "respectively", "to", "the", "right", "and", "bottom", "of", "the", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2804-L2807
train
jung-kurt/gofpdf
fpdf.go
SetProtection
func (f *Fpdf) SetProtection(actionFlag byte, userPassStr, ownerPassStr string) { if f.err != nil { return } f.protect.setProtection(actionFlag, userPassStr, ownerPassStr) }
go
func (f *Fpdf) SetProtection(actionFlag byte, userPassStr, ownerPassStr string) { if f.err != nil { return } f.protect.setProtection(actionFlag, userPassStr, ownerPassStr) }
[ "func", "(", "f", "*", "Fpdf", ")", "SetProtection", "(", "actionFlag", "byte", ",", "userPassStr", ",", "ownerPassStr", "string", ")", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "f", ".", "protect", ".", "setProtection", "(", "actionFlag", ",", "userPassStr", ",", "ownerPassStr", ")", "\n", "}" ]
// SetProtection applies certain constraints on the finished PDF document. // // actionFlag is a bitflag that controls various document operations. // CnProtectPrint allows the document to be printed. CnProtectModify allows a // document to be modified by a PDF editor. CnProtectCopy allows text and // images to be copied into the system clipboard. CnProtectAnnotForms allows // annotations and forms to be added by a PDF editor. These values can be // combined by or-ing them together, for example, // CnProtectCopy|CnProtectModify. This flag is advisory; not all PDF readers // implement the constraints that this argument attempts to control. // // userPassStr specifies the password that will need to be provided to view the // contents of the PDF. The permissions specified by actionFlag will apply. // // ownerPassStr specifies the password that will need to be provided to gain // full access to the document regardless of the actionFlag value. An empty // string for this argument will be replaced with a random value, effectively // prohibiting full access to the document.
[ "SetProtection", "applies", "certain", "constraints", "on", "the", "finished", "PDF", "document", ".", "actionFlag", "is", "a", "bitflag", "that", "controls", "various", "document", "operations", ".", "CnProtectPrint", "allows", "the", "document", "to", "be", "printed", ".", "CnProtectModify", "allows", "a", "document", "to", "be", "modified", "by", "a", "PDF", "editor", ".", "CnProtectCopy", "allows", "text", "and", "images", "to", "be", "copied", "into", "the", "system", "clipboard", ".", "CnProtectAnnotForms", "allows", "annotations", "and", "forms", "to", "be", "added", "by", "a", "PDF", "editor", ".", "These", "values", "can", "be", "combined", "by", "or", "-", "ing", "them", "together", "for", "example", "CnProtectCopy|CnProtectModify", ".", "This", "flag", "is", "advisory", ";", "not", "all", "PDF", "readers", "implement", "the", "constraints", "that", "this", "argument", "attempts", "to", "control", ".", "userPassStr", "specifies", "the", "password", "that", "will", "need", "to", "be", "provided", "to", "view", "the", "contents", "of", "the", "PDF", ".", "The", "permissions", "specified", "by", "actionFlag", "will", "apply", ".", "ownerPassStr", "specifies", "the", "password", "that", "will", "need", "to", "be", "provided", "to", "gain", "full", "access", "to", "the", "document", "regardless", "of", "the", "actionFlag", "value", ".", "An", "empty", "string", "for", "this", "argument", "will", "be", "replaced", "with", "a", "random", "value", "effectively", "prohibiting", "full", "access", "to", "the", "document", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2827-L2832
train
jung-kurt/gofpdf
fpdf.go
OutputAndClose
func (f *Fpdf) OutputAndClose(w io.WriteCloser) error { f.Output(w) w.Close() return f.err }
go
func (f *Fpdf) OutputAndClose(w io.WriteCloser) error { f.Output(w) w.Close() return f.err }
[ "func", "(", "f", "*", "Fpdf", ")", "OutputAndClose", "(", "w", "io", ".", "WriteCloser", ")", "error", "{", "f", ".", "Output", "(", "w", ")", "\n", "w", ".", "Close", "(", ")", "\n", "return", "f", ".", "err", "\n", "}" ]
// OutputAndClose sends the PDF document to the writer specified by w. This // method will close both f and w, even if an error is detected and no document // is produced.
[ "OutputAndClose", "sends", "the", "PDF", "document", "to", "the", "writer", "specified", "by", "w", ".", "This", "method", "will", "close", "both", "f", "and", "w", "even", "if", "an", "error", "is", "detected", "and", "no", "document", "is", "produced", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2837-L2841
train
jung-kurt/gofpdf
fpdf.go
OutputFileAndClose
func (f *Fpdf) OutputFileAndClose(fileStr string) error { if f.err == nil { pdfFile, err := os.Create(fileStr) if err == nil { f.Output(pdfFile) pdfFile.Close() } else { f.err = err } } return f.err }
go
func (f *Fpdf) OutputFileAndClose(fileStr string) error { if f.err == nil { pdfFile, err := os.Create(fileStr) if err == nil { f.Output(pdfFile) pdfFile.Close() } else { f.err = err } } return f.err }
[ "func", "(", "f", "*", "Fpdf", ")", "OutputFileAndClose", "(", "fileStr", "string", ")", "error", "{", "if", "f", ".", "err", "==", "nil", "{", "pdfFile", ",", "err", ":=", "os", ".", "Create", "(", "fileStr", ")", "\n", "if", "err", "==", "nil", "{", "f", ".", "Output", "(", "pdfFile", ")", "\n", "pdfFile", ".", "Close", "(", ")", "\n", "}", "else", "{", "f", ".", "err", "=", "err", "\n", "}", "\n", "}", "\n", "return", "f", ".", "err", "\n", "}" ]
// OutputFileAndClose creates or truncates the file specified by fileStr and // writes the PDF document to it. This method will close f and the newly // written file, even if an error is detected and no document is produced. // // Most examples demonstrate the use of this method.
[ "OutputFileAndClose", "creates", "or", "truncates", "the", "file", "specified", "by", "fileStr", "and", "writes", "the", "PDF", "document", "to", "it", ".", "This", "method", "will", "close", "f", "and", "the", "newly", "written", "file", "even", "if", "an", "error", "is", "detected", "and", "no", "document", "is", "produced", ".", "Most", "examples", "demonstrate", "the", "use", "of", "this", "method", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2848-L2859
train
jung-kurt/gofpdf
fpdf.go
Output
func (f *Fpdf) Output(w io.Writer) error { if f.err != nil { return f.err } // dbg("Output") if f.state < 3 { f.Close() } _, err := f.buffer.WriteTo(w) if err != nil { f.err = err } return f.err }
go
func (f *Fpdf) Output(w io.Writer) error { if f.err != nil { return f.err } // dbg("Output") if f.state < 3 { f.Close() } _, err := f.buffer.WriteTo(w) if err != nil { f.err = err } return f.err }
[ "func", "(", "f", "*", "Fpdf", ")", "Output", "(", "w", "io", ".", "Writer", ")", "error", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "f", ".", "err", "\n", "}", "\n", "// dbg(\"Output\")", "if", "f", ".", "state", "<", "3", "{", "f", ".", "Close", "(", ")", "\n", "}", "\n", "_", ",", "err", ":=", "f", ".", "buffer", ".", "WriteTo", "(", "w", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "}", "\n", "return", "f", ".", "err", "\n", "}" ]
// Output sends the PDF document to the writer specified by w. No output will // take place if an error has occurred in the document generation process. w // remains open after this function returns. After returning, f is in a closed // state and its methods should not be called.
[ "Output", "sends", "the", "PDF", "document", "to", "the", "writer", "specified", "by", "w", ".", "No", "output", "will", "take", "place", "if", "an", "error", "has", "occurred", "in", "the", "document", "generation", "process", ".", "w", "remains", "open", "after", "this", "function", "returns", ".", "After", "returning", "f", "is", "in", "a", "closed", "state", "and", "its", "methods", "should", "not", "be", "called", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2865-L2878
train
jung-kurt/gofpdf
fpdf.go
loadfont
func (f *Fpdf) loadfont(r io.Reader) (def fontDefType) { if f.err != nil { return } // dbg("Loading font [%s]", fontStr) var buf bytes.Buffer _, err := buf.ReadFrom(r) if err != nil { f.err = err return } err = json.Unmarshal(buf.Bytes(), &def) if err != nil { f.err = err return } if def.i, err = generateFontID(def); err != nil { f.err = err } // dump(def) return }
go
func (f *Fpdf) loadfont(r io.Reader) (def fontDefType) { if f.err != nil { return } // dbg("Loading font [%s]", fontStr) var buf bytes.Buffer _, err := buf.ReadFrom(r) if err != nil { f.err = err return } err = json.Unmarshal(buf.Bytes(), &def) if err != nil { f.err = err return } if def.i, err = generateFontID(def); err != nil { f.err = err } // dump(def) return }
[ "func", "(", "f", "*", "Fpdf", ")", "loadfont", "(", "r", "io", ".", "Reader", ")", "(", "def", "fontDefType", ")", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "// dbg(\"Loading font [%s]\", fontStr)", "var", "buf", "bytes", ".", "Buffer", "\n", "_", ",", "err", ":=", "buf", ".", "ReadFrom", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "err", "=", "json", ".", "Unmarshal", "(", "buf", ".", "Bytes", "(", ")", ",", "&", "def", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n\n", "if", "def", ".", "i", ",", "err", "=", "generateFontID", "(", "def", ")", ";", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "}", "\n", "// dump(def)", "return", "\n", "}" ]
// Load a font definition file from the given Reader
[ "Load", "a", "font", "definition", "file", "from", "the", "given", "Reader" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2960-L2982
train
jung-kurt/gofpdf
fpdf.go
escape
func (f *Fpdf) escape(s string) string { s = strings.Replace(s, "\\", "\\\\", -1) s = strings.Replace(s, "(", "\\(", -1) s = strings.Replace(s, ")", "\\)", -1) s = strings.Replace(s, "\r", "\\r", -1) return s }
go
func (f *Fpdf) escape(s string) string { s = strings.Replace(s, "\\", "\\\\", -1) s = strings.Replace(s, "(", "\\(", -1) s = strings.Replace(s, ")", "\\)", -1) s = strings.Replace(s, "\r", "\\r", -1) return s }
[ "func", "(", "f", "*", "Fpdf", ")", "escape", "(", "s", "string", ")", "string", "{", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\\\\", "\"", ",", "\"", "\\\\", "\\\\", "\"", ",", "-", "1", ")", "\n", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\"", ",", "\"", "\\\\", "\"", ",", "-", "1", ")", "\n", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\"", ",", "\"", "\\\\", "\"", ",", "-", "1", ")", "\n", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\\r", "\"", ",", "\"", "\\\\", "\"", ",", "-", "1", ")", "\n", "return", "s", "\n", "}" ]
// Escape special characters in strings
[ "Escape", "special", "characters", "in", "strings" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2985-L2991
train
jung-kurt/gofpdf
fpdf.go
textstring
func (f *Fpdf) textstring(s string) string { if f.protect.encrypted { b := []byte(s) f.protect.rc4(uint32(f.n), &b) s = string(b) } return "(" + f.escape(s) + ")" }
go
func (f *Fpdf) textstring(s string) string { if f.protect.encrypted { b := []byte(s) f.protect.rc4(uint32(f.n), &b) s = string(b) } return "(" + f.escape(s) + ")" }
[ "func", "(", "f", "*", "Fpdf", ")", "textstring", "(", "s", "string", ")", "string", "{", "if", "f", ".", "protect", ".", "encrypted", "{", "b", ":=", "[", "]", "byte", "(", "s", ")", "\n", "f", ".", "protect", ".", "rc4", "(", "uint32", "(", "f", ".", "n", ")", ",", "&", "b", ")", "\n", "s", "=", "string", "(", "b", ")", "\n", "}", "\n", "return", "\"", "\"", "+", "f", ".", "escape", "(", "s", ")", "+", "\"", "\"", "\n", "}" ]
// textstring formats a text string
[ "textstring", "formats", "a", "text", "string" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2994-L3001
train
jung-kurt/gofpdf
fpdf.go
parsejpg
func (f *Fpdf) parsejpg(r io.Reader) (info *ImageInfoType) { info = f.newImageInfo() var ( data bytes.Buffer err error ) _, err = data.ReadFrom(r) if err != nil { f.err = err return } info.data = data.Bytes() config, err := jpeg.DecodeConfig(bytes.NewReader(info.data)) if err != nil { f.err = err return } info.w = float64(config.Width) info.h = float64(config.Height) info.f = "DCTDecode" info.bpc = 8 switch config.ColorModel { case color.GrayModel: info.cs = "DeviceGray" case color.YCbCrModel: info.cs = "DeviceRGB" case color.CMYKModel: info.cs = "DeviceCMYK" default: f.err = fmt.Errorf("image JPEG buffer has unsupported color space (%v)", config.ColorModel) return } return }
go
func (f *Fpdf) parsejpg(r io.Reader) (info *ImageInfoType) { info = f.newImageInfo() var ( data bytes.Buffer err error ) _, err = data.ReadFrom(r) if err != nil { f.err = err return } info.data = data.Bytes() config, err := jpeg.DecodeConfig(bytes.NewReader(info.data)) if err != nil { f.err = err return } info.w = float64(config.Width) info.h = float64(config.Height) info.f = "DCTDecode" info.bpc = 8 switch config.ColorModel { case color.GrayModel: info.cs = "DeviceGray" case color.YCbCrModel: info.cs = "DeviceRGB" case color.CMYKModel: info.cs = "DeviceCMYK" default: f.err = fmt.Errorf("image JPEG buffer has unsupported color space (%v)", config.ColorModel) return } return }
[ "func", "(", "f", "*", "Fpdf", ")", "parsejpg", "(", "r", "io", ".", "Reader", ")", "(", "info", "*", "ImageInfoType", ")", "{", "info", "=", "f", ".", "newImageInfo", "(", ")", "\n", "var", "(", "data", "bytes", ".", "Buffer", "\n", "err", "error", "\n", ")", "\n", "_", ",", "err", "=", "data", ".", "ReadFrom", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "info", ".", "data", "=", "data", ".", "Bytes", "(", ")", "\n\n", "config", ",", "err", ":=", "jpeg", ".", "DecodeConfig", "(", "bytes", ".", "NewReader", "(", "info", ".", "data", ")", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "info", ".", "w", "=", "float64", "(", "config", ".", "Width", ")", "\n", "info", ".", "h", "=", "float64", "(", "config", ".", "Height", ")", "\n", "info", ".", "f", "=", "\"", "\"", "\n", "info", ".", "bpc", "=", "8", "\n", "switch", "config", ".", "ColorModel", "{", "case", "color", ".", "GrayModel", ":", "info", ".", "cs", "=", "\"", "\"", "\n", "case", "color", ".", "YCbCrModel", ":", "info", ".", "cs", "=", "\"", "\"", "\n", "case", "color", ".", "CMYKModel", ":", "info", ".", "cs", "=", "\"", "\"", "\n", "default", ":", "f", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "config", ".", "ColorModel", ")", "\n", "return", "\n", "}", "\n", "return", "\n", "}" ]
// parsejpg extracts info from io.Reader with JPEG data // Thank you, Bruno Michel, for providing this code.
[ "parsejpg", "extracts", "info", "from", "io", ".", "Reader", "with", "JPEG", "data", "Thank", "you", "Bruno", "Michel", "for", "providing", "this", "code", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3037-L3071
train
jung-kurt/gofpdf
fpdf.go
parsepng
func (f *Fpdf) parsepng(r io.Reader, readdpi bool) (info *ImageInfoType) { buf, err := bufferFromReader(r) if err != nil { f.err = err return } return f.parsepngstream(buf, readdpi) }
go
func (f *Fpdf) parsepng(r io.Reader, readdpi bool) (info *ImageInfoType) { buf, err := bufferFromReader(r) if err != nil { f.err = err return } return f.parsepngstream(buf, readdpi) }
[ "func", "(", "f", "*", "Fpdf", ")", "parsepng", "(", "r", "io", ".", "Reader", ",", "readdpi", "bool", ")", "(", "info", "*", "ImageInfoType", ")", "{", "buf", ",", "err", ":=", "bufferFromReader", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "return", "f", ".", "parsepngstream", "(", "buf", ",", "readdpi", ")", "\n", "}" ]
// parsepng extracts info from a PNG data
[ "parsepng", "extracts", "info", "from", "a", "PNG", "data" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3074-L3081
train
jung-kurt/gofpdf
fpdf.go
newobj
func (f *Fpdf) newobj() { // dbg("newobj") f.n++ for j := len(f.offsets); j <= f.n; j++ { f.offsets = append(f.offsets, 0) } f.offsets[f.n] = f.buffer.Len() f.outf("%d 0 obj", f.n) }
go
func (f *Fpdf) newobj() { // dbg("newobj") f.n++ for j := len(f.offsets); j <= f.n; j++ { f.offsets = append(f.offsets, 0) } f.offsets[f.n] = f.buffer.Len() f.outf("%d 0 obj", f.n) }
[ "func", "(", "f", "*", "Fpdf", ")", "newobj", "(", ")", "{", "// dbg(\"newobj\")", "f", ".", "n", "++", "\n", "for", "j", ":=", "len", "(", "f", ".", "offsets", ")", ";", "j", "<=", "f", ".", "n", ";", "j", "++", "{", "f", ".", "offsets", "=", "append", "(", "f", ".", "offsets", ",", "0", ")", "\n", "}", "\n", "f", ".", "offsets", "[", "f", ".", "n", "]", "=", "f", ".", "buffer", ".", "Len", "(", ")", "\n", "f", ".", "outf", "(", "\"", "\"", ",", "f", ".", "n", ")", "\n", "}" ]
// newobj begins a new object
[ "newobj", "begins", "a", "new", "object" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3122-L3130
train
jung-kurt/gofpdf
fpdf.go
out
func (f *Fpdf) out(s string) { if f.state == 2 { f.pages[f.page].WriteString(s) f.pages[f.page].WriteString("\n") } else { f.buffer.WriteString(s) f.buffer.WriteString("\n") } }
go
func (f *Fpdf) out(s string) { if f.state == 2 { f.pages[f.page].WriteString(s) f.pages[f.page].WriteString("\n") } else { f.buffer.WriteString(s) f.buffer.WriteString("\n") } }
[ "func", "(", "f", "*", "Fpdf", ")", "out", "(", "s", "string", ")", "{", "if", "f", ".", "state", "==", "2", "{", "f", ".", "pages", "[", "f", ".", "page", "]", ".", "WriteString", "(", "s", ")", "\n", "f", ".", "pages", "[", "f", ".", "page", "]", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "else", "{", "f", ".", "buffer", ".", "WriteString", "(", "s", ")", "\n", "f", ".", "buffer", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n", "}" ]
// out; Add a line to the document
[ "out", ";", "Add", "a", "line", "to", "the", "document" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3143-L3151
train
jung-kurt/gofpdf
fpdf.go
outbuf
func (f *Fpdf) outbuf(r io.Reader) { if f.state == 2 { f.pages[f.page].ReadFrom(r) f.pages[f.page].WriteString("\n") } else { f.buffer.ReadFrom(r) f.buffer.WriteString("\n") } }
go
func (f *Fpdf) outbuf(r io.Reader) { if f.state == 2 { f.pages[f.page].ReadFrom(r) f.pages[f.page].WriteString("\n") } else { f.buffer.ReadFrom(r) f.buffer.WriteString("\n") } }
[ "func", "(", "f", "*", "Fpdf", ")", "outbuf", "(", "r", "io", ".", "Reader", ")", "{", "if", "f", ".", "state", "==", "2", "{", "f", ".", "pages", "[", "f", ".", "page", "]", ".", "ReadFrom", "(", "r", ")", "\n", "f", ".", "pages", "[", "f", ".", "page", "]", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "else", "{", "f", ".", "buffer", ".", "ReadFrom", "(", "r", ")", "\n", "f", ".", "buffer", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n", "}" ]
// outbuf adds a buffered line to the document
[ "outbuf", "adds", "a", "buffered", "line", "to", "the", "document" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3154-L3162
train
jung-kurt/gofpdf
fpdf.go
outf
func (f *Fpdf) outf(fmtStr string, args ...interface{}) { f.out(sprintf(fmtStr, args...)) }
go
func (f *Fpdf) outf(fmtStr string, args ...interface{}) { f.out(sprintf(fmtStr, args...)) }
[ "func", "(", "f", "*", "Fpdf", ")", "outf", "(", "fmtStr", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "f", ".", "out", "(", "sprintf", "(", "fmtStr", ",", "args", "...", ")", ")", "\n", "}" ]
// outf adds a formatted line to the document
[ "outf", "adds", "a", "formatted", "line", "to", "the", "document" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3181-L3183
train
jung-kurt/gofpdf
util.go
fileExist
func fileExist(filename string) (ok bool) { info, err := os.Stat(filename) if err == nil { if ^os.ModePerm&info.Mode() == 0 { ok = true } } return ok }
go
func fileExist(filename string) (ok bool) { info, err := os.Stat(filename) if err == nil { if ^os.ModePerm&info.Mode() == 0 { ok = true } } return ok }
[ "func", "fileExist", "(", "filename", "string", ")", "(", "ok", "bool", ")", "{", "info", ",", "err", ":=", "os", ".", "Stat", "(", "filename", ")", "\n", "if", "err", "==", "nil", "{", "if", "^", "os", ".", "ModePerm", "&", "info", ".", "Mode", "(", ")", "==", "0", "{", "ok", "=", "true", "\n", "}", "\n", "}", "\n", "return", "ok", "\n", "}" ]
// fileExist returns true if the specified normal file exists
[ "fileExist", "returns", "true", "if", "the", "specified", "normal", "file", "exists" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L43-L51
train
jung-kurt/gofpdf
util.go
fileSize
func fileSize(filename string) (size int64, ok bool) { info, err := os.Stat(filename) ok = err == nil if ok { size = info.Size() } return }
go
func fileSize(filename string) (size int64, ok bool) { info, err := os.Stat(filename) ok = err == nil if ok { size = info.Size() } return }
[ "func", "fileSize", "(", "filename", "string", ")", "(", "size", "int64", ",", "ok", "bool", ")", "{", "info", ",", "err", ":=", "os", ".", "Stat", "(", "filename", ")", "\n", "ok", "=", "err", "==", "nil", "\n", "if", "ok", "{", "size", "=", "info", ".", "Size", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// fileSize returns the size of the specified file; ok will be false // if the file does not exist or is not an ordinary file
[ "fileSize", "returns", "the", "size", "of", "the", "specified", "file", ";", "ok", "will", "be", "false", "if", "the", "file", "does", "not", "exist", "or", "is", "not", "an", "ordinary", "file" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L55-L62
train
jung-kurt/gofpdf
util.go
bufferFromReader
func bufferFromReader(r io.Reader) (b *bytes.Buffer, err error) { b = new(bytes.Buffer) _, err = b.ReadFrom(r) return }
go
func bufferFromReader(r io.Reader) (b *bytes.Buffer, err error) { b = new(bytes.Buffer) _, err = b.ReadFrom(r) return }
[ "func", "bufferFromReader", "(", "r", "io", ".", "Reader", ")", "(", "b", "*", "bytes", ".", "Buffer", ",", "err", "error", ")", "{", "b", "=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "_", ",", "err", "=", "b", ".", "ReadFrom", "(", "r", ")", "\n", "return", "\n", "}" ]
// bufferFromReader returns a new buffer populated with the contents of the specified Reader
[ "bufferFromReader", "returns", "a", "new", "buffer", "populated", "with", "the", "contents", "of", "the", "specified", "Reader" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L65-L69
train
jung-kurt/gofpdf
util.go
slicesEqual
func slicesEqual(a, b []float64) bool { if len(a) != len(b) { return false } for i := range a { if a[i] != b[i] { return false } } return true }
go
func slicesEqual(a, b []float64) bool { if len(a) != len(b) { return false } for i := range a { if a[i] != b[i] { return false } } return true }
[ "func", "slicesEqual", "(", "a", ",", "b", "[", "]", "float64", ")", "bool", "{", "if", "len", "(", "a", ")", "!=", "len", "(", "b", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ":=", "range", "a", "{", "if", "a", "[", "i", "]", "!=", "b", "[", "i", "]", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// slicesEqual returns true if the two specified float slices are equal
[ "slicesEqual", "returns", "true", "if", "the", "two", "specified", "float", "slices", "are", "equal" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L72-L82
train
jung-kurt/gofpdf
util.go
sliceCompress
func sliceCompress(data []byte) []byte { var buf bytes.Buffer cmp, _ := zlib.NewWriterLevel(&buf, zlib.BestSpeed) cmp.Write(data) cmp.Close() return buf.Bytes() }
go
func sliceCompress(data []byte) []byte { var buf bytes.Buffer cmp, _ := zlib.NewWriterLevel(&buf, zlib.BestSpeed) cmp.Write(data) cmp.Close() return buf.Bytes() }
[ "func", "sliceCompress", "(", "data", "[", "]", "byte", ")", "[", "]", "byte", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "cmp", ",", "_", ":=", "zlib", ".", "NewWriterLevel", "(", "&", "buf", ",", "zlib", ".", "BestSpeed", ")", "\n", "cmp", ".", "Write", "(", "data", ")", "\n", "cmp", ".", "Close", "(", ")", "\n", "return", "buf", ".", "Bytes", "(", ")", "\n", "}" ]
// sliceCompress returns a zlib-compressed copy of the specified byte array
[ "sliceCompress", "returns", "a", "zlib", "-", "compressed", "copy", "of", "the", "specified", "byte", "array" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L85-L91
train
jung-kurt/gofpdf
util.go
sliceUncompress
func sliceUncompress(data []byte) (outData []byte, err error) { inBuf := bytes.NewReader(data) r, err := zlib.NewReader(inBuf) defer r.Close() if err == nil { var outBuf bytes.Buffer _, err = outBuf.ReadFrom(r) if err == nil { outData = outBuf.Bytes() } } return }
go
func sliceUncompress(data []byte) (outData []byte, err error) { inBuf := bytes.NewReader(data) r, err := zlib.NewReader(inBuf) defer r.Close() if err == nil { var outBuf bytes.Buffer _, err = outBuf.ReadFrom(r) if err == nil { outData = outBuf.Bytes() } } return }
[ "func", "sliceUncompress", "(", "data", "[", "]", "byte", ")", "(", "outData", "[", "]", "byte", ",", "err", "error", ")", "{", "inBuf", ":=", "bytes", ".", "NewReader", "(", "data", ")", "\n", "r", ",", "err", ":=", "zlib", ".", "NewReader", "(", "inBuf", ")", "\n", "defer", "r", ".", "Close", "(", ")", "\n", "if", "err", "==", "nil", "{", "var", "outBuf", "bytes", ".", "Buffer", "\n", "_", ",", "err", "=", "outBuf", ".", "ReadFrom", "(", "r", ")", "\n", "if", "err", "==", "nil", "{", "outData", "=", "outBuf", ".", "Bytes", "(", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// sliceUncompress returns an uncompressed copy of the specified zlib-compressed byte array
[ "sliceUncompress", "returns", "an", "uncompressed", "copy", "of", "the", "specified", "zlib", "-", "compressed", "byte", "array" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L94-L106
train
jung-kurt/gofpdf
util.go
intIf
func intIf(cnd bool, a, b int) int { if cnd { return a } return b }
go
func intIf(cnd bool, a, b int) int { if cnd { return a } return b }
[ "func", "intIf", "(", "cnd", "bool", ",", "a", ",", "b", "int", ")", "int", "{", "if", "cnd", "{", "return", "a", "\n", "}", "\n", "return", "b", "\n", "}" ]
// intIf returns a if cnd is true, otherwise b
[ "intIf", "returns", "a", "if", "cnd", "is", "true", "otherwise", "b" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L141-L146
train
jung-kurt/gofpdf
util.go
strIf
func strIf(cnd bool, aStr, bStr string) string { if cnd { return aStr } return bStr }
go
func strIf(cnd bool, aStr, bStr string) string { if cnd { return aStr } return bStr }
[ "func", "strIf", "(", "cnd", "bool", ",", "aStr", ",", "bStr", "string", ")", "string", "{", "if", "cnd", "{", "return", "aStr", "\n", "}", "\n", "return", "bStr", "\n", "}" ]
// strIf returns aStr if cnd is true, otherwise bStr
[ "strIf", "returns", "aStr", "if", "cnd", "is", "true", "otherwise", "bStr" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L149-L154
train
jung-kurt/gofpdf
util.go
UnicodeTranslator
func UnicodeTranslator(r io.Reader) (f func(string) string, err error) { m := make(map[rune]byte) var uPos, cPos uint32 var lineStr, nameStr string sc := bufio.NewScanner(r) for sc.Scan() { lineStr = sc.Text() lineStr = strings.TrimSpace(lineStr) if len(lineStr) > 0 { _, err = fmt.Sscanf(lineStr, "!%2X U+%4X %s", &cPos, &uPos, &nameStr) if err == nil { if cPos >= 0x80 { m[rune(uPos)] = byte(cPos) } } } } if err == nil { f = repClosure(m) } else { f = doNothing } return }
go
func UnicodeTranslator(r io.Reader) (f func(string) string, err error) { m := make(map[rune]byte) var uPos, cPos uint32 var lineStr, nameStr string sc := bufio.NewScanner(r) for sc.Scan() { lineStr = sc.Text() lineStr = strings.TrimSpace(lineStr) if len(lineStr) > 0 { _, err = fmt.Sscanf(lineStr, "!%2X U+%4X %s", &cPos, &uPos, &nameStr) if err == nil { if cPos >= 0x80 { m[rune(uPos)] = byte(cPos) } } } } if err == nil { f = repClosure(m) } else { f = doNothing } return }
[ "func", "UnicodeTranslator", "(", "r", "io", ".", "Reader", ")", "(", "f", "func", "(", "string", ")", "string", ",", "err", "error", ")", "{", "m", ":=", "make", "(", "map", "[", "rune", "]", "byte", ")", "\n", "var", "uPos", ",", "cPos", "uint32", "\n", "var", "lineStr", ",", "nameStr", "string", "\n", "sc", ":=", "bufio", ".", "NewScanner", "(", "r", ")", "\n", "for", "sc", ".", "Scan", "(", ")", "{", "lineStr", "=", "sc", ".", "Text", "(", ")", "\n", "lineStr", "=", "strings", ".", "TrimSpace", "(", "lineStr", ")", "\n", "if", "len", "(", "lineStr", ")", ">", "0", "{", "_", ",", "err", "=", "fmt", ".", "Sscanf", "(", "lineStr", ",", "\"", "\"", ",", "&", "cPos", ",", "&", "uPos", ",", "&", "nameStr", ")", "\n", "if", "err", "==", "nil", "{", "if", "cPos", ">=", "0x80", "{", "m", "[", "rune", "(", "uPos", ")", "]", "=", "byte", "(", "cPos", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "err", "==", "nil", "{", "f", "=", "repClosure", "(", "m", ")", "\n", "}", "else", "{", "f", "=", "doNothing", "\n", "}", "\n", "return", "\n", "}" ]
// UnicodeTranslator returns a function that can be used to translate, where // possible, utf-8 strings to a form that is compatible with the specified code // page. The returned function accepts a string and returns a string. // // r is a reader that should read a buffer made up of content lines that // pertain to the code page of interest. Each line is made up of three // whitespace separated fields. The first begins with "!" and is followed by // two hexadecimal digits that identify the glyph position in the code page of // interest. The second field begins with "U+" and is followed by the unicode // code point value. The third is the glyph name. A number of these code page // map files are packaged with the gfpdf library in the font directory. // // An error occurs only if a line is read that does not conform to the expected // format. In this case, the returned function is valid but does not perform // any rune translation.
[ "UnicodeTranslator", "returns", "a", "function", "that", "can", "be", "used", "to", "translate", "where", "possible", "utf", "-", "8", "strings", "to", "a", "form", "that", "is", "compatible", "with", "the", "specified", "code", "page", ".", "The", "returned", "function", "accepts", "a", "string", "and", "returns", "a", "string", ".", "r", "is", "a", "reader", "that", "should", "read", "a", "buffer", "made", "up", "of", "content", "lines", "that", "pertain", "to", "the", "code", "page", "of", "interest", ".", "Each", "line", "is", "made", "up", "of", "three", "whitespace", "separated", "fields", ".", "The", "first", "begins", "with", "!", "and", "is", "followed", "by", "two", "hexadecimal", "digits", "that", "identify", "the", "glyph", "position", "in", "the", "code", "page", "of", "interest", ".", "The", "second", "field", "begins", "with", "U", "+", "and", "is", "followed", "by", "the", "unicode", "code", "point", "value", ".", "The", "third", "is", "the", "glyph", "name", ".", "A", "number", "of", "these", "code", "page", "map", "files", "are", "packaged", "with", "the", "gfpdf", "library", "in", "the", "font", "directory", ".", "An", "error", "occurs", "only", "if", "a", "line", "is", "read", "that", "does", "not", "conform", "to", "the", "expected", "format", ".", "In", "this", "case", "the", "returned", "function", "is", "valid", "but", "does", "not", "perform", "any", "rune", "translation", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L207-L230
train
jung-kurt/gofpdf
util.go
UnicodeTranslatorFromFile
func UnicodeTranslatorFromFile(fileStr string) (f func(string) string, err error) { var fl *os.File fl, err = os.Open(fileStr) if err == nil { f, err = UnicodeTranslator(fl) fl.Close() } else { f = doNothing } return }
go
func UnicodeTranslatorFromFile(fileStr string) (f func(string) string, err error) { var fl *os.File fl, err = os.Open(fileStr) if err == nil { f, err = UnicodeTranslator(fl) fl.Close() } else { f = doNothing } return }
[ "func", "UnicodeTranslatorFromFile", "(", "fileStr", "string", ")", "(", "f", "func", "(", "string", ")", "string", ",", "err", "error", ")", "{", "var", "fl", "*", "os", ".", "File", "\n", "fl", ",", "err", "=", "os", ".", "Open", "(", "fileStr", ")", "\n", "if", "err", "==", "nil", "{", "f", ",", "err", "=", "UnicodeTranslator", "(", "fl", ")", "\n", "fl", ".", "Close", "(", ")", "\n", "}", "else", "{", "f", "=", "doNothing", "\n", "}", "\n", "return", "\n", "}" ]
// UnicodeTranslatorFromFile returns a function that can be used to translate, // where possible, utf-8 strings to a form that is compatible with the // specified code page. See UnicodeTranslator for more details. // // fileStr identifies a font descriptor file that maps glyph positions to names. // // If an error occurs reading the file, the returned function is valid but does // not perform any rune translation.
[ "UnicodeTranslatorFromFile", "returns", "a", "function", "that", "can", "be", "used", "to", "translate", "where", "possible", "utf", "-", "8", "strings", "to", "a", "form", "that", "is", "compatible", "with", "the", "specified", "code", "page", ".", "See", "UnicodeTranslator", "for", "more", "details", ".", "fileStr", "identifies", "a", "font", "descriptor", "file", "that", "maps", "glyph", "positions", "to", "names", ".", "If", "an", "error", "occurs", "reading", "the", "file", "the", "returned", "function", "is", "valid", "but", "does", "not", "perform", "any", "rune", "translation", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L240-L250
train
jung-kurt/gofpdf
util.go
Transform
func (p *PointType) Transform(x, y float64) PointType { return PointType{p.X + x, p.Y + y} }
go
func (p *PointType) Transform(x, y float64) PointType { return PointType{p.X + x, p.Y + y} }
[ "func", "(", "p", "*", "PointType", ")", "Transform", "(", "x", ",", "y", "float64", ")", "PointType", "{", "return", "PointType", "{", "p", ".", "X", "+", "x", ",", "p", ".", "Y", "+", "y", "}", "\n", "}" ]
// Transform moves a point by given X, Y offset
[ "Transform", "moves", "a", "point", "by", "given", "X", "Y", "offset" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L285-L287
train
jung-kurt/gofpdf
util.go
ScaleBy
func (s *SizeType) ScaleBy(factor float64) SizeType { return SizeType{s.Wd * factor, s.Ht * factor} }
go
func (s *SizeType) ScaleBy(factor float64) SizeType { return SizeType{s.Wd * factor, s.Ht * factor} }
[ "func", "(", "s", "*", "SizeType", ")", "ScaleBy", "(", "factor", "float64", ")", "SizeType", "{", "return", "SizeType", "{", "s", ".", "Wd", "*", "factor", ",", "s", ".", "Ht", "*", "factor", "}", "\n", "}" ]
// ScaleBy expands a size by a certain factor
[ "ScaleBy", "expands", "a", "size", "by", "a", "certain", "factor" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L302-L304
train
jung-kurt/gofpdf
util.go
ScaleToWidth
func (s *SizeType) ScaleToWidth(width float64) SizeType { height := s.Ht * width / s.Wd return SizeType{width, height} }
go
func (s *SizeType) ScaleToWidth(width float64) SizeType { height := s.Ht * width / s.Wd return SizeType{width, height} }
[ "func", "(", "s", "*", "SizeType", ")", "ScaleToWidth", "(", "width", "float64", ")", "SizeType", "{", "height", ":=", "s", ".", "Ht", "*", "width", "/", "s", ".", "Wd", "\n", "return", "SizeType", "{", "width", ",", "height", "}", "\n", "}" ]
// ScaleToWidth adjusts the height of a size to match the given width
[ "ScaleToWidth", "adjusts", "the", "height", "of", "a", "size", "to", "match", "the", "given", "width" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L307-L310
train
jung-kurt/gofpdf
util.go
ScaleToHeight
func (s *SizeType) ScaleToHeight(height float64) SizeType { width := s.Wd * height / s.Ht return SizeType{width, height} }
go
func (s *SizeType) ScaleToHeight(height float64) SizeType { width := s.Wd * height / s.Ht return SizeType{width, height} }
[ "func", "(", "s", "*", "SizeType", ")", "ScaleToHeight", "(", "height", "float64", ")", "SizeType", "{", "width", ":=", "s", ".", "Wd", "*", "height", "/", "s", ".", "Ht", "\n", "return", "SizeType", "{", "width", ",", "height", "}", "\n", "}" ]
// ScaleToHeight adjusts the width of a size to match the given height
[ "ScaleToHeight", "adjusts", "the", "width", "of", "a", "size", "to", "match", "the", "given", "height" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L313-L316
train
jung-kurt/gofpdf
template.go
CreateTemplate
func (f *Fpdf) CreateTemplate(fn func(*Tpl)) Template { return newTpl(PointType{0, 0}, f.curPageSize, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
go
func (f *Fpdf) CreateTemplate(fn func(*Tpl)) Template { return newTpl(PointType{0, 0}, f.curPageSize, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
[ "func", "(", "f", "*", "Fpdf", ")", "CreateTemplate", "(", "fn", "func", "(", "*", "Tpl", ")", ")", "Template", "{", "return", "newTpl", "(", "PointType", "{", "0", ",", "0", "}", ",", "f", ".", "curPageSize", ",", "f", ".", "defOrientation", ",", "f", ".", "unitStr", ",", "f", ".", "fontDirStr", ",", "fn", ",", "f", ")", "\n", "}" ]
// CreateTemplate defines a new template using the current page size.
[ "CreateTemplate", "defines", "a", "new", "template", "using", "the", "current", "page", "size", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L26-L28
train
jung-kurt/gofpdf
template.go
CreateTemplateCustom
func (f *Fpdf) CreateTemplateCustom(corner PointType, size SizeType, fn func(*Tpl)) Template { return newTpl(corner, size, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
go
func (f *Fpdf) CreateTemplateCustom(corner PointType, size SizeType, fn func(*Tpl)) Template { return newTpl(corner, size, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
[ "func", "(", "f", "*", "Fpdf", ")", "CreateTemplateCustom", "(", "corner", "PointType", ",", "size", "SizeType", ",", "fn", "func", "(", "*", "Tpl", ")", ")", "Template", "{", "return", "newTpl", "(", "corner", ",", "size", ",", "f", ".", "defOrientation", ",", "f", ".", "unitStr", ",", "f", ".", "fontDirStr", ",", "fn", ",", "f", ")", "\n", "}" ]
// CreateTemplateCustom starts a template, using the given bounds.
[ "CreateTemplateCustom", "starts", "a", "template", "using", "the", "given", "bounds", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L31-L33
train
jung-kurt/gofpdf
template.go
CreateTpl
func CreateTpl(corner PointType, size SizeType, orientationStr, unitStr, fontDirStr string, fn func(*Tpl)) Template { return newTpl(corner, size, orientationStr, unitStr, fontDirStr, fn, nil) }
go
func CreateTpl(corner PointType, size SizeType, orientationStr, unitStr, fontDirStr string, fn func(*Tpl)) Template { return newTpl(corner, size, orientationStr, unitStr, fontDirStr, fn, nil) }
[ "func", "CreateTpl", "(", "corner", "PointType", ",", "size", "SizeType", ",", "orientationStr", ",", "unitStr", ",", "fontDirStr", "string", ",", "fn", "func", "(", "*", "Tpl", ")", ")", "Template", "{", "return", "newTpl", "(", "corner", ",", "size", ",", "orientationStr", ",", "unitStr", ",", "fontDirStr", ",", "fn", ",", "nil", ")", "\n", "}" ]
// CreateTpl creates a template not attached to any document
[ "CreateTpl", "creates", "a", "template", "not", "attached", "to", "any", "document" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L52-L54
train
jung-kurt/gofpdf
template.go
UseTemplate
func (f *Fpdf) UseTemplate(t Template) { if t == nil { f.SetErrorf("template is nil") return } corner, size := t.Size() f.UseTemplateScaled(t, corner, size) }
go
func (f *Fpdf) UseTemplate(t Template) { if t == nil { f.SetErrorf("template is nil") return } corner, size := t.Size() f.UseTemplateScaled(t, corner, size) }
[ "func", "(", "f", "*", "Fpdf", ")", "UseTemplate", "(", "t", "Template", ")", "{", "if", "t", "==", "nil", "{", "f", ".", "SetErrorf", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "corner", ",", "size", ":=", "t", ".", "Size", "(", ")", "\n", "f", ".", "UseTemplateScaled", "(", "t", ",", "corner", ",", "size", ")", "\n", "}" ]
// UseTemplate adds a template to the current page or another template, // using the size and position at which it was originally written.
[ "UseTemplate", "adds", "a", "template", "to", "the", "current", "page", "or", "another", "template", "using", "the", "size", "and", "position", "at", "which", "it", "was", "originally", "written", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L58-L65
train
jung-kurt/gofpdf
template.go
UseTemplateScaled
func (f *Fpdf) UseTemplateScaled(t Template, corner PointType, size SizeType) { if t == nil { f.SetErrorf("template is nil") return } // You have to add at least a page first if f.page <= 0 { f.SetErrorf("cannot use a template without first adding a page") return } // make a note of the fact that we actually use this template, as well as any other templates, // images or fonts it uses f.templates[t.ID()] = t for _, tt := range t.Templates() { f.templates[tt.ID()] = tt } for name, ti := range t.Images() { name = sprintf("t%s-%s", t.ID(), name) f.images[name] = ti } // template data _, templateSize := t.Size() scaleX := size.Wd / templateSize.Wd scaleY := size.Ht / templateSize.Ht tx := corner.X * f.k ty := (f.curPageSize.Ht - corner.Y - size.Ht) * f.k f.outf("q %.4f 0 0 %.4f %.4f %.4f cm", scaleX, scaleY, tx, ty) // Translate f.outf("/TPL%s Do Q", t.ID()) }
go
func (f *Fpdf) UseTemplateScaled(t Template, corner PointType, size SizeType) { if t == nil { f.SetErrorf("template is nil") return } // You have to add at least a page first if f.page <= 0 { f.SetErrorf("cannot use a template without first adding a page") return } // make a note of the fact that we actually use this template, as well as any other templates, // images or fonts it uses f.templates[t.ID()] = t for _, tt := range t.Templates() { f.templates[tt.ID()] = tt } for name, ti := range t.Images() { name = sprintf("t%s-%s", t.ID(), name) f.images[name] = ti } // template data _, templateSize := t.Size() scaleX := size.Wd / templateSize.Wd scaleY := size.Ht / templateSize.Ht tx := corner.X * f.k ty := (f.curPageSize.Ht - corner.Y - size.Ht) * f.k f.outf("q %.4f 0 0 %.4f %.4f %.4f cm", scaleX, scaleY, tx, ty) // Translate f.outf("/TPL%s Do Q", t.ID()) }
[ "func", "(", "f", "*", "Fpdf", ")", "UseTemplateScaled", "(", "t", "Template", ",", "corner", "PointType", ",", "size", "SizeType", ")", "{", "if", "t", "==", "nil", "{", "f", ".", "SetErrorf", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "// You have to add at least a page first", "if", "f", ".", "page", "<=", "0", "{", "f", ".", "SetErrorf", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "// make a note of the fact that we actually use this template, as well as any other templates,", "// images or fonts it uses", "f", ".", "templates", "[", "t", ".", "ID", "(", ")", "]", "=", "t", "\n", "for", "_", ",", "tt", ":=", "range", "t", ".", "Templates", "(", ")", "{", "f", ".", "templates", "[", "tt", ".", "ID", "(", ")", "]", "=", "tt", "\n", "}", "\n", "for", "name", ",", "ti", ":=", "range", "t", ".", "Images", "(", ")", "{", "name", "=", "sprintf", "(", "\"", "\"", ",", "t", ".", "ID", "(", ")", ",", "name", ")", "\n", "f", ".", "images", "[", "name", "]", "=", "ti", "\n", "}", "\n\n", "// template data", "_", ",", "templateSize", ":=", "t", ".", "Size", "(", ")", "\n", "scaleX", ":=", "size", ".", "Wd", "/", "templateSize", ".", "Wd", "\n", "scaleY", ":=", "size", ".", "Ht", "/", "templateSize", ".", "Ht", "\n", "tx", ":=", "corner", ".", "X", "*", "f", ".", "k", "\n", "ty", ":=", "(", "f", ".", "curPageSize", ".", "Ht", "-", "corner", ".", "Y", "-", "size", ".", "Ht", ")", "*", "f", ".", "k", "\n\n", "f", ".", "outf", "(", "\"", "\"", ",", "scaleX", ",", "scaleY", ",", "tx", ",", "ty", ")", "// Translate", "\n", "f", ".", "outf", "(", "\"", "\"", ",", "t", ".", "ID", "(", ")", ")", "\n", "}" ]
// UseTemplateScaled adds a template to the current page or another template, // using the given page coordinates.
[ "UseTemplateScaled", "adds", "a", "template", "to", "the", "current", "page", "or", "another", "template", "using", "the", "given", "page", "coordinates", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L69-L101
train
jung-kurt/gofpdf
template.go
putTemplates
func (f *Fpdf) putTemplates() { filter := "" if f.compress { filter = "/Filter /FlateDecode " } templates := sortTemplates(f.templates, f.catalogSort) var t Template for _, t = range templates { corner, size := t.Size() f.newobj() f.templateObjects[t.ID()] = f.n f.outf("<<%s/Type /XObject", filter) f.out("/Subtype /Form") f.out("/Formtype 1") f.outf("/BBox [%.2f %.2f %.2f %.2f]", corner.X*f.k, corner.Y*f.k, (corner.X+size.Wd)*f.k, (corner.Y+size.Ht)*f.k) if corner.X != 0 || corner.Y != 0 { f.outf("/Matrix [1 0 0 1 %.5f %.5f]", -corner.X*f.k*2, corner.Y*f.k*2) } // Template's resource dictionary f.out("/Resources ") f.out("<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]") f.templateFontCatalog() tImages := t.Images() tTemplates := t.Templates() if len(tImages) > 0 || len(tTemplates) > 0 { f.out("/XObject <<") { var key string var keyList []string var ti *ImageInfoType for key = range tImages { keyList = append(keyList, key) } if gl.catalogSort { sort.Strings(keyList) } for _, key = range keyList { // for _, ti := range tImages { ti = tImages[key] f.outf("/I%s %d 0 R", ti.i, ti.n) } } for _, tt := range tTemplates { id := tt.ID() if objID, ok := f.templateObjects[id]; ok { f.outf("/TPL%s %d 0 R", id, objID) } } f.out(">>") } f.out(">>") // Write the template's byte stream buffer := t.Bytes() // fmt.Println("Put template bytes", string(buffer[:])) if f.compress { buffer = sliceCompress(buffer) } f.outf("/Length %d >>", len(buffer)) f.putstream(buffer) f.out("endobj") } }
go
func (f *Fpdf) putTemplates() { filter := "" if f.compress { filter = "/Filter /FlateDecode " } templates := sortTemplates(f.templates, f.catalogSort) var t Template for _, t = range templates { corner, size := t.Size() f.newobj() f.templateObjects[t.ID()] = f.n f.outf("<<%s/Type /XObject", filter) f.out("/Subtype /Form") f.out("/Formtype 1") f.outf("/BBox [%.2f %.2f %.2f %.2f]", corner.X*f.k, corner.Y*f.k, (corner.X+size.Wd)*f.k, (corner.Y+size.Ht)*f.k) if corner.X != 0 || corner.Y != 0 { f.outf("/Matrix [1 0 0 1 %.5f %.5f]", -corner.X*f.k*2, corner.Y*f.k*2) } // Template's resource dictionary f.out("/Resources ") f.out("<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]") f.templateFontCatalog() tImages := t.Images() tTemplates := t.Templates() if len(tImages) > 0 || len(tTemplates) > 0 { f.out("/XObject <<") { var key string var keyList []string var ti *ImageInfoType for key = range tImages { keyList = append(keyList, key) } if gl.catalogSort { sort.Strings(keyList) } for _, key = range keyList { // for _, ti := range tImages { ti = tImages[key] f.outf("/I%s %d 0 R", ti.i, ti.n) } } for _, tt := range tTemplates { id := tt.ID() if objID, ok := f.templateObjects[id]; ok { f.outf("/TPL%s %d 0 R", id, objID) } } f.out(">>") } f.out(">>") // Write the template's byte stream buffer := t.Bytes() // fmt.Println("Put template bytes", string(buffer[:])) if f.compress { buffer = sliceCompress(buffer) } f.outf("/Length %d >>", len(buffer)) f.putstream(buffer) f.out("endobj") } }
[ "func", "(", "f", "*", "Fpdf", ")", "putTemplates", "(", ")", "{", "filter", ":=", "\"", "\"", "\n", "if", "f", ".", "compress", "{", "filter", "=", "\"", "\"", "\n", "}", "\n\n", "templates", ":=", "sortTemplates", "(", "f", ".", "templates", ",", "f", ".", "catalogSort", ")", "\n", "var", "t", "Template", "\n", "for", "_", ",", "t", "=", "range", "templates", "{", "corner", ",", "size", ":=", "t", ".", "Size", "(", ")", "\n\n", "f", ".", "newobj", "(", ")", "\n", "f", ".", "templateObjects", "[", "t", ".", "ID", "(", ")", "]", "=", "f", ".", "n", "\n", "f", ".", "outf", "(", "\"", "\"", ",", "filter", ")", "\n", "f", ".", "out", "(", "\"", "\"", ")", "\n", "f", ".", "out", "(", "\"", "\"", ")", "\n", "f", ".", "outf", "(", "\"", "\"", ",", "corner", ".", "X", "*", "f", ".", "k", ",", "corner", ".", "Y", "*", "f", ".", "k", ",", "(", "corner", ".", "X", "+", "size", ".", "Wd", ")", "*", "f", ".", "k", ",", "(", "corner", ".", "Y", "+", "size", ".", "Ht", ")", "*", "f", ".", "k", ")", "\n", "if", "corner", ".", "X", "!=", "0", "||", "corner", ".", "Y", "!=", "0", "{", "f", ".", "outf", "(", "\"", "\"", ",", "-", "corner", ".", "X", "*", "f", ".", "k", "*", "2", ",", "corner", ".", "Y", "*", "f", ".", "k", "*", "2", ")", "\n", "}", "\n\n", "// Template's resource dictionary", "f", ".", "out", "(", "\"", "\"", ")", "\n", "f", ".", "out", "(", "\"", "\"", ")", "\n\n", "f", ".", "templateFontCatalog", "(", ")", "\n\n", "tImages", ":=", "t", ".", "Images", "(", ")", "\n", "tTemplates", ":=", "t", ".", "Templates", "(", ")", "\n", "if", "len", "(", "tImages", ")", ">", "0", "||", "len", "(", "tTemplates", ")", ">", "0", "{", "f", ".", "out", "(", "\"", "\"", ")", "\n", "{", "var", "key", "string", "\n", "var", "keyList", "[", "]", "string", "\n", "var", "ti", "*", "ImageInfoType", "\n", "for", "key", "=", "range", "tImages", "{", "keyList", "=", "append", "(", "keyList", ",", "key", ")", "\n", "}", "\n", "if", "gl", ".", "catalogSort", "{", "sort", ".", "Strings", "(", "keyList", ")", "\n", "}", "\n", "for", "_", ",", "key", "=", "range", "keyList", "{", "// for _, ti := range tImages {", "ti", "=", "tImages", "[", "key", "]", "\n", "f", ".", "outf", "(", "\"", "\"", ",", "ti", ".", "i", ",", "ti", ".", "n", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "tt", ":=", "range", "tTemplates", "{", "id", ":=", "tt", ".", "ID", "(", ")", "\n", "if", "objID", ",", "ok", ":=", "f", ".", "templateObjects", "[", "id", "]", ";", "ok", "{", "f", ".", "outf", "(", "\"", "\"", ",", "id", ",", "objID", ")", "\n", "}", "\n", "}", "\n", "f", ".", "out", "(", "\"", "\"", ")", "\n", "}", "\n\n", "f", ".", "out", "(", "\"", "\"", ")", "\n\n", "// Write the template's byte stream", "buffer", ":=", "t", ".", "Bytes", "(", ")", "\n", "// fmt.Println(\"Put template bytes\", string(buffer[:]))", "if", "f", ".", "compress", "{", "buffer", "=", "sliceCompress", "(", "buffer", ")", "\n", "}", "\n", "f", ".", "outf", "(", "\"", "\"", ",", "len", "(", "buffer", ")", ")", "\n", "f", ".", "putstream", "(", "buffer", ")", "\n", "f", ".", "out", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// putTemplates writes the templates to the PDF
[ "putTemplates", "writes", "the", "templates", "to", "the", "PDF" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L137-L205
train
jung-kurt/gofpdf
template.go
sortTemplates
func sortTemplates(templates map[string]Template, catalogSort bool) []Template { chain := make([]Template, 0, len(templates)*2) // build a full set of dependency chains var keyList []string var key string var t Template keyList = templateKeyList(templates, catalogSort) for _, key = range keyList { t = templates[key] tlist := templateChainDependencies(t) for _, tt := range tlist { if tt != nil { chain = append(chain, tt) } } } // reduce that to make a simple list sorted := make([]Template, 0, len(templates)) chain: for _, t := range chain { for _, already := range sorted { if t == already { continue chain } } sorted = append(sorted, t) } return sorted }
go
func sortTemplates(templates map[string]Template, catalogSort bool) []Template { chain := make([]Template, 0, len(templates)*2) // build a full set of dependency chains var keyList []string var key string var t Template keyList = templateKeyList(templates, catalogSort) for _, key = range keyList { t = templates[key] tlist := templateChainDependencies(t) for _, tt := range tlist { if tt != nil { chain = append(chain, tt) } } } // reduce that to make a simple list sorted := make([]Template, 0, len(templates)) chain: for _, t := range chain { for _, already := range sorted { if t == already { continue chain } } sorted = append(sorted, t) } return sorted }
[ "func", "sortTemplates", "(", "templates", "map", "[", "string", "]", "Template", ",", "catalogSort", "bool", ")", "[", "]", "Template", "{", "chain", ":=", "make", "(", "[", "]", "Template", ",", "0", ",", "len", "(", "templates", ")", "*", "2", ")", "\n\n", "// build a full set of dependency chains", "var", "keyList", "[", "]", "string", "\n", "var", "key", "string", "\n", "var", "t", "Template", "\n", "keyList", "=", "templateKeyList", "(", "templates", ",", "catalogSort", ")", "\n", "for", "_", ",", "key", "=", "range", "keyList", "{", "t", "=", "templates", "[", "key", "]", "\n", "tlist", ":=", "templateChainDependencies", "(", "t", ")", "\n", "for", "_", ",", "tt", ":=", "range", "tlist", "{", "if", "tt", "!=", "nil", "{", "chain", "=", "append", "(", "chain", ",", "tt", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// reduce that to make a simple list", "sorted", ":=", "make", "(", "[", "]", "Template", ",", "0", ",", "len", "(", "templates", ")", ")", "\n", "chain", ":", "for", "_", ",", "t", ":=", "range", "chain", "{", "for", "_", ",", "already", ":=", "range", "sorted", "{", "if", "t", "==", "already", "{", "continue", "chain", "\n", "}", "\n", "}", "\n", "sorted", "=", "append", "(", "sorted", ",", "t", ")", "\n", "}", "\n\n", "return", "sorted", "\n", "}" ]
// sortTemplates puts templates in a suitable order based on dependices
[ "sortTemplates", "puts", "templates", "in", "a", "suitable", "order", "based", "on", "dependices" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L225-L256
train
jung-kurt/gofpdf
template.go
templateChainDependencies
func templateChainDependencies(template Template) []Template { requires := template.Templates() chain := make([]Template, len(requires)*2) for _, req := range requires { chain = append(chain, templateChainDependencies(req)...) } chain = append(chain, template) return chain }
go
func templateChainDependencies(template Template) []Template { requires := template.Templates() chain := make([]Template, len(requires)*2) for _, req := range requires { chain = append(chain, templateChainDependencies(req)...) } chain = append(chain, template) return chain }
[ "func", "templateChainDependencies", "(", "template", "Template", ")", "[", "]", "Template", "{", "requires", ":=", "template", ".", "Templates", "(", ")", "\n", "chain", ":=", "make", "(", "[", "]", "Template", ",", "len", "(", "requires", ")", "*", "2", ")", "\n", "for", "_", ",", "req", ":=", "range", "requires", "{", "chain", "=", "append", "(", "chain", ",", "templateChainDependencies", "(", "req", ")", "...", ")", "\n", "}", "\n", "chain", "=", "append", "(", "chain", ",", "template", ")", "\n", "return", "chain", "\n", "}" ]
// templateChainDependencies is a recursive function for determining the full chain of template dependencies
[ "templateChainDependencies", "is", "a", "recursive", "function", "for", "determining", "the", "full", "chain", "of", "template", "dependencies" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L259-L267
train
jung-kurt/gofpdf
spotcolor.go
AddSpotColor
func (f *Fpdf) AddSpotColor(nameStr string, c, m, y, k byte) { if f.err == nil { _, ok := f.spotColorMap[nameStr] if !ok { id := len(f.spotColorMap) + 1 f.spotColorMap[nameStr] = spotColorType{ id: id, val: cmykColorType{ c: byteBound(c), m: byteBound(m), y: byteBound(y), k: byteBound(k), }, } } else { f.err = fmt.Errorf("name \"%s\" is already associated with a spot color", nameStr) } } }
go
func (f *Fpdf) AddSpotColor(nameStr string, c, m, y, k byte) { if f.err == nil { _, ok := f.spotColorMap[nameStr] if !ok { id := len(f.spotColorMap) + 1 f.spotColorMap[nameStr] = spotColorType{ id: id, val: cmykColorType{ c: byteBound(c), m: byteBound(m), y: byteBound(y), k: byteBound(k), }, } } else { f.err = fmt.Errorf("name \"%s\" is already associated with a spot color", nameStr) } } }
[ "func", "(", "f", "*", "Fpdf", ")", "AddSpotColor", "(", "nameStr", "string", ",", "c", ",", "m", ",", "y", ",", "k", "byte", ")", "{", "if", "f", ".", "err", "==", "nil", "{", "_", ",", "ok", ":=", "f", ".", "spotColorMap", "[", "nameStr", "]", "\n", "if", "!", "ok", "{", "id", ":=", "len", "(", "f", ".", "spotColorMap", ")", "+", "1", "\n", "f", ".", "spotColorMap", "[", "nameStr", "]", "=", "spotColorType", "{", "id", ":", "id", ",", "val", ":", "cmykColorType", "{", "c", ":", "byteBound", "(", "c", ")", ",", "m", ":", "byteBound", "(", "m", ")", ",", "y", ":", "byteBound", "(", "y", ")", ",", "k", ":", "byteBound", "(", "k", ")", ",", "}", ",", "}", "\n", "}", "else", "{", "f", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\\\"", "\\\"", "\"", ",", "nameStr", ")", "\n", "}", "\n", "}", "\n", "}" ]
// AddSpotColor adds an ink-based CMYK color to the gofpdf instance and // associates it with the specified name. The individual components specify // percentages ranging from 0 to 100. Values above this are quietly capped to // 100. An error occurs if the specified name is already associated with a // color.
[ "AddSpotColor", "adds", "an", "ink", "-", "based", "CMYK", "color", "to", "the", "gofpdf", "instance", "and", "associates", "it", "with", "the", "specified", "name", ".", "The", "individual", "components", "specify", "percentages", "ranging", "from", "0", "to", "100", ".", "Values", "above", "this", "are", "quietly", "capped", "to", "100", ".", "An", "error", "occurs", "if", "the", "specified", "name", "is", "already", "associated", "with", "a", "color", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L36-L54
train
jung-kurt/gofpdf
spotcolor.go
GetDrawSpotColor
func (f *Fpdf) GetDrawSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.draw) }
go
func (f *Fpdf) GetDrawSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.draw) }
[ "func", "(", "f", "*", "Fpdf", ")", "GetDrawSpotColor", "(", ")", "(", "name", "string", ",", "c", ",", "m", ",", "y", ",", "k", "byte", ")", "{", "return", "f", ".", "returnSpotColor", "(", "f", ".", "color", ".", "draw", ")", "\n", "}" ]
// GetDrawSpotColor returns the most recently used spot color information for // drawing. This will not be the current drawing color if some other color type // such as RGB is active. If no spot color has been set for drawing, zero // values are returned.
[ "GetDrawSpotColor", "returns", "the", "most", "recently", "used", "spot", "color", "information", "for", "drawing", ".", "This", "will", "not", "be", "the", "current", "drawing", "color", "if", "some", "other", "color", "type", "such", "as", "RGB", "is", "active", ".", "If", "no", "spot", "color", "has", "been", "set", "for", "drawing", "zero", "values", "are", "returned", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L143-L145
train
jung-kurt/gofpdf
spotcolor.go
GetTextSpotColor
func (f *Fpdf) GetTextSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.text) }
go
func (f *Fpdf) GetTextSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.text) }
[ "func", "(", "f", "*", "Fpdf", ")", "GetTextSpotColor", "(", ")", "(", "name", "string", ",", "c", ",", "m", ",", "y", ",", "k", "byte", ")", "{", "return", "f", ".", "returnSpotColor", "(", "f", ".", "color", ".", "text", ")", "\n", "}" ]
// GetTextSpotColor returns the most recently used spot color information for // text output. This will not be the current text color if some other color // type such as RGB is active. If no spot color has been set for text, zero // values are returned.
[ "GetTextSpotColor", "returns", "the", "most", "recently", "used", "spot", "color", "information", "for", "text", "output", ".", "This", "will", "not", "be", "the", "current", "text", "color", "if", "some", "other", "color", "type", "such", "as", "RGB", "is", "active", ".", "If", "no", "spot", "color", "has", "been", "set", "for", "text", "zero", "values", "are", "returned", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L151-L153
train
jung-kurt/gofpdf
spotcolor.go
GetFillSpotColor
func (f *Fpdf) GetFillSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.fill) }
go
func (f *Fpdf) GetFillSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.fill) }
[ "func", "(", "f", "*", "Fpdf", ")", "GetFillSpotColor", "(", ")", "(", "name", "string", ",", "c", ",", "m", ",", "y", ",", "k", "byte", ")", "{", "return", "f", ".", "returnSpotColor", "(", "f", ".", "color", ".", "fill", ")", "\n", "}" ]
// GetFillSpotColor returns the most recently used spot color information for // fill output. This will not be the current fill color if some other color // type such as RGB is active. If no fill spot color has been set, zero values // are returned.
[ "GetFillSpotColor", "returns", "the", "most", "recently", "used", "spot", "color", "information", "for", "fill", "output", ".", "This", "will", "not", "be", "the", "current", "fill", "color", "if", "some", "other", "color", "type", "such", "as", "RGB", "is", "active", ".", "If", "no", "fill", "spot", "color", "has", "been", "set", "zero", "values", "are", "returned", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L159-L161
train
jung-kurt/gofpdf
layer.go
BeginLayer
func (f *Fpdf) BeginLayer(id int) { f.EndLayer() if id >= 0 && id < len(f.layer.list) { f.outf("/OC /OC%d BDC", id) f.layer.currentLayer = id } }
go
func (f *Fpdf) BeginLayer(id int) { f.EndLayer() if id >= 0 && id < len(f.layer.list) { f.outf("/OC /OC%d BDC", id) f.layer.currentLayer = id } }
[ "func", "(", "f", "*", "Fpdf", ")", "BeginLayer", "(", "id", "int", ")", "{", "f", ".", "EndLayer", "(", ")", "\n", "if", "id", ">=", "0", "&&", "id", "<", "len", "(", "f", ".", "layer", ".", "list", ")", "{", "f", ".", "outf", "(", "\"", "\"", ",", "id", ")", "\n", "f", ".", "layer", ".", "currentLayer", "=", "id", "\n", "}", "\n", "}" ]
// BeginLayer is called to begin adding content to the specified layer. All // content added to the page between a call to BeginLayer and a call to // EndLayer is added to the layer specified by id. See AddLayer for more // details.
[ "BeginLayer", "is", "called", "to", "begin", "adding", "content", "to", "the", "specified", "layer", ".", "All", "content", "added", "to", "the", "page", "between", "a", "call", "to", "BeginLayer", "and", "a", "call", "to", "EndLayer", "is", "added", "to", "the", "layer", "specified", "by", "id", ".", "See", "AddLayer", "for", "more", "details", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/layer.go#L55-L61
train
jung-kurt/gofpdf
layer.go
EndLayer
func (f *Fpdf) EndLayer() { if f.layer.currentLayer >= 0 { f.out("EMC") f.layer.currentLayer = -1 } }
go
func (f *Fpdf) EndLayer() { if f.layer.currentLayer >= 0 { f.out("EMC") f.layer.currentLayer = -1 } }
[ "func", "(", "f", "*", "Fpdf", ")", "EndLayer", "(", ")", "{", "if", "f", ".", "layer", ".", "currentLayer", ">=", "0", "{", "f", ".", "out", "(", "\"", "\"", ")", "\n", "f", ".", "layer", ".", "currentLayer", "=", "-", "1", "\n", "}", "\n", "}" ]
// EndLayer is called to stop adding content to the currently active layer. See // BeginLayer for more details.
[ "EndLayer", "is", "called", "to", "stop", "adding", "content", "to", "the", "currently", "active", "layer", ".", "See", "BeginLayer", "for", "more", "details", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/layer.go#L65-L70
train
jung-kurt/gofpdf
contrib/barcode/barcode.go
GetUnscaledBarcodeDimensions
func GetUnscaledBarcodeDimensions(pdf barcodePdf, code string) (w, h float64) { barcodes.Lock() unscaled, ok := barcodes.cache[code] barcodes.Unlock() if !ok { err := errors.New("Barcode not found") pdf.SetError(err) return } return convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dx())), convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dy())) }
go
func GetUnscaledBarcodeDimensions(pdf barcodePdf, code string) (w, h float64) { barcodes.Lock() unscaled, ok := barcodes.cache[code] barcodes.Unlock() if !ok { err := errors.New("Barcode not found") pdf.SetError(err) return } return convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dx())), convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dy())) }
[ "func", "GetUnscaledBarcodeDimensions", "(", "pdf", "barcodePdf", ",", "code", "string", ")", "(", "w", ",", "h", "float64", ")", "{", "barcodes", ".", "Lock", "(", ")", "\n", "unscaled", ",", "ok", ":=", "barcodes", ".", "cache", "[", "code", "]", "\n", "barcodes", ".", "Unlock", "(", ")", "\n\n", "if", "!", "ok", "{", "err", ":=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "pdf", ".", "SetError", "(", "err", ")", "\n", "return", "\n", "}", "\n\n", "return", "convertFrom96Dpi", "(", "pdf", ",", "float64", "(", "unscaled", ".", "Bounds", "(", ")", ".", "Dx", "(", ")", ")", ")", ",", "convertFrom96Dpi", "(", "pdf", ",", "float64", "(", "unscaled", ".", "Bounds", "(", ")", ".", "Dy", "(", ")", ")", ")", "\n", "}" ]
// GetUnscaledBarcodeDimensions returns the width and height of the // unscaled barcode associated with the given code.
[ "GetUnscaledBarcodeDimensions", "returns", "the", "width", "and", "height", "of", "the", "unscaled", "barcode", "associated", "with", "the", "given", "code", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L127-L140
train
jung-kurt/gofpdf
contrib/barcode/barcode.go
uniqueBarcodeName
func uniqueBarcodeName(code string, x, y float64) string { xStr := strconv.FormatFloat(x, 'E', -1, 64) yStr := strconv.FormatFloat(y, 'E', -1, 64) return "barcode-" + code + "-" + xStr + yStr }
go
func uniqueBarcodeName(code string, x, y float64) string { xStr := strconv.FormatFloat(x, 'E', -1, 64) yStr := strconv.FormatFloat(y, 'E', -1, 64) return "barcode-" + code + "-" + xStr + yStr }
[ "func", "uniqueBarcodeName", "(", "code", "string", ",", "x", ",", "y", "float64", ")", "string", "{", "xStr", ":=", "strconv", ".", "FormatFloat", "(", "x", ",", "'E'", ",", "-", "1", ",", "64", ")", "\n", "yStr", ":=", "strconv", ".", "FormatFloat", "(", "y", ",", "'E'", ",", "-", "1", ",", "64", ")", "\n\n", "return", "\"", "\"", "+", "code", "+", "\"", "\"", "+", "xStr", "+", "yStr", "\n", "}" ]
// uniqueBarcodeName makes sure every barcode has a unique name for its // dimensions. Scaling a barcode image results in quality loss, which could be // a problem for barcode readers.
[ "uniqueBarcodeName", "makes", "sure", "every", "barcode", "has", "a", "unique", "name", "for", "its", "dimensions", ".", "Scaling", "a", "barcode", "image", "results", "in", "quality", "loss", "which", "could", "be", "a", "problem", "for", "barcode", "readers", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L252-L257
train
jung-kurt/gofpdf
contrib/barcode/barcode.go
barcodeKey
func barcodeKey(bcode barcode.Barcode) string { return bcode.Metadata().CodeKind + bcode.Content() }
go
func barcodeKey(bcode barcode.Barcode) string { return bcode.Metadata().CodeKind + bcode.Content() }
[ "func", "barcodeKey", "(", "bcode", "barcode", ".", "Barcode", ")", "string", "{", "return", "bcode", ".", "Metadata", "(", ")", ".", "CodeKind", "+", "bcode", ".", "Content", "(", ")", "\n", "}" ]
// barcodeKey combines the code type and code value into a unique identifier for // a barcode type. This is so that we can store several barcodes with the same // code but different type in the barcodes map.
[ "barcodeKey", "combines", "the", "code", "type", "and", "code", "value", "into", "a", "unique", "identifier", "for", "a", "barcode", "type", ".", "This", "is", "so", "that", "we", "can", "store", "several", "barcodes", "with", "the", "same", "code", "but", "different", "type", "in", "the", "barcodes", "map", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L262-L264
train
jung-kurt/gofpdf
grid.go
StateGet
func StateGet(pdf *Fpdf) (st StateType) { st.clrDraw.R, st.clrDraw.G, st.clrDraw.B = pdf.GetDrawColor() st.clrFill.R, st.clrFill.G, st.clrFill.B = pdf.GetFillColor() st.clrText.R, st.clrText.G, st.clrText.B = pdf.GetTextColor() st.lineWd = pdf.GetLineWidth() _, st.fontSize = pdf.GetFontSize() st.alpha, st.blendStr = pdf.GetAlpha() st.cellMargin = pdf.GetCellMargin() return }
go
func StateGet(pdf *Fpdf) (st StateType) { st.clrDraw.R, st.clrDraw.G, st.clrDraw.B = pdf.GetDrawColor() st.clrFill.R, st.clrFill.G, st.clrFill.B = pdf.GetFillColor() st.clrText.R, st.clrText.G, st.clrText.B = pdf.GetTextColor() st.lineWd = pdf.GetLineWidth() _, st.fontSize = pdf.GetFontSize() st.alpha, st.blendStr = pdf.GetAlpha() st.cellMargin = pdf.GetCellMargin() return }
[ "func", "StateGet", "(", "pdf", "*", "Fpdf", ")", "(", "st", "StateType", ")", "{", "st", ".", "clrDraw", ".", "R", ",", "st", ".", "clrDraw", ".", "G", ",", "st", ".", "clrDraw", ".", "B", "=", "pdf", ".", "GetDrawColor", "(", ")", "\n", "st", ".", "clrFill", ".", "R", ",", "st", ".", "clrFill", ".", "G", ",", "st", ".", "clrFill", ".", "B", "=", "pdf", ".", "GetFillColor", "(", ")", "\n", "st", ".", "clrText", ".", "R", ",", "st", ".", "clrText", ".", "G", ",", "st", ".", "clrText", ".", "B", "=", "pdf", ".", "GetTextColor", "(", ")", "\n", "st", ".", "lineWd", "=", "pdf", ".", "GetLineWidth", "(", ")", "\n", "_", ",", "st", ".", "fontSize", "=", "pdf", ".", "GetFontSize", "(", ")", "\n", "st", ".", "alpha", ",", "st", ".", "blendStr", "=", "pdf", ".", "GetAlpha", "(", ")", "\n", "st", ".", "cellMargin", "=", "pdf", ".", "GetCellMargin", "(", ")", "\n", "return", "\n", "}" ]
// StateGet returns a variable that contains common state values.
[ "StateGet", "returns", "a", "variable", "that", "contains", "common", "state", "values", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L35-L44
train
jung-kurt/gofpdf
grid.go
Put
func (st StateType) Put(pdf *Fpdf) { pdf.SetDrawColor(st.clrDraw.R, st.clrDraw.G, st.clrDraw.B) pdf.SetFillColor(st.clrFill.R, st.clrFill.G, st.clrFill.B) pdf.SetTextColor(st.clrText.R, st.clrText.G, st.clrText.B) pdf.SetLineWidth(st.lineWd) pdf.SetFontUnitSize(st.fontSize) pdf.SetAlpha(st.alpha, st.blendStr) pdf.SetCellMargin(st.cellMargin) }
go
func (st StateType) Put(pdf *Fpdf) { pdf.SetDrawColor(st.clrDraw.R, st.clrDraw.G, st.clrDraw.B) pdf.SetFillColor(st.clrFill.R, st.clrFill.G, st.clrFill.B) pdf.SetTextColor(st.clrText.R, st.clrText.G, st.clrText.B) pdf.SetLineWidth(st.lineWd) pdf.SetFontUnitSize(st.fontSize) pdf.SetAlpha(st.alpha, st.blendStr) pdf.SetCellMargin(st.cellMargin) }
[ "func", "(", "st", "StateType", ")", "Put", "(", "pdf", "*", "Fpdf", ")", "{", "pdf", ".", "SetDrawColor", "(", "st", ".", "clrDraw", ".", "R", ",", "st", ".", "clrDraw", ".", "G", ",", "st", ".", "clrDraw", ".", "B", ")", "\n", "pdf", ".", "SetFillColor", "(", "st", ".", "clrFill", ".", "R", ",", "st", ".", "clrFill", ".", "G", ",", "st", ".", "clrFill", ".", "B", ")", "\n", "pdf", ".", "SetTextColor", "(", "st", ".", "clrText", ".", "R", ",", "st", ".", "clrText", ".", "G", ",", "st", ".", "clrText", ".", "B", ")", "\n", "pdf", ".", "SetLineWidth", "(", "st", ".", "lineWd", ")", "\n", "pdf", ".", "SetFontUnitSize", "(", "st", ".", "fontSize", ")", "\n", "pdf", ".", "SetAlpha", "(", "st", ".", "alpha", ",", "st", ".", "blendStr", ")", "\n", "pdf", ".", "SetCellMargin", "(", "st", ".", "cellMargin", ")", "\n", "}" ]
// Put sets the common state values contained in the state structure // specified by st.
[ "Put", "sets", "the", "common", "state", "values", "contained", "in", "the", "state", "structure", "specified", "by", "st", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L48-L56
train
jung-kurt/gofpdf
grid.go
defaultFormatter
func defaultFormatter(val float64, precision int) string { return strconv.FormatFloat(val, 'f', precision, 64) }
go
func defaultFormatter(val float64, precision int) string { return strconv.FormatFloat(val, 'f', precision, 64) }
[ "func", "defaultFormatter", "(", "val", "float64", ",", "precision", "int", ")", "string", "{", "return", "strconv", ".", "FormatFloat", "(", "val", ",", "'f'", ",", "precision", ",", "64", ")", "\n", "}" ]
// defaultFormatter returns the string form of val with precision decimal places.
[ "defaultFormatter", "returns", "the", "string", "form", "of", "val", "with", "precision", "decimal", "places", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L62-L64
train
jung-kurt/gofpdf
grid.go
XY
func (g GridType) XY(dataX, dataY float64) (x, y float64) { return g.xm*dataX + g.xb, g.ym*dataY + g.yb }
go
func (g GridType) XY(dataX, dataY float64) (x, y float64) { return g.xm*dataX + g.xb, g.ym*dataY + g.yb }
[ "func", "(", "g", "GridType", ")", "XY", "(", "dataX", ",", "dataY", "float64", ")", "(", "x", ",", "y", "float64", ")", "{", "return", "g", ".", "xm", "*", "dataX", "+", "g", ".", "xb", ",", "g", ".", "ym", "*", "dataY", "+", "g", ".", "yb", "\n", "}" ]
// XY converts dataX and dataY, specified in logical data units, to the X and Y // position on the current page.
[ "XY", "converts", "dataX", "and", "dataY", "specified", "in", "logical", "data", "units", "to", "the", "X", "and", "Y", "position", "on", "the", "current", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L167-L169
train
jung-kurt/gofpdf
grid.go
Pos
func (g GridType) Pos(xRel, yRel float64) (x, y float64) { x = g.w*xRel + g.x y = g.h*(1-yRel) + g.y return }
go
func (g GridType) Pos(xRel, yRel float64) (x, y float64) { x = g.w*xRel + g.x y = g.h*(1-yRel) + g.y return }
[ "func", "(", "g", "GridType", ")", "Pos", "(", "xRel", ",", "yRel", "float64", ")", "(", "x", ",", "y", "float64", ")", "{", "x", "=", "g", ".", "w", "*", "xRel", "+", "g", ".", "x", "\n", "y", "=", "g", ".", "h", "*", "(", "1", "-", "yRel", ")", "+", "g", ".", "y", "\n", "return", "\n", "}" ]
// Pos returns the point, in page units, indicated by the relative positions // xRel and yRel. These are values between 0 and 1. xRel specifies the relative // position between the grid's left and right edges. yRel specifies the // relative position between the grid's bottom and top edges.
[ "Pos", "returns", "the", "point", "in", "page", "units", "indicated", "by", "the", "relative", "positions", "xRel", "and", "yRel", ".", "These", "are", "values", "between", "0", "and", "1", ".", "xRel", "specifies", "the", "relative", "position", "between", "the", "grid", "s", "left", "and", "right", "edges", ".", "yRel", "specifies", "the", "relative", "position", "between", "the", "grid", "s", "bottom", "and", "top", "edges", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L175-L179
train
jung-kurt/gofpdf
grid.go
X
func (g GridType) X(dataX float64) float64 { return g.xm*dataX + g.xb }
go
func (g GridType) X(dataX float64) float64 { return g.xm*dataX + g.xb }
[ "func", "(", "g", "GridType", ")", "X", "(", "dataX", "float64", ")", "float64", "{", "return", "g", ".", "xm", "*", "dataX", "+", "g", ".", "xb", "\n", "}" ]
// X converts dataX, specified in logical data units, to the X position on the // current page.
[ "X", "converts", "dataX", "specified", "in", "logical", "data", "units", "to", "the", "X", "position", "on", "the", "current", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L183-L185
train
jung-kurt/gofpdf
grid.go
Y
func (g GridType) Y(dataY float64) float64 { return g.ym*dataY + g.yb }
go
func (g GridType) Y(dataY float64) float64 { return g.ym*dataY + g.yb }
[ "func", "(", "g", "GridType", ")", "Y", "(", "dataY", "float64", ")", "float64", "{", "return", "g", ".", "ym", "*", "dataY", "+", "g", ".", "yb", "\n", "}" ]
// Y converts dataY, specified in logical data units, to the Y position on the // current page.
[ "Y", "converts", "dataY", "specified", "in", "logical", "data", "units", "to", "the", "Y", "position", "on", "the", "current", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L201-L203
train
jung-kurt/gofpdf
grid.go
XRange
func (g GridType) XRange() (min, max float64) { min = g.xTicks[0] max = g.xTicks[len(g.xTicks)-1] return }
go
func (g GridType) XRange() (min, max float64) { min = g.xTicks[0] max = g.xTicks[len(g.xTicks)-1] return }
[ "func", "(", "g", "GridType", ")", "XRange", "(", ")", "(", "min", ",", "max", "float64", ")", "{", "min", "=", "g", ".", "xTicks", "[", "0", "]", "\n", "max", "=", "g", ".", "xTicks", "[", "len", "(", "g", ".", "xTicks", ")", "-", "1", "]", "\n", "return", "\n", "}" ]
// XRange returns the minimum and maximum values for the current tickmark // sequence. These correspond to the data values of the graph's left and right // edges.
[ "XRange", "returns", "the", "minimum", "and", "maximum", "values", "for", "the", "current", "tickmark", "sequence", ".", "These", "correspond", "to", "the", "data", "values", "of", "the", "graph", "s", "left", "and", "right", "edges", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L208-L212
train
jung-kurt/gofpdf
grid.go
YRange
func (g GridType) YRange() (min, max float64) { min = g.yTicks[0] max = g.yTicks[len(g.yTicks)-1] return }
go
func (g GridType) YRange() (min, max float64) { min = g.yTicks[0] max = g.yTicks[len(g.yTicks)-1] return }
[ "func", "(", "g", "GridType", ")", "YRange", "(", ")", "(", "min", ",", "max", "float64", ")", "{", "min", "=", "g", ".", "yTicks", "[", "0", "]", "\n", "max", "=", "g", ".", "yTicks", "[", "len", "(", "g", ".", "yTicks", ")", "-", "1", "]", "\n", "return", "\n", "}" ]
// YRange returns the minimum and maximum values for the current tickmark // sequence. These correspond to the data values of the graph's bottom and top // edges.
[ "YRange", "returns", "the", "minimum", "and", "maximum", "values", "for", "the", "current", "tickmark", "sequence", ".", "These", "correspond", "to", "the", "data", "values", "of", "the", "graph", "s", "bottom", "and", "top", "edges", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L217-L221
train
jung-kurt/gofpdf
htmlbasic.go
HTMLBasicTokenize
func HTMLBasicTokenize(htmlStr string) (list []HTMLBasicSegmentType) { // This routine is adapted from http://www.fpdf.org/ list = make([]HTMLBasicSegmentType, 0, 16) htmlStr = strings.Replace(htmlStr, "\n", " ", -1) htmlStr = strings.Replace(htmlStr, "\r", "", -1) tagRe, _ := regexp.Compile(`(?U)<.*>`) attrRe, _ := regexp.Compile(`([^=]+)=["']?([^"']+)`) capList := tagRe.FindAllStringIndex(htmlStr, -1) if capList != nil { var seg HTMLBasicSegmentType var parts []string pos := 0 for _, cap := range capList { if pos < cap[0] { seg.Cat = 'T' seg.Str = htmlStr[pos:cap[0]] seg.Attr = nil list = append(list, seg) } if htmlStr[cap[0]+1] == '/' { seg.Cat = 'C' seg.Str = strings.ToLower(htmlStr[cap[0]+2 : cap[1]-1]) seg.Attr = nil list = append(list, seg) } else { // Extract attributes parts = strings.Split(htmlStr[cap[0]+1:cap[1]-1], " ") if len(parts) > 0 { for j, part := range parts { if j == 0 { seg.Cat = 'O' seg.Str = strings.ToLower(parts[0]) seg.Attr = make(map[string]string) } else { attrList := attrRe.FindAllStringSubmatch(part, -1) if attrList != nil { for _, attr := range attrList { seg.Attr[strings.ToLower(attr[1])] = attr[2] } } } } list = append(list, seg) } } pos = cap[1] } if len(htmlStr) > pos { seg.Cat = 'T' seg.Str = htmlStr[pos:] seg.Attr = nil list = append(list, seg) } } else { list = append(list, HTMLBasicSegmentType{Cat: 'T', Str: htmlStr, Attr: nil}) } return }
go
func HTMLBasicTokenize(htmlStr string) (list []HTMLBasicSegmentType) { // This routine is adapted from http://www.fpdf.org/ list = make([]HTMLBasicSegmentType, 0, 16) htmlStr = strings.Replace(htmlStr, "\n", " ", -1) htmlStr = strings.Replace(htmlStr, "\r", "", -1) tagRe, _ := regexp.Compile(`(?U)<.*>`) attrRe, _ := regexp.Compile(`([^=]+)=["']?([^"']+)`) capList := tagRe.FindAllStringIndex(htmlStr, -1) if capList != nil { var seg HTMLBasicSegmentType var parts []string pos := 0 for _, cap := range capList { if pos < cap[0] { seg.Cat = 'T' seg.Str = htmlStr[pos:cap[0]] seg.Attr = nil list = append(list, seg) } if htmlStr[cap[0]+1] == '/' { seg.Cat = 'C' seg.Str = strings.ToLower(htmlStr[cap[0]+2 : cap[1]-1]) seg.Attr = nil list = append(list, seg) } else { // Extract attributes parts = strings.Split(htmlStr[cap[0]+1:cap[1]-1], " ") if len(parts) > 0 { for j, part := range parts { if j == 0 { seg.Cat = 'O' seg.Str = strings.ToLower(parts[0]) seg.Attr = make(map[string]string) } else { attrList := attrRe.FindAllStringSubmatch(part, -1) if attrList != nil { for _, attr := range attrList { seg.Attr[strings.ToLower(attr[1])] = attr[2] } } } } list = append(list, seg) } } pos = cap[1] } if len(htmlStr) > pos { seg.Cat = 'T' seg.Str = htmlStr[pos:] seg.Attr = nil list = append(list, seg) } } else { list = append(list, HTMLBasicSegmentType{Cat: 'T', Str: htmlStr, Attr: nil}) } return }
[ "func", "HTMLBasicTokenize", "(", "htmlStr", "string", ")", "(", "list", "[", "]", "HTMLBasicSegmentType", ")", "{", "// This routine is adapted from http://www.fpdf.org/", "list", "=", "make", "(", "[", "]", "HTMLBasicSegmentType", ",", "0", ",", "16", ")", "\n", "htmlStr", "=", "strings", ".", "Replace", "(", "htmlStr", ",", "\"", "\\n", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "htmlStr", "=", "strings", ".", "Replace", "(", "htmlStr", ",", "\"", "\\r", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "tagRe", ",", "_", ":=", "regexp", ".", "Compile", "(", "`(?U)<.*>`", ")", "\n", "attrRe", ",", "_", ":=", "regexp", ".", "Compile", "(", "`([^=]+)=[\"']?([^\"']+)`", ")", "\n", "capList", ":=", "tagRe", ".", "FindAllStringIndex", "(", "htmlStr", ",", "-", "1", ")", "\n", "if", "capList", "!=", "nil", "{", "var", "seg", "HTMLBasicSegmentType", "\n", "var", "parts", "[", "]", "string", "\n", "pos", ":=", "0", "\n", "for", "_", ",", "cap", ":=", "range", "capList", "{", "if", "pos", "<", "cap", "[", "0", "]", "{", "seg", ".", "Cat", "=", "'T'", "\n", "seg", ".", "Str", "=", "htmlStr", "[", "pos", ":", "cap", "[", "0", "]", "]", "\n", "seg", ".", "Attr", "=", "nil", "\n", "list", "=", "append", "(", "list", ",", "seg", ")", "\n", "}", "\n", "if", "htmlStr", "[", "cap", "[", "0", "]", "+", "1", "]", "==", "'/'", "{", "seg", ".", "Cat", "=", "'C'", "\n", "seg", ".", "Str", "=", "strings", ".", "ToLower", "(", "htmlStr", "[", "cap", "[", "0", "]", "+", "2", ":", "cap", "[", "1", "]", "-", "1", "]", ")", "\n", "seg", ".", "Attr", "=", "nil", "\n", "list", "=", "append", "(", "list", ",", "seg", ")", "\n", "}", "else", "{", "// Extract attributes", "parts", "=", "strings", ".", "Split", "(", "htmlStr", "[", "cap", "[", "0", "]", "+", "1", ":", "cap", "[", "1", "]", "-", "1", "]", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", ">", "0", "{", "for", "j", ",", "part", ":=", "range", "parts", "{", "if", "j", "==", "0", "{", "seg", ".", "Cat", "=", "'O'", "\n", "seg", ".", "Str", "=", "strings", ".", "ToLower", "(", "parts", "[", "0", "]", ")", "\n", "seg", ".", "Attr", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "}", "else", "{", "attrList", ":=", "attrRe", ".", "FindAllStringSubmatch", "(", "part", ",", "-", "1", ")", "\n", "if", "attrList", "!=", "nil", "{", "for", "_", ",", "attr", ":=", "range", "attrList", "{", "seg", ".", "Attr", "[", "strings", ".", "ToLower", "(", "attr", "[", "1", "]", ")", "]", "=", "attr", "[", "2", "]", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "list", "=", "append", "(", "list", ",", "seg", ")", "\n", "}", "\n", "}", "\n", "pos", "=", "cap", "[", "1", "]", "\n", "}", "\n", "if", "len", "(", "htmlStr", ")", ">", "pos", "{", "seg", ".", "Cat", "=", "'T'", "\n", "seg", ".", "Str", "=", "htmlStr", "[", "pos", ":", "]", "\n", "seg", ".", "Attr", "=", "nil", "\n", "list", "=", "append", "(", "list", ",", "seg", ")", "\n", "}", "\n", "}", "else", "{", "list", "=", "append", "(", "list", ",", "HTMLBasicSegmentType", "{", "Cat", ":", "'T'", ",", "Str", ":", "htmlStr", ",", "Attr", ":", "nil", "}", ")", "\n", "}", "\n", "return", "\n", "}" ]
// HTMLBasicTokenize returns a list of HTML tags and literal elements. This is // done with regular expressions, so the result is only marginally better than // useless.
[ "HTMLBasicTokenize", "returns", "a", "list", "of", "HTML", "tags", "and", "literal", "elements", ".", "This", "is", "done", "with", "regular", "expressions", "so", "the", "result", "is", "only", "marginally", "better", "than", "useless", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/htmlbasic.go#L35-L92
train
jung-kurt/gofpdf
htmlbasic.go
HTMLBasicNew
func (f *Fpdf) HTMLBasicNew() (html HTMLBasicType) { html.pdf = f html.Link.ClrR, html.Link.ClrG, html.Link.ClrB = 0, 0, 128 html.Link.Bold, html.Link.Italic, html.Link.Underscore = false, false, true return }
go
func (f *Fpdf) HTMLBasicNew() (html HTMLBasicType) { html.pdf = f html.Link.ClrR, html.Link.ClrG, html.Link.ClrB = 0, 0, 128 html.Link.Bold, html.Link.Italic, html.Link.Underscore = false, false, true return }
[ "func", "(", "f", "*", "Fpdf", ")", "HTMLBasicNew", "(", ")", "(", "html", "HTMLBasicType", ")", "{", "html", ".", "pdf", "=", "f", "\n", "html", ".", "Link", ".", "ClrR", ",", "html", ".", "Link", ".", "ClrG", ",", "html", ".", "Link", ".", "ClrB", "=", "0", ",", "0", ",", "128", "\n", "html", ".", "Link", ".", "Bold", ",", "html", ".", "Link", ".", "Italic", ",", "html", ".", "Link", ".", "Underscore", "=", "false", ",", "false", ",", "true", "\n", "return", "\n", "}" ]
// HTMLBasicNew returns an instance that facilitates writing basic HTML in the // specified PDF file.
[ "HTMLBasicNew", "returns", "an", "instance", "that", "facilitates", "writing", "basic", "HTML", "in", "the", "specified", "PDF", "file", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/htmlbasic.go#L109-L114
train
jung-kurt/gofpdf
font.go
getInfoFromTrueType
func getInfoFromTrueType(fileStr string, msgWriter io.Writer, embed bool, encList encListType) (info fontInfoType, err error) { var ttf TtfType ttf, err = TtfParse(fileStr) if err != nil { return } if embed { if !ttf.Embeddable { err = fmt.Errorf("font license does not allow embedding") return } info.Data, err = ioutil.ReadFile(fileStr) if err != nil { return } info.OriginalSize = len(info.Data) } k := 1000.0 / float64(ttf.UnitsPerEm) info.FontName = ttf.PostScriptName info.Bold = ttf.Bold info.Desc.ItalicAngle = int(ttf.ItalicAngle) info.IsFixedPitch = ttf.IsFixedPitch info.Desc.Ascent = round(k * float64(ttf.TypoAscender)) info.Desc.Descent = round(k * float64(ttf.TypoDescender)) info.UnderlineThickness = round(k * float64(ttf.UnderlineThickness)) info.UnderlinePosition = round(k * float64(ttf.UnderlinePosition)) info.Desc.FontBBox = fontBoxType{ round(k * float64(ttf.Xmin)), round(k * float64(ttf.Ymin)), round(k * float64(ttf.Xmax)), round(k * float64(ttf.Ymax)), } // printf("FontBBox\n") // dump(info.Desc.FontBBox) info.Desc.CapHeight = round(k * float64(ttf.CapHeight)) info.Desc.MissingWidth = round(k * float64(ttf.Widths[0])) var wd int for j := 0; j < len(info.Widths); j++ { wd = info.Desc.MissingWidth if encList[j].name != ".notdef" { uv := encList[j].uv pos, ok := ttf.Chars[uint16(uv)] if ok { wd = round(k * float64(ttf.Widths[pos])) } else { fmt.Fprintf(msgWriter, "Character %s is missing\n", encList[j].name) } } info.Widths[j] = wd } // printf("getInfoFromTrueType/FontBBox\n") // dump(info.Desc.FontBBox) return }
go
func getInfoFromTrueType(fileStr string, msgWriter io.Writer, embed bool, encList encListType) (info fontInfoType, err error) { var ttf TtfType ttf, err = TtfParse(fileStr) if err != nil { return } if embed { if !ttf.Embeddable { err = fmt.Errorf("font license does not allow embedding") return } info.Data, err = ioutil.ReadFile(fileStr) if err != nil { return } info.OriginalSize = len(info.Data) } k := 1000.0 / float64(ttf.UnitsPerEm) info.FontName = ttf.PostScriptName info.Bold = ttf.Bold info.Desc.ItalicAngle = int(ttf.ItalicAngle) info.IsFixedPitch = ttf.IsFixedPitch info.Desc.Ascent = round(k * float64(ttf.TypoAscender)) info.Desc.Descent = round(k * float64(ttf.TypoDescender)) info.UnderlineThickness = round(k * float64(ttf.UnderlineThickness)) info.UnderlinePosition = round(k * float64(ttf.UnderlinePosition)) info.Desc.FontBBox = fontBoxType{ round(k * float64(ttf.Xmin)), round(k * float64(ttf.Ymin)), round(k * float64(ttf.Xmax)), round(k * float64(ttf.Ymax)), } // printf("FontBBox\n") // dump(info.Desc.FontBBox) info.Desc.CapHeight = round(k * float64(ttf.CapHeight)) info.Desc.MissingWidth = round(k * float64(ttf.Widths[0])) var wd int for j := 0; j < len(info.Widths); j++ { wd = info.Desc.MissingWidth if encList[j].name != ".notdef" { uv := encList[j].uv pos, ok := ttf.Chars[uint16(uv)] if ok { wd = round(k * float64(ttf.Widths[pos])) } else { fmt.Fprintf(msgWriter, "Character %s is missing\n", encList[j].name) } } info.Widths[j] = wd } // printf("getInfoFromTrueType/FontBBox\n") // dump(info.Desc.FontBBox) return }
[ "func", "getInfoFromTrueType", "(", "fileStr", "string", ",", "msgWriter", "io", ".", "Writer", ",", "embed", "bool", ",", "encList", "encListType", ")", "(", "info", "fontInfoType", ",", "err", "error", ")", "{", "var", "ttf", "TtfType", "\n", "ttf", ",", "err", "=", "TtfParse", "(", "fileStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "embed", "{", "if", "!", "ttf", ".", "Embeddable", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "info", ".", "Data", ",", "err", "=", "ioutil", ".", "ReadFile", "(", "fileStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "info", ".", "OriginalSize", "=", "len", "(", "info", ".", "Data", ")", "\n", "}", "\n", "k", ":=", "1000.0", "/", "float64", "(", "ttf", ".", "UnitsPerEm", ")", "\n", "info", ".", "FontName", "=", "ttf", ".", "PostScriptName", "\n", "info", ".", "Bold", "=", "ttf", ".", "Bold", "\n", "info", ".", "Desc", ".", "ItalicAngle", "=", "int", "(", "ttf", ".", "ItalicAngle", ")", "\n", "info", ".", "IsFixedPitch", "=", "ttf", ".", "IsFixedPitch", "\n", "info", ".", "Desc", ".", "Ascent", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "TypoAscender", ")", ")", "\n", "info", ".", "Desc", ".", "Descent", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "TypoDescender", ")", ")", "\n", "info", ".", "UnderlineThickness", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "UnderlineThickness", ")", ")", "\n", "info", ".", "UnderlinePosition", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "UnderlinePosition", ")", ")", "\n", "info", ".", "Desc", ".", "FontBBox", "=", "fontBoxType", "{", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Xmin", ")", ")", ",", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Ymin", ")", ")", ",", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Xmax", ")", ")", ",", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Ymax", ")", ")", ",", "}", "\n", "// printf(\"FontBBox\\n\")", "// dump(info.Desc.FontBBox)", "info", ".", "Desc", ".", "CapHeight", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "CapHeight", ")", ")", "\n", "info", ".", "Desc", ".", "MissingWidth", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Widths", "[", "0", "]", ")", ")", "\n", "var", "wd", "int", "\n", "for", "j", ":=", "0", ";", "j", "<", "len", "(", "info", ".", "Widths", ")", ";", "j", "++", "{", "wd", "=", "info", ".", "Desc", ".", "MissingWidth", "\n", "if", "encList", "[", "j", "]", ".", "name", "!=", "\"", "\"", "{", "uv", ":=", "encList", "[", "j", "]", ".", "uv", "\n", "pos", ",", "ok", ":=", "ttf", ".", "Chars", "[", "uint16", "(", "uv", ")", "]", "\n", "if", "ok", "{", "wd", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Widths", "[", "pos", "]", ")", ")", "\n", "}", "else", "{", "fmt", ".", "Fprintf", "(", "msgWriter", ",", "\"", "\\n", "\"", ",", "encList", "[", "j", "]", ".", "name", ")", "\n", "}", "\n", "}", "\n", "info", ".", "Widths", "[", "j", "]", "=", "wd", "\n", "}", "\n", "// printf(\"getInfoFromTrueType/FontBBox\\n\")", "// dump(info.Desc.FontBBox)", "return", "\n", "}" ]
// getInfoFromTrueType returns information from a TrueType font
[ "getInfoFromTrueType", "returns", "information", "from", "a", "TrueType", "font" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/font.go#L85-L138
train
jung-kurt/gofpdf
font.go
makeFontEncoding
func makeFontEncoding(encList encListType, refEncFileStr string) (diffStr string, err error) { var refList encListType if refList, err = loadMap(refEncFileStr); err != nil { return } var buf fmtBuffer last := 0 for j := 32; j < 256; j++ { if encList[j].name != refList[j].name { if j != last+1 { buf.printf("%d ", j) } last = j buf.printf("/%s ", encList[j].name) } } diffStr = strings.TrimSpace(buf.String()) return }
go
func makeFontEncoding(encList encListType, refEncFileStr string) (diffStr string, err error) { var refList encListType if refList, err = loadMap(refEncFileStr); err != nil { return } var buf fmtBuffer last := 0 for j := 32; j < 256; j++ { if encList[j].name != refList[j].name { if j != last+1 { buf.printf("%d ", j) } last = j buf.printf("/%s ", encList[j].name) } } diffStr = strings.TrimSpace(buf.String()) return }
[ "func", "makeFontEncoding", "(", "encList", "encListType", ",", "refEncFileStr", "string", ")", "(", "diffStr", "string", ",", "err", "error", ")", "{", "var", "refList", "encListType", "\n", "if", "refList", ",", "err", "=", "loadMap", "(", "refEncFileStr", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "var", "buf", "fmtBuffer", "\n", "last", ":=", "0", "\n", "for", "j", ":=", "32", ";", "j", "<", "256", ";", "j", "++", "{", "if", "encList", "[", "j", "]", ".", "name", "!=", "refList", "[", "j", "]", ".", "name", "{", "if", "j", "!=", "last", "+", "1", "{", "buf", ".", "printf", "(", "\"", "\"", ",", "j", ")", "\n", "}", "\n", "last", "=", "j", "\n", "buf", ".", "printf", "(", "\"", "\"", ",", "encList", "[", "j", "]", ".", "name", ")", "\n", "}", "\n", "}", "\n", "diffStr", "=", "strings", ".", "TrimSpace", "(", "buf", ".", "String", "(", ")", ")", "\n", "return", "\n", "}" ]
// makeFontEncoding builds differences from reference encoding
[ "makeFontEncoding", "builds", "differences", "from", "reference", "encoding" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/font.go#L314-L332
train