コード例 #1
0
	def bugmark(self, P):
		P = P - Point(1, 1)
		style = basestyle.Duplicate()
		style.fill_pattern = SolidPattern(StandardColors.black)
		style.line_pattern = SolidPattern(StandardColors.black)
		self.prop_stack.AddStyle(style)
		self.rectangle(2, 0, 0, 2, P.x, P.y)
コード例 #2
0
	def setfillstyle(self):
		style = basestyle.Duplicate()
		if reff.fill.type == 1:
			style.fill_pattern = SolidPattern(apply(CreateRGBColor , reff.fill.color))
		elif reff.fill.type == 3:
			style.fill_pattern = HatchingPattern(apply(CreateRGBColor , reff.fill.color),
													StandardColors.white,
													Point(2.0, 1.0), 5 , 1)
		if reff.edge.visible:
			style.line_pattern = SolidPattern(apply(CreateRGBColor , reff.edge.color))
			style.line_width = reff.edge.width
			if reff.edge.widthmode == 0:
				style.line_width = style.line_width * self.Scale
			style.line_dashes = reff.edge.dashtable[reff.edge.type - 1]
		self.prop_stack.AddStyle(style)
コード例 #3
0
 def ls(self):
     style = self.style
     style.line_pattern = SolidPattern(self.line_color)
     style.line_width = self.line_width
     style.line_join = self.line_join
     style.line_cap = self.line_cap
     style.line_dashes = self.line_dashes
コード例 #4
0
	def set_style(self, obj):
		style = self.style
		if obj.colorIndex:
			if self.info.fill_data.has_key(obj.colorIndex):
				style.fill_pattern = SolidPattern(self.info.fill_data[obj.colorIndex])
			else:
				style.fill_pattern = EmptyPattern
		else:
			style.fill_pattern = EmptyPattern
			
		if obj.outlineIndex:
			if self.info.outl_data.has_key(obj.outlineIndex):
				if self.info.outl_data[obj.outlineIndex].spec & 0x01:
					style.line_pattern = EmptyPattern
				else:
					style.line_pattern = SolidPattern(self.info.outl_data[obj.outlineIndex].color)
				
				if self.info.outl_data[obj.outlineIndex].spec & 0x04:
					style.line_dashes = self.info.outl_data[obj.outlineIndex].dashes
				
				if self.info.outl_data[obj.outlineIndex].spec & 0x20:
					style.line_width = self.info.outl_data[obj.outlineIndex].width*obj.scale
				else:
					style.line_width = self.info.outl_data[obj.outlineIndex].width
					
				style.line_cap = self.info.outl_data[obj.outlineIndex].caps + 1
				style.line_join = self.info.outl_data[obj.outlineIndex].corner
			else:
				style.line_pattern = EmptyPattern
		else:
			if self.info.default_outl_data:
				if self.info.default_outl_data.spec & 0x01:
					style.line_pattern = EmptyPattern
				else:
					style.line_pattern = SolidPattern(self.info.default_outl_data.color)
					
				if self.info.default_outl_data.spec & 0x04:
					style.line_dashes = self.info.default_outl_data.dashes

				if self.info.default_outl_data.spec & 0x20:
					style.line_width = self.info.default_outl_data.width*obj.scale
				else:
					style.line_width = self.info.default_outl_data.width
				style.line_cap = self.info.default_outl_data.caps + 1
				style.line_join = self.info.default_outl_data.corner
			else:
				style.line_pattern = EmptyPattern
コード例 #5
0
 def apply_pattern(self):
     kw = {}
     if self.current_color is None:
         kw["line_pattern"] = EmptyPattern
     else:
         kw["line_pattern"] = SolidPattern(self.current_color)
     styledlg.set_properties(self.mw.root, self.document,
                             _("Set Outline Color"), 'line', kw)
コード例 #6
0
	def setlinestyle(self):
		style = basestyle.Duplicate()
		style.line_pattern = SolidPattern(apply(CreateRGBColor , reff.line.color))
		style.line_width = reff.line.width
		if reff.line.widthmode == 0:
			style.line_width = style.line_width * self.Scale
		style.line_dashes = reff.line.dashtable[reff.line.type - 1]
		self.prop_stack.AddStyle(style)
コード例 #7
0
	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),))

		self._print('->', style, r, g, b, hatch)
コード例 #8
0
    def ta_set_colour(self, colour):

        if tuple(colour) == (255, 255, 255):

            return EmptyPattern
        else:
            return SolidPattern(
                CreateRGBColor(
                    float(colour[0]) / 255.0,
                    float(colour[1]) / 255.0,
                    float(colour[2]) / 255.0))
コード例 #9
0
 def apply_properties(self):
     kw = {}
     if self.color is not None:
         kw["line_pattern"] = SolidPattern(self.color)
         kw["line_width"] = self.var_width.get()
         kw["line_join"] = self.var_corner.get()
         kw["line_cap"] = self.var_caps.get()
         kw["line_dashes"] = self.dash
     else:
         kw["line_pattern"] = EmptyPattern
     styledlg.set_properties(self.mw.root, self.document,
                             _("Set Outline Properties"), 'line', kw)
