Ejemplo n.º 1
0
        /// <summary>
        /// Registers all the artefacts (name, outline) for this component (and only this component). Artefacts can represent
        /// </summary>
        /// <param name="context"></param>
        /// <param name="fullstyle"></param>
        /// <returns></returns>
        public virtual PDFArtefactRegistrationSet RegisterLayoutArtefacts(PDFLayoutContext context, Style fullstyle)
        {
            PDFArtefactRegistrationSet set = new PDFArtefactRegistrationSet(context.DocumentLayout, this);

            bool registername    = this.ShouldRegisterName(context);
            bool registerOutline = this.ShouldRegisterOutline(context);

            if (registername || registerOutline)
            {
                //register the name
                object name = context.DocumentLayout.RegisterCatalogEntry(context, PDFArtefactTypes.Names, new PDFDestination(this, OutlineFit.FullPage));
                set.SetArtefact(PDFArtefactTypes.Names, name);
            }

            object outline = null;

            //if we have a title then register the outline component
            if (registerOutline)
            {
                outline = context.DocumentLayout.RegisterCatalogEntry(context, PDFArtefactTypes.Outlines, new PDFOutlineRef(this.Outline, fullstyle.Outline));
                set.SetArtefact(PDFArtefactTypes.Outlines, outline);
            }

            this.DoRegisterArtefacts(context, set, fullstyle);
            return(set);
        }
Ejemplo n.º 2
0
        //
        // implementation methods
        //


        /// <summary>
        /// Main calling method that lays out each of the pages in this document
        /// </summary>
        /// <param name="avail">Available size (ignored)</param>
        /// <param name="startPageIndex">The starting page index</param>
        /// <returns>an empty size</returns>
        protected override void DoLayoutComponent()
        {
            this.Context.DocumentLayout = CreateDocumentLayout();
            Style style = this.FullStyle;

            this.StartPageNumbering(style);

            //Do the registration of top level document artefacts
            PDFArtefactRegistrationSet artefacts = this.Document.RegisterLayoutArtefacts(this.Context, style);

            LayoutAdditions(style);

            //this.Context.PerformanceMonitor.Begin(PerformanceMonitorType.Layout_Pages);

            LayoutAllPages();

            //this.Context.PerformanceMonitor.End(PerformanceMonitorType.Layout_Pages);

            if (null != artefacts)
            {
                this.Document.CloseLayoutArtefacts(Context, artefacts, style);
            }

            EndPageNumbering(style);

            this.Context.PerformanceMonitor.Begin(PerformanceMonitorType.Push_Component_Layout);

            this.Context.DocumentLayout.PushComponentLayout(this.Context, 0, PDFUnit.Zero, PDFUnit.Zero);

            this.Context.PerformanceMonitor.End(PerformanceMonitorType.Push_Component_Layout);
        }
Ejemplo n.º 3
0
        protected override void DoCloseLayoutArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet artefacts, Styles.Style fullstyle)
        {
            base.DoCloseLayoutArtefacts(context, artefacts, fullstyle);

            //Close the inner chid annotation entries
            object entries;

            if (artefacts.TryGetArtefact(LinkAnnotationChildEntries, out entries))
            {
                object[] all = (object[])entries;
                //TODO: Check the use of a link that flows over more than one page
                Layout.PDFLayoutPage pg = context.DocumentLayout.CurrentPage;

                for (int i = all.Length - 1; i >= 0; i--)
                {
                    pg.CloseArtefactEntry(PDFArtefactTypes.Annotations, all[i]);
                }
            }

            //Close the actual link
            object link;

            if (artefacts.TryGetArtefact(LinkArtefactName, out link))
            {
                context.DocumentLayout.CloseArtefactEntry(PDFArtefactTypes.Names, link);
            }
        }
Ejemplo n.º 4
0
        protected override void DoRegisterArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet set, Style fullstyle)
        {
            base.DoRegisterArtefacts(context, set, fullstyle);

            //object entry = context.DocumentLayout.RegisterCatalogEntry(context, PDFArtefactTypes.AcrobatForms, new PDFAcrobatFormEntry(this.ID));
            //this.FormEntry = (PDFAcrobatFormEntry)entry;
        }
