/// <summary>
        /// Draws a layout with a given style to the render context.
        /// </summary>
        /// <param name="displayContext">The display context.</param>
        /// <param name="renderContext">The render context.</param>
        /// <param name="region">The region for the various elements.</param>
        /// <param name="style">The style used for borders and padding.</param>
        public static void DrawLayout(
            IDisplayContext displayContext,
            IRenderContext renderContext,
            Rectangle region,
            BlockStyle style)
        {
            // If we don't have a style, then don't do anything.
            if (style == null)
            {
                return;
            }

            // Get the style for the line number.
            Spacing margins = style.GetMargins();
            Borders borders = style.GetBorders();

            double marginLeftX  = margins.Left + borders.Left.LineWidth;
            double marginRightX = margins.Right + borders.Right.LineWidth;

            // Get the context and save settings because we use anti-aliasing
            // to get a sharper line.
            Context   cairoContext = renderContext.CairoContext;
            Antialias oldAntialias = cairoContext.Antialias;

            try
            {
                // Draw the background color.
                Color?backgroundColor = style.GetBackgroundColor();

                if (backgroundColor.HasValue)
                {
                    var cairoArea = new Rectangle(
                        region.X + marginLeftX,
                        region.Y,
                        region.Width - marginLeftX - marginRightX,
                        region.Height);

                    cairoContext.Color = backgroundColor.Value;
                    cairoContext.Rectangle(cairoArea);
                    cairoContext.Fill();
                }

                // Figure out the width for rendering the horizontal borders so
                // they line up a little bit nicer. We adjust for half the border
                // width because Cairo draws in the middle and we have to shift by
                // half that to get the side to line up with the end of the
                // horizontal.
                double topMarginY    = region.Y + margins.Top;
                double bottomMarginY = region.Y + region.Height - margins.Bottom;

                double leftMarginX  = region.X + margins.Left + (borders.Left.LineWidth / 2);
                double rightMarginX = leftMarginX + region.Width - margins.Width;

                // Draw the border lines.
                cairoContext.Antialias = Antialias.None;

                if (borders.Top.LineWidth > 0)
                {
                    // Set up the line width and colors.
                    cairoContext.LineWidth = borders.Top.LineWidth;
                    cairoContext.Color     = borders.Top.Color;

                    cairoContext.MoveTo(leftMarginX, topMarginY);
                    cairoContext.LineTo(rightMarginX, topMarginY);
                    cairoContext.Stroke();
                }

                if (borders.Bottom.LineWidth > 0)
                {
                    cairoContext.LineWidth = borders.Bottom.LineWidth;
                    cairoContext.Color     = borders.Bottom.Color;

                    cairoContext.MoveTo(leftMarginX, bottomMarginY);
                    cairoContext.LineTo(rightMarginX, bottomMarginY);
                    cairoContext.Stroke();
                }

                if (borders.Left.LineWidth > 0)
                {
                    cairoContext.LineWidth = borders.Left.LineWidth;
                    cairoContext.Color     = borders.Left.Color;

                    cairoContext.MoveTo(region.X + marginLeftX, topMarginY);
                    cairoContext.LineTo(region.X + marginLeftX, bottomMarginY);
                    cairoContext.Stroke();
                }

                if (borders.Right.LineWidth > 0)
                {
                    cairoContext.LineWidth = borders.Right.LineWidth;
                    cairoContext.Color     = borders.Right.Color;

                    cairoContext.MoveTo(region.X + region.Width - margins.Right, topMarginY);
                    cairoContext.LineTo(region.X + region.Width - margins.Right, bottomMarginY);
                    cairoContext.Stroke();
                }
            }
            finally
            {
                // Restore the context.
                cairoContext.Antialias = oldAntialias;
            }
        }