Generate a name prefix to tag a font as subset. We use a random generator to select 6 upper case ASCII characters. The prefixed name must be put in the font xref as the "/BaseFont" value and in the FontDescriptor object as the '/FontName' value.
(new_xref)
| 7519 | return None |
| 7520 | |
| 7521 | def set_subset_fontname(new_xref): |
| 7522 | """Generate a name prefix to tag a font as subset. |
| 7523 | |
| 7524 | We use a random generator to select 6 upper case ASCII characters. |
| 7525 | The prefixed name must be put in the font xref as the "/BaseFont" value |
| 7526 | and in the FontDescriptor object as the '/FontName' value. |
| 7527 | """ |
| 7528 | # The following generates a prefix like 'ABCDEF+' |
| 7529 | import random |
| 7530 | import string |
| 7531 | prefix = "".join(random.choices(tuple(string.ascii_uppercase), k=6)) + "+" |
| 7532 | font_str = doc.xref_object(new_xref, compressed=True) |
| 7533 | font_str = font_str.replace("/BaseFont/", "/BaseFont/" + prefix) |
| 7534 | df = doc.xref_get_key(new_xref, "DescendantFonts") |
| 7535 | if df[0] == "array": |
| 7536 | df_xref = int(df[1][1:-1].replace("0 R", "")) |
| 7537 | fd = doc.xref_get_key(df_xref, "FontDescriptor") |
| 7538 | if fd[0] == "xref": |
| 7539 | fd_xref = int(fd[1].replace("0 R", "")) |
| 7540 | fd_str = doc.xref_object(fd_xref, compressed=True) |
| 7541 | fd_str = fd_str.replace("/FontName/", "/FontName/" + prefix) |
| 7542 | doc.update_object(fd_xref, fd_str) |
| 7543 | doc.update_object(new_xref, font_str) |
| 7544 | |
| 7545 | def build_subset(buffer, unc_set, gid_set): |
| 7546 | """Build font subset using fontTools. |
nothing calls this directly
no test coverage detected