Skip to content

Footnote popup: fix XHTML handling#12158

Merged
poire-z merged 1 commit into
koreader:masterfrom
poire-z:htmlbox_is_xhtml
Jul 12, 2024
Merged

Footnote popup: fix XHTML handling#12158
poire-z merged 1 commit into
koreader:masterfrom
poire-z:htmlbox_is_xhtml

Conversation

@poire-z

@poire-z poire-z commented Jul 12, 2024

Copy link
Copy Markdown
Contributor

Latest MuPDF update changed HTML parsing, and use a better HTML5 parser, which may cause some issues with the XHTML we get from crengine.
So, for footnote popups, be sure we use MuPDF's XHTML parser.
See #12144 (comment).
Closes #12144.


This change is Reviewable

Latest MuPDF update changed HTML parsing, and use a better
HTML5 parser, which may cause some issues with the XHTML
we get from crengine.
So, for footnote popups, be sure we use MuPDF's XHTML parser.
@Frenzie Frenzie added this to the 2024.07 milestone Jul 12, 2024
@poire-z poire-z merged commit 7ebd067 into koreader:master Jul 12, 2024
@poire-z poire-z deleted the htmlbox_is_xhtml branch July 12, 2024 11:34
@ptrm

ptrm commented Jul 14, 2024

Copy link
Copy Markdown
Contributor

@poire-z btw, what parser is used for dictionaries? After the big mupdf update I can't see images and spacings seem odd, will post a separate issue about it, but was curious whether a simple switch wouldn't help (images are broken probably due to some more secure path parsing not parser, but anyway)

@poire-z

poire-z commented Jul 14, 2024

Copy link
Copy Markdown
Contributor Author

The html5 parser. We only switched to the xhtml parser for footnote popups.
I also got some changes to some of my HTML dicts output, possibly due to that - but I tweaked my dict.lua that were already massaging the output, so not sure how it would have solve my issues if I had noticed the html5 vs xhtml parser thing. I also don't know if our old MuPDF was exclusively using its XHTML parser.
You can try forcing the use of the "xhtml" in:

ok, self.document = pcall(Mupdf.openDocumentFromText, html, is_xhtml and "xhtml" or "html")

and see if this brings back the old behaviour.

@poire-z

poire-z commented Jul 14, 2024

Copy link
Copy Markdown
Contributor Author

I tweaked my dict.lua that were already massaging the output, so not sure how it would have solve my issues if I had noticed the html5 vs xhtml parser thing.

Just checked with my old tweaks and forcing "xhtml" - but the result was as bad as with "html". (With "xhtml", it tries to parse it as XML but if the content is bad xhtml - which is the case with my dict, it fallback to using the same HTML5 as with "html").
I'm still curious about how this does on your side.

Commodore64user pushed a commit to Commodore64user/KOReader_fork that referenced this pull request Aug 2, 2024
Latest MuPDF update changed HTML parsing, and use a better
HTML5 parser, which may cause some issues with the XHTML
we get from crengine.
So, for footnote popups, be sure we use MuPDF's XHTML parser.
@ptrm

ptrm commented Aug 4, 2024

Copy link
Copy Markdown
Contributor

I tweaked my dict.lua that were already massaging the output, so not sure how it would have solve my issues if I had noticed the html5 vs xhtml parser thing.

Just checked with my old tweaks and forcing "xhtml" - but the result was as bad as with "html". (With "xhtml", it tries to parse it as XML but if the content is bad xhtml - which is the case with my dict, it fallback to using the same HTML5 as with "html"). I'm still curious about how this does on your side.

@poire-z so the reason behind the "odd spacings" I experienced on new mupdf (or since aroujd that time) is that color: darkgray; shows as white/invisible on 8bpp displays (tested on Kobo Libra 2 and Clara BW). Replacing to color: gray; works.

I will create a proper ticket for that with an example dict attached, just wanted to give a heads up that html layout rendering has been fine all the time, I just didn't notice the missing words around definitions xD

@poire-z

poire-z commented Aug 4, 2024

Copy link
Copy Markdown
Contributor Author

I'm not sure we can do anything, replacing colors (which could be specified as #xxyyzz or rgb(x,y,z) ) in the content is a bit intrusive.
I guess this is to be fixed by you with a dictname.lua (like I have to do with a few of my HTML dicts - I have one that shows colors on the emulator, and that I replace colors for my Kobo).

@benoit-pierre

Copy link
Copy Markdown
Member

It looks like there's only a limited number of supported color names in MuPDF source, html/css-apply.c:

static const char *color_kw[] = {
	"aqua",
	"black",
	"blue",
	"fuchsia",
	"gray",
	"green",
	"lime",
	"maroon",
	"navy",
	"olive",
	"orange",
	"purple",
	"red",
	"silver",
	"teal",
	"transparent",
	"white",
	"yellow",
};

@ptrm

ptrm commented Aug 4, 2024

Copy link
Copy Markdown
Contributor

I'm not sure we can do anything, replacing colors (which could be specified as #xxyyzz or rgb(x,y,z) ) in the content is a bit intrusive. I guess this is to be fixed by you with a dictname.lua (like I have to do with a few of my HTML dicts - I have one that shows colors on the emulator, and that I replace colors for my Kobo).

Oh the colors already come from my dict.css file, thery're not hardcoded into the dictionary. I was just surprised that a darkgray, which is darker than gray, shows as white (the word renders as long tapping on the blank space shows the definition), this does seem a bug to me. Before the mupdf upgrade the css darkgray showed as it should.

EDIT: And as you just replied in the meantime, replacing darkgray with #a9a9a9 works ^^ So I don't bother you more (thought it's maybe a colormapping issue or something)

@benoit-pierre

Copy link
Copy Markdown
Member

There's another more complete list when it come to SVG support, with 147 entries, which must cover the 140 standard color names supported by browsers.

@ptrm: can you provide a sample output (of what gets passed to MuPDF)?

@ptrm

ptrm commented Aug 4, 2024

Copy link
Copy Markdown
Contributor

Also, on Android darkgray shows as black in dicts, which is at least readable :o

