Ejemplo n.º 1
0
void CairoGLRenderer::InitDemo(HWND hWnd, HDC hdc)
{
	RECT rect;
    ::GetClientRect(hWnd, &rect);

    m_hdc = hdc;
	m_hglrc = wglCreateContext(hdc);

    long width = rect.right - rect.left;
    long height = rect.bottom - rect.top;

	m_device = cairo_wgl_device_create(m_hglrc);

    if (cairo_device_status(m_device) != CAIRO_STATUS_SUCCESS)
       printf("cairo device failed with %s\n", cairo_status_to_string(cairo_device_status(m_device)));
 
    m_surface = cairo_gl_surface_create_for_dc(m_device, m_hdc, width, height);
 
    if (cairo_surface_status(m_surface) != CAIRO_STATUS_SUCCESS)
	{
		const char* error = cairo_status_to_string(cairo_surface_status(m_surface));
        fprintf(stderr, "cairo surface failed with %s\n", error);
	}
 
    m_cr = cairo_create (m_surface);
 
    if (cairo_status(m_cr) != CAIRO_STATUS_SUCCESS)
       printf("cairo failed with %s\n", cairo_status_to_string(cairo_status(m_cr)));
}
Ejemplo n.º 2
0
void CAIRODrawLines(cairo_t *cr,Gpoint *ype,int npnt,int mode)
{
  int i;

/*    printf("line: cr: %p\n",cr); */
  if (mode != CoordModeOrigin ) {
    printf("drawing lines in wrong coordmode! your mode: %i vs %i\n",mode,CoordModeOrigin);
    exit(1);
  }
  cairo_move_to(cr,ype[0].x,ype[0].y);
  if (cairo_status(cr) != CAIRO_STATUS_SUCCESS ) {
    fprintf(stderr,"NOOOOOOOOOOOO BAD MOVETO%s\n",cairo_status_to_string(cairo_status(cr)));
    exit(1);
  }
  for(i=1;i<npnt;i++) {
    cairo_line_to(cr,ype[i].x,ype[i].y);
  if (cairo_status(cr) != CAIRO_STATUS_SUCCESS ) {
    fprintf(stderr,"NOOOOOOOOOOOO BAD LINETO%s\n",cairo_status_to_string(cairo_status(cr)));
    exit(1);
  }
  }
  cairo_stroke(cr);
  if (cairo_status(cr) != CAIRO_STATUS_SUCCESS ) {
    fprintf(stderr,"NOOOOOOOOOOOO BAD STROKE%s\n",cairo_status_to_string(cairo_status(cr)));
    exit(1);
  }
}
Ejemplo n.º 3
0
static void
render_cairo_surface (const RENDER * render, SNDFILE *infile, int samplerate, sf_count_t filelen)
{
	cairo_surface_t * surface = NULL ;
	cairo_status_t status ;

	/*
	**	CAIRO_FORMAT_RGB24 	 each pixel is a 32-bit quantity, with the upper 8 bits
	**	unused. Red, Green, and Blue are stored in the remaining 24 bits in that order.
	*/

	surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, render->width, render->height) ;
	if (surface == NULL || cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
	{	status = cairo_surface_status (surface) ;
		printf ("Error while creating surface : %s\n", cairo_status_to_string (status)) ;
		exit (1) ;
		} ;

	cairo_surface_flush (surface) ;

	render_to_surface (render, infile, samplerate, filelen, surface) ;

	status = cairo_surface_write_to_png (surface, render->pngfilepath) ;
	if (status != CAIRO_STATUS_SUCCESS)
	{	printf ("Error while creating PNG file : %s\n", cairo_status_to_string (status)) ;
		exit (1) ;
		} ;

	cairo_surface_destroy (surface) ;

	return ;
} /* render_cairo_surface */
Ejemplo n.º 4
0
void CAIROFillPolygon(cairo_t *cr, Gpoint *ype, int npnt, int shape, int mode) 
{
  int i;
  // printf("polyg: cr: %p\n",cr);
  if (mode != CoordModeOrigin ){
    printf("fill polygon in wrong coordmode, not implemented yet! your mode: %i vs %i\n",mode,CoordModeOrigin);
  }

  if (shape != Complex ) {
    printf("fill polygon in wrong shape mode, not implemented yet!\nResults may be different from expected ones");
  }
  cairo_move_to(cr,ype[0].x,ype[0].y);
  if (cairo_status(cr) != CAIRO_STATUS_SUCCESS ) {
    fprintf(stderr,"NOOOOOOOOOOOO BAD PMOVE TO: %s\n",cairo_status_to_string(cairo_status(cr)));
    exit(1);
  }
  for(i=1;i<npnt;i++) {
    cairo_line_to(cr,ype[i].x,ype[i].y);
    if (cairo_status(cr) != CAIRO_STATUS_SUCCESS ) {
      fprintf(stderr,"NOOOOOOOOOOOO BAD PLINE TO: %s\n",cairo_status_to_string(cairo_status(cr)));
      exit(1);
    }
  }
  cairo_fill(cr);
  if (cairo_status(cr) != CAIRO_STATUS_SUCCESS ) {
    fprintf(stderr,"NOOOOOOOOOOOO BAD PFILL%s\n",cairo_status_to_string(cairo_status(cr)));
    exit(1);
  }
}
Ejemplo n.º 5
0
int
Pycairo_Check_Status (cairo_status_t status)
{
    if (PyErr_Occurred() != NULL)
	return 1;

    switch (status) {
    case CAIRO_STATUS_SUCCESS:
	return 0;
    /* if appropriate - translate the status string into Python,
     * else - use cairo_status_to_string()
     */
    case CAIRO_STATUS_NO_MEMORY:
	PyErr_NoMemory();
	break;
    case CAIRO_STATUS_READ_ERROR:
    case CAIRO_STATUS_WRITE_ERROR:
	PyErr_SetString(PyExc_IOError, cairo_status_to_string (status));
	break;
    case CAIRO_STATUS_INVALID_RESTORE:
	PyErr_SetString(CairoError, "Context.restore without matching "
			"Context.save");
	break;
    case CAIRO_STATUS_INVALID_POP_GROUP:
	PyErr_SetString(CairoError, "Context.pop_group without matching "
			"Context.push_group");
	break;
    default:
	PyErr_SetString(CairoError, cairo_status_to_string (status));
    }
    return 1;
}
Ejemplo n.º 6
0
static Rboolean
BM_Open(pDevDesc dd, pX11Desc xd, int width, int height)
{
    cairo_status_t res;
    if (xd->type == PNG || xd->type == JPEG ||
	xd->type == TIFF || xd->type == BMP) {
	xd->cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
					    xd->windowWidth,
					    xd->windowHeight);
    } else if (xd->type == PNGdirect) {
	xd->cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
					    xd->windowWidth,
					    xd->windowHeight);
    } else if(xd->type == SVG || xd->type == PDF || xd->type == PS) {
	/* leave creation to BM_Newpage */
	return TRUE;
    } else
	error(_("unimplemented cairo-based device"));

    res = cairo_surface_status(xd->cs);
    if (res != CAIRO_STATUS_SUCCESS) {
	warning("cairo error '%s'", cairo_status_to_string(res));
	return FALSE;
    }
    xd->cc = cairo_create(xd->cs);
    res = cairo_status(xd->cc);
    if (res != CAIRO_STATUS_SUCCESS) {
	warning("cairo error '%s'", cairo_status_to_string(res));
	return FALSE;
    }
    cairo_set_operator(xd->cc, CAIRO_OPERATOR_OVER);
    cairo_reset_clip(xd->cc);
    cairo_set_antialias(xd->cc, xd->antialias);
    return TRUE;
}
Ejemplo n.º 7
0
bool
args_parse (args_t *args, int argc, char **argv)
{
    int i;
    if (argc < 3) {
	fprintf (stderr, "%s", copyright);
	fprintf (stderr, "%s", usage);
	return false;
    }
    for (i = 0; i < argc; i++) {
	if (i == 1) {
	    args->surface_a = cairo_image_surface_create_from_png (argv[1]);
	    if (cairo_surface_status (args->surface_a))
	    {
		fprintf (stderr, "FAIL: Cannot open %s: %s\n",
			 argv[1], cairo_status_to_string (cairo_surface_status (args->surface_a)));
		return false;
	    }
	} else if (i == 2) {
	    args->surface_b = cairo_image_surface_create_from_png (argv[2]);
	    if (cairo_surface_status (args->surface_b))
	    {
		fprintf (stderr, "FAIL: Cannot open %s: %s\n",
			 argv[2], cairo_status_to_string (cairo_surface_status (args->surface_b)));
		return false;
	    }
	} else {
	    if (strstr(argv[i], "-fov")) {
		if (i + 1 < argc) {
		    args->FieldOfView = (float) atof(argv[i + 1]);
		}
	    } else if (strstr(argv[i], "-verbose")) {
		args->Verbose = true;
	    } else 	if (strstr(argv[i], "-threshold")) {
		if (i + 1 < argc) {
		    args->ThresholdPixels = atoi(argv[i + 1]);
		}
	    } else 	if (strstr(argv[i], "-gamma")) {
		if (i + 1 < argc) {
		    args->Gamma = (float) atof(argv[i + 1]);
		}
	    }else 	if (strstr(argv[i], "-luminance")) {
		if (i + 1 < argc) {
		    args->Luminance = (float) atof(argv[i + 1]);
		}
	    }
	}
    } /* i */
    return true;
}
Ejemplo n.º 8
0
int
main (int argc, char *argv[])
{
    cairo_t *cr;
    cairo_surface_t *argb, *rgb24;
    cairo_status_t status;
    const char *input, *output;

    if (argc != 3) {
	fprintf (stderr, "usage: %s input.png output.png", argv[0]);
	fprintf (stderr, "Loads a PNG image (potentially with alpha) and writes out a flattened (no alpha)\nPNG image by first blending over white.\n");
	return 1;
    }

    input = argv[1];
    output = argv[2];

    argb = cairo_image_surface_create_from_png (input);
    status = cairo_surface_status (argb);
    if (status) {
	fprintf (stderr, "%s: Error: Failed to load %s: %s\n",
		 argv[0], input, cairo_status_to_string (status));
	return 1;
    }

    rgb24 = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
					cairo_image_surface_get_width (argb),
					cairo_image_surface_get_height (argb));

    cr = cairo_create (rgb24);

    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
    cairo_paint (cr);

    cairo_set_source_surface (cr, argb, 0, 0);
    cairo_paint (cr);

    cairo_destroy (cr);

    status = cairo_surface_write_to_png (rgb24, output);
    if (status) {
	fprintf (stderr, "%s: Error: Failed to write %s: %s\n",
		 argv[0], output, cairo_status_to_string (status));
	return 1;
    }

    return 0;
}
Ejemplo n.º 9
0
static const char *
_cairo_script_render_page (const char *filename,
			   cairo_surface_t **surface_out)
{
    cairo_script_interpreter_t *csi;
    cairo_surface_t *surface = NULL;
    cairo_status_t status;
    const cairo_script_interpreter_hooks_t hooks = {
	.closure = &surface,
	.surface_create = _create_image,
    };

    csi = cairo_script_interpreter_create ();
    cairo_script_interpreter_install_hooks (csi, &hooks);
    cairo_script_interpreter_run (csi, filename);
    status = cairo_script_interpreter_destroy (csi);
    if (surface == NULL) {
	return "cairo-script interpreter failed";
    }

    if (status == CAIRO_STATUS_SUCCESS)
	status = cairo_surface_status (surface);
    if (status) {
	cairo_surface_destroy (surface);
	return cairo_status_to_string (status);
    }

    *surface_out = surface;
    return NULL;
}
Ejemplo n.º 10
0
int
conv_pdf (RioData *data, const char *filename)
{
  int status;

  /* Determine original image height & width */
  uint32_t height, width;
  status = rio_data_get_metadata_uint32 (data, RIO_KEY_IMAGE_ROWS, &height)
    && rio_data_get_metadata_uint32 (data, RIO_KEY_IMAGE_COLS, &width);
  if (!status) {
    fprintf (stderr, "ERROR: Could not determine image dimensions.\n");
    return 0;
  }

  /* Create output surface */
  cairo_surface_t *pdf = cairo_pdf_surface_create (filename, width, height);
  if (cairo_surface_status (pdf) != CAIRO_STATUS_SUCCESS) {
    fprintf (stderr, "ERROR: Could not create PDF surface for %s: %s\n",
             filename, cairo_status_to_string (cairo_surface_status (pdf)));
    return 0;
  }
  /* FIXME naively assumes that all will be fine from now on. */

  svg_draw (data, pdf);

  cairo_surface_finish (pdf);
  return 1;
 }