Ejemplo n.º 5
0
        protected override void DoRegisterArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet set, Style fullstyle)
        {
            //var form = this.GetParentForm(context);
            PDFAcrobatFormFieldWidget entry = GetFieldEntry(context);

            context.DocumentLayout.RegisterCatalogEntry(context, PDFArtefactTypes.AcrobatForms, entry);
            this.Widget = entry;

            base.DoRegisterArtefacts(context, set, fullstyle);
        }
Ejemplo n.º 6
0
        protected override void DoRegisterArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet set, Style fullstyle)
        {
            _orgitems = context.Items;

            if (this.HasParams)
            {
                PDFItemCollection updated = _orgitems.Clone();
                updated.Merge(this.Params);
                context.Items = updated;
            }

            base.DoRegisterArtefacts(context, set, fullstyle);
        }
Ejemplo n.º 7
0
        public void CloseLayoutArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet artefacts, Style fullstyle)
        {
            object outline, name;

            if (artefacts.TryGetArtefact(PDFArtefactTypes.Outlines, out outline))
            {
                context.DocumentLayout.CloseArtefactEntry(PDFArtefactTypes.Outlines, outline);
            }

            if (artefacts.TryGetArtefact(PDFArtefactTypes.Names, out name))
            {
                context.DocumentLayout.CloseArtefactEntry(PDFArtefactTypes.Names, name);
            }

            this.DoCloseLayoutArtefacts(context, artefacts, fullstyle);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Overrides the base implementation to registed the image data as a resource on the current container
        /// </summary>
        /// <param name="context"></param>
        /// <param name="set"></param>
        /// <param name="fullstyle"></param>
        protected override void DoRegisterArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet set, Style fullstyle)
        {
            IPDFResourceContainer resources = this.GetResourceContainer();

            if (null == resources)
            {
                throw RecordAndRaise.NullReference(Errors.ResourceContainerOfComponnetNotFound, "Image", this.ID);
            }
            PDFImageXObject xobj = this.GetImageObject(context, fullstyle);

            if (null != xobj)
            {
                resources.Register(xobj);
            }

            base.DoRegisterArtefacts(context, set, fullstyle);
        }
        public void LayoutAPage(PageBase pg, bool first)
        {
            this.PushGroupHeader(pg, first);
            this.PushGroupFooter(pg, first);

            Style style = pg.GetAppliedStyle();

            if (null != style)
            {
                this.Context.StyleStack.Push(style);
            }

            Style full = this.Context.StyleStack.GetFullStyle(pg);

            PDFArtefactRegistrationSet artefacts = pg.RegisterLayoutArtefacts(this.Context, full);

            using (IPDFLayoutEngine engine = pg.GetEngine(this, this.Context, full))
            {
                if (this.Context.ShouldLogVerbose)
                {
                    this.Context.TraceLog.Begin(TraceLevel.Message, "Page Group Layout", "Starting the layout of page " + pg.ID);
                }

                engine.Layout(this.Context, full);

                if (this.Context.ShouldLogVerbose)
                {
                    this.Context.TraceLog.End(TraceLevel.Message, "Page Group Layout", "Completed the layout of page " + pg.ID + " and now on page index " + this.Context.DocumentLayout.CurrentPageIndex.ToString());
                }
                else if (this.Context.ShouldLogMessage)
                {
                    this.Context.TraceLog.Add(TraceLevel.Message, "Page Group Layout", "Completed the layout of page " + pg.ID + " and now on page index " + this.Context.DocumentLayout.CurrentPageIndex.ToString());
                }
            }

            if (null != artefacts)
            {
                pg.CloseLayoutArtefacts(this.Context, artefacts, full);
            }

            if (null != style)
            {
                this.Context.StyleStack.Pop();
            }
        }
Ejemplo n.º 10
0
        protected virtual void LayoutAdditions(Style docStyle)
        {
            if (this.Document.HasAdditions)
            {
                foreach (IPDFComponent comp in this.Document.Additions)
                {
                    if (comp is Component)
                    {
                        Component full = comp as Component;
                        PDFArtefactRegistrationSet artefacts = full.RegisterLayoutArtefacts(this.Context, docStyle);
                        if (full is IPDFViewPortComponent)
                        {
                            using (IPDFLayoutEngine engine = ((IPDFViewPortComponent)full).GetEngine(this, this.Context, docStyle))
                                engine.Layout(this.Context, docStyle);
                        }

                        if (null != artefacts)
                        {
                            full.CloseLayoutArtefacts(this.Context, artefacts, docStyle);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        protected void LayoutPageWithStyle(PageBase pg, Style full)
        {
            PDFArtefactRegistrationSet artefacts = pg.RegisterLayoutArtefacts(this.Context, full);

            using (IPDFLayoutEngine engine = pg.GetEngine(this, this.Context, full))
            {
                if (this.Context.TraceLog.ShouldLog(TraceLevel.Message))
                {
                    this.Context.TraceLog.Begin(TraceLevel.Message, "Document Layout", "Starting the layout of page " + pg.ID);
                }

                engine.Layout(this.Context, full);

                if (this.Context.TraceLog.ShouldLog(TraceLevel.Message))
                {
                    this.Context.TraceLog.End(TraceLevel.Message, "Document Layout", "Completed the layout of page " + pg.ID + " and now on page index " + this.DocumentLayout.CurrentPageIndex.ToString());
                }
            }

            if (null != artefacts)
            {
                pg.CloseLayoutArtefacts(this.Context, artefacts, full);
            }
        }
        /// <summary>
        /// Lays out a single list item based on the entry, and the list position options
        /// </summary>
        /// <param name="index"></param>
        /// <param name="entry"></param>
        /// <param name="listPosOpts"></param>
        /// <returns></returns>
        private PDFUnit LayoutAnItem(int index, ListNumberEntry entry, PDFPositionOptions listPosOpts)
        {
            //restore the items applied style onto the stack
            this.StyleStack.Push(entry.AppliedStyle);

            Style   full        = entry.FullStyle;
            PDFUnit numberWidth = entry.NumberWidth;



            PDFArtefactRegistrationSet artefacts = entry.ListItem.RegisterLayoutArtefacts(this.Context, full);

            PDFPositionOptions itemopts = full.CreatePostionOptions();

            PDFUnit pageHeight = this.Context.DocumentLayout.CurrentPage.Height;
            PDFUnit h          = pageHeight;
            PDFUnit w          = _listBlock.AvailableBounds.Width;
            PDFUnit y          = _itemoffset;

            PDFUnit alley = DefaultListItemAlley;

            if (itemopts.HasAlleyWidth)
            {
                alley = itemopts.AlleyWidth;
            }
            else if (listPosOpts.HasAlleyWidth)
            {
                alley = listPosOpts.AlleyWidth;
            }

            if (itemopts.Height.HasValue)
            {
                h = itemopts.Height.Value;
            }
            else if (itemopts.Margins.IsEmpty == false)
            {
                h -= itemopts.Margins.Top + itemopts.Margins.Bottom;
            }
            h -= itemopts.Padding.Top + itemopts.Padding.Bottom;

            if (itemopts.Width.HasValue)
            {
                w = itemopts.Width.Value;
            }

            else if (itemopts.Margins.IsEmpty == false)
            {
                w -= itemopts.Margins.Left + itemopts.Margins.Right;
            }
            w -= itemopts.Padding.Left + itemopts.Padding.Right;

            PDFRect totalBounds = new PDFRect(PDFUnit.Zero, y, w, h);

            this._itemblock = _listBlock.BeginNewContainerBlock(entry.ListItem, this, full, itemopts.PositionMode);

            PDFColumnOptions colOpts = new PDFColumnOptions()
            {
                AlleyWidth = alley, AutoFlow = false, ColumnCount = 2
            };

            this._itemblock.InitRegions(totalBounds, itemopts, colOpts, this.Context);

            //Alter the widths of the regions to allow for only the number width

            PDFRect region1bounds = this._itemblock.Columns[0].TotalBounds;
            PDFUnit difference    = region1bounds.Width - numberWidth;

            region1bounds.Width = numberWidth;
            this._itemblock.Columns[0].TotalBounds = region1bounds;
            this._itemblock.Columns[0].HAlignment  = entry.NumberAlignment;

            PDFRect region2Bounds = this._itemblock.Columns[1].TotalBounds;

            if (region2Bounds.X > 0)
            {
                region2Bounds.X -= difference;
            }
            region2Bounds.Width += difference;
            this._itemblock.Columns[1].TotalBounds = region2Bounds;

            PDFUnit numberHeight = this.LayoutItemNumber(entry, full);

            this._itemblock.CurrentRegion.Close();

            bool    success       = this._itemblock.MoveToNextRegion(true, PDFUnit.Zero, this.Context); //Pass Zero as we are not interested in overflowing yet
            PDFUnit contentHeight = this.LayoutItemContent(entry);

            //check that we can fit - addind the margins and padding back in.
            PDFUnit itemHeight = PDFUnit.Max(numberHeight, contentHeight);

            if (itemopts.Height.HasValue)
            {
                itemHeight = itemopts.Height.Value;
            }
            else if (itemopts.Margins.IsEmpty == false)
            {
                itemHeight += itemopts.Margins.Top + itemopts.Margins.Bottom;
            }
            itemHeight += itemopts.Padding.Top + itemopts.Padding.Bottom;

            if (itemHeight > this._listBlock.AvailableBounds.Height - _itemoffset)
            {
                PDFLayoutBlock  origparent = this.CurrentBlock;
                PDFLayoutRegion origregion = this.CurrentBlock.CurrentRegion;
                PDFLayoutBlock  origlist   = this._listBlock;
                PDFLayoutBlock  origItem   = this._itemblock;

                if (this._listBlock.Position.OverflowSplit == OverflowSplit.Never)
                {
                    if (this.MoveFullListToNextRegion(_itemoffset + itemHeight))
                    {
                        //_itemoffset += itemHeight;
                        //PDFRect avail = _listBlock.AvailableBounds;
                        //avail.Height = avail.Height - _itemoffset;
                    }
                    else
                    {
                        this.Context.TraceLog.Add(TraceLevel.Warning, LOG_CATEGORY, "List '" + this.List.UniqueID + "' has filled the available space, and cannot overflow onto a new region. Layout has stopped at item index " + index);
                        this.ContinueLayout = false;
                        return(0);
                    }
                }
                else if (this.StartListInAnotherRegion(itemHeight, origItem, index))
                {
                    //origregion.AddToSize(origlist);
                    _itemoffset = 0;
                    origItem.Offset(0, 0);
                }
                else
                {
                    (origItem.Parent as PDFLayoutBlock).CurrentRegion.RemoveItem(origItem);
                    this.Context.TraceLog.Add(TraceLevel.Warning, LOG_CATEGORY, "List '" + this.List.UniqueID + "' has filled the available space, and cannot overflow onto a new region. Layout has stopped at item index " + index);

                    this.ContinueLayout = false;
                }
            }
            else if (this._itemblock.CurrentRegion.IsClosed)
            {
                this._itemblock = this.CurrentBlock.LastOpenBlock();
                this._listBlock = this._itemblock.Parent as PDFLayoutBlock;
            }

            if (null != this._itemblock)
            {
                if (this._itemblock.CurrentRegion.IsClosed == false)
                {
                    this._itemblock.CurrentRegion.Close();
                }

                if (this._itemblock.IsClosed == false)
                {
                    this._itemblock.Close();
                    this._listBlock.CurrentRegion.AddToSize(this._itemblock);
                }
            }

            if (this.ContinueLayout)
            {
                RegisterChildLayout(entry.ListItem);
            }

            if (null != artefacts)
            {
                entry.ListItem.CloseLayoutArtefacts(this.Context, artefacts, full);
            }

            this.StyleStack.Pop();

            return(itemHeight);
        }
Ejemplo n.º 13
0
        protected override void DoRegisterArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet set, Style fullstyle)
        {
            base.DoRegisterArtefacts(context, set, fullstyle);

            LinkAction actiontype = this.Action;

            if (actiontype == LinkAction.Undefined)
            {
                actiontype = this.ResolveActionType(this.Destination, this.File);
            }

            object[]  entries = null;
            PDFAction action;

            if (this.IsNamedAction(actiontype))
            {
                PDFNamedAction named = new PDFNamedAction(this, this.Action);
                action = named;
            }
            else if (actiontype == LinkAction.Uri)
            {
                string url = this.File;
                if (!string.IsNullOrEmpty(url))
                {
                    action = new PDFUriDestinationAction(this, actiontype, url);
                }
                else
                {
                    throw new PDFLinkException(Errors.NoFileLinkSpecifiedOnUriAction);
                }
            }
            else if (actiontype == LinkAction.Destination)
            {
                //If we start with a # then we are an ID, otherwise we are a uniqueID or Name
                PDFDestination dest;
                Component      comp;
                if (string.IsNullOrEmpty(this.Destination))
                {
                    //if there is no destination then there is no link. So do not register
                    comp = null;
                    return;
                }
                else if (this.Destination.StartsWith(ComponentIDPrefix))
                {
                    string id = this.Destination.Substring(ComponentIDPrefix.Length);
                    comp = this.Document.FindAComponentById(id);
                }
                else
                {
                    comp = this.Document.FindAComponentByName(this.Destination);
                }


                if (null == comp)
                {
                    if (context.Conformance == ParserConformanceMode.Strict)
                    {
                        throw new PDFLayoutException(string.Format(Errors.LinkToDestinationCouldNotBeMade, this.Destination));
                    }
                    else
                    {
                        context.TraceLog.Add(TraceLevel.Error, "PDFLink", string.Format(Errors.LinkToDestinationCouldNotBeMade, this.Destination));
                    }

                    //cannot continue as we dont have anything to link to
                    return;
                }

                dest = new PDFDestination(comp, this.DestinationFit, this.UniqueID);

                PDFDestinationAction destact = new PDFDestinationAction(this, actiontype, dest);
                action = destact;


                if (null != dest)
                {
                    object link = context.DocumentLayout.RegisterCatalogEntry(context, PDFArtefactTypes.Names, dest);
                    set.SetArtefact(LinkArtefactName, link);
                }
            }
            else if (actiontype == LinkAction.ExternalDestination)
            {
                string name = this.Destination;
                string file = this.File;
                PDFRemoteDestinationAction remote = new PDFRemoteDestinationAction(this, actiontype, file, name);
                remote.NewWindow = this.NewWindow;

                action = remote;
            }
            else
            {
                throw RecordAndRaise.Argument("actiontype");
            }

            if (null != action)
            {
                entries = this.AddActionAnnotationToChildren(context, fullstyle, action);
                set.SetArtefact(LinkAnnotationChildEntries, entries);
            }
        }
Ejemplo n.º 14
0
        protected override void DoCloseLayoutArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet artefacts, Style fullstyle)
        {
            base.DoCloseLayoutArtefacts(context, artefacts, fullstyle);

            context.Items = _orgitems;
        }
Ejemplo n.º 15
0
 protected virtual void DoRegisterArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet set, Style fullstyle)
 {
 }
Ejemplo n.º 16
0
 protected override void DoCloseLayoutArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet artefacts, Style fullstyle)
 {
     //artefacts.Document.CloseArtefactEntry(PDFArtefactTypes.AcrobatForms, this.FormEntry);
     //base.DoCloseLayoutArtefacts(context, artefacts, fullstyle);
 }
Ejemplo n.º 17
0
 protected virtual void DoCloseLayoutArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet artefacts, Style fullstyle)
 {
     //Does nothing in base class
 }