use of org.ebookdroid.droids.mupdf.codec.TextWord in project LibreraReader by foobnix.
the class Page method findText.
public static List<TextWord> findText(String text, TextWord[][] texts) {
List<TextWord> result = new ArrayList<TextWord>();
if (texts == null) {
return result;
}
text = text.toLowerCase(Locale.US);
int index = 0;
List<TextWord> find = new ArrayList<TextWord>();
boolean nextWorld = false;
String firstPart = "";
TextWord firstWord = null;
for (final TextWord[] lines : texts) {
find.clear();
index = 0;
for (final TextWord word : lines) {
if (AppState.get().selectingByLetters) {
String it = String.valueOf(text.charAt(index));
if (word.w.toLowerCase(Locale.US).equals(it)) {
index++;
find.add(word);
} else {
index = 0;
find.clear();
}
if (index == text.length()) {
index = 0;
for (TextWord t : find) {
result.add(t);
}
}
} else if (word.w.toLowerCase(Locale.US).contains(text)) {
result.add(word);
} else if (word.w.length() >= 3 && word.w.endsWith("-")) {
nextWorld = true;
firstWord = word;
firstPart = word.w.replace("-", "");
} else if (nextWorld && (firstPart + word.w.toLowerCase(Locale.US)).contains(text)) {
result.add(firstWord);
result.add(word);
nextWorld = false;
firstWord = null;
firstPart = "";
} else if (nextWorld && TxtUtils.isNotEmpty(word.w)) {
nextWorld = false;
firstWord = null;
}
}
}
return result;
}
use of org.ebookdroid.droids.mupdf.codec.TextWord in project LibreraReader by foobnix.
the class VerticalModeController method underlineText.
@Override
public void underlineText(int color, float width, AnnotationType type) {
if (ctr == null || ctr.getDocumentController() == null || ctr.getDocumentModel() == null) {
LOG.d("Can't underlineText");
return;
}
final int first = ctr.getDocumentController().getFirstVisiblePage();
final int last = ctr.getDocumentController().getLastVisiblePage();
for (int i = first; i < last + 1; i++) {
final Page page = ctr.getDocumentModel().getPageByDocIndex(i);
if (page == null || page.selectedText == null) {
continue;
}
List<TextWord> texts = page.selectedText;
final ArrayList<PointF> quadPoints = new ArrayList<PointF>();
for (TextWord text : texts) {
RectF rect = text.getOriginal();
quadPoints.add(new PointF(rect.left, rect.bottom));
quadPoints.add(new PointF(rect.right, rect.bottom));
quadPoints.add(new PointF(rect.right, rect.top));
quadPoints.add(new PointF(rect.left, rect.top));
}
PointF[] array = quadPoints.toArray(new PointF[quadPoints.size()]);
ctr.getDecodeService().underlineText(i, array, color, type, new ResultResponse<List<Annotation>>() {
@Override
public boolean onResultRecive(List<Annotation> arg0) {
page.annotations = arg0;
page.selectedText = new ArrayList<TextWord>();
ctr.getDocumentController().toggleRenderingEffects();
return false;
}
});
}
}
use of org.ebookdroid.droids.mupdf.codec.TextWord in project LibreraReader by foobnix.
the class PageImaveView method selectText.
public String selectText(float x1, float y1, float xInit, float yInit) {
if (!AppState.get().isDouble && getPageText(0) == null) {
LOG.d("get pag No page text", pageNumber);
return null;
}
boolean single = Math.abs(x1 - xInit) < MIN && Math.abs(y1 - yInit) < MIN;
RectF tr = new RectF();
imageMatrix().mapRect(tr);
float x = x1 - tr.left;
float y = y1 - tr.top;
xInit = xInit - tr.left;
yInit = yInit - tr.top;
float[] f = new float[9];
imageMatrix().getValues(f);
float scaleX = f[Matrix.MSCALE_X];
x = x / scaleX;
y = y / scaleX;
xInit = xInit / scaleX;
yInit = yInit / scaleX;
RectF tapRect = new RectF(xInit, yInit, x, y);
if (yInit > y) {
tapRect.sort();
}
PageImageState.get().cleanSelectedWords();
StringBuilder build = new StringBuilder();
boolean isHyphenWorld = false;
TextWord prevWord = null;
int firstNumber = 0;
if (AppState.get().isDouble) {
firstNumber = xInit < drawableWidth / 2 ? 1 : 2;
}
TempHolder.get().textFromPage = firstNumber;
LOG.d("firstNumber", firstNumber);
TextWord[][] pageText = getPageText(firstNumber);
if (pageText == null) {
return null;
}
for (TextWord[] line : pageText) {
if (line == null) {
continue;
}
final TextWord[] current = line;
for (TextWord textWord : current) {
if (textWord == null) {
continue;
}
if (textWord.left <= 0 || textWord.top <= 0) {
continue;
}
RectF wordRect = transform(textWord, firstNumber);
if (single) {
boolean intersects = RectF.intersects(wordRect, tapRect);
if (intersects || isHyphenWorld) {
LOG.d("ADD TEXT", textWord);
if (prevWord != null && prevWord.w.endsWith("-") && !isHyphenWorld) {
build.append(prevWord.w.replace("-", ""));
PageImageState.get().addWord(pageNumber, prevWord);
}
if (!isHyphenWorld) {
PageImageState.get().addWord(pageNumber, textWord);
}
if (isHyphenWorld && TxtUtils.isNotEmpty(textWord.getWord())) {
PageImageState.get().addWord(pageNumber, textWord);
isHyphenWorld = false;
}
if (textWord.getWord().endsWith("-")) {
isHyphenWorld = true;
}
build.append(textWord.getWord() + " ");
}
} else {
if (y > yInit) {
if (wordRect.top < tapRect.top && wordRect.bottom > tapRect.top && wordRect.right > tapRect.left) {
PageImageState.get().addWord(pageNumber, textWord);
build.append(textWord.getWord() + TxtUtils.space());
} else if (wordRect.top < tapRect.bottom && wordRect.bottom > tapRect.bottom && wordRect.left < tapRect.right) {
PageImageState.get().addWord(pageNumber, textWord);
build.append(textWord.getWord() + TxtUtils.space());
} else if (wordRect.top > tapRect.top && wordRect.bottom < tapRect.bottom) {
PageImageState.get().addWord(pageNumber, textWord);
build.append(textWord.getWord() + TxtUtils.space());
}
} else if (RectF.intersects(wordRect, tapRect)) {
PageImageState.get().addWord(pageNumber, textWord);
if (AppState.get().selectingByLetters) {
build.append(textWord.w);
} else {
build.append(textWord.w.trim() + " ");
}
}
}
if (TxtUtils.isNotEmpty(textWord.w)) {
prevWord = textWord;
}
}
String k;
if (AppState.get().selectingByLetters && current.length >= 2 && !(k = current[current.length - 1].getWord()).equals(" ") && !k.equals("-")) {
build.append(" ");
}
}
String txt = TxtUtils.filterString(build.toString());
AppState.get().selectedText = txt;
invalidate();
return txt;
}
use of org.ebookdroid.droids.mupdf.codec.TextWord in project LibreraReader by foobnix.
the class PageImaveView method getPageText.
public TextWord[][] getPageText(int number) {
try {
if (AppState.get().isDouble && number != 0) {
int page = pageNumber * 2;
if (AppState.get().isDoubleCoverAlone) {
page--;
}
TextWord[][] t = null;
if (number == 1) {
t = PageImageState.get().pagesText.get(page);
} else if (number == 2) {
t = PageImageState.get().pagesText.get(page + 1);
}
for (int i = 0; i < t.length; i++) {
for (int j = 0; j < t[i].length; j++) {
TextWord textWord = t[i][j];
textWord.number = number;
t[i][j] = textWord;
}
}
return t;
} else {
return PageImageState.get().pagesText.get(pageNumber);
}
} catch (Exception e) {
LOG.e(e);
return null;
}
}
Aggregations