Fontforge Scripting how to add ligatures for a glyph - fontforge

I'm making a font with scripting on Fontforge. Everything goes well, but I have this problem I don't know how to specify for a selected glyph that if two other glyphs came simultaneously show the selected glyph. I have already made the Lookuptable and the subtable for that but I don't know the function that would define some ligatures for a specified glyph. Here is the code for making table and subtable for adding ligatures to a glyph.
AddLookup("Ligatures","GSUB_ligature",9,[["rlig",[["arab",["dflt"]]]]])
AddLookupSubtable("Ligatures","Ligatureshi")

You need to specify the Ligature substitution using a tuple of existing Glyph names.
A contrived example:
#!/usr/bin/env python3
import fontforge
# load your font, etc…
ligature_name = 'f_l'
ligature_tuple = ('f', 'l')
font.addLookup('ligatures','gsub_ligature', (),[['rlig',[['arab',['dflt']]]]])
font.addLookupSubtable('ligatures', 'ligatureshi')
glyph = font.createChar(-1, ligature_name)
glyph.addPosSub('ligatureshi', ligature_tuple)

After you've added the lookup & subtable, do this:
Select("fl")
AddPosSub("LigatureSubtableName", "f l")
The above FontForge script will add a fl ligature.

Related

FontForge: Count of Defined Glyphs

I'm fairly new to FontForge, and I just want to merge two fonts for my specific usage.
I know how to merge two fonts from this question and I'm aware of TTF, ... 65535 lookup limits, so I'm trying to Detach & Remove Glyphs... for some glyph ranges, and for this:
I need to know how many glyph is defined, so I can decide which range to detach and remove. It seems fairly simple info, but I can not find where it is shown.
is there any menu or macro to show the current number of defined glyphs in FontForge?
I was looking for the same info. This will give you the number of defined glyphs fairly quickly:
fontforge -lang=ff \
-c 'Open($1); SelectWorthOutputting(); Print($selection)' "$FONTFILE" \
2>/dev/null |tr -d '][' |tr , '\n' |grep -c 1
The SelectWorthOutputting() function fills an array with ones for each defined glyph, so we can print this out and filter it to get the count.
I think found an answer, however it may not be the best approach. as FontForge saves projects in plain text, we can search for StartChar: keywords in the saved project file (project_name.sfd), which each section started by a StartChar: defines one glyphs in the font project. so if we count them we may know how many glyphs has been defined in the font file, for example, in bash the command:
grep -E "^StartChar\:" project_name.sfd | wc -l
would count them for us, and then we may know how many glyphs has been define so far.
This question pops up as first Google hit, so I'll just place this for posterity, but the proper code answer is from #Jerry Penner.
It's also possible from the program GUI to obtain the info in a quick dirty way:
Reduce the number of displayed glyphs via Encoding > Compact menu
Select the last glyph in your font
At the top right below the menu will be displayed the glyph "number" starting from 0 (so in below picture example the total count is 270).
Note: the number displayed is for the current compact view, not the actual glyph number in the font.

FontForge Script: how to add kerning between two glyphs to a font

I would like to add kerning between the letter A and itself so that the two letters stack on top of each other, over many font files.
How would I achieve this using a FontForge script?
Here is a script to add kerning between the letter A and itself to a font that previously had no kerning table:
(1) Open your font
Open($1);
(2) Add a lookup with the gpos_pair type, and "kern" as feature, then create a subtable inside
AddLookup("kern","gpos_pair",0,[["kern",[["latn",["dflt"]]]]]);
AddLookupSubtable("kern","kern-1");
(3) Select your first glyph by name
Select("A");
(4) Add kerning from this glyph to another glyph:
AddPosSub("kern-1",GlyphInfo("Name"),0,0,-2883,0,0,0,0,0);
(5) Generate your font
Generate($1:r + "-kerned.ttf");
I am adding this here because I could not find a single example of AddPosSub for character pairs (and it is really difficult to figure out where all the 0 should go without randomly trying.

writing single-storey ɑ in Gnuplot graph title?

How can I write single-storey ɑ (The first letter in English) in Gnuplot graph title?
I am always get "a" (double-story) in Gnuplot plot title?
Suggesting to use the Greek letter alpha "ɑ" is not a good solution.
The correct answer is that the shape of the "a" glyph is dependent on the font, not the encoding. Unicode codepoints only specify what character is to be drawn, not what shape it has.
It depends on the terminal you want to use, but probably the most straightforward solution would be to use proper encoding and paste the required character directly:
set encoding utf8
set term wxt font "Times,12"
set title 'ɑ'
plot x
EDIT:
the special character ɑ can be also specified (for example in the interactive Gnuplot console) in terms of its UTF8 representation (two octal numbers) as:
set title '\311\221'
I only use lubunutu and do not use ubunutu.
In lubuntu CharacterMap utility exists and it can be used from accessory category.
On ubuntu, the same tool exists.
https://help.ubuntu.com/community/CharacterMap
I could copy and paste Lattin Small Letter alpha "ɑ" to terminal.
(Note that is not literally single-storey version of a).
As Ethan wrote use of Lattin Small Letter alpha "ɑ" is not correct in literal sense but I think this is possible workaround.
Correct solution is use font with single-storey a like Futura font.
Free Futura font seem to be available from
http://www.webpagepublicity.com/free-fonts-f4.html#Free%20Fonts

[aframe]how show chinese characters in aframe?

I want to use 'text' property to show chinese characters, but the characters cannot show. for example:
<a-entity text="align:center;value: 返回back; "></a-entity>
You will need to get a font file that contains the Chinese characters. Then generate an SDF font with Hiero (https://github.com/libgdx/libgdx/wiki/Distance-field-fonts).
https://aframe.io/docs/0.5.0/components/text.html#generating-sdf-fonts
Alternatively, the process is similar for the text-geometry component, you can generate a font set with Chinese characters using FaceType.js
Use MSDF font generator (source) then load that fond in the text component.

Adding glyphs to Fontforge

When I open Fontforge to create a new font, it only lists a limited set of characters / glyphs. In the font I create, I need some glyphs that are missing from that default set, e.g. "single right-pointing angle quotation mark" (U+203A) and "single left-pointing angle quotation mark" (U+2039).
How can I add "slots" for these glyphs, or rather:
What is the proper way to add glyphs that are defined in the Unicode table?
Ah, well, just go to Encoding > Add encoding slot, then there will be a dialog to set how many slot(s) you want to add.
Ah, well, just go to Encoding > Reencode and choose an encoding that contains the relevant slots.

Resources