Esempio n. 1
0
        private void CreateStructure(Cwdh.WidthRegion firstReg)
        {
            // CGLP
            // ... gets the glyphs in a array
            Colour[][,] glyphs = new Colour[this.glyphs.Count][,];
            for (int i = 0; i < this.glyphs.Count; i++)
                glyphs[i] = this.glyphs[i].Image;

            this.cglp = new Cglp(this, glyphs, this.boxWidth, this.boxHeight,
                                 this.glyphWidth, this.glyphHeight, this.depth, this.rotation);
            //if (!cglp.Check())
            //	throw new InvalidDataException("Invalid data for CGLP.");
            this.Blocks.Add(cglp);

            // CWDH
            this.cwdh = new Cwdh(this, firstReg);
            //if (!cwdh.Check())
            //	throw new InvalidDataException("Invalid data for CWDH.");
            this.Blocks.Add(cwdh);

            // CMAP
            //for (int i = 0; i < this.cmaps.Length; i++)
            //	if (!this.cmaps[i].Check())
            //		throw new InvalidDataException("Invalid data for CMAP (" + i.ToString() + ")");
            this.Blocks.AddRange(this.cmaps);

            // FINF
            this.finf = new Finf(this);
            this.finf.Unknown        = 0;
            this.finf.LineGap        = this.lineGap;
            this.finf.ErrorCharIndex = this.errorChar;
            this.finf.DefaultWidth   = this.defaultWidth;
            this.finf.Encoding       = this.encoding;
            this.finf.GlyphWidth     = this.glyphWidth;
            this.finf.GlyphHeight    = this.glyphHeight;
            this.finf.BearingX       = this.defaultWidth.BearingX;
            this.finf.BearingY       = this.lineGap;
            this.finf.UpdateOffsets();
            //if (!finf.Check())
            //	throw new InvalidDataException("Invalid data for FINF.");
            this.Blocks.Insert(0, finf);
        }
Esempio n. 2
0
        protected override void Read(Stream strIn, int size)
        {
            base.Read(strIn, size);

            this.finf  = this.Blocks.GetByType<Finf>(0);
            this.cglp  = this.Blocks.GetByType<Cglp>(0);
            this.cwdh  = this.Blocks.GetByType<Cwdh>(0);
            this.cmaps = this.Blocks.GetByType<Cmap>().ToArray();

            this.errorChar    = this.finf.ErrorCharIndex;
            this.encoding     = this.finf.Encoding;
            this.lineGap      = this.finf.LineGap;
            this.defaultWidth = this.finf.DefaultWidth;
            this.glyphHeight  = this.cglp.GlyphHeight;
            this.glyphWidth   = this.cglp.GlyphWidth;
            this.boxWidth     = this.cglp.BoxWidth;
            this.boxHeight    = this.cglp.BoxHeight;
            this.depth        = this.cglp.Depth;
            this.rotation     = (RotationMode)this.cglp.Rotation;

            // Get glyphs info
            this.glyphs = new List<Glyph>();
            for (int i = 0, idx = 0; i < this.cglp.NumGlyphs; i++) {
                int idMap;
                ushort charCode = this.SearchCharByImage(i, out idMap);
                if (idMap == -1) {
                    this.cglp.GetGlyphImage(i).Save("Unvalid char " + i.ToString() + ".png");
                    continue;
                }

                Glyph g = new Glyph();
                g.Id       = idx++;
                g.Image    = this.cglp.GetGlyph(i);
                g.Width    = this.cwdh.GetWidth(charCode, g.Id);
                g.CharCode = charCode;
                g.IdMap    = idMap;

                this.glyphs.Add(g);
            }

            #if DEBUG
            this.PrintInfo();
            #endif
        }