public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] buffer, int startAt, int len)
        {
            glyphPlans.Clear();
            _glyphLayout.Layout(_typeface, buffer, startAt, len, glyphPlans);

            TextPrinterHelper.CopyGlyphPlans(renderVx, glyphPlans, _typeface.CalculateToPixelScaleFromPointSize(font.SizeInPoints));
        }
示例#2
0
        void DrawText(DrawBoard d)
        {
            //d.DrawText(_mybuffer,
            //     new Rectangle(0, 0, bWidth, bHeight),
            //     style.ContentHAlign);

            if (_renderVxFormattedString == null)
            {
                _renderVxFormattedString = d.CreateFormattedString(_mybuffer, 0, _mybuffer.Length, DelayFormattedString);
            }

            switch (_renderVxFormattedString.State)
            {
            case RenderVxFormattedString.VxState.Ready:
                d.DrawRenderVx(_renderVxFormattedString, 0, 0);
                break;

            case RenderVxFormattedString.VxState.NoStrip:
            {
                //put this to the update queue system
                //(TODO: add extension method for this)
                GlobalRootGraphic.CurrentRootGfx.EnqueueRenderRequest(
                    new RenderBoxes.RenderElementRequest(
                        s_currentRenderE,
                        RenderBoxes.RequestCommand.ProcessFormattedString,
                        _renderVxFormattedString));
            }
            break;
            }
        }
 public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] text, int startAt, int len)
 {
     //1. update some props..
     //2. update current type face
     UpdateGlyphLayoutSettings();
     Typeface typeface = _currentTypeface;
 }
示例#4
0
        public void DrawText(RenderVxFormattedString renderVxFormattedString, float x, float y)
        {
#if DEBUG
            dbugCounter.dbugDrawStringCount++;
#endif
            switch (renderVxFormattedString.State)
            {
            case RenderVxFormattedString.VxState.Ready:
            {
                //int ox = _drawBoard.OriginX;
                //int oy = _drawBoard.OriginY;
                //_drawBoard.SetCanvasOrigin((int)point.X, (int)point.Y);
                _drawBoard.TextBackgroundColorHint = this.CurrentSolidBackgroundColorHint;
                _drawBoard.DrawRenderVx(renderVxFormattedString, x, y);
                //_drawBoard.SetCanvasOrigin(ox, oy);//restore
            }
            break;

            case RenderVxFormattedString.VxState.NoStrip:
            {
                //put this to the update queue system
                //(TODO: add extension method for this)

                //GlobalRootGraphic.CurrentRootGfx.EnqueueRenderRequest(
                //    new RenderBoxes.RenderElementRequest(
                //        s_currentRenderE,
                //        RenderBoxes.RequestCommand.ProcessFormattedString,
                //        renderVxFormattedString));
            }
            break;
            }
        }
示例#5
0
        public override void Draw(Painter p)
        {
            //painter.DrawString("hello world!", 100, 100);
            //painter.DrawString("กิ่น", 100, 100);
            // string test_str = "อูญูอุบ่ป่กินกิ่นก็โก้";
            //string test_str = "ปู่";
            //string test_str = "ก็";
            string test_str = "abcd";

            //string test_str = "A";
            //string test_str = "012345";
            //string test_str = "กิน";
            p.Clear(PixelFarm.Drawing.Color.White);
            p.FillColor = PixelFarm.Drawing.Color.Red;

            p.UseSubPixelLcdEffect = true;
            int n = 50;

            for (int i = 0; i < n; i++)
            {
                //  p.DrawString(test_str, i * 10, i * 10);
                float x_pos = i * 20;
                float y_pos = i * 20;
                p.FillRect(x_pos, y_pos, x_pos + 5, y_pos + 5);
            }
            p.FillColor = PixelFarm.Drawing.Color.Black;

            if (_strRenderVx_1 == null)
            {
                p.CurrentFont  = _font1;
                _strRenderVx_1 = p.CreateRenderVx(test_str);
            }
            if (_strRenderVx_2 == null)
            {
                p.CurrentFont  = _font2;
                _strRenderVx_2 = p.CreateRenderVx(test_str);
            }
            //
            for (int i = 0; i < n; i++)
            {
                float x_pos = i * 20;
                float y_pos = i * 20;
                //p.DrawString("(" + x_pos + "," + y_pos + ")", x_pos, y_pos);
                if ((i % 2) == 0)
                {
                    //since draw string may be slow
                    //we can convert it to a 'freezed' visual object (RenderVx)
                    p.CurrentFont = _font1;
                    p.DrawString(_strRenderVx_1, x_pos, y_pos);
                }
                else
                {
                    //since draw string may be slow
                    //we can convert it to a 'freezed' visual object (RenderVx)
                    p.CurrentFont = _font2;
                    p.DrawString(_strRenderVx_2, x_pos, y_pos);
                }
            }
        }
示例#6
0
 public void Dispose()
 {
     if (_renderVxFormattedString != null)
     {
         _renderVxFormattedString.Dispose();
         _renderVxFormattedString = null;
     }
 }
示例#7
0
 public override void DrawString(RenderVxFormattedString renderVx, double x, double y)
 {
     //
     if (_textPrinter != null)
     {
         _textPrinter.DrawString(renderVx, x, y);
     }
 }
        public void DrawString(RenderVxFormattedString renderVx, double x, double y)
        {
            _glsx.LoadTexture1(_glBmp);

            _glsx.FontFillColor = painter.FontFillColor;
            DrawingGL.GLRenderVxFormattedString renderVxString1 = (DrawingGL.GLRenderVxFormattedString)renderVx;
            DrawingGL.VertexBufferObject2       vbo             = renderVxString1.GetVbo();

            vbo.Bind();
            _glsx.DrawGlyphImageWithSubPixelRenderingTechnique4(renderVxString1.VertexCount, (float)x, (float)y);
            vbo.UnBind();
        }
示例#9
0
        public void DrawString(RenderVxFormattedString renderVx, double x, double y)
        {
            float ox = canvasPainter.OriginX;
            float oy = canvasPainter.OriginY;

            //1. update some props..
            //2. update current type face
            UpdateTypefaceAndGlyphBuilder();
            Typeface typeface = _glyphPathBuilder.Typeface;
            //3. layout glyphs with selected layout technique
            //TODO: review this again, we should use pixel?
            float fontSizePoint = this.FontSizeInPoints;
            float scale         = typeface.CalculateToPixelScaleFromPointSize(fontSizePoint);

            RenderVxGlyphPlan[] glyphPlans = renderVx.glyphList;
            int j = glyphPlans.Length;

            //---------------------------------------------------
            //consider use cached glyph, to increase performance
            hintGlyphCollection.SetCacheInfo(typeface, fontSizePoint, this.HintTechnique);
            //---------------------------------------------------

            for (int i = 0; i < j; ++i)
            {
                RenderVxGlyphPlan glyphPlan = glyphPlans[i];
                //-----------------------------------
                //TODO: review here ***
                //PERFORMANCE revisit here
                //if we have create a vxs we can cache it for later use?
                //-----------------------------------
                VertexStore glyphVxs;
                if (!hintGlyphCollection.TryGetCacheGlyph(glyphPlan.glyphIndex, out glyphVxs))
                {
                    //if not found then create new glyph vxs and cache it
                    _glyphPathBuilder.SetHintTechnique(this.HintTechnique);
                    _glyphPathBuilder.BuildFromGlyphIndex(glyphPlan.glyphIndex, fontSizePoint);
                    //-----------------------------------
                    _tovxs.Reset();
                    _glyphPathBuilder.ReadShapes(_tovxs);

                    //TODO: review here,
                    //float pxScale = _glyphPathBuilder.GetPixelScale();
                    glyphVxs = new VertexStore();
                    _tovxs.WriteOutput(glyphVxs, _vxsPool);
                    //
                    hintGlyphCollection.RegisterCachedGlyph(glyphPlan.glyphIndex, glyphVxs);
                }
                canvasPainter.SetOrigin((float)(glyphPlan.x * scale + x), (float)(glyphPlan.y * scale + y));
                canvasPainter.Fill(glyphVxs);
            }
            //restore prev origin
            canvasPainter.SetOrigin(ox, oy);
        }
