/// <summary> /// Ensures this structure contains valid data. /// </summary> /// <param name="font">The <see cref="TinyFont"/> containing this appendix.</param> public override void Update(TinyFont font) { UpdateAssert(_setsData.Count <= ushort.MaxValue, "Too many metadata sets."); UpdateAssert(_setsData.Count == _setsOffsets.ItemsCount, "Metadata set offset count mismatch."); SortedDictionary <MetadataSetOffset, byte[]> sortedSets = new SortedDictionary <MetadataSetOffset, byte[]>(); for (int i = 0; i < _setsOffsets.ItemsCount; i++) { sortedSets.Add(_setsOffsets[i], _setsData[i]); } _setsOffsets.Clear(); _setsOffsets.AddRange(sortedSets.Keys); _setsData.Clear(); _setsData.AddRange(sortedSets.Values); int offset = 0; for (int i = 0; i < _setsData.Count; i++) { UpdateAssert(offset <= ushort.MaxValue, "Too large metadata set."); _setsOffsets[i].Offset = (ushort)offset; offset += _setsData[i].Length; } _setsOffsets.Sentinel.Id = 0xFF; _setsOffsets.Sentinel.Offset = offset; }
/// <summary> /// Ensures this structure contains valid data. /// </summary> /// <param name="font">Tiny Font containing this appendix.</param> public override void Update(TinyFont font) { UpdateAssert(_features.ItemsCount <= ushort.MaxValue, "Too many features."); UpdateAssert(_features.ItemsCount == _featureOffsets.ItemsCount, "Feature offset count mismatch."); UpdateAssert(_parametersHeap == null || _parametersHeap.Length <= ushort.MaxValue, "The parameters heap is too large."); _featureCount = (ushort)_features.ItemsCount; _heapSize = (ushort)(_parametersHeap == null ? 0 : _parametersHeap.Length); for (int i = 0; i < _features.ItemsCount; i++) { _features[i].Update(); } _features.Sentinel.StateCount = 0; _features.Sentinel.Rules.Clear(); _features.Sentinel.StateOffsets.Clear(); _features.Sentinel.StateOffsets.Sentinel = 0; SortedDictionary <FeatureOffset, Feature> sortedFeatures = new SortedDictionary <FeatureOffset, Feature>(); for (int i = 0; i < _featureCount; i++) { sortedFeatures.Add(_featureOffsets[i], _features[i]); } _featureOffsets.Clear(); _featureOffsets.AddRange(sortedFeatures.Keys); _features.Clear(); _features.AddRange(sortedFeatures.Values); int offset = 0; for (int i = 0; i < _features.Count; i++) { UpdateAssert(offset <= ushort.MaxValue, "Too large feature."); _featureOffsets[i].Offset = (ushort)offset; offset += _features[i].GetSize(); } _featureOffsets.Sentinel.Tag = 0xFFFFFFFF; }