GLG Toolkit, C / C++ API Library  Version 4.6
Printing and Image Generation

This group contains functions used for printing, generating PostScript output and saving images. More...

Detailed Description

This group contains functions used for printing, generating PostScript output and saving images.

Functions

GlgBoolean GlgExportPostScript (GlgObject object, char *file, double x, double y, double width, double height, GlgBoolean portrait, GlgBoolean stretch, GlgBoolean center)
 Generates a PostScript output of the current state of the viewport's graphics. More...
 
PlatformDependent GlgGenerateImage (GlgObject object, char *resource_name, PlatformDependent image)
 Creates and returns an image of the current state of the viewport's graphics. More...
 
PlatformDependent GlgGenerateImageCustom (GlgObject object, char *resource_name, PlatformDependent image, GlgLong x, GlgLong y, GlgLong width, GlgLong height, GlgLong gap)
 Creates an image of the specified rectangular region of the viewport's graphics. More...
 
GlgBoolean GlgNativePrint (GlgObject object, PlatformDependent print_context, double x, double y, double width, double height, GlgBoolean stretch, GlgBoolean center)
 GTK and Windows only: Generates printing output of the current state of the viewport's graphics. More...
 
GlgBoolean GlgSaveImage (GlgObject object, char *resource_name, char *filename, GlgImageFormat format)
 Generates a JPEG or PNG image of the current state of the viewport's graphics and saves it to a file. More...
 
GlgBoolean GlgSaveImageCustom (GlgObject object, char *resource_name, char *filename, GlgImageFormat format, GlgLong x, GlgLong y, GlgLong width, GlgLong height, GlgLong gap)
 Generates a JPEG or PNG image of the specified rectangular region of the viewport's graphics and saves it to a file. More...
 

Function Documentation

◆ GlgExportPostScript()

GlgBoolean GlgExportPostScript ( GlgObject  object,
char *  file,
double  x,
double  y,
double  width,
double  height,
GlgBoolean  portrait,
GlgBoolean  stretch,
GlgBoolean  center 
)

Generates a PostScript output of the current state of the viewport's graphics.

Parameters
objectSpecifies a viewport. If object is a light viewport, the output will be generated for its parent viewport.
fileSpecifies a filename in which to save the generated PostScript output.
xDefines the X coordinate of the upper left corner of the rectangle on the page containing the PostScript output. All coordinates are specified in the world coordinate system, which maps a rectangle defined by the points (0;0) and (2000;2000) to a page.
yDefines the Y coordinate of the upper left corner of the rectangle.
widthDefines the width of the rectangle.
heightDefines the height of the rectangle.
portraitSpecifies the orientation of the PostScript output on the page. If True, a portrait orientation is used, otherwise a landscape orientation is used.
stretchSpecifies whether or not PostScript output should be stretched when mapping it to the specified rectangle:
  • If True, the PostScript output will be stretched to fit the rectangle exactly. This may distort printed objects.
  • If False, the ratio of height to width of the widget will be preserved in the PostScript output. This may leave some parts of the specified rectangle blank.
centerSpecifies whether or not PostScript output should be centered inside the specified output rectangle when stretch=False results in unused space on the sides of the rectangle. If True, the output will be centered inside the output area, otherwise it will be anchored in the upper left corner of the rectangle.
Returns
True if PostScript output was successfully written to the file, otherwise False.

The drawing's hierarchy must be set up in order to generate PostScript output. Use GlgUpdate before calling GlgExportPostScript to make sure the drawing is up to date.

◆ GlgGenerateImage()

PlatformDependent GlgGenerateImage ( GlgObject  object,
char *  resource_name,
PlatformDependent  image 
)

Creates and returns an image of the current state of the viewport's graphics.

Parameters
objectSpecifies a viewport object or a viewport's parent.
resource_nameSpecifies the resource path of a child viewport whose image to generate, or NULL to generate the image of the viewport specified by the object parameter. The resource path is relative to the object specified by the object parameter.
imageIf not NULL, specifies a platform-dependent image to be used. This image will be filled and returned instead of creating and returning a new image. The type of the image is platform-dependent:
  • cairo_surface_t* in GTK
  • Pixmap on X11
  • HBITMAP on Windows.
Returns
The generated image or NULL if image generation failed. The type of the returned image is platform-dependent:
  • cairo_surface_t* in GTK
  • Pixmap on X11
  • HBITMAP on Windows.

GlgGenerateImage creates an image of the visible part of the viewport, clipping out the parts of the drawing that extends outside of it.

For a light viewport, the output will be generated for its parent viewport. The drawing's hierarchy must be set up in order to generate an image.

◆ GlgGenerateImageCustom()

PlatformDependent GlgGenerateImageCustom ( GlgObject  object,
char *  resource_name,
PlatformDependent  image,
GlgLong  x,
GlgLong  y,
GlgLong  width,
GlgLong  height,
GlgLong  gap 
)

Creates an image of the specified rectangular region of the viewport's graphics.

Parameters
objectSpecifies a viewport object or a viewport's parent.
resource_nameSpecifies the resource path of a child viewport whose image to generate, or NULL to generate the image of the viewport specified by the object parameter. The resource path is relative to the object specified by the object parameter.
imageIf not NULL, specifies a platform-dependent image to be used. This image will be filled and returned instead of creating and returning a new image. The type of the image is platform-dependent:
  • cairo_surface_t* in GTK
  • Pixmap on X11
  • HBITMAP on Windows.
