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.

LFF Specification

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 with A 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).

Arc Bulge

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 and PrevPoint
  • 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;

LFF Fonts

LibreCAD distributed with a number of fonts in LFF format, also there are external LFF fonts not included in LibreCAD:

Font Converters

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

QCAD fonts (*.cxf) are single line based vector fonts, used in QCAD (https://qcad.org).

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

Hershey fonts (*.jhf) are single line based vector fonts. LibreCAD already includes some of Hersheys fonts converted to LFF.

FontoBene fonts

FontoBene fonts (*.bene) are single line based fonts, used in LibrePCB (https://librepcb.org). Font format is derived from LFF font specification.

TrueType fonts

TrueType fonts (*.ttf) are filled path based vector fonts.

Shapefile Index fonts

Shapefile Index fonts (*.shx) are vector fonts used by default in AutoCAD DXF.

Warning

SHX to LFF converter code listed above might has potential CVE issues, see #1244.

⚠️ **GitHub.com Fallback** ⚠️