Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

DynaPDF Manual - Page 440

Previous Page 439   Index   Next Page 441

Function Reference
Page 440 of 750
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 absolute string position?

Next topic: GetPageWidth