[Skencil-commits] r732 - in skencil/branches/skencil-0.6/src/Plugins: Filters Filters/Lib Objects Objects/Lib/multilinetext
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Sep 22 23:54:40 CEST 2010
Author: igor_n
Date: 2010-09-22 23:54:38 +0200 (Wed, 22 Sep 2010)
New Revision: 732
Modified:
skencil/branches/skencil-0.6/src/Plugins/Filters/Lib/drawfile.py
skencil/branches/skencil-0.6/src/Plugins/Filters/Lib/spritefile.py
skencil/branches/skencil-0.6/src/Plugins/Filters/ailoader.py
skencil/branches/skencil-0.6/src/Plugins/Filters/aisaver.py
skencil/branches/skencil-0.6/src/Plugins/Filters/cgmloader.py
skencil/branches/skencil-0.6/src/Plugins/Filters/cgmsaver.py
skencil/branches/skencil-0.6/src/Plugins/Filters/cmxloader.py
skencil/branches/skencil-0.6/src/Plugins/Filters/pdfgensaver.py
skencil/branches/skencil-0.6/src/Plugins/Filters/skloader.py
skencil/branches/skencil-0.6/src/Plugins/Filters/sksaver.py
skencil/branches/skencil-0.6/src/Plugins/Filters/svgloader.py
skencil/branches/skencil-0.6/src/Plugins/Filters/wmfloader.py
skencil/branches/skencil-0.6/src/Plugins/Filters/wmfsaver.py
skencil/branches/skencil-0.6/src/Plugins/Filters/xfigloader.py
skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/TextEditor.py
skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/chunker.py
skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/iterator.py
skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/styletext.py
skencil/branches/skencil-0.6/src/Plugins/Objects/lcdtext.py
skencil/branches/skencil-0.6/src/Plugins/Objects/multilinetext.py
skencil/branches/skencil-0.6/src/Plugins/Objects/regpoly.py
Log:
mixed indents are removed
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/Lib/drawfile.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/Lib/drawfile.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/Lib/drawfile.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -67,18 +67,18 @@
self.new()
def number(self, size, n):
-
+
# Little endian writing
-
+
s = ""
-
+
while size > 0:
i = n % 256
s = s + chr(i)
# n = n / 256
n = n >> 8
size = size - 1
-
+
return s
def str2num(self, size, s):
@@ -249,25 +249,25 @@
if pad != 0: pad = 4 - pad
data = self.number(4, 1) + \
- self.number(4, len(self.text) + 1 + pad + 24 + 28) + \
- self.number(4, self.x1) + \
- self.number(4, self.y1) + \
- self.number(4, self.x2) + \
- self.number(4, self.y2) + \
- self.number(1, self.foreground[0]) + \
- self.number(1, self.foreground[1]) + \
- self.number(1, self.foreground[2]) + \
- self.number(1, self.foreground[3]) + \
- self.number(1, self.background[0]) + \
- self.number(1, self.background[1]) + \
- self.number(1, self.background[2]) + \
- self.number(1, self.background[3]) + \
- self.number(4, self.style) + \
- self.number(4, self.size[0]) + \
- self.number(4, self.size[1]) + \
- self.number(4, self.baseline[0]) + \
- self.number(4, self.baseline[1]) + \
- self.text + '\000'
+ self.number(4, len(self.text) + 1 + pad + 24 + 28) + \
+ self.number(4, self.x1) + \
+ self.number(4, self.y1) + \
+ self.number(4, self.x2) + \
+ self.number(4, self.y2) + \
+ self.number(1, self.foreground[0]) + \
+ self.number(1, self.foreground[1]) + \
+ self.number(1, self.foreground[2]) + \
+ self.number(1, self.foreground[3]) + \
+ self.number(1, self.background[0]) + \
+ self.number(1, self.background[1]) + \
+ self.number(1, self.background[2]) + \
+ self.number(1, self.background[3]) + \
+ self.number(4, self.style) + \
+ self.number(4, self.size[0]) + \
+ self.number(4, self.size[1]) + \
+ self.number(4, self.baseline[0]) + \
+ self.number(4, self.baseline[1]) + \
+ self.text + '\000'
data = data + pad*'\000'
@@ -397,26 +397,26 @@
# Write the colours and width
data = self.number(1,self.fill[0]) + \
- self.number(1,self.fill[1]) + \
- self.number(1,self.fill[2]) + \
- self.number(1,self.fill[3]) + \
- self.number(1,self.outline[0]) + \
- self.number(1,self.outline[1]) + \
- self.number(1,self.outline[2]) + \
- self.number(1,self.outline[3]) + \
- self.number(4,self.width)
+ self.number(1,self.fill[1]) + \
+ self.number(1,self.fill[2]) + \
+ self.number(1,self.fill[3]) + \
+ self.number(1,self.outline[0]) + \
+ self.number(1,self.outline[1]) + \
+ self.number(1,self.outline[2]) + \
+ self.number(1,self.outline[3]) + \
+ self.number(4,self.width)
if hasattr(self, 'pattern'):
self.style['dash pattern'] == 'present'
# Write the path style
style = self.join.index(self.style['join']) | \
- (self.end_cap.index(self.style['end cap']) << 2) | \
- (self.start_cap.index(self.style['start cap']) << 4) | \
- (self.winding.index(self.style['winding rule']) << 6) | \
- (self.dashed.index(self.style['dash pattern']) << 7) | \
- (self.style['triangle cap width'] << 16) | \
- (self.style['triangle cap length'] << 24)
+ (self.end_cap.index(self.style['end cap']) << 2) | \
+ (self.start_cap.index(self.style['start cap']) << 4) | \
+ (self.winding.index(self.style['winding rule']) << 6) | \
+ (self.dashed.index(self.style['dash pattern']) << 7) | \
+ (self.style['triangle cap width'] << 16) | \
+ (self.style['triangle cap length'] << 24)
data = data + self.number(4, style)
@@ -445,11 +445,11 @@
# Write the header
data = self.number(4, 2) + \
- self.number(4, len(data) + 24) + \
- self.number(4, self.x1) + \
- self.number(4, self.y1) + \
- self.number(4, self.x2) + \
- self.number(4, self.y2) + data
+ self.number(4, len(data) + 24) + \
+ self.number(4, self.x1) + \
+ self.number(4, self.y1) + \
+ self.number(4, self.x2) + \
+ self.number(4, self.y2) + data
return data
@@ -481,7 +481,7 @@
# Construct a reasonable sprite block from the data supplied
# One sprite and offset to sprite
sprdata = self.number(4, 1) + \
- self.number(4, 0x10)
+ self.number(4, 0x10)
free = self.str2num(4, data[0:4]) + 0x10
sprdata = sprdata + self.number(4, free) + data
@@ -542,11 +542,11 @@
data = self.name + data
data = self.number(4,6) + \
- self.number(4,len(data)+24) + \
- self.number(4,self.x1) + \
- self.number(4,self.y1) + \
- self.number(4,self.x2) + \
- self.number(4,self.y2) + data
+ self.number(4,len(data)+24) + \
+ self.number(4,self.x1) + \
+ self.number(4,self.y1) + \
+ self.number(4,self.x2) + \
+ self.number(4,self.y2) + data
return data
@@ -580,11 +580,11 @@
data = data + self.data # add extra data
data = self.number(4,7) + \
- self.number(4,len(data)+24) + \
- self.number(4,self.x1) + \
- self.number(4,self.y1) + \
- self.number(4,self.x2) + \
- self.number(4,self.y2) + data
+ self.number(4,len(data)+24) + \
+ self.number(4,self.x1) + \
+ self.number(4,self.y1) + \
+ self.number(4,self.x2) + \
+ self.number(4,self.y2) + data
return data
@@ -1029,22 +1029,22 @@
data = data + c.output()
data = data + self.number(4, 0) + \
- self.number(4, 0) + \
- self.number(4, 0) + \
- self.number(4, self.foreground) + \
- self.number(4, self.background) + \
- self.text + '\000'
+ self.number(4, 0) + \
+ self.number(4, 0) + \
+ self.number(4, self.foreground) + \
+ self.number(4, self.background) + \
+ self.text + '\000'
excess = len(data) % 4
if excess != 0:
data = data + ((4 - excess)*'\000')
data = self.number(4,9) + \
- self.number(4,len(data)+24) + \
- self.number(4,self.x1) + \
- self.number(4,self.y1) + \
- self.number(4,self.x2) + \
- self.number(4,self.y2) + data
+ self.number(4,len(data)+24) + \
+ self.number(4,self.x1) + \
+ self.number(4,self.y1) + \
+ self.number(4,self.x2) + \
+ self.number(4,self.y2) + data
return data
@@ -1065,11 +1065,11 @@
def output(self):
data = self.number(4,10) + \
- self.number(4,24) + \
- self.number(4,self.x1) + \
- self.number(4,self.y1) + \
- self.number(4,self.x2) + \
- self.number(4,self.y2)
+ self.number(4,24) + \
+ self.number(4,self.x1) + \
+ self.number(4,self.y1) + \
+ self.number(4,self.x2) + \
+ self.number(4,self.y2)
return data
@@ -1088,7 +1088,7 @@
self.options = {}
self.options['paper size'] = 'A%i' % \
- ((self.str2num(4, data[0:4]) >> 8) - 1)
+ ((self.str2num(4, data[0:4]) >> 8) - 1)
paper = self.str2num(4, data[4:8])
@@ -1230,8 +1230,8 @@
data = ''
data = data + self.unknown + \
- self.number(4, self.dpi_x) + \
- self.number(4, self.dpi_y)
+ self.number(4, self.dpi_x) + \
+ self.number(4, self.dpi_y)
for value in self.transform:
data = data + self.number(4, value)
@@ -1298,18 +1298,18 @@
self.y2 = -2147483648
def number(self, size, n):
-
+
# Little endian writing
-
+
s = ""
-
+
while size > 0:
i = n % 256
s = s + chr(i)
# n = n / 256
n = n >> 8
size = size - 1
-
+
return s
@@ -1529,14 +1529,14 @@
# Write file header
file.write('Draw')
-
+
# Write version stamps
file.write(self.number(4, self.version['major']))
file.write(self.number(4, self.version['minor']))
# Write creator information
file.write(self.creator[:12])
-
+
# Write bounding box
file.write(self.number(4, self.x1))
file.write(self.number(4, self.y1))
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/Lib/spritefile.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/Lib/spritefile.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/Lib/spritefile.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -62,20 +62,20 @@
# Mode information dictionary (log2bpp, x scale, y scale)
self.mode_info = {
- 0: (0, 1, 2), 1: (1, 2, 2), 2: (2, 3, 2), 3: (1, 1, 2),
- 4: (0, 2, 2), 5: (1, 3, 2), 6: (1, 2, 2), 7: (2, 2, 2),
- 8: (1, 1, 2), 9: (2, 2, 2), 10: (3, 3, 2), 11: (1, 1, 2),
- 12: (2, 1, 2), 13: (3, 2, 2), 14: (2, 1, 2), 15: (3, 1, 2),
- 16: (2, 1, 2), 17: (2, 1, 2), 18: (0, 1, 1), 19: (1, 1, 1),
- 20: (2, 1, 1), 21: (3, 1, 1), 22: (2, 0, 1), 23: (0, 1, 1),
- 24: (3, 1, 2), 25: (0, 1, 1), 26: (1, 1, 1), 27: (2, 1, 1),
- 28: (3, 1, 1), 29: (0, 1, 1), 30: (1, 1, 1), 31: (2, 1, 1),
- 32: (3, 1, 1), 33: (0, 1, 2), 34: (1, 1, 2), 35: (2, 1, 2),
- 36: (3, 1, 2), 37: (0, 1, 2), 38: (1, 1, 2), 39: (2, 1, 2),
- 40: (3, 1, 2), 41: (0, 1, 2), 42: (1, 1, 2), 43: (2, 1, 2),
- 44: (0, 1, 2), 45: (1, 1, 2), 46: (2, 1, 2), 47: (3, 2, 2),
- 48: (2, 2, 1), 49: (3, 2, 1)
- }
+ 0: (0, 1, 2), 1: (1, 2, 2), 2: (2, 3, 2), 3: (1, 1, 2),
+ 4: (0, 2, 2), 5: (1, 3, 2), 6: (1, 2, 2), 7: (2, 2, 2),
+ 8: (1, 1, 2), 9: (2, 2, 2), 10: (3, 3, 2), 11: (1, 1, 2),
+ 12: (2, 1, 2), 13: (3, 2, 2), 14: (2, 1, 2), 15: (3, 1, 2),
+ 16: (2, 1, 2), 17: (2, 1, 2), 18: (0, 1, 1), 19: (1, 1, 1),
+ 20: (2, 1, 1), 21: (3, 1, 1), 22: (2, 0, 1), 23: (0, 1, 1),
+ 24: (3, 1, 2), 25: (0, 1, 1), 26: (1, 1, 1), 27: (2, 1, 1),
+ 28: (3, 1, 1), 29: (0, 1, 1), 30: (1, 1, 1), 31: (2, 1, 1),
+ 32: (3, 1, 1), 33: (0, 1, 2), 34: (1, 1, 2), 35: (2, 1, 2),
+ 36: (3, 1, 2), 37: (0, 1, 2), 38: (1, 1, 2), 39: (2, 1, 2),
+ 40: (3, 1, 2), 41: (0, 1, 2), 42: (1, 1, 2), 43: (2, 1, 2),
+ 44: (0, 1, 2), 45: (1, 1, 2), 46: (2, 1, 2), 47: (3, 2, 2),
+ 48: (2, 2, 1), 49: (3, 2, 1)
+ }
#self.palette16 = {
# 0: (0xff, 0xff, 0xff), 1 : (0xdd, 0xdd, 0xdd),
@@ -94,20 +94,20 @@
# }
self.palette16 = [
- (0xff, 0xff, 0xff), (0xdd, 0xdd, 0xdd),
- (0xbb, 0xbb, 0xbb), (0x99, 0x99, 0x99),
- (0x77, 0x77, 0x77), (0x55, 0x55, 0x55),
- (0x33, 0x33, 0x33), (0x00, 0x00, 0x00),
- (0x00, 0x44, 0x99), (0xee, 0xee, 0x00),
- (0x00, 0xcc, 0x00), (0xdd, 0x00, 0x00),
- (0xee, 0xee, 0xbb), (0x55, 0x88, 0x00),
- (0xff, 0xbb, 0x00), (0x00, 0xbb, 0xff)
- ]
+ (0xff, 0xff, 0xff), (0xdd, 0xdd, 0xdd),
+ (0xbb, 0xbb, 0xbb), (0x99, 0x99, 0x99),
+ (0x77, 0x77, 0x77), (0x55, 0x55, 0x55),
+ (0x33, 0x33, 0x33), (0x00, 0x00, 0x00),
+ (0x00, 0x44, 0x99), (0xee, 0xee, 0x00),
+ (0x00, 0xcc, 0x00), (0xdd, 0x00, 0x00),
+ (0xee, 0xee, 0xbb), (0x55, 0x88, 0x00),
+ (0xff, 0xbb, 0x00), (0x00, 0xbb, 0xff)
+ ]
self.palette4 = [
- (0xff, 0xff, 0xff), (0xbb, 0xbb, 0xbb),
- (0x77, 0x77, 0x77), (0x00, 0x00, 0x00)
- ]
+ (0xff, 0xff, 0xff), (0xbb, 0xbb, 0xbb),
+ (0x77, 0x77, 0x77), (0x00, 0x00, 0x00)
+ ]
if file != None:
self.read(file)
@@ -119,18 +119,18 @@
self.sprites = {}
def number(self, size, n):
-
+
# Little endian writing
-
+
s = ""
-
+
while size > 0:
i = n % 256
s = s + chr(i)
# n = n / 256
n = n >> 8
size = size - 1
-
+
return s
@@ -183,9 +183,9 @@
value = ord(file.read(1))
red = ((value & 0x10) >> 1) | (value & 7)
green = ((value & 0x40) >> 3) | \
- ((value & 0x20) >> 3) | (value & 3)
+ ((value & 0x20) >> 3) | (value & 3)
blue = ((value & 0x80) >> 4) | \
- ((value & 8) >> 1) | (value & 3)
+ ((value & 8) >> 1) | (value & 3)
red = int( red * scale8 )
green = int( green * scale8 )
blue = int( blue * scale8 )
@@ -434,7 +434,7 @@
bpp = (mode >> 27)
if bpp == 0:
-
+
mode = mode & 0x3f
# Information on commonly used modes
@@ -513,7 +513,7 @@
# supplied for the first 16 colours
red = (((j + i) & 0x10) >> 1) | (entry1[0] >> 4)
green = (((j + i) & 0x40) >> 3) | \
- (((j + i) & 0x20) >> 3) | (entry1[1] >> 4)
+ (((j + i) & 0x20) >> 3) | (entry1[1] >> 4)
blue = (((j + i) & 0x80) >> 4) | (entry1[2] >> 4)
red = int( red * scale8 )
green = int( green * scale8 )
@@ -533,7 +533,7 @@
red = (((j + i) & 0x10) >> 1) | (entry1[0] >> 4)
green = (((j + i) & 0x40) >> 3) | \
- (((j + i) & 0x20) >> 3) | (entry1[1] >> 4)
+ (((j + i) & 0x20) >> 3) | (entry1[1] >> 4)
blue = (((j + i) & 0x80) >> 4) | (entry1[2] >> 4)
red = int( red * scale8 )
green = int( green * scale8 )
@@ -548,7 +548,7 @@
data['palette'] = palette
width = (h_words * (32 >> log2bpp)) - (first_bit_used >> log2bpp) - \
- ((31-last_bit_used) >> log2bpp)
+ ((31-last_bit_used) >> log2bpp)
height = v_lines
data['width'] = width
@@ -686,8 +686,8 @@
# Convert the components to the relevant form
half_word = int(r/scale16) | \
- (int(g/scale16) << 5) | \
- (int(b/scale16) << 10)
+ (int(g/scale16) << 5) | \
+ (int(b/scale16) << 10)
sprite_word = sprite_word | (half_word << sprite_ptr)
sprite_ptr = sprite_ptr + 16
@@ -712,9 +712,9 @@
blue = int(b/scale8)
index = ((red & 0x8) << 1) | (red & 0x4) | \
- ((green & 0x8) << 3) | ((green & 0x4) << 3) | \
- ((blue & 0x8) << 4) | ((blue & 0x4) << 1) | \
- int((red + green + blue) / 15.0)
+ ((green & 0x8) << 3) | ((green & 0x4) << 3) | \
+ ((blue & 0x8) << 4) | ((blue & 0x4) << 1) | \
+ int((red + green + blue) / 15.0)
# Store the contents in the sprite word
sprite_word = sprite_word | (index << sprite_ptr)
@@ -856,21 +856,21 @@
# Write the sprite header minus the offset to the next sprite
header = name[:12] + (12 - len(name))*'\0' + \
- self.number(4, data['h_words'] - 1) + \
- self.number(4, data['v_lines'] - 1) + \
- self.number(4, data['first bit']) + \
- self.number(4, data['last bit']) + \
- self.number(4, 16 + len(palette))
+ self.number(4, data['h_words'] - 1) + \
+ self.number(4, data['v_lines'] - 1) + \
+ self.number(4, data['first bit']) + \
+ self.number(4, data['last bit']) + \
+ self.number(4, 16 + len(palette))
if mask != '':
# Offset to mask
header = header + \
- self.number(4, 12 + len(palette) + len(sprite))
+ self.number(4, 12 + len(palette) + len(sprite))
else:
# Point to sprite instead
header = header + \
- self.number(4, 12 + len(palette) )
+ self.number(4, 12 + len(palette) )
# Determine the screen mode from the bpp, xdpi and ydpi
if data['bpp'] == 1:
@@ -890,7 +890,7 @@
'Invalid number of bits per pixel in sprite.'
mode = (log2bpp << 27) | (int(180/data['dpi x'] << 1)) | \
- (int(180/data['dpi y']) << 14)
+ (int(180/data['dpi y']) << 14)
header = header + self.number(4, mode)
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/ailoader.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/ailoader.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/ailoader.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -167,7 +167,7 @@
array = [(0.0, color), (1.0, color)]
elif array[-1][0] < 1:
array.append((1.0, array[-1][1]))
-
+
return array
# arrays to convert AI join and cap to Sketch's join and cap. In AI
@@ -199,9 +199,9 @@
self.reencoder = encoding.Reencoder(self.encoding,
encoding.iso_latin_1)
return self.reencoder(text)
-
+
grow_join = [5.240843064, 0.5, 0.5]
grow_cap = [None, 0.5, 0.5, 0.70710678]
@@ -210,46 +210,46 @@
grow_join[style.line_join]))
-
+
class AILoader(GenericLoader):
format_name = format_name
functions = {"C": 'curveto',
- "c": 'curveto_smooth',
- "V": 'curveto_v',
- "v": 'curveto_v_smooth',
- "Y": 'curveto_y',
- "y": 'curveto_y_smooth',
- "m": 'moveto',
- "l": 'lineto',
- "L": 'lineto',
- "w": 'set_line_width',
- "j": 'set_line_join',
- "J": 'set_line_cap',
+ "c": 'curveto_smooth',
+ "V": 'curveto_v',
+ "v": 'curveto_v_smooth',
+ "Y": 'curveto_y',
+ "y": 'curveto_y_smooth',
+ "m": 'moveto',
+ "l": 'lineto',
+ "L": 'lineto',
+ "w": 'set_line_width',
+ "j": 'set_line_join',
+ "J": 'set_line_cap',
"d": 'set_line_dash',
- "G": 'set_line_gray',
- "K": 'set_line_cmyk',
- "XA": 'set_line_rgb',
- "X": 'set_line_cmyk_custom',
- "XX": 'set_line_generic_custom',
+ "G": 'set_line_gray',
+ "K": 'set_line_cmyk',
+ "XA": 'set_line_rgb',
+ "X": 'set_line_cmyk_custom',
+ "XX": 'set_line_generic_custom',
"P": 'set_line_pattern',
- "g": 'set_fill_gray',
- "k": 'set_fill_cmyk',
- "Xa": 'set_fill_rgb',
- "x": 'set_fill_cmyk_custom',
- "Xx": 'set_fill_generic_custom',
+ "g": 'set_fill_gray',
+ "k": 'set_fill_cmyk',
+ "Xa": 'set_fill_rgb',
+ "x": 'set_fill_cmyk_custom',
+ "Xx": 'set_fill_generic_custom',
"p": 'set_fill_pattern',
- "F": 'fill',
- "f": 'fill_close',
- "S": 'stroke',
- "s": 'stroke_close',
- "B": 'fill_stroke',
- "b": 'fill_stroke_close',
- "N": 'invisible', # an invisible open path
- "n": 'invisible_close', # a invisible closed path
- "u": 'begin_group',
- "U": 'end_group',
+ "F": 'fill',
+ "f": 'fill_close',
+ "S": 'stroke',
+ "s": 'stroke_close',
+ "B": 'fill_stroke',
+ "b": 'fill_stroke_close',
+ "N": 'invisible', # an invisible open path
+ "n": 'invisible_close', # a invisible closed path
+ "u": 'begin_group',
+ "U": 'end_group',
"*u": 'begin_compound_path',
"*U": 'end_compound_path',
"*": 'guide',
@@ -300,15 +300,15 @@
self.guess_continuity = 1
self.path = CreatePath()
self.compound_path = None # If compound_path is None, we're
- # outside of a compound path,
- # otherwise it's a possibly empty list
- # of paths
+ # outside of a compound path,
+ # otherwise it's a possibly empty list
+ # of paths
self.compound_render = ''
self.stack = []
self.gradients = {}
self.in_gradient_instance = 0
self.gradient_geo = None # set to a true value after Bg, and set
- # to false by make_gradient_pattern
+ # to false by make_gradient_pattern
self.gradient_rect = None
self.in_palette = 0
self.in_text = 0
@@ -329,19 +329,19 @@
self.format_version = 0.0
def __del__(self):
- pass
+ pass
def warn(self, level, *args, **kw):
- message = apply(warn, (level,) + args, kw)
- self.add_message(message)
+ message = apply(warn, (level,) + args, kw)
+ self.add_message(message)
def get_compiled(self):
- funclist = {}
- for char, name in self.functions.items():
+ funclist = {}
+ for char, name in self.functions.items():
method = getattr(self, name)
argc = method.im_func.func_code.co_argcount - 1
- funclist[char] = (method, argc)
- return funclist
+ funclist[char] = (method, argc)
+ return funclist
def pop(self):
value = self.stack[-1]
@@ -379,33 +379,33 @@
self.stack.append(array)
def convert_color(self, color_spec):
- c = apply(CreateRGBColor, color_spec)
- return c
+ c = apply(CreateRGBColor, color_spec)
+ return c
def set_line_join(self, join):
- self.line_join = _ai_join[join]
+ self.line_join = _ai_join[join]
def set_line_cap(self, cap):
- self.line_cap = _ai_cap[cap]
+ self.line_cap = _ai_cap[cap]
def set_line_width(self, w):
- self.line_width = w
+ self.line_width = w
def set_line_dash(self, array, phase):
self.line_dashes = tuple(array)
def set_line_gray(self, k):
- self.line_color = CreateRGBColor(k, k, k)
+ self.line_color = CreateRGBColor(k, k, k)
def set_line_cmyk(self, c, m, y, k):
- self.line_color = CreateCMYKColor(c, m, y, k)
-
+ self.line_color = CreateCMYKColor(c, m, y, k)
+
def set_line_rgb(self, r, g, b):
- self.line_color = CreateRGBColor(r, g, b)
+ self.line_color = CreateRGBColor(r, g, b)
def set_line_cmyk_custom(self, c, m, y, k, name, tint):
- self.line_color = cmyk_custom_color(c, m, y, k, tint)
-
+ self.line_color = cmyk_custom_color(c, m, y, k, tint)
+
def set_line_generic_custom(self, name, tint, type):
if type == 0:
# cmyk
@@ -421,19 +421,19 @@
if not self.in_palette:
self.add_message(_("Vector patterns not supported. Using black"))
self.line_color = StandardColors.black
-
+
def set_fill_gray(self, k):
- self.fill_color = CreateRGBColor(k, k, k)
+ self.fill_color = CreateRGBColor(k, k, k)
def set_fill_cmyk(self, c, m, y, k):
- self.fill_color = CreateCMYKColor(c, m, y, k)
-
+ self.fill_color = CreateCMYKColor(c, m, y, k)
+
def set_fill_rgb(self, r, g, b):
- self.fill_color = CreateRGBColor(r, g, b)
+ self.fill_color = CreateRGBColor(r, g, b)
def set_fill_cmyk_custom(self, c, m, y, k, name, tint):
- self.fill_color = cmyk_custom_color(c, m, y, k, tint)
-
+ self.fill_color = cmyk_custom_color(c, m, y, k, tint)
+
def set_fill_generic_custom(self, name, tint, type):
if type == 0:
# cmyk
@@ -459,7 +459,7 @@
style.line_dashes = self.line_dashes
def lsnone(self):
- self.style.line_pattern = EmptyPattern
+ self.style.line_pattern = EmptyPattern
def fs(self):
if self.gradient_geo:
@@ -692,53 +692,53 @@
else:
self.fill()
self.in_gradient_instance = 0
-
+
# Path construction
def moveto(self, x, y):
- self.cur_x = x
- self.cur_y = y
- self.path.AppendLine(x, y)
+ self.cur_x = x
+ self.cur_y = y
+ self.path.AppendLine(x, y)
def lineto(self, x, y):
- self.cur_x = x
- self.cur_y = y
+ self.cur_x = x
+ self.cur_y = y
self.path.AppendLine(x, y)
def curveto(self, x1, y1, x2, y2, x3, y3):
- self.path.AppendBezier(x1, y1, x2, y2, x3, y3)
- self.cur_x = x3
- self.cur_y = y3
+ self.path.AppendBezier(x1, y1, x2, y2, x3, y3)
+ self.cur_x = x3
+ self.cur_y = y3
def curveto_smooth(self, x1, y1, x2, y2, x3, y3):
- self.path.AppendBezier(x1, y1, x2, y2, x3, y3, ContSmooth)
- self.cur_x = x3
- self.cur_y = y3
+ self.path.AppendBezier(x1, y1, x2, y2, x3, y3, ContSmooth)
+ self.cur_x = x3
+ self.cur_y = y3
def curveto_v(self, x2, y2, x3, y3):
- # current point and first control point are identical
- self.path.AppendBezier(self.cur_x, self.cur_y, x2, y2, x3, y3)
- self.cur_x = x3
- self.cur_y = y3
+ # current point and first control point are identical
+ self.path.AppendBezier(self.cur_x, self.cur_y, x2, y2, x3, y3)
+ self.cur_x = x3
+ self.cur_y = y3
def curveto_v_smooth(self, x2, y2, x3, y3):
- # current point and first control point are identical
- self.path.AppendBezier(self.cur_x, self.cur_y, x2, y2, x3, y3,
- ContSmooth)
- self.cur_x = x3
- self.cur_y = y3
+ # current point and first control point are identical
+ self.path.AppendBezier(self.cur_x, self.cur_y, x2, y2, x3, y3,
+ ContSmooth)
+ self.cur_x = x3
+ self.cur_y = y3
def curveto_y(self, x1, y1, x3, y3):
- # endpoint and last controlpoint are identical
- self.path.AppendBezier(x1, y1, x3, y3, x3, y3)
- self.cur_x = x3
- self.cur_y = y3
+ # endpoint and last controlpoint are identical
+ self.path.AppendBezier(x1, y1, x3, y3, x3, y3)
+ self.cur_x = x3
+ self.cur_y = y3
def curveto_y_smooth(self, x1, y1, x3, y3):
- # endpoint and last controlpoint are identical
- self.path.AppendBezier(x1, y1, x3, y3, x3, y3, ContSmooth)
- self.cur_x = x3
- self.cur_y = y3
+ # endpoint and last controlpoint are identical
+ self.path.AppendBezier(x1, y1, x3, y3, x3, y3, ContSmooth)
+ self.cur_x = x3
+ self.cur_y = y3
def bezier_close(self):
if self.path.len > 1:
@@ -774,9 +774,9 @@
self.gradient_rect = None
getattr(self, self.compound_render)()
GenericLoader.bezier(self, paths = paths)
-
+
# Groups
-
+
def begin_group(self):
if self.compound_path is None:
# a normal group
@@ -811,15 +811,15 @@
# Layers
def begin_layer(self):
- self.layer(_("Layer %d") % (len(self.composite_items) + 1))
+ self.layer(_("Layer %d") % (len(self.composite_items) + 1))
def begin_ai_layer(self):
if self.format_version >= 4.0:
visible, preview, enabled, printing, dimmed, unused, has_mlm,\
- color, red, green, blue, unused, unused = self.pop_multi(13)
+ color, red, green, blue, unused, unused = self.pop_multi(13)
else:
visible, preview, enabled, printing, dimmed, has_mlm, \
- color, red, green, blue = self.pop_multi(10)
+ color, red, green, blue = self.pop_multi(10)
color = CreateRGBColor(red / 255.0, green / 255.0, blue / 255.0)
self.layer_kw_args = {'printable': printing,
'visible': visible,
@@ -1018,15 +1018,15 @@
mode == 'CMYK'
image = Image.fromstring(mode, (width, height), data, 'raw', mode)
self.image(image, apply(Trafo, tuple(trafo)))
-
+
#
def append_object(self, object):
- if self.composite_class == Document \
- and object.__class__ != Layer:
- self.begin_layer()
- self.composite_items.append(object)
- self.object = object
+ if self.composite_class == Document \
+ and object.__class__ != Layer:
+ self.begin_layer()
+ self.composite_items.append(object)
+ self.object = object
#
#
@@ -1092,9 +1092,9 @@
self.tokenizer.ai_pseudo_comments = 1
self.tokenizer.ai_dsc = 1
next = self.tokenizer.next
-
- self.document()
+ self.document()
+
value = self.read_prolog()
while 1:
@@ -1134,9 +1134,9 @@
except:
warn_tb(INTERNAL, 'AILoader: error')
- self.end_all()
- self.object.load_Completed()
+ self.end_all()
+ self.object.load_Completed()
for obj in self.guides:
self.object.guide_layer.Insert(obj, None)
- return self.object
+ return self.object
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/aisaver.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/aisaver.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/aisaver.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -40,8 +40,8 @@
y = 1.0 - color.blue
k = min(c, m, y)
return c - k, m - k, y - k, k
-
+
ps_join = (0, 1, 2)
ps_cap = (None, 0, 1, 2)
@@ -68,8 +68,8 @@
self.line_cap = None
self.line_dashes = None
self.fill_color = None
-
+
def analyze(self, object):
if object.has_fill:
fill = object.properties.fill_pattern
@@ -104,7 +104,7 @@
write('%%Creator: Adobe Illustrator exported by Skencil\n')
llx, lly, urx, ury = document.BoundingRect()
write('%%%%BoundingBox: %d %d %d %d\n' % (floor(llx), floor(lly),
- ceil(urx), ceil(ury)))
+ ceil(urx), ceil(ury)))
write('%%%%HiResBoundingBox: %g %g %g %g\n' % (llx, lly, urx, ury))
write('%AI5_FileFormat 3\n') # necessary for gradients
write('%%EndComments\n')
@@ -112,7 +112,7 @@
# Setup section
write('%%BeginSetup\n')
-
+
if self.gradients:
write('%d Bn\n' % len(self.gradients))
for name, type, gradient in self.gradients.values():
@@ -360,10 +360,10 @@
self.PolyBezier(object.Paths(), object.Properties(),
object.bounding_rect)
-
+
def save(document, file, filename, options = {}):
#options['layers_as_groups'] = 1
saver = AISaver(file, filename, document, options)
saver.Save()
saver.close()
-
+
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/cgmloader.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/cgmloader.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/cgmloader.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -144,8 +144,8 @@
0x5460: 'asf',
0x6020: 'ESCAPE',
}
-
+
cp = copy.deepcopy
fntlst = map(lambda l: l[0], Sketch.Graphics.font.fontlist)
@@ -176,8 +176,8 @@
'CharterBT' : ('Bernhard Modern BT' , 'Blackletter' , 'Brush' ,
'GeometricSlabSerif' , 'Humanist' , 'Onyx')
}
-
-
+
+
class cgminfo:
def __init__(self):
pass
@@ -672,11 +672,11 @@
# 0x2040:
def colrmode(self, size):
reff.color.mode = self.Enum()
-
+
# 0x2060:
def linewidthmode(self, size):
reff.line.widthmode = self.Enum()
-
+
# 0x2080:
def markersizemode(self, size):
reff.marker.sizemode = self.Enum()
@@ -701,13 +701,13 @@
sc = reff.scale.metric * 72 / 25.4
self.Scale = sc
self.trafo = Scale(sign(width)*sc , sign(height)*sc)(Translation(-left , -bottom))
-
+
# 0x20c0:
def vdcext(self, size):
ll = self.Pnt()
ur = self.Pnt()
reff.vdc.extend = (ll,ur)
-
+
# 0x20e0:
def backcolr(self, size):
self.getcol()
@@ -766,13 +766,13 @@
style.line_dashes = reff.line.dashtable[reff.line.type - 1]
self.prop_stack.AddStyle(style)
-
+
# 0x4020:
def LINE(self, size):
path = self.Path(size)
self.setlinestyle()
self.bezier((path,))
-
+
# 0x4040:
def DISJTLINE(self, size):
path = ()
@@ -800,8 +800,8 @@
self.style.font_size = reff.text.height * self.Scale
self.style.fill_pattern = SolidPattern(apply(CreateRGBColor , reff.text.color))
O = text.SimpleText(text = S, trafo = T(B),
- halign = text.ALIGN_LEFT, valign = text.ALIGN_BASE,
- properties = self.get_prop_stack())
+ halign = text.ALIGN_LEFT, valign = text.ALIGN_BASE,
+ properties = self.get_prop_stack())
self.append_object(O)
def setfillstyle(self):
@@ -940,7 +940,7 @@
T = transform_base(centre , cdp1 , cdp2)
self.setfillstyle()
apply(self.ellipse , T.coeff())
-
+
# 0x4240:
def ELLIPARC(self, size):
centre = self.trafo(self.Pnt())
@@ -1063,8 +1063,8 @@
size = head & 0x001f
hdsz = 2
if size == 31:
- size = self.u16()
- hdsz = 4
+ size = self.u16()
+ hdsz = 4
pdsz = ((size + 1) / 2) * 2
self._print(20 , '%4x at %5d) %5d(%5d): %4x: %s' , head, pos, size, pdsz, Id, CGM_ID.get(Id, ''))
if hasattr(self, CGM_ID.get(Id, '')):
@@ -1077,7 +1077,7 @@
Class = Id >> 12
Elem = (Id & 0x0fff) >> 5
self._print(2, '*** unimplemented: %4x; class = %d, element = %2d %s'
- , Id , Class , Elem, name)
+ , Id , Class , Elem, name)
pos = pos + hdsz + pdsz
if tell() < pos:
self.file.read(pos - tell())
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/cgmsaver.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/cgmsaver.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/cgmsaver.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -32,7 +32,7 @@
import os.path
from Sketch import Scale, Translation, Bezier, CreateRGBColor, EmptyPattern, \
- Point
+ Point
import Sketch.warn
@@ -60,7 +60,7 @@
P7 = (P4 + P5) / 2
P8 = (P5 + P6) / 2
P9 = (P7 + P8) / 2
-
+
B = P3 - P0
S = P9 - P0
C1 = P1 - P0
@@ -89,7 +89,7 @@
N = B.normalized()
if (C1 * N) < -EPS or (C2 * N) > EPS or cr(C1,B)*cr(C2,B) < 0 \
- or abs(cr(N,S)) > EPS:
+ or abs(cr(N,S)) > EPS:
return FlattenPath(P0, P4, P7, P9) + FlattenPath(P9, P8, P6, P3)
else:
return (P9, P3)
@@ -133,9 +133,9 @@
self.set = self.set >> 1
if msg != "":
msg = "The design you tried to save in CGM Version 1 format\n" + \
- "hit some limitations\n\n" + msg
+ "hit some limitations\n\n" + msg
Sketch.warn.warn(Sketch.warn.USER , msg)
-
+
class CGMSaver:
def __init__(self, file, pathname, options):
@@ -147,7 +147,7 @@
self.Msg = Warnings()
def w(self, str):
- self.file.write(str)
+ self.file.write(str)
def pack(self , *args):
self.file.write(apply(struct.pack , args))
@@ -170,8 +170,8 @@
if 4 * lng < 31:
self.pack("!H" , Id | 4 * lng)
else:
- self.pack("!H" , Id | 31)
- self.pack("!H" , 4 * lng)
+ self.pack("!H" , Id | 31)
+ self.pack("!H" , 4 * lng)
fmt = '!' + `lng` + "i"
args = (fmt,) + tuple(seq)
apply(self.pack , args)
@@ -181,8 +181,8 @@
green = rndtoint(255 * color.green)
blue = rndtoint(255 * color.blue)
self.pack("!HBBBB" , Id , red , green , blue , 0)
-
+
def close(self):
self.Msg.show()
self.file.close()
@@ -207,7 +207,7 @@
self.pack("!Hi" , 0x5064 , rndtoint(self.Scale * Props.line_width))
# Line color
self.putcol(0x5083 , Props.line_pattern.Color())
-
+
def FillStyle(self, Props):
line_pattern = Props.line_pattern
fill_pattern = Props.fill_pattern
@@ -286,8 +286,8 @@
if size < 31:
self.pack("!H" , 0x4100 | size)
else:
- self.pack("!H" , 0x4100 | 31)
- self.pack("!H" , size)
+ self.pack("!H" , 0x4100 | 31)
+ self.pack("!H" , size)
for lst in set:
while lst <> ():
Arg = tuple(map(rndtoint , lst[:2]))
@@ -310,20 +310,20 @@
P1 = trf(Point(0,0))
P2 = trf(Point(1,1))
self.putlongseq(0x4160 , map(rndtoint , tuple(self.trafo(P1)) \
- + tuple(self.trafo(P2))))
+ + tuple(self.trafo(P2))))
else:
self.PolyBezier(rct.Paths(), rct.Properties())
def Ellipse(self, ell):
trf = ell.trafo
if (abs(trf.m11 - trf.m22) < 0.001 and abs(trf.m21 + trf.m12) < 0.001) \
- or (abs(trf.m11 + trf.m22) < 0.001 and abs(trf.m21 - trf.m12) < 0.001):
+ or (abs(trf.m11 + trf.m22) < 0.001 and abs(trf.m21 - trf.m12) < 0.001):
if ell.start_angle == ell.end_angle:
self.FillStyle(ell.Properties())
C = trf(Point(0,0))
R = sqrt(trf.m11 * trf.m11 + trf.m12 * trf.m12)
self.putlongseq(0x4180 , map(rndtoint , tuple(self.trafo(C)) \
- + (R * self.Scale,)))
+ + (R * self.Scale,)))
else:
C = trf(Point(0,0))
S = Point(cos(ell.start_angle) , sin(ell.start_angle))
@@ -336,10 +336,10 @@
S = 1000000 * S / abs(S)
E = 1000000 * E / abs(E)
if ell.arc_type == 0 \
- and ell.Properties().fill_pattern == EmptyPattern:
+ and ell.Properties().fill_pattern == EmptyPattern:
self.LineStyle(ell.Properties())
self.putlongseq(0x41e0 , map(rndtoint , tuple(self.trafo(C)) \
- + tuple(S) + tuple(E) + (R * self.Scale,)))
+ + tuple(S) + tuple(E) + (R * self.Scale,)))
else:
#self.PolyBezier(ell.Paths(), ell.Properties())
self.FillStyle(ell.Properties())
@@ -348,7 +348,7 @@
else:
cp = 2 - ell.arc_type
Args = ["!H7iH" , 0x4200 + 30] + map(rndtoint , tuple(self.trafo(C)) \
- + tuple(S) + tuple(E) + (R * self.Scale , cp))
+ + tuple(S) + tuple(E) + (R * self.Scale , cp))
apply(self.pack , Args)
else:
if ell.start_angle == ell.end_angle:
@@ -357,7 +357,7 @@
P1 = trf(Point(1,0))
P2 = trf(Point(0,1))
self.putlongseq(0x4220 , map(rndtoint , tuple(self.trafo(C)) \
- + tuple(self.trafo(P1)) + tuple(self.trafo(P2))))
+ + tuple(self.trafo(P1)) + tuple(self.trafo(P2))))
else:
C = trf(Point(0,0))
P1 = trf(Point(1,0))
@@ -369,8 +369,8 @@
if ell.arc_type == 0 and ell.Properties().fill_pattern == EmptyPattern:
self.LineStyle(ell.Properties())
self.putlongseq(0x4240 , map(rndtoint , tuple(self.trafo(C)) \
- + tuple(self.trafo(P1)) + tuple(self.trafo(P2)) + tuple(S) \
- + tuple(E)))
+ + tuple(self.trafo(P1)) + tuple(self.trafo(P2)) + tuple(S) \
+ + tuple(E)))
else:
#self.PolyBezier(ell.Paths(), ell.Properties())
self.FillStyle(ell.Properties())
@@ -379,8 +379,8 @@
else:
cp = 2 - ell.arc_type
Args = ["!HH10iH" , 0x4260 + 31 , 42] + map(rndtoint , tuple(self.trafo(C)) \
- + tuple(self.trafo(P1)) + tuple(self.trafo(P2)) + tuple(S) \
- + tuple(E) + (cp,))
+ + tuple(self.trafo(P1)) + tuple(self.trafo(P2)) + tuple(S) \
+ + tuple(E) + (cp,))
apply(self.pack , Args)
def Image(self, object):
@@ -434,7 +434,7 @@
# moment to be the approach
for layer in Layers:
if not layer.is_SpecialLayer and layer.Printable():
-
+
# Begin Picture
self.putstr(0x0060 , layer.name)
@@ -506,7 +506,7 @@
self.pack("!H" , 0x1184)
# VDC Integer precision 32 bits
self.pack("!Hh" , 0x3022 , 32)
-
+
#Font List
#
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/cmxloader.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/cmxloader.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/cmxloader.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -106,18 +106,18 @@
class ChunkHeader:
def __init__(self, filepos, chunk_type, length, sub_type = ''):
- self.filepos = filepos
- self.chunk_type = chunk_type
- self.length = length
- self.sub_type = sub_type
- if sub_type:
- self.headersize = 12
- self.data_length = self.length - 4
- else:
- self.headersize = 8
- self.data_length = self.length
- self.data_start = self.filepos + self.headersize
- self.has_subchunks = self.sub_type != ''
+ self.filepos = filepos
+ self.chunk_type = chunk_type
+ self.length = length
+ self.sub_type = sub_type
+ if sub_type:
+ self.headersize = 12
+ self.data_length = self.length - 4
+ else:
+ self.headersize = 8
+ self.data_length = self.length
+ self.data_start = self.filepos + self.headersize
+ self.has_subchunks = self.sub_type != ''
self.subchunks = None
def SetSubchunks(self, chunks):
@@ -130,16 +130,16 @@
filepos = file.tell()
data = file.read(8)
if len(data) < 8:
- raise RiffEOF
+ raise RiffEOF
chunk_type, length = unpack('<4si', data)
if length % 2 != 0:
- length = length + 1
+ length = length + 1
if chunk_type in compound_chunks:
- sub_type = file.read(4)
- if len(sub_type) < 4:
- raise RiffEOF
+ sub_type = file.read(4)
+ if len(sub_type) < 4:
+ raise RiffEOF
else:
- sub_type = ''
+ sub_type = ''
return ChunkHeader(filepos, chunk_type, length, sub_type)
#
@@ -148,34 +148,34 @@
struct_cmxheader_start = ('32s' # Id
- '16s' # OS
- '4s' # ByteOrder, 2 little, 4 big endian
- '2s' # coord size, 2 = 16bit, 4 = 32bit
- '4s' # major version
- '4s' # minor version
- )
+ '16s' # OS
+ '4s' # ByteOrder, 2 little, 4 big endian
+ '2s' # coord size, 2 = 16bit, 4 = 32bit
+ '4s' # major version
+ '4s' # minor version
+ )
struct_cmxheader_end = ('<'
- 'H' # Unit, 35 = mm, 64 = inch
- 'd' # factor
- 'xxxx' # option, unused
- 'xxxx' # foreign key, unused
- 'xxxx' # capability, unused
- 'l' # index section, offset
- 'l' # info section, offset
- 'l' # thumbnail, offset (the docs differ here)
- 'l' # bb_left
- 'l' # bb_top
- 'l' # bb_right
- 'l' # bb_bottom
- 'l' # tally
- '64x' # reserved
- )
+ 'H' # Unit, 35 = mm, 64 = inch
+ 'd' # factor
+ 'xxxx' # option, unused
+ 'xxxx' # foreign key, unused
+ 'xxxx' # capability, unused
+ 'l' # index section, offset
+ 'l' # info section, offset
+ 'l' # thumbnail, offset (the docs differ here)
+ 'l' # bb_left
+ 'l' # bb_top
+ 'l' # bb_right
+ 'l' # bb_bottom
+ 'l' # tally
+ '64x' # reserved
+ )
color_models = ('Invalid', 'Pantone', 'CMYK', 'CMYK255', 'CMY', 'RGB',
- 'HSB', 'HLS', 'BW', 'Gray', 'YIQ255', 'LAB')
+ 'HSB', 'HLS', 'BW', 'Gray', 'YIQ255', 'LAB')
color_bytes = (0, 4, 4, 4, 4, 3, 4, 4, 1, 4, 1, 4)
color_palettes = ('Invalid', 'Truematch', 'PantoneProcess', 'PantoneSpot',
- 'Image', 'User', 'CustomFixed')
+ 'Image', 'User', 'CustomFixed')
cmx_commands = {
88: 'AddClippingRegion',
@@ -218,156 +218,156 @@
93: 'SetGlobalTransfo',
86: 'SimpleWideText',
98: 'TextFrame'
- }
+}
class Outline:
def __init__(self, style, screen, color, arrowheads, pen, dashes):
- self.style = style
- self.screen = screen
- self.color = color
- self.arrowheads = arrowheads
- self.pen = pen
- self.dashes = dashes
+ self.style = style
+ self.screen = screen
+ self.color = color
+ self.arrowheads = arrowheads
+ self.pen = pen
+ self.dashes = dashes
class CMXFile:
def __init__(self, loader, file):
- self.file = file
+ self.file = file
self.loader = loader
- self.tagged = 0
- self.colors = []
- self.screens = []
- self.dashes = []
- self.pens = []
- self.line_styles = []
+ self.tagged = 0
+ self.colors = []
+ self.screens = []
+ self.dashes = []
+ self.pens = []
+ self.line_styles = []
self.procindex = [None,]
self.bitmapindex = [None,]
self.embeddedindex = [None,]
self.arrowindex = [None,]
- self.verbosity = 0
+ self.verbosity = 0
self.angle_factor = 1
self.pages = []
def warn(self, message):
self.loader.add_message(message)
-
+
def _print(self, format, *args, **kw):
- if self.verbosity:
- if kw:
- text = format % kw
- elif args:
- text = format % args
- else:
- text = format
- sys.stderr.write(text)
+ if self.verbosity:
+ if kw:
+ text = format % kw
+ elif args:
+ text = format % args
+ else:
+ text = format
+ sys.stderr.write(text)
def read_header(self):
- self.file.seek(0)
- self.riff_header = h = read_chunk_header(self.file)
- self._print('%6d %s %s %d\n',
+ self.file.seek(0)
+ self.riff_header = h = read_chunk_header(self.file)
+ self._print('%6d %s %s %d\n',
h.filepos, h.chunk_type, h.sub_type, h.data_length)
def read_subchunks(self, header, indent = 1):
- bytesread = 0
- chunks = []
- self.file.seek(header.data_start)
- while bytesread < header.data_length:
- subheader = read_chunk_header(self.file)
- bytesread = bytesread + subheader.headersize
- self._print('%6d %s%s %s %d\n',
+ bytesread = 0
+ chunks = []
+ self.file.seek(header.data_start)
+ while bytesread < header.data_length:
+ subheader = read_chunk_header(self.file)
+ bytesread = bytesread + subheader.headersize
+ self._print('%6d %s%s %s %d\n',
subheader.filepos, indent * ' ', subheader.chunk_type,
subheader.sub_type, subheader.data_length)
if subheader.sub_type != '':
subchunks = self.read_subchunks(subheader, indent + 1)
subheader.SetSubchunks(subchunks)
- self.file.seek(subheader.data_start + subheader.data_length)
- bytesread = bytesread + subheader.data_length
- chunks.append(subheader)
- return chunks
+ self.file.seek(subheader.data_start + subheader.data_length)
+ bytesread = bytesread + subheader.data_length
+ chunks.append(subheader)
+ return chunks
def read_16(self):
- read = self.file.read
- lo, hi = read(2)
- value = ord(lo) + 256 * ord(hi)
- if value > 0x7FFF:
- value = value - 0x010000
- return value
+ read = self.file.read
+ lo, hi = read(2)
+ value = ord(lo) + 256 * ord(hi)
+ if value > 0x7FFF:
+ value = value - 0x010000
+ return value
def read_32(self):
- data = self.file.read(4)
- return int(unpack('<i', data)[0])
+ data = self.file.read(4)
+ return int(unpack('<i', data)[0])
def read_angle(self):
- angle = self.read_32()
- return angle * self.angle_factor
+ angle = self.read_32()
+ return angle * self.angle_factor
def read_matrix(self):
- type = self.read_16()
- if type == 1: # identity
- return (1, 0, 0, 1, 0, 0)
- data = self.file.read(48)
- matrix = unpack('<dddddd', data)
- return tuple(matrix)
+ type = self.read_16()
+ if type == 1: # identity
+ return (1, 0, 0, 1, 0, 0)
+ data = self.file.read(48)
+ matrix = unpack('<dddddd', data)
+ return tuple(matrix)
def read_string(self):
- count = self.read_16()
- return self.read(count)
+ count = self.read_16()
+ return self.read(count)
def get_rectangle(data):
- return unpack('<hhhh', self.file.read(8))
+ return unpack('<hhhh', self.file.read(8))
def read_tag(self, supported):
- read = self.file.read
- tag = -1; data = ''
- while tag != 255 and tag not in supported:
- tag = read(1);
+ read = self.file.read
+ tag = -1; data = ''
+ while tag != 255 and tag not in supported:
+ tag = read(1);
tag = ord(tag)
if tag == 255:
break
- size = ord(read(1)) + 256 * ord(read(1))
- data = read(size - 3)
- return tag, data
+ size = ord(read(1)) + 256 * ord(read(1))
+ data = read(size - 3)
+ return tag, data
def read_cont(self, chunk):
- self.file.seek(chunk.data_start)
- data = self.file.read(chunk.data_length)
- start_size = struct.calcsize(struct_cmxheader_start)
- end_size = struct.calcsize(struct_cmxheader_end)
- self.file_id, self.platform, byte_order, coord_size, major, minor \
- = unpack(struct_cmxheader_start, data[:start_size])
- self.byte_order = int(byte_order[:1])
- self.coord_size = int(coord_size[:1])
- self.version = float(major[:1])
- self.unit, self.coord_factor, index, info, thumbnail, \
- left, top, right, bottom, tally \
- = unpack(struct_cmxheader_end, data[start_size:])
- self.unit = int(self.unit) # unpack makes unit a long
- # (fixed in python 1.5.2)
- self.bbox = left, top, right, bottom
+ self.file.seek(chunk.data_start)
+ data = self.file.read(chunk.data_length)
+ start_size = struct.calcsize(struct_cmxheader_start)
+ end_size = struct.calcsize(struct_cmxheader_end)
+ self.file_id, self.platform, byte_order, coord_size, major, minor \
+ = unpack(struct_cmxheader_start, data[:start_size])
+ self.byte_order = int(byte_order[:1])
+ self.coord_size = int(coord_size[:1])
+ self.version = float(major[:1])
+ self.unit, self.coord_factor, index, info, thumbnail, \
+ left, top, right, bottom, tally \
+ = unpack(struct_cmxheader_end, data[start_size:])
+ self.unit = int(self.unit) # unpack makes unit a long
+ # (fixed in python 1.5.2)
+ self.bbox = left, top, right, bottom
if self.version == 2.0:
self.tagged = 1
self.angle_factor = pi / 180000000.0
else:
self.angle_factor = pi / 1800.0
- self._print('\nHeader\n------\n')
- fmt = '% 10s: %s\n'
- fmt2 = '% 10s: '
- self._print(fmt, 'ID', self.file_id)
- self._print(fmt, 'platform', self.platform)
- self._print(fmt2 + '%s %s\n', 'byte order',
+ self._print('\nHeader\n------\n')
+ fmt = '% 10s: %s\n'
+ fmt2 = '% 10s: '
+ self._print(fmt, 'ID', self.file_id)
+ self._print(fmt, 'platform', self.platform)
+ self._print(fmt2 + '%s %s\n', 'byte order',
(0, 0, 'little', '', 'big')[self.byte_order], 'endian')
- self._print(fmt2 + '%d %s\n', 'coord size',
+ self._print(fmt2 + '%d %s\n', 'coord size',
(0, 0, 16, 0, 32)[self.coord_size], 'bit')
- self._print(fmt, 'version', self.version)
- self._print(fmt, 'unit', self.unit == 35 and 'mm' or 'inch')
- self._print(fmt, 'factor', self.coord_factor)
- self._print(fmt, 'bound.box', (left, top, right, bottom))
- self._print('\n')
+ self._print(fmt, 'version', self.version)
+ self._print(fmt, 'unit', self.unit == 35 and 'mm' or 'inch')
+ self._print(fmt, 'factor', self.coord_factor)
+ self._print(fmt, 'bound.box', (left, top, right, bottom))
+ self._print('\n')
def append_color(self, colors, model, data):
if model == 2: # CMYK
@@ -394,35 +394,35 @@
% color_models[model])
colors.append(StandardColors.black)
self._print(`data`)
-
+
def read_colors(self, chunk):
- self._print('Colors\n------\n')
- colors = [None,]
- self.file.seek(chunk.data_start)
- count = self.read_16()
- self._print('%d %s\n', count, 'colors')
- if self.tagged:
- for i in range(count):
- tag = -1
- while tag != 255:
- tag, data = self.read_tag((1,2))
- if tag == 1: # color base
- model, palette = map(ord, data)
- elif tag == 2: # color description
+ self._print('Colors\n------\n')
+ colors = [None,]
+ self.file.seek(chunk.data_start)
+ count = self.read_16()
+ self._print('%d %s\n', count, 'colors')
+ if self.tagged:
+ for i in range(count):
+ tag = -1
+ while tag != 255:
+ tag, data = self.read_tag((1,2))
+ if tag == 1: # color base
+ model, palette = map(ord, data)
+ elif tag == 2: # color description
self.append_color(colors, model, data)
#
self._print('\n')
- else:
- read = self.file.read
- for i in range(count):
- model, palette = map(ord, read(2))
- self._print('%3d: %4s %-6s ', i, color_models[model],
+ else:
+ read = self.file.read
+ for i in range(count):
+ model, palette = map(ord, read(2))
+ self._print('%3d: %4s %-6s ', i, color_models[model],
color_palettes[palette])
- data = read(color_bytes[model])
+ data = read(color_bytes[model])
self.append_color(colors, model, data)
- self._print('\n')
- self._print('\n')
- return colors
+ self._print('\n')
+ self._print('\n')
+ return colors
def append_screen(self, screens, data):
spot, frequency, user, angle, overprint = unpack('<hHiiB', data)
@@ -431,58 +431,58 @@
self._print('%3d spot %d frequency %d user %d angle %g'
' overprint %d\n',
len(screens), spot, frequency, user, angle, overprint)
-
+
def read_screens(self, chunk):
- self._print('Screens\n-------\n')
- screens = [None,]
- self.file.seek(chunk.data_start)
- count = self.read_16()
- self._print('%d %s\n', count, 'screens')
- if self.tagged:
- for i in range(count):
- tag = -1
- while tag != 255:
- tag, data = self.read_tag((1, 2))
+ self._print('Screens\n-------\n')
+ screens = [None,]
+ self.file.seek(chunk.data_start)
+ count = self.read_16()
+ self._print('%d %s\n', count, 'screens')
+ if self.tagged:
+ for i in range(count):
+ tag = -1
+ while tag != 255:
+ tag, data = self.read_tag((1, 2))
if tag == 1: # screen basic
self.append_screen(screens, data)
elif tag == 2: # screen ps function
pass
- else:
- read16 = self.read_16
- for i in range(count):
+ else:
+ read16 = self.read_16
+ for i in range(count):
data = self.file.read(13)
spot = self.append_screen(screens, data)
- if spot == 3: # user defined
- ps_function = self.read_string()
- else:
- ps_function = ''
- self._print('\n')
- return screens
+ if spot == 3: # user defined
+ ps_function = self.read_string()
+ else:
+ ps_function = ''
+ self._print('\n')
+ return screens
def append_dashes(self, dashes, data):
dashes.append(unpack('<' + (len(data) / 2) * 'h', data))
self._print('%3d: %s\n', len(dashes), dashes[-1])
def read_dot(self, chunk):
- self._print('Dashes\n------\n')
- dashes = [None,]
- self.file.seek(chunk.data_start)
- count = self.read_16()
- self._print('%d %s\n', count, 'dashes')
- if self.tagged:
- for i in range(count):
- tag = -1
- while tag != 255:
- tag, data = self.read_tag((1,))
+ self._print('Dashes\n------\n')
+ dashes = [None,]
+ self.file.seek(chunk.data_start)
+ count = self.read_16()
+ self._print('%d %s\n', count, 'dashes')
+ if self.tagged:
+ for i in range(count):
+ tag = -1
+ while tag != 255:
+ tag, data = self.read_tag((1,))
if tag == 1:
self.append_dashes(dashes, data[2:])
- else:
- read16 = self.read_16
- for i in range(count):
- num = read16()
+ else:
+ read16 = self.read_16
+ for i in range(count):
+ num = read16()
self.append_dashes(dashes, self.file.read(2 * num))
- self._print('\n')
- return dashes
+ self._print('\n')
+ return dashes
def append_pen(self, pens, data):
if self.coord_size == 4:
@@ -503,42 +503,42 @@
matrix)
def read_pen(self, chunk):
- self._print('Pens\n----\n')
- pens = [None,]
- self.file.seek(chunk.data_start)
- count = self.read_16()
- self._print('%d %s\n', count, 'pens')
- if self.tagged:
- for i in range(count):
- tag = -1
- while tag != 255:
- tag, data = self.read_tag((1,))
+ self._print('Pens\n----\n')
+ pens = [None,]
+ self.file.seek(chunk.data_start)
+ count = self.read_16()
+ self._print('%d %s\n', count, 'pens')
+ if self.tagged:
+ for i in range(count):
+ tag = -1
+ while tag != 255:
+ tag, data = self.read_tag((1,))
if tag == 1:
self.append_pen(pens, data)
- else:
- read16 = self.read_16
- for i in range(count):
+ else:
+ read16 = self.read_16
+ for i in range(count):
data = self.file.read(10)
self.append_pen(pens, data)
- self._print('\n')
- return pens
+ self._print('\n')
+ return pens
def print_linestyle(self, style):
- spec, cap, join = style
- self._print('%s %s flags: ',
- ('miter', 'round', 'square')[cap],
- ('miter', 'round', 'bevel')[join])
- if spec & 0x01:
- self._print('none ')
- if spec & 0x02:
- self._print('solid ')
- if spec & 0x04:
- self._print('dashed ')
- if spec & 0x10:
- self._print('behind_fill ')
- if spec & 0x20:
- self._print('scale_pen')
- self._print('\n')
+ spec, cap, join = style
+ self._print('%s %s flags: ',
+ ('miter', 'round', 'square')[cap],
+ ('miter', 'round', 'bevel')[join])
+ if spec & 0x01:
+ self._print('none ')
+ if spec & 0x02:
+ self._print('solid ')
+ if spec & 0x04:
+ self._print('dashed ')
+ if spec & 0x10:
+ self._print('behind_fill ')
+ if spec & 0x20:
+ self._print('scale_pen')
+ self._print('\n')
def append_linestyle(self, styles, data):
spec, capjoin = map(ord, data)
@@ -549,24 +549,24 @@
self.print_linestyle((spec, cap, join))
def read_linestyles(self, chunk):
- self._print('Line Styles\n-----------\n')
- styles = [None,]
- self.file.seek(chunk.data_start)
- count = self.read_16()
- self._print('%d %s\n', count, 'line styles')
- if self.tagged:
- for i in range(count):
- tag = -1
- while tag != 255:
+ self._print('Line Styles\n-----------\n')
+ styles = [None,]
+ self.file.seek(chunk.data_start)
+ count = self.read_16()
+ self._print('%d %s\n', count, 'line styles')
+ if self.tagged:
+ for i in range(count):
+ tag = -1
+ while tag != 255:
tag, data = self.read_tag((1,))
if tag == 1:
self.append_linestyle(styles, data)
- else:
- read = self.file.read
- for i in range(count):
+ else:
+ read = self.file.read
+ for i in range(count):
self.append_linestyle(styles, self.file.read(2))
- self._print('\n')
- return styles
+ self._print('\n')
+ return styles
def append_arrowhead(self, heads, data):
head1, head2 = unpack('<hh', data)
@@ -574,57 +574,57 @@
self._print('%d: %d %d\n', len(heads) - 1, head1, head2)
def read_arrowheads(self, chunk):
- self._print('Arrow Heads\n-----------\n')
- heads = [None,]
- self.file.seek(chunk.data_start)
- count = self.read_16()
- self._print('%d %s\n', count, 'arrow heads')
+ self._print('Arrow Heads\n-----------\n')
+ heads = [None,]
+ self.file.seek(chunk.data_start)
+ count = self.read_16()
+ self._print('%d %s\n', count, 'arrow heads')
# The arrow heads section does not seem to use tags
for i in range(count):
self.append_arrowhead(heads, self.file.read(4))
- self._print('\n')
- return heads
+ self._print('\n')
+ return heads
def print_outline(self, outline):
- self._print('%s %s %s %s %s %s\n',
- outline.style, outline.screen, outline.color,
- outline.arrowheads, outline.pen, outline.dashes)
+ self._print('%s %s %s %s %s %s\n',
+ outline.style, outline.screen, outline.color,
+ outline.arrowheads, outline.pen, outline.dashes)
def append_outline(self, outlines, data):
style, screen, color, arrowheads, pen, dash = unpack('<hhhhhh', data)
outlines.append(Outline(self.line_styles[style], screen,
self.colors[color], arrowheads,
self.pens[pen], self.dashes[dash]))
-
+
self._print('%3d ', len(outlines))
self.print_outline(outlines[-1])
def read_outlines(self, chunk):
- self._print('Outlines\n--------\n')
- outlines = [None,]
- self.file.seek(chunk.data_start)
- count = self.read_16()
- self._print('%d %s\n', count, 'outlines')
- if self.tagged:
- for i in range(count):
- tag = -1
- while tag != 255:
+ self._print('Outlines\n--------\n')
+ outlines = [None,]
+ self.file.seek(chunk.data_start)
+ count = self.read_16()
+ self._print('%d %s\n', count, 'outlines')
+ if self.tagged:
+ for i in range(count):
+ tag = -1
+ while tag != 255:
tag, data = self.read_tag((1,))
if tag == 1:
self.append_outline(outlines, data)
- else:
- read16 = self.read_16
- for i in range(count):
+ else:
+ read16 = self.read_16
+ for i in range(count):
self.append_outline(outlines, self.file.read(12))
- self._print('\n')
- return outlines
+ self._print('\n')
+ return outlines
def read_procindex(self, chunk):
- self._print('Procedures\n----------\n')
- procindex = [None,]
- self.file.seek(chunk.data_start)
- count = self.read_16()
- self._print('%d %s\n', count, 'procedures')
+ self._print('Procedures\n----------\n')
+ procindex = [None,]
+ self.file.seek(chunk.data_start)
+ count = self.read_16()
+ self._print('%d %s\n', count, 'procedures')
if self.version < 2:
for i in range(count):
reflist, offset = unpack('<ll', self.file.read(8))
@@ -642,11 +642,11 @@
return procindex
def read_indextable(self, chunk):
- self._print('Table\n-----\n')
+ self._print('Table\n-----\n')
self.file.seek(chunk.data_start)
- count, length, idxtype = unpack('<hhh', self.file.read(6))
+ count, length, idxtype = unpack('<hhh', self.file.read(6))
self._print('index type %d, entry length %d\n', idxtype, length)
- self._print('%d %s\n', count, 'entries')
+ self._print('%d %s\n', count, 'entries')
index = None
if idxtype == 5:
self._print('Bitmap Index\n')
@@ -666,10 +666,10 @@
self._print('\n')
def read_embedded_index(self, chunk):
- self._print('Embedded Files\n--------------\n')
+ self._print('Embedded Files\n--------------\n')
self.file.seek(chunk.data_start)
- count = self.read_16()
- self._print('%d %s\n', count, 'entries')
+ count = self.read_16()
+ self._print('%d %s\n', count, 'entries')
for i in range(count):
length = self.read_16()
data = self.file.read(length)
@@ -677,8 +677,8 @@
self._print('offset %d, type %d\n', offset, image_type)
self.embeddedindex.append((offset, image_type))
self._print('\n')
-
+
def read_index(self, chunk):
self._print('Index\n-----\n')
for subchunk in chunk.subchunks:
@@ -690,32 +690,32 @@
self.read_embedded_index(subchunk)
def process_chunks(self):
- chunkdict = {}
- for chunk in self.chunks:
+ chunkdict = {}
+ for chunk in self.chunks:
if chunk.sub_type:
chunkdict[chunk.sub_type] = chunk
elif chunk.chunk_type == 'page':
self.pages.append(chunk)
else:
chunkdict[chunk.chunk_type] = chunk
- self.read_cont(chunkdict.get('cont'))
- for fcc, name, method in (('rclr', 'colors', 'read_colors'),
- ('rscr', 'screens', 'read_screens'),
- ('rdot', 'dashes', 'read_dot'),
- ('rpen', 'pens', 'read_pen'),
- ('rott', 'line_styles', 'read_linestyles'),
- ('rota', 'arrow_heads', 'read_arrowheads'),
- # rotl last as it references other attrs
+ self.read_cont(chunkdict.get('cont'))
+ for fcc, name, method in (('rclr', 'colors', 'read_colors'),
+ ('rscr', 'screens', 'read_screens'),
+ ('rdot', 'dashes', 'read_dot'),
+ ('rpen', 'pens', 'read_pen'),
+ ('rott', 'line_styles', 'read_linestyles'),
+ ('rota', 'arrow_heads', 'read_arrowheads'),
+ # rotl last as it references other attrs
('rotl', 'outlines', 'read_outlines')):
- chunk = chunkdict.get(fcc)
- if chunk is not None:
- setattr(self, name, getattr(self, method)(chunk))
+ chunk = chunkdict.get(fcc)
+ if chunk is not None:
+ setattr(self, name, getattr(self, method)(chunk))
self.read_index(chunkdict.get('indx'))
def Load(self):
- self.read_header()
- self.chunks = self.read_subchunks(self.riff_header)
- self.process_chunks()
+ self.read_header()
+ self.chunks = self.read_subchunks(self.riff_header)
+ self.process_chunks()
def NumPages(self):
return len(self.pages)
@@ -726,22 +726,22 @@
return self.file.read(chunk.data_length), chunk.data_start
def CoordFactor(self):
- if self.unit == 35: # mm
+ if self.unit == 35: # mm
# Is this really in mm?
- factor = self.coord_factor * units.mm_to_pt * 1000
- elif self.unit == 64: # inches
- factor = self.coord_factor * units.in_to_pt
- else:
- self.warn(_("Unknown unit specification %d, assuming inches")
+ factor = self.coord_factor * units.mm_to_pt * 1000
+ elif self.unit == 64: # inches
+ factor = self.coord_factor * units.in_to_pt
+ else:
+ self.warn(_("Unknown unit specification %d, assuming inches")
% self.unit)
- factor = self.coord_factor * units.in_to_pt
- return factor
+ factor = self.coord_factor * units.in_to_pt
+ return factor
def CoordTrafo(self):
- factor = self.CoordFactor()
- left, top, right, bottom = self.bbox
- return Trafo(factor, 0, 0, factor,
- -factor * min(left, right), -factor * min(bottom, top))
+ factor = self.CoordFactor()
+ left, top, right, bottom = self.bbox
+ return Trafo(factor, 0, 0, factor,
+ -factor * min(left, right), -factor * min(bottom, top))
def GetBitmap(self, index):
offset = self.bitmapindex[index]
@@ -781,7 +781,7 @@
if image_type == 0x08:
image = self.load_bitmap(subchunks[1].data_start,
subchunks[1].data_length)
-
+
elif image_type == 16:
image = self.load_rimage(subchunks[1].data_start,
subchunks[1].data_length)
@@ -859,15 +859,15 @@
class CMXInterpreter:
def __init__(self, loader, cmxfile, layer_prefix = ''):
- self.loader = loader
- self.cmxfile = cmxfile
+ self.loader = loader
+ self.cmxfile = cmxfile
self.source_stack = ()
self.source = None
- self.pos = 0
- self._print = cmxfile._print
- self.trafo = cmxfile.CoordTrafo()
+ self.pos = 0
+ self._print = cmxfile._print
+ self.trafo = cmxfile.CoordTrafo()
self.trafo_stack = ()
- self.factor = cmxfile.CoordFactor()
+ self.factor = cmxfile.CoordFactor()
self.angle_factor = cmxfile.angle_factor
self.layer_prefix = layer_prefix
@@ -892,22 +892,22 @@
return self.source.read_struct(format)
def get_int16(self):
- return self.source.read_struct('h')[0]
+ return self.source.read_struct('h')[0]
def get_uint16(self):
- return self.source.read_struct('H')[0]
+ return self.source.read_struct('H')[0]
def get_int32(self):
- return self.source.read_struct('l')[0]
+ return self.source.read_struct('l')[0]
def get_rectangle(self):
- return self.source.read_struct('iiii')
+ return self.source.read_struct('iiii')
def get_matrix(self):
- type = self.get_int16()
- if type == 1: # identity
- return (1, 0, 0, 1, 0, 0)
- return self.source.read_struct('dddddd')
+ type = self.get_int16()
+ if type == 1: # identity
+ return (1, 0, 0, 1, 0, 0)
+ return self.source.read_struct('dddddd')
def get_boolean(self):
return self.source.read_struct('B')[0]
@@ -918,12 +918,12 @@
return self.source.read(count)
def get_string(self):
- count = self.get_int16()
+ count = self.get_int16()
string = self.source.read(count)
return string
def get_angle(self):
- return self.get_int32() * self.angle_factor
+ return self.get_int32() * self.angle_factor
def get_tag(self):
tag = ord(self.source.read(1))
@@ -954,8 +954,8 @@
byte_order = 1
self.push_source(BinaryInput(data, byte_order,
self.cmxfile.coord_size))
- get_int16 = self.get_int16
- get_int32 = self.get_int32
+ get_int16 = self.get_int16
+ get_int32 = self.get_int32
try:
while self.source.tell() < len(data):
p = self.pos
@@ -1022,119 +1022,119 @@
class CMXInterpreter16(CMXInterpreter):
def BeginPage(self):
- page_number, flags = self.source.read_struct('hl')
- bbox = self.get_rectangle()
- endpage, group_count, tally = self.source.read_struct('lhl')
- matrix = self.get_matrix()
- mapflag = self.get_boolean()
+ page_number, flags = self.source.read_struct('hl')
+ bbox = self.get_rectangle()
+ endpage, group_count, tally = self.source.read_struct('lhl')
+ matrix = self.get_matrix()
+ mapflag = self.get_boolean()
- if mapflag:
- maprect1 = self.get_rectangle()
- maprect2 = self.get_rectangle()
+ if mapflag:
+ maprect1 = self.get_rectangle()
+ maprect2 = self.get_rectangle()
fmt = ' % 10s: %s\n'
- self._print(fmt, 'PageNumber', page_number)
- self._print(fmt, 'flags', flags)
- self._print(fmt, 'GroupCount:', group_count)
- self._print(fmt, 'Tally.', tally)
- self._print(fmt, 'Matrix', matrix)
- if mapflag:
- self._print(fmt, 'MapRect1', maprect1)
- self._print(fmt, 'MapRect2', maprect2)
- else:
- self._print(' No map.\n')
+ self._print(fmt, 'PageNumber', page_number)
+ self._print(fmt, 'flags', flags)
+ self._print(fmt, 'GroupCount:', group_count)
+ self._print(fmt, 'Tally.', tally)
+ self._print(fmt, 'Matrix', matrix)
+ if mapflag:
+ self._print(fmt, 'MapRect1', maprect1)
+ self._print(fmt, 'MapRect2', maprect2)
+ else:
+ self._print(' No map.\n')
def BeginLayer(self):
- page_number, layer_number, flags, tally \
- = self.source.read_struct('hhll')
- layer_name = self.get_string()
- matrix = self.get_matrix()
- mapflag = self.get_boolean()
- if mapflag:
- maprect1 = self.get_rectangle()
- maprect2 = self.get_rectangle()
- fmt = ' % 11s: %s\n'
- self._print(fmt, 'LayerName', layer_name)
- self._print(fmt, 'LayerNumber', layer_number)
- self._print(fmt, 'PageNumber', page_number)
- self._print(fmt, 'flags', flags)
- self._print(fmt, 'Tally.', tally)
- self._print(fmt, 'Matrix', matrix)
- if mapflag:
- self._print(fmt, 'MapRect1', maprect1)
- self._print(fmt, 'MapRect2', maprect2)
- else:
- self._print(' No map.\n')
+ page_number, layer_number, flags, tally \
+ = self.source.read_struct('hhll')
+ layer_name = self.get_string()
+ matrix = self.get_matrix()
+ mapflag = self.get_boolean()
+ if mapflag:
+ maprect1 = self.get_rectangle()
+ maprect2 = self.get_rectangle()
+ fmt = ' % 11s: %s\n'
+ self._print(fmt, 'LayerName', layer_name)
+ self._print(fmt, 'LayerNumber', layer_number)
+ self._print(fmt, 'PageNumber', page_number)
+ self._print(fmt, 'flags', flags)
+ self._print(fmt, 'Tally.', tally)
+ self._print(fmt, 'Matrix', matrix)
+ if mapflag:
+ self._print(fmt, 'MapRect1', maprect1)
+ self._print(fmt, 'MapRect2', maprect2)
+ else:
+ self._print(' No map.\n')
- # start layer
+ # start layer
self.loader.layer(self.layer_prefix + layer_name, 1, 1, 0, 0, (0,0,0))
def BeginGroup(self):
- bbox = self.get_rectangle()
- group_count, tally, endgroup = self.source.read_struct('hll')
- fmt = ' % 10s: %s\n'
- self._print(fmt, 'GroupCount', group_count)
- self._print(fmt, 'Tally.', tally)
- self._print(fmt, 'Bound.Box', bbox)
+ bbox = self.get_rectangle()
+ group_count, tally, endgroup = self.source.read_struct('hll')
+ fmt = ' % 10s: %s\n'
+ self._print(fmt, 'GroupCount', group_count)
+ self._print(fmt, 'Tally.', tally)
+ self._print(fmt, 'Bound.Box', bbox)
- # start group
- self.loader.begin_group()
-
+ # start group
+ self.loader.begin_group()
+
def get_rendering_attrs(self):
- self._print(' Rendering Attributes:\n')
- style = self.loader.style
- mask = self.get_byte()
- if mask & 0x01: # fill attrs
- self._print(' Fill:')
- fill = self.get_int16()
- if fill == 0: # no fill
- self._print('no fill\n')
- style.fill_pattern = EmptyPattern
- elif fill == 1: # uniform
- color, screen = self.source.read_struct('hh')
- self._print('uniform %s %s, screen %s\n', color,
+ self._print(' Rendering Attributes:\n')
+ style = self.loader.style
+ mask = self.get_byte()
+ if mask & 0x01: # fill attrs
+ self._print(' Fill:')
+ fill = self.get_int16()
+ if fill == 0: # no fill
+ self._print('no fill\n')
+ style.fill_pattern = EmptyPattern
+ elif fill == 1: # uniform
+ color, screen = self.source.read_struct('hh')
+ self._print('uniform %s %s, screen %s\n', color,
self.cmxfile.colors[color], screen)
- style.fill_pattern = SolidPattern(self.cmxfile.colors[color])
- elif fill == 2: # fountain (gradient)
- fountain, screen, padding = self.source.read_struct('hhh')
- angle = self.get_angle()
- xoff, yoff, steps, mode = self.source.read_struct('iihh')
- # The rate doesn't seem to be present in CMX1
- #rate_method, data = get_int16(data)
- #rate_value, data = get_int16(data)
- color_count = self.get_int16()
- colors = []
- for i in range(color_count):
- color, pos = self.source.read_struct('hh')
- color = self.cmxfile.colors[color]
- colors.append((pos / 100.0, color))
- self._print('fountain: %s pad %d angle %f off %d %d\n',
+ style.fill_pattern = SolidPattern(self.cmxfile.colors[color])
+ elif fill == 2: # fountain (gradient)
+ fountain, screen, padding = self.source.read_struct('hhh')
+ angle = self.get_angle()
+ xoff, yoff, steps, mode = self.source.read_struct('iihh')
+ # The rate doesn't seem to be present in CMX1
+ #rate_method, data = get_int16(data)
+ #rate_value, data = get_int16(data)
+ color_count = self.get_int16()
+ colors = []
+ for i in range(color_count):
+ color, pos = self.source.read_struct('hh')
+ color = self.cmxfile.colors[color]
+ colors.append((pos / 100.0, color))
+ self._print('fountain: %s pad %d angle %f off %d %d\n',
('linear','radial','conical','square')[fountain],
padding, angle, xoff, yoff)
- self._print(' steps %d mode %s\n', steps,
+ self._print(' steps %d mode %s\n', steps,
('RGB', 'HSB_CW', 'HSB_CCW', 'Custom')[mode])
- self._print(' colors %s\n', colors)
- style.fill_pattern = LinearGradient(MultiGradient(colors),
- -Polar(angle),
+ self._print(' colors %s\n', colors)
+ style.fill_pattern = LinearGradient(MultiGradient(colors),
+ -Polar(angle),
border = padding / 50.0)
elif fill == 7: # monochrome bitmap 1 (according to cmxbrowser)
bitmap = self.get_int16()
width, height, xoff, yoff, inter, flags \
- = self.source.read_struct('hhhhhh')
+ = self.source.read_struct('hhhhhh')
foreground, background, screen = self.source.read_struct('hhh')
- self._print('twocolor: bitmap %d\n', bitmap)
+ self._print('twocolor: bitmap %d\n', bitmap)
self._print(' size (%d, %d), off (%d, %d), inter %d, '
'flags %x\n',
width, height, xoff, yoff, inter, flags)
- self._print(' foreground %s, background %s, screen %d\n',
+ self._print(' foreground %s, background %s, screen %d\n',
self.cmxfile.colors[foreground],
self.cmxfile.colors[background], screen)
- self.warn(_("fill type 'monochrome-bitmap' not implemented, "
+ self.warn(_("fill type 'monochrome-bitmap' not implemented, "
"using solid black"))
style.fill_pattern = SolidPattern(StandardColors.black)
elif fill == 11: # Texture
function = self.get_int16()
width, height, xoff, yoff, inter, flags\
- = self.source.read_struct('hhhhhh')
+ = self.source.read_struct('hhhhhh')
bbox = self.get_rectangle()
reserved, res, max_edge = self.source.read_struct('blh')
lib = self.get_string()
@@ -1144,8 +1144,8 @@
params = []
for i in range(count):
params.append(self.source.read_struct('hhhh'))
-
- self._print('full-color: function %d\n', function)
+
+ self._print('full-color: function %d\n', function)
self._print(' size (%d, %d), off (%d, %d), inter %d, '
'flags %x\n',
width, height, xoff, yoff, inter, 0) #flags)
@@ -1157,10 +1157,10 @@
self._print(' params:\n')
for param in params:
self._print(' %s\n', param)
- self.warn(_("fill type 'texture' not implemented, "
+ self.warn(_("fill type 'texture' not implemented, "
"using solid black"))
style.fill_pattern = SolidPattern(StandardColors.black)
- else:
+ else:
if fill <= 8:
name = ('NoFill', 'Uniform', 'Fountain', 'PostScript',
'TwoColorPattern', 'Monochrom/Transparent',
@@ -1172,97 +1172,97 @@
self.warn(_("fill type %d not implemented, using solid black")
% fill)
style.fill_pattern = SolidPattern(StandardColors.black)
- else:
- style.fill_pattern = EmptyPattern
+ else:
+ style.fill_pattern = EmptyPattern
- if mask & 0x02: # line attrs
- outline = self.get_int16()
+ if mask & 0x02: # line attrs
+ outline = self.get_int16()
#print outline
- outline = self.cmxfile.outlines[outline]
- spec, cap, join = outline.style
- if spec & 1: # the none bit is set. no outline
- style.line_pattern = EmptyPattern
- else:
- style.line_pattern = SolidPattern(outline.color)
- style.line_width = abs(outline.pen[0] * self.factor)
- style.line_cap = cap + 1
- style.line_join = join
- if spec & 0x04: # dash dot
- style.line_dashes = outline.dashes
- else:
- style.line_dashes = ()
- # XXX whats the precise meaning of the dash-dot flag and
- # the solid outline flag?
- else:
- style.line_pattern = EmptyPattern
+ outline = self.cmxfile.outlines[outline]
+ spec, cap, join = outline.style
+ if spec & 1: # the none bit is set. no outline
+ style.line_pattern = EmptyPattern
+ else:
+ style.line_pattern = SolidPattern(outline.color)
+ style.line_width = abs(outline.pen[0] * self.factor)
+ style.line_cap = cap + 1
+ style.line_join = join
+ if spec & 0x04: # dash dot
+ style.line_dashes = outline.dashes
+ else:
+ style.line_dashes = ()
+ # XXX whats the precise meaning of the dash-dot flag and
+ # the solid outline flag?
+ else:
+ style.line_pattern = EmptyPattern
- if mask & 0x04: # lens attributes
- #self._print(" can't handle lens\n")
- raise TypeError, "can't handle lens"
+ if mask & 0x04: # lens attributes
+ #self._print(" can't handle lens\n")
+ raise TypeError, "can't handle lens"
- if mask & 0x08: # canvas
- #self._print(" can't handle canvas\n")
- raise TypeError, "can't handle canvas"
+ if mask & 0x08: # canvas
+ #self._print(" can't handle canvas\n")
+ raise TypeError, "can't handle canvas"
- if mask & 0x10: # container
- #self._print(" can't handle container\n")
- raise TypeError, "can't handle container"
+ if mask & 0x10: # container
+ #self._print(" can't handle container\n")
+ raise TypeError, "can't handle container"
def PolyCurve(self):
- get_struct = self.source.read_struct; trafo = self.trafo
- self.get_rendering_attrs()
- count = self.get_int16()
- self._print(' %d points\n', count)
- points = [];
+ get_struct = self.source.read_struct; trafo = self.trafo
+ self.get_rendering_attrs()
+ count = self.get_int16()
+ self._print(' %d points\n', count)
+ points = [];
coords = get_struct(count * 'ii')
append = points.append
for i in range(0, 2 * count, 2):
append(trafo(coords[i], coords[i + 1]))
- nodes = map(ord, self.get_bytes(count))
- if len(nodes) != len(points):
- self._print('lengths of nodes and points differ\n')
- bbox = self.get_rectangle()
+ nodes = map(ord, self.get_bytes(count))
+ if len(nodes) != len(points):
+ self._print('lengths of nodes and points differ\n')
+ bbox = self.get_rectangle()
- self._print(' bounding box: %s\n\n', bbox)
+ self._print(' bounding box: %s\n\n', bbox)
- path = None
- paths = []
- close = 0; i = 0
- while i < count:
- node = nodes[i]
- p = points[i]
- type = (node & 0xC0) >> 6
- if type == 0:
- if close and path is not None:
- path.load_close(1)
- close = node & 0x08
- path = CreatePath()
- paths.append(path)
- path.AppendLine(p, (node & 0x30) >> 4)
- elif type == 1:
- path.AppendLine(p, (node & 0x30) >> 4)
- elif type == 3:
- path.AppendBezier(p, points[i + 1], points[i + 2],
- (nodes[i + 2] & 0x30) >> 4)
+ path = None
+ paths = []
+ close = 0; i = 0
+ while i < count:
+ node = nodes[i]
+ p = points[i]
+ type = (node & 0xC0) >> 6
+ if type == 0:
+ if close and path is not None:
+ path.load_close(1)
+ close = node & 0x08
+ path = CreatePath()
+ paths.append(path)
+ path.AppendLine(p, (node & 0x30) >> 4)
+ elif type == 1:
+ path.AppendLine(p, (node & 0x30) >> 4)
+ elif type == 3:
+ path.AppendBezier(p, points[i + 1], points[i + 2],
+ (nodes[i + 2] & 0x30) >> 4)
i = i + 2
i = i + 1
- if close:
- path.load_close(1)
- for i in range(len(paths) - 1, -1, -1):
- path = paths[i]
- if path.len == 0:
- #print 'empty path %d deleted' % i
- del paths[i]
+ if close:
+ path.load_close(1)
+ for i in range(len(paths) - 1, -1, -1):
+ path = paths[i]
+ if path.len == 0:
+ #print 'empty path %d deleted' % i
+ del paths[i]
- if paths:
- self.loader.bezier(tuple(paths))
- else:
- self.get_prop_stack()
+ if paths:
+ self.loader.bezier(tuple(paths))
+ else:
+ self.get_prop_stack()
def JumpAbsolute(self):
return self.get_int32()
-
+
class CMXInterpreter32(CMXInterpreter):
def BeginPage(self):
@@ -1299,7 +1299,7 @@
self.pop_source()
def BeginLayer(self):
- fmt = ' % 11s: %s\n'
+ fmt = ' % 11s: %s\n'
tag = -1
while tag != 255:
tag = self.get_tag()
@@ -1307,7 +1307,7 @@
try:
if tag == 1:
page_number, layer_number, flags, tally \
- = self.source.read_struct('hhll')
+ = self.source.read_struct('hhll')
layer_name = self.get_string()
self._print(fmt, 'LayerName', layer_name)
self._print(fmt, 'LayerNumber', layer_number)
@@ -1329,11 +1329,11 @@
self._print(' no mapping\n')
finally:
self.pop_source()
- # start layer
- self.loader.layer(self.layer_prefix + layer_name, 1, 1, 0, 0, (0,0,0))
+ # start layer
+ self.loader.layer(self.layer_prefix + layer_name, 1, 1, 0, 0, (0,0,0))
def BeginGroup(self):
- fmt = ' % 10s: %s\n'
+ fmt = ' % 10s: %s\n'
tag = -1
while tag != 255:
tag = self.get_tag()
@@ -1346,36 +1346,36 @@
self._print(fmt, 'Tally', tally)
finally:
self.pop_source()
- # start group
- self.loader.begin_group()
+ # start group
+ self.loader.begin_group()
def get_rendering_attrs(self):
- self._print(' Rendering Attributes:\n')
- style = self.loader.style
- mask = self.get_byte()
-
- if mask & 0x01: # fill attrs
- self._print(' Fill:')
+ self._print(' Rendering Attributes:\n')
+ style = self.loader.style
+ mask = self.get_byte()
+
+ if mask & 0x01: # fill attrs
+ self._print(' Fill:')
self.get_fill(style)
else:
style.fill_pattern = EmptyPattern
- if mask & 0x02: # line attrs
+ if mask & 0x02: # line attrs
self.get_outline(style)
- else:
- style.line_pattern = EmptyPattern
+ else:
+ style.line_pattern = EmptyPattern
- if mask & 0x04: # lens attributes
- self.warn(_("Lens specification ignored"))
+ if mask & 0x04: # lens attributes
+ self.warn(_("Lens specification ignored"))
self.skip_tags()
#self.get_lens()
- if mask & 0x08: # canvas (XXX what is that, actually?)
- self.warn(_("Canvas specification ignored"))
+ if mask & 0x08: # canvas (XXX what is that, actually?)
+ self.warn(_("Canvas specification ignored"))
self.skip_tags() # ?
- if mask & 0x10: # container
- #self.warn("Container specification ignored")
+ if mask & 0x10: # container
+ #self.warn("Container specification ignored")
stack = self.loader.get_prop_stack()
self.get_container()
self.loader.set_prop_stack(stack)
@@ -1438,9 +1438,9 @@
fountain, screen, padding = self.source.read_struct('hhh')
angle = self.get_angle()
xoff, yoff, steps, mode, rate_method, rate_value \
- = self.source.read_struct('iihhhh')
+ = self.source.read_struct('iihhhh')
self._print('fountain: %s pad %d angle %f off %d %d\n',
- ('linear','radial','conical','square')[fountain],
+ ('linear','radial','conical','square')[fountain],
padding, angle, xoff, yoff)
self._print(' steps %d mode %s\n', steps,
('RGB', 'HSB_CW', 'HSB_CCW', 'Custom')[mode])
@@ -1498,7 +1498,7 @@
"not 1 bit deep"))
width, height, xoff, yoff, inter, flags = self.get_tiling()
background, foreground, screen \
- = self.source.read_struct('hhh')
+ = self.source.read_struct('hhh')
self._print(' foreground %s, background %s,'
' screen %d\n',
self.cmxfile.colors[foreground],
@@ -1533,7 +1533,7 @@
procedure = self.get_int16()
self._print('Color image procedure %d\n', procedure)
width, height, xoff, yoff, inter, flags = self.get_tiling()
-
+
stack = self.loader.get_prop_stack()
self.execute_procedure(procedure)
self.loader.set_prop_stack(stack)
@@ -1630,12 +1630,12 @@
paths = self.read_pointlist()
self.pop_trafo()
self.pop_source()
-
+
arrow = Arrow(paths[0])
self.cmxfile.arrowindex[index] = arrow
return arrow
-
+
def get_container(self):
verbosity = self.cmxfile.verbosity
self.cmxfile.verbosity = 0
@@ -1689,50 +1689,50 @@
self.loader.fix_lens = args
def read_pointlist(self):
- get_struct = self.source.read_struct; trafo = self.trafo
- count = self.get_int16()
- self._print('pointlist: %d points\n', count)
- points = [];
+ get_struct = self.source.read_struct; trafo = self.trafo
+ count = self.get_int16()
+ self._print('pointlist: %d points\n', count)
+ points = [];
coords = get_struct(count * 'ii')
append = points.append
for i in range(0, 2 * count, 2):
append(trafo(coords[i], coords[i + 1]))
- nodes = map(ord, self.get_bytes(count))
- if len(nodes) != len(points):
- self._print('lengths of nodes and points differ\n')
+ nodes = map(ord, self.get_bytes(count))
+ if len(nodes) != len(points):
+ self._print('lengths of nodes and points differ\n')
- path = None
- paths = []
- close = 0; i = 0
- while i < count:
- node = nodes[i]
- p = points[i]
- type = (node & 0xC0) >> 6
- if type == 0:
- if close and path is not None:
- path.load_close(1)
- close = node & 0x08
- path = CreatePath()
- paths.append(path)
- path.AppendLine(p, (node & 0x30) >> 4)
- elif type == 1:
- path.AppendLine(p, (node & 0x30) >> 4)
- elif type == 3:
- path.AppendBezier(p, points[i + 1], points[i + 2],
- (nodes[i + 2] & 0x30) >> 4)
+ path = None
+ paths = []
+ close = 0; i = 0
+ while i < count:
+ node = nodes[i]
+ p = points[i]
+ type = (node & 0xC0) >> 6
+ if type == 0:
+ if close and path is not None:
+ path.load_close(1)
+ close = node & 0x08
+ path = CreatePath()
+ paths.append(path)
+ path.AppendLine(p, (node & 0x30) >> 4)
+ elif type == 1:
+ path.AppendLine(p, (node & 0x30) >> 4)
+ elif type == 3:
+ path.AppendBezier(p, points[i + 1], points[i + 2],
+ (nodes[i + 2] & 0x30) >> 4)
i = i + 2
i = i + 1
- if close:
- path.load_close(1)
- for i in range(len(paths) - 1, -1, -1):
- path = paths[i]
- if path.len == 0:
- #print 'empty path %d deleted' % i
- del paths[i]
+ if close:
+ path.load_close(1)
+ for i in range(len(paths) - 1, -1, -1):
+ path = paths[i]
+ if path.len == 0:
+ #print 'empty path %d deleted' % i
+ del paths[i]
return tuple(paths)
-
+
def PolyCurve(self):
# We do the tag handling 'manually' here because the file format
# is broken for very long point lists. The CMX format has
@@ -1812,8 +1812,8 @@
finally:
if tag != 255:
self.pop_source()
-
-
+
+
def JumpAbsolute(self):
tag = -1
while tag != 255:
@@ -1828,7 +1828,7 @@
class CMXLoader(GenericLoader):
def __init__(self, file, filename, match):
- GenericLoader.__init__(self, file, filename, match)
+ GenericLoader.__init__(self, file, filename, match)
self.fix_tile = None
self.fix_clip = 0
self.fix_lens = ()
@@ -1895,4 +1895,4 @@
object = MaskGroup(objects)
self.fix_lens = ()
GenericLoader.append_object(self, object)
-
+
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/pdfgensaver.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/pdfgensaver.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/pdfgensaver.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -72,7 +72,7 @@
def Scale(self, scale):
self.pdf.scale(scale, scale)
-
+
def PopTrafo(self):
self.pdf.restoreState()
@@ -251,7 +251,7 @@
self.draw_arrow(arrow1, t1)
if arrow2 and t2 is not None:
self.draw_arrow(arrow2, t2)
-
+
def draw_arrow(self, arrow, trafo):
path = arrow.Paths()[0].Duplicate()
path.Transform(trafo)
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/skloader.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/skloader.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/skloader.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -60,16 +60,16 @@
# sanity check: does base_style have all properties?
for key in dir(properties.factory_defaults):
if not hasattr(base_style, key):
- warn(INTERNAL, 'added default for property %s', key)
- setattr(base_style, key,
+ warn(INTERNAL, 'added default for property %s', key)
+ setattr(base_style, key,
getattr(properties.factory_defaults, key))
papersizes = [# 'A0', 'A1', 'A2',
- 'A3', 'A4', 'A5', 'A6', 'A7',
- 'letter', 'legal', 'executive',
- ]
+ 'A3', 'A4', 'A5', 'A6', 'A7',
+ 'letter', 'legal', 'executive',
+ ]
-
+
class SKLoader(GenericLoader):
format_name = format_name
@@ -77,49 +77,49 @@
base_style = base_style
functions = ['document', 'layer', ('bezier', 'b'), ('rectangle', 'r'),
- ('ellipse', 'e'),
- 'group', ('group', 'G'), 'endgroup', ('endgroup', 'G_'),
- 'guess_cont']
+ ('ellipse', 'e'),
+ 'group', ('group', 'G'), 'endgroup', ('endgroup', 'G_'),
+ 'guess_cont']
def __init__(self, file, filename, match):
- GenericLoader.__init__(self, file, filename, match)
+ GenericLoader.__init__(self, file, filename, match)
if atoi(match.group('minor')) > 2:
self.add_message(_("The file was created by a newer version of "
- "Skencil or Sketch, there might be inaccuracies."))
- if self.filename:
- self.directory = os.path.split(filename)[0]
- else:
- self.directory = ''
- self.style_dict = {}
- self.id_dict = {}
- self.page_layout = None
- self.pattern = None
- self.gradient = None
- self.arrow1 = None
- self.arrow2 = None
- self.font = None
- self.font_size = 1.0
- self.color_cache = {}
+ "Skencil or Sketch, there might be inaccuracies."))
+ if self.filename:
+ self.directory = os.path.split(filename)[0]
+ else:
+ self.directory = ''
+ self.style_dict = {}
+ self.id_dict = {}
+ self.page_layout = None
+ self.pattern = None
+ self.gradient = None
+ self.arrow1 = None
+ self.arrow2 = None
+ self.font = None
+ self.font_size = 1.0
+ self.color_cache = {}
def __del__(self):
- pass
+ pass
def warn(self, level, *args, **kw):
- message = apply(warn, (level,) + args, kw)
- self.add_message(message)
+ message = apply(warn, (level,) + args, kw)
+ self.add_message(message)
def get_func_dict(self):
- func_dict = {}
- for name in self.functions:
- if type(name) == StringType:
- func_dict[name] = getattr(self, name)
- else:
- func_dict[name[1]] = getattr(self, name[0])
- return func_dict
+ func_dict = {}
+ for name in self.functions:
+ if type(name) == StringType:
+ func_dict[name] = getattr(self, name)
+ else:
+ func_dict[name[1]] = getattr(self, name[0])
+ return func_dict
functions.append('layout')
def layout(self, format, orientation):
- if type(format) == StringType:
+ if type(format) == StringType:
if format not in papersizes:
# The format is given by name but it's not one of the
# standard papersizes. The file may be corrupted.
@@ -127,113 +127,113 @@
"using A4 instead") % format)
format = "A4"
layout = pagelayout.PageLayout(format, orientation=orientation)
- else:
- w, h = format
- layout = pagelayout.PageLayout(width = w, height = h,
- orientation = orientation)
- self.page_layout = layout
+ else:
+ w, h = format
+ layout = pagelayout.PageLayout(width = w, height = h,
+ orientation = orientation)
+ self.page_layout = layout
functions.append('grid')
def grid(self, geometry, visible = 0, color = None, name = None):
if name is None:
name = _("Grid")
- self.begin_layer_class(GridLayer,
- (geometry, visible, self.convert_color(color),
- name))
- self.end_composite()
+ self.begin_layer_class(GridLayer,
+ (geometry, visible, self.convert_color(color),
+ name))
+ self.end_composite()
def convert_color(self, color_spec):
- try:
- c = self.color_cache.get(color_spec)
- if c:
- return c
- c = apply(CreateRGBColor, color_spec)
- self.color_cache[color_spec] = c
- except:
- # This should only happen if the color_spec is invalid
- type, value = sys.exc_info()[:2]
- warn(INTERNAL, 'Color allocation failed: %s: %s', type, value)
- c = StandardColors.black
- return c
+ try:
+ c = self.color_cache.get(color_spec)
+ if c:
+ return c
+ c = apply(CreateRGBColor, color_spec)
+ self.color_cache[color_spec] = c
+ except:
+ # This should only happen if the color_spec is invalid
+ type, value = sys.exc_info()[:2]
+ warn(INTERNAL, 'Color allocation failed: %s: %s', type, value)
+ c = StandardColors.black
+ return c
functions.append('gl')
def gl(self, colors):
- c = []
- for pos, color in colors:
- c.append((pos, self.convert_color(color)))
- self.gradient = MultiGradient(c)
+ c = []
+ for pos, color in colors:
+ c.append((pos, self.convert_color(color)))
+ self.gradient = MultiGradient(c)
functions.append('pe')
def pe(self):
- self.pattern = EmptyPattern
+ self.pattern = EmptyPattern
functions.append('ps')
def ps(self, color):
- self.pattern = SolidPattern(self.convert_color(color))
+ self.pattern = SolidPattern(self.convert_color(color))
functions.append('pgl')
def pgl(self, dx, dy, border = 0):
- if not self.gradient:
- raise SketchLoadError(_("No gradient for gradient pattern"))
- self.pattern = LinearGradient(self.gradient, Point(dx, dy), border)
+ if not self.gradient:
+ raise SketchLoadError(_("No gradient for gradient pattern"))
+ self.pattern = LinearGradient(self.gradient, Point(dx, dy), border)
functions.append('pgr')
def pgr(self, dx, dy, border = 0):
- if not self.gradient:
- raise SketchLoadError(_("No gradient for gradient pattern"))
- self.pattern = RadialGradient(self.gradient, Point(dx, dy), border)
+ if not self.gradient:
+ raise SketchLoadError(_("No gradient for gradient pattern"))
+ self.pattern = RadialGradient(self.gradient, Point(dx, dy), border)
functions.append('pgc')
def pgc(self, cx, cy, dx, dy):
- if not self.gradient:
- raise SketchLoadError(_("No gradient for gradient pattern"))
- self.pattern = ConicalGradient(self.gradient,
- Point(cx, cy), Point(dx, dy))
+ if not self.gradient:
+ raise SketchLoadError(_("No gradient for gradient pattern"))
+ self.pattern = ConicalGradient(self.gradient,
+ Point(cx, cy), Point(dx, dy))
functions.append('phs')
def phs(self, color, background, dx, dy, dist, width):
- self.pattern = HatchingPattern(self.convert_color(color),
- self.convert_color(background),
- Point(dx, dy), dist, width)
+ self.pattern = HatchingPattern(self.convert_color(color),
+ self.convert_color(background),
+ Point(dx, dy), dist, width)
functions.append('pit')
def pit(self, id, trafo):
trafo = apply(Trafo, trafo)
- self.pattern = ImageTilePattern(self.id_dict[id], trafo)
+ self.pattern = ImageTilePattern(self.id_dict[id], trafo)
functions.append('fp')
def fp(self, color = None):
- if color is None:
- self.style.fill_pattern = self.pattern
- else:
- self.style.fill_pattern = SolidPattern(self.convert_color(color))
+ if color is None:
+ self.style.fill_pattern = self.pattern
+ else:
+ self.style.fill_pattern = SolidPattern(self.convert_color(color))
functions.append('fe')
def fe(self):
- self.style.fill_pattern = EmptyPattern
+ self.style.fill_pattern = EmptyPattern
functions.append('ft')
def ft(self, bool):
- self.style.fill_transform = bool
+ self.style.fill_transform = bool
functions.append('lp')
def lp(self, color = None):
- if color is None:
- self.style.line_pattern = self.pattern
- else:
- self.style.line_pattern = SolidPattern(self.convert_color(color))
+ if color is None:
+ self.style.line_pattern = self.pattern
+ else:
+ self.style.line_pattern = SolidPattern(self.convert_color(color))
functions.append('le')
def le(self):
- self.style.line_pattern = EmptyPattern
+ self.style.line_pattern = EmptyPattern
functions.append('lw')
def lw(self, width):
- self.style.line_width = width
+ self.style.line_width = width
functions.append('lj')
def lj(self, join):
- self.style.line_join = join
+ self.style.line_join = join
functions.append('lc')
def lc(self, cap):
@@ -244,153 +244,153 @@
functions.append('ld')
def ld(self, dashes):
- self.style.line_dashes = dashes
+ self.style.line_dashes = dashes
functions.append('la1')
def la1(self, args = None):
- if args is not None:
- self.style.line_arrow1 = apply(Arrow, args)
- else:
- self.style.line_arrow1 = None
+ if args is not None:
+ self.style.line_arrow1 = apply(Arrow, args)
+ else:
+ self.style.line_arrow1 = None
functions.append('la2')
def la2(self, args = None):
- if args is not None:
- self.style.line_arrow2 = apply(Arrow, args)
- else:
- self.style.line_arrow2 = None
+ if args is not None:
+ self.style.line_arrow2 = apply(Arrow, args)
+ else:
+ self.style.line_arrow2 = None
functions.append('dstyle')
def dstyle(self, name = ''):
- if not name:
- raise SketchLoadError(_("unnamed style"))
- style = self.style.AsDynamicStyle()
- style.SetName(name)
- self.style_dict[name] = style
- self.style = Style()
+ if not name:
+ raise SketchLoadError(_("unnamed style"))
+ style = self.style.AsDynamicStyle()
+ style.SetName(name)
+ self.style_dict[name] = style
+ self.style = Style()
functions.append(('use_style', 'style'))
def use_style(self, name = ''):
- if not name:
- raise SketchLoadError(_("unnamed style"))
- if not self.style.IsEmpty():
- self.prop_stack.load_AddStyle(self.style)
- self.style = Style()
- style = self.style_dict[name]
- self.prop_stack.load_AddStyle(style)
+ if not name:
+ raise SketchLoadError(_("unnamed style"))
+ if not self.style.IsEmpty():
+ self.prop_stack.load_AddStyle(self.style)
+ self.style = Style()
+ style = self.style_dict[name]
+ self.prop_stack.load_AddStyle(style)
functions.append('Fn')
def Fn(self, name):
- self.style.font = GetFont(name)
+ self.style.font = GetFont(name)
functions.append('Fs')
def Fs(self, size):
- self.style.font_size = size
+ self.style.font_size = size
functions.append('guide')
def guide(self, pos, horizontal):
- if horizontal:
- p = Point(0, pos)
- else:
- p = Point(pos, 0)
- self.append_object(GuideLine(p, horizontal))
+ if horizontal:
+ p = Point(0, pos)
+ else:
+ p = Point(pos, 0)
+ self.append_object(GuideLine(p, horizontal))
functions.append('guidelayer')
def guidelayer(self, *args, **kw):
- self.begin_layer_class(GuideLayer, args, kw)
+ self.begin_layer_class(GuideLayer, args, kw)
def bezier_load(self, line):
- bezier = self.object
- while 1:
- try:
- bezier.paths[-1].append_from_string(line)
- line = bezier.paths[-1].append_from_file(self.file)
- except:
- warn(INTERNAL, _("Error reading line %s"), `line`)
- line = self.file.readline()
- if line[:2] == 'bC':
- bezier.paths[-1].load_close()
- line = self.file.readline()
- if line[:2] == 'bn':
- bezier.paths = bezier.paths + (CreatePath(),)
- line = self.file.readline()
- else:
- break
- if line[:2] not in ('bs', 'bc'):
- break
- return line
+ bezier = self.object
+ while 1:
+ try:
+ bezier.paths[-1].append_from_string(line)
+ line = bezier.paths[-1].append_from_file(self.file)
+ except:
+ warn(INTERNAL, _("Error reading line %s"), `line`)
+ line = self.file.readline()
+ if line[:2] == 'bC':
+ bezier.paths[-1].load_close()
+ line = self.file.readline()
+ if line[:2] == 'bn':
+ bezier.paths = bezier.paths + (CreatePath(),)
+ line = self.file.readline()
+ else:
+ break
+ if line[:2] not in ('bs', 'bc'):
+ break
+ return line
functions.append('txt')
def txt(self, thetext, trafo, halign = text.ALIGN_LEFT,
- valign = text.ALIGN_BASE):
- if len(trafo) == 2:
- trafo = Translation(trafo)
- else:
- trafo = apply(Trafo, trafo)
- object = text.SimpleText(text = thetext, trafo = trafo,
- halign = halign, valign = valign,
- properties = self.get_prop_stack())
- self.append_object(object)
+ valign = text.ALIGN_BASE):
+ if len(trafo) == 2:
+ trafo = Translation(trafo)
+ else:
+ trafo = apply(Trafo, trafo)
+ object = text.SimpleText(text = thetext, trafo = trafo,
+ halign = halign, valign = valign,
+ properties = self.get_prop_stack())
+ self.append_object(object)
functions.append('im')
def im(self, trafo, id):
- if len(trafo) == 2:
- trafo = Translation(trafo)
- else:
- trafo = apply(Trafo, trafo)
- self.append_object(image.Image(self.id_dict[id], trafo = trafo))
+ if len(trafo) == 2:
+ trafo = Translation(trafo)
+ else:
+ trafo = apply(Trafo, trafo)
+ self.append_object(image.Image(self.id_dict[id], trafo = trafo))
functions.append('bm')
def bm(self, id, filename = None):
- if filename is None:
- from streamfilter import Base64Decode, SubFileDecode
- decoder = Base64Decode(SubFileDecode(self.file, '-'))
- data = image.load_image(decoder)
- else:
+ if filename is None:
+ from streamfilter import Base64Decode, SubFileDecode
+ decoder = Base64Decode(SubFileDecode(self.file, '-'))
+ data = image.load_image(decoder)
+ else:
data = image.load_image(os.path.join(self.directory, filename))
- self.id_dict[id] = data
+ self.id_dict[id] = data
functions.append('eps')
def eps(self, trafo, filename):
- if len(trafo) == 2:
- trafo = Translation(trafo)
- else:
- trafo = apply(Trafo, trafo)
- if not os.path.isabs(filename):
- if self.directory:
- filename = os.path.join(self.directory, filename)
- else:
- filename = os.path.join(os.getcwd(), filename)
- self.append_object(eps.EpsImage(filename = filename, trafo = trafo))
+ if len(trafo) == 2:
+ trafo = Translation(trafo)
+ else:
+ trafo = apply(Trafo, trafo)
+ if not os.path.isabs(filename):
+ if self.directory:
+ filename = os.path.join(self.directory, filename)
+ else:
+ filename = os.path.join(os.getcwd(), filename)
+ self.append_object(eps.EpsImage(filename = filename, trafo = trafo))
functions.append('B')
def B(self, *args, **kw):
- self.begin_composite(blendgroup.BlendGroup, args, kw)
+ self.begin_composite(blendgroup.BlendGroup, args, kw)
functions.append('B_')
def B_(self):
- self.end_composite()
+ self.end_composite()
functions.append('Bi')
def Bi(self, *args, **kw):
- self.begin_composite(blendgroup.BlendInterpolation, args, kw)
- self.end_composite()
+ self.begin_composite(blendgroup.BlendInterpolation, args, kw)
+ self.end_composite()
group = GenericLoader.begin_group
endgroup = GenericLoader.end_group
functions.append('M')
def M(self, *args, **kw):
- from Sketch.Graphics import maskgroup
- self.begin_composite(maskgroup.MaskGroup, args, kw)
+ from Sketch.Graphics import maskgroup
+ self.begin_composite(maskgroup.MaskGroup, args, kw)
functions.append('M_')
def M_(self):
- self.end_composite()
+ self.end_composite()
functions.append('PT')
def PT(self, *args, **kw):
- self.begin_composite(text.PathText, args, kw)
+ self.begin_composite(text.PathText, args, kw)
functions.append('pt')
def pt(self, thetext, *args):
@@ -406,66 +406,66 @@
if len(args) > 1:
start_pos = args[1]
- if matrix:
- trafo = apply(Trafo, matrix)
- else:
- trafo = None
+ if matrix:
+ trafo = apply(Trafo, matrix)
+ else:
+ trafo = None
- self.append_object(text.InternalPathText(thetext, trafo = trafo,
- model = model,
+ self.append_object(text.InternalPathText(thetext, trafo = trafo,
+ model = model,
start_pos = start_pos,
- properties = self.get_prop_stack()))
+ properties = self.get_prop_stack()))
functions.append('PT_')
def PT_(self):
- self.end_composite()
+ self.end_composite()
functions.append('PC')
def PC(self, class_name, *args, **kw):
kw['loading'] = 1
- info = plugins.find_object_plugin(class_name)
- if info is not None:
- try:
- theclass = info.Constructor()
- self.begin_composite(theclass, args, kw)
- return
- except SketchError:
- pass
- # constructing the plugin object failed. Use an UnknownPlugin
- # object.
- self.add_message(_("Unknown Plugin: %s") % class_name)
- self.begin_composite(plugobj.UnknownPlugin, (class_name,) + args, kw)
+ info = plugins.find_object_plugin(class_name)
+ if info is not None:
+ try:
+ theclass = info.Constructor()
+ self.begin_composite(theclass, args, kw)
+ return
+ except SketchError:
+ pass
+ # constructing the plugin object failed. Use an UnknownPlugin
+ # object.
+ self.add_message(_("Unknown Plugin: %s") % class_name)
+ self.begin_composite(plugobj.UnknownPlugin, (class_name,) + args, kw)
functions.append('PC_')
def PC_(self):
- self.end_composite()
+ self.end_composite()
#
# The loader driver
#
def Load(self):
- file = self.file
- if type(file) == StringType:
- file = open(file, 'r')
- dict = self.get_func_dict()
- from Sketch import skread
- parse = skread.parse_sk_line2
- readline = file.readline
- bezier_load = self.bezier_load
- num = 1
- line = '#'
- if __debug__:
- import time
- start_time = time.clock()
- try:
- line = readline()
- while line:
- num = num + 1
- if line[0] == 'b' and line[1] in 'sc':
- line = bezier_load(line)
- continue
- #parse(line, dict)
+ file = self.file
+ if type(file) == StringType:
+ file = open(file, 'r')
+ dict = self.get_func_dict()
+ from Sketch import skread
+ parse = skread.parse_sk_line2
+ readline = file.readline
+ bezier_load = self.bezier_load
+ num = 1
+ line = '#'
+ if __debug__:
+ import time
+ start_time = time.clock()
+ try:
+ line = readline()
+ while line:
+ num = num + 1
+ if line[0] == 'b' and line[1] in 'sc':
+ line = bezier_load(line)
+ continue
+ #parse(line, dict)
funcname, args, kwargs = parse(line)
if funcname is not None:
function = dict.get(funcname)
@@ -494,38 +494,38 @@
del tb
else:
self.add_message(_("Unknown function %s") % funcname)
-
- line = readline()
- except (SketchLoadError, SyntaxError), value:
- # a loader specific error occurred
+ line = readline()
+
+ except (SketchLoadError, SyntaxError), value:
+ # a loader specific error occurred
warn_tb(INTERNAL, 'error in line %d', num)
- if load._dont_handle_exceptions:
- raise
- else:
- raise SketchLoadError('%d:%s' % (num, value))
- except:
- # An exception was not converted to a SketchLoadError.
- # This should be considered a bug.
+ if load._dont_handle_exceptions:
+ raise
+ else:
+ raise SketchLoadError('%d:%s' % (num, value))
+ except:
+ # An exception was not converted to a SketchLoadError.
+ # This should be considered a bug.
warn_tb(INTERNAL, 'error in line %d:\n%s', num, `line`)
- if load._dont_handle_exceptions:
- raise
- else:
- raise SketchLoadError(_("error %s:%s in line %d:\n%s")
- % (sys.exc_info()[:2] +(num, `line`)))
+ if load._dont_handle_exceptions:
+ raise
+ else:
+ raise SketchLoadError(_("error %s:%s in line %d:\n%s")
+ % (sys.exc_info()[:2] +(num, `line`)))
- self.end_all()
- if self.page_layout:
- self.object.load_SetLayout(self.page_layout)
- for style in self.style_dict.values():
- self.object.load_AddStyle(style)
- self.object.load_Completed()
+ self.end_all()
+ if self.page_layout:
+ self.object.load_SetLayout(self.page_layout)
+ for style in self.style_dict.values():
+ self.object.load_AddStyle(style)
+ self.object.load_Completed()
- self.object.meta.native_format = 1
+ self.object.meta.native_format = 1
- if __debug__:
- pdebug('timing', 'time:', time.clock() - start_time)
- return self.object
+ if __debug__:
+ pdebug('timing', 'time:', time.clock() - start_time)
+ return self.object
def call_function(function, args, kwargs):
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/sksaver.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/sksaver.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/sksaver.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -264,15 +264,15 @@
# 'A0': (0.841 * m_to_pt, 1.189 * m_to_pt),
# 'A1': (0.594 * m_to_pt, 0.841 * m_to_pt),
# 'A2': (0.420 * m_to_pt, 0.594 * m_to_pt),
- 'A3': (0.297 * m_to_pt, 0.420 * m_to_pt),
- 'A4': (0.210 * m_to_pt, 0.297 * m_to_pt),
- 'A5': (0.148 * m_to_pt, 0.210 * m_to_pt),
- 'A6': (0.105 * m_to_pt, 0.148 * m_to_pt),
- 'A7': (0.074 * m_to_pt, 0.105 * m_to_pt),
- 'letter': (8.5 * in_to_pt, 11 * in_to_pt),
- 'legal': (8.5 * in_to_pt, 14 * in_to_pt),
- 'executive': (7.25 * in_to_pt, 10.5 * in_to_pt)
- }
+'A3': (0.297 * m_to_pt, 0.420 * m_to_pt),
+'A4': (0.210 * m_to_pt, 0.297 * m_to_pt),
+'A5': (0.148 * m_to_pt, 0.210 * m_to_pt),
+'A6': (0.105 * m_to_pt, 0.148 * m_to_pt),
+'A7': (0.074 * m_to_pt, 0.105 * m_to_pt),
+'letter': (8.5 * in_to_pt, 11 * in_to_pt),
+'legal': (8.5 * in_to_pt, 14 * in_to_pt),
+'executive': (7.25 * in_to_pt, 10.5 * in_to_pt)
+}
class SketchSaveError(SketchError):
@@ -286,108 +286,108 @@
class SKSaver:
def __init__(self, file, filename, kw):
- self.file = file
- self.filename = filename
- if self.filename:
- self.directory = os.path.split(filename)[0]
- else:
- self.directory = ''
- self.style_dict = {}
- self.write_header()
- options = default_options.copy()
- options.update(kw)
- self.options = apply(Empty, (), options)
- self.saved_ids = {}
+ self.file = file
+ self.filename = filename
+ if self.filename:
+ self.directory = os.path.split(filename)[0]
+ else:
+ self.directory = ''
+ self.style_dict = {}
+ self.write_header()
+ options = default_options.copy()
+ options.update(kw)
+ self.options = apply(Empty, (), options)
+ self.saved_ids = {}
def __del__(self):
- self.Close()
+ self.Close()
def Close(self):
pass
- #if not self.file.closed:
- # self.file.close()
+ #if not self.file.closed:
+ # self.file.close()
def write_header(self):
- self.file.write('##Sketch 1 2\n')
+ self.file.write('##Sketch 1 2\n')
def BeginDocument(self):
- self.file.write('document()\n')
+ self.file.write('document()\n')
def EndDocument(self):
- pass
+ pass
def BeginLayer(self, name, visible, printable, locked, outlined, color):
- self.file.write('layer(%s,%d,%d,%d,%d,%s)\n'
- % (`name`, visible, printable, locked, outlined,
- color_repr(color)))
+ self.file.write('layer(%s,%d,%d,%d,%d,%s)\n'
+ % (`name`, visible, printable, locked, outlined,
+ color_repr(color)))
def EndLayer(self):
- pass
+ pass
def BeginGuideLayer(self, name, visible, printable, locked, outlined,
- color):
- self.file.write('guidelayer(%s,%d,%d,%d,%d,%s)\n'
- % (`name`, visible, printable, locked, outlined,
- color_repr(color)))
+ color):
+ self.file.write('guidelayer(%s,%d,%d,%d,%d,%s)\n'
+ % (`name`, visible, printable, locked, outlined,
+ color_repr(color)))
EndGuideLayer = EndLayer
def BeginGridLayer(self, geometry, visible, outline_color, name):
- self.file.write('grid((%g,%g,%g,%g),%d,%s,%s)\n'
- % (geometry
- + (visible, color_repr(outline_color), `name`)))
+ self.file.write('grid((%g,%g,%g,%g),%d,%s,%s)\n'
+ % (geometry
+ + (visible, color_repr(outline_color), `name`)))
EndGridLayer = EndLayer
def PageLayout(self, format, width, height, orientation):
- if format and papersizes.has_key(format):
- self.file.write('layout(%s,%d)\n' % (`format`, orientation))
- else:
- self.file.write('layout((%g,%g),%d)\n'
- % (width, height, orientation))
+ if format and papersizes.has_key(format):
+ self.file.write('layout(%s,%d)\n' % (`format`, orientation))
+ else:
+ self.file.write('layout((%g,%g),%d)\n'
+ % (width, height, orientation))
def BeginGroup(self):
- self.file.write('G()\n')
+ self.file.write('G()\n')
def EndGroup(self):
- self.file.write('G_()\n')
+ self.file.write('G_()\n')
def Gradient(self, colors):
- write = self.file.write
- write('gl([')
- write_comma = 0
- for pos, color in colors:
- if write_comma:
- write(',')
- else:
- write_comma = 1
- write('(%g,%s)' % (pos, color_repr(color)))
- write('])\n')
+ write = self.file.write
+ write('gl([')
+ write_comma = 0
+ for pos, color in colors:
+ if write_comma:
+ write(',')
+ else:
+ write_comma = 1
+ write('(%g,%s)' % (pos, color_repr(color)))
+ write('])\n')
def EmptyPattern(self):
- self.file.write('pe()\n')
+ self.file.write('pe()\n')
def SolidPattern(self, color):
- self.file.write('ps(%s)\n' % color_repr(color))
+ self.file.write('ps(%s)\n' % color_repr(color))
def LinearGradientPattern(self, gradient, direction, border):
- gradient.SaveToFile(self)
- self.file.write('pgl(%g,%g,%g)\n'
- % (round(direction.x, 10), round(direction.y, 10),
- border))
+ gradient.SaveToFile(self)
+ self.file.write('pgl(%g,%g,%g)\n'
+ % (round(direction.x, 10), round(direction.y, 10),
+ border))
def RadialGradientPattern(self, gradient, center, border):
- gradient.SaveToFile(self)
- self.file.write('pgr(%g,%g,%g)\n' % (center.x, center.y, border))
+ gradient.SaveToFile(self)
+ self.file.write('pgr(%g,%g,%g)\n' % (center.x, center.y, border))
def ConicalGradientPattern(self, gradient, center, direction):
- gradient.SaveToFile(self)
- self.file.write('pgc(%g,%g,%g,%g)\n'
- % (tuple(center) + (round(direction.x, 10),
- round(direction.y, 10))))
+ gradient.SaveToFile(self)
+ self.file.write('pgc(%g,%g,%g,%g)\n'
+ % (tuple(center) + (round(direction.x, 10),
+ round(direction.y, 10))))
def HatchingPattern(self, color, background, direction, distance, width):
- self.file.write('phs(%s,%s,%g,%g,%g,%g)\n'
- % (color_repr(color), color_repr(background),
- direction.x, direction.y, distance, width))
+ self.file.write('phs(%s,%s,%g,%g,%g,%g)\n'
+ % (color_repr(color), color_repr(background),
+ direction.x, direction.y, distance, width))
def ImageTilePattern(self, image, trafo, relative_filename = 1):
self.write_image(image, relative_filename)
@@ -395,73 +395,73 @@
% ((id(image),) + trafo.coeff()))
def write_style(self, style):
- write = self.file.write
- if hasattr(style, 'fill_pattern'):
- pattern = style.fill_pattern
- if pattern is EmptyPattern:
- write('fe()\n')
- elif isinstance(pattern, SolidPattern):
- write('fp(%s)\n' % color_repr(pattern.Color()))
- else:
- pattern.SaveToFile(self)
- write('fp()\n')
- if hasattr(style, 'fill_transform'):
- write('ft(%d)\n' % style.fill_transform)
- if hasattr(style, 'line_pattern'):
- pattern = style.line_pattern
- if pattern is EmptyPattern:
- write('le()\n')
- elif isinstance(pattern, SolidPattern):
- write('lp(%s)\n' % color_repr(pattern.Color()))
- else:
- pattern.SaveToFile(self)
- write('lp()\n')
- if hasattr(style, 'line_width') :
- write('lw(%g)\n' % style.line_width)
- if hasattr(style, 'line_cap'):
- write('lc(%d)\n' % style.line_cap)
- if hasattr(style, 'line_join'):
- write('lj(%d)\n' % style.line_join)
- if hasattr(style, 'line_dashes'):
- write('ld(%s)\n' % `style.line_dashes`)
- if hasattr(style, 'line_arrow1'):
- if style.line_arrow1 is not None:
- write('la1(%s)\n' % `style.line_arrow1.SaveRepr()`)
- else:
- write('la1()\n')
- if hasattr(style, 'line_arrow2'):
- if style.line_arrow2 is not None:
- write('la2(%s)\n' % `style.line_arrow2.SaveRepr()`)
- else:
- write('la2()\n')
- if hasattr(style, 'font'):
- write('Fn(%s)\n' % `style.font.PostScriptName()`)
- if hasattr(style, 'font_size'):
- write('Fs(%g)\n' % style.font_size)
+ write = self.file.write
+ if hasattr(style, 'fill_pattern'):
+ pattern = style.fill_pattern
+ if pattern is EmptyPattern:
+ write('fe()\n')
+ elif isinstance(pattern, SolidPattern):
+ write('fp(%s)\n' % color_repr(pattern.Color()))
+ else:
+ pattern.SaveToFile(self)
+ write('fp()\n')
+ if hasattr(style, 'fill_transform'):
+ write('ft(%d)\n' % style.fill_transform)
+ if hasattr(style, 'line_pattern'):
+ pattern = style.line_pattern
+ if pattern is EmptyPattern:
+ write('le()\n')
+ elif isinstance(pattern, SolidPattern):
+ write('lp(%s)\n' % color_repr(pattern.Color()))
+ else:
+ pattern.SaveToFile(self)
+ write('lp()\n')
+ if hasattr(style, 'line_width') :
+ write('lw(%g)\n' % style.line_width)
+ if hasattr(style, 'line_cap'):
+ write('lc(%d)\n' % style.line_cap)
+ if hasattr(style, 'line_join'):
+ write('lj(%d)\n' % style.line_join)
+ if hasattr(style, 'line_dashes'):
+ write('ld(%s)\n' % `style.line_dashes`)
+ if hasattr(style, 'line_arrow1'):
+ if style.line_arrow1 is not None:
+ write('la1(%s)\n' % `style.line_arrow1.SaveRepr()`)
+ else:
+ write('la1()\n')
+ if hasattr(style, 'line_arrow2'):
+ if style.line_arrow2 is not None:
+ write('la2(%s)\n' % `style.line_arrow2.SaveRepr()`)
+ else:
+ write('la2()\n')
+ if hasattr(style, 'font'):
+ write('Fn(%s)\n' % `style.font.PostScriptName()`)
+ if hasattr(style, 'font_size'):
+ write('Fs(%g)\n' % style.font_size)
def DynamicStyle(self, style):
- self.write_style(style)
- self.file.write('dstyle(%s)\n' % `style.Name()`)
+ self.write_style(style)
+ self.file.write('dstyle(%s)\n' % `style.Name()`)
def write_style_no_defaults(self, style):
- style = style.Copy()
- for key, value in base_style.__dict__.items():
- if hasattr(style, key) and getattr(style, key) == value:
- delattr(style, key)
- self.write_style(style)
+ style = style.Copy()
+ for key, value in base_style.__dict__.items():
+ if hasattr(style, key) and getattr(style, key) == value:
+ delattr(style, key)
+ self.write_style(style)
def Properties(self, properties):
- styles = properties.stack[:]
- styles.reverse()
- if styles[0].is_dynamic:
- self.file.write('style(%s)\n' % `style[0].Name()`)
- else:
- self.write_style_no_defaults(styles[0])
- for style in styles[1:]:
- if style.is_dynamic:
- self.file.write('style(%s)\n' % `style.Name()`)
- else:
- self.write_style(style)
+ styles = properties.stack[:]
+ styles.reverse()
+ if styles[0].is_dynamic:
+ self.file.write('style(%s)\n' % `style[0].Name()`)
+ else:
+ self.write_style_no_defaults(styles[0])
+ for style in styles[1:]:
+ if style.is_dynamic:
+ self.file.write('style(%s)\n' % `style.Name()`)
+ else:
+ self.write_style(style)
def Rectangle(self, trafo, radius1 = 0, radius2 = 0):
if radius1 == radius2 == 0:
@@ -471,44 +471,44 @@
% (trafo.coeff() + (radius1, radius2)))
def Ellipse(self, trafo, start_angle, end_angle, arc_type):
- if start_angle == end_angle:
- self.file.write('e(%g,%g,%g,%g,%g,%g)\n' % trafo.coeff())
- else:
- self.file.write('e(%g,%g,%g,%g,%g,%g,%g,%g,%d)\n'
- % (trafo.coeff()+(start_angle,end_angle,arc_type)))
+ if start_angle == end_angle:
+ self.file.write('e(%g,%g,%g,%g,%g,%g)\n' % trafo.coeff())
+ else:
+ self.file.write('e(%g,%g,%g,%g,%g,%g,%g,%g,%d)\n'
+ % (trafo.coeff()+(start_angle,end_angle,arc_type)))
def PolyBezier(self, paths):
- write = self.file.write
- write('b()\n')
- for path in paths:
- if path is not paths[0]:
- write('bn()\n')
- try:
- path.write_to_file(self.file)
- except TypeError:
- # self.file is no ordinary file (not tested!)
- list = path.get_save()
- for item in list:
- if len(item) == 3:
- write('bs(%g,%g,%d)\n' % item)
- elif len(item) == 7:
- write('bc(%g,%g,%g,%g,%g,%g,%d)\n' % item)
- else:
- raise SketchSaveError('got ivalid item: ' + `item`)
- if path.closed:
- write("bC()\n")
+ write = self.file.write
+ write('b()\n')
+ for path in paths:
+ if path is not paths[0]:
+ write('bn()\n')
+ try:
+ path.write_to_file(self.file)
+ except TypeError:
+ # self.file is no ordinary file (not tested!)
+ list = path.get_save()
+ for item in list:
+ if len(item) == 3:
+ write('bs(%g,%g,%d)\n' % item)
+ elif len(item) == 7:
+ write('bc(%g,%g,%g,%g,%g,%g,%d)\n' % item)
+ else:
+ raise SketchSaveError('got ivalid item: ' + `item`)
+ if path.closed:
+ write("bC()\n")
def SimpleText(self, text, trafo, halign, valign):
- write = self.file.write
- write('txt(%s,' % `text`)
- if trafo.matrix() != IdentityMatrix:
- write('(%g,%g,%g,%g,%g,%g)' % trafo.coeff())
- else:
- write('(%g,%g)' % (trafo.v1, trafo.v2))
- if halign or valign:
- write(',%d,%d' % (halign, valign))
- write(')\n')
+ write = self.file.write
+ write('txt(%s,' % `text`)
+ if trafo.matrix() != IdentityMatrix:
+ write('(%g,%g,%g,%g,%g,%g)' % trafo.coeff())
+ else:
+ write('(%g,%g)' % (trafo.v1, trafo.v2))
+ if halign or valign:
+ write(',%d,%d' % (halign, valign))
+ write(')\n')
def write_image(self, image, relative_filename = 1):
write = self.file.write
@@ -516,11 +516,11 @@
imagefile = image.Filename()
if not imagefile:
from streamfilter import Base64Encode
- write('bm(%d)\n' % id(image))
- file = Base64Encode(self.file)
- image.image.save(file, 'PPM')
+ write('bm(%d)\n' % id(image))
+ file = Base64Encode(self.file)
+ image.image.save(file, 'PPM')
file.close()
- write('-\n')
+ write('-\n')
else:
if self.directory and relative_filename:
imagefile = relpath(self.directory, imagefile)
@@ -530,86 +530,86 @@
def Image(self, image, trafo, relative_filename = 1):
self.write_image(image, relative_filename)
- write = self.file.write
- write('im(')
- if trafo.matrix() != IdentityMatrix:
- write('(%g,%g,%g,%g,%g,%g)' % trafo.coeff())
- else:
- write('(%g,%g)' % (trafo.v1, trafo.v2))
- write(',%d)\n' % id(image))
+ write = self.file.write
+ write('im(')
+ if trafo.matrix() != IdentityMatrix:
+ write('(%g,%g,%g,%g,%g,%g)' % trafo.coeff())
+ else:
+ write('(%g,%g)' % (trafo.v1, trafo.v2))
+ write(',%d)\n' % id(image))
def EpsFile(self, data, trafo, relative_filename = 1):
- write = self.file.write
- write('eps(')
- if trafo.matrix() != IdentityMatrix:
- write('(%g,%g,%g,%g,%g,%g)' % trafo.coeff())
- else:
- write('(%g,%g)' % (trafo.v1, trafo.v2))
- filename = data.Filename()
- if self.directory and relative_filename:
- filename = relpath(self.directory, filename)
- write(',%s)\n' % `filename`)
+ write = self.file.write
+ write('eps(')
+ if trafo.matrix() != IdentityMatrix:
+ write('(%g,%g,%g,%g,%g,%g)' % trafo.coeff())
+ else:
+ write('(%g,%g)' % (trafo.v1, trafo.v2))
+ filename = data.Filename()
+ if self.directory and relative_filename:
+ filename = relpath(self.directory, filename)
+ write(',%s)\n' % `filename`)
def BeginBlendGroup(self):
- self.file.write('B()\n')
+ self.file.write('B()\n')
def EndBlendGroup(self):
- self.file.write('B_()\n')
+ self.file.write('B_()\n')
def BeginBlendInterpolation(self, steps):
- self.file.write('blendinter(%d)\n' % steps)
+ self.file.write('blendinter(%d)\n' % steps)
def EndBlendInterpolation(self):
- self.file.write('endblendinter()\n')
+ self.file.write('endblendinter()\n')
def BlendInterpolation(self, steps):
- self.file.write('Bi(%d)\n' % steps)
+ self.file.write('Bi(%d)\n' % steps)
def BeginMaskGroup(self):
- self.file.write('M()\n')
+ self.file.write('M()\n')
def EndMaskGroup(self):
- self.file.write('M_()\n')
+ self.file.write('M_()\n')
def BeginPathText(self):
- self.file.write('PT()\n')
+ self.file.write('PT()\n')
def InternalPathText(self, text, trafo, model, start_pos = 0):
- matrix = trafo.matrix()
- if matrix != IdentityMatrix:
- self.file.write('pt(%s,(%g,%g,%g,%g),%d'
- % ((`text`,) + matrix + (model,)))
- else:
- self.file.write('pt(%s,%d' % (`text`, model))
+ matrix = trafo.matrix()
+ if matrix != IdentityMatrix:
+ self.file.write('pt(%s,(%g,%g,%g,%g),%d'
+ % ((`text`,) + matrix + (model,)))
+ else:
+ self.file.write('pt(%s,%d' % (`text`, model))
if start_pos > 0:
self.file.write(',%g)\n' % start_pos)
else:
self.file.write(')\n')
def EndPathText(self):
- self.file.write('PT_()\n')
+ self.file.write('PT_()\n')
def GuideLine(self, point, horizontal):
- if horizontal:
- args = point.y, 1
- else:
- args = point.x, 0
- self.file.write('guide(%g,%d)\n' % args)
+ if horizontal:
+ args = point.y, 1
+ else:
+ args = point.x, 0
+ self.file.write('guide(%g,%d)\n' % args)
def BeginPluginCompound(self, plugin_name, *args, **kw):
- write = self.file.write
- write('PC(%s' % `plugin_name`)
- for arg in args:
- write(',%s' % `arg`)
- for key, value in kw.items():
- write(',%s=%s' % (key, `value`))
- write(')\n')
+ write = self.file.write
+ write('PC(%s' % `plugin_name`)
+ for arg in args:
+ write(',%s' % `arg`)
+ for key, value in kw.items():
+ write(',%s=%s' % (key, `value`))
+ write(')\n')
def EndPluginCompound(self):
- self.file.write('PC_()\n')
+ self.file.write('PC_()\n')
def save(document, file, filename, options = {}):
saver = SKSaver(file, filename, options)
document.SaveToFile(saver)
-
+
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/svgloader.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/svgloader.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/svgloader.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -282,7 +282,7 @@
'defs': 'end_defs',
'text': 'end_text'
}
-
+
def __init__(self, loader):
self.loader = loader
self.trafo = self.basetrafo = Trafo()
@@ -351,7 +351,7 @@
method = self.dispatch_start.get(name)
if method is not None:
getattr(self, method)(attrs)
-
+
def endElement(self, name):
self.depth = self.depth - 1
self._print(')', name)
@@ -400,7 +400,7 @@
else:
# FIXME: we should probably print a message or something
pass
-
+
def try_add_style(self,key,val):
if key == 'fill':
if val == 'none':
@@ -445,11 +445,11 @@
####self.style.font_size = float(val)
elif key == 'text-anchor':
if val=='start':
- self.halign = text.ALIGN_LEFT
+ self.halign = text.ALIGN_LEFT
elif val == 'middle':
- self.halign = text.ALIGN_CENTER
+ self.halign = text.ALIGN_CENTER
elif val == 'end':
- self.halign = text.ALIGN_RIGHT
+ self.halign = text.ALIGN_RIGHT
def set_loader_style(self, allow_font = 0):
# Copy self.style to loader.
@@ -466,7 +466,7 @@
def push_state(self):
self.state_stack = self.style, self.trafo, self.state_stack
self.style = self.style.Copy()
-
+
def pop_state(self):
self.style, self.trafo, self.state_stack = self.state_stack
@@ -509,7 +509,7 @@
xunit = ''
factor = 1.0
x = float(x) * factor
-
+
yunit = y[-2:]
factor = factors.get(yunit)
if factor is not None:
@@ -563,8 +563,8 @@
self.parse_style(style)
self.set_loader_style()
apply(self.loader.ellipse, t.coeff())
-
+
def ellipse(self, attrs):
if self.in_defs:
id = attrs.get('id', '')
@@ -851,13 +851,13 @@
if style:
self.parse_style(style)
self.set_loader_style()
-
+
def end_path(self):
if self.in_defs:
return
self.loader.bezier(paths = tuple(self.paths))
self.paths = None
-
+
def image(self, attrs):
if self.in_defs:
id = attrs.get('id', '')
@@ -875,7 +875,7 @@
else:
y = '0'
x, y = self.user_point(x, y)
-
+
width = self.user_length(attrs['width'])
scalex = width / image.size[0]
@@ -902,7 +902,7 @@
# can have presentation attributes as well.
for key,value in attrs.items():
self.try_add_style(key,value)
-
+
if attrs.has_key('x'):
x = attrs['x']
else:
@@ -932,7 +932,7 @@
if style:
self.parse_style(style)
self.loader.begin_group()
-
+
def end_group(self):
try:
self.loader.end_group()
@@ -952,8 +952,8 @@
self.parse_style(attrs['style'])
self.startElement(data[1], data[2])
self.endElement(data[1])
-
+
def begin_defs(self, attrs):
self.in_defs = 1
@@ -970,7 +970,7 @@
self.directory = os.path.split(filename)[0]
else:
self.directory = ''
-
+
def __del__(self):
pass
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/wmfloader.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/wmfloader.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/wmfloader.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -59,26 +59,26 @@
struct_wmf_header = ('<'
- 'H' # Type
- 'H' # header size
- 'H' # Version
- 'I' # FileSize
- 'H' # Num. objects
- 'I' # Max. record size
- 'H' # Num. Parameters
- )
+ 'H' # Type
+ 'H' # header size
+ 'H' # Version
+ 'I' # FileSize
+ 'H' # Num. objects
+ 'I' # Max. record size
+ 'H' # Num. Parameters
+ )
struct_placeable_header = ('<'
- '4s' # Key
- 'H' # handle
- 'h' # left
- 'h' # top
- 'h' # right
- 'h' # bottom
- 'H' # Inch
- 'I' # Reserved
- 'H' # Checksum
- )
+ '4s' # Key
+ 'H' # handle
+ 'h' # left
+ 'h' # top
+ 'h' # right
+ 'h' # bottom
+ 'H' # Inch
+ 'I' # Reserved
+ 'H' # Checksum
+ )
wmf_functions = {
0x0052: 'AbortDoc',
@@ -171,116 +171,116 @@
class WMFLoader(GenericLoader):
def __init__(self, file, filename, match):
- GenericLoader.__init__(self, file, filename, match)
- self.file = file
- self.curstyle = Style()
- self.verbosity = 0
- self.gdiobjects = []
+ GenericLoader.__init__(self, file, filename, match)
+ self.file = file
+ self.curstyle = Style()
+ self.verbosity = 0
+ self.gdiobjects = []
self.dcstack = []
self.curpoint = Point(0, 0)
def _print(self, format, *args, **kw):
- if self.verbosity:
- try:
- if kw:
- text = format % kw
- elif args:
- text = format % args
- else:
- text = format
- except:
- text = string.join([format] + map(str, args))
- if text[-1] != '\n':
- text = text + '\n'
- sys.stdout.write(text)
+ if self.verbosity:
+ try:
+ if kw:
+ text = format % kw
+ elif args:
+ text = format % args
+ else:
+ text = format
+ except:
+ text = string.join([format] + map(str, args))
+ if text[-1] != '\n':
+ text = text + '\n'
+ sys.stdout.write(text)
def get_struct(self, format):
- size = calcsize(format)
- return unpack(format, self.file.read(size))
+ size = calcsize(format)
+ return unpack(format, self.file.read(size))
def get_int16(self):
- return self.get_struct('<h')[0]
+ return self.get_struct('<h')[0]
def get_int32(self):
- return self.get_struct('<i')[0]
+ return self.get_struct('<i')[0]
def read_headers(self):
- self.file.seek(0)
- placeable = self.file.read(calcsize(struct_placeable_header))
- key, handle, left, top, right, bottom, inch, reserved, checksum\
- = unpack(struct_placeable_header, placeable)
- if key != rx_magic:
- raise SketchLoadError(_("The file is not a placeable "
+ self.file.seek(0)
+ placeable = self.file.read(calcsize(struct_placeable_header))
+ key, handle, left, top, right, bottom, inch, reserved, checksum\
+ = unpack(struct_placeable_header, placeable)
+ if key != rx_magic:
+ raise SketchLoadError(_("The file is not a placeable "
"windows metafile"))
- self._print("The file is not a placeable windows metafile")
- sum = 0
- for word in unpack('<10h', placeable[:20]):
- sum = sum ^ word
- if sum != checksum:
- #raise SketchLoadError(_("The file has an incorrect checksum"))
- self._print("The file has an incorrect checksum")
+ self._print("The file is not a placeable windows metafile")
+ sum = 0
+ for word in unpack('<10h', placeable[:20]):
+ sum = sum ^ word
+ if sum != checksum:
+ #raise SketchLoadError(_("The file has an incorrect checksum"))
+ self._print("The file has an incorrect checksum")
- self.inch = inch
- self.bbox = (left, top, right, bottom)
- factor = 72.0 / self.inch
- self.wx = self.wy = 0
- self.wwidth = right - left
- self.wheight = bottom - top
+ self.inch = inch
+ self.bbox = (left, top, right, bottom)
+ factor = 72.0 / self.inch
+ self.wx = self.wy = 0
+ self.wwidth = right - left
+ self.wheight = bottom - top
self.vx = self.vy = 0
self.vwidth = self.wwidth
self.vheight = self.wheight
- self.base_trafo = Trafo(factor, 0, 0, -factor,
+ self.base_trafo = Trafo(factor, 0, 0, -factor,
0, factor * self.vheight)
- self.update_trafo()
+ self.update_trafo()
- header = self.file.read(calcsize(struct_wmf_header))
- filetype, headersize, version, filesize, numobj, maxrecord, numparams\
- = unpack(struct_wmf_header, header)
+ header = self.file.read(calcsize(struct_wmf_header))
+ filetype, headersize, version, filesize, numobj, maxrecord, numparams\
+ = unpack(struct_wmf_header, header)
- self._print('\nHeader\n------\n')
- fmt = '% 10s: %s\n'
- self._print(fmt, 'inch', self.inch)
- self._print(fmt, 'bbox', self.bbox)
- self._print(fmt, 'headersize', headersize)
- self._print(fmt, 'version', version)
- self._print(fmt, 'numobj', numobj)
- self._print(fmt, 'numparams', numparams)
- self._print(fmt, 'maxrecord', maxrecord)
- self._print('\n')
+ self._print('\nHeader\n------\n')
+ fmt = '% 10s: %s\n'
+ self._print(fmt, 'inch', self.inch)
+ self._print(fmt, 'bbox', self.bbox)
+ self._print(fmt, 'headersize', headersize)
+ self._print(fmt, 'version', version)
+ self._print(fmt, 'numobj', numobj)
+ self._print(fmt, 'numparams', numparams)
+ self._print(fmt, 'maxrecord', maxrecord)
+ self._print('\n')
def update_trafo(self):
- wt = Translation(-self.wx, -self.wy)
+ wt = Translation(-self.wx, -self.wy)
vt = Translation(self.vx, self.vy)
- scale = Scale(float(self.vwidth) / self.wwidth,
- float(self.vheight) / self.wheight)
- self.trafo = self.base_trafo(vt(scale(wt)))
+ scale = Scale(float(self.vwidth) / self.wwidth,
+ float(self.vheight) / self.wheight)
+ self.trafo = self.base_trafo(vt(scale(wt)))
def add_gdiobject(self, object):
- try:
- idx = self.gdiobjects.index(None)
- except ValueError:
- self.gdiobjects.append(object)
- else:
- self.gdiobjects[idx] = object
+ try:
+ idx = self.gdiobjects.index(None)
+ except ValueError:
+ self.gdiobjects.append(object)
+ else:
+ self.gdiobjects[idx] = object
def delete_gdiobject(self, idx):
- self.gdiobjects[idx] = None
+ self.gdiobjects[idx] = None
def SelectObject(self):
- idx = self.get_int16()
+ idx = self.get_int16()
try:
object = self.gdiobjects[idx]
except IndexError:
print 'Index Error:', idx, self.gdiobjects
raise
- for property, value in object:
- setattr(self.curstyle, property, value)
- self._print('->', idx, object)
+ for property, value in object:
+ setattr(self.curstyle, property, value)
+ self._print('->', idx, object)
def DeleteObject(self):
- idx = self.get_int16()
- self.delete_gdiobject(idx)
- self._print('->', idx)
+ idx = self.get_int16()
+ self.delete_gdiobject(idx)
+ self._print('->', idx)
def get_dc(self):
return self.curstyle.Duplicate(), self.trafo, self.curpoint
@@ -300,32 +300,32 @@
self._print('->', mode)
def SetWindowOrg(self):
- self.wy, self.wx = self.get_struct('<hh')
- self.update_trafo()
- self._print('->', self.wx, self.wy)
+ self.wy, self.wx = self.get_struct('<hh')
+ self.update_trafo()
+ self._print('->', self.wx, self.wy)
def SetWindowExt(self):
- self.wheight, self.wwidth = self.get_struct('<hh')
- self.update_trafo()
- self._print('->', self.wwidth, self.wheight)
+ self.wheight, self.wwidth = self.get_struct('<hh')
+ self.update_trafo()
+ self._print('->', self.wwidth, self.wheight)
def SetPolyFillMode(self):
- mode = self.get_int16()
- self._print('->', mode)
+ mode = self.get_int16()
+ self._print('->', mode)
SetBkMode = noop
SetBkColor = noop
SetROP2 = noop
def CreateBrushIndirect(self):
- style, r, g, b, hatch = self.get_struct('<hBBBxh')
- if style == 1:
- pattern = EmptyPattern
- else:
- pattern = SolidPattern(CreateRGBColor(r/255.0, g/255.0, b/255.0))
- self.add_gdiobject((('fill_pattern', pattern),))
+ style, r, g, b, hatch = self.get_struct('<hBBBxh')
+ if style == 1:
+ pattern = EmptyPattern
+ else:
+ pattern = SolidPattern(CreateRGBColor(r/255.0, g/255.0, b/255.0))
+ self.add_gdiobject((('fill_pattern', pattern),))
- self._print('->', style, r, g, b, hatch)
+ self._print('->', style, r, g, b, hatch)
def DibCreatePatternBrush(self):
self.add_message(_("Bitmap brushes not yet implemented. Using black"))
@@ -333,18 +333,18 @@
self.add_gdiobject((('fill_pattern', pattern),))
def CreatePenIndirect(self):
- style, widthx, widthy, r, g, b = self.get_struct('<hhhBBBx')
- cap = (style & 0x0F00) >> 8
- join = (style & 0x00F0) >> 4
- style = style & 0x000F
- if style == 5:
- pattern = EmptyPattern
- else:
- pattern = SolidPattern(CreateRGBColor(r/255.0, g/255.0, b/255.0))
+ style, widthx, widthy, r, g, b = self.get_struct('<hhhBBBx')
+ cap = (style & 0x0F00) >> 8
+ join = (style & 0x00F0) >> 4
+ style = style & 0x000F
+ if style == 5:
+ pattern = EmptyPattern
+ else:
+ pattern = SolidPattern(CreateRGBColor(r/255.0, g/255.0, b/255.0))
width = abs(widthx * self.trafo.m11)
- self.add_gdiobject((('line_pattern', pattern,),
- ('line_width', width)))
- self._print('->', style, widthx, widthy, r, g, b, cap, join)
+ self.add_gdiobject((('line_pattern', pattern,),
+ ('line_width', width)))
+ self._print('->', style, widthx, widthy, r, g, b, cap, join)
def CreatePalette(self):
self.add_gdiobject((('ignore', None),))
@@ -355,13 +355,13 @@
CreateFontIndirect = CreatePalette
SelectPalette = noop
RealizePalette = noop
-
+
SetTextColor = noop
SetTextAlign = noop
SetTextJustification = noop
SetStretchBltMode = noop
-
+
def read_points(self, num):
coords = self.get_struct('<' + num * 'hh')
points = [];
@@ -372,31 +372,31 @@
return points
def Polyline(self):
- points = self.read_points(self.get_int16())
- if points:
- path = CreatePath()
- map(path.AppendLine, points)
- self.prop_stack.AddStyle(self.curstyle.Duplicate())
- self.prop_stack.SetProperty(fill_pattern = EmptyPattern)
- self.bezier((path,))
+ points = self.read_points(self.get_int16())
+ if points:
+ path = CreatePath()
+ map(path.AppendLine, points)
+ self.prop_stack.AddStyle(self.curstyle.Duplicate())
+ self.prop_stack.SetProperty(fill_pattern = EmptyPattern)
+ self.bezier((path,))
- #for i in range(len(points)):
- # self._print('->', points[i])
+ #for i in range(len(points)):
+ # self._print('->', points[i])
def Polygon(self):
- points = self.read_points(self.get_int16())
- if points:
- path = CreatePath()
- map(path.AppendLine, points)
- if path.Node(-1) != path.Node(0):
- #print 'correct polygon'
- path.AppendLine(path.Node(0))
+ points = self.read_points(self.get_int16())
+ if points:
+ path = CreatePath()
+ map(path.AppendLine, points)
+ if path.Node(-1) != path.Node(0):
+ #print 'correct polygon'
+ path.AppendLine(path.Node(0))
path.load_close()
- self.prop_stack.AddStyle(self.curstyle.Duplicate())
+ self.prop_stack.AddStyle(self.curstyle.Duplicate())
self.bezier((path,))
- #for i in range(len(points)):
- # self._print('->', points[i])
+ #for i in range(len(points)):
+ # self._print('->', points[i])
def PolyPolygon(self):
nr_of_polygons = self.get_int16()
@@ -421,7 +421,7 @@
y, x = self.get_struct('<hh')
self.curpoint = self.trafo(x, y)
self._print('->', self.curpoint)
-
+
def LineTo(self):
y, x = self.get_struct('<hh')
p = self.trafo(x, y)
@@ -435,7 +435,7 @@
self._print('->', self.curpoint)
def Ellipse(self):
- bottom, right, top, left = self.get_struct('<hhhh')
+ bottom, right, top, left = self.get_struct('<hhhh')
left, top = self.trafo(left, top)
right, bottom = self.trafo(right, bottom)
self.prop_stack.AddStyle(self.curstyle.Duplicate())
@@ -443,7 +443,7 @@
(right + left) / 2, (top + bottom) / 2)
def Arc(self, arc_type = const.ArcArc):
- ye, xe, ys, xs, bottom, right, top, left = self.get_struct('<hhhhhhhh')
+ ye, xe, ys, xs, bottom, right, top, left = self.get_struct('<hhhhhhhh')
left, top = self.trafo(left, top)
right, bottom = self.trafo(right, bottom)
xs, ys = self.trafo(xs, ys)
@@ -483,39 +483,39 @@
self.rectangle(right - left, 0, 0, bottom - top, left, top,
radius1 = abs(ellw / (right - left)),
radius2 = abs(ellh / (bottom - top)))
-
+
def Escape(self):
pass
def interpret(self):
- tell = self.file.tell
- function = -1
- while function:
- pos = tell()
- size, function = self.get_struct('<ih')
- self._print('%5d: %4x: %s' % (size, function,
+ tell = self.file.tell
+ function = -1
+ while function:
+ pos = tell()
+ size, function = self.get_struct('<ih')
+ self._print('%5d: %4x: %s' % (size, function,
wmf_functions.get(function, '')))
if hasattr(self, wmf_functions.get(function, '')):
- getattr(self, wmf_functions[function])()
- else:
- if function:
- self.file.read(2 * (size - 3))
- self._print('*** unimplemented:',
+ getattr(self, wmf_functions[function])()
+ else:
+ if function:
+ self.file.read(2 * (size - 3))
+ self._print('*** unimplemented:',
wmf_functions.get(function, ''))
- pos = pos + 2 * size
- if tell() < pos:
- self.file.read(pos - tell())
- elif tell() > pos:
- self._print('read too many bytes')
- self.file.seek(pos - tell(), 1)
+ pos = pos + 2 * size
+ if tell() < pos:
+ self.file.read(pos - tell())
+ elif tell() > pos:
+ self._print('read too many bytes')
+ self.file.seek(pos - tell(), 1)
def Load(self):
- self.document()
- self.layer(name = _("WMF objects"))
- self.read_headers()
- self.interpret()
- self.end_all()
- self.object.load_Completed()
- return self.object
+ self.document()
+ self.layer(name = _("WMF objects"))
+ self.read_headers()
+ self.interpret()
+ self.end_all()
+ self.object.load_Completed()
+ return self.object
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/wmfsaver.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/wmfsaver.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/wmfsaver.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -433,7 +433,7 @@
self.Scale = sc
self.inch = inch
self.extend = map(rndtoint, tuple(self.trafo(left,bottom))
- + tuple(self.trafo(right,top)))
+ + tuple(self.trafo(right,top)))
self.numobj = self.idx = MIN_OBJECT
self.objects = []
Modified: skencil/branches/skencil-0.6/src/Plugins/Filters/xfigloader.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Filters/xfigloader.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Filters/xfigloader.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -67,12 +67,12 @@
std_colors = [StandardColors.black, StandardColors.blue, StandardColors.green,
StandardColors.cyan, StandardColors.red, StandardColors.magenta,
StandardColors.yellow, StandardColors.white] + \
- map(XRGBColor, ("#000090", "#0000b0", "#0000d0", "#87ceff",
- "#009000", "#00b000", "#00d000", "#009090",
- "#00b0b0", "#00d0d0", "#900000", "#b00000",
- "#d00000", "#900090", "#b000b0", "#d000d0",
- "#803000", "#a04000", "#c06000", "#ff8080",
- "#ffa0a0", "#ffc0c0", "#ffe0e0", "#ffd700"))
+ map(XRGBColor, ("#000090", "#0000b0", "#0000d0", "#87ceff",
+ "#009000", "#00b000", "#00d000", "#009090",
+ "#00b0b0", "#00d0d0", "#900000", "#b00000",
+ "#d00000", "#900090", "#b000b0", "#d000d0",
+ "#803000", "#a04000", "#c06000", "#ff8080",
+ "#ffa0a0", "#ffc0c0", "#ffe0e0", "#ffd700"))
BLACK = 0
WHITE = 7
@@ -120,7 +120,7 @@
class XFigLoader(SimplifiedLoader):
format_name = format_name
-
+
functions = [('define_color', 0),
('read_ellipse', 1),
('read_polyline', 2),
@@ -131,7 +131,7 @@
('end_compound', -6)]
def __init__(self, file, filename, match):
- SimplifiedLoader.__init__(self, file, filename, match)
+ SimplifiedLoader.__init__(self, file, filename, match)
self.layout = None
self.format_version = atof(match.group('version'))
self.trafo = Trafo(1.0, 0.0, 0.0, -1.0, 0.0, 800)
@@ -146,10 +146,10 @@
return line
def get_compiled(self):
- funclist = {}
- for name, rx in self.functions:
- funclist[rx] = getattr(self, name)
- return funclist
+ funclist = {}
+ for name, rx in self.functions:
+ funclist[rx] = getattr(self, name)
+ return funclist
def set_depth(self, depth):
self.depths[id(self.object)] = -depth
@@ -213,11 +213,11 @@
def fill(self, color, style):
pattern = self.get_pattern(color, style)
- try:
+ try:
self.set_properties(fill_pattern = pattern)
- except:
- raise SketchLoadError("can't assign fill style: %s:%s"
- % sys.exc_info()[:2])
+ except:
+ raise SketchLoadError("can't assign fill style: %s:%s"
+ % sys.exc_info()[:2])
def font(self, font, size, flags):
if flags & 4:
@@ -229,7 +229,7 @@
self.add_message(_("PostScript font `%(ps)s' substituted for "
"TeX-font `%(tex)s'")
% {'ps':name, 'tex':tex_font_names[font]})
-
+
self.set_properties(font = GetFont(name), font_size = size)
def read_tokens(self, num):
@@ -250,13 +250,13 @@
if len(args) != 21:
raise SketchLoadError('Invalid Arc specification')
sub_type, line_style, thickness, pen_color, fill_color, depth, \
- pen_style, area_fill, style, cap, direction, \
- forward_arrow, backward_arrow, \
- cx, cy, x1, y1, x2, y2, x3, y3 = args
+ pen_style, area_fill, style, cap, direction, \
+ forward_arrow, backward_arrow, \
+ cx, cy, x1, y1, x2, y2, x3, y3 = args
self.fill(fill_color, area_fill)
self.line(pen_color, thickness, const.JoinMiter, cap,
line_style, style)
-
+
if forward_arrow: readline() # XXX: implement this
if backward_arrow:readline() # XXX: implement this
@@ -281,12 +281,12 @@
if len(args) != 19:
raise SketchLoadError('Invalid Ellipse specification')
sub_type, line_style, thickness, pen_color, fill_color, depth, \
- pen_style, area_fill, style, direction, angle, \
- cx, cy, rx, ry, sx, sy, ex, ey = args
+ pen_style, area_fill, style, direction, angle, \
+ cx, cy, rx, ry, sx, sy, ex, ey = args
self.fill(fill_color, area_fill)
self.line(pen_color, thickness, const.JoinMiter, const.CapButt,
line_style, style)
-
+
center = self.trafo(cx, cy); radius = self.trafo.DTransform(rx, ry)
trafo = Trafo(radius.x, 0, 0, radius.y)
trafo = Rotation(angle)(trafo)
@@ -300,8 +300,8 @@
if len(args) != 15:
raise SketchLoadError('Invalid PolyLine specification')
sub_type, line_style, thickness, pen_color, fill_color, depth, \
- pen_style, area_fill, style, join, cap, \
- radius, forward_arrow, backward_arrow, npoints = args
+ pen_style, area_fill, style, join, cap, \
+ radius, forward_arrow, backward_arrow, npoints = args
self.fill(fill_color, area_fill)
self.line(pen_color, thickness, join, cap, line_style, style)
@@ -328,8 +328,8 @@
if len(args) != 13:
raise SketchLoadError('Invalid Spline specification')
sub_type, line_style, thickness, pen_color, fill_color, depth, \
- pen_style, area_fill, style, cap, \
- forward_arrow, backward_arrow, npoints = args
+ pen_style, area_fill, style, cap, \
+ forward_arrow, backward_arrow, npoints = args
closed = sub_type & 1
if forward_arrow: readline()
if backward_arrow:readline()
@@ -340,10 +340,10 @@
sub_type = 4
else:
sub_type = 5
-
+
self.fill(fill_color, area_fill)
self.line(pen_color, thickness, 0, cap, line_style, style)
-
+
ncoords = npoints * 2
pts = self.read_tokens(ncoords)
if not pts:
@@ -351,7 +351,7 @@
if len(pts) > ncoords:
del pts[ncoords:]
pts = coords_to_points(pts, self.trafo)
-
+
path = CreatePath()
if sub_type in (2, 3):
# interpolated spline, read 2 control points for each node
@@ -411,10 +411,10 @@
if len(args) != 13: # including the unparsed rest of the line
raise SketchLoadError('Invalid text specification')
sub_type, color, depth, pen_style, font, size, angle, flags, \
- height, length, x, y, rest = args
+ height, length, x, y, rest = args
self.fill(color, None)
self.font(font, size * 0.9, flags)
-
+
if len(rest) > 2: #at least a space and a newline
# read the actual text. This implementation may fail in
# certain cases!
@@ -432,7 +432,7 @@
string = eval("'''" + string[:-5] + "'''", globals)
else:
raise SketchLoadError('Invalid text string')
-
+
trafo = Translation(self.trafo(x, y))(Rotation(angle))
self.simple_text(string, trafo = trafo, halign = align[sub_type])
self.set_depth(depth)
@@ -494,14 +494,14 @@
def Load(self):
- file = self.file
- funclist = self.get_compiled()
- # binding frequently used functions to local variables speeds up
- # the process considerably...
+ file = self.file
+ funclist = self.get_compiled()
+ # binding frequently used functions to local variables speeds up
+ # the process considerably...
readline = file.readline; tokenize = skread.tokenize_line
self.document()
self.layer(_("Layer 1"))
- try:
+ try:
self.read_header()
line = self.readline()
while line:
@@ -516,21 +516,21 @@
if function:
function(rest)
line = self.readline()
-
- except SketchLoadError, value:
+
+ except SketchLoadError, value:
warn_tb(INTERNAL)
- raise SketchLoadError('%d:%s' % (self.lineno, str(value))), None,\
+ raise SketchLoadError('%d:%s' % (self.lineno, str(value))), None,\
sys.exc_traceback
- except:
- if load._dont_handle_exceptions:
- warn(INTERNAL, 'XFigLoader: error reading line %d:%s',
- self.lineno, `line`)
- raise
- raise SketchLoadError(_("error in line %d:\n%s")
- % (self.lineno, `line`)), None,\
- sys.exc_traceback
- self.end_all()
- self.object.load_Completed()
+ except:
+ if load._dont_handle_exceptions:
+ warn(INTERNAL, 'XFigLoader: error reading line %d:%s',
+ self.lineno, `line`)
+ raise
+ raise SketchLoadError(_("error in line %d:\n%s")
+ % (self.lineno, `line`)), None,\
+ sys.exc_traceback
+ self.end_all()
+ self.object.load_Completed()
return self.object
Modified: skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/TextEditor.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/TextEditor.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/TextEditor.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -34,7 +34,7 @@
style = apply(Style, [], {l[0] : l[1]})
styling.append((style, line, char))
return styling
-
+
def styling2raw(styling):
raw_styling = []
for style, line, char in styling:
@@ -44,9 +44,9 @@
l = 0
raw_styling.append((l, line, char))
return raw_styling
-
-
-
+
+
+
st_signature = '## styletext '
def load_text(name):
file = open(name, 'r')
@@ -91,7 +91,7 @@
family, attrs, xlfd_start, encoding = font.fontmap[name]
if attrs in list:
return font.xlfd_template % (xlfd_start, kw['size'],
- encoding)
+ encoding)
def ps(self, **kw):
family = kw['family']
@@ -103,7 +103,7 @@
for name in fonts:
family, attrs, xlfd_start, encoding = font.fontmap[name]
if attrs in list:
- return name
+ return name
return ''
font.read_font_dirs()
@@ -150,25 +150,25 @@
menu.options = Tkinter.Menu(menu)
self._plainmode_state = Tkinter.IntVar()
menu.options.add_checkbutton(label='Plain mode', \
- variable = self._plainmode_state,
- command = lambda s=self: s.fontify('1.0', 'end'))
+ variable = self._plainmode_state,
+ command = lambda s=self: s.fontify('1.0', 'end'))
menu.family = Tkinter.Menu(menu)
for f in FONTS.families:
menu.family.add_command(label=f,
- command=lambda s=self, f=f: s.change_family(f))
+ command=lambda s=self, f=f: s.change_family(f))
menu.size = Tkinter.Menu(menu)
for f in std_sizes:
menu.size.add_command(label=f,
- command=lambda s=self, f=f: s.change_size(f))
+ command=lambda s=self, f=f: s.change_size(f))
menu.color = Tkinter.Menu(menu)
for f in ('black', 'darkgray', 'gray', 'lightgray', 'blue', 'cyan',
'green', 'magenta', 'red', 'yellow', 'white'):
menu.color.add_command(label=f, \
- command=lambda s=self, f=f: s.change_color(f),
- background = f)
+ command=lambda s=self, f=f: s.change_color(f),
+ background = f)
# definition of the menu one level up...
menu.add_cascade(
@@ -198,36 +198,36 @@
menu.add_checkbutton(label=_('Bold'), \
variable=self._bold_state,
command=lambda s=self, i=self._bold_state: \
- s.change_bold(i.get())
- )
+ s.change_bold(i.get())
+ )
menu.add_checkbutton(label=_("Italic"),
variable=self._italic_state,
command=lambda s=self, i=self._italic_state: \
- s.change_italic(i.get())
- )
+ s.change_italic(i.get())
+ )
self._subscript_state = Tkinter.IntVar()
self._superscript_state = Tkinter.IntVar()
menu.add_checkbutton(label=_("Subscript"), \
- variable=self._subscript_state,
- command=lambda s=self, i=self._subscript_state: \
- s.change_subscript(i.get())
- )
+ variable=self._subscript_state,
+ command=lambda s=self, i=self._subscript_state: \
+ s.change_subscript(i.get())
+ )
menu.add_checkbutton(label=_("Superscript"), \
- variable=self._superscript_state,
- command=lambda s=self, i=self._superscript_state: \
- s.change_superscript(i.get())
- )
+ variable=self._superscript_state,
+ command=lambda s=self, i=self._superscript_state: \
+ s.change_superscript(i.get())
+ )
self.menu = menu
self.bind('<Button-3>',
lambda e, s=self: s.menu.tk_popup(e.x_root, e.y_root))
-
+
def warn(self, title, message):
# This will be overridden
pass
-
+
def _update_menu(self):
styles = self.style_get('insert')
dict = {}
@@ -253,7 +253,7 @@
else:
tagoptions['foreground'] = self.plain_options['color']
-
+
def SupersubSort(self, tagoptions, alloptions):
if self._plainmode_state.get():
size = self.plain_options['size']
@@ -270,13 +270,13 @@
def FamilySort(self, tagoptions, alloptions):
pass
-
+
def ItalicSort(self, tagoptions, alloptions):
pass
-
+
def BoldSort(self, tagoptions, alloptions):
pass
-
+
def SizeSort(self, tagoptions, alloptions):
dict = {}
if not self._plainmode_state.get():
@@ -348,7 +348,7 @@
def load(self, event=None):
name = askopenfilename( \
filetypes=[(_("styletext files"), "*.st"), \
- (_("all files"), "*")])
+ (_("all files"), "*")])
if name:
try:
text, styling = load_text(name)
@@ -356,9 +356,9 @@
self.warn(
title = _("Load File"),
message = _("Cannot load %(filename)s:\n"
- "%(message)s") \
+ "%(message)s") \
% {'filename':`os.path.split(name)[1]`,
- 'message':value})
+ 'message':value})
return
index = '1.0'
self.style_removeall()
@@ -369,7 +369,7 @@
def saveas(self, event=None):
name = asksaveasfilename( \
filetypes=[(_("styletext files"), "*.st"), \
- (_("all files"), "*")])
+ (_("all files"), "*")])
if name:
text = self.get('1.0', 'end')
styling = self.styling_get('1.0', 'end')
@@ -379,14 +379,14 @@
self.warn(
title = _("Save File"),
message = _("Cannot Save %(filename)s:\n"
- "%(message)s") \
+ "%(message)s") \
% {'filename':`os.path.split(name)[1]`,
- 'message':value})
+ 'message':value})
def insert_file(self, event=None):
name = askopenfilename( \
filetypes=[(_("styletext files"), "*.st"), \
- (_("all files"), "*")])
+ (_("all files"), "*")])
if name:
try:
text, styling = load_text(name)
@@ -394,17 +394,17 @@
self.warn(
title = _("Insert File"),
message = _("Cannot insert %(filename)s:\n"
- "%(message)s") \
+ "%(message)s") \
% {'filename':`os.path.split(name)[1]`,
- 'message':value})
+ 'message':value})
return
-
+
index = self.index('insert')
self.insert(index, text)
self.styling_apply(index, styling)
-
+
def test1():
tk = Tkinter.Tk()
text = TextEditor(tk, background='white')
@@ -496,7 +496,7 @@
sys.path.append('/usr/lib/sketch-0.6.12/')
#
test1()
-
+
#
#~ for test in (test3, test4, test5):
#~ print "\n", test.__name__
Modified: skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/chunker.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/chunker.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/chunker.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -77,10 +77,10 @@
# need to adjust i ?
while (self.i<len(self.styling)-1) and \
- ((self.line>line) or (self.line==line and self.col>=col)):
- self.i = self.i+1
- self.styles[style.sort] = style
- style, line, col = self.styling[self.i]
+ ((self.line>line) or (self.line==line and self.col>=col)):
+ self.i = self.i+1
+ self.styles[style.sort] = style
+ style, line, col = self.styling[self.i]
plus = 0
if self.pos>=self.len:
@@ -119,9 +119,9 @@
)
text = '''\n\nA234567890\nB234567890\nC234567890\tX123''' \
- '''45\tY12345\t\n\t\n'''
+ '''45\tY12345\t\n\t\n'''
chunker = Chunker(text, styling, '\t')
while not chunker.eof():
print ">",repr(chunker.get()), "eof = ",chunker.eof(), \
- "\t reason = ", repr(chunker.reason())
+ "\t reason = ", repr(chunker.reason())
Modified: skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/iterator.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/iterator.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/iterator.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -14,8 +14,8 @@
class StyletextError(Exception):
pass
-
-
+
+
class Style:
is_Style = 1
@@ -152,7 +152,7 @@
index = self.current
if index is None:
raise StyletextError(
- "Can't insert at index: %s" % index)
+ "Can't insert at index: %s" % index)
it = self.pool.iterator()
it.before(index)
it.next()
@@ -190,7 +190,7 @@
index = self.current
if index is None:
raise StyletextError(
- "Can't insert at index '%s'" % index)
+ "Can't insert at index '%s'" % index)
it = self.pool.iterator()
it.after(index)
@@ -298,7 +298,7 @@
# start with a good guess
it.guess(indexOrId)
while (not it.outofboundary) and (texti.compare(it,'>=', \
- indexOrId)):
+ indexOrId)):
it.prev()
if it.outofboundary:
@@ -373,7 +373,7 @@
s3 = Style(w=1)
if s2 == s3: print "error"
if s2 != s3: print "error"
-
+
i = pool.iterator()
i.insert_left(Style(color = "blue"),'1.0')
i.insert_left(Style(color = "red"),'2.0')
@@ -384,6 +384,6 @@
pool.dump()
i.after("1.0")
print "after 1.0: ",i,i.i
-
+
i.after("2.0")
print "after 2.0: ",i,i.i
Modified: skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/styletext.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/styletext.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Objects/Lib/multilinetext/styletext.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -106,7 +106,7 @@
print "============== mark dump ================="
for pos, name in list:
# if name[0] == '_':
- print pos,"\t", name
+ print pos,"\t", name
def tag_dump(self):
print "============== tag dump ==================="
@@ -395,7 +395,7 @@
family, attrs, xlfd_start, encoding = font.fontmap[name]
if attrs == kw['attr']:
return font.xlfd_template % \
- (xlfd_start, kw['size'], encoding)
+ (xlfd_start, kw['size'], encoding)
kw['attr'] = 'Roman'
return apply(self.xlfd, (), kw)
@@ -429,8 +429,8 @@
text.register_sort('family', FamilySort, 'Times' )
text.register_sort('attr', AttrSort, 'Roman')
text.register_sort('size', SizeSort, 12)
-
-
+
+
text.style_add(Style(size=24),'1.5','2.13')
text.pool.dump()
text.style_add(Style(size=72),'1.4','2.14')
Modified: skencil/branches/skencil-0.6/src/Plugins/Objects/lcdtext.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Objects/lcdtext.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Objects/lcdtext.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -34,61 +34,61 @@
segments = ((( 0, 18), (10, 18), ( 8, 16), ( 2, 16), ( 0, 18)),
- (( 0, 18), ( 2, 16), ( 2, 10), ( 0, 9), ( 0, 18)),
- ((10, 18), (10, 9), ( 8, 10), ( 8, 16), (10, 18)),
- (( 0, 9), ( 2, 10), ( 8, 10), (10, 9), ( 8, 8), (2, 8), (0, 9)),
- (( 0, 9), ( 2, 8), ( 2, 2), ( 0, 0), ( 0, 9)),
- ((10, 9), (10, 0), ( 8, 2), ( 8, 8), (10, 9)),
- (( 0, 0), ( 2, 2), ( 8, 2), (10, 0), ( 0, 0)))
+ (( 0, 18), ( 2, 16), ( 2, 10), ( 0, 9), ( 0, 18)),
+ ((10, 18), (10, 9), ( 8, 10), ( 8, 16), (10, 18)),
+ (( 0, 9), ( 2, 10), ( 8, 10), (10, 9), ( 8, 8), (2, 8), (0, 9)),
+ (( 0, 9), ( 2, 8), ( 2, 2), ( 0, 0), ( 0, 9)),
+ ((10, 9), (10, 0), ( 8, 2), ( 8, 8), (10, 9)),
+ (( 0, 0), ( 2, 2), ( 8, 2), (10, 0), ( 0, 0)))
chardefs = (('0DO', (0, 1, 2, 4, 5, 6)),
- ('1Il', (2, 5)),
- ('2Zz', (0, 2, 3, 4, 6)),
- ('3', (0, 2, 3, 5, 6)),
- ('4', (1, 2, 3, 5)),
- ('5Ss', (0, 1, 3, 5, 6)),
- ('6G', (0, 1, 3, 4, 5, 6)),
- ('7', (0, 2, 5)),
- ('8BQ', (0, 1, 2, 3, 4, 5, 6)),
- ('9gq', (0, 1, 2, 3, 5, 6)),
- ('AR', (0, 1, 2, 3, 4, 5)),
- ('C([{', (0, 1, 4, 6)),
- ('E', (0, 1, 3, 4, 6)),
- ('Ff', (0, 1, 3, 4)),
- ('HKMNWXkmwx', (1, 2, 3, 4, 5)),
- ('J', (2, 4, 5, 6)),
- ('L', (1, 4, 6)),
- ('Pp', (0, 1, 2, 3, 4)),
- ('T', (0, 1, 4)),
- ('UV', (1, 2, 4, 5, 6)),
- ('Yy', (1, 2, 3, 4)),
- ('b', (1, 3, 4, 5, 6)),
- ('c', (3, 4, 6)),
- ('d', (2, 3, 4, 5, 6)),
- ('e', (0, 1, 2, 3, 4, 6)),
- ('h', (1, 3, 4, 5)),
- ('i', (5,)),
- ('j', (5, 6)),
- ('n', (3, 4, 5)),
- ('oa', (3, 4, 5, 6)),
- ('r', (3, 4)),
- ('t', (1, 3, 4, 6)),
- ('uv', (4, 5, 6)),
- ("'", (2,)),
- ("`", (1,)),
- ('"', (1, 2)),
- ('-', (3,)),
- (' ', ()),
- ('_', (6,)),
- (')]}', (0, 2, 5, 6)),
- (',', (4,)),
- ('?', (0, 2, 3, 4)),
- )
+ ('1Il', (2, 5)),
+ ('2Zz', (0, 2, 3, 4, 6)),
+ ('3', (0, 2, 3, 5, 6)),
+ ('4', (1, 2, 3, 5)),
+ ('5Ss', (0, 1, 3, 5, 6)),
+ ('6G', (0, 1, 3, 4, 5, 6)),
+ ('7', (0, 2, 5)),
+ ('8BQ', (0, 1, 2, 3, 4, 5, 6)),
+ ('9gq', (0, 1, 2, 3, 5, 6)),
+ ('AR', (0, 1, 2, 3, 4, 5)),
+ ('C([{', (0, 1, 4, 6)),
+ ('E', (0, 1, 3, 4, 6)),
+ ('Ff', (0, 1, 3, 4)),
+ ('HKMNWXkmwx', (1, 2, 3, 4, 5)),
+ ('J', (2, 4, 5, 6)),
+ ('L', (1, 4, 6)),
+ ('Pp', (0, 1, 2, 3, 4)),
+ ('T', (0, 1, 4)),
+ ('UV', (1, 2, 4, 5, 6)),
+ ('Yy', (1, 2, 3, 4)),
+ ('b', (1, 3, 4, 5, 6)),
+ ('c', (3, 4, 6)),
+ ('d', (2, 3, 4, 5, 6)),
+ ('e', (0, 1, 2, 3, 4, 6)),
+ ('h', (1, 3, 4, 5)),
+ ('i', (5,)),
+ ('j', (5, 6)),
+ ('n', (3, 4, 5)),
+ ('oa', (3, 4, 5, 6)),
+ ('r', (3, 4)),
+ ('t', (1, 3, 4, 6)),
+ ('uv', (4, 5, 6)),
+ ("'", (2,)),
+ ("`", (1,)),
+ ('"', (1, 2)),
+ ('-', (3,)),
+ (' ', ()),
+ ('_', (6,)),
+ (')]}', (0, 2, 5, 6)),
+ (',', (4,)),
+ ('?', (0, 2, 3, 4)),
+ )
char_segs = {}
for chars, segs in chardefs:
for char in chars:
- char_segs[char] = segs
+ char_segs[char] = segs
@@ -101,55 +101,55 @@
is_curve = 1
def __init__(self, text = '0', size = 12.0, trafo = None, loading = 0,
- duplicate = None):
- TrafoPlugin.__init__(self, trafo = trafo, duplicate = duplicate)
- if duplicate is not None:
- self.text = duplicate.text
- self.size = duplicate.size
- else:
- self.text = text
- self.size = size
- if not loading:
- self.recompute()
+ duplicate = None):
+ TrafoPlugin.__init__(self, trafo = trafo, duplicate = duplicate)
+ if duplicate is not None:
+ self.text = duplicate.text
+ self.size = duplicate.size
+ else:
+ self.text = text
+ self.size = size
+ if not loading:
+ self.recompute()
def recompute(self):
- paths = []
- trafo = self.trafo(Scale(self.size / float(char_scale)))
- width = 0
- for char in self.text:
- segs = char_segs.get(char)
- if segs is not None:
- for seg in segs:
- path = CreatePath()
- map(path.AppendLine, segments[seg])
- path.ClosePath()
- path.Translate(width, 0)
- path.Transform(trafo)
- paths.append(path)
- width = width + char_width
+ paths = []
+ trafo = self.trafo(Scale(self.size / float(char_scale)))
+ width = 0
+ for char in self.text:
+ segs = char_segs.get(char)
+ if segs is not None:
+ for seg in segs:
+ path = CreatePath()
+ map(path.AppendLine, segments[seg])
+ path.ClosePath()
+ path.Translate(width, 0)
+ path.Transform(trafo)
+ paths.append(path)
+ width = width + char_width
- paths = tuple(paths)
- if self.objects:
- self.objects[0].SetPaths(paths)
- else:
- self.set_objects([PolyBezier(paths)])
+ paths = tuple(paths)
+ if self.objects:
+ self.objects[0].SetPaths(paths)
+ else:
+ self.set_objects([PolyBezier(paths)])
def Text(self):
- return self.text
+ return self.text
def Size(self):
- return self.size
+ return self.size
def SaveToFile(self, file):
- TrafoPlugin.SaveToFile(self, file, self.text, self.size,
- self.trafo.coeff())
+ TrafoPlugin.SaveToFile(self, file, self.text, self.size,
+ self.trafo.coeff())
def Info(self):
- return _("LCD Text: `%(text)s', size %(size)g") % self.__dict__
+ return _("LCD Text: `%(text)s', size %(size)g") % self.__dict__
def AsBezier(self):
- return self.objects[0].AsBezier()
+ return self.objects[0].AsBezier()
def Paths(self):
- return self.objects[0].Paths()
+ return self.objects[0].Paths()
Modified: skencil/branches/skencil-0.6/src/Plugins/Objects/multilinetext.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Objects/multilinetext.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Objects/multilinetext.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -26,7 +26,7 @@
import Tkinter
from Tkconstants import *
from Tkinter import StringVar, Entry, Label, Button, Frame, Text, END, \
- BOTH, LEFT, TOP, X, W, GROOVE, Frame, Label, StringVar, Radiobutton
+ BOTH, LEFT, TOP, X, W, GROOVE, Frame, Label, StringVar, Radiobutton
import os
from string import split, rstrip
@@ -35,7 +35,7 @@
import Sketch.const
from Sketch import Scale, TrafoPlugin, SimpleText, Translation, Identity, \
- GetFont, StandardColors, SolidPattern, UndoAfter, _
+ GetFont, StandardColors, SolidPattern, UndoAfter, _
from Sketch.UI.sketchdlg import SketchPanel
from Lib.multilinetext.TextEditor import TextEditor, FONTS, Style, \
@@ -130,7 +130,7 @@
font = GetFont(psfont)
textObj.SetProperties(font=font, font_size=size,
- fill_pattern=fill)
+ fill_pattern=fill)
left, bottom, right, top = textObj.coord_rect
width = right-left
@@ -223,9 +223,9 @@
self.text = ''
text_field = TextEditor(top,
- background = 'white',
- width = 40,
- height = 20)
+ background = 'white',
+ width = 40,
+ height = 20)
text_field.pack(fill = BOTH, expand = 1)
text_field.button_apply.configure(command=self.apply)
Modified: skencil/branches/skencil-0.6/src/Plugins/Objects/regpoly.py
===================================================================
--- skencil/branches/skencil-0.6/src/Plugins/Objects/regpoly.py 2010-09-22 21:54:21 UTC (rev 731)
+++ skencil/branches/skencil-0.6/src/Plugins/Objects/regpoly.py 2010-09-22 21:54:38 UTC (rev 732)
@@ -40,50 +40,50 @@
is_curve = 1
def __init__(self, vertices = 5, radius = 50.0, trafo = None, loading = 0,
- duplicate = None):
- TrafoPlugin.__init__(self, trafo = trafo, duplicate = duplicate)
- if duplicate is not None:
- self.vertices = duplicate.vertices
- self.radius = duplicate.radius
- else:
- self.vertices = vertices
- self.radius = radius
- if not loading:
- self.recompute()
+ duplicate = None):
+ TrafoPlugin.__init__(self, trafo = trafo, duplicate = duplicate)
+ if duplicate is not None:
+ self.vertices = duplicate.vertices
+ self.radius = duplicate.radius
+ else:
+ self.vertices = vertices
+ self.radius = radius
+ if not loading:
+ self.recompute()
def recompute(self):
- path = CreatePath()
- vertices = self.vertices
- radius = self.radius
- twopi = 2 * pi
- halfpi = pi / 2
- for i in range(vertices + 1):
- path.AppendLine(Polar(radius, (twopi * i) / vertices + halfpi),
- ContAngle)
- path.ClosePath()
- path.Transform(self.trafo)
- if self.objects:
- self.objects[0].SetPaths((path,))
- else:
- self.set_objects([PolyBezier((path,))])
+ path = CreatePath()
+ vertices = self.vertices
+ radius = self.radius
+ twopi = 2 * pi
+ halfpi = pi / 2
+ for i in range(vertices + 1):
+ path.AppendLine(Polar(radius, (twopi * i) / vertices + halfpi),
+ ContAngle)
+ path.ClosePath()
+ path.Transform(self.trafo)
+ if self.objects:
+ self.objects[0].SetPaths((path,))
+ else:
+ self.set_objects([PolyBezier((path,))])
def Vertices(self):
- return self.vertices
+ return self.vertices
def Radius(self):
- return self.radius
+ return self.radius
def SaveToFile(self, file):
- TrafoPlugin.SaveToFile(self, file, self.vertices, self.radius,
- self.trafo.coeff())
+ TrafoPlugin.SaveToFile(self, file, self.vertices, self.radius,
+ self.trafo.coeff())
def Info(self):
- return _("Regular Polygon: %(vertices)d vertices, "
+ return _("Regular Polygon: %(vertices)d vertices, "
"radius %(radius)[length]"), self.__dict__
def AsBezier(self):
- return self.objects[0].AsBezier()
+ return self.objects[0].AsBezier()
def Paths(self):
- return self.objects[0].Paths()
+ return self.objects[0].Paths()
More information about the Skencil-commits
mailing list