xSpecifies the X coordinate of the area used for generating an image. It defines an offset in screen pixels relative to the origin of the viewport's window, which has screen coordinates of (0,0).
ySpecifies the Y coordinate of the area used for generating an image. It defines an offset in screen pixels relative to the origin of the viewport's window, which has screen coordinates of (0,0).
widthSpecifies the width in screen pixels of the area used for generating an image.
heightSpecifies the height in screen pixels of the area used for generating an image.
gapSpecifies the padding space between the extent of the drawing and the border of the generated image in case when zero width and height parameters are specified.
Returns
The generated image or NULL if image generation failed. The type of the returned image is platform-dependent:
  • cairo_surface_t* in GTK
  • Pixmap on X11
  • HBITMAP on Windows.

The x, y, width and height parameters may be obtained by querying the bounding box of either the whole drawing or of the area of the drawing for which the image needs to be generated using GlgGetBoxPtr.

If width and height parameters are 0, the image of the whole drawing is generated using the drawing's bounding rectangle as the image generation area, without clipping to just the visible area. If the viewport is zoomed in, this area may be significantly bigger than the visible area of the viewport, and the image size may be quite large. The viewport's zoom factor defines the scaling factor for objects in the drawing when the image is saved.

For a light viewport, the output will be generated for its parent viewport. The drawing's hierarchy must be set up in order to generate an image.

◆ GlgNativePrint()

GlgBoolean GlgNativePrint ( GlgObject  object,
PlatformDependent  print_context,
double  x,
double  y,
double  width,
double  height,
GlgBoolean  stretch,
GlgBoolean  center 
)

GTK and Windows only: Generates printing output of the current state of the viewport's graphics.

Parameters
objectSpecifies a viewport. If object is a light viewport, the output will be generated for its parent viewport.
print_contextA platform-depended print context:
  • GtkPrintContext* in GTK
  • HDC on Windows
xDefines the X coordinate of the upper left corner of the rectangle on the page containing the output. All coordinates are specified in the world coordinate system, which maps a rectangle defined by the points (0;0) and (2000;2000) to a page.
yDefines the Y coordinate of the upper left corner of the rectangle.
widthDefines the width of the rectangle.
heightDefines the height of the rectangle.
stretchSpecifies whether or not printed output should be stretched when mapping it to the specified rectangle:
  • If True, the printed output will be stretched to fit the rectangle exactly. This may distort printed objects.
  • If False, the ratio of height to width of the widget will be preserved in the printed output. This may leave some parts of the specified rectangle blank.
centerSpecifies whether or not printed output should be centered inside the specified output rectangle when stretch=False results in unused space on the sides of the rectangle. If True, the output will be centered inside the output area, otherwise it will be anchored in the upper left corner of the rectangle.
Returns
True if printing output was successfully generated, otherwise False.

The drawing's hierarchy must be set up in order to print the drawing. Use GlgUpdate before printing to make sure the drawing is up to date.

In the MFC environment on Windows, GlgOnPrint may be used to support printing of the GlgControlC MFC wrapper.

◆ GlgSaveImage()

GlgBoolean GlgSaveImage ( GlgObject  object,
char *  resource_name,
char *  filename,
GlgImageFormat  format 
)

Generates a JPEG or PNG image of the current state of the viewport's graphics and saves it to a file.

Parameters
objectSpecifies a viewport object or a viewport's parent.
resource_nameSpecifies the resource path of a child viewport whose image to save, or NULL to save the image of the viewport specified by the object parameter. The resource path is relative to the object specified by the object parameter.
filenameSpecifies a filename in which to save the generated image.
formatSpecifies an image format, must be GLG_JPEG or GLG_PNG.
Returns
True if the image was successfully saved, otherwise False.

GlgSaveImage saves an image of the visible part of the viewport, clipping out the parts of the drawing that extends outside of it.

For a light viewport, the output will be generated for its parent viewport. The drawing's hierarchy must be set up in order to generate an image.

◆ GlgSaveImageCustom()

GlgBoolean GlgSaveImageCustom ( GlgObject  object,
char *  resource_name,
char *  filename,
GlgImageFormat  format,
GlgLong  x,
GlgLong  y,
GlgLong  width,
GlgLong  height,
GlgLong  gap 
)

Generates a JPEG or PNG image of the specified rectangular region of the viewport's graphics and saves it to a file.

Parameters
objectSpecifies a viewport object or a viewport's parent.
resource_nameSpecifies the resource path of a child viewport whose image to save, or NULL to save the image of the viewport specified by the object parameter. The resource path is relative to the object specified by the object parameter.
filenameSpecifies a filename in which to save the generated image.
formatSpecifies an image format, must be GLG_JPEG or GLG_PNG.
xSpecifies the X coordinate of the area used for generating an image. It defines an offset in screen pixels relative to the origin of the viewport's window, which has screen coordinates of (0,0).
ySpecifies the Y coordinate of the area used for generating an image. It defines an offset in screen pixels relative to the origin of the viewport's window, which has screen coordinates of (0,0).
widthSpecifies the width in screen pixels of the area used for generating an image.
heightSpecifies the height in screen pixels of the area used for generating an image.
gapSpecifies the padding space between the extent of the drawing and the border of the generated image in case when zero width and height parameters are specified.
Returns
True if the image was successfully saved, otherwise False.

The x, y, width and height parameters may be obtained by querying the bounding box of either the whole drawing or of the area of the drawing for which the image needs to be generated using GlgGetBoxPtr.

If width and height parameters are 0, the image of the whole drawing is generated using the drawing's bounding rectangle as the image generation area, without clipping to just the visible area. If the viewport is zoomed in, this area may be significantly bigger than the visible area of the viewport, and the image size may be quite large. The viewport's zoom factor defines the scaling factor for objects in the drawing when the image is saved.

For a light viewport, the output will be generated for its parent viewport. The drawing's hierarchy must be set up in order to generate an image.