public FontAtlasTextPrinter(AggPainter painter)
        {
            StartDrawOnLeftTop = true;
            _painter           = painter;

            this.PositionTechnique = PositionTechnique.OpenFont;
            _textServices          = new LayoutFarm.OpenFontTextService();

            //2.
            _bmpFontMx = new BitmapFontManager <MemBitmap>(
                _textServices,
                atlas =>
            {
                GlyphImage totalGlyphImg = atlas.TotalGlyph;
                if (atlas.UseSharedGlyphImage)
                {
                    if (!_sharedGlyphImgs.TryGetValue(totalGlyphImg, out MemBitmap found))
                    {
                        found = MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer());
                        _sharedGlyphImgs.Add(totalGlyphImg, found);
                    }
                    return(found);
                }
                else
                {
                    return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer()));
                }
            }
                );

            //3.
            ChangeFont(painter.CurrentFont);
            SetupMaskPixelBlender(painter.Width, painter.Height);
        }
Exemple #2
0
        public CpuBlitTextSpanPrinter(GLPainter canvasPainter, int w, int h)
        {
            //this class print long text into agg canvas
            //then copy pixel buffer from aff canvas to gl-bmp
            //then draw the  gl-bmp into target gl canvas


            //TODO: review here
            _canvasPainter = canvasPainter;
            _pcx           = canvasPainter.Canvas;
            _bmpWidth      = w;
            _bmpHeight     = h;

            _memBmp = new MemBitmap(_bmpWidth, _bmpHeight);
#if DEBUG
            _memBmp._dbugNote = "AggTextSpanPrinter.ctor";
#endif
            _aggPainter             = AggPainter.Create(_memBmp);
            _aggPainter.FillColor   = Color.Black;
            _aggPainter.StrokeColor = Color.Black;

            //set default1
            _aggPainter.CurrentFont = canvasPainter.CurrentFont;
            _openFontTextServices   = new LayoutFarm.OpenFontTextService();
            _vxsTextPrinter         = new VxsTextPrinter(_aggPainter, _openFontTextServices);
            _aggPainter.TextPrinter = _vxsTextPrinter;
        }
        /// <summary>
        /// use vertex buffer object
        /// </summary>

        public GLBitmapGlyphTextPrinter(GLPainter painter, LayoutFarm.OpenFontTextService textServices)
        {
            //create text printer for use with canvas painter
            _painter      = painter;
            _pcx          = painter.PainterContext;
            _textServices = textServices;

            //_currentTextureKind = TextureKind.Msdf;
            //_currentTextureKind = TextureKind.StencilGreyScale;

            _myGLBitmapFontMx = new MySimpleGLBitmapFontManager(textServices);


            LoadFontAtlas("tahoma_set1.multisize_fontAtlas", "tahoma_set1.multisize_fontAtlas.png");

            //test textures...

            //GlyphPosPixelSnapX = GlyphPosPixelSnapKind.Integer;
            //GlyphPosPixelSnapY = GlyphPosPixelSnapKind.Integer;
            //**
            ChangeFont(painter.CurrentFont);
            //
            DrawingTechnique = GlyphTexturePrinterDrawingTechnique.LcdSubPixelRendering; //default
            UseVBO           = true;
        }
