mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-01 22:17:29 +08:00
Address more golint recommendations #89
This commit is contained in:
parent
2ecf2acce5
commit
714b4bcb60
@ -25,10 +25,10 @@ const (
|
|||||||
XREF_OBJECT_STREAM = iota
|
XREF_OBJECT_STREAM = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
// Either can be in a normal xref table, or in an xref stream.
|
// XrefObject defines a cross reference entry which is a map between object number (with generation number) and the
|
||||||
// Can point either to a file offset, or to an object stream.
|
// location of the actual object, either as a file offset (xref table entry), or as a location within an xref
|
||||||
// XrefFileOffset or XrefObjectStream...
|
// stream object (xref object stream).
|
||||||
|
// TODO (v3): Unexport.
|
||||||
type XrefObject struct {
|
type XrefObject struct {
|
||||||
xtype int
|
xtype int
|
||||||
objectNumber int
|
objectNumber int
|
||||||
@ -40,16 +40,26 @@ type XrefObject struct {
|
|||||||
osObjIndex int
|
osObjIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XrefTable is a map between object number and corresponding XrefObject.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
type XrefTable map[int]XrefObject
|
type XrefTable map[int]XrefObject
|
||||||
|
|
||||||
|
// ObjectStream represents an object stream's information which can contain multiple indirect objects.
|
||||||
|
// The information specifies the number of objects and has information about offset locations for
|
||||||
|
// each object.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
type ObjectStream struct {
|
type ObjectStream struct {
|
||||||
N int
|
N int // TODO (v3): Unexport.
|
||||||
ds []byte
|
ds []byte
|
||||||
offsets map[int]int64
|
offsets map[int]int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ObjectStreams defines a map between object numbers (object streams only) and underlying ObjectStream information.
|
||||||
type ObjectStreams map[int]ObjectStream
|
type ObjectStreams map[int]ObjectStream
|
||||||
|
|
||||||
|
// ObjectCache defines a map between object numbers and corresponding PdfObject. Serves as a cache for PdfObjects that
|
||||||
|
// have already been parsed.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
type ObjectCache map[int]PdfObject
|
type ObjectCache map[int]PdfObject
|
||||||
|
|
||||||
// Get an object from an object stream.
|
// Get an object from an object stream.
|
||||||
@ -114,7 +124,7 @@ func (this *PdfParser) lookupObjectViaOS(sobjNumber int, objNum int) (PdfObject,
|
|||||||
|
|
||||||
common.Log.Trace("Parsing offset map")
|
common.Log.Trace("Parsing offset map")
|
||||||
// Load the offset map (relative to the beginning of the stream...)
|
// Load the offset map (relative to the beginning of the stream...)
|
||||||
var offsets map[int]int64 = make(map[int]int64)
|
offsets := map[int]int64{}
|
||||||
// Object list and offsets.
|
// Object list and offsets.
|
||||||
for i := 0; i < int(*N); i++ {
|
for i := 0; i < int(*N); i++ {
|
||||||
this.skipSpaces()
|
this.skipSpaces()
|
||||||
@ -182,11 +192,10 @@ func (this *PdfParser) lookupObjectViaOS(sobjNumber int, objNum int) (PdfObject,
|
|||||||
return &io, nil
|
return &io, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently a bit messy.. multiple wrappers. Can we clean up?
|
// LookupByNumber looks up a PdfObject by object number. Returns an error on failure.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
// Outside interface for lookupByNumberWrapper. Default attempts
|
|
||||||
// repairs of bad xref tables.
|
|
||||||
func (this *PdfParser) LookupByNumber(objNumber int) (PdfObject, error) {
|
func (this *PdfParser) LookupByNumber(objNumber int) (PdfObject, error) {
|
||||||
|
// Outside interface for lookupByNumberWrapper. Default attempts repairs of bad xref tables.
|
||||||
obj, _, err := this.lookupByNumberWrapper(objNumber, true)
|
obj, _, err := this.lookupByNumberWrapper(objNumber, true)
|
||||||
return obj, err
|
return obj, err
|
||||||
}
|
}
|
||||||
@ -318,13 +327,14 @@ func (this *PdfParser) lookupByNumber(objNumber int, attemptRepairs bool) (PdfOb
|
|||||||
return nil, false, errors.New("Unknown xref type")
|
return nil, false, errors.New("Unknown xref type")
|
||||||
}
|
}
|
||||||
|
|
||||||
// LookupByReference
|
// LookupByReference looks up a PdfObject by a reference.
|
||||||
func (this *PdfParser) LookupByReference(ref PdfObjectReference) (PdfObject, error) {
|
func (this *PdfParser) LookupByReference(ref PdfObjectReference) (PdfObject, error) {
|
||||||
common.Log.Trace("Looking up reference %s", ref.String())
|
common.Log.Trace("Looking up reference %s", ref.String())
|
||||||
return this.LookupByNumber(int(ref.ObjectNumber))
|
return this.LookupByNumber(int(ref.ObjectNumber))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trace to direct object.
|
// Trace traces a PdfObject to direct object, looking up and resolving references as needed (unlike TraceToDirect).
|
||||||
|
// TODO (v3): Unexport.
|
||||||
func (this *PdfParser) Trace(obj PdfObject) (PdfObject, error) {
|
func (this *PdfParser) Trace(obj PdfObject) (PdfObject, error) {
|
||||||
ref, isRef := obj.(*PdfObjectReference)
|
ref, isRef := obj.(*PdfObjectReference)
|
||||||
if !isRef {
|
if !isRef {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/unidoc/unidoc/common"
|
"github.com/unidoc/unidoc/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Creates the encoder from the stream's dictionary.
|
// NewEncoderFromStream creates a StreamEncoder based on the stream's dictionary.
|
||||||
func NewEncoderFromStream(streamObj *PdfObjectStream) (StreamEncoder, error) {
|
func NewEncoderFromStream(streamObj *PdfObjectStream) (StreamEncoder, error) {
|
||||||
filterObj := streamObj.PdfObjectDictionary.Get("Filter")
|
filterObj := streamObj.PdfObjectDictionary.Get("Filter")
|
||||||
if filterObj == nil {
|
if filterObj == nil {
|
||||||
@ -71,8 +71,8 @@ func NewEncoderFromStream(streamObj *PdfObjectStream) (StreamEncoder, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decodes the stream.
|
// DecodeStream decodes the stream data and returns the decoded data.
|
||||||
// Supports FlateDecode, ASCIIHexDecode, LZW.
|
// An error is returned upon failure.
|
||||||
func DecodeStream(streamObj *PdfObjectStream) ([]byte, error) {
|
func DecodeStream(streamObj *PdfObjectStream) ([]byte, error) {
|
||||||
common.Log.Trace("Decode stream")
|
common.Log.Trace("Decode stream")
|
||||||
|
|
||||||
@ -92,8 +92,7 @@ func DecodeStream(streamObj *PdfObjectStream) ([]byte, error) {
|
|||||||
return decoded, nil
|
return decoded, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encodes the stream.
|
// EncodeStream encodes the stream data using the encoded specified by the stream's dictionary.
|
||||||
// Uses the encoding specified by the object.
|
|
||||||
func EncodeStream(streamObj *PdfObjectStream) error {
|
func EncodeStream(streamObj *PdfObjectStream) error {
|
||||||
common.Log.Trace("Encode stream")
|
common.Log.Trace("Encode stream")
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
// IsWhiteSpace checks if byte represents a white space character.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
func IsWhiteSpace(ch byte) bool {
|
func IsWhiteSpace(ch byte) bool {
|
||||||
// Table 1 white-space characters (7.2.2 Character Set)
|
// Table 1 white-space characters (7.2.2 Character Set)
|
||||||
// spaceCharacters := string([]byte{0x00, 0x09, 0x0A, 0x0C, 0x0D, 0x20})
|
// spaceCharacters := string([]byte{0x00, 0x09, 0x0A, 0x0C, 0x0D, 0x20})
|
||||||
@ -15,10 +17,14 @@ func IsWhiteSpace(ch byte) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsFloatDigit checks if a character can be a part of a float number string.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
func IsFloatDigit(c byte) bool {
|
func IsFloatDigit(c byte) bool {
|
||||||
return ('0' <= c && c <= '9') || c == '.'
|
return ('0' <= c && c <= '9') || c == '.'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsDecimalDigit checks if the character is a part of a decimal number string.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
func IsDecimalDigit(c byte) bool {
|
func IsDecimalDigit(c byte) bool {
|
||||||
if c >= '0' && c <= '9' {
|
if c >= '0' && c <= '9' {
|
||||||
return true
|
return true
|
||||||
@ -27,6 +33,8 @@ func IsDecimalDigit(c byte) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsOctalDigit checks if a character can be part of an octal digit string.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
func IsOctalDigit(c byte) bool {
|
func IsOctalDigit(c byte) bool {
|
||||||
if c >= '0' && c <= '7' {
|
if c >= '0' && c <= '7' {
|
||||||
return true
|
return true
|
||||||
@ -35,8 +43,10 @@ func IsOctalDigit(c byte) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPrintable checks if a character is printable.
|
||||||
// Regular characters that are outside the range EXCLAMATION MARK(21h)
|
// Regular characters that are outside the range EXCLAMATION MARK(21h)
|
||||||
// (!) to TILDE (7Eh) (~) should be written using the hexadecimal notation.
|
// (!) to TILDE (7Eh) (~) should be written using the hexadecimal notation.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
func IsPrintable(char byte) bool {
|
func IsPrintable(char byte) bool {
|
||||||
if char < 0x21 || char > 0x7E {
|
if char < 0x21 || char > 0x7E {
|
||||||
return false
|
return false
|
||||||
@ -44,6 +54,8 @@ func IsPrintable(char byte) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsDelimiter checks if a character represents a delimiter.
|
||||||
|
// TODO (v3): Unexport.
|
||||||
func IsDelimiter(char byte) bool {
|
func IsDelimiter(char byte) bool {
|
||||||
if char == '(' || char == ')' {
|
if char == '(' || char == ')' {
|
||||||
return true
|
return true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user