AlignmentYEnum alignmentY,
float rotation
)
{
ContentScanner.GraphicsState state = scanner.getState();
Font font = state.getFont();
float fontSize = state.getFontSize();
float x = (float)location.getX();
float y = (float)location.getY();
float width = font.getKernedWidth(value,fontSize);
float height = font.getLineHeight(fontSize);
float descent = font.getDescent(fontSize);
Point2D[] frame = new Point2D[4];
if(alignmentX == AlignmentXEnum.Left
&& alignmentY == AlignmentYEnum.Top)
{
beginText();
try
{
if(rotation == 0)
{
translateText(
x,
(float)(scanner.getContentContext().getBox().getHeight() - y - font.getAscent(fontSize))
);
}
else
{
double rad = rotation * Math.PI / 180.0;
double cos = Math.cos(rad);
double sin = Math.sin(rad);
setTextMatrix(
cos,
sin,
-sin,
cos,
x,
scanner.getContentContext().getBox().getHeight() - y - font.getAscent(fontSize)
);
}
state = scanner.getState();
frame[0] = state.textToDeviceSpace(new Point2D.Double(0,descent),true);
frame[1] = state.textToDeviceSpace(new Point2D.Double(width,descent),true);
frame[2] = state.textToDeviceSpace(new Point2D.Double(width,height+descent),true);
frame[3] = state.textToDeviceSpace(new Point2D.Double(0,height+descent),true);
// Add the text!
add(new ShowSimpleText(font.encode(value)));
}
catch(Exception e)
{throw new RuntimeException("Failed to show text.", e);}
finally
{end(); /* Ends the text object. */}
}
else
{
beginLocalState();
try
{
// Coordinates transformation.
double cos, sin;
if(rotation == 0)
{
cos = 1;
sin = 0;
}
else
{
double rad = rotation * Math.PI / 180.0;
cos = Math.cos(rad);
sin = Math.sin(rad);
}
// Apply the transformation!
applyMatrix(
cos,
sin,
-sin,
cos,
x,
scanner.getContentContext().getBox().getHeight() - y
);
beginText();
try
{
// Text coordinates adjustment.
switch(alignmentX)
{
case Left:
x = 0;
break;
case Right:
x = -width;
break;
case Center:
case Justify:
x = -width / 2;
break;
}
switch(alignmentY)
{
case Top:
y = -font.getAscent(fontSize);
break;
case Bottom:
y = height - font.getAscent(fontSize);
break;
case Middle:
y = height / 2 - font.getAscent(fontSize);
break;
}
// Apply the text coordinates adjustment!
translateText(x,y);
state = scanner.getState();
frame[0] = state.textToDeviceSpace(new Point2D.Double(0,descent),true);
frame[1] = state.textToDeviceSpace(new Point2D.Double(width,descent),true);
frame[2] = state.textToDeviceSpace(new Point2D.Double(width,height+descent),true);
frame[3] = state.textToDeviceSpace(new Point2D.Double(0,height+descent),true);
// Add the text!
add(new ShowSimpleText(font.encode(value)));
}
catch(Exception e)
{throw new RuntimeException("Failed to show text.", e);}
finally
{end(); /* Ends the text object. */}