| 1 | // Copyright 2014 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | //go:build linux || darwin |
| 6 | |
| 7 | package fontscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/font`/ |
| 8 | |
| 9 | import ( |
| 10 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 11 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 12 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 13 | ) |
| 14 | |
| 15 | func looksLikeATTFscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/font`/looksLikeATTF().(b []byte) error { |
| 16 | if len(b) < 256 { |
| 17 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("not a TTF: not enough data") |
| 18 | } |
| 19 | b = b[:256] |
| 20 | |
| 21 | // Look for the 4-byte magic header. See |
| 22 | // http://www.microsoft.com/typography/otspec/otff.htm |
| 23 | switch string(b[:4]) { |
| 24 | case "\x00\x01\x00\x00", "ttcf": |
| 25 | // No-op. |
| 26 | default: |
| 27 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("not a TTF: missing magic header") |
| 28 | } |
| 29 | |
| 30 | // Look for a glyf table. |
| 31 | if i := bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Indexscip-go gomod github.com/golang/go/src go1.24.0 bytes/Index().(b, []byte("glyf")); i < 0 { |
| 32 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`not a TTF: missing "glyf" table`) |
| 33 | } else if i%0x10 != 0x0c { |
| 34 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`not a TTF: invalid "glyf" offset 0x%02x`, i) |
| 35 | } |
| 36 | return nil |
| 37 | } |
| 38 | |
| 39 | func TestLoadDefaultscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/font`/TestLoadDefault().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 40 | def, err := buildDefaultscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/font`/buildDefault().() |
| 41 | if err != nil { |
| 42 | t.Skipscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Skip().("default font not found") |
| 43 | } |
| 44 | if err := looksLikeATTFscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/font`/looksLikeATTF().(def); err != nil { |
| 45 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("default font: %v", err) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func TestLoadMonospacescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/font`/TestLoadMonospace().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 50 | mono, err := buildMonospacescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/font`/buildMonospace().() |
| 51 | if err != nil { |
| 52 | t.Skipscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Skip().("mono font not found") |
| 53 | } |
| 54 | if err := looksLikeATTFscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/font`/looksLikeATTF().(mono); err != nil { |
| 55 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("monospace font: %v", err) |
| 56 | } |
| 57 | } |