コード例 #1
0
ファイル: window.c プロジェクト: pietern/waterfall
static void compute_viewport(window_state_t *state, viewport_t *v) {
    stream_t *stream = state->stream;
    double min;
    double max;
    double unit;

    compute_scale_factor(state, &v->sx, &v->sy);

    v->w = gtk_widget_get_allocated_width(state->drawing_area);
    v->h = gtk_widget_get_allocated_height(state->drawing_area);

    v->uox = 0.0f;
    v->uoy = 0.0f;
    v->udx = v->w;
    v->udy = v->h;
    v->uw = v->w;
    v->uh = v->h;
    v->updx = 1.0f;
    v->updy = 1.0f;

    // Find equivalent for the origin and window size in user coordinates
    cairo_matrix_transform_point(&state->window_to_user_inv, &v->uox, &v->uoy);
    cairo_matrix_transform_point(&state->window_to_user_inv, &v->udx, &v->udy);
    cairo_matrix_transform_distance(&state->window_to_user_inv, &v->uw, &v->uh);
    cairo_matrix_transform_distance(&state->window_to_user_inv, &v->updx, &v->updy);

    v->sox = v->uox;
    v->soy = v->uoy;
    v->sdx = v->udx;
    v->sdy = v->udy;
    v->sw = v->uw;
    v->sh = v->uh;
    v->spdx = v->updx;
    v->spdy = v->updy;

    // Find equivalent for the origin and window size in scaled coordinates
    cairo_matrix_transform_point(&state->user_to_scaled_inv, &v->sox, &v->soy);
    cairo_matrix_transform_point(&state->user_to_scaled_inv, &v->sdx, &v->sdy);
    cairo_matrix_transform_distance(&state->user_to_scaled_inv, &v->sw, &v->sh);
    cairo_matrix_transform_distance(&state->user_to_scaled_inv, &v->spdx, &v->spdy);

    if (v->soy < v->sdy) {
        min = v->soy;
        max = v->sdy;
    } else {
        min = v->sdy;
        max = v->soy;
    }

    // Determine offsets of first wedge in view and first wedge out of view
    unit = state->wedge_height * stream->sample_rate / powf(2.0f, v->sy);
    v->start = floor((min * stream->sample_rate) / unit) * unit;
    v->end = (floor((max * stream->sample_rate) / unit) + 1.0f) * unit;
    v->skip = unit;

    // Offsets of stream
    v->stream_start = 0;
    v->stream_end = stream->n_samples;
}
コード例 #2
0
ファイル: cairo-matrix.c プロジェクト: jparris/enso
void
_cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix,
                                      double *x, double *y,
                                      double *width, double *height)
{
    int i;
    double quad_x[4], quad_y[4];
    double dx1, dy1;
    double dx2, dy2;
    double min_x, max_x;
    double min_y, max_y;

    quad_x[0] = *x;
    quad_y[0] = *y;
    cairo_matrix_transform_point (matrix, &quad_x[0], &quad_y[0]);

    dx1 = *width;
    dy1 = 0;
    cairo_matrix_transform_distance (matrix, &dx1, &dy1);
    quad_x[1] = quad_x[0] + dx1;
    quad_y[1] = quad_y[0] + dy1;

    dx2 = 0;
    dy2 = *height;
    cairo_matrix_transform_distance (matrix, &dx2, &dy2);
    quad_x[2] = quad_x[0] + dx2;
    quad_y[2] = quad_y[0] + dy2;

    quad_x[3] = quad_x[0] + dx1 + dx2;
    quad_y[3] = quad_y[0] + dy1 + dy2;

    min_x = max_x = quad_x[0];
    min_y = max_y = quad_y[0];

    for (i=1; i < 4; i++) {
        if (quad_x[i] < min_x)
            min_x = quad_x[i];
        if (quad_x[i] > max_x)
            max_x = quad_x[i];

        if (quad_y[i] < min_y)
            min_y = quad_y[i];
        if (quad_y[i] > max_y)
            max_y = quad_y[i];
    }

    *x = min_x;
    *y = min_y;
    *width = max_x - min_x;
    *height = max_y - min_y;
}
コード例 #3
0
ファイル: gfxMatrix.cpp プロジェクト: MozillaOnline/gecko-dev
gfxSize
gfxMatrix::Transform(const gfxSize& size) const
{
    gfxSize ret = size;
    cairo_matrix_transform_distance(CONST_CAIRO_MATRIX(this), &ret.width, &ret.height);
    return ret;
}
コード例 #4
0
ファイル: cpml-pair.c プロジェクト: bert/adg
/**
 * cpml_vector_transform:
 * @vector:               the destination #CpmlPair struct
 * @matrix: (allow-none): the transformation matrix
 *
 * Shortcut to apply a specific transformation matrix to @vector.
 * It works in a similar way of cpml_pair_transform() but uses
 * cairo_matrix_transform_distance() instead of
 * cairo_matrix_transform_point().
 *
 * Since: 1.0
 **/
