/// <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;
        }
Beispiel #2
0
        private void ReadBasicFrom(BinaryReader reader)
        {
            _characterRanges.Clear();
            _characterRanges.Capacity = _description.Ranges;
            for (int i = 0; i < _description.Ranges; i++)
            {
                CharacterRangeDescription range = new CharacterRangeDescription();
                range.ReadFrom(reader);

                _characterRanges.Add(range);
            }
            _characterRanges.Sentinel = new CharacterRangeDescription();
            _characterRanges.Sentinel.ReadFrom(reader);

            _characters.Clear();
            _characters.Capacity = _description.Characters;
            for (int i = 0; i < _description.Characters; i++)
            {
                CharacterDescription character = new CharacterDescription();
                character.ReadFrom(reader);

                _characters.Add(character);
            }
            _characters.Sentinel = new CharacterDescription();
            _characters.Sentinel.ReadFrom(reader);

            int wordwidth = (int)((_characterBitmapDescription.Width * _characterBitmapDescription.BitsPerPixel + 31) / 32 * _characterBitmapDescription.Height * 4);

            _characterBitmapData = reader.ReadBytes(wordwidth);
        }
Beispiel #3
0
        /// <summary>
        /// Deserializes this structure from binary data.
        /// </summary>
        /// <param name="reader">The <see cref="BinaryReader"/> to read the data from.</param>
        /// <param name="font">Tiny Font containing this appendix.</param>
        /// <exception cref="ArgumentNullException"><paramref name="reader"/> is null.</exception>
        public override void ReadFrom(BinaryReader reader, TinyFont font)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            _featureCount = reader.ReadUInt16();
            _heapSize     = reader.ReadUInt16();

            _featureOffsets.Clear();
            _featureOffsets.Capacity = _featureCount;

            for (int i = 0; i < _featureCount; i++)
            {
                FeatureOffset offset = new FeatureOffset();
                offset.ReadFrom(reader);

                _featureOffsets.Add(offset);
            }

            _featureOffsets.Sentinel.ReadFrom(reader);

            _features.Clear();
            _features.Capacity = _featureCount;

            for (int i = 0; i < _featureCount; i++)
            {
                Feature feature = new Feature();
                feature.ReadFrom(reader);

                _features.Add(feature);
            }

            _features.Sentinel.ReadFrom(reader);

            if (_heapSize > 0)
            {
                _parametersHeap = reader.ReadBytes(_heapSize);
            }
        }
            /// <summary>
            /// Ensures this structure contains valid data.
            /// </summary>
            public void Update()
            {
                _stateCount = 0;
                _stateOffsets.Clear();
                _stateOffsets.Sentinel = 0;

                if (_rules.Count > 0)
                {
                    // It is critical for the sort algorithm to be stable, List.Sort resp. Array.Sort is not.
                    Rule[] sortedRules = Enumerable.OrderBy(_rules, r => r.RequiredState).ToArray();
                    _rules.Clear();
                    _rules.AddRange(sortedRules);

                    Dictionary <ushort, ushort> stateMapping = new Dictionary <ushort, ushort>(_stateOffsets.Count);
                    ushort lastUsedState     = ushort.MaxValue;
                    ushort lastRequiredState = (ushort)~_rules[0].RequiredState;

                    UpdateAssert(_rules.Count <= ushort.MaxValue, "Too many rules.");
                    _stateOffsets.Sentinel = (ushort)_rules.Count;

                    for (ushort i = 0; i < _rules.Count; i++)
                    {
                        if (_rules[i].RequiredState != lastRequiredState)
                        {
                            lastRequiredState       = _rules[i].RequiredState;
                            _rules[i].RequiredState = ++lastUsedState;

                            _stateOffsets.Add(i);

                            stateMapping[lastRequiredState] = _rules[i].RequiredState;
                        }
                        else
                        {
                            _rules[i].RequiredState = lastUsedState;
                        }
                    }

                    _stateCount = ++lastUsedState;
                    foreach (Rule rule in _rules)
                    {
                        if (stateMapping.ContainsKey(rule.NewState))
                        {
                            rule.NewState = stateMapping[rule.NewState];
                        }
                        else
                        {
                            rule.NewState = 0;
                        }
                    }
                }
            }