Skip to content

Commit

Permalink
Add support for user stylesheet
Browse files Browse the repository at this point in the history
Fixes #947
  • Loading branch information
johnfactotum committed Jul 29, 2023
1 parent fd02c82 commit efc2dd4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/book-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ const invertTheme = ({ light, dark }) => ({ light, dark, inverted: {
link: utils.invertColor(dark.link),
} })

const userStylesheet = utils.readFile(Gio.File.new_for_path(
pkg.configpath('user-stylesheet.css')))

class BookData {
annotations = utils.connect(new AnnotationModel(), {
'update-annotation': async (_, annotation) => {
Expand Down Expand Up @@ -470,6 +473,7 @@ GObject.registerClass({
hyphenate: view.hyphenate,
invert: view.invert,
theme: view.invert ? invertTheme(theme) : theme,
userStylesheet,
},
})
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pkg.datadir = GLib.build_filenamev([GLib.get_user_data_dir(), pkg.name])
pkg.datapath = path => GLib.build_filenamev([pkg.datadir, path])
pkg.datafile = path => Gio.File.new_for_path(pkg.datapath(path))

pkg.configdir = GLib.build_filenamev([GLib.get_user_config_dir(), pkg.name])
pkg.configpath = path => GLib.build_filenamev([pkg.configdir, path])

pkg.cachedir = GLib.build_filenamev([GLib.get_user_cache_dir(), pkg.name])
pkg.cachepath = path => GLib.build_filenamev([pkg.cachedir, path])

Expand Down
4 changes: 2 additions & 2 deletions src/reader/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const open = async file => {
emit({ type: 'book-ready', book, reader })
}

const getCSS = ({ lineHeight, justify, hyphenate, invert, theme }) => [`
const getCSS = ({ lineHeight, justify, hyphenate, invert, theme, userStylesheet }) => [`
@namespace epub "http://www.idpf.org/2007/ops";
@media print {
html {
Expand Down Expand Up @@ -186,7 +186,7 @@ const getCSS = ({ lineHeight, justify, hyphenate, invert, theme }) => [`
text-align: ${justify ? 'justify' : 'start'};
-webkit-hyphens: ${hyphenate ? 'auto' : 'manual'};
}
`]
` + userStylesheet]

const frameRect = (frame, rect, sx = 1, sy = 1) => {
const left = sx * rect.left + frame.left
Expand Down

0 comments on commit efc2dd4

Please sign in to comment.