void
cpml_vector_transform(CpmlPair *vector, const cairo_matrix_t *matrix)
{
    if (matrix != NULL) {
        cairo_matrix_transform_distance(matrix, &vector->x, &vector->y);
    }
}
コード例 #5
0
OGREnvelope wxGISDisplay::TransformRect(wxRect &rect)
{
	OGREnvelope out;
	double dX1, dX2, dY2, dY1;
	double dWHalf = double(rect.width) / 2;
	double dHHalf = double(rect.height) / 2;
	double dXCenter = rect.x + dWHalf, dYCenter = rect.y + dHHalf;
	DC2World(&dXCenter, &dYCenter);

	cairo_matrix_t InvertMatrix = {m_pDisplayMatrixNoRotate->xx, m_pDisplayMatrixNoRotate->yx, m_pDisplayMatrixNoRotate->xy, m_pDisplayMatrixNoRotate->yy, m_pDisplayMatrixNoRotate->x0, m_pDisplayMatrixNoRotate->y0};
	cairo_matrix_invert(&InvertMatrix);

	cairo_matrix_transform_distance(&InvertMatrix, &dWHalf, &dHHalf);

	dX1 = dXCenter - dWHalf;
	dX2 = dXCenter + dWHalf;
	dY1 = dYCenter - dHHalf;
	dY2 = dYCenter + dHHalf;

    out.MinX = wxMin(dX1, dX2);
    out.MinY = wxMin(dY1, dY2);
    out.MaxX = wxMax(dX1, dX2);
    out.MaxY = wxMax(dY1, dY2);
	return out;
}
コード例 #6
0
ファイル: seed-cairo-matrix.c プロジェクト: dannote/seed
static SeedValue
seed_cairo_matrix_transform_distance (SeedContext ctx,
				      SeedObject function,
				      SeedObject this_object,
				      gsize argument_count,
				      const SeedValue arguments[],
				      SeedException *exception)
{
  SeedValue ret[2];
  gdouble x, y;
  cairo_matrix_t m;

  if (argument_count != 3)
    {
      EXPECTED_EXCEPTION("transform_distance", "3 arguments");
    }

  if (!seed_value_to_cairo_matrix (ctx, arguments[0], &m, exception))
    {
      seed_make_exception (ctx, exception, "ArgumentError", "transform_distance needs an array [xx, yx, xy, yy, x0, y0]");
    }
  x = seed_value_to_double (ctx, arguments[1], exception);
  y = seed_value_to_double (ctx, arguments[2], exception);

  cairo_matrix_transform_distance (&m, &x, &y);

  ret[0] = seed_value_from_double (ctx, x, exception);
  ret[1] = seed_value_from_double (ctx, y, exception);

  return seed_make_array (ctx, ret, 2, exception);
}
コード例 #7
0
ファイル: drawmatrix.c プロジェクト: 123vipulj/libui
void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y)
{
	cairo_matrix_t c;

	m2c(m, &c);
	cairo_matrix_transform_distance(&c, x, y);
}
コード例 #8
0
ファイル: adg-gtk-area.c プロジェクト: ntd/adg
static gboolean
_adg_motion_notify_event(GtkWidget *widget, GdkEventMotion *event)
{
    gboolean translating, local_space, global_space;
    cairo_matrix_t map, inverted;

    translating = (event->state & GDK_BUTTON2_MASK) == GDK_BUTTON2_MASK;
    local_space = (event->state & ADG_GTK_MODIFIERS) == 0;
    global_space = (event->state & ADG_GTK_MODIFIERS) == GDK_SHIFT_MASK;

    if (translating && (local_space || global_space) &&
        _adg_get_map(widget, local_space, &map, &inverted)) {
        AdgGtkAreaPrivate *data = adg_gtk_area_get_instance_private((AdgGtkArea *) widget);
        gdouble x = event->x - data->x_event;
        gdouble y = event->y - data->y_event;

        cairo_matrix_transform_distance(&inverted, &x, &y);
        cairo_matrix_translate(&map, x, y);
        data->x_event = event->x;
        data->y_event = event->y;

        _adg_set_map(widget, local_space, &map);

        gtk_widget_queue_draw(widget);

        /* Avoid to chain up the default handler:
         * this event has been grabbed by this function */
        return TRUE;
    }

    if (_ADG_OLD_WIDGET_CLASS->motion_notify_event == NULL)
        return FALSE;

    return _ADG_OLD_WIDGET_CLASS->motion_notify_event(widget, event);
}
コード例 #9
0
/**
 * cairo_matrix_transform_point:
 * @matrix: a #cairo_matrix_t
 * @x: X position. An in/out parameter
 * @y: Y position. An in/out parameter
 *
 * Transforms the point (@x, @y) by @matrix.
 **/
void
cairo_matrix_transform_point (const cairo_matrix_t *matrix, double *x, double *y)
{
    cairo_matrix_transform_distance (matrix, x, y);

    *x += matrix->x0;
    *y += matrix->y0;
}
コード例 #10
0
void wxGISDisplay::World2DCDist(double* pdX, double* pdY, bool bRotated)
{
	cairo_matrix_t Matrix;
	if(bRotated)
		Matrix = *m_pDisplayMatrix;
	else
		Matrix = *m_pDisplayMatrixNoRotate;
	cairo_matrix_transform_distance(&Matrix, pdX, pdY);
}
コード例 #11
0
static void
_cairo_skia_context_user_to_device_distance (void *abstract_cr,
					     double *dx,
					     double *dy)
{
    cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr;

    cairo_matrix_transform_distance (&cr->matrix, dx, dy);
}
コード例 #12
0
cairo_status_t
_cairo_pen_init (cairo_pen_t *pen, double radius, cairo_gstate_t *gstate)
{
    int i;
    int reflect;
    double  det;

    if (pen->num_vertices) {
	/* XXX: It would be nice to notice that the pen is already properly constructed.
	   However, this test would also have to account for possible changes in the transformation
	   matrix.
	   if (pen->radius == radius && pen->tolerance == tolerance)
	   return CAIRO_STATUS_SUCCESS;
	*/
	_cairo_pen_fini (pen);
    }

    pen->radius = radius;
    pen->tolerance = gstate->tolerance;

    _cairo_matrix_compute_determinant (&gstate->ctm, &det);
    if (det >= 0) {
	reflect = 0;
    } else {
	reflect = 1;
    }

    pen->num_vertices = _cairo_pen_vertices_needed (gstate->tolerance,
						    radius,
						    &gstate->ctm);
    
    pen->vertices = malloc (pen->num_vertices * sizeof (cairo_pen_vertex_t));
    if (pen->vertices == NULL) {
	return CAIRO_STATUS_NO_MEMORY;
    }

    /*
     * Compute pen coordinates.  To generate the right ellipse, compute points around
     * a circle in user space and transform them to device space.  To get a consistent
     * orientation in device space, flip the pen if the transformation matrix
     * is reflecting
     */
    for (i=0; i < pen->num_vertices; i++) {
	double theta = 2 * M_PI * i / (double) pen->num_vertices;
	double dx = radius * cos (reflect ? -theta : theta);
	double dy = radius * sin (reflect ? -theta : theta);
	cairo_pen_vertex_t *v = &pen->vertices[i];
	cairo_matrix_transform_distance (&gstate->ctm, &dx, &dy);
	v->point.x = _cairo_fixed_from_double (dx);
	v->point.y = _cairo_fixed_from_double (dy);
    }

    _cairo_pen_compute_slopes (pen);

    return CAIRO_STATUS_SUCCESS;
}
コード例 #13
0
ファイル: l_cairo_matrix.c プロジェクト: qioixiy/xboot
static int m_cairo_matrix_transform_distance(lua_State * L)
{
	const cairo_matrix_t * matrix = luaL_checkudata(L, 1, MT_NAME_CAIRO_MATRIX);
	double dx = luaL_checknumber(L, 2);
	double dy = luaL_checknumber(L, 3);
	cairo_matrix_transform_distance(matrix, &dx, &dy);
	lua_pushnumber(L, dx);
	lua_pushnumber(L, dy);
	return 2;
}
コード例 #14
0
void wxGISDisplay::DC2WorldDist(double* pdX, double* pdY, bool bRotated)
{
	cairo_matrix_t InvertMatrix;
	if(bRotated)//set center of real window not cache
		InvertMatrix = *m_pDisplayMatrix;
	else
		InvertMatrix = *m_pDisplayMatrixNoRotate;
	cairo_matrix_invert(&InvertMatrix);
	cairo_matrix_transform_distance(&InvertMatrix, pdX, pdY);
}
コード例 #15
0
ファイル: obj_matrix.c プロジェクト: awesomeWM/oocairo
static int
cairmat_transform_distance (lua_State *L) {
    cairo_matrix_t mat;
    double x = luaL_checknumber(L, 2), y = luaL_checknumber(L, 3);
    from_lua_matrix(L, &mat, 1);
    cairo_matrix_transform_distance(&mat, &x, &y);
    lua_pushnumber(L, x);
    lua_pushnumber(L, y);
    return 2;
}
コード例 #16
0
ファイル: matrix.c プロジェクト: Projjol/Fracktal
static PyObject *
matrix_transform_distance (PycairoMatrix *o, PyObject *args) {
  double dx, dy;

  if (!PyArg_ParseTuple(args, "dd:Matrix.transform_distance", &dx, &dy))
    return NULL;

  cairo_matrix_transform_distance (&o->matrix, &dx, &dy);
  return Py_BuildValue("(dd)", dx, dy);
}
コード例 #17
0
ファイル: window.c プロジェクト: pietern/waterfall
static void compute_scale_factor(window_state_t *state, int8_t *sx, int8_t *sy) {
    double ddx = 1.0f;
    double ddy = 1.0f;
    double dfx;
    double dfy;

    // Find equivalent for 1x1 pixel block in user coordinates
    cairo_matrix_transform_distance(&state->window_to_user_inv, &ddx, &ddy);
    cairo_matrix_transform_distance(&state->user_to_scaled_inv, &ddx, &ddy);

    ddx = log2f(fabs(ddx));
    dfx = -floor(ddx);
    if (dfx < 0) {
        *sx = 0;
    } else {
        *sx = dfx;
    }

    ddy = log2f(fabs(ddy));
    dfy = -floor(ddy);
    if (dfy < 0) {
        *sy = 0;
    } else {
        *sy = dfy;
    }

    // At scale 14 the wedge width is 16384, which is the maximum cairo surface width.
    // (the cairo status flips to invalid value after using one of higher width)
    if (*sx > 14) {
        *sx = 14;
    }

    if (*sy > 14) {
        *sy = 14;
    }

    if (DEBUG) {
        fprintf(stderr, "sx: %d (ddx: %.3f), sy: %d (ddy: %.3f)\n", *sx, ddx, *sy, ddy);
    }

    return;
}
コード例 #18
0
ファイル: cairo-pen.c プロジェクト: Distrotech/cairo
cairo_status_t
_cairo_pen_init (cairo_pen_t	*pen,
		 double		 radius,
		 double		 tolerance,
		 const cairo_matrix_t	*ctm)
{
    int i;
    int reflect;

    if (CAIRO_INJECT_FAULT ())
	return _cairo_error (CAIRO_STATUS_NO_MEMORY);

    VG (VALGRIND_MAKE_MEM_UNDEFINED (pen, sizeof (cairo_pen_t)));

    pen->radius = radius;
    pen->tolerance = tolerance;

    reflect = _cairo_matrix_compute_determinant (ctm) < 0.;

    pen->num_vertices = _cairo_pen_vertices_needed (tolerance,
						    radius,
						    ctm);

    if (pen->num_vertices > ARRAY_LENGTH (pen->vertices_embedded)) {
	pen->vertices = _cairo_malloc_ab (pen->num_vertices,
					  sizeof (cairo_pen_vertex_t));
	if (unlikely (pen->vertices == NULL))
	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
    } else {
	pen->vertices = pen->vertices_embedded;
    }

    /*
     * Compute pen coordinates.  To generate the right ellipse, compute points around
     * a circle in user space and transform them to device space.  To get a consistent
     * orientation in device space, flip the pen if the transformation matrix
     * is reflecting
     */
    for (i=0; i < pen->num_vertices; i++) {
	cairo_pen_vertex_t *v = &pen->vertices[i];
	double theta = 2 * M_PI * i / (double) pen->num_vertices, dx, dy;
	if (reflect)
	    theta = -theta;
	dx = radius * cos (theta);
	dy = radius * sin (theta);
	cairo_matrix_transform_distance (ctm, &dx, &dy);
	v->point.x = _cairo_fixed_from_double (dx);
	v->point.y = _cairo_fixed_from_double (dy);
    }

    _cairo_pen_compute_slopes (pen);

    return CAIRO_STATUS_SUCCESS;
}
コード例 #19
0
ファイル: griddle.c プロジェクト: jotok/griddle
/**
 * Convert a unit array to a C array of doubles representing NPC values.
 */
