Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
7a123151
Commit
7a123151
authored
Jun 06, 2012
by
Moritz Lipp
Browse files
Set page orientation while printing automatically
parent
dfbd39c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
print.c
View file @
7a123151
...
...
@@ -8,6 +8,14 @@
#include <girara/utils.h>
#include <girara/statusbar.h>
static
void
cb_print_draw_page
(
GtkPrintOperation
*
print_operation
,
GtkPrintContext
*
context
,
gint
page_number
,
zathura_t
*
zathura
);
static
void
cb_print_end
(
GtkPrintOperation
*
print_operation
,
GtkPrintContext
*
context
,
zathura_t
*
zathura
);
static
void
cb_print_request_page_setup
(
GtkPrintOperation
*
print_operation
,
GtkPrintContext
*
context
,
gint
page_number
,
GtkPageSetup
*
setup
,
zathura_t
*
zathura
);
void
print
(
zathura_t
*
zathura
)
{
...
...
@@ -31,8 +39,9 @@ print(zathura_t* zathura)
gtk_print_operation_set_use_full_page
(
print_operation
,
TRUE
);
/* print operation signals */
g_signal_connect
(
print_operation
,
"draw-page"
,
G_CALLBACK
(
cb_print_draw_page
),
zathura
);
g_signal_connect
(
print_operation
,
"end-print"
,
G_CALLBACK
(
cb_print_end
),
zathura
);
g_signal_connect
(
print_operation
,
"draw-page"
,
G_CALLBACK
(
cb_print_draw_page
),
zathura
);
g_signal_connect
(
print_operation
,
"end-print"
,
G_CALLBACK
(
cb_print_end
),
zathura
);
g_signal_connect
(
print_operation
,
"request_page_setup"
,
G_CALLBACK
(
cb_print_request_page_setup
),
zathura
);
/* print */
GtkPrintOperationResult
result
=
gtk_print_operation_run
(
print_operation
,
...
...
@@ -56,7 +65,7 @@ print(zathura_t* zathura)
g_object_unref
(
print_operation
);
}
void
static
void
cb_print_end
(
GtkPrintOperation
*
UNUSED
(
print_operation
),
GtkPrintContext
*
UNUSED
(
context
),
zathura_t
*
zathura
)
{
...
...
@@ -72,7 +81,7 @@ cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
}
}
void
static
void
cb_print_draw_page
(
GtkPrintOperation
*
UNUSED
(
print_operation
),
GtkPrintContext
*
context
,
gint
page_number
,
zathura_t
*
zathura
)
{
...
...
@@ -88,8 +97,8 @@ cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
g_free
(
tmp
);
/* render page */
cairo_t
*
cairo
=
gtk_print_context_get_cairo_context
(
context
);
zathura_page_t
*
page
=
zathura_document_get_page
(
zathura
->
document
,
page_number
);
cairo_t
*
cairo
=
gtk_print_context_get_cairo_context
(
context
);
zathura_page_t
*
page
=
zathura_document_get_page
(
zathura
->
document
,
page_number
);
if
(
cairo
==
NULL
||
page
==
NULL
)
{
return
;
}
...
...
@@ -98,3 +107,23 @@ cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
zathura_page_render
(
page
,
cairo
,
true
);
render_unlock
(
zathura
->
sync
.
render_thread
);
}
static
void
cb_print_request_page_setup
(
GtkPrintOperation
*
UNUSED
(
print_operation
),
GtkPrintContext
*
UNUSED
(
context
),
gint
page_number
,
GtkPageSetup
*
setup
,
zathura_t
*
zathura
)
{
if
(
zathura
==
NULL
||
zathura
->
document
==
NULL
)
{
return
;
}
zathura_page_t
*
page
=
zathura_document_get_page
(
zathura
->
document
,
page_number
);
double
width
=
zathura_page_get_width
(
page
);
double
height
=
zathura_page_get_height
(
page
);
if
(
width
>
height
)
{
gtk_page_setup_set_orientation
(
setup
,
GTK_PAGE_ORIENTATION_LANDSCAPE
);
}
else
{
gtk_page_setup_set_orientation
(
setup
,
GTK_PAGE_ORIENTATION_PORTRAIT
);
}
}
print.h
View file @
7a123151
...
...
@@ -3,6 +3,8 @@
#ifndef PRINT_H
#define PRINT_H
#include <gtk/gtkprintoperation.h>
#include "zathura.h"
/**
...
...
@@ -12,25 +14,4 @@
*/
void
print
(
zathura_t
*
zathura
);
/**
* Callback that is executed for every page that should be printed
*
* @param print_operation Print operation object
* @param context Print context
* @param page_number Current page number
* @param zathura Zathura object
*/
void
cb_print_draw_page
(
GtkPrintOperation
*
print_operation
,
GtkPrintContext
*
context
,
gint
page_number
,
zathura_t
*
zathura
);
/**
* Emitted after all pages have been rendered
*
* @param print_operation Print operation
* @param context Print context
* @param zathura Zathura object
*/
void
cb_print_end
(
GtkPrintOperation
*
print_operation
,
GtkPrintContext
*
context
,
zathura_t
*
zathura
);
#endif // PRINT_H
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment