2016-09-08 17:53:45 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions defined in
|
|
|
|
* file 'LICENSE.md', which is part of this source code package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/unidoc/unidoc/pdf/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
// A PDFModel is a higher level PDF construct which can be collapsed into a PDF primitive.
|
|
|
|
// Each PDFModel has an underlying Primitive and vice versa.
|
|
|
|
// Copies can be made, but care must be taken to do it properly.
|
|
|
|
type PdfModel interface {
|
2016-09-11 23:17:38 +00:00
|
|
|
ToPdfObject() PdfObject
|
|
|
|
GetContainingPdfObject() PdfObject
|
2016-09-08 17:53:45 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 23:17:38 +00:00
|
|
|
/*
|
|
|
|
|
2016-09-08 17:53:45 +00:00
|
|
|
type ModelManager struct {
|
|
|
|
primitiveCache map[PdfModel]PdfObject
|
|
|
|
modelCache map[PdfObject]PdfModel
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewModelManager() *ModelManager {
|
|
|
|
mm := ModelManager{}
|
|
|
|
mm.primitiveCache = map[PdfModel]PdfObject{}
|
|
|
|
mm.modelCache = map[PdfObject]PdfModel{}
|
|
|
|
return &mm
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register (cache) a model to primitive relationship.
|
2016-09-09 15:02:52 +00:00
|
|
|
func (this *ModelManager) Register(primitive PdfObject, model PdfModel) {
|
2016-09-08 17:53:45 +00:00
|
|
|
this.primitiveCache[model] = primitive
|
|
|
|
this.modelCache[primitive] = model
|
|
|
|
}
|
|
|
|
|
2016-09-09 15:02:52 +00:00
|
|
|
func (this *ModelManager) GetPrimitiveFromModel(model PdfModel) PdfObject {
|
2016-09-08 17:53:45 +00:00
|
|
|
primitive, has := this.primitiveCache[model]
|
|
|
|
if !has {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return primitive
|
|
|
|
}
|
|
|
|
|
2016-09-09 15:02:52 +00:00
|
|
|
func (this *ModelManager) GetModelFromPrimitive(primitive PdfObject) PdfModel {
|
2016-09-08 17:53:45 +00:00
|
|
|
model, has := this.modelCache[primitive]
|
|
|
|
if !has {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return model
|
|
|
|
}
|
2016-09-11 23:17:38 +00:00
|
|
|
*/
|