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); }
public MyHtmlTextService(Typography.Text.TextServiceClient txtsx) => _txtsx = txtsx;
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; } }