javagraphics2dikvm

Faster method than TextLayout.draw() - Graphics2D?


I am doing the following to write text to a bitmap:

AttributedString as = new AttributedString(buf.toString());
FontRenderContext frc = graphics.getFontRenderContext();
LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(as.getIterator(), frc);
TextLayout layout = lineMeasurer.nextLayout(Integer.MAX_VALUE);
layout.draw (graphics, left, line.getBaseline());

The problem is while this is very fast in Java, we also complie this using IKVM to run under .NET and it is horribly slow there.

Is there another way to write formatted text to a Graphics2D object?


Solution

  • We found the problem in IKVM (it was recreating an array once for each point in the curve for each glyph - so literally millions of array creations).

    We fixed this in IKVM and now it's lighting fast under IKVM too. If you hit the same problem we have it with this fix at https://www.nuget.org/packages/IKVM.WINDWARD/.