Beispiel #1
0
        private void btnLoadTRFont_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "请选择输入TRFont点阵字库路径";
            ofd.Filter = "bin files (*.bin)|*.bin";
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                ushort     fontHeight = getFontHeight(ofd.FileName);
                CXFontInfo info       = new CXFontInfo(fontHeight);
                info.loadFile(ofd.FileName);
                pxFont = info.ToPixelFont();
                pxFont.saveFile(Path.Combine(Application.StartupPath, "pxfont.bin"));
            }
            catch (TRFontException)
            {
                MessageBox.Show(this, "加载字体文件失败");
                return;
            }
        }
Beispiel #2
0
        private void btnLoadPixelFont_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "请选择输入PixelFont点阵字库路径";
            ofd.Filter = "bin files (*.bin)|*.bin";
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                DPixelFont info = new DPixelFont();
                info.loadFile(ofd.FileName);
                pxFont = info;
            }
            catch (TRFontException)
            {
                MessageBox.Show(this, "加载字体文件失败");
                return;
            }
        }
Beispiel #3
0
        private bool drawChar(DPixelFont fontInfo, char ch, Bitmap bmp)
        {
            DPixelFont.CharItem info = fontInfo.findChar(ch);
            if (info == null)
            {
                return(false);
            }

            int gridH = bmp.Height / fontInfo.MapHeight;
            int gridW = gridH;

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.Clear(Color.White);

                for (int i = 0; i < fontInfo.FontHeight; i++)
                {
                    int startIndex = (info.CharWidth + 7) / 8 * i;
                    for (int j = 0; j < info.CharWidth; j++)
                    {
                        int byteIndex = j / 8 + startIndex;
                        int bitIndex  = j % 8;
                        int needDraw  = (info.Data[byteIndex] << bitIndex) & 0x80;
                        if (needDraw != 0)
                        {
                            g.FillRectangle(Brushes.Black, j * gridW, i * gridH, gridW, gridH);
                        }
                        else
                        {
                            g.FillRectangle(Brushes.Yellow, j * gridW, i * gridH, gridW, gridH);
                        }
                    }
                }
            }

            return(true);
        }