public AggTextSpanPrinter(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
            this.canvasPainter = canvasPainter;
            this._glsx         = canvasPainter.Canvas;
            bmpWidth           = w;
            bmpHeight          = h;

            _actualImage            = new ActualImage(bmpWidth, bmpHeight);
            _aggsx                  = new AggRenderSurface(_actualImage);
            _aggPainter             = new AggPainter(_aggsx);
            _aggPainter.FillColor   = Color.Black;
            _aggPainter.StrokeColor = Color.Black;

            //set default1
            _aggPainter.CurrentFont = canvasPainter.CurrentFont;
            var openFontStore = new Typography.TextServices.OpenFontStore();

            _vxsTextPrinter         = new VxsTextPrinter(_aggPainter, openFontStore);
            _aggPainter.TextPrinter = _vxsTextPrinter;
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
0
        void SoftAggControl_Load(object sender, EventArgs e)
        {
            if (_useGdiPlusOutput)
            {
                // This example assumes the existence of a form called Form1.
                // Gets a reference to the current BufferedGraphicsContext
                //BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
                //_myBuffGfx = currentContext.Allocate(this.CreateGraphics(),
                //   this.DisplayRectangle);

                // Creates a BufferedGraphics instance associated with Form1, and with
                // dimensions the same size as the drawing surface of Form1.
                thisGfx       = this.CreateGraphics(); //for render to output
                bufferBmpRect = this.DisplayRectangle;
                bufferBmp     = new Bitmap(bufferBmpRect.Width, bufferBmpRect.Height);
                var gdiPlusCanvasPainter = new PixelFarm.Drawing.WinGdi.GdiPlusCanvasPainter(bufferBmp);
                gdiPlusCanvasPainter.SmoothingMode = _gdiAntiAlias ? PixelFarm.Drawing.SmoothingMode.AntiAlias : PixelFarm.Drawing.SmoothingMode.HighSpeed;
                painter             = gdiPlusCanvasPainter;
                painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 10);
            }
            else
            {
                ImageGraphics2D  imgGfx2d   = Initialize(myWidth, myHeight, 32);
                AggCanvasPainter aggPainter = new AggCanvasPainter(imgGfx2d);
                //set text printer for agg canvas painter
                aggPainter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 10);
                VxsTextPrinter textPrinter = new VxsTextPrinter(aggPainter);
                aggPainter.TextPrinter = textPrinter;

                painter = aggPainter;
            }


            painter.Clear(PixelFarm.Drawing.Color.White);
        }
Exemplo n.º 4
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();
            //----------
        }
        public void BindHostGraphics(Graphics hostControlGraphics)
        {
            g = hostControlGraphics;
            //
            destImg  = new ActualImage(400, 300, PixelFormat.ARGB32);
            imgGfx2d = new ImageGraphics2D(destImg); //no platform
            p        = new AggCanvasPainter(imgGfx2d);
            winBmp   = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            _printer    = new VxsTextPrinter(p, null);
            _visualLine = new VisualLine();
            _visualLine.BindLine(_line);
            _visualLine.Y = 100;
        }
Exemplo n.º 6
0
        public void BindHostGraphics(Graphics hostControlGraphics)
        {
            g = hostControlGraphics;
            //
            destImg = new ActualImage(400, 300, PixelFormat.ARGB32);
            aggsx   = new AggRenderSurface(destImg); //no platform
            p       = new AggPainter(aggsx);
            winBmp  = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            _printer    = new VxsTextPrinter(p, null);
            _visualLine = new VisualLine();
            _visualLine.BindLine(_line);
            _visualLine.Y = 100;
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
        public AggTextSpanPrinter(GLCanvasPainter 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
            this.canvasPainter = canvasPainter;
            this.canvas        = canvasPainter.Canvas;
            bmpWidth           = w;
            bmpHeight          = h;
            actualImage        = new ActualImage(bmpWidth, bmpHeight, PixelFormat.ARGB32);

            imgGfx2d                = new ImageGraphics2D(actualImage);
            _aggPainter             = new AggCanvasPainter(imgGfx2d);
            _aggPainter.FillColor   = Color.Black;
            _aggPainter.StrokeColor = Color.Black;

            //set default1
            _aggPainter.CurrentFont = canvasPainter.CurrentFont;
            textPrinter             = new VxsTextPrinter(_aggPainter, YourImplementation.BootStrapOpenGLES2.myFontLoader);
            _aggPainter.TextPrinter = textPrinter;
        }
Exemplo n.º 10
0
        void UpdateRenderOutput()
        {
            if (!_readyToRender)
            {
                return;
            }
            //
            if (g == null)
            {
                destImg  = new ActualImage(800, 600, PixelFormat.ARGB32);
                imgGfx2d = new ImageGraphics2D(destImg); //no platform
                painter  = new AggCanvasPainter(imgGfx2d);
                winBmp   = new Bitmap(destImg.Width, destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                g        = this.CreateGraphics();

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

                _devVxsTextPrinter = new VxsTextPrinter(painter, _basicOptions.OpenFontStore);
                _devVxsTextPrinter.TargetCanvasPainter = painter;
                _devVxsTextPrinter.ScriptLang          = _basicOptions.ScriptLang;
                _devVxsTextPrinter.PositionTechnique   = Typography.TextLayout.PositionTechnique.OpenFont;
                //_devGdiTextPrinter.TargetGraphics = g;
            }

            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
            _devVxsTextPrinter.UseWithLcdSubPixelRenderingTechnique = _contourAnalysisOpts.SetupPrinterLayoutForLcdSubPix;



            //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.UseSubPixelRendering = _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;

                //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 = 200;
                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.Agg.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();
            }
        }
Exemplo n.º 11
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();
            }
        }