mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
Remove dot imports from model/pattern.go
This commit is contained in:
parent
17acba5fad
commit
13fa75ce39
@ -11,7 +11,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/unidoc/unidoc/common"
|
"github.com/unidoc/unidoc/common"
|
||||||
. "github.com/unidoc/unidoc/pdf/core"
|
"github.com/unidoc/unidoc/pdf/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A PdfPattern can represent a Pattern, either a tiling pattern or a shading pattern.
|
// A PdfPattern can represent a Pattern, either a tiling pattern or a shading pattern.
|
||||||
@ -23,10 +23,10 @@ type PdfPattern struct {
|
|||||||
PatternType int64
|
PatternType int64
|
||||||
context PdfModel // The sub pattern, either PdfTilingPattern (Type 1) or PdfShadingPattern (Type 2).
|
context PdfModel // The sub pattern, either PdfTilingPattern (Type 1) or PdfShadingPattern (Type 2).
|
||||||
|
|
||||||
container PdfObject
|
container core.PdfObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PdfPattern) GetContainingPdfObject() PdfObject {
|
func (p *PdfPattern) GetContainingPdfObject() core.PdfObject {
|
||||||
return p.container
|
return p.container
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,13 +64,13 @@ func (p *PdfPattern) GetAsShadingPattern() *PdfShadingPattern {
|
|||||||
// a content stream that describes the pattern cell.
|
// a content stream that describes the pattern cell.
|
||||||
type PdfTilingPattern struct {
|
type PdfTilingPattern struct {
|
||||||
*PdfPattern
|
*PdfPattern
|
||||||
PaintType *PdfObjectInteger // Colored or uncolored tiling pattern.
|
PaintType *core.PdfObjectInteger // Colored or uncolored tiling pattern.
|
||||||
TilingType *PdfObjectInteger // Constant spacing, no distortion or constant spacing/faster tiling.
|
TilingType *core.PdfObjectInteger // Constant spacing, no distortion or constant spacing/faster tiling.
|
||||||
BBox *PdfRectangle
|
BBox *PdfRectangle
|
||||||
XStep *PdfObjectFloat
|
XStep *core.PdfObjectFloat
|
||||||
YStep *PdfObjectFloat
|
YStep *core.PdfObjectFloat
|
||||||
Resources *PdfPageResources
|
Resources *PdfPageResources
|
||||||
Matrix *PdfObjectArray // Pattern matrix (6 numbers).
|
Matrix *core.PdfObjectArray // Pattern matrix (6 numbers).
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PdfTilingPattern) IsColored() bool {
|
func (p *PdfTilingPattern) IsColored() bool {
|
||||||
@ -89,20 +89,20 @@ func (p *PdfTilingPattern) GetContentStream() ([]byte, error) {
|
|||||||
|
|
||||||
// GetContentStreamWithEncoder returns the pattern cell's content stream and its encoder
|
// GetContentStreamWithEncoder returns the pattern cell's content stream and its encoder
|
||||||
// TODO (v3): Change GetContentStreamWithEncoder to GetContentStream
|
// TODO (v3): Change GetContentStreamWithEncoder to GetContentStream
|
||||||
func (p *PdfTilingPattern) GetContentStreamWithEncoder() ([]byte, StreamEncoder, error) {
|
func (p *PdfTilingPattern) GetContentStreamWithEncoder() ([]byte, core.StreamEncoder, error) {
|
||||||
streamObj, ok := p.container.(*PdfObjectStream)
|
streamObj, ok := p.container.(*core.PdfObjectStream)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("Tiling pattern container not a stream (got %T)", p.container)
|
common.Log.Debug("Tiling pattern container not a stream (got %T)", p.container)
|
||||||
return nil, nil, ErrTypeError
|
return nil, nil, core.ErrTypeError
|
||||||
}
|
}
|
||||||
|
|
||||||
decoded, err := DecodeStream(streamObj)
|
decoded, err := core.DecodeStream(streamObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.Log.Debug("Failed decoding stream, err: %v", err)
|
common.Log.Debug("Failed decoding stream, err: %v", err)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
encoder, err := NewEncoderFromStream(streamObj)
|
encoder, err := core.NewEncoderFromStream(streamObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.Log.Debug("Failed finding decoding encoder: %v", err)
|
common.Log.Debug("Failed finding decoding encoder: %v", err)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -112,16 +112,16 @@ func (p *PdfTilingPattern) GetContentStreamWithEncoder() ([]byte, StreamEncoder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetContentStream sets the pattern cell's content stream.
|
// SetContentStream sets the pattern cell's content stream.
|
||||||
func (p *PdfTilingPattern) SetContentStream(content []byte, encoder StreamEncoder) error {
|
func (p *PdfTilingPattern) SetContentStream(content []byte, encoder core.StreamEncoder) error {
|
||||||
streamObj, ok := p.container.(*PdfObjectStream)
|
streamObj, ok := p.container.(*core.PdfObjectStream)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("Tiling pattern container not a stream (got %T)", p.container)
|
common.Log.Debug("Tiling pattern container not a stream (got %T)", p.container)
|
||||||
return ErrTypeError
|
return core.ErrTypeError
|
||||||
}
|
}
|
||||||
|
|
||||||
// If encoding is not set, use raw encoder.
|
// If encoding is not set, use raw encoder.
|
||||||
if encoder == nil {
|
if encoder == nil {
|
||||||
encoder = NewRawEncoder()
|
encoder = core.NewRawEncoder()
|
||||||
}
|
}
|
||||||
|
|
||||||
streamDict := streamObj.PdfObjectDictionary
|
streamDict := streamObj.PdfObjectDictionary
|
||||||
@ -137,7 +137,7 @@ func (p *PdfTilingPattern) SetContentStream(content []byte, encoder StreamEncode
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update length.
|
// Update length.
|
||||||
streamDict.Set("Length", MakeInteger(int64(len(encoded))))
|
streamDict.Set("Length", core.MakeInteger(int64(len(encoded))))
|
||||||
|
|
||||||
streamObj.Stream = []byte(encoded)
|
streamObj.Stream = []byte(encoded)
|
||||||
|
|
||||||
@ -150,29 +150,29 @@ func (p *PdfTilingPattern) SetContentStream(content []byte, encoder StreamEncode
|
|||||||
type PdfShadingPattern struct {
|
type PdfShadingPattern struct {
|
||||||
*PdfPattern
|
*PdfPattern
|
||||||
Shading *PdfShading
|
Shading *PdfShading
|
||||||
Matrix *PdfObjectArray
|
Matrix *core.PdfObjectArray
|
||||||
ExtGState PdfObject
|
ExtGState core.PdfObject
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a pdf pattern from an indirect object. Used in parsing/loading PDFs.
|
// Load a pdf pattern from an indirect object. Used in parsing/loading PDFs.
|
||||||
func newPdfPatternFromPdfObject(container PdfObject) (*PdfPattern, error) {
|
func newPdfPatternFromPdfObject(container core.PdfObject) (*PdfPattern, error) {
|
||||||
pattern := &PdfPattern{}
|
pattern := &PdfPattern{}
|
||||||
|
|
||||||
var dict *PdfObjectDictionary
|
var dict *core.PdfObjectDictionary
|
||||||
if indObj, is := container.(*PdfIndirectObject); is {
|
if indObj, is := container.(*core.PdfIndirectObject); is {
|
||||||
pattern.container = indObj
|
pattern.container = indObj
|
||||||
d, ok := indObj.PdfObject.(*PdfObjectDictionary)
|
d, ok := indObj.PdfObject.(*core.PdfObjectDictionary)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("Pattern indirect object not containing dictionary (got %T)", indObj.PdfObject)
|
common.Log.Debug("Pattern indirect object not containing dictionary (got %T)", indObj.PdfObject)
|
||||||
return nil, ErrTypeError
|
return nil, core.ErrTypeError
|
||||||
}
|
}
|
||||||
dict = d
|
dict = d
|
||||||
} else if streamObj, is := container.(*PdfObjectStream); is {
|
} else if streamObj, is := container.(*core.PdfObjectStream); is {
|
||||||
pattern.container = streamObj
|
pattern.container = streamObj
|
||||||
dict = streamObj.PdfObjectDictionary
|
dict = streamObj.PdfObjectDictionary
|
||||||
} else {
|
} else {
|
||||||
common.Log.Debug("Pattern not an indirect object or stream")
|
common.Log.Debug("Pattern not an indirect object or stream")
|
||||||
return nil, ErrTypeError
|
return nil, core.ErrTypeError
|
||||||
}
|
}
|
||||||
|
|
||||||
// PatternType.
|
// PatternType.
|
||||||
@ -181,14 +181,14 @@ func newPdfPatternFromPdfObject(container PdfObject) (*PdfPattern, error) {
|
|||||||
common.Log.Debug("Pdf Pattern not containing PatternType")
|
common.Log.Debug("Pdf Pattern not containing PatternType")
|
||||||
return nil, ErrRequiredAttributeMissing
|
return nil, ErrRequiredAttributeMissing
|
||||||
}
|
}
|
||||||
patternType, ok := obj.(*PdfObjectInteger)
|
patternType, ok := obj.(*core.PdfObjectInteger)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("Pattern type not an integer (got %T)", obj)
|
common.Log.Debug("Pattern type not an integer (got %T)", obj)
|
||||||
return nil, ErrTypeError
|
return nil, core.ErrTypeError
|
||||||
}
|
}
|
||||||
if *patternType != 1 && *patternType != 2 {
|
if *patternType != 1 && *patternType != 2 {
|
||||||
common.Log.Debug("Pattern type != 1/2 (got %d)", *patternType)
|
common.Log.Debug("Pattern type != 1/2 (got %d)", *patternType)
|
||||||
return nil, ErrRangeError
|
return nil, core.ErrRangeError
|
||||||
}
|
}
|
||||||
pattern.PatternType = int64(*patternType)
|
pattern.PatternType = int64(*patternType)
|
||||||
|
|
||||||
@ -214,8 +214,9 @@ func newPdfPatternFromPdfObject(container PdfObject) (*PdfPattern, error) {
|
|||||||
return nil, errors.New("unknown pattern")
|
return nil, errors.New("unknown pattern")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load entries specific to a pdf tiling pattern from a dictionary. Used in parsing/loading PDFs.
|
// Load entries specific to a pdf tiling pattern from a dictionary.
|
||||||
func newPdfTilingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfTilingPattern, error) {
|
// Used in parsing/loading PDFs.
|
||||||
|
func newPdfTilingPatternFromDictionary(dict *core.PdfObjectDictionary) (*PdfTilingPattern, error) {
|
||||||
pattern := &PdfTilingPattern{}
|
pattern := &PdfTilingPattern{}
|
||||||
|
|
||||||
// PaintType (required).
|
// PaintType (required).
|
||||||
@ -224,10 +225,10 @@ func newPdfTilingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfTilingPat
|
|||||||
common.Log.Debug("PaintType missing")
|
common.Log.Debug("PaintType missing")
|
||||||
return nil, ErrRequiredAttributeMissing
|
return nil, ErrRequiredAttributeMissing
|
||||||
}
|
}
|
||||||
paintType, ok := obj.(*PdfObjectInteger)
|
paintType, ok := obj.(*core.PdfObjectInteger)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("PaintType not an integer (got %T)", obj)
|
common.Log.Debug("PaintType not an integer (got %T)", obj)
|
||||||
return nil, ErrTypeError
|
return nil, core.ErrTypeError
|
||||||
}
|
}
|
||||||
pattern.PaintType = paintType
|
pattern.PaintType = paintType
|
||||||
|
|
||||||
@ -237,10 +238,10 @@ func newPdfTilingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfTilingPat
|
|||||||
common.Log.Debug("TilingType missing")
|
common.Log.Debug("TilingType missing")
|
||||||
return nil, ErrRequiredAttributeMissing
|
return nil, ErrRequiredAttributeMissing
|
||||||
}
|
}
|
||||||
tilingType, ok := obj.(*PdfObjectInteger)
|
tilingType, ok := obj.(*core.PdfObjectInteger)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("TilingType not an integer (got %T)", obj)
|
common.Log.Debug("TilingType not an integer (got %T)", obj)
|
||||||
return nil, ErrTypeError
|
return nil, core.ErrTypeError
|
||||||
}
|
}
|
||||||
pattern.TilingType = tilingType
|
pattern.TilingType = tilingType
|
||||||
|
|
||||||
@ -250,11 +251,11 @@ func newPdfTilingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfTilingPat
|
|||||||
common.Log.Debug("BBox missing")
|
common.Log.Debug("BBox missing")
|
||||||
return nil, ErrRequiredAttributeMissing
|
return nil, ErrRequiredAttributeMissing
|
||||||
}
|
}
|
||||||
obj = TraceToDirectObject(obj)
|
obj = core.TraceToDirectObject(obj)
|
||||||
arr, ok := obj.(*PdfObjectArray)
|
arr, ok := obj.(*core.PdfObjectArray)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("BBox should be specified by an array (got %T)", obj)
|
common.Log.Debug("BBox should be specified by an array (got %T)", obj)
|
||||||
return nil, ErrTypeError
|
return nil, core.ErrTypeError
|
||||||
}
|
}
|
||||||
rect, err := NewPdfRectangle(*arr)
|
rect, err := NewPdfRectangle(*arr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -269,12 +270,12 @@ func newPdfTilingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfTilingPat
|
|||||||
common.Log.Debug("XStep missing")
|
common.Log.Debug("XStep missing")
|
||||||
return nil, ErrRequiredAttributeMissing
|
return nil, ErrRequiredAttributeMissing
|
||||||
}
|
}
|
||||||
xStep, err := GetNumberAsFloat(obj)
|
xStep, err := core.GetNumberAsFloat(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.Log.Debug("Error getting XStep as float: %v", xStep)
|
common.Log.Debug("Error getting XStep as float: %v", xStep)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pattern.XStep = MakeFloat(xStep)
|
pattern.XStep = core.MakeFloat(xStep)
|
||||||
|
|
||||||
// YStep (required).
|
// YStep (required).
|
||||||
obj = dict.Get("YStep")
|
obj = dict.Get("YStep")
|
||||||
@ -282,12 +283,12 @@ func newPdfTilingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfTilingPat
|
|||||||
common.Log.Debug("YStep missing")
|
common.Log.Debug("YStep missing")
|
||||||
return nil, ErrRequiredAttributeMissing
|
return nil, ErrRequiredAttributeMissing
|
||||||
}
|
}
|
||||||
yStep, err := GetNumberAsFloat(obj)
|
yStep, err := core.GetNumberAsFloat(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.Log.Debug("Error getting YStep as float: %v", yStep)
|
common.Log.Debug("Error getting YStep as float: %v", yStep)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pattern.YStep = MakeFloat(yStep)
|
pattern.YStep = core.MakeFloat(yStep)
|
||||||
|
|
||||||
// Resources (required).
|
// Resources (required).
|
||||||
obj = dict.Get("Resources")
|
obj = dict.Get("Resources")
|
||||||
@ -295,7 +296,7 @@ func newPdfTilingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfTilingPat
|
|||||||
common.Log.Debug("Resources missing")
|
common.Log.Debug("Resources missing")
|
||||||
return nil, ErrRequiredAttributeMissing
|
return nil, ErrRequiredAttributeMissing
|
||||||
}
|
}
|
||||||
dict, ok = TraceToDirectObject(obj).(*PdfObjectDictionary)
|
dict, ok = core.TraceToDirectObject(obj).(*core.PdfObjectDictionary)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("invalid resource dictionary (%T)", obj)
|
return nil, fmt.Errorf("invalid resource dictionary (%T)", obj)
|
||||||
}
|
}
|
||||||
@ -307,10 +308,10 @@ func newPdfTilingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfTilingPat
|
|||||||
|
|
||||||
// Matrix (optional).
|
// Matrix (optional).
|
||||||
if obj := dict.Get("Matrix"); obj != nil {
|
if obj := dict.Get("Matrix"); obj != nil {
|
||||||
arr, ok := obj.(*PdfObjectArray)
|
arr, ok := obj.(*core.PdfObjectArray)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("Matrix not an array (got %T)", obj)
|
common.Log.Debug("Matrix not an array (got %T)", obj)
|
||||||
return nil, ErrTypeError
|
return nil, core.ErrTypeError
|
||||||
}
|
}
|
||||||
pattern.Matrix = arr
|
pattern.Matrix = arr
|
||||||
}
|
}
|
||||||
@ -318,8 +319,9 @@ func newPdfTilingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfTilingPat
|
|||||||
return pattern, nil
|
return pattern, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load entries specific to a pdf shading pattern from a dictionary. Used in parsing/loading PDFs.
|
// Load entries specific to a pdf shading pattern from a dictionary.
|
||||||
func newPdfShadingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfShadingPattern, error) {
|
// Used in parsing/loading PDFs.
|
||||||
|
func newPdfShadingPatternFromDictionary(dict *core.PdfObjectDictionary) (*PdfShadingPattern, error) {
|
||||||
pattern := &PdfShadingPattern{}
|
pattern := &PdfShadingPattern{}
|
||||||
|
|
||||||
// Shading (required).
|
// Shading (required).
|
||||||
@ -337,10 +339,10 @@ func newPdfShadingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfShadingP
|
|||||||
|
|
||||||
// Matrix (optional).
|
// Matrix (optional).
|
||||||
if obj := dict.Get("Matrix"); obj != nil {
|
if obj := dict.Get("Matrix"); obj != nil {
|
||||||
arr, ok := obj.(*PdfObjectArray)
|
arr, ok := obj.(*core.PdfObjectArray)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("Matrix not an array (got %T)", obj)
|
common.Log.Debug("Matrix not an array (got %T)", obj)
|
||||||
return nil, ErrTypeError
|
return nil, core.ErrTypeError
|
||||||
}
|
}
|
||||||
pattern.Matrix = arr
|
pattern.Matrix = arr
|
||||||
}
|
}
|
||||||
@ -355,14 +357,14 @@ func newPdfShadingPatternFromDictionary(dict *PdfObjectDictionary) (*PdfShadingP
|
|||||||
|
|
||||||
/* Conversions to pdf objects. */
|
/* Conversions to pdf objects. */
|
||||||
|
|
||||||
func (p *PdfPattern) getDict() *PdfObjectDictionary {
|
func (p *PdfPattern) getDict() *core.PdfObjectDictionary {
|
||||||
if indObj, is := p.container.(*PdfIndirectObject); is {
|
if indObj, is := p.container.(*core.PdfIndirectObject); is {
|
||||||
dict, ok := indObj.PdfObject.(*PdfObjectDictionary)
|
dict, ok := indObj.PdfObject.(*core.PdfObjectDictionary)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return dict
|
return dict
|
||||||
} else if streamObj, is := p.container.(*PdfObjectStream); is {
|
} else if streamObj, is := p.container.(*core.PdfObjectStream); is {
|
||||||
return streamObj.PdfObjectDictionary
|
return streamObj.PdfObjectDictionary
|
||||||
} else {
|
} else {
|
||||||
common.Log.Debug("Trying to access pattern dictionary of invalid object type (%T)", p.container)
|
common.Log.Debug("Trying to access pattern dictionary of invalid object type (%T)", p.container)
|
||||||
@ -370,15 +372,15 @@ func (p *PdfPattern) getDict() *PdfObjectDictionary {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PdfPattern) ToPdfObject() PdfObject {
|
func (p *PdfPattern) ToPdfObject() core.PdfObject {
|
||||||
d := p.getDict()
|
d := p.getDict()
|
||||||
d.Set("Type", MakeName("Pattern"))
|
d.Set("Type", core.MakeName("Pattern"))
|
||||||
d.Set("PatternType", MakeInteger(p.PatternType))
|
d.Set("PatternType", core.MakeInteger(p.PatternType))
|
||||||
|
|
||||||
return p.container
|
return p.container
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PdfTilingPattern) ToPdfObject() PdfObject {
|
func (p *PdfTilingPattern) ToPdfObject() core.PdfObject {
|
||||||
p.PdfPattern.ToPdfObject()
|
p.PdfPattern.ToPdfObject()
|
||||||
|
|
||||||
d := p.getDict()
|
d := p.getDict()
|
||||||
@ -407,7 +409,7 @@ func (p *PdfTilingPattern) ToPdfObject() PdfObject {
|
|||||||
return p.container
|
return p.container
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PdfShadingPattern) ToPdfObject() PdfObject {
|
func (p *PdfShadingPattern) ToPdfObject() core.PdfObject {
|
||||||
p.PdfPattern.ToPdfObject()
|
p.PdfPattern.ToPdfObject()
|
||||||
d := p.getDict()
|
d := p.getDict()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user