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
        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);
            }
        }