コード例 #1
0
        /// <summary>
        /// Helper function for ImportExternalPage.
        /// </summary>
        void CloneElement(PdfPage page, PdfPage importPage, string key, bool deepcopy)
        {
            Debug.Assert(page != null);
            Debug.Assert(page.Owner == _document);
            Debug.Assert(importPage.Owner != null);
            Debug.Assert(importPage.Owner != _document);

            PdfItem item = importPage.Elements[key];

            if (item != null)
            {
                PdfImportedObjectTable importedObjectTable = null;
                if (!deepcopy)
                {
                    importedObjectTable = Owner.FormTable.GetImportedObjectTable(importPage);
                }

                // The item can be indirect. If so, replace it by its value.
                if (item is PdfReference)
                {
                    item = ((PdfReference)item).Value;
                }
                if (item is PdfObject)
                {
                    PdfObject root = (PdfObject)item;
                    if (deepcopy)
                    {
                        Debug.Assert(root.Owner != null, "See 'else' case for details");
                        root = DeepCopyClosure(_document, root);
                    }
                    else
                    {
                        // The owner can be null if the item is not a reference.
                        if (root.Owner == null)
                        {
                            root.Document = importPage.Owner;
                        }
                        root = ImportClosure(importedObjectTable, page.Owner, root);
                    }

                    if (root.Reference == null)
                    {
                        page.Elements[key] = root;
                    }
                    else
                    {
                        page.Elements[key] = root.Reference;
                    }
                }
                else
                {
                    // Simple items are just cloned.
                    page.Elements[key] = item.Clone();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Inherit values from parent node.
        /// </summary>
        internal static void InheritValues(PdfDictionary page, InheritedValues values)
        {
            // HACK: I'M ABSOLUTELY NOT SURE WHETHER THIS CODE COVERS ALL CASES.
            if (values.Resources != null)
            {
                PdfDictionary resources;
                PdfItem       res = page.Elements[InheritablePageKeys.Resources];
                if (res is PdfReference)
                {
                    resources          = (PdfDictionary)((PdfReference)res).Value.Clone();
                    resources.Document = page.Owner;
                }
                else
                {
                    resources = (PdfDictionary)res;
                }

                if (resources == null)
                {
                    resources          = values.Resources.Clone();
                    resources.Document = page.Owner;
                    page.Elements.Add(InheritablePageKeys.Resources, resources);
                }
                else
                {
                    foreach (PdfName name in values.Resources.Elements.KeyNames)
                    {
                        if (!resources.Elements.ContainsKey(name.Value))
                        {
                            PdfItem item = values.Resources.Elements[name];
                            if (item is PdfObject)
                            {
                                item = item.Clone();
                            }
                            resources.Elements.Add(name.ToString(), item);
                        }
                    }
                }
            }

            if (values.MediaBox != null && page.Elements[InheritablePageKeys.MediaBox] == null)
            {
                page.Elements[InheritablePageKeys.MediaBox] = values.MediaBox;
            }

            if (values.CropBox != null && page.Elements[InheritablePageKeys.CropBox] == null)
            {
                page.Elements[InheritablePageKeys.CropBox] = values.CropBox;
            }

            if (values.Rotate != null && page.Elements[InheritablePageKeys.Rotate] == null)
            {
                page.Elements[InheritablePageKeys.Rotate] = values.Rotate;
            }
        }