- All Implemented Interfaces:
AutoCloseable
The following mime types are supported on source patterns:
MimeType.JPEG
, MimeType.UNIQUE_ID
,
MimeType.CCITT_FAX
, MimeType.CCITT_FAX_PARAMS
,
MimeType.TYPE_EPS
, MimeType.EPS_PARAMS
.
Source surfaces used by the PostScript surface that have a
MimeType.UNIQUE_ID
mime type will be stored in PostScript printer
memory for the duration of the print job. MimeType.UNIQUE_ID
should
only be used for small frequently used sources.
The MimeType.CCITT_FAX
and MimeType.CCITT_FAX_PARAMS
mime
types are documented in CCITT Fax Images.
Embedding EPS files
Encapsulated PostScript files can be embedded in the PS output by setting the
MimeType.TYPE_EPS
mime data on a surface to the EPS data and painting
the surface. The EPS will be scaled and translated to the extents of the
surface the EPS data is attached to.
The MimeType.TYPE_EPS
mime type requires the
MimeType.EPS_PARAMS
mime data to also be provided in order to specify
the embedding parameters. MimeType.EPS_PARAMS
mime data must contain
a string of the form "bbox=[llx lly urx ury]"
that specifies the
bounding box (in PS coordinates) of the EPS graphics. The parameters are:
lower left x, lower left y, upper right x, upper right y. Normally the bbox
data is identical to the BoundingBox
data in the EPS file.
- Since:
- 1.2
- See Also:
-
Constructor Summary
ConstructorDescriptionPSSurface
(MemorySegment address) Constructor used internally to instantiate a java PSSurface object for a nativecairo_surface_t
instance -
Method Summary
Modifier and TypeMethodDescriptionstatic PSSurface
create
(OutputStream stream, double widthInPoints, double heightInPoints) Creates a PostScript surface of the specified size in points to be written incrementally to the OutputStreamstream
.static PSSurface
Creates a PostScript surface of the specified size in points to be written tofilename
.This function indicates that subsequent calls todscComment(String)
should direct comments to the PageSetup section of the PostScript output.This function indicates that subsequent calls todscComment(String)
should direct comments to the Setup section of the PostScript output.dscComment
(String comment) Emit a comment into the PostScript output for the given surface.boolean
getEPS()
Check whether the PostScript surface will output Encapsulated PostScript.restrictToLevel
(PSLevel level) Restricts the generated PostSript file tolevel
.setEPS
(boolean eps) If eps istrue
, the PostScript surface will output Encapsulated PostScript.setSize
(double widthInPoints, double heightInPoints) Changes the size of a PostScript surface for the current (and subsequent) pages.Methods inherited from class org.freedesktop.cairo.Surface
close, copyPage, createForRectangle, createSimilar, createSimilarImage, destroy, finish, flush, getContent, getDevice, getDeviceOffset, getDeviceScale, getFallbackResolution, getFontOptions, getMimeData, getSurfaceType, getType, getUserData, hasShowTextGlyphs, mapToImage, markDirty, markDirtyRectangle, setDeviceOffset, setDeviceScale, setFallbackResolution, setMimeData, setUserData, showPage, status, supportsMimeType, unmapImage
-
Constructor Details
-
PSSurface
Constructor used internally to instantiate a java PSSurface object for a nativecairo_surface_t
instance- Parameters:
address
- the memory address of the nativecairo_surface_t
instance
-
-
Method Details
-
create
Creates a PostScript surface of the specified size in points to be written tofilename
. Seecreate(OutputStream, double, double)
for a more flexible mechanism for handling the PostScript output than simply writing it to a named file.Note that the size of individual pages of the PostScript output can vary. See
setSize(double, double)
.- Parameters:
filename
- a filename for the PS output (must be writable),null
may be used to specify no output. This will generate a PS surface that may be queried and used as a source, without generating a temporary file.widthInPoints
- width of the surface, in points (1 point == 1/72.0 inch)heightInPoints
- height of the surface, in points (1 point == 1/72.0 inch)- Returns:
- the newly created surface.
- Since:
- 1.2
-
create
Creates a PostScript surface of the specified size in points to be written incrementally to the OutputStreamstream
. Seecreate(String, double, double)
for a more convenient way to simply direct the PostScript output to a named file.Note that the size of individual pages of the PostScript output can vary. See
setSize(double, double)
.- Parameters:
stream
- anOutputStream
to accept the output data, may benull
to indicate a no-op stream. With a no-op stream, the surface may be queried or used as a source without generating any temporary files.widthInPoints
- width of the surface, in points (1 point == 1/72.0 inch)heightInPoints
- height of the surface, in points (1 point == 1/72.0 inch)- Returns:
- the newly created surface.
- Since:
- 1.2
-
restrictToLevel
Restricts the generated PostSript file tolevel
. SeePSLevel.getLevels()
for a list of available level values that can be used here.This function should only be called before any drawing operations have been performed on the given surface. The simplest way to do this is to call this function immediately after creating the surface.
- Parameters:
level
- PostScript level- Returns:
- the PostScript surface
- Since:
- 1.6
-
setEPS
If eps istrue
, the PostScript surface will output Encapsulated PostScript.This function should only be called before any drawing operations have been performed on the current page. The simplest way to do this is to call this function immediately after creating the surface. An Encapsulated PostScript file should never contain more than one page.
- Parameters:
eps
-true
to output EPS format PostScript- Returns:
- the PostScript surface
- Since:
- 1.6
-
getEPS
public boolean getEPS()Check whether the PostScript surface will output Encapsulated PostScript.- Returns:
true
if the surface will output Encapsulated PostScript.- Since:
- 1.6
-
setSize
Changes the size of a PostScript surface for the current (and subsequent) pages.This function should only be called before any drawing operations have been performed on the current page. The simplest way to do this is to call this function immediately after creating the surface or immediately after completing a page with either
Context.showPage()
orContext.copyPage()
.- Parameters:
widthInPoints
- new surface width, in points (1 point == 1/72.0 inch)heightInPoints
- new surface height, in points (1 point == 1/72.0 inch)- Returns:
- the PostScript surface
- Since:
- 1.2
-
dscBeginSetup
This function indicates that subsequent calls todscComment(String)
should direct comments to the Setup section of the PostScript output.This function should be called at most once per surface, and must be called before any call to
dscBeginPageSetup()
and before any drawing is performed to the surface.See
dscComment(String)
for more details.- Returns:
- the PostScript surface
- Since:
- 1.2
-
dscBeginPageSetup
This function indicates that subsequent calls todscComment(String)
should direct comments to the PageSetup section of the PostScript output.This function call is only needed for the first page of a surface. It should be called after any call to
dscBeginSetup()
and before any drawing is performed to the surface.See
dscComment(String)
for more details.- Returns:
- the PostScript surface
- Since:
- 1.2
-
dscComment
Emit a comment into the PostScript output for the given surface.The comment is expected to conform to the PostScript Language Document Structuring Conventions (DSC). Please see that manual for details on the available comments and their meanings. In particular, the %%IncludeFeature comment allows a device-independent means of controlling printer device features. So the PostScript Printer Description Files Specification will also be a useful reference.
The comment string must begin with a percent character (%) and the total length of the string (including any initial percent characters) must not exceed 255 characters. Violating either of these conditions will throw
IllegalArgumentException
and place the surface into an error state. But beyond these two conditions, this function will not enforce conformance of the comment with any particular specification.The comment string must not contain any newline characters.
The DSC specifies different sections in which particular comments can appear. This function provides for comments to be emitted within three sections: the header, the Setup section, and the PageSetup section. Comments appearing in the first two sections apply to the entire document while comments in the BeginPageSetup section apply only to a single page.
For comments to appear in the header section, this function should be called after the surface is created, but before a call to
dscBeginSetup()
.For comments to appear in the Setup section, this function should be called after a call to
dscBeginSetup()
but before a call todscBeginPageSetup()
.For comments to appear in the PageSetup section, this function should be called after a call to
dscBeginPageSetup()
.Note that it is only necessary to call
dscBeginPageSetup()
for the first page of any surface. After a call toContext.showPage()
orContext.copyPage()
comments are unambiguously directed to the PageSetup section of the current page. But it doesn't hurt to call this function at the beginning of every page as that consistency may make the calling code simpler.As a final note, cairo automatically generates several comments on its own. As such, applications must not manually generate any of the following comments:
Header section:
%!PS-Adobe-3.0
,%%Creator
,%%CreationDate
,%%Pages
,%%BoundingBox
,%%DocumentData
,%%LanguageLevel
,%%EndComments
.Setup section:
%%BeginSetup
,%%EndSetup
PageSetup section:
%%BeginPageSetup
,%%PageBoundingBox
,%%EndPageSetup
.Other sections:
%%BeginProlog
,%%EndProlog
,%%Page
,%%Trailer
,%%EOF
Here is an example sequence showing how this function might be used:
var surface = PSSurface.create(filename, width, height); ... surface.dscComment("%%Title: My excellent document") .dscComment("%%Copyright: Copyright (C) 2006 Cairo Lover") .beginSetup() .dscComment("%%IncludeFeature: *MediaColor White"); ... .beginPageSetup() .dscComment("%%IncludeFeature: *PageSize A3") .dscComment("%%IncludeFeature: *InputSlot LargeCapacity") .dscComment("%%IncludeFeature: *MediaType Glossy") .dscComment("%%IncludeFeature: *MediaColor Blue"); ... draw to first page here .. context.showPage(); ... surface.dscComment("%%IncludeFeature: *PageSize A5"); ...
- Parameters:
comment
- a comment string to be emitted into the PostScript output- Returns:
- the PostScript surface
- Throws:
IllegalArgumentException
- if the comment string does not begin with a percent character (%) or the total length of the string (including any initial percent characters) exceeds 255 characters.- Since:
- 1.2
-