Ejemplo n.º 1
0
        static int EvaluateFontAndTextColor(DrawBoard d, RunStyle runstyle)
        {
            RequestFont font             = runstyle.ReqFont;
            Color       color            = runstyle.FontColor;
            RequestFont currentTextFont  = d.CurrentFont;
            Color       currentTextColor = d.CurrentTextColor;

            if (font != null && font != currentTextFont)
            {
                if (currentTextColor != color)
                {
                    return(DIFF_FONT_DIFF_TEXT_COLOR);
                }
                else
                {
                    return(DIFF_FONT_SAME_TEXT_COLOR);
                }
            }
            else
            {
                if (currentTextColor != color)
                {
                    return(SAME_FONT_DIFF_TEXT_COLOR);
                }
                else
                {
                    return(SAME_FONT_SAME_TEXT_COLOR);
                }
            }
        }
Ejemplo n.º 2
0
        public SolidRun(char[] copyBuffer, RunStyle style)
            : base(style)
        {
            //check line break?

            _mybuffer = copyBuffer;
            UpdateRunWidth();
        }
Ejemplo n.º 3
0
        public override void Draw(DrawBoard d, UpdateArea updateArea)
        {
            int bWidth  = this.Width;
            int bHeight = this.Height;

#if DEBUG
            //canvas.dbug_DrawCrossRect(Color.Red, new Rectangle(0, 0, bWidth, bHeight));
            //canvas.DrawRectangle(Color.Red, 0, 0, bWidth, bHeight);
#endif

            RunStyle style = this.RunStyle;//must

            //set style to the canvas
            switch (EvaluateFontAndTextColor(d, style))
            {
            case DIFF_FONT_DIFF_TEXT_COLOR:
            {
                RequestFont prevFont  = d.CurrentFont;
                Color       prevColor = d.CurrentTextColor;
                d.CurrentFont      = style.ReqFont;
                d.CurrentTextColor = style.FontColor;

                DrawText(d);

                d.CurrentFont      = prevFont;
                d.CurrentTextColor = prevColor;
            }
            break;

            case DIFF_FONT_SAME_TEXT_COLOR:
            {
                RequestFont prevFont = d.CurrentFont;
                d.CurrentFont = style.ReqFont;

                DrawText(d);

                d.CurrentFont = prevFont;
            }
            break;

            case SAME_FONT_DIFF_TEXT_COLOR:
            {
                Color prevColor = d.CurrentTextColor;
                d.CurrentTextColor = style.FontColor;
                DrawText(d);
                d.CurrentTextColor = prevColor;
            }
            break;

            default:
            {
                DrawText(d);
            }
            break;
            }
        }
Ejemplo n.º 4
0
        public TextFlowLayer(ITextFlowLayerOwner owner, RunStyle defaultSpanStyle)
        {
            _owner = owner;

            //start with single line per layer
            //and can be changed to multiline
            DefaultRunStyle = defaultSpanStyle;

            //add default lines
            _lines.Add(new TextLineBox(this));

            VisualLineOverlapped = true;
        }
Ejemplo n.º 5
0
        public TextRun(RunStyle runstyle, char[] copyBuffer)
            : base(runstyle)
        {
#if DEBUG
            if (copyBuffer.Length == 0)
            {
            }
#endif
            //we need font info (in style) for evaluating the size fo this span
            //without font info we can't measure the size of this span
            SetNewContent(copyBuffer);
            UpdateRunWidth();
        }
