Skip to content

Commit

Permalink
Merge pull request #60 from gridpoint-com/save-text-align-base-context
Browse files Browse the repository at this point in the history
Save text align/base context
  • Loading branch information
crertel authored Dec 12, 2023
2 parents 4f9be00 + d9de5ed commit d06717f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions c_src/device/cairo/cairo_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ void pattern_stack_push(scenic_cairo_ctx_t* p_ctx)
pattern_stack_t* ptr = (pattern_stack_t*)malloc(sizeof(pattern_stack_t));

ptr->pattern = p_ctx->pattern;
ptr->text_align = p_ctx->text_align;
ptr->text_base = p_ctx->text_base;

if (!p_ctx->pattern_stack_head) {
ptr->next = NULL;
Expand All @@ -93,6 +95,8 @@ void pattern_stack_pop(scenic_cairo_ctx_t* p_ctx)
log_error("pattern stack underflow");
} else {
p_ctx->pattern = ptr->pattern;
p_ctx->text_align = ptr->text_align;
p_ctx->text_base = ptr->text_base;
p_ctx->pattern_stack_head = p_ctx->pattern_stack_head->next;
free(ptr);
}
Expand Down
2 changes: 2 additions & 0 deletions c_src/device/cairo/cairo_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ typedef struct {

typedef struct pattern_stack_t_ {
fill_stroke_pattern_t pattern;
text_align_t text_align;
text_base_t text_base;
struct pattern_stack_t_* next;
} pattern_stack_t;

Expand Down
5 changes: 2 additions & 3 deletions c_src/device/cairo/cairo_script_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ void script_ops_draw_text(void* v_ctx,
break;
}

cairo_save(p_ctx->cr);
cairo_translate(p_ctx->cr, align_offset, base_offset);
cairo_set_source(p_ctx->cr, p_ctx->pattern.fill);

Expand All @@ -307,9 +308,7 @@ void script_ops_draw_text(void* v_ctx,
} else {
log_error("%s: cairo_scaled_font_text_to_glyphs: error %d", __func__, status);
}

p_ctx->text_align = TEXT_ALIGN_LEFT;
p_ctx->text_base = TEXT_BASE_ALPHABETIC;
cairo_restore(p_ctx->cr);
}

static void draw_sprite(scenic_cairo_ctx_t* p_ctx,
Expand Down

0 comments on commit d06717f

Please sign in to comment.