示例#10
0
        public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] buffer, int startAt, int len)
        {
            var renderVxFormattedString = renderVx as GLRenderVxFormattedString;

#if DEBUG
            if (renderVxFormattedString == null)
            {
                throw new NotSupportedException();
            }
#endif
            PrepareStringForRenderVx(renderVxFormattedString, buffer, startAt, len);
        }
示例#11
0
        //each editable run has it own (dynamic) char buffer
        void SetNewContent(char[] newbuffer)
        {
#if DEBUG
            _dbugmybuffer = newbuffer;
#else
            _mybuffer = newbuffer;
#endif

            _content_unparsed = true;

            _renderVxFormattedString?.Dispose(); //clear old _renderVxFormattedString
            _renderVxFormattedString = null;
        }
示例#12
0
        public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] text, int startAt, int len)
        {
            //1. update some props..
            //2. update current type face
            UpdateTypefaceAndGlyphBuilder();
            Typeface typeface = _currentTypeface;// _glyphPathBuilder.Typeface;

            _glyphLayout.Typeface = typeface;
            _glyphLayout.Layout(text, startAt, len);
            //
            //3. scale from design unit to specific font size
            _outputGlyphPlans.Clear();
            _pxScaleEngine.Layout(_glyphLayout.ResultUnscaledGlyphPositions, _outputGlyphPlans);
            TextPrinterHelper.CopyGlyphPlans(renderVx, _outputGlyphPlans, this._currentFontSizePxScale);
        }
        public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] text, int startAt, int len)
        {
            //1. update some props..
            //2. update current type face
            UpdateTypefaceAndGlyphBuilder();
            Typeface typeface = _currentTypeface;// _glyphPathBuilder.Typeface;
            //3. layout glyphs with selected layout technique
            //TODO: review this again, we should use pixel?

            float pxscale = typeface.CalculateToPixelScaleFromPointSize(FontSizeInPoints);

            _outputGlyphPlans.Clear();
            _glyphLayout.Layout(typeface, text, startAt, len, _outputGlyphPlans);
            TextPrinterHelper.CopyGlyphPlans(renderVx, _outputGlyphPlans, pxscale);
        }
示例#14
0
        public override void UpdateRunWidth()
        {
            //***
            var textBufferSpan = new Typography.Text.TextBufferSpan(_mybuffer);

            //TODO: review here,
            //1. if mybuffer lenght is not changed,we don't need to alloc new array?

            _outputUserCharAdvances = new int[_mybuffer.Length];

            if (_renderVxFormattedString != null)
            {
                _renderVxFormattedString.Dispose();
                _renderVxFormattedString = null;
            }

            var measureResult = new TextSpanMeasureResult();

            measureResult.outputXAdvances = _outputUserCharAdvances;


            if (_content_unparsed)
            {
                //parse the content first
                if (_lineSegs == null)
                {
                    _lineSegs = new TextPrinterLineSegmentList <TextPrinterLineSegment>();
                }
                _lineSegs.Clear();
                //
                if (s_wordVistor == null)
                {
                    s_wordVistor = new TextPrinterWordVisitor();
                }

                s_wordVistor.SetLineSegmentList(_lineSegs);
                RunStyle.BreakToLineSegments(textBufferSpan, s_wordVistor);
                s_wordVistor.SetLineSegmentList(null);

                //BreakToLineSegs(textBufferSpan);
            }
            _content_unparsed = false;
            RunStyle.CalculateUserCharGlyphAdvancePos(textBufferSpan, _lineSegs, ref measureResult);

            SetSize(measureResult.outputTotalW, measureResult.lineHeight);

            InvalidateGraphics();
        }
