github.com/boki/go-xmp@v1.0.1/models/xmp_tpg/model.go (about)

     1  // Copyright (c) 2017-2018 Alexander Eichhorn
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  //
    15  
    16  // Package xmptpg implements the XMP Paged Text namespace as defined by XMP Specification Part 2.
    17  package xmptpg
    18  
    19  import (
    20  	"fmt"
    21  	"trimmer.io/go-xmp/xmp"
    22  )
    23  
    24  var (
    25  	NsXmpTPg = xmp.NewNamespace("xmpTPg", "http://ns.adobe.com/xap/1.0/t/pg/", NewModel)
    26  	nsStDim  = xmp.NewNamespace("stDim", "http://ns.adobe.com/xap/1.0/sType/Dimensions#", nil)
    27  	nsStFnt  = xmp.NewNamespace("stFnt", "http://ns.adobe.com/xap/1.0/sType/Font#", nil)
    28  )
    29  
    30  func init() {
    31  	xmp.Register(NsXmpTPg, xmp.XmpMetadata)
    32  	xmp.Register(nsStDim)
    33  	xmp.Register(nsStFnt)
    34  }
    35  
    36  func NewModel(name string) xmp.Model {
    37  	return &PagedText{}
    38  }
    39  
    40  func MakeModel(d *xmp.Document) (*PagedText, error) {
    41  	m, err := d.MakeModel(NsXmpTPg)
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  	x, _ := m.(*PagedText)
    46  	return x, nil
    47  }
    48  
    49  func FindModel(d *xmp.Document) *PagedText {
    50  	if m := d.FindModel(NsXmpTPg); m != nil {
    51  		return m.(*PagedText)
    52  	}
    53  	return nil
    54  }
    55  
    56  type PagedText struct {
    57  	Colorants              ColorantList    `xmp:"xmpTPg:Colorants"`
    58  	Fonts                  FontArray       `xmp:"xmpTPg:Fonts"`
    59  	MaxPageSize            Dimensions      `xmp:"xmpTPg:MaxPageSize"`
    60  	NPages                 int64           `xmp:"xmpTPg:NPages,attr"`
    61  	PlateNames             xmp.StringArray `xmp:"xmpTPg:PlateNames"`
    62  	HasVisibleTransparency xmp.Bool        `xmp:"xmpTPg:HasVisibleTransparency"`
    63  	HasVisibleOverprint    xmp.Bool        `xmp:"xmpTPg:HasVisibleOverprint"`
    64  	SwatchGroups           SwatchGroupList `xmp:"xmpTPg:SwatchGroups"`
    65  }
    66  
    67  func (x PagedText) Can(nsName string) bool {
    68  	return NsXmpTPg.GetName() == nsName
    69  }
    70  
    71  func (x PagedText) Namespaces() xmp.NamespaceList {
    72  	return xmp.NamespaceList{NsXmpTPg}
    73  }
    74  
    75  func (x *PagedText) SyncModel(d *xmp.Document) error {
    76  	return nil
    77  }
    78  
    79  func (x *PagedText) SyncFromXMP(d *xmp.Document) error {
    80  	return nil
    81  }
    82  
    83  func (x PagedText) SyncToXMP(d *xmp.Document) error {
    84  	return nil
    85  }
    86  
    87  func (x *PagedText) CanTag(tag string) bool {
    88  	_, err := xmp.GetNativeField(x, tag)
    89  	return err == nil
    90  }
    91  
    92  func (x *PagedText) GetTag(tag string) (string, error) {
    93  	if v, err := xmp.GetNativeField(x, tag); err != nil {
    94  		return "", fmt.Errorf("%s: %v", NsXmpTPg.GetName(), err)
    95  	} else {
    96  		return v, nil
    97  	}
    98  }
    99  
   100  func (x *PagedText) SetTag(tag, value string) error {
   101  	if err := xmp.SetNativeField(x, tag, value); err != nil {
   102  		return fmt.Errorf("%s: %v", NsXmpTPg.GetName(), err)
   103  	}
   104  	return nil
   105  }