Return the contents of a font file, identified by xref
(doc, xref)
| 19763 | |
| 19764 | |
| 19765 | def JM_get_fontbuffer(doc, xref): |
| 19766 | ''' |
| 19767 | Return the contents of a font file, identified by xref |
| 19768 | ''' |
| 19769 | if xref < 1: |
| 19770 | return |
| 19771 | o = mupdf.pdf_load_object(doc, xref) |
| 19772 | desft = mupdf.pdf_dict_get(o, PDF_NAME('DescendantFonts')) |
| 19773 | if desft.m_internal: |
| 19774 | obj = mupdf.pdf_resolve_indirect(mupdf.pdf_array_get(desft, 0)) |
| 19775 | obj = mupdf.pdf_dict_get(obj, PDF_NAME('FontDescriptor')) |
| 19776 | else: |
| 19777 | obj = mupdf.pdf_dict_get(o, PDF_NAME('FontDescriptor')) |
| 19778 | |
| 19779 | if not obj.m_internal: |
| 19780 | message(f"invalid font - FontDescriptor missing") |
| 19781 | return |
| 19782 | |
| 19783 | o = obj |
| 19784 | |
| 19785 | stream = None |
| 19786 | |
| 19787 | obj = mupdf.pdf_dict_get(o, PDF_NAME('FontFile')) |
| 19788 | if obj.m_internal: |
| 19789 | stream = obj # ext = "pfa" |
| 19790 | |
| 19791 | obj = mupdf.pdf_dict_get(o, PDF_NAME('FontFile2')) |
| 19792 | if obj.m_internal: |
| 19793 | stream = obj # ext = "ttf" |
| 19794 | |
| 19795 | obj = mupdf.pdf_dict_get(o, PDF_NAME('FontFile3')) |
| 19796 | if obj.m_internal: |
| 19797 | stream = obj |
| 19798 | |
| 19799 | obj = mupdf.pdf_dict_get(obj, PDF_NAME('Subtype')) |
| 19800 | if obj.m_internal and not mupdf.pdf_is_name(obj): |
| 19801 | message("invalid font descriptor subtype") |
| 19802 | return |
| 19803 | |
| 19804 | if mupdf.pdf_name_eq(obj, PDF_NAME('Type1C')): |
| 19805 | pass # Prev code did: ext = "cff", but this has no effect. |
| 19806 | elif mupdf.pdf_name_eq(obj, PDF_NAME('CIDFontType0C')): |
| 19807 | pass # Prev code did: ext = "cid", but this has no effect. |
| 19808 | elif mupdf.pdf_name_eq(obj, PDF_NAME('OpenType')): |
| 19809 | pass # Prev code did: ext = "otf", but this has no effect. */ |
| 19810 | else: |
| 19811 | message('warning: unhandled font type {pdf_to_name(ctx, obj)!r}') |
| 19812 | |
| 19813 | if not stream: |
| 19814 | message('warning: unhandled font type') |
| 19815 | return |
| 19816 | |
| 19817 | return mupdf.pdf_load_stream(stream) |
| 19818 | |
| 19819 | |
| 19820 | def JM_get_resource_properties(ref): |
no test coverage detected
searching dependent graphs…