Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git
src/main/java/com/keenwrite/preview/ImageReplacedElementFactory.java
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.text.ParseException;
return createElement( raster );
} catch( final Exception ex ) {
- clue( "Main.status.image.request.error.rasterize", ex );
+ clue( "Main.status.image.request.error.create", ex );
}
if( raster == null && mediaType.isImage() ) {
uri = resolve( source, uac, e );
- final var path = Path.of( uri.getPath() );
+
+ final var path = Paths.get( uri );
try( final var stream = Files.newInputStream( path ) ) {
raster = ImageIO.read( stream );
}
}
+
+ // Image path resolved; image rendered successfully.
+ clue();
return raster;
}
+ /**
+ * Attempt to rasterize based on file name.
+ *
+ * @param source The source URI from the document.
+ * @param uac A callback for retrieving the image resource.
+ * @param e The HTML element containing a reference to a file.
+ * @return The resolved URI to the file.
+ * @throws URISyntaxException Could not resolve URI.
+ */
private static URI resolve(
final String source,
final UserAgentCallback uac,
final Element e )
throws URISyntaxException {
- // Attempt to rasterize based on file name.
- final var baseUri = new URI( uac.getBaseURL() );
- final var path = baseUri.resolve( source ).normalize();
+ final var nSource = source.replaceAll( "\\\\", "/" );
- if( path.isAbsolute() ) {
- return path;
- }
- else {
- final var base = new URI( e.getBaseURI() ).getPath();
- return Path.of( base, source ).toUri();
+ try {
+ final var baseUri = new URI( uac.getBaseURL() );
+ final var resolved = baseUri.resolve( nSource );
+ final var path = resolved.normalize();
+ clue( "Main.status.image.request.resolve", path );
+
+ return path.isAbsolute() ? path : resolve( nSource, e );
+ } catch( final Exception ex ) {
+ clue( "Main.status.image.request.error.resolve", nSource );
+ throw new URISyntaxException( nSource, ex.getMessage() );
}
+ }
+
+ private static URI resolve( final String source, final Element e )
+ throws URISyntaxException {
+ final var base = new URI( e.getBaseURI() ).getPath();
+ return Path.of( base, source ).toUri();
}
src/main/resources/com/keenwrite/messages.properties
Main.status.image.request.fetch=Downloaded image ''{0}''
Main.status.image.request.success=Determined content type ''{0}''
+Main.status.image.request.resolve=Resolved image path: ''{0}''
Main.status.image.request.error.media=No media type for ''{0}''
Main.status.image.request.error.cert=Could not accept certificate for ''{0}''
-Main.status.image.request.error.rasterize=Rasterizer could not parse SVG image
+Main.status.image.request.error.create=Could not create image for preview document
+Main.status.image.request.error.resolve=Could not resolve image path: ''{0}''
Main.status.image.xhtml.image.download=Downloading ''{0}''

Fixes SVG image handling on Windows

Author DaveJarvis <email>
Date 2023-12-19 13:38:21 GMT-0800
Commit b26d4662fcfa5fd1dd8a4d1191e736b22778ce94
Parent cf01bd3
Delta 36 lines added, 12 lines removed, 24-line increase