Path construction in postscript Preface In PS, path is used to define shapes, tracks, and various types of areas. In the program, you can use path to dash, define the shape of the filled area, and define the cropping boxes of other images. A path consists of a set of connect or disconnect straight line segments and curve segments. A pair of continuous defined points will become connect (the starting point of the second line segment is the end point of the first line segment ). The direction of a line segment in a path is signed. A path consists of one or more disconnect subpaths. Each subpath contains a set of connected line segments. The path topology is free, can be concave, convex, and contains multiple subpaths to describe multiple isolated regions (disjoint areas does not know how to translate, it is called an isolated region for now ), any way of intersection. The closepath operator explicitly links the end point of a subpath to its starting point, so that the subpath is closed and not open ). Although path cannot be accessed directly as an object, its construction and use are still under the control of the program. The PS program can read the path, or it is usually used to control the paint-related operators. Current path) The "current path" is part of the graphic state. The path construction operator modifies only the "current path" and usually adds a vertex to it. The paint operator implicitly uses the "current path ", gsave and grestore save and restore the "current path" respectively ". Use newpath in the program to start a new path, which will initialize "current path" to empty (some paint operators will re-Initialize "current path" after execution "), then, use one or more operators to add a line segment for the current path. The call sequence of the operator is arbitrary, but the first operator must be moveTo. The last added node is generally called the current point ). If "current path" is empty, "current point" is not defined. Most operators add line segments starting from the current vertex. If no "current vertex" exists, a nocurrentpoint error is generated. The following is a list of the most common path construction operators. MoveTo creates a new "current vertex" (no line segment is added to the "current path"). Therefore, this operator creates a subpath. Lineto adds a straight line to the current path to make it a new "current point ". Add an arc to "current path" to arc, arcn, ARCT, and arcto ". Curveto adds a cube's curve to the current path ". Rmoveto, rlineto, and rcurveto execute the moveTo, lineto, and curveto operations. However, by converting in the user space, a new vertex relative to the "current vertex" is specified, rather than the absolute coordinate. Add a straight line to closepath to connect the starting point of the current vertex and the current subpath (usually this point is specified by the nearest moveTo). Therefore, close the current subpath. Note: The Path build operator does not leave any trace on the page, and only the paint operator will execute them. A program typically depicts a graphic element is implemented by defining this element as a path and then calling a paint operator. This is repeated for each element on the page. All vertices used to describe the path are defined in the user space ). When the program adds a point to the "current path", all coordinates are converted to the "device space" through the CTM ). Changing the CTM does not affect the coordinates of existing points in the device space. By calling a defined PS process for building a path, you can reuse the same path in the page description. In this case, each path can be built and painted in the following three steps: 1. Modify the CTM. If necessary, call the coordinate conversion operator to locate, redirect, and scale the path. 2. Call the PS process to build this path. 3. Call the paint operator to display it on the page. Generally, the path description remains unchanged. The user path operator in exploragelevel 2 can combine steps 2 and 3 above and encapsulate the entire process through the gsave and grestor operators. The following is an example: /Box % defines a path in the current user's coordinate system. Its origin is in the lower left corner. {Newpath 0 0 moveTo 0 1 lineto 1 1 lineto 1 0 lineto Closepath } Def Gsave % saves the current graphics state and creates a new graphics state that can be modified. 72 72 scale % modify the CTM and display it 72 times later. Box fill % draws a rectangle in the lower left corner and fills it with black. Because a cell is 1 inch, the side length of the rectangle is 1 inch. 2 2 2 translate % continue to modify the CTM so that the origin point is 2 inch away from the left side and the bottom side of the page. Box fill % draws this rectangle again. The position is 2 inch high from the lower left corner and 2 inch to the right. Grestore % restore the saved graphics state. Now the default user space is returned. "Crop path" (Clipping Path) Graphics State also contains a "Crop path" that limits the areas on the page that are affected by the paint-related operators. The closed subpaths defines that the elements in the area that can be affected by the painting will be displayed on the page, while those outside the area will not be displayed. "Crop path" only affects the current paint class operator; it does not affect the path constructor mentioned in the previous section. When a path is finally depicted, the result is only affected by the "Crop path" at that time, rather than the path when it is constructed. In PS level 3, the graphics state also contains an auxiliary "Crop path" Stack, which uses the clipsave and cliprestore operators to output and import stacks. Because "Crop path" is an element of graphics state, gsave and grestore Replace the entire "Crop path" when switching graphics state ". |