Exemple #4
0
        public override void Init()
        {
            //steps : detail ...
            //1. create a text service (or get it from a singleton class)

            _textServices = new LayoutFarm.OpenFontTextService();

            //2. create manager
            _bmpFontMx = new BitmapFontManager <MemBitmap>(
                TextureKind.StencilLcdEffect,
                _textServices,
                atlas =>
            {
                GlyphImage totalGlyphImg = atlas.TotalGlyph;
                return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer()));
            }
                );


            //3.
            _font      = new RequestFont("tahoma", 10);
            _fontAtlas = _bmpFontMx.GetFontAtlas(_font, out _fontBmp);


            //----------
        }
        public GLBitmapGlyphTextPrinter(GLPainter painter, LayoutFarm.OpenFontTextService textServices)
        {
            //create text printer for use with canvas painter
            this.painter       = painter;
            this._glsx         = painter.Canvas;
            this._textServices = textServices;

            //_currentTextureKind = TextureKind.Msdf;
            //_currentTextureKind = TextureKind.StencilGreyScale;

            _myGLBitmapFontMx = new MySimpleGLBitmapFontManager(TextureKind.StencilLcdEffect, textServices);
            //change this to fit yours.
            _myGLBitmapFontMx.SetCurrentScriptLangs(
                new ScriptLang[]
            {
                ScriptLangs.Latin,
                ScriptLangs.Thai     //eg. Thai, for test with complex script, you can change to your own
            });

            //test textures...

            //GlyphPosPixelSnapX = GlyphPosPixelSnapKind.Integer;
            //GlyphPosPixelSnapY = GlyphPosPixelSnapKind.Integer;


            ChangeFont(painter.CurrentFont);
        }
        public FontAtlasTextPrinter(AggPainter painter)
        {
            StartDrawOnLeftTop = true;
            _painter           = painter;

            this.PositionTechnique = PositionTechnique.OpenFont;

            _textServices = new LayoutFarm.OpenFontTextService();
            //2. create manager
            _bmpFontMx = new BitmapFontManager <MemBitmap>(
                TextureKind.StencilLcdEffect,
                _textServices,
                atlas =>
            {
                GlyphImage totalGlyphImg = atlas.TotalGlyph;
                return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer()));
            }
                );


            //3.

            ChangeFont(new RequestFont("tahoma", 10));
            SetupMaskPixelBlender(painter.Width, painter.Height);
        }
Exemple #7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }
            //
            _basicOptions = basicFontOptionsUserControl1.Options;
            _basicOptions.TypefaceChanged += (s, e2) =>
            {
                if (_devVxsTextPrinter != null)
                {
                    _devVxsTextPrinter.Typeface = e2.SelectedTypeface;
                }
            };
            _basicOptions.UpdateRenderOutput += (s, e2) =>
            {
                UpdateRenderOutput();
            };
            //
            //----------
            _renderOptions = glyphRenderOptionsUserControl1.Options;
            _renderOptions.UpdateRenderOutput += (s, e2) =>
            {
                UpdateRenderOutput();
            };

            //share text printer to our sample textbox
            //but you can create another text printer that specific to text textbox control

            destImg = new MemBitmap(800, 600);
            aggsx   = new AggRenderSurface();
            aggsx.AttachDstBitmap(destImg);

            painter = new AggPainter(aggsx);

            winBmp = new Bitmap(destImg.Width, destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            g      = this.sampleTextBox1.CreateGraphics();

            painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14);

            _openFontTextService = new LayoutFarm.OpenFontTextService();
            //....
            _devVxsTextPrinter                   = new VxsTextPrinter(painter, _openFontTextService);
            _devVxsTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
            _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont;
            _devVxsTextPrinter.FontSizeInPoints  = 10;

            _controllerForPixelFarm.BindHostGraphics(g);
            _controllerForPixelFarm.TextPrinter = _devVxsTextPrinter;

            this.sampleTextBox1.SetController(_controllerForPixelFarm);
            _readyToRender = true;
            _basicOptions.UpdateRenderOutput += (s, e2) => UpdateRenderOutput();
            //....
            //----------
            //txtInputChar.TextChanged += (s, e2) => UpdateRenderOutput();
            //----------
        }
Exemple #8
0
 public BitmapFontManager(TextureKind textureKind,
                          LayoutFarm.OpenFontTextService textServices,
                          LoadNewBmpDelegate <SimpleFontAtlas, B> _createNewDel)
     : this(textureKind, textServices)
 {
     //glyph cahce for specific atlas
     SetLoadNewBmpDel(_createNewDel);
 }
Exemple #9
0
 public BitmapFontManager(
     LayoutFarm.OpenFontTextService textServices,
     LoadNewBmpDelegate <SimpleFontAtlas, B> _createNewDel)
     : this(textServices)
 {
     //glyph cahce for specific atlas
     SetLoadNewBmpDel(_createNewDel);
     TextureKindForNewFont = PixelFarm.Drawing.BitmapAtlas.TextureKind.StencilLcdEffect;
 }
Exemple #10
0
        public MyApp(LayoutFarm.App app = null)
        {
            if (s_typefaceStore == null)
            {
                s_typefaceStore = new InstalledTypefaceCollection();
                s_textServices  = new LayoutFarm.OpenFontTextService();
            }

            _app = app;
        }
 public VxsTextPrinter(Painter painter, LayoutFarm.OpenFontTextService textService)
 {
     StartDrawOnLeftTop = true;
     //
     _painter        = painter;
     _glyphMeshStore = new GlyphMeshStore();
     _glyphMeshStore.FlipGlyphUpward = true;
     this.PositionTechnique          = PositionTechnique.OpenFont;
     //
     _textServices = textService;
     ChangeFont(new RequestFont("tahoma", 10));
 }
Exemple #12
0
        public void BindHostGraphics(Graphics hostControlGraphics)
        {
            g = hostControlGraphics;
            //
            destImg = new ActualBitmap(400, 300);
            p       = AggPainter.Create(destImg);
            winBmp  = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            _openFontTextServices = new LayoutFarm.OpenFontTextService();

            _printer    = new VxsTextPrinter(p, _openFontTextServices);
            _visualLine = new VisualLine();
            _visualLine.BindLine(_line);
            _visualLine.Y = 100;
        }
Exemple #13
0
        public MySimpleGLBitmapFontManager(TextureKind textureKind, LayoutFarm.OpenFontTextService textServices)
        {
            this.textServices = textServices;
            //glyph cahce for specific atlas
            _loadedGlyphs = new GLBitmapCache <SimpleFontAtlas>(atlas =>
            {
                //create new one
                Typography.Rendering.GlyphImage totalGlyphImg = atlas.TotalGlyph;
                //load to glbmp
                GLBitmap found = new GLBitmap(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer(), false);
                found.IsInvert = false;
                return(found);
            });

            _textureKind = textureKind;
        }
Exemple #14
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;

            PixelFarm.Drawing.ITextService textService = new LayoutFarm.OpenFontTextService();
            MyRootGraphic myRootGfx = new MyRootGraphic(w, h, textService);

            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,
                PixelFarm.Drawing.WinGdi.WinGdiPlusPlatform.GetTextService());

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

            viewport.PaintToOutputWindow();
            simpleForm.Show();
            ShowFormLayoutInspector(viewport);
        }
Exemple #15
0
 public MySimpleGLBitmapFontManager(TextureKind textureKind, LayoutFarm.OpenFontTextService textServices)
     : base(textureKind, textServices)
 {
     SetLoadNewBmpDel(atlas =>
     {
         //create new one
         GlyphImage totalGlyphImg = atlas.TotalGlyph;
         //load to glbmp
         GLBitmap found = new GLBitmap(
             PixelFarm.CpuBlit.MemBitmap.CreateFromCopy(
                 totalGlyphImg.Width,
                 totalGlyphImg.Height,
                 totalGlyphImg.GetImageBuffer()),
             true); //set true=> glbmp is the original owner of the membmp, when glbmp is disposed => the membmp is disposed too
         found.IsYFlipped = false;
         return(found);
     });
 }
Exemple #16
0
        void SetupFontAtlasPrinter(AggPainter p)
        {
            //use custom printer here
            //_printer = new FontAtlasTextPrinter(p);
            if (_fontAtlasTextPrinter == null)
            {
                _fontAtlasTextPrinter = new FontAtlasTextPrinter(p);
            }

            if (_vxsTextPrinter == null)
            {
                _openFontTextServices = new LayoutFarm.OpenFontTextService();
                _vxsTextPrinter       = new VxsTextPrinter(p, _openFontTextServices);
            }

            _printer = (_useFontAtlas) ?
                       (TextPrinterBase)_fontAtlasTextPrinter :
                       _vxsTextPrinter;

            _fontAtlasPrinterReady = true;
        }
Exemple #17
0
        public CpuBlit.AggPainter GetAggPainter()
        {
            if (_painter == null)
            {
                CpuBlit.AggPainter aggPainter = CpuBlit.AggPainter.Create(_memBmp);
                aggPainter.CurrentFont = this.CurrentFont;

                if (_openFontTextServices == null)
                {
                    _openFontTextServices = new LayoutFarm.OpenFontTextService();
                }
                //optional if we want to print text on agg surface


                //aggPainter.TextPrinter = new PixelFarm.Drawing.Fonts.VxsTextPrinter(aggPainter, _openFontTextServices); //1.
                //aggPainter.TextPrinter = new PixelFarm.Drawing.Fonts.FontAtlasTextPrinter(aggPainter);//2.
                aggPainter.TextPrinter = new GdiPlusTextPrinter(this);
                //
                _painter = aggPainter;
                _painter.SetOrigin(this.OriginX, this.OriginY);
            }
            return(_painter);
        }
