public static void Setup() { if (CommonTextServiceSetup.FontLoader == null) { InstalledTypefaceCollectionMx.Setup(); CommonTextServiceSetup.SetInstalledTypefaceCollection(InstalledTypefaceCollectionMx.GetDefaultInstalledTypefaceCollection()); } PixelFarm.DrawingGL.CachedBinaryShaderIO.SetActualImpl( () => new PixelFarm.DrawingGL.LocalFileCachedBinaryShaderIO(Application.CommonAppDataPath)); FrameworkInitGLES.SetupDefaultValues(); //TODO: review namespace*** var pars = new PixelFarm.Platforms.ImageIOSetupParameters(); pars.SaveToPng = (IntPtr imgBuffer, int stride, int width, int height, string filename) => { 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) => { //read //TODO: review here again 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); //you can use your font loader YourImplementation.FrameworkInitWinGDI.SetupDefaultValues(); //default text breaker, this bridge between LayoutFarm.Composers.Default.TextBreaker = new LayoutFarm.Composers.MyManagedTextBreaker(); }
static void Main() { PixelFarm.Platforms.StorageService.RegisterProvider(new YourImplementation.LocalFileStorageProvider("")); YourImplementation.FrameworkInitWinGDI.SetupDefaultValues(); YourImplementation.FrameworkInitGLES.SetupDefaultValues(); string icu_datadir = YourImplementation.RelativePathBuilder.SearchBackAndBuildFolderPath(System.IO.Directory.GetCurrentDirectory(), "HtmlRenderer", @"..\Typography\Typography.TextBreak\icu62\brkitr"); if (!System.IO.Directory.Exists(icu_datadir)) { throw new System.NotSupportedException("dic"); } var dicProvider = new Typography.TextBreak.IcuSimpleTextFileDictionaryProvider() { DataDir = icu_datadir }; Typography.TextBreak.CustomBreakerBuilder.Setup(dicProvider); PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO = new PixelFarm.Drawing.WinGdi.GdiBitmapIO(); YourImplementation.TestBedStartup.Setup(); PixelFarm.Platforms.ImageIOSetupParameters pars = new PixelFarm.Platforms.ImageIOSetupParameters(); pars.SaveToPng = (IntPtr imgBuffer, int stride, int width, int height, string filename) => { 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) => { //read //TODO: review here again 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); //------------------------------- Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ////------------------------------- formDemoList = new LayoutFarm.Dev.FormDemoList(); formDemoList.LoadDemoList(typeof(Program).Assembly); LoadHtmlSamples(formDemoList.SamplesTreeView); Application.Run(formDemoList); }
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; } }