TrueType based TextStyle

Phil Hargett hargettp at mindspring.com
Thu Dec 12 00:01:43 UTC 2002


Yoshiki,

Make that 2 vocal users of this thing: it's amazing how such a seemingly
simple visual detail as smooth, rich fonts make Squeak seem polished.

Here's a couple of changesets encompassing some tweaks I found helpful.

1) ProgressBarMorph.PH.1.cs -- I've modified the code that shows
"announcers" (e.g., those little progress bars that appear when filing in
code, among other things) to use a Morph.  This was helpful, as I could
not get earlier versions of TrueTypeTextStyle to show anything other than
white text on white background on those announcers.  This changeset
clearly assumes that Morphic is used, so this may not work for all, but it
has been pleasant for me.  I believe this changeset does add a couple of
methods to TTCFont, as they are necessary for the ProgressMorph code to
work.

2) TTCFont.class.PH.1.cs -- This code adds a service to the FileList so
that when a .TTF or .ttf file is selected in the file list pane, a button
is visible at the top labeled "install ttf" that allows on to install a
new TrueTypeTextStyle from the selected font file.  Thereafter, of course,
the font file is no longer needed.  The same action is available on the
FileList menu as well.

Oh, one other thing that I forgot: I have run into instances where
#maxWidth is sent to whatever font is being displayed; since I mostly use
your TrueType styles, missing this method gave me a walkback.  Adding
#maxWidth to TTCFont would be helpful; I implemented it by returning the
length of capital 'W'.

Thanks much for a more beautiful Smalltalk experience! :)

On Tue, 10 Dec 2002 Yoshiki.Ohshima at acm.org wrote:

>   Hello,
>
>   After releasing the previous versions, I've got a vocal user of this
> TrueTypeTextStyle thing:-) and had a chance to improve it one more
> round.  Now the code is cleaner and faster.
>
>   The attached one is intended to be filed into vanilla 3.2 or 3.4a
> images.
>
>   Any suggestions and comments are welcome.
>
>   Thank you,
>
> -- Yoshiki
>
-------------- next part --------------
'From Squeak3.4beta of ''1 December 2002'' [latest update: #5138] on 11 December 2002 at 6:37:26 pm'!
ProgressMorph subclass: #ProgressBarMorph
	instanceVariableNames: 'minVal maxVal workingBlock closingDelay '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Widgets'!

!ProgressMorph methodsFor: 'initialization' stamp: 'PH 12/11/2002 18:36'!
setupMorphs
	|  |
	self initProgressMorph.
	self	
		layoutPolicy: TableLayout new;
		listDirection: #topToBottom;
		cellPositioning: #topCenter;
		listCentering: #center;
		hResizing: #shrinkWrap;
		vResizing: #shrinkWrap;
		color: Color transparent.

	self addMorphBack: self labelMorph.
	self addMorphBack: self subLabelMorph.
	self addMorphBack: self progress.

	self borderWidth: 2.
	self borderColor: Color black.

	self color: Color veryLightGray.
	self align: self fullBounds center with: Display boundingBox center
! !


!ProgressBarMorph methodsFor: 'as yet unclassified' stamp: 'PH 12/3/2002 15:06'!
closingDelay
	closingDelay ifNil: [closingDelay := 100].
	^closingDelay! !

!ProgressBarMorph methodsFor: 'as yet unclassified' stamp: 'PH 12/3/2002 15:06'!
closingDelay: millisecondsDelay
	closingDelay := millisecondsDelay! !

!ProgressBarMorph methodsFor: 'as yet unclassified' stamp: 'PH 12/3/2002 15:22'!
delayedClose
	(Delay forMilliseconds: self closingDelay) wait.
	self delete.
	! !

!ProgressBarMorph methodsFor: 'as yet unclassified' stamp: 'PH 12/3/2002 15:22'!
display: argString at: argPoint from: argMinVal to: argMaxVal during: argWorkBlock
	self label: argString.
	minVal := argMinVal.
	maxVal := argMaxVal.
	workingBlock := argWorkBlock.
	self openInWorld.
	workingBlock 
		value: self 
		ifError: [
			self label: 'Error encountered'.
		].
	self delayedClose.
! !

!ProgressBarMorph methodsFor: 'as yet unclassified' stamp: 'PH 12/3/2002 15:17'!
initialize
	super initialize.
	labelMorph font: (TextStyle default fontAt: 1).
	^self! !

!ProgressBarMorph methodsFor: 'as yet unclassified' stamp: 'PH 12/3/2002 14:58'!
value: currentProgress
	((currentProgress >= minVal) and: [currentProgress <= maxVal])
		ifTrue: [
			self done: ((currentProgress - minVal) / (maxVal - minVal)).
		]! !


!ProgressBarMorph class methodsFor: 'as yet unclassified' stamp: 'PH 12/3/2002 15:11'!
new
	^super new initialize! !


!String methodsFor: 'displaying' stamp: 'PH 12/3/2002 15:10'!
displayProgressAt: aPoint from: minVal to: maxVal during: workBlock 
	"Display this string as a caption over a progress bar while workBlock is evaluated.

EXAMPLE (Select next 6 lines and Do It)
'Now here''s some Real Progress'
	displayProgressAt: Sensor cursorPoint
	from: 0 to: 10
	during: [:bar |
	1 to: 10 do: [:x | bar value: x.
			(Delay forMilliseconds: 500) wait]].

HOW IT WORKS (Try this in any other language :-)
Since your code (the last 2 lines in the above example) is in a block,
this method gets control to display its heading before, and clean up 
the screen after, its execution.
The key, though, is that the block is supplied with an argument,
named 'bar' in the example, which will update the bar image every 
it is sent the message value: x, where x is in the from:to: range.
"
"	^ProgressInitiationException "
	^ProgressBarMorph new
		display: self
		at: aPoint 
		from: minVal 
		to: maxVal 
		during: workBlock! !


!TTCFont methodsFor: 'accessing' stamp: 'yo 12/2/2002 14:09'!
textStyle
	^ Utilities actualTextStyles detect:
		[:aStyle | aStyle fontArray includes: self] ifNone: [nil]! !


!TTCFont class methodsFor: 'other' stamp: 'yo 11/30/2002 22:21'!
pointSizes

	^ #(12 24 36 48 60 72).
! !

-------------- next part --------------
'From Squeak3.4beta of ''1 December 2002'' [latest update: #5138] on 11 December 2002 at 6:44:27 pm'!


!TTCFont class methodsFor: 'as yet unclassified'!
fileReaderServicesForFile: fullName suffix: suffix 
	(suffix = 'ttf')
		ifTrue: [^self services].
	^ OrderedCollection new.!
serviceInstallTrueTypeFontStyle
	"Return a service to install a true type font as a text style"

	^ SimpleServiceEntry
		provider: self
		label: 'install ttf style'
		selector: #newTextStyleFromTTFile: 
		description: 'install a true type font as a text style'
		buttonLabel: 'install ttf'!
services
	"Return a set of services for use in FileList"

	^ Array with: self serviceInstallTrueTypeFontStyle! !




More information about the Squeak-dev mailing list