Represents a word inside an inline box
Inheritance: CssRun
Beispiel #1
0
 public static void SetCachedFormattedString(CssTextRun textrun, PixelFarm.Drawing.RenderVxFormattedString cache)
 {
     if (textrun._cacheRenderVx != null && textrun._cacheRenderVx != cache)
     {
         textrun._cacheRenderVx.Dispose();
     }
     textrun._cacheRenderVx = cache;
 }
Beispiel #2
0
        /// <summary>
        /// Assigns words its width and height
        /// </summary>
        /// <param name="g"></param>
        public virtual void MeasureRunsSize(LayoutVisitor lay)
        {
            //measure once !
            if ((_boxCompactFlags & BoxFlags.LAY_RUNSIZE_MEASURE) != 0)
            {
                return;
            }
            //--------------------------------
            if (this.BackgroundImageBinder != null)
            {
                //this has background
                if (this.BackgroundImageBinder.State == BinderState.Unload)
                {
                    lay.RequestImage(this.BackgroundImageBinder, this);
                }
            }
            //--------------------------------
            if (this.RunCount > 0)
            {
                //find word spacing
                float       actualWordspacing = _actualWordSpacing;
                RequestFont actualFont        = this.ResolvedFont;


                float fontHeight = (actualFont.AscentInPixels - actualFont.DescentInPixels + actualFont.LineGapInPixels);
                fontHeight += 4; //TODO: why +4 ????***

                List <CssRun> tmpRuns = this.Runs;
                for (int i = tmpRuns.Count - 1; i >= 0; --i)
                {
                    CssRun run = tmpRuns[i];
                    run.Height = fontHeight;
                    //if this is newline then width =0 ***
                    switch (run.Kind)
                    {
                    case CssRunKind.Text:
                    {
                        CssTextRun textRun = (CssTextRun)run;
                        Size       ss      = lay.MeasureStringSize(CssBox.UnsafeGetTextBuffer(this),
                                                                   textRun.TextStartIndex,
                                                                   textRun.TextLength,
                                                                   actualFont);
                        run.SetSize(ss.Width, ss.Height);
                    }
                    break;

                    case CssRunKind.SingleSpace:
                    {
                        run.Width = actualWordspacing;
                    }
                    break;

                    case CssRunKind.Space:
                    {
                        //other space size
                        run.Width = actualWordspacing * ((CssTextRun)run).TextLength;
                    }
                    break;

                    case CssRunKind.LineBreak:
                    {
                        run.Width = 0;
                    }
                    break;
                    }
                }
            }
            _boxCompactFlags |= BoxFlags.LAY_RUNSIZE_MEASURE;
        }
        internal void PaintRuns(PaintVisitor p)
        {
            List <CssRun> tmpRuns = _runs;
            int           j       = tmpRuns.Count;

            if (j < 1)
            {
                return;
            }
            //-----------------------


            //iterate from each words
            CssBox      latestOwner = null;
            DrawBoard   innerCanvas = p.InnerDrawBoard;
            RequestFont enterFont   = innerCanvas.CurrentFont;
            Color       enterColor  = innerCanvas.CurrentTextColor;

            for (int i = 0; i < j; ++i)
            {
                //-----------------
#if DEBUG
                dbugCounter.dbugRunPaintCount++;
#endif
                //-----------------

                CssRun w = tmpRuns[i];
                switch (w.Kind)
                {
                case CssRunKind.SolidContent:
                {
                    w.OwnerBox.Paint(p, new RectangleF(w.Left, w.Top, w.Width, w.Height));
                }
                break;

                case CssRunKind.BlockRun:
                {
                    //Console.WriteLine("blockrun");
                    CssBlockRun blockRun = (CssBlockRun)w;
                    int         ox       = p.CanvasOriginX;
                    int         oy       = p.CanvasOriginY;
                    //p.SetCanvasOrigin(ox + (int)(blockRun.Left + blockRun.ContentBox.LocalX), oy + (int)blockRun.Top);
                    p.SetCanvasOrigin(ox + (int)(blockRun.Left), oy + (int)blockRun.Top);
                    blockRun.ContentBox.Paint(p);
                    p.SetCanvasOrigin(ox, oy);
                }
                break;

                case CssRunKind.Text:
                {
                    if (latestOwner != w.OwnerBox)
                    {
                        //change
                        latestOwner = w.OwnerBox;
                        //change font when change owner

                        p.InnerDrawBoard.CurrentFont      = latestOwner.ResolvedFont;
                        p.InnerDrawBoard.CurrentTextColor = latestOwner.ActualColor;
                    }

                    CssTextRun textRun = (CssTextRun)w;
                    p.DrawText(CssBox.UnsafeGetTextBuffer(w.OwnerBox),
                               textRun.TextStartIndex,
                               textRun.TextLength,
                               new PointF(w.Left, w.Top),
                               new SizeF(w.Width, w.Height));
                }
                break;

                default:
                {
#if DEBUG
                    // w.OwnerBox.dbugPaintTextWordArea(g, offset, w);
#endif
                }
                break;
                }
            }


            innerCanvas.CurrentFont      = enterFont;
            innerCanvas.CurrentTextColor = enterColor;
        }
