| 68 | 68 | * Platform-independent (Windows, Linux, MacOS) |
| 69 | 69 | |
| 70 | ## Typesetting | |
| 71 | ||
| 72 | Typesetting to PDF files requires the following: | |
| 73 | ||
| 74 | * [Theme Pack](https://github.com/DaveJarvis/keenwrite-themes/releases/latest/download/theme-pack.zip) | |
| 75 | * [ConTeXt](https://wiki.contextgarden.net/Installation) | |
| 76 | ||
| 70 | 77 | ## Usage |
| 71 | 78 |
| 50 | 50 | * 嵌入R语句 |
| 51 | 51 | |
| 52 | ## Typesetting | |
| 53 | ||
| 54 | 排版到 PDF 文件需要以下內容: | |
| 55 | ||
| 56 | * [Theme Pack](https://github.com/DaveJarvis/keenwrite-themes/releases/latest/download/theme-pack.zip) | |
| 57 | * [ConTeXt](https://wiki.contextgarden.net/Installation) | |
| 58 | ||
| 52 | 59 | ## 软件使用 |
| 53 | 60 | |
| 54 | See the [detailed documentation](docs/README.md) for information about | |
| 55 | using the application. | |
| 61 | 有關使用該應用程序的信息,請參[閱詳細文檔](docs/README.md)。 | |
| 56 | 62 | |
| 57 | 63 | ## 截图 |
| 36 | 36 | */ |
| 37 | 37 | public final class FencedBlockExtension extends HtmlRendererAdapter { |
| 38 | private final static String TEMP_DIR = System.getProperty( "java.io.tmpdir" ); | |
| 39 | ||
| 40 | /** | |
| 41 | * Ensure that the device is always closed to prevent an out-of-resources | |
| 42 | * error, regardless of whether the R expression the user tries to evaluate | |
| 43 | * is valid by swallowing errors alongside a {@code finally} block. | |
| 44 | */ | |
| 45 | private final static String R_SVG_EXPORT = | |
| 46 | "tryCatch({svg('%s')%n%s%n},finally={dev.off()})%n"; | |
| 47 | ||
| 38 | 48 | private final static String STYLE_DIAGRAM = "diagram-"; |
| 39 | 49 | private final static int STYLE_DIAGRAM_LEN = STYLE_DIAGRAM.length(); |
| ... | ||
| 178 | 188 | final var text = mRVariableProcessor.apply( content ); |
| 179 | 189 | final var hash = Integer.toHexString( text.hashCode() ); |
| 180 | final var temp = System.getProperty( "java.io.tmpdir" ); | |
| 181 | final var file = format( "%s-%s.svg", APP_TITLE_LOWERCASE, hash ); | |
| 182 | final var source = Paths.get( temp, file ).toString(); | |
| 183 | final var link = context.resolveLink( LINK, source, false ); | |
| 184 | final var r = format( "svg('%s')%n%s%ndev.off()%n", source, text ); | |
| 190 | final var filename = format( "%s-%s.svg", APP_TITLE_LOWERCASE, hash ); | |
| 191 | final var svg = Paths.get( TEMP_DIR, filename ).toString(); | |
| 192 | final var link = context.resolveLink( LINK, svg, false ); | |
| 193 | final var r = format( R_SVG_EXPORT, svg, text ); | |
| 185 | 194 | final var result = mRChunkEvaluator.apply( r ); |
| 186 | 195 | |
| 187 | return new Pair<>( source, link ); | |
| 196 | return new Pair<>( svg, link ); | |
| 188 | 197 | } |
| 189 | 198 | |
| 1 | package com.keenwrite.io; | |
| 2 | ||
| 3 | import org.apache.commons.vfs2.FileSystemException; | |
| 4 | import org.junit.jupiter.api.Disabled; | |
| 5 | import org.renjin.eval.SessionBuilder; | |
| 6 | ||
| 7 | import java.io.IOException; | |
| 8 | import java.io.OutputStreamWriter; | |
| 9 | ||
| 10 | import static java.io.File.separator; | |
| 11 | import static java.lang.String.format; | |
| 12 | import static java.nio.charset.StandardCharsets.UTF_8; | |
| 13 | ||
| 14 | /** | |
| 15 | * Tests file resource allocation. | |
| 16 | */ | |
| 17 | public class FileObjectTest { | |
| 18 | private final static String TEMP_DIR = System.getProperty( "java.io.tmpdir" ); | |
| 19 | ||
| 20 | /** | |
| 21 | * Test that resources are not exhausted. | |
| 22 | * | |
| 23 | * Disabled because no issue was found and this test thrashes the I/O. | |
| 24 | */ | |
| 25 | @Disabled | |
| 26 | void test_Open_MultipleFiles_NoResourcesExpire() throws FileSystemException { | |
| 27 | final var builder = new SessionBuilder(); | |
| 28 | final var session = builder.build(); | |
| 29 | ||
| 30 | for( int i = 0; i < 10000; i++ ) { | |
| 31 | final var filename = format( "%s%s%d.txt", TEMP_DIR, separator, i ); | |
| 32 | final var fileObject = session | |
| 33 | .getFileSystemManager() | |
| 34 | .resolveFile( filename ); | |
| 35 | ||
| 36 | try( | |
| 37 | final var stream = fileObject.getContent().getOutputStream(); | |
| 38 | final var writer = new OutputStreamWriter( stream, UTF_8 ) ) { | |
| 39 | writer.write( "contents" ); | |
| 40 | } catch( final IOException e ) { | |
| 41 | throw new FileSystemException( e ); | |
| 42 | } | |
| 43 | ||
| 44 | fileObject.delete(); | |
| 45 | } | |
| 46 | } | |
| 47 | } | |
| 1 | 48 |