public static ColrTable Load(BigEndianBinaryReader reader) { // HEADER // Type | Name | Description // ----------|------------------------|---------------------------------------------------------------------------------------------------- // uint16 | version | Table version number(starts at 0). // uint16 | numBaseGlyphRecords | Number of Base Glyph Records. // Offset32 | baseGlyphRecordsOffset | Offset(from beginning of COLR table) to Base Glyph records. // Offset32 | layerRecordsOffset | Offset(from beginning of COLR table) to Layer Records. // uint16 | numLayerRecords | Number of Layer Records. // Base Glyph Record // Type | Name | Description // ----------|------------------------|---------------------------------------------------------------------------------------------------- // uint16 | gID | Glyph ID of reference glyph. This glyph is for reference only and is not rendered for color. // uint16 | firstLayerIndex | Index(from beginning of the Layer Records) to the layer record. There will be numLayers consecutive entries for this base glyph. // uint16 | numLayers | Number of color layers associated with this glyph. // Layer Record // Type | Name | Description // ----------|------------------------|---------------------------------------------------------------------------------------------------- // uint16 | gID | Glyph ID of layer glyph (must be in z-order from bottom to top). // uint16 | paletteIndex | Index value to use with a selected color palette. This value must be less than numPaletteEntries in // | | > the CPAL table. A palette entry index value of 0xFFFF is a special case indicating that the text // | | > foreground color (defined by a higher-level client) should be used and shall not be treated as // | | > actual index into CPAL ColorRecord array. var version = reader.ReadUInt16(); var numBaseGlyphRecords = reader.ReadUInt16(); var baseGlyphRecordsOffset = reader.ReadOffset32(); var layerRecordsOffset = reader.ReadOffset32(); var numLayerRecords = reader.ReadUInt16(); reader.Seek(baseGlyphRecordsOffset, System.IO.SeekOrigin.Begin); var glyphs = new BaseGlyphRecord[numBaseGlyphRecords]; var layers = new LayerRecord[numLayerRecords]; for (var i = 0; i < numBaseGlyphRecords; i++) { var gi = reader.ReadUInt16(); var idx = reader.ReadUInt16(); var num = reader.ReadUInt16(); glyphs[i] = new BaseGlyphRecord(gi, idx, num); } reader.Seek(layerRecordsOffset, System.IO.SeekOrigin.Begin); for (var i = 0; i < numLayerRecords; i++) { var gi = reader.ReadUInt16(); var pi = reader.ReadUInt16(); layers[i] = new LayerRecord(gi, pi); } return(new ColrTable(glyphs, layers)); }
public override UInt64 Validate(bool simpleValidationOnly) { /* See comments in OTTable regarding validation completion states and flags. * Assumed: this method does not re-do basic validations, and the completion * state flags can be set the same as on any prior call to the method. */ /* Base Base class constructor ran partial validations on the table record: * - table record tag matches type for this derived class * - table offset and length are within file bounds * - table record checksum == actual table checksum * * For simple validation, the following additional internal validation is * required: * - for each base glyph record: (firstLayerIndex + numLayers) is less * than or equal to numLayerRecords * * Simple validation does not validate various fields that require comparison * with other tables: * - gIDs in all base glyph records and all layer records are valid (compare to maxp or loca) * - paletteIndex in all layer records is valid (compare to 'CPAL') */ // validate layer fields in base glyph records for (uint i = 0; i < _numBaseGlyphRecords; i++) { BaseGlyphRecord bgr = _baseGlyphRecords[i]; if ((bgr.FirstLayerIndex + bgr.NumLayers) > _numLayerRecords) { // validate within the COLR table but not external to COLR byte bgr_val = bgr.Validate(_numLayerRecords); if ((bgr_val & OTFile.OTRecordValidation_ExternalValidationError) != 0) _validationStatus |= OTFile.OTFileValidation_StructureFieldsInternallyInvalid; } } // layer records have no additional COLR-internal validation // set completion state for all COLR-internal validation _validationStatus &= ~OTFile.OTFileValidation_PartialValidation; _validationStatus |= OTFile.OTFileValidation_InternalValidationOnly; if (!simpleValidationOnly) { // TO DO: implement this!! } return _validationStatus; }