[squeak-dev] The Trunk: Graphics-mt.455.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Dec 30 15:22:32 UTC 2021


Marcel Taeumel uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-mt.455.mcz

==================== Summary ====================

Name: Graphics-mt.455
Author: mt
Time: 30 December 2021, 4:22:26.004748 pm
UUID: 126ab0af-db2f-614d-b33e-a1f2fdcc79f3
Ancestors: Graphics-mt.454

Turns Squeak's Demo/High-DPI mode into a flexible scale factor. See http://lists.squeakfoundation.org/pipermail/squeak-dev/2021-December/217747.html

All existing StrikeFonts are updated to have a pointSize that matches about 96.0 pixels-per-inch.

=============== Diff against Graphics-mt.454 ===============

Item was changed:
  Form subclass: #DisplayScreen
  	instanceVariableNames: 'clippingBox extraRegions'
+ 	classVariableNames: 'DeferringUpdates DisplayChangeSignature DisplayIsFullScreen PlatformScaleFactor RelativeScaleFactorEnabled'
- 	classVariableNames: 'DeferringUpdates DisplayChangeSignature DisplayIsFullScreen'
  	poolDictionaries: ''
  	category: 'Graphics-Display Objects'!
  
  !DisplayScreen commentStamp: '<historical>' prior: 0!
  There is only one instance of me, Display. It is a global and is used to handle general user requests to deal with the whole display screen. 
  	Although I offer no protocol, my name provides a way to distinguish this special instance from all other Forms. This is useful, for example, in dealing with saving and restoring the system.
  	To change the depth of your Display...
  		Display newDepth: 16.
  		Display newDepth: 8.
  		Display newDepth: 1.
  Valid display depths are 1, 2, 4, 8, 16 and 32.  It is suggested that you run with your monitors setting the same, for better speed and color fidelity.  Note that this can add up to 4Mb for the Display form.  Finally, note that newDepth: ends by executing a 'ControlManager restore' which currently terminates the active process, so nothing that follows in the doit will get executed.
  
  Depths 1, 2, 4 and 8 bits go through a color map to put color on the screen, but 16 and 32-bit color use the pixel values directly for RGB color (5 and 8 bits per, respectivlely).  The color choice an be observed by executing Color fromUser in whatever depth you are using.
  !

Item was added:
+ ----- Method: DisplayScreen class>>actualScreenScaleFactor (in category 'snapshots') -----
+ actualScreenScaleFactor
+ 	"<primitive: #primitiveScreenScaleFactor>"
+ 	"Once the primitive is ready, you can simply uncomment it. The system is prepared for changes from 'nil' to actual factors and back."
+ 
+ 	^ nil "unknown -- do not default to 1.0 here"!

Item was added:
+ ----- Method: DisplayScreen class>>checkForNewScreenScaleFactor (in category 'display box access') -----
+ checkForNewScreenScaleFactor
+ 	"Check whether the platform's scale factor has changed and if so take appropriate actions"
+ 
+ 	Display platformScaleFactor: DisplayScreen actualScreenScaleFactor.!

Item was added:
+ ----- Method: DisplayScreen class>>relativeScaleFactor (in category 'preferences') -----
+ relativeScaleFactor
+ 	<preference: 'Scale Factor'
+ 		categoryList: #(Morphic Tools visuals)
+ 		description: 'Set the size of fonts and tools according to the pixels-per-inch of your display. Can be used to zoom in even further.'
+ 		type: #String>
+ 
+ 	^ Display relativeUiScaleFactor!

Item was added:
+ ----- Method: DisplayScreen class>>relativeScaleFactor: (in category 'preferences') -----
+ relativeScaleFactor: aFloatString
+ 
+ 	Display relativeUiScaleFactor: (aFloatString ifNotNil: [:s | s asNumber] ifNil: [1.0]).!

Item was added:
+ ----- Method: DisplayScreen class>>relativeScaleFactorEnabled (in category 'preferences') -----
+ relativeScaleFactorEnabled
+ 	<preference: 'Show Relative Scale Factor'
+ 		categoryList: #(Morphic Tools visuals)
+ 		description: 'When true, 100% means as-the-platform/monitor-demands, which is typical for macOS. When false, 100% means pixel-perfect, which is typical for Windows. Only works if #platformScaleFactorKnown.'
+ 		type: #Boolean>
+ 
+ 	"Note that we set the default to 'false' because pixels are very prominent in the Morphic programming model. So it makes sense to communcate this kind of pixel scaling openly and thus not hide the #platformScaleFactor from the user."
+ 	^ RelativeScaleFactorEnabled ifNil: [false].!

