|
1 | 1 | package tables |
2 | 2 |
|
3 | | -import "fmt" |
4 | | - |
5 | | -func ParseCPAL(src []byte) (CPAL1, error) { |
6 | | - header, _, err := parseCpal0(src) |
7 | | - if err != nil { |
8 | | - return CPAL1{}, err |
9 | | - } |
10 | | - switch header.Version { |
11 | | - case 0: |
12 | | - return CPAL1{cpal0: header}, nil |
13 | | - case 1: |
14 | | - out, _, err := ParseCPAL1(src) |
15 | | - return out, err |
16 | | - default: |
17 | | - return CPAL1{}, fmt.Errorf("unsupported version for CPAL: %d", header.Version) |
18 | | - } |
19 | | -} |
20 | | - |
21 | 3 | // https://learn.microsoft.com/en-us/typography/opentype/spec/cpal |
22 | | -type cpal0 struct { |
| 4 | +// |
| 5 | +// For now, only the CPAL version 0 is supported. |
| 6 | +type CPAL struct { |
23 | 7 | Version uint16 // Table version number |
24 | 8 | numPaletteEntries uint16 // Number of palette entries in each palette. |
25 | 9 | numPalettes uint16 // Number of palettes in the table. |
26 | 10 | numColorRecords uint16 // Total number of color records, combined for all palettes. |
27 | | - ColorRecordsArray []ColorRecord `arrayCount:"ComputedField-numColorRecords" offsetSize:"Offset32"` // Offset from the beginning of CPAL table to the first ColorRecord. |
28 | | - ColorRecordIndices []uint16 `arrayCount:"ComputedField-numPalettes"` //[numPalettes] Index of each palette’s first color record in the combined color record array. |
29 | | -} |
30 | | - |
31 | | -type CPAL1 struct { |
32 | | - cpal0 |
33 | | - paletteTypesArrayOffset Offset32 // Offset from the beginning of CPAL table to the Palette Types Array. Set to 0 if no array is provided. |
34 | | - paletteLabelsArrayOffset Offset32 // Offset from the beginning of CPAL table to the Palette Labels Array. Set to 0 if no array is provided. |
35 | | - paletteEntryLabelsArrayOffset Offset32 // Offset from the beginning of CPAL table to the Palette Entry Labels Array. Set to 0 if no array is provided. |
| 11 | + ColorRecordsArray []ColorRecord `arrayCount:"ComputedField-numColorRecords" offsetSize:"Offset32"` // Offset from the beginning of CPAL table to the first ColorRecord. |
| 12 | + ColorRecordIndices []uint16 `arrayCount:"ComputedField-numPalettes"` // [numPalettes] Index of each palette’s first color record in the combined color record array. |
36 | 13 | } |
37 | 14 |
|
38 | 15 | type ColorRecord struct { |
|
0 commit comments