Exemple #18
0
 public FormMsdfTest2()
 {
     InitializeComponent();
     //
     _textServices = new LayoutFarm.OpenFontTextService();
 }
Exemple #19
0
        void UpdateRenderOutput()
        {
            if (!_readyToRender)
            {
                return;
            }
            //
            if (_g == null)
            {
                _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("tahoma", 14);


                _textService = new LayoutFarm.OpenFontTextService();
                _textService.LoadFontsFromFolder("../../../TestFonts");

                _devVxsTextPrinter                   = new VxsTextPrinter(_painter, _textService);
                _devVxsTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
                _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont;
            }

            if (string.IsNullOrEmpty(this.txtInputChar.Text))
            {
                return;
            }

            //test option use be used with lcd subpixel rendering.
            //this demonstrate how we shift a pixel for subpixel rendering tech

            if (_contourAnalysisOpts.SetupPrinterLayoutForLcdSubPix)
            {
                //TODO: set lcd or not here
            }
            else
            {
                //TODO: set lcd or not here
            }

            //1. read typeface from font file
            TypographyTest.RenderChoice renderChoice = _basicOptions.RenderChoice;
            switch (renderChoice)
            {
            case TypographyTest.RenderChoice.RenderWithGdiPlusPath:
                //not render in this example
                //see more at ...
                break;

            case TypographyTest.RenderChoice.RenderWithTextPrinterAndMiniAgg:
            {
                //clear previous draw
                _painter.Clear(PixelFarm.Drawing.Color.White);
                _painter.UseSubPixelLcdEffect = _contourAnalysisOpts.LcdTechnique;
                _painter.FillColor            = PixelFarm.Drawing.Color.Black;

                _selectedTextPrinter                   = _devVxsTextPrinter;
                _selectedTextPrinter.Typeface          = _basicOptions.Typeface;
                _selectedTextPrinter.FontSizeInPoints  = _basicOptions.FontSizeInPoints;
                _selectedTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
                _selectedTextPrinter.PositionTechnique = _basicOptions.PositionTech;

                _selectedTextPrinter.HintTechnique  = _glyphRenderOptions.HintTechnique;
                _selectedTextPrinter.EnableLigature = _glyphRenderOptions.EnableLigature;
                _selectedTextPrinter.SimulateSlant  = _contourAnalysisOpts.SimulateSlant;

                //test print 3 lines
#if DEBUG
                GlyphDynamicOutline.dbugTestNewGridFitting    = _contourAnalysisOpts.EnableGridFit;
                GlyphDynamicOutline.dbugActualPosToConsole    = _contourAnalysisOpts.WriteFitOutputToConsole;
                GlyphDynamicOutline.dbugUseHorizontalFitValue = _contourAnalysisOpts.UseHorizontalFitAlignment;
#endif

                char[] printTextBuffer = this.txtInputChar.Text.ToCharArray();
                float  x_pos = 0, y_pos = 50;
                float  lineSpacingPx = _selectedTextPrinter.FontLineSpacingPx;
                for (int i = 0; i < 1; ++i)
                {
                    _selectedTextPrinter.DrawString(printTextBuffer, x_pos, y_pos);
                    y_pos -= lineSpacingPx;
                }


                //copy from Agg's memory buffer to gdi
                PixelFarm.CpuBlit.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(_destImg, _winBmp);
                _g.Clear(Color.White);
                _g.DrawImage(_winBmp, new Point(10, 0));
            }
            break;

            //==============================================
            //render 1 glyph for debug and test
            case TypographyTest.RenderChoice.RenderWithMsdfGen:
            case TypographyTest.RenderChoice.RenderWithSdfGen:
            {
                char     testChar = this.txtInputChar.Text[0];
                Typeface typeFace = _basicOptions.Typeface;
                RenderWithMsdfImg(typeFace, testChar, _basicOptions.FontSizeInPoints);
            }
            break;

            case TypographyTest.RenderChoice.RenderWithMiniAgg_SingleGlyph:
            {
                _selectedTextPrinter = _devVxsTextPrinter;
                //for test only 1 char
                RenderSingleCharWithMiniAgg(
                    _basicOptions.Typeface,
                    this.txtInputChar.Text[0],
                    _basicOptions.FontSizeInPoints);
            }
            break;

            default:
                throw new NotSupportedException();
            }
        }