@benoit-pierre something as simple as dictionaryfilename.css with contents body { color: darkgray; } should show the problem, if I read your question correctly. (Unless the dict's html uses <font color= or something :3 edit: not sure !important is respected by mupdf)

@benoit-pierre

benoit-pierre commented Aug 4, 2024

Copy link
Copy Markdown
Member

I'm looking for an HTML/CSS test sample using said color names… You'd think that would be easy, but all those pages listing the list of supported colors actually don't use color names in their source.

@benoit-pierre

Copy link
Copy Markdown
Member

MDN to the rescue: https://developer.mozilla.org/en-US/docs/Web/CSS/named-color. This one use the keywords in question:

    <tr>
      <td><code>black</code></td>
      <td><code>#000000</code></td>
      <td style="background: black"></td>
    </tr>
    
    <tr>
      <td><code>gray</code></td>
      <td><code>#808080</code></td>
      <td style="background: gray"></td>
    </tr>
    <tr>
      <td><code>white</code></td>
      <td><code>#ffffff</code></td>
      <td style="background: white"></td>
    </tr>

@ptrm

ptrm commented Aug 4, 2024

Copy link
Copy Markdown
Contributor

Well no worries, this just surprised me, but since unnamed colors work, that's not severe I guess. Well maybe apart from rendering unrecognised colors white on white on Kobos and black on white on Android (same dict and css) ^^

Edit: also just discovered darkgray (#a9a9a9) is actually lighter than gray (#808080) xD

@benoit-pierre

Copy link
Copy Markdown
Member

Here it is:

<html>
  <body>
    <table>
      <thead>
	<tr>
	  <th scope="col">Keyword</th>
	  <th scope="col">RGB hex value</th>
	  <th scope="col">Sample</th>
	</tr>
      </thead>
      <tbody>
	<tr>
	  <td><code>black</code></td>
	  <td><code>#000000</code></td>
	  <td style="color: black">black</td>
	</tr>
	<tr>
	  <td><code>silver</code></td>
	  <td><code>#c0c0c0</code></td>
	  <td style="color: silver">silver</td>
	</tr>
	<tr>
	  <td><code>gray</code></td>
	  <td><code>#808080</code></td>
	  <td style="color: gray">gray</td>
	</tr>
	<tr>
	  <td><code>white</code></td>
	  <td><code>#ffffff</code></td>
	  <td style="color: white">white</td>
	</tr>
	<tr>
	  <td><code>maroon</code></td>
	  <td><code>#800000</code></td>
	  <td style="color: maroon">maroon</td>
	</tr>
	<tr>
	  <td><code>red</code></td>
	  <td><code>#ff0000</code></td>
	  <td style="color: red">red</td>
	</tr>
	<tr>
	  <td><code>purple</code></td>
	  <td><code>#800080</code></td>
	  <td style="color: purple">purple</td>
	</tr>
	<tr>
	  <td><code>fuchsia</code></td>
	  <td><code>#ff00ff</code></td>
	  <td style="color: fuchsia">fuchsia</td>
	</tr>
	<tr>
	  <td><code>green</code></td>
	  <td><code>#008000</code></td>
	  <td style="color: green">green</td>
	</tr>
	<tr>
	  <td><code>lime</code></td>
	  <td><code>#00ff00</code></td>
	  <td style="color: lime">lime</td>
	</tr>
	<tr>
	  <td><code>olive</code></td>
	  <td><code>#808000</code></td>
	  <td style="color: olive">olive</td>
	</tr>
	<tr>
	  <td><code>yellow</code></td>
	  <td><code>#ffff00</code></td>
	  <td style="color: yellow">yellow</td>
	</tr>
	<tr>
	  <td><code>navy</code></td>
	  <td><code>#000080</code></td>
	  <td style="color: navy">navy</td>
	</tr>
	<tr>
	  <td><code>blue</code></td>
	  <td><code>#0000ff</code></td>
	  <td style="color: blue">blue</td>
	</tr>
	<tr>
	  <td><code>teal</code></td>
	  <td><code>#008080</code></td>
	  <td style="color: teal">teal</td>
	</tr>
	<tr>
	  <td><code>aqua</code></td>
	  <td><code>#00ffff</code></td>
	  <td style="color: aqua">aqua</td>
	</tr>
      </tbody>
    </table>
    <table>
      <thead>
	<tr>
	  <th scope="col">Keyword</th>
	  <th scope="col">RGB hex value</th>
	  <th scope="col">Sample</th>
	</tr>
      </thead>
      <tbody>
	<tr>
	  <td><code>aliceblue</code></td>
	  <td><code>#f0f8ff</code></td>
	  <td style="color: aliceblue">aliceblue</td>
	</tr>
	<tr>
	  <td><code>antiquewhite</code></td>
	  <td><code>#faebd7</code></td>
	  <td style="color: antiquewhite">antiquewhite</td>
	</tr>
	<tr>
	  <td><code>aqua</code></td>
	  <td><code>#00ffff</code></td>
	  <td style="color: aqua">aqua</td>
	</tr>
	<tr>
	  <td><code>aquamarine</code></td>
	  <td><code>#7fffd4</code></td>
	  <td style="color: aquamarine">aquamarine</td>
	</tr>
	<tr>
	  <td><code>azure</code></td>
	  <td><code>#f0ffff</code></td>
	  <td style="color: azure">azure</td>
	</tr>
	<tr>
	  <td><code>beige</code></td>
	  <td><code>#f5f5dc</code></td>
	  <td style="color: beige">beige</td>
	</tr>
	<tr>
	  <td><code>bisque</code></td>
	  <td><code>#ffe4c4</code></td>
	  <td style="color: bisque">bisque</td>
	</tr>
	<tr>
	  <td><code>black</code></td>
	  <td><code>#000000</code></td>
	  <td style="color: black">black</td>
	</tr>
	<tr>
	  <td><code>blanchedalmond</code></td>
	  <td><code>#ffebcd</code></td>
	  <td style="color: blanchedalmond">blanchedalmond</td>
	</tr>
	<tr>
	  <td><code>blue</code></td>
	  <td><code>#0000ff</code></td>
	  <td style="color: blue">blue</td>
	</tr>
	<tr>
	  <td><code>blueviolet</code></td>
	  <td><code>#8a2be2</code></td>
	  <td style="color: blueviolet">blueviolet</td>
	</tr>
	<tr>
	  <td><code>brown</code></td>
	  <td><code>#a52a2a</code></td>
	  <td style="color: brown">brown</td>
	</tr>
	<tr>
	  <td><code>burlywood</code></td>
	  <td><code>#deb887</code></td>
	  <td style="color: burlywood">burlywood</td>
	</tr>
	<tr>
	  <td><code>cadetblue</code></td>
	  <td><code>#5f9ea0</code></td>
	  <td style="color: cadetblue">cadetblue</td>
	</tr>
	<tr>
	  <td><code>chartreuse</code></td>
	  <td><code>#7fff00</code></td>
	  <td style="color: chartreuse">chartreuse</td>
	</tr>
	<tr>
	  <td><code>chocolate</code></td>
	  <td><code>#d2691e</code></td>
	  <td style="color: chocolate">chocolate</td>
	</tr>
	<tr>
	  <td><code>coral</code></td>
	  <td><code>#ff7f50</code></td>
	  <td style="color: coral">coral</td>
	</tr>
	<tr>
	  <td><code>cornflowerblue</code></td>
	  <td><code>#6495ed</code></td>
	  <td style="color: cornflowerblue">cornflowerblue</td>
	</tr>
	<tr>
	  <td><code>cornsilk</code></td>
	  <td><code>#fff8dc</code></td>
	  <td style="color: cornsilk">cornsilk</td>
	</tr>
	<tr>
	  <td><code>crimson</code></td>
	  <td><code>#dc143c</code></td>
	  <td style="color: crimson">crimson</td>
	</tr>
	<tr>
	  <td><code>cyan</code><br></td>
	  <td><code>#00ffff</code> (synonym of <code>aqua</code>)</td>
	  <td style="color: cyan">cyan</td>
	</tr>
	<tr>
	  <td><code>darkblue</code></td>
	  <td><code>#00008b</code></td>
	  <td style="color: darkblue">darkblue</td>
	</tr>
	<tr>
	  <td><code>darkcyan</code></td>
	  <td><code>#008b8b</code></td>
	  <td style="color: darkcyan">darkcyan</td>
	</tr>
	<tr>
	  <td><code>darkgoldenrod</code></td>
	  <td><code>#b8860b</code></td>
	  <td style="color: darkgoldenrod">darkgoldenrod</td>
	</tr>
	<tr>
	  <td><code>darkgray</code></td>
	  <td><code>#a9a9a9</code></td>
	  <td style="color: darkgray">darkgray</td>
	</tr>
	<tr>
	  <td><code>darkgreen</code></td>
	  <td><code>#006400</code></td>
	  <td style="color: darkgreen">darkgreen</td>
	</tr>
	<tr>
	  <td><code>darkgrey</code></td>
	  <td><code>#a9a9a9</code></td>
	  <td style="color: darkgrey">darkgrey</td>
	</tr>
	<tr>
	  <td><code>darkkhaki</code></td>
	  <td><code>#bdb76b</code></td>
	  <td style="color: darkkhaki">darkkhaki</td>
	</tr>
	<tr>
	  <td><code>darkmagenta</code></td>
	  <td><code>#8b008b</code></td>
	  <td style="color: darkmagenta">darkmagenta</td>
	</tr>
	<tr>
	  <td><code>darkolivegreen</code></td>
	  <td><code>#556b2f</code></td>
	  <td style="color: darkolivegreen">darkolivegreen</td>
	</tr>
	<tr>
	  <td><code>darkorange</code></td>
	  <td><code>#ff8c00</code></td>
	  <td style="color: darkorange">darkorange</td>
	</tr>
	<tr>
	  <td><code>darkorchid</code></td>
	  <td><code>#9932cc</code></td>
	  <td style="color: darkorchid">darkorchid</td>
	</tr>
	<tr>
	  <td><code>darkred</code></td>
	  <td><code>#8b0000</code></td>
	  <td style="color: darkred">darkred</td>
	</tr>
	<tr>
	  <td><code>darksalmon</code></td>
	  <td><code>#e9967a</code></td>
	  <td style="color: darksalmon">darksalmon</td>
	</tr>
	<tr>
	  <td><code>darkseagreen</code></td>
	  <td><code>#8fbc8f</code></td>
	  <td style="color: darkseagreen">darkseagreen</td>
	</tr>
	<tr>
	  <td><code>darkslateblue</code></td>
	  <td><code>#483d8b</code></td>
	  <td style="color: darkslateblue">darkslateblue</td>
	</tr>
	<tr>
	  <td><code>darkslategray</code></td>
	  <td><code>#2f4f4f</code></td>
	  <td style="color: darkslategray">darkslategray</td>
	</tr>
	<tr>
	  <td><code>darkslategrey</code></td>
	  <td><code>#2f4f4f</code></td>
	  <td style="color: darkslategrey">darkslategrey</td>
	</tr>
	<tr>
	  <td><code>darkturquoise</code></td>
	  <td><code>#00ced1</code></td>
	  <td style="color: darkturquoise">darkturquoise</td>
	</tr>
	<tr>
	  <td><code>darkviolet</code></td>
	  <td><code>#9400d3</code></td>
	  <td style="color: darkviolet">darkviolet</td>
	</tr>
	<tr>
	  <td><code>deeppink</code></td>
	  <td><code>#ff1493</code></td>
	  <td style="color: deeppink">deeppink</td>
	</tr>
	<tr>
	  <td><code>deepskyblue</code></td>
	  <td><code>#00bfff</code></td>
	  <td style="color: deepskyblue">deepskyblue</td>
	</tr>
	<tr>
	  <td><code>dimgray</code></td>
	  <td><code>#696969</code></td>
	  <td style="color: dimgray">dimgray</td>
	</tr>
	<tr>
	  <td><code>dimgrey</code></td>
	  <td><code>#696969</code></td>
	  <td style="color: dimgrey">dimgrey</td>
	</tr>
	<tr>
	  <td><code>dodgerblue</code></td>
	  <td><code>#1e90ff</code></td>
	  <td style="color: dodgerblue">dodgerblue</td>
	</tr>
	<tr>
	  <td><code>firebrick</code></td>
	  <td><code>#b22222</code></td>
	  <td style="color: firebrick">firebrick</td>
	</tr>
	<tr>
	  <td><code>floralwhite</code></td>
	  <td><code>#fffaf0</code></td>
	  <td style="color: floralwhite">floralwhite</td>
	</tr>
	<tr>
	  <td><code>forestgreen</code></td>
	  <td><code>#228b22</code></td>
	  <td style="color: forestgreen">forestgreen</td>
	</tr>
	<tr>
	  <td><code>fuchsia</code></td>
	  <td><code>#ff00ff</code></td>
	  <td style="color: fuchsia">fuchsia</td>
	</tr>
	<tr>
	  <td><code>gainsboro</code></td>
	  <td><code>#dcdcdc</code></td>
	  <td style="color: gainsboro">gainsboro</td>
	</tr>
	<tr>
	  <td><code>ghostwhite</code></td>
	  <td><code>#f8f8ff</code></td>
	  <td style="color: ghostwhite">ghostwhite</td>
	</tr>
	<tr>
	  <td><code>gold</code></td>
	  <td><code>#ffd700</code></td>
	  <td style="color: gold">gold</td>
	</tr>
	<tr>
	  <td><code>goldenrod</code></td>
	  <td><code>#daa520</code></td>
	  <td style="color: goldenrod">goldenrod</td>
	</tr>
	<tr>
	  <td><code>gray</code></td>
	  <td><code>#808080</code></td>
	  <td style="color: gray">gray</td>
	</tr>
	<tr>
	  <td><code>green</code></td>
	  <td><code>#008000</code></td>
	  <td style="color: green">green</td>
	</tr>
	<tr>
	  <td><code>greenyellow</code></td>
	  <td><code>#adff2f</code></td>
	  <td style="color: greenyellow">greenyellow</td>
	</tr>
	<tr>
	  <td><code>grey</code></td>
	  <td><code>#808080</code> (synonym of <code>gray</code>)</td>
	  <td style="color: grey">grey</td>
	</tr>
	<tr>
	  <td><code>honeydew</code></td>
	  <td><code>#f0fff0</code></td>
	  <td style="color: honeydew">honeydew</td>
	</tr>
	<tr>
	  <td><code>hotpink</code></td>
	  <td><code>#ff69b4</code></td>
	  <td style="color: hotpink">hotpink</td>
	</tr>
	<tr>
	  <td><code>indianred</code></td>
	  <td><code>#cd5c5c</code></td>
	  <td style="color: indianred">indianred</td>
	</tr>
	<tr>
	  <td><code>indigo</code></td>
	  <td><code>#4b0082</code></td>
	  <td style="color: indigo">indigo</td>
	</tr>
	<tr>
	  <td><code>ivory</code></td>
	  <td><code>#fffff0</code></td>
	  <td style="color: ivory">ivory</td>
	</tr>
	<tr>
	  <td><code>khaki</code></td>
	  <td><code>#f0e68c</code></td>
	  <td style="color: khaki">khaki</td>
	</tr>
	<tr>
	  <td><code>lavender</code></td>
	  <td><code>#e6e6fa</code></td>
	  <td style="color: lavender">lavender</td>
	</tr>
	<tr>
	  <td><code>lavenderblush</code></td>
	  <td><code>#fff0f5</code></td>
	  <td style="color: lavenderblush">lavenderblush</td>
	</tr>
	<tr>
	  <td><code>lawngreen</code></td>
	  <td><code>#7cfc00</code></td>
	  <td style="color: lawngreen">lawngreen</td>
	</tr>
	<tr>
	  <td><code>lemonchiffon</code></td>
	  <td><code>#fffacd</code></td>
	  <td style="color: lemonchiffon">lemonchiffon</td>
	</tr>
	<tr>
	  <td><code>lightblue</code></td>
	  <td><code>#add8e6</code></td>
	  <td style="color: lightblue">lightblue</td>
	</tr>
	<tr>
	  <td><code>lightcoral</code></td>
	  <td><code>#f08080</code></td>
	  <td style="color: lightcoral">lightcoral</td>
	</tr>
	<tr>
	  <td><code>lightcyan</code></td>
	  <td><code>#e0ffff</code></td>
	  <td style="color: lightcyan">lightcyan</td>
	</tr>
	<tr>
	  <td><code>lightgoldenrodyellow</code></td>
	  <td><code>#fafad2</code></td>
	  <td style="color: lightgoldenrodyellow">lightgoldenrodyellow</td>
	</tr>
	<tr>
	  <td><code>lightgray</code></td>
	  <td><code>#d3d3d3</code></td>
	  <td style="color: lightgray">lightgray</td>
	</tr>
	<tr>
	  <td><code>lightgreen</code></td>
	  <td><code>#90ee90</code></td>
	  <td style="color: lightgreen">lightgreen</td>
	</tr>
	<tr>
	  <td><code>lightgrey</code></td>
	  <td><code>#d3d3d3</code></td>
	  <td style="color: lightgrey">lightgrey</td>
	</tr>
	<tr>
	  <td><code>lightpink</code></td>
	  <td><code>#ffb6c1</code></td>
	  <td style="color: lightpink">lightpink</td>
	</tr>
	<tr>
	  <td><code>lightsalmon</code></td>
	  <td><code>#ffa07a</code></td>
	  <td style="color: lightsalmon">lightsalmon</td>
	</tr>
	<tr>
	  <td><code>lightseagreen</code></td>
	  <td><code>#20b2aa</code></td>
	  <td style="color: lightseagreen">lightseagreen</td>
	</tr>
	<tr>
	  <td><code>lightskyblue</code></td>
	  <td><code>#87cefa</code></td>
	  <td style="color: lightskyblue">lightskyblue</td>
	</tr>
	<tr>
	  <td><code>lightslategray</code></td>
	  <td><code>#778899</code></td>
	  <td style="color: lightslategray">lightslategray</td>
	</tr>
	<tr>
	  <td><code>lightslategrey</code></td>
	  <td><code>#778899</code></td>
	  <td style="color: lightslategrey">lightslategrey</td>
	</tr>
	<tr>
	  <td><code>lightsteelblue</code></td>
	  <td><code>#b0c4de</code></td>
	  <td style="color: lightsteelblue">lightsteelblue</td>
	</tr>
	<tr>
	  <td><code>lightyellow</code></td>
	  <td><code>#ffffe0</code></td>
	  <td style="color: lightyellow">lightyellow</td>
	</tr>
	<tr>
	  <td><code>lime</code></td>
	  <td><code>#00ff00</code></td>
	  <td style="color: lime">lime</td>
	</tr>
	<tr>
	  <td><code>limegreen</code></td>
	  <td><code>#32cd32</code></td>
	  <td style="color: limegreen">limegreen</td>
	</tr>
	<tr>
	  <td><code>linen</code></td>
	  <td><code>#faf0e6</code></td>
	  <td style="color: linen">linen</td>
	</tr>
	<tr>
	  <td><code>magenta</code><br></td>
	  <td><code>#ff00ff</code> (synonym of <code>fuchsia</code>)</td>
	  <td style="color: magenta">magenta</td>
	</tr>
	<tr>
	  <td><code>maroon</code></td>
	  <td><code>#800000</code></td>
	  <td style="color: maroon">maroon</td>
	</tr>
	<tr>
	  <td><code>mediumaquamarine</code></td>
	  <td><code>#66cdaa</code></td>
	  <td style="color: mediumaquamarine">mediumaquamarine</td>
	</tr>
	<tr>
	  <td><code>mediumblue</code></td>
	  <td><code>#0000cd</code></td>
	  <td style="color: mediumblue">mediumblue</td>
	</tr>
	<tr>
	  <td><code>mediumorchid</code></td>
	  <td><code>#ba55d3</code></td>
	  <td style="color: mediumorchid">mediumorchid</td>
	</tr>
	<tr>
	  <td><code>mediumpurple</code></td>
	  <td><code>#9370db</code></td>
	  <td style="color: mediumpurple">mediumpurple</td>
	</tr>
	<tr>
	  <td><code>mediumseagreen</code></td>
	  <td><code>#3cb371</code></td>
	  <td style="color: mediumseagreen">mediumseagreen</td>
	</tr>
	<tr>
	  <td><code>mediumslateblue</code></td>
	  <td><code>#7b68ee</code></td>
	  <td style="color: mediumslateblue">mediumslateblue</td>
	</tr>
	<tr>
	  <td><code>mediumspringgreen</code></td>
	  <td><code>#00fa9a</code></td>
	  <td style="color: mediumspringgreen">mediumspringgreen</td>
	</tr>
	<tr>
	  <td><code>mediumturquoise</code></td>
	  <td><code>#48d1cc</code></td>
	  <td style="color: mediumturquoise">mediumturquoise</td>
	</tr>
	<tr>
	  <td><code>mediumvioletred</code></td>
	  <td><code>#c71585</code></td>
	  <td style="color: mediumvioletred">mediumvioletred</td>
	</tr>
	<tr>
	  <td><code>midnightblue</code></td>
	  <td><code>#191970</code></td>
	  <td style="color: midnightblue">midnightblue</td>
	</tr>
	<tr>
	  <td><code>mintcream</code></td>
	  <td><code>#f5fffa</code></td>
	  <td style="color: mintcream">mintcream</td>
	</tr>
	<tr>
	  <td><code>mistyrose</code></td>
	  <td><code>#ffe4e1</code></td>
	  <td style="color: mistyrose">mistyrose</td>
	</tr>
	<tr>
	  <td><code>moccasin</code></td>
	  <td><code>#ffe4b5</code></td>
	  <td style="color: moccasin">moccasin</td>
	</tr>
	<tr>
	  <td><code>navajowhite</code></td>
	  <td><code>#ffdead</code></td>
	  <td style="color: navajowhite">navajowhite</td>
	</tr>
	<tr>
	  <td><code>navy</code></td>
	  <td><code>#000080</code></td>
	  <td style="color: navy">navy</td>
	</tr>
	<tr>
	  <td><code>oldlace</code></td>
	  <td><code>#fdf5e6</code></td>
	  <td style="color: oldlace">oldlace</td>
	</tr>
	<tr>
	  <td><code>olive</code></td>
	  <td><code>#808000</code></td>
	  <td style="color: olive">olive</td>
	</tr>
	<tr>
	  <td><code>olivedrab</code></td>
	  <td><code>#6b8e23</code></td>
	  <td style="color: olivedrab">olivedrab</td>
	</tr>
	<tr>
	  <td><code>orange</code></td>
	  <td><code>#ffa500</code></td>
	  <td style="color: orange">orange</td>
	</tr>
	<tr>
	  <td><code>orangered</code></td>
	  <td><code>#ff4500</code></td>
	  <td style="color: orangered">orangered</td>
	</tr>
	<tr>
	  <td><code>orchid</code></td>
	  <td><code>#da70d6</code></td>
	  <td style="color: orchid">orchid</td>
	</tr>
	<tr>
	  <td><code>palegoldenrod</code></td>
	  <td><code>#eee8aa</code></td>
	  <td style="color: palegoldenrod">palegoldenrod</td>
	</tr>
	<tr>
	  <td><code>palegreen</code></td>
	  <td><code>#98fb98</code></td>
	  <td style="color: palegreen">palegreen</td>
	</tr>
	<tr>
	  <td><code>paleturquoise</code></td>
	  <td><code>#afeeee</code></td>
	  <td style="color: paleturquoise">paleturquoise</td>
	</tr>
	<tr>
	  <td><code>palevioletred</code></td>
	  <td><code>#db7093</code></td>
	  <td style="color: palevioletred">palevioletred</td>
	</tr>
	<tr>
	  <td><code>papayawhip</code></td>
	  <td><code>#ffefd5</code></td>
	  <td style="color: papayawhip">papayawhip</td>
	</tr>
	<tr>
	  <td><code>peachpuff</code></td>
	  <td><code>#ffdab9</code></td>
	  <td style="color: peachpuff">peachpuff</td>
	</tr>
	<tr>
	  <td><code>peru</code></td>
	  <td><code>#cd853f</code></td>
	  <td style="color: peru">peru</td>
	</tr>
	<tr>
	  <td><code>pink</code></td>
	  <td><code>#ffc0cb</code></td>
	  <td style="color: pink">pink</td>
	</tr>
	<tr>
	  <td><code>plum</code></td>
	  <td><code>#dda0dd</code></td>
	  <td style="color: plum">plum</td>
	</tr>
	<tr>
	  <td><code>powderblue</code></td>
	  <td><code>#b0e0e6</code></td>
	  <td style="color: powderblue">powderblue</td>
	</tr>
	<tr>
	  <td><code>purple</code></td>
	  <td><code>#800080</code></td>
	  <td style="color: purple">purple</td>
	</tr>
	<tr>
	  <td><code>rebeccapurple</code></td>
	  <td><code>#663399</code></td>
	  <td style="color: rebeccapurple">rebeccapurple</td>
	</tr>
	<tr>
	  <td><code>red</code></td>
	  <td><code>#ff0000</code></td>
	  <td style="color: red">red</td>
	</tr>
	<tr>
	  <td><code>rosybrown</code></td>
	  <td><code>#bc8f8f</code></td>
	  <td style="color: rosybrown">rosybrown</td>
	</tr>
	<tr>
	  <td><code>royalblue</code></td>
	  <td><code>#4169e1</code></td>
	  <td style="color: royalblue">royalblue</td>
	</tr>
	<tr>
	  <td><code>saddlebrown</code></td>
	  <td><code>#8b4513</code></td>
	  <td style="color: saddlebrown">saddlebrown</td>
	</tr>
	<tr>
	  <td><code>salmon</code></td>
	  <td><code>#fa8072</code></td>
	  <td style="color: salmon">salmon</td>
	</tr>
	<tr>
	  <td><code>sandybrown</code></td>
	  <td><code>#f4a460</code></td>
	  <td style="color: sandybrown">sandybrown</td>
	</tr>
	<tr>
	  <td><code>seagreen</code></td>
	  <td><code>#2e8b57</code></td>
	  <td style="color: seagreen">seagreen</td>
	</tr>
	<tr>
	  <td><code>seashell</code></td>
	  <td><code>#fff5ee</code></td>
	  <td style="color: seashell">seashell</td>
	</tr>
	<tr>
	  <td><code>sienna</code></td>
	  <td><code>#a0522d</code></td>
	  <td style="color: sienna">sienna</td>
	</tr>
	<tr>
	  <td><code>silver</code></td>
	  <td><code>#c0c0c0</code></td>
	  <td style="color: silver">silver</td>
	</tr>
	<tr>
	  <td><code>skyblue</code></td>
	  <td><code>#87ceeb</code></td>
	  <td style="color: skyblue">skyblue</td>
	</tr>
	<tr>
	  <td><code>slateblue</code></td>
	  <td><code>#6a5acd</code></td>
	  <td style="color: slateblue">slateblue</td>
	</tr>
	<tr>
	  <td><code>slategray</code></td>
	  <td><code>#708090</code></td>
	  <td style="color: slategray">slategray</td>
	</tr>
	<tr>
	  <td><code>slategrey</code></td>
	  <td><code>#708090</code></td>
	  <td style="color: slategrey">slategrey</td>
	</tr>
	<tr>
	  <td><code>snow</code></td>
	  <td><code>#fffafa</code></td>
	  <td style="color: snow">snow</td>
	</tr>
	<tr>
	  <td><code>springgreen</code></td>
	  <td><code>#00ff7f</code></td>
	  <td style="color: springgreen">springgreen</td>
	</tr>
	<tr>
	  <td><code>steelblue</code></td>
	  <td><code>#4682b4</code></td>
	  <td style="color: steelblue">steelblue</td>
	</tr>
	<tr>
	  <td><code>tan</code></td>
	  <td><code>#d2b48c</code></td>
	  <td style="color: tan">tan</td>
	</tr>
	<tr>
	  <td><code>teal</code></td>
	  <td><code>#008080</code></td>
	  <td style="color: teal">teal</td>
	</tr>
	<tr>
	  <td><code>thistle</code></td>
	  <td><code>#d8bfd8</code></td>
	  <td style="color: thistle">thistle</td>
	</tr>
	<tr>
	  <td><code>tomato</code></td>
	  <td><code>#ff6347</code></td>
	  <td style="color: tomato">tomato</td>
	</tr>
	<tr>
	  <td><code>transparent</code></td>
	  <td>See <a href="#transparent">transparent</a>.</td>
	  <td style="color: transparent">transparent</td>
	</tr>
	<tr>
	  <td><code>turquoise</code></td>
	  <td><code>#40e0d0</code></td>
	  <td style="color: turquoise">turquoise</td>
	</tr>
	<tr>
	  <td><code>violet</code></td>
	  <td><code>#ee82ee</code></td>
	  <td style="color: violet">violet</td>
	</tr>
	<tr>
	  <td><code>wheat</code></td>
	  <td><code>#f5deb3</code></td>
	  <td style="color: wheat">wheat</td>
	</tr>
	<tr>
	  <td><code>white</code></td>
	  <td><code>#ffffff</code></td>
	  <td style="color: white">white</td>
	</tr>
	<tr>
	  <td><code>whitesmoke</code></td>
	  <td><code>#f5f5f5</code></td>
	  <td style="color: whitesmoke">whitesmoke</td>
	</tr>
	<tr>
	  <td><code>yellow</code></td>
	  <td><code>#ffff00</code></td>
	  <td style="color: yellow">yellow</td>
	</tr>
	<tr>
	  <td><code>yellowgreen</code></td>
	  <td><code>#9acd32</code></td>
	  <td style="color: yellowgreen">yellowgreen</td>
	</tr>
	<tr></tr>
      </tbody>
    </table>
  </body>
</html>

@benoit-pierre

benoit-pierre commented Aug 4, 2024

Copy link
Copy Markdown
Member

Quick and dirty patch:

--- a/source/html/css-apply.c
+++ b/source/html/css-apply.c
@@ -48,24 +48,307 @@
 };
 
 static const char *color_kw[] = {
+	"aliceblue",
+	"antiquewhite",
 	"aqua",
+	"aquamarine",
+	"azure",
+	"beige",
+	"bisque",
 	"black",
+	"blanchedalmond",
 	"blue",
+	"blueviolet",
+	"brown",
+	"burlywood",
+	"cadetblue",
+	"chartreuse",
+	"chocolate",
+	"coral",
+	"cornflowerblue",
+	"cornsilk",
+	"crimson",
+	"cyan",
+	"darkblue",
+	"darkcyan",
+	"darkgoldenrod",
+	"darkgray",
+	"darkgreen",
+	"darkgrey",
+	"darkkhaki",
+	"darkmagenta",
+	"darkolivegreen",
+	"darkorange",
+	"darkorchid",
+	"darkred",
+	"darksalmon",
+	"darkseagreen",
+	"darkslateblue",
+	"darkslategray",
+	"darkslategrey",
+	"darkturquoise",
+	"darkviolet",
+	"deeppink",
+	"deepskyblue",
+	"dimgray",
+	"dimgrey",
+	"dodgerblue",
+	"firebrick",
+	"floralwhite",
+	"forestgreen",
 	"fuchsia",
+	"gainsboro",
+	"ghostwhite",
+	"gold",
+	"goldenrod",
 	"gray",
 	"green",
+	"greenyellow",
+	"grey",
+	"honeydew",
+	"hotpink",
+	"indianred",
+	"indigo",
+	"ivory",
+	"khaki",
+	"lavender",
+	"lavenderblush",
+	"lawngreen",
+	"lemonchiffon",
+	"lightblue",
+	"lightcoral",
+	"lightcyan",
+	"lightgoldenrodyellow",
+	"lightgray",
+	"lightgreen",
+	"lightgrey",
+	"lightpink",
+	"lightsalmon",
+	"lightseagreen",
+	"lightskyblue",
+	"lightslategray",
+	"lightslategrey",
+	"lightsteelblue",
+	"lightyellow",
 	"lime",
+	"limegreen",
+	"linen",
+	"magenta",
 	"maroon",
+	"mediumaquamarine",
+	"mediumblue",
+	"mediumorchid",
+	"mediumpurple",
+	"mediumseagreen",
+	"mediumslateblue",
+	"mediumspringgreen",
+	"mediumturquoise",
+	"mediumvioletred",
+	"midnightblue",
+	"mintcream",
+	"mistyrose",
+	"moccasin",
+	"navajowhite",
 	"navy",
+	"oldlace",
 	"olive",
+	"olivedrab",
 	"orange",
+	"orangered",
+	"orchid",
+	"palegoldenrod",
+	"palegreen",
+	"paleturquoise",
+	"palevioletred",
+	"papayawhip",
+	"peachpuff",
+	"peru",
+	"pink",
+	"plum",
+	"powderblue",
 	"purple",
+	"rebeccapurple",
 	"red",
+	"rosybrown",
+	"royalblue",
+	"saddlebrown",
+	"salmon",
+	"sandybrown",
+	"seagreen",
+	"seashell",
+	"sienna",
 	"silver",
+	"skyblue",
+	"slateblue",
+	"slategray",
+	"slategrey",
+	"snow",
+	"springgreen",
+	"steelblue",
+	"tan",
 	"teal",
+	"thistle",
+	"tomato",
 	"transparent",
+	"turquoise",
+	"violet",
+	"wheat",
 	"white",
+	"whitesmoke",
 	"yellow",
+	"yellowgreen",
+};
+
+static uint8_t color_rgb[][3] = {
+	{ 240, 248, 255 },
+	{ 250, 235, 215 },
+	{ 0, 255, 255 },
+	{ 127, 255, 212 },
+	{ 240, 255, 255 },
+	{ 245, 245, 220 },
+	{ 255, 228, 196 },
+	{ 0, 0, 0 },
+	{ 255, 235, 205 },
+	{ 0, 0, 255 },
+	{ 138, 43, 226 },
+	{ 165, 42, 42 },
+	{ 222, 184, 135 },
+	{ 95, 158, 160 },
+	{ 127, 255, 0 },
+	{ 210, 105, 30 },
+	{ 255, 127, 80 },
+	{ 100, 149, 237 },
+	{ 255, 248, 220 },
+	{ 220, 20, 60 },
+	{ 0, 255, 255 },
+	{ 0, 0, 139 },
+	{ 0, 139, 139 },
+	{ 184, 134, 11 },
+	{ 169, 169, 169 },
+	{ 0, 100, 0 },
+	{ 169, 169, 169 },
+	{ 189, 183, 107 },
+	{ 139, 0, 139 },
+	{ 85, 107, 47 },
+	{ 255, 140, 0 },
+	{ 153, 50, 204 },
+	{ 139, 0, 0 },
+	{ 233, 150, 122 },
+	{ 143, 188, 143 },
+	{ 72, 61, 139 },
+	{ 47, 79, 79 },
+	{ 47, 79, 79 },
+	{ 0, 206, 209 },
+	{ 148, 0, 211 },
+	{ 255, 20, 147 },
+	{ 0, 191, 255 },
+	{ 105, 105, 105 },
+	{ 105, 105, 105 },
+	{ 30, 144, 255 },
+	{ 178, 34, 34 },
+	{ 255, 250, 240 },
+	{ 34, 139, 34 },
+	{ 255, 0, 255 },
+	{ 220, 220, 220 },
+	{ 248, 248, 255 },
+	{ 255, 215, 0 },
+	{ 218, 165, 32 },
+	{ 128, 128, 128 },
+	{ 0, 128, 0 },
+	{ 173, 255, 47 },
+	{ 128, 128, 128 },
+	{ 240, 255, 240 },
+	{ 255, 105, 180 },
+	{ 205, 92, 92 },
+	{ 75, 0, 130 },
+	{ 255, 255, 240 },
+	{ 240, 230, 140 },
+	{ 230, 230, 250 },
+	{ 255, 240, 245 },
+	{ 124, 252, 0 },
+	{ 255, 250, 205 },
+	{ 173, 216, 230 },
+	{ 240, 128, 128 },
+	{ 224, 255, 255 },
+	{ 250, 250, 210 },
+	{ 211, 211, 211 },
+	{ 144, 238, 144 },
+	{ 211, 211, 211 },
+	{ 255, 182, 193 },
+	{ 255, 160, 122 },
+	{ 32, 178, 170 },
+	{ 135, 206, 250 },
+	{ 119, 136, 153 },
+	{ 119, 136, 153 },
+	{ 176, 196, 222 },
+	{ 255, 255, 224 },
+	{ 0, 255, 0 },
+	{ 50, 205, 50 },
+	{ 250, 240, 230 },
+	{ 255, 0, 255 },
+	{ 128, 0, 0 },
+	{ 102, 205, 170 },
+	{ 0, 0, 205 },
+	{ 186, 85, 211 },
+	{ 147, 112, 219 },
+	{ 60, 179, 113 },
+	{ 123, 104, 238 },
+	{ 0, 250, 154 },
+	{ 72, 209, 204 },
+	{ 199, 21, 133 },
+	{ 25, 25, 112 },
+	{ 245, 255, 250 },
+	{ 255, 228, 225 },
+	{ 255, 228, 181 },
+	{ 255, 222, 173 },
+	{ 0, 0, 128 },
+	{ 253, 245, 230 },
+	{ 128, 128, 0 },
+	{ 107, 142, 35 },
+	{ 255, 165, 0 },
+	{ 255, 69, 0 },
+	{ 218, 112, 214 },
+	{ 238, 232, 170 },
+	{ 152, 251, 152 },
+	{ 175, 238, 238 },
+	{ 219, 112, 147 },
+	{ 255, 239, 213 },
+	{ 255, 218, 185 },
+	{ 205, 133, 63 },
+	{ 255, 192, 203 },
+	{ 221, 160, 221 },
+	{ 176, 224, 230 },
+	{ 128, 0, 128 },
+	{ 102, 51, 153 },
+	{ 255, 0, 0 },
+	{ 188, 143, 143 },
+	{ 65, 105, 225 },
+	{ 139, 69, 19 },
+	{ 250, 128, 114 },
+	{ 244, 164, 96 },
+	{ 46, 139, 87 },
+	{ 255, 245, 238 },
+	{ 160, 82, 45 },
+	{ 192, 192, 192 },
+	{ 135, 206, 235 },
+	{ 106, 90, 205 },
+	{ 112, 128, 144 },
+	{ 112, 128, 144 },
+	{ 255, 250, 250 },
+	{ 0, 255, 127 },
+	{ 70, 130, 180 },
+	{ 210, 180, 140 },
+	{ 0, 128, 128 },
+	{ 216, 191, 216 },
+	{ 255, 99, 71 },
+	{ 0, 0, 0 },
+	{ 64, 224, 208 },
+	{ 238, 130, 238 },
+	{ 245, 222, 179 },
+	{ 255, 255, 255 },
+	{ 245, 245, 245 },
+	{ 255, 255, 0 },
+	{ 154, 205, 50 },
 };
 
 static const char *list_style_type_kw[] = {
@@ -106,7 +387,7 @@
 		else if (c > 0)
 			l = m + 1;
 		else
-			return 1;
+			return m + 1;
 	}
 	return 0;
 }
