-
Notifications
You must be signed in to change notification settings - Fork 0
Add stub support for variable font tables #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
49b360a
d8039a1
b8b26c8
5756511
a9790ab
49c7b8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| font | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| ==== | ||
|
|
||
| [](https://travis-ci.org/ConradIrwin/font) [](https://godoc.org/github.com/ConradIrwin/font) | ||
|
|
||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [INFO] Info: Unrelated change Removing the Travis CI badge appears unrelated to adding variable font stubs. Consider keeping this change in a separate commit or PR for cleaner history, unless Travis CI is no longer used. |
||
| A collection of Go packages for parsing and encoding OpenType fonts. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,66 @@ func (font *Font) GsubTable() (*TableLayout, error) { | |
| return font.TableLayout(TagGsub) | ||
| } | ||
|
|
||
| // FvarTable returns the font variations table identified with the 'fvar' tag. | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| func (font *Font) FvarTable() (*TableFvar, error) { | ||
| t, err := font.Table(TagFvar) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return t.(*TableFvar), nil | ||
|
rohitkumbhar marked this conversation as resolved.
rohitkumbhar marked this conversation as resolved.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ERROR] Security/Correctness: Unsafe type assertion This uses an unsafe type assertion Recommendation: Use the safe two-value assertion pattern like fvar, ok := t.(*TableFvar)
if !ok {
return nil, fmt.Errorf("table %q is not an fvar table", tag)
}
return fvar, nilThis pattern is already used in |
||
| } | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
|
|
||
| // AvarTable returns the axis variations table identified with the 'avar' tag. | ||
| func (font *Font) AvarTable() (*TableAvar, error) { | ||
| t, err := font.Table(TagAvar) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return t.(*TableAvar), nil | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ERROR] Security/Correctness: Unsafe type assertion Same issue as FvarTable() - uses unsafe type assertion that will panic on type mismatch. See comment on line 176 for recommended fix pattern. |
||
| } | ||
|
|
||
|
rohitkumbhar marked this conversation as resolved.
|
||
| // GvarTable returns the glyph variations table identified with the 'gvar' tag. | ||
| func (font *Font) GvarTable() (*TableGvar, error) { | ||
| t, err := font.Table(TagGvar) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return t.(*TableGvar), nil | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ERROR] Security/Correctness: Unsafe type assertion Same issue as FvarTable() - uses unsafe type assertion that will panic on type mismatch. See comment on line 176 for recommended fix pattern. |
||
| } | ||
|
|
||
| // StatTable returns the style attributes table identified with the 'STAT' tag. | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| func (font *Font) StatTable() (*TableStat, error) { | ||
| t, err := font.Table(TagStat) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return t.(*TableStat), nil | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ERROR] Security/Correctness: Unsafe type assertion Same issue as FvarTable() - uses unsafe type assertion that will panic on type mismatch. See comment on line 176 for recommended fix pattern. |
||
| } | ||
|
|
||
| // HvarTable returns the horizontal metrics variations table identified with the 'HVAR' tag. | ||
| func (font *Font) HvarTable() (*TableHvar, error) { | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| t, err := font.Table(TagHvar) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return t.(*TableHvar), nil | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ERROR] Security/Correctness: Unsafe type assertion Same issue as FvarTable() - uses unsafe type assertion that will panic on type mismatch. See comment on line 176 for recommended fix pattern. |
||
| } | ||
|
|
||
| // MvarTable returns the metrics variations table identified with the 'MVAR' tag. | ||
| func (font *Font) MvarTable() (*TableMvar, error) { | ||
| t, err := font.Table(TagMvar) | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return t.(*TableMvar), nil | ||
|
rohitkumbhar marked this conversation as resolved.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ERROR] Security/Correctness: Unsafe type assertion Same issue as FvarTable() - uses unsafe type assertion that will panic on type mismatch. See comment on line 176 for recommended fix pattern. |
||
| } | ||
|
|
||
| // IsVariable returns true if this font contains an 'fvar' table, | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| // indicating it is a variable font. | ||
| func (font *Font) IsVariable() bool { | ||
| return font.HasTable(TagFvar) | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| } | ||
|
|
||
| func (font *Font) Table(tag Tag) (Table, error) { | ||
| s, found := font.tables[tag] | ||
| if !found { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package sfnt | ||
|
|
||
| // TableAvar contains the axis variations table, which provides | ||
| // optional fine-tuning of the variation space by remapping axis values. | ||
| // See https://learn.microsoft.com/en-us/typography/opentype/spec/avar | ||
| type TableAvar struct { | ||
| baseTable | ||
| bytes []byte | ||
| } | ||
|
|
||
| func parseTableAvar(tag Tag, buf []byte) (Table, error) { | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| return &TableAvar{ | ||
| baseTable: baseTable(tag), | ||
| bytes: buf, | ||
| }, nil | ||
| } | ||
|
|
||
| func (t *TableAvar) Bytes() []byte { | ||
| return t.bytes | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package sfnt | ||
|
|
||
| // TableFvar contains the font variations table, which defines the | ||
| // variation axes and named instances for a variable font. | ||
| // See https://learn.microsoft.com/en-us/typography/opentype/spec/fvar | ||
| type TableFvar struct { | ||
| baseTable | ||
| bytes []byte | ||
| } | ||
|
|
||
| func parseTableFvar(tag Tag, buf []byte) (Table, error) { | ||
|
rohitkumbhar marked this conversation as resolved.
rohitkumbhar marked this conversation as resolved.
rohitkumbhar marked this conversation as resolved.
|
||
| return &TableFvar{ | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [INFO] Info: Parser does not validate table data The parser accepts any byte slice without validation. While this matches the stub implementation pattern, consider adding basic validation in future iterations:
This is acceptable for a stub implementation but should be tracked for future work. |
||
| baseTable: baseTable(tag), | ||
| bytes: buf, | ||
| }, nil | ||
| } | ||
|
|
||
| func (t *TableFvar) Bytes() []byte { | ||
| return t.bytes | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package sfnt | ||
|
|
||
| // TableGvar contains the glyph variations table, which defines | ||
| // how TrueType glyph outlines vary across the font's variation axes. | ||
| // See https://learn.microsoft.com/en-us/typography/opentype/spec/gvar | ||
| type TableGvar struct { | ||
| baseTable | ||
| bytes []byte | ||
| } | ||
|
|
||
| func parseTableGvar(tag Tag, buf []byte) (Table, error) { | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| return &TableGvar{ | ||
| baseTable: baseTable(tag), | ||
| bytes: buf, | ||
| }, nil | ||
| } | ||
|
|
||
| func (t *TableGvar) Bytes() []byte { | ||
| return t.bytes | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package sfnt | ||
|
|
||
| // TableHvar contains the horizontal metrics variations table, which | ||
| // describes how horizontal glyph metrics vary across variation axes. | ||
| // See https://learn.microsoft.com/en-us/typography/opentype/spec/hvar | ||
| type TableHvar struct { | ||
| baseTable | ||
| bytes []byte | ||
| } | ||
|
|
||
| func parseTableHvar(tag Tag, buf []byte) (Table, error) { | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| return &TableHvar{ | ||
| baseTable: baseTable(tag), | ||
| bytes: buf, | ||
| }, nil | ||
| } | ||
|
|
||
| func (t *TableHvar) Bytes() []byte { | ||
| return t.bytes | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package sfnt | ||
|
|
||
| // TableMvar contains the metrics variations table, which describes | ||
| // how font-wide metrics vary across the font's variation axes. | ||
| // See https://learn.microsoft.com/en-us/typography/opentype/spec/mvar | ||
| type TableMvar struct { | ||
| baseTable | ||
| bytes []byte | ||
| } | ||
|
|
||
| func parseTableMvar(tag Tag, buf []byte) (Table, error) { | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| return &TableMvar{ | ||
| baseTable: baseTable(tag), | ||
| bytes: buf, | ||
| }, nil | ||
| } | ||
|
|
||
| func (t *TableMvar) Bytes() []byte { | ||
| return t.bytes | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package sfnt | ||
|
|
||
| // TableStat contains the style attributes table, which describes | ||
|
rohitkumbhar marked this conversation as resolved.
|
||
| // design axes and their values for variable and non-variable fonts. | ||
| // Required for variable fonts. | ||
| // See https://learn.microsoft.com/en-us/typography/opentype/spec/stat | ||
| type TableStat struct { | ||
| baseTable | ||
| bytes []byte | ||
| } | ||
|
|
||
|
rohitkumbhar marked this conversation as resolved.
|
||
| func parseTableStat(tag Tag, buf []byte) (Table, error) { | ||
| return &TableStat{ | ||
| baseTable: baseTable(tag), | ||
| bytes: buf, | ||
| }, nil | ||
| } | ||
|
|
||
| func (t *TableStat) Bytes() []byte { | ||
| return t.bytes | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.