//
        // overrides
        //

        #region protected override void DoPushComponentLayout(PDFLayoutContext context, int pageIndex, PDFUnit xoffset, PDFUnit yoffset)

        /// <summary>
        /// Overrides the default behaviour to push any arrangements for the child item of this region
        /// </summary>
        /// <param name="context"></param>
        protected override void DoPushComponentLayout(PDFLayoutContext context, int pageIndex, PDFUnit xoffset, PDFUnit yoffset)
        {
            bool logdebug = context.ShouldLogDebug;

            if (logdebug)
            {
                context.TraceLog.Begin(TraceLevel.Debug, "Layout Region", "Pushing the component layout for the region " + this.ToString());
            }


            if (!this.IsClosed)
            {
                if (logdebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, PDFLayoutItem.LOG_CATEGORY, "Closing the region " + this.ToString() + " before pushing the layout");
                }
                this.Close();
            }

            if (this._contents == null || this.Contents.Count == 0)
            {
                if (logdebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, PDFLayoutItem.LOG_CATEGORY, "The region " + this.ToString() + " is empty. Exiting the push component early.");
                }
                return;
            }

            bool applyAlignments = this.ShouldApplyAlignment();

            if (applyAlignments)
            {
                VerticalAlignment v = this.VAlignment;
                if (v != VerticalAlignment.Top)
                {
                    this.EnsureCorrectHeight();
                    if (logdebug)
                    {
                        context.TraceLog.Add(TraceLevel.Debug, PDFLayoutItem.LOG_CATEGORY, "Adjusting the vertical offset of the region " + this.ToString() + " as it is not top aligned");
                    }

                    PDFUnit space = this.AvailableHeight;

                    if (v == VerticalAlignment.Middle)
                    {
                        space = space / 2;
                    }
                    yoffset += space;
                }
            }


            HorizontalAlignment h = this.HAlignment;

            PDFTextRenderOptions       options = (this.Parent as PDFLayoutBlock).FullStyle.CreateTextOptions();
            List <PDFTextRunCharacter> cache   = new List <PDFTextRunCharacter>();
            bool lastwasapplied = false;

            foreach (PDFLayoutItem item in this.Contents)
            {
                PDFUnit itemXOffset = xoffset;

                ///Individually calculate each lines horizontal offset
                if (applyAlignments && h != HorizontalAlignment.Left)
                {
                    PDFUnit space = this.TotalBounds.Width - item.Width;

                    if (h == HorizontalAlignment.Justified)
                    {
                        if (item is PDFLayoutLine)
                        {
                            PDFLayoutLine line = item as PDFLayoutLine;
                            if (logdebug)
                            {
                                context.TraceLog.Add(TraceLevel.Debug, PDFLayoutItem.LOG_CATEGORY, "Justifying the textual content of the line " + line.LineIndex);
                            }

                            bool didjustify = line.JustifyContent(this.TotalBounds.Width, item.Width, space, false, cache, ref options);

                            if (!didjustify && lastwasapplied && null != options && !(options.WordSpacing.HasValue || options.CharacterSpacing.HasValue))
                            {
                                line.ResetJustifySpacing(options);
                            }

                            lastwasapplied = didjustify;
                        }
                        space = 0; // reset space to zero as already accounted for.
                    }
                    else if (h == HorizontalAlignment.Center)
                    {
                        space = space / 2;
                    }

                    itemXOffset = itemXOffset + space;
                }

                item.PushComponentLayout(context, pageIndex, itemXOffset, yoffset);
            }

            if (logdebug)
            {
                context.TraceLog.End(TraceLevel.Debug, "Layout Region", "Pushed all the component layouts for the region " + this.ToString());
            }
        }