📄 cairo-path.c
字号:
cairo_status_t_cairo_path_fixed_close_path (cairo_path_fixed_t *path){ cairo_status_t status; if (! path->has_current_point) return CAIRO_STATUS_SUCCESS; status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_CLOSE_PATH, NULL, 0); if (status) return status; path->current_point.x = path->last_move_point.x; path->current_point.y = path->last_move_point.y; path->has_current_point = TRUE; return CAIRO_STATUS_SUCCESS;}cairo_status_t_cairo_path_fixed_get_current_point (cairo_path_fixed_t *path, cairo_fixed_t *x, cairo_fixed_t *y){ if (! path->has_current_point) return CAIRO_STATUS_NO_CURRENT_POINT; *x = path->current_point.x; *y = path->current_point.y; return CAIRO_STATUS_SUCCESS;}static cairo_status_t_cairo_path_fixed_add (cairo_path_fixed_t *path, cairo_path_op_t op, cairo_point_t *points, int num_points){ if (path->op_buf_tail == NULL || path->op_buf_tail->num_ops + 1 > CAIRO_PATH_BUF_SIZE) { cairo_path_op_buf_t *op_buf; op_buf = _cairo_path_op_buf_create (); if (op_buf == NULL) return CAIRO_STATUS_NO_MEMORY; _cairo_path_fixed_add_op_buf (path, op_buf); } _cairo_path_op_buf_add_op (path->op_buf_tail, op); if (path->arg_buf_tail == NULL || path->arg_buf_tail->num_points + num_points > CAIRO_PATH_BUF_SIZE) { cairo_path_arg_buf_t *arg_buf; arg_buf = _cairo_path_arg_buf_create (); if (arg_buf == NULL) return CAIRO_STATUS_NO_MEMORY; _cairo_path_fixed_add_arg_buf (path, arg_buf); } _cairo_path_arg_buf_add_points (path->arg_buf_tail, points, num_points); return CAIRO_STATUS_SUCCESS;}static void_cairo_path_fixed_add_op_buf (cairo_path_fixed_t *path, cairo_path_op_buf_t *op_buf){ op_buf->next = NULL; op_buf->prev = path->op_buf_tail; if (path->op_buf_tail) { path->op_buf_tail->next = op_buf; } else { path->op_buf_head = op_buf; } path->op_buf_tail = op_buf;}static void_cairo_path_fixed_add_arg_buf (cairo_path_fixed_t *path, cairo_path_arg_buf_t *arg_buf){ arg_buf->next = NULL; arg_buf->prev = path->arg_buf_tail; if (path->arg_buf_tail) { path->arg_buf_tail->next = arg_buf; } else { path->arg_buf_head = arg_buf; } path->arg_buf_tail = arg_buf;}static cairo_path_op_buf_t *_cairo_path_op_buf_create (void){ cairo_path_op_buf_t *op_buf; op_buf = malloc (sizeof (cairo_path_op_buf_t)); if (op_buf) { op_buf->num_ops = 0; op_buf->next = NULL; } return op_buf;}static void_cairo_path_op_buf_destroy (cairo_path_op_buf_t *op_buf){ free (op_buf);}static void_cairo_path_op_buf_add_op (cairo_path_op_buf_t *op_buf, cairo_path_op_t op){ op_buf->op[op_buf->num_ops++] = op;}static cairo_path_arg_buf_t *_cairo_path_arg_buf_create (void){ cairo_path_arg_buf_t *arg_buf; arg_buf = malloc (sizeof (cairo_path_arg_buf_t)); if (arg_buf) { arg_buf->num_points = 0; arg_buf->next = NULL; } return arg_buf;}static void_cairo_path_arg_buf_destroy (cairo_path_arg_buf_t *arg_buf){ free (arg_buf);}static void_cairo_path_arg_buf_add_points (cairo_path_arg_buf_t *arg_buf, cairo_point_t *points, int num_points){ int i; for (i=0; i < num_points; i++) { arg_buf->points[arg_buf->num_points++] = points[i]; }}#define CAIRO_PATH_OP_MAX_ARGS 3static int const num_args[] ={ 1, /* cairo_path_move_to */ 1, /* cairo_path_op_line_to */ 3, /* cairo_path_op_curve_to */ 0, /* cairo_path_op_close_path */};cairo_status_t_cairo_path_fixed_interpret (cairo_path_fixed_t *path, cairo_direction_t dir, cairo_path_fixed_move_to_func_t *move_to, cairo_path_fixed_line_to_func_t *line_to, cairo_path_fixed_curve_to_func_t *curve_to, cairo_path_fixed_close_path_func_t *close_path, void *closure){ cairo_status_t status; int i, arg; cairo_path_op_buf_t *op_buf; cairo_path_op_t op; cairo_path_arg_buf_t *arg_buf = path->arg_buf_head; int buf_i = 0; cairo_point_t point[CAIRO_PATH_OP_MAX_ARGS]; cairo_bool_t forward = (dir == CAIRO_DIRECTION_FORWARD); int step = forward ? 1 : -1; for (op_buf = forward ? path->op_buf_head : path->op_buf_tail; op_buf; op_buf = forward ? op_buf->next : op_buf->prev) { int start, stop; if (forward) { start = 0; stop = op_buf->num_ops; } else { start = op_buf->num_ops - 1; stop = -1; } for (i=start; i != stop; i += step) { op = op_buf->op[i]; if (! forward) { if (buf_i == 0) { arg_buf = arg_buf->prev; buf_i = arg_buf->num_points; } buf_i -= num_args[op]; } for (arg = 0; arg < num_args[op]; arg++) { point[arg] = arg_buf->points[buf_i]; buf_i++; if (buf_i >= arg_buf->num_points) { arg_buf = arg_buf->next; buf_i = 0; } } if (! forward) { buf_i -= num_args[op]; } switch (op) { case CAIRO_PATH_OP_MOVE_TO: status = (*move_to) (closure, &point[0]); break; case CAIRO_PATH_OP_LINE_TO: status = (*line_to) (closure, &point[0]); break; case CAIRO_PATH_OP_CURVE_TO: status = (*curve_to) (closure, &point[0], &point[1], &point[2]); break; case CAIRO_PATH_OP_CLOSE_PATH: default: status = (*close_path) (closure); break; } if (status) return status; } } return CAIRO_STATUS_SUCCESS;}static void_cairo_path_fixed_offset_and_scale (cairo_path_fixed_t *path, cairo_fixed_t offx, cairo_fixed_t offy, cairo_fixed_t scalex, cairo_fixed_t scaley){ cairo_path_arg_buf_t *arg_buf = path->arg_buf_head; int i; cairo_int64_t i64temp; cairo_fixed_t fixedtemp; while (arg_buf) { for (i = 0; i < arg_buf->num_points; i++) { if (scalex == CAIRO_FIXED_ONE) { arg_buf->points[i].x += offx; } else { fixedtemp = arg_buf->points[i].x + offx; i64temp = _cairo_int32x32_64_mul (fixedtemp, scalex); arg_buf->points[i].x = _cairo_int64_to_int32(_cairo_int64_rsl (i64temp, 16)); } if (scaley == CAIRO_FIXED_ONE) { arg_buf->points[i].y += offy; } else { fixedtemp = arg_buf->points[i].y + offy; i64temp = _cairo_int32x32_64_mul (fixedtemp, scaley); arg_buf->points[i].y = _cairo_int64_to_int32(_cairo_int64_rsl (i64temp, 16)); } } arg_buf = arg_buf->next; }}/** * _cairo_path_fixed_device_transform: * @path: a #cairo_path_fixed_t to be transformed * @device_transform: a matrix with only scaling/translation (no rotation or shear) * * Transform the fixed-point path according to the scaling and * translation of the given matrix. This function assert()s that the * given matrix has no rotation or shear elements, (that is, xy and yx * are 0.0). **/void_cairo_path_fixed_device_transform (cairo_path_fixed_t *path, cairo_matrix_t *device_transform){ assert (device_transform->yx == 0.0 && device_transform->xy == 0.0); /* XXX: FRAGILE: I'm not really sure whether we're doing the * "right" thing here if there is both scaling and translation in * the matrix. But for now, the internals guarantee that we won't * really ever have both going on. */ _cairo_path_fixed_offset_and_scale (path, _cairo_fixed_from_double (device_transform->x0), _cairo_fixed_from_double (device_transform->y0), _cairo_fixed_from_double (device_transform->xx), _cairo_fixed_from_double (device_transform->yy));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -