Пример #1
0
 public MySimpleGLBitmapFontManager(Typography.Text.OpenFontTextService textServices)
     : base(textServices)
 {
     SetLoadNewBmpDel(atlas =>
     {
         MemBitmap mainBmp = atlas.MainBitmap;
         if (atlas.UseSharedImage)
         {
             if (!_sharedGlyphImgs.TryGetValue(mainBmp, out GLBitmap found))
             {
                 found = new GLBitmap(MemBitmap.CreateFromCopy(mainBmp), true);
                 //set true=> glbmp is the original owner of the membmp, when glbmp is disposed => the membmp is disposed too
                 found.IsYFlipped = false;
                 _sharedGlyphImgs.Add(mainBmp, found);
             }
             return(found);
         }
         else
         {
             //create new one
             //load to glbmp
             GLBitmap bmp = new GLBitmap(MemBitmap.CreateFromCopy(mainBmp), true);
             //set true=> glbmp is the original owner of the membmp, when glbmp is disposed => the membmp is disposed too
             bmp.IsYFlipped = false;
             return(bmp);
         }
     });
 }
Пример #2
0
        private void cmdShowEmbededViewport_Click(object sender, EventArgs e)
        {
            Form simpleForm = new Form();

            simpleForm.Text        = "SimpleForm2";
            simpleForm.WindowState = FormWindowState.Maximized;
            Rectangle screenClientAreaRect = Screen.PrimaryScreen.WorkingArea;

            MyWinFormsControl actualWinUI = new MyWinFormsControl();

            simpleForm.Controls.Add(actualWinUI);


            InnerViewportKind internalViewportKind = InnerViewportKind.GdiPlus;


            int w = 800;
            int h = 600;


            var textService = new Typography.Text.OpenFontTextService();

            Typography.Text.TextServiceClient client = textService.CreateNewServiceClient();
            MyRootGraphic myRootGfx = new MyRootGraphic(w, h);

            var viewport = new GraphicsViewRoot(screenClientAreaRect.Width, screenClientAreaRect.Height);

            AbstractTopWindowBridge bridge = GetTopWindowBridge(
                internalViewportKind,
                myRootGfx,
                myRootGfx.TopWinEventPortal);

            IGpuOpenGLSurfaceView viewAbstraction = actualWinUI.CreateWindowWrapper(bridge);

            var rootgfx = new MyRootGraphic(w, h);

            viewport.InitRootGraphics(rootgfx,
                                      rootgfx.TopWinEventPortal,
                                      InnerViewportKind.GdiPlus,
                                      viewAbstraction,
                                      bridge);


            viewport.PaintToOutputWindow();
            simpleForm.Show();
            ShowFormLayoutInspector(viewport);
        }
Пример #3
0
        public static void CreateCanvasControlOnExistingControl(
            Control landingControl,
            int xpos, int ypos,
            int w, int h,
            InnerViewportKind internalViewportKind,
            out GraphicsViewRoot view_root)
        {
            //1. init
            InitWinform();
            IInstalledTypefaceProvider fontLoader = YourImplementation.CommonTextServiceSetup.FontLoader;

            //2.


            switch (internalViewportKind)
            {
            default:
                //gdi, gdi on gles


                break;

            case InnerViewportKind.PureAgg:
            case InnerViewportKind.AggOnGLES:
            case InnerViewportKind.GLES:
            {
                var openFontTextService = new Typography.Text.OpenFontTextService();
                openFontTextService.SvgBmpBuilder = PaintLab.SvgBuilderHelper.ParseAndRenderSvg;

                PixelFarm.Drawing.GLES2.GLES2Platform.TextService = openFontTextService;

                Typography.Text.GlobalTextService.TxtClient = openFontTextService.CreateNewServiceClient();
            }
            break;
            }

            PixelFarm.Drawing.WinGdi.WinGdiPlusPlatform.SetInstalledTypefaceProvider(fontLoader);
            //---------------------------------------------------------------------------
            //3. root graphics

            PixelFarm.Drawing.Rectangle screenClientAreaRect = Conv.ToRect(Screen.PrimaryScreen.WorkingArea);
            w = screenClientAreaRect.Width;
            h = screenClientAreaRect.Height;



            MyRootGraphic myRootGfx = new MyRootGraphic(w, h);

            //4. create event bridge that will bridge from native window event to root graphics
            AbstractTopWindowBridge bridge = GetTopWindowBridge(internalViewportKind, myRootGfx, myRootGfx.TopWinEventPortal);

            //5. actualWinUI is platform specific
            var actualWinUI = new LayoutFarm.UI.MyWinFormsControl();

            actualWinUI.Size = new System.Drawing.Size(w, h);
            landingControl.Controls.Add(actualWinUI);


            //so we create abstraction of actual UI
            IGpuOpenGLSurfaceView viewAbstraction = actualWinUI.CreateWindowWrapper(bridge);

            var viewRoot = view_root = new GraphicsViewRoot(
                screenClientAreaRect.Width,
                screenClientAreaRect.Height);

            view_root.InitRootGraphics(
                myRootGfx,
                myRootGfx.TopWinEventPortal,
                internalViewportKind,
                viewAbstraction,
                bridge);

            //TODO: review here again
            myRootGfx.SetDrawboardReqDelegate(view_root.GetDrawBoard);
            //------
            //TODO: review here
            view_root.SetBounds(xpos, ypos,
                                screenClientAreaRect.Width,
                                screenClientAreaRect.Height);

            //
            Form ownerForm = landingControl.FindForm();

            if (ownerForm != null)
            {
                ownerForm.FormClosing += (s, e) =>
                {
                    //TODO: review here
                    viewRoot.Close();
                };
            }
        }
