Exemplo n.º 1
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));
     }
 }
Exemplo n.º 2
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));
     }
 }
Exemplo n.º 3
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);
        }
        //
        // 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);
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }