This is a tricky one as CMAP files are Postscript ones. Some refer to others with a 'usecmap' command
(self, name)
| 96 | return hasher.digest() |
| 97 | |
| 98 | def parseCMAPFile(self, name): |
| 99 | """This is a tricky one as CMAP files are Postscript |
| 100 | ones. Some refer to others with a 'usecmap' |
| 101 | command""" |
| 102 | #started = time.clock() |
| 103 | cmapfile = findCMapFile(name) |
| 104 | # this will CRAWL with the unicode encodings... |
| 105 | rawdata = open(cmapfile, 'r').read() |
| 106 | |
| 107 | self._mapFileHash = self._hash(rawdata) |
| 108 | #if it contains the token 'usecmap', parse the other |
| 109 | #cmap file first.... |
| 110 | usecmap_pos = find(rawdata, 'usecmap') |
| 111 | if usecmap_pos > -1: |
| 112 | #they tell us to look in another file |
| 113 | #for the code space ranges. The one |
| 114 | # to use will be the previous word. |
| 115 | chunk = rawdata[0:usecmap_pos] |
| 116 | words = split(chunk) |
| 117 | otherCMAPName = words[-1] |
| 118 | #print 'referred to another CMAP %s' % otherCMAPName |
| 119 | self.parseCMAPFile(otherCMAPName) |
| 120 | # now continue parsing this, as it may |
| 121 | # override some settings |
| 122 | |
| 123 | |
| 124 | words = split(rawdata) |
| 125 | while words <> []: |
| 126 | if words[0] == 'begincodespacerange': |
| 127 | words = words[1:] |
| 128 | while words[0] <> 'endcodespacerange': |
| 129 | strStart, strEnd, words = words[0], words[1], words[2:] |
| 130 | start = int(strStart[1:-1], 16) |
| 131 | end = int(strEnd[1:-1], 16) |
| 132 | self._codeSpaceRanges.append((start, end),) |
| 133 | elif words[0] == 'beginnotdefrange': |
| 134 | words = words[1:] |
| 135 | while words[0] <> 'endnotdefrange': |
| 136 | strStart, strEnd, strValue = words[0:3] |
| 137 | start = int(strStart[1:-1], 16) |
| 138 | end = int(strEnd[1:-1], 16) |
| 139 | value = int(strValue) |
| 140 | self._notDefRanges.append((start, end, value),) |
| 141 | words = words[3:] |
| 142 | elif words[0] == 'begincidrange': |
| 143 | words = words[1:] |
| 144 | while words[0] <> 'endcidrange': |
| 145 | strStart, strEnd, strValue = words[0:3] |
| 146 | start = int(strStart[1:-1], 16) |
| 147 | end = int(strEnd[1:-1], 16) |
| 148 | value = int(strValue) |
| 149 | # this means that 'start' corresponds to 'value', |
| 150 | # start+1 corresponds to value+1 and so on up |
| 151 | # to end |
| 152 | offset = 0 |
| 153 | while start + offset <= end: |
| 154 | self._cmap[start + offset] = value + offset |
| 155 | offset = offset + 1 |
no test coverage detected