oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1package svg
2
3import (
4 "bytes"
5 "strings"
6 "testing"
7
8 "amadan.net/oficina/slides/internal/slides/fonts"
9 "amadan.net/oficina/slides/internal/slides/layout"
10)
11
12// With EmbedFonts, a picture carries each uploaded face it draws in as
13// an @font-face of its own (final review, I2); without it, and for the
14// built-in faces, it carries none.
15func TestAPictureCarriesTheUploadedFacesItDraws(t *testing.T) {
16 f, err := fonts.Parse(fonts.Data(fonts.Face{Family: fonts.Serif}))
17 if err != nil {
18 t.Fatal(err)
19 }
20 up := fonts.UploadedFamily(&fonts.Uploaded{CSS: "Test Upload", Weight: 400, Font: f, Fallback: "serif"})
21 p := layout.Paint{W: 100, H: 50, Ops: []layout.Op{layout.Text{X: 1, Y: 20, Runs: []layout.Run{
22 {S: "upload", Size: 10, Face: fonts.Face{Family: fonts.Sans, Uploaded: up}},
23 {S: " built in", Size: 10, Face: fonts.Face{Family: fonts.Sans}},
24 {S: " again", Size: 10, Face: fonts.Face{Family: fonts.Sans, Uploaded: up}},
25 }}}}
26 with := Encode(p, Options{EmbedFonts: true})
27 if n := bytes.Count(with, []byte("@font-face")); n != 1 {
28 t.Fatalf("%d @font-face rules, want one for the one uploaded face:\n%s", n, with[:min(len(with), 600)])
29 }
30 if !bytes.Contains(with, []byte(`@font-face{font-family:'Test Upload';src:url(data:font/ttf;base64,`)) ||
31 !bytes.Contains(with, []byte(`font-weight:400;font-style:normal}`)) {
32 t.Errorf("the rule is not the upload's: %s", with[:min(len(with), 400)])
33 }
34 if !strings.Contains(string(with), "<defs>\n<style>") {
35 t.Error("the rule is not in the picture's own <style>")
36 }
37 if without := Encode(p, Options{}); bytes.Contains(without, []byte("@font-face")) {
38 t.Error("a picture without EmbedFonts carries a face")
39 }
40}
41