Ejemplo n.º 1
0
        private void Load(CharacterMapChunk map, CharacterWidthChunk widths, CharacterGlyphChunk glyphs)
        {
            this.characters = new List <Character>(map.Mappings.Count);
            this.type       = map.MapType;

            foreach (int code in map.Mappings.Keys)
            {
                int index = map.Mappings[code];
                if (index != Blank)
                {
                    Character c = new Character(code, glyphs.Glyphs[index], widths.XOffsets[index], widths.Widths[index], widths.NextOffsets[index]);
                    this.characters.Add(c);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the font to its associated file.
        /// </summary>
        public void Save()
        {
            this.cglpChunk.ReadFrom(this);
            this.cwdhChunk.ReadFrom(this);

            this.finfChunk.GlyphSectionOffset = this.header.Size + this.finfChunk.Size;
            this.finfChunk.WidthSectionOffset = this.finfChunk.GlyphSectionOffset + this.cglpChunk.Size;
            this.finfChunk.MapSectionOffset   = this.finfChunk.WidthSectionOffset + this.cwdhChunk.Size;

            this.cmapChunks.Clear();
            int cmapOffset = this.finfChunk.MapSectionOffset;

            foreach (CharacterSet characterSet in this.characterSets)
            {
                CharacterMapChunk cmapChunk = new CharacterMapChunk();
                cmapChunk.ReadFrom(characterSet, this.codes);
                cmapOffset += cmapChunk.Size;
                cmapChunk.NextChunkOffset = cmapOffset;
                this.cmapChunks.Add(cmapChunk);
            }

            this.cmapChunks[this.cmapChunks.Count - 1].NextChunkOffset = 0;

            this.header.SectionCount = 3 + this.cmapChunks.Count;
            this.header.FileSize     = cmapOffset;

            MemoryStream contents = new MemoryStream();

            this.header.WriteTo(contents);
            this.finfChunk.WriteTo(contents);
            this.cglpChunk.WriteTo(contents);
            this.cwdhChunk.WriteTo(contents);
            for (int i = 0; i < this.cmapChunks.Count; i++)
            {
                this.cmapChunks[i].WriteTo(contents);
            }

            StreamHelper.WriteFile(this.fileName, contents.ToArray());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads the font from its associated file.
        /// </summary>
        public void Load()
        {
            byte[] fileData = StreamHelper.ReadFile(this.fileName);

            this.header = new NitroHeader("RTFN");
            this.header.ReadFrom(fileData, 0);

            this.finfChunk = new FontInfoSection();
            int finfOffset = this.header.Size;

            this.finfChunk.ReadFrom(fileData, finfOffset);

            this.cwdhChunk = new CharacterWidthChunk();
            this.cwdhChunk.ReadFrom(fileData, this.finfChunk.WidthSectionOffset);

            int characterCount = this.cwdhChunk.Widths.Count;

            this.cglpChunk = new CharacterGlyphChunk(characterCount);
            this.cglpChunk.ReadFrom(fileData, this.finfChunk.GlyphSectionOffset);

            int cmapCount  = this.header.SectionCount - 3;
            int cmapOffset = this.finfChunk.MapSectionOffset;

            this.cmapChunks    = new List <CharacterMapChunk>();
            this.characterSets = new List <CharacterSet>();
            for (int i = 0; i < cmapCount; i++)
            {
                CharacterMapChunk cmapChunk = new CharacterMapChunk();
                cmapChunk.ReadFrom(fileData, cmapOffset);
                cmapOffset = cmapChunk.NextChunkOffset;
                this.cmapChunks.Add(cmapChunk);
                this.characterSets.Add(new CharacterSet(cmapChunk, this.cwdhChunk, this.cglpChunk));
            }

            this.RebuildIndices();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the CharacterSet class by reading the appropriate chunks from the font.
 /// </summary>
 /// <param name="map">The map between characters and their numerical codes.</param>
 /// <param name="widths">The width and offset data for all characters in the font.</param>
 /// <param name="glyphs">The graphical glyphs for all characters in the font.</param>
 public CharacterSet(CharacterMapChunk map, CharacterWidthChunk widths, CharacterGlyphChunk glyphs)
 {
     this.Load(map, widths, glyphs);
 }