Xojo Conferences
MBSOct2019CologneDE

DynaPDF Manual - Page 449

Previous Page 448   Index   Next Page 450

Function Reference
Page 449 of 767
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
double fs = stack.FontSize * GetScaleY(m);
// Real font size
How to calculate the rotation angle?
If you want to know whether the string is rotated then use the function TransRotation() to calculate
the rotation angle in radians. Note that this function requires again the pre-multiplied matrix in user
space.
double TransRotation(TCTM &M)
{
double x1 = 0.0; double x2 = 1.0;
double y1 = 0.0; double y2 = 0.0;
Transform(M, x1, y1);
Transform(M, x2, y2);
return atan2(y2-y1, x2-x1);
}
 

Previous topic: How to calculate the rotation angle?

Next topic: GetPrintSettings