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");
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            if (this.Roots.Count > 0)
            {
                if (context.ShouldLogDebug)
                {
                    context.TraceLog.Begin(TraceLevel.Verbose, "Outline Stack", "Starting to render the outline tree");
                }

                PDFObjectRef outlines = writer.BeginObject();
                writer.BeginDictionary();
                writer.WriteDictionaryNameEntry("Type", "Outlines");
                PDFObjectRef first, last;
                int          count;

                this.RenderOutlineCollection(this.Roots, outlines, context, writer, out first, out last, out count);

                if (null != first)
                {
                    writer.WriteDictionaryObjectRefEntry("First", first);
                }
                if (null != last)
                {
                    writer.WriteDictionaryObjectRefEntry("Last", last);
                }
                if (count > 0)
                {
                    writer.WriteDictionaryNumberEntry("Count", count);
                }

                writer.EndDictionary();
                writer.EndObject();//outlines

                if (context.ShouldLogDebug)
                {
                    context.TraceLog.End(TraceLevel.Verbose, "Outline Stack", "Finished rendering the outline tree");
                }
                else if (context.ShouldLogVerbose)
                {
                    context.TraceLog.Add(TraceLevel.Verbose, "Outline Stack", "Rendered the outline tree to indirect object " + outlines + " with first " + first + ", last " + last + " and count " + count);
                }

                return(outlines);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        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);
                    }
                }
            }
        }
        /// <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);
                }
            }
        }
Esempio n. 6
0
 protected override void RenderImageInformation(PDFContextBase context, PDFWriter writer)
 {
     base.RenderImageInformation(context, writer);
     if (this.AlphaData != null)
     {
         PDFObjectRef alpha = this.RenderAlpaImageData(context, writer);
         writer.WriteDictionaryObjectRefEntry("SMask", alpha);
     }
 }
        private void OutputDefaultResources(PDFRenderContext context, PDFWriter writer)
        {
            writer.BeginDictionaryEntry("DR");
            writer.BeginDictionaryS();

            writer.BeginDictionaryEntry("Font");

            writer.BeginDictionary();
            writer.WriteDictionaryObjectRefEntry("frsc1", new PDFObjectRef(7, 0));
            writer.EndDictionary();

            writer.EndDictionaryEntry();

            writer.EndDictionary();

            writer.EndDictionaryEntry();
        }
Esempio n. 8
0
        protected override PDFObjectRef DoRenderToPDF(PDFContextBase context, PDFWriter writer)
        {
            PDFObjectRef oref = writer.BeginObject(this.Name.Value);

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "Pattern");
            writer.WriteDictionaryNumberEntry("PatternType", (int)this.PatternType);
            //Actual shading dictionary
            var shading = this.RenderShadingDictionary(context, writer);

            if (null != shading)
            {
                writer.WriteDictionaryObjectRefEntry("Shading", shading);
            }

            writer.EndDictionary();
            writer.EndObject();

            return(oref);
        }
        /// <summary>
        /// Outputs all the names within this dictionary to a new PDFObject in output writer and returns a reference to the dictionary
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <returns></returns>
        public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            PDFObjectRef names = writer.BeginObject();

            writer.BeginDictionary();

            if (_dests.Count > 0)
            {
                List <string> all = new List <string>(_dests.Keys);

                all.Sort();
                PDFObjectRef dests = WriteDestinationNames(context, writer, all);

                writer.WriteDictionaryObjectRefEntry("Dests", dests);
            }
            writer.EndDictionary();

            writer.EndObject();

            return(names);
        }
Esempio n. 10
0
        private void RenderOutlineCollection(PDFOutlineRefCollection col, PDFObjectRef parent, PDFRenderContext context, PDFWriter writer, out PDFObjectRef first, out PDFObjectRef last, out int count)
        {
            PDFObjectRef        prev          = null;
            List <PDFObjectRef> previousitems = new List <PDFObjectRef>();

            first = null;
            last  = null;
            count = 0;
            int i = 0;

            do
            {
                int          innercount;
                PDFObjectRef one = RenderOutlineItem(col[i], parent, prev, context, writer, out innercount);
                if (i == 0)
                {
                    first = one;
                }
                if (i == col.Count - 1)
                {
                    last = one;
                }
                i++;
                prev = one;
                previousitems.Add(one);
                count += innercount;
            } while (i < col.Count);

            //close all the dictionaries and object in reverse order
            //adding the next entry first if we are not the last entry
            for (int p = previousitems.Count - 1; p >= 0; p--)
            {
                if (p < previousitems.Count - 1)
                {
                    writer.WriteDictionaryObjectRefEntry("Next", previousitems[p + 1]);
                }
                writer.EndDictionary();
                writer.EndObject();
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Outputs the entire contents of this name dictionary to the specified writer
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <returns></returns>
        public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            PDFObjectRef names = null;

            if (this.InnerDictionary.Count > 0)
            {
                names = writer.BeginObject();
                writer.BeginDictionary();

                foreach (KeyValuePair <string, PDFCategorisedNameTree> kvp in this.InnerDictionary)
                {
                    PDFObjectRef oref = kvp.Value.OutputToPDF(writer, context);
                    if (null != oref)
                    {
                        writer.WriteDictionaryObjectRefEntry(kvp.Key, oref);
                    }
                }

                writer.EndDictionary();
                writer.EndObject();
            }
            return(names);
        }
Esempio n. 12
0
        private PDFObjectRef RenderOutlineItem(PDFOutlineRef outlineref, PDFObjectRef parent, PDFObjectRef prev, PDFRenderContext context, PDFWriter writer, out int count)
        {
            PDFOutline outline = outlineref.Outline;

            Scryber.Drawing.PDFColor  c  = outlineref.GetColor();
            Scryber.Drawing.FontStyle fs = outlineref.GetFontStyle();
            bool isopen = outlineref.GetIsOpen();

            count = 1;//this one
            PDFObjectRef item = writer.BeginObject();

            writer.BeginDictionary();
            writer.WriteDictionaryObjectRefEntry("Parent", parent);
            writer.WriteDictionaryStringEntry("Title", outline.Title);
            writer.WriteDictionaryStringEntry("Dest", outline.DestinationName);
            if (null != c)
            {
                writer.BeginDictionaryEntry("C");
                writer.BeginArray();
                writer.WriteRealS(c.Red.Value, c.Green.Value, c.Blue.Value);
                writer.EndArray();
                writer.EndDictionaryEntry();
            }

            if (fs != Scryber.Drawing.FontStyle.Regular)
            {
                int f = 0;
                if ((fs & Scryber.Drawing.FontStyle.Bold) > 0)
                {
                    f = 2;
                }
                if ((fs & Scryber.Drawing.FontStyle.Italic) > 0)
                {
                    f += 1;
                }
                writer.WriteDictionaryNumberEntry("F", f);
            }

            if (null != prev)
            {
                writer.WriteDictionaryObjectRefEntry("Prev", prev);
            }

            if (context.ShouldLogVerbose)
            {
                context.TraceLog.Add(TraceLevel.Verbose, "Outline Stack", "Rendered outline item " + item + " with title '" + outline.Title + " and destination name " + outline.DestinationName);
            }

            if (outlineref.HasInnerItems)
            {
                if (context.ShouldLogDebug)
                {
                    context.TraceLog.Begin(TraceLevel.Debug, "Outline Stack", "Started rendering inner outline items");
                }


                int          opencount;
                PDFObjectRef childfirst, childlast;
                this.RenderOutlineCollection(outlineref.InnerItems, item, context, writer, out childfirst, out childlast, out opencount);

                writer.WriteDictionaryObjectRefEntry("First", childfirst);
                writer.WriteDictionaryObjectRefEntry("Last", childlast);
                if (opencount > 0)
                {
                    if (isopen)
                    {
                        writer.WriteDictionaryNumberEntry("Count", opencount);
                        count += opencount;
                    }
                    else
                    {
                        writer.WriteDictionaryNumberEntry("Count", -opencount);
                    }
                }

                if (context.ShouldLogDebug)
                {
                    context.TraceLog.End(TraceLevel.Debug, "Outlines", " Finished rendering inner outline items");
                }
            }

            //we don't close the dictionary here as we need the next entry written
            //It should be closed in the calling method

            return(item);
        }
Esempio n. 13
0
        protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            //Get the default font and size required for the DA (default Appearance value)
            var xObject = this._states[FormFieldAppearanceState.Normal];

            if (null == xObject)
            {
                return(null);
            }

            PDFObjectRef root = writer.BeginObject();

            var    font = this._style.CreateFont();
            var    rsrc = xObject.Document.GetResource(Scryber.Resources.PDFResource.FontDefnResourceType, font.FullName, true);
            string da   = rsrc.Name.ToString() + " " + font.Size.ToPoints().Value.ToString() + " Tf";

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Subtype", "Widget");
            writer.WriteDictionaryStringEntry("T", this.Name);

            if (!string.IsNullOrEmpty(this.Value))
            {
                writer.WriteDictionaryStringEntry("V", this.Value);
            }

            if (!string.IsNullOrEmpty(this.DefaultValue))
            {
                writer.WriteDictionaryStringEntry("DV", this.DefaultValue);
            }

            writer.WriteDictionaryNumberEntry("Ff", (int)this.FieldOptions + (int)this.FieldType);
            writer.WriteDictionaryStringEntry("DA", da);
            writer.WriteDictionaryNameEntry("FT", GetFieldTypeName(this.FieldType));
            if (null != this._page && null != this._page.PageObjectRef)
            {
                writer.WriteDictionaryObjectRefEntry("P", this._page.PageObjectRef);
            }

            //MK - appearance dictionary
            writer.BeginDictionaryEntry("MK");
            writer.BeginDictionary();

            if (this._style.IsValueDefined(Styles.StyleKeys.BorderColorKey))
            {
                WriteInputColor(context, writer, "BC", this._style.Border.Color);
            }
            if (this._style.IsValueDefined(Styles.StyleKeys.BgColorKey))
            {
                WriteInputColor(context, writer, "BG", this._style.Background.Color);
            }
            writer.EndDictionary();
            writer.EndDictionaryEntry();

            if (this._states.Count > 0)
            {
                _location = context.Offset;

                Drawing.PDFRect bounds = Drawing.PDFRect.Empty;
                writer.BeginDictionaryEntry("AP");
                writer.BeginDictionary();
                foreach (var kvp in _states)
                {
                    xObject = kvp.Value;
                    FormFieldAppearanceState state = kvp.Key;

                    PDFObjectRef oref = xObject.OutputToPDF(context, writer);

                    if (null != oref)
                    {
                        PDFSize sz = new Drawing.PDFSize(xObject.Width, xObject.Height);
                        if (_size == PDFSize.Empty)
                        {
                            _size = sz;
                        }
                        else
                        {
                            if (_size.Width < sz.Width)
                            {
                                _size.Width = sz.Width;
                            }
                            if (_size.Height < sz.Height)
                            {
                                _size.Height = sz.Height;
                            }
                        }
                        var name = GetFieldStateName(kvp.Key);
                        writer.WriteDictionaryObjectRefEntry(name, oref);

                        //We should have all states starting at the same location no matter what.
                        this._location = xObject.Location;
                    }
                }
                writer.EndDictionary();
                writer.EndDictionaryEntry();

                PDFReal left   = context.Graphics.GetXPosition(_location.X);
                PDFReal top    = context.Graphics.GetYPosition(_location.Y);
                PDFReal right  = left + context.Graphics.GetXOffset(_size.Width);
                PDFReal bottom = top + context.Graphics.GetYOffset(_size.Height);

                writer.BeginDictionaryEntry("Rect");
                writer.WriteArrayRealEntries(true, left.Value, bottom.Value, right.Value, top.Value);
                writer.EndDictionaryEntry();
            }
            writer.EndDictionary();
            writer.EndObject();
            //context.Offset = new PDFPoint(context.Offset.X, context.Offset.Y + _size.Height);
            return(root);
        }
