oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1package fonts
2
3import (
4 "testing"
5
6 "amadan.net/oficina/estilo.git/typeface"
7)
8
9// A slide picture carries an uploaded face as a web subset (final
10// review, I2): a font a browser's sanitiser takes, mapping the drawn
11// characters to the same glyphs as the whole face, called by the deck's
12// name, and small.
13func TestAWebSubsetIsAFontOfTheDrawnGlyphs(t *testing.T) {
14 orig := serifRegular(t)
15 const text = "Café ÿ — ok"
16 b, err := orig.WebSubset(text, "Test Upload", 700, true)
17 if err != nil {
18 t.Fatal(err)
19 }
20 sub, err := Parse(b)
21 if err != nil {
22 t.Fatalf("the subset does not parse: %v", err)
23 }
24 for _, r := range text {
25 if got, want := sub.GlyphIndex(r), orig.GlyphIndex(r); got != want {
26 t.Errorf("%q maps to glyph %d, the face's is %d", r, got, want)
27 }
28 }
29 if sub.GlyphIndex('Z') != 0 {
30 t.Error("a character not drawn is mapped")
31 }
32 face, err := typeface.Inspect(b)
33 if err != nil {
34 t.Fatalf("typeface.Inspect refuses the subset: %v", err)
35 }
36 if face.Family != "Test Upload" || face.Weight != 700 || !face.Italic {
37 t.Errorf("the subset is %q %d italic %v", face.Family, face.Weight, face.Italic)
38 }
39 if len(b) > len(orig.data)/4 {
40 t.Errorf("the subset of %d characters is %d bytes of a %d-byte face", len([]rune(text)), len(b), len(orig.data))
41 }
42}
43