| Author | DaveJarvis <email> |
|---|---|
| Date | 2020-12-29 15:51:32 GMT-0800 |
| Commit | 300ed49f117df1caca9c23a27044136507bd7562 |
| Parent | a4b1398 |
| /** | ||
| + * Singleton instance for rendering math symbols. | ||
| + */ | ||
| + public static final MathRenderer MATH_RENDERER = new MathRenderer(); | ||
| + | ||
| + /** | ||
| * Default font size in points. | ||
| */ | ||
| private static final float FONT_SIZE = 20f; | ||
| private final TeXFont mTeXFont = createDefaultTeXFont( FONT_SIZE ); | ||
| private final TeXEnvironment mEnvironment = createTeXEnvironment( mTeXFont ); | ||
| private final SvgDomGraphics2D mGraphics = createSvgDomGraphics2D(); | ||
| - public MathRenderer() { | ||
| + private MathRenderer() { | ||
| mGraphics.scale( FONT_SIZE, FONT_SIZE ); | ||
| } |
| import static com.keenwrite.StatusBarNotifier.clue; | ||
| import static com.keenwrite.io.MediaType.*; | ||
| +import static com.keenwrite.preview.MathRenderer.MATH_RENDERER; | ||
| import static com.keenwrite.preview.SvgRasterizer.BROKEN_IMAGE_PLACEHOLDER; | ||
| import static com.keenwrite.preview.SvgRasterizer.rasterize; | ||
| */ | ||
| public class SvgReplacedElementFactory extends ReplacedElementAdapter { | ||
| - | ||
| - /** | ||
| - * Implementation of the initialization-on-demand holder design pattern, | ||
| - * an for a lazy-loaded singleton. In all versions of Java, the idiom enables | ||
| - * a safe, highly concurrent lazy initialization of static fields with good | ||
| - * performance. The implementation relies upon the initialization phase of | ||
| - * execution within the Java Virtual Machine (JVM) as specified by the Java | ||
| - * Language Specification. | ||
| - */ | ||
| - private static class Container { | ||
| - private static final MathRenderer INSTANCE = new MathRenderer(); | ||
| - } | ||
| - | ||
| - /** | ||
| - * Returns the singleton instance for rendering math symbols. | ||
| - * | ||
| - * @return A non-null instance, loaded, configured, and ready to render math. | ||
| - */ | ||
| - public static MathRenderer getInstance() { | ||
| - return Container.INSTANCE; | ||
| - } | ||
| public static final String HTML_IMAGE = "img"; | ||
| case HTML_TEX -> | ||
| // Convert the TeX element to a raster graphic. | ||
| - raster = rasterize( getInstance().render( e.getTextContent() ) ); | ||
| + raster = rasterize( MATH_RENDERER.render( e.getTextContent() ) ); | ||
| } | ||
| import com.keenwrite.ExportFormat; | ||
| import com.keenwrite.preview.SvgRasterizer; | ||
| -import com.keenwrite.preview.SvgReplacedElementFactory; | ||
| import com.vladsch.flexmark.html.HtmlWriter; | ||
| import com.vladsch.flexmark.html.renderer.NodeRenderer; | ||
| import java.util.Set; | ||
| +import static com.keenwrite.preview.MathRenderer.MATH_RENDERER; | ||
| import static com.keenwrite.processors.markdown.tex.TexNode.*; | ||
| final NodeRendererContext context, | ||
| final HtmlWriter html ) { | ||
| - final var renderer = SvgReplacedElementFactory.getInstance(); | ||
| final var tex = node.getText().toStringOrNull(); | ||
| - final var doc = renderer.render( tex == null ? "" : tex ); | ||
| + final var doc = MATH_RENDERER.render( tex == null ? "" : tex ); | ||
| final var svg = SvgRasterizer.toSvg( doc.getDocumentElement() ); | ||
| html.raw( svg ); | ||
| Delta | 10 lines added, 26 lines removed, 16-line decrease |
|---|