Ejemplo n.º 11
0
void *
addgra2cairo()
/* addgra2cairoile() returns NULL on error */
{
  int i;

  if (CompatibleFontHash == NULL) {
    CompatibleFontHash = nhash_new();
    if (CompatibleFontHash == NULL) {
      return NULL;
    }
    for (i = 0; i < (int) (sizeof(CompatibleFont) / sizeof(*CompatibleFont)); i++) {
      nhash_set_int(CompatibleFontHash, CompatibleFont[i].old_name, i);
    }
  }

  if (Gra2CairoErrMsgs == NULL) {
    Gra2CairoErrMsgs = g_malloc(sizeof(*Gra2CairoErrMsgs) * CAIRO_STATUS_LAST_STATUS);
    Gra2CairoErrMsgNum = CAIRO_STATUS_LAST_STATUS;

    for (i = 0; i < CAIRO_STATUS_LAST_STATUS; i++) {
      Gra2CairoErrMsgs[i] = g_strdup(cairo_status_to_string(i));
    }
  }

  return addobject(NAME, NULL, PARENT, OVERSION, TBLNUM, gra2cairo, Gra2CairoErrMsgNum, Gra2CairoErrMsgs, NULL, NULL);
}
Ejemplo n.º 12
0
static cairo_bool_t
check_count (const cairo_test_context_t *ctx,
	     const char *message, cairo_bool_t uses_clip_rects,
             cairo_rectangle_list_t *list, int expected)
{
    if (!uses_clip_rects) {
        if (expected == 0 && list->num_rectangles == 0)
            return 1;
	if (list->num_rectangles == expected)
	    return 1;
	if (list->status == CAIRO_STATUS_CLIP_NOT_REPRESENTABLE)
	    return 1;
        cairo_test_log (ctx, "Error: %s; cairo_copy_clip_rectangle_list unexpectedly got %d rectangles\n",
                        message, list->num_rectangles);
        return 0;
    }

    if (list->status != CAIRO_STATUS_SUCCESS) {
        cairo_test_log (ctx, "Error: %s; cairo_copy_clip_rectangle_list failed with \"%s\"\n",
                        message, cairo_status_to_string(list->status));
        return 0;
    }

    if (list->num_rectangles == expected)
        return 1;
    cairo_test_log (ctx, "Error: %s; expected %d rectangles, got %d\n", message,
                    expected, list->num_rectangles);
    return 0;
}
Ejemplo n.º 13
0
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
    int x,y;
    int width = 10;
    int height = 10;
    cairo_surface_t *surf;
    cairo_t *cr;
    int false_positive_count = 0;
    cairo_status_t status;
    cairo_test_status_t ret;

    surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
    cr = cairo_create (surf);
    cairo_surface_destroy (surf);

    /* Empty horizontal trapezoid. */
    cairo_move_to (cr, 0, height/3);
    cairo_line_to (cr, width, height/3);
    cairo_close_path (cr);

    /* Empty non-horizontal trapezoid #1. */
    cairo_move_to (cr, 0, 0);
    cairo_line_to (cr, width, height/2);
    cairo_close_path (cr);

    /* Empty non-horizontal trapezoid #2 intersecting #1. */
    cairo_move_to (cr, 0, height/2);
    cairo_line_to (cr, width, 0);
    cairo_close_path (cr);

    status = cairo_status (cr);

    /* Point sample the tessellated path. */
    for (y = 0; y < height; y++) {
	for (x = 0; x < width; x++) {
	    if (cairo_in_fill (cr, x, y)) {
		false_positive_count++;
	    }
	}
    }
    cairo_destroy (cr);

    /* Check that everything went well. */
    ret = CAIRO_TEST_SUCCESS;
    if (CAIRO_STATUS_SUCCESS != status) {
	cairo_test_log (ctx, "Failed to create a test surface and path: %s\n",
			cairo_status_to_string (status));
	ret = CAIRO_TEST_XFAILURE;
    }

    if (0 != false_positive_count) {
	cairo_test_log (ctx, "Point sampling found %d false positives "
			"from cairo_in_fill()\n",
			false_positive_count);
	ret = CAIRO_TEST_XFAILURE;
    }

    return ret;
}
Ejemplo n.º 14
0
    explicit font_fc(cairo_t* cairo, FcPattern* pattern, double offset, double dpi_x, double dpi_y) : font(cairo, offset), m_pattern(pattern) {
      cairo_matrix_t fm;
      cairo_matrix_t ctm;
      cairo_matrix_init_scale(&fm, size(dpi_x), size(dpi_y));
      cairo_get_matrix(m_cairo, &ctm);

      auto fontface = cairo_ft_font_face_create_for_pattern(m_pattern);
      auto opts = cairo_font_options_create();
      m_scaled = cairo_scaled_font_create(fontface, &fm, &ctm, opts);
      cairo_font_options_destroy(opts);
      cairo_font_face_destroy(fontface);

      auto status = cairo_scaled_font_status(m_scaled);
      if (status != CAIRO_STATUS_SUCCESS) {
        throw application_error(sstream() << "cairo_scaled_font_create(): " << cairo_status_to_string(status));
      }

      auto lock = make_unique<utils::ft_face_lock>(m_scaled);
      auto face = static_cast<FT_Face>(*lock);

      if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) == FT_Err_Ok) {
        return;
      } else if (FT_Select_Charmap(face, FT_ENCODING_BIG5) == FT_Err_Ok) {
        return;
      } else if (FT_Select_Charmap(face, FT_ENCODING_SJIS) == FT_Err_Ok) {
        return;
      }

      lock.reset();
    }
