Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions font.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func LoadFont(data []byte) (*Font, error) {
// The face is sized to the em, so AdvanceIndexUnits returns advances in font
// units — exactly what a PDF /W width array wants — at the base (uninstanced)
// design.
// opentype accepts a font with no character map; pdfkit cannot. Every text
// call resolves runes through Font.GlyphIndex, so a font without a 'cmap'
// maps nothing and would silently draw a page of blanks. The requirement is
// pdfkit's own and is stated here, rather than borrowed from however strict
// the parser happens to be.
if _, ok := ot.Table("cmap"); !ok {
return nil, fmt.Errorf("pdfkit: parse font: no cmap table, the font maps no characters")
}

face := ot.NewFace(ot.UnitsPerEm())

name := ""
Expand Down
5 changes: 3 additions & 2 deletions font_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ func TestLoadFontErrors(t *testing.T) {
if _, err := LoadFont([]byte("not a font")); err == nil {
t.Error("expected opentype parse error")
}
// A valid sfnt container missing cmap: opentype (which requires a cmap)
// rejects it, covering LoadFont's error branch.
// A valid sfnt container missing cmap. opentype used to reject this and the
// test leaned on that; since it became optional upstream, LoadFont makes the
// check itself, because pdfkit resolves every rune through the cmap.
if _, err := LoadFont(synthTTF(synthOpts{noCmap: true})); err == nil {
t.Error("expected opentype parse error for missing cmap")
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module github.com/go-pdfkit/pdfkit

go 1.26.4

require github.com/go-opentype/opentype v0.6.0
require github.com/go-opentype/opentype v0.12.0

require (
github.com/go-widgets/painter v0.11.0
github.com/go-widgets/toolkit v0.288.0
github.com/go-widgets/painter v0.12.0
github.com/go-widgets/toolkit v0.289.0
rsc.io/pdf v0.1.1
)

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-opentype/fonts v0.8.0 h1:77i3VPIH90GbstzNb21mk+an4WvEOe2idC6W+J0n0fw=
github.com/go-opentype/fonts v0.8.0/go.mod h1:C6yQL2apHItfEZ5hztpsHF0S5mlX/hklLlq/Z5fRG/g=
github.com/go-opentype/opentype v0.6.0 h1:2t1Qs/Uo4M+f9gahV5QGihLTTeI/q4s0l7MIsbkd290=
github.com/go-opentype/opentype v0.6.0/go.mod h1:AOixevJf7XQaH7+WG+OMIOZEbYPXfMqklVk26Y6YTUU=
github.com/go-opentype/opentype v0.12.0 h1:wBlcDi+3ZaNZXEt5z+Ixr11/cYYwi5W+jX6yTl/qr1I=
github.com/go-opentype/opentype v0.12.0/go.mod h1:AOixevJf7XQaH7+WG+OMIOZEbYPXfMqklVk26Y6YTUU=
github.com/go-opentype/shape v0.5.0 h1:jHNaOMHNBdDj5EixOevlrrsi92svMxvVMKN7GYaPfxo=
github.com/go-opentype/shape v0.5.0/go.mod h1:3ImRYNIj6zpwWQ/DV3BWhgMFfmzDITH6XpZw2auQHTo=
github.com/go-richdoc/richdoc v0.2.0 h1:z9cLox9MoInZL6fIlweMzgDT/VqgnB2ZucSIEaRFglY=
Expand All @@ -30,10 +30,10 @@ github.com/go-typeset/bidi v0.3.0 h1:4fjGjejvjE2LzLNzY4si8PkVO321NcsKIiANhWT3jF4
github.com/go-typeset/bidi v0.3.0/go.mod h1:ct3cmYT8Qt1FGJQ+2QaakrUxqaP4ZysgdQQg2ym5+Xo=
github.com/go-widgets/mvvm v0.5.0 h1:o5hh6HAxbApONcbZxmyV9q12pCAPGRd6L24aS3gaCbA=
github.com/go-widgets/mvvm v0.5.0/go.mod h1:Phdrd434RLxXW1D6dL1PPQH1tABwYLIN2X7jQVC4TbY=
github.com/go-widgets/painter v0.11.0 h1:xsj4zTz8B43rOZnWrx7ZsaUBMgJyvgaE/Pq2FfcG2Sw=
github.com/go-widgets/painter v0.11.0/go.mod h1:IPRLqdUJuJX8sfuHeYLZCzjoLvA0ApbOlyIAVmguJDQ=
github.com/go-widgets/toolkit v0.288.0 h1:vtQDXZAbZRSQqIoEYQf/xE8ARE4YV4QtfHGHgnKP6NM=
github.com/go-widgets/toolkit v0.288.0/go.mod h1:IaRQFcV6FjxwzGXpHd3dpEoWZ+82f7dMPwtEZSH4nIg=
github.com/go-widgets/painter v0.12.0 h1:gMqTVbIbGSKmaE28NKsbbKdNIk2drupNMNuLjFP6T6I=
github.com/go-widgets/painter v0.12.0/go.mod h1:IPRLqdUJuJX8sfuHeYLZCzjoLvA0ApbOlyIAVmguJDQ=
github.com/go-widgets/toolkit v0.289.0 h1:iVbye2D7YMAkUOcJOXYNZKXqyeOmnxtRhdzEBlbBcz8=
github.com/go-widgets/toolkit v0.289.0/go.mod h1:IaRQFcV6FjxwzGXpHd3dpEoWZ+82f7dMPwtEZSH4nIg=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
Expand Down