Пример #1
0
        public override void Draw(TextDrawingRequest request)
        {
            request.Canvas.Translate(new Position(0, request.TotalAscent));
            request.Canvas.DrawSectionLink(SectionName, new Size(request.TextSize.Width, request.TextSize.Height));
            request.Canvas.Translate(new Position(0, -request.TotalAscent));

            base.Draw(request);
        }
Пример #2
0
        public void Draw(TextDrawingRequest request)
        {
            Element.VisitChildren(x => (x as IStateResettable)?.ResetState());
            Element.VisitChildren(x => x.Initialize(request.PageContext, request.Canvas));

            request.Canvas.Translate(new Position(0, request.TotalAscent));
            Element.Draw(new Size(request.TextSize.Width, -request.TotalAscent));
            request.Canvas.Translate(new Position(0, -request.TotalAscent));
        }
Пример #3
0
 public override void Draw(TextDrawingRequest request)
 {
     UpdatePageNumberText(request.PageContext);
     base.Draw(request);
 }
Пример #4
0
        internal override void Draw(Size availableSpace)
        {
            var lines = DivideTextItemsIntoLines(availableSpace.Width, availableSpace.Height).ToList();

            if (!lines.Any())
            {
                return;
            }

            var heightOffset = 0f;
            var widthOffset  = 0f;

            foreach (var line in lines)
            {
                widthOffset = 0f;

                var alignmentOffset = GetAlignmentOffset(line.Width);

                Canvas.Translate(new Position(alignmentOffset, 0));
                Canvas.Translate(new Position(0, -line.Ascent));

                foreach (var item in line.Elements)
                {
                    var textDrawingRequest = new TextDrawingRequest
                    {
                        Canvas      = Canvas,
                        PageContext = PageContext,

                        StartIndex = item.Measurement.StartIndex,
                        EndIndex   = item.Measurement.EndIndex,

                        TextSize    = new Size(item.Measurement.Width, line.LineHeight),
                        TotalAscent = line.Ascent
                    };

                    item.Item.Draw(textDrawingRequest);

                    Canvas.Translate(new Position(item.Measurement.Width, 0));
                    widthOffset += item.Measurement.Width;
                }

                Canvas.Translate(new Position(-alignmentOffset, 0));
                Canvas.Translate(new Position(-line.Width, line.Ascent));
                Canvas.Translate(new Position(0, line.LineHeight));

                heightOffset += line.LineHeight;
            }

            Canvas.Translate(new Position(0, -heightOffset));

            lines
            .SelectMany(x => x.Elements)
            .GroupBy(x => x.Item)
            .Where(x => x.Any(y => y.Measurement.IsLast))
            .Select(x => x.Key)
            .ToList()
            .ForEach(x => RenderingQueue.Dequeue());

            var lastElementMeasurement = lines.Last().Elements.Last().Measurement;

            CurrentElementIndex = lastElementMeasurement.IsLast ? 0 : lastElementMeasurement.EndIndex;

            if (!RenderingQueue.Any())
            {
                ResetState();
            }

            float GetAlignmentOffset(float lineWidth)
            {
                if (Alignment == HorizontalAlignment.Left)
                {
                    return(0);
                }

                var emptySpace = availableSpace.Width - lineWidth;

                if (Alignment == HorizontalAlignment.Right)
                {
                    return(emptySpace);
                }

                if (Alignment == HorizontalAlignment.Center)
                {
                    return(emptySpace / 2);
                }

                throw new ArgumentException();
            }
        }