Search in sources :

Example 1 with PageLink

use of org.ebookdroid.core.codec.PageLink in project LibreraReader by foobnix.

the class AbstractViewController method getLinkPage.

public int getLinkPage(final float x, final float y) {
    final float zoom = base.getZoomModel().getZoom();
    final RectF rect = new RectF(x, y, x, y);
    rect.offset(getScrollX(), getScrollY());
    for (final Page page : model.getPages(firstVisiblePage, lastVisiblePage + 1)) {
        final RectF bounds = page.getBounds(zoom);
        if (RectF.intersects(bounds, rect)) {
            if (LengthUtils.isNotEmpty(page.links)) {
                for (final PageLink link : page.links) {
                    final RectF linkRect = page.getLinkSourceRect(bounds, link);
                    if (linkRect == null || !RectF.intersects(linkRect, rect)) {
                        return -1;
                    }
                    if (link != null) {
                        return link.targetPage;
                    }
                }
            }
            return -1;
        }
    }
    return -1;
}
Also used : RectF(android.graphics.RectF) PageLink(org.ebookdroid.core.codec.PageLink)

Example 2 with PageLink

use of org.ebookdroid.core.codec.PageLink in project LibreraReader by foobnix.

the class AbstractViewController method processLongTap.

public final String processLongTap(boolean single, final MotionEvent e1, final MotionEvent e2, boolean draw) {
    if (e1 != null) {
        xLong = e1.getX();
        yLong = e1.getY();
    }
    float x2 = e2.getX();
    float y2 = e2.getY();
    final float zoom = base.getZoomModel().getZoom();
    final RectF tapRect = new RectF(xLong, yLong, x2, y2);
    if (yLong > y2) {
        tapRect.sort();
    }
    tapRect.offset(getScrollX(), getScrollY());
    StringBuilder build = new StringBuilder();
    boolean isHyphenWorld = false;
    LOG.d("Add Word page", "----", firstVisiblePage, lastVisiblePage + 1);
    for (final Page page : model.getPages(firstVisiblePage, lastVisiblePage + 1)) {
        if (draw)
            page.selectedText.clear();
        LOG.d("Add Word page", page.hashCode());
        final RectF bounds = page.getBounds(zoom);
        TextWord prevWord = null;
        if (RectF.intersects(bounds, tapRect)) {
            if (LengthUtils.isNotEmpty(page.texts)) {
                for (final TextWord[] lines : page.texts) {
                    final TextWord[] current = lines;
                    for (final TextWord line : current) {
                        if (line.left <= 0 || line.top <= 0) {
                            continue;
                        }
                        RectF wordRect = page.getPageRegion(bounds, line);
                        if (wordRect == null) {
                            continue;
                        }
                        if (isHyphenWorld || (single && RectF.intersects(wordRect, tapRect))) {
                            if (prevWord != null && prevWord.w.endsWith("-") && !isHyphenWorld) {
                                build.append(prevWord.w.replace("-", ""));
                                if (draw)
                                    page.selectedText.add(prevWord);
                            }
                            build.append(line.w + " ");
                            if (!isHyphenWorld) {
                                if (draw)
                                    page.selectedText.add(line);
                            }
                            LOG.d("Add Word", line.w);
                            if (isHyphenWorld && TxtUtils.isNotEmpty(line.w)) {
                                if (draw)
                                    page.selectedText.add(line);
                                isHyphenWorld = false;
                            }
                            if (line.w.endsWith("-")) {
                                isHyphenWorld = true;
                            }
                            // get links
                            if (LengthUtils.isNotEmpty(page.links)) {
                                for (final PageLink link : page.links) {
                                    final RectF linkRect = page.getLinkSourceRect(bounds, link);
                                    if (linkRect == null) {
                                        continue;
                                    }
                                    if (RectF.intersects(linkRect, wordRect)) {
                                        TempHolder.get().linkPage = link.targetPage;
                                    }
                                }
                            }
                        } else if (!single) {
                            if (y2 > yLong) {
                                if (wordRect.top < tapRect.top && wordRect.bottom > tapRect.top && wordRect.right > tapRect.left) {
                                    if (draw)
                                        page.selectedText.add(line);
                                    build.append(line.w + TxtUtils.space());
                                    LOG.d("Add Word", line.w);
                                } else if (wordRect.top < tapRect.bottom && wordRect.bottom > tapRect.bottom && wordRect.left < tapRect.right) {
                                    if (draw)
                                        page.selectedText.add(line);
                                    build.append(line.w + TxtUtils.space());
                                    LOG.d("Add Word", line.w);
                                } else if (wordRect.top > tapRect.top && wordRect.bottom < tapRect.bottom) {
                                    if (draw)
                                        page.selectedText.add(line);
                                    build.append(line.w + TxtUtils.space());
                                    LOG.d("Add Word", line.w);
                                }
                            } else if (RectF.intersects(wordRect, tapRect)) {
                                if (draw)
                                    page.selectedText.add(line);
                                if (AppState.get().selectingByLetters) {
                                    build.append(line.w);
                                } else {
                                    build.append(line.w.trim() + " ");
                                }
                                LOG.d("Add Word", line.w);
                            }
                        }
                        if (TxtUtils.isNotEmpty(line.w)) {
                            prevWord = line;
                        }
                    }
                    String k;
                    if (AppState.get().selectingByLetters && current.length >= 2 && !(k = current[current.length - 1].getWord()).equals(" ") && !k.equals("-")) {
                        build.append(" ");
                    }
                }
            }
        }
    }
    if (build.length() > 0) {
        redrawView();
        String filterString = TxtUtils.filterString(build.toString());
        LOG.d("Add Word SELECT TEXT", filterString);
        return filterString;
    }
    return null;
}
Also used : RectF(android.graphics.RectF) PageLink(org.ebookdroid.core.codec.PageLink) TextWord(org.ebookdroid.droids.mupdf.codec.TextWord)

