Debian Codegraph @

doc/sphinx/scripting/python/fontforge.rst

raw
1 fontforge
2 =========
3
4 .. default-domain:: py
5
6 .. module:: fontforge
7 :synopsis: The primary module for interacting with FontForge
8
9 Module attributes
10 -----------------
11
12 .. data:: hooks
13
14 A dictionary which the user may fill to associate certain FontForge
15 events with a python function to be run when those events happen.
16 The function will be passed the font (or possibly glyph) for which
17 the relevant event occurred.
18
19 **Hook names**
20
21 .. object:: newFontHook
22
23 This function will be called when a new font has been created.
24
25 .. object:: loadFontHook
26
27 This function will be called when a font is loaded from disk.
28 (if a font has an "initScriptString" entry in its persistent
29 dictionary, that script will be invoked before this function).
30
31 Other hooks are defined in a font's own temporary and persistent dictionaries.
32
33 .. data:: splineCorner
34
35 A point type enumeration of value 0
36
37 .. data:: splineCurve
38
39 A point type enumeration of value 1
40
41 .. data:: splineHVCurve
42
43 A point type enumeration of value 2
44
45 .. data:: splineTangent
46
47 A point type enumeration of value 3
48
49 .. data:: fontforge.spiroG4
50
51 A spiro point type enumeration of value 1.
52
53 A Spiro G4 curve point
54
55 .. data:: fontforge.spiroG2
56
57 A spiro point type enumeration of value 2.
58
59 A Spiro G2 curve point
60
61 .. data:: fontforge.spiroCorner
62
63 A spiro point type enumeration of value 3.
64
65 A Spiro corner point
66
67 .. data:: fontforge.spiroLeft
68
69 A spiro point type enumeration of value 4.
70
71 A Spiro left "tangent" point
72
73 .. data:: fontforge.spiroRight
74
75 A spiro point type enumeration of value 5.
76
77 A Spiro right "tangent" point
78
79 .. data:: fontforge.spiroOpen
80
81 A spiro point type enumeration of value 6.
82
83 This may only be used on the first point in a spiro tuple. It indicates that the tuple
84 describes an open contour.
85
86 .. data:: fontforge.unspecifiedMathValue
87
88 A constant, used when the value is unspecified
89
90 Module functions
91 ----------------
92
93 .. function:: getPrefs(pref_name)
94
95 returns the value of the named preference item
96
97 .. function:: setPrefs(pref_name, value)
98
99 sets the value of the named preference item
100
101 .. function:: hasSpiro()
102
103 Returns a boolean, ``True`` if Raph Levien's spiro package is available for
104 use in FontForge.
105
106 .. function:: savePrefs()
107
108 Saves the current preference settings
109
110 .. function:: loadPrefs()
111
112 Loads the user's default preference settings. Not done automatically in a
113 script.
114
115 .. function:: defaultOtherSubrs()
116
117 Sets the type1 PostScript OtherSubrs to the default value
118
119 .. function:: readOtherSubrsFile(filename)
120
121 Sets the type1 PostScript OtherSubrs to the stuff found in the file.
122
123 .. function:: loadEncodingFile(filename[, encname])
124
125 Loads an encoding file, returns the name of the encoding or ``None``. When
126 loading encodings in Unicode consortium format, an encname has to be specified
127 or the encoding will be ignored and ``None`` will be returned.
128
129 .. function:: loadNamelist(filename)
130
131 Loads a namelist
132
133 .. function:: loadNamelistDir(dirname)
134
135 Loads all namelist files in the directory
136
137 .. function:: preloadCidmap(filename, registry, order, supplement)
138
139 Loads a FontForge cidmap file (first three args are strings, last is an integer)
140
141 .. function:: printSetup(type[, printer|cmd|file, width, height])
142
143 Prepare to :func:`print a font sample <font.printSample>`.
144 The first argument may be one of:
145
146 .. object:: lp
147
148 Queues postscript output to the printer using lp.
149 You may use the optional second argument to specify the printer name.
150
151 .. object:: lpr
152
153 Queues postscript output to the printer using lpr.
154 You may use the optional second argument to specify the printer name.
155
156 .. object:: ghostview
157
158 Displays the output using ghostview (or gv). The second argument is ignored.
159
160 .. object:: command
161
162 Use a custom shell command to print the output.
163 The second argument should contain the command and its arguments.
164
165 .. object:: ps-file
166
167 Dump the postscript output to a file. The second argument specifies the filename.
168
169 .. pdf-file
170
171 Dump the output as pdf to a file. The second argument specifies the filename.
172
173 The third and fourth arguments are optional and specify the page size
174 (in points) for the output. The third argument is the page width and the
175 fourth is the height. These settings remain until changed.
176
177 .. function:: nameFromUnicode(uni[, namelist])
178
179 Finds the glyph name associated with a given unicode codepoint. If a
180 namelist is specified the name will be taken from that.
181
182 .. function:: UnicodeAnnotationFromLib(n)
183
184 Returns the Unicode Annotations for this value as described by
185 www.unicode.org. If there is no unicode annotation for this value, or no
186 library available, then return empty string "". It can execute with no
187 current font.
188
189 .. function:: UnicodeBlockCountFromLib(n)
190
191 Return the number of Unicode Blocks as described by www.unicode.org.
192 Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
193 If there is no value, then return -1. This can execute with no current font.
194
195 .. function:: UnicodeBlockEndFromLib(n)
196
197 Returns the Unicode Block end value as described by www.unicode.org.
198 Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
199 If there is no value, then return -1. This can execute with no current font.
200
201 .. function:: UnicodeBlockNameFromLib(n)
202
203 Returns the Unicode Block Name as described by www.unicode.org.
204 Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
205 If there is no value, then return empty string "". This can execute with no
206 current font.
207
208 .. function:: UnicodeBlockStartFromLib(n)
209
210 Returns the Unicode Block start value as described by www.unicode.org.
211 Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
212 If there is no value, then return -1. This can execute with no current font.
213
214 .. function:: unicodeFromName(glyphname)
215
216 Looks up glyph name in its dictionary and if it is associated with a unicode
217 code point returns that number. Otherwise it returns -1
218
219 .. function:: UnicodeNameFromLib(n)
220
221 Returns the Unicode Name for this value as described by www.unicode.org.
222 If there is no unicode name for this value, then return empty string "".
223 It can execute with no current font.
224
225 .. function:: UnicodeNamesListVersion()
226
227 Return the Unicode Nameslist Version (as described by www.unicode.org).
228
229 This can execute with no current font.
230
231 .. function:: UnicodeNames2FromLib(val)
232
233 Errors and corrections happen, therefore names can be corrected in the next
234 Unicode Nameslist version. This function returns the formal alias for the
235 unicode value given, or an empty string if there is no such alias.
236
237 .. function:: scriptFromUnicode(n)
238
239 Return the script tag for the given Unicode codepoint. So, for ``ord('Q')``,
240 it would return ``latn``. This is most useful with :meth:`font.addLookup()`,
241 like: ::
242
243 # Add a `mark` lookup for an arbitrary glyph...
244 script = fontforge.scriptFromUnicode(glyph.unicode)
245 font.addLookup("l1", "gpos_mark2base", None, (("mark",((script,("dflt")),)),))
246 font.addLookupSubtable("l1", "l1-1")
247 font.addAnchorClass("l1-1", "top")
248
249 .. function:: SpiroVersion()
250
251 Returns the version of LibSpiro available to FontForge. Versions 0.1 to 0.5
252 do not have a method to indicate version numbers, but there is a limited
253 method to estimate versions {'0.0'..'0.5'}. '0.0' if FontForge has no LibSpiro
254 available. '0.1' if LibSpiro 20071029 is available. '0.2' if LibSpiro 0.2 to
255 0.5 is available. LibSpiro 0.6 and higher reports back its version available.
256
257 .. function:: version()
258
259 Returns FontForge's version number. This will be a large number like 20070406.
260
261 .. function:: loadPlugins()
262
263 Discovers and loads FontForge python plugins according to the current
264 configuration, if not already loaded. This is primarily intended when
265 importing FontForge into a python process but can also be when loading
266 is delayed by the ``-skippyplug`` command-line flag.
267
268 .. function:: getPluginInfo()
269
270 Returns a list of dictionary objects describing configured and/or discovered
271 plugins. Configured plugins are listed first in loading order followed by
272 any newly discovered plugins. Each dictionary object will have the keys:
273
274 .. object:: name
275
276 The name of the plugin as defined by its author.
277
278 .. object:: enabled
279
280 "On" if the plugin is enabled, "Off" if it is disabled, "New" if the
281 user has not yet configured this plugin.
282
283 .. object:: status
284
285 "Not Found" if the plugin is configured but was not discovered.
286 "Couldn't Load" if the plugin was discovered and its load status is
287 "On" but the relevant module could not be imported. "Couldn't Start"
288 if the module could be imported but the initialization function
289 was missing or returned an error. "Unloaded" if the plugin was discovered
290 and its load status is "On" but loading has not been attempted (most
291 likely because of a configuration change or startup flag). ``None``
292 if the plugin was discovered but has load status "Off" or New" or if
293 it was loaded successfully.
294
295 .. object:: package_name
296
297 The name of the Python package containing the plugin.
298
299 .. object:: module_name
300
301 The name of the Python module carrying the initialization function.
302
303 .. object:: attrs
304
305 Additional sub-objects or properties of the module needed to pick
306 out the location of the initialization function (if any).
307
308 .. object:: prefs
309
310 A boolean indicating whether the plugin has configurable preferences.
311
312 .. object:: package_url
313
314 The "Home-page" URL listed in the package, if any.
315
316 .. object:: summary
317
318 The "Summary" line in the package's metadata with a brief description
319 of the plugin.
320
321 Some of these values will be ``None`` if the plugin has not been loaded
322 and a few more will be ``None`` if the plugin was not discovered.
323
324 .. function:: configurePlugins([List of dictionaries])
325
326 This method allows plugins to be reconfigured using the Python API. It
327 accepts a list (or any other iterable object) of dictionaries similar to
328 those provided by ``getPluginInfo()`` except that only the ``name`` and
329 ``enabled`` fields are examined. The ``name`` value must be the name of a
330 known (currently configured or discovered) plugin. The ``enabled`` value
331 must be "On" or "Off". The configuration will be updated to correspond to
332 the listed plugins in the specified order.
333
334 If a plugin that was *not* discovered is missing from the list it will be
335 removed from the configuration. Any missing but discovered plugins will
336 be added to the end of the configuration list with load status "New".
337
338 .. function:: runInitScripts()
339
340 Runs the system or user initialization scripts, if not already run. This is
341 primarily intended when importing FontForge into a python process.
342
343 .. function:: scriptPath()
344
345 Returns a tuple listing the directory paths which are searched for python
346 scripts during FontForge initialization.
347
348 .. function:: userConfigPath()
349
350 Returns the path to the user's FontForge configuration directory, which should
351 be writable.
352
353 .. function:: fonts()
354
355 Returns a tuple of all fonts currently loaded into FontForge for editing
356
357 .. function:: activeFont()
358
359 If the script were invoked from the File->Execute Script... dialog, or
360 invoked by a menu item in the font view, this returns the font that was
361 active at the time. Otherwise it returns ``None``.
362
363 .. function:: activeGlyph()
364
365 If the script were invoked from the File->Execute Script... dialog or a menu
366 item from an outline glyph window or a glyph import/export command this
367 returns the glyph that was active at the time. Otherwise it returns ``None``.
368
369 .. function:: activeLayer()
370
371 This returns the currently active layer as an integer between 0 (inclusive)
372 and the font/glyph's layer count (exclusive). It may also be set to -1 if the
373 current glyph window is displaying the font's guideline layer.
374
375 .. function:: fontsInFile(filename)
376
377 Returns a tuple of all font names found in the specified file. The tuple may
378 be empty if FontForge couldn't find any.
379
380 .. function:: open(filename[, flags])
381
382 Opens a filename and returns the font it contains (if any). The optional
383 ``flags`` argument can be string tuple or integer combination of the
384 following flags:
385
386 .. object:: fstypepermitted (1)
387
388 The user has the appropriate license to examine the font no matter what
389 the fstype setting is.
390
391 .. object:: allglyphsinttc (4)
392
393 Load all glyphs from the 'glyf' table of a ttc font (rather than only the
394 glyphs used in the font picked).
395
396 .. object:: fontlint (8)
397
398 Report more error conditions.
399
400 .. object:: hidewindow (16)
401
402 Do not create a view window for this font even if the UI is active.
403
404 .. note::
405
406 This option supports efficient bulk processing of fonts in scripts run
407 through the UI but using it can be tricky. Open fonts will be listed at
408 the bottom of the "Window" menu but choosing them will have no effect.
409
410 If some fonts are not closed you may need to "force-quit" the
411 application using your OS.
412
413 .. object:: alltables (32)
414
415 Retain all recognized font tables that do not have a native format.
416
417 This function can also be used with the ``with`` statement, in which case
418 there is no need to call :meth:`font.close()` explicitly:
419
420 ::
421
422 with fontforge.open('somefont.sfd') as fnt:
423 # do something
424 fnt.generate('somefont.ttf')
425
426 .. function:: parseTTInstrs(string)
427
428 Returns a binary string each byte of which corresponds to a truetype
429 instruction. The input string should contain a set of instruction names as ::
430
431 "SRP0 MIRP[min,rnd,black]"
432
433 .. function:: unParseTTInstrs(sequence)
434
435 Reverse of the above. Converts a binary string into a human (sort of)
436 readable string
437
438 .. function:: unitShape(n)
439
440 Returns a closed contour which is a regular n-gon. The contour will be
441 inscribed in the unit circle. If n is negative, then the contour will be
442 circumscribed around the unit circle. A value of 0 will produce a unit circle.
443 If n==1 it is treated as if n were -4 -- a circumscribed square where each
444 side is 2 units long (this is for historical reasons). Behavior is undefined
445 for n=2,-1,-2.
446
447 .. function:: registerGlyphSeparationHook(hook)
448
449 The GlyphSeparationHook is a python routine which FontForge will call when
450 it wants to figure out the optical separation between two glyphs. If you
451 never call this, or if you call it with a value of ``None`` FontForge will
452 use a built-in default. This routine gets called during AutoWidth, AutoKern,
453 and computing the optical left and right side bearings (for 'lfbd' and 'rtbd'
454 features). For more information see its own section.
455
456 .. function:: onAppClosing(hook)
457
458 Add a python function which is called when FontForge is closing down.
459
460 .. _fontforge.ui_functions:
461
462 User Interface Module Functions
463 -------------------------------
464
465 Users may define scripts to be run when menu items are invoked. Some of these
466 scripts will want to ask users questions, so this section provides routines to
467 determine if FontForge has a user interface, a command to add menu items, and
468 various small standard dialogs to interact with the user. I do not currently
469 provide a mechanism for allowing people to define special purpose dialogs (for
470 example they might want to ask more than one question in a dialog, and I don't
471 support that).
472
473 When FontForge starts (if it's a FontForge with python) it will look at the
474 directories ``$(PREFIX)/share/fontforge/python`` and ``~/.config/fontforge/python``
475 and attempt to run all files in those directories which end in ``".py"``.
476 Presumably these files will allow people to customize the user interface to
477 suit their needs.
478
479 Currently it reads the files in directory order (which is generally somewhere
480 between creation order and totally random). It will read the system directory
481 before the user directory.
482
483 .. rubric:: Example
484
485 ::
486
487 import fontforge
488
489 def nameGlyph(junk, glyph):
490 print(glyph.glyphname)
491
492 fontforge.registerMenuItem(callback=nameGlyph, context="Glyph",
493 name=("Print Glyph Name", "MyExt_PrintGlyphName"))
494
495 def neverEnableMe(junk, glyph):
496 return False
497
498 fontforge.registerMenuItem(callback=nameGlyph, enable=neverEnableMe, context="Glyph",
499 submenu=("SubMenu", "MyExt_SubMenu"),
500 name=("Print Glyph Name", "MyExt_PrintGlyphName"))
501
502 def importGlyph(junk, glyph, filename, toback):
503 print("Import")
504 print(glyph.glyphname)
505 print(filename)
506
507 def exportGlyph(junk, glyph, filename):
508 print("Import")
509 print(glyph.glyphname)
510 print(filename)
511
512 fontforge.registerImportExport(importGlyph, exportGlyph, None, "foosball", "foo", "foo,foobar")
513
514 The first call will define a menu item in the Tools menu of the Glyph window.
515 The menu will be called "Print Glyph Name". It has no shortcut to invoke it. It
516 needs no external data. It is always enabled. And when activated it will invoke
517 the function "nameGlyph" which prints the name of the glyph in the window from
518 which the command is invoked.
519
520 The second call defines a menu item in a submenu of the Tools menu. This submenu
521 is called "SubMenu". This item will never be enabled -- but if it were enabled
522 it would again call "nameGlyph" to print the name of the current glyph.
523
524 The last provides a way to import and export files of type "foosball" (or it
525 would if the routines did anything).
526
527 Not a very useful example.
528
529
530 .. function:: hasUserInterface()
531
532 Returns ``True`` if this session of FontForge has a user interface
533
534 .. function:: registerMenuItem(callback, enable, data, context, hotkey, {submenu_names, } name)
535 (Positional interface)
536
537 .. function:: registerMenuItem(callback=, enable=None, data=None, context=, hotkey=None, name=, submenu=None, keyword_only=False)
538 (Keyword interface)
539 :noindex:
540 .. function:: registerMenuItem(context=, divider=, submenu=None)
541 (Divider interface)
542 :noindex:
543
544 If FontForge has a user interface this will add this menu item to the
545 FontForge menu(s) specified by the ``context`` parameter. This second
546 keyword interface is explained in the ``divider`` section.
547
548 We also recommend reading the :ref:`Menu <fontforge.plugin_menu>` section
549 of :doc:`Extending FontForge with Python </techref/pyextend>`
550
551 **Note:** The positional interface is forward-compatible with earlier
552 versions of FontForge.
553
554 .. object:: callback
555
556 This is the function that will be called when the menu item is activated.
557 It will be passed two arguments, the first is the data value specified
558 here (which defaults to ``None``) and the second is a :class:`fontforge.glyph`
559 or :class:`fontforge.font` object (depending on the ``context``).
560 The callback's return value is ignored.
561
562 .. object:: enable
563
564 When specified this function is called with the same arguments as ``callback``
565 right before the menu or submenu is displayed. When it returns ``True``
566 the menu item will be enabled and when it returns ``False`` it will be
567 disabled. (When ``enable`` is ``None`` the menu item is always enabled.)
568
569 .. object:: data
570
571 ``data`` can be whatever you want; it defaults to ``None``. FontForge
572 passes it to both of the above functions. It can be used to provide
573 context or default arguments for the function (so that one function can
574 be used for multiple menu items.)
575
576 .. object:: context
577
578 Currently this can the string ``"Font"``, the string ``"Glyph"``
579 or the tuple ``("Font", "Glyph")``). ``"Font"`` will add the menu item
580 to the FontView "Tools" menu or its submenu, while ``"Glyph"`` will
581 add it to the CharView tools menu or its submenu.
582
583 .. object:: hotkey
584
585 ``hotkey`` must be either ``None`` or a string in hotkey format,
586 which is the same as the second part of a
587 :ref:`HotKey assignment <HotKeys.hotkeyassign>`.
588 Because hotkeys are a "limited
589 resource" this string is only a `suggestion`; it has no effect
590 when the specified HotKey is already taken. Therefore, before picking
591 a candidate HotKey you should at least verify that it is not already
592 used by the relevant window in FontForge.
593
594 Even when the specified HotKey is taken a user can still specify their
595 own in the HotKeys file. You can make this easier to do, now and in the
596 future, by providing the full triplet of names for each "level" using
597 the current interface.
598
599 .. object:: name
600
601 ``name`` can be a string but ideally it is a tuple of three strings
602 ``(localized_name, english_name, identifier_string)`` or of two strings
603 ``(english_name, identifier_string)``. Use the three-tuple version when
604 your plugin or other extension is localized and the two-tuple version
605 when it is not localized or the user has configured the base locale.
606
607 **Note:** The ``english_name`` and ``localized_name`` can and should
608 include a *mnemonic*, picked out by a leading underscore. However,
609 mnemonics at the top level (so the first ``submenu`` name or the ``name``
610 if ``submenu`` is ``None``) are taken as a suggestion, similar to the
611 ``hotkey`` argument. Please read the sections on Internationalization and
612 Localization and on Mnemonics in Extending FontForge with Python.
613
614 The ``identifier_string`` should be a single alphanumeric (plus
615 underscores, but no spaces) string to identify this menu item. In the
616 future this will serve as the representation of the menu item in menu
617 configuration files, allowing a user or administrator to put the item
618 where they like. It should include the name of your plugin or an
619 abbreviation of it. For a plugin called "Feature File Helpers" and an
620 item with (English) name "Save Fragment" a reasonable option would be
621 "FeatFileHelp_SaveFragment". (This is for the future, as configurable
622 menus are not yet supported by FontForge.)
623
624 .. object:: submenu
625
626 **Note:** ``submenu`` is a keyword-only argument.
627
628 ``submenu`` can be any of: ``None``, a string, a two-tuple or three-tuple
629 as with ``name``, or a Python *list* of any of these, with each
630 specifying a level of sub-menu. (You cannot specify muitple levels of
631 submenu with a tuple, as this would be ambiguous.) The tuple elements are
632 analogous to ``name``: a three-tuple of ``(localized_name, english_name,
633 identifier_string)``, a two-tuple of ``(english_name,
634 identifier_string)``, or a string which is treated as the
635 ``localized_name``. Submenus can and should also specify a *mnemonic*.
636
637 In the future the ``identifier_string`` will allow a whole submenu to be
638 moved to a different location in the menu hierarchy.
639
640 .. object:: submenu_names
641
642 When using the positional interface, each of these "intermediate" entries
643 can be a three-tuple, two-tuple, or string, corresponding to an entry
644 in the ``submenu`` list.
645
646 .. object:: keyword_only
647
648 When ``keyword_only`` is ``False`` (the default) the function will attempt
649 to fall back to the positional interface and any reported errors will be
650 relative to that interface. If you're having trouble with keyword parameters
651 set ``keyword_only`` to ``True`` to see a more specific error message.
652
653 .. object:: divider
654
655 This special form of the function adds a horizontal line to the menu.
656 The ``context`` keyword is required and ``divider`` must be set to ``True``.
657 If the ``submenu`` keyword is omitted the divider is added to the top level.
658
659 .. function:: registerImportExport(import_function, export_function, data, name, extension, [extension_list])
660
661 This will add the capability to import or export files of a given type,
662 presumably a way of specifying the splines in a given glyph.
663
664 .. object:: import_function
665
666 The function to call to import a file into a glyph. It will be called
667 with: The data argument (specified below), A pointer to the glyph into
668 which the import is to happen, A filename, A flag indicating whether the
669 import should go to the background layer or foreground. This function may
670 be ``None``. In which case there is no import method for this file type.
671
672 .. object:: export_function
673
674 The function to call to export a glyph into a file. It will be called
675 with: The data argument (see below), a pointer to the glyph, and a
676 filename. This function may be ``None``, in which case there is no export
677 method for this file type.
678
679 .. object:: data
680
681 Anything you like (including ``None``). It will be passed to the
682 import/export routines and can provide them with context if they need that.
683
684 .. object:: name
685
686 The name to be displayed in the user interface for this file type.
687 This may just be the extension, or it might be something more informative.
688
689 .. object:: extension
690
691 This is the default extension for this file type. It is used by the
692 export dialog to pick an extension for the generated filename.
693
694 .. object:: extension_list
695
696 Some file types have more than one common extension (eps files are usually
697 named "eps", but I have also seen "ps" and "art" used). The import dialog
698 needs to filter all possible filenames of this file type. This argument
699 should be a comma separated list of extensions. It may be omitted, in
700 which case it defaults to being the same as the "extension" argument above.
701
702 .. function:: getConvexNib(context)
703
704 Returns the specified 'Convex' nib as a layer. ``context`` may be
705 ``"default"``, ``"freehand"``, or ``"ui"``.
706
707 .. function:: setConvexNib(nib, context)
708
709 Sets the specified 'Convex' to a layer/contour. ``context`` may be
710 ``"default"``, ``"freehand"``, or ``"ui"``.
711
712 .. function:: logWarning(msg)
713
714 Adds the message (a string) to FontForge's Warnings window. (if you wish to
715 display a % character you must represent it as two percents). If there is no
716 user interface the output will go to stderr.
717
718 .. function:: postError(win_title, msg)
719
720 Creates a popup dialog to display the message (a string) in that dlg. (if you
721 wish to display a % character you must represent it as two percents). If
722 there is no user interface the output will go to stderr.
723
724 .. function:: postNotice(win_title, msg)
725
726 Creates a little window which will silently vanish after a minute or two and
727 displays the message (a string) in that window. (if you wish to display a %
728 character you must represent it as two percents). If there is no user
729 interface the output will go to stderr.
730
731 .. function:: openFilename(question, [def_name, [filter]])
732
733 All arguments are strings. The first is a question asked to the user (for
734 which a filename to open is presumed to be the answer). The second is
735 optional and provides a default filename. The third is optional and provides
736 a filter (like "\*.sfd")
737
738 The result is either a filename or ``None`` if the user canceled the dialog.
739
740 Throws an exception if there is no user interface.
741
742 .. function:: saveFilename(question, [def_name, [filter]])
743
744 All arguments are strings. The first is a question asked to the user (for
745 which a filename to save something to is presumed to be the answer). The
746 second is optional and provides a default filename. The third is optional and
747 provides a filter (like "\*.sfd")
748
749 The result is either a filename or ``None`` if the user canceled the dialog.
750
751 Throws an exception if there is no user interface.
752
753 .. function:: ask(title, question, answers, [def, cancel])
754
755 Allows you to ask the user a multiple choice question. It pops up a dialog
756 posing the question with a list of buttons ranged underneath it -- one for
757 each answer.
758
759 The first argument is the dialog's title, the second is the question to be
760 asked, the third is a tuple of strings -- each string will become a button,
761 the fourth and fifth arguments are optional, the fourth is the index in the
762 answer array that will be the default answer (the one invoked if the user
763 presses the [Return] key), and the fifth is the answer invoked if the user
764 presses the [Escape] key. If omitted the default answer will be the first,
765 and the cancel answer will be the last.
766
767 The function returns the index in the answer array of the answer chosen by
768 the user.
769
770 Throws an exception if there is no user interface.
771
772 .. function:: askChoices(title, question, answers[,default=,multiple=])
773
774 Similar to the above allows you to ask the user a multiple choice question.
775 It pops up a dialog posing the question with a scrollable list of choices --
776 one for each answer.
777
778 The first argument is the dialog's title, the second is the question to be
779 asked, the third is a tuple of strings -- each string will become a button,
780 the fourth and fifth arguments are optional, the fourth is the index in the
781 answer array that will be the default answer (the one invoked if the user
782 presses the [Return] key). If omitted the default answer will be the first.
783
784 The fifth argument means that multiple options can be selected. If true,
785 the fourth argument should be a tuple of Boolean values or a single integer
786 index into the answer tuple. So, if there are three options, it should look
787 like ``(True, False, True)``, which would select the first and last option.
788
789 The function returns the index in the answer array of the answer chosen by
790 the user. If the user
791 cancels the dialog, a -1 is returned.
792
793 ``default`` and ``multiple`` may be passed by position if desired.
794
795 Throws an exception if there is no user interface.
796
797 .. function:: askString(title, question, [def_string])
798
799 Allows you to ask the user a question for which a string is the answer.
800
801 The first argument is the dialog's title, the second is the question to be
802 asked, the third is optional and specified a default answer.
803
804 The function returns the string the user typed or ``None`` if they cancelled
805 the dialog.
806
807 Throws an exception if there is no user interface.
808
809 .. function:: askMulti(title, specification)
810
811 This method raises a dialog with multiple questions for the user, optionally
812 organized into separate tabs. The answers can be choices (similar to
813 :func:`fontforge.askChoices()`) a string (similar to
814 :func:`fontforge.askString()`) an existing filename (similar to
815 :func:`fontforge.openFilename()`) or a save filename (similar to
816 :func:`fontforge.saveFilename()`.
817
818 Due to the variety of potential ``specification`` parameters this facility is
819 explained in a separate :doc:`document </techref/askmulti>`.
820
821 The method throws an exception if there is no user interface or the
822 specification is not valid. Otherwise it either returns a dictionary of answers
823 or ``None`` if the user chose "Cancel" or closed the dialog without choosing "OK".
824
825 Point
826 -----
827
828 .. class:: point([x, y, on_curve, type, selected])
829
830 Creates a new point. Optionally specifying its x,y location,
831 on-curve status and selected status. x and y must be supplied together.
832
833 A "point initializer tuple" is any tuple (x,y[,True|False[,0|1|2|3[,True|False]]]),
834 where x and y are numbers, the third value corresponds to on-curve, the
835 fourth to type, and the fifth to selected.
836
837 .. attribute:: point.x
838
839 The x location of the point
840
841 .. attribute:: point.y
842
843 The y location of the point
844
845 .. attribute:: point.on_curve
846
847 Whether this is an on curve point or an off curve point (a control point)
848
849 .. attribute:: point.selected
850
851 The value of this member also determines the selected status in the UI on
852 setting a layer. FontForge usually retains the selection status of any point
853 between and that of an on-curve point when saving, whether or not a UI is present.
854
855 .. attribute:: point.type
856
857 For an on-curve point, its FontForge point type.
858
859 There are four types: :data:`fontforge.splineCorner`, :data:`fontforge.splineCurve`,
860 :data:`fontforge.splineHVCurve` and :data:`fontforge.splineTangent`.
861
862 A new point will have type :data:`splineCorner`. When assigning a layer to
863 :attr:`glyph.layers`, :attr:`glyph.background` or :attr:`glyph.foreground`
864 the type value is ignored. To influence the type FontForge will associate
865 with an on-curve point use :meth:`glyph.setLayer`.
866
867 .. attribute:: point.interpolated
868
869 ``True`` if FontForge treats this (quadratic, on-curve) point as interpolated.
870 All interpolated points should be mid-way between their off-curve points,
871 but some such points are not treated as interpolated. This flag is ignored
872 when setting a layer.
873
874 Older versions of FontForge omitted interpolated points. This was equivalent
875 to executing the following on a contour: ::
876
877 c[:] = [ p for p in c if not p.interpolated ]
878
879 This member will be false for a point marked "Never interpolate" in FontForge
880 but there is currently no way of setting or preserving that mark when a layer
881 is replaced using the Python interfaces. A "round trip" through a Python
882 contour therefore clears that mark on any points that have it, and FontForge
883 treats mid-placed and omitted :attr:`on_curve` points as equivalent.
884
885 .. attribute:: point.name
886
887 The point name (generally there is no name)
888
889 .. method:: point.dup()
890
891 Returns a copy of the current point.
892
893 .. method:: point.transform(tuple)
894
895 Transforms the point by the transformation matrix
896
897 .. method:: point.__reduce__()
898
899 This function allows the pickler to work on this type. I don't think it is
900 useful for anything else.
901
902
903 Contour
904 -------
905
906 A contour is a collection of points. A contour may be either based on cubic or
907 quadratic splines.
908
909 If based on cubic splines there should be either 0 or 2 off-curve points
910 between every two on-curve points. If there are no off-curve points then
911 we have a line between those two points. If there are 2 off-curve points
912 we have a cubic bezier curve between the two end points.
913
914 If based on quadratic splines things are more complex. Again, two
915 adjacent on-curve points yield a line between those points. Two on-curve
916 points with an off-curve point between them yields a quadratic bezier
917 curve. However if there are two adjacent off-curve points then an
918 on-curve point will be interpolated between them. (This should be
919 familiar to anyone who has read the truetype 'glyf' table docs).
920
921 For examples of what these splines can look like see the
922 :doc:`section on bezier curves </techref/bezier>`.
923
924 A contour may be open in which case it is just a long wiggly line, or
925 closed when it is more like a circle with an inside and an outside.
926 Unless you are making stroked fonts all your contours should eventually
927 be closed.
928
929 Contours may also be expressed in terms of Raph Levien's spiro points.
930 This is an alternate representation for the contour, and is not always
931 available (Only if :func:`fontforge.hasSpiro()` is ``True``. If
932 available the spiro member will return a tuple of spiro control points,
933 while assigning to this member will change the shape of the contour to
934 match the new spiros.
935
936 Two contours may be compared to see if they describe similar paths.
937
938
939
940 .. class:: contour(is_quadratic=False)
941
942 Creates a new contour.
943
944 .. attribute:: contour.is_quadratic
945
946 Whether the contour should be interpreted as a set of quadratic or cubic
947 splines. Setting this value has the side effect of converting the point list
948 to the appropriate format.
949
950 .. attribute:: contour.closed
951
952 Whether the contour is open or closed.
953
954 .. attribute:: contour.name
955
956 The contour name (generally there is no name).
957
958 .. attribute:: contour.spiros
959
960 This is an alternate representation of a curve. This member is only
961 available if :meth:`fontforge.hasSpiro()` is ``True``. Returns a tuple
962 of spiro control points. Each of these is itself a tuple of four
963 elements; an x,y location, a type field, and a set of flags. The type
964 field takes on values (which are predefined constants in the
965 :mod:`fontforge` module):
966
967
968
969 * :data:`fontforge.spiroG4`
970 * :data:`fontforge.spiroG2`
971 * :data:`fontforge.spiroCorner`
972 * :data:`fontforge.spiroLeft`
973 * :data:`fontforge.spiroRight`
974 * :data:`fontforge.spiroOpen`
975
976 For more information on what these point types mean see
977 `Raph Levien's work <https://www.levien.com/spiro/>`_.
978
979 The flags argument is treated as a bitset of which currently only one bit (0x1)
980 is defined. This indicates that this point is selected in the UI.
981
982 When you assign a tuple of spiro control points to this member, the point
983 list for the Bezier interpretation of the contour will change. And when you
984 change the Bezier interpretation the set of spiro points will change.
985
986 .. method:: contour.dup()
987
988 Returns a deep copy of the contour. That is, it copies the points that make
989 up the contour.
990
991 .. method:: contour.isEmpty()
992
993 Returns whether the contour is empty (contains no points)
994
995 .. method:: contour.boundingBox()
996
997 Returns a tuple representing a rectangle ``(xmin,ymin, xmax,ymax)`` into
998 which the contour fits. It is not guaranteed to be the smallest such
999 rectangle, but it will often be.
1000
1001 .. method:: contour.getSplineAfterPoint(pos)
1002
1003 Returns a tuple of two four-element tuples. These tuples are x and y splines
1004 for the curve after the specified point.
1005
1006 .. method:: contour.draw(pen)
1007
1008 Draw the contour to the pen argument.
1009
1010 .. method:: contour.__reduce__()
1011
1012 This function allows the pickler to work on this type. I don't think it is
1013 useful for anything else.
1014
1015 .. method:: contour.__iter__()
1016
1017 Returns an iterator for the contour which will return the points in order.
1018
1019
1020 .. rubric:: Sequence Protocol
1021
1022 Does not support the repeat concept.
1023
1024 .. object:: len(c)
1025
1026 The number of points in the contour
1027
1028 .. object:: c[i]
1029
1030 The ``i`` th point on the contour. You may assign a point or point
1031 initializer to this (keeping the number of points constant) or use
1032 ``del c[i]`` to remove the entry (reducing the number by one).
1033
1034 .. object:: c[i:j]
1035
1036 The contour containing points between i and j; j must be >= i.
1037 Alternatively, ``c[j:i:-1]`` returns those points in reverse order (larger
1038 strides are not supported).
1039
1040 .. object:: c[i:j] = d
1041
1042 The points between i and j are replaced by those in d; j must be >= i.
1043 d can be a contour or a sequence of point initializer tuples, as in
1044 ``[(1,1,False),(2,1)]``. If ``c[j:i:-1]`` is used instead the points of d
1045 are assigned in reverse order.
1046
1047 .. object:: c + d
1048
1049 A contour concatenating c and d. d may be or encode either another contour
1050 or a point.
1051
1052 .. object:: c += d
1053
1054 Appends d to c. d may be or encode either another contour or a point.
1055
1056 .. object:: p in c
1057
1058 When p is a point, returns whether some point ``(p.x, p.y)`` is in the
1059 contour c. p can also be a tuple of two numbers.
1060
1061
1062 .. rubric:: Contour construction
1063
1064 .. method:: contour.moveTo(x, y)
1065
1066 Adds an initial, on-curve point at ``(x,y)`` to the contour
1067
1068 .. method:: contour.lineTo(x, y[, pos])
1069
1070 Adds a line to the contour. If the optional third argument is given, the
1071 line will be added after the pos'th point, otherwise it will be at the end
1072 of the contour.
1073
1074 .. method:: contour.cubicTo((cp1x, cp1y)(cp2x, cp2y)(x, y)[, pos])
1075
1076 Adds a cubic curve to the contour. If the optional fourth argument is given,
1077 the curve will be added after the pos'th point, otherwise it will be at the
1078 end of the contour.
1079
1080 .. method:: contour.quadraticTo((cpx, cpy)(x, y)[, pos])
1081
1082 Adds a quadratic curve to the contour. If the optional third argument is
1083 given, the curve will be added after the pos'th point, otherwise it will be at
1084 the end of the contour.
1085
1086 .. method:: contour.insertPoint(point[, pos])
1087
1088 Adds a point to the contour. If the optional second argument is given, the point
1089 will be added after the pos'th point, otherwise it will be at the end of the
1090 contour. The point may be either a point or a point initializer tuple.
1091
1092 .. method:: contour.makeFirst(pos)
1093
1094 Rotate the point list so that the pos'th point becomes the first point
1095
1096 .. method:: contour.isClockwise()
1097
1098 Returns whether the contour is drawn in a clockwise direction. A return
1099 value of -1 indicates that no consistent direction could be found (the
1100 contour self-intersects).
1101
1102 .. method:: contour.reverseDirection()
1103
1104 Reverse the order in which the contour is drawn (turns a clockwise contour
1105 into a counter-clockwise one). See also :meth:`layer.correctDirection`.
1106
1107 .. method:: contour.similar(other_contour[, error])
1108
1109 Checks whether this contour is similar to the other one where error is the
1110 maximum distance (in em-units) allowed for the two contours to diverge.
1111
1112 This is like the comparison operator, but that doesn't allow you to specify
1113 an error bound.
1114
1115 .. method:: contour.xBoundsAtY(ybottom[, ytop])
1116
1117 Finds the minimum and maximum x positions attained by the contour when y is
1118 between ybottom and ytop (if ytop is not specified it is assumed the same as
1119 ybottom). If the contour does not have any y values in the specified range
1120 then ff will return ``None``.
1121
1122 .. method:: contour.yBoundsAtX(xleft[, xright])
1123
1124 Finds the minimum and maximum y positions attained by the contour when x is
1125 between xleft and xright (if xright is not specified it is assumed the same
1126 as xleft). If the contour does not have any x values in the specified range
1127 then ff will return ``None``.
1128
1129
1130 .. rubric:: Contour manipulation
1131
1132 .. method:: contour.addExtrema([flags, emsize])
1133
1134 Extrema should be marked by on-curve points. If a curve lacks a point at an
1135 extrema this command will add one. Flags may be one of the following strings:
1136
1137 .. object:: all
1138
1139 Add all missing extrema
1140
1141 .. object:: only_good
1142
1143 Only add extrema on longer splines (with respect to the em-size)
1144
1145 .. object:: only_good_rm
1146
1147 As above but also merge away on-curve points which are very close to, but
1148 not on, an added extremum
1149
1150 .. method:: contour.cluster([within, max])
1151
1152 Moves clustered coordinates to a standard central value.
1153
1154 See also :meth:`contour.round()`.
1155
1156 .. method:: contour.merge(pos)
1157
1158 Removes the on-curve point at the given position and rearranges the other
1159 points to make the curve as similar to the original as possible. (pos may
1160 also be a tuple of positions, all of which will be removed)
1161
1162 See also :meth:`contour.simplify()`.
1163
1164 .. method:: contour.round([factor])
1165
1166 Rounds the x and y coordinates. If factor is specified then ::
1167
1168 new_coord = round(factor*old_coord)/factor
1169
1170 See also :meth:`contour.cluster()`.
1171
1172 .. method:: contour.selfIntersects()
1173
1174 Returns whether this contour intersects itself.
1175
1176 .. method:: contour.simplify([error_bound, flags, tan_bounds, linefixup, linelenmax])
1177
1178 Tries to remove excess points on the contour if doing so will not perturb
1179 the curve by more than error-bound. Flags is a tuple of the following strings:
1180
1181 .. object:: ignoreslopes
1182
1183 Allow slopes to change
1184
1185 .. object:: ignoreextrema
1186
1187 Allow removal of extrema
1188
1189 .. object:: smoothcurves
1190
1191 Allow curve smoothing
1192
1193 .. object:: choosehv
1194
1195 Snap to horizontal or vertical
1196
1197 .. object:: forcelines
1198
1199 flatten bumps on lines
1200
1201 .. object:: nearlyhvlines
1202
1203 Make nearly horizontal/vertical lines be so
1204
1205 .. object:: mergelines
1206
1207 Merge adjacent lines into one
1208
1209 .. object:: setstarttoextremum
1210
1211 Rotate the point list so that the start point is on an extremum
1212
1213 .. object:: removesingletonpoints
1214
1215 If the contour contains just one point then remove it
1216
1217 See also :meth:`contour.merge()`.
1218
1219 .. method:: contour.transform(matrix)
1220
1221 Transforms the contour by the matrix
1222
1223 .. seealso::
1224
1225 `Curvatura documentation <https://github.com/linusromer/curvatura/blob/master/curvatura-doc.pdf>`_
1226 Documentation for adding points of inflection, balancing and harmonizing.
1227
1228 .. method:: contour.addInflections()
1229
1230 If the curvature of a spline in the contour changes sign then break the
1231 spline so that there will be a point at all points of inflection.
1232
1233 .. method:: contour.balance()
1234
1235 For all cubic bezier splines of the contour make the line between the control
1236 points parallel to the chord such that the area is preserved. This is an
1237 improved version of the algorithm known as "tunnify".
1238
1239 .. method:: contour.harmonize()
1240
1241 For all bezier splines of the contour move the smooth on-curve points between
1242 its adjacent control points such that the adjacent curvatures become equal.
1243
1244
1245 Layer
1246 -----
1247
1248 A layer is a collection of contours. All the contours must be the same order
1249 (all quadratic or all cubic). Currently layers do not contain references.
1250
1251 Layers may be compared to see if their contours are similar.
1252
1253 .. class:: layer(is_quadratic=False)
1254
1255 Creates a new layer
1256
1257 .. attribute:: layer.is_quadratic
1258
1259 Whether the contours should be interpreted as a set of quadratic cubic
1260 splines. Setting this value has the side effect of converting the contour
1261 list to the appropriate format.
1262
1263 .. method:: layer.__iter__()
1264
1265 Returns an iterator for the layer which will return the contours in order.
1266
1267 .. method:: layer.__reduce__()
1268
1269 This function allows the pickler to work on this type. I don't think it is
1270 useful for anything else.
1271
1272 .. method:: layer.dup()
1273
1274 Returns a deep copy of the layer. That is, it will copy all the contours and
1275 all the points as well as copying the layer object itself.
1276
1277 .. method:: layer.isEmpty()
1278
1279 Returns whether the layer is empty (contains no contour)
1280
1281 .. method:: layer.addExtrema([flags, emsize])
1282
1283 Extrema should be marked by on-curve points. If a curve lacks a point at an
1284 extrema this command will add one. Flags may be one of the following strings:
1285
1286 .. object:: all
1287
1288 Add all missing extrema
1289
1290 .. object:: only_good
1291
1292 Only add extrema on longer splines (with respect to the em-size)
1293
1294 .. object:: only_good_rm
1295
1296 As above but also merge away on-curve points which are very close to, but
1297 not on, an added extremum
1298
1299 .. method:: layer.cluster([within, max])
1300
1301 Moves clustered coordinates to a standard central value.
1302
1303 See also :meth:`layer.round()`.
1304
1305 .. method:: layer.correctDirection()
1306
1307 Orients all contours so that external ones are clockwise and internal
1308 counter-clockwise. See also :meth:`contour.isClockwise()`.
1309
1310 .. method:: layer.export(filename[, KEYWORD])
1311
1312 Exports the current layer (in outline format) to a file. The type of file is
1313 determined by the extension.
1314
1315 The following optional keywords modify the export process for various formats:
1316
1317 .. object:: usetransform (boolean, default=False)
1318
1319 Flip the Y-axis of exported SVGs with a transform element rather than
1320 modifying the individual Y values.
1321
1322 .. object:: usesystem (boolean, default=False)
1323
1324 Ignore the above keyword settings and use the values set by the user
1325 in the Import options dialog.
1326
1327 .. object:: asksystem (boolean, default=False)
1328
1329 If the UI is present show the Import options dialog to the user
1330 and use the chosen values (does nothing otherwise).
1331
1332 .. method:: layer.exclude(excluded_layer)
1333
1334 Removes the excluded area from the current contours. See also
1335 :meth:`layer.removeOverlap()` and :meth:`layer.intersect()`.
1336
1337 .. method:: layer.intersect()
1338
1339 Leaves only areas in the intersection of contours. See also
1340 :meth:`layer.removeOverlap()` and :meth:`layer.exclude()`.
1341
1342 .. method:: layer.removeOverlap()
1343
1344 Removes overlapping areas. See also :meth:`layer.intersect()` and
1345 :meth:`layer.exclude()`.
1346
1347 .. method:: layer.interpolateNewLayer(other_layer, amount)
1348
1349 Creates (and returns) a new layer which contains splines interpolated from
1350 the current layer and the first argument. If amount is 0 the result will
1351 look like the current layer, if 1 then like the first argument.
1352
1353 .. method:: layer.reverseDirection()
1354
1355 Reverse the orientation of each contour in the layer.
1356
1357 .. method:: layer.round([factor])
1358
1359 Rounds the x and y coordinates. If factor is specified then ::
1360
1361 new_coord = round(factor*old_coord)/factor
1362
1363 See also :meth:`layer.cluster()`.
1364
1365 .. method:: layer.selfIntersects()
1366
1367 Returns whether any of the contours on this layer intersects any other
1368 contour (including itself).
1369
1370 .. method:: layer.similar(other_layer[, error])
1371
1372 Checks whether this layer is similar to the other one where error is the
1373 maximum distance (in em-units) allowed for any two corresponding contours
1374 in the layers to diverge.
1375
1376 This is like the comparison operator, but that doesn't allow you to specify
1377 an error bound.
1378
1379 .. method:: layer.simplify([error_bound, flags, tan_bounds, linefixup, linelenmax])
1380
1381 Tries to remove excess points on the layer if doing so will not perturb the
1382 curve by more than error-bound. Flags is a tuple of the following strings:
1383
1384 .. object:: ignoreslopes
1385
1386 Allow slopes to change
1387
1388 .. object:: ignoreextrema
1389
1390 Allow removal of extrema
1391
1392 .. object:: smoothcurves
1393
1394 Allow curve smoothing
1395
1396 .. object:: choosehv
1397
1398 Snap to horizontal or vertical
1399
1400 .. object:: forcelines
1401
1402 flatten bumps on lines
1403
1404 .. object:: nearlyhvlines
1405
1406 Make nearly horizontal/vertical lines be so
1407
1408 .. object:: mergelines
1409
1410 Merge adjacent lines into one
1411
1412 .. object:: setstarttoextremum
1413
1414 Rotate the point list so that the start point is on an extremum
1415
1416 .. object:: removesingletonpoints
1417
1418 If the contour contains just one point then remove it
1419
1420 .. method:: layer.stemControl(stem_width_scale, [hscale, stem_height_scale, vscale, xheight])
1421
1422 Allows you to scale counters and stems independently of each other.
1423 ``stem_width_scale`` specifies by how much the widths of stems should be
1424 scaled (this should be a number around 1).
1425
1426 If omitted, ``hscale`` defaults to 1, otherwise it will indicate the
1427 horizontal scaling factor for the glyph as a whole.
1428
1429 If omitted, ``stem_height_scale`` defaults to ``stem_width_scale``,
1430 otherwise it specifies the scaling for stem heights.
1431
1432 If omitted, ``vscale`` defaults to ``hscale``, otherwise it specifies the
1433 vertical scale factor for the glyph as a whole. ``xheight`` is optional; if
1434 specified it will fix the points at that height so that they will be at the
1435 same level across glyphs.
1436
1437 .. method:: layer.stroke("circular", width[, CAP, JOIN, FLAGS])
1438 layer.stroke("elliptical", width, minor_width, ANGLE [, CAP, JOIN, FLAGS])
1439 layer.stroke("calligraphic", width, height, angle[, FLAGS])
1440 layer.stroke("polygon", contour[, FLAGS])
1441 (Legacy interface)
1442 :noindex:
1443
1444 .. method:: layer.stroke("circular", width [, CAP, JOIN, ANGLE, KEYWORD])
1445 layer.stroke("elliptical", width, minor_width [, ANGLE, CAP, JOIN, KEYWORD])
1446 layer.stroke("calligraphic", width, height [, ANGLE, CAP, JOIN, KEYWORD])
1447 layer.stroke("convex", contour[, ANGLE, CAP, JOIN, KEYWORD])
1448 (Current interface)
1449
1450 Strokes the lines of each contour in the layer according to the supplied
1451 parameters. See the corresponding :meth:`glyph.stroke()` for a description
1452 of the syntax and the :doc:`stroke </techref/stroke>` documentation for more general
1453 information.
1454
1455 .. method:: layer.transform(matrix)
1456
1457 Transforms the layer by the matrix
1458
1459 .. method:: layer.nltransform(xexpr, yexpr)
1460
1461 xexpr and yexpr are strings specifying non-linear transformations that will
1462 be applied to all points in the layer (with xexpr being applied to x values,
1463 and yexpr to y values, of course). The syntax for the expressions is
1464 explained in the :ref:`non-linear transform dialog <transform.Non-Linear>`.
1465
1466 .. method:: layer.boundingBox()
1467
1468 Returns a tuple representing a rectangle ``(xmin,ymin, xmax,ymax)`` into
1469 which the layer fits. It is not guaranteed to be the smallest such
1470 rectangle, but it will often be.
1471
1472 .. method:: layer.xBoundsAtY(ybottom[, ytop])
1473
1474 Finds the minimum and maximum x positions attained by the layer when y is
1475 between ybottom and ytop (if ytop is not specified it is assumed the same as
1476 ybottom). If the layer does not have any y values in the specified range
1477 then FontForge will return ``None``.
1478
1479 .. method:: layer.yBoundsAtX(xleft[, xright])
1480
1481 Finds the minimum and maximum y positions attained by the layer when x is
1482 between xleft and xright (if xright is not specified it is assumed the same
1483 as xleft). If the layer does not have any x values in the specified range
1484 then FontForge will return ``None``.
1485
1486 .. method:: layer.draw(pen)
1487
1488 Draw the layer to the :class:`pen <glyphPen>` argument.
1489
1490 .. method:: layer.addInflections()
1491
1492 Please see :meth:`contour.addInflections()`.
1493
1494 .. method:: layer.balance()
1495
1496 Please see :meth:`contour.balance()`.
1497
1498 .. method:: layer.harmonize()
1499
1500 Please see :meth:`contour.harmonize()`.
1501
1502
1503 .. rubric:: Sequence Protocol
1504
1505 Does not support the repeat, slice and contains concepts.
1506
1507 .. object:: len(l)
1508
1509 The number of contours in the layer
1510
1511 .. object:: l[i]
1512
1513 The ``i`` th contour in the layer. You may assign a contour to this (keeping
1514 the number of contours constant) or use ``del l[i]`` to remove the entry
1515 (reducing the number by one)
1516
1517 .. object:: l + m
1518
1519 A layer concatenating l and m. m may be either another layer or a contour.
1520
1521 .. object:: l += m
1522
1523 Appends m to l. m may be either another layer or a contour.
1524
1525
1526 Glyph Pen
1527 ---------
1528
1529 This implements the `Pen Protocol <http://robofab.org/objects/pens.html>`_ to
1530 draw a FontForge :class:`glyph`. You create a :class:`glyphPen` with
1531 :meth:`glyph.glyphPen()`. You then draw into it with the operators below.
1532
1533 This type may not be pickled.
1534
1535 .. rubric:: Example
1536
1537 ::
1538
1539 import fontforge
1540 font = fontforge.open("Ambrosia.sfd") # Open a font
1541 pen = font["B"].glyphPen() # Create a pen to draw into glyph "B"
1542 pen.moveTo((100,100)) # draw a square
1543 pen.lineTo((100,200))
1544 pen.lineTo((200,200))
1545 pen.lineTo((200,100))
1546 pen.closePath() # end the contour
1547
1548 font["A"].draw(pen) # or you can copy from one glyph to another
1549 # by having a glyph draw itself into the pen
1550 pen = None # Finalize the pen. This tells FontForge
1551 # that the drawing is done and causes
1552 # it to refresh the display (if a UI is active).
1553
1554
1555 .. class:: glyphPen
1556
1557 .. method:: glyphPen.moveTo((x, y))
1558
1559 With one exception this call begins every contour and creates an on curve
1560 point at ``(x,y)`` as the start point of that contour. This should be the
1561 first call after a pen has been created and the call that follows a
1562 :meth:`glyphPen.closePath()`, :meth:`glyphPen.endPath()`.
1563
1564 .. method:: glyphPen.lineTo((x, y))
1565
1566 Draws a line from the last point to ``(x,y)`` and adds that to the contour.
1567
1568 .. method:: glyphPen.curveTo((cp1.x, cp1.y), (cp2.x, cp2.y), (x, y)) ((cp.x, cp.y), (x, y))
1569
1570 This routine has slightly different arguments depending on the type of the
1571 font. When drawing into a cubic font (PostScript) use the first set of
1572 arguments (with two control points -- off curve points -- between each on
1573 curve point). When drawing into a quadratic font (TrueType) use the second
1574 format with one control point between adjacent on-curve points.
1575
1576 The standard appears to support super-bezier curves with more than two
1577 control points between on-curve points. FontForge does not. Nor does
1578 FontForge allow you to draw a quadratic spline into a cubic font, nor vice versa.
1579
1580 .. method:: glyphPen.qCurveTo([(cp.x, cp.y)]*, (x, y)) ([(cp.x, cp.y)]*, None))
1581
1582 This routine may only be used in quadratic (TrueType) fonts and has two
1583 different formats. It is used to express the TrueType idiom where an on-curve
1584 point mid-way between its control points may be omitted, leading to a run of
1585 off-curve points (with implied but unspecified on-curve points between them).
1586
1587 The first format allows an arbitrary number of off-curve points followed by
1588 one on-curve point.
1589
1590 It is possible to have a contour which consists solely of off-curve points.
1591 When this happens the contour is NOT started with a :meth:`glyphPen.moveTo()`,
1592 instead the entire contour, all the off curve points, are listed in one call,
1593 and the argument list is terminated by a ``None`` to indicate there are no
1594 on-curve points.
1595
1596 .. method:: glyphPen.closePath()
1597
1598 Closes the contour (connects the last point to the first point to make a
1599 loop) and ends it.
1600
1601 .. method:: glyphPen.endPath()
1602
1603 Ends the contour without closing it. This is only relevant if you are
1604 stroking contours.
1605
1606 .. method:: glyphPen.addComponent(glyph_name[, transform, selected])
1607
1608 Adds a reference (a component) to the glyph. The PostScript transformation
1609 matrix is a 6 element tuple (with a default of the identity transformation).
1610 When ``selected`` is true the reference will be marked as selected in the
1611 UI and related API calls.
1612
1613
1614 Glyph
1615 -----
1616
1617 The glyph type refers to a :class:`glyph` object. It has no independent life
1618 of its own, it always lives within a font. It has all the things you expect to
1619 be associated with a glyph: a glyph name, a unicode encoding, a drawing layer,
1620 GPOS/GSUB features...
1621
1622
1623 This type may not be pickled.
1624
1625 This type may not be created directly -- all glyphs are bound to a font and
1626 must be created through the font.
1627
1628 .. class:: glyph
1629
1630 **Note:** Glyphs do not have an independent existence. They live in fonts.
1631 You may not create them stand-alone, only in the context of a font. See
1632 :meth:`font.createChar()`.
1633
1634 .. attribute:: glyph.activeLayer
1635
1636 Returns currently active layer in the glyph (as an integer). May be set to
1637 an integer or a layer name to change the active layer.
1638
1639 .. attribute:: glyph.altuni
1640
1641 Returns additional unicode code points for this glyph. For a primary code
1642 point, see :attr:`glyph.unicode`.
1643
1644 Returns either None or a tuple of alternate encodings. Each alternate
1645 encoding is a tuple of ::
1646
1647 (unicode-value, variation-selector, reserved-field)
1648
1649 The first is a unicode value of this alternate code point. The second is an
1650 integer for variation selector and can be set to -1 if not used. The third
1651 is an empty field reserved for future use and currently must be set to zero.
1652
1653 :attr:`glyph.altuni` can be set to None to clear all alternates, or to a
1654 tuple. The elements of the tuple may be either integers (an alternate
1655 unicode value with no variation selector) or a tuple with up to 3 values in
1656 it as explained above.
1657
1658 .. attribute:: glyph.anchorPoints
1659
1660 Returns the list of anchor points in the glyph. Each anchor point is a
1661 tuple of ::
1662
1663 (anchor-class-name, type, x,y [,ligature-index])
1664
1665 The first two are strings, the next two doubles, and the last (which is only
1666 present if ``type=="ligature"``) is an integer. Type may be
1667
1668 * ``mark``
1669 * ``base``
1670 * ``ligature``
1671 * ``basemark``
1672 * ``entry``
1673 * ``exit``
1674
1675 .. attribute:: glyph.anchorPointsWithSel
1676
1677 Same as the above, except also includes whether the anchor point is selected
1678 in the UI. Returns a tuple of all anchor points in the glyph. Each anchor
1679 point is a tuple of ::
1680
1681 (anchor-class-name, type, x,y, selected [,ligature-index])
1682
1683 The first two are strings, the next two doubles, then a boolean, and the
1684 last (which is only present if ``type=="ligature"``) is an integer.
1685 Type may be
1686
1687 * ``mark``
1688 * ``base``
1689 * ``ligature``
1690 * ``basemark``
1691 * ``entry``
1692 * ``exit``
1693
1694 .. attribute:: glyph.background
1695
1696 The glyph's background layer. This is a *copy* of the glyph's data. See
1697 also :attr:`glyph.foreground` and :attr:`glyph.layers`.
1698
1699 .. attribute:: glyph.changed
1700
1701 Whether this glyph has been modified. This is (should be) maintained
1702 automatically, but you may set it if you wish.
1703
1704 .. attribute:: glyph.codepoint
1705
1706 Unicode code point for this glyph in U+XXXX format for the Basic Multilingual
1707 Plane, and up to U+XXXXXX for the supplementary planes, or ``None``. (readonly)
1708
1709 .. attribute:: glyph.color
1710
1711 The color of the glyph in the fontview. A 6 hex-digit RGB number or -1 for
1712 default. 0xffffff is white, 0x0000ff is blue, etc.
1713
1714 .. attribute:: glyph.comment
1715
1716 Any comment you wish to associate with the glyph. UTF-8
1717
1718 .. attribute:: glyph.dhints
1719
1720 A tuple with one entry for each diagonal stem hint. Each stem hint is itself
1721 represented by a tuple of three coordinate pairs (themselves tuples of two
1722 numbers), these three are: a point on one side of the stem, a point on the
1723 other side, and a unit vector pointing in the stem's direction.
1724
1725 .. attribute:: glyph.encoding
1726
1727 Returns the glyph's encoding in the font's encoding. (readonly)
1728
1729 If the glyph has multiple encodings, one will be picked at random.
1730
1731 If the glyph is not in the font's encoding then a number will be returned
1732 beyond the encoding size (or in some cases -1 will be returned).
1733
1734 .. attribute:: glyph.font
1735
1736 The font containing this glyph. (readonly)
1737
1738 .. attribute:: glyph.foreground
1739
1740 The glyph's foreground layer. This is a *copy* of the glyph's data. See also
1741 :attr:`glyph.background`, :attr:`glyph.layers` and :attr:`glyph.references`.
1742
1743 .. attribute:: glyph.glyphclass
1744
1745 An opentype glyphclass, one of automatic, noclass, baseglyph, baseligature,
1746 mark, component
1747
1748 .. attribute:: glyph.glyphname
1749
1750 The name of the glyph
1751
1752 .. attribute:: glyph.hhints
1753
1754 A tuple of all horizontal postscript hints. Each hint is itself a tuple of
1755 starting locations and widths.
1756
1757 .. attribute:: glyph.horizontalComponents
1758
1759 A tuple of tuples.
1760
1761 This allows :ref:`constructing <math.GlyphConstruction>` very large versions
1762 of the glyph by stacking the components together. Some components may be
1763 repeated so there is no bound on the size.
1764
1765 This is different from horizontalVariants which expects prebuilt glyphs of
1766 various fixed sizes.
1767
1768 The components are stacked in the order they appear in the (top-level) tuple.
1769 Each sub-tuple represents information on one component. The subtuple should
1770 contain: (String glyph-name, Boolean is-extender, Int startConnectorLength,
1771 Int endConnectorLength, Int fullAdvance). Any of these may be omitted (except
1772 the glyph name) and will be assumed to be 0 if so.
1773
1774 .. attribute:: glyph.horizontalComponentItalicCorrection
1775
1776 The italic correction for any composite glyph made with the horizontalComponents.
1777
1778 .. attribute:: glyph.horizontalVariants
1779
1780 A string containing a list of glyph names. These are
1781 :ref:`alternate forms <math.Variants>` of the current glyph for use in
1782 typesetting math. Presumably the variants are of different sizes.
1783
1784 Although ff will always return a string of glyph names, you may assign to it
1785 with a tuple of glyphs and ff will convert that to corresponding names.
1786
1787 .. attribute:: glyph.isExtendedShape
1788
1789 A boolean containing the MATH "is extended shape" field.
1790
1791 .. attribute:: glyph.italicCorrection
1792
1793 The glyph's italic correction field. Used by both TeX and MATH. The special
1794 value :data:`fontforge.unspecifiedMathValue` means the value is unspecified
1795 (An unspecified value will not go into the output tables, a value of 0 will)
1796
1797 .. attribute:: glyph.layer_cnt
1798
1799 The number of layers in this glyph. (Cannot be set)
1800
1801 .. attribute:: glyph.layers
1802
1803 A dictionary like object containing the layers of the glyph. It may be
1804 indexed by either a layer name or an integer between 0 and
1805 ``glyph.layer_cnt-1`` to produce a :class:`layer` object. Layer 0 is the
1806 background layer. Layer 1 is the foreground layer.
1807
1808 .. attribute:: glyph.layerrefs
1809
1810 A dictionary like object containing the references in the layers of the
1811 glyph. It may be indexed by either a layer name, or an integer between 0 and
1812 ``glyph.layer_cnt-1`` to produce a :attr:`reference tuple<glyph.references>`
1813 object. Layer 0 is the background layer. Layer 1 is the foreground layer.
1814
1815 .. attribute:: glyph.lcarets
1816
1817 A tuple containing the glyph's ligature caret locations. Setting this will
1818 also either enable or disable the "Default Ligature Caret Count" flag
1819 depending from the number of elements in the tuple.
1820
1821 .. attribute:: glyph.left_side_bearing
1822
1823 The left side bearing of the glyph. Setting this value will adjust all
1824 layers so that guides in the background etc will be adjusted with the rest
1825 of the glyph
1826
1827 .. attribute:: glyph.manualHints
1828
1829 The glyph's hints have been set by hand, and the glyph should not be
1830 autohinted without a specific request from the user. The "Don't AutoHint" flag.
1831
1832 .. attribute:: glyph.mathKern.bottomLeft
1833
1834 The glyph's math kerning data associated with the bottom left vertex. This
1835 returns a tuple of two element tuples, each of which contains a kerning
1836 offset and an associated height (in the last entry the height term is
1837 meaningless, but present).
1838
1839 .. attribute:: glyph.mathKern.bottomRight
1840
1841 The glyph's math kerning data associated with the bottom right vertex. This
1842 returns a tuple of two element tuples, each of which contains a kerning
1843 offset and an associated height (in the last entry the height term is
1844 meaningless, but present).
1845
1846 .. attribute:: glyph.mathKern.topLeft
1847
1848 The glyph's math kerning data associated with the top left vertex. This
1849 returns a tuple of two element tuples, each of which contains a kerning
1850 offset and an associated height (in the last entry the height term is
1851 meaningless, but present).
1852
1853 .. attribute:: glyph.mathKern.topRight
1854
1855 The glyph's math kerning data associated with the top right vertex. This
1856 returns a tuple of two element tuples, each of which contains a kerning
1857 offset and an associated height (in the last entry the height term is
1858 meaningless, but present).
1859
1860 .. attribute:: glyph.originalgid
1861
1862 The GID of this glyph in the font it was read from. (readonly)
1863
1864 .. attribute:: glyph.persistent
1865
1866 Whatever you want (these data will be saved as a pickled object in the
1867 sfd file. It is your job to ensure that whatever you put here can be pickled).
1868 See also the :attr:`glyph.temporary` field.
1869
1870 .. attribute:: glyph.references
1871
1872 A tuple of tuples containing, for each reference in the foreground, a
1873 glyph-name, a transformation matrix, and whether the reference is currently
1874 selected. When assigning to the object the matrix and ``selected`` values
1875 are optional. See also :attr:`glyph.foreground` and :attr:`glyph.layerrefs`.
1876
1877 .. attribute:: glyph.right_side_bearing
1878
1879 The right side bearing of the glyph
1880
1881 .. attribute:: glyph.script
1882
1883 A string containing the OpenType 4 letter tag for the script associated with
1884 this glyph (readonly)
1885
1886 .. attribute:: glyph.temporary
1887
1888 Whatever you want (these data will be lost once the font is closed)
1889
1890 See also :attr:`glyph.persistent`.
1891
1892 .. attribute:: glyph.texheight
1893
1894 The Tex height. The special value :data:`fontforge.unspecifiedMathValue`
1895 means the field is unspecified (An unspecified value will not go into the
1896 output tables, a value of 0 will)
1897
1898 .. attribute:: glyph.texdepth
1899
1900 The Tex depth. The special value :data:`fontforge.unspecifiedMathValue`
1901 means the field is unspecified (An unspecified value will not go into the
1902 output tables, a value of 0 will)
1903
1904 .. attribute:: glyph.topaccent
1905
1906 The glyph's top accent position field. Used by MATH. The special value
1907 :data:`fontforge.unspecifiedMathValue` means the field is unspecified (An
1908 unspecified value will not go into the output tables, a value of 0 will)
1909
1910 .. attribute:: glyph.ttinstrs
1911
1912 Any truetype instructions, returned as a binary string
1913
1914 .. attribute:: glyph.unicode
1915
1916 The glyph's unicode code point, or -1. In addition to this primary mapping,
1917 a glyph can have multiple secondary mappings - see :attr:`glyph.altuni`.
1918
1919 .. attribute:: glyph.unlinkRmOvrlpSave
1920
1921 A flag that indicates the glyph's references should be unlinked and remove
1922 overlap run on it before the font is saved (and then the original references
1923 replaced after the save finishes)
1924
1925 .. attribute:: glyph.user_decomp
1926
1927 Your preferred decomposition for this glyph; used by :meth:`glyph.build()`.
1928
1929 .. attribute:: glyph.userdata
1930
1931 .. warning:: Deprecated name for :attr:`glyph.temporary`
1932
1933 .. attribute:: glyph.vhints
1934
1935 A tuple of all vertical postscript hints. Each hint is itself a tuple of
1936 starting locations and widths.
1937
1938 .. attribute:: glyph.validation_state
1939
1940 A bit mask indicating some problems this glyph might have. (readonly)
1941
1942 .. object:: 0x1
1943
1944 If set then this glyph has been validated.
1945
1946 If unset then other bits are meaningless.
1947
1948 .. object:: 0x2
1949
1950 Glyph has an open contour.
1951
1952 .. object:: 0x4
1953
1954 Glyph intersects itself somewhere.
1955
1956 .. object:: 0x8
1957
1958 At least one contour is drawn in the wrong direction
1959
1960 .. object:: 0x10
1961
1962 At least one reference in the glyph has been flipped
1963
1964 (and so is drawn in the wrong direction)
1965
1966 .. object:: 0x20
1967
1968 Missing extrema
1969
1970 .. object:: 0x40
1971
1972 A glyph name referred to from this glyph, in an opentype table, is not
1973 present in the font.
1974
1975 .. object:: 0x40000
1976
1977 Points (or control points) are too far apart. (Coordinates must be
1978 within 32767)
1979
1980 **Postscript only**
1981
1982 .. object:: 0x80
1983
1984 PostScript has a limit of 1500 points in a glyph.
1985
1986 .. object:: 0x100
1987
1988 PostScript has a limit of 96 hints in a glyph.
1989
1990 .. object:: 0x200
1991
1992 Invalid glyph name.
1993
1994 **TrueType only, errors in original file**
1995
1996 .. object:: 0x400
1997
1998 More points in a glyph than allowed in 'maxp'
1999
2000 .. object:: 0x800
2001
2002 More paths in a glyph than allowed in 'maxp'
2003
2004 .. object:: 0x1000
2005
2006 More points in a composite glyph than allowed in 'maxp'
2007
2008 .. object:: 0x2000
2009
2010 More paths in a composite glyph than allowed in 'maxp'
2011
2012 .. object:: 0x4000
2013
2014 Instructions longer than allowed in 'maxp'
2015
2016 .. object:: 0x8000
2017
2018 More references in a glyph than allowed in 'maxp'
2019
2020 .. object:: 0x10000
2021
2022 References nested more deeply than allowed in 'maxp'
2023
2024 .. object:: 0x40000
2025
2026 Points too far apart. TrueType and Type2 fonts are limited to 16 bit
2027 numbers, and so adjacent points must be within 32767 em-units of each other.
2028
2029 .. object:: 0x80000
2030
2031 Points non-integral. TrueType points and control points must be integer
2032 aligned. (FontForge will round them if they aren't)
2033
2034 .. object:: 0x100000
2035
2036 Missing anchor. According to the opentype spec, if a glyph contains an
2037 anchor point for one anchor class in a subtable, it must contain anchor
2038 points for all anchor classes in the subtable. Even it, logically, they
2039 do not apply and are unnecessary.
2040
2041 .. object:: 0x200000
2042
2043 Duplicate glyph name. Two (or more) glyphs in this font have the same
2044 name. When outputting a PostScript font only one of them will ever be seen.
2045
2046 It's a little hard to detect this in normal use, but if you change the
2047 encoding to "Glyph Order", and then use Edit->Select->Wildcard and enter
2048 the glyph name, both of them should be selected.
2049
2050 .. object:: 0x400000
2051
2052 Duplicate unicode code point. Two (or more) glyphs in this font have the
2053 code point. When outputting an sfnt (TrueType/OpenType) font only one of
2054 them will ever be seen.
2055
2056 It's a little hard to detect this in normal use, but if you change the
2057 encoding to "Glyph Order", and then use Edit->Select->Wildcard and enter
2058 the code point, both of them should be selected.
2059
2060 .. object:: 0x800000
2061
2062 Overlapped hints. Either the glyph has no hint masks and there are
2063 overlapped hints, or a hint mask specifies two overlapping hints.
2064
2065 .. attribute:: glyph.verticalComponents
2066
2067 A tuple of tuples.
2068
2069 This allows :ref:`constructing <math.GlyphConstruction>` very large versions
2070 of the glyph by stacking the components together. Some components may be
2071 repeated so there is no bound on the size.
2072
2073 This is different from verticalVariants which expects prebuilt glyphs of
2074 various fixed sizes.
2075
2076 The components are stacked in the order they appear in the (top-level) tuple.
2077 Each sub-tuple represents information on one component. The subtuple should
2078 contain: (String glyph-name, Boolean is-extender, Int startConnectorLength,
2079 Int endConnectorLength, Int fullAdvance). Any of these may be omitted
2080 (except the glyph name) and will be assumed to be 0 if so.
2081
2082 .. attribute:: glyph.verticalComponentItalicCorrection
2083
2084 The italic correction for any composite glyph made with the verticalComponents.
2085
2086 .. attribute:: glyph.verticalVariants
2087
2088 A string containing a list of glyph names. These are
2089 :ref:`alternate forms <math.Variants>`
2090 of the current glyph for use in typesetting math. Presumably the variants
2091 are of different sizes.
2092
2093 .. attribute:: glyph.width
2094
2095 The advance width of the glyph. See also :attr:`glyph.vwidth`.
2096
2097 .. attribute:: glyph.vwidth
2098
2099 The vertical advance width of the glyph. See also :attr:`glyph.width`.
2100
2101 .. method:: glyph.addAnchorPoint(anchor_class_name, anchor_type, x, y[, ligature_index])
2102
2103 Adds an anchor point. anchor-type may be one of the strings
2104
2105 * ``"mark"``
2106 * ``"base"``
2107 * ``"ligature"``
2108 * ``"basemark"``
2109 * ``"entry"``
2110 * ``"exit"``
2111
2112
2113 If there is an anchor point with the same ``anchor_class_name`` and:
2114
2115 * lookup type is ``"gpos_mark2base"`` or
2116 * lookup type is ``"gpos_mark2ligature"`` and ``ligature_index`` is the same or
2117 * ``anchor_type`` is the same
2118
2119 then the existing anchor will be overwritten.
2120
2121 .. method:: glyph.addExtrema([flags, emsize])
2122
2123 Extrema should be marked by on-curve points. If a curve lacks a point at an
2124 extrema this command will add one. Flags may be one of the following strings
2125
2126 .. object:: all
2127
2128 Add all missing extrema
2129
2130 .. object:: only_good
2131
2132 Only add extrema on longer splines (with respect to the em-size)
2133
2134 .. object:: only_good_rm
2135
2136 As above but also merge away on-curve points which are very close to,
2137 but not on, an added extremum
2138
2139 .. method:: glyph.addReference(glyph_name[, transform, selected])
2140
2141 Adds a reference to the specified glyph into the current glyph. Optionally
2142 specifying a transformation matrix and whether the reference is to be
2143 marked selected in the UI and related API calls.
2144
2145 .. method:: glyph.addHint(is_vertical, start, width)
2146
2147 Adds a postscript hint. Takes a boolean flag indicating whether the hint is
2148 horizontal or vertical, a start location and the hint's width.
2149
2150 .. method:: glyph.addPosSub(subtable_name, variant)
2151 glyph.addPosSub(subtable_name, variants)
2152 glyph.addPosSub(subtable_name, ligature_components)
2153 glyph.addPosSub(subtable_name, xoff, yoff, xadv, yadv)
2154 glyph.addPosSub(subtable_name, other_glyph_name, kerning)
2155 glyph.addPosSub(subtable_name, other_glyph_name, xoff1, yoff1, xadv1, yadv1, xoff2, yoff2, xadv2, yadv2)
2156
2157 Adds position/substitution data to the glyph. The number and type of the
2158 arguments vary according to the type of the lookup containing the subtable.
2159
2160 The first argument should always be a lookup subtable name.
2161
2162 If the lookup is for single substitutions then the second argument should be
2163 a string containing a single glyph name.
2164
2165 For multiple and alternated substitutions a tuple of glyph names. For
2166 ligatures, a tuple of the ligature components (glyph names).
2167
2168 For single positionings the second through fifth arguments should be small
2169 integers representing the adjustment along the appropriate axis.
2170
2171 For pairwise positionings (kerning) the second argument should be the name
2172 of the other glyph being kerned with, and the third through tenth should be
2173 small integers -- or, if there are exactly three arguments then the third
2174 specifies traditional, one-axis, kerning.
2175
2176 If there is a previously existing entry, this will replace it (except for
2177 ligatures).
2178
2179 .. method:: glyph.appendAccent(name="glyph_name")
2180 glyph.appendAccent(unicode=<codepoint>)
2181
2182 Makes a reference to the specified glyph, adds that reference to the current
2183 layer of this glyph, and positions it to make a reasonable accent.
2184
2185 .. method:: glyph.autoHint()
2186
2187 Generates PostScript hints for this glyph.
2188
2189 .. method:: glyph.autoInstr()
2190
2191 Generates TrueType instructions for this glyph.
2192
2193 .. method:: glyph.autoTrace()
2194
2195 Auto traces any background images
2196
2197 .. method:: glyph.boundingBox()
2198
2199 Returns a tuple representing a rectangle (xmin,ymin, xmax,ymax) which is
2200 the minimum bounding box of the glyph.
2201
2202 .. method:: glyph.build()
2203
2204 If the character is a composite character, then clears it and inserts
2205 references to its components.
2206
2207 .. method:: glyph.canonicalContours()
2208
2209 Orders the contours in the current glyph by the x coordinate of their
2210 leftmost point. (This can reduce the size of the charstring needed to
2211 describe the glyph(s).
2212
2213 .. method:: glyph.canonicalStart()
2214
2215 Sets the start point of all the contours of the current glyph to be the
2216 leftmost point on the contour. (If there are several points with that value
2217 then use the one which is closest to the baseline). This can reduce the size
2218 of the charstring needed to describe the glyph(s). By regularizing things it
2219 can also make more things available to be put in subroutines.
2220
2221 .. method:: glyph.changeWeight(stroke_width[, type, serif_height, serif_fuzz, counter_type, removeoverlap, custom_zones])
2222
2223 See the :ref:`Element->Style->Change Width <Styles.Embolden>` command for a
2224 more complete description of these arguments.
2225
2226 ``stroke_width`` is the amount by which all stems are expanded.
2227
2228 ``type`` is one of ``"LCG"``, ``"CJK"``, ``"auto"``, ``"custom"``.
2229
2230 ``serif_height`` tells ff not to expand serifs which are that much off the
2231 baseline, while serif_fuzz specifies the amount of fuzziness allowed in the
2232 match. If you don't want special serif behavior set this to 0.
2233
2234 ``counter_type`` is one of ``"squish"``, ``"retain"``, ``"auto"``.
2235
2236 ``removeoverlap`` (Cleanup Self Intersect) is a boolean int
2237 (0=false, 1=true). When activated, and FontForge detects that an expanded
2238 stroke will self-intersect, then setting this option will cause it to try to
2239 make things nice by removing the intersections.
2240
2241 ``custom_zones`` is only meaningful if the type argument were ``"custom"``.
2242 It may be either a number, which specifies the "top hint" value (bottom hint
2243 is assumed to be 0, others are between), or a tuple of 4 numbers (top hint,
2244 top zone, bottom zone, bottom hint).
2245
2246 .. method:: glyph.condenseExtend(c_factor, c_add[, sb_factor, sb_add, correct])
2247
2248 Condenses or extends the size of the counters and side-bearings of the glyph.
2249 The first two arguments provide information on shrinking/growing the
2250 counters, the second two the sidebearings. If the last two are omitted they
2251 default to the same values as the first two.
2252
2253 A counter's width will become: ::
2254
2255 new_width = c_factor * old_width + c_add
2256
2257 If present the ``correct`` argument allows you to specify whether you want
2258 to correct for the italic angle before condensing the glyph.
2259 (it defaults to``True``)
2260
2261 .. method:: glyph.clear([layer])
2262
2263 With no arguments, clears the contents of the glyph (and marks it as not :meth:`glyph.isWorthOutputting()`).
2264 It is not possible to clear the guide layer with this function.
2265 ``layer`` may be either an integer index or a string.
2266
2267 .. method:: glyph.cluster([within, max])
2268
2269 Moves clustered coordinates to a standard central value.
2270 See also :meth:`glyph.round()`.
2271
2272 .. method:: glyph.correctDirection()
2273
2274 Orients all contours so that external ones are clockwise and internal
2275 counter-clockwise.
2276
2277 .. method:: glyph.doUndoLayer([layer, redo])
2278
2279 When ``redo`` is False this method is equivalent to the "Undo" UI menu item.
2280 It restores the last preserved layer state discarding the current state.
2281 When ``redo`` is True it is equivalent to "Redo". You may omit the
2282 ``layer`` parameter, in which case the currently active layer will be used.
2283 Otherwise it must either be a layer name or an integer between 0 and
2284 ``glyph.layer_cnt-1``.
2285
2286 ``doUndoLayer`` is normally used in conjunction with
2287 :meth:`glyph.preserveLayerAsUndo()`
2288
2289 .. method:: glyph.exclude(excluded_layer)
2290
2291 Removes the excluded area from the current glyph. Takes an argument which is
2292 a layer. See also :meth:`glyph.removeOverlap()` and :meth:`glyph.intersect()`.
2293
2294 .. method:: glyph.export(filename[, KEYWORD])
2295
2296 Creates a file with the specified name containing a representation of
2297 the glyph. Uses the file's extension to determine output file type.
2298
2299 The following optional keywords modify the export process for various formats:
2300
2301 .. object:: layer (string or integer, default=glyph.activeLayer)
2302
2303 For vector formats, the layer to export.
2304
2305 .. object:: pixelsize (integer, default=100)
2306
2307 For raster formats, the size of the image to output.
2308
2309 .. object:: bitdepth (integer, default=8)
2310
2311 For raster formats, the depth of the image to output. Must be 1 or 8.
2312
2313 .. object:: usetransform (boolean, default=False)
2314
2315 Flip the Y-axis of exported SVGs with a transform element rather than
2316 modifying the individual Y values.
2317
2318 .. object:: usesystem (boolean, default=False)
2319
2320 Ignore the above keyword settings and use the values set by the user
2321 in the Import options dialog.
2322
2323 .. object:: asksystem (boolean, default=False)
2324
2325 If the UI is present show the Import options dialog to the user
2326 and use the chosen values (does nothing otherwise).
2327
2328 Note: The old positional layer/pixelsize,bitdepth calling conventions are
2329 still supported but are not compatible with the other keyword parameters.
2330
2331 .. method:: glyph.genericGlyphChange(stemType=<str>, thickThreshold=<double>, stemScale=<double>, stemAdd=<double>, stemHeightScale=<double>, stemHeightAdd=<double>, stemWidthScale=<double>, stemWidthAdd=<double>, thinStemScale=<double>, thinStemAdd=<double>, thickStemScale=<double>, thickStemAdd=<double>, processDiagonalStems=<boolean>, hCounterType=<str>, hCounterScale=<double>, hCounterAdd=<double>, lsbScale=<double>, lsbAdd=<double>, rsbScale=<double>, rsbAdd=<double>, vCounterType=<str>, vCounterScale=<double>, vCounterAdd=<double>, vScale=<double>, vMap=<tuple of tuples>)
2332
2333 Similar to :meth:`font.genericGlyphChange`, but acting on this glyph only.
2334
2335 .. method:: glyph.getPosSub(lookup_subtable_name)
2336
2337 Returns any positioning/substitution data attached to the glyph controlled
2338 by the lookup-subtable. If the name is ``"*"`` then returns data from all
2339 subtables.
2340
2341 The data are returned as a tuple of tuples. The first element of the
2342 subtuples is the name of the lookup-subtable. The second element will be one
2343 of the strings: ``"Position"``, ``"Pair"``, ``"Substitution"``,
2344 ``"AltSubs"``, ``"MultSubs"``, ``"Ligature"``.
2345
2346 Positioning data will be followed by four small integers representing
2347 adjustments to the: x position of the glyph, the y position, the horizontal
2348 advance, and the vertical advance.
2349
2350 Pair data will be followed by the name of the other glyph in the pair and
2351 then eight small integers representing adjustments to the: x position of the
2352 first glyph, the y position, the horizontal advance, and the vertical
2353 advance, and then a similar foursome for the second glyph.
2354
2355 Substitution data will be followed by a string containing the name of the
2356 glyph to replace the current one.
2357
2358 Multiple and Alternate data will be followed by several strings each
2359 containing the name of a replacement glyph.
2360
2361 Ligature data will be followed by several strings each containing the name
2362 of a ligature component glyph.
2363
2364 .. method:: glyph.importOutlines(filename, [KEYWORD])
2365
2366 Uses the file's extension to determine behavior. Imports outline descriptions
2367 (eps, svg, glif files) into the foreground layer. Imports image descriptions
2368 (bmp, png, xbm, etc.) into the background layer. The following optional keywords modify the import process for various formats:
2369
2370 .. object:: scale (boolean, default=True)
2371
2372 Scale imported images and SVGs to ascender height
2373
2374 .. object:: simplify (boolean, default=True)
2375
2376 Run simplify on the output of stroked paths
2377
2378 .. object:: accuracy (float, default=0.25)
2379
2380 The minimum accuracy (in em-units) of stroked paths.
2381
2382 .. object:: default_joinlimit (float, default=-1)
2383
2384 Override the format's default miterlimit for stroked paths, which is
2385 10.0 for PostScript and 4.0 for SVG. (Value -1 means "inherit" those
2386 defaults.)
2387
2388 .. object:: handle_eraser (boolean, default=False)
2389
2390 Certain programs use pens with white ink as erasers. When this flag is
2391 set FontForge will attempt to simulate that.
2392
2393 .. object:: correctdir (boolean, default=False)
2394
2395 Run "Correct direction" on (some) PostScript paths
2396
2397 .. object:: usesystem (boolean, default=False)
2398
2399 Ignore the above keyword settings and use the values set by the user
2400 in the Import options dialog.
2401
2402 .. object:: asksystem (boolean, default=False)
2403
2404 If the UI is present show the Import options dialog to the user
2405 and use the chosen values (does nothing otherwise).
2406
2407 Note: The old PostScript correctdir/handle_eraser flag tuple is still
2408 supported but is not compatible with the other keywords.
2409
2410 .. method:: glyph.intersect()
2411
2412 Leaves only areas in the intersection of contours. See also
2413 :meth:`glyph.removeOverlap()` and :meth:`glyph.exclude()`.
2414
2415 .. method:: glyph.isWorthOutputting()
2416
2417 Returns whether the glyph is worth outputting into a font file. Basically a
2418 glyph is worth outputting if it contains any contours, or references or has
2419 had its width set.
2420
2421 .. method:: glyph.preserveLayerAsUndo([layer, dohints])
2422
2423 Normally undo handling is turned off during python scripting. This method
2424 preserves the current state of a layer so that whatever you do after can be
2425 undone by the user. You may omit the ``layer`` parameter, in which case the
2426 currently active layer will be used. Otherwise it must either be a layer name
2427 or an integer between 0 and ``glyph.layer_cnt-1``. When ``dohints`` is True
2428 then hints will also be preserved (they are not by default).
2429
2430 .. method:: glyph.removeOverlap()
2431
2432 Removes overlapping areas.
2433 See also :meth:`glyph.intersect()` and :meth:`glyph.exclude()`.
2434
2435 .. method:: glyph.removePosSub(lookup_subtable_name)
2436
2437 Removes all data from the glyph corresponding to the given lookup-subtable.
2438 If the name is "*" then all data will be removed.
2439
2440 .. method:: glyph.round([factor])
2441
2442 Rounds the x and y coordinates of each point in the glyph. If factor is
2443 specified then ::
2444
2445 new-coord = round(factor*old-coord)/factor
2446
2447 See also :meth:`glyph.cluster()`.
2448
2449 .. method:: glyph.selfIntersects()
2450
2451 Returns whether any of the contours in this glyph intersects any other
2452 contour in the glyph (including itself).
2453
2454 .. method:: glyph.setLayer(layer, layer_index[, flags])
2455
2456 An alternative to assigning to :attr:`glyph.layers`, :attr:`glyph.background`,
2457 or :attr:`glyph.foreground`, and equivalent to those when not using the
2458 optional ``flags`` argument. When present, ``flags`` can be used to influence
2459 the types FontForge will assign to on-curve points. It should be a tuple of
2460 up to three of the following strings.
2461
2462 (In the following descriptions *selected* refers to points picked out by the
2463 chosen ``select_`` flag, which is unrelated to :attr:`point.selected`. At
2464 most one ``"select_"`` flag and one mode flag should be included.)
2465
2466 .. object:: select_none
2467
2468 Each (on-curve) point will be assigned a type corresponding to its
2469 :attr:`point.type` value.
2470
2471 .. object:: select_all
2472
2473 (default) Each point will have a type assigned according to the chosen mode.
2474
2475 .. object:: select_smooth
2476
2477 Each point with the type :data:`splineCorner` will retain that type,
2478 others will be assigned a type according to the chosen mode. This makes
2479 :attr:`point.type` function like the ``smooth`` tag in the UFO glif
2480 format and some other spline storage formats.
2481
2482 .. object:: select_incompat
2483
2484 Each point with a type compatible with its current geometry will retain
2485 that type, others will be assigned a type according to the chosen mode.
2486
2487 .. object:: by_geom
2488
2489 (default) In this mode, each *selected* point will be assigned a type
2490 based on only its geometry. (However, see ``"hvcurve"``` below.)
2491
2492 .. object:: downgrade
2493
2494 In this mode, each *selected* point will be assigned the most specific
2495 type compatible with its geometry and its :attr:`point.type`. A point
2496 marked :data:`splineHVCurve` can keep that type or be downgraded to
2497 :data:`splineCurve` or :data:`splineCorner`, while a :data:`splineCurve`
2498 or :data:`splineTangent` can keep that (respective) type or be downgraded
2499 to :data:`splineCorner`. (:data:`splineCorner` is compatible with any
2500 geometry.)
2501
2502 .. object:: check
2503
2504 In this mode, the type of each *selected* point is verified to be
2505 compatible with its geometry. If it is not compatible the function raises
2506 an exception. (At present this exception is not very informative. However,
2507 to identify the specific problem one can duplicate the layer, use
2508 :meth:`glyph.setLayer()` with ``downgrade``, and then retrieve the layer
2509 and compare it with the original.)
2510
2511 .. object:: force
2512
2513 In this mode, the geometry of each *selected* point is altered to match
2514 its :attr:`point.type`, similar to changing a point's type using the UI.
2515 Note that FontForge's point conversion algorithm is not sophisticated
2516 and may not have the desired result.
2517
2518 .. object:: hvcurve
2519
2520 This extra flag can be used to include :data:`splineHVCurve` among the
2521 types that can be assigned "by geometry". Normally FontForge assigns
2522 :data:`splineCurve` to on-curve points with strictly horizontal or
2523 vertical off-curve points.
2524
2525 .. method:: glyph.simplify([error_bound, flags, tan_bounds, linefixup, linelenmax])
2526
2527 Tries to remove excess points in the glyph if doing so will not perturb the
2528 curve by more than ``error-bound``. Flags is a tuple of the following strings
2529
2530 .. object:: ignoreslopes
2531
2532 Allow slopes to change
2533
2534 .. object:: ignoreextrema
2535
2536 Allow removal of extrema
2537
2538 .. object:: smoothcurves
2539
2540 Allow curve smoothing
2541
2542 .. object:: choosehv
2543
2544 Snap to horizontal or vertical
2545
2546 .. object:: forcelines
2547
2548 flatten bumps on lines
2549
2550 .. object:: nearlyhvlines
2551
2552 Make nearly horizontal/vertical lines be so
2553
2554 .. object:: mergelines
2555
2556 Merge adjacent lines into one
2557
2558 .. object:: setstarttoextremum
2559
2560 Rotate the point list so that the start point is on an extremum
2561
2562 .. object:: removesingletonpoints
2563
2564 If the contour contains just one point then remove it
2565
2566 .. method:: glyph.stroke("circular", width[, CAP, JOIN, FLAGS])
2567 glyph.stroke("elliptical", width, minor_width, ANGLE[, CAP, JOIN, FLAGS])
2568 glyph.stroke("calligraphic", width, height, angle[, FLAGS])
2569 glyph.stroke("polygon", contour[, FLAGS])
2570 (Legacy interface)
2571 :noindex:
2572
2573 .. method:: glyph.stroke("circular", width[, CAP, JOIN, ANGLE, KEYWORD])
2574 glyph.stroke("elliptical", width, minor_width[, ANGLE, CAP, JOIN, KEYWORD])
2575 glyph.stroke("calligraphic", width, height[, ANGLE, CAP, JOIN, KEYWORD])
2576 glyph.stroke("convex", contour[, ANGLE, CAP, JOIN, KEYWORD])
2577 (Current interface)
2578
2579 Strokes the contours of the glyph according to the supplied parameters. See
2580 the :doc:`stroke </techref/stroke>` documentation for a more complete description of
2581 the facility and its parameters.
2582
2583 A ``"circular"`` nib just has a ``width`` (the diameter), while an
2584 ``"elliptical"`` nib has a ``width`` (major axis) and a ``minor_width``
2585 (minor axis). A ``"calligraphic"`` or ``"rectangular"`` nib is similar in
2586 that it has a ``width`` and a ``height``. Finally a ``"convex"`` nib is one
2587 supplied by the user as a :class:`fontforge.contour` or :class:`fontforge.layer`.
2588 It must be *convex* as defined in the main stroke facility documentation.
2589
2590 ``ANGLE`` is optional. It can be specified either positionally or with
2591 ``angle=float``. It must be a floating point number in units of radians and
2592 defaults to zero. The nib is rotated by this angle before stroking the path.
2593
2594 ``CAP`` is optional. It can be specified either positionally or with
2595 ``cap=string``. It must be one of the strings "nib" (the default), "butt",
2596 "round", and "bevel".
2597
2598 ``JOIN`` is optional. It can be specified either positionally or with
2599 ``join=string``. It must be one of the strings "nib" (the default), "bevel",
2600 "miter", and "miterclip", "round", and "arcs".
2601
2602 ``KEYWORD`` Parameters:
2603
2604 .. object:: removeinternal (boolean, default=False)
2605
2606 When a contour is closed and clockwise, only the smaller "inside" contour
2607 is retained. When a contour is closed and counter-clockwise only the
2608 larger "outside" contour is retained.
2609
2610 .. object:: removeexternal (boolean, default=False)
2611
2612 When a contour is closed and clockwise, only the larger "outside" contour
2613 is retained. When a contour is closed and counter-clockwise only the
2614 smaller "inside" contour is retained.
2615
2616 .. object:: extrema (boolean, default=True)
2617
2618 When true, any missing extrema on the stroked paths are added.
2619
2620 .. object:: simplify (boolean, default=True)
2621
2622 When true, simplify is called on the path before it is returned. The
2623 ``error-bound`` is set to the ``accuracy`` value.
2624
2625 .. object:: removeoverlap (string, default="layer")
2626
2627 Specifies whether, and on what basis, remove-overlap should be run.
2628 "layer" corresponds to running remove-overlap on the :class:`layer` as a
2629 whole. "contour" corresponds to running remove-overlap on individual
2630 contours. "none" corresponds to not running remove-overlap. Note that
2631 because the stroke facility relies on remove-overlap to eliminate cusps
2632 and other artifacts, "none" is an unusual choice and available primarily
2633 for debugging purposes.
2634
2635 .. object:: accuracy (float, default=0.25)
2636
2637 This is a target (but not a guarantee) for the allowed error, in em-units,
2638 of the output relative to the input path and nib geometries. Higher values
2639 allow more error will typically yield contours with fewer points.
2640
2641 .. object:: jlrelative (boolean, default=True)
2642
2643 See below.
2644
2645 .. object:: joinlimit (float, default=20)
2646
2647 Specifies the maximum length of a "miter", "miterclip", or "arcs" join.
2648 For "miter" joins that would be longer will fall back to "bevel". With
2649 "miterclip" and "arcs" a longer join will be trimmed to the specified
2650 length. Note, however, that no join is trimmed past the "bevel line" and
2651 therefore lower values do not guarantee a given length.
2652
2653
2654 When ``jlrelative`` is false the value is interpreted as a length in
2655 em-units. Otherwise the value is interpreted as a multiple of
2656 "stroke-widths": the average of the spans of the nib at the incoming
2657 and outgoing join angles.
2658
2659 .. object:: ecrelative (boolean, default=True)
2660
2661 See below.
2662
2663 .. object:: extendcap (float, default=0)
2664
2665 When the contour being stroked is open and the ``cap`` style is "butt" or
2666 "round", this parameter adds area between the end of that contour and the
2667 cap. The length of that area will never be less than the specified value
2668 but may be more, depending on the geometry of the nib and the join.
2669 (However, it will always be exact for circular nibs.)
2670
2671
2672 When ``ecrelative`` is false the value is interpreted as a length in
2673 em-units. Otherwise the value is interpreted as a multiple of
2674 "stroke-widths": the span of the stroked path at the angle at the cap.
2675
2676 .. object:: arcsclip (string, default="auto")
2677
2678 When using the "arcs" join style this parameter influences the algorithm
2679 used to clip joins that exceed the ``joinlimit``. The value "svg2"
2680 specifies the standard SVG algorithm while the value "ratio" specifies an
2681 alternative algorithm that works better for longer and thinner nibs at
2682 shorter limits. The default value "auto" chooses the "ratio" algorithm
2683 for oblong elliptical and calligraphic nibs and
2684 ``jlrelative joinlimit`` < 4 and the "svg2" algorithm otherwise.
2685
2686 In the legacy interface, ``FLAGS`` is an optional tuple containing zero or
2687 more of the strings "removeinternal", "removeexternal", and "cleanup". The
2688 last is interpreted as ``simplify=True``, with a default of ``False`` when a
2689 FLAGS tuple is present.
2690
2691 .. method:: glyph.transform(matrix[, flags])
2692
2693 Transforms the glyph by the matrix. The optional flags argument should be a
2694 tuple containing any of the following strings:
2695
2696 .. object:: partialRefs
2697
2698 Don't transform any references in the glyph, but do transform their offsets.
2699 This is useful if the referred glyph will be (or has been) transformed.
2700
2701 .. object:: round
2702
2703 Round to int after the transformation is done.
2704
2705
2706 .. method:: glyph.nltransform(xexpr, yexpr)
2707
2708 xexpr and yexpr are strings specifying non-linear transformations that will
2709 be applied to all points in the current layer (with xexpr being applied to x
2710 values, and yexpr to y values, of course). The syntax for the expressions is
2711 explained in the :ref:`non-linear transform dialog <transform.Non-Linear>`.
2712
2713 .. method:: glyph.unlinkRef([ref_name])
2714
2715 Unlinks the reference to the glyph named ``ref-name``. If ``ref-name`` is
2716 omitted, unlinks all references.
2717
2718 .. method:: glyph.unlinkThisGlyph()
2719
2720 Unlinks all the references to the current glyph within any other glyph in
2721 the font.
2722
2723 .. method:: glyph.useRefsMetrics(ref_name[, flag])
2724
2725 Finds a reference with the given name and sets the "use_my_metrics" flag on
2726 it (so this glyph will have the same advance width as the glyph the
2727 reference points to).
2728
2729 If the optional flag argument is False, then the glyph will no longer have
2730 its metrics bound to the reference.
2731
2732 .. method:: glyph.validate([force])
2733
2734 Validates the glyph and returns the :attr:`validation_state` of the glyph
2735 (except bit 0x1 will always be clear). If the glyph passed the validation
2736 then the return value will be 0 (not 0x1). Otherwise the return value will
2737 be the set of errors found. If force is specified true this will always be
2738 validated, if force is unspecified (or specified as false) then it will
2739 return the cached value if it is known, otherwise will validate it.
2740
2741 .. method:: glyph.xBoundsAtY(ybottom[, ytop, layer=])
2742
2743 Finds the minimum and maximum x positions attained by the glyph when y is
2744 between ybottom and ytop (if ytop is not specified it is assumed the same as
2745 ybottom). If the glyph does not have any y values in the specified range
2746 then FontForge will return ``None``. A layer name or index may be provided
2747 to only find bounds for a particular layer.
2748
2749 .. method:: glyph.yBoundsAtX(xleft[, xright, layer=])
2750
2751 Finds the minimum and maximum y positions attained by the glyph when x is
2752 between xleft and xright (if xright is not specified it is assumed the same
2753 as xleft). If the glyph does not have any x values in the specified range
2754 then FontForge will return ``None``. A layer name or index may be provided
2755 to only find bounds for a particular layer.
2756
2757 .. method:: glyph.draw(pen)
2758
2759 Draw the glyph's outline to the `pen argument. <http://robofab.org/objects/pens.html>`_
2760
2761 .. method:: glyph.glyphPen([replace=True])
2762
2763 Creates a new glyphPen which will draw into the current glyph. By default
2764 the pen will replace any existing contours and references, but setting the
2765 optional keyword argument, ``replace`` to false will retain the old contents.
2766 Replacing the foreground layer will also reset the advance.
2767
2768 .. method:: glyph.addInflections()
2769
2770 Please see :meth:`contour.addInflections()`.
2771
2772 .. method:: glyph.balance()
2773
2774 Please see :meth:`contour.balance()`.
2775
2776 .. method:: glyph.harmonize()
2777
2778 Please see :meth:`contour.harmonize()`.
2779
2780
2781 Selection
2782 ---------
2783
2784 This represents a font's selection. You may index it with an encoding value (in
2785 the encoding ISO-646-US (ASCII) the character "A" has encoding index 65), or
2786 with a glyph's name, or with a string like ``"uXXXXX"`` where ``XXXXX``
2787 represent the glyph's unicode codepoint in hex, or with a
2788 :class:`fontforge.glyph` object. The value of indexing into a selection will be
2789 either ``True`` or ``False``. ::
2790
2791 >>> print(fontforge.activeFont().selection[65])
2792 True
2793
2794 This type may not be pickled.
2795
2796 .. class:: selection()
2797
2798 .. attribute:: selection.byGlyphs
2799
2800 Returns another selection, just the same as this one except that its iterator
2801 function will return glyphs (rather than encoding slots) and will only return
2802 those entries for which glyphs exist.
2803
2804 This is read-only.
2805
2806 .. attribute:: selection.font
2807
2808 Returns the font for which this is a selection.
2809
2810 .. method:: selection.__iter__()
2811
2812 Returns an iterator for the selection which will return all selected
2813 encoding slots in encoding order.
2814
2815 .. method:: selection.all()
2816
2817 Select everything.
2818
2819 .. method:: selection.none()
2820
2821 Deselect everything.
2822
2823 .. method:: selection.changed()
2824
2825 Select all glyphs which have changed.
2826
2827 .. method:: selection.invert()
2828
2829 Invert the selection.
2830
2831 .. method:: selection.select(args)
2832
2833 There may be an arbitrary number of arguments. Each argument may be either:
2834
2835 * A glyph name
2836
2837 Note: There need not be a glyph with this name in the font yet, but if you
2838 use a standard name (like "A") fontforge will still know where that glyph
2839 should be.
2840 * An integer (this will be interpreted as either an encoding index or
2841 (default) a unicode code point depending on the flags).
2842 * A fontforge glyph.
2843 * A tuple of flags.
2844
2845 (If you wish to specify a single flag it must still be in a tuple, and you
2846 must append a trailing comma to the flag (so ``("more",)`` rather than
2847 just ``("more")`` ). FF needs the flags to be in a tuple otherwise it
2848 can't distinguish them from glyph names)
2849
2850 .. object:: unicode
2851
2852 Interpret integer arguments as unicode code points
2853
2854 .. object:: encoding
2855
2856 Interpret integer arguments as encoding indices.
2857
2858 .. object:: more
2859
2860 Specified items should be selected
2861
2862 .. object:: less
2863
2864 Specified items should be deselected.
2865
2866 .. object:: singletons
2867
2868 Specified items should be interpreted individually and mean the obvious.
2869
2870 .. object:: ranges
2871
2872 Specified items should be interpreted in pairs and represent all
2873 encoding slots between the start and end points specified by the pair.
2874 So ``.select(("ranges",None),"A","Z")`` would select all the upper case
2875 (latin) letters.
2876
2877
2878 If the first argument is not a flag argument (or if it doesn't specify
2879 either "more" or "less") then the selection will be cleared. So
2880 ``.select("A")`` would produce a selection with only "A" selected,
2881 ``.select(("more",None),"A")`` would add "A" to the current selection, while
2882 ``.select(("less",None),"A")`` would remove "A" from the current selection.
2883
2884
2885 Private
2886 -------
2887
2888 This represents a font's postscript private dictionary. You may index it with
2889 one of the standard names of things that live in the private dictionary.
2890
2891 This type may not be pickled.
2892
2893 .. class:: private
2894
2895 .. method:: private.__iter__()
2896
2897 Returns an iterator for the dictionary which will return all entries.
2898
2899 .. method:: private.guess(name)
2900
2901 Guess a value for this entry in the private dictionary. If FontForge
2902 can't make a guess it will simply ignore the request.
2903
2904
2905 Math
2906 ----
2907
2908 This represents a font's math constant table. Not all fonts have math tables,
2909 and checking this field will not create the underlying object, but examining or
2910 assigning to its members will create it.
2911
2912 This type may not be pickled.
2913
2914 .. rubric:: Members
2915
2916 Any of the math constant names may be used as member names.
2917
2918 (These names begin with capital letters, not Python's conventions but Microsoft's)
2919
2920 These all take (16 bit) integer values.
2921
2922 Each ``DeviceTable`` property takes a dictionary with keys representing a font size
2923 in pixels and values representing the corresponding adjustment, e.g. ``{9: -1, 10: -1, 12: -1}``.
2924 Setting ``DeviceTable`` property to ``None`` will delete it.
2925
2926 Device table entries can also be queried and assigned by font size ::
2927
2928 font.math.MathLeadingDeviceTable[12] = 2
2929 adj = font.math.MathLeadingDeviceTable[12]
2930
2931 .. attribute:: math.ScriptPercentScaleDown
2932
2933 Percentage scale down for script level 1
2934
2935 .. attribute:: math.ScriptScriptPercentScaleDown
2936
2937 Percentage scale down for script level 2
2938
2939 .. attribute:: math.DelimitedSubFormulaMinHeight
2940
2941 Minimum height at which to treat a delimited expression as a subformula
2942
2943 .. attribute:: math.DisplayOperatorMinHeight
2944
2945 Minimum height of n-ary operators (integration, summation, etc.)
2946
2947 .. attribute:: math.MathLeading
2948 .. attribute:: math.MathLeadingDeviceTable
2949
2950 White space to be left between math formulae to ensure proper line spacing.
2951
2952 .. attribute:: math.AxisHeight
2953 .. attribute:: math.AxisHeightDeviceTable
2954
2955 Axis height of the font
2956
2957 .. attribute:: math.AccentBaseHeight
2958 .. attribute:: math.AccentBaseHeightDeviceTable
2959
2960 Maximum (ink) height of accent base that does not require raising the accents.
2961
2962 .. attribute:: math.FlattenedAccentBaseHeight
2963 .. attribute:: math.FlattenedAccentBaseHeightDeviceTable
2964
2965 Maximum (ink) height of accent base that does not require flattening the accents.
2966
2967 .. attribute:: math.SubscriptShiftDown
2968 .. attribute:: math.SubscriptShiftDownDeviceTable
2969
2970 The standard shift down applied to subscript elements. Positive for
2971 moving downward.
2972
2973 .. attribute:: math.SubscriptTopMax
2974 .. attribute:: math.SubscriptTopMaxDeviceTable
2975
2976 Maximum height of the (ink) top of subscripts that does not require moving
2977 subscripts further down.
2978
2979 .. attribute:: math.SubscriptBaselineDropMin
2980 .. attribute:: math.SubscriptBaselineDropMinDeviceTable
2981
2982 Maximum allowed drop of the baseline of subscripts relative to the bottom of
2983 the base. Used for bases that are treated as a box or extended shape.
2984 Positive for subscript baseline dropped below base bottom.
2985
2986 .. attribute:: math.SuperscriptShiftUp
2987 .. attribute:: math.SuperscriptShiftUpDeviceTable
2988
2989 Standard shift up applied to superscript elements.
2990
2991 .. attribute:: math.SuperscriptShiftUpCramped
2992 .. attribute:: math.SuperscriptShiftUpCrampedDeviceTable
2993
2994 Standard shift of superscript relative to base in cramped mode.
2995
2996 .. attribute:: math.SuperscriptBottomMin
2997 .. attribute:: math.SuperscriptBottomMinDeviceTable
2998
2999 Minimum allowed height of the bottom of superscripts that does not require
3000 moving them further up.
3001
3002 .. attribute:: math.SuperscriptBaselineDropMax
3003 .. attribute:: math.SuperscriptBaselineDropMaxDeviceTable
3004
3005 Maximum allowed drop of the baseline of superscripts relative to the top of
3006 the base. Used for bases that are treated as a box or extended shape.
3007 Positive for superscript baseline below base top.
3008
3009 .. attribute:: math.SubSuperscriptGapMin
3010 .. attribute:: math.SubSuperscriptGapMinDeviceTable
3011
3012 Minimum gap between the superscript and subscript ink.
3013
3014 .. attribute:: math.SuperscriptBottomMaxWithSubscript
3015 .. attribute:: math.SuperscriptBottomMaxWithSubscriptDeviceTable
3016
3017 The maximum level to which the (ink) bottom of superscript can be pushed to
3018 increase the gap between superscript and subscript, before subscript starts
3019 being moved down.
3020
3021 .. attribute:: math.SpaceAfterScript
3022 .. attribute:: math.SpaceAfterScriptDeviceTable
3023
3024 Extra white space to be added after each sub/superscript.
3025
3026 .. attribute:: math.UpperLimitGapMin
3027 .. attribute:: math.UpperLimitGapMinDeviceTable
3028
3029 Minimum gap between the bottom of the upper limit, and the top of the base
3030 operator.
3031
3032 .. attribute:: math.UpperLimitBaselineRiseMin
3033 .. attribute:: math.UpperLimitBaselineRiseMinDeviceTable
3034
3035 Minimum distance between the baseline of an upper limit and the bottom of
3036 the base operator.
3037
3038 .. attribute:: math.LowerLimitGapMin
3039 .. attribute:: math.LowerLimitGapMinDeviceTable
3040
3041 Minimum gap between (ink) top of the lower limit, and (ink) bottom of the
3042 base operator.
3043
3044 .. attribute:: math.LowerLimitBaselineDropMin
3045 .. attribute:: math.LowerLimitBaselineDropMinDeviceTable
3046
3047 Minimum distance between the baseline of the lower limit and bottom of the
3048 base operator.
3049
3050 .. attribute:: math.StackTopShiftUp
3051 .. attribute:: math.StackTopShiftUpDeviceTable
3052
3053 Standard shift up applied to the top element of a stack.
3054
3055 .. attribute:: math.StackTopDisplayStyleShiftUp
3056 .. attribute:: math.StackTopDisplayStyleShiftUpDeviceTable
3057
3058 Standard shift up applied to the top element of a stack in display style.
3059
3060 .. attribute:: math.StackBottomShiftDown
3061 .. attribute:: math.StackBottomShiftDownDeviceTable
3062
3063 Standard shift down applied to the bottom element of a stack. Positive
3064 values indicate downward motion.
3065
3066 .. attribute:: math.StackBottomDisplayStyleShiftDown
3067 .. attribute:: math.StackBottomDisplayStyleShiftDownDeviceTable
3068
3069 Standard shift down applied to the bottom element of a stack in display
3070 style. Positive values indicate downward motion.
3071
3072 .. attribute:: math.StackGapMin
3073 .. attribute:: math.StackGapMinDeviceTable
3074
3075 Minimum gap between bottom of the top element of a stack, and the top of
3076 the bottom element.
3077
3078 .. attribute:: math.StackDisplayStyleGapMin
3079 .. attribute:: math.StackDisplayStyleGapMinDeviceTable
3080
3081 Minimum gap between bottom of the top element of a stack and the top of the
3082 bottom element in display style.
3083
3084 .. attribute:: math.StretchStackTopShiftUp
3085 .. attribute:: math.StretchStackTopShiftUpDeviceTable
3086
3087 Standard shift up applied to the top element of the stretch stack.
3088
3089 .. attribute:: math.StretchStackBottomShiftDown
3090 .. attribute:: math.StretchStackBottomShiftDownDeviceTable
3091
3092 Standard shift down applied to the bottom element of the stretch stack.
3093 Positive values indicate
3094 downward motion.
3095
3096 .. attribute:: math.StretchStackGapAboveMin
3097 .. attribute:: math.StretchStackGapAboveMinDeviceTable
3098
3099 Minimum gap between the ink of the stretched element and the ink bottom of
3100 the element above.
3101
3102 .. attribute:: math.StretchStackGapBelowMin
3103 .. attribute:: math.StretchStackGapBelowMinDeviceTable
3104
3105 Minimum gap between the ink of the stretched element and the ink top of
3106 the element below.
3107
3108 .. attribute:: math.FractionNumeratorShiftUp
3109 .. attribute:: math.FractionNumeratorShiftUpDeviceTable
3110
3111 Standard shift up applied to the numerator.
3112
3113 .. attribute:: math.FractionNumeratorDisplayStyleShiftUp
3114 .. attribute:: math.FractionNumeratorDisplayStyleShiftUpDeviceTable
3115
3116 Standard shift up applied to the numerator in display style.
3117
3118 .. attribute:: math.FractionDenominatorShiftDown
3119 .. attribute:: math.FractionDenominatorShiftDownDeviceTable
3120
3121 Standard shift down applied to the denominator. Positive values indicate
3122 downward motion.
3123
3124 .. attribute:: math.FractionDenominatorDisplayStyleShiftDown
3125 .. attribute:: math.FractionDenominatorDisplayStyleShiftDownDeviceTable
3126
3127 Standard shift down applied to the denominator in display style. Positive
3128 values indicate downward motion.
3129
3130 .. attribute:: math.FractionNumeratorGapMin
3131 .. attribute:: math.FractionNumeratorGapMinDeviceTable
3132
3133 Minimum tolerated gap between the ink bottom of the numerator and the ink of
3134 the fraction bar.
3135
3136 .. attribute:: math.FractionNumeratorDisplayStyleGapMin
3137 .. attribute:: math.FractionNumeratorDisplayStyleGapMinDeviceTable
3138
3139 Minimum tolerated gap between the ink bottom of the numerator and the ink of
3140 the fraction bar in display style.
3141
3142 .. attribute:: math.FractionRuleThickness
3143 .. attribute:: math.FractionRuleThicknessDeviceTable
3144
3145 Thickness of the fraction bar.
3146
3147 .. attribute:: math.FractionDenominatorGapMin
3148 .. attribute:: math.FractionDenominatorGapMinDeviceTable
3149
3150 Minimum tolerated gap between the ink top of the denominator and the ink of
3151 the fraction bar.
3152
3153 .. attribute:: math.FractionDenominatorDisplayStyleGapMin
3154 .. attribute:: math.FractionDenominatorDisplayStyleGapMinDeviceTable
3155
3156 Minimum tolerated gap between the ink top of the denominator and the ink of
3157 the fraction bar in display style.
3158
3159 .. attribute:: math.SkewedFractionHorizontalGap
3160 .. attribute:: math.SkewedFractionHorizontalGapDeviceTable
3161
3162 Horizontal distance between the top and bottom elements of a skewed fraction.
3163
3164 .. attribute:: math.SkewedFractionVerticalGap
3165 .. attribute:: math.SkewedFractionVerticalGapDeviceTable
3166
3167 Vertical distance between the ink of the top and bottom elements of a skewed
3168 fraction.
3169
3170 .. attribute:: math.OverbarVerticalGap
3171 .. attribute:: math.OverbarVerticalGapDeviceTable
3172
3173 Distance between the overbar and the ink top of the base.
3174
3175 .. attribute:: math.OverbarRuleThickness
3176 .. attribute:: math.OverbarRuleThicknessDeviceTable
3177
3178 Thickness of the overbar.
3179
3180 .. attribute:: math.OverbarExtraAscender
3181 .. attribute:: math.OverbarExtraAscenderDeviceTable
3182
3183 Extra white space reserved above the overbar.
3184
3185 .. attribute:: math.UnderbarVerticalGap
3186 .. attribute:: math.UnderbarVerticalGapDeviceTable
3187
3188 Distance between underbar and the (ink) bottom of the base.
3189
3190 .. attribute:: math.UnderbarRuleThickness
3191 .. attribute:: math.UnderbarRuleThicknessDeviceTable
3192
3193 Thickness of the underbar.
3194
3195 .. attribute:: math.UnderbarExtraDescender
3196 .. attribute:: math.UnderbarExtraDescenderDeviceTable
3197
3198 Extra white space reserved below the underbar.
3199
3200 .. attribute:: math.RadicalVerticalGap
3201 .. attribute:: math.RadicalVerticalGapDeviceTable
3202
3203 Space between the ink to of the expression and the bar over it.
3204
3205 .. attribute:: math.RadicalDisplayStyleVerticalGap
3206 .. attribute:: math.RadicalDisplayStyleVerticalGapDeviceTable
3207
3208 Space between the ink top of the expression and the bar over it in display
3209 style.
3210
3211 .. attribute:: math.RadicalRuleThickness
3212 .. attribute:: math.RadicalRuleThicknessDeviceTable
3213
3214 Thickness of the radical rule in designed or constructed radical signs.
3215
3216 .. attribute:: math.RadicalExtraAscender
3217 .. attribute:: math.RadicalExtraAscenderDeviceTable
3218
3219 Extra white space reserved above the radical.
3220
3221 .. attribute:: math.RadicalKernBeforeDegree
3222 .. attribute:: math.RadicalKernBeforeDegreeDeviceTable
3223
3224 Extra horizontal kern before the degree of a radical if such be present.
3225
3226 .. attribute:: math.RadicalKernAfterDegree
3227 .. attribute:: math.RadicalKernAfterDegreeDeviceTable
3228
3229 Negative horizontal kern after the degree of a radical if such be present.
3230
3231 .. attribute:: math.RadicalDegreeBottomRaisePercent
3232
3233 Height of the bottom of the radical degree, if such be present, in
3234 proportion to the ascender of the radical sign.
3235
3236 .. attribute:: math.MinConnectorOverlap
3237
3238 Minimum overlap of connecting glyphs during glyph construction.
3239
3240 .. method:: math.exists()
3241
3242 Returns whether the font currently has an underlying math table associated
3243 with it. Note that examining or assigning to one of the members will create
3244 such a table.
3245
3246 .. method:: math.clear()
3247
3248 Removes any underlying math table from the font.
3249
3250 Font
3251 ----
3252
3253 The font type refers to a fontforge :class:`font` object. It generally contains
3254 a list of :class:`glyphs <fontforge.glyph>`, an encoding to order those glyphs,
3255 a fontname, a list of GPOS/GSUB lookups and many other things.
3256
3257 This type may not be pickled.
3258
3259 .. class:: font()
3260
3261 Creates a new font.
3262
3263 .. attribute:: font.activeLayer
3264
3265 Returns currently active layer in the font (as an integer). May be set to an
3266 integer or a layer name to change the active layer.
3267
3268 .. attribute:: font.ascent
3269
3270 The font's ascent
3271
3272 .. attribute:: font.bitmapSizes
3273
3274 A tuple with an entry for each bitmap strike attached to the font. Each
3275 strike is identified by pixelsize (if the strike is a grey scale font it
3276 will be indicated by ``(bitmap-depth<<16)|pixelsize``.
3277
3278 When setting this value pass in a tuple of the same format. Any existing
3279 strike not specified in the tuple will be removed. Any new sizes will be
3280 created (but not rasterized -- use :meth:`font.regenBitmaps()` for that).
3281
3282 .. attribute:: font.capHeight
3283
3284 (readonly) Computes the Cap Height (the height of capital letters such as
3285 "E"). A negative number indicates the value could not be computed (the font
3286 might have no capital letters because it was lower case only, or didn't
3287 include glyphs for a script with capital letters).
3288
3289 .. attribute:: font.changed
3290
3291 Bit indicating whether the font has been modified. This is (should be)
3292 maintained automatically, but you may set it if you wish.
3293
3294 .. attribute:: font.cidcopyright
3295
3296 Copyright message of the cid-keyed font as a whole (ie. not the current subfont).
3297
3298 .. attribute:: font.cidfamilyname
3299
3300 Family name of the cid-keyed font as a whole (ie. not the current subfont).
3301
3302 .. attribute:: font.cidfontname
3303
3304 Font name of the cid-keyed font as a whole (ie. not the current subfont).
3305
3306 .. attribute:: font.cidfullname
3307
3308 Full name of the cid-keyed font as a whole (ie. not the current subfont).
3309
3310 .. attribute:: font.cidordering
3311
3312
3313 .. attribute:: font.cidregistry
3314
3315
3316 .. attribute:: font.cidsubfont
3317
3318 Returns the number index of the current subfont in the cid-keyed font (or -1
3319 if this is not a cid-keyed font).
3320
3321 May be set to an index (an integer) or a subfont fontname (a string) to
3322 change the current subfont. (To find the name of the current subfont,
3323 simply use .fontname).
3324
3325 .. attribute:: font.cidsubfontcnt
3326
3327 Returns the number of subfonts in this cid-keyed font (or 0 if it is not a
3328 cid-keyed font)
3329
3330 .. attribute:: font.cidsubfontnames
3331
3332 Returns a tuple of the subfont names in this cid-keyed font (or None if it
3333 is not a cid-keyed font)
3334
3335 .. attribute:: font.cidsupplement
3336
3337
3338 .. attribute:: font.cidversion
3339
3340
3341 .. attribute:: font.cidweight
3342
3343 Weight of the cid-keyed font as a whole
3344
3345 .. attribute:: font.comment
3346
3347 A comment associated with the font. Can be anything.
3348
3349 .. attribute:: font.copyright
3350
3351 PostScript copyright notice
3352
3353 .. attribute:: font.creationtime
3354
3355 Font creation time. (readonly)
3356
3357 .. attribute:: font.cvt
3358
3359 Returns a sequence object containing the font's cvt table. Changes made
3360 to this object will be made to the font (this is a reference not a copy).
3361
3362 The object has one additional method ``cvt.find(value[,low,high])`` which
3363 finds the index of value in the cvt table (or -1 if not found). If low and
3364 high are specified then the index will be between ``[low,high)``.
3365
3366 .. attribute:: font.default_base_filename
3367
3368 The default base for the filename when generating a font
3369
3370 .. attribute:: font.descent
3371
3372 The font's descent
3373
3374 .. attribute:: font.design_size
3375
3376 Size (in pica points) for which this font was designed.
3377
3378 .. attribute:: font.em
3379
3380 The em size of the font. Setting this will scale the entire font to the
3381 new size.
3382
3383 .. attribute:: font.encoding
3384
3385 The name of the current encoding. Setting it will change the encoding used
3386 for indexing. To compact the encoding, first set it to your desired encoding
3387 (e.g. ``UnicodeBMP``), then set it to ``compacted``.
3388
3389 .. attribute:: font.familyname
3390
3391 PostScript font family name
3392
3393 .. attribute:: font.fondname
3394
3395 Mac fond name
3396
3397 .. attribute:: font.fontlog
3398
3399 A comment associated with the font. Can be anything.
3400
3401 .. attribute:: font.fontname
3402
3403 PostScript font name
3404
3405 Note that in a CID keyed font this will be the name of the current subfont.
3406 Use cidfontname for the name of the font as a whole.
3407
3408 .. attribute:: font.fullname
3409
3410 PostScript font name
3411
3412 .. attribute:: font.gasp
3413
3414 Returns a tuple of all gasp table entries. Each item in the tuple is itself
3415 a tuple composed of a ppem (an integer) and a tuple of flags. The flags are
3416 chosen from:
3417
3418 * ``gridfit``
3419 * ``antialias``
3420 * ``symmetric-smoothing``
3421 * ``gridfit+smoothing``
3422
3423 .. attribute:: font.gasp_version
3424
3425 The version of the 'gasp' table. Currently this may be 0 or 1.
3426
3427 .. attribute:: font.gpos_lookups
3428
3429 Returns a tuple of all positioning lookup names in the font.
3430 This member cannot be set.
3431
3432 .. attribute:: font.gsub_lookups
3433
3434 Returns a tuple of all substitution lookup names in the font.
3435 This member cannot be set.
3436
3437 .. attribute:: font.guide
3438
3439 A copy of the font's guide layer
3440
3441 .. attribute:: font.hasvmetrics
3442
3443
3444 .. attribute:: font.head_optimized_for_cleartype
3445
3446
3447 .. attribute:: font.hhea_ascent
3448
3449
3450 .. attribute:: font.hhea_ascent_add
3451
3452
3453 .. attribute:: font.hhea_descent
3454
3455
3456 .. attribute:: font.hhea_descent_add
3457
3458
3459 .. attribute:: font.hhea_linegap
3460
3461
3462 .. attribute:: font.horizontalBaseline
3463
3464 Returns a tuple of tuples containing the horizontal baseline information in
3465 the font (the 'BASE' table). If there is no information ``None`` will be
3466 returned, otherwise the format of the tuple is: ::
3467
3468 ((tuple of baseline tags used), (tuple of script information))
3469
3470 The ``(tuple of baseline tags used)`` is simply a tuple of 4 letter strings
3471 as ``("hang", "ideo", "romn")`` these are standard baseline tag names as
3472 defined in the opentype spec. The number of entries here, and their order is
3473 important as there will be subsequent tuples (in the script tuple) which use
3474 the same ordering.
3475
3476 The ``(tuple of script information)`` is again a tuple of
3477 ``script information`` tuples.
3478
3479 A ``script information`` tuple looks like ::
3480
3481 (script-tag,default-baseline-tag, (tuple of baseline positions), (tuple of language extents))
3482
3483 If there are no baseline tags defined (an empty tuple), then the
3484 ``default-baseline-tag`` and the ``(tuple of baseline positions)`` will be
3485 ``None``. Otherwise both tags will be 4 character strings, and the ``(tuple
3486 of baseline positions)`` will be a tuple of numbers (in the same order as the
3487 ``(tuple of baseline tags used)`` above) specifying the relative positions
3488 of each baseline for this script.
3489
3490 A ``(tuple of language extents)`` is a tuple of ``language extent`` tuples.
3491
3492 A ``language extent`` tuple is ::
3493
3494 (language-tag,min-extent,max-extent, (tuple of feature extents))
3495
3496 ``language-tag`` is a 4 letter string specifying an opentype language,
3497 ``min``/``max-extent`` are numbers specifying how far above and below the
3498 baseline characters go in this script/language.
3499
3500 A ``(tuple of feature extents>`` is a tuple of ``feature extent`` tuples.
3501
3502 A ``feature extent`` tuple is ::
3503
3504 (feature-tag,min-extent,max-extent)
3505
3506 ``feature-tag`` is a 4 letter string specifying an opentype (GPOS or GSUB)
3507 feature tag, ``min``/``max-extent`` are numbers specifying how far above and
3508 below the baseline characters go in this script/language with the
3509 feature applied.
3510
3511 **Example:**
3512
3513 ::
3514
3515 (("hang","ideo","romn"),
3516 (("cyrl","romn",(1405,-288,0),()),
3517 ("grek","romn",(1405,-288,0),()),
3518 ("latn","romn",(1405,-288,0),
3519 (("dflt",-576,1913,
3520 (("NoAc",-576,1482),
3521 ("ENG ",-576,1482))
3522 ),
3523 )
3524 )
3525 )
3526 )
3527
3528 (Note: The comma after the ``dflt`` tuple puts it into a one-element tuple.)
3529
3530 .. attribute:: font.is_cid
3531
3532 Indicates whether the font is a cid-keyed font or not. (Read-only)
3533
3534 .. attribute:: font.is_quadratic
3535
3536 Deprecated. Whether the contours should be interpreted as a set of quadratic
3537 or cubic splines. Setting this value has the side effect of converting the
3538 entire font into the other format
3539
3540 Now each layer may have its own setting for this value, which should be set
3541 on the font's :attr:`font.layers`.
3542
3543 .. attribute:: font.isnew
3544
3545 A flag indicating that this is a new font
3546
3547 .. attribute:: font.italicangle
3548
3549
3550 .. attribute:: font.macstyle
3551
3552 .. object:: Bit 0
3553
3554 Bold (if set to 1)
3555
3556 .. object:: Bit 1
3557
3558 Italic (if set to 1)
3559
3560 .. object:: Bit 2
3561
3562 Underline (if set to 1)
3563
3564 .. object:: Bit 3
3565
3566 Outline (if set to 1)
3567
3568 .. object:: Bit 4
3569
3570 Shadow (if set to 1)
3571
3572 .. object:: Bit 5
3573
3574 Condensed (if set to 1)
3575
3576 .. object:: Bit 6
3577
3578 Extended (if set to 1)
3579
3580 .. object:: Bits 7-15
3581
3582 Reserved (set to 0).
3583
3584 (`source <https://docs.microsoft.com/en-us/typography/opentype/spec/head>`_)
3585
3586 .. attribute:: font.markClasses
3587
3588 A tuple each entry of which is itself a tuple containing a mark-class-name
3589 and a tuple of glyph-names.
3590
3591 .. attribute:: font.markSets
3592
3593 A tuple each entry of which is itself a tuple containing a mark-set-name
3594 and a tuple of glyph-names.
3595
3596 .. attribute:: font.layer_cnt
3597
3598 The number of layers in the font. (Read only. Can change using ``add``
3599 and ``del`` operations on the :attr:`font.layers` array)
3600
3601 .. attribute:: font.layers
3602
3603 Returns a dictionary like object with information on the layers of the
3604 font -- a name and a boolean indicating whether the layer is quadratic or not.
3605
3606 You may remove a layer with ::
3607
3608 del font.layers["unneeded layer"]
3609
3610 You may add a new layer with ::
3611
3612 font.layers.add("layer-name",is_quadratic[, is_background])
3613
3614 You may change a layer's name with ::
3615
3616 font.layers["layer"].name = "new-name"
3617
3618 You may change the type of splines in a layer with ::
3619
3620 font.layers["layer"].is_quadratic = True
3621
3622 You may change whether it is a background layer by ::
3623
3624 font.layers["layer"].is_background = True
3625
3626 Note: The layers that live in the font are different from layers that live
3627 in a glyph. These objects do not have the Layer type documented earlier.
3628
3629 .. attribute:: font.loadState
3630
3631 A bitmask indicating non-fatal errors found when loading the font. (readonly)
3632
3633 .. object:: 0x01
3634
3635 Bad PostScript entry in 'name' table
3636
3637 .. object:: 0x02
3638
3639 Bad 'glyf' or 'loca' table
3640
3641 .. object:: 0x04
3642
3643 Bad 'CFF ' table
3644
3645 .. object:: 0x08
3646
3647 Bad 'hhea', 'hmtx', 'vhea' or 'vmtx' table
3648
3649 .. object:: 0x10
3650
3651 Bad 'cmap' table
3652
3653 .. object:: 0x20
3654
3655 Bad 'EBLC', 'bloc', 'EBDT' or 'bdat' (embedded bitmap) table
3656
3657 .. object:: 0x40
3658
3659 Bad Apple GX advanced typography table
3660
3661 .. object:: 0x80
3662
3663 Bad OpenType advanced typography table (GPOS, GSUB, GDEF, BASE)
3664
3665 .. object:: 0x100
3666
3667 Bad OS/2 version number
3668
3669 Windows will reject all fonts with a OS/2 version number of 0 and will
3670 reject OT-CFF fonts with a version number of 1
3671
3672
3673 .. attribute:: font.maxp_FDEFs
3674
3675 The number of function definitions used by the tt program
3676
3677 .. attribute:: font.maxp_IDEFs
3678
3679 The number of instruction definitions used by the tt program
3680
3681 .. attribute:: font.maxp_maxStackDepth
3682
3683 The maximum stack depth used by the tt program
3684
3685 .. attribute:: font.maxp_storageCnt
3686
3687 The number of storage locations used by the tt program
3688
3689 .. attribute:: font.maxp_twilightPtCnt
3690
3691 The number of points in the twilight zone of the tt program
3692
3693 .. attribute:: font.maxp_zones
3694
3695 The number of zones used in the tt program
3696
3697 .. attribute:: font.multilayer
3698
3699
3700 .. attribute:: font.onlybitmaps
3701
3702 A flag indicating that this font only contains bitmaps. No outlines.
3703
3704 .. attribute:: font.os2_capheight
3705
3706
3707 .. attribute:: font.os2_codepages
3708
3709 A 2 element tuple containing the OS/2 Codepages field
3710
3711 .. attribute:: font.os2_family_class
3712
3713
3714 .. attribute:: font.os2_fstype
3715
3716
3717 .. attribute:: font.os2_panose
3718
3719
3720 .. attribute:: font.os2_strikeypos
3721
3722
3723 .. attribute:: font.os2_strikeysize
3724
3725
3726 .. attribute:: font.os2_stylemap
3727
3728 Write access to fsSelection, keep in sync with :attr:`font.macstyle`
3729
3730 .. attribute:: font.os2_subxoff
3731
3732
3733 .. attribute:: font.os2_subxsize
3734
3735
3736 .. attribute:: font.os2_subyoff
3737
3738
3739 .. attribute:: font.os2_subysize
3740
3741
3742 .. attribute:: font.os2_supxoff
3743
3744
3745 .. attribute:: font.os2_supxsize
3746
3747
3748 .. attribute:: font.os2_supyoff
3749
3750
3751 .. attribute:: font.os2_supysize
3752
3753
3754 .. attribute:: font.os2_typoascent
3755
3756
3757 .. attribute:: font.os2_typoascent_add
3758
3759
3760 .. attribute:: font.os2_typodescent
3761
3762
3763 .. attribute:: font.os2_typodescent_add
3764
3765
3766 .. attribute:: font.os2_typolinegap
3767
3768
3769 .. attribute:: font.os2_unicoderanges
3770
3771 A 4 element tuple containing the OS/2 Unicode Ranges field
3772
3773 .. attribute:: font.os2_use_typo_metrics
3774
3775
3776 .. attribute:: font.os2_vendor
3777
3778
3779 .. attribute:: font.os2_version
3780
3781
3782 .. attribute:: font.os2_weight
3783
3784
3785 .. attribute:: font.os2_weight_width_slope_only
3786
3787
3788 .. attribute:: font.os2_width
3789
3790
3791 .. attribute:: font.os2_winascent
3792
3793
3794 .. attribute:: font.os2_winascent_add
3795
3796
3797 .. attribute:: font.os2_windescent
3798
3799
3800 .. attribute:: font.os2_windescent_add
3801
3802
3803 .. attribute:: font.os2_xheight
3804
3805
3806 .. attribute:: font.path
3807
3808 (readonly) Returns a string containing the name of the file from which the
3809 font was originally read (in this session), or if this is a new font, returns
3810 a made up filename in the current directory named something like
3811 "Untitled1.sfd". See also :attr:`font.sfd_path`.
3812
3813 .. attribute:: font.persistent
3814
3815 Whatever you want -- though I recommend you store a dict here (these data
3816 will be saved as a pickled object in the sfd file. It is your job to ensure
3817 that whatever you put here can be pickled)
3818
3819 If you do store a dict then the following entries will be treated specially:
3820
3821 .. object:: initScriptString
3822
3823 If present, and if this is a string, then each time the font is loaded
3824 from an sfd file, this string will be passed to the python interpreter.
3825
3826 .. note::
3827
3828 This is a string, not a function.
3829 Function code cannot be pickled. Since it is a string it will receive
3830 no arguments, but the current font will be available in the activeFont
3831 method of the fontforge module.
3832
3833 This string will be interpreted before the loadFontHook of the
3834 :data:`fontforge.hooks` dictionary.
3835
3836 One possible behavior for this string is to define function hooks to
3837 be stored in the temporary dict described below.
3838
3839
3840 .. attribute:: font.math
3841
3842 Returns a :class:`math` object which provides information on the font's
3843 underlying math constant table. There is only one of these per font.
3844
3845 .. attribute:: font.private
3846
3847 Returns a :class:`private` dictionary-like object representing the
3848 PostScript private dictionary for the font. Changing entries in this object
3849 will change them in the font. (It's a reference, not a copy).
3850
3851 There is an iterator associated with this entry.
3852
3853 .. attribute:: font.privateState
3854
3855 Checks the (PostScript) Private dictionary and returns a bitmask of some
3856 common errors.
3857
3858 .. object:: 0x000001
3859
3860 Odd number of elements in either the BlueValues or OtherBlues array.
3861
3862 .. object:: 0x000002
3863
3864 Elements in either the BlueValues or OtherBlues are disordered.
3865
3866 .. object:: 0x000004
3867
3868 Too many elements in either the BlueValues or OtherBlues array.
3869
3870 .. object:: 0x000008
3871
3872 Elements in either the BlueValues or OtherBlues array are too close
3873 (must be at least ``2*BlueFuzz +1`` apart).
3874
3875 .. object:: 0x000010
3876
3877 Elements in either the BlueValues or OtherBlues array are not integers.
3878
3879 .. object:: 0x000020
3880
3881 Alignment zone height in either the BlueValues or OtherBlues array is too
3882 big for the value of BlueScale.
3883
3884 .. object:: 0x000100
3885
3886 Odd number of elements in either the FamilyBlues or FamilyOtherBlues array.
3887
3888 .. object:: 0x000200
3889
3890 Elements in either the FamilyBlues or FamilyOtherBlues are disordered.
3891
3892 .. object:: 0x000400
3893
3894 Too many elements in either the FamilyBlues or FamilyOtherBlues array.
3895
3896 .. object:: 0x000800
3897
3898 Elements in either the FamilyBlues or FamilyOtherBlues array are too
3899 close (must be at least ``2*BlueFuzz +1`` apart).
3900
3901 .. object:: 0x001000
3902
3903 Elements in either the FamilyBlues or FamilyOtherBlues array are not
3904 integers.
3905
3906 .. object:: 0x002000
3907
3908 Alignment zone height in either the FamilyBlues or FamilyOtherBlues array
3909 is too big for the value of BlueScale.
3910
3911 .. object:: 0x010000
3912
3913 Missing BlueValues entry.
3914
3915 .. object:: 0x020000
3916
3917 Bad BlueFuzz entry.
3918
3919 .. object:: 0x040000
3920
3921 Bad BlueScale entry.
3922
3923 .. object:: 0x080000
3924
3925 Bad StdHW entry.
3926
3927 .. object:: 0x100000
3928
3929 Bad StdVW entry.
3930
3931 .. object:: 0x200000
3932
3933 Bad StemSnapH entry.
3934
3935 .. object:: 0x400000
3936
3937 Bad StemSnapV entry.
3938
3939 .. object:: 0x800000
3940
3941 StemSnapH does not include StdHW.
3942
3943 .. object:: 0x1000000
3944
3945 StemSnapV does not include StdVW.
3946
3947 .. object:: 0x2000000
3948
3949 Bad BlueShift entry.
3950
3951
3952 .. attribute:: font.selection
3953
3954 Returns a reference to a :class:`array-like object representing the font's
3955 selection <selection>`. There is one entry for each encoding slot (there may
3956 not be a glyph attached to every encoding slot). You may set this with a
3957 tuple of integers (or boolean values). There should not be more entries in
3958 the tuple than there are encoding slots in the current encoding. A ``True``
3959 or non-0 value means the slot is selected.
3960
3961 .. attribute:: font.sfd_path
3962
3963 (readonly) Returns a string (or None) containing the name of the sfd file
3964 associated with this font. Sometimes this will be the same as :attr:`font.path`.
3965
3966 .. attribute:: font.sfnt_names
3967
3968 The strings in the sfnt 'name' table. A tuple of all MS names. Each name is
3969 itself a tuple of strings ``(language,strid,string)``. Language may be
3970 either the (english) name of the language/locale, or the number representing
3971 that language in Microsoft's specification. Strid may be one of the
3972 (English) string names ``(Copyright, Family, SubFamily, etc.)`` or the
3973 numeric value of that item. The string itself is in UTF-8.
3974
3975 Mac names will be automagically created from MS names
3976
3977 .. attribute:: font.sfntRevision
3978
3979 The font revision field stored in the ``'head'`` table of an sfnt. This
3980 is documented to be a fixed 16.16 number (that is a 32 bit number with the
3981 binary point between bits 15 and 16).
3982
3983 The field may be unset (in which case when the font is generated, FontForge
3984 will guess a default value from one of the version strings).
3985
3986 The value returned will be ``None`` if the field is unset or a double.
3987
3988 You may set it to ``None`` which "unsets" it, or to a double value, or to an
3989 integer. The integer will be treated as a 32 bit integer and right shifted
3990 by 16 to get a 16.16 value).
3991
3992 .. attribute:: font.size_feature
3993
3994 The OpenType 'size' feature has two formats. It may either represent the
3995 design size of the font (and nothing else) or the design size, and range
3996 (top and bottom point sizes for which this design works), a style id (used
3997 to represent this design size throughout the font family) and a set of
3998 language/string pairs used to represent this design size in the menu.
3999
4000 If no size information is specified in the font FontForge will return None.
4001
4002 If only the design size is specified, FontForge will return a tuple
4003 containing a single element: the point size for which the font was designed.
4004 (This is returned as a real number -- the field can represent tenths of a point).
4005
4006 Otherwise FontForge returns a tuple containing five elements, the design
4007 size, the bottom of the design range, the top, the style id and a tuple of
4008 tuples. Each sub-tuple is a language/string pair. Language may be either
4009 the (english) name of the language/locale, or the string itself in UTF-8.
4010
4011 .. attribute:: font.strokedfont
4012
4013 is this a stroked font?
4014
4015 .. attribute:: font.strokewidth
4016
4017 the stroke width of a stroked font
4018
4019 .. attribute:: font.style_set_names
4020
4021 A tuple, each entry of which is a 3-element tuple containing:
4022 * For style sets, the language name (e.g. ``"English (US)"``), the style set
4023 tag (e.g. ``"ss01"``) and the style set name.
4024 * For character variants, the language name, the character variant tag (e.g.
4025 ``"cv01"``) and a 5-element tuple containing the feature name, the tooltip text,
4026 the sample text (these three can be ``None``), a tuple containing parameter
4027 names (can be empty) and ``None`` (reserved for the character list).
4028
4029 .. attribute:: font.temporary
4030
4031 Whatever you want -- though I recommend you store a dict here (these data
4032 will be lost once the font is closed)
4033
4034 If you do store a dict then the following entries will be treated specially:
4035
4036 .. object:: generateFontPreHook
4037
4038 If present, and if this is a function it will be called just before a
4039 font is generated. It will be called with the font and the filename to
4040 which the font will be written.
4041
4042 .. object:: generateFontPostHook
4043
4044 If present, and if this is a function it will be called just after a font
4045 is generated. It will be called with the font and the filename to which
4046 the font will be written.
4047
4048 .. attribute:: font.texparameters
4049
4050 Returns a tuple of :ref:`TeX font parameters <fontinfo.TeX>`. TeX font type
4051 followed by 22 parameters. Font type is one of:
4052
4053 * ``text``
4054 * ``mathsym``
4055 * ``mathext``
4056 * ``unset``
4057
4058
4059 In case of ``unset`` default values for font parameters will be returned.
4060
4061 .. attribute:: font.uniqueid
4062
4063
4064 .. attribute:: font.upos
4065
4066 underline position
4067
4068 .. attribute:: font.userdata
4069
4070 .. warning:: Deprecated name for :attr:`font.temporary`
4071
4072 .. attribute:: font.uwidth
4073
4074 underline width
4075
4076 .. attribute:: font.version
4077
4078 PostScript font version string
4079
4080 .. attribute:: font.verticalBaseline
4081
4082 Same format as :attr:`font.horizontalBaseline`.
4083
4084 .. attribute:: font.vertical_origin
4085
4086 .. warning:: Deprecated
4087
4088 .. attribute:: font.vhea_linegap
4089
4090
4091 .. attribute:: font.weight
4092
4093 PostScript font weight string
4094
4095 .. attribute:: font.woffMajor
4096
4097 The major version number of a woff file, an integer.
4098
4099 The field may be unset (in which case when the font is generated, FontForge
4100 will guess a default value from one of the version strings).
4101
4102 The value returned will be ``None`` if the field is unset or an integer.
4103
4104 You may set it to ``None`` which "unsets" it, or to an integer.
4105
4106 .. attribute:: font.woffMinor
4107
4108 The minor version number of a woff file, an integer.
4109
4110 The field may be unset (in which case when the font is generated, FontForge
4111 will guess a default value from one of the version strings).
4112
4113 The value returned will be ``None`` if the field is unset or an integer.
4114
4115 You may set it to ``None`` which "unsets" it, or to an integer.
4116
4117 .. attribute:: font.woffMetadata
4118
4119 Any metadata associated with a woff file. This is a utf8 string containing
4120 unparsed xml.
4121
4122 .. attribute:: font.xHeight
4123
4124 (readonly) Computes the X Height (the height of lower case letters such as
4125 "x"). A negative number indicates the value could not be computed (the font
4126 might have no lower case letters because it was upper case only, or didn't
4127 include glyphs for a script with lower case letters).
4128
4129 .. attribute:: font.xuid
4130
4131 PostScript eXtended Unique ID.
4132
4133 .. method:: font.__iter__()
4134
4135 Returns an iterator for the font which will run through the font, in gid
4136 order, returning glyph names
4137
4138 .. method:: font.__contains__()
4139
4140 Returns whether the font contains a glyph with the given name.
4141
4142 .. method:: font.__len__()
4143
4144 The number of glyph slots in the current encoding
4145
4146 .. method:: font.__getitem__(key)
4147
4148 If ``key`` is an integer, then returns the glyph at that encoding. If a
4149 string then returns the glyph with that name. May not be assigned to.
4150
4151 .. method:: font.addAnchorClass(lookup_subtable_name, new_anchor_class_name)
4152
4153 Adds an anchor class to the specified (anchor) subtable.
4154
4155 .. method:: font.addKerningClass(lookup_name, new_subtable_name, first_classes, second_classes, offsets[, after])
4156 font.addKerningClass(lookup_name, new_subtable_name, separation, first_classes, second_classes[, onlyCloser, autokern, after])
4157 font.addKerningClass(lookup_name, new_subtable_name, separation, class_distance, first_glyph_list, second_glyph_list, [, onlyCloser, autokern, after])
4158 font.addKerningClass(lookup_name, new_subtable_name, separation, class_distance, [, onlyCloser, autokern, after])
4159
4160 Creates a new subtable and a new kerning class in the named lookup. The
4161 classes arguments are tuples of tuples of glyph names (each sub-tuple of
4162 glyph names is a kerning class). The offsets argument is a tuple of kerning
4163 offsets. There must be as many entries as ::
4164
4165 len(first-class)*len(second-class)
4166
4167 The optional after argument is used to specify the order of the subtable
4168 within the lookup.
4169
4170 The second format will cause FontForge to auto kern the subtable. The
4171 separation argument specifies the desired optical distance between any two
4172 glyphs (if this is specified as 0 then the kerning class will be designed so
4173 glyphs just touch each other). Again the user specifies two sets of
4174 predefined classes. If the (optional) ``onlyCloser`` flag is set true then
4175 only negative kerning values will be inserted into the table.
4176
4177 In the third format the user merely specifies two lists of glyphs to be
4178 used, fontforge will look for similarities among among the glyphs and guess
4179 at classes. The class-distance argument to determine how precise the classes
4180 should match (1 is very tight matching, 20 is rather loose).
4181
4182 In the last format the font's selection will be used to specify the list of
4183 glyphs to be examined (and the same list will be used for both the left and
4184 right glyphs -- but fontforge will probably find different classes).
4185
4186 .. method:: font.addLookup(new_lookup_name, type, flags, feature_script_lang_tuple[, after_lookup_name)
4187
4188 Creates a new lookup with the given name, type and flags. It will tag it
4189 with any indicated features. The type is one of
4190
4191 * ``gsub_single``
4192 * ``gsub_multiple``
4193 * ``gsub_alternate``
4194 * ``gsub_ligature``
4195 * ``gsub_context``
4196 * ``gsub_contextchain``
4197 * ``gsub_reversecchain``
4198 * ``morx_indic``
4199 * ``morx_context``
4200 * ``morx_insert``
4201 * ``gpos_single``
4202 * ``gpos_pair``
4203 * ``gpos_cursive``
4204 * ``gpos_mark2base``
4205 * ``gpos_mark2ligature``
4206 * ``gpos_mark2mark``
4207 * ``gpos_context``
4208 * ``gpos_contextchain``
4209 * ``kern_statemachine``
4210
4211 The flags argument is a tuple of strings, or ``None``. At most one of these
4212 strings may be the name of a mark class or a mark set. The others are:
4213
4214 * ``right_to_left``
4215 * ``ignore_bases``
4216 * ``ignore_ligatures``
4217 * ``ignore_marks``
4218
4219 A feature-script-lang tuple is a tuple with one entry for each feature
4220 (there may be no entries if there are no features). Each entry is itself a
4221 two element tuple, the first entry is a string containing a 4 letter feature
4222 tag, and the second entry is another tuple (potentially empty) with an entry
4223 for each script for which the feature is active. Each entry here is itself a
4224 two element tuple. The first element is a 4 letter script tag and the second
4225 is a tuple of languages. Each entry in the language tuple is a four letter
4226 language. Example: ``(("liga",(("latn",("dflt")),)),)``
4227
4228 The optional final argument allows you to specify the ordering of the lookup.
4229 If not specified the lookup will become the first lookup in its table.
4230
4231 .. method:: font.addLookupSubtable(lookup_name, new_subtable_name[, after_subtable_name])
4232
4233 Creates a new subtable within the specified lookup. The lookup name should
4234 be a string specifying an existing lookup. The subtable name should also be
4235 a string and should not match any currently existing subtable in the lookup.
4236 The optional final argument allows you to specify the ordering within the
4237 lookup. If not specified this subtable will be first in the lookup.
4238
4239 If you want to create a subtable in a contextual lookup, then use
4240 :meth:`font.addContextualSubtable`. If you want to create a kerning class
4241 subtable, then use :meth:`font.addKerningClass`.
4242
4243 .. method:: font.addContextualSubtable(lookup_name, new_subtable_name, type, rule[, afterSubtable=] [, bclasses=] [, mclasses=] [, fclasses=] [, bclassnames=] [, mclassnames=] [, fclassnames=])
4244
4245 Creates a new subtable within the specified contextual lookup (contextual,
4246 contextual chaining, or reverse contextual chaining). The lookup name should
4247 be a string specifying an existing lookup. The subtable name should also be
4248 a string and should not match any currently existing subtable in the lookup.
4249
4250 The ``type`` should be one of the strings "glyph", "class", "coverage" or
4251 "reversecoverage". The ``rule`` should be a string specifying a string to
4252 match and a set of lookups to apply once the match has been made. For
4253 "glyph" and "class" subtables, ``rule`` may also be a sequence of strings;
4254 passing a sequence creates one subtable containing multiple contextual rules.
4255 (See below for more details).
4256
4257 The remaining arguments are optional, keyword arguments.
4258
4259 * ``afterSubtable=``, if present this should be followed by a string, the
4260 name of a subtable after which this one is to be placed in the lookup. If
4261 not specified this subtable will be first in the lookup.
4262 * ``bclasses=, fclasses=, mclasses=`` these three arguments specify sets of
4263 glyph classes for when ``type="class"``. They should be a tuple of
4264 thingies where each thingy is either a string containing a list of space
4265 separated glyph names, or another tuple containing a set of strings, each
4266 a glyph name. Note that the first class is magic and should usually be
4267 left as a null string.
4268 * ``bclassnames=, fclassnames=, mclassnames=`` These provide names for the
4269 glyph classes described above. These names are optional, but can be
4270 convenient. These are tuples of strings. There should be the same number
4271 of entries in ``bclassnames`` as there are in ``bclasses``.
4272
4273 .. object:: When type="glyph"
4274
4275 The rule should look something like: ::
4276
4277 glyph-name1 glyph-name2 | glyph-name3 @<lookup-name> | glyph-name4
4278
4279 The ``|`` s divide between backtrack, match and lookahead sections. So
4280 this example would match if the current glyph were named ``glyph-name3``
4281 and it were preceded by ``glyph-name2`` and that by ``glyph-name1`` and
4282 followed by ``glyph-name4``. If the match were successful then the lookup
4283 named ``lookup-name`` would be applied. The ``@<>`` are literal
4284 characters and should be present in the rule.
4285
4286 If the invoked lookup is a ligature lookup then it should be invoked
4287 after the first glyph that forms the lookup (rather than the last) and
4288 all glyphs that might make up the lookup should be in the match section.
4289 So... ::
4290
4291 e | f @<ff-lig> f l | o
4292
4293 would only apply the ``ff-lig`` lookup if the ``ffl`` were preceded by
4294 ``e`` and followed by ``o``.
4295
4296 .. object:: When type="class"
4297
4298 The rule should look something like: ::
4299
4300 class-name1 class-name2 | class-name3 @<lookup-name> | class-name4
4301
4302 Very similar to the case of glyphs, except that instead of glyph names
4303 we have class names here. It is possible to have different sets of class
4304 names in the three different sections (backtrack, match and lookahead).
4305 If you don't specify any class names then you must use numbers instead,
4306 each number referring to the class at that position in the tuple (the first
4307 class will be class 0, the second class 1, and so on).
4308
4309 .. object:: When type="coverage"
4310
4311 The rule should look something like: ::
4312
4313 [g1 g2] [g3 g4] | [g5 g6 g7] @<lookup-name> | [g8 g9]
4314
4315 Each entry within brackets, ``[]``, represents a coverage table and
4316 should be a list of glyph names. The brackets are specified literally.
4317
4318 .. object:: When type="reversecoverage"
4319
4320 The rule should look something like: ::
4321
4322 [g1 g2] [g3 g4] | [g5 g6 g7] => [rg1 rg2 rg3] | [g8 g9]
4323
4324 Very similar to normal coverage tables except that instead of specifying
4325 a lookup there are replacement glyphs inline. There must be the same
4326 number of replacement glyphs (``rg1, rg2,rg3``) as match glyphs
4327 (``g5, g6, g7``) and there may be only one coverage table in the match
4328 section.
4329
4330 .. warning::
4331
4332 This format has some limitations, if there are multiple lookups they
4333 will be applied in textual order (First lookup in the string is the first
4334 one applied). This limitation is also present in Adobe's feature files so
4335 I hope it shan't be a severe limitation.
4336
4337 .. method:: font.addSmallCaps(scheight=None, capheight=None, lcstem=None, ucstem=None, symbols=None, letter_extension=None, symbol_extension=None, stem_height_factor=None)
4338
4339 This function uses keyword parameters. None are required, if omitted a
4340 default value will be used (generally found by analyzing the font).
4341
4342 For each selected letter, this function will create a corresponding small
4343 caps glyph. If you set the ``symbols`` keyword to ``True`` it will also
4344 create small caps variants of digits and symbols.
4345
4346 The outlines of the new glyph will be based on the outlines of the
4347 upper-case variant of the letter. These will then be scaled so that a glyph
4348 which was ``capheight`` high will now be ``scheight`` high, and so that
4349 stems which were ``ucstem`` wide will be ``lcstem`` wide. Normally the ratio
4350 of stem heights is the same as the ratio of stem widths, but you may change
4351 that with ``stem_height_factor``.
4352
4353 When it creates a new glyph it will name that glyph by appending ".sc" to
4354 the original lower case letter name (so "a" would become "a.sc") you may
4355 change the extension used with ``letter_extension``. Similarly symbols and
4356 digits will use the extension "taboldstyle", but you may change that with
4357 ``symbol_extension``.
4358
4359 When it creates a glyph it also creates two lookups one bound to the feature
4360 "c2sc" and the other to "smcp". A mapping from the lower case letter to the
4361 small caps letter will be provided under "smcp", while a mapping from the
4362 upper case to the small caps under "c2sc". Symbols will have both lookup
4363 maps attached to the original glyph.
4364
4365 .. method:: font.alterKerningClass(subtable_name, first_classes, second_classes, offsets)
4366
4367 Changes the kerning class in the named subtable. The classes arguments are
4368 tuples of tuples of glyph names (each sub-tuple of glyph names is a kerning
4369 class). The offsets argument is a tuple of kerning offsets. There must be as
4370 many entries as ``len(first-class)*len(second-class)``.
4371
4372 .. method:: font.autoKern(subtable_name, separation[, minKern=, onlyCloser=, touch=])
4373 font.autoKern(subtable_name, separation, glyph_list1, glyph_list2[, minKern=, onlyCloser=, touch=])
4374
4375 The named subtable must be a kerning pair subtable that already exists.
4376
4377 This command will automatically generate kerning pairs for the named
4378 subtable. If no glyph lists are specified it will look at all pairs of the
4379 glyphs in the selection; if glyph lists are specified then it will look at
4380 all pairs that can be made with one glyph from the first list and the second
4381 from the second list.
4382
4383 It will attempt to guess a good kerning value between the two glyphs -- a
4384 value which will make the optical separation between the two appear to be
4385 ``separation`` em-units. If ``minKern`` is specified and the (absolute
4386 value of the) kerning correction is less than this number then no kerning
4387 pair will be generated. If ``onlyCloser`` is set to true then only negative
4388 kerning offsets will be generated (only thing which moves two glyphs closer
4389 together). If touch is set to 1 then the kerning offset will not be based on
4390 optical distance but on the closest approach between the two glyphs.
4391
4392 .. method:: font.appendSFNTName(language, strid, string)
4393
4394 Adds a new (or replaces an old) string in the sfnt 'name' table. Language
4395 may be either the English name of the language/locale as a string, or the
4396 number representing that language in MicroSoft's specification. Strid may be
4397 one of the (english) string names (Copyright, Family, SubFamily, etc.) or
4398 the numeric value of that item. The string itself is in UTF-8.
4399
4400 .. method:: font.buildOrReplaceAALTFeatures()
4401
4402 Removes any existing AALT features (and any lookups solely controlled by such
4403 features) and creates new ones containing all possible single and alternate
4404 substitutions available for each glyph.
4405
4406 .. method:: font.cidConvertByCmap(cmap_filename)
4407
4408 Converts a normal font into a CID-keyed font with one subfont using
4409 the CMAP to determine the mapping.
4410
4411 .. method:: font.cidConvertTo(registry, ordering, supplement)
4412
4413 Converts a normal font into a CID-keyed font with one subfont.
4414
4415 .. method:: font.cidFlatten()
4416
4417 Converts a CID font into a normal font (glyphs will be in CID order).
4418
4419 .. method:: font.cidFlattenByCMap(cmap_filename)
4420
4421 Converts a CID font into a normal font using the encoding specified in the
4422 CMAP file.
4423
4424 .. method:: font.cidInsertBlankSubFont()
4425
4426 Adds a new (blank) sub-font into a cid-keyed font and changes the current
4427 sub-font to be it.
4428
4429 .. method:: font.cidRemoveSubFont()
4430
4431 Removes the current subfont from a cid-keyed font.
4432
4433 .. method:: font.clearSpecialData()
4434
4435 Clear special data not accessible in FontForge.
4436
4437 .. method:: font.close()
4438
4439 Frees memory for the current font.
4440
4441 **Warning:** Any python references to it will become invalid.
4442
4443 .. method:: font.compareFonts(other_font, filename, flags_tuple)
4444
4445 This will compare the current font with the font in ``other_font`` (which
4446 must already have been opened). It will write the results to the
4447 ``filename``, you may use "-" to send the output to stdout. The ``flags``
4448 argument is a tuple of strings and controls what will be compared.
4449
4450 .. object:: outlines
4451
4452 compare outlines
4453
4454 .. object:: outlines-exactly
4455
4456 compare outlines exactly (otherwise allow slight errors and the unlinking
4457 of references)
4458
4459 .. object:: warn-outlines-mismatch
4460
4461 warn if the outlines don't exactly match (but are pretty close)
4462
4463 .. object:: hints
4464
4465 compare hints
4466
4467 .. object:: warn-refs-unlink
4468
4469 warn if references need to be unlinked before a match is found
4470
4471 .. object:: strikes
4472
4473 compare bitmap strikes
4474
4475 .. object:: fontnames
4476
4477 compare font names
4478
4479 .. object:: gpos
4480
4481 compare glyph positioning
4482
4483 .. object:: gsub
4484
4485 compare glyph substitutions
4486
4487 .. object:: add-outlines
4488
4489 for any glyphs whose outlines differ, add the outlines of the glyph in
4490 the second font to the background of the glyph in the first
4491
4492 .. object:: create-glyphs
4493
4494 if a glyph exists in the second font but not the first, create that
4495 glyph in the first and add the outlines from the second into the
4496 background layer
4497
4498
4499 .. method:: font.createChar(uni[, name])
4500
4501 Create (and return) a character at the specified unicode codepoint in this
4502 font and optionally name it. If you wish to create a glyph with no unicode
4503 codepoint, set the first argument to -1 and specify a name.
4504
4505 If there is already a character at that (positive) codepoint then it is
4506 returned. If the optional name parameter is included and differs from its
4507 current name then the character is also renamed.
4508
4509 .. method:: font.createInterpolatedGlyph(glyph1, glyph2, amount)
4510
4511 Create (and return) a glyph with the same unicode code point as glyph1.
4512 The glyph may not already exist. The contents of the glyph will be formed
4513 by interpolating between glyph1 and glyph2. If amount==0 the result will
4514 look like glyph1, or 1 then like glyph2.
4515
4516 .. method:: font.createMappedChar(enc)
4517 font.createMappedChar(name)
4518
4519 Create (and return) a character at the specified encoding in this font.
4520 If there is already a character there, return it
4521
4522 .. method:: font.find(contour[, error_bound, search_flags])
4523
4524 Searches the font for all glyphs containing the contour (or layer) and
4525 returns an iterator which returns those glyphs.
4526
4527 error-bound: defaults to 0.01.
4528
4529 search_flags: tuple of the strings: reverse, flips, rotate, scale.
4530
4531 When found, the glyph.temporary is set to a dict of:
4532
4533 ::
4534
4535 {
4536 "findMatchedRefs": matched_refs_bit_map,
4537 "findMatchedContours": matched_contours_bit_map,
4538 "findMatchedContoursStart": matched_contours_start_bit_map,
4539 }
4540
4541 .. method:: font.findEncodingSlot(uni)
4542 font.findEncodingSlot(name)
4543
4544 Tests whether a glyph with this codepoint or name is in the font's encoding
4545 and returns the encoding slot. If the glyph is not present it returns -1.
4546
4547 (If a glyph with that name/unicode is in the font, but is not in the
4548 encoding, then a value beyond the end of the encoding will be returned).
4549
4550 .. method:: font.glyphs([type])
4551
4552 Returns an iterator which will return the glyphs in the font. By default
4553 they will be returned in "GID" order, but if type is specified as "encoding"
4554 they will be returned in encoding order. If returned in encoding order it
4555 is possible that a glyph will be returned more than once if there are
4556 multiple encoding slots which reference it.
4557
4558 .. method:: font.generate(filename[, bitmap_type=, flags=, bitmap_resolution=, subfont_directory=, namelist=, layer=])
4559
4560 Generates a font. The type is determined by the font's extension. The bitmap
4561 type (if specified) is also an extension. If layer is specified, then the
4562 splines and references in that layer will be used instead of the foreground
4563 layer.
4564
4565 Flags is a tuple containing some of
4566
4567 .. object:: afm
4568
4569 output an afm file
4570
4571 .. object:: pfm
4572
4573 output a pfm file
4574
4575 .. object:: tfm
4576
4577 output a tfm file
4578
4579 .. object:: ofm
4580
4581 output a ofm file
4582
4583 .. object:: composites-in-afm
4584
4585 Store composite info in the afm file
4586
4587 .. object:: glyph-map-file
4588
4589 Output a glyph map file giving the mapping between output gid and glyphnames
4590
4591 .. object:: short-post
4592
4593 Do not include glyphnames in a ttf/otf file
4594
4595 .. object:: apple
4596
4597 output apple advanced typography tables
4598
4599 .. object:: opentype
4600
4601 output opentype tables
4602
4603 .. object:: old-kern
4604
4605 output an old style 'kern' with opentype tables
4606
4607 .. object:: winkern
4608
4609 only add kern pairs for mapped glyphs (required for kerning in some/all
4610 versions of Windows)
4611
4612 .. object:: dummy-dsig
4613
4614 output an empty DSIG table so MS will mark a font with .ttf extension as
4615 an OpenType font.
4616
4617 .. object:: no-FFTM-table
4618
4619 Do not generate an 'FFTM' table
4620
4621 .. object:: TeX-table
4622
4623 Include a 'TeX ' table in an ttf/otf file
4624
4625 .. object:: no-mac-names
4626
4627 Do not include Mac names used on Classic Mac OS. This option does not
4628 affect native macOS (formerly known as Mac OS X) applications.
4629
4630 .. object:: round
4631
4632 Round PS coordinates to integers
4633
4634 .. object:: no-hints
4635
4636 Do not include PS hints
4637
4638 .. object:: no-flex
4639
4640 Do not include PS flex hints
4641
4642 .. object:: omit-instructions
4643
4644 Do not include TrueType instructions
4645
4646 .. object:: PfEd-comments
4647
4648 Include font and glyph comments in the 'PfEd' table
4649
4650 .. object:: PfEd-colors
4651
4652 Include glyph colors in the 'PfEd' table
4653
4654 .. object:: PfEd-lookups
4655
4656 Include lookup names in the 'PfEd' table
4657
4658 .. object:: PfEd-guidelines
4659
4660 Include guideline locations in the 'PfEd' table
4661
4662 .. object:: PfEd-background
4663
4664 Include background (and spiro) layers in the 'PfEd' table
4665
4666 .. object:: symbol
4667
4668 Generate an sfnt with a Symbol cmap entry rather than a Unicode entry.
4669
4670 See also :meth:`font.save()`.
4671
4672 .. method:: font.generateTtc(filename, others, [flags=, ttcflags=, namelist=, layer=])
4673
4674 Generates a truetype collection file containing the current font and all
4675 others listed -- the ``others`` argument may be ``None``, a font, or a tuple
4676 (or list) of fonts.
4677
4678 Flags are as above,
4679
4680 Ttcflags is a tuple consisting of the following
4681
4682 .. object:: merge
4683
4684 Try and share tables and glyphs among the various fonts.
4685
4686 .. object:: cff
4687
4688 Use the CFF glyph format rather than the TrueType format (the OpenType
4689 documentation says that this does not work, but both the Mac and
4690 unix/linux accept it).
4691
4692 .. method:: font.generateFeatureFile(filename[, lookup_name])
4693
4694 Generates an adobe feature file for the current font. If a lookup-name is
4695 specified then only data for that lookup will be generated.
4696
4697 .. method:: font.genericGlyphChange(stemType=<str>, thickThreshold=<double>, stemScale=<double>, stemAdd=<double>, stemHeightScale=<double>, stemHeightAdd=<double>, stemWidthScale=<double>, stemWidthAdd=<double>, thinStemScale=<double>, thinStemAdd=<double>, thickStemScale=<double>, thickStemAdd=<double>, processDiagonalStems=<boolean>, hCounterType=<str>, hCounterScale=<double>, hCounterAdd=<double>, lsbScale=<double>, lsbAdd=<double>, rsbScale=<double>, rsbAdd=<double>, vCounterType=<str>, vCounterScale=<double>, vCounterAdd=<double>, vScale=<double>, vMap=<tuple of tuples>)
4698
4699 This function uses keyword parameters. Which ones are required depends on
4700 the three type arguments (``stemType, hCounterType, vCounterType``).
4701
4702 If ``stemType`` is omitted, or is the string "uniform", then the
4703 ``stemScale`` parameter must be specified (and ``stemAdd`` may be).
4704 ``stemScale`` specifies a scaling factor by which all stems (horizontal and
4705 vertical, thick and thin) will be scaled. A value of 1.0 means no change.
4706 While ``stemAdd`` specifies the number of em-units to add to the width of
4707 each stem.
4708
4709 If ``stemType`` is the string "horizontalVertical", then values must be
4710 specified for ``stemHeightScale`` and ``stemWidthScale`` (and may be for
4711 ``stemHeightAdd, stemWidthAdd`` ). The first of these specifies scaling for
4712 the height of horizontal stems, and the second scaling for the width of
4713 vertical stems.
4714
4715 If ``stemType`` is the string "thickThin", then values must be specified for
4716 ``thinStemScale``, ``thickStemScale`` and ``thickThreshold`` (and may be for
4717 ``thinStemAdd, thickStemAdd`` ). The first of these specifies scaling for
4718 the width/height of thin stems, and the second scaling for the width/height
4719 of thick stems. While the ``thickThreshold`` argument specifies the size (in
4720 em-units) at which a stem is classified as "thick".
4721
4722 If ``hCounterType`` is omitted, or is the string "uniform", then horizontal
4723 counters, and the left and right side bearings will all be scaled using the
4724 same rules, and ``hCounterScale`` must be specified to provide the scaling
4725 factor (while ``hCounterAdd`` may be specified).
4726
4727 If ``hCounterType`` is the string "nonUniform", then horizontal counters,
4728 and the left and right side bearings may all be scaled using different
4729 rules, and ``hCounterScale, lsbScale`` and ``rsbScale`` must be specified
4730 to provide the scaling factors (while ``hCounterAdd, lsbAdd,`` and
4731 ``rsbAdd`` may be specified).
4732
4733 If ``hCounterType`` is the string "center", then the left and right
4734 side-bearings will be set so the new glyph is centered within the original
4735 glyph's width. (Probably more useful for CJK fonts than LGC fonts).
4736
4737 If ``hCounterType`` is the string "retainScale", then the left and right
4738 side-bearings will be set so the new glyph is within within the original
4739 glyph's width, and the side-bearings remain in the same proportion to each
4740 other as before.
4741
4742 If ``vCounterType`` is omitted, or is the string "mapped", then certain
4743 zones on the glyph may be placed at new (or the same) locations -- similar
4744 to BlueValues. So you can specify a zone for the baseline, one for the
4745 x-height and another for the top of capitals and ascenders (and perhaps a
4746 fourth for descenders). Each such zone is specified by the ``vMap`` argument
4747 which is a tuple of 3-tuples, each 3-tuple specifying a zone with: Original
4748 location, final location, and original width.
4749
4750 .. note::
4751
4752 No default value is provided for this argument you must figure out all the
4753 values yourself.
4754
4755 If ``vCounterType`` is the string "scaled", then vertical counters, and the
4756 top and bottom side bearings will all be scaled using the same rules, and
4757 ``vCounterScale`` must be specified to provide the scaling factor (while
4758 ``vCounterAdd`` may be specified). This is probably most useful for CJK fonts.
4759
4760 .. method:: font.getKerningClass(subtable_name)
4761
4762 Returns a tuple whose entries are: (first-classes, second-classes, offsets).
4763 The classes are themselves tuples of tuples of glyph names. The offsets will
4764 be a tuple of numeric kerning offsets.
4765
4766 .. method:: font.getLookupInfo(lookup_name)
4767
4768 Returns a tuple whose entries are: (lookup-type, lookup-flags,
4769 feature-script-lang-tuple). The lookup type is a string as described in
4770 :meth:`font.addLookup`, and the feature-script-lang tuple is also described
4771 there.
4772
4773 .. method:: font.getLookupSubtables(lookup_name)
4774
4775 Returns a tuple of all subtable names in that lookup.
4776
4777 .. method:: font.getLookupSubtableAnchorClasses(subtable_name)
4778
4779 Returns a tuple of all anchor class names in that subtable.
4780
4781 .. method:: font.getLookupOfSubtable(subtable_name)
4782
4783 Returns the name of the lookup containing this subtable.
4784
4785 .. method:: font.getSubtableOfAnchor(anchor_class_name)
4786
4787 Returns the name of the subtable containing this anchor class.
4788
4789 .. method:: font.importBitmaps(bitmap_font_file[, to_background])
4790
4791 Load any bitmap strikes out of the bitmap-font-file into the current font
4792
4793 .. method:: font.importLookups(another_font, lookup_names[, before_name])
4794
4795 The first argument must be a :class:`font` object, the second a string or a
4796 tuple of strings, and the third, another string.
4797
4798 It will search the other font for the named lookup(s) and import it into the
4799 current font. (Contextual lookups which invoke other lookups will have any
4800 nested lookups imported as well).
4801
4802 Lookups will be imported in the order listed. If a before-name is specified,
4803 then it is looked up in the current font and all lookups will be added
4804 before it, if not specified lookups will appear at the end of the list.
4805
4806 .. method:: font.interpolateFonts(fraction, filename)
4807
4808 Interpolates a font between the current font and the font contained in
4809 filename.
4810
4811 .. method:: font.isKerningClass(subtable_name)
4812
4813 Returns whether the named subtable contains a kerning class.
4814
4815 .. method:: font.isVerticalKerning(subtable_name)
4816
4817 Returns whether the named subtable contains a vertical kerning data
4818
4819 .. method:: font.italicize(italic_angle=, ia=lc_condense=, lc=uc_condense=, uc=symbol_condense=, symbol=deserif_flat=, deserif_slant=, deserif_pen=, baseline_serifs=, xheight_serifs=, ascent_serifs=, descent_serifs=, diagonal_serifs=, a=, f=, u0438=, u043f=, u0442=, u0444=, u0448=, u0452=, u045f=, xheight_percent=)
4820
4821 This function uses keyword parameters. None are required, if omitted a
4822 default value will be used. Some keywords have abbreviations ("ia" for
4823 "italic_angle") you may use either.
4824
4825 This function will attempt to italicize each selected glyph. For a detailed
4826 explanation of what this entails please see the information on the
4827 :ref:`Italic dialog <Styles.Italic>`.
4828
4829 The ``*_condense`` keywords should be 4 element tuples of floating point
4830 numbers; these numbers correspond to: Left side bearing condensation,
4831 stem condensation, counter condensation and right side bearing condensation.
4832 These numbers should be small numbers around 1 (scale factors, not
4833 percentages).
4834
4835 Set at most one of the ``deserif_*`` keywords.
4836
4837 Setting ``a`` to ``True`` will turn on the transformation that applies to
4838 the "a" glyph. Setting ``u0438`` will control the transformation that
4839 applies to the glyph at unicode codepoint U+0438.
4840
4841 The ``f`` keyword is slightly more complex. Setting it to 0 turns off all
4842 transformations of glyphs like "f", setting it to 1 will give "f" a tail
4843 which looks like a rotated version of its head, and setting it to 2 will
4844 simply extend the main stem of "f" below the baseline.
4845
4846 The ``xheight_percent`` keyword specifies how much the x-height should be
4847 changed by the transformation. The default value is 0.95, which reduces the
4848 x-height to 95% of its original size; a value of 1.0 means no change.
4849
4850 .. method:: font.lookupSetFeatureList(lookup_name, feature_script_lang_tuple)
4851
4852 Sets the feature list of indicated lookup. The feature-script-lang tuple is
4853 described at :meth:`font.addLookup()`.
4854
4855 .. method:: font.lookupSetFlags(lookup_name, flags)
4856
4857 Sets the lookup flags for the named lookup.
4858
4859 .. method:: font.lookupSetStoreLigatureInAfm(lookup_name, boolean)
4860
4861 Sets whether this ligature lookup contains data to store in the afm.
4862
4863 .. method:: font.mergeFonts(filename[, preserveCrossFontKerning])(font[, preserveCrossFontKerning])
4864
4865 Merges the font in the file into the current font.
4866
4867 .. method:: font.mergeFeature(filename, boolean)
4868
4869 Merge feature and lookup information from an adobe feature file, or metrics
4870 information from the (afm, tfm, etc) file into the current font. The
4871 optional boolean will try to skip invalid feature lookups containing
4872 replacement glyphs which do not exist in the font, which can help in reusing
4873 large feature files.
4874
4875 .. method:: font.mergeKern(filename)
4876
4877 Deprecated name for mergeFeature above
4878
4879 .. method:: font.mergeLookups(lookup_name1, lookup_name2)
4880
4881 The lookups must be of the same type. All subtables from lookup_name2 will
4882 be moved to lookup_name1, the features list of lookup_name2 will be merged
4883 with that of lookup_name1, and lookup_name2 will be removed.
4884
4885 .. method:: font.mergeLookupSubtables(subtable_name1, subtable_name2)
4886
4887 The subtables must be in the same lookup. Not all lookup types allow their
4888 subtables to be merged (contextual subtables may not be merged, kerning
4889 classes may not be (kerning pairs may be)). Any information bound to
4890 subtable2 will be bound to subtable1 and subtable2 will be removed.
4891
4892 .. method:: font.printSample(type, pointsize, sample, output_file)
4893
4894 Type is a string which must be one of
4895
4896 .. object:: fontdisplay
4897
4898 Display all glyphs in the font in encoding order
4899
4900 .. object:: chars
4901
4902 Display the selected glyphs scaled to fill a page
4903
4904 Ignores the pointsize argument.
4905
4906 .. object:: waterfall
4907
4908 Displays the selected glyphs at many pointsizes.
4909
4910 The pointsize argument should be a tuple of pointsizes here.
4911
4912 .. object:: fontsample
4913
4914 The third argument should contain a string which will be laid out
4915 and displayed as well as FontForge can.
4916
4917 .. object:: fontsampleinfile
4918
4919 The third argument should contain the name of a file which contains
4920 text to be laid out and displayed.
4921
4922 If output is to a file (see :func:`fontforge.printSetup()`) then the last
4923 argument specifies a file name in which to store output.
4924
4925 .. method:: font.randomText(script[, lang])
4926
4927 Returns a random text sample using the letter frequencies of the specified
4928 script (and optionally language). Both script and language should be
4929 expressed as strings containing OpenType Script and Language tags. "dflt" is
4930 a reasonable language tag. If the language is not specified, one will be
4931 chosen at random. If ff has no frequency information for the script/language
4932 specified it will use the letters in the script with equal frequencies.
4933
4934 .. method:: font.reencode(encoding[, force])
4935
4936 Reencodes the current font into the given encoding. Optionally force
4937 reencoding.
4938
4939 .. method:: font.regenBitmaps(tuple_of_sizes)
4940
4941 A tuple with an entry for each bitmap strike to be regenerated
4942 (rerasterized). Each strike is identified by pixelsize (if the strike is a
4943 grey scale font it will be indicated by ``(bitmap-depth<<16)|pixelsize``.
4944
4945 .. method:: font.removeAnchorClass(anchor_class_name)
4946
4947 Removes the named AnchorClass (and all associated points) from the font.
4948
4949 .. method:: font.removeLookup(lookup_name[, remove_acs])
4950
4951 Remove the lookup (and any subtables within it). remove_acs (0 or 1),
4952 specifies whether to remove associated anchor classes and points.
4953
4954 .. method:: font.removeLookupSubtable(subtable_name[, remove_acs])
4955
4956 Remove the subtable (and all data associated with it). remove_acs (0 or 1),
4957 specifies whether to remove associated anchor classes and points
4958
4959 .. method:: font.removeGlyph(uni[, name])(name)(glyph)
4960
4961 You may either pass in a FontForge glyph object (from this font) or identify
4962 a glyph in the font by unicode code point or name. In any case the glyph
4963 will be removed from the font.
4964
4965 If you use (uni,name) to specify a name, set uni to -1.
4966
4967 .. warning::
4968
4969 This frees FontForge's storage to this glyph. If you have any python
4970 references to that storage they will be looking at garbage. This does not
4971 go through the usual python reference mechanism.
4972
4973 .. method:: font.replaceAll(srch, rpl[, error_bound])
4974
4975 Searches the font for all occurrences of the srch contour (or layer) and
4976 replaces them with the replace contour (or layer).
4977
4978 .. method:: font.revert()
4979
4980 Reloads the font from the disk.
4981
4982 .. warning::
4983
4984 If you have any references to glyphs which live in the font those
4985 references will no longer be valid, and using them will cause crashes.
4986 This is very un-python-like.
4987
4988 .. method:: font.revertFromBackup()
4989
4990 Reloads the font from the backup file on the disk.
4991
4992 .. warning::
4993
4994 If you have any references to glyphs which live in the font those
4995 references will no longer be valid, and using them will cause crashes.
4996 This is very un-python-like.
4997
4998 .. method:: font.save([filename])
4999
5000 Saves the font to an sfd file. See also :meth:`font.generate()`
5001
5002 .. method:: font.saveNamelist(filename)
5003
5004 Saves the font's namelist to a file.
5005
5006 .. method:: font.getTableData(table_name)
5007
5008 Gets binary data from any saved table. FF will save 'fpgm', 'prep', 'cvt '
5009 and 'maxp'. FF may also save tables which you explicitly request. Do not
5010 expect to get binary data for tables like 'GPOS' or 'glyf' which FF will
5011 generate when it creates a font... that information is not currently available.
5012
5013 Returns a binary string.
5014
5015 .. method:: font.setTableData(table_name, sequence)
5016
5017 Sets binary data of any saved table. FF will save 'fpgm', 'prep', 'cvt '
5018 and 'maxp'. FF may also save tables which you explicitly request. Do not
5019 expect to set binary data for tables like 'GPOS' or 'glyf' which FF will
5020 generate when it creates a font... that information is not currently available.
5021
5022 If sequence is None, then the named table will be removed from the font.
5023
5024 .. method:: font.validate([force])
5025
5026 Validates the font and returns a bit mask of all errors from all glyphs (as
5027 defined in the ``validation_state`` of a glyph -- except bit 0x1 is clear).
5028 If the font passed the validation then the return value will be 0 (not 0x1).
5029 Otherwise the return value will be the set of errors found.
5030
5031 Note: The set of errors is slightly different for TrueType and PostScript
5032 output. The returned mask contains the list of potential errors. You must
5033 figure out which apply to you.
5034
5035 Normally each glyph will cache its validation_state and it will not be
5036 recalculated. If you pass a non-zero argument to the routine then it will
5037 force recalculation of each glyph -- this can be slow.
5038
5039
5040 .. rubric:: Selection Based Interface
5041
5042 See the :class:`selection` type for how to alter the selection.
5043
5044
5045 .. method:: font.addExtrema()
5046
5047 Extrema should be marked by on-curve points. If a curve in any selected
5048 glyph lacks a point at a significant extremum this command will add one.
5049
5050 .. method:: font.addInflections()
5051
5052 Please see :meth:`contour.addInflections()`.
5053
5054 .. method:: font.autoHint()
5055
5056 Generates PostScript hints for all selected glyphs.
5057
5058 .. method:: font.autoInstr()
5059
5060 Generates TrueType instructions for all selected glyphs.
5061
5062 .. method:: font.autoWidth(separation[, minBearing=, maxBearing=, height=, loopCnt=])
5063
5064 Guesses at reasonable horizontal advance widths for the selected glyphs
5065
5066 .. method:: font.autoTrace()
5067
5068 Auto traces any background images in all selected glyphs
5069
5070 .. method:: font.build()
5071
5072 If any of the selected characters is a composite character, then this
5073 command will clear it and insert references to its components (this command
5074 can create new glyphs).
5075
5076 .. method:: font.canonicalContours()
5077
5078 Orders the contours in the selected glyphs by the x coordinate of their
5079 leftmost point. (This can reduce the size of the charstring needed to
5080 describe the glyph(s).
5081
5082 .. method:: font.canonicalStart()
5083
5084 Sets the start point of all the contours of the selected glyphs to be the
5085 leftmost point on the contour. (If there are several points with that value
5086 then use the one which is closest to the baseline). This can reduce the size
5087 of the charstring needed to describe the glyph(s). By regularizing things it
5088 can also make more things available to be put in subroutines.
5089
5090 .. method:: font.changeWeight(stroke_width[, type, serif_height, serif_fuzz, counter_type, custom_zones])
5091
5092 See the :ref:`Element->Style->Change Width <Styles.Embolden>` command for a
5093 more complete description of these arguments.
5094
5095 Stroke_width is the amount by which all stems are expanded.
5096
5097 Type is one of "LCG", "CJK", "auto", "custom".
5098
5099 Serif_height tells ff not to expand serifs which are that much off the
5100 baseline, while serif_fuzz specifies the amount of fuzziness allowed in the
5101 match. If you don't want special serif behavior set this to 0.
5102
5103 Counter_type is one of "squish", "retain", "auto".
5104
5105 Custom_zones is only meaningful if the type argument were "custom". It may
5106 be either a number, which specifies the "top hint" value (bottom hint is
5107 assumed to be 0, others are between), or a tuple of 4 numbers (top hint,
5108 top zone, bottom zone, bottom hint).
5109
5110 .. method:: font.condenseExtend(c_factor, c_add[, sb_factor, sb_add, correct])
5111
5112 Condenses or extends the size of the counters and side-bearings of the
5113 selected glyphs. The first two arguments provide information on
5114 shrinking/growing the counters, the second two the sidebearings. If the last
5115 two are omitted they default to the same values as the first two.
5116
5117 A counter's width will become: ::
5118
5119 new_width = c_factor * old_width + c_add
5120
5121 If present the ``correct`` argument allows you to specify whether you want
5122 to correct for the italic angle before condensing the glyph. (it defaults to
5123 True)
5124
5125 .. method:: font.clear()
5126
5127 Clears the contents of all selected glyphs
5128
5129 .. method:: font.cluster([within, max])
5130
5131 Moves clustered coordinates to a standard central value in all selected
5132 glyphs. See also :meth:`font.round()`.
5133
5134 .. method:: font.copy()
5135
5136 Copies all selected glyphs into (FontForge's internal) clipboard.
5137
5138 .. method:: font.copyReference()
5139
5140 Copies all selected glyphs (as references) into (FontForge's internal)
5141 clipboard.
5142
5143 .. method:: font.correctDirection()
5144
5145 Orients all contours so that external ones are clockwise and internal
5146 counter-clockwise in all selected glyphs.
5147
5148 .. method:: font.correctReferences()
5149
5150 Checks a font for glyphs with mixed contours and references (or references
5151 with transformation matrices which cannot be represented in truetype (ie.
5152 scaling by 2 or more)). If a mixed case is discovered FontForge will take
5153 the contours out of the glyph, put them in a new glyph, and make a reference
5154 to the new glyph.
5155
5156 .. method:: font.cut()
5157
5158 Copies all selected glyphs into (FontForge's internal) clipboard. And then
5159 clears them.
5160
5161 .. method:: font.paste()
5162
5163 Pastes the contents of (FontForge's internal) clipboard into the selected
5164 glyphs -- and removes what was there before.
5165
5166 .. method:: font.intersect()
5167
5168 Leaves only areas in the intersection of contours in all selected glyphs.
5169 See also :meth:`font.removeOverlap()`.
5170
5171 .. method:: font.pasteInto()
5172
5173 Pastes the contents of (FontForge's internal) clipboard into the selected
5174 glyphs -- and retains what was there before.
5175
5176 .. method:: font.removeOverlap()
5177
5178 Removes overlapping areas in all selected glyphs.
5179 See also :meth:`font.intersect()`.
5180
5181 .. method:: font.replaceWithReference([fudge])
5182
5183 Finds any glyph which contains an inline copy of one of the selected glyphs,
5184 and converts that copy into a reference to the appropriate glyph. Selection
5185 is changed to the set of glyphs which the command alters.
5186
5187 If specified the fudge argument specifies the error allowed for coordinate
5188 differences.
5189
5190 .. method:: font.round([factor])
5191
5192 Rounds the x and y coordinates of each point in all selected glyphs. If
5193 factor is specified then ::
5194
5195 new-coord = round(factor*old-coord)/factor
5196
5197 See also :meth:`font.cluster()`.
5198
5199 .. method:: font.simplify([error_bound, flags, tan_bounds, linefixup, linelenmax])
5200
5201 Tries to remove excess points in all selected glyphs if doing so will not
5202 perturb the curve by more than ``error-bound``. Flags is a tuple of the
5203 following strings
5204
5205 .. object:: ignoreslopes
5206
5207 Allow slopes to change
5208
5209 .. object:: ignoreextrema
5210
5211 Allow removal of extrema
5212
5213 .. object:: smoothcurves
5214
5215 Allow curve smoothing
5216
5217 .. object:: choosehv
5218
5219 Snap to horizontal or vertical
5220
5221 .. object:: forcelines
5222
5223 flatten bumps on lines
5224
5225 .. object:: nearlyhvlines
5226
5227 Make nearly horizontal/vertical lines be so
5228
5229 .. object:: mergelines
5230
5231 Merge adjacent lines into one
5232
5233 .. object:: setstarttoextremum
5234
5235 Rotate the point list so that the start point is on an extremum
5236
5237 .. object:: removesingletonpoints
5238
5239 If the contour contains just one point then remove it
5240
5241 .. method:: font.stroke("circular", width[, CAP, JOIN, FLAGS])
5242 font.stroke("elliptical", width, minor_width, ANGLE[, CAP, JOIN, FLAGS])
5243 font.stroke("calligraphic", width, height, angle[, FLAGS])
5244 font.stroke("polygon", contour[, FLAGS])
5245 (Legacy interface)
5246 :noindex:
5247
5248 .. method:: font.stroke("circular", width[, CAP, JOIN, ANGLE, KEYWORD])
5249 font.stroke("elliptical", width, minor_width[, ANGLE, CAP, JOIN, KEYWORD])
5250 font.stroke("calligraphic", width, height[, ANGLE, CAP, JOIN, KEYWORD])
5251 font.stroke("convex", contour[, ANGLE, CAP, JOIN, KEYWORD])
5252 (Current interface)
5253
5254 Strokes the lines of the contours in all selected glyphs according to the
5255 supplied parameters. See :meth:`glyph.stroke()` for a description of the
5256 syntax and the :doc:`stroke </techref/stroke>` documentation for more general
5257 information.
5258
5259 .. method:: font.transform(matrix[, flags])
5260
5261 Transforms all selected glyphs by the matrix. The optional flags argument
5262 should be a tuple containing any of the following strings:
5263
5264 .. object:: activeLayer
5265
5266 Transform :attr:`font.activeLayer` only. (By default all layers are
5267 transformed.)
5268
5269 .. object:: guide
5270
5271 Also transform :attr:`font.guide` layer.
5272
5273 .. object:: noWidth
5274
5275 Do not change :attr:`glyph.width`.
5276
5277 .. object:: round
5278
5279 Round to int after the transformation is done.
5280
5281 .. object:: simplePos
5282
5283 Also transform simple positioning features and kern pairs.
5284
5285 .. object:: kernClasses
5286
5287 Also transform kerning classes.
5288
5289 .. method:: font.nltransform(xexpr, yexpr)
5290
5291 xexpr and yexpr are strings specifying non-linear transformations that will
5292 be applied to all points in the selected glyphs of the font (with xexpr
5293 being applied to x values, and yexpr to y values, of course). The syntax
5294 for the expressions is explained in the
5295 :ref:`non-linear transform dialog <transform.Non-Linear>`.
5296
5297 .. method:: font.unlinkReferences()
5298
5299 Unlinks all references in all selected glyphs and replaces them with splines.
5300