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); }
/// <summary> /// Gets a glyph from an image. /// </summary> /// <returns>The glyph</returns> /// <param name="img">Image with all glyphs drawn</param> /// <param name="glyphIdx">Glyph index.</param> /// <param name="charWidth">Char width.</param> /// <param name="charHeight">Char height.</param> /// <param name="numRows">Number of rows.</param> /// <param name="numColumns">Number of columns.</param> /// <param name="zoom">Zoom.</param> /// <param name="borderThickness">Border thickness.</param> private Colour[,] CharFromMap(Bitmap img, int glyphIdx, int charWidth, int charHeight, int numRows, int numColumns, int zoom, int borderThickness) { if (zoom != 1) throw new NotImplementedException(); int width = numColumns * charWidth + (numColumns + 1) * borderThickness; int height = numRows * charHeight + (numRows + 1) * borderThickness; if (width != img.Width || height != img.Height) { throw new ArgumentException("Incorrect image size."); } Colour[,] glyph = new Colour[charWidth, charHeight]; int column = glyphIdx % numColumns; int row = glyphIdx / numColumns; int startX = column * charWidth + (column + 1) * borderThickness; int startY = row * charHeight + (row + 1) * borderThickness; for (int x = startX, gx = 0; x < startX + charWidth; x += zoom, gx++) { for (int y = startY, gy = 0; y < startY + charHeight; y += zoom, gy++) { glyph[gx, gy] = Colour.FromColor(img.GetPixel(x, y)); } } return glyph; }