added chapter about fonts.
[swftools.git] / doc / swfc.xml
1 <?xml version='1.0'?>
2 <guide>
3     
4 <title>SWFC Manual</title>
5
6 <abstract>
7 swfc is a tool for generating flash files. You can write small simple scripts
8 and then have them compiled to SWF Flash Animations.
9 </abstract>
10
11
12 <!--
13
14 This comment aims to give a short overview over the tags defined in guide.xslt.
15 Most are like html.
16
17 Markups and Highlights:
18
19     <i>italic</i>
20     <b>bold</b>
21     <ul>Underline</ul>
22
23     <f>filename or pathname</f>
24     <c>variable name, command</c> ("c" stands for "code")
25
26 Paragraphs:
27
28     <p>
29     Paragraph
30     </p>
31
32 Line breaking:
33
34     <br/>
35
36 Links:
37
38     <uri>http://www.quiss.org</uri> OR
39     <uri link=http://www.quiss.org>Quiss</uri>
40
41 Shell scripts, commands to execute:
42
43     <shell>tail /var/log/messages</shell>
44
45 Code:
46     
47     <code lang="sc">   (The lang= is optional)
48         .flash
49             .box b1 100 100
50         .end
51     </code>
52
53 Tables:
54
55     <table>
56     <tr><td>Apples</td><td>Pears</td></tr>
57     <tr><td>3</td><td>4</td></tr>
58     </table>
59
60 Boxes:
61     <note>
62     Something interesting
63     </note>
64
65     <impo>
66     Something important
67     </impo>
68     
69     <warn>
70     Something to be careful about
71     </warn>
72
73 -->
74
75 <chapter><title>swfc Basics</title>
76
77  <section><title>Calling swfc</title>
78
79  <p>
80
81   swfc is command line based. You call it via
82
83   <shell>$ swfc file.sc</shell>
84
85   The filename of what is generated depends on the filename of the script (<f>file.sc</f>),
86   the filename given inside the script, and the optional <c>-o</c> passed to swfc.
87
88  </p>
89
90  <note>
91   Though swfc is a command-line utility, there also exists a nice graphical
92   frontend for it, called <uri link="http://www.ucolick.de/~de/Snarf/quiss">Swifty</uri>.
93  </note>
94
95  </section>
96
97  <section><title>A simple swfc example</title>
98
99   <p>
100    Let's create simple SWF file, shall we?
101    The following script creates a red box with a yellow border. On the right side you
102    see the script used, on the left side the swf file that is generated.
103   </p>
104
105   <code lang="swfc">
106 .flash name="box.swf"
107     .box b1 100 100 color=yellow fill=red
108     .put b1 pin=center scale=0%
109     .frame 100
110     .change b1 pin=center scale=100%
111     .frame 200
112     .change b1 pin=center scale=0%
113 .end
114   </code>
115
116   The <c>.box</c> command creates the box. Every object that is created must also be explicitly
117   put into the scene using <c>.put</c> to become visible.
118
119  </section>
120  
121  <section><title>Color transforms</title>
122
123   <code lang="swfc">
124 .flash name="cxform.swf" version=5
125     
126     .jpeg s1 "photo.jpeg" quality=80%
127
128     .put s1 x=50 y=50 scalex=110 scaley=110
129     .frame 100
130     .change s1 x=0 y=0 scalex=210 scaley=210 red=-1+255 green=-1+255 blue=-1+255 #invert
131     .frame 200
132     .change s1 x=100 y=50 scalex=110 scaley=110 red=0 green=+0 blue=+0 #remove red
133     .frame 300
134     .change s1 x=0 y=0 scalex=210 scaley=210 red=+0 green=2 blue=-1+255 #amplify green, invert blue
135     .frame 400
136     .change s1 x=50 y=100 scalex=110 scaley=110 red=2-128 green=-2+255 blue=+0.7+40 #alien glow
137     .frame 500
138     .change s1 x=0 y=0 scalex=210 scaley=210 red=8-1024 green=8-1024 blue=8-1024 #palette reduce
139     .frame 600
140     .change s1 x=0 y=0 scalex=210 scaley=210 red=+0 green=+0 blue=+0 #back to normal
141     .frame 700
142     .change s1 x=105 y=105 scalex=0 scaley=0 luminance=0 #fadeout
143 .end
144   </code>
145  
146  </section>
147  
148
149 </chapter>
150
151 <chapter><title>Fonts</title>
152
153 <section>
154
155 swfc has font support. That means you can also insert texts into
156 your animations.
157 The easiest way to load a font is to do something like
158 <c>
159     .font Arial filename="Arial.ttf"
160 </c>
161 .
162 You now have a font named <c>Arial</c> to play with.
163 For example, for the obligatory hello world program:
164
165   <code lang="swfc">
166 .flash name="helloworld.swf"
167     
168     .font Arial filename="Arial.ttf"
169     .text helloworld font=Arial text="Hello World!"
170     .put helloworld
171 .end
172   </code>
173
174 Besides TrueType fonts, swfc also supports native SWF fonts.
175 If you have a SWF with a font you would like to use, do a 
176 <shell>
177     swfextract file.swf
178 </shell>
179 Then write down the font ID of the font, and do a
180 <shell>
181     swfextract -f <fontid> file.swf -o myfont.swf
182 </shell>
183 .
184 This will give you a file named myfont.swf which you can
185 also use in the <c>filename</c> parameter of <c>.font</c>.
186
187 </section>
188 <section>
189 <p>
190 So much for the basics. Now let's go to the more advanced
191 functionality.
192 </p>
193
194 <p>
195 Apart from being able to define text in your swfc files,
196 you can also define text <c>outlines</c>. 
197 Those are not real characters but rather abstract vector 
198 objects which you can use in other commands.
199 </p>
200
201 <code lang="swfc">
202 .flash name="fontoutline.swf"
203     .font Arial "Arial.swf"
204     .textshape helloworld font="arial" text="Hello World"
205     .filled filled_helloworld outline=helloworld fill=blue line=5 color=green
206     .put filled_helloworld
207 .end
208 </code>
209
210 Here, <c>.textshape helloworld</c> defines an outline named "helloworld",
211 which is then used to construct a filled outline named filled_helloworld.
212
213 To make this a little more interesting, let's fill with a gradient instead
214 of a plain color:
215
216 <code lang="swfc">
217 .flash name="fontgradient.swf"
218     .font Arial "Arial.swf"
219     .textshape helloworld font="arial" text="Hello World"
220     
221     .gradient whitefade:
222         0% black
223         50% #505050
224         100% yellow
225     .end
226
227     .filled filled_helloworld outline=helloworld fill=blue line=5 color=green
228     .put filled_helloworld
229 .end
230 </code>
231
232 But let's get back to normal <c>.text</c> characters.
233 The following demonstrates that you can treat objects defined
234 with <c>.text</c> like normal shapes, i.e., scale them, move them, and use
235 them for clipping:
236
237   <code lang="swfc">
238 .flash name="text5.swf"
239 .font courier "Courier.swf"
240 .font helvetica "Helvetica.swf"
241 .text hithere text="HELLO" font=courier size=50%
242 .swf scene Scenery50.swf
243
244 .frame 0
245     .startclip hithere pin=center x=100 y=75 scale=50% #text clips...
246         .put scene # ...the image "scene"
247     .end
248 .frame 100
249      .change hithere rotate+=360 pin=center scale=100%
250
251 .end
252   </code>
253
254 Also, <c>.text</c> takes a color attribute (that's actually
255 the poor man's version of the more advanced filling options
256 that <c>.textshape</c> in conjunction with <c>.filled</c> offers),
257 which is used here together with the alpha parameter of <c>.change</c>:
258
259   <code lang="swfc">
260 .flash name="text6.swf"
261 .font courier "Courier.swf"
262 .font helvetica "Helvetica.swf"
263 .text hello text="HELLO" font=helvetica size=50% color=blue
264 .text world text="WORLD" font=helvetica size=50% color=red
265
266 .frame 0
267         .put hello pin=center x=50 y=50 
268         .put world pin=center x=50 y=50 alpha=25%
269 .frame 200
270      .change hello rotate+=360 pin=center alpha=25% 
271      .change world rotate-=360 pin=center alpha=100% 
272 .end
273   </code>
274  
275  </section>
276
277
278
279 </section>
280
281
282
283
284 </chapter>
285
286
287 </guide>