Skip to content

Commit

Permalink
change device clip to scissor
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjipeng committed Apr 25, 2024
1 parent f74b645 commit ecb002a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
6 changes: 3 additions & 3 deletions include/picasso.h
Original file line number Diff line number Diff line change
Expand Up @@ -1820,12 +1820,12 @@ PEXPORT void PICAPI ps_clip_path(ps_context* ctx, const ps_path* path, ps_fill_r
* \param ctx Pointer to an existing context object.
* \param rect The rectangle which will be clipped.
*
* \sa ps_clip, ps_clip_path, ps_clip_rects, ps_reset_clip, ps_clip_device_rect
* \sa ps_clip, ps_clip_path, ps_clip_rects, ps_reset_clip, ps_scissor_rect
*/
PEXPORT void PICAPI ps_clip_rect(ps_context* ctx, const ps_rect* rect);

/**
* \fn void ps_clip_device_rect(ps_context* ctx, const ps_rect* rect)
* \fn void ps_scissor_rect(ps_context* ctx, const ps_rect* rect)
* \brief The fast way to clipping specified rectangle, the clip rect can not be rotated
* by world matrix. (Deprecated)
*
Expand All @@ -1836,7 +1836,7 @@ PEXPORT void PICAPI ps_clip_rect(ps_context* ctx, const ps_rect* rect);
*
* \sa ps_clip, ps_clip_path, ps_clip_rects, ps_reset_clip, ps_clip_rect
*/
PEXPORT void PICAPI ps_clip_device_rect(ps_context* ctx, const ps_rect* rect);
PEXPORT void PICAPI ps_scissor_rect(ps_context* ctx, const ps_rect* rect);

/**
* \fn void ps_clip_rects(ps_context* ctx, const ps_rect* rects, unsigned int num_rects)
Expand Down
17 changes: 2 additions & 15 deletions src/picasso_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ void PICAPI ps_clip_path(ps_context* ctx, const ps_path* p, ps_fill_rule r)
global_status = STATUS_SUCCEED;
}

void PICAPI ps_clip_device_rect(ps_context* ctx, const ps_rect* r)
void PICAPI ps_scissor_rect(ps_context* ctx, const ps_rect* r)
{
if (!picasso::is_valid_system_device()) {
global_status = STATUS_DEVICE_ERROR;
Expand All @@ -1470,21 +1470,8 @@ void PICAPI ps_clip_device_rect(ps_context* ctx, const ps_rect* r)
FLT_TO_SCALAR(r->x + r->w),
FLT_TO_SCALAR(r->y + r->h));

picasso::trans_affine mtx = ctx->state->world_matrix;
scalar rotate = mtx.rotation();
mtx.rotate(-rotate); //not support rotation
mtx.transform(&(tr.x1), &(tr.y1));
mtx.transform(&(tr.x2), &(tr.y2));

if (ctx->state->clip.type == picasso::clip_device) { //clip device rect.
picasso::rect_s cr = ctx->state->clip.rect;
if (cr.clip(tr)) {
ctx->state->clip.rect = cr;
}
} else {
ctx->state->clip.rect = tr;
}
ctx->state->clip.type = picasso::clip_device;
ctx->state->clip.rect = tr;
ctx->canvas->p->render_clip(ctx->state, true);
global_status = STATUS_SUCCEED;
}
Expand Down

0 comments on commit ecb002a

Please sign in to comment.