예제 #1
0
        public void Pack(string chars, Font font, string prefix)
        {
            DrawTextArgs args = new DrawTextArgs("", font, true);

            widths = new int[chars.Length];

            using (IDrawer2D drawer = game.Drawer2D) {
                args.Text = prefix;
                Size size = game.Drawer2D.MeasureText(ref args);
                offset      = size.Width;
                size.Width += fontSize * chars.Length;

                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) {
                    drawer.SetBitmap(bmp);
                    drawer.DrawText(ref args, 0, 0);

                    for (int i = 0; i < chars.Length; i++)
                    {
                        args.Text = new String(chars[i], 1);
                        widths[i] = game.Drawer2D.MeasureText(ref args).Width;
                        drawer.DrawText(ref args, offset + fontSize * i, 0);
                    }

                    tex = drawer.Make2DTexture(bmp, size, 0, 0);
                    drawer.ReducePadding(ref tex, Utils.Floor(font.Size), 4);

                    uScale    = 1.0f / bmp.Width;
                    tex.U2    = offset * uScale;
                    tex.Width = (ushort)offset;
                }
            }
        }