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

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

Detailed Description

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

Functions

GlgBoolean ExportPostScript (char *filename="out.ps", double x=0., double y=0., double width=2000., double height=2000., GlgBoolean portrait=True, GlgBoolean stretch=True, GlgBoolean center=True)
 Generates a PostScript output of the current state of the viewport's graphics. More...
 
PlatformDependent GenerateImage (char *resource_name=NULL, PlatformDependent image=NULL)
 Creates and returns an image of the current state of the viewport's graphics. More...
 
PlatformDependent GenerateImageCustom (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...
 
void OnDrawMetafile (CDC *print_dc)
 Windows only: Provides MFC metafile output support. More...
 
void OnPrint (CDC *print_dc)
 Windows only: Provides MFC printing support. More...
 
GlgBoolean Print (PlatformDependent print_context, double x=0., double y=0., double width=2000., double height=2000., GlgBoolean portrait=True, GlgBoolean stretch=True, GlgBoolean center=True)
 GTK and Windows only: Generates printing output of the current state of the viewport's graphics. More...
 
GlgBoolean SaveImage (char *resource_name, char *filename, GlgImageFormat format=GLG_JPEG)
 Generates a JPEG or PNG image of the current state of this viewport's graphics and saves it to a file. More...
 
GlgBoolean SaveImageCustom (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

◆ ExportPostScript()

GlgBoolean ExportPostScript ( char *  filename = "out.ps",
double  x = 0.,
double  y = 0.,
double  width = 2000.,
double  height = 2000.,
GlgBoolean  portrait = True,
GlgBoolean  stretch = True,
GlgBoolean  center = True 
)

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

This is a wrapper for GlgExportPostScript, which receives the method's parameters. See GlgExportPostScript for parameter descriptions.

Parameters
filenameSee GlgExportPostScript for parameter description.
x,ySee GlgExportPostScript for parameter description.
width,heightSee GlgExportPostScript for parameter description.
portraitSee GlgExportPostScript for parameter description.
stretchSee GlgExportPostScript for parameter description.
centerSee GlgExportPostScript for parameter description.
Returns
Success or failure status.

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

◆ GenerateImage()

PlatformDependent GenerateImage ( char *  resource_name = NULL,
PlatformDependent  image = NULL 
)

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

This is a wrapper for GlgGenerateImage.

Parameters
resource_nameSpecifies the resource path of a child viewport whose image to save, or NULL to save the image of this viewport. The resource path is relative to this viewport.
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.

GenerateImage 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.

◆ GenerateImageCustom()

PlatformDependent GenerateImageCustom ( 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.

This is a wrapper for GlgGenerateImageCustom.

Parameters
resource_nameSpecifies the resource path of a child viewport whose image to save, or NULL to save the image of this viewport. The resource path is relative to this viewport.
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 GetBoxPtr.

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.

◆ OnDrawMetafile()

void OnDrawMetafile ( CDC *  print_dc)

Windows only: Provides MFC metafile output support.

Is used by the MFC container's OnDrawMetafile method to produce metafile for the GLG child window.

If this object is a light viewport, the output will be generated for its parent viewport.

Parameters
print_dcSpecifies the printing device context for metafile output.

◆ OnPrint()

void OnPrint ( CDC *  print_dc)

Windows only: Provides MFC printing support.

Is used by the MFC container's OnPrint method to print GLG child window. This is a wrapper for GlgOnPrint.

If this object is a light viewport, the output will be generated for its parent viewport.

Parameters
print_dcSpecifies the printing device context.

◆ Print()

GlgBoolean Print ( PlatformDependent  print_context,
double  x = 0.,
double  y = 0.,
double  width = 2000.,
double  height = 2000.,
GlgBoolean  portrait = True,
GlgBoolean  stretch = True,
GlgBoolean  center = True 
)

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

This is a wrapper for GlgNativePrint, which receives the method's parameters. See GlgNativePrint for parameter descriptions.

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

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

Parameters
print_contextSee GlgExportPostScript for parameter description.
x,ySee GlgExportPostScript for parameter description.
width,heightSee GlgExportPostScript for parameter description.
portraitSee GlgExportPostScript for parameter description.
stretchSee GlgExportPostScript for parameter description.
centerSee GlgExportPostScript for parameter description.
Returns
Success or failure status.

◆ SaveImage()

GlgBoolean SaveImage ( char *  resource_name,
char *  filename,
GlgImageFormat  format = GLG_JPEG 
)

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

This is a wrapper for GlgSaveImage.

Parameters
resource_nameSpecifies the resource path of a child viewport whose image to save, or NULL to save the image of this viewport. The resource path is relative to this viewport.
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.

SaveImage 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.

◆ SaveImageCustom()

GlgBoolean SaveImageCustom ( 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.

This is a wrapper for GlgSaveImageCustom.

Parameters
resource_nameSpecifies the resource path of a child viewport whose image to save, or NULL to save the image of this viewport. The resource path is relative to this viewport.
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 GetBoxPtr.

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.