609 Commits

Author SHA1 Message Date
Ben Harris
891129f1f4 Correct baseline of BDF fonts 2024-11-16 14:40:47 +00:00
Ben Harris
ac1a68d964 Emit OpenType tables in a more logical order
TTX doesn't actually care what order we emit tables in: it will always
put them into the recommended order.  So I've made the order something
that works correctly and that doesn't look too silly in TTX's console
output.
2024-11-16 11:53:04 +00:00
Ben Harris
290c8032b6 Correct cap height in font headers 2024-11-16 11:53:04 +00:00
Ben Harris
3c333a8790 Put version number in glyph complement PDF
Now that we've got the version number in a constant, this is
convenient.
2024-11-16 11:53:04 +00:00
Ben Harris
62ba3a3307 Correct ordering of stem hints
The spec for Type 2 charstrings requires that all hstem hints must
occur before all vstem hints.
2024-11-14 23:31:36 +00:00
Ben Harris
b8abf30fcd Make the processing of SOURCE_DATE_EPOCH safe
And explain in excruciating detail why it's safe.  It's only actually
safe on systems (like POSIX ones) where time_t is an integer type, but
I think that's good enough for me.
2024-11-14 22:27:18 +00:00
Ben Harris
c924855103 Support SOURCE_DATE_EPOCH
If set, it is used to set the "created" and "modified" fields in the
OpenType 'head' table.  This means that builds of Bedstead can be
reproducible.

The current code just casts the "long long" interpretation of the
environment variable into a time_t.  This is potentially undefined
behaviour, because time_t might be a signed integer type smaller than
"long long".  But I can't find a way to properly range-check it.  Even
in POSIX, where time_t is required to be an integer type, there
doesn't seem to be a constant that specifies its range.
2024-11-14 22:27:18 +00:00
Ben Harris
4254bff53a Generate stem hints
These are generated from the glyph bitmap by a similar
pattern-matching arrangement that generates the outline.  Then, like
emit_path(), there's an emit_hints() that turns them into valid
charstrings.  The handling of overlapping hints could be cleverer: at
the moment we emit the leftmost-possible set of hints, but we collect
a histogram of where hints are needed so could instead emit the most
useful.  Or even try to do hint substitution.

This makes the Bedstead Web page at 90% zoom much prettier than
before, but it's not as good as the FontForge auto-hinter managed.
Edge hints and counter hints will probably help.
2024-11-14 22:27:18 +00:00
Ben Harris
e572e11b12 Use my own, officially assigned, achVendID
The assignment is recorded at
<https://learn.microsoft.com/en-gb/typography/vendors/>.