Ejemplo n.º 15
0
/* Shows how to draw with Cairo on SDL surfaces */
static void
draw_screen (SDL_Surface *screen)
{
    cairo_t *cr;
    cairo_status_t status;

    /* Create a cairo drawing context, normalize it and draw a clock. */
    SDL_LockSurface (screen); {
        cr = cairosdl_create (screen);

        cairo_scale (cr, screen->w, screen->h);
        draw (cr);

        status = cairo_status (cr);
        cairosdl_destroy (cr);
    }
    SDL_UnlockSurface (screen);
    SDL_Flip (screen);

    /* Nasty nasty error handling. */
    if (status != CAIRO_STATUS_SUCCESS) {
        fprintf (stderr, "Unable to create or draw with a cairo context "
                 "for the screen: %s\n",
                 cairo_status_to_string (status));
        exit (1);
    }
}
static inline cairo_surface_t *
get_icon_from_gconf (GConfClient *client,
                     const gchar *plugin_id)
{
  gchar *icon_path;

  icon_path = get_icon_path_from_gconf (client, plugin_id);

  if (icon_path)
    {
      cairo_surface_t *icon, *scaled_icon = NULL;
      cairo_status_t status;

      icon = cairo_image_surface_create_from_png (icon_path);
      status = cairo_surface_status (icon);

      if (status != CAIRO_STATUS_SUCCESS)
        g_warning ("%s. Could not get thumbnail from file %s. %s",
                   __FUNCTION__,
                   icon_path,
                   cairo_status_to_string (status));
      else
        scaled_icon = scale_icon_if_required (icon);

      cairo_surface_destroy (icon);
      g_free (icon_path);

      return scaled_icon;
    }

  return NULL;
}
static void
expose_event_cb (GtkDrawingArea *drawing_area,
		 GdkEventExpose *eev,
		 gpointer  user_data)
{
	GtkWidget *widget;
	EomPrintPreviewPrivate *priv;
	cairo_t *cr;

	widget = GTK_WIDGET (drawing_area);
	priv = EOM_PRINT_PREVIEW (user_data)->priv;

	update_relative_sizes (EOM_PRINT_PREVIEW (user_data));

	cr = gdk_cairo_create (gtk_widget_get_window (widget));

	eom_print_preview_draw (EOM_PRINT_PREVIEW (user_data), cr);

	if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
		fprintf (stderr, "Cairo is unhappy: %s\n",
			 cairo_status_to_string (cairo_status (cr)));
	}

	cairo_destroy (cr);

	gdk_window_get_pointer (gtk_widget_get_window (widget), NULL, NULL, NULL);
}
Ejemplo n.º 18
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
    char *filename;
    cairo_surface_t *surface;

    xasprintf (&filename, "%s/%s", ctx->srcdir,
	       "create-from-png.ref.png");

    surface = cairo_image_surface_create_from_png (filename);
    if (cairo_surface_status (surface)) {
	cairo_test_status_t result;

	result = cairo_test_status_from_status (ctx,
						cairo_surface_status (surface));
	if (result == CAIRO_TEST_FAILURE) {
	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
			    filename,
			    cairo_status_to_string (cairo_surface_status (surface)));
	}

	free (filename);
	return result;
    }

    cairo_set_source_surface (cr, surface, 0, 0);
    cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
    cairo_paint (cr);

    cairo_surface_destroy (surface);

    free (filename);
    return CAIRO_TEST_SUCCESS;
}
Ejemplo n.º 19
0
static void
draw_page(SDL_Surface * dst, cairo_t * cr, PopplerDocument * document,
	  int page_num)
{
	cairo_status_t status;
	PopplerPage *page;

	/* Create a cairo drawing context, normalize it and draw a clock. */
	SDL_LockSurface(dst);
	{

		page = poppler_document_get_page(document, page_num - 1);
		if (page == NULL) {
			printf("poppler fail: page not found\n");
			return;
		}

		cairo_save(cr);
		poppler_page_render(page, cr);
		cairo_restore(cr);
		g_object_unref(page);

		status = cairo_status(cr);
	}
	SDL_UnlockSurface(dst);

	/* Nasty nasty error handling. */
	if (status != CAIRO_STATUS_SUCCESS) {
		fprintf(stderr, "Unable to create or draw with a cairo context "
			"for the screen: %s\n", cairo_status_to_string(status));
		exit(1);
	}
}
Ejemplo n.º 20
0
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
    cairo_t *cr;
    const char *filename = "svg-clip.out.svg";
    cairo_surface_t *surface;

    if (! cairo_test_is_target_enabled (ctx, "svg11") &&
	! cairo_test_is_target_enabled (ctx, "svg12"))
    {
	return CAIRO_TEST_UNTESTED;
    }

    surface = cairo_svg_surface_create (filename,
					WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
    if (cairo_surface_status (surface)) {
	cairo_test_log (ctx,
			"Failed to create svg surface for file %s: %s\n",
			filename, cairo_status_to_string (cairo_surface_status (surface)));
	return CAIRO_TEST_FAILURE;
    }

    cr = cairo_create (surface);

    test_clip (cr, WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
    cairo_show_page (cr);

    cairo_destroy (cr);
    cairo_surface_destroy (surface);

    printf ("svg-clip: Please check %s to make sure it looks happy.\n",
	    filename);
    return CAIRO_TEST_SUCCESS;
}
Ejemplo n.º 21
0
void
lsm_dom_view_render (LsmDomView *view, cairo_t *cairo, double x, double y)
{
	LsmDomViewClass *view_class;

	g_return_if_fail (LSM_IS_DOM_VIEW (view));
	g_return_if_fail (LSM_IS_DOM_DOCUMENT (view->document));
	g_return_if_fail (cairo != NULL);

	lsm_dom_view_set_cairo_context (view, cairo);

	cairo_save (view->cairo);

	cairo_translate (view->cairo, x, y);

	view_class = LSM_DOM_VIEW_GET_CLASS (view);
	if (view_class->render != NULL)
		view_class->render (view);

	cairo_restore (view->cairo);

	lsm_debug_render ("[LsmDomView::render] cairo status = %s",
			  cairo_status_to_string (cairo_status (view->cairo)));

	lsm_dom_view_set_cairo_context (view, NULL);
}
Ejemplo n.º 22
0
CAMLexport value caml_cairo_status_to_string(value vstatus)
{
  CAMLparam1(vstatus);
  cairo_status_t status = (cairo_status_t) (Int_val(vstatus) + 2);
  const char* msg = cairo_status_to_string(status);
  CAMLreturn(caml_copy_string(msg));
}
Ejemplo n.º 23
0
static const char *
_rsvg_render_page (const char *filename,
		   cairo_surface_t **surface_out)
{
    RsvgHandle *handle;
    RsvgDimensionData dimensions;
    GError *error = NULL;
    cairo_surface_t *surface;
    cairo_t *cr;
    cairo_status_t status;

    handle = rsvg_handle_new_from_file (filename, &error);
    if (handle == NULL)
	return error->message; /* XXX g_error_free */

    rsvg_handle_get_dimensions (handle, &dimensions);
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
					  dimensions.width,
					  dimensions.height);
    cr = cairo_create (surface);

    rsvg_handle_render_cairo (handle, cr);
    g_object_unref (handle);

    status = cairo_status (cr);
    cairo_destroy (cr);

    if (status) {
	cairo_surface_destroy (surface);
	return  cairo_status_to_string (status);
    }

    *surface_out = surface;
    return NULL;
}
static void
generate_reference (double ppi_x, double ppi_y, const char *filename)
{
    cairo_surface_t *surface, *target;
    cairo_t *cr;
    cairo_status_t status;

    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
	                                  SIZE*ppi_x/72, SIZE*ppi_y/72);
    cr = cairo_create (surface);
    cairo_surface_destroy (surface);

    /* As we wish to mimic a PDF surface, copy across the default font options
     * from the PDF backend.
     */
    {
	cairo_surface_t *pdf;
	cairo_font_options_t *options;

	options = cairo_font_options_create ();

	pdf = cairo_pdf_surface_create ("tmp.pdf", 1, 1);
	cairo_surface_get_font_options (pdf, options);
	cairo_surface_destroy (pdf);

	cairo_set_font_options (cr, options);
	cairo_font_options_destroy (options);
    }

#if SET_TOLERANCE
    cairo_set_tolerance (cr, 3.0);
#endif

    cairo_save (cr); {
	cairo_set_source_rgb (cr, 1, 1, 1);
	cairo_paint (cr);
    } cairo_restore (cr);

    cairo_scale (cr, ppi_x/72., ppi_y/72.);
    draw (cr, SIZE, SIZE);

    surface = cairo_surface_reference (cairo_get_target (cr));
    cairo_destroy (cr);

    target = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE, SIZE);
    cr = cairo_create (target);
    cairo_scale (cr, 72./ppi_x, 72./ppi_y);
    cairo_set_source_surface (cr, surface, 0, 0);
    cairo_paint (cr);

    status = cairo_surface_write_to_png (cairo_get_target (cr), filename);
    cairo_destroy (cr);

    if (status) {
	fprintf (stderr, "Failed to generate reference image '%s': %s\n",
		 filename, cairo_status_to_string (status));
	exit (1);
    }
}
Ejemplo n.º 25
0
/* adapted from pdf2png.c */
static const char *
_poppler_render_page (const char *filename,
		      const char *page_label,
		      cairo_surface_t **surface_out)
{
    PopplerDocument *document;
    PopplerPage *page;
    double width, height;
    GError *error = NULL;
    gchar *absolute, *uri;
    cairo_surface_t *surface;
    cairo_t *cr;
    cairo_status_t status;

    if (g_path_is_absolute (filename)) {
	absolute = g_strdup (filename);
    } else {
	gchar *dir = g_get_current_dir ();
	absolute = g_build_filename (dir, filename, (gchar *) 0);
	g_free (dir);
    }

    uri = g_filename_to_uri (absolute, NULL, &error);
    g_free (absolute);
    if (uri == NULL)
	return error->message; /* XXX g_error_free (error) */

    document = poppler_document_new_from_file (uri, NULL, &error);
    g_free (uri);
    if (document == NULL)
	return error->message; /* XXX g_error_free (error) */

    page = poppler_document_get_page_by_label (document, page_label);
    g_object_unref (document);
    if (page == NULL)
	return "page not found";

    poppler_page_get_size (page, &width, &height);

    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
    cr = cairo_create (surface);

    cairo_set_source_rgb (cr, 1., 1., 1.);
    cairo_paint (cr);

    poppler_page_render (page, cr);
    g_object_unref (page);

    status = cairo_status (cr);
    cairo_destroy (cr);

    if (status) {
	cairo_surface_destroy (surface);
	return  cairo_status_to_string (status);
    }

    *surface_out = surface;
    return NULL;
}
Ejemplo n.º 26
0
int
main (int argc, char **argv)
{
    FILE *in = stdin, *out = stdout;
    cairo_status_t status;
    int i;

    if (argc >= 3) {
	if (strcmp (argv[argc-1], "-")) {
	    out = fopen (argv[argc-1], "w");
	    if (out == NULL) {
		fprintf (stderr, "Failed to open output '%s'\n", argv[argc-1]);
		return 1;
	    }
	}
    }

    if (argc > 2) {
	for (i = 1; i < argc - 1; i++) {
	    in = fopen (argv[i], "r");
	    if (in == NULL) {
		fprintf (stderr, "Failed to open input '%s'\n", argv[i]);
		return 1;
	    }

	    status = cairo_script_interpreter_translate_stream (in, write_func, out);
	    fclose (in);

	    if (status)
		break;
	}
    } else {
	if (argc > 1) {
	    if (strcmp (argv[1], "-")) {
		in = fopen (argv[1], "r");
		if (in == NULL) {
		    fprintf (stderr, "Failed to open input '%s'\n", argv[1]);
		    return 1;
		}
	    }
	}

	status = cairo_script_interpreter_translate_stream (in, write_func, out);

	if (in != stdin)
	    fclose (in);
    }

    if (out != stdout)
	fclose (out);

    if (status) {
	fprintf (stderr, "Translation failed: %s\n",
		cairo_status_to_string (status));
	return status;
    }

    return status;
}
PassRefPtr<Evas_Object> evasObjectFromCairoImageSurface(Evas* canvas, cairo_surface_t* surface)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(surface, 0);

    cairo_status_t status = cairo_surface_status(surface);
    if (status != CAIRO_STATUS_SUCCESS) {
        EINA_LOG_ERR("cairo surface is invalid: %s", cairo_status_to_string(status));
        return 0;
    }

    cairo_surface_type_t type = cairo_surface_get_type(surface);
    if (type != CAIRO_SURFACE_TYPE_IMAGE) {
        EINA_LOG_ERR("unknown surface type %d, required %d (CAIRO_SURFACE_TYPE_IMAGE).",
            type, CAIRO_SURFACE_TYPE_IMAGE);
        return 0;
    }

    cairo_format_t format = cairo_image_surface_get_format(surface);
    if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) {
        EINA_LOG_ERR("unknown surface format %d, expected %d or %d.",
            format, CAIRO_FORMAT_ARGB32, CAIRO_FORMAT_RGB24);
        return 0;
    }

    int width = cairo_image_surface_get_width(surface);
    int height = cairo_image_surface_get_height(surface);
    int stride = cairo_image_surface_get_stride(surface);
    if (width <= 0 || height <= 0 || stride <= 0) {
        EINA_LOG_ERR("invalid image size %dx%d, stride=%d", width, height, stride);
        return 0;
    }

    void* data = cairo_image_surface_get_data(surface);
    if (!data) {
        EINA_LOG_ERR("could not get source data.");
        return 0;
    }

    RefPtr<Evas_Object> image = adoptRef(evas_object_image_filled_add(canvas));
    if (!image) {
        EINA_LOG_ERR("could not add image to canvas.");
        return 0;
    }

    evas_object_image_colorspace_set(image.get(), EVAS_COLORSPACE_ARGB8888);
    evas_object_image_size_set(image.get(), width, height);
    evas_object_image_alpha_set(image.get(), format == CAIRO_FORMAT_ARGB32);

    if (evas_object_image_stride_get(image.get()) != stride) {
        EINA_LOG_ERR("evas' stride %d diverges from cairo's %d.",
            evas_object_image_stride_get(image.get()), stride);
        return 0;
    }

    evas_object_image_data_copy_set(image.get(), data);

    return image.release();
}
Ejemplo n.º 28
0
/* Prints a message and quits with error status if a cairo status
 * value is not "success". */