Beispiel #4
0
        internal void PaintRuns(PaintVisitor p)
        {
            List <CssRun> tmpRuns = _runs;
            int           j       = tmpRuns.Count;

            if (j < 1)
            {
                return;
            }
            //-----------------------


            //iterate from each words
            CssBox      latestOwner = null;
            DrawBoard   innerCanvas = p.InnerDrawBoard;
            RequestFont enterFont   = innerCanvas.CurrentFont;
            Color       enterColor  = innerCanvas.CurrentTextColor;

            for (int i = 0; i < j; ++i)
            {
                //-----------------
#if DEBUG
                dbugCounter.dbugRunPaintCount++;
#endif
                //-----------------

                CssRun w = tmpRuns[i];
                switch (w.Kind)
                {
                case CssRunKind.SolidContent:
                {
#if DEBUG
                    //System.Diagnostics.Debug.WriteLine("ox,oy=" + p.CanvasOriginX + "," + p.CanvasOriginY);
                    //System.Diagnostics.Debug.WriteLine("clip=" + p.CurrentClipRect);
#endif

                    Rectangle currentClipRect = p.CurrentClipRect;
                    Rectangle wRect           = new Rectangle((int)w.Left, (int)w.Top, (int)w.Width, (int)w.Height);
                    wRect.Intersect(currentClipRect);
#if DEBUG
                    //System.Diagnostics.Debug.WriteLine("empty_clip=" + (wRect.Height == 0 || wRect.Width == 0));
#endif

                    if (wRect.Height != 0 && wRect.Width != 0)
                    {
                        w.OwnerBox.Paint(p, new RectangleF(w.Left, w.Top, w.Width, w.Height));
                    }
                }
                break;

                case CssRunKind.BlockRun:
                {
                    //Console.WriteLine("blockrun");
                    CssBlockRun blockRun = (CssBlockRun)w;
                    int         ox       = p.CanvasOriginX;
                    int         oy       = p.CanvasOriginY;
                    //p.SetCanvasOrigin(ox + (int)(blockRun.Left + blockRun.ContentBox.LocalX), oy + (int)blockRun.Top);
                    p.SetCanvasOrigin(ox + (int)(blockRun.Left), oy + (int)blockRun.Top);
                    blockRun.ContentBox.Paint(p);
                    p.SetCanvasOrigin(ox, oy);
                }
                break;

                case CssRunKind.Text:
                {
                    if (latestOwner != w.OwnerBox)
                    {
                        //change
                        latestOwner = w.OwnerBox;
                        //change font when change owner

                        p.InnerDrawBoard.CurrentFont      = latestOwner.ResolvedFont;
                        p.InnerDrawBoard.CurrentTextColor = latestOwner.ActualColor;
                    }

                    CssTextRun textRun = (CssTextRun)w;
                    p.DrawText(CssBox.UnsafeGetTextBuffer(w.OwnerBox),
                               textRun.TextStartIndex,
                               textRun.TextLength,
                               new PointF(w.Left, w.Top),
                               new SizeF(w.Width, w.Height));


                    //RenderVxFormattedString formattedStr = CssTextRun.GetCachedFormatString(textRun);
                    //if (formattedStr == null)
                    //{
                    //    formattedStr = p.CreateRenderVx(CssBox.UnsafeGetTextBuffer(w.OwnerBox),
                    //                                textRun.TextStartIndex,
                    //                                textRun.TextLength);

                    //    CssTextRun.SetCachedFormattedString(textRun, formattedStr);
                    //}
                    //if (formattedStr != null)
                    //{
                    //    p.DrawText(formattedStr,
                    //                               new PointF(w.Left, w.Top),
                    //                               new SizeF(w.Width, w.Height));
                    //}
                    //else
                    //{
                    //    p.DrawText(CssBox.UnsafeGetTextBuffer(w.OwnerBox),
                    //                               textRun.TextStartIndex,
                    //                               textRun.TextLength,
                    //                               new PointF(w.Left, w.Top),
                    //                               new SizeF(w.Width, w.Height));
                    //}
                }
                break;

                default:
                {
#if DEBUG
                    // w.OwnerBox.dbugPaintTextWordArea(g, offset, w);
#endif
                }
                break;
                }
            }


            innerCanvas.CurrentFont      = enterFont;
            innerCanvas.CurrentTextColor = enterColor;
        }