Item was added:
+ ----- Method: DisplayScreen class>>relativeScaleFactorEnabled: (in category 'preferences') -----
+ relativeScaleFactorEnabled: aBoolean
+ 
+ 	RelativeScaleFactorEnabled := Display platformScaleFactorKnown and: [aBoolean ifNil: [false]].!

Item was added:
+ ----- Method: DisplayScreen>>currentScaleError (in category 'scale factor') -----
+ currentScaleError
+ 	"Documentation and debugging only. The scale error originates in rounding errors while rendering the standard TTCFont font into pixels or using a pre-rendered StrikeFont in the first place.
+ 	
+ 	Display currentScaleError
+ 	"
+ 	
+ 	^ RealEstateAgent scaleFactor - self uiScaleFactor
+ 	
+ "
+ | errors current |
+ errors := OrderedDictionary new.
+ current := Display uiScaleFactor.
+ 1.0 to: 3.0 by: 0.25 do: [:s |
+ 	Display uiScaleFactor: s.
+ 	errors at: s put: Display currentScaleError].
+ Display uiScaleFactor: current.
+ errors explore.
+ "!

Item was added:
+ ----- Method: DisplayScreen>>platformScaleFactor (in category 'scale factor') -----
+ platformScaleFactor
+ 	"Answers the platform's (and thus monitor's) current scale factor as last reported via VM primitive. See #checkForNewScreenScaleFactor."
+ 
+ 	^ PlatformScaleFactor ifNil: [1.0 "Primitive not ready."]!

Item was added:
+ ----- Method: DisplayScreen>>platformScaleFactor: (in category 'scale factor') -----
+ platformScaleFactor: aFloatOrNil
+ 	"Report a new scale factor from the platform to the image. This can happen if you move Squeak's window between monitors with different pixels-per-inch. On some platforms, you can also set a scale factor independent of monitor PPI. Note that the user might have scaled the image regardless of the previous platform scale factor."
+ 
+ 	| old new |
+ 	aFloatOrNil ifNil: [
+ 		"Ignore. Primitive not ready (anymore)."
+ 		PlatformScaleFactor := nil.
+ 		^ self].
+ 	PlatformScaleFactor ifNil: [
+ 		"First time. Ignore. Assume that the user scaled manually until now."
+ 		PlatformScaleFactor := aFloatOrNil.
+ 		^ self].
+ 	
+ 	(old := self platformScaleFactor) = (new := aFloatOrNil) ifTrue: [^ self].
+ 	PlatformScaleFactor := new.
+ 	self uiScaleFactor: self uiScaleFactor * (new/old).!

Item was added:
+ ----- Method: DisplayScreen>>platformScaleFactorKnown (in category 'scale factor') -----
+ platformScaleFactorKnown
+ 	"Tools can help users understand whether Squeak will adjust the scale factor automatically or whether they have to scale manually. See class-side's #actualScreenScaleFactor and also #relativeUiScaleFactor."
+ 
+ 	^ PlatformScaleFactor notNil!

Item was added:
+ ----- Method: DisplayScreen>>relativeUiScaleFactor (in category 'scale factor') -----
+ relativeUiScaleFactor
+ 	"Answers the scale factor as perceived by the user. Note that this concept might be platform-dependent. On Windows, for example, 100% means pixel-perfect while on macOS 100% means as-the-monitor-demands. So, Retina displays are effectively scaled even if the user sees 100% in a Choose-Your-Scale dialog."
+ 	
+ 	^ self class relativeScaleFactorEnabled
+ 		ifTrue: [ "macOS" self uiScaleFactor / self platformScaleFactor ]
+ 		ifFalse: [ "Windows" self uiScaleFactor ]!

