@@ -191,8 +191,13 @@ Context2d::~Context2d() {
191
191
192
192
void
193
193
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
+ }
196
201
}
197
202
198
203
/*
@@ -201,35 +206,14 @@ Context2d::save() {
201
206
202
207
void
203
208
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
+ }
233
217
}
234
218
235
219
/*
0 commit comments