/// <summary> /// If this document has artefacts then the collection is output. /// </summary> /// <param name="context"></param> /// <param name="writer"></param> private void WriteArtefacts(PDFRenderContext context, PDFWriter writer) { PDFArtefactCollectionSet artefacts = this.Artefacts; if (artefacts != null && artefacts.Count > 0) { foreach (IArtefactCollection col in artefacts) { context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Outputting artefact catalog entry collection " + col.CollectionName); writer.BeginDictionaryEntry(col.CollectionName); PDFObjectRef entry = col.OutputToPDF(context, writer); if (entry != null) { writer.WriteObjectRef(entry); } else { writer.WriteNull(); } writer.EndDictionaryEntry(); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished artefact catalog entry collection " + col.CollectionName); } } }
/// <summary> /// Outputs the positioning and visibility of UI elements for the viewer /// </summary> /// <param name="context"></param> /// <param name="writer"></param> protected virtual void WriteViewerPreferences(PDFRenderContext context, PDFWriter writer) { DocumentViewPreferences docview = this.DocumentComponent.ViewPreferences; if (null != docview) { PDFObjectRef view = docview.OutputToPDF(context, writer); if (null != view) { writer.WriteDictionaryObjectRefEntry("ViewerPreferences", view); } string value = docview.GetPageDisplayName(docview.PageDisplay); if (!string.IsNullOrEmpty(value)) { writer.WriteDictionaryNameEntry("PageMode", value); } value = docview.GetPageLayoutName(docview.PageLayout); if (!string.IsNullOrEmpty(value)) { writer.WriteDictionaryNameEntry("PageLayout", value); } } }
protected void DoWriteArtefacts(PDFRenderContext context, PDFWriter writer) { if (this.Artefacts != null && this.Artefacts.Count > 0) { foreach (IArtefactCollection col in this.Artefacts) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Debug, "Layout Page", "Rendering artefact entry " + col.CollectionName); } PDFObjectRef artefact = col.OutputToPDF(context, writer); if (null != artefact) { writer.WriteDictionaryObjectRefEntry(col.CollectionName, artefact); } if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Debug, "Layout Page", "Finished artefact entry " + col.CollectionName); } } } }
// // methods // public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (this.IsEmpty()) { if (context.ShouldLogMessage) { context.TraceLog.Add(TraceLevel.Message, "Viewer Preferences", "No values set on the document viewer preferences so not outputting"); } return(null); } else { PDFObjectRef oref = writer.BeginObject(); writer.BeginDictionary(); this.WriteOptionalFlag("CenterWindow", _centrewindow, context, writer); this.WriteOptionalFlag("FitWindow", _fitwindow, context, writer); this.WriteOptionalFlag("HideWindowUI", _hidewindowui, context, writer); this.WriteOptionalFlag("HideToolbar", _hidetoolbar, context, writer); this.WriteOptionalFlag("HideMenubar", _hidemenubar, context, writer); if (this.NonFullScreenPageDisplay != PageDisplayMode.Undefined) { this.WriteOptionalName("NonFullScreenPageMode", this.NonFullScreenPageDisplay.ToString(), context, writer); } writer.EndDictionary(); writer.EndObject(); return(oref); } }
public void RenderUnderlines(PDFTextRunEnd end, PDFRenderContext context, PDFWriter writer) { PDFUnit offsetV = this.TextRenderOptions.GetAscent() / UnderlineOffsetFactor; PDFUnit linethickness = this.TextRenderOptions.Font.Size / ThicknessFactor; this.RenderTextDecoration(end, context, writer, offsetV, linethickness); }
public void RenderOverLines(PDFTextRunEnd end, PDFRenderContext context, PDFWriter writer) { PDFUnit offsetV = new PDFUnit(-this.TextRenderOptions.GetAscent().PointsValue, PageUnits.Points); PDFUnit linethickness = this.TextRenderOptions.Font.Size / ThicknessFactor; this.RenderTextDecoration(end, context, writer, offsetV, linethickness); }
// // methods // #region public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) + Support methods /// <summary> /// Outputs this Info to the current writer /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFObjectRef inforef = writer.BeginObject("Info"); writer.BeginDictionary(); OutputInfoEntry("Title", this.Title, writer); OutputInfoEntry("Subject", this.Subject, writer); OutputInfoEntry("Author", this.Author, writer); OutputInfoEntry("Keywords", this.Keywords, writer); OutputInfoEntry("Producer", this.Producer, writer); OutputInfoEntry("Creator", this.Creator, writer); OutputInfoEntry("CreationDate", this.CreationDate, writer); OutputInfoEntry("ModDate", this.ModifiedDate, writer); if (this.HasTrapping) { writer.WriteDictionaryNameEntry("Trapped", this.Trapped.ToString()); } if (this.HasExtras) { foreach (PDFDocumentInfoExtra extra in this.Extras) { OutputInfoEntry(extra.Name, extra.Value, writer); } } writer.EndDictionary(); writer.EndObject(); return(inforef); }
// // rendering // protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { if (context.ShouldLogVerbose) { context.TraceLog.Begin(TraceLevel.Verbose, "Layout Page", "Starting the render of Page: " + this.PageIndex); } else if (context.ShouldLogMessage) { context.TraceLog.Add(TraceLevel.Message, "Layout Page", "Rendering layout page " + this.PageIndex); } //get the current style and aply it to the style stack Style style = this.FullStyle; context.StyleStack.Push(style); PageSize pagesize = this.PageOwner.GetPageSize(style); //PDFPageNumbering num = this.GetNumbering(style); //this.Document.RegisterPageNumbering(context.PageIndex, this, num); PDFObjectRef last = writer.LastObjectReference(); PDFObjectRef pg; pg = DoWritePage(context, writer, last); context.StyleStack.Pop(); if (context.ShouldLogVerbose) { context.TraceLog.End(TraceLevel.Verbose, "Layout Page", "Completed the rendering of page: " + this.PageIndex); } return(pg); }
/// <summary> /// Simply ends the text and restores state /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected override Native.PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { context.Graphics.EndText(); context.Graphics.RestoreGraphicsState(); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, PDFTextRun.TEXT_LOG_CATEGORY, "Ended the text rendering of component '" + this.Owner.ToString()); } if (null != this.Start) { if (this.Start.ShouldRenderUnderline(context)) { this.Start.RenderUnderlines(this, context, writer); } if (this.Start.ShouldRenderStrikeThrough(context)) { this.Start.RenderStrikeThrough(this, context, writer); } if (this.Start.ShouldRenderOverline(context)) { this.Start.RenderOverLines(this, context, writer); } if (this.Start.HasCustomSpace) { context.Graphics.ResetCustomWordSpace(); } } return(null); }
protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFName name = PDFLayoutMarkedContentBegin.GetNameForContentType(this.Begin.ContentType); context.Graphics.EndMarkedContent(name); return(base.DoOutputToPDF(context, writer)); }
/// <summary> /// Outputs the first Page tree Component and calls Output on each of the layout pages. /// </summary> /// <param name="context">The current context</param> /// <param name="writer">The current writer</param> /// <returns>A reference to the current page tree root Component</returns> protected virtual PDFObjectRef OutputPageTree(PDFRenderContext context, PDFWriter writer) { //Begin the Pages object and dictionary PDFObjectRef pgs = writer.BeginObject(Const.PageTreeName); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Pages"); List <PDFObjectRef> pagerefs = OutputAllPages(pgs, context, writer); //write the kids array entry in the dictionary writer.BeginDictionaryEntry("Kids"); writer.BeginArray(); foreach (PDFObjectRef kid in pagerefs) { writer.BeginArrayEntry(); writer.WriteFileObject(kid); writer.EndArrayEntry(); } writer.EndArray(); //Write the total number of pages to the dictionary writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("Count"); writer.WriteNumber(pagerefs.Count); writer.EndDictionaryEntry(); //close the ditionary and the object writer.EndDictionary(); writer.EndObject(); return(pgs); }
protected override Native.PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { bool first = true; foreach (PDFLayoutRun run in this.Runs) { if (null != _linespacingOptions) { if (run is PDFTextRunBegin) { (run as PDFTextRunBegin).SetTextSpacing(this._linespacingOptions.WordSpace, this._linespacingOptions.CharSpace); } else if (run is PDFTextRunSpacer) { continue; } else if (first) { context.Graphics.SetTextSpacing(this._linespacingOptions.WordSpace, this._linespacingOptions.CharSpace, this._linespacingOptions.Options.Font.Size); } } run.OutputToPDF(context, writer); first = false; } return(base.DoOutputToPDF(context, writer)); }
protected virtual void WriteCatalogEntries(PDFRenderContext context, PDFWriter writer) { // Pages context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write Pages"); PDFObjectRef pglist = this.OutputPageTree(context, writer); writer.WriteDictionaryObjectRefEntry("Pages", pglist); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing Pages with page tree " + pglist); // Page Labels context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write Page Labels"); PDFObjectRef pglabels = this.WritePageLabels(context, writer); if (null != pglabels) { writer.WriteDictionaryObjectRefEntry("PageLabels", pglabels); } context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing Page Labels"); // Artefacts context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write document Artefacts"); this.WriteArtefacts(context, writer); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing document Artefacts"); //Viewer Preferences context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write Viewer Preferences"); this.WriteViewerPreferences(context, writer); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing Viewer Preferences"); }
protected virtual PDFObjectRef DoWritePage(PDFRenderContext context, PDFWriter writer, PDFObjectRef parent) { PDFObjectRef pg = writer.BeginPage(context.PageIndex); this.PageObjectRef = pg; writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Page"); writer.WriteDictionaryObjectRefEntry("Parent", parent); writer.BeginDictionaryEntry("MediaBox"); writer.WriteArrayRealEntries(0.0, 0.0, this.Size.Width.ToPoints().Value, this.Size.Height.ToPoints().Value); writer.EndDictionaryEntry(); if (this.FullStyle.IsValueDefined(StyleKeys.PageAngle)) { int value = this.FullStyle.GetValue(StyleKeys.PageAngle, 0); writer.WriteDictionaryNumberEntry("Rotate", value); } context.PageSize = this.Size; context.Offset = new PDFPoint(); context.Space = context.PageSize; if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Layout Page", "Rendering the contents of page : " + this.PageIndex); } PDFObjectRef content = this.OutputContent(context, writer); if (content != null) { writer.WriteDictionaryObjectRefEntry("Contents", content); } if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Layout Page", "Rendering the resources of page : " + this.PageIndex); } //PDFObjectRef[] annots = this.DoWriteAnnotations(context, writer); //if (null != annots && annots.Length > 0) //{ // writer.BeginDictionaryEntry("Annots"); // writer.WriteArrayRefEntries(true, annots); // writer.EndDictionaryEntry(); //} PDFObjectRef ress = this.DoWriteResource(context, writer); if (ress != null) { writer.WriteDictionaryObjectRefEntry("Resources", ress); } DoWriteArtefacts(context, writer); writer.EndDictionary(); writer.EndPage(context.PageIndex); return(pg); }
public void SetArrangement(PDFRenderContext context, Style style, PDFRect contentBounds) { PDFComponentMultiArrangement arrange = new PDFComponentMultiArrangement(); arrange.PageIndex = context.PageIndex; arrange.RenderBounds = contentBounds; arrange.FullStyle = style; this.SetArrangement(arrange); }
public void RenderStrikeThrough(PDFTextRunEnd end, PDFRenderContext context, PDFWriter writer) { //Strike through is up offset one third the font ascent PDFUnit offsetV = new PDFUnit(-this.TextRenderOptions.GetAscent().PointsValue *StrikeThroughOffset, PageUnits.Points); PDFUnit linethickness = this.TextRenderOptions.Font.Size / ThicknessFactor; this.RenderTextDecoration(end, context, writer, offsetV, linethickness); }
/// <summary> /// writes the collection of document info entries /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected virtual void WriteInfo(PDFRenderContext context, PDFWriter writer) { DocumentInfo info = this.DocumentComponent.Info; if (null != info) { info.OutputToPDF(context, writer); } }
/// <summary> /// Invokes the output to PDF on each of the components in this list /// that implement the IPDFRenderComponent interface /// </summary> /// <param name="context"></param> /// <param name="writer"></param> public void OutputToPDF(PDFRenderContext context, PDFWriter writer) { foreach (IPDFComponent comp in this) { if (comp is IPDFRenderComponent) { ((IPDFRenderComponent)comp).OutputToPDF(context, writer); } } }
public void RegisterPostRender(PDFRenderContext context) { foreach (IPDFComponent comp in this) { if (comp is Component) { ((Component)comp).RegisterPostRender(context); } } }
/// <summary> /// Raises the PostRender event. Inheritors can override this method to perfom their own actions /// </summary> /// <param name="context">The current render context</param> protected virtual void OnPostRender(PDFRenderContext context) { if (this.HasRegisteredEvents) { PDFRenderEventHandler handler = (PDFRenderEventHandler)this.Events[PostRenderEventKey]; if (null != handler) { handler(this, new PDFRenderEventArgs(context)); } } }
/// <summary> /// Overrides base implementation to call the inner content methods /// </summary> internal override void RegisterPreRender(PDFRenderContext context) { base.RegisterPreRender(context); if (this.HasContent) { for (int i = 0; i < this.InnerContent.Count; i++) { Component comp = this.InnerContent[i]; comp.RegisterPreRender(context); } } }
private PDFObjectRef[] DoWriteAnnotations(PDFRenderContext context, PDFWriter writer) { IArtefactCollection annots; if (this.Artefacts.TryGetCollection(PDFArtefactTypes.Annotations, out annots)) { return(annots.OutputContentsToPDF(context, writer)); } else { return(null); } }
protected override Native.PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { Scryber.Drawing.PDFPoint oldOffset = context.Offset; if (this.Region.PositionMode == Drawing.PositionMode.Absolute) { context.Offset = Scryber.Drawing.PDFPoint.Empty; } Native.PDFObjectRef oref = this.Region.OutputToPDF(context, writer); context.Offset = oldOffset; return(oref); }
public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFGraphics graphics = context.Graphics; Style full = null; PDFComponentArrangement arrange = this.GetFirstArrangement(); if (null != arrange) { full = arrange.FullStyle; } if (null == full) { full = context.FullStyle; } PDFImageXObject img = this.GetImageObject(context, full); if (img != null) { PDFPoint pos = context.Offset; PDFSize imgsize = context.Space; //the pictures are drawn from their bottom left corner, so take off the height. //if (context.DrawingOrigin == DrawingOrigin.TopLeft) // pos.Y = pos.Y + imgsize.Height; graphics.SaveGraphicsState(); StyleValue <double> op; if (full.TryGetValue(StyleKeys.FillOpacityKey, out op)) { if (op.Value(full) < 1.0) { graphics.SetFillOpacity(op.Value(full)); } } PDFObjectRef imgref = img.EnsureRendered(context, writer); graphics.PaintImageRef(img, imgsize, pos); graphics.RestoreGraphicsState(); return(imgref); } else { return(null); } }
protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { //Only do this once, but can be referenced from multiple places; if (null == _renderRef) { _renderRef = this.OutputContent(context, writer); } OutputDrawingContent(context, writer); return(_renderRef); }
private void WriteAPageLabel(PDFRenderContext context, PDFWriter writer, PDFPageNumberRegistration entry) { writer.WriteLine(); writer.BeginArrayEntry(); writer.WriteNumberS(entry.FirstPageIndex); writer.BeginDictionaryS(); string type; switch (entry.Group.NumberStyle) { case PageNumberStyle.Decimals: type = "D"; break; case PageNumberStyle.UppercaseRoman: type = "R"; break; case PageNumberStyle.LowercaseRoman: type = "r"; break; case PageNumberStyle.UppercaseLetters: type = "A"; break; case PageNumberStyle.LowercaseLetters: type = "a"; break; default: type = ""; break; } if (!string.IsNullOrEmpty(type)) { writer.WriteDictionaryNameEntry("S", type); } if (entry.Group.NumberStart > 0) { writer.WriteDictionaryNumberEntry("St", entry.Group.NumberStart + entry.PreviousLinkedRegistrationPageCount); } writer.EndDictionary(); writer.EndArrayEntry(); if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Page Labels", "Output the page label entry starting at page index " + entry.FirstPageIndex + " with style " + entry.Group.NumberStyle + ", starting at " + entry.Group.NumberStart); } }
/// <summary> /// overrides the base implementation to also move the spacer and move the cursor in the graphics context /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected override Native.PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFSize offset = this.Offset; if (null != this.NextLineSpacer) { PDFUnit nextoffset = NextLineSpacer.Width; offset.Width = nextoffset - offset.Width; } context.Graphics.MoveTextCursor(offset, false); return(null); }
/// <summary> /// Outputs the document catalog (usually the first Component) and then calls output on each of the documents /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected virtual PDFObjectRef WriteCatalog(PDFRenderContext context, PDFWriter writer) { PDFObjectRef catalog = writer.BeginObject("Catalog"); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Catalog"); WriteCatalogEntries(context, writer); writer.EndDictionary(); writer.EndObject(); return(catalog); }
/// <summary> /// Outputs this region by rendering the inner item of this region /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected override Native.PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { bool logdebug = context.ShouldLogDebug; string name = string.Empty; if (logdebug) { name = this.ToString(); context.TraceLog.Begin(TraceLevel.Debug, "Layout Region", "Outputting region " + name); } if (this._contents != null && this._contents.Count > 0) { PDFSize prevsize = context.Space; PDFPoint prevloc = context.Offset; PDFPoint offset = new PDFPoint(prevloc.X + this.TotalBounds.X, prevloc.Y + this.TotalBounds.Y); context.Space = this.TotalBounds.Size; context.Offset = offset; if (logdebug) { context.TraceLog.Add(TraceLevel.Debug, "Layout Region", "Adjusted bounds of context for region " + name + " with offset " + context.Offset + " and space " + context.Space + ", now rendering contents"); } foreach (PDFLayoutItem item in this._contents) { item.OutputToPDF(context, writer); } context.Space = prevsize; context.Offset = prevloc; } else if (logdebug) { context.TraceLog.Add(TraceLevel.Debug, "Layout Region", "Region " + name + " does not have any contents so no inner rendering required"); } if (logdebug) { context.TraceLog.End(TraceLevel.Debug, "Layout Region", "Completed output of region " + name); } return(null); }
/// <summary> /// Outputs the background for this block in the specified rect with the background style. /// </summary> /// <param name="bg">The backgrond style</param> /// <param name="border">The border style (which indicates the corner radius)</param> /// <param name="context">The current render context</param> /// <param name="rect">The rectangle to be output</param> protected virtual void OutputBackground(PDFBrush bg, PDFUnit?corner, PDFRenderContext context, PDFRect rect) { PDFGraphics g = context.Graphics; if (null != bg) { if (corner.HasValue && corner.Value != PDFUnit.Zero) { g.FillRoundRectangle(bg, rect, corner.Value); } else { g.FillRectangle(bg, rect); } } }