示例#1
0
        protected IPDFDataSource GetDataSourceComponent(string datasourceComponentID, PDFDataContext context)
        {
            IPDFDataSource datasourceComponent = null;

            if (string.IsNullOrEmpty(datasourceComponentID))
            {
                throw new ArgumentNullException("datasourceComponentID");
            }

            Component found = base.FindDocumentComponentById(datasourceComponentID);

            if (found == null)
            {
                throw RecordAndRaise.ArgumentNull("DataSourceID", Errors.CouldNotFindControlWithID, datasourceComponentID);
            }
            else if (!(found is IPDFDataSource))
            {
                throw RecordAndRaise.Argument("DataSourceID", Errors.AssignedDataSourceIsNotIPDFDataSource, datasourceComponentID);
            }
            else
            {
                datasourceComponent = ((IPDFDataSource)found);
            }


            return(datasourceComponent);
        }
        protected IPDFContainerComponent GetContainerParent()
        {
            Component ele = this;

            while (null != ele)
            {
                Component par = ele.Parent;
                if (par == null)
                {
                    throw RecordAndRaise.ArgumentNull(Errors.TemplateComponentParentMustBeContainer);
                }

                else if ((par is IPDFContainerComponent) == false)
                {
                    ele = par;
                }
                else
                {
                    return(par as IPDFContainerComponent);
                }
            }

            //If we get this far then we haven't got a viable container to add our items to.
            throw RecordAndRaise.ArgumentNull(Errors.TemplateComponentParentMustBeContainer);
        }
示例#3
0
 protected void DecrementNoOps()
 {
     if ((--this._noopcount) < 0)
     {
         throw RecordAndRaise.ArgumentOutOfRange(Errors.NoOpCountOutOfRange);
     }
 }
示例#4
0
 /// <summary>
 /// Parses a pdfx file located at the full path
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 protected virtual IPDFComponent ParseComponentAtPath(string path)
 {
     if (null == this.Parent)
     {
         throw RecordAndRaise.NullReference(Errors.ParentDocumentCannotBeNull);
     }
     else
     {
         return(this.Parent.ParseComponentAtPath(path));
     }
 }
示例#5
0
 /// <summary>
 /// Finds an Component in the entire document hierarchy with the specified ID
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 protected virtual Component FindDocumentComponentById(string id)
 {
     if (this.Document != null)
     {
         return(this.Document.FindAComponentById(id));
     }
     else
     {
         throw RecordAndRaise.Operation(Errors.CannotUseFindForComponentNotInDocumentHeirarchy);
     }
 }
示例#6
0
 /// <summary>
 /// Creates a new PDFGraphics context within which drawing to the PDF Surface can take place
 /// </summary>
 /// <param name="writer">The writer used to write graphical instructions to</param>
 /// <param name="styles">The styles of the new graphics context</param>
 /// <returns>A newly instantiated graphics context</returns>
 public virtual PDFGraphics CreateGraphics(PDFWriter writer, StyleStack styles, PDFContextBase context)
 {
     if (this.Parent == null)
     {
         throw RecordAndRaise.NullReference(Errors.InvalidCallToGetGraphicsForStructure);
     }
     else
     {
         return(this.Parent.CreateGraphics(writer, styles, context));
     }
 }
示例#7
0
 void IPDFComponentList.Insert(int index, IPDFComponent component)
 {
     if (component is Component)
     {
         this.Insert(index, (Component)component);
         this.OnCollectionChanged();
     }
     else
     {
         RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, component.GetType(), "PDFComponent");
     }
 }
        public ComponentWrappingList(ComponentList inner)
        {
            if (null == inner)
            {
                throw RecordAndRaise.ArgumentNull("innerList");
            }

            this._inner = inner;

            //hook into the changed event so we are notified if any new items are added to the collection
            this._inner.CollectionChanged += new EventHandler(inner_CollectionChanged);
        }
