CSS: add support for pseudo element ::first-letter#648
Conversation
Having them known and a fixed id can avoid stylesheet hash mismatches.
AddSourceLine() (used by lvrend to add text fragment) can be provided with a 'offset' value indicating that some leading chars of the source text node should be skipped. No code was ever providing an offset different than 0, so it didn't matter if things were a bit inconsistent. We will use that offset to support CSS '::first-letter' (in next commit) so make things consistent, with two simple facts: - really only add text starting at offset to m_text - word->t.start counts from the source text node, and not from the offset (which makes things simpler elsewhere, including when dealing with xpointers)
|
Keeping here the full description Copilot has updated in the top post of poire-z#2, for reference (some bits are not fully true or right). Adds complete infrastructure for ChangesCSS Parsing and Style Matching (
|
|
Now you can ask Copilot to review this PR. 😄 |
| // Misc other attributes commonly found in books (ie. with cover SVG wrappers) | ||
| XS_ATTR( viewBox ) | ||
| XS_ATTR( preserveAspectRatio ) | ||
| XS_ATTR2( aria_hidden, "aria-hidden" ) |
There was a problem hiding this comment.
Should a few others like aria-label/labelled-by also be added then? I don't think I've spotted any in the wild, but I have seen it advocated in for example https://www.tpgi.com/using-aria-enhance-svg-accessibility/.
There was a problem hiding this comment.
If you feel like compiling those that feel like they can be found in books and providing the list, we can add them, there is room.
| if ( props & (CH_PROP_UPPER | CH_PROP_LOWER | CH_PROP_DIGIT | CH_PROP_SIGN) ) { | ||
| // Found the start of the first letter | ||
| foundFirstLetter = true; | ||
| i++; |
There was a problem hiding this comment.
Would this be clearer in the foundFirstLetter block?
There was a problem hiding this comment.
Can you be more explicite ?
There was a problem hiding this comment.
When I looked at this I thought huh, that's funny, they both do i++. Which made me think I'd either put it before the condition:
while ( i < len ) {
lUInt16 props = lGetCharProps(text[i]);
i++;Or like:
if ( props & (CH_PROP_UPPER | CH_PROP_LOWER | CH_PROP_DIGIT | CH_PROP_SIGN) ) {
// Found the start of the first letter
foundFirstLetter = true;
// not here
break;
}
i++;
}
// Now grab any trailing modifiers/punctuation that are part of the first letter
if ( foundFirstLetter ) {
// but here
i++;
while ( i < len ) {But it's just a an idle thought, do whatever you prefer obviously. ^_^
There was a problem hiding this comment.
Yes, I indeed prefer it written like you did.
Handled as another variation of the pseudoElem
internal element we introduced to support ::before
and ::after, so we benefit from its existing CSS
parsing/checking/applying and styles inheritance.
Have it inserted just before the text node it
should pick its first letter from, store in a
FirstLetter= attribute how many chars should be
picked from the next text node and rendered when
we render that pseudoElem, and skipped when
rendering the text node itself.
Known non-conformance to the CSS specs:
- we don't limit which CSS properties can be used
(the specs enumarate a subset of known properties).
- we may apply it where we should not (ie. among inlines,
propagate it from paragraph to a first inline-table...)
(Firefox and Chrome already have different behaviours
in this regard).
- if there are a ::before and a ::first-letter, we won't
pick the first letter from that ::before's content, and
we will render the ::before BEFORE the first-letter
picked from the following text.
First letters can be disabled with using
::first-leter { display: none; }
('display:' being one of the property the specs say
we should not support, we can use it to disable them
with style tweaks.)
|
To be bumped after next stable release. |
fb2def.h: add a few common attributes
Having them known and a fixed id can avoid stylesheet hash mismatches.
lvtext: includes
src->t.offsetinword->t.startAddSourceLine()(used by lvrend to add text fragment) can be provided with aoffsetvalue indicating that some leading chars of the source text node should be skipped.No code was ever providing an offset different than 0, so it didn't matter if things were a bit inconsistent.
We will use that offset to support CSS
::first-letter(in next commit) so make things consistent, with two simple facts:offsettom_textword->t.startcounts from the source text node, and not from the offset (which makes things simpler elsewhere, including when dealing with xpointers)CSS: support for pseudo element
::first-letterHandled as another variation of the
pseudoEleminternal element we introduced to support::beforeand::after, so we benefit from its existing CSS parsing/checking/applying and styles inheritance.Have it inserted just before the text node it should pick its first letter from, store in a
FirstLetter=attribute how many chars should be picked from the next text node and rendered when we render that pseudoElem, and skipped when rendering the text node itself.Known non-conformance to the CSS specs:
::beforeand a::first-letter, we won't pick the first letter from that::before's content, and we will render the::beforeBEFORE the first-letter picked from the following text.First letters can be disabled with using
::first-leter { display: none; }(
display:being one of the property the specs say we should not support, we can use it to disable them with style tweaks.)Should allow closing:
koreader/koreader#6944
koreader/koreader#9142
koreader/koreader#14391
Discussed in #646.
Done with the help of Github copilot by guiding it step by step along the idea I had in mind. Experience related in #646 (comment).
Full Copilot conversation/copiloting in poire-z#2 (140 conversation posts, 48 commits!...)
This change is