| 17 | | bstyle = style.get('background.style') |
| 18 | | assert bstyle in ('fill', 'gradient', 'image') |
| 19 | | if bstyle == 'fill' and 'background.color' in style: |
| 20 | | cairo.cairo_set_source_rgb(cr, *style['background.color']) |
| 21 | | cairo.cairo_fill(cr) |
| 22 | | elif bstyle == 'gradient' and 'background.fill-line' in style and 'background.fill-stops' in style: |
| 23 | | pat = cairo.cairo_pattern_create_linear(*style['background.fill-line']) |
| 24 | | for stop in style['background.fill-stops']: |
| 25 | | cairo.cairo_pattern_add_color_stop_rgb(pat, *stop) |
| 26 | | cairo.cairo_set_source(cr, pat) |
| 27 | | cairo.cairo_fill(cr) |
| 28 | | elif bstyle == 'image' and 'background.image' in style and style['background.image']: |
| 29 | | image = cairo.cairo_image_surface_create_from_png(style.get('background.image')) |
| 30 | | w = float(cairo.cairo_image_surface_get_width(image)) |
| 31 | | h = float(cairo.cairo_image_surface_get_height(image)) |
| 32 | | |
| 33 | | cairo.cairo_scale(cr, width/w, height/h) |
| 34 | | |
| 35 | | cairo.cairo_set_source_surface(cr, image, x, y) |
| 36 | | cairo.cairo_paint(cr) |
| 37 | | |
| 38 | | if 'border.color' in style: |
| 39 | | bstyle = style.get('style', 'fill') |
| 40 | | assert bstyle in ('fill', 'gradient') |
| 41 | | if bstyle == 'fill' and 'border.color' in style: |
| 42 | | cairo.cairo_set_source_rgb(cr, *style['border.color']) |
| 43 | | elif bstyle == 'gradient' and 'border.fill-line' in style and 'border.fill-stops' in style: |
| 44 | | pat = cairo.cairo_pattern_create_linear(*style['border.fill-line']) |
| 45 | | for stop in style['border.fill-stops']: |
| 46 | | cairo.cairo_pattern_add_color_stop_rgb(pat, *stop) |
| 47 | | cairo.cairo_set_source(cr, pat) |
| 48 | | cairo.cairo_set_line_width(cr, style.get('width', 1.0)) |
| 49 | | cairo.cairo_rectangle(cr, x, y, width, height) |
| 50 | | cairo.cairo_stroke(cr) |
| | 12 | def yahiko_render(cr, style, width, height): |
| | 13 | win = Window(style=style) |
| | 14 | win.set_render_coords(0, 0, width, height) |
| | 15 | win.render(cr) |