示例#9
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);
        }
        //
        // IPDFDataSource Members
        //

        #region public object Select(string path, PDFDataContext context)

        /// <summary>
        /// Retrieves the data from this DataSource based on the path
        /// </summary>
        /// <param name="path">The path to source the data from - for an XML DataSource this is an XPath query</param>
        /// <param name="data">The data to extract the result from</param>
        /// <returns>The required data (could be null)</returns>
        public object Select(string path, PDFDataContext context)
        {
            if (path == null)
            {
                path = string.Empty;
            }
            object data;

            try
            {
                data = this.DoSelectData(path, context);
            }
            catch (Exception ex)
            {
                throw RecordAndRaise.Data(ex, Errors.CouldNotSelectData);
            }

            return(data);
        }
        public object Evaluate(string expr, object withData, PDFDataContext context)
        {
            if (expr == null)
            {
                expr = string.Empty;
            }

            object result;

            try
            {
                result = this.DoEvaluateExpression(expr, withData, context);
            }
            catch (Exception ex)
            {
                throw RecordAndRaise.Data(ex, Errors.CouldNotSelectData);
            }
            return(result);
        }
        /// <summary>
        /// Overridable method that creates the specific collections for individual artefact types
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        internal protected virtual IArtefactCollection CreateArtefactCollection(string type)
        {
            switch (type)
            {
            case (PDFArtefactTypes.Annotations):
                return(new PDFAnnotationCollection(type));

            case (PDFArtefactTypes.Names):
                return(new PDFCategorisedNameDictionary(type));

            case (PDFArtefactTypes.Outlines):
                return(new PDFOutlineStack(type));

            case (PDFArtefactTypes.AcrobatForms):
                return(new PDFAcrobatFormFieldCollection(type, this.Owner));

            default:
                throw RecordAndRaise.NotSupported("The catalog type {0} is not a known catalog type", type);
            }
        }
示例#13
0
        /// <summary>
        /// Begins a header on a the current document page
        /// </summary>
        public void BeginHeader(PDFPageHeader owner, Style full, PDFLayoutContext context)
        {
            if (null != this.HeaderBlock)
            {
                throw RecordAndRaise.LayoutException(Errors.AlreadyAHeaderDefinedOnPage);
            }

            PDFLayoutBlock block = new PDFLayoutBlock(this, owner, this.Engine, full, OverflowSplit.Never);

            //Take the magins away from the total bounds before initializing the regions
            PDFRect content = this.ContentBlock.TotalBounds;

            if (this.PositionOptions.Margins.IsEmpty == false)
            {
                content.Width  -= this.PositionOptions.Margins.Left + this.PositionOptions.Margins.Right;
                content.Height -= this.PositionOptions.Margins.Top + this.PositionOptions.Margins.Bottom;
            }

            block.InitRegions(content, this.ContentBlock.Position, full.CreateColumnOptions(), context);
            this._header = block;
            //Make this block current
            this.CurrentBlock = block;
        }
示例#14
0
        /// <summary>
        /// Sets an arrangement for this component
        /// </summary>
        /// <param name="arrange"></param>
        protected virtual void SetArrangement(PDFComponentArrangement arrange)
        {
            if (arrange is PDFComponentMultiArrangement)
            {
                if (_arrange == null)
                {
                    _arrange = arrange;
                    //this.EnsureAllChildrenAreOnThisPage(arrange);
                }

                else if (_arrange != null && _arrange is PDFComponentMultiArrangement)
                {
                    ((PDFComponentMultiArrangement)_arrange).AppendArrangement((PDFComponentMultiArrangement)arrange);
                }
                else
                {
                    throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, typeof(PDFComponentArrangement), typeof(PDFComponentMultiArrangement));
                }
            }
            else
            {
                _arrange = arrange;
            }
        }
示例#15
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);
            }
        }
