-
Notifications
You must be signed in to change notification settings - Fork 20
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
use release version of pdf.js #116
Conversation
@@ -112,11 +112,11 @@ internal class PdfStaticServer : HttpRequestHandler() { | |||
fun getPreviewUrl(file: VirtualFile, withReloadSalt: Boolean = false): String { | |||
val salt = if (withReloadSalt) Random.nextInt() else 0 | |||
vfsMap[file.url] = file | |||
val url = parseEncodedPath("$serverUrl/index.html") | |||
val url = parseEncodedPath("$serverUrl/web/viewer.html") |
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.
entry point of mozilla's pdf.js
val server = BuiltInServerManager.getInstance() | ||
return server.addAuthToken(url) | ||
// `file` would be read via `urlDecoder.path()`, which calls `decodeComponent` | ||
.addParameters(mapOf("__reloadSalt" to "$salt", "file" to URLUtil.encodeURIComponent("get-file/${file.url}"))) | ||
.addParameters(mapOf("__reloadSalt" to "$salt", "file" to "/$uuid/get-file/${URLUtil.encodeURIComponent(file.url)}")) |
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.
as we use web/viewer.html, so change the file to absolute path.
doLast { | ||
val viewerHtml = layout.buildDirectory.get().asFile.resolve("web/viewer.html") | ||
val modifiedContent = viewerHtml.readText() | ||
.replace("(<link rel=\"stylesheet\" href=\"viewer.css\">)".toRegex(), "$1<link rel=\"stylesheet\" href=\"../fixes.css\">") |
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.
This is the magic 1, add our css after original viewer.css
val viewerHtml = layout.buildDirectory.get().asFile.resolve("web/viewer.html") | ||
val modifiedContent = viewerHtml.readText() | ||
.replace("(<link rel=\"stylesheet\" href=\"viewer.css\">)".toRegex(), "$1<link rel=\"stylesheet\" href=\"../fixes.css\">") | ||
.replace("(<script src=\"viewer.m?js\"[^<>]*></script>)".toRegex(), "$1<script src=\"../viewer.js\"></script>") |
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.
This is the magic 2, add our js after original viewer.js
|
||
@ExperimentalSerializationApi | ||
fun main() { | ||
ApplicationFactory.init() |
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.
point to inject our javascript.
1. navigateTo is removed since v2.9.359 ref: mozilla/pdf.js@92ec10b 2. the type of `dest` in outline is `{string | Array<any> | null}` we use `JsonElement` to indicate
This version won't use |
|
||
@Serializable | ||
data class InternalOutline( | ||
val dest: String, | ||
val dest: JsonElement, |
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.
the dest in outline is {string | Array | null}
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.
Great! This solution is a lot cleaner. I'll create a release with this included.
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.
This version won't use
pdf_viewer.css
, it may break theme values. However, there areviewerCssTheme
andpageColorsBackground
,pageColorsForeground
.pageColorsXXX
is available since pdf.js v2.14+, in commit mozilla/pdf.js@c8afd6c
Wait, as you say, something is not working with the theme. The background color of the sidebar is not correct anymore:
before:
@PHPirates it's nothing with Lines 44 to 50 in fa79e56
There is no There is no I'll use the this new way with the old pdf.js, may be a downgrade until we solve the css. |
pdf.js sidebar triangles switched to svg since 2.6.347 in commit mozilla/pdf.js@c0b671d However, previous viewer.css use a png, so it need fix Now, we use pdf.js version, which use svg already
@PHPirates I have added severa commits, please help to review. And, I cannot reproduct your sidebar's screenshot. And, for the sidebar on macos, now, it shows always. However, I think it's acceptable, and Markdown plugin show the scrollbar always too. And, the scrollbar looks like the same as markdown plugin now. |
@PHPirates Just found the differences. In pdf.js v2.7 and v0.16.1, the background color of sidebar is intellij-pdf-viewer/web-view/bootstrap/src/viewer.css Lines 258 to 266 in 75b76e6
https://github.com/mozilla/pdf.js/blob/v2.7.350/web/viewer.css#L258-L266 However, intellij-pdf-viewer want to change sidebar background color to the same as body background color. Lines 17 to 18 in fa79e56
However, I don't know why your screenshot don't update the background. Please use DevTools to find it. |
Thanks for the explanation! Sorry must have been something wrong on my side, after a gradle clean everything works as expected. Also changing the background color in the PDF Viewer settings work fine (foreground The scrollbar looks good to me, much better than it was! |
upstream change the background-color of narrow sidebar to --sidebar-narrow-bg-color in commit mozilla/pdf.js@7c52c01 since v2.8.335
There is no `border-image` in `.pdfViewer .page` since v3.3.122, see mozilla/pdf.js@685b586 There is no `box-shadow` in `.thumbnailImage` since v3.6.172, see mozilla/pdf.js@1b6a83d #116 (comment)
@PHPirates I self-review again, and it could be merged into master now. For the events in 062acd1#diff-85699ae3492958e0a83d3d768422d1124006a9213eaa31c775de20f22a4755a5L223-L243 it's introduced in a2d6bdd, the commit message is to add mouse shortcuts for zoom in/out, however, it's core function was removed as in another commit ad34116 |
Great, thanks for checking! |
As discussing in #114, there are several options to include pdf.js.
In #114, we choose compile from pdf.js's source code.
However, we don't need to.
This PR simplify the processes, just download and unzip, the inject intellij-pdf-viewer's js and css, make it much easy.