Class: GtkSource::PrintCompositor

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ GtkSource::PrintCompositor

Creates a new print compositor that can be used to print the buffer associated with view.

This constructor sets some configuration properties to make the printed output match view as much as possible. The properties set are [propertyPrintCompositor:tab-width], [propertyPrintCompositor:highlight-syntax], [propertyPrintCompositor:wrap-mode], [propertyPrintCompositor:body-font-name] and [propertyPrintCompositor:print-line-numbers].

Parameters:

Instance Method Details

#body_font_nameString

Name of the font used for the text body.

Accepted values are strings representing a font description Pango can understand. (e.g. "Monospace 10"). See [funcPango.FontDescription.from_string] for a description of the format of the string representation.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

  • (String)

    body-font-name

#body_font_name=(body_font_name) ⇒ String

Name of the font used for the text body.

Accepted values are strings representing a font description Pango can understand. (e.g. "Monospace 10"). See [funcPango.FontDescription.from_string] for a description of the format of the string representation.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • body_font_name (String)

Returns:

  • (String)

    body-font-name

  • (String)

    body-font-name

#bufferGtkSource::Buffer

The [classBuffer] object to print.

Returns:

#buffer=(buffer) ⇒ GtkSource::Buffer

The [classBuffer] object to print.

Parameters:

Returns:

#draw_page(context, page_nr) ⇒ nil

Draw page page_nr for printing on the the Cairo context encapsuled in context.

This method has been designed to be called in the handler of the [signalGtk.PrintOperation::draw_page] signal as shown in the following example:

// Signal handler for the GtkPrintOperation::draw_page signal

static void
draw_page (GtkPrintOperation *operation,
           GtkPrintContext   *context,
           gint               page_nr,
           gpointer           user_data)
{
    GtkSourcePrintCompositor *compositor;

    compositor = GTK_SOURCE_PRINT_COMPOSITOR (user_data);

    gtk_source_print_compositor_draw_page (compositor,
                                           context,
                                           page_nr);
}

Parameters:

  • context (Gtk::PrintContext)

    the Gtk::PrintContext encapsulating the context information that is required when drawing the page for printing.

  • page_nr (Integer)

    the number of the page to print.

Returns:

  • (nil)

Name of the font used to print page footer. If this property is unspecified, the text body font is used.

Accepted values are strings representing a font description Pango can understand. (e.g. "Monospace 10"). See [funcPango.FontDescription.from_string] for a description of the format of the string representation.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

  • (String)

    footer-font-name

Name of the font used to print page footer. If this property is unspecified, the text body font is used.

Accepted values are strings representing a font description Pango can understand. (e.g. "Monospace 10"). See [funcPango.FontDescription.from_string] for a description of the format of the string representation.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • footer_font_name (String)

Returns:

  • (String)

    footer-font-name

  • (String)

    footer-font-name

#get_bottom_margin(unit) ⇒ Float

Gets the bottom margin in units of unit.

Parameters:

  • unit (Gtk::Unit)

    the unit for the return value.

Returns:

  • (Float)

    the bottom margin.

#get_left_margin(unit) ⇒ Float

Gets the left margin in units of unit.

Parameters:

  • unit (Gtk::Unit)

    the unit for the return value.

Returns:

  • (Float)

    the left margin

#get_right_margin(unit) ⇒ Float

Gets the right margin in units of unit.

Parameters:

  • unit (Gtk::Unit)

    the unit for the return value.

Returns:

  • (Float)

    the right margin.

#get_top_margin(unit) ⇒ Float

Gets the top margin in units of unit.

Parameters:

  • unit (Gtk::Unit)

    the unit for the return value.

Returns:

  • (Float)

    the top margin.

#header_font_nameString

Name of the font used to print page header. If this property is unspecified, the text body font is used.

Accepted values are strings representing a font description Pango can understand. (e.g. "Monospace 10"). See [funcPango.FontDescription.from_string] for a description of the format of the string representation.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

  • (String)

    header-font-name

#header_font_name=(header_font_name) ⇒ String

Name of the font used to print page header. If this property is unspecified, the text body font is used.

Accepted values are strings representing a font description Pango can understand. (e.g. "Monospace 10"). See [funcPango.FontDescription.from_string] for a description of the format of the string representation.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • header_font_name (String)

Returns:

  • (String)

    header-font-name

  • (String)

    header-font-name

#highlight_syntaxBoolean

Determines whether the printed text will be highlighted according to the buffer rules.

