Created
October 9, 2010 12:28
-
-
Save osima/618142 to your computer and use it in GitHub Desktop.
Hello World! の idml パッケージを生成する groovy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Hello World! の idml パッケージを生成する groovy. | |
| // | |
| import groovy.xml.MarkupBuilder | |
| import groovy.xml.MarkupBuilderHelper | |
| ENC = 'UTF-8' | |
| NS = 'http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging' | |
| createXml = { | |
| def xml = new MarkupBuilder(it) | |
| xml.doubleQuotes = true | |
| new MarkupBuilderHelper(xml).xmlDeclaration(version:'1.0',encoding:ENC) | |
| xml | |
| } | |
| output = { writer,f-> | |
| w = f.newWriter(ENC) | |
| w.print writer.toString() | |
| w.close() | |
| } | |
| // 0) ディレクトリの用意 | |
| dirStories = new File('Stories') | |
| dirStories.mkdir() | |
| dirSpreads = new File('Spreads') | |
| dirSpreads.mkdir() | |
| // 1) Story | |
| writer = new StringWriter() | |
| createXml(writer).'idPkg:Story'('xmlns:idPkg': NS , DOMVersion:'6.0') { | |
| Story(Self:'story1'){ | |
| Content('Hello World!') | |
| } | |
| } | |
| output( writer,new File(dirStories,'Story_story1.xml') ) | |
| // 2) Spread | |
| writer = new StringWriter() | |
| createXml(writer).'idPkg:Spread'('xmlns:idPkg': NS, DOMVersion:'6.0') { | |
| Spread(Self:'spred_1',PageCount:'1',ItemTransform:'1 0 0 1 0 0'){ | |
| TextFrame(Self:'textframe1',ParentStory:'story1',ContentType:'TextType',ItemTransform:'1 0 0 1 -612 -396'){ | |
| Properties(){ | |
| PathGeometry(){ | |
| GeometryPath(PathOpen:'false'){ | |
| PathPointArray(){ | |
| def rect = new java.awt.Rectangle(36,36,172-36,186-36) | |
| def v = null | |
| v = "${rect.@x} ${rect.@y}" | |
| PathPoint(Anchor:v, LeftDirection:v, RightDirection:v) | |
| v = "${rect.@x} ${rect.@y+rect.@height}" | |
| PathPoint(Anchor:v, LeftDirection:v, RightDirection:v) | |
| v = "${rect.@x+rect.@width} ${rect.@y+rect.@height}" | |
| PathPoint(Anchor:v, LeftDirection:v, RightDirection:v) | |
| v = "${rect.@x+rect.@width} ${rect.@y}" | |
| PathPoint(Anchor:v, LeftDirection:v, RightDirection:v) | |
| } } } } } } } | |
| output( writer,new File(dirSpreads,'Spread_spread1.xml') ) | |
| // 3) designmap.xml | |
| writer = new StringWriter() | |
| xml = createXml(writer) | |
| new MarkupBuilderHelper(xml).pi('aid':[style:'50', type:'document', readerVersion:'6.0', featureSet:'257']) | |
| xml.'Document'('xmlns:idPkg': NS, DOMVersion:'6.0', Self:'d') { | |
| 'idPkg:Spread'(src:'Spreads/Spread_spread1.xml') | |
| 'idPkg:Story'(src:'Stories/Story_story1.xml') | |
| } | |
| output( writer, new File('designmap.xml') ) | |
| // 4) mimetype | |
| w = new File('mimetype').newWriter(ENC) | |
| w.print 'application/vnd.adobe.indesign-idml-package' | |
| w.close() | |
| // 5) zip | |
| // TODO 本来は mimetype ファイルのみ uncompress で格納すればよいのだが、とりあえず全部を uncompress で格納. | |
| new AntBuilder().zip(destfile:'helloworld.idml', basedir:'.', compress:'false'){ | |
| patternset { | |
| include(name: '**/*.xml') | |
| include(name: 'mimetype') | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment