github.com/boki/go-xmp@v1.0.1/models/xmp_tpg/types.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  	"trimmer.io/go-xmp/xmp"
    21  )
    22  
    23  // Part 2: 1.2.2.2 Dimensions
    24  //
    25  // Default dimensions
    26  // Letter       612x792
    27  // LetterSmall  612x792
    28  // Tabloid      792x1224
    29  // Ledger       1224x792
    30  // Legal        612x1008
    31  // Statement    396x612
    32  // Executive    540x720
    33  // A0           2384x3371
    34  // A1           1685x2384
    35  // A2           1190x1684
    36  // A3           842x1190
    37  // A4           595x842
    38  // A4Small      595x842
    39  // A5           420x595
    40  // B4           729x1032
    41  // B5           516x729
    42  // Envelope     ???x???
    43  // Folio        612x936
    44  // Quarto       610x780
    45  // 10x14        720x1008
    46  type Dimensions struct {
    47  	H    float32 `xmp:"stDim:h,attr"`
    48  	W    float32 `xmp:"stDim:w,attr"`
    49  	Unit Unit    `xmp:"stDim:unit,attr"`
    50  }
    51  
    52  func (x Dimensions) IsZero() bool {
    53  	return x.H == 0 && x.W == 0 && x.Unit == ""
    54  }
    55  
    56  func (x Dimensions) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error {
    57  	if x.IsZero() {
    58  		return nil
    59  	}
    60  	type _t Dimensions
    61  	return e.EncodeElement(_t(x), node)
    62  }
    63  
    64  type Unit string
    65  
    66  const (
    67  	UnitInch       Unit = "inch"
    68  	UnitMillimeter Unit = "mm"
    69  	UnitPixel      Unit = "pixel"
    70  	UnitPica       Unit = "pica"
    71  	UnitPoint      Unit = "point"
    72  )
    73  
    74  // Part 2: 1.2.2.3 Font
    75  type Font struct {
    76  	ChildFontFiles xmp.StringArray `xmp:"stFnt:childFontFiles"`
    77  	Composite      xmp.Bool        `xmp:"stFnt:composite,attr"`
    78  	FontFace       string          `xmp:"stFnt:fontFace,attr"`
    79  	FontFamily     string          `xmp:"stFnt:fontFamily,attr"`
    80  	FontFileName   string          `xmp:"stFnt:fontFileName,attr"`
    81  	FontName       string          `xmp:"stFnt:fontName,attr"`
    82  	FontType       FontType        `xmp:"stFnt:fontType,attr"`
    83  	VersionString  string          `xmp:"stFnt:versionString,attr"`
    84  }
    85  
    86  type FontType string
    87  
    88  const (
    89  	FontTypeTrueType FontType = "TrueType"
    90  	FontTypeType1    FontType = "Type 1"
    91  	FontTypeOpenType FontType = "Open Type"
    92  )
    93  
    94  type FontArray []Font
    95  
    96  func (x FontArray) Typ() xmp.ArrayType {
    97  	return xmp.ArrayTypeUnordered
    98  }
    99  
   100  func (x FontArray) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error {
   101  	return xmp.MarshalArray(e, node, x.Typ(), x)
   102  }
   103  
   104  func (x *FontArray) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error {
   105  	return xmp.UnmarshalArray(d, node, x.Typ(), x)
   106  }
   107  
   108  // Part 2: 1.2.2.1 Colorant
   109  type Colorant struct {
   110  	A          int64        `xmp:"xmpG:A,attr"`
   111  	B          int64        `xmp:"xmpG:B,attr"`
   112  	L          float64      `xmp:"xmpG:L,attr"`
   113  	Black      float64      `xmp:"xmpG:black,attr"`
   114  	Cyan       float64      `xmp:"xmpG:cyan,attr"`
   115  	Magenta    float64      `xmp:"xmpG:magenta,attr"`
   116  	Yellow     float64      `xmp:"xmpG:yellow,attr"`
   117  	Blue       int64        `xmp:"xmpG:blue,attr"`
   118  	Green      int64        `xmp:"xmpG:green,attr"`
   119  	Red        int64        `xmp:"xmpG:red,attr"`
   120  	Mode       ColorantMode `xmp:"xmpG:mode,attr"`
   121  	SwatchName string       `xmp:"xmpG:swatchName,attr"`
   122  	Type       ColorType    `xmp:"xmpG:type,attr"`
   123  }
   124  
   125  func (x Colorant) IsZero() bool {
   126  	return x.A == 0 && x.B == 0 && x.L == 0 &&
   127  		x.Black == 0 && x.Cyan == 0 && x.Magenta == 0 && x.Yellow == 0 &&
   128  		x.Blue == 0 && x.Green == 0 && x.Red == 0 && x.Mode == "" && x.Type == "" &&
   129  		x.SwatchName == ""
   130  }
   131  
   132  func (x Colorant) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error {
   133  	if x.IsZero() {
   134  		return nil
   135  	}
   136  	type _t Colorant
   137  	return e.EncodeElement(_t(x), node)
   138  }
   139  
   140  type ColorantMode string
   141  
   142  const (
   143  	ColorantModeCMYK ColorantMode = "CMYK"
   144  	ColorantModeRGB  ColorantMode = "RGB"
   145  	ColorantModeLAB  ColorantMode = "LAB"
   146  )
   147  
   148  type ColorType string
   149  
   150  const (
   151  	ColorTypeProcess ColorType = "PROCESS"
   152  	ColorTypeSpot    ColorType = "SPOT"
   153  )
   154  
   155  type ColorantList []Colorant
   156  
   157  func (x ColorantList) Typ() xmp.ArrayType {
   158  	return xmp.ArrayTypeOrdered
   159  }
   160  
   161  func (x ColorantList) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error {
   162  	return xmp.MarshalArray(e, node, x.Typ(), x)
   163  }
   164  
   165  func (x *ColorantList) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error {
   166  	return xmp.UnmarshalArray(d, node, x.Typ(), x)
   167  }
   168  
   169  type SwatchGroup struct {
   170  	GroupName string       `xmp:"xmpG:groupName"`
   171  	GroupType int          `xmp:"xmpG:groupType"`
   172  	Colorants ColorantList `xmp:"xmpG:Colorants"`
   173  }
   174  
   175  type SwatchGroupList []SwatchGroup
   176  
   177  func (x SwatchGroupList) Typ() xmp.ArrayType {
   178  	return xmp.ArrayTypeOrdered
   179  }
   180  
   181  func (x SwatchGroupList) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error {
   182  	return xmp.MarshalArray(e, node, x.Typ(), x)
   183  }
   184  
   185  func (x *SwatchGroupList) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error {
   186  	return xmp.UnmarshalArray(d, node, x.Typ(), x)
   187  }