Item was added:
+ ----- Method: DisplayScreen>>relativeUiScaleFactor: (in category 'scale factor') -----
+ relativeUiScaleFactor: aFloat
+ 	
+ 	^ self class relativeScaleFactorEnabled
+ 		ifTrue: [ "macOS" self uiScaleFactor: aFloat * self platformScaleFactor ]
+ 		ifFalse: [ "Windows" self uiScaleFactor: aFloat ]!

Item was added:
+ ----- Method: DisplayScreen>>uiScaleFactor (in category 'scale factor') -----
+ uiScaleFactor
+ 	"Answers the current scale factor used to configure all widgets, tools, or windows to be prepared for the current rendering system, i.e., BitBlt. Note that 1.0 means 'pixel perfect'."
+ 	
+ 	^ UserInterfaceTheme current isTTCBased
+ 		ifTrue: [TextStyle pixelsPerInch / 96.0 "Hide rounding errors in TTCFont >> #height."]
+ 		ifFalse: [RealEstateAgent scaleFactor roundTo: 0.25 "Force 25% steps. See, e.g., #doScale150."].!

Item was added:
+ ----- Method: DisplayScreen>>uiScaleFactor: (in category 'scale factor') -----
+ uiScaleFactor: aFloat
+ 	"Sets the effective scale factor for the user interface, i.e., all widgets, tools, and windows. The user can override the CurrentScaleFactor recommended by the platform."
+ 
+ 	| oldFactor newFactor |
+ 	(UserInterfaceTheme current canFakeScaleFactor: aFloat) ifTrue: [
+ 		self flag: #isTTCBased.
+ 		^ UserInterfaceTheme current applyScaled: aFloat].
+ 	
+ 	oldFactor := RealEstateAgent scaleFactor. "Use effective, pixel-based factor to account for rounding errors. See #isTTCBased and #uiScaleFactor."
+ 	newFactor := aFloat max: 1.0.
+ 	newFactor = oldFactor ifTrue: [^ self].
+ 	
+ 	TextStyle pixelsPerInch: 96.0 * aFloat.
+ 	newFactor := RealEstateAgent resetScaleFactor; scaleFactor. "Again, account for rounding errors."
+ 	Project current ifNotNil: [:p | p displayScaleChangedFrom: oldFactor to: newFactor].!

Item was changed:
  ----- Method: TextStyle class>>pixelsPerInch: (in category 'utilities') -----
  pixelsPerInch: aNumber
  	"Set the nominal number of pixels per inch to aNumber."
+ 
+ 	self pixelsPerInch = aNumber ifTrue: [^ self].
+ 	TextConstants at: #pixelsPerInch put: aNumber.
+ 	AbstractFont allSubInstancesDo: [ :font | font pixelsPerInchChanged ].!
- 	TextConstants at: #pixelsPerInch put: aNumber asFloat.
- 	AbstractFont allSubInstancesDo: [ :font | font pixelsPerInchChanged ].
- 	Display restore.!

Item was changed:
+ (PackageInfo named: 'Graphics') postscript: '"Unpack unnecessary StrikeFontSet in Accuny."
+ (TextStyle named: ''Accuny'') ifNotNil: [:style |
+ 	style fontArray withIndexDo: [:fontSet :index |
+ 		((fontSet isKindOf: StrikeFontSet) and: [fontSet fontArray size = 1])
+ 			ifTrue: [style fontArray at: index put: fontSet fontArray first]]].
+ 	
+ "Fix font names for Atlanta."
+ (TextStyle named: ''Atlanta'') fontArray do: [:font |
+ 	font name last isDigit ifFalse: [font name: font name, font pointSize]].
+ 
+ "Fix PPI to be around 96 in all pre-rendered fonts."
+ (TextStyle knownTextStylesWithoutDefault
+ 	collect: [:ea | TextStyle named: ea]
+ 	thenSelect: [:style | style defaultFont isTTCFont not])
+ 		do: [:style | style fontArray do: [:font |
+ 			font pointSize: ((72 * font height / 96) roundTo: 0.5).
+ 			font derivativeFonts do: [:derivate |
+ 				derivate pointSize: font pointSize]]].'!
- (PackageInfo named: 'Graphics') postscript: 'Smalltalk removeFromStartUpList: DisplayScreen. "see Project class >> #startUp"
- Smalltalk removeFromShutDownList: DisplayScreen. "see Project class >> #shutDown"'!



More information about the Squeak-dev mailing list