918 Commits

Author SHA1 Message Date
Ben Harris
b74582bccc More-or-less functional edge hints
This gets me to the milestone where the new version isn't uniformly
worse than the old one when rendered by FreeType at 10.5 ppem (the
worst size I've found).

The big problem I still have is that letters with three horizontal
stems (like 'B') get their middle stem rounded down in this version
and up in 002.009.  I think this is because FontForge generates and
edge hint and not a stem hint at the bottom of the character, which
also makes bottom stems rather fuzzy.  This version gives sharper
stems, but the characters all end up looking top-heavy.
2024-11-17 14:03:47 +00:00
Ben Harris
347dcfd579 Support for edge hints in select_hints()
Which demonstrated plenty of bugs in the code generating them.
Currently edge hints only appear in a helpful comment.
2024-11-17 13:43:08 +00:00
Ben Harris
15b8a9a584 Process pixels in raster order
If we're imitating a CRT character generator, obviously we should
process pixels line-by-line, not column-by-column.  But that means
writing "for (y ...)" before "for (x ...)" which isn't the instinctive
way I did it.

So now that's corrected and the Y loops are outside the X loops, which
should make any debugging output easier to follow.  This has been
confirmed not to change FreeType rendering at 10.5 ppem.
2024-11-17 10:11:23 +00:00
Ben Harris
86f186342a Reverse (almost) all the paths
Type 1 fonts (and by extension CFF fonts) are required to have their
outer contours go counter-clockwise.  Bedstead has always generated
outlines clockwise and depended on FontForge to correct them.  Now
they're generated counter-clockwise as is proper, which will be fine
until I decide I want TrueType outlines instead.

This makes no difference to FreeType's rendering at either 20 ppem or
10.5 ppem
2024-11-17 09:36:54 +00:00
Ben Harris
f234538428 Switch hhints loop in emit_hints() so it counts forwards
Now that it only touches the input array once, it's much simpler to do
the y-axis inversion there.
2024-11-16 23:39:30 +00:00
Ben Harris
1ad04e13fa Some infrastructure towards edge hints
There are places to record them now, but they're ignored by
select_hints() and emit_hints().
2024-11-16 23:33:30 +00:00
Ben Harris
30d226f30f Separate selecting usable hints from emitting them
Now there's a select_hints() function that decides what hints should
be emitted, and emit_hints() just handles putting those hints into a
charstring.  I hope this will make each function reasonably simple.
Importantly, it means that select_hints() can be called twice, once
for horizontal stems and once for vertical ones.
2024-11-16 18:58:41 +00:00
Ben Harris
1459c8cf93 Change version number so pre-release fonts are distinguishable 2024-11-16 14:41:43 +00:00
Ben Harris
891129f1f4 Correct baseline of BDF fonts 2024-11-16 14:40:47 +00:00
Ben Harris
be223879a1 Pass --no-recalc-timestamp to TTX
Without that, it updates the "modified" field in the 'head' table,
which makes builds unreproducible.
2024-11-16 11:53:04 +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
62d562879a Update Web page for new generation procedure 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
650103b465 Extract version number from C file, not nonexistent SFD 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
59a535c335 Ignore stem hints in editor
Though it would be neat if it could display them.
2024-11-14 23:31:36 +00:00
Ben Harris
c93160c507 Add .DELETE_ON_ERROR target to Makefile
That ensures that output files of a rule get properly deleted if the
recipe fails, which is almost always correct.
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
8b6bfa5298 Update editor to read Type 2 charstrings (in source form)
Now the editor displays something useful again.
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