Note that highlighting will happen only if the buffer to print has highlighting activated.

Returns:

  • (Boolean)

    true if the printed output will be highlighted.

#highlight_syntax=(highlight_syntax) ⇒ Boolean

Whether to print the document with highlighted syntax.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • highlight_syntax (Boolean)

Returns:

  • (Boolean)

    highlight-syntax

  • (Boolean)

    highlight-syntax

#highlight_syntax?Boolean

Whether to print the document with highlighted syntax.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

  • (Boolean)

    highlight-syntax

#ignore_tag(tag) ⇒ nil

Specifies a tag whose style should be ignored when compositing the document to the printable page.

Parameters:

Returns:

  • (nil)

#line_numbers_font_nameString

Name of the font used to print line numbers on the left margin. If this property is unspecified, the text body font is used.

Accepted values are strings representing a font description Pango can understand. (e.g. "Monospace 10"). See [funcPango.FontDescription.from_string] for a description of the format of the string representation.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

  • (String)

    line-numbers-font-name

#line_numbers_font_name=(line_numbers_font_name) ⇒ String

Name of the font used to print line numbers on the left margin. If this property is unspecified, the text body font is used.

Accepted values are strings representing a font description Pango can understand. (e.g. "Monospace 10"). See [funcPango.FontDescription.from_string] for a description of the format of the string representation.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • line_numbers_font_name (String)

Returns:

  • (String)

    line-numbers-font-name

  • (String)

    line-numbers-font-name

#n_pagesInteger

The number of pages in the document or -1 if the document has not been completely paginated.

Returns:

  • (Integer)

    n-pages

#n_pages=(n_pages) ⇒ Integer

The number of pages in the document or -1 if the document has not been completely paginated.

Parameters:

  • n_pages (Integer)

Returns:

  • (Integer)

    n-pages

  • (Integer)

    n-pages

#paginate(context) ⇒ Boolean

Paginate the document associated with the compositor.

In order to support non-blocking pagination, document is paginated in small chunks. Each time [methodPrintCompositor.paginate] is invoked, a chunk of the document is paginated. To paginate the entire document, [methodPrintCompositor.paginate] must be invoked multiple times. It returns true if the document has been completely paginated, otherwise it returns false.

This method has been designed to be invoked in the handler of the [signalGtk.PrintOperation::paginate] signal, as shown in the following example:

// Signal handler for the GtkPrintOperation::paginate signal

static gboolean
paginate (GtkPrintOperation *operation,
          GtkPrintContext   *context,
          gpointer           user_data)
{
    GtkSourcePrintCompositor *compositor;

    compositor = GTK_SOURCE_PRINT_COMPOSITOR (user_data);

    if (gtk_source_print_compositor_paginate (compositor, context))
    {
        gint n_pages;

        n_pages = gtk_source_print_compositor_get_n_pages (compositor);
        gtk_print_operation_set_n_pages (operation, n_pages);

        return TRUE;
    }

    return FALSE;
}

If you don't need to do pagination in chunks, you can simply do it all in the [signalGtk.PrintOperation::begin-print] handler, and set the number of pages from there, like in the following example:

// Signal handler for the GtkPrintOperation::begin-print signal

static void
begin_print (GtkPrintOperation *operation,
             GtkPrintContext   *context,
             gpointer           user_data)
{
    GtkSourcePrintCompositor *compositor;
    gint n_pages;

    compositor = GTK_SOURCE_PRINT_COMPOSITOR (user_data);

    while (!gtk_source_print_compositor_paginate (compositor, context));

    n_pages = gtk_source_print_compositor_get_n_pages (compositor);
    gtk_print_operation_set_n_pages (operation, n_pages);
}

are used by the the compositor to paginate the document.

Parameters:

  • context (Gtk::PrintContext)

    the Gtk::PrintContext whose parameters (e.g. paper size, print margins, etc.)

Returns:

  • (Boolean)

    true if the document has been completely paginated, false otherwise.

#pagination_progressFloat

Returns the current fraction of the document pagination that has been completed.

Returns:

  • (Float)

    a fraction from 0.0 to 1.0 inclusive.

Determines if a footer is set to be printed for each page.

A footer will be printed if this function returns true and some format strings have been specified with [methodPrintCompositor.set_footer_format].

Returns:

  • (Boolean)

    true if the footer is set to be printed.

Whether to print a footer in each page.

Note that by default the footer format is unspecified, and if it is unspecified the footer will not be printed, regardless of the value of this property.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • print_footer (Boolean)

