Ejemplo n.º 1
0
        /// <summary>
        /// Repopulates the mappings from the given character set.
        /// </summary>
        /// <param name="characterSet">The character set to be read from.</param>
        /// <param name="codes">A list of all numerical encodings in the font, sorted by index.</param>
        public void ReadFrom(CharacterSet characterSet, IList <int> codes)
        {
            ushort code;
            ushort index;

            this.unknown = 0;
            this.mappings.Clear();
            IList <Character> chars = characterSet.Characters;

            this.type = characterSet.MapType;
            switch (this.MapType)
            {
            // Type 0: Codes and indices are assigned in ascending order
            case CharacterMapType.Range:
                this.startCode = (ushort)chars[0].Code;
                this.endCode   = (ushort)chars[chars.Count - 1].Code;
                for (int i = 0; i < chars.Count; i++)
                {
                    code  = (ushort)chars[i].Code;
                    index = (ushort)codes.IndexOf(code);
                    this.mappings.Add(code, index);
                }

                break;

            // Type 1: Codes are assigned in ascending order to the specified indices
            case CharacterMapType.List:
                this.startCode = (ushort)chars[0].Code;
                this.endCode   = (ushort)chars[chars.Count - 1].Code;
                code           = this.startCode;
                for (int i = 0; i < chars.Count; i++, code++)
                {
                    for (; chars[i].Code > code; code++)
                    {
                        this.mappings.Add(code, Blank);
                    }

                    index = (ushort)codes.IndexOf(code);
                    this.mappings.Add(code, index);
                }

                break;

            // Type 2: Codes and indices are assigned individually
            case CharacterMapType.Map:
                this.startCode = 0x0000;
                this.endCode   = 0xFFFF;
                for (int i = 0; i < chars.Count; i++)
                {
                    code  = (ushort)chars[i].Code;
                    index = (ushort)codes.IndexOf(code);
                    this.mappings.Add(code, index);
                }

                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the given character set to the font.
        /// The new set must not contain any characters with codes that already exist in the font.
        /// </summary>
        /// <param name="characterSet">The character set to add to the font.</param>
        public void AddCharacterSet(CharacterSet characterSet)
        {
            foreach (Character character in characterSet.Characters)
            {
                if (this.codeToChar.ContainsKey(character.Code))
                {
                    throw new ArgumentException("A character with code " + character.Code + " already exists in the font.");
                }
            }

            this.characterSets.Add(characterSet);
            this.RebuildIndices();
        }