示例#15
0
        public void DrawString(RenderVxFormattedString renderVx, double x, double y)
        {
            //TODO: review here
            float ox = _painter.OriginX;
            float oy = _painter.OriginY;

            //1. update some props..
            //2. update current type face
            UpdateGlyphLayoutSettings();
            _glyphMeshStore.SetFont(_currentTypeface, this.FontSizeInPoints);
            _glyphMeshStore.SimulateOblique = this.SimulateSlant;

            //3. layout glyphs with selected layout technique
            //TODO: review this again, we should use pixel?
            float fontSizePoint = this.FontSizeInPoints;
            float scale         = _currentTypeface.CalculateScaleToPixelFromPointSize(fontSizePoint);

            RenderVxGlyphPlan[] glyphPlans = renderVx.GlyphList;
            int j = glyphPlans.Length;
            //---------------------------------------------------
            //consider use cached glyph, to increase performance

            //GlyphPosPixelSnapKind x_snap = this.GlyphPosPixelSnapX;
            //GlyphPosPixelSnapKind y_snap = this.GlyphPosPixelSnapY;
            float g_x   = 0;
            float g_y   = 0;
            float baseY = (int)y;

            for (int i = 0; i < j; ++i)
            {
                RenderVxGlyphPlan glyphPlan = glyphPlans[i];
                //-----------------------------------
                //TODO: review here ***
                //PERFORMANCE revisit here
                //if we have create a vxs we can cache it for later use?
                //-----------------------------------
                VertexStore vxs = _glyphMeshStore.GetGlyphMesh(glyphPlan.glyphIndex);
                g_x = (float)(glyphPlan.x * scale + x);
                g_y = (float)glyphPlan.y * scale;

                _painter.SetOrigin(g_x, g_y);
                _painter.Fill(vxs);
            }
            //restore prev origin
            _painter.SetOrigin(ox, oy);
        }
示例#16
0
        public static void CopyGlyphPlans(RenderVxFormattedString renderVx, GlyphPlanList glyphPlans, float scale)
        {
            int n = glyphPlans.Count;
            //copy
            var renderVxGlyphPlans = new RenderVxGlyphPlan[n];

            for (int i = 0; i < n; ++i)
            {
                GlyphPlan glyphPlan = glyphPlans[i];
                renderVxGlyphPlans[i] = new RenderVxGlyphPlan(
                    glyphPlan.glyphIndex,
                    glyphPlan.ExactX,
                    glyphPlan.ExactY,
                    glyphPlan.AdvanceX
                    );
            }
            renderVx.glyphList = renderVxGlyphPlans;
        }
示例#17
0
        public static void CopyGlyphPlans(RenderVxFormattedString renderVx, List <GlyphPlan> glyphPlans, float scale)
        {
            int n = glyphPlans.Count;
            //copy
            var renderVxGlyphPlans = new RenderVxGlyphPlan[n];

            for (int i = 0; i < n; ++i)
            {
                GlyphPlan glyphPlan = glyphPlans[i];
                renderVxGlyphPlans[i] = new RenderVxGlyphPlan(
                    glyphPlan.glyphIndex,
                    glyphPlan.x * scale,
                    glyphPlan.y * scale,
                    glyphPlan.advX * scale
                    );
            }
            renderVx.glyphList = renderVxGlyphPlans;
        }
示例#18
0
        public override void CustomDrawToThisCanvas(DrawBoard canvas, Rectangle updateArea)
        {
            if (this.textBuffer != null)
            {
                var prevColor = canvas.CurrentTextColor;
                canvas.CurrentTextColor = textColor;
                canvas.CurrentFont      = _font;

                //for faster text drawing
                //we create a formatted-text
                //canvas.DrawText(this.textBuffer, this.X, this.Y);
                if (renderVxFormattedString == null)
                {
                    renderVxFormattedString = canvas.CreateFormattedString(textBuffer, 0, textBuffer.Length);
                }
                canvas.DrawRenderVx(renderVxFormattedString, this.X, this.Y);
                canvas.CurrentTextColor = prevColor;
            }
        }
