'From etoys2.3 of 28 November 2007 [latest update: #1829] on 11 December 2007 at 11:12:52 pm'! "Change Set: TTCFontSetFix-yo Date: 11 December 2007 Author: Yoshiki Ohshima Fix more problems with TTCFontSet."! !TTCFont class methodsFor: 'instance creation' stamp: 'yo 12/11/2007 23:11'! reorganizeForNewFontArray: array name: styleName | style existings regular altName | (TextConstants includesKey: styleName) ifFalse: [ TextConstants at: styleName put: (TextStyle fontArray: array). ^ TextConstants at: styleName. ]. "There is a text style with the name I want to use. See if it is a TTC font..." style _ TextConstants at: styleName. style isTTCStyle ifFalse: [ altName _ ((array at: 1) name, 'TT') asSymbol. ^ self reorganizeForNewFontArray: array name: altName. ]. existings _ (self getExistings: style fontArray) copyWith: array. regular _ existings reversed detect: [:e | (e at: 1) isRegular] ifNone: [existings at: 1]. regular do: [:r | r addLined: r. ]. "The existing array may be different in size than the new one." existings do: [:e | (e at: 1) isRegular ifFalse: [ regular do: [ :r | | f | f _ e detect: [ :ea | ea pointSize = r pointSize ] ifNone: [ ]. f ifNotNil: [ r derivativeFont: f ]. ]. ]. ]. style newFontArray: regular. self register: regular at: styleName. self recreateCache. ^ style. ! ! !TTCFontSet methodsFor: 'accessing' stamp: 'yo 12/11/2007 17:00'! widthOf: aCharacter | encoding font | encoding _ aCharacter leadingChar. encoding >= fontArray size ifFalse: [ font _ (fontArray at: encoding + 1). font ifNotNil: [^ font widthOf: aCharacter]. ]. fallbackFont ifNotNil: [^ fallbackFont widthOf: aCharacter]. ^ (fontArray at: 1) widthOf: aCharacter. ! ! !TTCFontSet class methodsFor: 'file out/in' stamp: 'yo 12/11/2007 14:19'! installExternalFontFileName: aFileName " TTCFontSet installExternalFontFileName: 'GreekTT.out'. TTCFontSet installExternalFontFileName: 'RussianTT.out'. TTCFontSet installExternalFontFileName: 'JapaneseTT.out'. " | f | f _ FileStream readOnlyFileNamed: aFileName. TTCFontSet newTextStyleFromSmartRefStream: (SmartRefStream on: f).. f close. ! ! !TTCFontSet class methodsFor: 'file out/in' stamp: 'yo 12/11/2007 13:28'! newTextStyleFromSmartRefStream: ref | descriptions | descriptions _ TTFontDescription addFromSmartRefStream: ref. descriptions do: [:desc | self newTextStyleFromTT: desc].! ! !TTFontDescription class methodsFor: 'instance creations' stamp: 'yo 12/11/2007 22:41'! addFromSmartRefStream: ref | tts | tts := ref nextAndClose. ^ tts collect: [:tt | self addToDescription: tt. ]. ! ! !TTFontDescription class methodsFor: 'instance creations' stamp: 'yo 12/11/2007 22:40'! addFromTTStream: readStream " self addFromTTFile: 'C:\WINDOWS\Fonts\ARIALN.TTF' " | tt | tt _ TTFontReader readFrom: readStream. tt _ self addToDescription: tt. tt blankGlyphForSeparators. ^ tt. ! ! !TTFontDescription class methodsFor: 'instance creations' stamp: 'yo 12/11/2007 22:41'! addSetFromTTFile: fileName " Execute the following only if you know what you are doing. self addFromTTFile: 'C:\WINDOWS\Fonts\msgothic.TTC' " | tt | (fileName asLowercase endsWith: 'ttf') ifTrue: [ tt _ TTCFontReader readTTFFrom: (FileStream readOnlyFileNamed: fileName). ] ifFalse: [ tt _ TTCFontReader readFrom: (FileStream readOnlyFileNamed: fileName). ]. ^ self addToDescription: tt. ! ! !TTFontDescription class methodsFor: 'instance creations' stamp: 'yo 12/11/2007 22:41'! addSetFromTTFile: fileName encodingTag: encodingTag ranges: ranges | tt | (fileName asLowercase endsWith: 'ttf') ifTrue: [ tt _ TTCFontReader readTTFFrom: (FileStream readOnlyFileNamed: fileName). ] ifFalse: [ tt _ TTCFontReader readFrom: (FileStream readOnlyFileNamed: fileName). ]. (tt at: encodingTag + 1) compactForRanges: ranges. ^ self addToDescription: tt. ! ! !TTFontDescription class methodsFor: 'instance creations' stamp: 'yo 12/11/2007 22:40'! addToDescription: tt | old new | old _ Descriptions detect: [:f | f first fullName = tt first fullName] ifNone: [nil]. ^ old ifNotNil: [ new _ old, (Array new: ((tt size - old size) max: 0)). 1 to: tt size do: [:ind | (tt at: ind) ifNotNil: [ new at: ind put: (tt at: ind) ]. ]. Descriptions remove: old. Descriptions add: new. new. ] ifNil: [ Descriptions add: tt. tt. ] ! !