Ejemplo n.º 6
0
        public override void SetStyle(RunStyle runstyle)
        {
            //TODO: review this again
            //update style may affect the 'visual' layout of the span
            //the span may expand large or shrink down
            //so we invalidate graphics area pre and post

            //TODO: review here***
            this.InvalidateGraphics();
            base.SetStyle(runstyle);
            this.InvalidateGraphics();
            UpdateRunWidth();
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
 public SolidRun(string str, RunStyle style)
     : base(style)
 {
     if (str != null && str.Length > 0)
     {
         _mybuffer = str.ToCharArray();
         if (_mybuffer.Length == 1 && _mybuffer[0] == '\n')
         {
             //this.IsLineBreak = true;
             throw new NotSupportedException();
         }
         UpdateRunWidth();
     }
     else
     {
         throw new Exception("string must be null or zero length");
     }
 }
Ejemplo n.º 9
0
        public TextFlowRenderBox(int width, int height, bool isMultiLine)
            : base(width, height)
        {
            var defaultRunStyle = new RunStyle();

            defaultRunStyle.FontColor = Color.Black;                                            //set default

            defaultRunStyle.ReqFont = GlobalRootGraphic.CurrentRootGfx.DefaultTextEditFontInfo; //TODO: review here

            _textLayer = new TextFlowLayer(this, defaultRunStyle);                              //presentation
            _textLayer.ContentSizeChanged += (s, e) => OnTextContentSizeChanged();

            //
            _editSession = new TextFlowEditSession(_textLayer);//controller
            _isMultiLine = isMultiLine;


            RenderBackground = RenderSelectionRange = RenderMarkers = true;
            //
            MayHasViewport  = true;
            BackgroundColor = Color.White;// Color.Transparent;
        }
Ejemplo n.º 10
0
 public void SetDefaultRunStyle(RunStyle runStyle)
 {
     DefaultRunStyle = runStyle;
 }
Ejemplo n.º 11
0
        //
        public override void Draw(DrawBoard d, UpdateArea updateArea)
        {
            if (_externalCustomDraw != null)
            {
                _externalCustomDraw(this, d, updateArea);
                return;
            }
            else if (ExternalRenderElement != null)
            {
                RenderElement.Render(ExternalRenderElement, d, updateArea);
                return;
            }

            int bWidth  = this.Width;
            int bHeight = this.Height;

            //1. bg, yellow for test**
            d.FillRectangle(Color.Yellow, 0, 0, bWidth, bHeight);

            //if (!this.HasStyle)
            //{
            //    canvas.DrawText(_mybuffer, new Rectangle(0, 0, bWidth, bHeight), 0);
            //}
            //else
            //{
            //TODO: review here, we don't need to do this

            RunStyle style = this.RunStyle;

            switch (EvaluateFontAndTextColor(d, style))
            {
            case DIFF_FONT_SAME_TEXT_COLOR:
            {
                var prevFont = d.CurrentFont;
                d.CurrentFont = style.ReqFont;
                d.DrawText(_mybuffer,
                           new Rectangle(0, 0, bWidth, bHeight),
                           style.ContentHAlign);
                d.CurrentFont = prevFont;
            }
            break;

            case DIFF_FONT_DIFF_TEXT_COLOR:
            {
                var prevFont  = d.CurrentFont;
                var prevColor = d.CurrentTextColor;
                d.CurrentFont      = style.ReqFont;
                d.CurrentTextColor = style.FontColor;
                d.DrawText(_mybuffer,
                           new Rectangle(0, 0, bWidth, bHeight),
                           style.ContentHAlign);
                d.CurrentFont      = prevFont;
                d.CurrentTextColor = prevColor;
            }
            break;

            case SAME_FONT_DIFF_TEXT_COLOR:
            {
                var prevColor = d.CurrentTextColor;
                d.DrawText(_mybuffer,
                           new Rectangle(0, 0, bWidth, bHeight),
                           style.ContentHAlign);
                d.CurrentTextColor = prevColor;
            }
            break;

            default:
            {
                d.DrawText(_mybuffer,
                           new Rectangle(0, 0, bWidth, bHeight),
                           style.ContentHAlign);
            }
            break;
            }
            //}
        }
Ejemplo n.º 12
0
 internal Run(RunStyle runStyle)
 {
     _runStyle = runStyle;
     _width    = _height = 10;
 }