コード例 #10
0
    def next_color(self, index=None):
        if index is None:
            index = self.index + 1
        self.index = index

        if not self.from_file and self.order:
            index = self.order[self.index - 1]

        if index in self.items:
            color = self.items[index]
        else:
            color = StandardColors.black
        return SolidPattern(color)
コード例 #11
0
	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))
		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)
コード例 #12
0
    def change_color(self, object):
        if object.has_properties:
            properties = object.Properties()
            pattern = properties.fill_pattern
            if pattern.is_Solid:
                if pattern.Color() == self.color:
                    pattern = SolidPattern(black)
                else:
                    pattern = SolidPattern(white)
                undo = properties.SetProperty(fill_pattern=pattern)
                self.undo.append(undo)

            pattern = properties.line_pattern
            if pattern.is_Solid:
                if pattern.Color() == self.color:
                    pattern = SolidPattern(black)
                else:
                    pattern = SolidPattern(white)
                undo = properties.SetProperty(line_pattern=pattern)
                self.undo.append(undo)
コード例 #13
0
 def select_pen(self, pen='1'):
     if not pen in colors:
         pen = '1'
     if not pen in self.penwidth:
         width = def_width_pen
     else:
         width = self.penwidth[pen]
     if not self.curpen == pen:
         if self.draw == 1:
             self.pen_up()
             self.pen_down()
         patern = SolidPattern(colors[pen])
         self.curstyle.line_pattern = patern
         self.curstyle.line_width = width
         self.curpen = pen
コード例 #14
0
	def get_pattern(self, color, style = None):
		if style == -1:
			return EmptyPattern
		rgb = self.colors[color]
		if style is not None:
			if color in (BLACK, DEFAULT_COLOR):
				if style > 0 and style <= 20:
					rgb = Blend(self.colors[WHITE], rgb, (20 - style) / 20.0)
				elif style == 0:
					rgb = self.colors[WHITE]
			else:
				if style >= 0 and style < 20:
					rgb = Blend(self.colors[BLACK], rgb, (20 - style) / 20.0)
				elif style > 20 and style <= 40:
					rgb = Blend(self.colors[WHITE], rgb, (style - 20) / 20.0)
		return SolidPattern(rgb)
コード例 #15
0
def create_text(context):
    # Create the text 'xyzzy' at 100,100. The first parameter to the
    # constructor is an affine transformation.
    text = SimpleText(Translation(100, 100), "xyzzy")

    # Set the font to 36pt Times-Bold and fill with solid green.
    # The text object is modified by this method, but the text object is
    # not yet part of the document, so we don't have to deal with undo
    # here.
    text.SetProperties(fill_pattern=SolidPattern(StandardColors.green),
                       font=GetFont('Times-Bold'),
                       font_size=36)
    # Finally, insert the text object at the top of the current layer
    # and select it. Like all public document methods that modify the
    # document, the Insert method takes care of undo information itself.
    context.document.Insert(text)
コード例 #16
0
	def TEXT(self, size):
		P = self.Pnt()
		F = self.Enum()
		S = self.getstr()
		T = Translation(self.trafo(P))
		Py = Point(reff.text.orientation[0]).normalized()
		Px = Point(reff.text.orientation[1]).normalized()
		B = transform_base(Point(0.0, 0.0) , reff.text.expansion * Px , Py)
		self.style = basestyle.Duplicate()
		self.style.font = GetFont(fntlst[self.fntmap[reff.text.fontindex]])
		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())
		self.append_object(O)
コード例 #17
0
	def __init__(self, loader):
		self.loader = loader
		self.trafo = self.basetrafo = None
		self.state_stack = ()
		self.style = loader.style.Copy()
		self.style.line_pattern = EmptyPattern
		self.style.fill_pattern = SolidPattern(StandardColors.black)
		self.current_text = None
		self.style.font = GetFont("Times-Roman")
		self.style.font_size = 12
		self.halign = text.ALIGN_LEFT
		self.elements_id = {}
		self.elements = []
		self.in_defs = 0
		self.in_use = 0
		self.paths = None
		self.path = None
		self.depth = 0
		self.indent = '    '
		self.viewPort = (0, 0, 210*factors['mm'], 297*factors['mm'])
コード例 #18
0
	def get_pattern(self, color_index):
		# 0 = Color BYBLOCK
		if color_index == 0:
			block_name = self.default_block
			if block_name is None:
				layer_name = '0'
			else:
				layer_name = self.block_dict[block_name]['8']
			color_index = self.layer_dict[layer_name]['62']
		# 256 = Color BYLAYER
		if  color_index == 256 or color_index is None:
			layer_name = self.default_layer
			color_index = self.layer_dict[layer_name]['62']
		## FIXMY 257 = Color BYENTITY
		
		if color_index < 0:
			pattern = EmptyPattern
		else:
			pattern = SolidPattern(colors[color_index])
		
		return pattern
コード例 #19
0
def create_star(context):
	# Instantiate the modal dialog...
	dlg = CreateStarDlg(context.application.root)
	# ... and run it.
	result = dlg.RunDialog()
	if result is not None:
		# if the result is not None, the user pressed OK. Now constuct
		# the star-path...
		corners, steps, radius = result
		path = create_star_path(corners, steps, radius)
	
		# ... and create the bezier object. The parameter to the
		# constructor must be a tuple of paths
		bezier = PolyBezier((path,))

		# Set the line color to blue, the line width to 4pt
		bezier.SetProperties(line_pattern = SolidPattern(StandardColors.blue),
								line_width = 4)

		# and insert it into the document
		context.main_window.PlaceObject(bezier)
コード例 #20
0
 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))
コード例 #21
0
 def ps(self, color):
     self.pattern = SolidPattern(self.convert_color(color))
コード例 #22
0
   CreateRGBAColor, CreateCMYKAColor, CreateSPOTAColor
from app import SolidPattern, HatchingPattern,EmptyPattern, \
  LinearGradient, ConicalGradient, RadialGradient, ImageTilePattern, \
  Style, MultiGradient, Trafo, Translation, Point, \
  GridLayer, GuideLayer, GuideLine, Arrow, CreatePath, StandardColors, \
  GetFont

from app.io.load import GenericLoader

from app.Graphics import pagelayout, plugobj, blendgroup, text, image, eps,\
  properties

base_style = Style()
base_style.fill_pattern = EmptyPattern
base_style.fill_transform = 1
base_style.line_pattern = SolidPattern(StandardColors.black)
base_style.line_width = 0.0
base_style.line_join = const.JoinMiter
base_style.line_cap = const.CapButt
base_style.line_dashes = ()
base_style.line_arrow1 = None
base_style.line_arrow2 = None
base_style.font = None
base_style.font_size = 12.0

# 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, getattr(properties.factory_defaults, key))
コード例 #23
0
	def setSolidPatternOutline(self, object, color, cs_name):
		if color.model == cs_name:
			return
		color=self.convert_color(color, cs_name)
		undo=(object.SetProperties(line_pattern=SolidPattern(color)))
		return undo
コード例 #24
0
	def import_curves(self):
		objcount=0
		objnum=len(self.info.paths_heap)
		jump=87.0/objnum
		interval=int((objnum/20)/10)+1
		interval_count=0
		for obj in self.info.paths_heap:
			objcount+=1
			interval_count+=1
			if interval_count>interval:
				interval_count=0
				app.updateInfo(inf2=_("Interpreting object %u of %u")%(objcount,objnum),inf3=10+int(jump*objcount))
			if obj==1:
				self.begin_group()
			elif obj==0:
				self.end_group()
			elif type(obj)==TupleType and obj[0]=='BMP':
				self.image(obj[1],obj[2])
			else:
				style = self.style
				if obj.colorIndex:
					if self.info.fill_data.has_key(obj.colorIndex):
						style.fill_pattern = SolidPattern(self.info.fill_data[obj.colorIndex])
					else:
						style.fill_pattern = EmptyPattern
				else:
					style.fill_pattern = EmptyPattern
					
				if obj.outlineIndex:
					if self.info.outl_data.has_key(obj.outlineIndex):
						if self.info.outl_data[obj.outlineIndex].spec & 0x01:
							style.line_pattern = EmptyPattern
						else:
							style.line_pattern = SolidPattern(self.info.outl_data[obj.outlineIndex].color)
						
						if self.info.outl_data[obj.outlineIndex].spec & 0x04:
							style.line_dashes = self.info.outl_data[obj.outlineIndex].dashes
						
						if self.info.outl_data[obj.outlineIndex].spec & 0x20:
							style.line_width = self.info.outl_data[obj.outlineIndex].width*obj.scale
						else:
							style.line_width = self.info.outl_data[obj.outlineIndex].width
							
						style.line_cap = self.info.outl_data[obj.outlineIndex].caps + 1
						style.line_join = self.info.outl_data[obj.outlineIndex].corner
					else:
						style.line_pattern = EmptyPattern
				else:
					if self.info.default_outl_data:
						if self.info.default_outl_data.spec & 0x01:
							style.line_pattern = EmptyPattern
						else:
							style.line_pattern = SolidPattern(self.info.default_outl_data.color)
							
						if self.info.default_outl_data.spec & 0x04:
							style.line_dashes = self.info.default_outl_data.dashes

						if self.info.default_outl_data.spec & 0x20:
							style.line_width = self.info.default_outl_data.width*obj.scale
						else:
							style.line_width = self.info.default_outl_data.width
						style.line_cap = self.info.default_outl_data.caps + 1
						style.line_join = self.info.default_outl_data.corner
					else:
						style.line_pattern = EmptyPattern
						
				object = PolyBezier(paths = tuple(obj.paths), properties = self.get_prop_stack())
				self.append_object(object)
				
				if obj.outlineIndex:
					if self.info.outl_data[obj.outlineIndex].spec & 0x10:
						copy = object.Duplicate()
						copy.properties.SetProperty(line_width=0)
						self.append_object(copy)
				else:
					if self.info.default_outl_data.spec & 0x10:
						copy = object.Duplicate()
						copy.properties.SetProperty(line_width=0)
						self.append_object(copy)
