-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathAI2ASS UI.coffee
81 lines (67 loc) · 2.52 KB
/
AI2ASS UI.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
dlgRes = "Group { orientation:'column', alignChildren: ['fill', 'fill'], \
output: Panel { orientation:'column', text: 'ASS Output', \
edit: EditText {text: 'have ass, will typeset', properties: {multiline: true}, alignment: ['fill', 'fill'], preferredSize: [-1, 100] } \
}, \
outputFormat: Panel { orientation:'column', text: 'Output Format', \
clip: Group {orientation: 'row', alignChildren: ['fill', 'fill'], spacing: 5, \
noclip: RadioButton {text: 'Drawing', value: true}, \
clip: RadioButton {text: '\\\\clip'}, \
iclip: RadioButton {text: '\\\\iclip'}, \
bare: RadioButton {text: 'Bare'}, \
line: RadioButton {text: 'Line'} \
}, \
}, \
settings: Panel {orientation: 'column', alignChildren: ['left','fill'], text: 'Settings', \
collectionTarget: DropDownList {title: 'Collection Target:'}, \
pathCombining: DropDownList {title: 'Path Combining:'} \
}, \
export: Button {text: 'Export'} \
}"
win = new Window "palette", "Export ASS" , undefined, {}
dlg = win.add dlgRes
outputFormats = {
"Drawing:": "noclip"
"\\clip": "clip"
"\\iclip": "iclip"
"Bare": "bare"
"Line": "line"
}
exportMethods = {
"Active Layer": "collectActiveLayer"
"Non-Empty Layers": "collectAllLayers"
"All Layers": "collectAllLayersIncludeEmpty"
}
dlg.settings.collectionTarget.add "item", k for k, v of exportMethods
dlg.settings.collectionTarget.selection = 0
pathCombiningStrategies = {
"Disabled": "off"
"Safe (Maintain Order)": "safe"
"Ignore Blending Order": "any"
}
dlg.settings.pathCombining.add "item", k for k, v of pathCombiningStrategies
dlg.settings.pathCombining.selection = 1
bt = new BridgeTalk
bt.target = "illustrator"
backendScript = ai2assBackend.toString()
radioString = ( radioGroup ) ->
for child in radioGroup.children
if child.value
return outputFormats[child.text]
objToString = (obj) ->
fragments = ("#{k}: \"#{v}\"" for k, v of obj).join ", "
return "{#{fragments}}"
dlg.export.onClick = ->
dlg.output.edit.active = false
options = objToString {
method: exportMethods[dlg.settings.collectionTarget.selection.text]
wrapper: radioString dlg.outputFormat.clip
combineStrategy: pathCombiningStrategies[dlg.settings.pathCombining.selection.text]
}
bt.body = "(#{backendScript})(#{options});"
bt.onResult = ( result ) ->
dlg.output.edit.text = result.body.replace( /\\\\/g, "\\" ).replace /\\n/g, "\n"
dlg.output.edit.active = true
bt.onError = ( err ) ->
alert "#{err.body} (#{a.headers["Error-Code"]})"
bt.send( )
win.show( )