fix wrong git ignore
This commit is contained in:
57
internal/pdf/model/utils.go
Normal file
57
internal/pdf/model/utils.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gitea.tecamino.com/paadi/pdfmerge/internal/pdf/common"
|
||||
"gitea.tecamino.com/paadi/pdfmerge/internal/pdf/core"
|
||||
)
|
||||
|
||||
func getNumberAsFloat(obj core.PdfObject) (float64, error) {
|
||||
if fObj, ok := obj.(*core.PdfObjectFloat); ok {
|
||||
return float64(*fObj), nil
|
||||
}
|
||||
|
||||
if iObj, ok := obj.(*core.PdfObjectInteger); ok {
|
||||
return float64(*iObj), nil
|
||||
}
|
||||
|
||||
return 0, errors.New("not a number")
|
||||
}
|
||||
|
||||
func isNullObject(obj core.PdfObject) bool {
|
||||
if _, isNull := obj.(*core.PdfObjectNull); isNull {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Convert a list of pdf objects representing floats or integers to a slice of float64 values.
|
||||
func getNumbersAsFloat(objects []core.PdfObject) ([]float64, error) {
|
||||
floats := []float64{}
|
||||
for _, obj := range objects {
|
||||
val, err := getNumberAsFloat(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
floats = append(floats, val)
|
||||
|
||||
}
|
||||
return floats, nil
|
||||
}
|
||||
|
||||
// Cases where expecting an integer, but some implementations actually
|
||||
// store the number in a floating point format.
|
||||
func getNumberAsInt64(obj core.PdfObject) (int64, error) {
|
||||
if iObj, ok := obj.(*core.PdfObjectInteger); ok {
|
||||
return int64(*iObj), nil
|
||||
}
|
||||
|
||||
if fObj, ok := obj.(*core.PdfObjectFloat); ok {
|
||||
common.Log.Debug("Number expected as integer was stored as float (type casting used)")
|
||||
return int64(*fObj), nil
|
||||
}
|
||||
|
||||
return 0, errors.New("not a number")
|
||||
}
|
||||
Reference in New Issue
Block a user