Interface PrintOperation.DrawPageCallback

All Superinterfaces:
FunctionPointer
Enclosing class:
PrintOperation
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public static interface PrintOperation.DrawPageCallback extends FunctionPointer

Functional interface declaration of the DrawPageCallback callback.

See Also:
  • Method Details

    • run

      void run(@Nullable PrintContext context, int pageNr)

      Emitted for every page that is printed.

      The signal handler must render the pageNr's page onto the cairo context obtained from context using PrintContext.getCairoContext().

      static void
      draw_page (GtkPrintOperation *operation,
                 GtkPrintContext   *context,
                 int                page_nr,
                 gpointer           user_data)
      {
        cairo_t *cr;
        PangoLayout *layout;
        double width, text_height;
        int layout_height;
        PangoFontDescription *desc;
        
        cr = gtk_print_context_get_cairo_context (context);
        width = gtk_print_context_get_width (context);
        
        cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT);
        
        cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
        cairo_fill (cr);
        
        layout = gtk_print_context_create_pango_layout (context);
        
        desc = pango_font_description_from_string ("sans 14");
        pango_layout_set_font_description (layout, desc);
        pango_font_description_free (desc);
        
        pango_layout_set_text (layout, "some text", -1);
        pango_layout_set_width (layout, width * PANGO_SCALE);
        pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
           		      
        pango_layout_get_size (layout, NULL, &layout_height);
        text_height = (double)layout_height / PANGO_SCALE;
        
        cairo_move_to (cr, width / 2,  (HEADER_HEIGHT - text_height) / 2);
        pango_cairo_show_layout (cr, layout);
        
        g_object_unref (layout);
      }
      

      Use PrintOperation.setUseFullPage(boolean) and PrintOperation.setUnit(Unit) before starting the print operation to set up the transformation of the cairo context according to your needs.

    • upcall

      default void upcall(MemorySegment sourcePrintOperation, MemorySegment context, int pageNr)
      The upcall method is called from native code. The parameters are marshaled and run(PrintContext, int) is executed.
    • toCallback

      default MemorySegment toCallback(Arena arena)
      Creates a native function pointer to the upcall(MemorySegment, MemorySegment, int) method.
      Specified by:
      toCallback in interface FunctionPointer
      Parameters:
      arena - the arena in which the function pointer is allocated
      Returns:
      the native function pointer