Skip to content
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 high-dpi mode for all screenshots #137

Merged
merged 66 commits into from
Jun 9, 2023
Merged

Use high-dpi mode for all screenshots #137

merged 66 commits into from
Jun 9, 2023

Conversation

LinqLover
Copy link
Collaborator

@LinqLover LinqLover commented Sep 28, 2022

This PR changes all figure scripts to use a high-dpi mode. Currently, a scale factor of 1000% is used.

Plan (see details below)

  • Discuss steps/necessity to improve performance.
  • Reassess figure dimensions in book?
  • Backport required Squeak Trunk fixes to 6.0.

About the scale factor

The reasoning for the chosen scale factor is:

We assume an intended print quality of 300 ppi, which seems to widely recommended.
One page might be ~8 inches wide, corresponding to 8 * 300 ppi = 2400 ppi.
To meet these requirements, a small screenshot, 200 px wide, would require 2400 ppi/200 px ~= 10 points/pixel.

Plus, 1000% just look extremely sharp even on my high-dpi monitor when I scroll into any screenshot:

image

Performance considerations

  • Space: File size (PDF) increased from 6 MB to 29 MB.
  • Build times (all numbers rounded to 5s, +/- pretty much due to CI fluctuations):
    • Figure generation slowed down from 115 s to 325 s.
    • PDF compilation slowed down from 60 s to 330 s.

Is this impact too large?

If yes, my recommendation would be to make the quality configurable so that we can still use the high quality for deploying the print version of the book (e.g., only when triggering a manual release through the CI).

  • If only the PDF size needs to be improved, we could just add another build step for compressing the PDF file There seem to be tools that could make this compression pretty straightforward.
  • If also the build times need to be improved, we can make SBEWorldHelper class>>#scaleFactor dynamic. But this increases the risk for unexpected figure slips that only occur for certain scale factors, as I have met some while migrating for this PR. I have not yet further spiked this.

Implementation

The key change is in 1af076a#diff-3c20f202c870e5c8070c65943b8b009add95dbfa97dd06304e4c152a68d23560 where the scale factor used during screenshotting is raised to 10. Besides, various places in the SBE-Extract logic and in the individual figure scripts are adjusted to be high-dpi-sensitive, i.e., using #px & Co. I had some fun converting the scripts semi-automatically, see the commit message in 01d95a3 for additional details.

All \includegraphics that used scale= are rewritten to width= to eliminate the dependency on a concrete scale factor. While I checked all figures in the book again, there might be some figures that no longer have to perfect size for your taste @codeZeilen.

Regarding the Morphic examples in the book (Quinto/SBE-Morphic), they are kept free from any high-dpi-aware code for sake of simplicity. Instead, a few relevant figure scripts rescale the morphs in question manually (see https://github.com/hpi-swa-lab/SqueakByExample-english/pull/137/files#diff-8c737ffb22e03102e18ddb43a4ff377860346cfad3c78badbe05e37a4b75c5f8R49-R57 for instance).

Also, some scripts are refactored and some figures (such as QuickTour/ClassBrowser2) receive minor optical tweaking.

Depends on Morphic-ct.2047 and Morphic-ct.2048, which are already integrated into Squeak 6.1Alpha and backported to Squeak 6.0. Without these patches, some lists were scrolled incorrectly, and some halo labels were truncated.


Integrates #136. Closes #35.

LinqLover and others added 5 commits September 28, 2022 13:58
Adapting all screenshots for high-dpi aware dimensions is yet to come ...
This did it:

	| matcher files |
	matcher := '%%\{(SBESqueakPicture)(([^\r\n]*([\r\n]|\r\n))%%)*(])\}' asRegex.
	files := SBEScriptBuilder getTexFilesIn: SBEScriptBuilder resourceDirectory.
	files
		collect: [:file | file -> (SBEScriptBuilder collectScriptsFromFile: file)]
		as: Dictionary.
	files do: [:file |
		file writeStreamDo: [:stream | | translated |
			translated := matcher copy: file contents translatingMatchesUsing: [:s | '\begin{ExecuteSmalltalkScript}' , (matcher subexpression: 5) , (((matcher subexpressions: 2) , (matcher subexpressions: 4) , (matcher subexpressions: 6)) join) , (matcher subexpression: 5) , '\end{ExecuteSmalltalkScript}'].
			stream reset; nextPutAll: translated]]
Regex:
    SBESqueakPicture( writeTo: .* (frame: .* ))using:(?= \[)
->
    SBEScreenshotRecorder$1building:
@LinqLover LinqLover self-assigned this Sep 28, 2022
@LinqLover
Copy link
Collaborator Author

This will take time.

This did it (thanks Copilot!):

    > const fs = require('fs')
    > const path = require('path')
    > const glob = require('glob')
    > const replace = require('replace-in-file')
    > var options = {
      files: glob.sync('**/*.tex', {ignore: ['**/node_modules/**']}),
      from: /(?<=\\begin\{ExecuteSmalltalkScript\}((?<!\\end\{ExecuteSmalltalkScript\})[\s\S\n\r])*(?<!(fraction:(\s*\d+(\.\d+)?\s*@\s*)?|crtab:|selection:|selectAt:|to:|by:|\/|\*|[<>])\s?)(?<!-|-?\d+\.\d*)\(?-?\d+(\.\d+)?(?! px)(?!(\d*\.)?\d))(?!\.png)(?![\}'"])(?!\s*to:)/gi,
      to: ' px',
    }
    > replace.sync(options)
In high-dpi mode, saving of scenes may actually take more than 5 seconds.
Basically, we must not use \includegraphics.scale any longer to avoid assumptions on the current scaleFactor for the screenshots.
Exclude very slow #testPercentEncodingJa.
@LinqLover LinqLover enabled auto-merge June 9, 2023 16:51
@LinqLover LinqLover merged commit 3b160d7 into master Jun 9, 2023
@LinqLover LinqLover deleted the high-dpi branch June 9, 2023 17:06
@LinqLover LinqLover mentioned this pull request Jun 27, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve resolution of screenshots
2 participants