コード例 #25
0
	def DibCreatePatternBrush(self):
		self.add_message(_("Bitmap brushes not yet implemented. Using black"))
		pattern = SolidPattern(StandardColors.black)
		self.add_gdiobject((('fill_pattern', pattern),))
コード例 #26
0
 def fs(self):
     if self.gradient_geo:
         pattern = self.make_gradient_pattern()
     else:
         pattern = SolidPattern(self.fill_color)
     self.style.fill_pattern = pattern
コード例 #27
0
	def try_add_style(self,key,val):
		if key == 'fill':
			if val == 'none':
				self.style.fill_pattern = EmptyPattern
			elif val[:3] == 'url' and self.grad_patters.has_key(val[5:-1]):
				grad=self.grad_patters[val[5:-1]]
				try:
					if grad[0]=='LinearGradient':
						point1,point2=grad[2]
						point1=self.trafo(point1)
						point2=self.trafo(point2)	
						point=Point(point2.x-point1.x, point2.y-point1.y)
						if not grad[1].__class__ == MultiGradient:
							if self.gradients.has_key(grad[1]):
								self.style.fill_pattern = LinearGradient(self.gradients[grad[1]].Duplicate(),point)
						else:
							self.style.fill_pattern = LinearGradient(grad[1].Duplicate(),point)
					if grad[0]=='RadialGradient':
						point1,point2=grad[2]
						point1=self.trafo(point1)
						point2=self.trafo(point2)
						point1=Point(0.5,0.5)						
						if not grad[1].__class__ == MultiGradient:
							if self.gradients.has_key(grad[1]):
								self.style.fill_pattern = RadialGradient(self.gradients[grad[1]].Duplicate(),point1)
						else:
							self.style.fill_pattern = RadialGradient(grad[1].Duplicate(),point1)
				except:
					pass
					
			else:
				color = csscolor(val)
				self._print('fill', color)
				self.style.fill_pattern = SolidPattern(color)
		elif key == 'fill-opacity':
			value=atof(val)
			if self.style.fill_pattern.__class__ == SolidPattern:
				self.style.fill_pattern.Color().alpha*=value
				self.style.fill_pattern.Color().update()
		elif key == 'stroke':
			if val == 'none':
				self.style.line_pattern = EmptyPattern
			else:
				color = csscolor(val)
				self._print('stroke', color)
				self.style.line_pattern = SolidPattern(color)
				if not self.opacity is None:
					self.style.line_pattern.Color().alpha=self.opacity
					self.style.line_pattern.Color().update()
		elif key == 'stroke-opacity':
			value=atof(val)
			if self.style.line_pattern.__class__ == SolidPattern:
				self.style.line_pattern.Color().alpha*=value
				self.style.line_pattern.Color().update()
		elif key == 'opacity':
			value=atof(val)
			self.opacity=value
			if self.style.fill_pattern.__class__ == SolidPattern:
				self.style.fill_pattern.Color().alpha=value
				self.style.fill_pattern.Color().update()
			if self.style.line_pattern.__class__ == SolidPattern:
				self.style.line_pattern.Color().alpha=self.opacity
				self.style.line_pattern.Color().update()			
		elif key == 'stroke-width':
			width = self.user_length(val)
			# Multiply the width with a value taken from the
			# transformation matrix because so far transforming an
			# object in Sketch does not affect the stroke width in any
			# way. Thus we have to do that explicitly here.
			# FIXME: using m11 is not really the best approach but in
			# many cases better than using the width as is.
			width = self.trafo.m11 * width
			self._print('width', width)
			self.style.line_width = abs(width)
		elif key == 'stroke-linejoin':
			self.style.line_join = join[val]
		elif key == 'stroke-linecap':
			self.style.line_cap = cap[val]
		elif key == 'font-family':
			self.style.font = GetFont(val)
		elif key == '-inkscape-font-specification':
			self.style.font = GetFont(val)			
		elif key == 'font-size':
			self.style.font_size = self.user_length(val)
			####self.style.font_size = float(val)
		elif key == 'text-anchor':
			if val=='start':
				self.halign = text.ALIGN_LEFT
			elif val == 'middle':
				self.halign = text.ALIGN_CENTER
			elif val == 'end':
				self.halign = text.ALIGN_RIGHT