static inline void
export_cairo_check_error (cairo_status_t status)
{
  if (status != CAIRO_STATUS_SUCCESS) {
    fprintf (stderr, _("ERROR: %s.\n"), cairo_status_to_string (status));
    exit (1);
  }
}
Ejemplo n.º 29
0
int main (int argc, char **argv)
{
	RsvgDimensionData dimensions;
	RsvgHandle *logo_handle;
	cairo_surface_t *surface;
	GError *error = NULL;
	cairo_t *cr;
	cairo_status_t status;
	char *input, *size, *output;
	GString *layer;
	char *layer_name;
	int h, w;

	g_type_init ();

	input = argv[1];
	size = argv[2];
	layer = g_string_new (argv[3]);
	g_string_ascii_down (layer);
	g_string_prepend_c (layer, '#');
	output = argv[4];

	if (sscanf (size, "%dx%d", &w, &h) != 2) {
		g_warning ("Couldn't parse size '%s'", size);
		return 1;
	}

	logo_handle = rsvg_handle_new_from_file (input, &error);
	if (!logo_handle) {
		g_warning ("Couldn't open '%s': %s", input, error->message);
		g_error_free (error);
		return 1;
	}

	surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, w, h);
	cr = cairo_create (surface);

	rsvg_handle_get_dimensions (logo_handle, &dimensions);
	cairo_scale (cr,
		     (double) w / dimensions.width,
		     (double) h / dimensions.height);

	layer_name = g_string_free (layer, FALSE);
	rsvg_handle_render_cairo_sub (logo_handle, cr, "#background");