static void
unit_array_to_npc(double *result, grid_context_t *gr, char dim, 
                  const unit_array_t *u) 
{
    grid_viewport_node_t *node = gr->current_node;
    double dev_x_per_npc, dev_y_per_npc;
    dev_x_per_npc = dev_y_per_npc = 1.0;
    cairo_matrix_transform_distance(node->npc_to_dev, &dev_x_per_npc, 
                                                      &dev_y_per_npc);

    double x_ntv, y_ntv, w_ntv, h_ntv;
    x_ntv = y_ntv = 0.0;
    w_ntv = h_ntv = 1.0;
    cairo_matrix_transform_point(node->npc_to_ntv, &x_ntv, &y_ntv);
    cairo_matrix_transform_distance(node->npc_to_ntv, &w_ntv, &h_ntv);

    cairo_font_extents_t font_extents;
    cairo_font_extents(gr->cr, &font_extents);

    cairo_text_extents_t em_extents;
    cairo_text_extents(gr->cr, "m", &em_extents);

    double dev_per_npc, o_ntv, size_ntv;
    dev_per_npc = o_ntv = size_ntv = 0.0;

    if (dim == 'x') {
        dev_per_npc = dev_x_per_npc;
        o_ntv = x_ntv;
        size_ntv = w_ntv;
    } else if (dim == 'y') {
        dev_per_npc = dev_y_per_npc;
        o_ntv = y_ntv;
        size_ntv = h_ntv;
    } else {
        fprintf(stderr, "Warning: unknown dimension '%c'\n", dim);
    }

    unit_array_to_npc_helper(result, dev_per_npc, font_extents.height,
                             em_extents.width, o_ntv, size_ntv, 
                             unit_array_size(u), u);
}
コード例 #20
0
ファイル: gtkpixelcache.c プロジェクト: Vort/gtk
static gboolean
context_is_unscaled (cairo_t *cr)
{
  cairo_matrix_t matrix;
  gdouble x, y;

  x = y = 1;
  cairo_get_matrix (cr, &matrix);
  cairo_matrix_transform_distance (&matrix, &x, &y);

  return x == 1 && y == 1;
}
コード例 #21
0
ファイル: mech-surface.c プロジェクト: arthurfait/mechane
static gdouble
_mech_surface_get_axis_scale (cairo_matrix_t *matrix,
                              MechAxis        axis)
{
  gdouble distance_x, distance_y;

  distance_x = (axis == MECH_AXIS_X) ? 1 : 0;
  distance_y = (axis == MECH_AXIS_Y) ? 1 : 0;
  cairo_matrix_transform_distance (matrix, &distance_x, &distance_y);

  return sqrt ((distance_x * distance_x) + (distance_y * distance_y));
}
コード例 #22
0
ファイル: cairo-path-stroke.c プロジェクト: csyuschmjuh/apl
static void
_compute_face (const cairo_point_t *point,
	       const cairo_slope_t *dev_slope,
	       double slope_dx,
	       double slope_dy,
	       cairo_stroker_t *stroker,
	       cairo_stroke_face_t *face)
{
    double face_dx, face_dy;
    cairo_point_t offset_ccw, offset_cw;

    /*
     * rotate to get a line_width/2 vector along the face, note that
     * the vector must be rotated the right direction in device space,
     * but by 90° in user space. So, the rotation depends on
     * whether the ctm reflects or not, and that can be determined
     * by looking at the determinant of the matrix.
     */
    if (stroker->ctm_det_positive)
    {
	face_dx = - slope_dy * (stroker->style.line_width / 2.0);
	face_dy = slope_dx * (stroker->style.line_width / 2.0);
    }
    else
    {
	face_dx = slope_dy * (stroker->style.line_width / 2.0);
	face_dy = - slope_dx * (stroker->style.line_width / 2.0);
    }

    /* back to device space */
    cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy);

    offset_ccw.x = _cairo_fixed_from_double (face_dx);
    offset_ccw.y = _cairo_fixed_from_double (face_dy);
    offset_cw.x = -offset_ccw.x;
    offset_cw.y = -offset_ccw.y;

    face->ccw = *point;
    _translate_point (&face->ccw, &offset_ccw);

    face->point = *point;

    face->cw = *point;
    _translate_point (&face->cw, &offset_cw);

    face->usr_vector.x = slope_dx;
    face->usr_vector.y = slope_dy;

    face->dev_vector = *dev_slope;
}
コード例 #23
0
ファイル: cairo-pen.c プロジェクト: achellies/ISeeBrowser
cairo_status_t
_cairo_pen_init (cairo_pen_t	*pen,
		 double		 radius,
		 double		 tolerance,
		 cairo_matrix_t	*ctm)
{
    int i;
    int reflect;
    double  det;

    pen->radius = radius;
    pen->tolerance = tolerance;

    _cairo_matrix_compute_determinant (ctm, &det);
    if (det >= 0) {
	reflect = 0;
    } else {
	reflect = 1;
    }

    pen->num_vertices = _cairo_pen_vertices_needed (tolerance,
						    radius,
						    ctm);

    pen->vertices = _cairo_malloc_ab (pen->num_vertices, sizeof (cairo_pen_vertex_t));
    if (pen->vertices == NULL) {
	return CAIRO_STATUS_NO_MEMORY;
    }

    /*
     * Compute pen coordinates.  To generate the right ellipse, compute points around
     * a circle in user space and transform them to device space.  To get a consistent
     * orientation in device space, flip the pen if the transformation matrix
     * is reflecting
     */
    for (i=0; i < pen->num_vertices; i++) {
	double theta = 2 * M_PI * i / (double) pen->num_vertices;
	double dx = radius * cos (reflect ? -theta : theta);
	double dy = radius * sin (reflect ? -theta : theta);
	cairo_pen_vertex_t *v = &pen->vertices[i];
	cairo_matrix_transform_distance (ctm, &dx, &dy);
	v->point.x = _cairo_fixed_from_double (dx);
	v->point.y = _cairo_fixed_from_double (dy);
    }

    _cairo_pen_compute_slopes (pen);

    return CAIRO_STATUS_SUCCESS;
}
コード例 #24
0
static void
_cairo_skia_context_device_to_user_distance (void *abstract_cr,
					     double *dx,
					     double *dy)
{
    cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr;
    cairo_matrix_t inverse;
    cairo_status_t status;

    inverse = cr->matrix;
    status = cairo_matrix_invert (&inverse);
    assert (CAIRO_STATUS_SUCCESS == status);

    cairo_matrix_transform_distance (&inverse, dx, dy);
}
コード例 #25
0
static void
add_cap (struct stroker *stroker,
	 const cairo_stroke_face_t *f,
	 struct stroke_contour *c)
{
    switch (stroker->style.line_cap) {
    case CAIRO_LINE_CAP_ROUND: {
	cairo_slope_t slope;

	slope.dx = -f->dev_vector.dx;
	slope.dy = -f->dev_vector.dy;

	add_fan (stroker, &f->dev_vector, &slope,
		 &f->point, &f->ccw, &f->cw,
		 FALSE, c);
	break;
    }

    case CAIRO_LINE_CAP_SQUARE: {
	double dx, dy;
	cairo_slope_t	fvector;
	cairo_point_t	quad[4];

	dx = f->usr_vector.x;
	dy = f->usr_vector.y;
	dx *= stroker->style.line_width / 2.0;
	dy *= stroker->style.line_width / 2.0;
	cairo_matrix_transform_distance (stroker->ctm, &dx, &dy);
	fvector.dx = _cairo_fixed_from_double (dx);
	fvector.dy = _cairo_fixed_from_double (dy);

	quad[0] = f->ccw;
	quad[1].x = f->ccw.x + fvector.dx;
	quad[1].y = f->ccw.y + fvector.dy;
	quad[2].x = f->cw.x + fvector.dx;
	quad[2].y = f->cw.y + fvector.dy;
	quad[3] = f->cw;

	contour_add_point (stroker, c, &quad[1]);
	contour_add_point (stroker, c, &quad[2]);
    }

    case CAIRO_LINE_CAP_BUTT:
    default:
	break;
    }
    contour_add_point (stroker, c, &f->cw);
}
コード例 #26
0
/**
 * _cairo_matrix_compute_basis_scale_factors:
 * @matrix: a matrix
 * @basis_scale: the scale factor in the direction of basis
 * @normal_scale: the scale factor in the direction normal to the basis
 * @x_basis: basis to use.  X basis if true, Y basis otherwise.
 *
 * Computes |Mv| and det(M)/|Mv| for v=[1,0] if x_basis is true, and v=[0,1]
 * otherwise, and M is @matrix.
 *
 * Return value: the scale factor of @matrix on the height of the font,
 * or 1.0 if @matrix is %NULL.
 **/
