Work with graphics states in PS
Clip and transform graphics states of PS files using API for C++
In PostScript, a graphic state is a collection of attributes that define how graphics are drawn on a page and allow you to create complex and varied graphics with a single set of commands. By saving and restoring graphic states, you can avoid redundant operations. You can also define reusable graphic styles and apply them to different document parts. Graphic state includes settings such as:
- The thickness of lines(Line width).
- The shape of the ends of lines (round, square, or butt).
- The shape of the junctions between lines (miter, round, or bevel).
- The color of lines and fills (RGB, CMYK, or grayscale).
- The font used for text and its size.
- The matrix used to transform coordinates (scaling, rotation, translation).
Managing graphics states in PS documents (equivalent of canvases in XPS) is one of the main features offered by Aspose.Page for C++.
To transform graphics states of a PS file follow the next guide:
- Create a PS file using the PsDocument Class .
- Create a rectangle graphics path.
- Save the current graphics state, create a new graphics state and set it as current with the WriteGraphicsSave() Method.
- Translate the current graphics state using the Translate() Method.
- Set the paint in the current graphics state with the SetPaint() Method.
- Fill the graphics path by means of the Fill() method.
- Restore the previous graphics state with the WriteGraphicsRestore Method.
- Repeat steps 3-7 for adding more graphics states with other transformations using Scale() , Rotate() , Shear() and Transform() Methods.
- Close the current page by means of the ClosePage() method.
- Save the created PS document using the PsDocument.Save() Method.
Transform graphics states of a PS
To add Clips to the graphics state of a PS file follow the next guide:
- Create a PS file using the PsDocument Class .
- Create a rectangle graphics path.
- Save the current graphics state, create a new graphics stateand and set it as current with the WriteGraphicsSave() Method.
- Translate the current graphics state using the Translate() Method.
- Create a circle graphics path.
- Add clipping by circle to the current graphics state using the Clip() Method.
- Set the paint in the current graphics state with the SetPaint() Method.
- Fill the rectangle graphics path by means of the Fill() Method.
- Restore the previous graphics state with WriteGraphicsRestore() Method.
- Translate the current graphics state using the Translate() Method.
- Create a System.Drawing.Pen object.
- Set a stroke in the current graphics state with the SetStroke() Method.
- Draw the rectangle graphics path above the clipped rectangle by means of the Draw() Method.
- Close the current page by means of the ClosePage() Method.
- Save the created PS document using the PsDocument.Save() Method.
Add Clip to graphics state of a PS
PS What is PS File Format
PS format is one of the page description language (PDL) formats. It is capable to contain graphic as well as text information on the page. That is why the format was supported by most of the programs for image editing. The postscript file itself is a kind of instruction for printers. It contains information on what and how to print from its page.