-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS: parse/skip at-rules, support @media
, @supports
#454
Conversation
@virxkane : I picked your commit without really studying it. Hope I didn't do an error when picking :/ Can you have a look at this clang output and see if this is an issue (if not, we should find a way to silence it). |
Should be fixed in https://github.com/virxkane/coolreader/commit/11d48c157e426acf8e950af674dba0dbe6037536 |
zip64 is only relevant if 'large file support' is enabled, so we check |
Thanks! clang-tidy no longer complains about it !
Yes, our build stuff vs. crsetup.h is a bit hard to grasp, but I think we don't enable it. |
42cd1e5
to
9ea32c6
Compare
Added a commit to fix the issue noticed at koreader/koreader#7343 (comment). |
while (*str && *str != ' ' ) { | ||
// skip next char until we find a space or '!', that would start | ||
// a new token or '!important" itself if stuck to previous token | ||
while (*str && *str != ' ' && *str != '!') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, seems like something I might've noticed sooner. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fine in the general parsing, line-height:1!important
has been working without issue.
The issue was just with font-family
which has some dedicated parsing, for splitting the multiple font names.
(And I was indeed lazy as you, typing font-family:inherit!important
without spaces in my book style tweaks editor :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you could call it lazy, but from a reading perspective, not a writing one.
I think it's easier to read (as long as it doesn't get too long):
a {line-height:1!important; font-weight:bold}
than
a {
line-height: 1 !important;
font-weight: bold;
}
The reason I usually write the latter is a combination of how diffs work and that most other people seem to prefer it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, I'm not really sure about !important with or without a space. I normally don't use it, except in user styles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, no immediate comments
"For historical reasons, in the HTML syntax, a leading newline character immediately following the pre element start tag is stripped." Bump DOM version as this can shift highlight xpointers indexes by 1.
Note: there might still be something fishy with multiple spaces at boundaries between pre and non-pre text nodes, possibly overlapping.
Not sure why we went with initNodeRendMethodRecursive(), it feels we just want to set it to this single node, whose inner content has already been inited, and shouldn't need them changed.
Properly handle whitespaces between table element nodes according to the specs. This fix was mostly not needed with normal tables as the XML parsers would remove these whitespace text, and the table rendering algorithm would ignore them. But it might be needed when completing incomplete tables (where these whitespace may have been kept by the parser and should, or not, be included with what is wrapped) or when table elements are white-space:pre (which is rare).
Have LVDocView store the screen size in ldomDocument just so we'll be able to check CSS media queries like @media (min-device-width:500px) or (device-aspect-ratio:4/3)
Add a generic parsing helper skip_to_next() that properly observes the rules for matching pairs of (), [], {}, "", and '', and correctly handle escapes, as per specs. Use it for next_property() and next_token(). Will be also of use when parsing CSS @-rules.
Properly parse CSS @-rules, skipping most of them (by handling their content as nested stylesheets or nested declarations) as we don't support much except @media and @supports. Implement a AtRuleLogicalConditionParser and dedicated subclasses to parse logical combinations in @media and @supports. Implement handling of @supports items by tweaking LVCssDeclaration::parse() and parse_content_property() so that the same code can be used for parsing and just checking if we would parse it fine.
Add support for: <link href="s.css" type="text/css" rel="stylesheet" media="screen and (orientation:portrait)"/> and @import "s.css" screen and (orientation:portrait); Tweak stylesheets handling in ldomDocumentWriters: Parse and handle media= in '<link href="foo" media="bar">', and translate them into '@import url("foo") bar;' in the <stylesheet> child element's text we put them in. Rework a bit ldomDocumentFragmentWriter to make this parsing a bit clearer. Handle media conditions in LVProcessStyleSheetImport(). No change to LVLoadStylesheetFile(), used by frontends to get the user-agent stylesheet, which still handle only a unique first @import, without media condition support.
When without any space.
Our max nb of elements and attributes IDs starts with 1024, but can grow if we meet more. Be sure we grow them too as needed when loading from cache.
a379b02
to
9962acd
Compare
Postponing the zip64 stuff to an other PR, with more stuff from buggins/coolreader#312. |
That is great news! Thanks! For the sake of css tweaks I would like to also get specific answer: |
This in a user style tweak works for me: @media (orientation: portrait) { body { color: blue; } } Note that it's the orientation of the "page" (where the BODY is rendered, excluding KOReader's own margins set via the bottom menu), and not of the "device screen". (Beware your 9pt will make your font a fixed size, and the only way to change it then is thru Zoom/DPI) |
Sure, that was just an example :)
True. Same goes for width queries (match the column width), which has its upsides tbh :) It must have been a typo with orientations, after checking max- and min-width, orientation is working :) Crazy thing is that min-color is working, too :D I'm very glad it works inside css files too, anyway, will keep fiddling with it and report if need be :)))) |
That is a crazy lie :) : crengine/crengine/src/lvstsheet.cpp Lines 1812 to 1825 in 69b3f55
|
Wait, I swear on my PW4 EDIT: crengine/crengine/src/lvstsheet.cpp Line 2032 in 69b3f55
Ohhh, it was 8 not 12 in min-color that worked, and it makes sense if color value is about bits per channel, which it is per spec. I mistook it for color-index :) |
#### (Upstream) Minimal support for zip64postponing this one for another PRThis is enough to open zip archives larger than 4GB.From buggins/coolreader#310 - not sure we're using it as it depends on a #define - a bit of refacto to bits of code we use, hope it's fine.
XML parsing: strip leading
\n
in PRE and TEXTAREASee #345 (comment) for details.
"For historical reasons, in the HTML syntax, a leading newline character immediately following the pre element start tag is stripped."
Bump DOM version as this can shift highlight xpointers indexes by 1. (It may still cause a shift for very old opened books that will get migrated from that very old DOM version to this one... but well, who highlights in PRE ?!! Or I could do this inconditionnally:
https://github.com/koreader/koreader/blob/ab4e27908b292ab7172f06bb2b1e203558780d96/frontend/apps/reader/modules/readerrolling.lua#L1415-L1420
Text: allow wrap on any space in "white-space: pre"
Note: there might still be something fishy with multiple spaces at boundaries between pre and non-pre text nodes, possibly overlapping.


Before, a long sequence of space was unbreakable, so the possible break was found by hyphenating the previous word (and the next break is because there's no other solution):
After:
The fix looks simple and sane - but well, with our text rendering code, we never know...
I think we have many other issues with
white-space:pre
(like what we do this, we don't do it in gerRenderedWidths()), but well, didn't have the courage for more...initTableRendMethods(): avoid expensive processing
Not sure why we went with
initNodeRendMethodRecursive()
, it feels we just want to set it to this single node, whose inner content has already been inited, and shouldn't need them changed.Fixes the 2nd issue noticed at #370 (comment):
Tables: fix handling of whitespace between nodes
Properly handle whitespaces between table element nodes according to the specs.
This fix was mostly not needed with normal tables as the XML parsers would remove these whitespace text, and the table rendering algorithm would ignore them.
But it might be needed when completing incomplete tables (where these whitespace may have been kept by the parser and should, or not, be included with what is wrapped) or when table elements are
white-space:pre
(which is rare).We probably won't trigger this in real-life cases, but I had the bad idea to wrap all my "complete incomplete tables" test case in
white-space:pre
, and we did render mostly everything unlike Firefox.Got to answer a few of my questions in the comments... A bit risky though (had to fight with "styles have changed in such a way..." on re-rendering), hope it will be ok.
ldomDocument: store screen size
Have LVDocView store the screen size in ldomDocument just so we'll be able to check CSS media queries like
@media (min-device-width:500px) or (device-aspect-ratio:4/3)
CSS: more robust skipping of invalid content
Add a generic parsing helper
skip_to_next()
that properly observes the rules for matching pairs of(), [], {}, "", and ''
, and correctly handle escapes, as per specs.Use it for
next_property()
andnext_token()
.Will be also of use when parsing CSS
@-rules
.CSS: parse/skip at-rules, support
@media
,@supports
Properly parse CSS
@-rules
, skipping most of them (by handling their content as nested stylesheets or nested declarations) as we don't support much except@media
and@supports
.Implement a
AtRuleLogicalConditionParser
and dedicated subclasses to parse logical combinations in@media
and@supports
.Implement handling of
@supports
items by tweakingLVCssDeclaration::parse()
andparse_content_property()
so that the same code can be used for parsing and just checking if we would parse it fine.References:
https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
https://www.w3.org/TR/css3-mediaqueries/#media0
https://drafts.csswg.org/css-conditional/#at-supports
Some previous discussion in koreader/koreader#3179
Should allow closing koreader/koreader#7199.
CSS: handle media condition with
@import
and<link/>
Add support for:
and
Tweak stylesheets handling in ldomDocumentWriters:
Parse and handle media= in
<link href="foo" media="bar">
, and translate them into@import url("foo") bar;
in the<stylesheet>
child element's text we put them in.Rework a bit ldomDocumentFragmentWriter to make this parsing a bit clearer.
Handle media conditions in
LVProcessStyleSheetImport()
.No change to
LVLoadStylesheetFile()
, used by frontends to get the user-agent stylesheet, which still handle only a unique first@import
, without media condition support.Should allow closing koreader/koreader#3179.
CSS: fix parsing of "font-family:inherit!important"
When without any space.
LDOMNameIdMap::deserialize(): fix when >1024 items
Our max nb of elements and attributes IDs starts with 1024, but can grow if we meet more. Be sure we grow them too as needed when loading from cache.
Should avoid the issue noticed at koreader/koreader#7343 (comment).
(I apologize to the 3 users that decided to pick the nicks
@media @supports @import
. They are in my commit messages, so for any people that will sync their crengine fork with this repo, they may get a mail - but I guess that's not new to them and that by now, they have disabled such github mails :)This change is