Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into master_github
Browse files Browse the repository at this point in the history
  • Loading branch information
tsdgeos committed Jan 20, 2025

Verified

This commit was signed with the committer’s verified signature.
ppkarwasz Piotr P. Karwasz
2 parents 22db77d + 7a69738 commit 58a168b
Showing 51 changed files with 368 additions and 588 deletions.
10 changes: 5 additions & 5 deletions glib/demo/print.c
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ static void pgd_print_draw_page(GtkPrintOperation *op, GtkPrintContext *context,
GtkPrintSettings *settings;
#endif
PgdPrintOptions options;
PopplerPrintFlags flags = 0;
PopplerRenderAnnotsFlags flags = 0;

page = poppler_document_get_page(demo->doc, page_nr);
if (!page) {
@@ -82,20 +82,20 @@ static void pgd_print_draw_page(GtkPrintOperation *op, GtkPrintContext *context,
#endif
switch (options) {
case PRINT_DOCUMENT:
flags |= POPPLER_PRINT_DOCUMENT;
flags = POPPLER_RENDER_ANNOTS_PRINT_DOCUMENT;
break;
case PRINT_DOCUMENT_MARKUPS:
flags |= POPPLER_PRINT_MARKUP_ANNOTS;
flags = POPPLER_RENDER_ANNOTS_PRINT_MARKUP;
break;
case PRINT_DOCUMENT_STAMPS:
flags |= POPPLER_PRINT_STAMP_ANNOTS_ONLY;
flags = POPPLER_RENDER_ANNOTS_PRINT_STAMP;
break;
default:
g_assert_not_reached();
}

cr = gtk_print_context_get_cairo_context(context);
poppler_page_render_for_printing_with_options(page, cr, flags);
poppler_page_render_full(page, cr, TRUE, flags);
g_object_unref(page);
}

25 changes: 19 additions & 6 deletions glib/demo/render.c
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ typedef struct
gint rotate;
GdkRectangle slice;
gboolean printing;
gboolean highlight;

GtkWidget *swindow;
GtkWidget *darea;
@@ -139,8 +140,10 @@ static void pgd_render_start(GtkButton *button, PgdRenderDemo *demo)

if (demo->printing) {
poppler_page_render_for_printing(page, cr);
} else {
} else if (demo->highlight) {
poppler_page_render(page, cr);
} else {
poppler_page_render_full(page, cr, FALSE, POPPLER_RENDER_ANNOTS_ALL & (~POPPLER_RENDER_ANNOTS_HIGHLIGHT));
}
cairo_restore(cr);

@@ -209,6 +212,11 @@ static void pgd_render_printing_selector_changed(GtkToggleButton *tooglebutton,
demo->printing = gtk_toggle_button_get_active(tooglebutton);
}

static void pgd_render_highlight_selector_changed(GtkToggleButton *tooglebutton, PgdRenderDemo *demo)
{
demo->highlight = gtk_toggle_button_get_active(tooglebutton);
}

static void pgd_render_slice_selector_value_changed(GtkSpinButton *spinbutton, PgdRenderDemo *demo)
{
demo->slice.x = (gint)gtk_spin_button_get_value(GTK_SPIN_BUTTON(demo->slice_x));
@@ -224,7 +232,7 @@ GtkWidget *pgd_render_properties_selector_create(PgdRenderDemo *demo)
GtkWidget *page_hbox, *page_selector;
GtkWidget *scale_hbox, *scale_selector;
GtkWidget *rotate_hbox, *rotate_selector;
GtkWidget *printing_selector;
GtkWidget *selector;
GtkWidget *slice_hbox;
GtkWidget *button;
gint n_pages;
@@ -292,10 +300,15 @@ GtkWidget *pgd_render_properties_selector_create(PgdRenderDemo *demo)
gtk_box_pack_start(GTK_BOX(hbox), rotate_hbox, FALSE, TRUE, 0);
gtk_widget_show(rotate_hbox);

printing_selector = gtk_check_button_new_with_label("Printing");
g_signal_connect(printing_selector, "toggled", G_CALLBACK(pgd_render_printing_selector_changed), (gpointer)demo);
gtk_box_pack_start(GTK_BOX(hbox), printing_selector, FALSE, TRUE, 0);
gtk_widget_show(printing_selector);
selector = gtk_check_button_new_with_label("Printing");
g_signal_connect(selector, "toggled", G_CALLBACK(pgd_render_printing_selector_changed), (gpointer)demo);
gtk_box_pack_start(GTK_BOX(hbox), selector, FALSE, TRUE, 0);
gtk_widget_show(selector);

selector = gtk_check_button_new_with_label("Render highlight annots");
g_signal_connect(selector, "toggled", G_CALLBACK(pgd_render_highlight_selector_changed), (gpointer)demo);
gtk_box_pack_start(GTK_BOX(hbox), selector, FALSE, TRUE, 0);
gtk_widget_show(selector);

hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
8 changes: 6 additions & 2 deletions glib/poppler-annot.cc
Original file line number Diff line number Diff line change
@@ -2037,13 +2037,17 @@ void poppler_annot_free_text_set_font_desc(PopplerAnnotFreeText *poppler_annot,
*
* Gets the font description (i.e. font family name, style, weight, stretch and size).
*
* Returns: (transfer full): a copy of the annotation font description
* Returns: (nullable) (transfer full): a copy of the annotation font description, or NULL if there is
* no font description set.
*
* Since: 24.12.0
**/
PopplerFontDescription *poppler_annot_free_text_get_font_desc(PopplerAnnotFreeText *poppler_annot)
{
return poppler_font_description_copy(poppler_annot->font_desc);
if (poppler_annot->font_desc) {
return poppler_font_description_copy(poppler_annot->font_desc);
}
return nullptr;
}

/**
4 changes: 1 addition & 3 deletions glib/poppler-form-field.cc
Original file line number Diff line number Diff line change
@@ -362,11 +362,9 @@ gchar *poppler_form_field_get_mapping_name(PopplerFormField *field)
**/
gchar *poppler_form_field_get_name(PopplerFormField *field)
{
GooString *tmp;

g_return_val_if_fail(POPPLER_IS_FORM_FIELD(field), NULL);

tmp = field->widget->getFullyQualifiedName();
const GooString *tmp = field->widget->getFullyQualifiedName();

return tmp ? _poppler_goo_string_to_utf8(tmp) : nullptr;
}
87 changes: 46 additions & 41 deletions glib/poppler-page.cc
Original file line number Diff line number Diff line change
@@ -271,45 +271,41 @@ static TextPage *poppler_page_get_text_page(PopplerPage *page)
return page->text;
}

static gboolean annot_is_markup(Annot *annot)
{
switch (annot->getType()) {
case Annot::typeLink:
case Annot::typePopup:
case Annot::typeMovie:
case Annot::typeScreen:
case Annot::typePrinterMark:
case Annot::typeTrapNet:
case Annot::typeWatermark:
case Annot::type3D:
case Annot::typeWidget:
return FALSE;
default:
return TRUE;
}
}

static bool poppler_print_annot_cb(Annot *annot, void *user_data)
static bool annots_display_decide_cb(Annot *annot, void *user_data)
{
PopplerPrintFlags user_print_flags = (PopplerPrintFlags)GPOINTER_TO_INT(user_data);

if (user_print_flags & POPPLER_PRINT_STAMP_ANNOTS_ONLY && (annot->getType() == Annot::typeStamp)) {
return true;
}
PopplerRenderAnnotsFlags flags = (PopplerRenderAnnotsFlags)GPOINTER_TO_UINT(user_data);
Annot::AnnotSubtype type = annot->getType();
int typeMask = 1 << MAX(0, (((int)type) - 1));

if (user_print_flags & POPPLER_PRINT_MARKUP_ANNOTS && annot_is_markup(annot)) {
if (flags & typeMask) {
return true;
}

/* Form fields are always printed */
return (annot->getType() == Annot::typeWidget);
return false;
}

static void _poppler_page_render(PopplerPage *page, cairo_t *cairo, bool printing, PopplerPrintFlags print_flags)
/**
* poppler_page_render_full:
* @page: the page to render from
* @cairo: cairo context to render to
* @printing: cairo context to render to
* @flags: flags which allow to select which annotations to render
*
* Render the page to the given cairo context, manually selecting which
* annotations should be displayed.
*
* The @printing parameter determines whether a page is rendered for printing
* or for displaying it on a screen. See the documentation for
* poppler_page_render_for_printing() for the differences between rendering to
* the screen and rendering to a printer.
*
* Since: 25.02
**/
void poppler_page_render_full(PopplerPage *page, cairo_t *cairo, gboolean printing, PopplerRenderAnnotsFlags flags)
{
CairoOutputDev *output_dev;

g_return_if_fail(POPPLER_IS_PAGE(page));
g_return_if_fail(cairo != nullptr);

output_dev = page->document->output_dev;
output_dev->setCairo(cairo);
@@ -319,12 +315,13 @@ static void _poppler_page_render(PopplerPage *page, cairo_t *cairo, bool printin
page->text = new TextPage(false);
output_dev->setTextPage(page->text);
}
/* NOTE: instead of passing -1 we should/could use cairo_clip_extents()
* to get a bounding box */

cairo_save(cairo);
page->page->displaySlice(output_dev, 72.0, 72.0, 0, false, /* useMediaBox */
true, /* Crop */
-1, -1, -1, -1, printing, nullptr, nullptr, printing ? poppler_print_annot_cb : nullptr, printing ? GINT_TO_POINTER((gint)print_flags) : nullptr);
-1, -1, -1, -1, /* instead of passing -1 we could use cairo_clip_extents() to get a bounding box */

printing, nullptr, nullptr, annots_display_decide_cb, GUINT_TO_POINTER((guint)flags));
cairo_restore(cairo);

output_dev->setCairo(nullptr);
@@ -345,9 +342,7 @@ static void _poppler_page_render(PopplerPage *page, cairo_t *cairo, bool printin
**/
void poppler_page_render(PopplerPage *page, cairo_t *cairo)
{
g_return_if_fail(POPPLER_IS_PAGE(page));

_poppler_page_render(page, cairo, false, (PopplerPrintFlags)0);
poppler_page_render_full(page, cairo, false, POPPLER_RENDER_ANNOTS_ALL);
}

/**
@@ -363,13 +358,24 @@ void poppler_page_render(PopplerPage *page, cairo_t *cairo)
* differences between rendering to the screen and rendering to a printer.
*
* Since: 0.16
*
* Deprecated: 25.02: Use poppler_page_render_full() instead.
**/
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
void poppler_page_render_for_printing_with_options(PopplerPage *page, cairo_t *cairo, PopplerPrintFlags options)
{
g_return_if_fail(POPPLER_IS_PAGE(page));
int flags = (int)POPPLER_RENDER_ANNOTS_PRINT_DOCUMENT;

if (options & POPPLER_PRINT_STAMP_ANNOTS_ONLY) {
flags |= POPPLER_RENDER_ANNOTS_PRINT_STAMP;
}
if (options & POPPLER_PRINT_MARKUP_ANNOTS) {
flags |= POPPLER_RENDER_ANNOTS_PRINT_MARKUP;
}

_poppler_page_render(page, cairo, true, options);
poppler_page_render_full(page, cairo, true, (PopplerRenderAnnotsFlags)flags);
}
G_GNUC_END_IGNORE_DEPRECATIONS

/**
* poppler_page_render_for_printing:
@@ -378,7 +384,8 @@ void poppler_page_render_for_printing_with_options(PopplerPage *page, cairo_t *c
*
* Render the page to the given cairo context for printing with
* #POPPLER_PRINT_ALL flags selected. If you want a different set of flags,
* use poppler_page_render_for_printing_with_options().
* use poppler_page_render_full() with printing #TRUE and the corresponding
* flags.
*
* The difference between poppler_page_render() and this function is that some
* things get rendered differently between screens and printers:
@@ -409,9 +416,7 @@ void poppler_page_render_for_printing_with_options(PopplerPage *page, cairo_t *c
**/
void poppler_page_render_for_printing(PopplerPage *page, cairo_t *cairo)
{
g_return_if_fail(POPPLER_IS_PAGE(page));

_poppler_page_render(page, cairo, true, POPPLER_PRINT_ALL);
poppler_page_render_full(page, cairo, true, POPPLER_RENDER_ANNOTS_PRINT_ALL);
}

static cairo_surface_t *create_surface_from_thumbnail_data(guchar *data, gint width, gint height, gint rowstride)
6 changes: 5 additions & 1 deletion glib/poppler-page.h
Original file line number Diff line number Diff line change
@@ -37,9 +37,13 @@ GType poppler_page_get_type(void) G_GNUC_CONST;
POPPLER_PUBLIC
void poppler_page_render(PopplerPage *page, cairo_t *cairo);
POPPLER_PUBLIC
void poppler_page_render_full(PopplerPage *page, cairo_t *cairo, gboolean printing, PopplerRenderAnnotsFlags flags);
POPPLER_PUBLIC
void poppler_page_render_for_printing(PopplerPage *page, cairo_t *cairo);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
POPPLER_PUBLIC
void poppler_page_render_for_printing_with_options(PopplerPage *page, cairo_t *cairo, PopplerPrintFlags options);
void poppler_page_render_for_printing_with_options(PopplerPage *page, cairo_t *cairo, PopplerPrintFlags options) G_GNUC_DEPRECATED_FOR(poppler_page_render_full);
G_GNUC_END_IGNORE_DEPRECATIONS
POPPLER_PUBLIC
cairo_surface_t *poppler_page_get_thumbnail(PopplerPage *page);
POPPLER_PUBLIC
Loading

0 comments on commit 58a168b

Please sign in to comment.