summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2016-07-13 03:14:15 +0800
committerSebastian Rasmussen <sebras@gmail.com>2016-07-15 02:22:21 +0800
commitbd3988a1a64348496b770ab94f22bb6c8f5e3ae5 (patch)
tree60ab5d0e41f28429806daee371e3bf757dc9331c
parent48b7d735af8b5e38e6930df4174187e7f88d9b8d (diff)
downloadmupdf-bd3988a1a64348496b770ab94f22bb6c8f5e3ae5.tar.xz
Support changing reflowable font size in JNI sample viewer.
Also fix bug in sample java viewer where zoom caused an Exception.
-rw-r--r--platform/java/example/PageCanvas.java12
-rw-r--r--platform/java/example/Viewer.java39
2 files changed, 43 insertions, 8 deletions
diff --git a/platform/java/example/PageCanvas.java b/platform/java/example/PageCanvas.java
index 29f98a18..cca57dc5 100644
--- a/platform/java/example/PageCanvas.java
+++ b/platform/java/example/PageCanvas.java
@@ -68,13 +68,17 @@ public class PageCanvas extends java.awt.Canvas
}
public void zoomIn() {
- mScale += 0.25f;
- run();
+ if (mScale < 10) {
+ mScale += 0.25f;
+ run();
+ }
}
public void zoomOut() {
- mScale -= 0.25f;
- run();
+ if (mScale > 0.25f) {
+ mScale -= 0.25f;
+ run();
+ }
}
public void paint(Graphics g)
diff --git a/platform/java/example/Viewer.java b/platform/java/example/Viewer.java
index c158c42d..d70a82e3 100644
--- a/platform/java/example/Viewer.java
+++ b/platform/java/example/Viewer.java
@@ -29,9 +29,12 @@ public class Viewer extends Frame implements WindowListener, ActionListener
protected Panel toolbar;
protected PageCanvas pageCanvas;
protected Label pageLabel;
- protected Button firstButton, prevButton, nextButton, lastButton, zoomInButton, zoomOutButton;
+ protected Button firstButton, prevButton, nextButton, lastButton, zoomInButton, zoomOutButton, fontIncButton, fontDecButton;
protected int pageCount;
protected int pageNumber;
+ protected int layoutWidth;
+ protected int layoutHeight;
+ protected int layoutEm;
private float retinaScale;
@@ -45,7 +48,11 @@ public class Viewer extends Frame implements WindowListener, ActionListener
pageCount = doc.countPages();
pageNumber = 0;
- setSize(1200, 900);
+ layoutWidth = 1200;
+ layoutHeight = 800;
+ layoutEm = 12;
+
+ setSize(layoutWidth, layoutHeight + 100);
setTitle("MuPDF: " + doc.getMetaData(Document.META_INFO_TITLE));
toolbar = new Panel();
@@ -62,6 +69,14 @@ public class Viewer extends Frame implements WindowListener, ActionListener
zoomInButton.addActionListener(this);
zoomOutButton = new Button("-");
zoomOutButton.addActionListener(this);
+
+ if (doc.isReflowable()) {
+ fontIncButton = new Button("FONT");
+ fontIncButton.addActionListener(this);
+ fontDecButton = new Button("font");
+ fontDecButton.addActionListener(this);
+ }
+
pageLabel = new Label();
toolbar.add(firstButton);
@@ -70,6 +85,10 @@ public class Viewer extends Frame implements WindowListener, ActionListener
toolbar.add(lastButton);
toolbar.add(zoomInButton);
toolbar.add(zoomOutButton);
+ if (doc.isReflowable()) {
+ toolbar.add(fontIncButton);
+ toolbar.add(fontDecButton);
+ }
toolbar.add(pageLabel);
add(toolbar, BorderLayout.NORTH);
@@ -91,6 +110,7 @@ public class Viewer extends Frame implements WindowListener, ActionListener
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
int oldPageNumber = pageNumber;
+ int oldLayoutEm = layoutEm;
if (source == firstButton)
pageNumber = 0;
@@ -109,6 +129,12 @@ public class Viewer extends Frame implements WindowListener, ActionListener
if (pageNumber >= pageCount)
pageNumber = pageCount - 1;
}
+ if (doc.isReflowable() && source == fontIncButton) {
+ layoutEm = layoutEm + 1;
+ }
+ if (doc.isReflowable() && source == fontDecButton) {
+ layoutEm = layoutEm - 1;
+ }
if (source == zoomInButton) {
pageCanvas.zoomIn();
@@ -118,7 +144,10 @@ public class Viewer extends Frame implements WindowListener, ActionListener
pageCanvas.zoomOut();
}
- if (pageNumber != oldPageNumber)
+ if (layoutEm != oldLayoutEm)
+ doc.layout(layoutWidth, layoutHeight, layoutEm);
+
+ if (pageNumber != oldPageNumber || layoutEm != oldLayoutEm)
stuff();
}
@@ -141,7 +170,7 @@ public class Viewer extends Frame implements WindowListener, ActionListener
{
public String getDescription()
{
- return "Supported files (*.pdf, *,xps, *.jpg, *.jpeg, *.png, *.epub, *.cbz, *.cbr)";
+ return "Supported files (*.pdf, *,xps, *.jpg, *.jpeg, *.png, *.epub, *.cbz, *.cbr, *.epub)";
}
public boolean accept(File f)
@@ -166,6 +195,8 @@ public class Viewer extends Frame implements WindowListener, ActionListener
return true;
if (filename.endsWith(".cbr"))
return true;
+ if (filename.endsWith(".epub"))
+ return true;
return false;
}