Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
cmap [2020/02/23 10:28] christian [General Info] |
cmap [2020/02/23 14:26] christian [Char to string mapping] |
||
---|---|---|---|
Line 108: | Line 108: | ||
endbfrange | endbfrange | ||
</ | </ | ||
- | ===== Decoding ===== | ||
- | The steps of decoding are: | ||
- | * take the first byte from the source and find a 1-byte codespace range which includes it | ||
- | * if found, find a 1-byte mapping for the byte | ||
- | * if found, return the destination code or character | ||
- | * if no mapping found, try to find a notdef mapping and return the code | ||
- | * if not found, see below | ||
- | * if not found, read the next byte and repeat with 2-byte mappings | ||
- | |||
- | When no mapping was found, one has to find out how many of the unmappable bytes have to be read from the source. This is not well defined (or I have not understood it yet). | ||
===== Implementation notes ===== | ===== Implementation notes ===== | ||
Line 134: | Line 124: | ||
* the mappings are ordered. This is not strictly prescribed, but recommended by the specifications. | * the mappings are ordered. This is not strictly prescribed, but recommended by the specifications. | ||
- | ==== Handling malformed | + | ===== Monster from the wild ===== |
+ | |||
+ | CMaps are not well defined. Therefore, there are some interesting variations of them in the wild. Here is a small selection of some issues. | ||
+ | ==== Codespace problems ==== | ||
+ | |||
+ | === Wrong code length === | ||
+ | |||
+ | <code postscript> | ||
+ | %... | ||
+ | 1 begincodespacerange | ||
+ | < | ||
+ | endcodespacerange | ||
+ | 27 beginbfchar | ||
+ | <20> < | ||
+ | <2E> < | ||
+ | <43> < | ||
+ | <44> < | ||
+ | <45> < | ||
+ | %... | ||
+ | </ | ||
+ | |||
+ | Here are single byte mappings in a double byte codespace which is not correct according to the documentation. | ||
+ | |||
+ | This can be seen often. These illegal mappings are collected into the ''# | ||
+ | |||
+ | === Mappings outside the codespace === | ||
+ | |||
+ | <code postscript> | ||
+ | %... | ||
+ | 1 begincodespacerange | ||
+ | < | ||
+ | endcodespacerange | ||
+ | 11 beginbfchar | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | %... | ||
+ | </ | ||
+ | |||
+ | Here, only the first mapping matches the code space. All others fall outside of it, because the second byte has to be between <00> and < | ||
+ | |||
+ | ==== Wrong PostScript ==== | ||
+ | |||
+ | On one occasion, I saw a CMap where the PostScript used a non-existing operator (''/ | ||
+ | ==== Prevent copying | ||
- | Sometimes CMaps define mappings which are not covered by the codespace ranges. This can be seen very often in the wild. These illegal mappings are collected into the ''# | + | <code postscript> |
- | ===== Examples from the wild ===== | + | %... |
+ | 1 begincodespacerange | ||
+ | < | ||
+ | endcodespacerange | ||
+ | 100 beginbfchar | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | %... | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | %... | ||
+ | </ | ||
- | single | + | Here, all codes map to the same character (Substitute character, Ctrl-Z) to prevent extracting the text. Interesting is also the ordering by the second |
- | using /find instead of /findresource | + | Seen in [[https://github.com/ |
+ | ==== Char to string mapping ==== | ||
- | preventing copying | + | <code postscript> |
+ | %... | ||
+ | /CMapType 2 def | ||
+ | 1 begincodespacerange | ||
+ | < | ||
+ | endcodespacerange | ||
+ | 1 beginbfchar | ||
+ | < | ||
+ | endbfchar | ||
+ | 1 beginbfchar | ||
+ | < | ||
+ | endbfchar | ||
+ | 50 beginbfrange | ||
+ | < | ||
+ | %... | ||
+ | </ | ||
+ | Two codes (<24> and <50>) are mapped to a string of 2-byte characters. This is defined by the PDF spec(({{pdf: | ||
+ | Seen in a PDF with the '' |