Beispiel #1
0
        static void BuildFontGlyphs(PixelFarm.Drawing.RequestFont font,
                                    Typography.Rendering.SimpleFontAtlasBuilder atlasBuilder,
                                    int startAt, int endAt)
        {
            //font glyph for specific font face
            ActualFont nativeFont = GetActualFont(font.Name, font.SizeInPoints);// nativeFontStore.GetResolvedNativeFont(font);

            for (int i = startAt; i <= endAt; ++i)
            {
                char      c         = (char)i;
                FontGlyph fontGlyph = nativeFont.GetGlyph(c);
                //-------------------
                GlyphImage glyphImg = NativeMsdfGen.BuildMsdfFontImage(fontGlyph);

                // Console.WriteLine(c.ToString() + " ox,oy" + glyphImg.OffsetX + "," + glyphImg.OffsetY);

                int   w      = glyphImg.Width;
                int   h      = glyphImg.Height;
                int[] buffer = glyphImg.GetImageBuffer();
                NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer);
                glyphImg.SetImageBuffer(buffer, false);
                // atlasBuilder.AddGlyph(fontGlyph.glyphMatrix.u c, fontGlyph, glyphImg);
                //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                //{
                //    var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                //    System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
                //    bmp.UnlockBits(bmpdata);
                //    bmp.Save("d:\\WImageTest\\a001_x1_" + (int)c + ".png");
                //}
            }
        }
Beispiel #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            //1. load font
            string fontName = "tahoma";
            string fontfile = "c:\\Windows\\Fonts\\tahoma.ttf";
            //string fontfile = @"D:\WImageTest\THSarabunNew\THSarabunNew.ttf";
            ActualFont font = GetActualFont(fontfile, 18);// nativeFontStore.LoadFont(fontName, fontfile, 28);
            //2. get glyph
            var atlasBuilder = new Typography.Rendering.SimpleFontAtlasBuilder();

            //for (int i = 0; i < 256; ++i)
            //BuildFontGlyphsByIndex(font, atlasBuilder, 0, 255);
            //BuildFontGlyphs(font, atlasBuilder, 0x0e00, 0x0e5b);
            //BuildFontGlyphsByIndex(font, atlasBuilder, 0, 3417);
            //BuildFontGlyphsByIndex(font, atlasBuilder, 0, 509);
            //BuildFontGlyphsByIndex(font, atlasBuilder, 97, 97);
            BuildFontGlyph(font, atlasBuilder, 'B');
            //----------------------------------------------------
            //GlyphImage totalImg = atlasBuilder.BuildSingleImage();
            GlyphImage totalImg = atlasBuilder.BuildSingleImage();

            using (Bitmap bmp = new Bitmap(totalImg.Width, totalImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                int[] buffer = totalImg.GetImageBuffer();
                if (totalImg.IsBigEndian)
                {
                    NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer);
                    totalImg.SetImageBuffer(buffer, false);
                }

                var bmpdata = bmp.LockBits(
                    new System.Drawing.Rectangle(0, 0, totalImg.Width, totalImg.Height),
                    System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
                bmp.UnlockBits(bmpdata);
                bmp.Save("d:\\WImageTest\\a_total.png");
            }

            string fontfilename = "d:\\WImageTest\\a_total.xml";

            atlasBuilder.SaveFontInfo(fontfilename);
            //----------------------------------
        }
Beispiel #3
0
        static void BuildFontGlyph(ActualFont nativefont, Typography.Rendering.SimpleFontAtlasBuilder atlasBuilder, char c)
        {
            //font glyph for specific font face



            FontGlyph  fontGlyph = nativefont.GetGlyph(c);
            GlyphImage glyphImg  = NativeMsdfGen.BuildMsdfFontImage(fontGlyph);

            int w = glyphImg.Width;
            int h = glyphImg.Height;

            int[] buffer = glyphImg.GetImageBuffer();
            NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer);
            glyphImg.SetImageBuffer(buffer, false);
            atlasBuilder.AddGlyph(0, glyphImg);
            //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            //{
            //    var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
            //    System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
            //    bmp.UnlockBits(bmpdata);
            //    bmp.Save("d:\\WImageTest\\a001_x1_" + (int)c + ".png");
            //}
        }
