Class PrintCompositor
- All Implemented Interfaces:
Proxy
Buffer
for printing.
The GtkSourcePrintCompositor
object is used to compose a Buffer
for printing. You can set various configuration options to customize the
printed output. GtkSourcePrintCompositor
is designed to be used with the
high-level printing API of gtk+, i.e. PrintOperation
.
The margins specified in this object are the layout margins: they define the
blank space bordering the printed area of the pages. They must not be
confused with the "print margins", i.e. the parts of the page that the
printer cannot print on, defined in the PageSetup
objects. If the
specified layout margins are smaller than the "print margins", the latter
ones are used as a fallback by the GtkSourcePrintCompositor
object, so that
the printed area is not clipped.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
PrintCompositor.Builder<B extends PrintCompositor.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionPrintCompositor
(MemorySegment address) Create a PrintCompositor proxy instance for the provided memory address.PrintCompositor
(Buffer buffer) Creates a new print compositor that can be used to printbuffer
. -
Method Summary
Modifier and TypeMethodDescriptionprotected PrintCompositor
asParent()
Returns this instance as if it were its parent type.static PrintCompositor.Builder
<? extends PrintCompositor.Builder> builder()
APrintCompositor.Builder
object constructs aPrintCompositor
with the specified properties.void
drawPage
(PrintContext context, int pageNr) Draw pagepageNr
for printing on the the Cairo context encapsuled incontext
.static PrintCompositor
Creates a new print compositor that can be used to print the buffer associated withview
.Returns the name of the font used to print the text body.double
getBottomMargin
(Unit unit) Gets the bottom margin in units ofunit
.Gets theBuffer
associated with the compositor.Returns the name of the font used to print the page footer.Returns the name of the font used to print the page header.boolean
Determines whether the printed text will be highlighted according to the buffer rules.double
getLeftMargin
(Unit unit) Gets the left margin in units ofunit
.Returns the name of the font used to print line numbers on the left margin.static MemoryLayout
The memory layout of the native struct.int
Returns the number of pages in the document or <code>-1</code> if the document has not been completely paginated.double
Returns the current fraction of the document pagination that has been completed.boolean
Determines if a footer is set to be printed for each page.boolean
Determines if a header is set to be printed for each page.int
Returns the interval used for line number printing.double
getRightMargin
(Unit unit) Gets the right margin in units ofunit
.int
Returns the width of tabulation in characters for printed text.double
getTopMargin
(Unit unit) Gets the top margin in units ofunit
.static Type
getType()
Get the GType of the PrintCompositor classGets the line wrapping mode for the printed text.void
Specifies a tag whose style should be ignored when compositing the document to the printable page.boolean
paginate
(PrintContext context) Paginate the document associated with the this PrintCompositor.void
setBodyFontName
(String fontName) Sets the default font for the printed text.void
setBottomMargin
(double margin, Unit unit) Sets the bottom margin used by this PrintCompositor.void
setFooterFontName
(@Nullable String fontName) Sets the font for printing the page footer.void
setFooterFormat
(boolean separator, @Nullable String left, @Nullable String center, @Nullable String right) SeesetHeaderFormat(boolean, java.lang.String, java.lang.String, java.lang.String)
for more information about the parameters.void
setHeaderFontName
(@Nullable String fontName) Sets the font for printing the page header.void
setHeaderFormat
(boolean separator, @Nullable String left, @Nullable String center, @Nullable String right) Sets strftime like header format strings, to be printed on the left, center and right of the top of each page.void
setHighlightSyntax
(boolean highlight) Sets whether the printed text will be highlighted according to the buffer rules.void
setLeftMargin
(double margin, Unit unit) Sets the left margin used by this PrintCompositor.void
setLineNumbersFontName
(@Nullable String fontName) Sets the font for printing line numbers on the left margin.void
setPrintFooter
(boolean print) Sets whether you want to print a footer in each page.void
setPrintHeader
(boolean print) Sets whether you want to print a header in each page.void
setPrintLineNumbers
(int interval) Sets the interval for printed line numbers.void
setRightMargin
(double margin, Unit unit) Sets the right margin used by this PrintCompositor.void
setTabWidth
(int width) Sets the width of tabulation in characters for printed text.void
setTopMargin
(double margin, Unit unit) Sets the top margin used by this PrintCompositor.void
setWrapMode
(WrapMode wrapMode) Sets the line wrapping mode for the printed text.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
PrintCompositor
Create a PrintCompositor proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
PrintCompositor
Creates a new print compositor that can be used to printbuffer
.- Parameters:
buffer
- theGtkSourceBuffer
to print.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
fromView
Creates a new print compositor that can be used to print the buffer associated withview
.This constructor sets some configuration properties to make the printed output match
view
as much as possible. The properties set arePrintCompositor:tab-width
,PrintCompositor:highlight-syntax
,PrintCompositor:wrap-mode
,PrintCompositor:body-font-name
andPrintCompositor:print-line-numbers
.- Parameters:
view
- aGtkSourceView
to get configuration from.- Returns:
- a new print compositor object.
-
drawPage
Draw pagepageNr
for printing on the the Cairo context encapsuled incontext
.This method has been designed to be called in the handler of the
Gtk.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
- theGtkPrintContext
encapsulating the context information that is required when drawing the page for printing.pageNr
- the number of the page to print.
-
getBodyFontName
Returns the name of the font used to print the text body.The returned string must be freed with g_free().
- Returns:
- a new string containing the name of the font used to print the text body.
-
getBottomMargin
Gets the bottom margin in units ofunit
.- Parameters:
unit
- the unit for the return value.- Returns:
- the bottom margin.
-
getBuffer
-
getHeaderFontName
Returns the name of the font used to print the page header.The returned string must be freed with g_free().
- Returns:
- a new string containing the name of the font used to print the page header.
-
getHighlightSyntax
public boolean getHighlightSyntax()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:
true
if the printed output will be highlighted.
-
getLeftMargin
Gets the left margin in units ofunit
.- Parameters:
unit
- the unit for the return value.- Returns:
- the left margin
-
getLineNumbersFontName
Returns the name of the font used to print line numbers on the left margin.The returned string must be freed with g_free().
- Returns:
- a new string containing the name of the font used to print line numbers on the left margin.
-
getNPages
public int getNPages()Returns the number of pages in the document or <code>-1</code> if the document has not been completely paginated.- Returns:
- the number of pages in the document or <code>-1</code> if the document has not been completely paginated.
-
getPaginationProgress
public double getPaginationProgress()Returns the current fraction of the document pagination that has been completed.- Returns:
- a fraction from 0.0 to 1.0 inclusive.
-
getPrintHeader
public boolean getPrintHeader()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 withsetHeaderFormat(boolean, java.lang.String, java.lang.String, java.lang.String)
.- Returns:
true
if the header is set to be printed.
-
getPrintLineNumbers
public int getPrintLineNumbers()Returns the interval used for line number printing.If the value is 0, no line numbers will be printed. The default value is 1 (i.e. numbers printed in all lines).
- Returns:
- the interval of printed line numbers.
-
getRightMargin
Gets the right margin in units ofunit
.- Parameters:
unit
- the unit for the return value.- Returns:
- the right margin.
-
getTabWidth
public int getTabWidth()Returns the width of tabulation in characters for printed text.- Returns:
- width of tab.
-
getTopMargin
Gets the top margin in units ofunit
.- Parameters:
unit
- the unit for the return value.- Returns:
- the top margin.
-
getWrapMode
Gets the line wrapping mode for the printed text.- Returns:
- the line wrap mode.
-
ignoreTag
Specifies a tag whose style should be ignored when compositing the document to the printable page.- Parameters:
tag
- aGtkTextTag
-
paginate
Paginate the document associated with the this PrintCompositor.In order to support non-blocking pagination, document is paginated in small chunks. Each time
paginate(org.gnome.gtk.PrintContext)
is invoked, a chunk of the document is paginated. To paginate the entire document,paginate(org.gnome.gtk.PrintContext)
must be invoked multiple times. It returnstrue
if the document has been completely paginated, otherwise it returnsfalse
.This method has been designed to be invoked in the handler of the
Gtk.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
Gtk.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); }
- Parameters:
context
- theGtkPrintContext
whose parameters (e.g. paper size, print margins, etc.) are used by the the this PrintCompositor to paginate the document.- Returns:
true
if the document has been completely paginated,false
otherwise.
-
setBodyFontName
Sets the default font for the printed text.fontName
should be a string representation of a font description Pango can understand. (e.g. "Monospace 10"). SeeFontDescription.fromString(java.lang.String)
for a description of the format of the string representation.This function cannot be called anymore after the first call to the
paginate(org.gnome.gtk.PrintContext)
function.- Parameters:
fontName
- the name of the default font for the body text.
-
setBottomMargin
Sets the bottom margin used by this PrintCompositor.- Parameters:
margin
- the new bottom margin in units ofunit
.unit
- the units formargin
.
-
setHeaderFontName
Sets the font for printing the page header.If
null
is supplied, the default font (i.e. the one being used for the text) will be used instead.fontName
should be a string representation of a font description Pango can understand. (e.g. "Monospace 10"). SeeFontDescription.fromString(java.lang.String)
for a description of the format of the string representation.This function cannot be called anymore after the first call to the
paginate(org.gnome.gtk.PrintContext)
function.- Parameters:
fontName
- the name of the font for header text, ornull
.
-
setHeaderFormat
public void setHeaderFormat(boolean separator, @Nullable @Nullable String left, @Nullable @Nullable String center, @Nullable @Nullable String right) 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
DateTime.format(java.lang.String)
for more details on the accepted format specifiers. Additionally the following format specifiers are accepted:N
: the page numberQ
: the page count.
separator
specifies if a solid line should be drawn to separate the header from the document text.If
null
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
setPrintHeader(boolean)
.This function cannot be called anymore after the first call to the
paginate(org.gnome.gtk.PrintContext)
function.- Parameters:
separator
-true
if you want a separator line to be printed.left
- a format string to print on the left of the header.center
- a format string to print on the center of the header.right
- a format string to print on the right of the header.
-
setHighlightSyntax
public void setHighlightSyntax(boolean highlight) Sets whether the printed text will be highlighted according to the buffer rules. Both color and font style are applied.This function cannot be called anymore after the first call to the
paginate(org.gnome.gtk.PrintContext)
function.- Parameters:
highlight
- whether syntax should be highlighted.
-
setLeftMargin
Sets the left margin used by this PrintCompositor.- Parameters:
margin
- the new left margin in units ofunit
.unit
- the units formargin
.
-
setLineNumbersFontName
Sets the font for printing line numbers on the left margin.If
null
is supplied, the default font (i.e. the one being used for the text) will be used instead.fontName
should be a string representation of a font description Pango can understand. (e.g. "Monospace 10"). SeeFontDescription.fromString(java.lang.String)
for a description of the format of the string representation.This function cannot be called anymore after the first call to the
paginate(org.gnome.gtk.PrintContext)
function.- Parameters:
fontName
- the name of the font for line numbers, ornull
.
-
setPrintHeader
public void setPrintHeader(boolean print) Sets whether you want to print a header in each page.The header consists of three pieces of text and an optional line separator, configurable with
setHeaderFormat(boolean, java.lang.String, java.lang.String, java.lang.String)
.Note that by default the header format is unspecified, and if it's empty it will not be printed, regardless of this setting.
This function cannot be called anymore after the first call to the
paginate(org.gnome.gtk.PrintContext)
function.- Parameters:
print
-true
if you want the header to be printed.
-
setPrintLineNumbers
public void setPrintLineNumbers(int interval) Sets the interval for printed line numbers.If
interval
is 0 no numbers will be printed. If greater than 0, a number will be printed everyinterval
lines (i.e. 1 will print all line numbers).Maximum accepted value for
interval
is 100.This function cannot be called anymore after the first call to the
paginate(org.gnome.gtk.PrintContext)
function.- Parameters:
interval
- interval for printed line numbers.
-
setRightMargin
Sets the right margin used by this PrintCompositor.- Parameters:
margin
- the new right margin in units ofunit
.unit
- the units formargin
.
-
setTabWidth
public void setTabWidth(int width) Sets the width of tabulation in characters for printed text.This function cannot be called anymore after the first call to the
paginate(org.gnome.gtk.PrintContext)
function.- Parameters:
width
- width of tab in characters.
-
setTopMargin
Sets the top margin used by this PrintCompositor.- Parameters:
margin
- the new top margin in units ofunit
unit
- the units formargin
-
setWrapMode
Sets the line wrapping mode for the printed text.This function cannot be called anymore after the first call to the
paginate(org.gnome.gtk.PrintContext)
function.- Parameters:
wrapMode
- aGtkWrapMode
.
-
builder
APrintCompositor.Builder
object constructs aPrintCompositor
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withPrintCompositor.Builder.build()
.
-