cairo_status_t
_cairo_matrix_compute_basis_scale_factors (const cairo_matrix_t *matrix,
					   double *basis_scale, double *normal_scale,
					   cairo_bool_t x_basis)
{
    double det;

    det = _cairo_matrix_compute_determinant (matrix);

    if (! ISFINITE (det))
	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);

    if (det == 0)
    {
	*basis_scale = *normal_scale = 0;
    }
    else
    {
	double x = x_basis != 0;
	double y = x == 0;
	double major, minor;

	cairo_matrix_transform_distance (matrix, &x, &y);
	major = hypot (x, y);
	/*
	 * ignore mirroring
	 */
	if (det < 0)
	    det = -det;
	if (major)
	    minor = det / major;
	else
	    minor = 0.0;
	if (x_basis)
	{
	    *basis_scale = major;
	    *normal_scale = minor;
	}
	else
	{
	    *basis_scale = minor;
	    *normal_scale = major;
	}
    }

    return CAIRO_STATUS_SUCCESS;
}
コード例 #27
0
ファイル: cc-camera.c プロジェクト: herzi/ccc
static void
camera_world_to_window_distance(CcView const* view,
				gdouble     * x,
				gdouble     * y)
{
	cairo_matrix_t matrix;
	gdouble real_x = x ? *x : 0.0,
		real_y = y ? *y : 0.0;
	camera_init_matrix(CC_CAMERA(view), &matrix);
	cairo_matrix_transform_distance(&matrix, &real_x, &real_y);
	if(x) {
		*x = real_x;
	}
	if(y) {
		*y = real_y;
	}
}
コード例 #28
0
ファイル: cairo-path-stroke.c プロジェクト: alexgcastro/cairo
static inline cairo_bool_t
_compute_normalized_device_slope (double *dx, double *dy,
				  const cairo_matrix_t *ctm_inverse,
				  double *mag_out)
{
    double dx0 = *dx, dy0 = *dy;
    double mag;

    cairo_matrix_transform_distance (ctm_inverse, &dx0, &dy0);

    if (dx0 == 0.0 && dy0 == 0.0) {
	if (mag_out)
	    *mag_out = 0.0;
	return FALSE;
    }

    if (dx0 == 0.0) {
	*dx = 0.0;
	if (dy0 > 0.0) {
	    mag = dy0;
	    *dy = 1.0;
	} else {
	    mag = -dy0;
	    *dy = -1.0;
	}
    } else if (dy0 == 0.0) {
	*dy = 0.0;
	if (dx0 > 0.0) {
	    mag = dx0;
	    *dx = 1.0;
	} else {
	    mag = -dx0;
	    *dx = -1.0;
	}
    } else {
	mag = hypot (dx0, dy0);
	*dx = dx0 / mag;
	*dy = dy0 / mag;
    }

    if (mag_out)
	*mag_out = mag;

    return TRUE;
}
コード例 #29
0
ファイル: cairo-matrix.c プロジェクト: jparris/enso
/* Compute the amount that each basis vector is scaled by. */
cairo_status_t
_cairo_matrix_compute_scale_factors (const cairo_matrix_t *matrix,
                                     double *sx, double *sy, int x_major)
{
    double det;

    _cairo_matrix_compute_determinant (matrix, &det);

    if (det == 0)
    {
        *sx = *sy = 0;
    }
    else
    {
        double x = x_major != 0;
        double y = x == 0;
        double major, minor;

        cairo_matrix_transform_distance (matrix, &x, &y);
        major = sqrt(x*x + y*y);
        /*
         * ignore mirroring
         */
        if (det < 0)
            det = -det;
        if (major)
            minor = det / major;
        else
            minor = 0.0;
        if (x_major)
        {
            *sx = major;
            *sy = minor;
        }
        else
        {
            *sx = minor;
            *sy = major;
        }
    }

    return CAIRO_STATUS_SUCCESS;
}
コード例 #30
0
static cairo_status_t
_cairo_pdf_operators_add_glyph (cairo_pdf_operators_t             *pdf_operators,
				cairo_scaled_font_subsets_glyph_t *glyph,
				double 			           x_position)
{
    double x, y;

    x = glyph->x_advance;
    y = glyph->y_advance;
    if (glyph->is_scaled)
	cairo_matrix_transform_distance (&pdf_operators->font_matrix_inverse, &x, &y);

    pdf_operators->glyphs[pdf_operators->num_glyphs].x_position = x_position;
    pdf_operators->glyphs[pdf_operators->num_glyphs].glyph_index = glyph->subset_glyph_index;
    pdf_operators->glyphs[pdf_operators->num_glyphs].x_advance = x;
    pdf_operators->glyph_buf_x_pos += x;
    pdf_operators->num_glyphs++;
    if (pdf_operators->num_glyphs == PDF_GLYPH_BUFFER_SIZE)
	return _cairo_pdf_operators_flush_glyphs (pdf_operators);

    return CAIRO_STATUS_SUCCESS;
}