'From etoys3.0 of 24 February 2008 [latest update: #2113] on 28 August 2008 at 8:38:58 pm'! "Change Set: pangoWidth2-yo Date: 28 August 2008 Author: Yoshiki Ohshima Fix the width of menu. Also some refactoring of code."! !AbstractFont methodsFor: 'measuring' stamp: 'yo 8/28/2008 18:48'! widthOfStringWithPango: aString | r utf8ContentsSize attrs myLines tl f | aString ifNil:[^0]. r := RomePluginCanvas composingCanvas. utf8ContentsSize := (aString ifNotNil: [(r primUtf8StringFor: aString andIndexFor: -1 into: (Array new: 2) nullFlag: false) first size] ifNil: [0]). f := RomePangoFont familyName: (RomePangoFont familyNameFrom: self) size: self pointSize. attrs := Array with: (Array with: #F with: 0 with: utf8ContentsSize with: f descriptionIndex with: f). myLines := r pangoComposeString: aString attributeArray: attrs at: 0@0 width: SmallInteger maxVal height: SmallInteger maxVal withWrap: false. myLines ifNotNil: [ myLines second size > 0 ifFalse: [^ 0]. tl := myLines second first. ^ tl bottomRight x - tl topLeft x. ]. ^ 0! ! !RomePangoFont class methodsFor: 'as yet unclassified' stamp: 'yo 8/28/2008 18:38'! familyNameFrom: aFont | fontName | fontName := aFont familyName. (fontName beginsWith: 'Accuny') ifTrue: [ ^ 'Times New Roman'. ]. (fontName beginsWith: 'Accujen') ifTrue: [ ^ 'Arial'. ]. ^ fontName. ! ! !RomePangoFont class methodsFor: 'as yet unclassified' stamp: 'yo 8/28/2008 18:45'! familyName: familyName size: size ^ self new familyName: familyName size: (size * 0.8) asInteger. ! ! !RunArray methodsFor: '*pango' stamp: 'yo 8/28/2008 18:47'! pangoFontAttributeFromArray: a from: start to: end | font fontSize fontRef fontChange r | fontRef := a detect: [:e | e isMemberOf: TextFontReference] ifNone: [nil]. font := fontRef ifNil: [TextStyle defaultFont] ifNotNil: [fontRef font]. fontChange := a detect: [:e | e isMemberOf: TextFontChange] ifNone: [nil]. fontSize := fontChange ifNil: [font pointSize] ifNotNil: [ (font textStyle fontArray at: fontChange fontNumber) pointSize]. r := RomePangoFont familyName: (RomePangoFont familyNameFrom: font) size: fontSize. ^ Array with: #F with: start with: end with: r descriptionIndex with: r. ! ! !StringMorph methodsFor: '*pango' stamp: 'yo 8/28/2008 18:48'! asPangoAttributes | usedFont colorArray emphasisArray r utf8ContentsSize | usedFont := font ifNil: [TextStyle defaultFont] ifNotNil: [font]. utf8ContentsSize := (contents ifNotNil: [(RomePluginCanvas composingCanvas primUtf8StringFor: contents andIndexFor: -1 into: (Array new: 2) nullFlag: false) first size] ifNil: [0]). colorArray := Array with: #C with: 0 with: utf8ContentsSize with: color pixelValue32. emphasisArray := Array with: #E with: 0 with: utf8ContentsSize with: emphasis. r := RomePangoFont familyName: (RomePangoFont familyNameFrom: usedFont) size: usedFont pointSize. ^ Array with: (Array with: #F with: 0 with: utf8ContentsSize with: r descriptionIndex with: r) with: colorArray with: emphasisArray. ! ! !MenuItemMorph methodsFor: 'drawing' stamp: 'yo 8/28/2008 20:36'! drawOn: aCanvas "Draw the menu item, including icons, markers; apply appropriate color and centering." | stringColor stringBounds leftEdge outerBounds stringWidth oldColor | isSelected & isEnabled ifTrue: [ aCanvas fillRectangle: self bounds fillStyle: self selectionFillStyle. stringColor := color negated] ifFalse: [stringColor := color]. leftEdge := 0. self hasIcon ifTrue: [| iconForm | iconForm := isEnabled ifTrue:[self icon] ifFalse:[self icon asGrayScale]. aCanvas paintImage: iconForm at: self left @ (self top + (self height - iconForm height // 2)). leftEdge := iconForm width + 2]. self hasMarker ifTrue: [ leftEdge := leftEdge + self submorphBounds width + 8 ]. outerBounds := bounds left: bounds left + leftEdge. stringWidth := Preferences standardMenuFont perform: ((RomePluginCanvas pangoIsAvailable and: [self usePango]) ifTrue: [#widthOfStringWithPango:] ifFalse: [#widthOfString:]) with: contents. stringBounds := (self hasProperty: #centered) ifFalse: [outerBounds] ifTrue: [outerBounds insetBy: (((outerBounds width - stringWidth) max: 0) // 2) @ 0]. self usePango ifTrue: [ oldColor := color. color _ stringColor. aCanvas translateBy: (leftEdge@0) during: [:cc | super drawOn: cc]. color _ oldColor. ] ifFalse: [ aCanvas drawString: contents in: stringBounds font: self fontToUse color: stringColor. ]. stringBounds := stringBounds origin extent: (stringWidth+ 3) @ stringBounds height. self drawExtraIconOn: aCanvas forStringBounds: stringBounds. subMenu ifNotNil: [aCanvas paintImage: SubMenuMarker at: self right - 8 @ (self top + self bottom - SubMenuMarker height // 2)]! ! !MenuItemMorph methodsFor: 'layout' stamp: 'yo 8/28/2008 16:32'! minWidth | fontToUse iconWidth subMenuWidth markerWidth | fontToUse := self fontToUse. subMenuWidth := self hasSubMenu ifFalse: [0] ifTrue: [10]. iconWidth := self hasIcon ifTrue: [self icon width + 2] ifFalse: [0]. markerWidth := self hasMarker ifTrue: [ self submorphBounds width + 8 ] ifFalse: [ 0 ]. ^ (self measureContents x) + subMenuWidth + iconWidth + markerWidth.! !