static UnderlineMetrics deriveUnderlineMetrics(FreeTypeFontGenerator generator, int size) { try { // Size metrics aren't publicly accessible (as of 1.9.3). (Ab)use reflection to gain access. Field faceField = FreeTypeFontGenerator.class.getDeclaredField("face"); faceField.setAccessible(true); Face face = (Face)faceField.get(generator); SizeMetrics sizeMetrics = face.getSize().getMetrics(); int yScale = sizeMetrics.getYscale(); // 16.16 fixed point float position = FreeType.toInt(face.getUnderlinePosition() * yScale >> 16); float thickness = FreeType.toInt(face.getUnderlineThickness() * yScale >> 16); return new UnderlineMetrics(position, thickness); } catch (Exception e) { LOG.error("Error fetching FreeType underline metrics", e); } // Return a reasonable default return UnderlineMetrics.defaultInstance(size); }