示例#16
0
        protected override Resources.PDFImageXObject InitImageXObject(PDFContextBase context, Style style)
        {
            Document doc = this.Document;

            if (null == doc)
            {
                throw RecordAndRaise.NullReference(Errors.ParentDocumentCannotBeNull);
            }

            PDFImageXObject xobj = null;

            if (null != this.Data)
            {
                xobj = this.Document.GetImageResource(this.Data.SourcePath, this, false);
                if (null == xobj)
                {
                    string name = this.Document.GetIncrementID(PDFObjectTypes.ImageXObject);
                    xobj = PDFImageXObject.Load(this.Data, name);
                    this.Document.SharedResources.Add(xobj);
                }
            }
            else if (String.IsNullOrEmpty(this.Source) == false)
            {
                string fullpath = this.Source;

                try
                {
                    xobj = this.Document.GetImageResource(fullpath, this, true);
                }
                catch (Exception ex)
                {
                    throw new PDFMissingImageException(string.Format(Errors.CouldNotLoadImageFromPath, this.Source), ex);
                }

                if (null == xobj)
                {
                    PDFImageXObject data = null;
                    try
                    {
                        data = this.Document.LoadImageData(this, fullpath);
                    }
                    catch (Exception ex)
                    {
                        throw new PDFMissingImageException(string.Format(Errors.CouldNotLoadImageFromPath, this.Source), ex);
                    }

                    if (null != data)
                    {
                        this.Document.SharedResources.Add(data);
                        xobj = data;
                    }
                    else
                    {
                        throw new PDFMissingImageException(string.Format(Errors.CouldNotLoadImageFromPath, this.Source));
                    }
                }
            }


            return(xobj);
        }
        //
        // IPDFTemplate Instantiate method.
        //

        public IEnumerable <IPDFComponent> Instantiate(int index, IPDFComponent owner)
        {
            if (!_initialised)
            {
                this.InitTemplate(this.XmlContent, this.NamespacePrefixMappings);
            }

            if (null == owner)
            {
                throw new ArgumentNullException("owner");
            }

            using (System.IO.StringReader sr = new System.IO.StringReader(this._toparse))
            {
                //Get the closest remote component
                IPDFRemoteComponent remote = this.GetRemoteComponent(owner);
                IPDFDocument        doc    = owner.Document;
                IPDFComponent       comp;
                if (doc is IPDFTemplateParser)
                {
                    comp = ((IPDFTemplateParser)doc).ParseTemplate(remote, sr);
                }
                else
                {
                    throw RecordAndRaise.NullReference(Errors.ParentDocumentMustBeTemplateParser);
                }

                if (this.IsBlock)
                {
                    if (!(comp is TemplateBlockInstance))
                    {
                        throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, comp.GetType(), typeof(TemplateBlockInstance));
                    }

                    TemplateBlockInstance template = (TemplateBlockInstance)comp;

                    if (null != this.Style && (template is IPDFStyledComponent))
                    {
                        this.Style.MergeInto((template as IPDFStyledComponent).Style);
                    }

                    template.StyleClass  = this.StyleClass;
                    template.ElementName = this.ElementName;
                }
                else
                {
                    if (!(comp is TemplateInstance))
                    {
                        throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, comp.GetType(), typeof(TemplateInstance));
                    }

                    TemplateInstance template = (TemplateInstance)comp;

                    if (null != this.Style && (template is IPDFStyledComponent))
                    {
                        this.Style.MergeInto((template as IPDFStyledComponent).Style);
                    }

                    template.StyleClass  = this.StyleClass;
                    template.ElementName = this.ElementName;
                }

                if (comp is Component && owner is Component && this.UseDataStyleIdentifier)
                {
                    var stem = this.DataStyleStem;
                    if (string.IsNullOrEmpty(stem))
                    {
                        stem = ((Component)owner).UniqueID;
                    }

                    DataStyleIdentifierVisitor visitor = new DataStyleIdentifierVisitor(stem, 1);
                    visitor.PushToComponents(comp as Component);
                }

                List <IPDFComponent> all = new List <IPDFComponent>(1);

                all.Add(comp);
                return(all);
            }
        }
示例#18
0
        protected override Resources.PDFImageXObject InitImageXObject(PDFContextBase context, Style style)
        {
            Document doc = this.Document;

            if (null == doc)
            {
                throw RecordAndRaise.NullReference(Errors.ParentDocumentCannotBeNull);
            }

            PDFImageXObject xobj = null;

            if (null != this.Data)
            {
                xobj = this.Document.GetImageResource(this.Data.SourcePath, this, false);
                if (null == xobj)
                {
                    string name = this.Document.GetIncrementID(PDFObjectTypes.ImageXObject);
                    xobj = PDFImageXObject.Load(this.Data, name);
                    this.Document.SharedResources.Add(xobj);
                }
            }
            else if (String.IsNullOrEmpty(this.Source) == false)
            {
                string fullpath = this.Source;

                try
                {
                    //Commented so the document checks the factories, and if not found calls back to this component to map the path after.
                    //if (System.Uri.IsWellFormedUriString(fullpath, UriKind.Relative))
                    //    fullpath = this.MapPath(fullpath);
                    xobj = this.Document.GetImageResource(fullpath, this, true);
                }
                catch (Exception ex)
                {
                    throw new PDFMissingImageException(string.Format(Errors.CouldNotLoadImageFromPath, this.Source), ex);
                }

                if (null == xobj)
                {
                    PDFImageData data = null;
                    try
                    {
                        data = this.Document.LoadImageData(this, fullpath);
                    }
                    catch (Exception ex)
                    {
                        throw new PDFMissingImageException(string.Format(Errors.CouldNotLoadImageFromPath, this.Source), ex);
                    }

                    if (null != data)
                    {
                        string name = this.Document.GetIncrementID(PDFObjectTypes.ImageXObject);
                        xobj = PDFImageXObject.Load(data, name);

                        this.Document.SharedResources.Add(xobj);
                    }
                    else
                    {
                        throw new PDFMissingImageException(string.Format(Errors.CouldNotLoadImageFromPath, this.Source));
                    }
                }
            }


            return(xobj);
        }