public PDFName Register(PDFResource rsrc) { if (null == rsrc.Name || string.IsNullOrEmpty(rsrc.Name.Value)) { string name = this.Document.GetIncrementID(rsrc.Type); rsrc.Name = (PDFName)name; } rsrc.RegisterUse(this._resources, this.Owner); return(rsrc.Name); }
public PDFName Register(PDFResource reference) { if (null == reference.Name || string.IsNullOrEmpty(reference.Name.Value)) { string name = this.Document.GetIncrementID(reference.Type); reference.Name = (PDFName)name; } reference.RegisterUse(this.Resources, this); return(reference.Name); }
public void SetCurrentFont(PDFFont font) { PDFResource rsrc = this.Container.Document.GetResource(PDFResource.FontDefnResourceType, font.FullName, true); if (null == rsrc) { throw new NullReferenceException(String.Format(Errors.FontNotFound, font.FullName)); } PDFName name = this.Container.Register(rsrc); this.CurrentFontResource = (PDFFontResource)rsrc; this.CurrentFont = font; if (null != this.Writer) { this.Writer.WriteOpCodeS(PDFOpCode.TxtFont, name, font.Size.RealValue); } }
public override bool SetUpGraphics(PDFGraphics g, PDFRect bounds) { Scryber.Resources.PDFImageXObject imagex; string fullpath = _source; // g.Container.MapPath(_source); - Map Path is done in the document now //TODO: Add XStep, YStep etc. string resourcekey = GetImagePatternKey(fullpath); PDFResource rsrc = g.Container.Document.GetResource(PDFResource.PatternResourceType, resourcekey, false); if (null == rsrc) { //Create the image imagex = g.Container.Document.GetResource(Scryber.Resources.PDFResource.XObjectResourceType, fullpath, true) as PDFImageXObject; if (null == imagex) { if (g.Context.Conformance == ParserConformanceMode.Lax) { g.Context.TraceLog.Add(TraceLevel.Error, "Drawing", "Could not set up the image brush as the graphic image was not found or returned for : " + fullpath); return(false); } else { throw new PDFRenderException("Could not set up the image brush as the graphic image was not found or returned for : " + fullpath); } } //The container of a pattern is the document as this is the scope PDFImageTilingPattern tile = new PDFImageTilingPattern(g.Container.Document, resourcekey, imagex); tile.Container = g.Container; tile.Image = imagex; tile.PaintType = PatternPaintType.ColoredTile; tile.TilingType = PatternTilingType.NoDistortion; //Calculate the bounds of the pattern PDFUnit width; PDFUnit height; PDFSize imgsize = CalculateAppropriateImageSize(imagex.ImageData, bounds); width = imgsize.Width; height = imgsize.Height; //Patterns are drawn from the bottom of the page so Y is the container height minus the vertical position and offset PDFUnit y = 0; // g.ContainerSize.Height - (bounds.Y);// g.ContainerSize.Height - (bounds.Y + height + this.YPostion); //X is simply the horizontal position plus offset PDFUnit x = 0; // bounds.X + this.XPostion; tile.ImageSize = imgsize; PDFSize step = new PDFSize(); if (this.XStep == 0) { step.Width = width; } else { step.Width = this.XStep; } if (this.YStep == 0) { step.Height = height; } else { step.Height = this.YStep; } tile.Step = step; PDFPoint start = new PDFPoint(bounds.X + this.XPostion, bounds.Y + this.YPostion); if (g.Origin == DrawingOrigin.TopLeft) { start.Y = g.ContainerSize.Height - start.Y; } tile.Start = start; PDFName name = g.Container.Register(tile); g.SetFillPattern(name); return(true); } else { return(false); } }