github.com/boki/go-xmp@v1.0.1/xmp/sdk.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  // Package xmp implements the Extensible Metadata Platform (XMP) defined in ISO 16684-1:2011(E).
    16  package xmp // import "trimmer.io/go-xmp/xmp"
    17  
    18  import (
    19  	"encoding/xml"
    20  	"strings"
    21  )
    22  
    23  const XMP_TOOLKIT_VERSION = "Go XMP SDK 1.0"
    24  
    25  var Agent AgentName = XMP_TOOLKIT_VERSION
    26  
    27  func SetAgent(org, software, version, extra string) {
    28  	Agent = AgentName(strings.Join([]string{org, software, version, extra}, " "))
    29  }
    30  
    31  var (
    32  	// Core XMP namespaces
    33  	nsX   = &Namespace{"x", "adobe:ns:meta/", nil}
    34  	nsXML = &Namespace{"xml", "http://www.w3.org/XML/1998/namespace", nil}
    35  	nsRDF = &Namespace{"rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", nil}
    36  
    37  	// Common Structures
    38  	nsStArea = &Namespace{"stArea", "http://ns.adobe.com/xmp/sType/Area#", nil}
    39  
    40  	// private resources
    41  	emptyName       = xml.Name{}
    42  	rdfResourceAttr = Attr{Name: xml.Name{Local: "rdf:parseType"}, Value: "Resource"}
    43  	rdfDescription  = xml.Name{Local: "rdf:Description"}
    44  	aboutAttr       = Attr{Name: xml.Name{Local: "rdf:about"}, Value: ""}
    45  )
    46  
    47  var (
    48  	xmp_packet_header    = []byte("<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n")
    49  	xmp_packet_footer    = []byte("\n<?xpacket end=\"w\"?>")
    50  	xmp_packet_footer_ro = []byte("\n<?xpacket end=\"r\"?>")
    51  )
    52  
    53  func init() {
    54  	for _, v := range []*Namespace{
    55  		nsX,
    56  		nsXML,
    57  		nsRDF,
    58  		nsStArea,
    59  	} {
    60  		NsRegistry.RegisterNamespace(v, nil)
    61  	}
    62  }