Skip to content

Commit

Permalink
fill background color before replay
Browse files Browse the repository at this point in the history
  • Loading branch information
undertherain committed Sep 9, 2018
1 parent c332ba2 commit 986d133
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions contextfree/contextfree.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
WIDTH = 100
_state = {}
_ctx = None
_background_color = None


def _init__state():
Expand Down Expand Up @@ -66,10 +67,17 @@ def render_record_surface():
image_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
context = cairo.Context(image_surface)
scale = min(WIDTH / width_actual, HEIGHT / height_actual)
if _background_color is not None:
print("filling background_color")
source = context.get_source()
pat = cairo.SolidPattern(* htmlcolor_to_rgb(_background_color))
context.rectangle(0, 0, WIDTH, HEIGHT) # Rectangle(x0, y0, x1, y1)
context.set_source(pat)
context.fill()
context.set_source(source)
context.translate(WIDTH / 2, HEIGHT / 2)
context.scale(scale, scale) # Normalizing the canvas
context.translate(-x_start - width_actual / 2, -y_start - height_actual / 2)
# context.translate(-x_start, -y_start)
context.set_source_surface(surface, 0, 0)
context.paint()
return image_surface
Expand Down Expand Up @@ -105,6 +113,8 @@ def report():

def init(canvas_size=(512, 512), max_depth=10, face_color=None, background_color=None):
"""Initializes global state"""
global _background_color
_background_color = background_color
global surface
global _ctx
global cnt_elements
Expand All @@ -123,13 +133,6 @@ def init(canvas_size=(512, 512), max_depth=10, face_color=None, background_color
# _ctx.scale(scale, -scale) # Normalizing the canvas
# _ctx.rotate(math.pi)

if background_color is not None:
source = _ctx.get_source()
pat = cairo.SolidPattern(* htmlcolor_to_rgb(background_color))
_ctx.rectangle(-1, -1, 2, 2) # Rectangle(x0, y0, x1, y1)
_ctx.set_source(pat)
_ctx.fill()
_ctx.set_source(source)
if face_color is not None:
_ctx.set_source_rgb(* htmlcolor_to_rgb(face_color))

Expand Down

0 comments on commit 986d133

Please sign in to comment.