@@ -1116,43 +1397,12 @@
 
 	if (value->type == CSS_KEYWORD)
 	{
-		if (!strcmp(value->data, "transparent"))
-			return make_color(0, 0, 0, 0);
+		int n = keyword_in_list(value->data, color_kw, nelem(color_kw));
+		if (!n)
+			goto hex_color; /* last ditch attempt: maybe it's a #XXXXXX color without the # */
+		if (--n == 141)
+			return make_color(0, 0, 0, 0); // transparent
-		if (!strcmp(value->data, "maroon"))
-			return make_color(0x80, 0x00, 0x00, 255);
-		if (!strcmp(value->data, "red"))
-			return make_color(0xFF, 0x00, 0x00, 255);
-		if (!strcmp(value->data, "orange"))
-			return make_color(0xFF, 0xA5, 0x00, 255);
-		if (!strcmp(value->data, "yellow"))
-			return make_color(0xFF, 0xFF, 0x00, 255);
-		if (!strcmp(value->data, "olive"))
-			return make_color(0x80, 0x80, 0x00, 255);
-		if (!strcmp(value->data, "purple"))
-			return make_color(0x80, 0x00, 0x80, 255);
-		if (!strcmp(value->data, "fuchsia"))
-			return make_color(0xFF, 0x00, 0xFF, 255);
-		if (!strcmp(value->data, "white"))
-			return make_color(0xFF, 0xFF, 0xFF, 255);
-		if (!strcmp(value->data, "lime"))
-			return make_color(0x00, 0xFF, 0x00, 255);
-		if (!strcmp(value->data, "green"))
-			return make_color(0x00, 0x80, 0x00, 255);
-		if (!strcmp(value->data, "navy"))
-			return make_color(0x00, 0x00, 0x80, 255);
-		if (!strcmp(value->data, "blue"))
-			return make_color(0x00, 0x00, 0xFF, 255);
-		if (!strcmp(value->data, "aqua"))
-			return make_color(0x00, 0xFF, 0xFF, 255);
-		if (!strcmp(value->data, "teal"))
-			return make_color(0x00, 0x80, 0x80, 255);
-		if (!strcmp(value->data, "black"))
-			return make_color(0x00, 0x00, 0x00, 255);
-		if (!strcmp(value->data, "silver"))
-			return make_color(0xC0, 0xC0, 0xC0, 255);
-		if (!strcmp(value->data, "gray"))
-			return make_color(0x80, 0x80, 0x80, 255);
-		goto hex_color; /* last ditch attempt: maybe it's a #XXXXXX color without the # */
+		return make_color(color_rgb[n][0], color_rgb[n][1], color_rgb[n][2], 255);
 	}
 	return initial;
 }

