private PDFObjectRef RenderAlpaImageData(PDFContextBase context, PDFWriter writer) { context.TraceLog.Add(TraceLevel.Debug, "IMAGE", "Rendering image alpha mask"); PDFObjectRef mask = writer.BeginObject(); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "XObject"); writer.WriteDictionaryNameEntry("Subtype", "Image"); writer.WriteDictionaryNumberEntry("Width", this.PixelWidth); writer.WriteDictionaryNumberEntry("Height", this.PixelHeight); //writer.WriteDictionaryNumberEntry("Length", this.AlphaData.LongLength); writer.WriteDictionaryNameEntry("ColorSpace", "DeviceGray"); writer.WriteDictionaryNumberEntry("BitsPerComponent", 8); this.WriteFilterNames(context, writer); //writer.EndDictionary(); writer.BeginStream(mask); byte[] data; if (this.HasFilter && this.ShouldApplyFilters(context)) { data = this.GetAlphaFilteredData(this.Filters, context); if (null == data) { data = this.ApplyFiltersToData(this.AlphaData, context); this.SetAlphaFilteredData(this.Filters, data, context); } } else { data = this.AlphaData; } writer.WriteRaw(data, 0, data.Length); writer.EndStream(); //inserted 15/01/15 - Write the filtered length, not the actua image data length to the dictionary. writer.WriteDictionaryNumberEntry("Length", data.Length); writer.EndDictionary(); //end of insert writer.EndObject(); return(mask); }
internal PDFObjectRef Render(PDFName name, PDFContextBase context, PDFWriter writer) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Message, "Image Data", "Rendering image data for '" + name.ToString() + "'"); } PDFObjectRef renderref = writer.BeginObject(name.Value); writer.BeginDictionaryS(); writer.WriteDictionaryNameEntry("Name", name.Value); writer.WriteDictionaryNameEntry("Type", "XObject"); writer.WriteDictionaryNameEntry("Subtype", "Image"); RenderImageInformation(context, writer); //writer.EndDictionary(); //- commented for data length fix writer.BeginStream(renderref); int length = this.RenderImageStreamData(context, writer); writer.EndStream(); //Added for Data Length fix HRB 15/01/2015 writer.WriteDictionaryNumberEntry("Length", length); writer.EndDictionary(); //End of add writer.EndObject(); if (context.ShouldLogDebug) { context.TraceLog.End(TraceLevel.Message, "Image Data", "Completed render of the image data for '" + name + "' with source " + this.SourcePath); } else { context.TraceLog.Add(TraceLevel.Message, "Image Data", "Rendered the image data for '" + name.ToString() + "' with source " + this.SourcePath); } return(renderref); }
/// <summary> /// This will render the actual content of the XObject graphical content in a new object reference. /// This can then be referred to. /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> private PDFObjectRef OutputContent(PDFRenderContext context, PDFWriter writer) { PDFObjectRef xObject = writer.BeginObject(); IStreamFilter[] filters = (context.Compression == OutputCompressionType.FlateDecode) ? this._page.PageCompressionFilters : null; writer.BeginStream(xObject, filters); this.Location = context.Offset.Offset(0, this.Line.OffsetY); PDFSize origSpace = context.Space.Clone(); PDFGraphics prevGraphics = context.Graphics; using (PDFGraphics g = this.CreateGraphics(writer, context.StyleStack, context)) { context.Graphics = g; g.SaveGraphicsState(); g.RestoreGraphicsState(); context.Offset = Drawing.PDFPoint.Empty; this._childContainer.OutputToPDF(context, writer); } context.Offset = this.Location; context.Space = origSpace; context.Graphics = prevGraphics; long len = writer.EndStream(); writer.BeginDictionary(); this.WriteXObjectDictionaryContent(context, writer, len, filters); writer.EndDictionary(); writer.EndObject(); return(xObject); }
protected virtual PDFObjectRef OutputContent(PDFRenderContext context, PDFWriter writer) { PDFObjectRef oref = writer.BeginObject(); IStreamFilter[] filters = (context.Compression == OutputCompressionType.FlateDecode) ? this.PageCompressionFilters : null; writer.BeginStream(oref, filters); PDFPoint pt = context.Offset.Clone(); PDFSize sz = context.Space.Clone(); using (PDFGraphics g = this.CreateGraphics(writer, context.StyleStack, context)) { context.Graphics = g; if (null != this.HeaderBlock) { this.HeaderBlock.OutputToPDF(context, writer); } this.ContentBlock.OutputToPDF(context, writer); if (null != this.FooterBlock) { this.FooterBlock.OutputToPDF(context, writer); } if (_outputbadge) { this.PaintBadgeXObj(context, writer); } } context.Offset = pt; context.Space = sz; long len = writer.EndStream(); writer.BeginDictionary(); if (null != filters && filters.Length > 0) { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("Filter"); writer.BeginArray(); foreach (IStreamFilter filter in filters) { writer.BeginArrayEntry(); writer.WriteName(filter.FilterName); writer.EndArrayEntry(); } writer.EndArray(); writer.EndDictionaryEntry(); } else { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); } writer.EndDictionary(); writer.EndObject(); return(oref); }
// // methods // #region protected override PDFObjectRef DoRenderToPDF(PDFContextBase context, PDFWriter writer) /// <summary> /// Renders the tiling image /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected override PDFObjectRef DoRenderToPDF(PDFContextBase context, PDFWriter writer) { IStreamFilter[] filters = writer.DefaultStreamFilters; PDFObjectRef pattern = writer.BeginObject(); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Pattern"); writer.WriteDictionaryNumberEntry("PatternType", (int)this.PatternType); writer.WriteDictionaryNumberEntry("PaintType", (int)this.PaintType); writer.WriteDictionaryNumberEntry("TilingType", (int)this.TilingType); writer.BeginDictionaryEntry("BBox"); PDFPoint offset = new PDFPoint(this.Start.X, this.Start.Y - this.ImageSize.Height);// this.Start; PDFSize size = this.ImageSize; PDFSize graphicsSize = new PDFSize(size.Width + offset.X, size.Height + offset.Y); writer.WriteArrayRealEntries(true, offset.X.PointsValue, offset.Y.PointsValue, offset.X.PointsValue + size.Width.PointsValue, offset.Y.PointsValue + size.Height.PointsValue); writer.EndDictionaryEntry(); writer.WriteDictionaryRealEntry("XStep", this.Step.Width.PointsValue); writer.WriteDictionaryRealEntry("YStep", this.Step.Height.PointsValue); PDFObjectRef all = this.Resources.WriteResourceList(context, writer); writer.WriteDictionaryObjectRefEntry("Resources", all); writer.BeginStream(pattern); using (PDFGraphics g = PDFGraphics.Create(writer, false, this, DrawingOrigin.TopLeft, graphicsSize, context)) { offset = new PDFPoint(offset.X, 0.0); g.PaintImageRef(this.Image, size, offset); } long len = writer.EndStream(); if (null != filters && filters.Length > 0) { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("Filter"); writer.BeginArray(); foreach (IStreamFilter filter in filters) { writer.BeginArrayEntry(); writer.WriteName(filter.FilterName); writer.EndArrayEntry(); } writer.EndArray(); writer.EndDictionaryEntry(); } else { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); } writer.EndDictionary(); writer.EndObject(); return(pattern); }
public PDFObjectRef RenderToPDF(string fullname, PDFContextBase context, PDFWriter writer) { if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Font Descriptor", "Rendering the font descriptor information"); } PDFObjectRef oref = writer.BeginObject(); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "FontDescriptor"); writer.WriteDictionaryNameEntry("FontName", fullname); if (this.FontFamily != String.Empty) { writer.WriteDictionaryStringEntry("FontFamily", this.FontFamily); } if (this.BoundingBox != null && this.BoundingBox.Length > 0) { writer.BeginDictionaryEntry("FontBBox"); writer.WriteArrayNumberEntries(this.BoundingBox); writer.EndDictionaryEntry(); } if (this.FontStretch != FontStretch.Normal) { writer.WriteDictionaryStringEntry("FontStretch", this.FontStretch.ToString()); } if (this.Weight != 400) { writer.WriteDictionaryNumberEntry("FontWeight", this.Weight); } writer.WriteDictionaryNumberEntry("FontWeight", 700); writer.WriteDictionaryNumberEntry("Flags", (int)this.Flags); writer.WriteDictionaryNumberEntry("Ascent", (int)(this.Ascent * 0.6)); writer.WriteDictionaryNumberEntry("Descent", this.Descent); //if (this.Leading != 0.0) // writer.WriteDictionaryNumberEntry("Leading", this.Leading); if (this.CapHeight != 0.0) { writer.WriteDictionaryNumberEntry("CapHeight", this.CapHeight); } if (this.XHeight != 0.0) { writer.WriteDictionaryNumberEntry("XHeight", this.XHeight); } writer.WriteDictionaryNumberEntry("StemV", this.StemV); writer.WriteDictionaryNumberEntry("ItalicAngle", this.ItalicAngle); if (this.StemH != 0.0) { writer.WriteDictionaryNumberEntry("StemH", this.StemH); } if (this.AvgWidth != 0.0) { writer.WriteDictionaryNumberEntry("AvgWidth", this.AvgWidth); } if (this.MaxWidth != 0.0) { writer.WriteDictionaryNumberEntry("MaxWidth", this.MaxWidth); } if (this.MissingWidth != 0.0) { writer.WriteDictionaryNumberEntry("MissingWidth", this.MissingWidth); } if (this.FontFile != null) { if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Font Descriptor", "Rendering the font descriptor font file"); } byte[] outputdata = this.FontFile; string filter = null; if (context.Compression == OutputCompressionType.FlateDecode) { if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Font Descriptor", "Ensuring the font data is compressed"); } outputdata = this.FilteredFontFile; filter = this.FilterName; } PDFObjectRef fileref = writer.BeginObject(); writer.BeginDictionary(); writer.WriteDictionaryNumberEntry("Length", outputdata.Length); if (this.FontType == FontType.TrueType) { writer.WriteDictionaryNumberEntry("Length1", this.FontFile.Length); } else { throw new ArgumentOutOfRangeException("FontType"); } if (!string.IsNullOrEmpty(filter)) { writer.WriteDictionaryNameEntry("Filter", this.FilterName); } writer.EndDictionary(); writer.BeginStream(fileref); writer.WriteRaw(outputdata, 0, outputdata.Length); writer.EndStream(); writer.EndObject(); //We know this is a true type font program from above writer.WriteDictionaryObjectRefEntry("FontFile2", fileref); } writer.EndDictionary(); writer.EndObject(); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Font Descriptor", "Completed font descriptor"); } return(oref); }