"Chris Uppal" <
[hidden email]> wrote in message
news:3fb4ec3c$0$107$
[hidden email]...
> I've suddenly started to hit problems caused by the implementation of
> Canvas>>font: -- I don't know why it's started suddenly (not caused by
> installing the patches), and I don't know whether it's my understanding
that's
> wrong or a bug in #font:.
>
Hmmm, I think the bug is that Canvas>>font: should not really return nil.
The simplest patch for this is to replace the direct access to the 'font'
instance variable with an invocation of the #font accessor method.
> Anyway, I have code that could be paraphrased like:
>
> paintWithFontOn: aCanvas
> | newFont oldFont |
> newFont := ... create a font ...
> oldFont := aCanvas font: newFont.
> [self doSomeMorePaintingOn: aCanvas]
> ensure: [aCanvas font: oldFont. newFont free].
The workaround would be to write it like this:
paintWithFontOn: aCanvas
| newFont oldFont |
newFont := ... create a font ...
oldFont := aCanvas font.
aCanvas font: newFont.
[self doSomeMorePaintingOn: aCanvas]
ensure: [aCanvas font: oldFont. newFont free].
Or you can apply the hotfix below.
Thanks for the report.
Blair
------------------
"#1390"
!Canvas methodsFor!
font: aFont
"Select aFont into this canvas. Ensure that the font is realized for the
receiver's
resolution. Answer the previously selected font."
| oldFont |
oldFont := self font.
font := aFont.
font resolution: self resolution.
self selectObject: aFont.
^oldFont! !
!Canvas categoriesFor: #font:!public!tools! !