@ptrm: do you have a dev environment?

@ptrm

ptrm commented Aug 4, 2024

Copy link
Copy Markdown
Contributor

do you have a dev environment?

@benoit-pierre I do on a Mac. Cross compiling isn't needed I guess? (Few months ago it didn't want to work even on Debian arm VM, but I saw commits mentioning mac build fixes since then)

Edit: Bottom line is I'll try applying it ;)

@benoit-pierre

Copy link
Copy Markdown
Member

Support for latest XCode version, yes.

If you want to give the patch a try:

  • save it to base/thirdparty/mupdf/css_color_names.patch
  • update base/thirdparty/mupdf/CMakeLists.txt:
index 38eecb6c..af21b55f 100644
--- i/thirdparty/mupdf/CMakeLists.txt
+++ w/thirdparty/mupdf/CMakeLists.txt
@@ -19,6 +19,8 @@ list(APPEND PATCH_FILES
     relink_on_xlibs_change.patch
     # Fix symbols visiblity.
     visibility.patch
+    # Expand list of supported CSS color names.
+    css_color_names.patch
 )
 
 list(APPEND PATCH_CMD COMMAND rm -rf

0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Latest MuPDF update changed HTML parsing, and use a better
HTML5 parser, which may cause some issues with the XHTML
we get from crengine.
So, for footnote popups, be sure we use MuPDF's XHTML parser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tags in popup fotnote

4 participants