Beispiel #5
0
        internal void FindSelectionPoint(ITextService ifonts,
                                         int offset, out int selectionIndex,
                                         out int runSelectionOffsetPx)
        {
            int charFit;
            int charFitWidth;
            var maxWidth = offset;

            switch (this.Kind)
            {
            case CssRunKind.BlockRun:
            {
                //contains sub
                selectionIndex       = -1;
                runSelectionOffsetPx = 0;
            }
            break;

            case CssRunKind.SolidContent:
            {
                // not a text word - set full selection
                selectionIndex       = -1;
                runSelectionOffsetPx = 0;
            }
            break;

            case CssRunKind.Text:
            {
                char[]     ownerTextBuff = CssBox.UnsafeGetTextBuffer(this.OwnerBox);
                CssTextRun textRun       = (CssTextRun)this;
                var        textBuf       = new TextBufferSpan(ownerTextBuff, textRun.TextStartIndex, textRun.TextLength);

                ifonts.MeasureString(ref textBuf,
                                     this.OwnerBox.ResolvedFont, maxWidth, out charFit, out charFitWidth);
                selectionIndex       = charFit;
                runSelectionOffsetPx = charFitWidth;
            }
            break;

            case CssRunKind.Space:
            {
                char[]     ownerTextBuff = CssBox.UnsafeGetTextBuffer(this.OwnerBox);
                CssTextRun textRun       = (CssTextRun)this;
                var        textBuf       = new TextBufferSpan(ownerTextBuff, textRun.TextStartIndex, textRun.TextLength);

                ifonts.MeasureString(ref textBuf,
                                     this.OwnerBox.ResolvedFont, maxWidth, out charFit, out charFitWidth);
                selectionIndex       = charFit;
                runSelectionOffsetPx = charFitWidth;
            }
            break;

            case CssRunKind.SingleSpace:
            {
                if (offset > this.Width / 2)
                {
                    selectionIndex       = -1;
                    runSelectionOffsetPx = 0;
                }
                else
                {
                    selectionIndex       = 0;
                    runSelectionOffsetPx = (int)this.Width;
                }
            }
            break;

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Beispiel #6
0
 public static PixelFarm.Drawing.RenderVxFormattedString GetCachedFormatString(CssTextRun textrun) => textrun._cacheRenderVx;
Beispiel #7
0
        /// <summary>
        /// Assigns words its width and height
        /// </summary>
        /// <param name="g"></param>
        public virtual void MeasureRunsSize(LayoutVisitor lay)
        {
            //measure once !
            if ((this._boxCompactFlags & BoxFlags.LAY_RUNSIZE_MEASURE) != 0)
            {
                return;
            }

            //--------------------------------
            if (this.BackgroundImageBinder != null)
            {
                //this has background
                if (this.BackgroundImageBinder.State == ImageBinderState.Unload)
                {
                    lay.RequestImage(this.BackgroundImageBinder, this);
                }
            }

            //--------------------------------
            if (this.RunCount > 0)
            {
                //find word spacing
                float actualWordspacing = this._actualWordSpacing;
                Font  actualFont        = this.ActualFont;
                var   fontInfo          = actualFont.FontInfo;
                float fontHeight        = fontInfo.LineHeight;

                var tmpRuns = this.Runs;
                for (int i = tmpRuns.Count - 1; i >= 0; --i)
                {
                    CssRun run = tmpRuns[i];
                    run.Height = fontHeight;
                    //if this is newline then width =0 ***
                    switch (run.Kind)
                    {
                    case CssRunKind.Text:
                    {
                        CssTextRun textRun = (CssTextRun)run;
                        run.Width = lay.MeasureStringWidth(
                            CssBox.UnsafeGetTextBuffer(this),
                            textRun.TextStartIndex,
                            textRun.TextLength,
                            actualFont);
                    }
                    break;

                    case CssRunKind.SingleSpace:
                    {
                        run.Width = actualWordspacing;
                    }
                    break;

                    case CssRunKind.Space:
                    {
                        //other space size
                        run.Width = actualWordspacing * ((CssTextRun)run).TextLength;
                    }
                    break;

                    case CssRunKind.LineBreak:
                    {
                        run.Width = 0;
                    }
                    break;
                    }
                }
            }
            this._boxCompactFlags |= BoxFlags.LAY_RUNSIZE_MEASURE;
        }