Beispiel #1
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);
}
Beispiel #2
0
double
lsm_dom_view_get_resolution (LsmDomView *self)
{
	g_return_val_if_fail (LSM_IS_DOM_VIEW (self), 0.0);

	return self->resolution_ppi;
}
Beispiel #3
0
void
lsm_dom_view_get_size_pixels (LsmDomView *view, unsigned int *width, unsigned int *height, unsigned int *baseline)
{
	double resolution_ppi;
	double width_pt;
	double height_pt;
	double baseline_pt;

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

	resolution_ppi = view->resolution_ppi;
	g_return_if_fail (resolution_ppi > 0.0);

	width_pt =  width  != NULL ? *width  * 72.0 / resolution_ppi : 0.0;
	height_pt = height != NULL ? *height * 72.0 / resolution_ppi : 0.0;
	baseline_pt = baseline != NULL? *baseline * 72.0 /resolution_ppi : 0.0;

	lsm_dom_view_get_size (view, &width_pt, &height_pt,&baseline_pt);

	if (width != NULL)
		*width =  (double) (0.5 + width_pt  * resolution_ppi / 72.0);
	if (height != NULL)
		*height = (double) (0.5 + height_pt * resolution_ppi / 72.0);
	if (baseline != NULL)
		*baseline = (double) (0.5 + baseline_pt * resolution_ppi / 72.0);
}
Beispiel #4
0
void
lsm_dom_view_set_viewport (LsmDomView *self, const LsmBox *viewport_pt)
{
	g_return_if_fail (LSM_IS_DOM_VIEW (self));
	g_return_if_fail (viewport_pt != NULL);

	self->viewport_pt = *viewport_pt;
}
Beispiel #5
0
LsmBox
lsm_dom_view_get_viewport (LsmDomView *self)
{
	static const LsmBox null_viewport = {0, 0, 0, 0};

	g_return_val_if_fail (LSM_IS_DOM_VIEW (self), null_viewport);

	return self->viewport_pt;
}
Beispiel #6
0
void
lsm_dom_view_set_resolution (LsmDomView *self, double ppi)
{
	g_return_if_fail (LSM_IS_DOM_VIEW (self));

	if (ppi < 0.0)
		self->resolution_ppi = LSM_DOM_VIEW_DEFAULT_RESOLUTION;
	else
		self->resolution_ppi = ppi;
}
Beispiel #7
0
void
lsm_dom_view_set_viewport_pixels (LsmDomView *self, const LsmBox *viewport)
{
	g_return_if_fail (LSM_IS_DOM_VIEW (self));
	g_return_if_fail (viewport != NULL);

	self->viewport_pt.x      = viewport->x      * 72.0 / self->resolution_ppi;
	self->viewport_pt.y      = viewport->y      * 72.0 / self->resolution_ppi;
	self->viewport_pt.width  = viewport->width  * 72.0 / self->resolution_ppi;
	self->viewport_pt.height = viewport->height * 72.0 / self->resolution_ppi;
}
Beispiel #8
0
static void
render_test (gconstpointer user_data)
{
	const char *filename = user_data;
	char *basename;
	LsmDomDocument *document;
	LsmDomView *view;
	LsmBox viewport;
	unsigned int width, height;
	cairo_t *cairo;
	cairo_surface_t *surface;

	basename = g_path_get_basename (filename);

	document = lsm_dom_document_new_from_path (filename, NULL);
	g_assert (LSM_IS_DOM_DOCUMENT (document));

	view = lsm_dom_document_create_view (document);
	g_assert (LSM_IS_DOM_VIEW (view));

	viewport.x = 0.0;
	viewport.y = 0.0;
	viewport.width = 480.0;
	viewport.height = 360.0;

	lsm_dom_view_set_resolution (view, 96);
	lsm_dom_view_set_viewport_pixels (view, &viewport);

	lsm_dom_view_get_size_pixels (LSM_DOM_VIEW (view), &width, &height, NULL);

	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
	cairo = cairo_create (surface);
	cairo_surface_destroy (surface);

	if (cairo_status (cairo) == CAIRO_STATUS_SUCCESS) {
		lsm_dom_view_render (LSM_DOM_VIEW (view), cairo, 1, 1);

		if (cairo_status (cairo) != CAIRO_STATUS_SUCCESS) {
			g_test_message ("cairo_status = %s", cairo_status_to_string (cairo_status (cairo)));
			if (!g_key_file_get_boolean (suite_options, basename, "ignore-cairo-status", NULL)) {
				g_test_message ("incorrect cairo status");
				g_test_fail ();
			}
		}
	}

	cairo_destroy (cairo);

	g_object_unref (view);
	g_object_unref (document);

	g_free (basename);
}
Beispiel #9
0
void
lsm_dom_view_set_debug (LsmDomView *view, const char *feature, gboolean enable)
{
	LsmDomViewClass *view_class;

	g_return_if_fail (LSM_IS_DOM_VIEW (view));
	g_return_if_fail (feature != NULL);


	view_class = LSM_DOM_VIEW_GET_CLASS (view);
	if (view_class->set_debug)
		view_class->set_debug (view, feature, enable);
}
Beispiel #10
0
static void
lsm_dom_view_set_cairo_context (LsmDomView *view, cairo_t *cairo)
{
	PangoContext *context;
	cairo_font_options_t *font_options;
	const cairo_font_options_t *current_font_options;
	cairo_surface_t *surface;
	cairo_surface_type_t type;

	g_return_if_fail (LSM_IS_DOM_VIEW (view));

	if (view->cairo == cairo)
		return;

	if (view->cairo != NULL) {
		cairo_destroy (view->cairo);
		g_object_unref (view->pango_layout);
	}

	if (cairo == NULL) {
		view->cairo = NULL;
		view->pango_layout = NULL;

		return;
	}

	cairo_reference (cairo);
	view->cairo = cairo;
	view->pango_layout = pango_cairo_create_layout (cairo);

	surface = cairo_get_target (cairo);

	type = cairo_surface_get_type (surface);

	view->is_vector = (type == CAIRO_SURFACE_TYPE_SVG ||
			   type == CAIRO_SURFACE_TYPE_PDF ||
			   type == CAIRO_SURFACE_TYPE_PS);

	context = pango_layout_get_context (view->pango_layout);
	pango_cairo_context_set_resolution (context, 72);

	current_font_options = pango_cairo_context_get_font_options (context);
	if (current_font_options == NULL)
		font_options = cairo_font_options_create ();
	else
		font_options = cairo_font_options_copy (current_font_options);
	cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
	pango_cairo_context_set_font_options (context, font_options);
	cairo_font_options_destroy (font_options);
}
Beispiel #11
0
LsmBox
lsm_dom_view_get_viewport_pixels (LsmDomView *self)
{
	LsmBox viewport = {0, 0, 0, 0};

	g_return_val_if_fail (LSM_IS_DOM_VIEW (self), viewport);

	viewport.x      = self->viewport_pt.x      * self->resolution_ppi / 72.0;
	viewport.y      = self->viewport_pt.y      * self->resolution_ppi / 72.0;
	viewport.width  = self->viewport_pt.width  * self->resolution_ppi / 72.0;
	viewport.height = self->viewport_pt.height * self->resolution_ppi / 72.0;

	return viewport;
}
Beispiel #12
0
void
lsm_dom_view_set_document (LsmDomView *view, LsmDomDocument *document)
{
	g_return_if_fail (LSM_IS_DOM_VIEW (view));
	g_return_if_fail (document == NULL || LSM_IS_DOM_DOCUMENT (document));

	if (view->document == document)
		return;

	if (view->document != NULL)
		g_object_unref (view->document);

	if (document != NULL)
	    g_object_ref (document);

	view->document = document;
}
Beispiel #13
0
void
lsm_dom_view_get_size (LsmDomView *view, double *width, double *height, double *baseline)
{
	LsmDomViewClass *view_class;
	double dummy_width = 0.0;
	double dummy_height = 0.0;

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

	if (width == NULL)
		width = &dummy_width;
	if (height == NULL)
		height = &dummy_height;

	view_class = LSM_DOM_VIEW_GET_CLASS (view);
	if (view_class->measure != NULL)
		view_class->measure (view, width, height, baseline);
}
Beispiel #14
0
static void
render_test (gconstpointer user_data)
{
	const char *filename = user_data;
	LsmDomDocument *document;
	LsmDomView *view;
	LsmBox viewport;
	unsigned int width, height;
	cairo_t *cairo;
	cairo_surface_t *surface;

	document = lsm_dom_document_new_from_path (filename, NULL);
	g_assert (LSM_IS_DOM_DOCUMENT (document));

	view = lsm_dom_document_create_view (document);
	g_assert (LSM_IS_DOM_VIEW (view));

	viewport.x = 0.0;
	viewport.y = 0.0;
	viewport.width = 480.0;
	viewport.height = 360.0;

	lsm_dom_view_set_resolution (view, 96);
	lsm_dom_view_set_viewport_pixels (view, &viewport);

	lsm_dom_view_get_size_pixels (LSM_DOM_VIEW (view), &width, &height, NULL);

	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
	cairo = cairo_create (surface);
	cairo_surface_destroy (surface);

	if (cairo_status (cairo) == CAIRO_STATUS_SUCCESS) {
		lsm_dom_view_render (LSM_DOM_VIEW (view), cairo, 1, 1);
		g_assert (cairo_status (cairo) == CAIRO_STATUS_SUCCESS);
	}

	cairo_destroy (cairo);

	g_object_unref (view);
	g_object_unref (document);
}