After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 768003 - Apply styling in epub
Apply styling in epub
Status: RESOLVED OBSOLETE
Product: gnome-documents
Classification: Core
Component: books
unspecified
Other All
: Normal normal
: ---
Assigned To: GNOME Books Maintainers
GNOME documents maintainer(s)
: 792541 (view as bug list)
Depends on:
Blocks: 768004
 
 
Reported: 2016-06-24 11:33 UTC by Bastien Nocera
Modified: 2021-07-05 11:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
document css change example (1.13 KB, patch)
2017-06-08 13:14 UTC, Daniel Garcia
none Details | Review
document css change example (2.98 KB, patch)
2017-06-09 07:50 UTC, Daniel Garcia
none Details | Review
epub style change example code (3.01 KB, patch)
2018-01-17 08:35 UTC, Bastien Nocera
reviewed Details | Review

Description Bastien Nocera 2016-06-24 11:33:26 UTC
Something that looks more like an electronic book, and less like a 1990's HTML home page:
https://people.gnome.org/~hadess/gnome-books-examples/ibooks-ios/
https://people.gnome.org/~hadess/gnome-books-examples/ibooks-osx/
Comment 1 Daniel Garcia 2017-06-08 13:14:47 UTC
Created attachment 353381 [details] [review]
document css change example

This patch is an example of how we can change the style of the document loaded injecting javascript.

In this patch I only change body style property, but we can add html elements and styles so we can do anything.
Comment 2 Bastien Nocera 2017-06-08 14:44:07 UTC
(In reply to Daniel Garcia from comment #1)
> Created attachment 353381 [details] [review] [review]
> document css change example
> 
> This patch is an example of how we can change the style of the document
> loaded injecting javascript.
> 
> In this patch I only change body style property, but we can add html
> elements and styles so we can do anything.

Could you please make the .css a separate file to be added to the GResources? That would make it easier to manage and avoid excessive quoting.

CC:ing Lapo and Jimmac
Comment 3 Daniel Garcia 2017-06-09 07:50:33 UTC
Created attachment 353440 [details] [review]
document css change example

This new patch uses a resource file called epub.css where you can define the css that will be applied to all epub docs.

I've also added a div '#epubwrap', to be able to style it, intead the body, so all the book content is inside this div. I think this can be useful.

And to make it easiest to debug and play with styles, I've enabled the dev tools of the webview widget, so now you can right click in the book content and inspect the html and edit the css and html in live.
Comment 4 Bastien Nocera 2018-01-17 08:35:57 UTC
Created attachment 366915 [details] [review]
epub style change example code

This will be the base code to add custom styles to the book view of epub
documents. It's a webkitwebview so we can run javascript and change the
body styles.
Comment 5 Bastien Nocera 2018-01-17 08:36:47 UTC
Fixed those bugs in the new patch (from bug 792541):

Gjs-Message: 18:37:27.180: JS WARNING: [resource:///org/gnome/Books/js/epubview.js 89]: Too many arguments to method WebKit2.WebView.run_javascript: expected 3, got 4
    Gjs-Message: 18:37:27.181: JS WARNING: [resource:///org/gnome/Books/js/epubview.js 98]: Too many arguments to method Gio.File.read: expected 1, got 2
    Gjs-Message: 18:37:27.183: JS WARNING: [resource:///org/gnome/Books/js/epubview.js 109]: Too many arguments to method WebKit2.WebView.run_javascript: expected 3, got 4
Comment 6 Bastien Nocera 2018-01-17 08:37:09 UTC
*** Bug 792541 has been marked as a duplicate of this bug. ***
Comment 7 Cosimo Cecchi 2018-01-19 17:20:38 UTC
Review of attachment 366915 [details] [review]:

Generally looks good to me with a few comments, but I assume we'll have to adjust the style before pushing this?

::: src/epubview.js
@@ +86,3 @@
+                      'document.body.innerHTML = \'<div id="gepubwrap">\'',
+                      '+ document.body.innerHTML + "</div>";'].join('');
+            this.view.run_javascript(js, null, null);

Why is the wrapper needed? It does not seem like either the CSS or the later JS use this ID.

@@ +89,3 @@
+
+            let file = Gio.File.new_for_uri("resource:///org/gnome/Documents/epub.css");
+                      'document.body.innerHTML = \'<div id="gepubwrap">\'',

Please use single quotes consistently.

@@ +96,3 @@
+                null).get_size();
+            let stream = file.read(null);
+            let file = Gio.File.new_for_uri("resource:///org/gnome/Documents/epub.css");

You can probably just call stream.read_all() instead of looking at the file size beforehand. Or use something like g_resources_lookup_data() which gives you a GBytes directly.
Comment 8 GNOME Infrastructure Team 2021-07-05 11:31:37 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/gnome-documents/-/issues/

Thank you for your understanding and your help.