'From etoys4.0 of 9 October 2008 [latest update: #2275] on 8 September 2009 at 3:47:29 pm'! "Change Set: FontAvailCheck-yo Date: 31 August 2009 Author: Yoshiki Ohshima Mitigate the font not available problem."! !LanguageEnvironment methodsFor: 'fonts support' stamp: 'yo 9/7/2009 21:26'! fontDownload "(Locale isoLanguage: 'ja') languageEnvironment fontDownload" | contents f | (FileDirectory default fileExists: self fontFullName) ifTrue: [^ true]. " Cursor read showWhile: [self fontDownloadUrls do: [:each | [contents := (each , '/' , self fontFileName) asUrl retrieveContents contents. (contents first: 2) = 'PK' ifTrue: [f := FileStream newFileNamed: self fontFullName. f binary. [f nextPutAll: contents] ensure: [f close]. ^ true]] on: NameLookupFailure do: [:e | e]]]. self inform: 'Fonts does not found (' , self fontFullName , ')'. " ^ false. ! ! !LanguageEnvironment methodsFor: 'fonts support' stamp: 'yo 8/31/2009 16:23'! fontFullName "(Locale isoLanguage: 'ja') languageEnvironment fontFullName" | dir | dir := FileDirectory on: (Smalltalk imagePath, FileDirectory slash, 'fonts'). "dir exists is needed if it is in restricted mode" dir exists ifFalse: [dir assureExistence]. ^ dir fullNameFor: self fontFileName! ! !LanguageEnvironment methodsFor: 'fonts support' stamp: 'yo 8/31/2009 16:40'! installFont "(Locale isoLanguage: 'ja') languageEnvironment installFont" | result | result := self fontDownload. result ifTrue: [SARInstaller installSAR: self fontFullName]. ^ result. ! ! !LanguageEnvironment methodsFor: 'fonts support' stamp: 'yo 2/12/2007 21:40'! isFontAvailable | encoding f | encoding := self leadingChar + 1. f _ TextStyle defaultFont. f isFontSet ifTrue: [ f fontArray at: encoding ifAbsent: [^ false]. ^ true ]. encoding = 1 ifTrue: [^ true]. f fallbackFont fontArray at: encoding ifAbsent: [^ false]. ^ true ! ! !Locale class methodsFor: 'accessing' stamp: 'yo 9/8/2009 15:47'! switchAndInstallFontToID: localeID gently: gentlyFlag | locale result env envFound ret fontInImage menu | "Assumption: Rainbow => can try Pango" "Logic: - in Sugar, we don't bother asking any questions, and we don't bother automatically loading fonts. in Sugar, and if the font is available, use the font. in Sugar, and if the font is not in the image, try to enable Pango. - if the previous step fails, notify the user that you cannot switch to the language. - not in Rainbow, - if the font is in the image, use the font. - if the font is not in the image, - ask to choose: - load font - try to enable pango, if pango is available - or cancel. - if the previous step fails, notify the user that you cannot switch to the language. Details: - how to check non-pango font is available: - if the language environment for the locale doesn't exist, the font is not available. - if font loading fails, it is not available. - how to check if the language environment doesn't exist: - if the locales languageEnvironment is Latin1 but the locale isn't it is not available. " locale := Locale localeID: localeID. env := locale languageEnvironment. result := true. envFound := (Latin1Environment supportedLanguages includes: locale isoLanguage) or: [(env isMemberOf: Latin1Environment) not]. fontInImage := envFound and: [env isFontAvailable]. SugarLauncher isRunningInSugar ifTrue: [ fontInImage ifFalse: [ "font is not available in the image. Even don't ask for font installation." Cursor wait showWhile: [ Preferences setPreference: #usePangoRenderer toValue: true. TextMorph usePango: true]]. ] ifFalse: [ fontInImage ifFalse: [ menu := MenuMorph new. menu defaultTarget: menu. envFound ifTrue: [menu add: 'load font' translated selector: #modalSelection: argument: #loadFont]. RomePluginCanvas pangoIsAvailable ifTrue: [menu add: 'enable Pango' translated selector: #modalSelection: argument: #enablePango]. menu add: 'cancel' translated selector: #modalSelection: argument: #cancel. menu addTitle: 'This language needs additional fonts. Do you want to install the fonts?' translated. ret := menu invokeModal. ret = #loadFont ifTrue: [result := env installFont. result ifTrue: [StrikeFont setupDefaultFallbackTextStyle]]. ret = #enablePango ifTrue: [ (result := RomePluginCanvas pangoIsAvailable) ifTrue: [ Cursor wait showWhile: [ Preferences setPreference: #usePangoRenderer toValue: true. TextMorph usePango: true]]]. (ret ~~ #loadFont and: [ret ~~ #enablePango]) ifTrue: [result := false]]]. result ifFalse: [self inform: 'Cannot load additional fonts' translated] ifTrue: [self switchTo: locale gently: gentlyFlag]. ! ! NepaleseEnvironment removeSelector: #isFontAvailable! LanguageEnvironment removeSelector: #isFontAvailableFor:!