How does the PDF line width interact with CTM both horizontally and vertically?

I am trying to figure out exactly how the line width affects the row string in a PDF, given the current transformation matrix (CTM). Two questions...

First: how to convert line width to device space using CTM? Page 208 of the PDF 1.7 Reference , which describes how to convert points using CTM, assumes the input is a (x, y) point. The line width is just one value, so how to convert it? Create a dummy like point from it (lineWidth, lineWidth)?

Secondly: as soon as I make this calculation, I will get another (x, y) point. If CTM has different scaling factors for horizontal and vertical points, this gives me two different line widths. How are these line widths applied? Is the first (x) used only when drawing horizontal lines?

A specific example of the second question: if I draw / stroke a horizontal line from (0, 0) to (4, 4) with a line width (2, 1), what are the coordinates of the bounding rectangle (i.e. the rectangle that contains the line width)?

This is from the reference, but it really does not explain how the thickness of the lines will change:

The effect created in the device space depends on the current transformation matrix (CTM), valid at the time of stroking the path. If CTM indicates scaling for various factors in horizontal and vertical dimensions, the thickness of the smoothed lines in the device space will vary depending on their orientation.

+5
source share
2 answers

How to convert line width to device space using CTM?

The line width is essentially the size of the line perpendicular to its direction. Thus, in order to calculate the width after conversion using CTM, you select a plane vector perpendicular to the original line whose length is the width of the line from the current graphic state, apply CTM (without translating, i.e. setting e and f to 0) so that this vector (embedded in three-dimensional space, setting the third coordinate to 1) and calculating the length of the resulting 2D vector (projecting the first two coordinates).

eg. you have a line from (0,0) to (1,4) in the current coordinates of the user space with a width of 1. You need to find a vector perpendicular to it, for example. (-4,1) by rotating 90 Β° counterclockwise and scaling it to a length of 1, i.e. (-4 / sqrt (17), 1 / sqrt (17)) in this case.

If CTM is that of @Tikitu's answers

CTM has a horizontal scaling factor of 2 and a vertical scaling factor of 1

it will be

2 0 0 0 1 0 0 0 1 

This matrix will cause the line from the above example to go from (0,0) to (2,4), and the "width vector" (-4 / sqrt (17), 1 / sqrt (17)) will be converted to (-8 / sqrt (17), 1 / sqrt (17)) (CTM no longer has a translation part) with a length of sqrt (65/17), which is about 1.955. That is, the width of the resulting line (its size perpendicular to its direction) is almost 2.

If the original row were (0,0) - (4,1) with a width of 1, the choice of the width vector would be (-1 / sqrt (17), 4 / sqrt (17)). In this case, the converted line will go from (0,0) to (8,1), and the width vector will be converted to (-2 / sqrt (17), 4 / sqrt (17)) with a length of sqrt (20/17) which is about 1,085. That is, the width of the resulting line (perpendicular to its direction) is slightly greater than 1.

It seems to you that you are interested in the "corners" of the line. To do this, you need to take the beginning and end of the converted line and add or subtract half the vector of the transformed width. In the above samples:

  • (source string from (0,0) to (1,4)): (-4 / sqrt (17), 1 / (2 * sqrt (17))), (4 / sqrt (17), (2-4 sqrt (17))), -1 / (2 * sqrt (17)));

  • (source string from (0,0) to (4,1)): (-1 / sqrt (17), 2 / sqrt (17)), (1 / sqrt (17), -2 / sqrt (17)) , (8-1 / sqrt (17), 1 + 2 / sqrt (17)), (8 + 1 / sqrt (17), 1-2 / sqrt (17)).

Remember, however, that PDF lines are often not trimmed at the end, but instead have some kind of cap. And besides that, remember the special value of line width 0.

+3
source

I don't know anything about internal PDFs, but I can guess what this passage can mean, based on knowing a little about how to use matrices to represent linear transformations.

If you represent your vowel line as a rectangle (long and thin, but with a certain width) and apply CTM to the four corner points, you will see how the line orientation changes its width when the CTM has different horizontal and vertical scaling factors.

If your CTM has a horizontal scale factor of 2 and a vertical scale factor of 1, think of lines at different angles:

  • the horizontal line (a rectangle with a short but wide) gets twice the length, and the "height" (line width) remains unchanged;
  • the vertical line (tall and thin rectangle) doubles the width (i.e. the line becomes twice as large), and the length remains unchanged;
  • lines at different angles become thicker to varying degrees, depending on the angle, because they stretch horizontally, but not vertically.
  • line thickness at 45 degrees is measured diagonally (45 degrees to the other side), so it becomes somewhat thicker (some horizontal stretching), but not twice as thick (the vertical component of the diagonal did not increase). (You can determine the thickness with two applications of the Pythagorean theorem, about 1.58 times or sqrt (5) / sqrt (2).)

If this story is true, you cannot convert the line width using CTM: it is just different depending on the orientation of the line. What you can convert is the width of a particular line, with a specific orientation, using the trick of thinking the line as a solid region and controlling its angles individually through CTM. (This also means that the β€œsame” line with the same thickness will look different since you will change its orientation if your CTM has different horizontal and vertical scaling factors.)

+1
source

Source: https://habr.com/ru/post/1201931/


All Articles