Example 3 with PageLink

use of org.ebookdroid.core.codec.PageLink in project LibreraReader by foobnix.

the class EventDraw method drawPageLinks.

private void drawPageLinks(final Page page) {
    if (LengthUtils.isEmpty(page.links)) {
        return;
    }
    for (final PageLink link : page.links) {
        final RectF rect = page.getLinkSourceRect(pageBounds, link);
        if (rect != null) {
            rect.offset(-viewState.viewBase.x, -viewState.viewBase.y);
            final Paint p = new Paint();
            p.setColor(Color.MAGENTA);
            p.setAlpha(40);
            canvas.drawRect(rect, p);
        }
    }
}
Also used : RectF(android.graphics.RectF) PageLink(org.ebookdroid.core.codec.PageLink) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 4 with PageLink

use of org.ebookdroid.core.codec.PageLink in project LibreraReader by foobnix.

the class MuPdfLinks method getPageLinks.

static List<PageLink> getPageLinks(final long docHandle, final long pageHandle, final RectF pageBounds) {
    final List<PageLink> links = new ArrayList<PageLink>();
    for (long linkHandle = getFirstPageLink(docHandle, pageHandle); linkHandle != 0; linkHandle = getNextPageLink(linkHandle)) {
        final PageLink link = new PageLink();
        LOG.d("LINK GET", docHandle, linkHandle);
        final int type = getPageLinkType(docHandle, linkHandle);
        if (type == 1) {
            // external
            link.url = getPageLinkUrl(linkHandle);
            if (fillPageLinkSourceRect(linkHandle, temp)) {
                link.sourceRect = new RectF();
                link.sourceRect.left = (temp[0] - pageBounds.left) / pageBounds.width();
                link.sourceRect.top = (temp[1] - pageBounds.top) / pageBounds.height();
                link.sourceRect.right = (temp[2] - pageBounds.left) / pageBounds.width();
                link.sourceRect.bottom = (temp[3] - pageBounds.top) / pageBounds.height();
            }
            links.add(link);
        } else if (type == 0) {
            // internal
            if (fillPageLinkSourceRect(linkHandle, temp)) {
                link.sourceRect = new RectF();
                link.sourceRect.left = (temp[0] - pageBounds.left) / pageBounds.width();
                link.sourceRect.top = (temp[1] - pageBounds.top) / pageBounds.height();
                link.sourceRect.right = (temp[2] - pageBounds.left) / pageBounds.width();
                link.sourceRect.bottom = (temp[3] - pageBounds.top) / pageBounds.height();
            }
            try {
                link.targetPage = getPageLinkTargetPage(docHandle, linkHandle);
            // link.targetPage--;
            } catch (Exception e) {
                link.targetPage = -1;
            }
            links.add(link);
        }
        LOG.d("LINK DROP", docHandle, linkHandle);
    // dropLink(docHandle, linkHandle);
    }
    return links;
}
Also used : RectF(android.graphics.RectF) PageLink(org.ebookdroid.core.codec.PageLink) ArrayList(java.util.ArrayList)

Example 5 with PageLink

use of org.ebookdroid.core.codec.PageLink in project LibreraReader by foobnix.

the class AbstractViewController method processLinkTap.

protected final boolean processLinkTap(final float x, final float y) {
    final float zoom = base.getZoomModel().getZoom();
    final RectF rect = new RectF(x, y, x, y);
    rect.offset(getScrollX(), getScrollY());
    for (final Page page : model.getPages(firstVisiblePage, lastVisiblePage + 1)) {
        final RectF bounds = page.getBounds(zoom);
        if (RectF.intersects(bounds, rect)) {
            if (LengthUtils.isNotEmpty(page.links)) {
                for (final PageLink link : page.links) {
                    if (processLinkTap(page, link, bounds, rect)) {
                        return true;
                    }
                }
            }
            return false;
        }
    }
    return false;
}
Also used : RectF(android.graphics.RectF) PageLink(org.ebookdroid.core.codec.PageLink)

Aggregations

PageLink (org.ebookdroid.core.codec.PageLink)7 RectF (android.graphics.RectF)6 Paint (android.graphics.Paint)1 TextPaint (android.text.TextPaint)1 ArrayList (java.util.ArrayList)1 TextWord (org.ebookdroid.droids.mupdf.codec.TextWord)1