page based load epub when changing font

前端 未结 3 1747
既然无缘
既然无缘 2021-02-09 23:53

I am doing ebook reader app like as iBooks. I have succesfully read a .epub file. But my problem is:-

I have to add Font size increase and decrease and font changing fun

相关标签:
3条回答
  • 2021-02-10 00:30

    Well, this is really a hard question...

    I have an idea for a method that splits a HTML page into two parts: the first page, and the rest. You can then repeatedly call that method on the "rest" to get all pages.

    1. Set $num_words = 100
    2. Take the first $num_words words from the page => $first_page_html;
    3. Put $first_page_html into UIWebView and "render" it (see note below).
    4. Check height of UIWebView. Does it fit? If yes, return from algorithm.
    5. If the words don't fit into the UIWebView, do $num_words--;
    6. Otherwise, do $num_words++;
    7. GOTO 2

    This is a first algorithm that should work somehow. However, there are optimization opportunities and hidden problems:

    You should probably do something like a binary search instead of a linear search. So $num_words should not be 100, 99, 98, 97, 96, ..., 62, but rather 100, 80, 60, 70, 65, 64, 63, 62. It would be even faster to ask the webview how much it is bigger or smaller than expected. I.e. if the webview is 30% too big in height, it means that you should reduce it by (1-1/(1+30%))=23%, so you should probably multiply the word-count by 0.77 in the first step.

    When there are hard page-breaks in the document, your function should take that into account.

    You get the height of the UIWebView by calling webView.scrollView.contentSize.height. I think you have to wait for the UIWebView to finish rendering before you can check the height though.

    If you know a bit more about the structure of your HTML you may be able to use the -stringByEvaluatingJavaScriptFromString: method from UIWebView to add individual words and see what happens. That way the webview doesn't have to re-render everything all the time.

    Note: by "rendering" I mean calling -loadHTMLString:baseURL: and then waiting for the -webViewDidFinishLoad: delegate method to be called.

    If performance is an issue it may be faster (for the device) to encode this algorithm in Javascript somehow, but I think that would be much harder.

    0 讨论(0)
  • 2021-02-10 00:42

    Finally I got answer .It is very simple . In ios 7 you don't need to write javascript for pagination or any logic .

    Just set UIWebview Property . Here is my code.

    self.webView.paginationMode = UIWebPaginationModeLeftToRight;
    self.webView.paginationBreakingMode = UIWebPaginationBreakingModePage;
    self.webView.scrollView.delegate = self;
    self.webView.scrollView.pagingEnabled = YES;
    self.webView.scrollView.alwaysBounceHorizontal = YES;
    self.webView.scrollView.alwaysBounceVertical = NO;
    self.webView.scrollView.bounces = YES;
    

    Here is sample code a : https://github.com/kalpesh22m/Epub-Reader-With-Pegination

    0 讨论(0)
  • 2021-02-10 00:52

    first to increase font size you need to give font size in em . before using em you need to give the body font-size:62.5% and for the elements inside div give font-size like 1.2em (which will act as 12px). so when you want to increase any Div's font-size you just have to increase font size of body by 10%. And you don't need to calculate characters for adjusting pages and this is not good practice for if you are making responsive book. use column property off css, let css handle flow of your pages. See below link for font size and flowable html structure

    js fiddle

    <a href="http://jsfiddle.net/hJ6Mj/4/">Js Fiddle</a>
    

    and also see "readium js for chrome". which will give you idea about how to render epub file on browser

    0 讨论(0)
提交回复
热议问题