“FBReader”如何使用对 epub 中的 html 文件进行分页

发布于 2024-11-07 12:38:55 字数 277 浏览 2 评论 0原文

我正在尝试制作一个 epub 阅读器

我想像 fbreader 那样进行分页

现在我有 fbreader 的源代码,但我不知道它在哪里实现分页

我有其他功能的实现

我需要 fbreader 提供的只是pagination

有没有人做过类似的事情?

感谢您花时间阅读这个问题。

ps:分页是把html文件吐到页面上,取决于屏幕的大小和字体的大小,还有语言的考虑,当改变字体大小时,页码也改变了。并且epub文件内容是html格式

I'm trying to make an epub reader

I want to do the pagination like fbreader does

Now I have source code of fbreader, but I don't know where it implement pagination

I have my implementation on other features

All I need from fbreader is the pagination

Is there anyone who have done the similar thing?

Thanks for your time to read this question.

ps: the pagination is to spit html file to pages, depending on the size of screen and size of font, and language is also in consideration, when changed the font size, the page number also changed. And epub file content is html format

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清旖 2024-11-14 12:38:55

这是令人着迷的代码。我很想看到原始学生项目的翻译(但我认为原始文档是俄语的)。由于这是 C++ 项目的移植,因此它在某些地方具有有趣的编码风格。

该应用程序使用段落光标 (ZLTextParagraphCursor) 跟踪您在书中的位置。这种情况与数据库游标和记录分页相比较。负责提供当前页面并计算页面数的类是ZLTextView

由于epub是可重排的文档,而不是面向页面的,因此页面并没有真正的具体定义 - 它仅取决于您在文档中碰巧查看的位置(段落、单词、字符)和使用什么显示设置。

It is fascinating code. I would love to see a translation of the original student project (but I presume the original document is in Russian). As this is a port of a C++ project it has an interesting style of coding in places.

The app keeps track of where you are in the book by using paragraph cursors (ZLTextParagraphCursor). This situation is comparative with database cursors and record pagination. The class that is responsible for serving up the current page and calculating the number of pages is ZLTextView.

As epubs are reflowable documents and not page-oriented there isn't really a concrete definition of a page - it just depends on where in the document you happen to be looking (paragraph, word, character) and with what display settings.

や三分注定 2024-11-14 12:38:55

正如 McLaren 所说,FBReader 实现分页:它使用 ZLibrary,可从同一个 网站 作为 FBReader。

原始代码使用这个来计算当前页码:

size_t ZLTextView::pageNumber() const {
    if (textArea().isEmpty()) {
        return 0;
    }
    std::vector<size_t>::const_iterator i = nextBreakIterator();
    const size_t startIndex = (i != myTextBreaks.begin()) ? *(i - 1) : 0;
    const size_t endIndex = (i != myTextBreaks.end()) ? *i : 
            textArea().model()->paragraphsNumber();
    return (myTextSize[endIndex] - myTextSize[startIndex]) / 2048 + 1;
}

Java版本使用这个函数来计算页码:

private synchronized int computeTextPageNumber(int textSize) {
    if (myModel == null || myModel.getParagraphsNumber() == 0) {
        return 1;
    }

    final float factor = 1.0f / computeCharsPerPage();
    final float pages = textSize * factor;
    return Math.max((int)(pages + 1.0f - 0.5f * factor), 1);
}

这个位于 org.geometerplus.zlibrary.text.view.TextView 中,

非常简单,不过,您也可以实现自己的。

As McLaren says, FBReader doesn't implement pagination: It uses the ZLibrary, which is available from the same website as FBReader.

The original code uses this to calculate the current page number:

size_t ZLTextView::pageNumber() const {
    if (textArea().isEmpty()) {
        return 0;
    }
    std::vector<size_t>::const_iterator i = nextBreakIterator();
    const size_t startIndex = (i != myTextBreaks.begin()) ? *(i - 1) : 0;
    const size_t endIndex = (i != myTextBreaks.end()) ? *i : 
            textArea().model()->paragraphsNumber();
    return (myTextSize[endIndex] - myTextSize[startIndex]) / 2048 + 1;
}

The Java version uses this function to compute the page number:

private synchronized int computeTextPageNumber(int textSize) {
    if (myModel == null || myModel.getParagraphsNumber() == 0) {
        return 1;
    }

    final float factor = 1.0f / computeCharsPerPage();
    final float pages = textSize * factor;
    return Math.max((int)(pages + 1.0f - 0.5f * factor), 1);
}

This is located in org.geometerplus.zlibrary.text.view.TextView

It's so simplistic, though, that you might as well implement your own.

世界和平 2024-11-14 12:38:55

我的理解是它使用了前一个、当前和下一个的 3 个位图。他们所做的是编写一个文本,通过这 3 个位图来存储和读取该文本。正如您在顶部看到的那样,它们计算您在其他示例中看到的滚动的段落数据。您可以从 android.view 包类 bitmapManager 开始逆向工程。这应该可以解释有关他们如何进行寻呼的所有内容。

How I understood it is that it uses 3 bitmaps previous current and next. What they have done is written a text which gets stored and read over this 3 bitmaps. Over as what you see on the top they calculate paragraphs data of how long it is for the scroll you see on the others example. You can start reverse engineering at android.view package class bitmapManager. This should explain everything about how they do their paging.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文