Beispiel #1
0
            internal Enumerator(
                Tree <TKey, TValue> tree
                )
            {
                this.tree = tree;

                container = tree.Container;
                PdfDictionary   rootNode   = tree.BaseDataObject;
                PdfDirectObject kidsObject = rootNode[PdfName.Kids];

                if (kidsObject == null) // Leaf node.
                {
                    PdfDirectObject namesObject = rootNode[PdfName.Names];
                    if (namesObject is PdfReference)
                    {
                        container = ((PdfReference)namesObject).IndirectObject;
                    }
                    names = (PdfArray)namesObject.Resolve();
                }
                else // Intermediate node.
                {
                    if (kidsObject is PdfReference)
                    {
                        container = ((PdfReference)kidsObject).IndirectObject;
                    }
                    kids = (PdfArray)kidsObject.Resolve();
                }
            }
            public override void AfterClone(
                Cloner cloner,
                PdfArray parent,
                int index,
                PdfDirectObject item
                )
            {
                PdfDictionary annotation = (PdfDictionary)item.Resolve();

                if (annotation.ContainsKey(PdfName.FT))
                {
                    cloner.context.Document.Form.Fields.Add(Field.Wrap(annotation.Reference));
                }
            }
Beispiel #3
0
            public override void AfterClone(
                Cloner cloner,
                PdfArray source,
                PdfArray clone,
                int index,
                PdfDirectObject item
                )
            {
                PdfDictionary annotation = (PdfDictionary)item.Resolve();

                if (annotation.ContainsKey(PdfName.FT))
                {
                    cloner.context.Document.Form.Fields.Add(Field.Wrap(annotation.Reference));
                }
                else if (annotation.ContainsKey(PdfName.Dest))
                {
                    PdfDirectObject destObject = annotation[PdfName.Dest];
                    if (destObject is PdfString) // Named destination.
                    {
                        CloneNamedObject <Destination>(cloner, source, (PdfString)destObject);
                    }
                }
            }
Beispiel #4
0
            private KeyValuePair <TKey, TValue>?GetNext(
                )
            {
                /*
                 * NOTE: Algorithm:
                 * 1. [Vertical, down] We have to go downward the name tree till we reach
                 * a names collection (leaf node).
                 * 2. [Horizontal] Then we iterate across the names collection.
                 * 3. [Vertical, up] When leaf-nodes scan is complete, we go upward solving
                 * parent nodes, repeating step 1.
                 */
                while (true)
                {
                    if (names == null)
                    {
                        if (kids == null ||
                            kids.Count == levelIndex) // Kids subtree complete.
                        {
                            if (levels.Count == 0)
                            {
                                return(null);
                            }

                            // 3. Go upward one level.
                            // Restore current level!
                            object[] level = levels.Pop();
                            container  = (PdfIndirectObject)level[0];
                            kids       = (PdfArray)level[1];
                            levelIndex = ((int)level[2]) + 1; // Next node (partially scanned level).
                        }
                        else // Kids subtree incomplete.
                        {
                            // 1. Go downward one level.
                            // Save current level!
                            levels.Push(new object[] { container, kids, levelIndex });

                            // Move downward!
                            PdfReference kidReference = (PdfReference)kids[levelIndex];
                            container = kidReference.IndirectObject;
                            PdfDictionary   kid        = (PdfDictionary)kidReference.DataObject;
                            PdfDirectObject kidsObject = kid[PdfName.Kids];
                            if (kidsObject == null) // Leaf node.
                            {
                                PdfDirectObject namesObject = kid[tree.pairsKey];
                                if (namesObject is PdfReference)
                                {
                                    container = ((PdfReference)namesObject).IndirectObject;
                                }
                                names = (PdfArray)namesObject.Resolve();
                                kids  = null;
                            }
                            else // Intermediate node.
                            {
                                if (kidsObject is PdfReference)
                                {
                                    container = ((PdfReference)kidsObject).IndirectObject;
                                }
                                kids = (PdfArray)kidsObject.Resolve();
                            }
                            levelIndex = 0; // First node (new level).
                        }
                    }
                    else
                    {
                        if (names.Count == levelIndex) // Names complete.
                        {
                            names = null;
                        }
                        else // Names incomplete.
                        {
                            // 2. Object found.
                            TKey   key   = (TKey)names[levelIndex];
                            TValue value = tree.WrapValue(names[levelIndex + 1]);
                            levelIndex += 2;

                            return(new KeyValuePair <TKey, TValue>(key, value));
                        }
                    }
                }
            }
 private Rectangle(
     PdfDirectObject baseObject
     ) : base(Normalize((PdfArray)baseObject.Resolve()))
 {
 }