In this post you will learn all about fonts, complex line types, and shapes in BricsCAD®.
BricsCAD uses .shx files for fonts, shapes, GD&T symbols, and complex linetypes. You can create source .shp files, the subject of this post. BricsCAD, does not have a compiler to convert .shp to the compiled .shx files that BricsCAD works with.
BricsCAD displays fonts from both TrueType (.ttf) and AutoCAD® shape (.shx) files.
In addition to using .shx files for displaying fonts, BricsCAD uses the second type of .shx file for simple blocks-type entities known as "shapes," and so includes the Load and Shape commands for loading and placing them.
Explanations updated by Jason Bourhill of CAD Concepts.
QUICK SUMMARY OF SHAPE DEFINITIONS
Shapes and fonts are defined by .shp files, which need to be compiled into .shx files. A shape definition consists of at least two lines of text, a header that labels the shape or font, followed by one or more lines of data that describe the shape. The end of the data section is signified with a zero.
LINE 1: HEADER
*
130,6,NAME
*
(asterisk) --- indicates the start of the shape definition.
130 --- numbers the shape; fonts use the character's ASCII number. The range is 1-255.
6 --- specifies the total number of data bytes.
NAME --- names the shape; must be in uppercase, and a maximum of 16 characters
LINE 2: DATA
014,002,01C,001,01C,0
Shape data consists of vector and instruction codes. Vector codes define movement and drawing in 16 directions:
- --- first digit (always 0) indicates the number is hexadecimal
- --- second character specifies the vector length and ranges from 1 through F (15 units). 4 --- the third character specifies the direction of the vector
INSTRUCTION CODES
13Multiple bulge-specified arcs.
Hexadecimal | Decimal | Description |
---|---|---|
000 | 0 | End of shape definition. |
Basic Draw and Move | ||
001 | 1 | Begin draw mode (pen down). |
002 | 2 | End draw mode (pen up). |
Scaling | ||
003 | 3 | Divide vector lengths by the next byte. |
004 | 4 | Multiply vector lengths by the next byte. |
Memory | ||
005 | 5 | Push the current location onto the stack. |
006 | 6 | Pop the current location from the stack. |
Draw subshape | ||
007 | 7 | Draw the subshape number given by the next byte. |
Advanced Draw and Move | ||
008 | 8 | x,y displacment given by next two bytes. |
009 | 9 | Multiple x,y displacements; terminated with (0,0) code. |
Arcs | ||
00A | 10 | Octant arc defined by next two bytes |
00B | 11 | Fraction arc defined by next five bytes. |
00C | 12 | Arc defined by x,y displacement and bulge. 00D |
Fonts, Complex Linetypes, and Shapes
BricsCAD uses shapes for fonts, text in complex line types, and shapes.
SHX FONTS
In the early days of CAD, fonts were coded to be highly efficient. Computers didn't have much horsepower, and text was one of the slowest parts of the drawing display. To solve the problem of vector fonts taking a long time to display on the slow computers of the 1980s, Autodesk® invented the SHX format: the simpler the font, the fewer the lines, the faster the display.
The simplest font of all,Txt.shx, looked ugly, but was able to draw most characters with just eight lines. The drawback to SHX-based shapes, however, is that they are not well-suited to defining the complex curves that truly represent fonts, nor can they be properly filled.
As computers became faster over time, the number of lines used to draw characters increased. Eventually, Apple's TrueType font technology allowed for truly smooth-looking and filled fonts, even in CAD drawings and on plots. The gallery below illustrates the development of the letter Q, from the original Txt.shx to the more recent TimesRoman.ttf.
Development of the letter Q from the 1980s to today
These are the file names of the SHX files included with BricsCAD:
SHX Font File | Meaning |
---|---|
complex .shx | Serif font |
hangul .shx | Korean font |
isocp .shx | ISO standard font (European) |
italic .shx | Single-stroke italic font |
italicc .shx | Double-stroke italic font |
italict .shx | Triple-stroke italic font |
Japanese .shx | Japanese font |
monotxt .shx | Mono-spaced font (every character takes up the same width) |
romanc .shx | Triple-stroke serif font |
romand .shx | Double-stroke serif font |
romans .shx | Single-stroke serif font |
romant .shx | Triple-stroke serif font (same as RomanC) |
simplex .shx | Non-serif font |
trad_chin .shx | Chinese font |
txt .shx | Minimal non-serif font |
About Fonts in BricsCAD
To be compatible with old drawings, BricsCAD supports the use of original .shx fonts as well as today's .ttf TrueType fonts. TTF files are included by default with the Windows and MacOS operating systems, and with some Linux systems. BricsCAD does not support PostScript fonts, such as those provided as PFA and PFB files.
To load a font file into a drawing, use the Style command (a.k.a. Drawing Explorer), and then place text with the Text, MText, and other text-related commands. BricsCAD accesses TrueType fonts from each operating system's default font folder:
Windows: C:\Windows\FontsLinux: /usr/share/fonts/truetype
Linux: /usr/share/fonts/truetype
MacOS: /Users/Library/FontCollections
If a drawing displays fonts incorrectly, then the problem lies with BricsCAD not finding the location of the source font file. Here you have two solutions:
- Use Settings | Files | Support file search path to add paths
- Add the missing font files to the existing paths
TIP To obtain a list of all fonts used by a drawing, run the eTransmit command.
USING SHX IN COMPLEX LINETYPES
Complex linetypes use shapes for the text portion. The position and size of the text are defined in the default.lin and iso.lin linetype files, while the characters themselves are defined by the arial.ttf font, by default. The font used is determined by the Standard text style; change the style, and the linetype font changes.
Complex linetype showing how it combines text with regular linetypes
They are loaded and placed with the Linetype command. For details, see the post on linetypes
SHX IN SHAPES
Shapes are an early form of a block (symbol). Like fonts, they were displayed very quickly on the slow computers of the 1980s. Unfortunately, they were very hard to code; today it is so much easier to use blocks, and so shapes are no longer used for symbols. Nowadays, shapes are used only by the Tolerance command.
Shapes use a format of the SHX file that is nearly identical to that of fonts. Shapes must first be loaded into the drawing with the Load command, and then placed in the drawing with the Shape command.
SHX IN GD&T
GD&T (geometric dimensioning and tolerances) symbols are used for machining parts precisely.
Tolerance symbols
The symbols are placed by the Tolerance command, and are based on shapes from the gdt.shx file.
SHAPE COMPATIBILITY WITH AUTOCAD®
For fonts, complex linetypes, shapes, and tolerances, BricsCAD can use any .shx file that AutoCAD® can use.
Both CAD packages use a .fmp file (short for "font map") to substitute similar-looking .shx fonts for those found in each other's drawings. At the time of writing, BricsCAD specifies default.fmp but has not implemented it.
About Shape Files
The shape file format is arcane, written to be a highly efficient form of the symbol for the slow-running personal computers of the 1980s. Shapes were quickly superseded by blocks but remained on the scene due to their use in line types and so on.
Coding custom shape definitions require knowledge of trigonometry. Jason Bourhill recommends that you use the MkShape (make the shape) utility provided by Martin Drese.
There are two kinds of files used for shapes: .shp and .shx. The differences between them are as follows:
- .shp are shape source When you write or edit a shape or font, you work with the .shp file. A portion of a typical .shp file looks like this:
*
130,6,TRACK1
014,002,01C,001,01C,0
- .shx are compiled shape files. These are the files that are loaded into BricsCAD for use with fonts, tolerances, and so on.
TIP You can use AutoCAD® or the Compile utility from Bricsys to compile shape files you create using the information in this post. The Compile utility is part of the free BCadTools collection by Torsten Moses from Bricsys. You cannot edit .shx files, unless you have access to a shape decompiler program. Autodesk® offers the DumpShx.Exe utility in AutoCAD®'s Express folder, or else search online for decompilers.
THE SHAPE FILE FORMAT
Autodesk® defined two formats for the shape file: one for shapes (simple blocks), and one for fonts. The difference between the two types is subtle: the font version of the file includes a code 0 to alert the CAD system to treat the file as a font definition. When the 0 is missing, the file is treated as a shape definition.
BricsCAD can load both forms of a shape file, as shapes with the Load command, and as fonts with the Style command. You cannot, unfortunately, distinguish between the two easily. One way is to guess by the file or folder names. For instance, italic.shx is a font file, while ltypeshap.shx is probably a shape file. Other file names can be vague: symusic.shx seems like a shape file, but in fact, is a font file (musical symbols). BricsCAD does not warn you if you load the wrong kind of shape file with the Load command; in contrast, the Style command lists only font-related SHX files.
Here are some aspects of the shape file format:
- Shape files typically define one or more shapes, up to 258 in total.
- Font files typically define all the characters for a single font, such as A-Z, a-z, 0-9, and punctuation.
- Unicode font files can have up to 32,768 definitions.
Like many other customization files, shape definitions consist of two or more lines. The first line is the header, which labels the shape, while the second (and following) lines define the shape through codes. The final code in each definition is 0, which is called the terminator.
The general format of a shape definition consists of a header line, followed by one or more definition lines:
*
shapeNumber,totalBytes,shapeName
byte1,byte2,byte3,...,0
Each line can be up to 128 characters in length; shape files with long lines will not be compiled. Each definition is limited to a total of 2,000 bytes. You can use blank lines to separate shape definitions and the semicolon ( ; ) to include comments in the file.
HEADER FIELDS
The following describes the fields of the shape's header description:
Definition Start
*
130,6,TRACK1
The asterisk signals AutoCAD® that the next shape definition is starting.
shapeNumber *
130,6,TRACK1
Each shape requires a unique number by which it is identified. For fonts, the number is the equivalent ASCII code, such as 65 for the letter A.
TIP The shapeNumbers 256, 257, and 258 are reserved for the degree, plus-or-minus, and diameter symbols.
totalBytes
*
130,6,TRACK1
After defining the shape, you have to add up the number of bytes that describe the shape, including the terminator, 0. Makes no sense to me. There is a limit of 2,000 bytes per shape definition.
Unicode shape numbers use two bytes each.
shapeName
*
130,6,TRACK1
Shape names can be mixed cases. The maximum length of the name is 16 characters; excess characters are truncated.
DEFINITION LINES
The header line is followed by one or more lines that define the shape or font. This is the nitty-gritty part of shape files, and you will now see why they are rarely used anymore.
bytes
014,002,01C,001,01C,0
The shape is defined by "bytes," called that because each code is a single byte (the computer measurement) in size. Bytes define vector lengths and directions, or instruction codes. They can be in decimal (base 10) or hexadecimal (base 16) format. Definition lines are a maximum of 128 characters long (including commas), and a maximum of 2,000 bytes overall (not including commas).
The last definition line ends with a 0.
TIP When the first character of a byte is a 0, the two characters following are in hexadecimal, such as 00C (12, in decimal).
VECTOR CODES
Vector codes describe how the shape is drawn. They define movement (pen up) and drawing (pen down). Vector codes are limited to 16 directions, increments of 22.5 degrees, as shown by the figure:
Vectors defining direction and distance
Notice that the lengths are not radial. Diagonal vectors such as 2 and E are 1.414 times longer than the orthogonal vectors, such as 4 and 0. (Recall that 1.414 is the square root of 2.)
Vector codes are always in hexadecimal notation, such as 02C:
Decimal | Hexadecimal |
---|---|
0 … 9 | 0 … 9 |
10 | A |
11 | B |
12 | C |
13 | D |
14 | E |
15 | F |
INSTRUCTION CODES
In addition to describing direction and length, shapes use codes to provide instructions. Code numbers can be in decimal (dec) or hexadecimal (hex). Hex codes always have three digits, the first being a 0 (zero). Notice that some codes rely on additional codes following. And, note that shapes are limited to lines, arcs, and spaces.
Hex | Dec | Description |
---|---|---|
000 | 0 | |
Basic Draw and Move | ||
001 | 1 | |
2 | ||
Scaling | ||
003 | 3 | |
004 | 4 | |
Memory | ||
005 | 5 | |
6 | ||
Draw Subshape | ||
007 | 7 | |
Advanced Draw and Move | ||
008 | 8 | |
009 | 9 | |
Arcs | ||
00A | 10 | |
00B | 11 | |
00C | 12 | |
00D | 13 | |
Fonts Only | ||
00E | 14 |
A stack is a specific type of memory called FILO, short for "first in, last out." When two numbers are stored in the stack memory, the last number stored is the first one out. Think of an elevator, where the first person in is usually the last one out.
End of Shape -- 0/000
Code 0 must mark the end of every shape definition. It appears at the end of the last line.
00C,(2,0,-127),0
In hex notation, 0 appears as 000.
Draw Mode -- 1/001
Code 1 starts drawing mode ("pen" is down). By default, every shape definition starts with draw mode turned on.
2/002: Move Mode --
Code 2 starts move mode ("pen" is up). In the sample below, the pen is raised before moving to a new location.
2,8,(-36,-63),1,0
Reduced Scale -- 3/003
Code 3 specifies the relative size of each vector. Each shape starts at the height of one of the orthogonal vectors, such as 4. To make the shape smaller, use code 3 followed by a byte specifying the scale factor, 1 through 255. For example, the following code draws the shape half as large:
TIP Within a shape definition, the scale factor is cumulative. Using the same scale code twice multiplies the effect. For example, 3,2 followed by another 3,2 makes part of the shape four times smaller. At the end of the shape definition, return the scale to unity so that other shapes are not affected.
Enlarged Scale -- 4/004
To make the shape larger, use code 4 followed by a byte specifying the scale factor, 1 through 255. For example, the following code draws the shape twice as large:
4,2
Note that you can use the 3 and 4 codes within a shape definition to make parts of the shape larger and smaller.
Save (Push) -- 5/005
Code 5 saves (pushes) the current x, and y-coordinates to the stack memory. You then use code 6 to recall (pop) the coordinates for later use. The stack memory is limited to four coordinates. By the end of the shape definition, you must recall all coordinates that you saved; i.e., there must be an equal number of code 5s and 6s, as shown below:
2,14,8,(-8,-25),14,5,8,(6,24),1,01A,016,012,01E,02C,02B,01A,2,
8,(8,5),1,01A,016,012,01E,02C,02B,01A,2,8,(4,-19),14,6, 14,8,(8,-9),0
Recall (Pop) -- 6/006
Code 6 recalls (pops) the most recently saved coordinates from the stack memory.
Subshape -- 7/007
Code 7 calls a subshape, which is simply another shape. Shapes can be used within other shapes, which helps reduce the tedium of coding shapes. Code 7 is followed by a reference to another shape number, between 1 to 255. (Recall that all shapes within a .shp file are identified by number.) For example:
7,2 calls shape 2 a subshape.
X,y Distance -- 8/008
Codes 8 and 9 overcome the restriction that the vector codes (just 16 directions) place on the drawing.
Code 8 defines a distance using two bytes that range from -128 to 127:
8,xDistance,yDistance
The example below shows code 8 being used often:
2,14,3,2,14,8,(-21,-50),14,4,2,14,5,8,(11,25),1,8,(-7,-32),2,
8,(13,32),1,8,(-7,-32),2,8,(-6,19),1,0E0,2,8,(-15,-6),1,0E0,2,
8,(4,-6),14,6,14,3,2,14,8,(21,-32),14,4,2,0
In the first line of code above, 8,(-21,-50) draws 21 units left (-x), and 50 units down (-y).
X,y Distances -- 9/009
Whereas code 8 specifies a single coordinate, code 9 specifies a series of coordinates, terminated by (0,0). For example:
9,(1,2),(-3,4),(5,-6),(0,0)
Octant Arc -- 10/00A
Code 10 defines an octant arc, which is an arc whose angle is limited to multiples of 45 degrees, as shown in the following figure. The arc always starts at position 0, and then moves counterclockwise.
Defining the length of an arc through octants
The arc is specified by the following bytes:
10,radius,- 0 startingOctant octantSpan
- 10 specifies an octant arc.
- radius is a value between 1 and 255.
- Negative sign changes the direction of the arc to clockwise; leave it out for a counterclockwise direction.
- 0 specifies the following characters are hexadecimal.
- startingOctant specifies where the arc starts; the value ranges between 0 and 7).
- octantSpan specifies how hard the arc travels, again a number between 0 through 7.
TIP When octantSpan is 0, the shape draws a circle. The octant arc code usually uses parentheses to make itself clearer, such as: 10,(25,-040)
Fractional Arc -- 11/ 00B
Code 11 is more useful because it draws arcs that don't end and start at octant angles. Its specification requires, however, five bytes:
11,startOffset,endOffset,highRadius, radius,- 0 startingOctant octantSpan
- 11 defines the fractional arc.
- startOffset specifies how far (in degrees) from the octant angle the arc begins.
- endOffset specifies how far from an octant angle the arc ends.
- highRadius specifies a radius larger than 255 units; when the arc has a radius of 255 units or smaller, then this parameter is 0. The highRadius is multiplied by 256, then added to the radius value to find the radius of the arc.
- radius is a value between 1 and 255.
- Negative sign changes the direction of the arc to clockwise; leave it out for a counterclockwise direction.
- 0 specifies the following characters are hexadecimal.
- startingOctant specifies where the arc starts; the value ranges between 0 and 7.
- octantSpan specifies how far the arc travels, again a number between 0 through 7.
TIP Here is how Autodesk® suggests determining the value of startOffset and endOffset:
- Determine the offsets by calculating the difference in degrees between the starting octant's boundary (which is always a multiple of 45 degrees) and the start of the arc.
- Multiply the difference by 256.
- Divide the result by 45.
Bulge Arc -- 12/00C
Code 12 draws a single-segment arc by applying a bulge factor to the displacement vector. 0C,xDisplacement,yDisplacement, bulge
- xDisplacement and yDisplacement specify the starting x, and y-coordinates of the arc.
- bulge specifies the curvature of the arc. All three values range from -127 to 127.
This is how Autodesk® says the bulge is calculated: "If the line segment specified by the displacement has length D, and the perpendicular distance from the midpoint of that segment has height H, the magnitude of the bulge is ((2 * H / D) * 127)."
Calculating the size of a bulge
A semicircle (180 degrees) would have a bulge value of 127 (drawn counterclockwise) or -127 (drawn clockwise), while a line has a value of 0. For an arc greater than 180 degrees, use two arcs in a row.
Polyarc -- 13/00D
Code 13 draws a polyarc, an arc with two or more parts. It is terminated by (0,0).
13,(0,2,127),(0,2,-127),(0,0)
TIP To draw a straight line between two arcs, it is more efficient to use a zero-bulge arc, than to switch between arcs and lines.
Flag Vertical Text Flag -- 14/00E
Code 14 is for fonts only, and only fonts that are designed to be placed horizontally and vertically. When the orientation is vertical, the code following is processed; if horizontal, the code is skipped.
Download BricsCAD free for 30-days
Start Making Complex Linetypes Today
Permanent or subscription licenses that work in all languages, and all regions.
- Introduction
- 55 Tips for BricsCAD Users
- Settings
- Changing the Environment
- Custom User Interface
- Introduction to the Customize Dialog Box
- Customize the Menu Bar & Context Menus
- Toolbars and Button Icons
- Writing Macros and Diesel Code
- Ribbon Tabs and Panels
- Keystroke Shortcuts, Aliases & Shell Commands
- Mouse, Double-click & Tablet Buttons
- Absolutely Everything You Need to Know About The Quad
- Rollover Properties
- Workspaces and the User Interface
- Designing Tool & Structure Panels
- Creating Simple & Complex Linetypes
- Patterning Hatches
- Decoding Shapes & Fonts
- Coding with Field Text
- Writing Scripts
- Programming with LISP (Introduction)
- LISP Functions