| 1 |
Finding shapes within glyphs |
| 2 |
============================ |
| 3 |
|
| 4 |
.. figure:: /images/rplref.png |
| 5 |
|
| 6 |
FontForge will allow you to search a font for all glyphs containing a certain |
| 7 |
shape and optionally replace that shape with another shape. |
| 8 |
|
| 9 |
FontForge allows you to control whether a match will be found even if the shape |
| 10 |
has undergone certain transformations (ie. rotated, scaled, flipped, etc.). |
| 11 |
|
| 12 |
The search will be on a point by point basis. That is, the first point of the |
| 13 |
search pattern will be moved to a point in the glyph being searched, and all |
| 14 |
subsequent points and control points in the search pattern must lie exactly on |
| 15 |
top of an equivalent point in the glyph. |
| 16 |
|
| 17 |
Of course if a transformation is allowed, then it is the transformed search |
| 18 |
pattern which must match. |
| 19 |
|
| 20 |
Normally FontForge will search all glyphs in a font, but you may restrict the |
| 21 |
search so that only those glyphs which are selected will be tested. |
| 22 |
|
| 23 |
The search and replace panes behave very much like the outline glyph views and |
| 24 |
you may draw within them using the tools available in the outline view. The menu |
| 25 |
at the top of the window is a subset of the menu in the outline glyph view. Only |
| 26 |
one of the two panes is active at a given time, and the menu works on the active |
| 27 |
one. You can make a pane active by clicking in it, or by using the [Tab] key. |
| 28 |
|
| 29 |
The ``[Find]`` button will start at the beginning of the font and search for the |
| 30 |
first glyph containing the search pattern and then open an outline glyph view |
| 31 |
looking at that glyph. After ``[Find]`` has been used once the button changes to |
| 32 |
``[Find Next]`` whose behavior is similar excepts that it starts at the last |
| 33 |
glyph found and displays the next glyph in the same window. |
| 34 |
|
| 35 |
The ``[Find All]`` button will select all glyphs containing the pattern. |
| 36 |
|
| 37 |
The ``[Replace]`` button only works after a ``[Find]/[Find Next]/[Replace]``. It |
| 38 |
replaces the thing found with the replace pattern, and does another |
| 39 |
``[Find Next]``. |
| 40 |
|
| 41 |
The ``[Replace All]`` button replaces all instances of the search pattern with |
| 42 |
the replace pattern and selects all glyphs found. |
| 43 |
|
| 44 |
There are three different kinds of search, and which is used depends on the |
| 45 |
shapes in the patterns. If the search pattern contains a closed path or multiple |
| 46 |
paths, then the search looks for an exact match, ie. for each path in the search |
| 47 |
pattern there must be a path in the glyph which matches it exactly. Whereas, if |
| 48 |
the search pattern is a single open path then the search will look for the |
| 49 |
search pattern *within* any path. And a variant of this last-- if the |
| 50 |
``[] Endpoints specify minimum length and direction only`` box is checked, then |
| 51 |
the end points of the search pattern will not be matched, only the points |
| 52 |
between them will match -- This may seem rather odd, but it allows you to match |
| 53 |
something like "all right angles" where you neither know nor care how long the |
| 54 |
segments are on either side of the right angle. |
| 55 |
|
| 56 |
The way a replacement happens will depend on the type of search. |
| 57 |
|
| 58 |
#. In a contour search (the first type above) all matching contours will be |
| 59 |
removed, and the replacement contours will be copied in. |
| 60 |
#. In a segment match the matched points will be removed from the contour and the |
| 61 |
replacement points will be added in their place. Note that the order in which |
| 62 |
you draw the two patterns is important, and the start point of the replacement |
| 63 |
will go where the start point of the search pattern came from. If you draw your |
| 64 |
patterns in the wrong direction you will not get the effect you want. Similarly, |
| 65 |
in most cases you will want the distance between the start point and end point |
| 66 |
of the search pattern to be the same as the equivalent distance in the replace |
| 67 |
pattern (else you will get odd jumps in your results). |
| 68 |
#. If the endpoints of the search pattern are not explicitly matched, then the end |
| 69 |
points of the replace pattern will not be used either. The end points of the |
| 70 |
replace pattern are simply used to position the replacement. So the first point |
| 71 |
matched will correspond to the second point in the search pattern; FontForge |
| 72 |
will figure out where the first point of the search pattern would lie; it will |
| 73 |
then position the first point of the replace pattern there, and use that to |
| 74 |
figure out where the real replacement points should go. It's hard to explain in |
| 75 |
words, but fairly obvious in a picture: |
| 76 |
|
| 77 |
.. flex-grid:: |
| 78 |
:class: flex-nobreak |
| 79 |
|
| 80 |
* :flex-widths: 5 1 |
| 81 |
|
| 82 |
- .. image:: /images/rplsansserifs.png |
| 83 |
- .. image:: /images/rplprocess.png |
| 84 |
|
| 85 |
The above could be used to convert a san-serif font into a serifed one |
| 86 |
(simplifying grossly). The end point of the search pattern is the same distance |
| 87 |
from its start point as is the end point of the replace pattern. The first |
| 88 |
(only) point matched in the search pattern is the right angle point. There is no |
| 89 |
point in the replace pattern that corresponds to it, so nothing in the replace |
| 90 |
pattern can be aligned with it, but given that point we can extrapolate |
| 91 |
backwards where the start point would be, then lay a virtual replacement point |
| 92 |
on top of it, and place the other replacement points normally. |
| 93 |
|
| 94 |
Now the end points also specify a minimum distance which must be matched. This |
| 95 |
is important because the replacement pattern also contains a right angle. You |
| 96 |
would not want FontForge recursively placing smaller and smaller serifs onto |
| 97 |
already existing ones. |
| 98 |
|
| 99 |
At the moment I see two possible uses for the replace feature: |
| 100 |
|
| 101 |
#. It can help you change the style of serifs in your font (see the example below) |
| 102 |
#. FontForge can't always detect which glyphs should contain references when |
| 103 |
reading in opentype (and some type1) fonts. You can use the replace feature to |
| 104 |
fix up all things that look like "A" with a reference to A. (see the first |
| 105 |
example above) |
| 106 |
|
| 107 |
.. image:: /images/rplserifs.png |