Function Reference
Page 516 of 874
Note that the order in which the matrices are multiplied is important; the reversed order would
produce an incorrect result.
Now we need a function that transforms a point with the matrix:
void Transform(TCTM &M, double &x, double &y)
{
double ox = x;
x = ox * M.a + y * M.c + M.x;
y = ox * M.b + y * M.d + M.y;
}
The text position can now easily calculated as follows:
// Get the text matrix in user space
TCTM m = MulMatrix(stack.ctm, stack.tm);
double x = 0.0;
double y = 0.0;
Transform(m, x, y);
How to caluculate the font size?
The font size that is provided in the structure TPDFStack is measured in text space. If you want to
know the visible font size then the value must be transformed to user space:
First, we must multiply the matrices ctm and tm with MulMatrix() as shown above and pass the
resulting matrix to GetScaleY() as described below; the return value is the scaling factor on the y-
axis. Finally, the font size must be multiplied with the scaling factor:
// Distance between two points
double CalcDistance(double x1, double y1, double x2, double y2)
{
double dx = x2-x1;
double dy = y2-y1;
return sqrt(dx*dx + dy*dy);
}
// Scaling factor of the y-axis
double GetScaleY(TCTM &M)
{
double x1 = 0.0;
double y1 = 0.0;
double x2 = 0.0;
double y2 = 1.0;
Transform(M, x1, y1);
Transform(M, x2, y2);
if (y1 > y2)
return -CalcDistance(x1, y1, x2, y2);
else
return CalcDistance(x1, y1, x2, y2);
}
TCTM
m = MulMatrix(stack.ctm, stack.tm); // User space matrix