'From etoys3.0 of 24 February 2008 [latest update: #1931] on 24 March 2008 at 6:27:39 pm'! "Change Set: romepango2-yo Date: 24 March 2008 Author: Yoshiki Ohshima The image-side Pango support rev. 2."! AbstractFont subclass: #StandInFont instanceVariableNames: 'familyName pointSize emphasis' classVariableNames: '' poolDictionaries: '' category: 'Graphics-Text'! RectangleMorph subclass: #TextMorph instanceVariableNames: 'textStyle text wrapFlag paragraph editor container predecessor successor backgroundColor margins editHistory fillStyle usePango ' classVariableNames: 'CaretForm ' poolDictionaries: '' category: 'Morphic-Basic'! !CharacterScanner methodsFor: 'private' stamp: 'yo 3/24/2008 15:18'! setFont | priorFont | "Set the font and other emphasis." (font isMemberOf: StandInFont) ifTrue: [ font _ TextStyle defaultFont ]. priorFont _ font. text == nil ifFalse:[ emphasisCode _ 0. kern _ 0. indentationLevel _ 0. alignment _ textStyle alignment. font _ nil. (text attributesAt: lastIndex forStyle: textStyle) do: [:att | att emphasizeScanner: self]]. font == nil ifTrue: [self setFont: textStyle defaultFontIndex]. font _ font emphasized: emphasisCode. priorFont ifNotNil: [destX _ destX + priorFont descentKern]. destX _ destX - font descentKern. "NOTE: next statement should be removed when clipping works" leftMargin ifNotNil: [destX _ destX max: leftMargin]. kern _ kern - font baseKern. "Install various parameters from the font." spaceWidth _ font widthOf: Space. xTable _ font xTable. stopConditions _ DefaultStopConditions.! ! !StandInFont methodsFor: 'as yet unclassified' stamp: 'yo 3/24/2008 15:08'! ascent | threeQ | threeQ := pointSize * 3 // 4. ^ threeQ. ! ! !StandInFont methodsFor: 'as yet unclassified' stamp: 'yo 3/24/2008 15:08'! descent | threeQ | threeQ := pointSize * 3 // 4. ^ pointSize - threeQ. ! ! !StandInFont methodsFor: 'as yet unclassified' stamp: 'yo 3/24/2008 14:56'! emphasis ^ emphasis! ! !StandInFont methodsFor: 'as yet unclassified' stamp: 'yo 3/24/2008 15:13'! emphasized: code ^ TextStyle defaultFont emphasized: code. ! ! !StandInFont methodsFor: 'as yet unclassified' stamp: 'yo 3/24/2008 14:56'! familyName ^ familyName! ! !StandInFont methodsFor: 'as yet unclassified' stamp: 'yo 3/24/2008 14:56'! familyName: aString pointSize: aNumber emphasized: emph familyName := aString. pointSize := aNumber. emphasis := emph. ! ! !StandInFont methodsFor: 'as yet unclassified' stamp: 'yo 3/24/2008 15:07'! height ^ pointSize. ! ! !StandInFont methodsFor: 'as yet unclassified' stamp: 'yo 3/24/2008 14:57'! pointSize ^ pointSize! ! !StrikeFont class methodsFor: 'instance creation' stamp: 'yo 3/24/2008 18:08'! fromUser: priorFont allowKeyboard: aBoolean "rr 3/23/2004 10:02 : made the menu invoked modally, thus allowing keyboard control" "StrikeFont fromUser" "Present a menu of available fonts, and if one is chosen, return it. Otherwise return nil." | fontList fontMenu style active ptMenu label spec font | fontList _ StrikeFont actualFamilyNames. fontMenu _ MenuMorph new defaultTarget: self. fontList do: [:fontName | style _ TextStyle named: fontName. active _ priorFont familyName sameAs: fontName. ptMenu _ MenuMorph new defaultTarget: self. style pointSizes do: [:pt | (active and:[pt = priorFont pointSize]) ifTrue:[label _ ''] ifFalse:[label _ '']. label _ label, pt printString, ' pt'. ptMenu add: label target: fontMenu selector: #modalSelection: argument: {fontName. pt}]. style isTTCStyle ifTrue: [ ptMenu add: 'new size' translated target: style selector: #addNewFontSizeDialog: argument: {fontName. fontMenu}. ]. active ifTrue:[label _ ''] ifFalse:[label _ '']. label _ label, fontName. fontMenu add: label subMenu: ptMenu]. true "Preferences usePangoRenderer" ifTrue: [ font := fontMenu add: 'external font' translated target: TextStyle selector: #addNewStyle: argument: {nil. fontMenu}. ]. spec _ fontMenu invokeModalAt: ActiveHand position in: ActiveWorld allowKeyboard: aBoolean. spec ifNil: [^ nil]. style _ TextStyle named: spec first. style ifNil: [^ self]. font _ style fonts detect: [:any | any pointSize = spec last] ifNone: [nil]. ^ font! ! !StringMorph methodsFor: 'menu' stamp: 'yo 3/24/2008 18:22'! addCustomMenuItems: aCustomMenu hand: aHandMorph super addCustomMenuItems: aCustomMenu hand: aHandMorph. aCustomMenu add: 'change font' translated action: #changeFont. aCustomMenu add: 'change emphasis' translated action: #changeEmphasis. aCustomMenu addUpdating: #usePangoString target: self action: #toggleUsePango. ! ! !StringMorph methodsFor: '*pango' stamp: 'yo 3/24/2008 18:22'! toggleUsePango RomePluginCanvas pangoIsAvailable ifFalse: [^ self]. self usePango: self usePango not. ! ! !StringMorph methodsFor: '*pango' stamp: 'yo 3/24/2008 18:20'! usePangoString ^ (self usePango ifTrue: [''] ifFalse: ['']), ('use pango' translated)! ! !TextMorph methodsFor: 'copying' stamp: 'yo 3/24/2008 14:14'! veryDeepInner: deepCopier "Copy all of my instance variables. Some need to be not copied at all, but shared. Warning!!!! Every instance variable defined in this class must be handled. We must also implement veryDeepFixupWith:. See DeepCopier class comment." super veryDeepInner: deepCopier. textStyle _ textStyle veryDeepCopyWith: deepCopier. text _ text veryDeepCopyWith: deepCopier. wrapFlag _ wrapFlag veryDeepCopyWith: deepCopier. paragraph _ paragraph veryDeepCopyWith: deepCopier. editor _ editor veryDeepCopyWith: deepCopier. container _ container veryDeepCopyWith: deepCopier. predecessor _ predecessor. successor _ successor. backgroundColor _ backgroundColor veryDeepCopyWith: deepCopier. margins _ margins veryDeepCopyWith: deepCopier. usePango _ usePango.! ! !TextMorph methodsFor: '*pango' stamp: 'yo 3/24/2008 18:24'! toggleUsePango RomePluginCanvas pangoIsAvailable ifFalse: [^ self]. self usePango: self usePango not. ! ! !TextMorph methodsFor: '*pango' stamp: 'yo 3/24/2008 18:23'! usePangoString ^ (self usePango ifTrue: [''] ifFalse: ['']), ('use pango' translated)! ! !TextMorph methodsFor: 'menus' stamp: 'yo 3/24/2008 18:26'! addFitAndWrapItemsTo: aMenu "Add items relating to fitting and wrapping to the menu provided, providing menu-lines before and after the group added." aMenu addLine. aMenu addUpdating: #autoFitString target: self action: #autoFitOnOff. aMenu balloonTextForLastItem: 'When checked, bounds are automatically adjusted to fit the contents.' translated. aMenu addUpdating: #wrapString target: self action: #wrapOnOff. aMenu balloonTextForLastItem: 'When checked, text is automatically wrapped to fit horizontally within the boundaries specifed.' translated. aMenu addUpdating: #translatableString target: self action: #toggleTranslatable. aMenu balloonTextForLastItem: 'When checked, contents will automatically be translated upon a locale change' translated. aMenu addUpdating: #usePangoString target: self action: #toggleUsePango. aMenu addLine.! ! !TextStyle class methodsFor: 'instance creation' stamp: 'yo 3/24/2008 15:42'! addNewStyle: args | newName f newStyle newSize | newName := FillInTheBlank request: 'new font name' translated initialAnswer: 'Times New Roman'. newName ifEmpty: [^ nil]. (TextStyle actualTextStyles keys includes: newName asSymbol) ifTrue: [ ^ nil ]. newSize := FillInTheBlank request: 'new size' translated initialAnswer: '18'. newSize := newSize asNumber. newSize < 1 ifTrue: [^ nil]. f := StandInFont new familyName: newName pointSize: newSize emphasized: 0. newStyle := self fontArray: (Array with: f). TextConstants at: newName put: newStyle. args second modalSelection: {newName. newSize}. ! ! TextStyle class removeSelector: #addNewStyle! RectangleMorph subclass: #TextMorph instanceVariableNames: 'textStyle text wrapFlag paragraph editor container predecessor successor backgroundColor margins fillStyle usePango' classVariableNames: 'CaretForm' poolDictionaries: '' category: 'Morphic-Basic'! !StringMorph reorganize! ('accessing' contents contentsClipped: contents: fitContents font fontName:size: fontToUse font:emphasis: interimContents: label:font: measureContents minimumWidth setWidth: userString valueFromContents) ('connectors-layout' minHeight) ('drawing' drawOn: lookTranslucent) ('editing' acceptContents acceptValue: cancelEdits doneWithEdits launchMiniEditor: lostFocusWithoutAccepting wantsKeyboardFocusOnShiftClick) ('event handling' handlesMouseDown: hasFocus mouseDown: wouldAcceptKeyboardFocus) ('font' emphasis:) ('halos and balloon help' addOptionalHandlesTo:box: boundsForBalloon) ('initialization' defaultColor initialize initWithContents:font:emphasis:) ('layout' fullBounds) ('menu' addCustomMenuItems:hand: changeEmphasis changeFont) ('objects from disk' fixUponLoad:seg:) ('parts bin' initializeToStandAlone) ('printing' font: printOn:) ('*MorphicExtras-accessing' getCharacters handsWithMeForKeyboardFocus) ('*MorphicExtras-printing' fullPrintOn:) ('*Tools' balloonTextForClassAndMethodString balloonTextForLexiconString balloonTextForMethodString) ('*pango' asPangoAttributes pangoDrawOn:in:color: pangoMeasureContents toggleUsePango usePango usePangoString usePango:) ('drop outside' mimeTypes) ('*connectors-testing' isStringMorph) ! StandInFont removeSelector: #familyName:pointSize:!