Exemple #20
0
 public BitmapFontManager(TextureKind textureKind, LayoutFarm.OpenFontTextService textServices)
 {
     _textServices = textServices;
     _textureKind  = textureKind;
 }
Exemple #21
0
        protected override void PaintImp(PaintVisitor p)
        {
#if DEBUG
            p.dbugEnterNewContext(this, PaintVisitor.PaintVisitorContextName.Init);
#endif
            DrawBoard drawBoard = p.InnerDrawBoard;

            if (DisableBmpCache)
            {
                PixelFarm.CpuBlit.AggPainter painter = drawBoard.GetPainter() as PixelFarm.CpuBlit.AggPainter;
                if (painter == null)
                {
                    return;
                }
                //TODO: review here
                //temp fix
                if (s_openfontTextService == null)
                {
                    s_openfontTextService = new OpenFontTextService();
                }

                //painter.CurrentFont = new RequestFont("tahoma", 14);
                //var textPrinter = new PixelFarm.Drawing.Fonts.VxsTextPrinter(painter, s_openfontTextService);
                //painter.TextPrinter = textPrinter;
                //painter.Clear(Color.White);
                //
                double prevStrokeW = painter.StrokeWidth;
                //Color fillColor = painter.FillColor;
                //painter.StrokeWidth = 1;//default
                //painter.FillColor = Color.Black;

                using (Tools.More.BorrowVgPaintArgs(painter, out var paintArgs))
                {
                    if (_vgVisualElem.CoordTx != null)
                    {
                    }
                    _vgVisualElem.Paint(paintArgs);
                }


                painter.StrokeWidth = prevStrokeW;//restore
                //painter.FillColor = fillColor;////restore

                return;
            }


            if (_vgVisualElem.HasBitmapSnapshot)
            {
                Image backimg = _vgVisualElem.BackingImage;
                drawBoard.DrawImage(backimg, new RectangleF(0, 0, backimg.Width, backimg.Height));
            }
            else
            {
                PixelFarm.CpuBlit.RectD bound = _vgVisualElem.GetRectBounds();
                //create
                PixelFarm.CpuBlit.MemBitmap backimg = new PixelFarm.CpuBlit.MemBitmap((int)bound.Width + 10, (int)bound.Height + 10);
#if DEBUG
                backimg._dbugNote = "cssBoxSvgRoot";
#endif
                PixelFarm.CpuBlit.AggPainter painter = PixelFarm.CpuBlit.AggPainter.Create(backimg);
                //TODO: review here
                //temp fix
                if (s_openfontTextService == null)
                {
                    s_openfontTextService = new OpenFontTextService();
                }


                //
                double prevStrokeW = painter.StrokeWidth;

                using (Tools.More.BorrowVgPaintArgs(painter, out VgPaintArgs paintArgs))
                {
                    if (_vgVisualElem.CoordTx != null)
                    {
                    }
                    _vgVisualElem.Paint(paintArgs);
                }

                painter.StrokeWidth = prevStrokeW;//restore
                //painter.FillColor = fillColor;////restore
#if DEBUG
                //test
                //PixelFarm.CpuBlit.Imaging.PngImageWriter.dbugSaveToPngFile(backimg, "d:\\WImageTest\\subimg1.png");
#endif
                _vgVisualElem.SetBitmapSnapshot(backimg, true);
                drawBoard.DrawImage(backimg, new RectangleF(0, 0, backimg.Width, backimg.Height));
            }
        }
Exemple #22
0
 public GlfwGLES2()
 {
     s_typefaceStore = new InstalledTypefaceCollection();
     s_textServices  = new LayoutFarm.OpenFontTextService();
 }
Exemple #23
0
 public GlfwGLES2()
 {
     s_fontstore    = new OpenFontStore();
     s_textServices = new LayoutFarm.OpenFontTextService();
 }
Exemple #24
0
 public BitmapFontManager(LayoutFarm.OpenFontTextService textServices)
 {
     _textServices = textServices;
 }