Skip to content

Commit 84d8e89

Browse files
authored
Merge pull request #810 from chearon/restore-blackhole
fix #809
2 parents a19f790 + 8ef00a4 commit 84d8e89

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

src/CanvasRenderingContext2d.cc

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,13 @@ Context2d::~Context2d() {
191191

192192
void
193193
Context2d::save() {
194-
cairo_save(_context);
195-
saveState();
194+
if (stateno < CANVAS_MAX_STATES) {
195+
cairo_save(_context);
196+
states[++stateno] = (canvas_state_t *) malloc(sizeof(canvas_state_t));
197+
memcpy(states[stateno], state, sizeof(canvas_state_t));
198+
states[stateno]->fontDescription = pango_font_description_copy(states[stateno-1]->fontDescription);
199+
state = states[stateno];
200+
}
196201
}
197202

198203
/*
@@ -201,35 +206,14 @@ Context2d::save() {
201206

202207
void
203208
Context2d::restore() {
204-
cairo_restore(_context);
205-
restoreState();
206-
}
207-
208-
/*
209-
* Save the current state.
210-
*/
211-
212-
void
213-
Context2d::saveState() {
214-
if (stateno == CANVAS_MAX_STATES) return;
215-
states[++stateno] = (canvas_state_t *) malloc(sizeof(canvas_state_t));
216-
memcpy(states[stateno], state, sizeof(canvas_state_t));
217-
states[stateno]->fontDescription = pango_font_description_copy(states[stateno-1]->fontDescription);
218-
state = states[stateno];
219-
}
220-
221-
/*
222-
* Restore state.
223-
*/
224-
225-
void
226-
Context2d::restoreState() {
227-
if (0 == stateno) return;
228-
pango_font_description_free(states[stateno]->fontDescription);
229-
free(states[stateno]);
230-
states[stateno] = NULL;
231-
state = states[--stateno];
232-
pango_layout_set_font_description(_layout, state->fontDescription);
209+
if (stateno > 0) {
210+
cairo_restore(_context);
211+
pango_font_description_free(states[stateno]->fontDescription);
212+
free(states[stateno]);
213+
states[stateno] = NULL;
214+
state = states[--stateno];
215+
pango_layout_set_font_description(_layout, state->fontDescription);
216+
}
233217
}
234218

235219
/*

0 commit comments

Comments
 (0)