'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 27 April 2008 at 9:32:36 am'!

!Color class methodsFor: 'other' stamp: 'jmv 4/27/2008 09:19'!
shutDown
	"Color shutDown"

	ColorChart _ nil.		"Palette of colors for the user to pick from"
	CachedColormaps _ nil.	"Maps to translate between color depths"
	MaskingMap _ nil.		"Maps all colors except transparent to black for creating a mask"
	
	"Do not hold too many of these"
	(CachedColormapsForAAText notNil and: [
		CachedColormapsForAAText anySatisfy: [ :dict | dict size > 12 ]]) ifTrue: [
			CachedColormapsForAAText _ nil]! !


!StrikeFont methodsFor: 'accessing' stamp: 'jmv 4/27/2008 09:22'!
baseKern
	"Return the base kern value to be used for all characters."
	self isSynthetic ifFalse: [^0].
	(emphasis noMask: 2) ifTrue: [^ 0].
	^ ((self height-1-self ascent+4)//4 max: 0)  "See makeItalicGlyphs"
		+ (((self ascent-5+4)//4 max: 0))
! !

!StrikeFont methodsFor: 'emphasis' stamp: 'jmv 4/26/2008 14:12'!
isSynthetic
	^type = 3! !

!StrikeFont methodsFor: 'emphasis' stamp: 'jmv 4/26/2008 14:11'!
isSynthetic: aBoolean
	type _ aBoolean ifTrue: [3] ifFalse: [0]! !

!StrikeFont methodsFor: 'emphasis' stamp: 'jmv 4/26/2008 14:12'!
makeBoldGlyphs
	"Make a bold set of glyphs with same widths by ORing 1 bit to the right
		(requires at least 1 pixel of intercharacter space)"
	| g bonkForm |
	g _ glyphs deepCopy.
	bonkForm _ (Form extent: 1@16) fillBlack offset: -1@0.
	self bonk: g with: bonkForm.
	glyphs depth = 1 ifTrue: [
		g copyBits: g boundingBox from: g at: (1@0)
			clippingBox: g boundingBox rule: Form under fillColor: nil]
		ifFalse: [
			0 to: g width - 2 do: [ :x | 0 to: g height-1 do: [ :y |
				(glyphs colorAt:  x@y) = Color white ifFalse: [
					g colorAt: x+1@y put: 
						((glyphs colorAt: x+1@y) = Color white 
							ifTrue: [glyphs colorAt:  x@y]
							ifFalse: [Color black])]]]].
	glyphs _ g.
	self isSynthetic: true! !

!StrikeFont methodsFor: 'emphasis' stamp: 'jmv 4/26/2008 14:12'!
makeCondensedGlyphs
	"Make a condensed set of glyphs with same widths.
	NOTE: this has been superceded by kerning -- should not get called"
	| g newXTable x x1 w |
	g _ glyphs deepCopy.
	newXTable _ Array new: xTable size.
	newXTable at: 1 put: (x _ xTable at: 1).
	1 to: xTable size-1 do:
		[:i | x1 _ xTable at: i.  w _ (xTable at: i+1) - x1.
		w > 1 ifTrue: [w _ w-1].  "Shrink every character wider than 1"
		g copy: (x@0 extent: w@g height) from: x1@0 in: glyphs rule: Form over.
		newXTable at: i+1 put: (x _ x + w)].
	xTable _ newXTable.
	glyphs _ g.
	self isSynthetic: true
"
(TextStyle default fontAt: 1) copy makeCondensedGlyphs
	displayLine: 'The quick brown fox jumps over the lazy dog'
	at: Sensor cursorPoint
"! !

!StrikeFont methodsFor: 'emphasis' stamp: 'jmv 4/26/2008 14:12'!
makeItalicGlyphs
	"Make an italic set of glyphs with same widths by skewing left and right.
	In the process, characters would overlap, so we widen them all first.
	"
	| extraWidth newGlyphs newXTable x newX w extraOnLeft |  
	extraOnLeft _ (self height-1-self ascent+4)//4 max: 0.
	extraWidth _ ((self ascent-5+4)//4 max: 0) + extraOnLeft.
	newGlyphs _ Form extent: (glyphs width + (maxAscii + 1 - minAscii*extraWidth)) @ glyphs height depth: glyphs depth.
	newGlyphs fillWhite.
	newXTable _ xTable copy.

	"Copy glyphs into newGlyphs with room on left and right for overlap."
	minAscii to: maxAscii+1 do:
		[:ascii | x _ xTable at: ascii+1.  w _ (xTable at: ascii+2) - x.
		newX _ newXTable at: ascii+1.
		newGlyphs copy: ((newX + extraOnLeft) @ 0 extent: w @ glyphs height)
			from: x @ 0 in: glyphs rule: Form over.
		newXTable at: ascii+2 put: newX + w + extraWidth].		
	glyphs _ newGlyphs. 
	xTable _ newXTable.
	"Slide the bitmaps left and right for synthetic italic effect."
	4 to: self ascent-1 by: 4 do:
		[:y | 		"Slide ascenders right..."
		glyphs copy: (1@0 extent: glyphs width @ (self ascent - y))
			from: 0@0 in: glyphs rule: Form over].
	self ascent to: self height-1 by: 4 do:
		[:y | 		"Slide descenders left..."
		glyphs copy: (0@y extent: glyphs width @ glyphs height)
			from: 1@y in: glyphs rule: Form over].
	self isSynthetic: true! !

!StrikeFont methodsFor: 'emphasis' stamp: 'jmv 4/26/2008 14:12'!
makeStruckOutGlyphs
	"Make a struck-out set of glyphs with same widths"
	| g |
	g _ glyphs deepCopy.
	g fillBlack: (0 @ (self ascent - (self ascent//3)) extent: g width @ 1).
	glyphs _ g.
	self isSynthetic: true
! !

!StrikeFont methodsFor: 'emphasis' stamp: 'jmv 4/26/2008 14:12'!
makeUnderlinedGlyphs
	"Make an underlined set of glyphs with same widths"
	| g |
	g _ glyphs deepCopy.
	g fillBlack: (0 @ (self ascent+1) extent: g width @ 1).
	glyphs _ g.
	self isSynthetic: true
! !

!StrikeFont methodsFor: 'emphasis' stamp: 'jmv 4/26/2008 14:18'!
reset
	"Reset the cache of derivative emphasized fonts"
	
	derivativeFonts notNil ifTrue: [
		derivativeFonts withIndexDo: [ :f :i |
			(f notNil and: [f isSynthetic]) ifTrue: [derivativeFonts at: i put: nil]]].
	"
	derivativeFonts _ Array new: 32.
	#('B' 'I' 'BI') doWithIndex:
		[:tag :index | 
		(style _ TextStyle named: self familyName) ifNotNil:
			[(font _ style fontArray
				detect: [:each | each name = (self name , tag)]
				ifNone: [nil]) ifNotNil: [derivativeFonts at: index put: font]]]
	"! !

!StrikeFont methodsFor: 'building' stamp: 'jmv 4/27/2008 09:06'!
lineMarkersIn: aForm
"
	StrikeFont new lineMarkersIn: (Form fromFileNamed: 'AAFonts\Vera8.bmp')
"
	| tally glyphsTop glyphsBottom max glyphsBaseline |
	tally _ aForm yTallyPixelValue: 32767 orNot: true.
	glyphsTop _ (1 to: tally size-1) select: [ :y | 
		(tally at: y) = 0 and: [(tally at: y+1) > 0 ]].
	glyphsBottom _ (0 to: tally size-2) select: [ :y | 
		(tally at: y+2) = 0 and: [(tally at: y+1) > 0 ]].
	max _ tally max.
	glyphsBaseline _ (1 to: glyphsBottom size) collect: [ :i |
		((glyphsBottom at: i) to: (glyphsTop at: i) by: -1) detect: [ :y |
			(tally at: y+1) > (max //3) ]].
	ascent _ ((1 to: glyphsBottom size) collect: [ :i | 
		(glyphsBaseline at: i) - (glyphsTop at: i) ]) max+1.
	descent _ ((1 to: glyphsBottom size) collect: [ :i | 
		(glyphsBottom at: i) - (glyphsBaseline at: i) ]) max.
	^Array with: ascent with: descent with: glyphsBaseline! !


!StrikeFont class methodsFor: 'instance creation' stamp: 'jmv 4/27/2008 09:11'!
installAAVera
"
StrikeFont installAAVera
"
	| baseF base boldF italicF bold italic |
	baseF := {'AAFonts\Vera8.bmp'-> 'Vera 8'. 'AAFonts\Vera10.bmp'-> 'Vera 10'. 'AAFonts\Vera12.bmp'-> 'Vera 12'. 'AAFonts\Vera16.bmp'-> 'Vera 16'. 'AAFonts\Vera18.bmp'-> 'Vera 18'}.
	boldF := {'AAFonts\Vera8b.bmp'-> 'Vera 8B'. 'AAFonts\Vera10b.bmp'-> 'Vera 10B'. 'AAFonts\Vera12b.bmp'-> 'Vera 12B'. 'AAFonts\Vera16b.bmp'-> 'Vera 16B'}.
	italicF := {'AAFonts\Vera10i.bmp'-> 'Vera 10I'. 'AAFonts\Vera12i.bmp'-> 'Vera 12I'. 'AAFonts\Vera16i.bmp'-> 'Vera 16I'. 'AAFonts\Vera18i.bmp'-> 'Vera 18I'}.
	base := OrderedCollection new.
	bold := OrderedCollection new.
	italic := OrderedCollection new.
	
			baseF withIndexDo: [:keyValue :index | |form |	
					form _ Form fromFileNamed:keyValue key.
					base add: ((StrikeFont new buildFromForm: form name: keyValue value)
						pointSize: keyValue value substrings last asNumber)].
			boldF withIndexDo: [:keyValue :index | |form |
					form _ Form fromFileNamed:keyValue key.
					bold add: ((StrikeFont new buildFromForm: form name: keyValue value) 
						emphasis: 1;
						pointSize: keyValue value substrings last asNumber)].
			italicF withIndexDo: [:keyValue :index | |form |
					form _ Form fromFileNamed:keyValue key.
					italic add: ((StrikeFont new buildFromForm: form name: keyValue value)
						emphasis:2;
						pointSize: keyValue value substrings last asNumber)].
			
			(base at: 1) derivativeFont: (bold at: 1) at: 1.
			(base at: 2) derivativeFont: (bold at: 2) at: 1.
			(base at: 3) derivativeFont: (bold at: 3) at: 1.
			(base at: 4) derivativeFont: (bold at: 4) at: 1.

			(base at: 2) derivativeFont: (italic at: 1) at: 2.
			(base at: 3) derivativeFont: (italic at: 2) at: 2.
			(base at: 4) derivativeFont: (italic at: 3) at: 2.
			(base at: 5) derivativeFont: (italic at: 4) at: 2.

			TextConstants at: #Vera put: (TextStyle fontArray: base).
"
			Preferences setDefaultFonts: #(
				(setSystemFontTo: 'Vera' 10)
				(setListFontTo: 'Vera' 10)
				(setMenuFontTo: 'Vera' 12)
				(setWindowTitleFontTo: 'Vera Bold' 12)
				(setBalloonHelpFontTo: 'Vera' 10)
				(setCodeFontTo: 'Vera' 12)
				(setButtonFontTo: 'Vera' 10))
"! !

