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;
        }
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;
        }
        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);
        }
        /// <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;
        }
        public void DrawImage(GLPainter glPainter, AtlasImageBinder atlasImgBinder, float left, float top)
        {
            if (atlasImgBinder.State == BinderState.Loaded && atlasImgBinder.LatestPainterId != _painterId)
            {
                atlasImgBinder.State           = BinderState.Unload;
                atlasImgBinder.LatestPainterId = _painterId;
            }


            switch (atlasImgBinder.State)
            {
            case BinderState.Loaded:
            {
                if (PixelFarm.Drawing.ImageBinder.GetCacheInnerImage(atlasImgBinder) is GLBitmap glbmp)
                {
                    AtlasItem atlasItem = atlasImgBinder.AtlasItem;
                    Rectangle srcRect   =
                        new Rectangle(atlasItem.Left,
                                      atlasItem.Top, //diff from font atlas***
                                      atlasItem.Width,
                                      atlasItem.Height);

                    switch (atlasImgBinder.TextureKind)
                    {
                    default:
                    case TextureKind.Msdf:
                        throw new NotSupportedException();

                    case TextureKind.Bitmap:
                    {
                        //atlasImgBinder.State = BinderState.Loaded;
                        //ImageBinder.SetCacheInnerImage(atlasImgBinder, glbmp, false);
                        //atlasImgBinder.AtlasItem = atlasItem;

                        glPainter.Core.DrawSubImage(glbmp,
                                                    srcRect,
                                                    left,
                                                    top);
                    }
                    break;
                    }
                }
            }
            break;

            case BinderState.Unload:
            {
                atlasImgBinder.LatestPainterId = _painterId;
                //load img first
                if (_bmpAtlas == null || _lastestImgFile != atlasImgBinder.AtlasName)
                {
                    _bmpAtlas = _atlasManager.GetBitmapAtlas(atlasImgBinder.AtlasName, out _glBmp);
                    if (_bmpAtlas == null)
                    {
                        //error
                        atlasImgBinder.State = BinderState.Error;        //not found
                        return;
                    }
                    _lastestImgFile = atlasImgBinder.AtlasName;
                }
                //--------

                if (_bmpAtlas.TryGetItem(atlasImgBinder.ImageName, out AtlasItem atlasItem))
                {
                    //found map data
                    Rectangle srcRect =
                        new Rectangle(atlasItem.Left,
                                      atlasItem.Top, //diff from font atlas***
                                      atlasItem.Width,
                                      atlasItem.Height);

                    TextureKind textureKind = _bmpAtlas.TextureKind;
                    switch (textureKind)
                    {
                    default:
                    case TextureKind.Msdf:
                        throw new NotSupportedException();

                    case TextureKind.Bitmap:
                    {
                        atlasImgBinder.State = BinderState.Loaded;
                        ImageBinder.SetCacheInnerImage(atlasImgBinder, _glBmp, false);
                        atlasImgBinder.AtlasItem = atlasItem;
                        atlasImgBinder.SetPreviewImageSize(atlasItem.Width, atlasItem.Height);
                        atlasImgBinder.RaiseImageChanged();
                        atlasImgBinder.TextureKind = textureKind;
                        glPainter.Core.DrawSubImage(_glBmp,
                                                    srcRect,
                                                    left,
                                                    top);
                    }
                    break;
                    }
                }
                else
                {
                    atlasImgBinder.State = BinderState.Error;        //not found
                }
            }
            break;
            }
#if DEBUG
            if (atlasImgBinder.State == BinderState.Unload)
            {
            }
#endif
        }
        /// <summary>
        /// use vertex buffer object
        /// </summary>

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

            _txtClient = textServices.CreateNewServiceClient();

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

            _myGLBitmapFontMx = new MySimpleGLBitmapFontManager(textServices);

            //--------
            //load preview of pre-built texture font
            //temp fix, TODO: review this again
            string[] maybeTextureInfoFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.tx_info");
            if (maybeTextureInfoFiles.Length > 0)
            {
                for (int i = 0; i < maybeTextureInfoFiles.Length; ++i)
                {
                    //try read
                    using (FileStream fs = new FileStream(maybeTextureInfoFiles[i], FileMode.Open))
                    {
                        try
                        {
                            _myGLBitmapFontMx.LoadBitmapAtlasPreview(fs);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }



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

            //test textures...

            //GlyphPosPixelSnapX = GlyphPosPixelSnapKind.Integer;
            //GlyphPosPixelSnapY = GlyphPosPixelSnapKind.Integer;
            //**
            //ChangeFont(painter.CurrentFont);
            //
            //TextDrawingTechnique = GlyphTexturePrinterDrawingTechnique.LcdSubPixelRendering; //default
            TextDrawingTechnique = GlyphTexturePrinterDrawingTechnique.Stencil; //default
            UseVBO = true;

            TextBaseline = PixelFarm.Drawing.TextBaseline.Top;
            //TextBaseline = TextBaseline.Alphabetic;
            //TextBaseline = TextBaseline.Bottom;


            //TODO: temp fix,
            //...
            var myAlternativeTypefaceSelector = new AlternativeTypefaceSelector();

            {
                var preferTypefaces = new Typography.FontCollections.PreferredTypefaceList();
                preferTypefaces.AddTypefaceName("Source Sans Pro");
                preferTypefaces.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, },
                    preferTypefaces);
            }
            {
                var preferTypefaces = new Typography.FontCollections.PreferredTypefaceList();
                preferTypefaces.AddTypefaceName("Twitter Color Emoji");
                myAlternativeTypefaceSelector.SetPerferredEmoji(preferTypefaces);
            }

            AlternativeTypefaceSelector = myAlternativeTypefaceSelector;
        }
        public bool CreateWordStrip(GLPainter painter, GLRenderVxFormattedString renderVxFormattedString)
        {
            //--------------
            //create stencil text buffer
            //we use white glyphs on black bg
            //--------------

            if (!_isInitBg)
            {
                //by default, we init bg to black for stencil buffer
                _isInitBg = true;
                painter.Clear(Color.Black);
            }


            float width = renderVxFormattedString.Width;

            if (_currentX + width > _plateWidth)
            {
                //move to newline
                _currentY += _currentLineHeightMax + INTERLINE_SPACE;//interspace =4 px
                _currentX  = 0;
                //new line
                _currentLineHeightMax = (int)Math.Ceiling(renderVxFormattedString.SpanHeight);
            }

            //on current line
            //check available height
            if (_currentY + renderVxFormattedString.SpanHeight > _plateHeight)
            {
                _full = true;
                return(false);
            }
            //----------------------------------

            if (renderVxFormattedString.SpanHeight > _currentLineHeightMax)
            {
                _currentLineHeightMax = (int)Math.Ceiling(renderVxFormattedString.SpanHeight);
            }


            Color prevColor              = painter.FontFillColor;
            Color prevTextBgHint         = painter.TextBgColorHint;
            bool  prevPreparingWordStrip = painter.PreparingWordStrip;
            GlyphTexturePrinterDrawingTechnique prevTextDrawing = painter.TextPrinterDrawingTechnique;

            painter.TextBgColorHint    = Color.Black;
            painter.FontFillColor      = Color.White;
            painter.PreparingWordStrip = true;
            renderVxFormattedString.UseWithWordPlate = false;


            GLBitmapGlyphTextPrinter textPrinter = (GLBitmapGlyphTextPrinter)painter.TextPrinter;

            switch (renderVxFormattedString.GlyphMixMode)
            {
            case GLRenderVxFormattedStringGlyphMixMode.OnlyColorGlyphs:
            {
                //TODO: review this option again
                //optional
                painter.TextPrinterDrawingTechnique = GlyphTexturePrinterDrawingTechnique.Copy;
                Rectangle currentClip = painter.ClipBox;
                painter.SetClipBox(_currentX, _currentY, (int)(_currentX + width), _currentY + _currentLineHeightMax);
                painter.Clear(Color.Transparent);
                painter.SetClipBox(currentClip.Left, currentClip.Top, currentClip.Right, currentClip.Bottom);         //restore
            }
            break;
            }

            //use special mode of the GLBitmapGlyphTextPrinter
            //-----------
            textPrinter.WordPlateCreatingMode = true;              //turn on platemode
            textPrinter.DrawString(renderVxFormattedString, _currentX, _currentY);
            textPrinter.WordPlateCreatingMode = false;             //switch back
            //-----------
            renderVxFormattedString.UseWithWordPlate = true;       //restore
            painter.FontFillColor               = prevColor;       //restore
            painter.TextBgColorHint             = prevTextBgHint;  //restore
            painter.PreparingWordStrip          = prevPreparingWordStrip;
            painter.TextPrinterDrawingTechnique = prevTextDrawing; //restore
            //in this case we can dispose vbo inside renderVx
            //(we can recreate that vbo later)
            renderVxFormattedString.DisposeVbo();

            renderVxFormattedString.OwnerPlate       = this;
            renderVxFormattedString.WordPlateLeft    = (ushort)_currentX;
            renderVxFormattedString.WordPlateTop     = (ushort)_currentY;
            renderVxFormattedString.UseWithWordPlate = true;

#if DEBUG
            dbugUsedCount++;
#endif
            _wordStrips.Add(renderVxFormattedString, true);
            //--------

            _currentX += (int)Math.Ceiling(renderVxFormattedString.Width) + INTERWORD_SPACE; //interspace x 1px

#if DEBUG
            //dbugSaveBackBuffer("dbug_test1.png");
#endif

            return(true);
        }
Exemple #8
0
        public void DrawImage(GLPainter glPainter, AtlasImageBinder atlasImgBinder, float left, float top)
        {
            switch (atlasImgBinder.State)
            {
            case LayoutFarm.BinderState.Loaded:
            {
                GLBitmap glbmp = LayoutFarm.ImageBinder.GetCacheInnerImage(atlasImgBinder) as GLBitmap;
                if (glbmp != null)
                {
                    BitmapMapData mapData = atlasImgBinder.MapData;
                    Rectangle     srcRect =
                        new Rectangle(mapData.Left,
                                      mapData.Top, //diff from font atlas***
                                      mapData.Width,
                                      mapData.Height);

                    TextureKind textureKind = _bmpAtlas.TextureKind;
                    switch (textureKind)
                    {
                    default:
                    case TextureKind.Msdf:
                        throw new NotSupportedException();

                    case TextureKind.Bitmap:
                    {
                        atlasImgBinder.State = LayoutFarm.BinderState.Loaded;
                        LayoutFarm.ImageBinder.SetCacheInnerImage(atlasImgBinder, _glBmp, false);

                        atlasImgBinder.MapData = mapData;
                        glPainter.PainterContext.DrawSubImage(_glBmp,
                                                              ref srcRect,
                                                              left,
                                                              top);
                    }
                    break;
                    }
                }
            }
            break;

            case LayoutFarm.BinderState.Unload:
            {
                //load img first
                if (_lastestImgFile != atlasImgBinder.AtlasName)
                {
                    _bmpAtlas = _atlasManager.GetBitmapAtlas(atlasImgBinder.AtlasName, out _glBmp);
                    if (_bmpAtlas == null)
                    {
                        //error
                        atlasImgBinder.State = LayoutFarm.BinderState.Error;        //not found
                        return;
                    }
                    _lastestImgFile = atlasImgBinder.AtlasName;
                }
                //--------
                if (_bmpAtlas.TryGetBitmapMapData(atlasImgBinder.ImageName, out BitmapMapData mapData))
                {
                    //found map data
                    Rectangle srcRect =
                        new Rectangle(mapData.Left,
                                      mapData.Top, //diff from font atlas***
                                      mapData.Width,
                                      mapData.Height);

                    TextureKind textureKind = _bmpAtlas.TextureKind;
                    switch (textureKind)
                    {
                    default:
                    case TextureKind.Msdf:
                        throw new NotSupportedException();

                    case TextureKind.Bitmap:
                    {
                        atlasImgBinder.State = LayoutFarm.BinderState.Loaded;
                        LayoutFarm.ImageBinder.SetCacheInnerImage(atlasImgBinder, _glBmp, false);
                        atlasImgBinder.MapData = mapData;
                        atlasImgBinder.SetPreviewImageSize(mapData.Width, mapData.Height);
                        atlasImgBinder.RaiseImageChanged();

                        glPainter.PainterContext.DrawSubImage(_glBmp,
                                                              ref srcRect,
                                                              left,
                                                              top);
                    }
                    break;
                    }
                }
                else
                {
                    atlasImgBinder.State = LayoutFarm.BinderState.Error;        //not found
                }
            }
            break;
            }
            if (atlasImgBinder.State == LayoutFarm.BinderState.Unload)
            {
            }
        }