Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a font's example text #12

Merged
merged 6 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/fondue/Fondue.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,14 @@ export default class Fondue {
}
return null;
}

get customText() {
// Currently Font.js returns null bytes in name table strings,
// we filter them here.
// https://github.com/Pomax/Font.js/issues/74
return (
/* eslint-disable no-control-regex */
this._font.opentype.tables.name.get(19).replace(/\x00/g, "") || null
);
}
}
27 changes: 17 additions & 10 deletions test/Fondue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const otfFont = async () => {
);
};

const ttfFont = async () => {
return await loadFondue("./test/fixtures/letterA/letterA.ttf");
const WFTestFont = async () => {
return await loadFondue("./test/fixtures/WFTestFont/WFTestFont.ttf");
};

const variableFont = async () => {
Expand Down Expand Up @@ -75,7 +75,7 @@ describe("format", () => {
});

test("TTF font", async () => {
const fondue = await ttfFont();
const fondue = await WFTestFont();
expect(fondue.format).toBe("TrueType");
});
});
Expand All @@ -87,7 +87,7 @@ describe("isVariable", () => {
});

test("nonvariable font", async () => {
const fondue = await ttfFont();
const fondue = await WFTestFont();
expect(fondue.isVariable).toBe(false);
});
});
Expand All @@ -99,7 +99,7 @@ describe("isColor", () => {
});

test("non color font", async () => {
const fondue = await ttfFont();
const fondue = await WFTestFont();
expect(fondue.isColor).toBe(false);
});
});
Expand All @@ -111,7 +111,7 @@ describe("hasColorTable", () => {
});

test("non color font", async () => {
const fondue = await ttfFont();
const fondue = await WFTestFont();
expect(fondue.colorFormats).toStrictEqual([]);
});
});
Expand All @@ -138,7 +138,7 @@ describe("hasAxes", () => {
});

test("nonvariable font", async () => {
const fondue = await ttfFont();
const fondue = await WFTestFont();
expect(fondue.variable).toBeUndefined();
});
});
Expand All @@ -150,21 +150,21 @@ describe("hasFeatures", () => {
});

test("has no layout features", async () => {
const fondue = await ttfFont();
const fondue = await WFTestFont();
expect(fondue.features).toEqual([]);
});
});