Esempio n. 14
0
        private void WriteXObjectDictionaryContent(PDFRenderContext context, PDFWriter writer, long len, IStreamFilter[] filters)
        {
            writer.WriteDictionaryNameEntry("Type", "XObject");
            if (!string.IsNullOrEmpty(this.SubType))
            {
                writer.WriteDictionaryNameEntry("Subtype", "Form");
            }

            writer.BeginDictionaryEntry("Matrix");
            writer.WriteArrayRealEntries(PDFTransformationMatrix.Identity().Components); // this.Matrix.Components);
            writer.EndDictionaryEntry();

            writer.BeginDictionaryEntry("BBox");
            writer.BeginArrayS();

            if (this._position.ViewPort.HasValue)
            {
                PDFRect vp = this._position.ViewPort.Value;
                writer.WriteReal(vp.X.PointsValue);
                writer.WriteRealS(vp.Y.PointsValue);
                writer.WriteRealS(vp.Width.PointsValue);
                writer.WriteRealS(vp.Height.PointsValue);
            }
            else
            {
                writer.WriteReal(0.0F);
                writer.WriteRealS(0.0F);
                writer.WriteRealS(this._childContainer.Height.PointsValue);
                writer.WriteRealS(this._childContainer.Height.PointsValue);
            }
            writer.EndArray();
            writer.EndDictionaryEntry();


            PDFObjectRef res = this._resources.WriteResourceList(context, writer);

            if (null != res)
            {
                writer.WriteDictionaryObjectRefEntry("Resources", res);
            }

            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();
            }
        }
        //
        // 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);
        }
Esempio n. 16
0
        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);
        }