summaryrefslogtreecommitdiff
path: root/android/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'android/src/com')
-rw-r--r--android/src/com/artifex/mupdf/MuPDFCore.java39
-rw-r--r--android/src/com/artifex/mupdf/TextChar.java12
-rw-r--r--android/src/com/artifex/mupdf/TextWord.java17
3 files changed, 68 insertions, 0 deletions
diff --git a/android/src/com/artifex/mupdf/MuPDFCore.java b/android/src/com/artifex/mupdf/MuPDFCore.java
index 15c90e17..2785664f 100644
--- a/android/src/com/artifex/mupdf/MuPDFCore.java
+++ b/android/src/com/artifex/mupdf/MuPDFCore.java
@@ -1,4 +1,6 @@
package com.artifex.mupdf;
+import java.util.ArrayList;
+
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.PointF;
@@ -33,6 +35,7 @@ public class MuPDFCore
int patchX, int patchY,
int patchW, int patchH);
private native RectF[] searchPage(String text);
+ private native TextChar[][][][] text();
private native int passClickEventInternal(int page, float x, float y);
private native void setFocusedWidgetChoiceSelectedInternal(String [] selected);
private native String [] getFocusedWidgetChoiceSelected();
@@ -185,6 +188,42 @@ public class MuPDFCore
return searchPage(text);
}
+ public synchronized TextWord [][] textLines(int page) {
+ gotoPage(page);
+ TextChar[][][][] chars = text();
+
+ // The text of the page held in a hierarchy (blocks, lines, spans).
+ // Currently we don't need to distinguish the blocks level or
+ // the spans, and we need to collect the text into words.
+ ArrayList<TextWord[]> lns = new ArrayList<TextWord[]>();
+
+ for (TextChar[][][] bl: chars) {
+ for (TextChar[][] ln: bl) {
+ ArrayList<TextWord> wds = new ArrayList<TextWord>();
+ TextWord wd = new TextWord();
+
+ for (TextChar[] sp: ln) {
+ for (TextChar tc: sp) {
+ if (tc.c != ' ') {
+ wd.Add(tc);
+ } else if (wd.w.length() > 0) {
+ wds.add(wd);
+ wd = new TextWord();
+ }
+ }
+ }
+
+ if (wd.w.length() > 0)
+ wds.add(wd);
+
+ if (wds.size() > 0)
+ lns.add(wds.toArray(new TextWord[wds.size()]));
+ }
+ }
+
+ return lns.toArray(new TextWord[lns.size()][]);
+ }
+
public synchronized boolean hasOutline() {
return hasOutlineInternal();
}
diff --git a/android/src/com/artifex/mupdf/TextChar.java b/android/src/com/artifex/mupdf/TextChar.java
new file mode 100644
index 00000000..f51f8b5f
--- /dev/null
+++ b/android/src/com/artifex/mupdf/TextChar.java
@@ -0,0 +1,12 @@
+package com.artifex.mupdf;
+
+import android.graphics.RectF;
+
+public class TextChar extends RectF {
+ public char c;
+
+ public TextChar(float x0, float y0, float x1, float y1, char _c) {
+ super(x0, y0, x1, y1);
+ c = _c;
+ }
+}
diff --git a/android/src/com/artifex/mupdf/TextWord.java b/android/src/com/artifex/mupdf/TextWord.java
new file mode 100644
index 00000000..9b1570f4
--- /dev/null
+++ b/android/src/com/artifex/mupdf/TextWord.java
@@ -0,0 +1,17 @@
+package com.artifex.mupdf;
+
+import android.graphics.RectF;
+
+public class TextWord extends RectF {
+ public String w;
+
+ public TextWord() {
+ super();
+ w = new String();
+ }
+
+ public void Add(TextChar tc) {
+ super.union(tc);
+ w = w.concat(new String(new char[]{tc.c}));
+ }
+}