Пример #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");
                //}
            }
        }
        protected override void OnStart(AppHost host)
        {
            {
                var reqFont1 = new PixelFarm.Drawing.RequestFont("Sarabun", 14);
                var textbox1 = new LayoutFarm.CustomWidgets.TextBox(400, 100, true);
                var style1   = new TextEditing.TextSpanStyle();
                style1.ReqFont = reqFont1;
                //test with various font style
                style1.FontColor          = new PixelFarm.Drawing.Color(0, 0, 0);
                textbox1.DefaultSpanStyle = style1;
                host.AddChild(textbox1);
            }
            //-------------------
            //{
            //    var reqFont2 = new PixelFarm.Drawing.RequestFont("Sarabun", 10);
            //    //this version we need to set a style font each textbox
            //    var textbox2 = new LayoutFarm.CustomWidgets.TextBox(400, 500, true);
            //    var style2 = new TextEditing.TextSpanStyle();
            //    style2.ReqFont = reqFont2;
            //    style2.FontColor = new PixelFarm.Drawing.Color(0, 0, 0);
            //    textbox2.DefaultSpanStyle = style2;
            //    textbox2.SetLocation(20, 120);
            //    host.AddChild(textbox2);

            //    var textSplitter = new ContentTextSplitter();
            //    textbox2.TextSplitter = textSplitter;
            //    textbox2.Text = "Hello World!";
            //}
        }
Пример #3
0
        protected override void OnStart(AppHost host)
        {
            //simple textbox
            var reqFont       = new PixelFarm.Drawing.RequestFont("Sarabun", 18);
            var textbox       = new LayoutFarm.CustomWidgets.TextBox(200, 30, false);
            var textSpanStyle = new TextEditing.TextSpanStyle()
            {
                ReqFont   = reqFont,
                FontColor = new PixelFarm.Drawing.Color(255, 0, 0)
            };

            //test with various font style
            //set default style
            textbox.DefaultSpanStyle = textSpanStyle;
            //
            host.AddChild(textbox);


            //--------------
            //mask text box
            var maskTextBox    = new LayoutFarm.CustomWidgets.MaskTextBox(200, 30);
            var textSpanStyle2 = new TextEditing.TextSpanStyle()
            {
                ReqFont   = reqFont,
                FontColor = PixelFarm.Drawing.Color.Black
            };

            maskTextBox.SetLocation(0, 40);
            host.AddChild(maskTextBox);
        }
Пример #4
0
        public override void Init()
        {
            string fontName = "tahoma";

            //load font ?
            _font1 = new Drawing.RequestFont(fontName, 48);
            _font2 = new Drawing.RequestFont(fontName, 10);

            ////------------
            //var win32InstalledFont = new PixelFarm.Drawing.WinGdi.InstallFontsProviderWin32();
            //InstalledFontCollection collection = new InstalledFontCollection();
            //collection.LoadInstalledFont(win32InstalledFont.GetInstalledFontIter());
            ////test
            //InstalledFont installedFont = collection.GetFont(fontName, InstalledFontStyle.Regular);
        }
Пример #5
0
        private void Form1_Load(object sender, EventArgs e1)
        {
            this.Text = "Render with PixelFarm";
            //
            _basicOptions = openFontOptions1.Options;
            _basicOptions.TypefaceChanged += (s, e) =>
            {
                if (e.SelectedTypeface == null)
                {
                    return;
                }
                //
                if (_devVxsTextPrinter != null)
                {
                    PixelFarm.Drawing.FontStyle fontstyle = PixelFarm.Drawing.FontStyle.Regular;
                    switch (_basicOptions.SelectedTypefaceStyle)
                    {
                    case Typography.FontManagement.TypefaceStyle.Bold:
                        fontstyle = PixelFarm.Drawing.FontStyle.Bold;
                        break;

                    case Typography.FontManagement.TypefaceStyle.Italic:
                        fontstyle = PixelFarm.Drawing.FontStyle.Italic;
                        break;
                    }
                    _devVxsTextPrinter.Typeface = e.SelectedTypeface;
                    var reqFont = new PixelFarm.Drawing.RequestFont(
                        e.SelectedTypeface.Name,
                        _basicOptions.FontSizeInPoints,
                        fontstyle);
                    _devVxsTextPrinter.ChangeFont(reqFont);
                    _painter.CurrentFont = reqFont;
                }


                this.glyphNameListUserControl1.Typeface = e.SelectedTypeface;
            };

            _basicOptions.UpdateRenderOutput += (s, e) => UpdateRenderOutput();
            //
            _glyphRenderOptions = glyphRenderOptionsUserControl1.Options;
            _glyphRenderOptions.UpdateRenderOutput += (s, e) => UpdateRenderOutput();
            //
            _contourAnalysisOpts = glyphContourAnalysisOptionsUserControl1.Options;
            _contourAnalysisOpts.UpdateRenderOutput += (s, e) => UpdateRenderOutput();



            txtInputChar.TextChanged += (s, e) => UpdateRenderOutput();
            button1.Click            += (s, e) => UpdateRenderOutput();

            //
            this.glyphNameListUserControl1.GlyphNameChanged += (s, e) =>
            {
                //test render
                //just our convention by add & and ;
                RenderByGlyphName(glyphNameListUserControl1.SelectedGlyphName);
            };
            //----------------
            //string inputstr = "ก้า";
            //string inputstr = "น้ำน้ำ";
            //string inputstr = "example";
            //string inputstr = "lllll";
            //string inputstr = "e";
            //string inputstr = "T";
            //string inputstr = "u";
            //string inputstr = "t";
            //string inputstr = "2";
            //string inputstr = "3";
            //string inputstr = "o";
            //string inputstr = "l";
            //string inputstr = "k";
            //string inputstr = "8";
            //string inputstr = "#";
            //string inputstr = "a";
            string inputstr = "0";

            //string inputstr = "e";
            //string inputstr = "l";
            //string inputstr = "t";
            //string inputstr = "i";
            //string inputstr = "ma";
            //string inputstr = "po";
            //string inputstr = "Å";
            //string inputstr = "fi";
            //string inputstr = "ก่นกิ่น";
            //string inputstr = "ญญู";
            //string inputstr = "ป่า"; //for gpos test
            //string inputstr = "快速上手";
            //string inputstr = "啊";
            this.txtInputChar.Text = inputstr;
            _readyToRender         = true;

            if (_readyToRender)
            {
                UpdateRenderOutput();
            }
        }
Пример #6
0
        //-----------------------------------------------------------------------------------------------
        void BuiltAtlas_FromUserOptions(List <GlyphTextureBuildDetail> buildDetails)
        {
            //we can create font atlas by specific script-langs
            //-------------------------------------------------------------------------------

            //setting...
            Typeface typeface = _typeface;

            if (!float.TryParse(txtSelectedFontSize.Text, out float fontSizeInPoints))
            {
                MessageBox.Show("err: selected font size " + txtSelectedFontSize.Text);
                return;
            }

            //create request font, indeed we need its 'FontKey'
            PixelFarm.Drawing.RequestFont reqFont = new PixelFarm.Drawing.RequestFont(
                typeface.Name,
                fontSizeInPoints
                );


            //user may want only some script lang (not all script in the font)
            //and each script user may want different glyph-gen technique.
            //so we use GlyphTextureBuildDetail to describe that information.



            if (buildDetails.Count == 0)
            {
                MessageBox.Show("please select some script");
                return;
            }

            //-------------------------------------------------------------------------------

            //1. create glyph-texture-bitmap generator
            var glyphTextureGen = new GlyphTextureBitmapGenerator();

            glyphTextureGen.SetSvgBmpBuilderFunc(SvgBuilderHelper.ParseAndRenderSvg);

            //2. generate the glyphs
            TextureKindAndDescription textureKindAndDesc = (TextureKindAndDescription)this.cmbTextureKind.SelectedItem;

            if (textureKindAndDesc.Kind == TextureKind.Msdf)
            {
                glyphTextureGen.MsdfGenVersion = textureKindAndDesc.TechniqueDetail;
            }

            FontAtlasBuilderHelper helper = new FontAtlasBuilderHelper();

            helper.Build(glyphTextureGen, typeface, fontSizeInPoints, textureKindAndDesc.Kind, buildDetails.ToArray());

#if DEBUG
            this.Text += ", finished: build time(ms)=" + helper.dbugBuildTimeMillisec;
            System.Diagnostics.Debug.WriteLine("font atlas build time (ms): " + helper.dbugBuildTimeMillisec);
#endif


            ///------------------------------------------------
            //lets view result ...

            SimpleUtils.DisposeExistingPictureBoxImage(picOutput);

            uiFontAtlasFileViewer1.LoadFontAtlasFile(helper.TextureInfoFilename, helper.OutputImgFilename);

            this.picOutput.Image = new Bitmap(helper.OutputImgFilename);
            this.lblOutput.Text  = "Output: " + helper.OutputImgFilename;

            ////read .info back and convert to base64
            //byte[] atlas_info_content = File.ReadAllBytes(textureName + ".info");
            //string base64 = Convert.ToBase64String(atlas_info_content);
            ////create atlas
            //SimpleFontAtlas fontAtlas = atlasBuilder.CreateSimpleFontAtlas();
            //fontAtlas.TotalGlyph = totalGlyphsImg;
        }
