Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Add setting to toggle resize behaviour

AuthorDaveJarvis <email>
Date2021-05-12 23:14:21 GMT-0700
Commit365676183c807ad186ba2ac6d02805687ee0084d
Parent535fe60
Delta20 lines added, 15 lines removed, 5-line increase
src/main/resources/com/keenwrite/messages.properties
workspace.images.order.desc=Preferred order of image file types to embed, separated by spaces.
workspace.images.order.title=Extensions
+workspace.images.resize=Resize
+workspace.images.resize.desc=Scale images to fit the preview panel when resizing, automatically.
+workspace.images.resize.title=Resize
workspace.definition=Variable
src/main/java/com/keenwrite/preview/HtmlPreview.java
/**
- * The order is important: Swing factory will replace SVG images with
- * a blank image, which will cause the chained factory to cache the image
- * and exit. Instead, the SVG must execute first to rasterize the content.
- * Consequently, the chained factory must maintain insertion order.
- */
- private static final ChainedReplacedElementFactory sFactory
- = new ChainedReplacedElementFactory(
- new SvgReplacedElementFactory(),
- new SwingReplacedElementFactory()
- );
-
- /**
* Used to populate the {@link #HTML_HEAD} with stylesheet file references.
*/
private static final URL HTML_STYLE_PREVIEW = toUrl( STYLESHEET_PREVIEW );
+
+ /**
+ * The order is important: Swing factory will replace SVG images with
+ * a blank image, which will cause the chained factory to cache the image
+ * and exit. Instead, the SVG must execute first to rasterize the content.
+ * Consequently, the chained factory must maintain insertion order.
+ */
+ private final ChainedReplacedElementFactory mFactory;
/**
public HtmlPreview( final Workspace workspace ) {
mWorkspace = workspace;
+ mFactory = new ChainedReplacedElementFactory(
+ mWorkspace,
+ new SvgReplacedElementFactory(),
+ new SwingReplacedElementFactory()
+ );
// Attempts to prevent a flash of black un-styled content upon load.
setCacheHint( SPEED );
setContent( wrapper );
- wrapper.addComponentListener( sFactory );
+ wrapper.addComponentListener( mFactory );
final var context = mView.getSharedContext();
final var textRenderer = context.getTextRenderer();
- context.setReplacedElementFactory( sFactory );
+ context.setReplacedElementFactory( mFactory );
textRenderer.setSmoothingThreshold( 0 );
*/
public void refresh() {
- sFactory.clearCache();
+ mFactory.clearCache();
rerender();
}
src/main/java/com/keenwrite/preferences/WorkspaceKeys.java
public static final Key KEY_IMAGES_DIR = key( KEY_IMAGES, "dir" );
public static final Key KEY_IMAGES_ORDER = key( KEY_IMAGES, "order" );
+ public static final Key KEY_IMAGES_RESIZE = key( KEY_IMAGES, "resize" );
public static final Key KEY_DEF = key( KEY_ROOT, "definition" );