mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 05:16:01 +01:00
Merge branch 'cleanup-cairo' into 'develop'
Clean up cairo error handling See merge request pwmt/zathura!77
This commit is contained in:
commit
a1b93ff180
3 changed files with 15 additions and 25 deletions
|
@ -733,23 +733,24 @@ draw_thumbnail_image(cairo_surface_t* surface, size_t max_size)
|
||||||
const unsigned int unscaled_height = height / device.y;
|
const unsigned int unscaled_height = height / device.y;
|
||||||
|
|
||||||
/* create thumbnail surface, taking width and height as _unscaled_ device units */
|
/* create thumbnail surface, taking width and height as _unscaled_ device units */
|
||||||
cairo_surface_t *thumbnail;
|
cairo_surface_t* thumbnail;
|
||||||
thumbnail = cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR, unscaled_width, unscaled_height);
|
thumbnail = cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR, unscaled_width, unscaled_height);
|
||||||
if (thumbnail == NULL) {
|
if (cairo_surface_status(thumbnail) != CAIRO_STATUS_SUCCESS) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
cairo_t *cr = cairo_create(thumbnail);
|
|
||||||
if (cr == NULL) {
|
cairo_t* cairo = cairo_create(thumbnail);
|
||||||
|
if (cairo_status(cairo) != CAIRO_STATUS_SUCCESS) {
|
||||||
cairo_surface_destroy(thumbnail);
|
cairo_surface_destroy(thumbnail);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_scale(cr, scale, scale);
|
cairo_scale(cairo, scale, scale);
|
||||||
cairo_set_source_surface(cr, surface, 0, 0);
|
cairo_set_source_surface(cairo, surface, 0, 0);
|
||||||
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BILINEAR);
|
cairo_pattern_set_filter(cairo_get_source(cairo), CAIRO_FILTER_BILINEAR);
|
||||||
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||||
cairo_paint(cr);
|
cairo_paint(cairo);
|
||||||
cairo_destroy(cr);
|
cairo_destroy(cairo);
|
||||||
|
|
||||||
return thumbnail;
|
return thumbnail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,16 +52,12 @@ draw_page_image(cairo_t* cairo, GtkPrintContext* context, zathura_t* zathura,
|
||||||
const double page_height = zathura_page_get_height(page) * scale_height;
|
const double page_height = zathura_page_get_height(page) * scale_height;
|
||||||
const double page_width = zathura_page_get_width(page) * scale_width;
|
const double page_width = zathura_page_get_width(page) * scale_width;
|
||||||
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height);
|
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height);
|
||||||
if (surface == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
|
if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
|
||||||
cairo_surface_destroy(surface);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_t* temp_cairo = cairo_create(surface);
|
cairo_t* temp_cairo = cairo_create(surface);
|
||||||
if (cairo == NULL) {
|
if (cairo_status(temp_cairo) != CAIRO_STATUS_SUCCESS) {
|
||||||
cairo_surface_destroy(surface);
|
cairo_surface_destroy(surface);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -113,9 +109,9 @@ cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext*
|
||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
|
|
||||||
/* Get the page and cairo handle. */
|
/* Get the page and cairo handle. */
|
||||||
cairo_t* cairo = gtk_print_context_get_cairo_context(context);
|
|
||||||
zathura_page_t* page = zathura_document_get_page(zathura->document, page_number);
|
zathura_page_t* page = zathura_document_get_page(zathura->document, page_number);
|
||||||
if (cairo == NULL || page == NULL) {
|
cairo_t* cairo = gtk_print_context_get_cairo_context(context);
|
||||||
|
if (cairo_status(cairo) != CAIRO_STATUS_SUCCESS || page == NULL) {
|
||||||
gtk_print_operation_cancel(print_operation);
|
gtk_print_operation_cancel(print_operation);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -767,7 +767,7 @@ static bool
|
||||||
render_to_cairo_surface(cairo_surface_t* surface, zathura_page_t* page, ZathuraRenderer* renderer, double real_scale)
|
render_to_cairo_surface(cairo_surface_t* surface, zathura_page_t* page, ZathuraRenderer* renderer, double real_scale)
|
||||||
{
|
{
|
||||||
cairo_t* cairo = cairo_create(surface);
|
cairo_t* cairo = cairo_create(surface);
|
||||||
if (cairo == NULL) {
|
if (cairo_status(cairo) != CAIRO_STATUS_SUCCESS) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -775,7 +775,6 @@ render_to_cairo_surface(cairo_surface_t* surface, zathura_page_t* page, ZathuraR
|
||||||
cairo_set_source_rgb(cairo, 1, 1, 1);
|
cairo_set_source_rgb(cairo, 1, 1, 1);
|
||||||
cairo_paint(cairo);
|
cairo_paint(cairo);
|
||||||
cairo_restore(cairo);
|
cairo_restore(cairo);
|
||||||
cairo_save(cairo);
|
|
||||||
|
|
||||||
/* apply scale (used by e.g. Poppler as pixels per point) */
|
/* apply scale (used by e.g. Poppler as pixels per point) */
|
||||||
if (fabs(real_scale - 1.0f) > FLT_EPSILON) {
|
if (fabs(real_scale - 1.0f) > FLT_EPSILON) {
|
||||||
|
@ -785,7 +784,6 @@ render_to_cairo_surface(cairo_surface_t* surface, zathura_page_t* page, ZathuraR
|
||||||
zathura_renderer_lock(renderer);
|
zathura_renderer_lock(renderer);
|
||||||
const int err = zathura_page_render(page, cairo, false);
|
const int err = zathura_page_render(page, cairo, false);
|
||||||
zathura_renderer_unlock(renderer);
|
zathura_renderer_unlock(renderer);
|
||||||
cairo_restore(cairo);
|
|
||||||
cairo_destroy(cairo);
|
cairo_destroy(cairo);
|
||||||
|
|
||||||
return err == ZATHURA_ERROR_OK;
|
return err == ZATHURA_ERROR_OK;
|
||||||
|
@ -833,11 +831,6 @@ render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* render
|
||||||
}
|
}
|
||||||
cairo_surface_t* surface = cairo_image_surface_create(format,
|
cairo_surface_t* surface = cairo_image_surface_create(format,
|
||||||
page_width, page_height);
|
page_width, page_height);
|
||||||
|
|
||||||
if (surface == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request_priv->render_plain == false) {
|
if (request_priv->render_plain == false) {
|
||||||
cairo_surface_set_device_scale(surface, device_factors.x, device_factors.y);
|
cairo_surface_set_device_scale(surface, device_factors.x, device_factors.y);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue