| Author | DaveJarvis <email> |
|---|---|
| Date | 2020-09-12 23:22:54 GMT-0700 |
| Commit | b9a0a61371d743c9eaffde66d417feb033adce12 |
| Parent | 6e515a4 |
| Delta | 40 lines added, 26 lines removed, 14-line increase |
|---|
| final EventType<T> eventType, | ||
| final EventHandler<? super T> eventFilter ) { | ||
| - getEditorPane().getEditor().addEventFilter( eventType, eventFilter ); | ||
| + getEditor().addEventFilter( eventType, eventFilter ); | ||
| } | ||
| ( tab ) -> { | ||
| final var fet = (FileEditorTab) tab; | ||
| - fet.modifiedProperty() | ||
| - .addListener( modifiedListener ); | ||
| + fet.modifiedProperty().addListener( modifiedListener ); | ||
| } ); | ||
| } | ||
| else if( change.wasRemoved() ) { | ||
| change.getRemoved().forEach( | ||
| - ( tab ) -> | ||
| - ((FileEditorTab) tab).modifiedProperty() | ||
| - .removeListener( modifiedListener ) ); | ||
| + ( tab ) -> { | ||
| + final var fet = (FileEditorTab) tab; | ||
| + fet.modifiedProperty().removeListener( modifiedListener ); | ||
| + } | ||
| + ); | ||
| } | ||
| } |
| private void initTextChangeListener( final FileEditorTab tab ) { | ||
| tab.addTextChangeListener( | ||
| - ( editor, oldValue, newValue ) -> { | ||
| - process( tab ); | ||
| - scrollToParagraph( getCurrentParagraphIndex() ); | ||
| + ( __, ov, nv ) -> { | ||
| + //final var editor = tab.getEditorPane().getEditor(); | ||
| + | ||
| + //if( ov.isEmpty() ) { | ||
| + process( tab ); | ||
| + scrollToParagraph( getCurrentParagraphIndex() ); | ||
| + //} | ||
| + | ||
| +// editor.setOnKeyReleased( ( event ) -> { | ||
| +// process( tab ); | ||
| +// scrollToParagraph( getCurrentParagraphIndex() ); | ||
| +// } ); | ||
| } | ||
| ); |
| import static com.scrivenvar.StatusBarNotifier.alert; | ||
| -import static com.scrivenvar.graphics.SvgRasterizer.rasterize; | ||
| +import static com.scrivenvar.graphics.SvgRasterizer.*; | ||
| /** | ||
| private static final String SVG_FILE = "svg"; | ||
| private static final String HTML_SVG = "svg"; | ||
| + | ||
| + /** | ||
| + * The {@code <svg>} element attribute name containing a value that uniquely | ||
| + * identifies the vector graphic file. This value must always be the same for | ||
| + * the same formula. That is, {@code E=mc^2} must always hash the same way | ||
| + * (e.g., by calling {@link String#hashCode()} on the formula). | ||
| + */ | ||
| + private static final String SVG_IMAGE_SRC = "id"; | ||
| private static final String HTML_IMAGE = "img"; | ||
| // Convert the <svg> element to a raster graphic. | ||
| try { | ||
| - final var src = getCachedSvg( e ); | ||
| - image = getCachedImage( src, SvgRasterizer::rasterizeString ); | ||
| + final var src = e.getAttribute( "id" ); | ||
| + image = getCachedImage( src, __ -> rasterizeString( toSvg( e ) ) ); | ||
| } catch( final Exception ex ) { | ||
| alert( ex ); | ||
| private BufferedImage getCachedImage( | ||
| final String src, final Function<String, BufferedImage> rasterizer ) { | ||
| - return mImageCache.computeIfAbsent( src, v -> rasterizer.apply( src ) ); | ||
| + return mImageCache.computeIfAbsent( src, __ -> rasterizer.apply( src ) ); | ||
| } | ||
| } | ||
| - private Processor<String> createMathProcessor( | ||
| - final Processor<String> successor ) { | ||
| - return new MathProcessor( successor ); | ||
| - } | ||
| - | ||
| /** | ||
| * Creates and links the processors at the end of the processing chain. | ||
| * | ||
| * @return A markdown, caret replacement, and preview pane processor chain. | ||
| */ | ||
| private Processor<String> createMarkdownProcessor() { | ||
| final var hpp = createHTMLPreviewProcessor(); | ||
| final var mdp = new MarkdownProcessor( hpp, getPreviewPane().getPath() ); | ||
| return createMathProcessor( mdp ); | ||
| + } | ||
| + | ||
| + private Processor<String> createMathProcessor( | ||
| + final Processor<String> successor ) { | ||
| + return new MathProcessor( successor ); | ||
| } | ||
| final var l = new TeXLayout( box, mSize ); | ||
| - mGraphics.initialize( formula.hashCode(), l.getWidth(), l.getHeight() ); | ||
| + mGraphics.initialize( equation.hashCode(), l.getWidth(), l.getHeight() ); | ||
| box.draw( mGraphics, l.getX(), l.getY() ); | ||
| import com.whitemagicsoftware.tex.TeXLayout; | ||
| import com.whitemagicsoftware.tex.graphics.SvgGraphics2D; | ||
| -import org.apache.batik.transcoder.TranscoderException; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.xml.sax.SAXException; | ||
| import javax.imageio.ImageIO; | ||
| import javax.xml.parsers.DocumentBuilderFactory; | ||
| import javax.xml.parsers.ParserConfigurationException; | ||
| -import javax.xml.transform.TransformerException; | ||
| import java.awt.image.BufferedImage; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| -import java.text.ParseException; | ||
| import static com.scrivenvar.graphics.SvgRasterizer.rasterizeString; | ||
| @Test | ||
| public void test_Rasterize_SimpleFormula_CorrectImageSize() | ||
| - throws IOException, TranscoderException, ParseException { | ||
| + throws IOException { | ||
| final var svg = createSvg(); | ||
| final var image = rasterizeString( svg ); | ||
| @Test | ||
| public void test_Conversion_InputElement_OutputRasterizableSvg() | ||
| - throws ParserConfigurationException, IOException, SAXException, | ||
| - ParseException, TranscoderException, TransformerException { | ||
| + throws ParserConfigurationException, IOException, SAXException { | ||
| final var expectedSvg = createSvg(); | ||
| final var bytes = expectedSvg.getBytes(); | ||
| final var layout = new TeXLayout( box, size ); | ||
| - g.setDimensions( layout.getWidth(), layout.getHeight() ); | ||
| + g.initialize( layout.getWidth(), layout.getHeight() ); | ||
| box.draw( g, layout.getX(), layout.getY() ); | ||
| return g.toString(); | ||