示例#19
0
        public static void CopyGlyphPlans(RenderVxFormattedString renderVx, UnscaledGlyphPlanList glyphPlans, float scale)
        {
            int n = glyphPlans.Count;
            //copy
            var   renderVxGlyphPlans = new RenderVxGlyphPlan[n];
            float acc_x = 0;
            float acc_y = 0;
            float x     = 0;
            float y     = 0;
            float g_x   = 0;
            float g_y   = 0;

            for (int i = 0; i < n; ++i)
            {
                UnscaledGlyphPlan glyphPlan = glyphPlans[i];


                float ngx = acc_x + (float)Math.Round(glyphPlan.OffsetX * scale);
                float ngy = acc_y + (float)Math.Round(glyphPlan.OffsetY * scale);
                //NOTE:
                // -glyphData.TextureXOffset => restore to original pos
                // -glyphData.TextureYOffset => restore to original pos
                //--------------------------
                g_x = (float)(x + ngx); //ideal x
                g_y = (float)(y + ngy);


                float g_w = (float)Math.Round(glyphPlan.AdvanceX * scale);
                acc_x += g_w;

                //g_x = (float)Math.Round(g_x);
                g_y = (float)Math.Floor(g_y);


                renderVxGlyphPlans[i] = new RenderVxGlyphPlan(
                    glyphPlan.glyphIndex,
                    g_x,
                    g_y,
                    g_w
                    );
            }
            renderVx.glyphList = renderVxGlyphPlans;
        }
示例#20
0
        public void DrawString(RenderVxFormattedString renderVx, double x, double y)
        {
            RenderVxGlyphPlan[] glyphPlans = renderVx.glyphList;
            int n = glyphPlans.Length;

            EnsureLoadGLBmp();

            //PERF:
            //TODO: review here, can we cache the glbmp for later use
            //not to create it every time

            float scaleFromTexture = _finalTextureScale;

            TextureKind textureKind = _fontAtlas.TextureKind;
            float       g_x         = 0;
            float       g_y         = 0;
            int         baseY       = (int)Math.Round(y);
            float       scale       = 1;

            for (int i = 0; i < n; ++i)
            {
                //PERF:
                //TODO:
                //render a set of glyph instead of one glyph per time ***
                RenderVxGlyphPlan glyph = glyphPlans[i];
                Typography.Rendering.TextureFontGlyphData glyphData;
                if (!_fontAtlas.TryGetGlyphDataByCodePoint(glyph.glyphIndex, out glyphData))
                {
                    //if no glyph data, we should render a missing glyph ***

                    continue;
                }
                //--------------------------------------
                //TODO: review precise height in float
                //--------------------------------------
                PixelFarm.Drawing.Rectangle srcRect = ConvToRect(glyphData.Rect);
                //--------------------------
                g_x = (float)(x + (glyph.x * scale - glyphData.TextureXOffset) * scaleFromTexture); //ideal x
                g_y = (float)((glyph.y * scale - glyphData.TextureYOffset + srcRect.Height) * scaleFromTexture);

                switch (textureKind)
                {
                case TextureKind.Msdf:

                    _glsx.DrawSubImageWithMsdf(_glBmp,
                                               ref srcRect,
                                               g_x,
                                               g_y,
                                               scaleFromTexture);

                    break;

                case TextureKind.StencilGreyScale:

                    //stencil gray scale with fill-color
                    _glsx.DrawGlyphImageWithStecil(_glBmp,
                                                   ref srcRect,
                                                   g_x,
                                                   g_y,
                                                   scaleFromTexture);

                    break;

                case TextureKind.Bitmap:
                    _glsx.DrawSubImage(_glBmp,
                                       ref srcRect,
                                       g_x,
                                       g_y,
                                       scaleFromTexture);
                    break;

                case TextureKind.StencilLcdEffect:
                    _glsx.DrawGlyphImageWithSubPixelRenderingTechnique(_glBmp,
                                                                       ref srcRect,
                                                                       g_x,
                                                                       g_y,
                                                                       scaleFromTexture);
                    break;
                }
            }
        }
 public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] text, int start, int len)
 {
     throw new NotImplementedException();
 }
示例#22
0
 public override void DrawString(RenderVxFormattedString renderVx, double x, double y)
 {
     //TODO: review here again
     _skCanvas.DrawText(renderVx.OriginalString, (float)x, (float)y, _stroke);
 }
示例#23
0
 public abstract void DrawString(RenderVxFormattedString renderVx, double x, double y);
示例#24
0
 public void DrawText(RenderVxFormattedString formattedStr, PointF point, SizeF size)
 {
     _drawBoard.GetPainter().DrawString(formattedStr, point.X, point.Y);
 }
示例#25
0
 public void DrawString(RenderVxFormattedString renderVx, double x, double y)
 {
     DrawString((GLRenderVxFormattedString)renderVx, x, y);
 }
        public void DrawString(RenderVxFormattedString renderVx, double x, double y)
        {
            RenderVxGlyphPlan[] glyphPlans = renderVx.glyphList;
            int n = glyphPlans.Length;

            EnsureLoadGLBmp();

            //PERF:
            //TODO: review here, can we cache the glbmp for later use
            //not to create it every time

            float scaleFromTexture = _finalTextureScale;

            Typography.Rendering.TextureKind textureKind = simpleFontAtlas.TextureKind;
            float g_x   = 0;
            float g_y   = 0;
            int   baseY = (int)Math.Round(y);
            float scale = 1;

            for (int i = 0; i < n; ++i)
            {
                //PERF:
                //TODO:
                //render a set of glyph instead of one glyph per time ***
                RenderVxGlyphPlan glyph = glyphPlans[i];
                Typography.Rendering.TextureFontGlyphData glyphData;
                if (!simpleFontAtlas.TryGetGlyphDataByCodePoint(glyph.glyphIndex, out glyphData))
                {
                    continue;
                }
                //--------------------------------------
                //TODO: review precise height in float
                //--------------------------------------
                PixelFarm.Drawing.Rectangle srcRect = ConvToRect(glyphData.Rect);
                //--------------------------
                GlyphPosPixelSnapKind x_snap = this.GlyphPosPixelSnapX;
                GlyphPosPixelSnapKind y_snap = this.GlyphPosPixelSnapY;
                switch (x_snap)
                {
                default: throw new NotSupportedException();

                case GlyphPosPixelSnapKind.Integer:
                {
                    g_x = (float)(x + (glyph.x * scale - glyphData.TextureXOffset) * scaleFromTexture);         //ideal x
                    int floor_x = (int)g_x;

                    //round to int 0,1
                    if (g_x - floor_x >= (1f / 2f))
                    {
                        g_x = floor_x + 1;
                    }
                    else
                    {
                        g_x = floor_x;
                    }
                }
                break;

                case GlyphPosPixelSnapKind.Half:
                {
                    g_x = (float)(x + (glyph.x * scale - glyphData.TextureXOffset) * scaleFromTexture);         //ideal x
                                                                                                                //adjust
                    int floor_x = (int)g_x;
                    //round to int 0, 0.5,1.0
                    if (g_x - floor_x >= (2f / 3f))
                    {
                        g_x = floor_x + 1;
                    }
                    else if (g_x - floor_x >= (1f / 3f))
                    {
                        g_x = floor_x + 0.5f;
                    }
                    else
                    {
                        g_x = floor_x;
                    }
                }
                break;

                case GlyphPosPixelSnapKind.None:
                    g_x = (float)(x + (glyph.x * scale - glyphData.TextureXOffset) * scaleFromTexture);
                    break;
                }
                //
                switch (y_snap)
                {
                default: throw new NotSupportedException();

                case GlyphPosPixelSnapKind.Integer:
                    //use baseY not y
                {
                    g_y = (float)((glyph.y * scale - glyphData.TextureYOffset + srcRect.Height) * scaleFromTexture);
                    int floor_y = (int)g_y;
                    //round to int 0,1
                    if (g_y - floor_y >= (1f / 2f))
                    {
                        g_y = floor_y + 1;
                    }
                    else
                    {
                        g_y = floor_y;
                    }
                    g_y = baseY + g_y;
                }
                break;

                case GlyphPosPixelSnapKind.Half:
                    //review here
                    //use baseY not y
                {
                    g_y = (float)((glyph.y * scale - glyphData.TextureYOffset + srcRect.Height) * scaleFromTexture);
                    int floor_y = (int)g_y;
                    //round to int 0, 0.5,1.0
                    if (g_y - floor_y >= (2f / 3f))
                    {
                        g_y = floor_y + 1;
                    }
                    else if (g_x - floor_y >= (1f / 3f))
                    {
                        g_y = floor_y + 0.5f;
                    }
                    else
                    {
                        g_y = floor_y;
                    }
                    g_y = baseY + g_y;
                }
                break;

                case GlyphPosPixelSnapKind.None:
                    //use Y not baseY
                    g_y = (float)(y + (glyph.y * scale - glyphData.TextureYOffset + srcRect.Height) * scaleFromTexture);
                    break;
                }
                switch (textureKind)
                {
                case Typography.Rendering.TextureKind.Msdf:

                    canvas2d.DrawSubImageWithMsdf(_glBmp,
                                                  ref srcRect,
                                                  g_x,
                                                  g_y,
                                                  scaleFromTexture);

                    break;

                case Typography.Rendering.TextureKind.AggGrayScale:

                    canvas2d.DrawSubImage(_glBmp,
                                          ref srcRect,
                                          g_x,
                                          g_y,
                                          scaleFromTexture);

                    break;

                case Typography.Rendering.TextureKind.AggSubPixel:
                    canvas2d.DrawGlyphImageWithSubPixelRenderingTechnique(_glBmp,
                                                                          ref srcRect,
                                                                          g_x,
                                                                          g_y,
                                                                          scaleFromTexture);
                    break;
                }
                //-----------
                //backup
                //switch (textureKind)
                //{
                //    case Typography.Rendering.TextureKind.Msdf:
                //        {
                //            canvas2d.DrawSubImageWithMsdf(_glBmp,
                //                ref srcRect,
                //                (float)(x + (glyph.x - glyphData.TextureXOffset) * scaleFromTexture), // -glyphData.TextureXOffset => restore to original pos
                //                (float)(y + (glyph.y - glyphData.TextureYOffset + srcRect.Height) * scaleFromTexture),// -glyphData.TextureYOffset => restore to original pos
                //                scaleFromTexture);
                //        }
                //        break;
                //    case Typography.Rendering.TextureKind.AggGrayScale:
                //        {
                //            canvas2d.DrawSubImage(_glBmp,
                //              ref srcRect,
                //              (float)(x + (glyph.x - glyphData.TextureXOffset) * scaleFromTexture), // -glyphData.TextureXOffset => restore to original pos
                //              (float)(y + (glyph.y - glyphData.TextureYOffset + srcRect.Height) * scaleFromTexture),// -glyphData.TextureYOffset => restore to original pos
                //              scaleFromTexture);
                //        }
                //        break;
                //    case Typography.Rendering.TextureKind.AggSubPixel:
                //        canvas2d.DrawGlyphImageWithSubPixelRenderingTechnique(_glBmp,
                //                 ref srcRect,
                //                 (float)(x + (glyph.x - glyphData.TextureXOffset) * scaleFromTexture), // -glyphData.TextureXOffset => restore to original pos
                //                 (float)(y + (glyph.y - glyphData.TextureYOffset + srcRect.Height) * scaleFromTexture),// -glyphData.TextureYOffset => restore to original pos
                //                 scaleFromTexture);
                //        break;
                //}
            }
        }
