hpgl_parser.py

changeset 20
de60b63b2275
parent 19
42af82fdb8bb
equal deleted inserted replaced
19:42af82fdb8bb 20:de60b63b2275
67 self.plot_symbols(values[1:]) 67 self.plot_symbols(values[1:])
68 if self.pen_state == "down": 68 if self.pen_state == "down":
69 self.plot_lines(values) 69 self.plot_lines(values)
70 self.pos = values[-1] 70 self.pos = values[-1]
71 71
72 def plot_string(self, s):
73 pass
74
72 def get_window_for_paper(self): 75 def get_window_for_paper(self):
73 return 0,100,0,100 76 return 0,100,0,100
74 def get_scaling_points_for_paper(self): 77 def get_scaling_points_for_paper(self):
75 return 0,100,0,100 78 return 0,100,0,100
76 79
80 def plot_lines(self, points): 83 def plot_lines(self, points):
81 pass 84 pass
82 85
83 # HPGL-related methods 86 # HPGL-related methods
84 def ESC(self): 87 def ESC(self):
85 print "ESC" 88 #print "ESC"
86 self.idx += 1 89 self.idx += 1
87 90
88 def OE(self): 91 def OE(self):
89 """ Output Error """ 92 """ Output Error """
90 pass 93 pass
107 110
108 111
109 def DF(self): 112 def DF(self):
110 """ Default """ 113 """ Default """
111 self.pen = 0 114 self.pen = 0
115 self.pen_width = 1 # 1/300 inch
112 self.pos = 0,0 116 self.pos = 0,0
113 self.char_set = "std" 117 self.char_set = "std"
114 self.plot_mode = 'absolute' 118 self.plot_mode = 'absolute'
115 self.char_direction = 1,0 119 self.char_direction = 1,0
116 self.line_type = 0 # 'solid' 120 self.line_type = 0 # 'solid'
343 self.str_terminator = values[0] 347 self.str_terminator = values[0]
344 348
345 def LB(self): 349 def LB(self):
346 """ Character Plot """ 350 """ Character Plot """
347 values = self.extract_string() 351 values = self.extract_string()
348 # TODO 352 self.plot_string(values)
349 353 x, y = self.pos
354 values = values.split('\n')
355 if self.char_size == "absolute":
356 x += len(values[-1]) * self.char_width *1016/2.54
357 y += (len(values)-1) * self.char_height *1016/2.54
358 else:
359 x0, x1, y0, y1 = self.scale
360 dx = x1-x0
361 dy = y1-y0
362 x += len(values[-1]) * self.char_width / 100.0 * dx
363 y += (len(values)-1) * self.char_height / 100.0 * dy
364
365 #print "LB pos[%s] %s -> %s"%(repr(values), self.pos, (x,y))
366 self.pos = [x, y]
367
368 def get_char_size(self):
369 if self.char_size == "absolute":
370 x = self.char_width *1016/2.54
371 y = self.char_height *1016/2.54
372 else:
373 x0, x1, y0, y1 = self.scale
374 dx = x1-x0
375 dy = y1-y0
376 x = self.char_width / 100.0 * dx
377 y = self.char_height / 100.0 * dy
378 return x, y
379
350 def DI(self): 380 def DI(self):
351 """ Absolute Direction """ 381 """ Absolute Direction """
352 values = self.extract_value() 382 values = self.extract_value()
353 if len(values) == 0: 383 if len(values) == 0:
354 self.char_direction = 1.0, 0.0 384 self.char_direction = 1.0, 0.0
367 def CP(self): 397 def CP(self):
368 """ Character Plot """ 398 """ Character Plot """
369 values = self.extract_value() 399 values = self.extract_value()
370 # TODO 400 # TODO
371 if len(values) == 0: 401 if len(values) == 0:
372 values = 0, -1 402 values = 0, 1
373 #if len(values) == 2: 403 x, y = self.pos
374 # self.pos = 404 if self.char_size == "absolute":
405 x += values[0] * self.char_width *1016/2.54
406 y += values[1] * self.char_height *1016/2.54
407 else:
408 x0, x1, y0, y1 = self.scale
409 dx = x1-x0
410 dy = y1-y0
411 x += values[0] * self.char_width / 100.0 * dx
412 y += values[1] * self.char_height / 100.0 * dy
413 #print "CB pos[%s] %s -> %s"%(repr(values), self.pos, (x,y))
414 self.pos = [x, y]
375 415
376 def SI(self): 416 def SI(self):
377 """ Set Absolute Character Size """ 417 """ Set Absolute Character Size """
378 values = self.extract_value() 418 values = self.extract_value()
379 self.char_size = "absolute" 419 self.char_size = "absolute"
380 if len(values) == 0: 420 if len(values) == 0:
381 self.char_width = 0.1879 421 self.char_width = 0.1879 # cm
382 self.char_height = 0.2690 422 self.char_height = 0.2690 # cm
383 elif len(values) == 2: 423 elif len(values) == 2:
384 self.char_width, self.char_height = values 424 self.char_width, self.char_height = values
385 425
386 def SR(self): 426 def SR(self):
387 """ Set Relative Character Size """ 427 """ Set Relative Character Size """
388 values = self.extract_value() 428 values = self.extract_value()
389 self.char_size = "relative" 429 self.char_size = "relative"
390 if len(values) == 0: 430 if len(values) == 0:
391 self.char_width = 0.75 431 self.char_width = 0.75 # percentage
392 self.char_height = 1.5 432 self.char_height = 1.5 # id
393 elif len(values) == 2: 433 elif len(values) == 2:
394 self.char_width, self.char_height = values 434 self.char_width, self.char_height = values
395 435
396 def SL(self): 436 def SL(self):
397 """ Character Slant """ 437 """ Character Slant """

mercurial