private static Geometry fontGlyph(Geometry g, String text, Font font) {
Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
Geometry textGeom = FontGlyphReader.read(text, font, geomFact);
Envelope envText = textGeom.getEnvelopeInternal();
if (g != null) {
Coordinate baseText0 = new Coordinate(envText.getMinX(), envText.getMinY());
Coordinate baseText1 = new Coordinate(envText.getMaxX(), envText.getMinY());
Coordinate baseGeom0 = new Coordinate(env.getMinX(), env.getMinY());
Coordinate baseGeom1 = new Coordinate(env.getMaxX(), env.getMinY());
AffineTransformation trans = AffineTransformationFactory.createFromBaseLines(baseText0, baseText1, baseGeom0, baseGeom1);
return trans.transform(textGeom);
}
return textGeom;
}