Example #1
0
        private void bannerSaveFileDialog_FileOk(object sender, CancelEventArgs e)
        {
            byte[] fntData = findFile(fontTextBox.Text);
            if (fntData == null)
            {
                MessageBox.Show(this, "Cannot find the given font", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string text = textTextBox.Text;

            LibDescent.Data.Font font  = MainForm.LoadFont(new MemoryStream(fntData));
            FNTRenderer          frend = new FNTRenderer(font);
            Bitmap result;

            if (testing)
            {
                int cw = Math.Max(8, font.GetCharWidth('\0')) * 2;
                result = new Bitmap(cw * 16, (font.Height + 3) * 16);
                Graphics gdi = Graphics.FromImage(result);
                int      x = 0, lx, ly, lw;
                Pen      pen = new Pen(Color.Red);
                for (int c = 0; c < 256; ++c)
                {
                    lx = (c % 16) * cw;
                    ly = (font.Height + 3) * (c / 16);
                    x  = lx;
                    frend.Reset();
                    frend.DrawCharacterRaw(result, (char)c, Color.Green, ref x, ly);

                    x   = lx;
                    ly += font.Height;
                    lw  = font.GetCharWidth((char)c);
                    gdi.DrawLine(pen, lx, ly, lx + lw, ly);
                }
            }
            else
            {
                result = new Bitmap(font.MeasureWidth(text), font.Height);
                int x = 0;
                foreach (char c in text)
                {
                    frend.DrawCharacterRaw(result, c, Color.Green, ref x, 0);
                }
            }
            result.Save(bannerSaveFileDialog.FileName);
        }
Example #2
0
 private void MoveText(int x, int y)
 {
     font.Reset();
     tx = x;
     ty = y;
 }