コード例 #28
0
    def read_objects(self, objects):

        n_objects = 0

        # Traverse the list of drawfile object
        for object in objects:

            if isinstance(object, drawfile.group):

                # Start a group object in the document
                self.begin_group()

                # Descend into the group
                n_objects_lower = self.read_objects(object.objects)

                # If the group was empty then don't try to end it
                if n_objects_lower == 0:
                    #                    self.__pop()
                    (self.composite_class, self.composite_args,
                     self.composite_items,
                     self.composite_stack) = self.composite_stack
                else:
                    # End group object
                    self.end_group()
                    n_objects = n_objects + 1

            elif isinstance(object, drawfile.tagged):

                # Tagged object
                n_objects_lower = self.read_objects([object.object])

                if n_objects_lower != 0:
                    n_objects = n_objects + 1

            elif isinstance(object, drawfile.path):

                # Path object
                n_objects = n_objects + 1

                # Set the path style
                self.style.line_width = object.width / scale

                if object.style['join'] == 'mitred':
                    self.style.line_join = const.JoinMiter

                if object.style['start cap'] == 'butt':
                    self.style.line_cap = const.CapButt

                elif object.style['start cap'] == 'round':

                    if object.width > 0:
                        width = 0.5
                        length = 0.5
                    else:
                        width = 0.0
                        length = 0.0

                    # Draw arrow
                    path = [(0.0, width),
                            (0.5 * length, width, length, 0.5 * width, length,
                             0.0),
                            (length, -0.5 * width, 0.5 * length, -width, 0.0,
                             -width), (0.0, width)]

                    self.style.line_arrow1 = Arrow(path, 1)

                elif object.style['start cap'] == 'square':

                    if object.width > 0:
                        width = 0.5
                        length = 0.5
                    else:
                        width = 0.0
                        length = 0.0

                    # Draw arrow
                    path = [(0.0, width), (length, width), (length, -width),
                            (0.0, -width), (0.0, width)]

                    self.style.line_arrow1 = Arrow(path, 1)

                elif object.style['start cap'] == 'triangular':

                    if object.width > 0:
                        width = object.style['triangle cap width'] / 16.0
                        length = object.style['triangle cap length'] / 16.0
                    else:
                        width = 0.0
                        length = 0.0

                    # Draw arrow
                    path = [(0.0, width), (length, 0.0), (0.0, -width),
                            (0.0, width)]

                    self.style.line_arrow1 = Arrow(path, 1)
                    if (object.width / scale) < 1.0:
                        self.style.line_arrow1.path.Transform(
                            Scale(object.width / scale, object.width / scale))

                if object.style['end cap'] == 'butt':
                    self.style.line_cap = const.CapButt

                elif object.style['end cap'] == 'round':

                    if object.width > 0:
                        width = 0.5
                        length = 0.5
                    else:
                        width = 0.0
                        length = 0.0

                    # Draw arrow
                    path = [(0.0, width),
                            (0.5 * length, width, length, 0.5 * width, length,
                             0.0),
                            (length, -0.5 * width, 0.5 * length, -width, 0.0,
                             -width), (0.0, width)]

                    self.style.line_arrow2 = Arrow(path, 1)

                elif object.style['end cap'] == 'square':

                    if object.width > 0:
                        width = 0.5
                        length = 0.5
                    else:
                        width = 0.0
                        length = 0.0

                    # Draw arrow
                    path = [(0.0, width), (length, width), (length, -width),
                            (0.0, -width), (0.0, width)]

                    self.style.line_arrow2 = Arrow(path, 1)

                elif object.style['end cap'] == 'triangular':

                    if object.width > 0:
                        width = object.style['triangle cap width'] / 16.0
                        length = object.style['triangle cap length'] / 16.0
                    else:
                        width = 0.0
                        length = 0.0

                    # Draw arrow
                    path = [(0.0, width), (length, 0.0), (0.0, -width),
                            (0.0, width)]

                    self.style.line_arrow2 = Arrow(path, 1)
                    if (object.width / scale) < 1.0:
                        self.style.line_arrow2.path.Transform(
                            Scale(object.width / scale, object.width / scale))

                # Outline colour
                if object.outline == [255, 255, 255, 255]:
                    self.style.line_pattern = EmptyPattern
                else:
                    self.style.line_pattern = SolidPattern(
                        CreateRGBColor(
                            float(object.outline[1]) / 255.0,
                            float(object.outline[2]) / 255.0,
                            float(object.outline[3]) / 255.0))

                # Fill colour
                if object.fill == [255, 255, 255, 255]:
                    self.style.fill_pattern = EmptyPattern
                else:
                    self.style.fill_pattern = SolidPattern(
                        CreateRGBColor(
                            float(object.fill[1]) / 255.0,
                            float(object.fill[2]) / 255.0,
                            float(object.fill[3]) / 255.0))

                # Dash pattern
                if object.style['dash pattern'] == 'present':
                    line_dashes = []
                    for n in object.pattern:

                        line_dashes.append(int(n / scale))

                    self.style.line_dashes = tuple(line_dashes)

                # Create a list of path objects in the document
                paths = []
                path = None

                # Examine the path elements
                for element in object.path:

                    if element[0] == 'move':

                        x, y = self.relative(element[1][0], element[1][1])

                        # Add any previous path to the list
                        if path != None:
                            #                            path.load_close()
                            paths.append(path)

                        path = CreatePath()
                        path.AppendLine(x, y)

                    elif element[0] == 'draw':

                        x, y = self.relative(element[1][0], element[1][1])
                        path.AppendLine(x, y)

                    elif element[0] == 'bezier':

                        x1, y1 = self.relative(element[1][0], element[1][1])
                        x2, y2 = self.relative(element[2][0], element[2][1])
                        x, y = self.relative(element[3][0], element[3][1])
                        path.AppendBezier(x1, y1, x2, y2, x, y)

                    elif element[0] == 'close':

                        path.ClosePath()

                    elif element[0] == 'end':

                        # Should be the last object in the path
                        #                        path.load_close()
                        paths.append(path)
                        break

                # Create a bezier object
                if paths != []:
                    self.bezier(tuple(paths))

            elif isinstance(object, drawfile.font_table):

                # Font table
                n_objects = n_objects + 1

                # Set object level instance
                self.font_table = object.font_table

            elif isinstance(object, drawfile.text):

                # Text object
                n_objects = n_objects + 1

                # Determine the font
                if self.font_table.has_key(object.style):
                    self.style.font = RISCOSFont(self.font_table[object.style])
                else:
                    self.style.font = GetFont('Times Roman')

                # The size
                self.style.font_size = object.size[0] / scale

                # Outline colour
                if object.background == [255, 255, 255, 255]:
                    self.style.line_pattern = EmptyPattern
                else:
                    self.style.line_pattern = SolidPattern(
                        CreateRGBColor(
                            float(object.background[1]) / 255.0,
                            float(object.background[2]) / 255.0,
                            float(object.background[3]) / 255.0))

                # Fill colour
                if object.foreground == [255, 255, 255, 255]:
                    self.style.fill_pattern = EmptyPattern
                else:
                    self.style.fill_pattern = SolidPattern(
                        CreateRGBColor(
                            float(object.foreground[1]) / 255.0,
                            float(object.foreground[2]) / 255.0,
                            float(object.foreground[3]) / 255.0))

                # Transformation
                if hasattr(object, 'transform'):
                    x, y = object.transform[4] / scale, object.transform[
                        5] / scale
                    ox, oy = self.relative(object.baseline[0],
                                           object.baseline[1])
                    transform = Trafo(object.transform[0] / 65536.0,
                                      object.transform[1] / 65536.0,
                                      object.transform[2] / 65536.0,
                                      object.transform[3] / 65536.0, ox + x,
                                      oy + y)
                else:
                    transform = Translation(
                        self.relative(object.baseline[0], object.baseline[1]))

                # Write the text
                self.simple_text(object.text, transform)

            elif isinstance(object, drawfile.jpeg):

                # JPEG object
                n_objects = n_objects + 1

                # Transformation matrix
                x, y = self.relative(object.transform[4], object.transform[5])

                # Scale the object using the dpi information available, noting
                # that unlike Draw which uses 90 dpi, Sketch uses 72 dpi.
                # (I assume this since 90 dpi Drawfile JPEG objects appear 1.25
                # times larger in Sketch if no scaling is performed here.)
                scale_x = (object.transform[0] / 65536.0) * (72.0 /
                                                             object.dpi_x)
                scale_y = (object.transform[3] / 65536.0) * (72.0 /
                                                             object.dpi_y)

                transform = Trafo(scale_x, object.transform[1] / 65536.0,
                                  object.transform[2] / 65536.0, scale_y, x, y)

                # Decode the JPEG image
                image = Image.open(StringIO.StringIO(object.image))

                #                # Read dimensions of images in pixels
                #                width, height = image.size
                #
                #                # Divide these by the dpi values to obtain the size of the
                #                # image in inches
                #                width, height = width/float(object.dpi_x), \
                #                height/float(object.dpi_y)

                #                image.load()
                self.image(image, transform)

            elif isinstance(object, drawfile.sprite):

                # Sprite object
                n_objects = n_objects + 1

                # Transformation matrix

                if hasattr(object, 'transform'):
                    x, y = self.relative(object.transform[4],
                                         object.transform[5])

                    # Multiply the scale factor by that in the transformation matrix
                    scale_x = (object.transform[0] /
                               65536.0) * (72.0 / object.sprite['dpi x'])
                    scale_y = (object.transform[3] /
                               65536.0) * (72.0 / object.sprite['dpi y'])

                    transform = Trafo(scale_x,
                         (object.transform[1] / 65536.0) * \
                         (72.0 / object.sprite['dpi y']),
                         (object.transform[2] / 65536.0) * \
                         (72.0 / object.sprite['dpi x']),
                         scale_y,
                         x, y)
                else:
                    x, y = self.relative(object.x1, object.y1)

                    # Draw scales the Sprite to fit in the object's
                    # bounding box. To do the same, we need to know the
                    # actual size of the Sprite
                    # In points:
                    #                    size_x = 72.0 * float(object.sprite['width']) / \
                    #                                           object.sprite['dpi x']
                    #                    size_y = 72.0 * float(object.sprite['height']) / \
                    #                                           object.sprite['dpi y']
                    #
                    #                    # Bounding box dimensions in points:
                    #                    bbox_width = (object.x2 - object.x1)/scale
                    #                    bbox_height = (object.y2 - object.y1)/scale
                    #
                    #                    # Scale factors
                    #                    scale_x = (bbox_width / size_x) * \
                    #                               (72.0 / object.sprite['dpi x'])
                    #                    scale_y = (bbox_height / size_y) * \
                    #                               (72.0 / object.sprite['dpi y'])
                    scale_x = (object.x2 -
                               object.x1) / (scale * object.sprite['width'])
                    scale_y = (object.y2 -
                               object.y1) / (scale * object.sprite['height'])

                    transform = Trafo(scale_x, 0.0, 0.0, scale_y, x, y)

                # Create an Image object
                image = Image.fromstring(
                    object.sprite['mode'],
                    (object.sprite['width'], object.sprite['height']),
                    object.sprite['image'])

                self.image(image, transform)

            elif isinstance(object, drawfile.options):

                # Options object
                n_objects = n_objects + 1

                # Read page size
                paper_size = object.options['paper size']
                orientation = object.options['paper limits']
                if paper_size in papersizes:

                    if orientation == 'landscape':
                        self.page_layout = pagelayout.PageLayout(
                            object.options['paper size'],
                            orientation=pagelayout.Landscape)
                    else:
                        self.page_layout = pagelayout.PageLayout(
                            object.options['paper size'],
                            orientation=pagelayout.Portrait)

                if object.options['grid locking'] == 'on':

                    spacing = object.options['grid spacing']
                    if object.options['grid units'] == 'in':
                        spacing = spacing * 72.0
                    else:
                        spacing = spacing * 72.0 / 2.54

                    if object.options['grid shown'] == 'on':
                        visible = 1
                    else:
                        visible = 0