示例#27
0
 public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] text, int startAt, int len)
 {
     UpdateGlyphLayoutSettings();
 }
        public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] buffer, int startAt, int len)
        {
            int j = buffer.Length;

            //create temp buffer span that describe the part of a whole char buffer
            TextBufferSpan textBufferSpan = new TextBufferSpan(buffer, startAt, len);

            //ask text service to parse user input char buffer and create a glyph-plan-sequence (list of glyph-plan)
            //with specific request font
            GlyphPlanSequence glyphPlanSeq = _textServices.CreateGlyphPlanSeq(ref textBufferSpan, font);

            float scale = _fontAtlas.TargetTextureScale;
            int   recommendLineSpacing = _fontAtlas.OriginalRecommendLineSpacing;

            //--------------------------
            //TODO:
            //if (x,y) is left top
            //we need to adjust y again
            float x = 0;
            float y = 0;

            y -= ((recommendLineSpacing) * scale);
            renderVx.RecommmendLineSpacing = (int)(recommendLineSpacing * scale);

            //
            float       scaleFromTexture = _finalTextureScale;
            TextureKind textureKind      = _fontAtlas.TextureKind;

            //--------------------------

            //TODO: review render steps
            //NOTE:
            // -glyphData.TextureXOffset => restore to original pos
            // -glyphData.TextureYOffset => restore to original pos
            // ideal_x = (float)(x + (glyph.x * scale - glyphData.TextureXOffset) * scaleFromTexture);
            // ideal_y = (float)(y + (glyph.y * scale - glyphData.TextureYOffset + srcRect.Height) * scaleFromTexture);
            //--------------------------

            float g_x       = 0;
            float g_y       = 0;
            int   baseY     = (int)Math.Round(y);
            int   n         = glyphPlanSeq.len;
            int   endBefore = glyphPlanSeq.startAt + n;

            //***
            _glsx.SetAssociatedTextureInfo(_glBmp);
            //
            vboBufferList2.Clear();
            indexList2.Clear();

            float acc_x = 0;
            float acc_y = 0;

            for (int i = glyphPlanSeq.startAt; i < endBefore; ++i)
            {
                UnscaledGlyphPlanList glyphPlanList = GlyphPlanSequence.UnsafeGetInteralGlyphPlanList(glyphPlanSeq);
                UnscaledGlyphPlan     glyph         = glyphPlanList[i];

                Typography.Rendering.TextureFontGlyphData glyphData;
                if (!_fontAtlas.TryGetGlyphDataByGlyphIndex(glyph.glyphIndex, out glyphData))
                {
                    //if no glyph data, we should render a missing glyph ***
                    continue;
                }

                //--------------------------------------
                //TODO: review precise height in float
                //--------------------------------------
                PixelFarm.Drawing.Rectangle srcRect = ConvToRect(glyphData.Rect);

                float ngx = acc_x + (float)Math.Round(glyph.OffsetX * scale);
                float ngy = acc_y + (float)Math.Round(glyph.OffsetY * scale);

                //NOTE:
                // -glyphData.TextureXOffset => restore to original pos
                // -glyphData.TextureYOffset => restore to original pos
                //--------------------------
                g_x = (float)(x + (ngx - glyphData.TextureXOffset) * scaleFromTexture); //ideal x
                g_y = (float)(y + (ngy - glyphData.TextureYOffset + srcRect.Height) * scaleFromTexture);


                acc_x += (float)Math.Round(glyph.AdvanceX * scale);

                //g_x = (float)Math.Round(g_x);
                g_y = (float)Math.Floor(g_y);



                switch (textureKind)
                {
                case TextureKind.Msdf:

                    _glsx.DrawSubImageWithMsdf(_glBmp,
                                               ref srcRect,
                                               g_x,
                                               g_y,
                                               scaleFromTexture);

                    break;

                case TextureKind.StencilGreyScale:

                    //stencil gray scale with fill-color
                    _glsx.DrawGlyphImageWithStecil(_glBmp,
                                                   ref srcRect,
                                                   g_x,
                                                   g_y,
                                                   scaleFromTexture);

                    break;

                case TextureKind.Bitmap:
                    _glsx.DrawSubImage(_glBmp,
                                       ref srcRect,
                                       g_x,
                                       g_y,
                                       scaleFromTexture);
                    break;

                case TextureKind.StencilLcdEffect:
                    _glsx.WriteVboToList(
                        vboBufferList2,
                        indexList2,
                        ref srcRect,
                        g_x,
                        g_y,
                        scaleFromTexture);
                    break;
                }
            }
            //---------

            DrawingGL.GLRenderVxFormattedString renderVxFormattedString = (DrawingGL.GLRenderVxFormattedString)renderVx;
            renderVxFormattedString.IndexArray   = indexList2.ToArray();
            renderVxFormattedString.VertexCoords = vboBufferList2.ToArray();
            renderVxFormattedString.VertexCount  = indexList2.Count;
        }
示例#29
0
 public override void DrawString(RenderVxFormattedString renderVx, double x, double y)
 {
     throw new NotImplementedException();
 }
示例#30
0
 public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] buffer, int startAt, int len)
 {
     //TextPrinterHelper.CopyGlyphPlans(renderVx, glyphPlans, _typeface.CalculateScaleToPixelFromPointSize(font.SizeInPoints));
 }