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:48] christian [CMap] |
cmap [2020/02/23 11:16] christian |
||
---|---|---|---|
Line 16: | Line 16: | ||
===== 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 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 ''# | 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 ''# | ||
- | ===== Examples from the wild ===== | + | |
+ | ==== Mappings outside | ||
single byte mappings in a double byte codespace | single byte mappings in a double byte codespace | ||
- | using /find instead of / | + | ==== Wrong PostScript ==== |
- | preventing copying | + | using /find instead of / |
+ | See [[postscript# | ||
+ | ==== 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 '' |