Exemplo n.º 1
0
        /// <summary>
        /// Create a new <see cref="CatalogDictionary"/>.
        /// </summary>
        internal Catalog(DictionaryToken catalogDictionary, DictionaryToken pagesDictionary,
                         PageTreeNode pageTree)
        {
            CatalogDictionary = catalogDictionary ?? throw new ArgumentNullException(nameof(catalogDictionary));
            PagesDictionary   = pagesDictionary ?? throw new ArgumentNullException(nameof(pagesDictionary));
            PageTree          = pageTree ?? throw new ArgumentNullException(nameof(pageTree));

            if (!pageTree.IsRoot)
            {
                throw new ArgumentException("Page tree must be the root page tree node.", nameof(pageTree));
            }

            var byNumber = new Dictionary <int, PageTreeNode>();

            PopulatePageByNumberDictionary(pageTree, byNumber);
            pagesByNumber = byNumber;
        }
Exemplo n.º 2
0
        private static void PopulatePageByNumberDictionary(PageTreeNode node, Dictionary <int, PageTreeNode> result)
        {
            if (node.IsPage)
            {
                if (!node.PageNumber.HasValue)
                {
                    throw new InvalidOperationException($"Node was page but did not have page number: {node}.");
                }

                result[node.PageNumber.Value] = node;
                return;
            }

            foreach (var child in node.Children)
            {
                PopulatePageByNumberDictionary(child, result);
            }
        }