Exemple #1
0
static cairo_time_t
do_text (cairo_t *cr, int width, int height, int loops)
{
    const char text[] = "the jay, pig, fox, zebra and my wolves quack";
    int len = strlen (text);
    double x, y;
    int i = 0, j = 0;

    cairo_set_font_size (cr, 9);

    cairo_perf_timer_start ();
    cairo_perf_set_thread_aware (cr, FALSE);

    while (loops--) {
	if (loops == 0)
		cairo_perf_set_thread_aware (cr, TRUE);
	do {
	    cairo_move_to (cr, 0, j++ * 10);
	    cairo_show_text (cr, text + i);
	    cairo_get_current_point (cr, &x, &y);
	    while (x < width && cairo_status (cr) == CAIRO_STATUS_SUCCESS) {
		cairo_show_text (cr, text);
		cairo_get_current_point (cr, &x, &y);
	    }
	    if (++i >= len)
		i = 0;
	} while (y < height && cairo_status (cr) == CAIRO_STATUS_SUCCESS);
    }

    cairo_perf_timer_stop ();

    return cairo_perf_timer_elapsed ();
}
static PangoLayout *
show_text_with_page_feed (cairo_t *cr, const gchar *utf8)
{
    PangoLayout *layout;
    double x, y;
    int width, height;

    if (!utf8)
        return NULL;

    layout = cut_cairo_create_pango_layout(cr, utf8, 10);
    if (!layout)
        return NULL;

    cairo_get_current_point(cr, &x, &y);
    pango_layout_get_pixel_size(layout, &width, &height);

    if (A4_HEIGHT < y + height) {
        cairo_show_page(cr);
        init_page(cr);
        cairo_get_current_point(cr, NULL, &y);
        cairo_move_to(cr, x, y);
    }

    pango_cairo_show_layout(cr, layout);
    return layout;
}
Exemple #3
0
static cairo_perf_ticks_t
do_world_map (cairo_t *cr, int width, int height, int loops)
{
    const wm_element_t *e;
    double cx, cy;

    cairo_set_line_width (cr, 0.2);

    cairo_perf_timer_start ();

    while (loops--) {
        cairo_set_source_rgb (cr, .68, .85, .90); /* lightblue */
        cairo_rectangle (cr, 0, 0, 800, 400);
        cairo_fill (cr);

        e = &countries[0];
        while (1) {
            switch (e->type) {
            case WM_NEW_PATH:
            case WM_END:
                cairo_set_source_rgb (cr, .75, .75, .75); /* silver */
                cairo_fill_preserve (cr);
                cairo_set_source_rgb (cr, .50, .50, .50); /* gray */
                cairo_stroke (cr);
                cairo_move_to (cr, e->x, e->y);
                break;
            case WM_MOVE_TO:
                cairo_close_path (cr);
                cairo_move_to (cr, e->x, e->y);
                break;
            case WM_LINE_TO:
                cairo_line_to (cr, e->x, e->y);
                break;
            case WM_HLINE_TO:
                cairo_get_current_point (cr, &cx, &cy);
                cairo_line_to (cr, e->x, cy);
                break;
            case WM_VLINE_TO:
                cairo_get_current_point (cr, &cx, &cy);
                cairo_line_to (cr, cx, e->y);
                break;
            case WM_REL_LINE_TO:
                cairo_rel_line_to (cr, e->x, e->y);
                break;
            }
            if (e->type == WM_END)
                break;
            e++;
        }

        cairo_new_path (cr);
    }

    cairo_perf_timer_stop ();

    return cairo_perf_timer_elapsed ();
}
Exemple #4
0
static void paint_output_info(struct connector *c, struct igt_fb *fb)
{
	cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb);
	int l_width = fb->width;
	int l_height = fb->height;
	double str_width;
	double x, y, top_y;
	double max_width;
	int i;

	cairo_move_to(cr, l_width / 2, l_height / 2);

	/* Print connector and mode name */
	cairo_set_font_size(cr, 48);
	igt_cairo_printf_line(cr, align_hcenter, 10, "%s",
		 kmstest_connector_type_str(c->connector->connector_type));

	cairo_set_font_size(cr, 36);
	str_width = igt_cairo_printf_line(cr, align_hcenter, 10,
		"%s @ %dHz on %s encoder", c->mode.name, c->mode.vrefresh,
		kmstest_encoder_type_str(c->encoder->encoder_type));

	cairo_rel_move_to(cr, -str_width / 2, 0);

	/* List available modes */
	cairo_set_font_size(cr, 18);
	str_width = igt_cairo_printf_line(cr, align_left, 10,
					      "Available modes:");
	cairo_rel_move_to(cr, str_width, 0);
	cairo_get_current_point(cr, &x, &top_y);

	max_width = 0;
	for (i = 0; i < c->connector->count_modes; i++) {
		cairo_get_current_point(cr, &x, &y);
		if (y >= l_height) {
			x += max_width + 10;
			max_width = 0;
			cairo_move_to(cr, x, top_y);
		}
		str_width = igt_cairo_printf_line(cr, align_right, 10,
			"%s @ %dHz", c->connector->modes[i].name,
			 c->connector->modes[i].vrefresh);
		if (str_width > max_width)
			max_width = str_width;
	}

	if (qr_code)
		paint_image(cr, "pass.png");

	igt_assert(!cairo_status(cr));

	cairo_destroy(cr);
}
static void
icon_shape_renderer (cairo_t        *cr,
                     PangoAttrShape *attr,
                     gboolean        do_path,
                     gpointer        user_data)
{
        IconShapeData *data = user_data;
        gdouble x, y;

        cairo_get_current_point (cr, &x, &y);
        if (GPOINTER_TO_UINT (attr->data) == data->placeholder) {
                gdouble ascent;
                gdouble height;
                GdkPixbuf *pixbuf;
                GtkIconInfo *info;

                ascent = pango_units_to_double (attr->ink_rect.y);
                height = pango_units_to_double (attr->ink_rect.height);
                info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
                                                       data->icon,
                                                       (gint)height,
                                                       GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_USE_BUILTIN);
                pixbuf = gtk_icon_info_load_icon (info, NULL);
                g_object_unref (info);

                cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
                cairo_reset_clip (cr);
                gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y + ascent);
                cairo_paint (cr);
                g_object_unref (pixbuf);
        }
}
Exemple #6
0
static void
add_rectangle (cairo_t *cr, double size)
{
    double x, y;

    if (size < 1)
	return;

    cairo_get_current_point (cr, &x, &y);

    cairo_rel_move_to (cr, -size/2., -size/2.);
    cairo_rel_line_to (cr, size, 0);
    cairo_rel_line_to (cr, 0, size);
    cairo_rel_line_to (cr, -size, 0);
    cairo_close_path (cr);

    cairo_save (cr);
    cairo_translate (cr, -size/2., size);
    cairo_move_to (cr, x, y);
    cairo_rotate (cr, M_PI/4);
    add_rectangle (cr, size / M_SQRT2);
    cairo_restore (cr);

    cairo_save (cr);
    cairo_translate (cr, size/2., size);
    cairo_move_to (cr, x, y);
    cairo_rotate (cr, -M_PI/4);
    add_rectangle (cr, size / M_SQRT2);
    cairo_restore (cr);
}
void CanvasCairo::pathAltArcTo(float rx, float ry, float angle, bool largeArc, bool sweep, float x, float y) {
	double _x, _y;
	cairo_get_current_point (_context, &_x, &_y);

	rx = fabsf(rx); ry = fabsf(ry);

	Mat4 transform(Mat4::IDENTITY); Mat4::createRotationZ(angle, &transform);
	Mat4 inverse = transform; inverse.transpose();

	Vec2 vDash(cocos2d::PointApplyTransform(Vec2((_x - x) / 2, (_y - y) / 2), inverse));
	float lambda = (vDash.x * vDash.x) / (rx * rx) + (vDash.y * vDash.y) / (ry * ry);
	if (lambda > 1.0f) {
		rx = sqrtf(lambda) * rx; ry = sqrtf(lambda) * ry;
		vDash = Vec2(cocos2d::PointApplyTransform(Vec2((_x - x) / 2, (_y - y) / 2), inverse));
	}

	float rx_y1_ = (rx * rx * vDash.y * vDash.y);
	float ry_x1_ = (ry * ry * vDash.x * vDash.x);
	float cst = sqrtf(((rx * rx * ry * ry) - rx_y1_ - ry_x1_) / (rx_y1_ + ry_x1_));

	Vec2 cDash((largeArc != sweep ? 1.0f : -1.0f) * cst * rx * vDash.y / ry,
			(largeArc != sweep ? 1.0f : -1.0f) * - cst * ry * vDash.x / rx);

	float cx = cDash.x + (_x + x) / 2;
	float cy = cDash.y + (_y + y) / 2;

	float startAngle = Vec2::angle(Vec2(1.0f, 0.0f), Vec2((vDash.x - cDash.x) / rx, (vDash.y - cDash.y) / ry));
	float sweepAngle = Vec2::angle(Vec2((vDash.x - cDash.x) / rx, (vDash.y - cDash.y) / ry),
			Vec2((-vDash.x - cDash.x) / rx, (-vDash.y - cDash.y) / ry));

	pathArcTo(cx, cy, rx, ry, startAngle, sweepAngle, angle);
}
static void
show_test_case (cairo_t *cr, CutTestCase *test_case, CutTestResultStatus status,
                guint n_tests, guint n_successes, guint n_failures,
                guint n_errors, guint n_pendings, guint n_omissions)
{
    PangoLayout *layout;
    const gchar *utf8;
    int width, height;
    gdouble x, y;

    utf8 = cut_test_get_name(CUT_TEST(test_case));
    layout = show_text_with_page_feed(cr, utf8);
    if (!layout)
        return;

    cairo_get_current_point(cr, &x, &y);
    cairo_save(cr);
    pango_layout_get_pixel_size(layout, &width, &height);
    cairo_rectangle(cr, A4_WIDTH - 100 - 10, y + 2, 100, height - 4);
    cut_cairo_set_source_result_color(cr, status);
    cairo_fill_preserve(cr);
    cairo_set_line_width(cr, 0.5);
    cairo_set_source_rgb(cr, 0, 0, 0);
    cairo_stroke(cr);
    cairo_restore(cr);

    cairo_move_to(cr, x, y + height);
    g_object_unref(layout);
}
static PyObject *
pycairo_get_current_point (PycairoContext *o)
{
    double x, y;
    cairo_get_current_point (o->ctx, &x, &y);
    return Py_BuildValue("(dd)", x, y);
}
Exemple #10
0
CAMLprim value
ml_cairo_get_current_point (value cr)
{
  double x, y;
  cairo_get_current_point (cairo_t_val (cr), &x, &y);
  return ml_cairo_point (x, y);
}
static VALUE
cr_get_current_point (VALUE self)
{
  double point[2];
  cairo_get_current_point (_SELF, point, point + 1);
  return rb_cairo__float_array (point, 2);
}
Exemple #12
0
gfxPoint
gfxContext::CurrentPoint() const
{
    double x, y;
    cairo_get_current_point(mCairo, &x, &y);
    return gfxPoint(x, y);
}
Exemple #13
0
static void
fancy_shape_renderer (cairo_t        *cr,
                      PangoAttrShape *attr,
                      gboolean        do_path,
                      gpointer        data)
{
  double x, y;
  cairo_get_current_point (cr, &x, &y);
  cairo_translate (cr, x, y);

  cairo_scale (cr,
               (double) attr->ink_rect.width  / PANGO_SCALE,
               (double) attr->ink_rect.height / PANGO_SCALE);

  switch (GPOINTER_TO_UINT (attr->data))
    {
    case 0x2665: /* U+2665 BLACK HEART SUIT */
      {
        cairo_move_to (cr, .5, .0);
        cairo_line_to (cr, .9, -.4);
        cairo_curve_to (cr, 1.1, -.8, .5, -.9, .5, -.5);
        cairo_curve_to (cr, .5, -.9, -.1, -.8, .1, -.4);
        cairo_close_path (cr);
      }
      break;
    }

  if (!do_path) {
    cairo_set_source_rgb (cr, 1., 0., 0.);
    cairo_fill (cr);
  }
}
Exemple #14
0
void
lsm_cairo_rel_horizontal (cairo_t *cairo, double dx)
{
	double x0, y0;

	cairo_get_current_point (cairo, &x0, &y0);
	cairo_line_to (cairo, x0 + dx, y0);
}
Exemple #15
0
void
lsm_cairo_rel_vertical (cairo_t *cairo, double dy)
{
	double x0, y0;

	cairo_get_current_point (cairo, &x0, &y0);
	cairo_line_to (cairo, x0, y0 + dy);
}
Exemple #16
0
void
lsm_cairo_rel_quadratic_curve_to (cairo_t *cr, double dx1, double dy1, double dx, double dy)
{
	double x0, y0;

	cairo_get_current_point (cr, &x0, &y0);
	lsm_cairo_quadratic_curve_to (cr, x0 + dx1, y0 + dy1, x0 + dx, y0 + dy);
}
Exemple #17
0
Point
PathBuilderCairo::CurrentPoint() const
{
  CairoTempMatrix tempMatrix(*mPathContext, mTransform);
  double x, y;
  cairo_get_current_point(*mPathContext, &x, &y);
  return Point((Float)x, (Float)y);
}
Exemple #18
0
	value lime_cairo_get_current_point (double handle) {
		
		double x, y;
		cairo_get_current_point ((cairo_t*)(intptr_t)handle, &x, &y);
		Vector2 vec2 = Vector2 (x, y);
		return vec2.Value ();
		
	}
Exemple #19
0
FloatPoint Path::currentPoint() const 
{
    // FIXME: Is this the correct way?
    double x;
    double y;
    cairo_get_current_point(platformPath()->context(), &x, &y);
    return FloatPoint(x, y);
}
Exemple #20
0
	value lime_cairo_get_current_point (value handle) {
		
		double x, y;
		cairo_get_current_point ((cairo_t*)val_data (handle), &x, &y);
		Vector2 vec2 = Vector2 (x, y);
		return vec2.Value ();
		
	}
Exemple #21
0
static void
_emit_smooth_curve (LsmSvgPathContext *ctxt, gboolean relative)
{
	double x, y;
	double x0, y0;

	cairo_get_current_point (ctxt->cr, &x0, &y0);

	switch (ctxt->last_command) {
		case 'C':
			x = 2 * x0 - ctxt->values[2];
			y = 2 * y0 - ctxt->values[3];
			break;
		case 'c':
			x = 2 * x0 - (ctxt->values[2] + x0 - ctxt->values[4]);
			y = 2 * y0 - (ctxt->values[3] + y0 - ctxt->values[5]);
			break;
		case 'S':
			x = 2 * x0 - ctxt->values[0];
			y = 2 * y0 - ctxt->values[1];
			break;
		case 's':
			x = 2 * x0 - (ctxt->values[0] + x0 - ctxt->values[2]);
			y = 2 * y0 - (ctxt->values[1] + y0 - ctxt->values[3]);
			break;
		default: x = x0; y = y0; break;
	}

	while (lsm_str_parse_double_list (&ctxt->ptr, 4, ctxt->values) == 4) {
		if (relative) {
			cairo_get_current_point (ctxt->cr, &x0, &y0);
			cairo_curve_to (ctxt->cr,
					x, y,
					x0 + ctxt->values[0], y0 + ctxt->values[1],
					x0 + ctxt->values[2], y0 + ctxt->values[3]);
			x = 2 * (x0 + ctxt->values[2]) - (x0 + ctxt->values[0]);
			y = 2 * (y0 + ctxt->values[3]) - (y0 + ctxt->values[1]);
		} else {
			cairo_curve_to (ctxt->cr, x, y,
					ctxt->values[0], ctxt->values[1], ctxt->values[2], ctxt->values[3]);
			x = 2 * ctxt->values[2] - ctxt->values[0];
			y = 2 * ctxt->values[3] - ctxt->values[1];
		}
	}
}
Exemple #22
0
void CanvasCairo::pathQuadTo(float x1, float y1, float x2, float y2) {
	double x0, y0;
	cairo_get_current_point (_context, &x0, &y0);
	cairo_curve_to (_context,
		2.0 / 3.0 * x1 + 1.0 / 3.0 * x0,
		2.0 / 3.0 * y1 + 1.0 / 3.0 * y0,
		2.0 / 3.0 * x1 + 1.0 / 3.0 * x2,
		2.0 / 3.0 * y1 + 1.0 / 3.0 * y2,
		x2, y2);
}
Exemple #23
0
void
lsm_cairo_rel_elliptical_arc (cairo_t *cairo, double rx, double ry, double x_axis_rotation,
			   gboolean large_arc_flag, gboolean sweep_flag, double dx, double dy)
{
	double x, y;

	cairo_get_current_point (cairo, &x, &y);

	lsm_cairo_elliptical_arc (cairo, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x +dx ,y + dy);
}
//-----------------------------------------------------------------------------------
void ct_helper_quadratic_to (cairo_t *cr, double x1, double y1, double x2, double y2){
	double x0, y0;
	cairo_get_current_point (cr, &x0, &y0);
	cairo_curve_to (cr,
					2.0 / 3.0 * x1 + 1.0 / 3.0 * x0,
					2.0 / 3.0 * y1 + 1.0 / 3.0 * y0,
					2.0 / 3.0 * x1 + 1.0 / 3.0 * x2,
					2.0 / 3.0 * y1 + 1.0 / 3.0 * y2,
					y1, y2);
}
Exemple #25
0
static int
cr_get_current_point (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    double x, y;
    if (!cairo_has_current_point(*obj))
        return 0;
    cairo_get_current_point(*obj, &x, &y);
    lua_pushnumber(L, x);
    lua_pushnumber(L, y);
    return 2;
}
Exemple #26
0
cairo_t *
gsk_cairo_blur_start_drawing (cairo_t         *cr,
                              float            radius,
                              GskBlurFlags     blur_flags)
{
  cairo_rectangle_int_t clip_rect;
  cairo_surface_t *surface;
  cairo_t *blur_cr;
  gdouble clip_radius;
  gdouble x_scale, y_scale;
  gboolean blur_x = (blur_flags & GSK_BLUR_X) != 0;
  gboolean blur_y = (blur_flags & GSK_BLUR_Y) != 0;

  if (!needs_blur (radius))
    return cr;

  gdk_cairo_get_clip_rectangle (cr, &clip_rect);

  clip_radius = gsk_cairo_blur_compute_pixels (radius);

  x_scale = y_scale = 1;
  cairo_surface_get_device_scale (cairo_get_target (cr), &x_scale, &y_scale);

  if (blur_flags & GSK_BLUR_REPEAT)
    {
      if (!blur_x)
        clip_rect.width = 1;
      if (!blur_y)
        clip_rect.height = 1;
    }

  /* Create a larger surface to center the blur. */
  surface = cairo_surface_create_similar_image (cairo_get_target (cr),
                                                CAIRO_FORMAT_A8,
                                                x_scale * (clip_rect.width + (blur_x ? 2 * clip_radius : 0)),
                                                y_scale * (clip_rect.height + (blur_y ? 2 * clip_radius : 0)));
  cairo_surface_set_device_scale (surface, x_scale, y_scale);
  cairo_surface_set_device_offset (surface,
                                    x_scale * ((blur_x ? clip_radius : 0) - clip_rect.x),
                                    y_scale * ((blur_y ? clip_radius : 0) - clip_rect.y));

  blur_cr = cairo_create (surface);
  cairo_set_user_data (blur_cr, &original_cr_key, cairo_reference (cr), (cairo_destroy_func_t) cairo_destroy);

  if (cairo_has_current_point (cr))
    {
      double x, y;

      cairo_get_current_point (cr, &x, &y);
      cairo_move_to (blur_cr, x, y);
    }

  return blur_cr;
}
Exemple #27
0
void
gra2cairo_draw_path(struct gra2cairo_local *local)
{
  if (local->cairo && local->linetonum) {
    double x, y;

    cairo_get_current_point(local->cairo, &x, &y);
    cairo_stroke(local->cairo);
    cairo_move_to(local->cairo, x, y);
    local->linetonum = 0;
  }
}
Exemple #28
0
static int ui_get_current_point(lua_State *L)
{
	double x, y;

	struct context *c = lua_touserdata(L, 1);

	cairo_get_current_point(c->cr, &x, &y);

	lua_pushnumber(L, x);
	lua_pushnumber(L, y);

	return 2;
}
Exemple #29
0
void
gfxContext::QuadraticCurveTo(const gfxPoint& pt1, const gfxPoint& pt2)
{
    double cx, cy;
    cairo_get_current_point(mCairo, &cx, &cy);
    cairo_curve_to(mCairo,
                   (cx + pt1.x * 2.0) / 3.0,
                   (cy + pt1.y * 2.0) / 3.0,
                   (pt1.x * 2.0 + pt2.x) / 3.0,
                   (pt1.y * 2.0 + pt2.y) / 3.0,
                   pt2.x,
                   pt2.y);
}
Exemple #30
0
static void
mini_svg_render (MiniSvg  *shape,
		 cairo_t  *cr,
		 gboolean  do_path)
{
  double x, y;
  const char *p;
  char op[2];
  int items, len;

  cairo_get_current_point (cr, &x, &y);
  cairo_translate (cr, x, y);

  for (p = shape->path; (items = sscanf (p, "%1s %n", op, &len)), p += len, *p;)
    switch (*op)
    {
      case 'M':
        {
	  sscanf (p, "%lf,%lf %n", &x, &y, &len); p += len;
	  cairo_move_to (cr, x, y);
	  break;
	}
      case 'L':
        {
	  sscanf (p, "%lf,%lf %n", &x, &y, &len); p += len;
	  cairo_line_to (cr, x, y);
	  break;
	}
      case 'C':
        {
	  double x1, y1, x2, y2, x3, y3;
	  sscanf (p, "%lf,%lf %lf,%lf %lf,%lf %n", &x1, &y1, &x2, &y2, &x3, &y3, &len); p += len;
	  cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
	  break;
	}
      case 'z':
        {
	  cairo_close_path (cr);
	  break;
	}
      default: 
        {
	  g_warning ("Invalid MiniSvg operation '%c'", *op);
	  break;
	}
    }

  if (!do_path)
    cairo_fill (cr);
}