Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
cmap [2020/02/22 17:45] christian [CMap] |
cmap [2020/02/23 13:37] christian [Monster from the wild] |
||
---|---|---|---|
Line 13: | Line 13: | ||
- to unicode (in the '' | - to unicode (in the '' | ||
- | The official standard CMaps are now hosted at GitHub as open source project(([[https:// | + | The official standard CMaps are now hosted at GitHub as open source project(([[https:// |
===== Example ===== | ===== Example ===== | ||
+ | The source of a typical CMap looks like: | ||
+ | {{: | ||
+ | |||
+ | The derived CMap is displayed like this: | ||
+ | {{: | ||
===== Components ===== | ===== Components ===== | ||
Line 28: | Line 33: | ||
* **/ | * **/ | ||
* **/ | * **/ | ||
- | * **/ | + | * **/ |
* **/WMode** Writing direction: 0 for horizontal, 1 for vertical | * **/WMode** Writing direction: 0 for horizontal, 1 for vertical | ||
* **/ | * **/ | ||
Line 103: | 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 129: | 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 CMaps ==== | + | ===== Monster from the wild ===== |
- | Sometimes | + | CMaps are not well defined. Therefore, there are some interesting variations of them in the wild. Here is a small selection |
- | ===== Examples from the wild ===== | + | ==== Mappings outside |
- | single byte mappings in a double byte codespace | + | <code postscript> |
+ | %... | ||
+ | 1 begincodespacerange | ||
+ | < | ||
+ | endcodespacerange | ||
+ | 27 beginbfchar | ||
+ | <20> < | ||
+ | <2E> < | ||
+ | <43> < | ||
+ | <44> < | ||
+ | <45> < | ||
+ | %... | ||
+ | </ | ||
- | using /find instead of / | + | Here are single byte mappings in a double byte codespace which is not correct according to the documentation. |
- | preventing copying | + | This can be seen often. These illegal mappings are collected into the ''# |
+ | ==== Wrong PostScript ==== | ||
+ | |||
+ | On one occasion, I saw a CMap where the PostScript used a non-existing operator (''/ | ||
+ | ==== Prevent copying ==== | ||
+ | |||
+ | <code postscript> | ||
+ | %... | ||
+ | 1 begincodespacerange | ||
+ | < | ||
+ | endcodespacerange | ||
+ | 100 beginbfchar | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | %... | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | %... | ||
+ | </ | ||
+ | |||
+ | 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 byte, which forced me to redesign the object structure to avoid exponential processing time. | ||
+ | |||
+ | Seen in [[https:// | ||
+ | ==== Char to string mapping ==== | ||
+ | |||
+ | <code postscript> | ||
+ | %... | ||
+ | /CMapType 2 def | ||
+ | 1 begincodespacerange | ||
+ | < | ||
+ | endcodespacerange | ||
+ | 1 beginbfchar | ||
+ | < | ||
+ | endbfchar | ||
+ | 1 beginbfchar | ||
+ | < | ||
+ | endbfchar | ||
+ | 50 beginbfrange | ||
+ | < | ||
+ | %... | ||
+ | </ | ||
+ | It looks as if two codes (<24> and <50>) are mapped to a string of 2-byte characters. I have not found anything about this in the documenation. Seen in a PDF with the '' |