//
// legacy calculations which were previously in PDFStreamEngine
//
PDGraphicsState state = getGraphicsState();
Matrix ctm = state.getCurrentTransformationMatrix();
float fontSize = state.getTextState().getFontSize();
float horizontalScaling = state.getTextState().getHorizontalScaling() / 100f;
Matrix textMatrix = getTextMatrix();
// 1/2 the bbox is used as the height todo: why?
float glyphHeight = font.getBoundingBox().getHeight() / 2;
// transformPoint from glyph space -> text space
float height = font.getFontMatrix().transformPoint(0, glyphHeight).y;
// (modified) combined displacement, this is calculated *without* taking the character
// spacing and word spacing into account, due to legacy code in TextStripper
float tx = displacement.getX() * fontSize * horizontalScaling;
float ty = 0; // todo: support vertical writing mode
// (modified) combined displacement matrix
Matrix td = Matrix.getTranslatingInstance(tx, ty);
// (modified) text rendering matrix
Matrix nextTextRenderingMatrix = td.multiply(textMatrix).multiply(ctm); // text space -> device space
float nextX = nextTextRenderingMatrix.getXPosition();
float nextY = nextTextRenderingMatrix.getYPosition();
// (modified) width and height calculations
float dxDisplay = nextX - textRenderingMatrix.getXPosition();
float dyDisplay = height * textRenderingMatrix.getYScale();