Example #1
0
        //
        // public methods
        //

        #region object IArtefactCollection.Register(IArtefactEntry entry)

        /// <summary>
        /// Registers and begins an artefact in the name dictionary
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        object IArtefactCollection.Register(IArtefactEntry entry)
        {
            PDFCategorisedNameTree col;
            object returnValue;

            if (entry is ICategorisedArtefactNamesEntry)
            {
                ICategorisedArtefactNamesEntry catEntry = (ICategorisedArtefactNamesEntry)entry;
                if (_dictionary.TryGetValue(catEntry.NamesCategory, out col) == false)
                {
                    col = CreateTreeForCategory(catEntry.NamesCategory);
                    _dictionary.Add(catEntry.NamesCategory, col);
                }
                returnValue = col.Push(catEntry.FullName, catEntry);
            }
            //else if (entry is PDFDestination) //Default is Destination as this was generated before the Attachments or any other ICategorizedArtefactNameEntry implementation
            //{
            //    PDFDestination dest = (PDFDestination)entry;
            //    if (_dictionary.TryGetValue(DestinationsName, out col) == false)
            //    {
            //        col = CreateTreeForCategory(DestinationsName);
            //        _dictionary.Add(DestinationsName, col);
            //    }
            //    returnValue = col.Push(dest.FullName, dest);
            //}
            else
            {
                throw new PDFException(Errors.UnknownArtefactForNamesDictionary);
            }

            return(returnValue);
        }
Example #2
0
        /// <summary>
        /// Closes a previous artefact registration popping it off the stack of it's name tree collection
        /// </summary>
        /// <param name="registration"></param>
        public void Close(object registration)
        {
            PDFCategorisedNameTree col;

            if (registration is ICategorisedArtefactNamesEntry)
            {
                ICategorisedArtefactNamesEntry catEntry = (ICategorisedArtefactNamesEntry)registration;
                if (_dictionary.TryGetValue(catEntry.NamesCategory, out col))
                {
                    col.Pop(catEntry.FullName, catEntry);
                }
                else
                {
                    throw new PDFException(catEntry.NamesCategory + " Names dictionary entry has not previously been registered");
                }
            }
            else if (registration is PDFDestination) //Default is Destination as this was generated before the support for other name trees
            {
                PDFDestination dest = (PDFDestination)registration;
                if (_dictionary.TryGetValue(DestinationsName, out col))
                {
                    col.Pop(dest.FullName, dest);
                }
                else
                {
                    throw new PDFException("Destinations Names dictionary entry has not previously been registered");
                }
            }
            else
            {
                throw new PDFException("Unknown Artefact entry for the Names dictionary");
            }
        }
        //
        // methods
        //

        #region object IArtefactCollection.Register(IArtefactEntry entry)

        /// <summary>
        /// Implmentation of the IArtefactCollection Register method, to ensure that all names are included in the final PDF docucment. Calls RegisterDestination
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        object IArtefactCollection.Register(IArtefactEntry entry)
        {
            if (entry is ICategorisedArtefactNamesEntry)
            {
                ICategorisedArtefactNamesEntry catNameEntry = (ICategorisedArtefactNamesEntry)entry;
            }
            PDFDestination dest = (PDFDestination)entry;

            return(this.RegisterDestination(dest));
        }
        public Native.PDFObjectRef OutputToPDF(PDFWriter writer, PDFRenderContext context)
        {
            List <ICategorisedArtefactNamesEntry> entries = new List <ICategorisedArtefactNamesEntry>();

            Native.PDFObjectRef oref = null;
            if (this.InnerEntries.Count == 0)
            {
                return(oref);
            }
            if (this.NameType == PDFCategorisedNameDictionary.DestinationsName)
            {
                oref = writer.BeginObject();
                writer.BeginDictionary();
                writer.BeginDictionaryEntry("Names");


                string first = null;
                string last  = null;
                writer.BeginArray();
                foreach (KeyValuePair <string, IArtefactEntry> kvp in this.InnerEntries)
                {
                    if (string.IsNullOrEmpty(first))
                    {
                        first = kvp.Key;
                    }
                    else
                    {
                        last = kvp.Key;
                    }

                    writer.BeginArrayEntry();
                    writer.WriteStringLiteral(kvp.Key);
                    writer.EndArrayEntry();

                    writer.BeginArrayEntry();
                    ((PDFDestination)kvp.Value).OutputToPDF(context, writer);
                    writer.EndArrayEntry();
                    writer.WriteLine();
                }

                writer.EndArray();
                writer.EndDictionaryEntry();

                if (!string.IsNullOrEmpty(first) && !string.IsNullOrEmpty(last))
                {
                    writer.BeginDictionaryEntry("Limits");
                    writer.WriteArrayStringEntries(true, first, last);
                    writer.EndDictionaryEntry();
                }

                writer.EndDictionary();
                writer.EndObject();
            }
            else //we contain ICategorizedArtefactNameEntry(s)
            {
                oref = writer.BeginObject();
                writer.BeginDictionary();
                writer.BeginDictionaryEntry("Names");


                //string first = null;
                //string last = null;

                writer.BeginArray();
                foreach (KeyValuePair <string, IArtefactEntry> kvp in this.InnerEntries)
                {
                    //if (string.IsNullOrEmpty(first))
                    //    first = kvp.Key;
                    //else
                    //    last = kvp.Key;

                    writer.BeginArrayEntry();
                    writer.WriteStringLiteral(kvp.Key);
                    writer.EndArrayEntry();

                    writer.BeginArrayEntry();
                    ICategorisedArtefactNamesEntry entry = (ICategorisedArtefactNamesEntry)kvp.Value;

                    Native.PDFObjectRef entryOref = entry.OutputToPDF(context, writer);
                    if (null != entryOref)
                    {
                        writer.WriteObjectRef(entryOref);
                    }

                    writer.EndArrayEntry();
                    writer.WriteLine();
                }

                writer.EndArray();
                writer.EndDictionaryEntry();

                //Limits only required on Intermediate and Leaf nodes of a tree, not the root
                //if (!string.IsNullOrEmpty(first) && !string.IsNullOrEmpty(last))
                //{
                //    writer.BeginDictionaryEntry("Limits");
                //    writer.WriteArrayStringEntries(true, first, last);
                //    writer.EndDictionaryEntry();

                //}

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

            return(oref);
        }