Add geometrical figures to PS files

C++ API solution to work with shapes of PS files

 

PostScript is a powerful page description language that offers precise control over the rendering of geometric shapes. However, there are a few nuances to be aware of when drawing these figures:

  • Coordinate System - PostScript uses a Cartesian coordinate system, with the origin (0,0) typically located at the bottom-left corner of the page. Positive x-values move to the right, and positive y-values move upwards. Understanding this coordinate system is crucial for positioning shapes accurately.
  • Path-Based Graphics - PostScript uses a path-based approach to drawing shapes. This involves defining a series of points and curves that form the outline of the shape. Common path operators include moveto, lineto, curveto, and closepath. Mastering these operators is essential for creating complex shapes.
  • Line Width and Color - The setlinewidth operator controls the thickness of lines. The setgray, setrgbcolor, and setcmykcolor operators define the color of the stroke and fill. Experimenting with different line widths and colors can significantly impact the visual appearance of your figures.
  • Transformations, such as translation, rotation, and scaling, can be applied to shapes using operators like translate, rotate, and scale. These transformations allow you to create intricate and dynamic figures.
  • Text and Fonts - While not strictly geometric, text is often integrated with shapes in PostScript documents. Understanding font metrics and text positioning is important for creating clear and visually appealing figures.
  • Clipping paths can be used to restrict drawing operations to specific areas of the page. This technique is useful for creating complex shapes with overlapping or intersecting components.
  • Rendering Quality - The quality of rendered shapes can be affected by factors such as line joins, line caps, and anti-aliasing. Experimenting with different rendering settings can improve the visual appearance of your figures.

Knowing these aspects will let you ensure proper shape integration and accurate rendering in PostScript-based workflows. But no matter what, - Aspose.Page provides you with the functionality to draw geometrical shapes in PS files easily. With this API you can add different images using C++. To learn more about how to deal with PS files and how to work with shapes in PS files in particular follow the documentation.

To add shapes to PS documents we need:

  • Aspose.Page for C++ API which is a feature-rich, powerful, and easy-to-use document manipulation and conversion C++ API.

  • Open the NuGet package manager, and search for Aspose.Page and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command

    PM> Install-Package Aspose.Page.Cpp

Steps to add figures to a PS file.

This code below creates a PS document, adds a rectangle to it, and paints it with an orange color. To see more examples go to Aspose.Page for C++ GitHub project .

  1. Create an output stream for the PostScript document using the FileStream class.
  2. Create a PsSaveOptions object to specify the save options for the PostScript document.
  3. Create a graphics path using the System.Drawing.Drawing2D.GraphicsPath class and specify the coordinates and dimensions of the rectangle using the System.Drawing.RectangleF Class.
  4. Use the SetPaint() Method to specify the color of the rectangle.
  5. Call the Fill() Method to add the specified color to the rectangle.
  6. Call the ClosePage() to indicate that the current page is completed.
  7. Save the changes using the Save() Method.
Add shapes to 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.