Пример #4
0
        void InitGraphics()
        {
            //INIT ONCE
            if (_g != null)
            {
                return;
            }
            //

            _destImg = new MemBitmap(800, 600);
            _painter = AggPainter.Create(_destImg);
            _winBmp  = new Bitmap(_destImg.Width, _destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            _g       = this.CreateGraphics();

            _painter.CurrentFont = new PixelFarm.Drawing.RequestFont("Source Sans Pro", 10);


            _textService = new Typography.Text.OpenFontTextService();
            _textService.LoadFontsFromFolder("../../../TestFonts");
            _textService.UpdateUnicodeRanges();

            _devVxsTextPrinter = new PixelFarm.Drawing.VxsTextSpanPrinter(_painter, _textService.CreateNewServiceClient());
            _devVxsTextPrinter.SetSvgBmpBuilderFunc(PaintLab.SvgBuilderHelper.ParseAndRenderSvg);
            _devVxsTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
            _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont;
            _devVxsTextPrinter.Typeface          = _textService.ResolveFont(_painter.CurrentFont).Typeface;

            //Alternative Typeface selector..
            var myAlternativeTypefaceSelector = new Typography.Text.AlternativeTypefaceSelector();

            {
                //TODO: review this again,
                //load from config ?, settings?

                //arabic
                //1. create prefer typeface list for arabic script
                var preferredTypefaces = new Typography.FontCollections.PreferredTypefaceList();
                preferredTypefaces.AddTypefaceName("Noto Sans Arabic UI");

                //2. set unicode ranges and prefered typeface list.
                myAlternativeTypefaceSelector.SetPreferredTypefaces(
                    new[] { Typography.TextBreak.Unicode13RangeInfoList.Arabic,
                            Typography.TextBreak.Unicode13RangeInfoList.Arabic_Supplement,
                            Typography.TextBreak.Unicode13RangeInfoList.Arabic_Extended_A },
                    preferredTypefaces);
            }
            {
                //latin


                var preferredTypefaces = new Typography.FontCollections.PreferredTypefaceList();
                preferredTypefaces.AddTypefaceName("Sarabun");

                myAlternativeTypefaceSelector.SetPreferredTypefaces(
                    new[] { Typography.TextBreak.Unicode13RangeInfoList.C0_Controls_and_Basic_Latin,
                            Typography.TextBreak.Unicode13RangeInfoList.C1_Controls_and_Latin_1_Supplement,
                            Typography.TextBreak.Unicode13RangeInfoList.Latin_Extended_A,
                            Typography.TextBreak.Unicode13RangeInfoList.Latin_Extended_B, },
                    preferredTypefaces);
            }

            _devVxsTextPrinter.AlternativeTypefaceSelector = myAlternativeTypefaceSelector;
        }
Пример #5
0
        static void Init(GlFwForm form)
        {
            //PART1:
            //1. storage io
            PixelFarm.Platforms.StorageService.RegisterProvider(new YourImplementation.LocalFileStorageProvider(""));

            //2. img-io implementation
            PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO = new YourImplementation.ImgCodecMemBitmapIO(); // new PixelFarm.Drawing.WinGdi.GdiBitmapIO();
            //PixelFarm.CpuBlit.MemBitmapExtensions.DefaultMemBitmapIO = new PixelFarm.Drawing.WinGdi.GdiBitmapIO();

            //------------------------------------------------------------------------
            //
            //if we don't set this, it will error on read-write image
            //you can implement this with other lib that can read-write images

            var pars = new PixelFarm.Platforms.ImageIOSetupParameters();

            pars.SaveToPng = (IntPtr imgBuffer, int stride, int width, int height, string filename) =>
            {
                MemBitmap memBmp = new MemBitmap(width, height, imgBuffer);
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO.SaveImage(memBmp, fs,
                                                                                MemBitmapIO.OutputImageFormat.Png,
                                                                                null);
                }

                //---save with GDI+---
                //using (System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                //{
                //    PixelFarm.CpuBlit.BitmapHelper.CopyToGdiPlusBitmapSameSize(imgBuffer, newBmp);
                //    //save
                //    newBmp.Save(filename);
                //}
            };
            pars.ReadFromMemStream = (System.IO.MemoryStream ms, string kind) =>
            {
                return(PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO.LoadImage(ms));
                //read/guest img format

                //--- load img with GDI+---
                ////read
                //using (System.Drawing.Bitmap gdiBmp = new System.Drawing.Bitmap(ms))
                //{
                //    PixelFarm.CpuBlit.MemBitmap memBmp = new PixelFarm.CpuBlit.MemBitmap(gdiBmp.Width, gdiBmp.Height);
                //    //#if DEBUG
                //    //                        memBmp._dbugNote = "img;
                //    //#endif

                //    PixelFarm.CpuBlit.BitmapHelper.CopyFromGdiPlusBitmapSameSizeTo32BitsBuffer(gdiBmp, memBmp);
                //    return memBmp;
                //}
            };
            PixelFarm.Platforms.ImageIOPortal.Setup(pars);
            //------------------------------------------------------------------------


            //3. setup text-breaker
            string icu_datadir = "brkitr"; //see brkitr folder, we link data from Typography project and copy to output if newer

            if (!System.IO.Directory.Exists(icu_datadir))
            {
                throw new System.NotSupportedException("dic");
            }
            Typography.TextBreak.CustomBreakerBuilder.Setup(new Typography.TextBreak.IcuSimpleTextFileDictionaryProvider()
            {
                DataDir = icu_datadir
            });

            //---------------------------------------------------------------------------
            //4. Typography TextService
            Typography.Text.OpenFontTextService textService = new Typography.Text.OpenFontTextService();
            textService.LoadFontsFromFolder("Fonts");
            Typography.Text.TextServiceClient serviceClient = textService.CreateNewServiceClient();
            GlobalTextService.TextService = serviceClient;
            //---------------------------------------------------------------------------

            //PART2: root graphics
            Size primScreenSize = UIPlatform.CurrentPlatform.GetPrimaryMonitorSize();

            s_myRootGfx = new MyRootGraphic(primScreenSize.Width, primScreenSize.Height);
            s_viewroot  = new GraphicsViewRoot(primScreenSize.Width, primScreenSize.Height);
            MyGlfwTopWindowBridge bridge1 = new MyGlfwTopWindowBridge(s_myRootGfx, s_myRootGfx.TopWinEventPortal);

            ((MyGlfwTopWindowBridge.GlfwEventBridge)(form.WindowEventListener)).SetWindowBridge(bridge1);


            var glfwWindowWrapper = new GlfwWindowWrapper(form);

            bridge1.BindWindowControl(glfwWindowWrapper);

            s_viewroot.InitRootGraphics(s_myRootGfx,
                                        s_myRootGfx.TopWinEventPortal,
                                        InnerViewportKind.GLES,
                                        glfwWindowWrapper,
                                        bridge1);



            //------------------------------------------------------------------------
            //optional:
            if (s_viewroot.GetGLPainter() is GLPainter glPainter)
            {
                glPainter.SmoothingMode = SmoothingMode.AntiAlias;
            }
        }
 public void SetCurrentReqFont(RequestFont reqFont, Typography.Text.OpenFontTextService textService)
 {
     _reqFont     = reqFont;
     _textService = textService;
 }