Returns:

  • (Boolean)

    print-footer

  • (Boolean)

    print-footer

Whether to print a footer in each page.

Note that by default the footer format is unspecified, and if it is unspecified the footer will not be printed, regardless of the value of this property.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

  • (Boolean)

    print-footer

Determines if a header is set to be printed for each page.

A header will be printed if this function returns true and some format strings have been specified with [methodPrintCompositor.set_header_format].

Returns:

  • (Boolean)

    true if the header is set to be printed.

Whether to print a header in each page.

Note that by default the header format is unspecified, and if it is unspecified the header will not be printed, regardless of the value of this property.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • print_header (Boolean)

Returns:

  • (Boolean)

    print-header

  • (Boolean)

    print-header

Whether to print a header in each page.

Note that by default the header format is unspecified, and if it is unspecified the header will not be printed, regardless of the value of this property.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

  • (Boolean)

    print-header

Interval of printed line numbers.

If this property is set to 0 no numbers will be printed. If greater than 0, a number will be printed every "print-line-numbers" lines (i.e. 1 will print all line numbers).

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

  • (Integer)

    print-line-numbers

Interval of printed line numbers.

If this property is set to 0 no numbers will be printed. If greater than 0, a number will be printed every "print-line-numbers" lines (i.e. 1 will print all line numbers).

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • print_line_numbers (Integer)

Returns:

  • (Integer)

    print-line-numbers

  • (Integer)

    print-line-numbers

#set_bottom_margin(margin, unit) ⇒ nil

Sets the bottom margin used by compositor.

Parameters:

  • margin (Float)

    the new bottom margin in units of unit.

  • unit (Gtk::Unit)

    the units for margin.

Returns:

  • (nil)

See [methodPrintCompositor.set_header_format] for more information about the parameters.

Parameters:

  • separator (Boolean)

    true if you want a separator line to be printed.

  • left (String)

    a format string to print on the left of the footer.

  • center (String)

    a format string to print on the center of the footer.

  • right (String)

    a format string to print on the right of the footer.

Returns:

  • (nil)

#set_header_format(separator, left, center, right) ⇒ nil

Sets strftime like header format strings, to be printed on the left, center and right of the top of each page.

The strings may include strftime(3) codes which will be expanded at print time. A subset of strftime() codes are accepted, see [methodGLib.DateTime.format] for more details on the accepted format specifiers. Additionally the following format specifiers are accepted:

  • #N: the page number
  • #Q: the page count.

separator specifies if a solid line should be drawn to separate the header from the document text.

If nil is given for any of the three arguments, that particular string will not be printed.

For the header to be printed, in addition to specifying format strings, you need to enable header printing with [methodPrintCompositor.set_print_header].

This function cannot be called anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • separator (Boolean)

    true if you want a separator line to be printed.

  • left (String)

    a format string to print on the left of the header.

  • center (String)

    a format string to print on the center of the header.

  • right (String)

    a format string to print on the right of the header.

Returns:

  • (nil)

#set_left_margin(margin, unit) ⇒ nil

Sets the left margin used by compositor.

Parameters:

  • margin (Float)

    the new left margin in units of unit.

  • unit (Gtk::Unit)

    the units for margin.

Returns:

  • (nil)

#set_right_margin(margin, unit) ⇒ nil

Sets the right margin used by compositor.

Parameters:

  • margin (Float)

    the new right margin in units of unit.

  • unit (Gtk::Unit)

    the units for margin.

Returns:

  • (nil)

#set_top_margin(margin, unit) ⇒ nil

Sets the top margin used by compositor.

Parameters:

  • margin (Float)

    the new top margin in units of unit

  • unit (Gtk::Unit)

    the units for margin

Returns:

  • (nil)

#tab_widthInteger

Width of a tab character expressed in spaces.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

  • (Integer)

    tab-width

#tab_width=(tab_width) ⇒ Integer

Width of a tab character expressed in spaces.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

  • tab_width (Integer)

Returns:

  • (Integer)

    tab-width

  • (Integer)

    tab-width

#wrap_modeGtk::WrapMode

Whether to wrap lines never, at word boundaries, or at character boundaries.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Returns:

#wrap_mode=(wrap_mode) ⇒ Gtk::WrapMode

Whether to wrap lines never, at word boundaries, or at character boundaries.

The value of this property cannot be changed anymore after the first call to the [methodPrintCompositor.paginate] function.

Parameters:

Returns: