LFF Font Format - LibreCAD/LibreCAD GitHub Wiki
LFF is an abbreviation and the file extension name of the LibreCAD Font File (*.lff
).
Here are the LFF specification, the list of ready to use LFF fonts, and the list of utilities and converters used to work with LFF and other font formats.
The header of file is self-documented. Any line
started with #
is a comment line (in comments could be defined some
font variables and properties).
# Format: LibreCAD Font 1
# Creator: LibreCAD
# Version: {librecad_version}
# Name: {font_name}
# Encoding: UTF-8
# LetterSpacing: 3
# WordSpacing: 6.75
# LineSpacingFactor: 1
# Created: {author_name}
# Last modified: {YYYY-MM-DD}
# License: {license_name}
Font Name
value is recommended, but ignored by
LibreCAD — font file name used in font choosing
dialogs instead.
Below header, separated with emppty line, is an explanation of a glyph definition, and every glyph is separated with empty line.
[0041] A
0.0000,0.0000;3.0000,9.0000;6.0000,9.000
1.0800,2.5500;4.7300,2.5500
- Line 1 — UTF-8 code + letter/symbol;
- Line 2 & 3 — sequence like polyline vertex with
;
separating vertex and,
separating X and Y coords of single vertex/point. One polyline definition in each line of text.
[0066] f
1,0;1,7.5;2.5,9,A-0.414214;3,9
0,6;3,6
- Line 2 — sequence like polyline vertex with
;
separating vertex and,
separating X and Y coords of single vertex/point. If there is a third field prefixed withA
this field is a polyline bulge (the tangent of 1/4 of the arc angle).
[00C1] Á
C0041
2.000000,9.0000,4.0000,10.0000
- Line 2 — copy defined char
[0041] A
as a nested block.
Note
LFF fonts created by and for LibreCAD may include hardcoded rhombus
("diamond") shape for [fffd] �
symbol:
[fffd] �
1,0;0,2;1,4;2,2;1,0
This shape could be changed in LFF font code manually, but LibreCAD
will always ignore custom defined shape for [fffd] �
symbol,
and would use hardcoded rhombus instead (other software with
LFF fonts support might allow to use custom defined shape for this
symbol though, see #1835
and #1839).
The bulge is the tangent of 1/4 of the arc angle. If bulge is positive the arc included angle is counter-clockwise.
For code to calculate center, radius and included angle you can see the
function, in file src/lib/engine/rs_polyline.cpp
:
std::unique_ptr<RS_Entity> RS_Polyline::createVertex(const RS_Vector& v, double bulge, bool prepend)
Note
In previous LibreCAD versions Arc Bulge code has been set as next:
RS_Entity* RS_Polyline::createVertex(const RS_Vector& v, double bulge, bool prepend)
The formula to calculate the radius is:
A = arctangent(B)*4
R = absolute(D / (sin(A/2)*2) )
where:
-
B
is bulge -
D
is distance from start to end point -
R
is the calculated radius
Another formula to calculate the radius:
S = B*d
R = (S*S + d*d) / (2*S)
where:
-
B
is bulge -
S
is the calculated sagitta -
d
is half chord (half of distance from start to end point) -
R
is the calculated radius
Determining direction:
- In:
LastPoint
andPrevPoint
- Out: points starting and ending arc
if (B>=0)
{
startPoint = PrevPoint;
endPoint = LastPoint;
}
else
{
startPoint = LastPoint;
endPoint = PrevPoint;
}
Calculate center of circle of arc:
- Point
middle = (PrevPoint + LastPoint) /2
Distance from middle
to Center is z
:
z = sqrt(sqr(R)-sqr(d)); //d = D/2
Center is distance z
from middle
in direction perpendicular to line
between startPoint
and endPoint
:
center.X = middle.X - (endPoint.y-startPoint.y)/d*z;
center.Y = middle.Y + (endPoint.x-startPoint.x)/d*z;
LibreCAD distributed with a number of fonts in LFF format, also there are external LFF fonts not included in LibreCAD:
- https://github.com/LibreCAD/LibreCAD/tree/master/librecad/support/fonts
- Japanese stroke fonts (bundled in LibreCAD): https://domisan.sakura.ne.jp/article/cadfont/cadfont.html
- UnifontEX (outlined font): https://stgiga.github.io/UnifontEX/#librecad-lff-version-download
- Simple stencil font: https://github.com/blackjetrock/librecadfonts
There is number of font formats and converters.
DXF files could use various font formats, see: https://ezdxf.mozman.at/docs/tools/fonts.html
QCAD fonts (*.cxf
) are single line based vector fonts, used in
QCAD (https://qcad.org).
- CXF fonts examples: https://github.com/qcad/qcad/tree/master/fonts
Note
LibreCAD Font File format is derived in a part from the QCAD fonts format.
And LibreCAD is able to open and save CXF files natively.
Hershey fonts (*.jhf
) are single line based vector fonts. LibreCAD
already includes some of Hersheys fonts converted to LFF.
- Specification: https://coolbutuseless.github.io/package/hershey/articles/hershey-font-format.html
- JHF fonts examples:
-
JHF to LFF aka
jhf2lff
(CLI utility): https://github.com/Rallaz/LibreCAD/blob/master/tools/ttf2lff/lfftransform.cpp -
jhftool
(Python script): jhftool.txt (specially for Chinese font Mingti-basic.hf.txt, CJK URO and Ext-A font) - Hershey Text (Inkscape built-in Hershey fonts editor): https://www.evilmadscientist.com/2015/inkscape-v-0-91/
- Discussions:
FontoBene fonts (*.bene
) are single line based fonts, used in
LibrePCB (https://librepcb.org). Font format is derived from LFF
font specification.
- Specification: https://github.com/fontobene/fontobene
- BENE fonts examples: https://github.com/fontobene/fontobene-fonts/
-
LFF to BENE aka
lff2bene
(Python script): https://github.com/fontobene/fontobene-converters/blob/master/lff/convert.py
TrueType fonts (*.ttf
) are filled path based vector fonts.
-
TTF to LFF aka
ttf2lff
(online): https://librecad.org/ttf2lff - TTF fonts examples:
-
ttf2lff
(offline CLI utility): https://github.com/LibreCAD/LibreCAD/tree/master/tools/ttf2lff-
ttf2lff
(binary for Windows/Wine): https://sourceforge.net/projects/librecad/files/Windows/ttf2lff/
-
Shapefile Index fonts (*.shx
) are vector fonts used by default
in AutoCAD DXF.
- Specification: http://docs.autodesk.com/ACD/2011/ENU/filesACG/WS73099cc142f4875513fb5cd10c4aa30d6b-7f3c.htm
-
SHX to LFF aka
shx2lff
: https://github.com/Kharabadze/SHX_font_converter (outdated mirror on SF.net)
Warning
SHX to LFF converter code listed above might has potential CVE issues, see #1244.
- SHX to Hershey aka
shx2jhf
: https://github.com/tatarize/shxparser - SHX fonts examples:
- Discussions: