Example #1
0
            public void InsertWidth(ushort charCode, GlyphWidth width, int index)
            {
                if (!this.Contains(charCode)) {
                    if (this.NextRegion != null) {
                        this.NextRegion.InsertWidth(charCode, width, index);
                        return;
                    } else {
                        throw new ArgumentException("Invalid char code");
                    }
                }

                //int index = charCode - this.FirstChar;
                if (this.Widths.Length <= index) {
                    GlyphWidth[] widths = this.Widths;
                    Array.Resize(ref widths, index + 1);
                    this.Widths = widths;
                }

                this.Widths[index] = width;
            }
Example #2
0
            public static WidthRegion FromStream(Stream strIn, GlyphWidth defaultWidth)
            {
                BinaryReader br = new BinaryReader(strIn);
                long startPosition = strIn.Position;

                WidthRegion wr = new WidthRegion(defaultWidth);
                wr.FirstChar = br.ReadUInt16();
                wr.LastChar = br.ReadUInt16();
                uint nextRegion = br.ReadUInt32();

                // Read widths
                int numWidths = wr.LastChar - wr.FirstChar + 1;
                wr.Widths = new GlyphWidth[numWidths];

                for (int i = 0; i < numWidths; i++) {
                    wr.Widths[i] = GlyphWidth.FromStream(strIn, wr.Id);
                }

                br = null;

                // Get other regions
                if (nextRegion != 0) {
                    strIn.Position = startPosition + nextRegion;
                    wr.NextRegion = WidthRegion.FromStream(strIn, defaultWidth);
                } else {
                    wr.NextRegion = null;
                }

                return wr;
            }
Example #3
0
 public static GlyphWidth FromXml(XElement node)
 {
     GlyphWidth gw = new GlyphWidth();
     gw.IdRegion = Convert.ToInt32(node.Element("IdRegion").Value);
     gw.BearingX = Convert.ToByte(node.Element("BearingX").Value);
     gw.Width    = Convert.ToByte(node.Element("Width").Value);
     gw.Advance  = Convert.ToByte(node.Element("Advance").Value);
     return gw;
 }
Example #4
0
 public WidthRegion(GlyphWidth defaultWidth)
 {
     this.Id = IdWidth++;
     this.defaultWidth = defaultWidth;
     this.Widths = new GlyphWidth[0];
 }
Example #5
0
 public static GlyphWidth FromStream(Stream strIn, int idRegion)
 {
     GlyphWidth gw = new GlyphWidth();
     gw.IdRegion = idRegion;
     gw.BearingX = (byte)strIn.ReadByte();
     gw.Width    = (byte)strIn.ReadByte();
     gw.Advance  = (byte)strIn.ReadByte();
     return gw;
 }