]] if not outline_paths or options.bounds_artwork: # No outline path found, or bounds were supposed to be found from all artwork # so use all artwork except for unscaled drill layer and determine coords srcrect = artwork_bounds # Try to guess-fit the drill layer if "DRILL" in layers: layers["DRILL"].scaleToFit((srcrect.getEndPoint().x, srcrect.getEndPoint().y)) # Calculate the image size and transform (width, height), transform = GD.prepareCairoTransform(1024, srcrect, pad = 50, trim_to_ratio = True, **plotmode.getTransformArgs()) # Prepare a surface to render onto surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) cr = cairo.Context(surface) # Apply the transform to the context transform(cr) # Setup the background plotmode.renderBackground(cr, outline_paths) for i in reversed(render_order): try: t = layers[i]; except KeyError:
cr.set_source_rgba(1,0,0, 1) else: cr.set_source_rgba(0,0,1, 1) for k in j.draws: GD.emitGerbObjectCairoPath(cr, k) cr.stroke() cr.pop_group_to_source() cr.paint_with_alpha(1) srcrect = GU.calculateBoundingRectFromPCBLayers([p], False) print srcrect # Calculate the image size and transform (width, height), transform = GD.prepareCairoTransform(1024, srcrect, pad = 50, trim_to_ratio = True) # Prepare a surface to render onto surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) cr = cairo.Context(surface) # Apply the transform to the context transform(cr) renderGerberFile(p, cr) surface.write_to_png(open("out.png", 'w'))
if not outline_paths or options.bounds_artwork: # No outline path found, or bounds were supposed to be found from all artwork # so use all artwork except for unscaled drill layer and determine coords srcrect = artwork_bounds # Try to guess-fit the drill layer if "DRILL" in layers: layers["DRILL"].scaleToFit( (srcrect.getEndPoint().x, srcrect.getEndPoint().y)) # Calculate the image size and transform (width, height), transform = GD.prepareCairoTransform(1024, srcrect, pad=50, trim_to_ratio=True, **plotmode.getTransformArgs()) # Prepare a surface to render onto surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) cr = cairo.Context(surface) # Apply the transform to the context transform(cr) # Setup the background plotmode.renderBackground(cr, outline_paths) for i in reversed(render_order): try: