private void listBoxFontChars_SelectedIndexChanged(object sender, EventArgs e) { Graphics gr = pictureBoxPreviewAll.CreateGraphics(); gr.Clear(this.BackColor); int index = listBoxFontChars.SelectedIndex; if (index < 0 || index >= man.GetEmbeddedFont().Chars.Count) { return; } CharBitmap cbm = man.GetEmbeddedFont().Chars[index]; int width = (int)gr.VisibleClipBounds.Width; int height = (int)gr.VisibleClipBounds.Height; int pixWidth = width / cbm.GetWidth(); int pixHeight = height / cbm.GetHeight(); int pixSize = Math.Min(pixWidth, pixHeight); int pixWidthOffset = (width - pixSize * cbm.GetWidth()) / 2; int pixHeightOffset = (height - pixSize * cbm.GetHeight()) / 2; int pixCount = 0; Color byteColor1 = Color.Green; Color byteColor2 = Color.Blue; Color byteColor = byteColor1; int gridWidth = 4; CharBitmap.Padding padding = cbm.GetPadding(); for (int Y = padding.Top; Y < cbm.GetHeight() - padding.Bottom; Y++) { for (int X = padding.Left; X < cbm.GetWidth() - padding.Right; X++) { Color pixColor = cbm.IsForegroundColor(X, Y) ? Color.Black : Color.White; SolidBrush brush = new SolidBrush(pixColor); gr.FillRectangle(brush, pixWidthOffset + X * pixSize, pixHeightOffset + Y * pixSize, pixSize - gridWidth, pixSize - gridWidth); Pen pen = new Pen(byteColor, gridWidth); gr.DrawRectangle(pen, pixWidthOffset + X * pixSize, pixHeightOffset + Y * pixSize, pixSize - gridWidth, pixSize - gridWidth); pen = new Pen(this.BackColor, 1); gr.DrawRectangle(pen, pixWidthOffset + X * pixSize - gridWidth / 2, pixHeightOffset + Y * pixSize - gridWidth / 2, pixSize, pixSize); pixCount++; if (0 == pixCount % 8) { if (byteColor1 == byteColor) { byteColor = byteColor2; } else { byteColor = byteColor1; } } } } textBoxCodePreview.Text = cbm.GetSource(padding); }
private void pad() { CharBitmap.Padding commonPadding = new CharBitmap.Padding(); commonPadding.Top = int.MaxValue; commonPadding.Bottom = int.MaxValue; commonPadding.Left = int.MaxValue; commonPadding.Right = int.MaxValue; int unpaddedBitSize = 0; int fullPaddedBitSize = 0; foreach (CharBitmap cbm in embeddedFont.Chars) { CharBitmap.Padding padding = cbm.GetPadding(); if (padding.Top < commonPadding.Top) { commonPadding.Top = padding.Top; } if (padding.Bottom < commonPadding.Bottom) { commonPadding.Bottom = padding.Bottom; } if (padding.Left < commonPadding.Left) { commonPadding.Left = padding.Left; } if (padding.Right < commonPadding.Right) { commonPadding.Right = padding.Right; } unpaddedBitSize += ((cbm.GetWidth() * cbm.GetHeight() + 7) >> 3) << 3; // round to byte unpaddedBitSize += 32; // add pointer fullPaddedBitSize += (((cbm.GetWidth() - (padding.Left + padding.Right)) * (cbm.GetHeight() - (padding.Top + padding.Bottom)) + 7) >> 3) << 3; fullPaddedBitSize += 4 * 8 + 32; // for each padding info is needed + pointer System.Diagnostics.Debug.WriteLine("{0}: {1}", cbm.GetChar(), padding.ToString()); } System.Diagnostics.Debug.WriteLine("Unpadded size: {0} bits = {1} bytes", unpaddedBitSize, unpaddedBitSize / 8); System.Diagnostics.Debug.WriteLine("Full padded size: {0} bits = {1} bytes", fullPaddedBitSize, fullPaddedBitSize / 8); int savedBits = unpaddedBitSize - fullPaddedBitSize; System.Diagnostics.Debug.WriteLine("Saved with full padding: {0} bits = {1} bytes", savedBits, savedBits / 8); System.Diagnostics.Debug.WriteLine("Common padding: " + commonPadding.ToString()); int commonPaddedBitSize = 0; foreach (CharBitmap cbm in embeddedFont.Chars) { commonPaddedBitSize += (((cbm.GetWidth() - (commonPadding.Left + commonPadding.Right)) * (cbm.GetHeight() - (commonPadding.Top + commonPadding.Bottom)) + 7) >> 3) << 3; commonPaddedBitSize += 32; // pointer for each } savedBits = unpaddedBitSize - commonPaddedBitSize; System.Diagnostics.Debug.WriteLine("Padded size: {0} bits = {1} bytes", commonPaddedBitSize, commonPaddedBitSize / 8); System.Diagnostics.Debug.WriteLine("Saved with common padding: {0} bits = {1} bytes", savedBits, savedBits / 8); }
private void pad() { CharBitmap.Padding commonPadding = new CharBitmap.Padding(); commonPadding.Top = int.MaxValue; commonPadding.Bottom = int.MaxValue; commonPadding.Left = int.MaxValue; commonPadding.Right = int.MaxValue; int unpaddedBitSize = 0; int fullPaddedBitSize = 0; foreach (CharBitmap cbm in embeddedFont.Chars) { CharBitmap.Padding padding = cbm.GetPadding(); if (padding.Top < commonPadding.Top) commonPadding.Top = padding.Top; if (padding.Bottom < commonPadding.Bottom) commonPadding.Bottom = padding.Bottom; if (padding.Left < commonPadding.Left) commonPadding.Left = padding.Left; if (padding.Right < commonPadding.Right) commonPadding.Right = padding.Right; unpaddedBitSize += ((cbm.GetWidth() * cbm.GetHeight() + 7) >> 3) << 3; // round to byte unpaddedBitSize += 32; // add pointer fullPaddedBitSize += (((cbm.GetWidth() - (padding.Left + padding.Right)) * (cbm.GetHeight() - (padding.Top + padding.Bottom)) + 7) >> 3) << 3; fullPaddedBitSize += 4 * 8 + 32; // for each padding info is needed + pointer System.Diagnostics.Debug.WriteLine("{0}: {1}", cbm.GetChar(), padding.ToString()); } System.Diagnostics.Debug.WriteLine("Unpadded size: {0} bits = {1} bytes", unpaddedBitSize, unpaddedBitSize / 8); System.Diagnostics.Debug.WriteLine("Full padded size: {0} bits = {1} bytes", fullPaddedBitSize, fullPaddedBitSize / 8); int savedBits = unpaddedBitSize - fullPaddedBitSize; System.Diagnostics.Debug.WriteLine("Saved with full padding: {0} bits = {1} bytes", savedBits, savedBits / 8); System.Diagnostics.Debug.WriteLine("Common padding: " + commonPadding.ToString()); int commonPaddedBitSize = 0 ; foreach (CharBitmap cbm in embeddedFont.Chars) { commonPaddedBitSize += (((cbm.GetWidth() - (commonPadding.Left + commonPadding.Right)) * (cbm.GetHeight() - (commonPadding.Top + commonPadding.Bottom)) + 7) >> 3) << 3; commonPaddedBitSize += 32; // pointer for each } savedBits = unpaddedBitSize - commonPaddedBitSize; System.Diagnostics.Debug.WriteLine("Padded size: {0} bits = {1} bytes", commonPaddedBitSize, commonPaddedBitSize / 8); System.Diagnostics.Debug.WriteLine("Saved with common padding: {0} bits = {1} bytes", savedBits, savedBits / 8); }