//	rsvg_handle_render_cairo_sub (logo_handle, cr, "#base");
	rsvg_handle_render_cairo_sub (logo_handle, cr, layer_name);

	status = cairo_surface_write_to_png (surface, output);
	if (status != CAIRO_STATUS_SUCCESS) {
		g_warning ("Couldn't write output '%s': %s", output, cairo_status_to_string (status));
		return 1;
	}

	g_free (layer_name);
	cairo_destroy (cr);

	return 0;
}
Ejemplo n.º 30
0
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
    cairo_surface_t *surface;
    cairo_t *cr;
    cairo_status_t status;
    size_t i;
    char *filename;
    const char *path = cairo_test_mkdir (CAIRO_TEST_OUTPUT_DIR) ? CAIRO_TEST_OUTPUT_DIR : ".";

    if (! cairo_test_is_target_enabled (ctx, "pdf"))
	return CAIRO_TEST_UNTESTED;

    xasprintf (&filename, "%s/%s.pdf", path, BASENAME);

    /* The initial size passed here is the default size that will be
     * inheritable by each page. That is, any page for which this
     * initial size applies will not have its own /MediaBox entry in
     * its dictionary. */
    surface = cairo_pdf_surface_create (filename,
					INCHES_TO_POINTS(8.5),
					INCHES_TO_POINTS(11));

    cr = cairo_create (surface);

    cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
			    CAIRO_FONT_SLANT_NORMAL,
			    CAIRO_FONT_WEIGHT_NORMAL);
    cairo_set_font_size (cr, TEXT_SIZE);

    for (i = 0; i < ARRAY_LENGTH (pages); i++) {
	cairo_pdf_surface_set_size (surface,
				   pages[i].width_in_points,
				   pages[i].height_in_points);

	cairo_move_to (cr, TEXT_SIZE, TEXT_SIZE);
	cairo_show_text (cr, pages[i].page_size);
	cairo_show_text (cr, " - ");
	cairo_show_text (cr, pages[i].orientation);
	cairo_show_page (cr);
    }

    status = cairo_status (cr);

    cairo_destroy (cr);
    cairo_surface_destroy (surface);
    free (filename);

    if (status) {
	cairo_test_log (ctx, "Failed to create pdf surface for file %s: %s\n",
			filename, cairo_status_to_string (status));
	return CAIRO_TEST_FAILURE;
    }

    printf ("pdf-features: Please check %s to ensure it looks/prints correctly.\n", filename);
    return CAIRO_TEST_SUCCESS;
}