Add color info to all items of an extended TOC list.
(self, items)
| 3749 | return xref |
| 3750 | |
| 3751 | def _extend_toc_items(self, items): |
| 3752 | """Add color info to all items of an extended TOC list.""" |
| 3753 | if self.is_closed: |
| 3754 | raise ValueError("document closed") |
| 3755 | if g_use_extra: |
| 3756 | return extra.Document_extend_toc_items( self.this, items) |
| 3757 | pdf = _as_pdf_document(self) |
| 3758 | zoom = "zoom" |
| 3759 | bold = "bold" |
| 3760 | italic = "italic" |
| 3761 | collapse = "collapse" |
| 3762 | |
| 3763 | root = mupdf.pdf_dict_get(mupdf.pdf_trailer(pdf), PDF_NAME('Root')) |
| 3764 | if not root.m_internal: |
| 3765 | return |
| 3766 | olroot = mupdf.pdf_dict_get(root, PDF_NAME('Outlines')) |
| 3767 | if not olroot.m_internal: |
| 3768 | return |
| 3769 | first = mupdf.pdf_dict_get(olroot, PDF_NAME('First')) |
| 3770 | if not first.m_internal: |
| 3771 | return |
| 3772 | xrefs = [] |
| 3773 | xrefs = JM_outline_xrefs(first, xrefs) |
| 3774 | n = len(xrefs) |
| 3775 | m = len(items) |
| 3776 | if not n: |
| 3777 | return |
| 3778 | if n != m: |
| 3779 | raise IndexError( "internal error finding outline xrefs") |
| 3780 | |
| 3781 | # update all TOC item dictionaries |
| 3782 | for i in range(n): |
| 3783 | xref = int(xrefs[i]) |
| 3784 | item = items[i] |
| 3785 | itemdict = item[3] |
| 3786 | if not isinstance(itemdict, dict): |
| 3787 | raise ValueError( "need non-simple TOC format") |
| 3788 | itemdict[dictkey_xref] = xrefs[i] |
| 3789 | bm = mupdf.pdf_load_object(pdf, xref) |
| 3790 | flags = mupdf.pdf_to_int( mupdf.pdf_dict_get(bm, PDF_NAME('F'))) |
| 3791 | if flags == 1: |
| 3792 | itemdict[italic] = True |
| 3793 | elif flags == 2: |
| 3794 | itemdict[bold] = True |
| 3795 | elif flags == 3: |
| 3796 | itemdict[italic] = True |
| 3797 | itemdict[bold] = True |
| 3798 | count = mupdf.pdf_to_int( mupdf.pdf_dict_get(bm, PDF_NAME('Count'))) |
| 3799 | if count < 0: |
| 3800 | itemdict[collapse] = True |
| 3801 | elif count > 0: |
| 3802 | itemdict[collapse] = False |
| 3803 | col = mupdf.pdf_dict_get(bm, PDF_NAME('C')) |
| 3804 | if mupdf.pdf_is_array(col) and mupdf.pdf_array_len(col) == 3: |
| 3805 | color = ( |
| 3806 | mupdf.pdf_to_real(mupdf.pdf_array_get(col, 0)), |
| 3807 | mupdf.pdf_to_real(mupdf.pdf_array_get(col, 1)), |
| 3808 | mupdf.pdf_to_real(mupdf.pdf_array_get(col, 2)), |
no test coverage detected