From: <jo...@us...> - 2008-12-08 12:26:58
|
Revision: 6505 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6505&view=rev Author: jouni Date: 2008-12-08 12:26:53 +0000 (Mon, 08 Dec 2008) Log Message: ----------- Fix SymmetricalLogLocator bug that caused platform-specific behavior Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/scale.py trunk/matplotlib/lib/matplotlib/type1font.py Modified: trunk/matplotlib/lib/matplotlib/scale.py =================================================================== --- trunk/matplotlib/lib/matplotlib/scale.py 2008-12-07 20:52:13 UTC (rev 6504) +++ trunk/matplotlib/lib/matplotlib/scale.py 2008-12-08 12:26:53 UTC (rev 6505) @@ -301,7 +301,8 @@ self._linadjust = (np.log(linthresh) / self._log_base) / linthresh def transform(self, a): - sign = np.sign(np.asarray(a)) + a = np.asarray(a) + sign = np.sign(a) masked = ma.masked_inside(a, -self.linthresh, self.linthresh, copy=False) log = sign * ma.log(np.abs(masked)) / self._log_base if masked.mask.any(): Modified: trunk/matplotlib/lib/matplotlib/type1font.py =================================================================== --- trunk/matplotlib/lib/matplotlib/type1font.py 2008-12-07 20:52:13 UTC (rev 6504) +++ trunk/matplotlib/lib/matplotlib/type1font.py 2008-12-08 12:26:53 UTC (rev 6505) @@ -17,6 +17,7 @@ Systems Incorporated, third printing, v1.1, 1993. ISBN 0-201-57044-0. """ +import re import struct class Type1Font(object): @@ -28,6 +29,7 @@ finally: file.close() self.parts = self._split(data) + self._parse() def _read(self, file): rawdata = file.read() @@ -97,8 +99,86 @@ return data[:len1], binary, data[idx:] + _whitespace = re.compile(r'[\0\t\r\014\n ]+') + _delim = re.compile(r'[()<>[]{}/%]') + _token = re.compile(r'/{0,2}[^]\0\t\r\v\n ()<>{}/%[]+') + _comment = re.compile(r'%[^\r\n\v]*') + _instring = re.compile(r'[()\\]') + def _parse(self): + """ + A very limited kind of parsing to find the Encoding of the + font. + """ + def tokens(text): + """ + Yield pairs (position, token), ignoring comments and + whitespace. Numbers count as tokens. + """ + pos = 0 + while pos < len(text): + match = self._comment.match(text[pos:]) or self._whitespace.match(text[pos:]) + if match: + pos += match.end() + elif text[pos] == '(': + start = pos + pos += 1 + depth = 1 + while depth: + match = self._instring.search(text[pos:]) + if match is None: return + if match.group() == '(': + depth += 1 + pos += 1 + elif match.group() == ')': + depth -= 1 + pos += 1 + else: + pos += 2 + yield (start, text[start:pos]) + elif text[pos:pos+2] in ('<<', '>>'): + yield (pos, text[pos:pos+2]) + pos += 2 + elif text[pos] == '<': + start = pos + pos += text[pos:].index('>') + yield (start, text[start:pos]) + else: + match = self._token.match(text[pos:]) + if match: + yield (pos, match.group()) + pos += match.end() + else: + yield (pos, text[pos]) + pos += 1 + + enc_starts, enc_ends = None, None + state = 0 + # State transitions: + # 0 -> /Encoding -> 1 + # 1 -> StandardEncoding -> 2 -> def -> (ends) + # 1 -> dup -> 4 -> put -> 5 + # 5 -> dup -> 4 -> put -> 5 + # 5 -> def -> (ends) + for pos,token in tokens(self.parts[0]): + if state == 0 and token == '/Encoding': + enc_starts = pos + state = 1 + elif state == 1 and token == 'StandardEncoding': + state = 2 + elif state in (2,5) and token == 'def': + enc_ends = pos+3 + break + elif state in (1,5) and token == 'dup': + state = 4 + elif state == 4 and token == 'put': + state = 5 + self.enc_starts, self.enc_ends = enc_starts, enc_ends + + if __name__ == '__main__': import sys font = Type1Font(sys.argv[1]) parts = font.parts print len(parts[0]), len(parts[1]), len(parts[2]) + print parts[0][font.enc_starts:font.enc_ends] + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |