LibGfx/OpenType: Add named constants for header tags
...together with spec comments. No behavior change.
This commit is contained in:
parent
36bbf12b73
commit
41e0a0f0aa
Notes:
sideshowbarker
2024-07-17 07:06:47 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/41e0a0f0aa Pull-request: https://github.com/SerenityOS/serenity/pull/23385
2 changed files with 16 additions and 3 deletions
|
@ -165,7 +165,7 @@ static ErrorOr<Tag> read_tag(ReadonlyBytes buffer)
|
|||
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(ReadonlyBytes buffer, Options options)
|
||||
{
|
||||
auto tag = TRY(read_tag(buffer));
|
||||
if (tag == Tag("ttcf")) {
|
||||
if (tag == HeaderTag_FontCollection) {
|
||||
// It's a font collection
|
||||
FixedMemoryStream stream { buffer };
|
||||
auto ttc_header_v1 = TRY(stream.read_in_place<TTCHeaderV1>());
|
||||
|
@ -178,10 +178,10 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(Readonl
|
|||
auto offset = TRY(stream.read_value<BigEndian<u32>>());
|
||||
return try_load_from_offset(buffer, offset, move(options));
|
||||
}
|
||||
if (tag == Tag("OTTO"))
|
||||
if (tag == HeaderTag_CFFOutlines)
|
||||
return Error::from_string_literal("CFF fonts not supported yet");
|
||||
|
||||
if (tag.to_u32() != 0x00010000 && tag != Tag("true"))
|
||||
if (tag != HeaderTag_TrueTypeOutlines && tag != HeaderTag_TrueTypeOutlinesApple)
|
||||
return Error::from_string_literal("Not a valid font");
|
||||
|
||||
return try_load_from_offset(buffer, 0, move(options));
|
||||
|
|
|
@ -72,6 +72,19 @@ public:
|
|||
Optional<ReadonlyBytes> control_value_program() const;
|
||||
Optional<ReadonlyBytes> glyph_program(u32 glyph_id) const;
|
||||
|
||||
// https://learn.microsoft.com/en-us/typography/opentype/spec/otff
|
||||
// "OpenType fonts that contain TrueType outlines should use the value of 0x00010000 for the sfntVersion.
|
||||
// OpenType fonts containing CFF data (version 1 or 2) should use 0x4F54544F ('OTTO', when re-interpreted as a Tag) for sfntVersion.
|
||||
// Note: The Apple specification for TrueType fonts allows for 'true' and 'typ1' for sfnt version.
|
||||
// These version tags should not be used for OpenType fonts."
|
||||
// "Font Collection ID string: 'ttcf' (used for fonts with CFF or CFF2 outlines as well as TrueType outlines)"
|
||||
// The old Apple TrueType spec said "Fonts with TrueType outlines produced for OS X or iOS only are encouraged to use 'true'",
|
||||
// so 'true' is somewhat common, especially in PDFs.
|
||||
static constexpr Tag HeaderTag_TrueTypeOutlines = Tag::from_u32(0x00010000);
|
||||
static constexpr Tag HeaderTag_TrueTypeOutlinesApple = Tag { "true" };
|
||||
static constexpr Tag HeaderTag_CFFOutlines = Tag { "OTTO" };
|
||||
static constexpr Tag HeaderTag_FontCollection = Tag { "ttcf" };
|
||||
|
||||
private:
|
||||
struct AscenderAndDescender {
|
||||
i16 ascender;
|
||||
|
|
Loading…
Add table
Reference in a new issue