describe("supportedCharacters", () => {
test("returns characters of best cmap", async () => {
const fondue = await ttfFont();
const fondue = await WFTestFont();
expect(fondue.supportedCharacters).toEqual(
expect.arrayContaining(["41"]) // 0x41 = letter Z
);
});

test("does not return non-unicode char", async () => {
const fondue = await ttfFont();
const fondue = await WFTestFont();
expect(fondue.supportedCharacters).not.toEqual(
expect.arrayContaining(["ffff"]) // 0x41 = letter Z
);
Expand All @@ -181,3 +181,10 @@ describe("supportedLanguages", () => {
);
});
});

describe("nameTable", () => {
test("return sample text", async () => {
const fondue = await WFTestFont();
expect(fondue.customText).toContain("Wakamai Fondue rules!");
});
});
23 changes: 23 additions & 0 deletions test/fixtures/WFTestFont/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# WFTestFont

A versatile test font for Wakamai Fondue, created by Roel Nieskens.

Make changes in the .ttx file, [compile](https://github.com/fonttools/fonttools) to .ttf so it can be used in Wakamai Fondue's tests:

```bash
$ ttx -o WFTestFont.ttf WFTestFont.ttx
```

## What can this font do?

- It has TrueType outlines (`glyf`)
- It has a `.notdef` character
- It has an `A` character
- Name table entries:
Font Family: WFTest
Font Subfamily: Regular
Unique Font Identifier: WFTest
Font Name: WFTest
Version String: Version 1.0
PostScript Name: WFTest
Sample text: Wakamai Fondue rules!
Binary file added test/fixtures/WFTestFont/WFTestFont.ttf
Binary file not shown.
204 changes: 204 additions & 0 deletions test/fixtures/WFTestFont/WFTestFont.ttx
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.12">

<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="A"/>
</GlyphOrder>

<head>
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="1.0"/>
<fontRevision value="1.0"/>
<checkSumAdjustment value="0xc8ef8923"/>
<magicNumber value="0x5f0f3cf5"/>
<flags value="00000000 00001011"/>
<unitsPerEm value="512"/>
<created value="Wed Aug 26 09:42:14 2020"/>
<modified value="Wed Aug 26 09:48:41 2020"/>
<xMin value="0"/>
<yMin value="0"/>
<xMax value="512"/>
<yMax value="512"/>
<macStyle value="00000000 00000000"/>
<lowestRecPPEM value="8"/>
<fontDirectionHint value="2"/>
<indexToLocFormat value="0"/>
<glyphDataFormat value="0"/>
</head>

<hhea>
<tableVersion value="0x00010000"/>
<ascent value="512"/>
<descent value="0"/>
<lineGap value="0"/>
<advanceWidthMax value="512"/>
<minLeftSideBearing value="0"/>
<minRightSideBearing value="0"/>
<xMaxExtent value="512"/>
<caretSlopeRise value="1"/>
<caretSlopeRun value="0"/>
<caretOffset value="0"/>
<reserved0 value="0"/>
<reserved1 value="0"/>
<reserved2 value="0"/>
<reserved3 value="0"/>
<metricDataFormat value="0"/>
<numberOfHMetrics value="1"/>
</hhea>

<maxp>
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="0x10000"/>
<numGlyphs value="2"/>
<maxPoints value="4"/>
<maxContours value="1"/>
<maxCompositePoints value="0"/>
<maxCompositeContours value="0"/>
<maxZones value="2"/>
<maxTwilightPoints value="0"/>
<maxStorage value="0"/>
<maxFunctionDefs value="0"/>
<maxInstructionDefs value="0"/>
<maxStackElements value="0"/>
<maxSizeOfInstructions value="0"/>
<maxComponentElements value="0"/>
<maxComponentDepth value="0"/>
</maxp>

<OS_2>
<!-- The fields 'usFirstCharIndex' and 'usLastCharIndex'
will be recalculated by the compiler -->
<version value="3"/>
<xAvgCharWidth value="512"/>
<usWeightClass value="400"/>
<usWidthClass value="5"/>
<fsType value="00000000 00000000"/>
<ySubscriptXSize value="332"/>
<ySubscriptYSize value="358"/>
<ySubscriptXOffset value="0"/>
<ySubscriptYOffset value="71"/>
<ySuperscriptXSize value="332"/>
<ySuperscriptYSize value="358"/>
<ySuperscriptXOffset value="0"/>
<ySuperscriptYOffset value="245"/>
<yStrikeoutSize value="25"/>
<yStrikeoutPosition value="132"/>
<sFamilyClass value="0"/>
<panose>
<bFamilyType value="0"/>
<bSerifStyle value="0"/>
<bWeight value="0"/>
<bProportion value="0"/>
<bContrast value="0"/>
<bStrokeVariation value="0"/>
<bArmStyle value="0"/>
<bLetterForm value="0"/>
<bMidline value="0"/>
<bXHeight value="0"/>
</panose>
<ulUnicodeRange1 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange2 value="00010000 00000000 00000000 00000000"/>
<ulUnicodeRange3 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange4 value="00000000 00000000 00000000 00000000"/>
<achVendID value="\x00\x00\x00\x00"/>
<fsSelection value="00000000 01000000"/>
<usFirstCharIndex value="65"/>
<usLastCharIndex value="65"/>
<sTypoAscender value="512"/>
<sTypoDescender value="0"/>
<sTypoLineGap value="0"/>
<usWinAscent value="512"/>
<usWinDescent value="0"/>
<ulCodePageRange1 value="00000000 00000000 00000000 00000001"/>
<ulCodePageRange2 value="00000000 00000000 00000000 00000000"/>
<sxHeight value="0"/>
<sCapHeight value="0"/>
<usDefaultChar value="0"/>
<usBreakChar value="32"/>
<usMaxContext value="0"/>
</OS_2>

<hmtx>
<mtx name=".notdef" width="512" lsb="0"/>
<mtx name="A" width="512" lsb="0"/>
</hmtx>

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
<map code="0x41" name="A"/><!-- LATIN CAPITAL LETTER A -->
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0x41" name="A"/><!-- LATIN CAPITAL LETTER A -->
</cmap_format_4>
</cmap>

<loca>
<!-- The 'loca' table will be calculated by the compiler -->
</loca>

<glyf>

<!-- The xMin, yMin, xMax and yMax values
will be recalculated by the compiler. -->

<TTGlyph name=".notdef"/><!-- contains no outline data -->

<TTGlyph name="A" xMin="0" yMin="0" xMax="512" yMax="512">
<contour>
<pt x="0" y="512" on="1"/>
<pt x="512" y="512" on="1"/>
<pt x="512" y="0" on="1"/>
<pt x="0" y="0" on="1"/>
</contour>
<instructions/>
</TTGlyph>

</glyf>

<name>
<namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
WFTestFont
</namerecord>
<namerecord nameID="2" platformID="3" platEncID="1" langID="0x409">
Regular
</namerecord>
<namerecord nameID="3" platformID="3" platEncID="1" langID="0x409">
WFTestFont
</namerecord>
<namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
WFTestFont
</namerecord>
<namerecord nameID="5" platformID="3" platEncID="1" langID="0x409">
Version 1.0
</namerecord>
<namerecord nameID="6" platformID="3" platEncID="1" langID="0x409">
WFTestFont
</namerecord>
<namerecord nameID="6" platformID="3" platEncID="1" langID="0x409">
WFTestFont
</namerecord>
<namerecord nameID="19" platformID="3" platEncID="1" langID="0x409">
Wakamai Fondue rules!
</namerecord>
</name>

<post>
<formatType value="3.0"/>
<italicAngle value="0.0"/>
<underlinePosition value="0"/>
<underlineThickness value="0"/>
<isFixedPitch value="0"/>
<minMemType42 value="0"/>
<maxMemType42 value="0"/>
<minMemType1 value="0"/>
<maxMemType1 value="0"/>
</post>

<gasp>
<gaspRange rangeMaxPPEM="65535" rangeGaspBehavior="15"/>
</gasp>

</ttFont>
Binary file removed test/fixtures/letterA/letterA.ttf
Binary file not shown.