Exemplo n.º 1
0
        /// <summary>
        /// Draw this paragraph onto a context.
        /// </summary>
        /// <param name="context">The context to use for drawing.</param>
        /// <param name="x">The X-coordinate of the top left corner of the paragraph.</param>
        /// <param name="y">The Y-coordinate of the top-left corner of the paragraph.</param>
        public void DrawAt(IGraphicsContext context, double x, double y)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            IGraphicsState state = context.Save();

            Reorientate(context, x, y, false);
            try
            {
                switch (VerticalAlignment)
                {
                case VerticalAlignment.Centred:
                    y += (ComputedHeight - ContentHeight) / 2;
                    break;

                case VerticalAlignment.Bottom:
                    y += (ComputedHeight - ContentHeight);
                    break;
                }

                foreach (Line line in Lines)
                {
                    double xPos;
                    switch (HorizontalAlignment)
                    {
                    case HorizontalAlignment.Left:
                    case HorizontalAlignment.Justified:
                    default:
                        xPos = x + Margins.Left;
                        break;

                    case HorizontalAlignment.Centred:
                        xPos = x + Margins.Left + (MaximumWidth - (line.MinWidth + Margins.Left + Margins.Right)) / 2;
                        break;

                    case HorizontalAlignment.Right:
                        xPos = x + (MaximumWidth - line.MinWidth) - Margins.Right;
                        break;
                    }
                    line.DrawAt(context, xPos, y);
                    y += line.ContentHeight;
                }
            }
            finally
            {
                context.Restore(state);
            }
        }