Get a font by xref. Returns a tuple or dictionary.
(self, xref=0, info_only=0, named=None)
| 4549 | return xref |
| 4550 | |
| 4551 | def extract_font(self, xref=0, info_only=0, named=None): |
| 4552 | ''' |
| 4553 | Get a font by xref. Returns a tuple or dictionary. |
| 4554 | ''' |
| 4555 | #log( '{=xref info_only}') |
| 4556 | pdf = _as_pdf_document(self) |
| 4557 | obj = mupdf.pdf_load_object(pdf, xref) |
| 4558 | type_ = mupdf.pdf_dict_get(obj, PDF_NAME('Type')) |
| 4559 | subtype = mupdf.pdf_dict_get(obj, PDF_NAME('Subtype')) |
| 4560 | if (mupdf.pdf_name_eq(type_, PDF_NAME('Font')) |
| 4561 | and not mupdf.pdf_to_name( subtype).startswith('CIDFontType') |
| 4562 | ): |
| 4563 | basefont = mupdf.pdf_dict_get(obj, PDF_NAME('BaseFont')) |
| 4564 | if not basefont.m_internal or mupdf.pdf_is_null(basefont): |
| 4565 | bname = mupdf.pdf_dict_get(obj, PDF_NAME('Name')) |
| 4566 | else: |
| 4567 | bname = basefont |
| 4568 | ext = JM_get_fontextension(pdf, xref) |
| 4569 | if ext != 'n/a' and not info_only: |
| 4570 | buffer_ = JM_get_fontbuffer(pdf, xref) |
| 4571 | bytes_ = JM_BinFromBuffer(buffer_) |
| 4572 | else: |
| 4573 | bytes_ = b'' |
| 4574 | if not named: |
| 4575 | rc = ( |
| 4576 | JM_EscapeStrFromStr(mupdf.pdf_to_name(bname)), |
| 4577 | JM_UnicodeFromStr(ext), |
| 4578 | JM_UnicodeFromStr(mupdf.pdf_to_name(subtype)), |
| 4579 | bytes_, |
| 4580 | ) |
| 4581 | else: |
| 4582 | rc = { |
| 4583 | dictkey_name: JM_EscapeStrFromStr(mupdf.pdf_to_name(bname)), |
| 4584 | dictkey_ext: JM_UnicodeFromStr(ext), |
| 4585 | dictkey_type: JM_UnicodeFromStr(mupdf.pdf_to_name(subtype)), |
| 4586 | dictkey_content: bytes_, |
| 4587 | } |
| 4588 | else: |
| 4589 | if not named: |
| 4590 | rc = '', '', '', b'' |
| 4591 | else: |
| 4592 | rc = { |
| 4593 | dictkey_name: '', |
| 4594 | dictkey_ext: '', |
| 4595 | dictkey_type: '', |
| 4596 | dictkey_content: b'', |
| 4597 | } |
| 4598 | return rc |
| 4599 | |
| 4600 | def extract_image(self, xref): |
| 4601 | """Get image by xref. Returns a dictionary.""" |