forked from fontforge/fontforge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
python.html
5358 lines (5349 loc) · 189 KB
/
python.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<HTML>
<HEAD>
<!-- Created with AOLpress/2.0 -->
<!-- AP: Created on: 6-Apr-2007 -->
<!-- AP: Last modified: 28-Apr-2010 -->
<TITLE>Writing python scripts to change fonts in FontForge</TITLE>
<LINK REL="icon" href="fftype16.png">
<LINK REL="stylesheet" TYPE="text/css" HREF="FontForge.css">
</HEAD>
<BODY>
<DIV id="in">
<H1 ALIGN=Center>
Writing python scripts to change fonts in FontForge
</H1>
<P>
I assume you have a working knowledge of <A href="http://www.python.org/doc/">Python</A>.
FontForge implements two Python modules -- one great huge one
called <CODE><A HREF="python.html#fontforge">fontforge</A></CODE> which provides
access to as much of FontForge's functionality as I've had time to write,
and one tiny one called
<CODE><A HREF="python.html#psMat">psMat</A></CODE> which provides quick access
to some useful transformations expressed as PostScript matrices.
<P>
In python terms fontforge <EM>embeds</EM> python. It is possible to build
fontforge so that it is also a <A HREF="#Extension">python <EM>extension</EM>
</A>(<CODE>configure --enable-pyextension</CODE>)
<P>
The fontforge module also defines several types
<UL>
<LI>
<A href="#Point">point</A>
<LI>
<A href="#Contour">contour</A>
<LI>
<A href="#Layer">layer</A>
<LI>
<A href="#GlyphPen">glyphPen</A>
<LI>
<A href="#Glyph">glyph</A>
<LI>
<A href="#selection">selection</A>
<LI>
<A HREF="#private">private</A>
<LI>
<A HREF="#math">math</A>
<LI>
<A href="#Font">font</A>
</UL>
<H2>Command line convenience</H2>
<P>For convenience, Python commands given as a <CODE>-c</CODE> argument on the command line have the following code prepended:
<BLOCKQUOTE>
<PRE>from sys import argv; from fontforge import *</PRE>
</BLOCKQUOTE>
<P>Hence, the trivial script to convert a font can be written:
<BLOCKQUOTE>
<PRE>fontforge -c 'open(argv[1]).generate(argv[2])'</PRE>
</BLOCKQUOTE>
<TABLE id="module" border=1>
<CAPTION>
<A NAME="psMat">psMat</A>
</CAPTION>
<TR>
<TH span=3>Methods</TH>
</TR>
<TR>
<TH>method</TH>
<TH>args</TH>
<TH>comments</TH>
</TR>
<TR>
<TD><CODE>identity</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>returns an identity matrix as a 6 element tuple</TD>
</TR>
<TR>
<TD><CODE>compose</CODE></TD>
<TD><CODE>(mat1,mat2)</CODE></TD>
<TD>returns a matrix which is the composition of the two input transformations</TD>
</TR>
<TR>
<TD><CODE>inverse</CODE></TD>
<TD><CODE>(mat)</CODE></TD>
<TD>returns a matrix which is the inverse of the input transformation. (Note:
There will not always be an inverse)</TD>
</TR>
<TR>
<TD><CODE>rotate</CODE></TD>
<TD><CODE>(theta)</CODE></TD>
<TD>returns a matrix which will rotate by <CODE>theta</CODE>.
<CODE>Theta</CODE> is expressed in radians</TD>
</TR>
<TR>
<TD><CODE>scale</CODE></TD>
<TD><CODE>(x[,y])</CODE></TD>
<TD>returns a matrix which will scale by <CODE>x</CODE> in the horizontal
direction and <CODE>y</CODE> in the vertical. If <CODE>y</CODE> is omitted,
it will scale by the same amount (<CODE>x</CODE>) in both directions</TD>
</TR>
<TR>
<TD><CODE>skew</CODE></TD>
<TD><CODE>(theta)</CODE></TD>
<TD>returns a matrix which will skew by <CODE>theta</CODE> (to produce a
oblique font). <CODE>Theta</CODE> is expressed in radians</TD>
</TR>
<TR>
<TD><CODE>translate</CODE></TD>
<TD><CODE>(x,y)</CODE></TD>
<TD>returns a matrix which will translate by <CODE>x</CODE> in the horizontal
direction and <CODE>y</CODE> in the vertical</TD>
</TR>
<TR>
<TH colspan=3>Types</TH>
</TR>
<TR>
<TD colspan=3>None</TD>
</TR>
</TABLE>
<P>
<TABLE id="module" border=1>
<CAPTION>
<A NAME="fontforge">fontforge</A>
</CAPTION>
<TR>
<TH colspan=3>Global Variables</TH>
</TR>
<TR>
<TH>variable</TH>
<TH colspan=2>comments</TH>
</TR>
<TR>
<TD><CODE><A NAME="module-hooks">hooks</A></CODE></TD>
<TD colspan=2>A dictionary which the user may fill to associate certain fontforge
events with a python function to be run when those events happen. The function
will be passed the font (or possibly glyph) for which the relevant event
occurred.
<TABLE BORDER CELLPADDING="2">
<CAPTION>
Hook names
</CAPTION>
<TR>
<TD>newFontHook</TD>
<TD>This function will be called when a new font has been created.</TD>
</TR>
<TR>
<TD>loadFontHook</TD>
<TD>This function will be called when a font is loaded from disk.<BR>
(if a font has an "initScriptString" entry in its persistent dictionary,
that script will be invoked before this function).</TD>
</TR>
</TABLE>
<P>
Other hooks are defined in a font's own
<A HREF="#font-temporary">temporary</A> and
<A HREF="#font-persistent">persistent</A> dictionaries.</TD>
</TR>
<TR>
<TH colspan=3>Methods</TH>
</TR>
<TR>
<TH>method</TH>
<TH>args</TH>
<TH>comments</TH>
</TR>
<TR>
<TD><CODE>getPrefs</CODE></TD>
<TD><CODE>(pref-name)</CODE></TD>
<TD>returns the value of the named preference item</TD>
</TR>
<TR>
<TD><CODE>setPrefs</CODE></TD>
<TD><CODE>(pref-name,value)</CODE></TD>
<TD>sets the value of the named preference item</TD>
</TR>
<TR>
<TD><CODE><A NAME="ff-hasSpiro">hasSpiro</A></CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns a boolean, <CODE>True</CODE> if Raph Levien's spiro package is
available for use in FontForge.</TD>
</TR>
<TR>
<TD><CODE>savePrefs</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Saves the current preference settings</TD>
</TR>
<TR>
<TD><CODE>loadPrefs</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Loads the user's default preference settings. Not done automatically
in a script.</TD>
</TR>
<TR>
<TD><CODE>defaultOtherSubrs</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Sets the type1 PostScript OtherSubrs to the default value</TD>
</TR>
<TR>
<TD><CODE>readOtherSubrsFile</CODE></TD>
<TD><CODE>(filename)</CODE></TD>
<TD>Sets the type1 PostScript OtherSubrs to the stuff found in the file.</TD>
</TR>
<TR>
<TD><CODE>loadEncodingFile</CODE></TD>
<TD><CODE>(filename[,encname])</CODE></TD>
<TD>Loads an encoding file, returns the name of the encoding or None.
When loading encodings in Unicode consortium format, an encname has to
be specefied or the encoding will be ignored and None will be
reterned.</TD>
</TR>
<TR>
<TD><CODE>loadNamelist</CODE></TD>
<TD><CODE>(filename)</CODE></TD>
<TD>Loads a namelist</TD>
</TR>
<TR>
<TD><CODE>loadNamelistDir</CODE></TD>
<TD><CODE>(dirname)</CODE></TD>
<TD>Loads all namelist files in the directory</TD>
</TR>
<TR>
<TD><CODE>loadPlugin</CODE></TD>
<TD><CODE>(filename)</CODE></TD>
<TD>Loads a fontforge plugin</TD>
</TR>
<TR>
<TD><CODE>loadPluginDir</CODE></TD>
<TD><CODE>(dirname)</CODE></TD>
<TD>Loads all fontforge plugins in the directory</TD>
</TR>
<TR>
<TD><CODE>preloadCidmap</CODE></TD>
<TD><CODE>(filename,registry,order,supplement)</CODE></TD>
<TD>Loads a fontforge cidmap file (first three args are strings, last is
an integer)</TD>
</TR>
<TR>
<TD><CODE><A name="printSetup">printSetup</A></CODE></TD>
<TD><CODE>(type[,printer|cmd|file,<BR>
width,height])</CODE></TD>
<TD>Prepare to <A href="#f-print">print a font sample</A>. The first argument
may be one of:
<DL>
<DT>
lp
<DD>
Queues postscript output to the printer using <CODE>lp</CODE>. You may use
the optional second argument to specify the printer name.
<DT>
lpr
<DD>
Queues postscript output to the printer using <CODE>lpr</CODE>. You may use
the optional second argument to specify the printer name.
<DT>
ghostview
<DD>
Displays the output using ghostview (or gv). The second argument is ignored.
<DT>
command
<DD>
Use a custom shell command to print the output. The second argument should
contain the command and its arguments.
<DT>
ps-file
<DD>
Dump the postscript output to a file. The second argument specifies the filename.
<DT>
pdf-file
<DD>
Dump the output as pdf to a file. The second argument specifies the filename.
</DL>
<P>
The third and fourth arguments are optional and specify the page size (in
points) for the output. The third argument is the page width and the fourth
is the height.
<P>
These setting remain until changed</TD>
</TR>
<TR>
<TD><CODE>nameFromUnicode</CODE></TD>
<TD><CODE>(uni[,namelist])</CODE></TD>
<TD>Finds the glyph name associated with a given unicode codepoint. If a
namelist is specified the name will be taken from that.</TD>
</TR>
<TR>
<TD><CODE>UnicodeAnnotationFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Returns the Unicode Annotations for this value as described by www.unicode.org.
If there is no unicode annotation for this value, or no library available,
then return empty string "". It can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>UnicodeBlockCountFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Return the number of Unicode Blocks as described by www.unicode.org.
Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
If there is no value, or no library available, then return -1.
This can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>UnicodeBlockEndFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Returns the Unicode Block end value as described by www.unicode.org.
Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
If there is no value, or no library available, then return -1.
This can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>UnicodeBlockNameFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Returns the Unicode Block Name as described by www.unicode.org.
Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
If there is no value, or no library available, then return empty string "".
This can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>UnicodeBlockStartFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Returns the Unicode Block start value as described by www.unicode.org.
Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
If there is no value, or no library available, then return -1.
This can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>unicodeFromName</CODE></TD>
<TD><CODE>(glyphname)</CODE></TD>
<TD>Looks up glyph name in its dictionary and if it is associated with a
unicode code point returns that number. Otherwise it returns -1</TD>
</TR>
<TR>
<TD><CODE>UnicodeNameFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Returns the Unicode Name for this value as described by www.unicode.org.
If there is no unicode name for this value, or no library available,
then return empty string "". It can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>UnicodeNamesListVersion</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Return the Unicode Nameslist Version (as described by www.unicode.org).
libuninameslist is released on a schedule that depends on
when www.unicode.org releases new information. These dates do not match
FontForge release dates, therefore users might not keep this optional library
upto current updates. This instruction can be used to test if the Nameslist
library is recent for your script. This function currently works only for
libuninameslist ver_0.3.20130501 or later, else it returns empty string "".
This can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>UnicodeNames2GetCntFromLib</CODE></TD>
<TD><CODE>()</CODE></TD>
Return the Total Count of all Names that were corrected with a new name.
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version.
If there is no libuninameslist ver 0.5 or later available, then return -1
</TR>
<TR>
<TD><CODE>UnicodeNames2GetNxtFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. With val==unicode value, this function
returns -1 if no Names2 exists, or the Nth table location for this
unicode value listed in libuninameslist that was corrected to a new name.
If there is no libuninameslist ver 0.5 or later, then return -1.
</TR>
<TR>
<TD><CODE>UnicodeNames2NxtUniFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. This function returns the Next Names2
listed in libuninameslist internal table that was corrected to a new name.
The internal table of Unicode values is of size UnicodeNames2GetCntFromLib().
If there is no libuninameslist ver 0.5 or later, then return -1.
</TR>
<TR>
<TD><CODE>UnicodeNames2FrmTabFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. This function returns the Next Names2
listed in libuninameslist internal table that was corrected to a new name.
The internal table of Unicode values is of size UnicodeNames2GetCntFromLib().
If there is no libuninameslist ver 0.5 or later, then return NULL.
<TR>
</TR>
<TD><CODE>UnicodeNames2FromLib</CODE></TD>
<TD><CODE>(val)</CODE></TD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. This function returns the Names2 or NULL
based on the unicode value given.
If there is no libuninameslist ver 0.5 or later, then return NULL.
</TR>
<TR>
<TD><CODE>IsFraction</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Return 1 if n is a unicode fraction (either a vulgar fraction or other
fraction) as described by www.unicode.org. Return 0 if there is no
fraction for this value. It can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>IsLigature</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Return 1 if n is a ligature as described by www.unicode.org. Return 0
if there is no unicode ligature for this value. It can execute with no
current font.</TD>
</TR>
<TR>
<TD><CODE>IsOtherFraction</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Return 1 if n is a unicode fraction (not defined as vulgar fraction)
as described by www.unicode.org. Return 0 if there is no fraction for
this value. It can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>IsVulgarFraction</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Return 1 if n is a unicode vulgar fraction as described by
www.unicode.org. Return 0 if there is no fraction for this value.
It can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>ucFracChartGetCnt</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns total count of Fractions found in the Unicode chart as
described by www.unicode.org. It can execute with no current font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>ucLigChartGetCnt</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns total count of Ligatures found in the Unicode chart as
described by www.unicode.org. It can execute with no current font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>ucLigChartGetLoc</CODE></TD>
<TD><CODE>(val)</CODE></TD>
<TD>Returns n for FontForge internal table Unicode val=Ligature[n]. If
val does not exist in table, then return -1. Can execute with no
current font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>ucLigChartGetNxt</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Returns FontForge internal table Unicode Ligature[n]. Return -1 if
n<0 or n>=ucLigChartGetCnt(). It can execute with no current font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>ucOFracChartGetCnt</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns total count of non-Vulgar Fractions found in the Unicode
chart as described by www.unicode.org. It can execute with no current
font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>ucOFracChartGetLoc</CODE></TD>
<TD><CODE>(val)</CODE></TD>
<TD>Returns n for FontForge internal table Unicode val=OtherFraction[n].
If val does not exist in table, then return -1. Can execute with no
current font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>ucOFracChartGetNxt</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Returns FontForge internal table Unicode (non-vulgar) Fraction[n].
Return -1 if n<0 or n>=ucOFracChartGetCnt(). Can execute with no
current font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>ucVulChartGetCnt</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns total count of Vulgar Fractions found in the Unicode chart
as described by www.unicode.org. It can execute with no current font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>ucVulChartGetLoc</CODE></TD>
<TD><CODE>(val)</CODE></TD>
<TD>Returns n for FontForge internal table Unicode val=VulgarFraction[n].
If val does not exist in table, then return -1. Can execute with no
current font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>ucVulChartGetNxt</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Returns FontForge internal table Unicode Vulgar Fraction[n]. Returns
-1 if n<0 or n>=ucVulChartGetCnt(). Can execute with no current font.
<BR>Note: Count depends on chart version built into FontForge.</TD>
</TR>
<TR>
<TD><CODE>SpiroVersion</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns the version of LibSpiro available to FontForge.<BR>
Versions 0.1 to 0.5 do not have a method to indicate version numbers,
but there is a limited method to estimate versions {'0.0'..'0.5'}.
<P>
'0.0' if FontForge has no LibSpiro available.<BR>
'0.1' if LibSpiro 20071029 is available.<BR>
'0.2' if LibSpiro 0.2 to 0.5 is available.<BR>
LibSpiro 0.6 and higher reports back it's version available.</TD>
</TR>
<TR>
<TD><CODE>version</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns fontforge's version number. This will be a large number like
20070406.</TD>
</TR>
<TR>
<TD><CODE>runInitScripts</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Runs the system or user initialization scripts, if not already run. This is primarily intended when importing FontForge into a python process.</TD>
</TR>
<TR>
<TD><CODE>scriptPath</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns a tuple listing the directory paths which are searched for python scripts during FontForge initialization.</TD>
</TR>
<TR>
<TD><CODE>fonts</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns a tuple of all fonts currently loaded into fontforge for editing</TD>
</TR>
<TR>
<TD><CODE>activeFont</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>If the script were invoked from the File->Execute Script... dialog,
or invoked by a menu item in the font view, this returns the font that was
active at the time. Otherwise it returns None.</TD>
</TR>
<TR>
<TD><CODE>activeGlyph</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>If the script were invoked from the File->Execute Script... dialog
or a menu item from an outline glyph window or a glyph import/export command
this returns the glyph that was active at the time. Otherwise it returns
None.</TD>
</TR>
<TR>
<TD><CODE>activeLayer</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>This returns the currently active layer as an integer between 0 (inclusive)
and the font/glyph's layer count (exclusive). It may also be set to -1 if
the current glyph window is displaying the font's guidline layer.</TD>
</TR>
<TR>
<TD><CODE>fontsInFile</CODE></TD>
<TD><CODE>(filename)</CODE></TD>
<TD>Returns a tuple of all fontnames found in the specified file. The tuple
may be empty if fontforge couldn't find any.</TD>
</TR>
<TR>
<TD><CODE>open</CODE></TD>
<TD><CODE>(filename[,flags])</CODE></TD>
<TD>Opens a filename and returns the font it contains. If it does.
<P>
If the flags argument is 4, then ff will load all glyphs in the 'glyf' table
of a ttc file (rather than just the glyphs used in the font picked). This
will not load all 'glyf' tables though.</TD>
</TR>
<TR>
<TD><CODE>parseTTInstrs</CODE></TD>
<TD><CODE>(string)</CODE></TD>
<TD>Returns a binary string each byte of which corresponds to a truetype
instruction. The input string should contain a set of instruction names as
"SRP0\nMIRP[min,rnd,black]"</TD>
</TR>
<TR>
<TD><CODE>unParseTTInstrs</CODE></TD>
<TD><CODE>(sequence)</CODE></TD>
<TD>Reverse of the above. Converts a binary string into a human (sort of)
readable string</TD>
</TR>
<TR>
<TD><CODE>unitShape</CODE></TD>
<TD><CODE>(n)</CODE></TD>
<TD>Returns a closed contour which is a regular n-gon. The contour will be
inscribed in the unit circle. If n is negative, then the contour will be
circumscribed around the unit circle. A value of 0 will produce a unit circle.
If n==1 it is treated as if n were -4 -- a circumscribed square where each
side is 2 units long (this is for historical reasons). Behavior is undefined
for n=2,-1,-2.</TD>
</TR>
<TR>
<TD><CODE>registerGlyphSeparationHook</CODE></TD>
<TD><CODE>(hook)</CODE></TD>
<TD>The GlpyphSeparationHook is a python routine which FontForge will call
when it wants to figure out the optical separation between two glyphs. If
you neve call this, or if you call it with a value of <CODE>None</CODE> FontForge
will use a built-in default. This routine gets called during AutoWidth, AutoKern,
and computing the optical left and right side bearings (for 'lfbd' and 'rtbd'
features). For more infomation see
<A HREF="autowidth.html#GlyphSeparationHook">its own section</A>.</TD>
</TR>
<TR>
<TH colspan=3>User Interface Methods</TH>
</TR>
<TR>
<TD colspan=3><A NAME="python-init-scripts">Users</A> may define scripts
to be run when menu items are invoked. Some of these scripts will want to
ask users questions, so this section provides routines to determine if fontforge
has a user interface, a command to add menu items, and various small standard
dialogs to interact with the user. I do not currently provide a mechanism
for allowing people to define special purpose dialogs (for example they might
want to ask more than one question in a dialog, and I don't support that).
<P>
When FontForge <A NAME="starts">starts</A> (if it's a fontforge with python)
it will look at the directories <CODE>$(PREFIX)/share/fontforge/python</CODE>
and <CODE>~/.FontForge/python</CODE> and attempt to run all files in those
directories which end in ".py". Presumably these files will allow people
to customize the user interface to suit their needs.
<P>
Currently it reads the files in directory order (which is generally somewhere
between creation order and totally random). It will read the system directory
before the user directory.
<H3>
Example
</H3>
<BLOCKQUOTE>
<PRE>import fontforge
def nameGlyph(junk,glyph):
print glyph.glyphname
fontforge.registerMenuItem(nameGlyph,None,None,"Glyph",None,"Print Glyph Name")
def neverEnableMe(junk,glyph):
return False
fontforge.registerMenuItem(nameGlyph,neverEnableMe,None,"Glyph",None,"SubMenu","Print Glyph Name")
def importGlyph(junk,glyph,filename,toback):
print "Import"
print glyph.glyphname
print filename
def exportGlyph(junk,glyph,filename):
print "Import"
print glyph.glyphname
print filename
fontforge.registerImportExport(importGlyph,exportGlyph,None,"foosball","foo","foo,foobar")
</PRE>
</BLOCKQUOTE>
<P>
The first call will define a menu item in the Tools menu of the Glyph window.
The menu will be called "Print Glyph Name". It has no shortcut to invoke
it. It needs no external data. It is always enabled. And when activated it
will invoke the function "nameGlyph" whch prints the name of the glyph in
the window from which the command is invoked.
<P>
The second call defines a menu item in a submenu of the Tools menu. This
submenu is called "SubMenu". This item will never be enabled -- but if it
were enabled it would again call "nameGlyph" to print the name of the current
glyph.
<P>
The last provides a way to import and export files of type "foosball" (or
it would if the routines did anything).
<P>
Not a very useful example</TD>
</TR>
<TR>
<TD><CODE>hasUserInterface</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns True if this session of FontForge has a user interface</TD>
</TR>
<TR>
<TD><CODE>registerMenuItem</CODE></TD>
<TD><CODE>(menu-function,<BR>
enable_function,<BR>
data,<BR>
which_window,<BR>
shortcut_string,<BR>
{submenu-names,}<BR>
menu-name-string)</CODE></TD>
<TD>If fontforge has a user interface this will add this menu item to FontForge's
<A HREF="toolsmenu.html#Tools">Tool</A> menu, either in the font or the outline
glyph view (or both).
<DL>
<DT>
menu-function
<DD>
This is the function that will be called when the menu item is activated.
It will be passed two arguments, the first is the data value specified here
(which may be None, indeed will probably usually be None), and the second
is the glyph or font (depending on the window type) from which the menu item
was activated. Its return value is ignored.
<DT>
enable_function
<DD>
This may be None -- in which case the menu item will always be enabled. Otherwise
it will be called before the menu pops up on the screen to determine whether
this item should be enabled. It will be passed the same arguments as above.
It should return True if the item should be enabled and False otherwise.
<DT>
data
<DD>
This can be whatever you want (including None). FontForge keeps track of
it and passes it to both of the above functions. Use it if you need to provide
some context for the menu item.
<DT>
which_window
<DD>
May be either of the strings "Font" or "Glyph (or the tuple
<CODE>("Font","Glyph")</CODE>) and it determines which type of window will
have this menu item in its "Tools" menu.
<DT>
shortcut-string
<DD>
May be None if you do not wish to supply a shortcut. Otherwise should be
a string like "Menu Name|Cntl-H" (the syntax is defined in the
<A HREF="uitranslationnotes.html#HotKeys">translation section</A>).
<DT>
submenu-names
<DD>
You may specify as many of these as you wish (including leaving them out
altogether), this allows you to organize the Tools menu into submenus. (If
a submenu of this name does not currently exist, fontforge will create it).
<DT>
menu-name
<DD>
The name that will appear in the menu for this item.
</DL>
<P>
This will only affect windows created after this command is executed. Normally
the command will be executed at startup and so it will affect all windows.</TD>
</TR>
<TR>
<TD><CODE>registerImportExport</CODE></TD>
<TD><CODE>(import-function,<BR>
export_function,<BR>
data,<BR>
name,<BR>
extension,<BR>
[extension-list])</CODE></TD>
<TD>This will add the capability to import or export files of a given type,
presumably a way of specifying the splines in a given glyph.
<DL>
<DT>
import-function
<DD>
The function to call to import a file into a glyph. It will be called with:
The data argument (specified below), A pointer to the glyph into which the
import is to happen, A filename, A flag indicating whether the import should
go to the background layer or foreground.
<P>
This function may be None. In which case there is no import method for this
file type.
<DT>
export-function
<DD>
The function to call to export a glyph into a file. It will be called with:
The data argument (see below), a pointer to the glyph, and a filename.
<P>
This function may be None, in which case there is no export method for this
file type.
<DT>
data
<DD>
Anything you like (including None). It will be passed to the import/export
routines and can provide them with context if they need that.
<DT>
name
<DD>
The name to be displayed in the user interface for this file type. This may
just be the extension, or it might be something more informative.
<DT>
extension
<DD>
This is the default extension for this file type. It is used by the export
dialog to pick an extension for the generated filename.
<DT>
extension-list
<DD>
Some file types have more than one common extension (eps files are usually
named "eps", but I have also seen "ps" and "art" used). The import dialog
needs to filter all possible filenames of this file type. This argument should
be a comma separated list of extensions. It may be omitted, in which case
it defaults to being the same as the "extension" argument above.
</DL>
</TD>
</TR>
<TR>
<TD><CODE>logWarning</CODE></TD>
<TD><CODE>(msg)</CODE></TD>
<TD>Adds the message (a string) to FontForge's Warnings window. (if you wish
to display a % character you must represent it as two percents). If there
is no user interface the output will go to stderr.</TD>
</TR>
<TR>
<TD><CODE>postError</CODE></TD>
<TD><CODE>(win-title,msg)</CODE></TD>
<TD>Creates a popup dialog to display the message (a string) in that dlg.
(if you wish to display a % character you must represent it as two percents).
If there is no user interface the output will go to stderr.</TD>
</TR>
<TR>
<TD><CODE>postNotice</CODE></TD>
<TD><CODE>(win-title,msg)</CODE></TD>
<TD>Creates a little window which will silently vanish after a minute or
two and displays the message (a string) in that window. (if you wish to display
a % character you must represent it as two percents). If there is no user
interface the output will go to stderr.</TD>
</TR>
<TR>
<TD><CODE>openFilename</CODE></TD>
<TD><CODE>(question,[def-name,[filter]])</CODE></TD>
<TD>All arguments are strings. The first is a question asked to the user
(for which a filename to open is presumed to be the answer). The second is
optional and provides a default filename. The third is optional and provides
a filter (like "*.sfd")
<P>
The result is either a filename or None if the user canceled the dialog.
<P>
Throws an exception if there is no user interface.</TD>
</TR>
<TR>
<TD><CODE>saveFilename</CODE></TD>
<TD><CODE>(question,[def-name,[filter]])</CODE></TD>
<TD>All arguments are strings. The first is a question asked to the user
(for which a filename to save something to is presumed to be the answer).
The second is optional and provides a default filename. The third is optional
and provides a filter (like "*.sfd")
<P>
The result is either a filename or None if the user canceled the dialog.
<P>
Throws an exception if there is no user interface.</TD>
</TR>
<TR>
<TD><CODE>ask</CODE></TD>
<TD><CODE>(title,question,answers,<BR>
[def,cancel])</CODE></TD>
<TD>Allows you to ask the user a multiple choice question. It popups up a
dialog posing the question with a list of buttons ranged underneath it --
one for each answer.
<P>
The first argument is the dialog's title, the second is the question to be
asked, the third is a tuple of strings -- each string will become a button,
the fourth and fifth arguments are option, the fourth is the index in the
answer array that will be the default answer (the one invoked if the user
presses the [Return] key), and the fifth is the answer invoked if the user
presses the [Escape] key. If omitted the default answer will be the first,
and the cancel answer will be the last.
<P>
The function returns the index in the answer array of the answer choosen
by the user.
<P>
Throws an exception if there is no user interface.</TD>
</TR>
<TR>
<TD><CODE>askChoice</CODE>s</TD>
<TD><CODE>(title,question,answers,<BR>
[def])</CODE></TD>
<TD>Similar to the above allows you to ask the user a multiple choice question.
It popups up a dialog posing the question with a scrollable list of choices
-- one for each answer.
<P>
The first argument is the dialog's title, the second is the question to be
asked, the third is a tuple of strings -- each string will become a button,
the fourth and fifth arguments are option, the fourth is the index in the
answer array that will be the default answer (the one invoked if the user
presses the [Return] key). If omitted the default answer will be the first.
<P>
The function returns the index in the answer array of the answer choosen
by the user. If the user cancels the dialog, a -1 is returned.
<P>
Throws an exception if there is no user interface.</TD>
</TR>
<TR>
<TD><CODE>askString</CODE></TD>
<TD><CODE>(title,question,[def-string])</CODE></TD>
<TD>Allows you to as the user a question for which a string is the answer.
<P>
The first argument is the dialog's title, the second is the question to be
asked, the third is optional and specified a default answer.
<P>
The function returns the string the user typed or None if they cancelled
the dialog.
<P>
Throws an exception if there is no user interface.</TD>
</TR>
<TR>
<TH colspan=3>Types</TH>
</TR>
<TR>
<TD colspan=3><A href="#Point">point</A></TD>
</TR>
<TR>
<TD colspan=3><A href="#Contour">contour</A></TD>
</TR>
<TR>
<TD colspan=3><A href="#Layer">layer</A></TD>
</TR>
<TR>
<TD colspan=3><A href="#GlyphPen">glyphPen</A></TD>
</TR>
<TR>
<TD colspan=3><A href="#Glyph">glyph</A></TD>
</TR>
<TR>
<TD colspan=3><A href="#selection">selection</A></TD>
</TR>
<TR>
<TD colspan=3><A href="#Font">font</A></TD>
</TR>
</TABLE>
<P>
<TABLE id="type" border=1>
<CAPTION>
<A name="Point">point</A>
</CAPTION>
<TR>
<TH colspan=3>Creation</TH>
</TR>
<TR>
<TD><CODE>fontforge.point</CODE></TD>
<TD><CODE>([x,y,on-curve])</CODE></TD>
<TD>Creates a new point. Optionally specifying its location</TD>
</TR>
<TR>
<TH colspan=3>Members</TH>
</TR>
<TR>
<TH>member</TH>
<TH colspan=2>comments</TH>
</TR>
<TR>
<TD><CODE>x</CODE></TD>
<TD colspan=2>The x location of the point</TD>
</TR>
<TR>
<TD><CODE>y</CODE></TD>
<TD colspan=2>The y location of the point</TD>
</TR>
<TR>
<TD><CODE>on_curve</CODE></TD>
<TD colspan=2>Whether this is an on curve point or an off curve point (a
control point)</TD>
</TR>
<TR>
<TD><CODE>selected</CODE></TD>
<TD colspan=2>Whether this point is selected in the UI. If an off-curve point
is selected in means the preceding (interpolated) on-curve point is selected.</TD>
</TR>
<TR>
<TD><CODE>name</CODE></TD>
<TD colspan=2>The point name (generally there is no name)</TD>
</TR>
<TR>
</TR>
<TR>
<TH colspan=3>Methods</TH>
</TR>
<TR>
<TH>method</TH>
<TH>args</TH>
<TH>comments</TH>
</TR>
<TR>
<TD><CODE>dup</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>Returns a copy of the current point.</TD>
</TR>
<TR>
<TD><CODE>transform</CODE></TD>
<TD><CODE>(tuple)</CODE></TD>
<TD>Transforms the point by the transformation matrix</TD>
</TR>
<TR>
<TH colspan=3>Pickling Methods</TH>
</TR>
<TR>
<TD><CODE>__reduce__</CODE></TD>
<TD><CODE>()</CODE></TD>
<TD>This function allows the pickler to work on this type. I don't think
it is useful for anything else.</TD>
</TR>
</TABLE>
<P>
<TABLE id="type" border=1>
<CAPTION>
<A name="Contour">contour</A>
</CAPTION>
<TR>
<TH colspan=3>Description</TH>
</TR>
<TR>
<TD colspan=3>A contour is a collection of points. A contour may be either
based on cubic or quadratic splines.
<P>
If based on cubic splines there should be either 0 or 2 off-curve points
between every two on-curve points. If there are no off-curve points then
we have a line between those two points. If there are 2 off-curve points
we have a cubic bezier curve between the two end points.
<P>
If based on quadratic splines things are more complex. Again, two adjacent
on-curve points yield a line between those points. Two on-curve points with
an off-curve point between them yields a quadratic bezier curve. However
if there are two adjacent off-curve points then an on-curve point will be