This branch is destined to be the next major version of Bedstead, so
it's a sensible place to make this change.
2024-11-14 22:27:18 +00:00
Ben Harris
259b718c9f Constants for 'OS/2' achVendID and XLFD/BDF FOUNDRY 2024-11-14 22:27:18 +00:00
Ben Harris
eb2175ef3f Have a defined constant for the family name "Bedstead"
All occurrences of the name in the OTF and BDF files are now derived
from that definition so that they can conveniently be changed together.
2024-11-14 22:27:18 +00:00
Ben Harris
b83edc5cc0 Very rough but apparently functional 'palt' support 2024-11-14 22:27:18 +00:00
Ben Harris
1055dd31f5 Change TTXI etc macros to take XML tag name as a string
Stringifying it from a C token may have been more compact, but it was
also quite confusing because those really weren't C identifiers and
everywhere else XML appears in strings.
2024-11-14 22:27:18 +00:00
Ben Harris
f7094e7c75 Skeleton of GPOS support 2024-11-14 22:27:18 +00:00
Ben Harris
27f54ed926 Put single substitutions in the GSUB table 2024-11-14 22:27:18 +00:00
Ben Harris
774c06ba3b 'aalt' feature implemented via TTX 2024-11-14 22:27:18 +00:00
Ben Harris
f919dbc7ae Beginnings of 'GSUB' generation: a table of the lookups we need
This is now used to generate the 'name' entries for stylistic sets.
2024-11-14 22:27:18 +00:00
Ben Harris
64f55f1f87 Clean up trailing whitespace in bedstead.c 2024-11-14 22:27:18 +00:00
Ben Harris
7b9dc784ee Record proper left sidebearings in 'hmtx' table
That change was more invasive than I was expecting.
2024-11-14 22:27:18 +00:00
Ben Harris
71addbd605 Move function declarations after structure declarations 2024-11-14 22:27:18 +00:00
Ben Harris
29fe1642cb Update comment on compare_glyphs_by_ffid()
It's not necessary any more, but it does seem to make the output file
smaller so it can stay for now.
2024-11-14 22:27:18 +00:00
Ben Harris
1a878099e3 Note that TTX overrides hhea.numberOfHMetrics 2024-11-14 22:27:18 +00:00
Ben Harris
bf07043b37 Adjust indentation of CFF XML
It's not perfect, but it's prettier.
2024-11-14 22:27:18 +00:00
Ben Harris
568f347469 Remove extraglyphs variable that's no longer needed 2024-11-14 22:27:18 +00:00
Ben Harris
061c83e8c8 Don't emit unnecessary CFF DICT entries
In several cases, Bedstead uses the defaults, so there's no need to
mention them.
2024-11-14 22:27:18 +00:00
Ben Harris
627870cfbf Remove newlines from charstrings in TTX output
This does make the file rather wide, but I think it also makes it
easier to find what you're looking for.
2024-11-14 22:27:18 +00:00
Ben Harris
59667dea04 Create a subroutine for each aliased glyph
So both the original name and any aliases can then call the subroutine
instead.
2024-11-14 22:27:18 +00:00
Ben Harris
492cea7bf1 Correct charstring stack accounting in emit_contour()
The first point doesn't count because it gets an rmoveto rather than an
rlineto.
2024-11-14 22:27:18 +00:00
Ben Harris
36a99e6005 Make aliases work again, inefficiently
This pulls the conditional that works out how to render a glyph into
it's own function, doglyph(), that also handles indirecting through
aliases.  Later maybe we'll properly use subroutines to share the
charstrings for aliased glyphs.
2024-11-14 22:27:18 +00:00
Ben Harris
82447229df Put the charstring cursor in a local variable 2024-11-14 22:27:18 +00:00
Ben Harris
e3eae733ee Combine successive rlineto operators
In a Type 2 charstring, an rlineto operator can take up to 24 pairs of
co-ordinates, so most contours need only one rmoveto and one rlineto.
2024-11-14 22:27:18 +00:00
Ben Harris
6f2fcc8799 Don't emit first point of a contour twice
Type 2 charstrings implicitly close each contour with a line, so there's
no need for us to explicitly do so.
2024-11-14 22:27:18 +00:00
Ben Harris
abb8dbbf27 Emit 'CFF ' and 'hmtx' tables for TTX (mostly)
The left sidebearings in 'hmtx' are not set yet, and there are (of
course) no hints, but the glyphs are the right shapes.
2024-11-14 22:27:18 +00:00
Ben Harris
932722f07d cmap fixup 2024-11-14 22:27:18 +00:00
Ben Harris
f1423c7124 Generate 'post' table for TTX 2024-11-14 22:27:18 +00:00
Ben Harris
b0cbe870b3 Generate 'cmap' table for TTX
TTX currently refuses to compile it, but I suspect that's because the
font still has no glyphs.
2024-11-14 22:27:18 +00:00
Ben Harris
75ad9bc479 Generate 'name' table for TTX 2024-11-14 22:27:18 +00:00
Ben Harris
030d9c36f9 Macros for the common TTX pattern <foo value='bar'/>
That makes things a little less verbose.
2024-11-14 22:27:18 +00:00
Ben Harris
d4d2223429 Generate 'OS/2' table for TTX 2024-11-14 22:27:18 +00:00
Ben Harris
29b33c20af Use constants for ascent, descent, etc
This way there won't be quite so many magic numbers in the font metrics.
2024-11-14 22:27:18 +00:00
Ben Harris
c354f9c3ac Generate 'maxp' table for TTX 2024-11-14 22:27:18 +00:00
Ben Harris
4e5727d371 Generate 'hhea' table for TTX 2024-11-14 22:27:18 +00:00
Ben Harris
9899c0e4a6 Generate 'head' table for TTX 2024-11-14 22:27:18 +00:00
Ben Harris
39d226c820 Minimal infrastructure for going via TTX rather than SFD
bedstead.c outputs an utterly minimal TTX file containing no tables, and
TTX compiles it into a similarly minimal OTF.  Which Ghostscript then
complains about.

FontForge is an impressive application, but it's not well-suited to
being part of a mechanical font-production pipeline.  The SFD format is
weird and rather difficult to generate, and FontForge imposes rather
more of its own opinions on the output than I'd like.

TTX is a lower-level format, and while it's a little bit weird, most of
it's weirdness comes from being a faithful representation of the
structure of an OpenType font.  Ideally I'd like something a little
higher-level, but a format that's too low-level is much easier to work
with than one that's too high-level.  The obvious alternative is UFO,
which is very popular but looks like being a pain to generate from plain
C.

Looking to the future, I like the idea of a variable version of
Bedstead, and neither SFD nor UFO seems to support that very well.  In
UFO's case, it seems that the convention is to create UFOs at various
points in the design space and then have a tool interpolate between
them, which seems wrong when they're all procedurally generated from the
same source.  TTX will allow me to directly generate the variation
tables, if I can understand how they work.
2024-11-14 22:27:18 +00:00
Ben Harris
90bc582e16 Add DEFAULT_CHAR to BDF
Also sort properties into the order they appear in the XLFD spec.
2024-11-10 09:30:35 +00:00
Ben Harris
1fd2576cfa Correct weight and width names in BDF
They shouldn't have leading spaces.
2024-11-10 09:30:35 +00:00
Ben Harris
9c6e156d80 Add FACE_NAME property to BDF 2024-11-10 09:30:35 +00:00
Ben Harris
305d15129d Add FONT_VERSION property to BDF 2024-11-10 09:30:35 +00:00
Ben Harris
ca7fa3a80d Add support for choosing font size and weight in BDF generation 2024-11-10 09:30:32 +00:00
Ben Harris
4c81bfa249 More BDF properties and a proper XLFD name 2024-11-10 09:29:36 +00:00