/* * write font byte declarations */ override protected void WriteFontBytes() { string str; bool[,] values; byte b, bitpos; int x, y; _sourceWriter.Write(" // byte definitions for " + _font.Identifier + "\n\n"); foreach (char c in _font.Characters()) { str = GetBytesName(c); _sourceWriter.Write(" const uint8_t __attribute__((progmem)) " + str + "[] PROGMEM={ "); values = FontUtil.GetCharacterBitmap(_refControl, _font.GdiFont, c, _font.XOffset, _font.YOffset, _font.ExtraLines); b = 0; bitpos = 0; for (y = 0; y < values.GetLength(1); y++) { for (x = 0; x < values.GetLength(0); x++) { if (values[x, y]) { b |= (byte)(1 << bitpos); } if (bitpos++ == 7) { _sourceWriter.Write(b.ToString() + ","); bitpos = 0; b = 0; } } } if (bitpos > 0) { _sourceWriter.Write(b.ToString() + ","); } _sourceWriter.Write("};\n"); } _sourceWriter.Write("\n"); }
private void RefillCharsPanel() { FontChar fc; try { _charsPanel.SuspendLayout(); // empty panel _charsPanel.Controls.Clear(); // add new. not particularly fast. using (Graphics g = CreateGraphics()) { foreach (FontUtil.FontRange fr in FontUtil.GetFontUnicodeRanges(_sizedFont.GdiFont)) { for (UInt16 code = fr.Low; code <= fr.High; code++) { char c; int width; fc = new FontChar(); c = Convert.ToChar(code); // special case for space which we map to the width of a "-" width = (int)g.MeasureString(c == ' ' ? "-" : c.ToString(), _sizedFont.GdiFont, PointF.Empty, StringFormat.GenericTypographic).Width; fc.Text = c.ToString(); fc.Font = _sizedFont.GdiFont; fc.Size = new Size(width, _sizedFont.Size); fc.Selected = _sizedFont.ContainsChar(c); fc.Click += OnClickFontChar; fc.Tag = c; _charsPanel.Controls.Add(fc); } } } _preview.Font = _sizedFont.GdiFont; RefillPreviews(); } finally { _charsPanel.ResumeLayout(); } }
/* * create from the given character */ public void Create(char c_, int xoffset_, int yoffset_, int extraLines_) { bool[,] values; int x, y; Point pos; Point[] line; values = FontUtil.GetCharacterBitmap(this, this.Font, c_, xoffset_, yoffset_, extraLines_); _bitmap = new Bitmap(values.GetLength(0) * PixelSize, values.GetLength(1) * PixelSize); pos = Point.Empty; using (Graphics g = Graphics.FromImage(_bitmap)) { g.FillRectangle(Brushes.White, 0, 0, _bitmap.Width, _bitmap.Height); for (y = 0; y < values.GetLength(1); y++) { for (x = 0; x < values.GetLength(0); x++) { if (values[x, y]) { g.FillRectangle(Brushes.Black, pos.X, pos.Y, PixelSize, PixelSize); } pos.X += PixelSize; } pos.X = 0; pos.Y += PixelSize; } // grid line = new Point[2]; line[0].X = line[1].X = 0; line[0].Y = 0; line[1].Y = _bitmap.Height; for (x = 0; x <= values.GetLength(0); x++) { g.DrawLine(Pens.LightGray, line[0], line[1]); line[0].X += PixelSize; line[1].X += PixelSize; } line[0].X = 0; line[1].X = _bitmap.Width; line[0].Y = line[1].Y = 0; for (y = 0; y <= values.GetLength(1); y++) { g.DrawLine(Pens.LightGray, line[0], line[1]); line[0].Y += PixelSize; line[1].Y += PixelSize; } } // set the control size this.Size = _bitmap.Size; }