#                    self.begin_layer_class( GridLayer,
#                                (
#                                    (0, 0, int(spacing), int(spacing)),
#                                    visible,
#                                    CreateRGBColor(0.0, 0.0, 0.0),
#                                    _("Grid")
#                                ) )
#                    self.end_composite()

            elif isinstance(object, drawfile.text_area):

                # Text area
                n_objects = n_objects + 1

                # The text area object contains a number of columns.
                self.columns = len(object.columns)

                # Start in the first column and move to subsequent
                # columns as required, unless the number is overidden
                # by details in the text area.
                self.column = 0

                # The cursor position is initially undefined.
                cursor = [None, None]

                # The column margins
                self.margin_offsets = [1.0, 1.0]
                self.margins = [ (object.columns[self.column].x1 / scale) + \
                     self.margin_offsets[0],
                     (object.columns[self.column].x2 / scale) - \
                     self.margin_offsets[1] ]

                # The column base
                self.column_base = object.columns[self.column].y1 / scale

                # Line and paragraph spacing
                self.linespacing = 0.0
                paragraph = 10.0

                # Current font name and dimensions
                font_name = ''
                font_size = 0.0
                font_width = 0.0

                # Text colours
                background = (255, 255, 255)
                foreground = (0, 0, 0)

                # Build lines (lists of words) until the column width
                # is reached then write the line to the page.
                line = []
                width = 0.0

                # Current text alignment
                align = 'L'

                # Last command to be executed
                last_command = ''

                # Execute the commands in the text area:
                for command, args in object.commands:

                    if command == '!':
                        # Version number
                        #                        print 'Version number', args
                        pass

                    elif command == 'A':
                        #                        print 'Align:', args
                        # Write current line
                        self.ta_write_line(align, cursor, line, 0)
                        # Empty the line list
                        line = []
                        # Set the line width
                        width = 0.0
                        # Align text
                        align = args
                        # Start new line
                        cursor = self.ta_new_line(cursor, object,
                                                  self.linespacing)

                    elif command == 'B':
                        #                        print 'Background:', args
                        # Background colour
                        background = args

                    elif command == 'C':
                        #                        print 'Foreground:', args
                        # Foreground colour
                        foreground = args

                    elif command == 'D':
                        #                        print 'Columns:', args
                        # Number of columns
                        if self.column == 0 and cursor == [None, None]:
                            # Nothing rendered yet, so change number of columns
                            self.columns = args

                    elif command == 'F':
                        #                        print 'Define font:', args
                        # Define font (already defined in object.font_table)
                        pass

                    elif command == 'L':
                        #                        print 'Line spacing:', args
                        # Set line spacing
                        self.linespacing = args

                    elif command == 'M':
                        #                        print 'Margins:', args
                        # Change margins
                        self.margin_offsets = [args[0], args[1]]
                        self.margins = [
                            (object.columns[self.column].x1 / scale) + args[0],
                            (object.columns[self.column].x2 / scale) - args[1]
                        ]

                    elif command == 'P':
                        #                        print 'Paragraph spacing:', args
                        # Change paragraph spacing
                        paragraph = args

                    elif command == 'U':
                        #                        print 'Underlining'
                        # Underlining
                        pass

                    elif command == 'V':
                        #                        print 'Vertical displacement'
                        # Vertical displacement
                        pass

                    elif command == '-':
                        #                        print 'Hyphen'
                        # Hyphen
                        pass

                    elif command == 'newl':

                        #                        print 'New line'
                        # New line
                        # Write current line
                        self.ta_write_line(align, cursor, line, 0)
                        # Start new line
                        cursor = self.ta_new_line(cursor, object,
                                                  self.linespacing)

                        # Can't position cursor?
                        if cursor == [None, None]:
                            break

                        # Empty the line list
                        line = []
                        # Set the line width
                        width = 0.0

                    elif command == 'para':

                        #                        print 'New paragraph'
                        # New paragraph
                        # Write current line
                        self.ta_write_line(align, cursor, line, 0)
                        # Start new line
                        if last_command != 'newl':
                            cursor = self.ta_new_line(
                                cursor, object, paragraph + self.linespacing)
                        else:
                            cursor = self.ta_new_line(cursor, object,
                                                      paragraph)

                        # Can't position cursor?
                        if cursor == [None, None]:
                            break

                        # Empty the line list
                        line = []
                        # Set the line width
                        width = 0.0

                    elif command == ';':
                        #                        print 'Comment:', args
                        # Comment
                        pass

                    elif command == 'font':
                        #                        print 'Use font:', args
                        # Font change
                        font_name, font_size, font_width = object.font_table[
                            args]
                        # Select font
                        use_font = RISCOSFont(font_name)
                        # Move cursor to start of a line if the cursor is
                        # undefined
                        if cursor == [None, None]:
                            cursor[0] = self.margins[0]
                            cursor[1] = (object.columns[self.column].y2 /
                                         scale) - font_size
                        # Set line spacing
                        self.linespacing = font_size

                    elif command == 'text':

                        #                        print args
                        # Text. Add it to the line, checking that the line
                        # remains within the margins.
                        text, space = self.make_safe(args[0]), args[1]

                        # Add the width of the text to the current total width
                        textobj = SimpleText()
                        width = width + use_font.TextCoordBox(
                            text, font_size, textobj.properties)[2]

                        #                        print width, margins[1] - margins[0]

                        # Compare current total width with column width
                        while width > (self.margins[1] - self.margins[0]):

                            # First write any text on this line
                            if line != []:

                                # Width will exceed column width
                                #                                print 'Width will exceed column width'
                                # Write current line
                                self.ta_write_line(align, cursor, line, 1)
                                # Start new line
                                cursor = self.ta_new_line(
                                    cursor, object, self.linespacing)

                                # Can't position cursor?
                                if cursor == [None, None]:
                                    break

                                # Clear the list
                                line = []
                                # Reset the width
                                width = 0.0

                            # Now attempt to fit this word on the next line
                            width = use_font.TextCoordBox(
                                text, font_size, textobj.properties)[2]

                            br = len(text)
                            # Continue to try until the word fits, or none of it fits
                            while width > (self.margins[1] -
                                           self.margins[0]) and br > 0:

                                # Keep checking the size of the word
                                width = use_font.TextCoordBox(
                                    text[:br], font_size,
                                    textobj.properties)[2]
                                br = br - 1

                            if br == 0:
                                # Word couldn't fit in the column at all, so
                                # break out of this loop
                                break

                            elif br < len(text):
                                # Write the subword to the line
                                self.ta_write_line(
                                    align, cursor,
                                    [(text[:br], font_name,
                                      font_size, font_width,
                                      self.ta_set_colour(foreground),
                                      self.ta_set_colour(background))], 0)

                                # Start new line
                                cursor = self.ta_new_line(
                                    cursor, object, self.linespacing)

                                # Can't position cursor?
                                if cursor == [None, None]:
                                    break

                                # keep the remaining text
                                text = text[br:]
                                # The width is just the width of this text
                                width = use_font.TextCoordBox(
                                    text, font_size, textobj.properties)[2]

                            # If the whole string fit onto the line then
                            # control will flow to the else clause which will
                            # append the text to the line list for next time.
                        else:
                            # The text fits within the margins so add the text
                            # to the line
                            line.append(
                                (text, font_name, font_size, font_width,
                                 self.ta_set_colour(foreground),
                                 self.ta_set_colour(background)))

                            # Also append any trailing space
                            if space != '':
                                line.append(
                                    (space, font_name, font_size, font_width,
                                     self.ta_set_colour(foreground),
                                     self.ta_set_colour(background)))
                                width = width + use_font.TextCoordBox(
                                    space, font_size, textobj.properties)[2]

                        # Can't position cursor?
                        if cursor == [None, None]:
                            break

                    # Remember this command
                    last_command = command

                # Render any remaining text
                if line != [] and cursor != [None, None]:

                    # Write current line
                    self.ta_write_line(align, cursor, line, 0)

            else:
                pass

        # Return the number of recognised objects
        return n_objects