Squeak
  QotD    "To be or not to be" – Shakespeare
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Rendering a TTGlyph
Last updated at 9:38 am UTC on 7 August 2017
The method

 asFormWithScale:ascender:descender:fgColor:bgColor:depth:replaceColor:lineGlyph:lingGlyphWidth:emphasis:

of TTGlyph gives back the glyph rendered as an instance of the class Form.

TTFontDescription instances hold TTGlyph instances.


Method code adapted to be run as an example from a workspace


The example needs this TrueType font.

	| glyph form canvas code depth scale  font |
	font := (TextConstants at: #LiberationSans) fontArray at: 3.
	glyph := font ttcDescription at: 732.
	glyph inspect.
	scale := scale := font ttcDescription fontHeight asFloat / (font ttcDescription ascender - font ttcDescription descender).
	depth := 8.
	code := 0. "is for emphasis"
	form := Form extent: (glyph advanceWidth @ (font ttcDescription ascender - font ttcDescription descender) * scale) rounded depth: depth.
	form fillColor: Color transparent.
	canvas := form getCanvas asBalloonCanvas.
	canvas aaLevel: 4.
	canvas
		transformBy: (MatrixTransform2x3 withScale: scale asPoint * (1 @ -1)).
	canvas
		transformBy: (MatrixTransform2x3 withOffset: 0 @ font ttcDescription ascender negated).
	canvas
		drawGeneralBezierShape: glyph contours
		color: Color black
		borderWidth: 0
		borderColor: Color black.
	form asMorph openInHand