CSS: support for pseudo elements ::before & ::after#345
CSS: support for pseudo elements ::before & ::after#345poire-z merged 11 commits intokoreader:masterfrom
Conversation
With some image, we would be writting outside rev_buf array bounds. That's supposed to be driven by some other data, and should not happen - so there might be a bug somewhere else and we might have crap image data. Anyway, avoid this crash. koreader/koreader#6215
LVDocView::getSectionBounds(), used to compute marks to show in the top progress bar, which isn't cheap, could be called (with KOReader) on each page turn. Have it be trashed only when a re-rendering is really done. Note that m_imageCache might be used by some frontends, and not by others.
crengine builds its top progress bar markers from the start of each DocFragments (each html file in an EPUB). This will allow KOReader to manage it and fill it with markers made from the TOC, similarly to its bottom bar.
Also properly measure table captions as they are just like erm_final nodes.
Only white-space 'normal' and 'pre' was supported, other values were ignored and handled as 'normal'. This adds support (possibly limited or approximated) for: 'nowrap', 'pre-line', 'pre-wrap' and 'break-spaces'. Fix pre & nowrap handling in text formatting and rendered width measuring.
Rework 89af063: we might want our added content to get space collapsing. We have to provide LTEXT_FLAG_PREFORMATTED when we don't want that.
|
@poire-z: Yep, I'm all for using actual fancy double quotes in French (never been a fan of the chevrons myself ;)). |
|
Well, I like the |
| // Also, when "text-align-last: justify", Firefox does justify the last | ||
| // (or single) line. | ||
| if ( last ) { // Last line of paragraph, or single line paragraph | ||
| // https://drafts.csswg.org/css-text-3/#text-align-last-property |
Handle parsing of '::before', '::after' (CSS3), ':before'
and ':after (CSS2) in selectors.
Properly check if they should be generated or not, and if
yes, insert a new internal element in the DOM: pseudoElem.
Handle needed added CSS property: 'content:'. Parse original
values and store a pre-computed string in style->content,
ready to be used to get the final generated content for
a node. Supports string, attributes, open/close-quote.
Replaces <Q> specific handling in the code with:
q::before { content: open-quote; }
q::after { content: close-quote; }
Get the right quote chars for each language, and ensure nested quote levels (per lang_cfg).
One can use "-cr-hint: text-selection-inline", "text-selection-block" and "text-selection-skip" to target some elements and tweak how their text will appear (or not) in user text selection. Might be useful to exclude the content of ruby annotations (<ruby><rt>) from text selection when providing it to dict lookup or translation.
d8ce6c9 to
71923f2
Compare
|
Some issue related to <h1>PRE and newlines</h1>
<pre style="background-color: yellow">no newline char before and after</pre>
<pre style="background-color: yellow"> space char before and after </pre>
<pre style="background-color: yellow"> 2 space chars before and after </pre>
<pre style="background-color: yellow"> 3 space chars before and after </pre>
<pre style="background-color: yellow">
newline char before and after
</pre>
<pre style="background-color: yellow">
Blank line above and below
</pre>
<pre style="background-color: yellow">
<code>newline char before and after, in code</code>
</pre>
<pre style="background-color: yellow">
<table>newline char before and after, in table</table>
</pre>
<div style="background-color: yellow; white-space: pre">
newline char before and after, in a DIV white-space: pre
</div>We render the leading https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
So, I guess that for PRE and TEXTAREA, I should just remove a leading \n in its first text content ? Thought about fixing that in the text rendering code (where we already remove leading and collapsed spaces), but we'd need to go up to the element to check if it's a PRE - which we never do, we're fine with flags and CSS. Or we'd need a FLAG to say it comes from a PRE or TEXTAREA (but there is only 1bit left in our 32 bits slot for flags...). Or I should implement this in the XML and HTML parsers and do it only for a domVersionRequested greater than a bumped DOM_VERSION_CURRENT (because removing one char would break highlights made in a PRE). Witnessed in some O'Reilly Rust book (spent some time looking for an inexistant evil |
I think so, yes.
I can't judge the advantages and disadvantages nearly as well as you can. I would intuitively think the parser is the more logical place to do it and that it sounds a bit out of place in the text renderer, but I assume you mentioned it first for a reason. |
Not really, I was just thinking out loud :) and that was my first thought. |
I guess I won't :/ I solved this exact same issue the exact same way 3 years ago..... #337 (comment) |
|
For info and reference (in case of probable future bad memory, and me going back to this issue): Got some other bothering case with publisher bad job and footnote link numbers where all made like this: which is what should happen, per specs:
(except that we explicitely don't make that no-break-space visible at start of next line, which is usually for the best, as it would double the bothersomeness in my case). Using Possible solution I found: It's ugly and big, so let's make it small and invisible: (The blank space gets bigger, but it's more bearable than the closing quote at start of line.) (Somehow, using a narrower ASCII |









See individual commit messages for details.
GIF decoding: avoid crash on some imagesSee koreader/koreader#6215
Top progress bar: avoid re-computing when not neededSee koreader/koreader#6191
Top progress bar: allow external filling of marksWill allow frontend to feed crengine with TOC markers, so we can have the same markers in the top bar and in the bottom bar. See koreader/koreader#5848 (comment), #335.
CSS/Text: properly inherit and handle text-align-lastgetRenderedWidths(): fix handling of text-indentReorder some flags to make the sets clearer(chores)
CSS: support more white-space named valuesLeast fancy CSS value... but needed to properly size some table cells and floats (some



:beforepseudo elements are styles withfloats: left; white-space: pre-wrap)Each colored segment is an element with
white-space: nowrap:References:
https://www.w3.org/TR/CSS2/text.html#white-space-prop
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
https://www.xul.fr/en/css/white-space.php
Text: fix standalone BR not making an empty line (rework)Needed by next commit, where pseudo element content is handled as generated content, which might not be PRE.
CSS: support for pseudo elements ::before & ::afterJust a bit more fancy that
white-space, but not by much :)Handle
content:with tokens:none, strings"blah", attributesattr(blah),open-quote/close-quote.References:
https://developer.mozilla.org/en-US/docs/Web/CSS/content
https://developer.mozilla.org/en-US/docs/Web/CSS/string
https://www.w3.org/TR/CSS2/syndata.html#parsing-errors
Often used for cosmetics in books, but sometimes it can reveal some content, that it retrieves from the element attribute - like this paragraph number:


Or some references:
(The pseudo element added text will not be part of text selection - Firefox does the same by default.)
CSS: content: open-quote support via TextLangManEach language can have its own two pairs of quotes to use with open/close-quote.

I'm not happy with French getting the same quotes in both pairs !
« » « »@NiLuJe : what do you think, should we ignore HTML5 suggestion and use
« » “ ”like Italian ?CSS/Text selection: adds a few "-cr-hint:" tweaksMight be helpful in some cases, see koreader/koreader#6223 (comment)
This change is