Пример #7
0
        public Form1()
        {
            InitializeComponent();

            //
            _basicOptions = openFontOptions1.Options;
            _basicOptions.TypefaceChanged += (s, e) =>
            {
                if (e.SelectedTypeface == null)
                {
                    return;
                }
                //
                if (_devVxsTextPrinter != null)
                {
                    _devVxsTextPrinter.Typeface = e.SelectedTypeface;
                    var reqFont = new PixelFarm.Drawing.RequestFont(e.SelectedTypeface.Name, _basicOptions.FontSizeInPoints);
                    _devVxsTextPrinter.ChangeFont(reqFont);
                    painter.CurrentFont = reqFont;
                }


                this.glyphNameListUserControl1.Typeface = e.SelectedTypeface;
            };

            _basicOptions.UpdateRenderOutput += (s, e) => UpdateRenderOutput();
            //
            _glyphRenderOptions = glyphRenderOptionsUserControl1.Options;
            _glyphRenderOptions.UpdateRenderOutput += (s, e) => UpdateRenderOutput();
            //
            _contourAnalysisOpts = glyphContourAnalysisOptionsUserControl1.Options;
            _contourAnalysisOpts.UpdateRenderOutput += (s, e) => UpdateRenderOutput();



            txtInputChar.TextChanged += (s, e) => UpdateRenderOutput();
            button1.Click            += (s, e) => UpdateRenderOutput();

            //
            this.glyphNameListUserControl1.GlyphNameChanged += (s, e) =>
            {
                //test render
                //just our convention by add & and ;
                RenderByGlyphName(glyphNameListUserControl1.SelectedGlyphName);
            };
            //----------------
            //string inputstr = "ก้า";
            //string inputstr = "น้ำน้ำ";
            //string inputstr = "example";
            //string inputstr = "lllll";
            //string inputstr = "e";
            //string inputstr = "T";
            //string inputstr = "u";
            //string inputstr = "t";
            //string inputstr = "2";
            //string inputstr = "3";
            //string inputstr = "o";
            //string inputstr = "l";
            //string inputstr = "k";
            //string inputstr = "8";
            //string inputstr = "#";
            //string inputstr = "a";
            string inputstr = "0";

            //string inputstr = "e";
            //string inputstr = "l";
            //string inputstr = "t";
            //string inputstr = "i";
            //string inputstr = "ma";
            //string inputstr = "po";
            //string inputstr = "Å";
            //string inputstr = "fi";
            //string inputstr = "ก่นกิ่น";
            //string inputstr = "ญญู";
            //string inputstr = "ป่า"; //for gpos test
            //string inputstr = "快速上手";
            //string inputstr = "啊";

            //----------------
            this.txtInputChar.Text = inputstr;
            _readyToRender         = true;
        }