Fonts: pictures and the PDF use uploaded TrueType faces
A deck stack whose first name is a family in meta.fontFiles is measured
and drawn in its faces marked for pictures, per weight (400/700) and
slope; a style with no such face, or a face that does not load, parse,
is variable or forbids embedding, falls back down the stack with no
warning. layout.New(d, Options{Fonts}) is one render: each face is read
and parsed once and dropped with it. The SVG names the uploaded family
first, then the fallback; the export hands the PDF module each face
renamed to that CSS name, since the module matches the name inside the
font. Font bytes are read from the object store at fontObjectKey(ref).
Existing decks render byte for byte as before (new SVG goldens written
by the old code).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 files changed,
+1,772
−25
AGENTS.md+6 −0internal/slides/export.go+22 −5internal/slides/export_fonts_test.go+242 −0internal/slides/exports.go+1 −0internal/slides/fonts/fonts.go+23 −12internal/slides/fonts/uploaded.go+306 −0internal/slides/fonts/uploaded_test.go+101 −0internal/slides/fontstore.go+56 −0internal/slides/layout/layout.go+153 −2internal/slides/layout/paint.go+5 −4internal/slides/layout/testdata/svg/fixture-blank.golden.svg+24 −0internal/slides/layout/testdata/svg/fixture-canvas-reflow.golden.svg+11 −0internal/slides/layout/testdata/svg/fixture-canvas.golden.svg+10 −0internal/slides/layout/testdata/svg/fixture-image-full.golden.svg+7 −0internal/slides/layout/testdata/svg/fixture-quote.golden.svg+8 −0internal/slides/layout/testdata/svg/fixture-section.golden.svg+7 −0internal/slides/layout/testdata/svg/fixture-title-body.golden.svg+18 −0internal/slides/layout/testdata/svg/fixture-title.golden.svg+7 −0internal/slides/layout/testdata/svg/fixture-two-column.golden.svg+14 −0internal/slides/layout/testdata/svg/listed-blank.golden.svg+24 −0internal/slides/layout/testdata/svg/listed-canvas-reflow.golden.svg+11 −0internal/slides/layout/testdata/svg/listed-canvas.golden.svg+10 −0internal/slides/layout/testdata/svg/listed-image-full.golden.svg+7 −0internal/slides/layout/testdata/svg/listed-quote.golden.svg+8 −0internal/slides/layout/testdata/svg/listed-section.golden.svg+7 −0internal/slides/layout/testdata/svg/listed-title-body.golden.svg+18 −0internal/slides/layout/testdata/svg/listed-title.golden.svg+7 −0internal/slides/layout/testdata/svg/listed-two-column.golden.svg+14 −0internal/slides/layout/testdata/svg/named-blank.golden.svg+24 −0internal/slides/layout/testdata/svg/named-canvas-reflow.golden.svg+11 −0internal/slides/layout/testdata/svg/named-canvas.golden.svg+10 −0internal/slides/layout/testdata/svg/named-image-full.golden.svg+7 −0internal/slides/layout/testdata/svg/named-quote.golden.svg+8 −0internal/slides/layout/testdata/svg/named-section.golden.svg+7 −0internal/slides/layout/testdata/svg/named-title-body.golden.svg+18 −0internal/slides/layout/testdata/svg/named-title.golden.svg+7 −0internal/slides/layout/testdata/svg/named-two-column.golden.svg+13 −0internal/slides/layout/text.go+1 −0internal/slides/layout/unchanged_test.go+75 −0internal/slides/layout/uploaded_test.go+458 −0internal/slides/svg/svg.go+5 −1internal/slides/thumbs.go+1 −1
diff --git a/AGENTS.md b/AGENTS.md| index 89d96ea..b2f16f0 100644 |
| --- a/AGENTS.md |
| +++ b/AGENTS.md |
| @@ -158,6 +158,12 @@ seeded on first sign-in — and comes back out as a PDF. |
| `thumbs.go`): every slide measured into a paint list with the same |
| embedded Liberation faces the browser sets it in, written as an SVG, |
| and served as `{surface}/slides/{id}.svg` from all four capabilities. |
| + A deck stack that names an uploaded family first is set in its static |
| + TrueType faces (`meta.fontFiles` faces marked `pictures`), read from |
| + the object store (`fontstore.go`) and parsed once per render through |
| + `layout.New`; anything else falls back down the stack, and the export |
| + hands the PDF module those faces renamed to the deck's CSS name |
| + (`fonts.Renamed`), because the module matches the name inside a font. |
| The editor strip and the remote are that picture. The presenter |
| window is not: it draws live slides (see the last section); only |
| sessions begun before positions keep the pictures. |
diff --git a/internal/slides/export.go b/internal/slides/export.go| index 413ebda..18a5144 100644 |
| --- a/internal/slides/export.go |
| +++ b/internal/slides/export.go |
| @@ -6,10 +6,12 @@ |
| // nothing here shortcuts it: layout.Layout draws each slide into a |
| // paint list, svg.Encode writes that paint list as an SVG, and the Rust |
| // module under internal/slides/pdfcore turns the SVGs into a PDF with |
| -// the text as glyphs from the same Liberation faces the layout engine |
| -// measured with. The PDF path never reads a deck; a notes page is a |
| -// paint list too, built here from the notes text and typeset with the |
| -// same fonts package, so it goes through the same two steps. |
| +// the text as glyphs from the same faces the layout engine measured |
| +// with: the Liberation set, and any static TrueType face uploaded to |
| +// the deck that its stacks name first. The PDF path never reads a |
| +// deck; a notes page is a paint list too, built here from the notes |
| +// text and typeset with the same fonts package, so it goes through the |
| +// same two steps. |
| // |
| // # Self-contained |
| // |
| @@ -117,6 +119,12 @@ type ExportOptions struct { |
| // words are the caller's: they are a person's words, and this |
| // package has no locale. |
| Progress func(slide, total int) |
| + |
| + // Fonts reads a face uploaded to the deck by its ref |
| + // (deck.FontFace.Ref) — the app's object store, as Assets is. Nil |
| + // reads none: every uploaded family falls back to the rest of its |
| + // stack, in the pages and the PDF alike (layout.Options.Fonts). |
| + Fonts func(ref string) ([]byte, error) |
| } |
| // Export renders d as a PDF. The warnings are everything worth telling |
| @@ -140,6 +148,9 @@ func Export(ctx context.Context, d *deck.Deck, o ExportOptions) ([]byte, []layou |
| } |
| x := &exporter{deck: d, opts: o} |
| + // One render for every page: each uploaded face is read and parsed |
| + // once for the whole export, and dropped with it. |
| + lay := layout.New(d, layout.Options{Fonts: o.Fonts}) |
| var pages [][]byte |
| for i := range d.Slides { |
| if err := ctx.Err(); err != nil { |
| @@ -152,7 +163,7 @@ func Export(ctx context.Context, d *deck.Deck, o ExportOptions) ([]byte, []layou |
| if o.Progress != nil { |
| o.Progress(i+1, len(d.Slides)) |
| } |
| - p, warnings, err := layout.Layout(d, i) |
| + p, warnings, err := lay.Layout(i) |
| if err != nil { |
| return nil, x.warnings, fmt.Errorf("slides: export: slide %d: %w", i+1, err) |
| } |
| @@ -173,6 +184,12 @@ func Export(ctx context.Context, d *deck.Deck, o ExportOptions) ([]byte, []layou |
| for _, f := range fonts.All() { |
| faces = append(faces, fonts.Data(f)) |
| } |
| + // The uploaded faces the pages were set in, each renamed to the |
| + // family the pages' SVG names it by: the module matches a |
| + // font-family against the name inside the font (fonts.Renamed). |
| + for _, u := range lay.Uploaded() { |
| + faces = append(faces, u.Font.Renamed(u.CSS, u.Weight, u.Italic)) |
| + } |
| pdf, err := o.Runtime.Render(ctx, pages, faces) |
| if err != nil { |
| return nil, x.warnings, fmt.Errorf("slides: export: %w", err) |
diff --git a/internal/slides/export_fonts_test.go b/internal/slides/export_fonts_test.go| new file mode 100644 |
| index 0000000..cbb1cb2 |
| --- /dev/null |
| +++ b/internal/slides/export_fonts_test.go |
| @@ -0,0 +1,242 @@ |
| +package slides |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "encoding/binary" |
| + "errors" |
| + "io" |
| + "os" |
| + "path/filepath" |
| + "regexp" |
| + "sort" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/slides/internal/slides/deck" |
| + "amadan.net/oficina/slides/internal/slides/layout" |
| + "amadan.net/oficina/slides/internal/slides/svg" |
| + |
| + "amadan.net/rastrillo/rastrillo/blobs" |
| +) |
| + |
| +// The "uploaded" font here is Liberation Serif (SIL OFL) under another |
| +// CSS name, in a theme set entirely in Liberation Sans: a PDF that |
| +// carries a Liberation Serif subset got it from the upload. |
| +const ( |
| + uploadedCSS = "Test Upload" |
| + uploadedRef = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" |
| +) |
| + |
| +func embeddedFont(t *testing.T, name string) []byte { |
| + t.Helper() |
| + b, err := os.ReadFile(filepath.Join("fonts", "files", name)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return b |
| +} |
| + |
| +func uploadedDeck(face deck.FontFace) *deck.Deck { |
| + stack := "'" + uploadedCSS + "', Liberation Sans, sans-serif" |
| + return &deck.Deck{ |
| + Meta: deck.Meta{ |
| + Title: "Uploads", Theme: "ink", Aspect: "16:9", |
| + Fonts: &deck.Fonts{Heading: "Liberation Sans", Body: stack}, |
| + FontFiles: []deck.FontFamily{{Family: "Test Upload family", CSS: uploadedCSS, Faces: []deck.FontFace{face}}}, |
| + }, |
| + Slides: []deck.Slide{{ |
| + ID: "s1", Layout: "flow", Template: "title-body", |
| + Blocks: []deck.Block{ |
| + {ID: "h1", Type: "heading", Region: "heading", |
| + Props: map[string]any{"level": float64(1)}, Text: deck.Text{{{T: "Heading"}}}}, |
| + {ID: "t1", Type: "text", Region: "body", |
| + Text: deck.Text{{{T: "Quietly drawn in the upload"}}}}, |
| + }, |
| + }}, |
| + } |
| +} |
| + |
| +func fontsFrom(files map[string][]byte) func(string) ([]byte, error) { |
| + return func(ref string) ([]byte, error) { |
| + if b, ok := files[ref]; ok { |
| + return b, nil |
| + } |
| + return nil, errors.New("no such font") |
| + } |
| +} |
| + |
| +var serifSubset = regexp.MustCompile(`/BaseFont ?/[A-Z]{6}\+LiberationSerif\b`) |
| + |
| +func exportWith(t *testing.T, d *deck.Deck, load func(string) ([]byte, error)) ([]byte, []layout.Warning) { |
| + t.Helper() |
| + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) |
| + defer cancel() |
| + pdf, warnings, err := Export(ctx, d, exportOpts(t, ExportOptions{Fonts: load})) |
| + if err != nil { |
| + t.Fatalf("Export: %v", err) |
| + } |
| + return pdf, warnings |
| +} |
| + |
| +func TestTheExportEmbedsAnUploadedFace(t *testing.T) { |
| + face := deck.FontFace{Ref: uploadedRef, Format: "ttf", Weight: [2]int{400, 400}, Pictures: true} |
| + d := uploadedDeck(face) |
| + |
| + // Without the bytes the body falls back to Liberation Sans, and |
| + // there is no serif in the PDF: the control for what follows. |
| + pdf, _ := exportWith(t, d, nil) |
| + if serifSubset.Match(pdf) { |
| + t.Fatal("a Liberation Serif subset in a deck that never draws in it") |
| + } |
| + |
| + pdf, warnings := exportWith(t, d, fontsFrom(map[string][]byte{uploadedRef: embeddedFont(t, "LiberationSerif-Regular.ttf")})) |
| + for _, w := range warnings { |
| + if w.Kind == layout.WarnFont { |
| + t.Errorf("a font warning for an uploaded family: %s", w.Detail) |
| + } |
| + } |
| + if !bytes.Contains(pdf, []byte("/FontFile2")) { |
| + t.Error("no embedded TrueType program (/FontFile2)") |
| + } |
| + if !serifSubset.Match(pdf) { |
| + t.Error("the upload's PostScript name (LiberationSerif) is not a /BaseFont: the PDF drew the body in something else") |
| + } |
| + if text := strings.ReplaceAll(pdfText(t, pdf), " ", ""); !strings.Contains(text, "Quietlydrawnintheupload") { |
| + t.Errorf("the body's words are not in the PDF's text: %q", text) |
| + } |
| +} |
| + |
| +func TestAVariableFontFallsBackInPicturesAndPDF(t *testing.T) { |
| + serif := embeddedFont(t, "LiberationSerif-Regular.ttf") |
| + for name, c := range map[string]struct { |
| + face deck.FontFace |
| + data []byte |
| + }{ |
| + "marked": {deck.FontFace{Ref: uploadedRef, Format: "ttf", Weight: [2]int{100, 900}}, serif}, |
| + "marked for pictures by hand": {deck.FontFace{Ref: uploadedRef, Format: "ttf", Weight: [2]int{400, 400}, Pictures: true}, addTable(t, serif, "fvar", make([]byte, 16))}, |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + d := uploadedDeck(c.face) |
| + load := fontsFrom(map[string][]byte{uploadedRef: c.data}) |
| + |
| + // The picture. |
| + p, warnings, err := layout.New(d, layout.Options{Fonts: load}).Layout(0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, w := range warnings { |
| + if w.Kind == layout.WarnFont { |
| + t.Errorf("a font warning for an uploaded family: %s", w.Detail) |
| + } |
| + } |
| + if pic := svg.Encode(p, svg.Options{}); bytes.Contains(pic, []byte(uploadedCSS)) { |
| + t.Error("the picture names the variable upload") |
| + } |
| + |
| + // The PDF. |
| + pdf, _ := exportWith(t, d, load) |
| + if serifSubset.Match(pdf) { |
| + t.Error("the PDF embeds the variable upload") |
| + } |
| + if !regexp.MustCompile(`/BaseFont ?/[A-Z]{6}\+LiberationSans\b`).Match(pdf) { |
| + t.Error("the PDF does not draw the body in the fallback") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// fakeFontStore is a blobs.Store that answers Get for the keys it holds |
| +// and remembers what it was asked for. |
| +type fakeFontStore struct { |
| + held map[string][]byte |
| + asked []string |
| +} |
| + |
| +func (s *fakeFontStore) Put(context.Context, io.Reader, string) (blobs.Ref, error) { |
| + return blobs.Ref{}, errors.New("read only") |
| +} |
| + |
| +func (s *fakeFontStore) Get(_ context.Context, key string) (io.ReadCloser, error) { |
| + s.asked = append(s.asked, key) |
| + b, ok := s.held[key] |
| + if !ok { |
| + return nil, blobs.ErrNotFound |
| + } |
| + return io.NopCloser(bytes.NewReader(b)), nil |
| +} |
| + |
| +func (s *fakeFontStore) Delete(context.Context, string) error { return nil } |
| + |
| +func TestTheFontLoaderReadsTheObjectStore(t *testing.T) { |
| + ctx := context.Background() |
| + if got := fontObjectKey(uploadedRef); got != "fonts/"+uploadedRef { |
| + t.Errorf("fontObjectKey = %q", got) |
| + } |
| + |
| + // No store: every read is an error, and so everything falls back. |
| + if _, err := (&app{}).fontLoader(ctx)(uploadedRef); err == nil { |
| + t.Error("a read with no object store succeeded") |
| + } |
| + |
| + serif := embeddedFont(t, "LiberationSerif-Regular.ttf") |
| + store := &fakeFontStore{held: map[string][]byte{ |
| + fontObjectKey(uploadedRef): serif, |
| + fontObjectKey(strings.Repeat("d", 64)): make([]byte, maxFontFileBytes+1), |
| + }} |
| + a := &app{} |
| + a.cfg.Blobs = store |
| + load := a.fontLoader(ctx) |
| + if b, err := load(uploadedRef); err != nil || !bytes.Equal(b, serif) { |
| + t.Errorf("load = %d bytes, %v; want the stored face", len(b), err) |
| + } |
| + if _, err := load(strings.Repeat("d", 64)); err == nil { |
| + t.Error("a face over the size limit loaded") |
| + } |
| + for _, bad := range []string{"", "../x", "fonts/" + uploadedRef, strings.ToUpper(uploadedRef)} { |
| + if _, err := load(bad); err == nil { |
| + t.Errorf("ref %q loaded", bad) |
| + } |
| + } |
| + sort.Strings(store.asked) |
| + want := []string{fontObjectKey(uploadedRef), fontObjectKey(strings.Repeat("d", 64))} |
| + sort.Strings(want) |
| + if strings.Join(store.asked, " ") != strings.Join(want, " ") { |
| + t.Errorf("the store was asked for %q, want only %q", store.asked, want) |
| + } |
| +} |
| + |
| +// addTable is a TrueType file with one more table in it. |
| +func addTable(t *testing.T, data []byte, tag string, body []byte) []byte { |
| + t.Helper() |
| + n := int(binary.BigEndian.Uint16(data[4:])) |
| + type rec struct { |
| + tag string |
| + body []byte |
| + } |
| + var recs []rec |
| + for i := 0; i < n; i++ { |
| + at := 12 + i*16 |
| + off := binary.BigEndian.Uint32(data[at+8:]) |
| + length := binary.BigEndian.Uint32(data[at+12:]) |
| + recs = append(recs, rec{string(data[at : at+4]), data[off : off+length]}) |
| + } |
| + recs = append(recs, rec{tag, body}) |
| + sort.Slice(recs, func(i, j int) bool { return recs[i].tag < recs[j].tag }) |
| + head := make([]byte, 12+16*len(recs)) |
| + copy(head, data[:4]) |
| + binary.BigEndian.PutUint16(head[4:], uint16(len(recs))) |
| + var out []byte |
| + for i, r := range recs { |
| + at := 12 + i*16 |
| + copy(head[at:], r.tag) |
| + binary.BigEndian.PutUint32(head[at+8:], uint32(len(head)+len(out))) |
| + binary.BigEndian.PutUint32(head[at+12:], uint32(len(r.body))) |
| + out = append(out, r.body...) |
| + for len(out)%4 != 0 { |
| + out = append(out, 0) |
| + } |
| + } |
| + return append(head, out...) |
| +} |
diff --git a/internal/slides/exports.go b/internal/slides/exports.go| index 51f70c0..cd94951 100644 |
| --- a/internal/slides/exports.go |
| +++ b/internal/slides/exports.go |
| @@ -541,6 +541,7 @@ func (a *app) exportJob(id <-chan string, d Deck, actor string, withNotes bool, |
| WithNotes: withNotes, |
| Runtime: rt, |
| Assets: a.assetBytes(ctx, d, view), |
| + Fonts: a.fontLoader(ctx), |
| Progress: func(slide, of int) { |
| progress(fillWords(words.progress, "n", slide, "total", of)) |
| }, |
diff --git a/internal/slides/fonts/fonts.go b/internal/slides/fonts/fonts.go| index 9d387d3..2bb554d 100644 |
| --- a/internal/slides/fonts/fonts.go |
| +++ b/internal/slides/fonts/fonts.go |
| @@ -78,14 +78,20 @@ const ( |
| Code |
| ) |
| -// Face is one font program: a family and a weight/slope. Three fields |
| -// and no payload — the bytes come from Data and the metrics from |
| -// Metrics, so a Face is a value a caller can compare, put in a map key |
| -// and write into a golden file. |
| +// Face is one font program: a family and a weight/slope. No payload — |
| +// the bytes come from Data and the metrics from Metrics, so a Face is a |
| +// value a caller can compare, put in a map key and write into a golden |
| +// file. |
| +// |
| +// Uploaded, when set, is the deck's uploaded family the face is drawn |
| +// in where it has a face for Bold and Italic (Upload says which), with |
| +// Family as the fallback for the styles it lacks. Advance, Metrics and |
| +// Stack follow it; nil is a built-in face, exactly as before uploads. |
| type Face struct { |
| - Family Family |
| - Bold bool |
| - Italic bool |
| + Family Family |
| + Bold bool |
| + Italic bool |
| + Uploaded *Uploaded |
| } |
| // themeHeading is the heading family per theme, and it is the ONE fact |
| @@ -317,9 +323,14 @@ func init() { |
| } |
| } |
| -// Data is the face's font program. The slice is the embedded one and |
| -// callers must not write to it; every caller here reads. |
| -func Data(f Face) []byte { return data[f] } |
| +// Data is the built-in face's font program, whatever upload f also |
| +// names. The slice is the embedded one and callers must not write to |
| +// it; every caller here reads. |
| +func Data(f Face) []byte { return data[f.builtIn()] } |
| + |
| +// builtIn is f without its upload: the key its built-in face is held |
| +// under. |
| +func (f Face) builtIn() Face { return Face{Family: f.Family, Bold: f.Bold, Italic: f.Italic} } |
| // Metrics is the face's vertical extent at size, in the same units |
| // size is in (the layout engine works in px at a 1920-wide frame). |
| @@ -331,7 +342,7 @@ func Data(f Face) []byte { return data[f] } |
| // is what internal/slides/layout does, because the browser it has to |
| // agree with is following the stylesheet and not the font. |
| func Metrics(f Face, size float64) (asc, desc, lineHeight float64) { |
| - font, err := f.Parsed() |
| + font, err := f.font() |
| if err != nil { |
| // Unreachable while the twelve embedded faces parse, which |
| // init has effectively proved. A plausible fallback rather |
| @@ -363,7 +374,7 @@ func Advance(f Face, size float64, s string) (width float64, missing []rune) { |
| if s == "" { |
| return 0, nil |
| } |
| - font, err := f.Parsed() |
| + font, err := f.font() |
| if err != nil { |
| return 0, nil |
| } |
diff --git a/internal/slides/fonts/uploaded.go b/internal/slides/fonts/uploaded.go| new file mode 100644 |
| index 0000000..fd38c6c |
| --- /dev/null |
| +++ b/internal/slides/fonts/uploaded.go |
| @@ -0,0 +1,306 @@ |
| +package fonts |
| + |
| +import ( |
| + "encoding/binary" |
| + "sort" |
| + "strings" |
| + "unicode/utf16" |
| +) |
| + |
| +// uploaded.go is the one way a face outside this package's twelve |
| +// reaches the layout engine and the PDF: a static TrueType face a |
| +// person uploaded to a deck (meta.fontFiles), read and parsed for one |
| +// render and dropped with it. Nothing here caches one across renders — |
| +// the bytes are the person's, and they stay in the object store. |
| + |
| +// Uploaded is one uploaded face a picture can be drawn with: the CSS |
| +// family the deck names it by, the weight (400 or 700) and slope it is |
| +// set for, and the parsed font. |
| +type Uploaded struct { |
| + CSS string |
| + Weight int |
| + Italic bool |
| + Font *Font |
| + |
| + // family is the faces of the same upload by slot (see slot), shared |
| + // by all of them, so a face that turns bold or italic part-way |
| + // through a paragraph finds its sibling — or finds there is none, |
| + // and is drawn in the fallback. |
| + family *[4]*Uploaded |
| +} |
| + |
| +func slot(bold, italic bool) int { |
| + n := 0 |
| + if bold { |
| + n |= 2 |
| + } |
| + if italic { |
| + n |= 1 |
| + } |
| + return n |
| +} |
| + |
| +// UploadedFamily links the faces of one uploaded family (nil entries |
| +// are skipped) and returns one of them to put in Face.Uploaded, or nil |
| +// when there are none. Each face takes the slot its Weight and Italic |
| +// name; a second face for a slot already taken is ignored. |
| +func UploadedFamily(faces ...*Uploaded) *Uploaded { |
| + family := new([4]*Uploaded) |
| + var first *Uploaded |
| + for _, u := range faces { |
| + if u == nil { |
| + continue |
| + } |
| + i := slot(u.Weight == 700, u.Italic) |
| + if family[i] != nil { |
| + continue |
| + } |
| + family[i] = u |
| + u.family = family |
| + if first == nil { |
| + first = u |
| + } |
| + } |
| + return first |
| +} |
| + |
| +// Upload is the uploaded face f is drawn in, or nil when it is drawn |
| +// in its Family. f.Uploaded names the uploaded family; which of its |
| +// faces is wanted depends on f.Bold and f.Italic, which a caller sets |
| +// after choosing the family (a bold run, an italic quote), so the |
| +// choice is made here, every time, rather than once. |
| +func (f Face) Upload() *Uploaded { |
| + u := f.Uploaded |
| + if u == nil { |
| + return nil |
| + } |
| + if u.family != nil { |
| + return u.family[slot(f.Bold, f.Italic)] |
| + } |
| + if u.Weight == f.Weight() && u.Italic == f.Italic { |
| + return u |
| + } |
| + return nil |
| +} |
| + |
| +// Stack is the CSS font-family a picture writes for f: the uploaded |
| +// family first when f is drawn in one, then its Family's stack — so a |
| +// browser that has the uploaded font shows it, and one that does not |
| +// shows the face the text was measured with when it fell back. |
| +func (f Face) Stack() string { |
| + if u := f.Upload(); u != nil { |
| + return "'" + u.CSS + "', " + f.Family.Stack() |
| + } |
| + return f.Family.Stack() |
| +} |
| + |
| +// Name is how a paint list writes f: the PostScript name of a built-in |
| +// face, or the uploaded family's CSS name with its weight and slope. |
| +func (f Face) Name() string { |
| + u := f.Upload() |
| + if u == nil { |
| + return f.PostScriptName() |
| + } |
| + name := u.CSS + " 400" |
| + if u.Weight == 700 { |
| + name = u.CSS + " 700" |
| + } |
| + if u.Italic { |
| + name += " italic" |
| + } |
| + return name |
| +} |
| + |
| +// font is the parsed font f measures with. |
| +func (f Face) font() (*Font, error) { |
| + if u := f.Upload(); u != nil && u.Font != nil { |
| + return u.Font, nil |
| + } |
| + return f.Parsed() |
| +} |
| + |
| +// Variable reports a variable font (one with an fvar table). The |
| +// layout engine measures a font at its default instance only, so a |
| +// variable face is never drawn with, whatever its upload record says. |
| +func (f *Font) Variable() bool { |
| + _, ok := f.tables["fvar"] |
| + return ok |
| +} |
| + |
| +// Embeddable reports whether the font's licence flags (OS/2 fsType) |
| +// let a PDF embed a subset of it: not restricted-licence (0x0002), not |
| +// "no subsetting" (0x0100), not bitmap-only (0x0200). A font without an |
| +// OS/2 table carries no restriction. |
| +func (f *Font) Embeddable() bool { |
| + os2, ok := f.tables["OS/2"] |
| + if !ok { |
| + return true |
| + } |
| + if len(os2) < 10 { |
| + return false |
| + } |
| + fsType := binary.BigEndian.Uint16(os2[8:]) |
| + return fsType&(0x0002|0x0100|0x0200) == 0 |
| +} |
| + |
| +// Renamed is the whole font file with its family name replaced by |
| +// family and its OS/2 weight and slope set to weight and italic. |
| +// |
| +// The PDF module matches an SVG's font-family against the family name |
| +// inside each font it is given (core/pdf/src/lib.rs), case for case, |
| +// then weight and style. A picture names an uploaded face by the CSS |
| +// name the deck gave it, which need not be the name the font calls |
| +// itself — and the font's own name may even be one of the built-in |
| +// families. Renaming the copy handed to the PDF makes the two agree, |
| +// and keeps an upload from shadowing a built-in face. Every other name |
| +// stays, the PostScript name among them, which is what the PDF writes |
| +// as the face's /BaseFont. |
| +func (f *Font) Renamed(family string, weight int, italic bool) []byte { |
| + tables := make(map[string][]byte, len(f.tables)) |
| + for tag, b := range f.tables { |
| + tables[tag] = b |
| + } |
| + tables["name"] = renameTable(f.tables["name"], family) |
| + if os2, ok := f.tables["OS/2"]; ok && len(os2) >= 64 { |
| + os2 = append([]byte(nil), os2...) |
| + binary.BigEndian.PutUint16(os2[4:], uint16(weight)) |
| + sel := binary.BigEndian.Uint16(os2[62:]) |
| + sel &^= 0x0001 | 0x0200 // italic, oblique |
| + if italic { |
| + sel |= 0x0001 |
| + } |
| + binary.BigEndian.PutUint16(os2[62:], sel) |
| + tables["OS/2"] = os2 |
| + } |
| + head := append([]byte(nil), tables["head"]...) |
| + binary.BigEndian.PutUint32(head[8:], 0) // checkSumAdjustment, set by buildSfnt |
| + tables["head"] = head |
| + return buildSfnt(tables) |
| +} |
| + |
| +// nameRecord is one string of a name table. |
| +type nameRecord struct { |
| + platform, encoding, language, id uint16 |
| + value []byte |
| +} |
| + |
| +// renameTable is a format 0 name table holding old's records except |
| +// its family names (1, 16 and 21) and any language-tagged record, plus |
| +// family as the Windows Unicode English family name — and a PostScript |
| +// name made from family should old carry none, because a font without |
| +// one is a font the PDF module will not load. |
| +func renameTable(old []byte, family string) []byte { |
| + var recs []nameRecord |
| + hasPS := false |
| + if len(old) >= 6 { |
| + count := int(binary.BigEndian.Uint16(old[2:])) |
| + base := int(binary.BigEndian.Uint16(old[4:])) |
| + for i := 0; i < count; i++ { |
| + at := 6 + i*12 |
| + if at+12 > len(old) { |
| + break |
| + } |
| + r := nameRecord{ |
| + platform: binary.BigEndian.Uint16(old[at:]), |
| + encoding: binary.BigEndian.Uint16(old[at+2:]), |
| + language: binary.BigEndian.Uint16(old[at+4:]), |
| + id: binary.BigEndian.Uint16(old[at+6:]), |
| + } |
| + length := int(binary.BigEndian.Uint16(old[at+8:])) |
| + off := base + int(binary.BigEndian.Uint16(old[at+10:])) |
| + if off+length > len(old) || r.language >= 0x8000 { |
| + continue |
| + } |
| + switch r.id { |
| + case 1, 16, 21: |
| + continue |
| + case 6: |
| + hasPS = true |
| + } |
| + r.value = old[off : off+length] |
| + recs = append(recs, r) |
| + } |
| + } |
| + recs = append(recs, nameRecord{3, 1, 0x409, 1, utf16BE(family)}) |
| + if !hasPS { |
| + recs = append(recs, nameRecord{3, 1, 0x409, 6, utf16BE(postScriptFrom(family))}) |
| + } |
| + sort.SliceStable(recs, func(i, j int) bool { |
| + a, b := recs[i], recs[j] |
| + if a.platform != b.platform { |
| + return a.platform < b.platform |
| + } |
| + if a.encoding != b.encoding { |
| + return a.encoding < b.encoding |
| + } |
| + if a.language != b.language { |
| + return a.language < b.language |
| + } |
| + return a.id < b.id |
| + }) |
| + |
| + // String offsets are 16 bits. Strings old shared are copied once |
| + // each here, so a table already near the limit could pass it: drop |
| + // what does not fit (and any record past the 4,096th, which keeps |
| + // the header's own size in range), keeping room for the family and |
| + // PostScript names this table exists to carry. |
| + reserve := 0 |
| + for _, r := range recs { |
| + if r.id == 1 || r.id == 6 { |
| + reserve += len(r.value) |
| + } |
| + } |
| + kept, size := recs[:0], 0 |
| + for _, r := range recs { |
| + essential := r.id == 1 || r.id == 6 |
| + if !essential && (size+len(r.value)+reserve > 0xffff || len(kept) >= 4096) { |
| + continue |
| + } |
| + if essential { |
| + reserve -= len(r.value) |
| + } |
| + size += len(r.value) |
| + kept = append(kept, r) |
| + } |
| + recs = kept |
| + |
| + head := make([]byte, 6+12*len(recs)) |
| + binary.BigEndian.PutUint16(head[2:], uint16(len(recs))) |
| + binary.BigEndian.PutUint16(head[4:], uint16(len(head))) |
| + var store []byte |
| + for i, r := range recs { |
| + at := 6 + i*12 |
| + binary.BigEndian.PutUint16(head[at:], r.platform) |
| + binary.BigEndian.PutUint16(head[at+2:], r.encoding) |
| + binary.BigEndian.PutUint16(head[at+4:], r.language) |
| + binary.BigEndian.PutUint16(head[at+6:], r.id) |
| + binary.BigEndian.PutUint16(head[at+8:], uint16(len(r.value))) |
| + binary.BigEndian.PutUint16(head[at+10:], uint16(len(store))) |
| + store = append(store, r.value...) |
| + } |
| + return append(head, store...) |
| +} |
| + |
| +func utf16BE(s string) []byte { |
| + units := utf16.Encode([]rune(s)) |
| + out := make([]byte, 2*len(units)) |
| + for i, u := range units { |
| + binary.BigEndian.PutUint16(out[2*i:], u) |
| + } |
| + return out |
| +} |
| + |
| +// postScriptFrom is family without the characters a PostScript name |
| +// may not carry. |
| +func postScriptFrom(family string) string { |
| + ps := strings.Map(func(r rune) rune { |
| + if r > ' ' && r < 0x7f && !strings.ContainsRune("[](){}<>/%", r) { |
| + return r |
| + } |
| + return -1 |
| + }, family) |
| + if ps == "" { |
| + ps = "Uploaded" |
| + } |
| + return ps |
| +} |
diff --git a/internal/slides/fonts/uploaded_test.go b/internal/slides/fonts/uploaded_test.go| new file mode 100644 |
| index 0000000..ae225d0 |
| --- /dev/null |
| +++ b/internal/slides/fonts/uploaded_test.go |
| @@ -0,0 +1,101 @@ |
| +package fonts |
| + |
| +import ( |
| + "bytes" |
| + "encoding/binary" |
| + "testing" |
| + "unicode/utf16" |
| +) |
| + |
| +func serifRegular(t *testing.T) *Font { |
| + t.Helper() |
| + f, err := Parse(Data(Face{Family: Serif})) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return f |
| +} |
| + |
| +// A face whose upload has no face for its style is measured in its |
| +// built-in Family, even before that face was ever parsed. |
| +func TestAnUploadWithoutTheStyleMeasuresTheBuiltInFace(t *testing.T) { |
| + parsedMu.Lock() |
| + saved := parsed |
| + parsed = map[string]*Font{} |
| + parsedMu.Unlock() |
| + t.Cleanup(func() { parsedMu.Lock(); parsed = saved; parsedMu.Unlock() }) |
| + |
| + up := UploadedFamily(&Uploaded{CSS: "Upload", Weight: 400, Font: serifRegular(t)}) |
| + bold := Face{Family: Sans, Bold: true, Uploaded: up} |
| + if bold.Upload() != nil { |
| + t.Fatal("a bold face found a regular-only upload") |
| + } |
| + got, _ := Advance(bold, 40, "Bold words") |
| + want, _ := Advance(Face{Family: Sans, Bold: true}, 40, "Bold words") |
| + if got == 0 || got != want { |
| + t.Errorf("measured %v, want Liberation Sans Bold's %v", got, want) |
| + } |
| + if bold.Stack() != Sans.Stack() || bold.Name() != "LiberationSans-Bold" { |
| + t.Errorf("stack %q, name %q: the fallback face should be named as itself", bold.Stack(), bold.Name()) |
| + } |
| + regular := Face{Family: Sans, Uploaded: up} |
| + if regular.Stack() != "'Upload', "+Sans.Stack() || regular.Name() != "Upload 400" { |
| + t.Errorf("stack %q, name %q", regular.Stack(), regular.Name()) |
| + } |
| +} |
| + |
| +// nameStrings is every (nameID, string) of a font's Windows Unicode |
| +// names. |
| +func nameStrings(t *testing.T, f *Font) map[uint16][]string { |
| + t.Helper() |
| + name := f.tables["name"] |
| + count := int(binary.BigEndian.Uint16(name[2:])) |
| + base := int(binary.BigEndian.Uint16(name[4:])) |
| + out := map[uint16][]string{} |
| + for i := 0; i < count; i++ { |
| + at := 6 + i*12 |
| + if binary.BigEndian.Uint16(name[at:]) != 3 { |
| + continue |
| + } |
| + id := binary.BigEndian.Uint16(name[at+6:]) |
| + length := int(binary.BigEndian.Uint16(name[at+8:])) |
| + off := base + int(binary.BigEndian.Uint16(name[at+10:])) |
| + raw := name[off : off+length] |
| + units := make([]uint16, len(raw)/2) |
| + for j := range units { |
| + units[j] = binary.BigEndian.Uint16(raw[2*j:]) |
| + } |
| + out[id] = append(out[id], string(utf16.Decode(units))) |
| + } |
| + return out |
| +} |
| + |
| +// The copy handed to the PDF calls itself by the deck's CSS name, keeps |
| +// its PostScript name, and is the same font otherwise. |
| +func TestRenamedCallsTheFontByTheDecksName(t *testing.T) { |
| + orig := serifRegular(t) |
| + renamed, err := Parse(orig.Renamed("Test Upload", 700, true)) |
| + if err != nil { |
| + t.Fatalf("the renamed font does not parse: %v", err) |
| + } |
| + names := nameStrings(t, renamed) |
| + if got := names[1]; len(got) != 1 || got[0] != "Test Upload" { |
| + t.Errorf("family names %q, want only Test Upload", got) |
| + } |
| + if len(names[16]) != 0 { |
| + t.Errorf("a typographic family survived: %q", names[16]) |
| + } |
| + if got := names[6]; len(got) != 1 || got[0] != "LiberationSerif" { |
| + t.Errorf("PostScript names %q, want LiberationSerif", got) |
| + } |
| + os2 := renamed.tables["OS/2"] |
| + if w := binary.BigEndian.Uint16(os2[4:]); w != 700 { |
| + t.Errorf("usWeightClass %d, want 700", w) |
| + } |
| + if sel := binary.BigEndian.Uint16(os2[62:]); sel&1 == 0 { |
| + t.Error("fsSelection is not italic") |
| + } |
| + if !bytes.Equal(renamed.tables["glyf"], orig.tables["glyf"]) || renamed.NumGlyphs != orig.NumGlyphs { |
| + t.Error("the outlines changed") |
| + } |
| +} |
diff --git a/internal/slides/fontstore.go b/internal/slides/fontstore.go| new file mode 100644 |
| index 0000000..5364aeb |
| --- /dev/null |
| +++ b/internal/slides/fontstore.go |
| @@ -0,0 +1,56 @@ |
| +package slides |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "io" |
| + "regexp" |
| +) |
| + |
| +// fontstore.go is where a deck's uploaded font files are read from: |
| +// the object store (Config.Blobs), and nowhere else — never a |
| +// repository, a bundle, or a cache that outlives one render. |
| + |
| +// maxFontFileBytes is the most one uploaded font file may be: 10 MiB, |
| +// the upload limit. A stored object bigger than that is not read. |
| +const maxFontFileBytes = 10 << 20 |
| + |
| +// fontRefPattern is a face's ref as meta.fontFiles carries it: the |
| +// file's SHA-256 in lowercase hex. |
| +var fontRefPattern = regexp.MustCompile(`^[0-9a-f]{64}$`) |
| + |
| +// errNoFontStore is every font read on a deployment with no object |
| +// store; the text falls back to the rest of its stack. |
| +var errNoFontStore = errors.New("slides: no object store to read a font from") |
| + |
| +// fontObjectKey is the object-store key an uploaded font file lives at. |
| +func fontObjectKey(ref string) string { return "fonts/" + ref } |
| + |
| +// fontLoader reads uploaded font files for one render (a thumbnail, an |
| +// export): layout.Options.Fonts and ExportOptions.Fonts. It reads, and |
| +// keeps nothing; the render parses each face once and drops it after. |
| +func (a *app) fontLoader(ctx context.Context) func(ref string) ([]byte, error) { |
| + store := a.cfg.Blobs |
| + return func(ref string) ([]byte, error) { |
| + if store == nil { |
| + return nil, errNoFontStore |
| + } |
| + if !fontRefPattern.MatchString(ref) { |
| + return nil, fmt.Errorf("slides: %q is not a font ref", ref) |
| + } |
| + rc, err := store.Get(ctx, fontObjectKey(ref)) |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer rc.Close() |
| + raw, err := io.ReadAll(io.LimitReader(rc, maxFontFileBytes+1)) |
| + if err != nil { |
| + return nil, err |
| + } |
| + if len(raw) > maxFontFileBytes { |
| + return nil, fmt.Errorf("slides: font %s is over %d bytes", ref, maxFontFileBytes) |
| + } |
| + return raw, nil |
| + } |
| +} |
diff --git a/internal/slides/layout/layout.go b/internal/slides/layout/layout.go| index 56466f5..bc11d9c 100644 |
| --- a/internal/slides/layout/layout.go |
| +++ b/internal/slides/layout/layout.go |
| @@ -2,6 +2,7 @@ package layout |
| import ( |
| "fmt" |
| + "regexp" |
| "slices" |
| "strings" |
| @@ -23,21 +24,134 @@ import ( |
| // a block that outgrew its box, a rune no embedded face can draw, an |
| // image the deck never registered. None of them stops the drawing. |
| func Layout(d *deck.Deck, index int) (Paint, []Warning, error) { |
| + return New(d, Options{}).Layout(index) |
| +} |
| + |
| +// Options is what a render needs beyond the deck. |
| +type Options struct { |
| + // Fonts reads an uploaded face's file by its ref (deck.FontFace.Ref). |
| + // Nil reads none, and an error is a face that is not there: either |
| + // way the text is set in the next family of its stack, as it would |
| + // be in a browser that never got the file. |
| + Fonts func(ref string) ([]byte, error) |
| +} |
| + |
| +// Renderer lays out one deck's slides for one render — a thumbnail, or |
| +// every page of an export. It reads and parses each uploaded face the |
| +// deck's stacks call for at most once, and keeps them only as long as |
| +// it is kept: nothing here holds a person's font past the render. |
| +type Renderer struct { |
| + d *deck.Deck |
| + opts Options |
| + |
| + // parsed is each ref read so far: its font, or nil for one that |
| + // did not load or is not a face a picture may draw with. |
| + parsed map[string]*fonts.Font |
| + // families is each uploaded family resolved so far, by its CSS name |
| + // folded to lower case: one of its faces (fonts.UploadedFamily), or |
| + // nil for a family with none to draw with. |
| + families map[string]*fonts.Uploaded |
| + // used is every uploaded face of those families, in the order they |
| + // were resolved — what the PDF has to be handed. |
| + used []*fonts.Uploaded |
| +} |
| + |
| +// New is a render of d. |
| +func New(d *deck.Deck, o Options) *Renderer { |
| + return &Renderer{d: d, opts: o, parsed: map[string]*fonts.Font{}, families: map[string]*fonts.Uploaded{}} |
| +} |
| + |
| +// Layout draws the deck's slide at index; see the package's Layout. |
| +func (r *Renderer) Layout(index int) (Paint, []Warning, error) { |
| + d := r.d |
| if d == nil { |
| return Paint{}, nil, fmt.Errorf("layout: no deck") |
| } |
| if index < 0 || index >= len(d.Slides) { |
| return Paint{}, nil, fmt.Errorf("layout: slide %d is outside a deck of %d", index, len(d.Slides)) |
| } |
| - e := newEngine(d, index) |
| + e := newEngine(r, index) |
| e.slide(d.Slides[index]) |
| return Paint{W: FrameW, H: FrameH, Background: e.bg, Ops: e.ops}, e.warnings, nil |
| } |
| +// Uploaded is every uploaded face this render has drawn with, or may |
| +// have: every face of each uploaded family a stack it laid out named. |
| +func (r *Renderer) Uploaded() []*fonts.Uploaded { return r.used } |
| + |
| +// uploadedCSS is a CSS family name a picture can name an upload by: |
| +// written into a quoted font-family as it is, so no quote and no comma. |
| +var uploadedCSS = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9 ._-]*$`) |
| + |
| +// declared is the deck's uploaded family whose CSS name is name, if it |
| +// has one. |
| +func (r *Renderer) declared(name string) (deck.FontFamily, bool) { |
| + for _, fam := range r.d.Meta.FontFiles { |
| + if strings.EqualFold(fam.CSS, name) { |
| + return fam, true |
| + } |
| + } |
| + return deck.FontFamily{}, false |
| +} |
| + |
| +// family resolves an uploaded family to the faces a picture can draw |
| +// with, once per render: for each of regular, italic, bold and bold |
| +// italic, the first face marked for pictures that covers the weight |
| +// (400 or 700) and has the slope, and whose bytes load, parse, are not |
| +// a variable font and allow embedding. The checks after the mark are |
| +// there because a deck's meta.fontFiles is a document anyone with the |
| +// deck can write, and the mark is only what it says. |
| +func (r *Renderer) family(fam deck.FontFamily) *fonts.Uploaded { |
| + key := strings.ToLower(fam.CSS) |
| + if u, ok := r.families[key]; ok { |
| + return u |
| + } |
| + var faces []*fonts.Uploaded |
| + if uploadedCSS.MatchString(fam.CSS) { |
| + for _, weight := range []int{400, 700} { |
| + for _, italic := range []bool{false, true} { |
| + for _, face := range fam.Faces { |
| + if !face.Pictures || face.Italic != italic || weight < face.Weight[0] || weight > face.Weight[1] { |
| + continue |
| + } |
| + if font := r.font(face.Ref); font != nil { |
| + faces = append(faces, &fonts.Uploaded{CSS: fam.CSS, Weight: weight, Italic: italic, Font: font}) |
| + break |
| + } |
| + } |
| + } |
| + } |
| + } |
| + u := fonts.UploadedFamily(faces...) |
| + r.families[key] = u |
| + r.used = append(r.used, faces...) |
| + return u |
| +} |
| + |
| +// font reads and parses one uploaded face, once per render. |
| +func (r *Renderer) font(ref string) *fonts.Font { |
| + if font, ok := r.parsed[ref]; ok { |
| + return font |
| + } |
| + var font *fonts.Font |
| + if r.opts.Fonts != nil { |
| + if data, err := r.opts.Fonts(ref); err == nil { |
| + if f, err := fonts.Parse(data); err == nil && !f.Variable() && f.Embeddable() { |
| + font = f |
| + } |
| + } |
| + } |
| + r.parsed[ref] = font |
| + return font |
| +} |
| + |
| // engine is one Layout call: the palette it paints in, the faces it |
| // measures with, and what it has drawn and noticed so far. |
| type engine struct { |
| deck *deck.Deck |
| + // render is the Renderer this slide is part of: where the deck's |
| + // uploaded faces are read, once for all its slides. |
| + render *Renderer |
| bg, fg Fill |
| accent, accent2 Fill |
| @@ -63,7 +177,8 @@ type engine struct { |
| seen map[rune]bool |
| } |
| -func newEngine(d *deck.Deck, index int) *engine { |
| +func newEngine(r *Renderer, index int) *engine { |
| + d := r.d |
| // The same palette the section carries, overrides and contrast |
| // judgements included — render.SlideVars is the seam, so the paint |
| // list cannot form a second opinion about what colour a slide is. |
| @@ -72,6 +187,7 @@ func newEngine(d *deck.Deck, index int) *engine { |
| e := &engine{ |
| deck: d, |
| + render: r, |
| slideID: d.Slides[index].ID, |
| bg: Fill(vars["--slides-bg"]), |
| fg: Fill(vars["--slides-fg"]), |
| @@ -92,10 +208,38 @@ func newEngine(d *deck.Deck, index int) *engine { |
| // it is the one case where the browser and this engine are knowingly |
| // setting a slide in two different faces, and an export nobody warned |
| // about is an export nobody checks. |
| +// |
| +// A stack whose first name is a family uploaded to the deck is set in |
| +// that upload wherever it has a face a picture can draw with |
| +// (Renderer.family), and in the rest of the stack, judged as it always |
| +// was, wherever it has none. Falling back from an upload is expected — |
| +// a variable font, a WOFF2 file, a style never uploaded — so it is not |
| +// reported; a family that is neither built in nor uploaded still is. |
| func (e *engine) faceFor(theme string, role fonts.Role, stack string) fonts.Face { |
| + return e.stackFace(theme, role, stack, true) |
| +} |
| + |
| +// stackFace is faceFor, drawing in an uploaded family only when it is |
| +// the first name of the deck's stack (upload); one later in the stack |
| +// is passed over in silence. |
| +func (e *engine) stackFace(theme string, role fonts.Role, stack string, upload bool) fonts.Face { |
| if fam, ok := fonts.FamilyForStack(stack); ok { |
| return fonts.Face{Family: fam} |
| } |
| + if first, rest := firstName(stack); first != "" { |
| + if fam, ok := e.render.declared(first); ok { |
| + face := e.stackFace(theme, role, rest, false) |
| + if upload { |
| + face.Uploaded = e.render.family(fam) |
| + } |
| + return face |
| + } |
| + } |
| + if strings.TrimSpace(stack) == "" { |
| + // Only reached past an uploaded family that named nothing after |
| + // it: the theme's own face, as the browser falls back to it. |
| + return fonts.Get(theme, role, false, false) |
| + } |
| sub := fonts.Get(theme, role, false, false) |
| e.warn(Warning{Kind: WarnFont, Detail: fmt.Sprintf( |
| "this deck asks for %q, which is not a face this build carries: measured in %s instead", |
| @@ -103,6 +247,13 @@ func (e *engine) faceFor(theme string, role fonts.Role, stack string) fonts.Face |
| return sub |
| } |
| +// firstName splits a CSS font stack into its first family name, |
| +// unquoted, and the rest of the stack. |
| +func firstName(stack string) (first, rest string) { |
| + first, rest, _ = strings.Cut(stack, ",") |
| + return strings.Trim(strings.TrimSpace(first), `"'`), rest |
| +} |
| + |
| // warn records a warning, stamping the slide being drawn onto it so no |
| // call site has to remember to. A warning that already names a slide |
| // keeps the one it names. |
diff --git a/internal/slides/layout/paint.go b/internal/slides/layout/paint.go| index af1ac62..4b8760a 100644 |
| --- a/internal/slides/layout/paint.go |
| +++ b/internal/slides/layout/paint.go |
| @@ -295,9 +295,10 @@ func (t Text) MarshalJSON() ([]byte, error) { |
| return opJSON(t.kind(), alias{r4(t.X), r4(t.Y), t.Runs}) |
| } |
| -// MarshalJSON writes the face by name — "LiberationSans-Bold" — which |
| -// is what a person reading a golden file wants to see, and what the |
| -// PDF registers the face under anyway. |
| +// MarshalJSON writes the face by name — "LiberationSans-Bold", or an |
| +// uploaded face's family, weight and slope ("Brand Sans 700 italic") — |
| +// which is what a person reading a golden file wants to see, and what |
| +// the PDF registers a built-in face under anyway. |
| func (r Run) MarshalJSON() ([]byte, error) { |
| type alias struct { |
| S string `json:"s"` |
| @@ -306,7 +307,7 @@ func (r Run) MarshalJSON() ([]byte, error) { |
| Fill Fill `json:"fill,omitempty"` |
| Href string `json:"href,omitempty"` |
| } |
| - return json.Marshal(alias{r.S, r.Face.PostScriptName(), r4(r.Size), r.Fill, r.Href}) |
| + return json.Marshal(alias{r.S, r.Face.Name(), r4(r.Size), r.Fill, r.Href}) |
| } |
| // opJSON marshals v and splices the op's name in as the first key, so |
diff --git a/internal/slides/layout/testdata/svg/fixture-blank.golden.svg b/internal/slides/layout/testdata/svg/fixture-blank.golden.svg| new file mode 100644 |
| index 0000000..7acdd45 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/fixture-blank.golden.svg |
| @@ -0,0 +1,24 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>blank</title> |
| +<defs> |
| +<marker id="slides-arrow-1" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="5" markerHeight="5" markerUnits="strokeWidth" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" fill="#1c1a17"/></marker> |
| +</defs> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<rect x="120" y="120" width="1680" height="245.364" rx="23.184" fill="#e8e5df"/> |
| +<text x="158.64" y="196.9366" xml:space="preserve"><tspan x="158.64" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="38.64" fill="#1c1a17">func main() {</tspan></text> |
| +<text x="158.64" y="252.9646" xml:space="preserve"><tspan x="158.64" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="38.64" fill="#1c1a17"> fmt.Println("hi <there>")</tspan></text> |
| +<text x="158.64" y="308.9926" xml:space="preserve"><tspan x="158.64" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="38.64" fill="#1c1a17">}</tspan></text> |
| +<text x="145.872" y="462.5133" xml:space="preserve"><tspan x="145.872" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" font-weight="700" fill="#1c1a17">Region</tspan></text> |
| +<text x="985.872" y="462.5133" xml:space="preserve"><tspan x="985.872" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" font-weight="700" fill="#1c1a17">Holds</tspan></text> |
| +<line x1="120" y1="490.356" x2="1800" y2="490.356" stroke="#8a5410" stroke-width="1" stroke-linecap="round"/> |
| +<text x="145.872" y="544.8253" xml:space="preserve"><tspan x="145.872" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#1c1a17">heading</tspan></text> |
| +<text x="985.872" y="544.8253" xml:space="preserve"><tspan x="985.872" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#1c1a17">the title</tspan></text> |
| +<line x1="120" y1="572.668" x2="1800" y2="572.668" stroke="#c9c6c0" stroke-width="1" stroke-linecap="round"/> |
| +<rect x="120" y="617.348" width="1680" height="8.4" rx="4.2" fill="#b7b5af"/> |
| +<rect x="136.8" y="801.812" width="1646.4" height="131.712" rx="201.6" fill="#e8e2d6" stroke="#8a7f6a" stroke-width="2"/> |
| +<text x="753.4076" y="883.9758" xml:space="preserve"><tspan x="753.4076" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">A labelled rectangle</tspan></text> |
| +<ellipse cx="960" cy="1045.748" rx="823.2" ry="65.856" fill="#cfd9e8" stroke="#5a6f8a" stroke-width="2"/> |
| +<line x1="136.8" y1="1223.828" x2="1783.2" y2="1223.828" stroke="#5a6f8a" stroke-width="3" stroke-linecap="round"/> |
| +<line x1="136.8" y1="1401.908" x2="1783.2" y2="1401.908" stroke="#1c1a17" stroke-width="1" stroke-linecap="round" marker-end="url(#slides-arrow-1)"/> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/fixture-canvas-reflow.golden.svg b/internal/slides/layout/testdata/svg/fixture-canvas-reflow.golden.svg| new file mode 100644 |
| index 0000000..26c9f08 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/fixture-canvas-reflow.golden.svg |
| @@ -0,0 +1,11 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>canvas-reflow</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="115.2" y="220.4516" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="126.72" font-weight="700" fill="#1c1a17">On a phone this one reflows</tspan></text> |
| +<rect x="1234.56" y="350.352" width="564.48" height="465.696" rx="69.12" fill="#e0d7e8" stroke="#75608a" stroke-width="2"/> |
| +<text x="1361.4131" y="601.8375" xml:space="preserve"><tspan x="1361.4131" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">Desktop only</tspan></text> |
| +<text x="115.2" y="399.1815" xml:space="preserve"><tspan x="115.2" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">Setting phone to reflow lays the blocks</tspan></text> |
| +<text x="115.2" y="469.0695" xml:space="preserve"><tspan x="115.2" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">out as one column.</tspan></text> |
| +<text x="115.2" y="917.5815" xml:space="preserve"><tspan x="115.2" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">A footnote, last by z.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/fixture-canvas.golden.svg b/internal/slides/layout/testdata/svg/fixture-canvas.golden.svg| new file mode 100644 |
| index 0000000..a951c0c |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/fixture-canvas.golden.svg |
| @@ -0,0 +1,10 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>canvas</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<rect x="160.512" y="371.952" width="677.376" height="465.696" rx="82.944" fill="#e8e2d6" stroke="#8a7f6a" stroke-width="2"/> |
| +<text x="115.2" y="198.8516" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="126.72" font-weight="700" fill="#1c1a17">Canvas: put it where you want</tspan></text> |
| +<text x="115.2" y="338.2436" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="126.72" font-weight="700" fill="#1c1a17">it</tspan></text> |
| +<text x="1113.6" y="442.3815" xml:space="preserve"><tspan x="1113.6" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">Every box is a fraction of the</tspan></text> |
| +<text x="1113.6" y="512.2695" xml:space="preserve"><tspan x="1113.6" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">16:9 frame.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/fixture-image-full.golden.svg b/internal/slides/layout/testdata/svg/fixture-image-full.golden.svg| new file mode 100644 |
| index 0000000..0b6c038 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/fixture-image-full.golden.svg |
| @@ -0,0 +1,7 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>image-full</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<rect x="120" y="804.48" width="1064.3381" height="155.52" rx="19.2" fill="#faf7f0"/> |
| +<text x="169.92" y="914.6306" xml:space="preserve"><tspan x="169.92" font-family="Liberation Serif, Georgia, serif" font-size="96" font-weight="700" fill="#1c1a17">A picture would go here</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/fixture-quote.golden.svg b/internal/slides/layout/testdata/svg/fixture-quote.golden.svg| new file mode 100644 |
| index 0000000..7afd620 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/fixture-quote.golden.svg |
| @@ -0,0 +1,8 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>quote</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="491.6746" y="460.679" xml:space="preserve"><tspan x="491.6746" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="57.12" font-style="italic" fill="#1c1a17">A deck is a document, not a drawing.</tspan></text> |
| +<text x="807.4397" y="547.5735" xml:space="preserve"><tspan x="807.4397" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="35.4144" fill="#8a5410">— The design spec</tspan></text> |
| +<text x="599.6113" y="658.9257" xml:space="preserve"><tspan x="599.6113" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="57.12" font-style="italic" fill="#1c1a17">Said by nobody in particular.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/fixture-section.golden.svg b/internal/slides/layout/testdata/svg/fixture-section.golden.svg| new file mode 100644 |
| index 0000000..2368e52 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/fixture-section.golden.svg |
| @@ -0,0 +1,7 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>section</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#2b1030"/> |
| +<text x="759.7024" y="551.3712" xml:space="preserve"><tspan x="759.7024" font-family="Liberation Serif, Georgia, serif" font-size="110.88" font-weight="700" fill="#faf7f0">Part two</tspan></text> |
| +<rect x="808.8" y="618.624" width="302.4" height="8.4" rx="4.2" fill="#faf7f0"/> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/fixture-title-body.golden.svg b/internal/slides/layout/testdata/svg/fixture-title-body.golden.svg| new file mode 100644 |
| index 0000000..ebf2046 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/fixture-title-body.golden.svg |
| @@ -0,0 +1,18 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>title-body</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="120" y="218.3952" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="110.88" font-weight="700" fill="#1c1a17">Text and marks</tspan></text> |
| +<rect x="638.2871" y="289.9478" width="189.3406" height="52.5525" rx="9.408" fill="#ddcdb6"/> |
| +<rect x="840.5008" y="289.9478" width="211.1479" height="52.5525" rx="8.279" fill="#ddcdb6"/> |
| +<text x="120" y="332.5318" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">Marks: </tspan><tspan x="274.1892" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" font-weight="700" fill="#1c1a17">bold</tspan><tspan x="373.4602" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="399.5986" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" font-style="italic" fill="#1c1a17">italic</tspan><tspan x="493.7016" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="519.84" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="41.3952" fill="#1c1a17">code</tspan><tspan x="619.2047" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="645.3431" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">highlight</tspan><tspan x="820.5717" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="846.7101" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="41.3952" font-weight="700" font-style="italic" fill="#1c1a17">all four</tspan><tspan x="1045.4394" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17"> and a </tspan><a href="https://amadan.net/oficina/slides"><tspan x="1189.2927" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#8a5410">link</tspan></a><tspan x="1259.8757" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17"> <not markup>.</tspan></text> |
| +<line x1="1189.2927" y1="339.5878" x2="1259.8757" y2="339.5878" stroke="#8a5410" stroke-width="3.2928" stroke-linecap="round"/> |
| +<text x="185.856" y="437.3638" xml:space="preserve"><tspan x="185.856" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">One item per paragraph</tspan></text> |
| +<text x="152.9234" y="437.3638" xml:space="preserve"><tspan x="152.9234" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#8a5410">•</tspan></text> |
| +<text x="185.856" y="517.3318" xml:space="preserve"><tspan x="185.856" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">Bullets or numbers</tspan></text> |
| +<text x="152.9234" y="517.3318" xml:space="preserve"><tspan x="152.9234" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#8a5410">•</tspan></text> |
| +<text x="230.88" y="612.1173" xml:space="preserve"><tspan x="230.88" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#1c1a17">First</tspan></text> |
| +<text x="187.1199" y="612.1173" xml:space="preserve"><tspan x="187.1199" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#8a5410">1.</tspan></text> |
| +<text x="230.88" y="674.9493" xml:space="preserve"><tspan x="230.88" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#1c1a17">Second</tspan></text> |
| +<text x="187.1199" y="674.9493" xml:space="preserve"><tspan x="187.1199" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#8a5410">2.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/fixture-title.golden.svg b/internal/slides/layout/testdata/svg/fixture-title.golden.svg| new file mode 100644 |
| index 0000000..5b24ea6 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/fixture-title.golden.svg |
| @@ -0,0 +1,7 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>title</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="570.1788" y="518.4432" xml:space="preserve"><tspan x="570.1788" font-family="Liberation Serif, Georgia, serif" font-size="110.88" font-weight="700" fill="#1c1a17">Renderer fixture</tspan></text> |
| +<text x="386.8895" y="642.6263" xml:space="preserve"><tspan x="386.8895" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="57.12" fill="#1c1a17">One section per slide, one element per block.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/fixture-two-column.golden.svg b/internal/slides/layout/testdata/svg/fixture-two-column.golden.svg| new file mode 100644 |
| index 0000000..bb1654f |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/fixture-two-column.golden.svg |
| @@ -0,0 +1,14 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>two-column</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="120" y="194.5418" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="84" font-weight="700" fill="#1c1a17">Regions, not coordinates</tspan></text> |
| +<text x="120" y="332.5318" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">A flow slide names regions and blocks</tspan></text> |
| +<text x="120" y="393.6838" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">stack inside the one they are in.</tspan></text> |
| +<text x="120" y="498.5158" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">First column,</tspan></text> |
| +<text x="120" y="559.6678" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">second in the</tspan></text> |
| +<text x="120" y="620.8198" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">array.</tspan></text> |
| +<text x="544.368" y="498.5158" xml:space="preserve"><tspan x="544.368" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">Second column,</tspan></text> |
| +<text x="544.368" y="559.6678" xml:space="preserve"><tspan x="544.368" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">first in the array.</tspan></text> |
| +<text x="994.944" y="332.5318" xml:space="preserve"><tspan x="994.944" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">The aside is the second column.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/listed-blank.golden.svg b/internal/slides/layout/testdata/svg/listed-blank.golden.svg| new file mode 100644 |
| index 0000000..7acdd45 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/listed-blank.golden.svg |
| @@ -0,0 +1,24 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>blank</title> |
| +<defs> |
| +<marker id="slides-arrow-1" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="5" markerHeight="5" markerUnits="strokeWidth" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" fill="#1c1a17"/></marker> |
| +</defs> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<rect x="120" y="120" width="1680" height="245.364" rx="23.184" fill="#e8e5df"/> |
| +<text x="158.64" y="196.9366" xml:space="preserve"><tspan x="158.64" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="38.64" fill="#1c1a17">func main() {</tspan></text> |
| +<text x="158.64" y="252.9646" xml:space="preserve"><tspan x="158.64" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="38.64" fill="#1c1a17"> fmt.Println("hi <there>")</tspan></text> |
| +<text x="158.64" y="308.9926" xml:space="preserve"><tspan x="158.64" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="38.64" fill="#1c1a17">}</tspan></text> |
| +<text x="145.872" y="462.5133" xml:space="preserve"><tspan x="145.872" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" font-weight="700" fill="#1c1a17">Region</tspan></text> |
| +<text x="985.872" y="462.5133" xml:space="preserve"><tspan x="985.872" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" font-weight="700" fill="#1c1a17">Holds</tspan></text> |
| +<line x1="120" y1="490.356" x2="1800" y2="490.356" stroke="#8a5410" stroke-width="1" stroke-linecap="round"/> |
| +<text x="145.872" y="544.8253" xml:space="preserve"><tspan x="145.872" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#1c1a17">heading</tspan></text> |
| +<text x="985.872" y="544.8253" xml:space="preserve"><tspan x="985.872" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#1c1a17">the title</tspan></text> |
| +<line x1="120" y1="572.668" x2="1800" y2="572.668" stroke="#c9c6c0" stroke-width="1" stroke-linecap="round"/> |
| +<rect x="120" y="617.348" width="1680" height="8.4" rx="4.2" fill="#b7b5af"/> |
| +<rect x="136.8" y="801.812" width="1646.4" height="131.712" rx="201.6" fill="#e8e2d6" stroke="#8a7f6a" stroke-width="2"/> |
| +<text x="753.4076" y="883.9758" xml:space="preserve"><tspan x="753.4076" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">A labelled rectangle</tspan></text> |
| +<ellipse cx="960" cy="1045.748" rx="823.2" ry="65.856" fill="#cfd9e8" stroke="#5a6f8a" stroke-width="2"/> |
| +<line x1="136.8" y1="1223.828" x2="1783.2" y2="1223.828" stroke="#5a6f8a" stroke-width="3" stroke-linecap="round"/> |
| +<line x1="136.8" y1="1401.908" x2="1783.2" y2="1401.908" stroke="#1c1a17" stroke-width="1" stroke-linecap="round" marker-end="url(#slides-arrow-1)"/> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/listed-canvas-reflow.golden.svg b/internal/slides/layout/testdata/svg/listed-canvas-reflow.golden.svg| new file mode 100644 |
| index 0000000..26c9f08 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/listed-canvas-reflow.golden.svg |
| @@ -0,0 +1,11 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>canvas-reflow</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="115.2" y="220.4516" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="126.72" font-weight="700" fill="#1c1a17">On a phone this one reflows</tspan></text> |
| +<rect x="1234.56" y="350.352" width="564.48" height="465.696" rx="69.12" fill="#e0d7e8" stroke="#75608a" stroke-width="2"/> |
| +<text x="1361.4131" y="601.8375" xml:space="preserve"><tspan x="1361.4131" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">Desktop only</tspan></text> |
| +<text x="115.2" y="399.1815" xml:space="preserve"><tspan x="115.2" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">Setting phone to reflow lays the blocks</tspan></text> |
| +<text x="115.2" y="469.0695" xml:space="preserve"><tspan x="115.2" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">out as one column.</tspan></text> |
| +<text x="115.2" y="917.5815" xml:space="preserve"><tspan x="115.2" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">A footnote, last by z.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/listed-canvas.golden.svg b/internal/slides/layout/testdata/svg/listed-canvas.golden.svg| new file mode 100644 |
| index 0000000..a951c0c |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/listed-canvas.golden.svg |
| @@ -0,0 +1,10 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>canvas</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<rect x="160.512" y="371.952" width="677.376" height="465.696" rx="82.944" fill="#e8e2d6" stroke="#8a7f6a" stroke-width="2"/> |
| +<text x="115.2" y="198.8516" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="126.72" font-weight="700" fill="#1c1a17">Canvas: put it where you want</tspan></text> |
| +<text x="115.2" y="338.2436" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="126.72" font-weight="700" fill="#1c1a17">it</tspan></text> |
| +<text x="1113.6" y="442.3815" xml:space="preserve"><tspan x="1113.6" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">Every box is a fraction of the</tspan></text> |
| +<text x="1113.6" y="512.2695" xml:space="preserve"><tspan x="1113.6" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="53.76" fill="#1c1a17">16:9 frame.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/listed-image-full.golden.svg b/internal/slides/layout/testdata/svg/listed-image-full.golden.svg| new file mode 100644 |
| index 0000000..0b6c038 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/listed-image-full.golden.svg |
| @@ -0,0 +1,7 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>image-full</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<rect x="120" y="804.48" width="1064.3381" height="155.52" rx="19.2" fill="#faf7f0"/> |
| +<text x="169.92" y="914.6306" xml:space="preserve"><tspan x="169.92" font-family="Liberation Serif, Georgia, serif" font-size="96" font-weight="700" fill="#1c1a17">A picture would go here</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/listed-quote.golden.svg b/internal/slides/layout/testdata/svg/listed-quote.golden.svg| new file mode 100644 |
| index 0000000..7afd620 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/listed-quote.golden.svg |
| @@ -0,0 +1,8 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>quote</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="491.6746" y="460.679" xml:space="preserve"><tspan x="491.6746" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="57.12" font-style="italic" fill="#1c1a17">A deck is a document, not a drawing.</tspan></text> |
| +<text x="807.4397" y="547.5735" xml:space="preserve"><tspan x="807.4397" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="35.4144" fill="#8a5410">— The design spec</tspan></text> |
| +<text x="599.6113" y="658.9257" xml:space="preserve"><tspan x="599.6113" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="57.12" font-style="italic" fill="#1c1a17">Said by nobody in particular.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/listed-section.golden.svg b/internal/slides/layout/testdata/svg/listed-section.golden.svg| new file mode 100644 |
| index 0000000..2368e52 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/listed-section.golden.svg |
| @@ -0,0 +1,7 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>section</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#2b1030"/> |
| +<text x="759.7024" y="551.3712" xml:space="preserve"><tspan x="759.7024" font-family="Liberation Serif, Georgia, serif" font-size="110.88" font-weight="700" fill="#faf7f0">Part two</tspan></text> |
| +<rect x="808.8" y="618.624" width="302.4" height="8.4" rx="4.2" fill="#faf7f0"/> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/listed-title-body.golden.svg b/internal/slides/layout/testdata/svg/listed-title-body.golden.svg| new file mode 100644 |
| index 0000000..ebf2046 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/listed-title-body.golden.svg |
| @@ -0,0 +1,18 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>title-body</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="120" y="218.3952" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="110.88" font-weight="700" fill="#1c1a17">Text and marks</tspan></text> |
| +<rect x="638.2871" y="289.9478" width="189.3406" height="52.5525" rx="9.408" fill="#ddcdb6"/> |
| +<rect x="840.5008" y="289.9478" width="211.1479" height="52.5525" rx="8.279" fill="#ddcdb6"/> |
| +<text x="120" y="332.5318" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">Marks: </tspan><tspan x="274.1892" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" font-weight="700" fill="#1c1a17">bold</tspan><tspan x="373.4602" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="399.5986" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" font-style="italic" fill="#1c1a17">italic</tspan><tspan x="493.7016" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="519.84" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="41.3952" fill="#1c1a17">code</tspan><tspan x="619.2047" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="645.3431" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">highlight</tspan><tspan x="820.5717" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="846.7101" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="41.3952" font-weight="700" font-style="italic" fill="#1c1a17">all four</tspan><tspan x="1045.4394" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17"> and a </tspan><a href="https://amadan.net/oficina/slides"><tspan x="1189.2927" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#8a5410">link</tspan></a><tspan x="1259.8757" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17"> <not markup>.</tspan></text> |
| +<line x1="1189.2927" y1="339.5878" x2="1259.8757" y2="339.5878" stroke="#8a5410" stroke-width="3.2928" stroke-linecap="round"/> |
| +<text x="185.856" y="437.3638" xml:space="preserve"><tspan x="185.856" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">One item per paragraph</tspan></text> |
| +<text x="152.9234" y="437.3638" xml:space="preserve"><tspan x="152.9234" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#8a5410">•</tspan></text> |
| +<text x="185.856" y="517.3318" xml:space="preserve"><tspan x="185.856" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">Bullets or numbers</tspan></text> |
| +<text x="152.9234" y="517.3318" xml:space="preserve"><tspan x="152.9234" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#8a5410">•</tspan></text> |
| +<text x="230.88" y="612.1173" xml:space="preserve"><tspan x="230.88" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#1c1a17">First</tspan></text> |
| +<text x="187.1199" y="612.1173" xml:space="preserve"><tspan x="187.1199" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#8a5410">1.</tspan></text> |
| +<text x="230.88" y="674.9493" xml:space="preserve"><tspan x="230.88" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#1c1a17">Second</tspan></text> |
| +<text x="187.1199" y="674.9493" xml:space="preserve"><tspan x="187.1199" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="36.96" fill="#8a5410">2.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/listed-title.golden.svg b/internal/slides/layout/testdata/svg/listed-title.golden.svg| new file mode 100644 |
| index 0000000..5b24ea6 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/listed-title.golden.svg |
| @@ -0,0 +1,7 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>title</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="570.1788" y="518.4432" xml:space="preserve"><tspan x="570.1788" font-family="Liberation Serif, Georgia, serif" font-size="110.88" font-weight="700" fill="#1c1a17">Renderer fixture</tspan></text> |
| +<text x="386.8895" y="642.6263" xml:space="preserve"><tspan x="386.8895" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="57.12" fill="#1c1a17">One section per slide, one element per block.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/listed-two-column.golden.svg b/internal/slides/layout/testdata/svg/listed-two-column.golden.svg| new file mode 100644 |
| index 0000000..bb1654f |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/listed-two-column.golden.svg |
| @@ -0,0 +1,14 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>two-column</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="120" y="194.5418" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="84" font-weight="700" fill="#1c1a17">Regions, not coordinates</tspan></text> |
| +<text x="120" y="332.5318" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">A flow slide names regions and blocks</tspan></text> |
| +<text x="120" y="393.6838" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">stack inside the one they are in.</tspan></text> |
| +<text x="120" y="498.5158" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">First column,</tspan></text> |
| +<text x="120" y="559.6678" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">second in the</tspan></text> |
| +<text x="120" y="620.8198" xml:space="preserve"><tspan x="120" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">array.</tspan></text> |
| +<text x="544.368" y="498.5158" xml:space="preserve"><tspan x="544.368" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">Second column,</tspan></text> |
| +<text x="544.368" y="559.6678" xml:space="preserve"><tspan x="544.368" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">first in the array.</tspan></text> |
| +<text x="994.944" y="332.5318" xml:space="preserve"><tspan x="994.944" font-family="Liberation Sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" font-size="47.04" fill="#1c1a17">The aside is the second column.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/named-blank.golden.svg b/internal/slides/layout/testdata/svg/named-blank.golden.svg| new file mode 100644 |
| index 0000000..3581aa2 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/named-blank.golden.svg |
| @@ -0,0 +1,24 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>blank</title> |
| +<defs> |
| +<marker id="slides-arrow-1" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="5" markerHeight="5" markerUnits="strokeWidth" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" fill="#1c1a17"/></marker> |
| +</defs> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<rect x="120" y="120" width="1680" height="245.364" rx="23.184" fill="#e8e5df"/> |
| +<text x="158.64" y="196.9366" xml:space="preserve"><tspan x="158.64" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="38.64" fill="#1c1a17">func main() {</tspan></text> |
| +<text x="158.64" y="252.9646" xml:space="preserve"><tspan x="158.64" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="38.64" fill="#1c1a17"> fmt.Println("hi <there>")</tspan></text> |
| +<text x="158.64" y="308.9926" xml:space="preserve"><tspan x="158.64" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="38.64" fill="#1c1a17">}</tspan></text> |
| +<text x="145.872" y="462.1704" xml:space="preserve"><tspan x="145.872" font-family="Liberation Serif, Georgia, serif" font-size="36.96" font-weight="700" fill="#1c1a17">Region</tspan></text> |
| +<text x="985.872" y="462.1704" xml:space="preserve"><tspan x="985.872" font-family="Liberation Serif, Georgia, serif" font-size="36.96" font-weight="700" fill="#1c1a17">Holds</tspan></text> |
| +<line x1="120" y1="490.356" x2="1800" y2="490.356" stroke="#8a5410" stroke-width="1" stroke-linecap="round"/> |
| +<text x="145.872" y="544.4824" xml:space="preserve"><tspan x="145.872" font-family="Liberation Serif, Georgia, serif" font-size="36.96" fill="#1c1a17">heading</tspan></text> |
| +<text x="985.872" y="544.4824" xml:space="preserve"><tspan x="985.872" font-family="Liberation Serif, Georgia, serif" font-size="36.96" fill="#1c1a17">the title</tspan></text> |
| +<line x1="120" y1="572.668" x2="1800" y2="572.668" stroke="#c9c6c0" stroke-width="1" stroke-linecap="round"/> |
| +<rect x="120" y="617.348" width="1680" height="8.4" rx="4.2" fill="#b7b5af"/> |
| +<rect x="136.8" y="801.812" width="1646.4" height="131.712" rx="201.6" fill="#e8e2d6" stroke="#8a7f6a" stroke-width="2"/> |
| +<text x="770.6341" y="883.5394" xml:space="preserve"><tspan x="770.6341" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">A labelled rectangle</tspan></text> |
| +<ellipse cx="960" cy="1045.748" rx="823.2" ry="65.856" fill="#cfd9e8" stroke="#5a6f8a" stroke-width="2"/> |
| +<line x1="136.8" y1="1223.828" x2="1783.2" y2="1223.828" stroke="#5a6f8a" stroke-width="3" stroke-linecap="round"/> |
| +<line x1="136.8" y1="1401.908" x2="1783.2" y2="1401.908" stroke="#1c1a17" stroke-width="1" stroke-linecap="round" marker-end="url(#slides-arrow-1)"/> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/named-canvas-reflow.golden.svg b/internal/slides/layout/testdata/svg/named-canvas-reflow.golden.svg| new file mode 100644 |
| index 0000000..fb04e09 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/named-canvas-reflow.golden.svg |
| @@ -0,0 +1,11 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>canvas-reflow</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="115.2" y="220.4516" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="126.72" font-weight="700" fill="#1c1a17">On a phone this one reflows</tspan></text> |
| +<rect x="1234.56" y="350.352" width="564.48" height="465.696" rx="69.12" fill="#e0d7e8" stroke="#75608a" stroke-width="2"/> |
| +<text x="1372.7006" y="601.3388" xml:space="preserve"><tspan x="1372.7006" font-family="Liberation Serif, Georgia, serif" font-size="53.76" fill="#1c1a17">Desktop only</tspan></text> |
| +<text x="115.2" y="398.6828" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="53.76" fill="#1c1a17">Setting phone to reflow lays the blocks out as</tspan></text> |
| +<text x="115.2" y="468.5708" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="53.76" fill="#1c1a17">one column.</tspan></text> |
| +<text x="115.2" y="917.0828" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="53.76" fill="#1c1a17">A footnote, last by z.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/named-canvas.golden.svg b/internal/slides/layout/testdata/svg/named-canvas.golden.svg| new file mode 100644 |
| index 0000000..3700ad5 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/named-canvas.golden.svg |
| @@ -0,0 +1,10 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>canvas</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<rect x="160.512" y="371.952" width="677.376" height="465.696" rx="82.944" fill="#e8e2d6" stroke="#8a7f6a" stroke-width="2"/> |
| +<text x="115.2" y="198.8516" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="126.72" font-weight="700" fill="#1c1a17">Canvas: put it where you want</tspan></text> |
| +<text x="115.2" y="338.2436" xml:space="preserve"><tspan x="115.2" font-family="Liberation Serif, Georgia, serif" font-size="126.72" font-weight="700" fill="#1c1a17">it</tspan></text> |
| +<text x="1113.6" y="441.8828" xml:space="preserve"><tspan x="1113.6" font-family="Liberation Serif, Georgia, serif" font-size="53.76" fill="#1c1a17">Every box is a fraction of the</tspan></text> |
| +<text x="1113.6" y="511.7708" xml:space="preserve"><tspan x="1113.6" font-family="Liberation Serif, Georgia, serif" font-size="53.76" fill="#1c1a17">16:9 frame.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/named-image-full.golden.svg b/internal/slides/layout/testdata/svg/named-image-full.golden.svg| new file mode 100644 |
| index 0000000..0b6c038 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/named-image-full.golden.svg |
| @@ -0,0 +1,7 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>image-full</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<rect x="120" y="804.48" width="1064.3381" height="155.52" rx="19.2" fill="#faf7f0"/> |
| +<text x="169.92" y="914.6306" xml:space="preserve"><tspan x="169.92" font-family="Liberation Serif, Georgia, serif" font-size="96" font-weight="700" fill="#1c1a17">A picture would go here</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/named-quote.golden.svg b/internal/slides/layout/testdata/svg/named-quote.golden.svg| new file mode 100644 |
| index 0000000..a7784be |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/named-quote.golden.svg |
| @@ -0,0 +1,8 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>quote</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="535.6302" y="460.1491" xml:space="preserve"><tspan x="535.6302" font-family="Liberation Serif, Georgia, serif" font-size="57.12" font-style="italic" fill="#1c1a17">A deck is a document, not a drawing.</tspan></text> |
| +<text x="823.7894" y="547.2449" xml:space="preserve"><tspan x="823.7894" font-family="Liberation Serif, Georgia, serif" font-size="35.4144" fill="#8a5410">— The design spec</tspan></text> |
| +<text x="624.4479" y="658.3958" xml:space="preserve"><tspan x="624.4479" font-family="Liberation Serif, Georgia, serif" font-size="57.12" font-style="italic" fill="#1c1a17">Said by nobody in particular.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/named-section.golden.svg b/internal/slides/layout/testdata/svg/named-section.golden.svg| new file mode 100644 |
| index 0000000..2368e52 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/named-section.golden.svg |
| @@ -0,0 +1,7 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>section</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#2b1030"/> |
| +<text x="759.7024" y="551.3712" xml:space="preserve"><tspan x="759.7024" font-family="Liberation Serif, Georgia, serif" font-size="110.88" font-weight="700" fill="#faf7f0">Part two</tspan></text> |
| +<rect x="808.8" y="618.624" width="302.4" height="8.4" rx="4.2" fill="#faf7f0"/> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/named-title-body.golden.svg b/internal/slides/layout/testdata/svg/named-title-body.golden.svg| new file mode 100644 |
| index 0000000..a1c7ea4 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/named-title-body.golden.svg |
| @@ -0,0 +1,18 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>title-body</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="120" y="218.3952" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="110.88" font-weight="700" fill="#1c1a17">Text and marks</tspan></text> |
| +<rect x="613.4808" y="290.1774" width="183.9889" height="52.0931" rx="9.408" fill="#ddcdb6"/> |
| +<rect x="807.7244" y="290.1774" width="211.1479" height="52.0931" rx="8.279" fill="#ddcdb6"/> |
| +<text x="120" y="332.0954" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">Marks: </tspan><tspan x="265.0247" font-family="Liberation Serif, Georgia, serif" font-size="47.04" font-weight="700" fill="#1c1a17">bold</tspan><tspan x="353.9367" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="377.4567" font-family="Liberation Serif, Georgia, serif" font-size="47.04" font-style="italic" fill="#1c1a17">italic</tspan><tspan x="474.1322" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="497.6522" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="41.3952" fill="#1c1a17">code</tspan><tspan x="597.0168" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="620.5368" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">highlight</tspan><tspan x="790.4137" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">, </tspan><tspan x="813.9337" font-family="Liberation Mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="41.3952" font-weight="700" font-style="italic" fill="#1c1a17">all four</tspan><tspan x="1012.663" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17"> and a </tspan><a href="https://amadan.net/oficina/slides"><tspan x="1136.7402" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#8a5410">link</tspan></a><tspan x="1209.9186" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17"> <not markup>.</tspan></text> |
| +<line x1="1136.7402" y1="339.1514" x2="1209.9186" y2="339.1514" stroke="#8a5410" stroke-width="3.2928" stroke-linecap="round"/> |
| +<text x="185.856" y="436.9274" xml:space="preserve"><tspan x="185.856" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">One item per paragraph</tspan></text> |
| +<text x="152.9234" y="436.9274" xml:space="preserve"><tspan x="152.9234" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#8a5410">•</tspan></text> |
| +<text x="185.856" y="516.8954" xml:space="preserve"><tspan x="185.856" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">Bullets or numbers</tspan></text> |
| +<text x="152.9234" y="516.8954" xml:space="preserve"><tspan x="152.9234" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#8a5410">•</tspan></text> |
| +<text x="230.88" y="611.7744" xml:space="preserve"><tspan x="230.88" font-family="Liberation Serif, Georgia, serif" font-size="36.96" fill="#1c1a17">First</tspan></text> |
| +<text x="190.224" y="611.7744" xml:space="preserve"><tspan x="190.224" font-family="Liberation Serif, Georgia, serif" font-size="36.96" fill="#8a5410">1.</tspan></text> |
| +<text x="230.88" y="674.6064" xml:space="preserve"><tspan x="230.88" font-family="Liberation Serif, Georgia, serif" font-size="36.96" fill="#1c1a17">Second</tspan></text> |
| +<text x="190.224" y="674.6064" xml:space="preserve"><tspan x="190.224" font-family="Liberation Serif, Georgia, serif" font-size="36.96" fill="#8a5410">2.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/named-title.golden.svg b/internal/slides/layout/testdata/svg/named-title.golden.svg| new file mode 100644 |
| index 0000000..1469926 |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/named-title.golden.svg |
| @@ -0,0 +1,7 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>title</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="570.1788" y="518.4432" xml:space="preserve"><tspan x="570.1788" font-family="Liberation Serif, Georgia, serif" font-size="110.88" font-weight="700" fill="#1c1a17">Renderer fixture</tspan></text> |
| +<text x="445.3064" y="642.0964" xml:space="preserve"><tspan x="445.3064" font-family="Liberation Serif, Georgia, serif" font-size="57.12" fill="#1c1a17">One section per slide, one element per block.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/testdata/svg/named-two-column.golden.svg b/internal/slides/layout/testdata/svg/named-two-column.golden.svg| new file mode 100644 |
| index 0000000..135340b |
| --- /dev/null |
| +++ b/internal/slides/layout/testdata/svg/named-two-column.golden.svg |
| @@ -0,0 +1,13 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" role="img"> |
| +<title>two-column</title> |
| +<rect x="0" y="0" width="1920" height="1080" fill="#faf7f0"/> |
| +<text x="120" y="194.5418" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="84" font-weight="700" fill="#1c1a17">Regions, not coordinates</tspan></text> |
| +<text x="120" y="332.0954" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">A flow slide names regions and blocks</tspan></text> |
| +<text x="120" y="393.2474" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">stack inside the one they are in.</tspan></text> |
| +<text x="120" y="498.0794" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">First column,</tspan></text> |
| +<text x="120" y="559.2314" xml:space="preserve"><tspan x="120" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">second in the array.</tspan></text> |
| +<text x="544.368" y="498.0794" xml:space="preserve"><tspan x="544.368" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">Second column,</tspan></text> |
| +<text x="544.368" y="559.2314" xml:space="preserve"><tspan x="544.368" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">first in the array.</tspan></text> |
| +<text x="994.944" y="332.0954" xml:space="preserve"><tspan x="994.944" font-family="Liberation Serif, Georgia, serif" font-size="47.04" fill="#1c1a17">The aside is the second column.</tspan></text> |
| +</svg> |
diff --git a/internal/slides/layout/text.go b/internal/slides/layout/text.go| index 9d9adeb..2c3f5b3 100644 |
| --- a/internal/slides/layout/text.go |
| +++ b/internal/slides/layout/text.go |
| @@ -103,6 +103,7 @@ func (e *engine) styleFor(base style, r deck.Run) style { |
| } |
| if r.C { |
| st.face.Family = fonts.Mono |
| + st.face.Uploaded = nil |
| st.size = base.size * inlineEm |
| } |
| if r.H { |
diff --git a/internal/slides/layout/unchanged_test.go b/internal/slides/layout/unchanged_test.go| new file mode 100644 |
| index 0000000..4860d81 |
| --- /dev/null |
| +++ b/internal/slides/layout/unchanged_test.go |
| @@ -0,0 +1,75 @@ |
| +package layout_test |
| + |
| +import ( |
| + "encoding/json" |
| + "os" |
| + "path/filepath" |
| + "testing" |
| + |
| + "amadan.net/oficina/slides/internal/slides/deck" |
| + "amadan.net/oficina/slides/internal/slides/layout" |
| + "amadan.net/oficina/slides/internal/slides/svg" |
| +) |
| + |
| +// existingDecks are decks written before uploaded fonts existed: the |
| +// golden fixture, and the same deck naming a family this build has |
| +// never heard of (the substitution path, warning and all). |
| +func existingDecks() map[string]*deck.Deck { |
| + named := fixture() |
| + named.Meta.Fonts = &deck.Fonts{Heading: "Nonesuch Grotesk, Georgia, serif", Body: "Liberation Serif, serif"} |
| + // listed uploads a family its stacks never name. |
| + listed := fixture() |
| + listed.Meta.FontFiles = []deck.FontFamily{{Family: "Unused", CSS: "Unused", Faces: []deck.FontFace{ |
| + {Ref: refRegular, Format: "ttf", Weight: [2]int{400, 400}, Pictures: true}}}} |
| + return map[string]*deck.Deck{"fixture": fixture(), "named": named, "listed": listed} |
| +} |
| + |
| +// TestExistingDecksRenderUnchanged holds the pictures of decks that |
| +// upload nothing to the bytes they had before uploaded fonts: every |
| +// fixture slide's SVG against a golden written by the code before the |
| +// change (the paint-list goldens in TestPaintGoldens hold the layout). |
| +func TestExistingDecksRenderUnchanged(t *testing.T) { |
| + for name, d := range existingDecks() { |
| + // A deck whose stacks name no uploaded family reads no font. |
| + r := layout.New(d, layout.Options{Fonts: func(ref string) ([]byte, error) { |
| + t.Errorf("%s read uploaded font %q", name, ref) |
| + return nil, os.ErrNotExist |
| + }}) |
| + for _, g := range goldenNames { |
| + t.Run(name+"/"+g.name, func(t *testing.T) { |
| + p, _, err := r.Layout(g.index) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + // The paint list through the new path is the old one. |
| + old, _, err := layout.Layout(d, g.index) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + a, _ := json.Marshal(p) |
| + b, _ := json.Marshal(old) |
| + if string(a) != string(b) { |
| + t.Errorf("the paint list through layout.New differs from layout.Layout's") |
| + } |
| + got := svg.Encode(p, svg.Options{Title: g.name}) |
| + path := filepath.Join("testdata", "svg", name+"-"+g.name+".golden.svg") |
| + if *update { |
| + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(path, got, 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + return |
| + } |
| + want, err := os.ReadFile(path) |
| + if err != nil { |
| + t.Fatalf("read golden: %v", err) |
| + } |
| + if string(got) != string(want) { |
| + t.Errorf("%s's picture changed", path) |
| + } |
| + }) |
| + } |
| + } |
| +} |
diff --git a/internal/slides/layout/uploaded_test.go b/internal/slides/layout/uploaded_test.go| new file mode 100644 |
| index 0000000..154d8d4 |
| --- /dev/null |
| +++ b/internal/slides/layout/uploaded_test.go |
| @@ -0,0 +1,458 @@ |
| +package layout_test |
| + |
| +import ( |
| + "encoding/binary" |
| + "encoding/xml" |
| + "errors" |
| + "math" |
| + "os" |
| + "path/filepath" |
| + "sort" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/slides/internal/slides/deck" |
| + "amadan.net/oficina/slides/internal/slides/fonts" |
| + "amadan.net/oficina/slides/internal/slides/layout" |
| + "amadan.net/oficina/slides/internal/slides/svg" |
| +) |
| + |
| +// The "uploaded" font in these tests is Liberation Serif (SIL OFL, |
| +// already in ../fonts/files) set under another CSS name in a theme |
| +// whose every face is Liberation Sans, so a run measured or drawn in |
| +// the upload cannot be mistaken for the fallback. |
| +const ( |
| + uploadCSS = "Test Upload" |
| + refRegular = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" |
| + refItalic = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" |
| + uploadSize = 10 |
| +) |
| + |
| +var sansStack = fonts.Sans.Stack() |
| + |
| +func uploadStack() string { return "'" + uploadCSS + "', " + sansStack } |
| + |
| +func libFile(t *testing.T, name string) []byte { |
| + t.Helper() |
| + b, err := os.ReadFile(filepath.Join("..", "fonts", "files", name)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return b |
| +} |
| + |
| +// loader is an injectable Options.Fonts over a map, counting reads. |
| +type loader struct { |
| + files map[string][]byte |
| + reads map[string]int |
| +} |
| + |
| +func newLoader(files map[string][]byte) *loader { |
| + return &loader{files: files, reads: map[string]int{}} |
| +} |
| + |
| +func (l *loader) load(ref string) ([]byte, error) { |
| + l.reads[ref]++ |
| + b, ok := l.files[ref] |
| + if !ok { |
| + return nil, errors.New("no such font") |
| + } |
| + return b, nil |
| +} |
| + |
| +// uploadDeck is one title-body slide, theme ink (Liberation Sans |
| +// throughout), whose heading and body name the uploaded family first. |
| +func uploadDeck(faces ...deck.FontFace) *deck.Deck { |
| + return &deck.Deck{ |
| + Meta: deck.Meta{ |
| + Theme: "ink", Aspect: "16:9", |
| + Fonts: &deck.Fonts{Heading: "'" + uploadCSS + "', Liberation Sans, sans-serif", Body: "'" + uploadCSS + "', Liberation Sans, sans-serif"}, |
| + FontFiles: []deck.FontFamily{{Family: "Test Upload family", CSS: uploadCSS, Faces: faces}}, |
| + }, |
| + Slides: []deck.Slide{{ |
| + ID: "up1", Layout: "flow", Template: "title-body", |
| + Blocks: []deck.Block{ |
| + {ID: "h1", Type: "heading", Region: "heading", |
| + Props: map[string]any{"level": float64(1)}, Text: txt("Heading")}, |
| + {ID: "t1", Type: "text", Region: "body", Props: map[string]any{"size": "m"}, |
| + Text: deck.Text{{ |
| + {T: "plain words "}, |
| + {T: "bold", B: true}, |
| + {T: " then "}, |
| + {T: "slanted", I: true}, |
| + {T: " then "}, |
| + {T: "code", C: true}, |
| + }}}, |
| + }, |
| + }}, |
| + } |
| +} |
| + |
| +func regularFace(ref string) deck.FontFace { |
| + return deck.FontFace{Ref: ref, Format: "ttf", Weight: [2]int{400, 400}, Pictures: true} |
| +} |
| + |
| +// runsOf is every run the paint list draws, in order, with the x it is |
| +// drawn at. |
| +type placedRun struct { |
| + layout.Run |
| + X float64 |
| +} |
| + |
| +func runsOf(p layout.Paint) []placedRun { |
| + var out []placedRun |
| + for _, op := range p.Ops { |
| + txt, ok := op.(layout.Text) |
| + if !ok { |
| + continue |
| + } |
| + x := txt.X |
| + for _, r := range txt.Runs { |
| + out = append(out, placedRun{r, x}) |
| + w, _ := fonts.Advance(r.Face, r.Size, r.S) |
| + x += w |
| + } |
| + } |
| + return out |
| +} |
| + |
| +func runNamed(t *testing.T, runs []placedRun, s string) placedRun { |
| + t.Helper() |
| + for _, r := range runs { |
| + if strings.TrimSpace(r.S) == s { |
| + return r |
| + } |
| + } |
| + t.Fatalf("no run %q in %v", s, runs) |
| + return placedRun{} |
| +} |
| + |
| +// tspans is every <tspan> in an SVG: its text and attributes. |
| +type tspan struct { |
| + text string |
| + attrs map[string]string |
| +} |
| + |
| +func tspans(t *testing.T, out []byte) []tspan { |
| + t.Helper() |
| + dec := xml.NewDecoder(strings.NewReader(string(out))) |
| + var spans []tspan |
| + var cur *tspan |
| + for { |
| + tok, err := dec.Token() |
| + if err != nil { |
| + break |
| + } |
| + switch v := tok.(type) { |
| + case xml.StartElement: |
| + if v.Name.Local == "tspan" { |
| + cur = &tspan{attrs: map[string]string{}} |
| + for _, a := range v.Attr { |
| + cur.attrs[a.Name.Local] = a.Value |
| + } |
| + } |
| + case xml.CharData: |
| + if cur != nil { |
| + cur.text += string(v) |
| + } |
| + case xml.EndElement: |
| + if v.Name.Local == "tspan" && cur != nil { |
| + spans = append(spans, *cur) |
| + cur = nil |
| + } |
| + } |
| + } |
| + return spans |
| +} |
| + |
| +func spanNamed(t *testing.T, spans []tspan, s string) tspan { |
| + t.Helper() |
| + for _, sp := range spans { |
| + if strings.TrimSpace(sp.text) == s { |
| + return sp |
| + } |
| + } |
| + t.Fatalf("no tspan %q", s) |
| + return tspan{} |
| +} |
| + |
| +// serifWidth is s's width at size summed straight from Liberation |
| +// Serif's own tables: what an upload of it measures. |
| +func serifWidth(t *testing.T, file string, size float64, s string) float64 { |
| + t.Helper() |
| + f, err := fonts.Parse(libFile(t, file)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var w float64 |
| + for _, r := range s { |
| + w += float64(f.Advance(f.GlyphIndex(r))) / float64(f.UnitsPerEm) * size |
| + } |
| + return w |
| +} |
| + |
| +func noFontWarning(t *testing.T, ws []layout.Warning) { |
| + t.Helper() |
| + for _, w := range ws { |
| + if w.Kind == layout.WarnFont { |
| + t.Errorf("a font warning for an uploaded family: %s", w.Detail) |
| + } |
| + } |
| +} |
| + |
| +func TestAStaticTrueTypeUploadIsMeasuredAndDrawn(t *testing.T) { |
| + l := newLoader(map[string][]byte{ |
| + refRegular: libFile(t, "LiberationSerif-Regular.ttf"), |
| + refItalic: libFile(t, "LiberationSerif-Italic.ttf"), |
| + }) |
| + italic := regularFace(refItalic) |
| + italic.Italic = true |
| + d := uploadDeck(regularFace(refRegular), italic) |
| + |
| + r := layout.New(d, layout.Options{Fonts: l.load}) |
| + p, warnings, err := r.Layout(0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + noFontWarning(t, warnings) |
| + runs := runsOf(p) |
| + |
| + // Measured: the regular and italic runs are as wide as Liberation |
| + // Serif's own advances say, which is not what the fallback says. |
| + plain := runNamed(t, runs, "plain words") |
| + want := serifWidth(t, "LiberationSerif-Regular.ttf", plain.Size, plain.S) |
| + got, _ := fonts.Advance(plain.Face, plain.Size, plain.S) |
| + if math.Abs(got-want) > 1e-9 { |
| + t.Errorf("the regular run measures %v, want the upload's %v", got, want) |
| + } |
| + if sans, _ := fonts.Advance(fonts.Face{Family: fonts.Sans}, plain.Size, plain.S); math.Abs(sans-want) < 1 { |
| + t.Fatalf("the fallback measures %v and the upload %v: the test cannot tell them apart", sans, want) |
| + } |
| + bold := runNamed(t, runs, "bold") |
| + if math.Abs(bold.X-(plain.X+want)) > 1e-6 { |
| + t.Errorf("the run after the upload starts at %v, want %v (placed by the upload's advances)", bold.X, plain.X+want) |
| + } |
| + slanted := runNamed(t, runs, "slanted") |
| + if got, want := func() float64 { w, _ := fonts.Advance(slanted.Face, slanted.Size, slanted.S); return w }(), |
| + serifWidth(t, "LiberationSerif-Italic.ttf", slanted.Size, slanted.S); math.Abs(got-want) > 1e-9 { |
| + t.Errorf("the italic run measures %v, want the italic upload's %v", got, want) |
| + } |
| + // Bold has no uploaded face: it is the next family in the stack. |
| + if got, want := func() float64 { w, _ := fonts.Advance(bold.Face, bold.Size, bold.S); return w }(), |
| + func() float64 { |
| + w, _ := fonts.Advance(fonts.Face{Family: fonts.Sans, Bold: true}, bold.Size, bold.S) |
| + return w |
| + }(); got != want { |
| + t.Errorf("the bold run measures %v, want Liberation Sans Bold's %v", got, want) |
| + } |
| + |
| + // Drawn: the SVG names the uploaded family first, then the |
| + // fallback, on the runs set in it, and only the fallback elsewhere. |
| + spans := tspans(t, svg.Encode(p, svg.Options{})) |
| + for _, c := range []struct{ run, family string }{ |
| + {"plain words", uploadStack()}, |
| + {"slanted", uploadStack()}, |
| + {"bold", sansStack}, |
| + {"Heading", sansStack}, |
| + {"code", fonts.Mono.Stack()}, |
| + } { |
| + if got := spanNamed(t, spans, c.run).attrs["font-family"]; got != c.family { |
| + t.Errorf("%q is drawn in %q, want %q", c.run, got, c.family) |
| + } |
| + } |
| + sp := spanNamed(t, spans, "bold") |
| + x, _ := strconv.ParseFloat(sp.attrs["x"], 64) |
| + if math.Abs(x-(plain.X+want)) > 0.01 { |
| + t.Errorf("the picture places the run after the upload at %v, want %v", x, plain.X+want) |
| + } |
| + |
| + // One render reads and parses each face at most once, however many |
| + // times it lays out. |
| + if _, _, err := r.Layout(0); err != nil { |
| + t.Fatal(err) |
| + } |
| + for ref, n := range l.reads { |
| + if n > 1 { |
| + t.Errorf("face %s was read %d times in one render", ref[:8], n) |
| + } |
| + } |
| + if len(r.Uploaded()) != 2 { |
| + t.Errorf("the render used %d uploaded faces, want 2", len(r.Uploaded())) |
| + } |
| +} |
| + |
| +// fallsBack lays out uploadDeck(faces) with files and asserts every run |
| +// is in the fallback, the picture never names the upload, and nothing |
| +// warns about it. |
| +func fallsBack(t *testing.T, files map[string][]byte, faces ...deck.FontFace) { |
| + t.Helper() |
| + r := layout.New(uploadDeck(faces...), layout.Options{Fonts: newLoader(files).load}) |
| + p, warnings, err := r.Layout(0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + noFontWarning(t, warnings) |
| + for _, run := range runsOf(p) { |
| + if run.Face.Upload() != nil { |
| + t.Errorf("%q is set in the upload", run.S) |
| + } |
| + } |
| + for _, sp := range tspans(t, svg.Encode(p, svg.Options{})) { |
| + if strings.Contains(sp.attrs["font-family"], uploadCSS) { |
| + t.Errorf("%q names the upload: %q", sp.text, sp.attrs["font-family"]) |
| + } |
| + } |
| + if n := len(r.Uploaded()); n != 0 { |
| + t.Errorf("the render used %d uploaded faces, want none", n) |
| + } |
| +} |
| + |
| +func TestAVariableFontFallsBackInPicturesAndPDF(t *testing.T) { |
| + serif := libFile(t, "LiberationSerif-Regular.ttf") |
| + t.Run("marked", func(t *testing.T) { |
| + face := deck.FontFace{Ref: refRegular, Format: "ttf", Weight: [2]int{100, 900}} |
| + fallsBack(t, map[string][]byte{refRegular: serif}, face) |
| + }) |
| + t.Run("marked for pictures by hand", func(t *testing.T) { |
| + fallsBack(t, map[string][]byte{refRegular: withTable(t, serif, "fvar", make([]byte, 16))}, regularFace(refRegular)) |
| + }) |
| +} |
| + |
| +func TestARestrictedFontFallsBack(t *testing.T) { |
| + serif := libFile(t, "LiberationSerif-Regular.ttf") |
| + t.Run("marked", func(t *testing.T) { |
| + face := regularFace(refRegular) |
| + face.Pictures = false |
| + fallsBack(t, map[string][]byte{refRegular: serif}, face) |
| + }) |
| + t.Run("marked for pictures by hand", func(t *testing.T) { |
| + for _, fsType := range []uint16{0x0002, 0x0100, 0x0200} { |
| + fallsBack(t, map[string][]byte{refRegular: withFsType(t, serif, fsType)}, regularFace(refRegular)) |
| + } |
| + }) |
| +} |
| + |
| +func TestAWOFF2FallsBack(t *testing.T) { |
| + woff2 := append([]byte("wOF2\x00\x01\x00\x00"), make([]byte, 64)...) |
| + t.Run("marked", func(t *testing.T) { |
| + fallsBack(t, map[string][]byte{refRegular: woff2}, |
| + deck.FontFace{Ref: refRegular, Format: "woff2", Weight: [2]int{400, 400}}) |
| + }) |
| + t.Run("marked for pictures by hand", func(t *testing.T) { |
| + face := regularFace(refRegular) |
| + face.Format = "woff2" |
| + fallsBack(t, map[string][]byte{refRegular: woff2}, face) |
| + }) |
| +} |
| + |
| +func TestAnUploadThatDoesNotLoadFallsBack(t *testing.T) { |
| + fallsBack(t, nil, regularFace(refRegular)) |
| + // No loader at all (no object store): the same. |
| + r := layout.New(uploadDeck(regularFace(refRegular)), layout.Options{}) |
| + _, warnings, err := r.Layout(0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + noFontWarning(t, warnings) |
| +} |
| + |
| +// A family that is neither in this build nor uploaded to the deck is |
| +// still the warning it always was. |
| +func TestAFamilyNeitherBuiltInNorUploadedStillWarns(t *testing.T) { |
| + d := uploadDeck(regularFace(refRegular)) |
| + d.Meta.Fonts = &deck.Fonts{Heading: "'Elsewhere Sans', Liberation Sans", Body: "'" + uploadCSS + "', 'Elsewhere Sans', serif"} |
| + r := layout.New(d, layout.Options{Fonts: newLoader(nil).load}) |
| + _, warnings, err := r.Layout(0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var details []string |
| + for _, w := range warnings { |
| + if w.Kind == layout.WarnFont { |
| + details = append(details, w.Detail) |
| + } |
| + } |
| + sort.Strings(details) |
| + if len(details) != 2 || !strings.Contains(details[0], "Elsewhere Sans") || !strings.Contains(details[1], "Elsewhere Sans") { |
| + t.Errorf("want one warning per stack naming Elsewhere Sans, got %q", details) |
| + } |
| + for _, d := range details { |
| + if strings.Contains(d, uploadCSS) { |
| + t.Errorf("a warning names the uploaded family: %q", d) |
| + } |
| + } |
| +} |
| + |
| +// withTable is a TrueType file with one more table in it. |
| +func withTable(t *testing.T, data []byte, tag string, body []byte) []byte { |
| + t.Helper() |
| + n := int(binary.BigEndian.Uint16(data[4:])) |
| + type rec struct { |
| + tag string |
| + body []byte |
| + } |
| + var recs []rec |
| + for i := 0; i < n; i++ { |
| + at := 12 + i*16 |
| + off := binary.BigEndian.Uint32(data[at+8:]) |
| + length := binary.BigEndian.Uint32(data[at+12:]) |
| + recs = append(recs, rec{string(data[at : at+4]), data[off : off+length]}) |
| + } |
| + recs = append(recs, rec{tag, body}) |
| + sort.Slice(recs, func(i, j int) bool { return recs[i].tag < recs[j].tag }) |
| + head := make([]byte, 12+16*len(recs)) |
| + copy(head, data[:4]) |
| + binary.BigEndian.PutUint16(head[4:], uint16(len(recs))) |
| + var bodyBytes []byte |
| + for i, r := range recs { |
| + at := 12 + i*16 |
| + copy(head[at:], r.tag) |
| + binary.BigEndian.PutUint32(head[at+8:], uint32(len(head)+len(bodyBytes))) |
| + binary.BigEndian.PutUint32(head[at+12:], uint32(len(r.body))) |
| + bodyBytes = append(bodyBytes, r.body...) |
| + for len(bodyBytes)%4 != 0 { |
| + bodyBytes = append(bodyBytes, 0) |
| + } |
| + } |
| + return append(head, bodyBytes...) |
| +} |
| + |
| +// withFsType is a TrueType file whose OS/2 embedding flags are fsType. |
| +func withFsType(t *testing.T, data []byte, fsType uint16) []byte { |
| + t.Helper() |
| + out := append([]byte(nil), data...) |
| + n := int(binary.BigEndian.Uint16(out[4:])) |
| + for i := 0; i < n; i++ { |
| + at := 12 + i*16 |
| + if string(out[at:at+4]) == "OS/2" { |
| + off := binary.BigEndian.Uint32(out[at+8:]) |
| + binary.BigEndian.PutUint16(out[off+8:], fsType) |
| + return out |
| + } |
| + } |
| + t.Fatal("no OS/2 table") |
| + return nil |
| +} |
| + |
| +// A bold upload sets the heading, which is bold. |
| +func TestAnUploadedBoldFaceSetsTheHeading(t *testing.T) { |
| + bold := regularFace(refItalic) |
| + bold.Weight = [2]int{700, 700} |
| + l := newLoader(map[string][]byte{refItalic: libFile(t, "LiberationSerif-Bold.ttf")}) |
| + p, _, err := layout.New(uploadDeck(bold), layout.Options{Fonts: l.load}).Layout(0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + runs := runsOf(p) |
| + h := runNamed(t, runs, "Heading") |
| + if u := h.Face.Upload(); u == nil || u.Weight != 700 { |
| + t.Fatalf("the heading is not set in the bold upload") |
| + } |
| + if runNamed(t, runs, "plain words").Face.Upload() != nil { |
| + t.Error("regular text is set in the bold upload") |
| + } |
| + if got := spanNamed(t, tspans(t, svg.Encode(p, svg.Options{})), "Heading").attrs["font-family"]; got != uploadStack() { |
| + t.Errorf("the heading is drawn in %q", got) |
| + } |
| +} |
diff --git a/internal/slides/svg/svg.go b/internal/slides/svg/svg.go| index 627f8de..9e92074 100644 |
| --- a/internal/slides/svg/svg.go |
| +++ b/internal/slides/svg/svg.go |
| @@ -246,6 +246,10 @@ func (w *writer) arrowhead(stroke layout.Fill) string { |
| // xml:space="preserve" because a run's trailing space is layout: "the " |
| // followed by "spec" is a word gap, and an XML processor is otherwise |
| // entitled to collapse it. |
| +// |
| +// font-family is the face's Stack: a run set in a deck's uploaded font |
| +// names that family first, which is also the name the export renames |
| +// the font to before handing it to the PDF module (fonts.Renamed). |
| func (w *writer) text(t layout.Text) { |
| runs := make([]layout.Run, 0, len(t.Runs)) |
| for _, r := range t.Runs { |
| @@ -261,7 +265,7 @@ func (w *writer) text(t layout.Text) { |
| for _, r := range runs { |
| attrs := []string{ |
| attr("x", num(x)), |
| - attr("font-family", esc(r.Face.Family.Stack())), |
| + attr("font-family", esc(r.Face.Stack())), |
| attr("font-size", num(r.Size)), |
| } |
| if r.Face.Bold { |
diff --git a/internal/slides/thumbs.go b/internal/slides/thumbs.go| index 682da0b..d51a318 100644 |
| --- a/internal/slides/thumbs.go |
| +++ b/internal/slides/thumbs.go |
| @@ -186,7 +186,7 @@ func (a *app) serveThumb(w http.ResponseWriter, r *http.Request, d Deck, base st |
| // shows it carries the same words in its alt, because an alt is what a |
| // browser reads and it never opens the file to find a title. |
| func (a *app) thumbnail(r *http.Request, d Deck, view *deck.Deck, index int, base string) ([]byte, error) { |
| - paint, warnings, err := layout.Layout(view, index) |
| + paint, warnings, err := layout.New(view, layout.Options{Fonts: a.fontLoader(r.Context())}).Layout(index) |
| if err != nil { |
| return nil, err |
| } |