Beispiel #4
0
        private void button6_Click(object sender, EventArgs e)
        {
            //1. load font
            ActualFont font = GetActualFont("tahoma", 28);// nativeFontStore.LoadFont("tahoma", 28);
            //2. get glyph

            var g1 = font.GetGlyph('C');

            var plans = new List <Typography.TextLayout.GlyphPlan>();

            PixelFarm.Drawing.Text.TextShapingService.GetGlyphPos(font, "ABC".ToCharArray(), 0, 3, plans);


            int[] glyphIndice = new int[] { 1076, 1127, 1164 };
            int   j           = glyphIndice.Length;

            var atlasBuilder = new Typography.Rendering.SimpleFontAtlasBuilder();

            for (int i = 0; i < j; ++i)
            {
                int       codepoint = glyphIndice[i];
                FontGlyph fontGlyph = font.GetGlyphByIndex((uint)codepoint);

                GlyphImage glyphImg = NativeMsdfGen.BuildMsdfFontImage(fontGlyph);
                int        w        = glyphImg.Width;
                int        h        = glyphImg.Height;
                int[]      buffer   = glyphImg.GetImageBuffer();
                NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer);
                glyphImg.SetImageBuffer(buffer, false);
                atlasBuilder.AddGlyph(codepoint, glyphImg);

                using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                    System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
                    bmp.UnlockBits(bmpdata);
                    bmp.Save("d:\\WImageTest\\a001_y1_" + codepoint + ".png");
                }
            }
            //----------------------------------------------------
            GlyphImage totalImg = atlasBuilder.BuildSingleImage();

            using (Bitmap bmp = new Bitmap(totalImg.Width, totalImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                int[] buffer = totalImg.GetImageBuffer();
                if (totalImg.IsBigEndian)
                {
                    NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer);
                    totalImg.SetImageBuffer(buffer, false);
                }

                var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, totalImg.Width, totalImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
                bmp.UnlockBits(bmpdata);
                bmp.Save("d:\\WImageTest\\a_total.png");
            }

            string fontfilename = "d:\\WImageTest\\a_total.xml";

            atlasBuilder.SaveFontInfo(fontfilename);
            //----------------------------------
        }
Beispiel #5
0
        private void button3_Click(object sender, EventArgs e)
        {
            //1. load font
            string     fontName      = "tahoma";
            int        fontSizeInPts = 28;
            ActualFont font          = GetActualFont(fontName, fontSizeInPts);

            //2. get glyph
            char[] fontChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray();
            int    j         = fontChars.Length;


            var atlasBuilder = new Typography.Rendering.SimpleFontAtlasBuilder();

            atlasBuilder.SetAtlasInfo(TextureKind.Msdf, fontSizeInPts);

            for (int i = 0; i < j; ++i)
            {
                char c = fontChars[i];

                FontGlyph  fontGlyph = font.GetGlyph(c);
                GlyphImage glyphImg  = NativeMsdfGen.BuildMsdfFontImage(fontGlyph);

                int   w      = glyphImg.Width;
                int   h      = glyphImg.Height;
                int[] buffer = glyphImg.GetImageBuffer();
                NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer);
                glyphImg.SetImageBuffer(buffer, false);
                atlasBuilder.AddGlyph(0, glyphImg);

                using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    var bmpdata = bmp.LockBits(
                        new System.Drawing.Rectangle(0, 0, w, h),
                        System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                    System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
                    bmp.UnlockBits(bmpdata);
                    bmp.Save("d:\\WImageTest\\a001_x1_" + (int)c + ".png");
                }
            }
            //----------------------------------------------------
            GlyphImage totalImg = atlasBuilder.BuildSingleImage();

            using (Bitmap bmp = new Bitmap(totalImg.Width, totalImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                int[] buffer = totalImg.GetImageBuffer();
                if (totalImg.IsBigEndian)
                {
                    NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer);
                    totalImg.SetImageBuffer(buffer, false);
                }

                var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, totalImg.Width, totalImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
                bmp.UnlockBits(bmpdata);
                bmp.Save("d:\\WImageTest\\a_total.png");
            }

            string fontfilename = "d:\\WImageTest\\a_total.xml";

            atlasBuilder.SaveFontInfo(fontfilename);
            //----------------------------------
        }