示例#1
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();
        }
示例#2
0
        public void FindCurrentHitWord(out int startAt, out int len)
        {
            if (_currentTextRun == null)
            {
                startAt = 0;
                len     = 0;
                return;
            }

            using (var copyContext = new TempTextLineCopyContext(_currentLine, out Typography.Text.TextBufferSpan textBufferSpan))
            {
                _lineSegs.Clear();
                _wordVisitor.SetLineSegmentList(_lineSegs);
                Typography.Text.GlobalTextService.TxtClient.BreakToLineSegments(textBufferSpan, _wordVisitor);

                if (_lineSegs.Count == 0)
                {
                    startAt = 0;
                    len     = 0;
                    return;
                }

                int segcount = _lineSegs.Count;
                for (int i = 0; i < segcount; ++i)
                {
                    TextPrinterLineSegment seg = _lineSegs.GetLineSegment(i);
                    if (seg.StartAt + seg.Length >= caret_char_index)
                    {
                        //stop at this segment
                        startAt = seg.StartAt;
                        len     = seg.Length;
                        return;
                    }
                }
            }

            //?
            startAt = 0;
            len     = 0;
        }
示例#3
0
        Size MeasureCopyRunLength(CopyRun copyRun)
        {
            //IAdvanceTextService txServices = GlobalTextService.AdvanceTextService;

            char[] mybuffer = copyRun.RawContent;
            //if (txServices.SupportsWordBreak)
            //{
            var textBufferSpan = new Typography.Text.TextBufferSpan(mybuffer);

            _lineSegs.Clear();
            _wordVisitor.SetLineSegmentList(_lineSegs);
            Typography.Text.GlobalTextService.TxtClient.BreakToLineSegments(textBufferSpan, _wordVisitor);

            var result = new TextSpanMeasureResult();

            result.outputXAdvances = new int[mybuffer.Length];

            Typography.Text.GlobalTextService.TxtClient.CalculateUserCharGlyphAdvancePos(textBufferSpan, _lineSegs,
                                                                                         DefaultRunStyle.ReqFont,
                                                                                         ref result);

            return(new Size(result.outputTotalW, result.lineHeight));
            //}
            //else
            //{


            //    var textBufferSpan = new Typography.Text.TextBufferSpan(mybuffer);

            //    var result = new TextSpanMeasureResult();
            //    result.outputXAdvances = new int[mybuffer.Length];

            //    txServices.CalculateUserCharGlyphAdvancePos(textBufferSpan,
            //        DefaultRunStyle.ReqFont,
            //        ref result);

            //    return new Size(result.outputTotalW, result.lineHeight);
            //}
        }