diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2013-01-10 14:40:32 +0000 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2013-01-10 14:40:32 +0000 |
commit | 5ffe63ad521dc71b33d9c280ad108ca495a450d1 (patch) | |
tree | 3a61e8afd0046b30d961a844581cec4acf3f7822 /android/src/com | |
parent | 9ed0aa9c0b4dce36530f41f950e94bfe4d9133bc (diff) | |
download | mupdf-5ffe63ad521dc71b33d9c280ad108ca495a450d1.tar.xz |
Android: add core method returning the words on a page
Diffstat (limited to 'android/src/com')
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFCore.java | 39 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/TextChar.java | 12 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/TextWord.java | 17 |
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})); + } +} |