koreader / crengine

This is the KOReader CREngine fork. It cross-pollinates with the official CoolReader repository at https://github.com/buggins/coolreader, in case you were looking for that one.
70 stars 45 forks source link

Various text selection, footnotes & misc fixes and tweaks #554

Closed poire-z closed 6 months ago

poire-z commented 6 months ago

LvDocView: allow setting custom title/authors/series

Frontend can set custom title/authors/series to be displayed in the top status bar (and in the rarely seen FB2 synthesized front text cover). Will help https://github.com/koreader/koreader/pull/11463 to do it stuff more properly. See https://github.com/koreader/koreader/pull/11463#issuecomment-1939067151

elementFromPoint(): fix possible crash when float at end of document

A float at the end of the document could add some overflow to the root node "rect", and we would segfault when looking for its parent. See https://github.com/koreader/koreader/issues/11409#issuecomment-1913089844 . Should allow closing https://github.com/koreader/koreader/issues/11409 .

Non-linear fragments: fix generic handling on erm_final

Followup to 03e0f372, where we added the closing of a non-linear sequence for erm_block elements, but totally forgot to do the same for erm_final elements! Noticed around https://github.com/koreader/koreader/issues/10193#issuecomment-1915204376.

DrawBorder: fix bottom border inset/outset drawing

The bottom border could be thicker than the others. Now similar to the top/left/right border drawing branches.

getSegmentRects(): allow segments to include images

This will allow including images at start or end of line in text selection & highlights, avoiding holes. It is also necessary with popup footnotes it we want to have them detected and highlight the link when the footnote link is solely an image (which seems popular in Chinese EPUBs). Should allow closing the popup footnotes issue in https://github.com/koreader/koreader/issues/11451 Will allow to go on with including images in text selection and highlights: https://github.com/koreader/koreader/issues/11460.

getRangeText(): allow gathering images

Allow getting in the text one unicode codepoint in place of each image (which may make the highlight text more readable). Can optionally return the list of associated image nodes. Will allow to go on with including images in text selection and highlights: https://github.com/koreader/koreader/issues/11460.

Allow standalone image in link to trigger in-page footnotes

We were only considering links with text as candidates to get in-page footnotes. (Image links seem popular in some Chinese books.) Should allow closing the in-page footnotes issue in https://github.com/koreader/koreader/issues/11451

ldomDocument::render(): avoid uneeded deserialization on each page turn

_pagesData is the serialized pages data, loaded from cache, and to be saved to cache. pos() > 0 means it has some content, that can be saved to cache. There were some interference with using it as meaning there has been some content read, that should be deserialized. Only deserialize when we know we should, when just loaded from cache.

lvtinydom: add ldomNode::getAllInnerAttributeValues()

Will be useful to get all the id= values in a footnote section.

LVFootNote: avoid retrieving internal CompactArray object

Add methods to get what we want, without the need to get a reference to the internal object itself (which could cause it to be freed when going out of scope and could cause some crashes if accessed again).

In-page footnotes: allows for multiple id= inside them

Previously, when entering a block element tagged with -cr-hint: footnote-inpage, we were associating it with the first id= attribute found inside it. It was then added to the page containing links with href= this id. But it may happen that some href= points to some inner id= inside the footnote section (ie. the container has an id= but the href= points to a <span id=> inside the container, with another id), in which case no footnote was found for that href. We now reference the same LVFootNote to all the ids met. The LVFootNote stubs created when meeting the href need to be kept, so we associate them with the "actual footnote" we create, so it can act as a proxy to it. Problem met in a few koreader issues, latest one at https://github.com/koreader/koreader/issues/11411#issuecomment-1925925214.


This change is Reviewable