简体   繁体   English

转到epub阅读器中的Page(PageTurner)

[英]Go to Page in epub reader (PageTurner)

I have to implement Go To Page feature in epub reader. 我必须在epub阅读器中实现Go To Page功能。 I have try to implement this feature in source code of Page-Turner , but its not working successfully because of multiple xhtml in .epub file, as we know that each chapter have single xhtml file and its divide as per screen size in this app. 我尝试在Page-Turner的源代码中实现此功能,但由于.epub文件中存在多个xhtml,因此无法成功运行,因为我们知道每个章节都有单个xhtml文件,并且在此应用程序中按照屏幕大小划分。 So whenever screen size is big then total number of pages are less and more number of pages when screen is small, So there is no fix page number where to jump. 因此,每当屏幕尺寸较大时,当屏幕较小时,总页数就会越来越少,因此没有固定页码可以跳转到哪里。 I have edit and try to implement like giver below. 我编辑并尝试实现如下的给予者。

ReadingFragment.java ReadingFragment.java

public void performSearch(String query) {

    int index = Integer.parseInt(query);

    if (index > bookView.getTotalNumberOfPages()) {
        Toast.makeText(context, "Please enter number between 0 to " + bookView.getTotalNumberOfPages(), Toast.LENGTH_SHORT).show();
    } else {
        bookView.gotoPageNumber(index);
    }
}

BookView.java BookView.java

public void gotoPageNumber(int pageNum) {
    strategy.gotoPage(pageNum);
    progressUpdate();
}

PageChangeStrategy.java PageChangeStrategy.java

public void gotoPage(int pageNumber);

FixedPagesStrategy.java FixedPagesStrategy.java

@Override
public void gotoPage(int pageNumber) {

    PageTurnerSpine spinePos = bookView.getSpine();

    this.storedPosition = -1;

    int currentPage = getCurrentPage() + spinePos.getUptoPage(spinePos.getPosition());
    Log.e(TAG, "Adding >> Upto Page : " + spinePos.getUptoPage(spinePos.getPosition())
            + ", currentPage :  " + getCurrentPage());
    Log.e(TAG, "pagenum : " + pageNum);

    if (pageNumber > currentPage) {     //pageNumber is greater then current page

        int jumpSpine = spinePos.getIndexFromPage(pageNumber);
        int currentSpine = spinePos.getPosition();
        Log.e(TAG, "jumpSpine : " + jumpSpine + ", currentSpine : " + currentSpine);

        if (jumpSpine == currentSpine) {

            int diffrence = pageNumber - currentPage;
            Log.e(TAG, "diffrence < : " + diffrence);

            Log.e(TAG, "Minimum >> PageOffSets - 1 : " + (spinePos.getPageOffSets(currentSpine) - 1)
                    + ", pageNum + diffrence : " + (pageNum + diffrence));

            this.pageNum = Math.min(pageNum + diffrence, spinePos.getPageOffSets(currentSpine) - 1);
            updatePosition();

        } else {

            PageTurnerSpine spine = bookView.getSpine();

            if (spine == null || !spine.navigateFrontSpine(spine.getIndexFromPage(pageNumber))) {
                return;
            }
            this.pageNum = 0;

            gotoPage(pageNumber);

        }

    } else {                            //pageNumber is less then current page

        int jumpSpine = spinePos.getIndexFromPage(pageNumber);
        int currentSpine = spinePos.getPosition();
        Log.e(TAG, "jumpSpine : " + jumpSpine + ", currentSpine : " + currentSpine);

        if (jumpSpine == currentSpine) {

            int diffrence = currentPage - pageNumber;
            Log.e(TAG, "diffrence > : " + diffrence);

            Log.e(TAG, "pagenum - diffrence : " + (pageNum - diffrence));

            this.pageNum = Math.max(pageNum - diffrence, 0);
            updatePosition();

        } else {

            PageTurnerSpine spine = bookView.getSpine();

            if (spine == null || !spine.navigateBackSpine(spine.getIndexFromPage(pageNumber))) {
                return;
            }
            this.pageNum = 0;

            gotoPage(pageNumber);
        }
    }

    Log.e(TAG, "In last pageNum : " + pageNum);
}

PageTurnerSpine.java PageTurnerSpine.java

public int getIndexFromPage(int pageNumber) {
    int total = 0;
    int totalIndex = 0;

    for (List<Integer> pagesPerSection : pageOffsets) {
        total += pagesPerSection.size();
        totalIndex = totalIndex + 1;
        if (total - 1 >= pageNumber) {
            return totalIndex - 1;
        }
    }
    return 0;
}

public int getUptoPage(int position) {
    int total = 0, max = 0;
    for (List<Integer> pagesPerSection : pageOffsets) {
        max = max + 1;

        if (position == max - 1) {
            return total;
        }
        total += pagesPerSection.size();
    }
    return 0;
}

public int getPageOffSets(int position) {
    int max = 0;
    for (List<Integer> pagesPerSection : pageOffsets) {
        max = max + 1;

        if (position == max - 1) {
            return pagesPerSection.size();
        }
    }
    return 0;
}

public boolean navigateFrontSpine(int indexSpine) {

    if (this.position == size() - 1) {
        return false;
    }

    this.position = indexSpine;
    return true;
}

public boolean navigateBackSpine(int indexSpine) {

    if (this.position == 0) {
        return false;
    }

    this.position = indexSpine;
    return true;
}

When i apply this code and run some time it work correctly. 当我应用此代码并运行一段时间它正常工作。 but some time it jump on other page number, like if i enter 110 then it will jump on 109. and when i am trying to jump on chapter starting page then contain dose not changes. 但是有一段时间它跳到其他页码上,就像我输入110然后它会跳到109.当我试图跳到章节起始页然后包含剂量没有变化。 Please help me. 请帮我。

https://github.com/NightWhistler/PageTurner In this source code i have edited some file given above. https://github.com/NightWhistler/PageTurner在这个源代码中,我编辑了上面给出的一些文件。 they already exists in this project. 它们已经存在于这个项目中。

Mostly i see that most of epub reader like Kindle, FBReader, etc... does not implement Go To Page feature. 大多数情况下,我看到像Kindle,FBReader等大多数epub读者都没有实现Go To Page功能。 So, i want to also know that is it possible to implement this feature or not? 所以,我还想知道是否可以实现此功能?

Thanks for Help :) 感谢帮助 :)

You really need to consult the IDPF Epub standards at IDPF.org/epub . 你真的需要咨询的IDPF电子出版标准IDPF.org/epub

One approach, that I think is optional within the standard (but am not sure about) is to mark the content with the physical page numbers from the paper book (if there is one), or decide on your own numbering system along with your Table of Contents, and use a corresponding virtual page as the start of it. 我认为标准中可选的一种方法(但不确定)是使用纸质书中的物理页码(如果有的话)标记内容,或者与您的表一起决定您自己的编号系统内容,并使用相应的虚拟页面作为它的开始。

This enables going to the start of the same page, but the number of virtual pages per physical page will vary, depending on font sizes etc. currently in use. 这样可以转到同一页面的开头 ,但每个物理页面的虚拟页面数量会有所不同,具体取决于当前使用的字体大小等。

It's a data issue as much as a programming one. 这是一个数据问题和编程问题一样多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM