hpgl_parser.py

Fri, 11 Jan 2008 18:50:46 +0100

author
David Douard <david.douard@logilab.fr>
date
Fri, 11 Jan 2008 18:50:46 +0100
changeset 22
b2f4646161be
parent 20
de60b63b2275
permissions
-rw-r--r--

Begin of a HPGL plotter application (PyQt4)

18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 import re
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 import numpy
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 vsplitter = re.compile('[ ,]')
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 vextractor = re.compile('(?P<value>[^;\n\r\aA-DF-Za-df-z]*?)(?P<terminator>[;\n\r\a]+)', re.S+re.M)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 class HPGLParser(object):
19
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
10 def __init__(self, data=None):
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
11 self.str_terminator = chr(0x03)
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
12 self.IN()
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
13 if data:
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
14 self.parse(data)
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
15
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
16 def parse(self, data):
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 self.data = data
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18 self.idx = 0
19
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
19 self.IN()
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20 while self.idx<len(data):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 while data[self.idx] in [';','\n','\r', '\a', ' ']:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22 self.idx += 1
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 if data[self.idx] == chr(0x03):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 self.ESC()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25 else:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 cmd = data[self.idx: self.idx+2]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 self.idx += 2
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 getattr(self, cmd)()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 while self.idx<len(data) and data[self.idx] in [';','\n','\r', '\a', ' ']:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 self.idx += 1
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 def user_to_abs(self, pos):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33 """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 converts a position (x, y) given in user units to absolute
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 units
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37 return pos #TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
39 def extract_value(self, raw=False):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 m = vextractor.match(self.data[self.idx:])
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
41 if m:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
42 val = m.group("value")
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43 self.idx = self.idx + len(val) + len(m.group("terminator"))
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
44 val = vsplitter.split(val)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
45 if not raw:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
46 val = [eval(x) for x in val if x.strip()]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
47 return val
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
48 return []
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
49
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
50 def extract_string(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
51 idx2 = self.data.find(self.str_terminator, self.idx)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
52 val = self.data[self.idx: idx2]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
53 self.idx = idx2+1
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
54 return val
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
55
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
56 def polyline(self, values):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
57 if (len(values)%2) == 1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
58 # this is a syntax error in the HPGL data
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
59 values = values[:-1]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
60 values = numpy.array(values).reshape(-1, 2)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
61 # TODO use scaling
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
62 # do plots
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
63 values = numpy.r_[[self.pos], values] #add self.pos as 1st value
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
64 if self.plot_mode == 'relative':
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
65 values = values.cumsum(axis=0)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
66 if self.symbol_mode:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
67 self.plot_symbols(values[1:])
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
68 if self.pen_state == "down":
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
69 self.plot_lines(values)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
70 self.pos = values[-1]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
71
20
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
72 def plot_string(self, s):
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
73 pass
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
74
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
75 def get_window_for_paper(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
76 return 0,100,0,100
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
77 def get_scaling_points_for_paper(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
78 return 0,100,0,100
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
79
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
80 # effective plot methods; to be defined in subclasses (backends)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
81 def plot_symbols(self, points):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
82 pass
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
83 def plot_lines(self, points):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
84 pass
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
85
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
86 # HPGL-related methods
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
87 def ESC(self):
20
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
88 #print "ESC"
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
89 self.idx += 1
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
90
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
91 def OE(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
92 """ Output Error """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
93 pass
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
94
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
95 def EC(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
96 """? what's this """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
97 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
98
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
99 def OO(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
100 """idem"""
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
101 pass
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
102
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
103 def OP(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
104 """idem"""
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
105 pass
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
106
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
107 def VS(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
108 """idem"""
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
109 pass
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
110
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
111
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
112 def DF(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
113 """ Default """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
114 self.pen = 0
20
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
115 self.pen_width = 1 # 1/300 inch
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
116 self.pos = 0,0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
117 self.char_set = "std"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
118 self.plot_mode = 'absolute'
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
119 self.char_direction = 1,0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
120 self.line_type = 0 # 'solid'
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
121 self.pattern_len = 4 #percentage
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
122 self.window = self.get_window_for_paper()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
123 self.char_size = 0.75, 1.5 #percentages
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
124 self.symbol_mode = False
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
125 self.tick_len = 0.5, 0.5 # %
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
126 self.std_char_set = 0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
127 self.alt_char_set = 0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
128 self.selected_char_set = 0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
129 self.char_slant = 0 # degrees
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
130 self.scale = None
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
131 self.str_terminator = chr(0x03)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
132 self.chord_ang = 5 #degrees
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
133 self.fill_type = 'bidirectionnal', 1
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
134 self.fill_distance = 1 # %
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
135 self.fill_slant = 0 # degrees
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
136 self.pen_thickness = 0.3 # mm
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
137
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
138 def IN(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
139 """ Initialize """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
140 self.DF()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
141 self.pen_state = "up"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
142 self.rotation = 0 #degrees
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
143 self.scaling_points = self.get_scaling_points_for_paper()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
144
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
145 def IP(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
146 """ Input Scale Point"""
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
147 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
148 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
149 self.scaling_points = self.get_scaling_points_for_paper()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
150 elif len(values) == 2:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
151 p1x, p1y, p2x, p2y = self.scaling_points
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
152 dx, dy = p2x-p1x, p2y-p1y
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
153 x, y = values
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
154 self.scaling = (x, y, x+dx, y+dy)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
155 elif len(values) == 4:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
156 self.values = tuple(values)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
157
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
158 def SC(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
159 """ Scale """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
160 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
161 if len(values) == 4:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
162 self.scale = tuple(values)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
163 else:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
164 self.scale = None
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
165
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
166 def IW(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
167 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
168 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
169 self.window = self.get_window_for_paper()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
170 elif len(value) == 4:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
171 self.window = tuple(values)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
172
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
173 def RO(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
174 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
175 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
176 self.rotation = 0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
177 elif len(values) == 1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
178 self.rotation = values[0]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
179
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
180 def PG(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
181 pass
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
182
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
183 def PU(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
184 """ Pen Up"""
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
185 self.pen_state = "up"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
186 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
187 self.polyline(values)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
188
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
189 def PD(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
190 """ Pen Down """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
191 self.pen_state = "down"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
192 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
193 self.polyline(values)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
194
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
195 def PA(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
196 """ Plot Absolute """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
197 self.plot_mode = "absolute"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
198 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
199 self.polyline(values)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
200
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
201 def PR(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
202 """ Plot Relative """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
203 self.plot_mode = "relative"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
204 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
205 self.polyline(values)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
206
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
207 def AA(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
208 """ Arc Absolute """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
209 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
210 if len(values) in [3, 4]:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
211 x, y, qc = values[:3]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
212 if len(values)==4:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
213 qd = values[-1]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
214 else:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
215 qd = self.chord_ang
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
216 # TODO : plot arc
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
217 print "plotting an arc"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
218 def AR(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
219 """ Arc Relative """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
220 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
221 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
222
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
223 def CI(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
224 """ Circle Plot"""
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
225 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
226 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
227
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
228 def EA(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
229 """Edge Rectangle Absolute"""
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
230 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
231 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
232
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
233 def ER(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
234 """Edge Rectangle Relative"""
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
235 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
236 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
237
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
238 def EW(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
239 """ Edge Wedge """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
240 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
241 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
242
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
243 def RA(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
244 """ Fill Rectangle Absolute """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
245 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
246 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
247
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
248 def RR(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
249 """ Fill Rectangle Relative """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
250 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
251 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
252
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
253 def WG(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
254 """ Fill Wedge """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
255 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
256 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
257
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
258 def FT(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
259 """ Fill Type """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
260 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
261 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
262
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
263 def LT(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
264 """ Line Type """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
265 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
266
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
267 if len(values)==0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
268 self.line_type = 0 #'solid'
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
269 else:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
270 self.line_type = values[0]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
271 if len(values)>1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
272 self.pattern_len = values[1]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
273
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
274 def PW(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
275 """ Pen Width """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
276 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
277 if len(values) == 1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
278 self.pen_thickness = values[0]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
279
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
280 def SM(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
281 """ Symbol Mode """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
282 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
283 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
284 self.symbol_mode = False
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
285 elif len(values) == 1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
286 self.symbol_mode = values[0]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
287
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
288 def SP(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
289 """ Select Pen """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
290 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
291 if len(values) == 1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
292 self.pen = values[0]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
293
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
294 def TL(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
295 """ Tick Len """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
296 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
297 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
298
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
299 def XT(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
300 """ X-axis Tick """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
301 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
302 print "X ticks"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
303
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
304 def YT(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
305 """ X-axis Tick """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
306 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
307 print "Y ticks"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
308
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
309 def PT(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
310 """ Pen Thickness Select """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
311 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
312 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
313 self.pen_thickness = 0.3
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
314 elif len(values) == 1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
315 self.pen_thickness = values[0]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
316
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
317 def CS(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
318 """ Standard Character Set """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
319 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
320 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
321 self.std_char_set = 0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
322 elif len(values) == 1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
323 self.std_char_set = values[0]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
324
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
325 def CA(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
326 """ Alternate Character Set """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
327 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
328 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
329 self.alt_char_set = 0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
330 elif len(values) == 1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
331 self.alt_char_set = values[0]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
332
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
333 def SS(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
334 """ Select Standard Character Set """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
335 self.char_set = "std"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
336
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
337 def SA(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
338 """ Select Alternate Character Set """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
339 self.char_set = "alt"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
340
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
341 def DT(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
342 """ Define Label Terminator """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
343 values = self.extract_value(raw=True)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
344 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
345 self.str_terminator = chr(0x03)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
346 elif len(values) == 1:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
347 self.str_terminator = values[0]
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
348
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
349 def LB(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
350 """ Character Plot """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
351 values = self.extract_string()
20
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
352 self.plot_string(values)
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
353 x, y = self.pos
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
354 values = values.split('\n')
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
355 if self.char_size == "absolute":
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
356 x += len(values[-1]) * self.char_width *1016/2.54
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
357 y += (len(values)-1) * self.char_height *1016/2.54
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
358 else:
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
359 x0, x1, y0, y1 = self.scale
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
360 dx = x1-x0
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
361 dy = y1-y0
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
362 x += len(values[-1]) * self.char_width / 100.0 * dx
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
363 y += (len(values)-1) * self.char_height / 100.0 * dy
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
364
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
365 #print "LB pos[%s] %s -> %s"%(repr(values), self.pos, (x,y))
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
366 self.pos = [x, y]
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
367
20
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
368 def get_char_size(self):
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
369 if self.char_size == "absolute":
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
370 x = self.char_width *1016/2.54
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
371 y = self.char_height *1016/2.54
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
372 else:
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
373 x0, x1, y0, y1 = self.scale
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
374 dx = x1-x0
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
375 dy = y1-y0
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
376 x = self.char_width / 100.0 * dx
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
377 y = self.char_height / 100.0 * dy
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
378 return x, y
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
379
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
380 def DI(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
381 """ Absolute Direction """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
382 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
383 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
384 self.char_direction = 1.0, 0.0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
385 elif len(values) == 2:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
386 self.char_direction = values
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
387
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
388 def DR(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
389 """ Relative Direction """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
390 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
391 if len(values) == 0:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
392 self.char_direction = 1.0, 0.0
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
393 elif len(values) == 2:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
394 # TODO : compute as percentages
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
395 self.char_direction = values
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
396
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
397 def CP(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
398 """ Character Plot """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
399 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
400 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
401 if len(values) == 0:
20
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
402 values = 0, 1
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
403 x, y = self.pos
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
404 if self.char_size == "absolute":
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
405 x += values[0] * self.char_width *1016/2.54
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
406 y += values[1] * self.char_height *1016/2.54
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
407 else:
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
408 x0, x1, y0, y1 = self.scale
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
409 dx = x1-x0
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
410 dy = y1-y0
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
411 x += values[0] * self.char_width / 100.0 * dx
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
412 y += values[1] * self.char_height / 100.0 * dy
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
413 #print "CB pos[%s] %s -> %s"%(repr(values), self.pos, (x,y))
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
414 self.pos = [x, y]
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
415
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
416 def SI(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
417 """ Set Absolute Character Size """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
418 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
419 self.char_size = "absolute"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
420 if len(values) == 0:
20
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
421 self.char_width = 0.1879 # cm
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
422 self.char_height = 0.2690 # cm
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
423 elif len(values) == 2:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
424 self.char_width, self.char_height = values
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
425
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
426 def SR(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
427 """ Set Relative Character Size """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
428 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
429 self.char_size = "relative"
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
430 if len(values) == 0:
20
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
431 self.char_width = 0.75 # percentage
de60b63b2275 improved hpgl parser : plot strings
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
432 self.char_height = 1.5 # id
18
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
433 elif len(values) == 2:
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
434 self.char_width, self.char_height = values
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
435
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
436 def SL(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
437 """ Character Slant """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
438 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
439 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
440
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
441 def UC(self):
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
442 """ User Defined Character """
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
443 values = self.extract_value()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
444 # TODO
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
445
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
446 if __name__ == '__main__':
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
447 import sys
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
448 data = open(sys.argv[1]).read()
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
449
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
450 p = HPGLParser(data)
c691b040e8c9 added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
451

mercurial