3 ms·
> If you need to generate basic shapes it's fairly straightforward. You'd think so. While integrating TeX into my editor[0], using JMathTeX[1] as a starting po
by thangalin 6y ago
> If you need to generate basic shapes it's fairly straightforward.
You'd think so. While integrating TeX into my editor[0], using JMathTeX[1] as a starting point, I wanted to convert font glyphs to vector paths. At the time, every Java-based SVG renderer (Batik, JFreeSVG, SVG Salamander) suffered from the exact same performance problem: they all used Java's DecimalFormat class to convert floating point numbers to strings. These strings were then concatenated as paths into the output document. Sometimes the strings were re-copied numerous times because of buffer re-allocations and other reasons. (Part 5 of my series[2] on developing a TeX-oriented text editor covers this in depth.)
To get great performance---in Java, at least---even for basic shapes requires a sufficiently large, reusable buffer that doesn't incur memory re-allocations and an efficient algorithm to convert floats to strings---such as Ryu[3]. See my implementation that converts glyph paths to vector paths for details[4]. With these two changes I was able to improve upon JFreeSVG's implementation four-fold.
[0]: https://github.com/DaveJarvis/keenwrite https://github.com/DaveJarvis/keenwrite (my editor)
[1]: https://github.com/DaveJarvis/JMathTeX/ https://github.com/DaveJarvis/JMathTeX/ (my fork)
[2]: https://bell-sw.com/announcements/2020/11/02/TeXnical-Writing-Part-1-Foundations/ https://bell-sw.com/announcements/2020/11/02/TeXnical-Writin... (my blog series)
[3]: https://github.com/ulfjack/ryu https://github.com/ulfjack/ryu
[4]: https://github.com/DaveJarvis/JMathTeX/blob/d2d678717505765be78922774654091ec9295231/src/main/java/com/whitemagicsoftware/tex/graphics/SvgGraphics2D.java#L45 https://github.com/DaveJarvis/JMathTeX/blob/d2d678717505765b...