FontPanel.st
changeset 6151 16206c642558
parent 6149 b3f27b4b16b0
child 6246 16356c6f37c0
equal deleted inserted replaced
6150:fd1642c99acb 6151:16206c642558
   802 
   802 
   803     fontBrowserView := View in:previewAndFontSelectionPanel.
   803     fontBrowserView := View in:previewAndFontSelectionPanel.
   804     self createFontSelectionBrowserIn:fontBrowserView.
   804     self createFontSelectionBrowserIn:fontBrowserView.
   805 
   805 
   806     encodingAndXFTOnlyBox := HorizontalPanelView in:filterBox.
   806     encodingAndXFTOnlyBox := HorizontalPanelView in:filterBox.
   807     encodingAndXFTOnlyBox height:32.
   807     encodingAndXFTOnlyBox height:36.
   808     encodingAndXFTOnlyBox horizontalLayout:#leftSpace.
   808     encodingAndXFTOnlyBox horizontalLayout:#leftSpace.
   809 
   809 
   810     l := Label label:(resources string:'Encoding:') in:encodingAndXFTOnlyBox.
   810     l := Label label:(resources string:'Encoding:') in:encodingAndXFTOnlyBox.
   811     l borderWidth:0.
   811     l borderWidth:0.
   812     l adjust:#left.
   812     l adjust:#left.
   842         xftCheckBox := CheckBox label:(resources string:'XFT Fonts Only') in:encodingAndXFTOnlyBox.
   842         xftCheckBox := CheckBox label:(resources string:'XFT Fonts Only') in:encodingAndXFTOnlyBox.
   843         xftCheckBox model:xftFontsOnlyHolder.
   843         xftCheckBox model:xftFontsOnlyHolder.
   844         xftCheckBox helpKey:#xftFontsOnlyHolder.
   844         xftCheckBox helpKey:#xftFontsOnlyHolder.
   845         xftFontsOnlyHolder onChangeEvaluate:[ self xftFontsOnlyChanged ].
   845         xftFontsOnlyHolder onChangeEvaluate:[ self xftFontsOnlyChanged ].
   846 
   846 
   847         xftFlushFontList := Button label:(resources string:'Flush Cached List of Fonts') in:encodingAndXFTOnlyBox.
   847         xftFlushFontList := Button label:(resources string:'Flush Cached Fontlist') in:encodingAndXFTOnlyBox.
   848         xftFlushFontList action:[ self flushListOfAvailableFonts].
   848         xftFlushFontList action:[ self flushListOfAvailableFonts].
   849         xftFlushFontList helpKey:#flushCachedListOfFonts.
   849         xftFlushFontList helpKey:#flushCachedListOfFonts.
   850 
   850 
   851     ].
   851     ].
   852 
   852 
  1044         familyFonts := fontsPerFamily at:currentFamily asUppercaseFirst ifAbsent:nil.
  1044         familyFonts := fontsPerFamily at:currentFamily asUppercaseFirst ifAbsent:nil.
  1045         familyFonts isNil ifTrue:[
  1045         familyFonts isNil ifTrue:[
  1046             ^ nil
  1046             ^ nil
  1047         ].
  1047         ].
  1048     ].
  1048     ].
       
  1049 
       
  1050     false "(familyFonts contains:#isXftFont)" ifTrue:[
       
  1051         "/ anything goes...
       
  1052         szUnitUsed == #px ifTrue:[
       
  1053             fontShown := Font family:currentFamily face:currentFace style:currentStyle size:sz sizeUnit:#px encoding:nil.
       
  1054         ] ifFalse:[
       
  1055             fontShown := Font family:currentFamily face:currentFace style:currentStyle size:sz.
       
  1056         ].
       
  1057         ^ fontShown
       
  1058     ].
       
  1059 
  1049     fonts := familyFonts
  1060     fonts := familyFonts
  1050                 select:[:fntDescr |
  1061                 select:[:fntDescr |
  1051                     fntDescr face = currentFace
  1062                     fntDescr face = currentFace
  1052                     and:[fntDescr style = currentStyle
  1063                     and:[fntDescr style = currentStyle
  1053                     and:[fntDescr isScaledFont
  1064                     and:[fntDescr isScaledFont
  1118 !
  1129 !
  1119 
  1130 
  1120 getFacesForFamily:aFamilyName filtering:filter
  1131 getFacesForFamily:aFamilyName filtering:filter
  1121     "the list of font faces for a given family"
  1132     "the list of font faces for a given family"
  1122 
  1133 
  1123     |familyFonts|
  1134     |familyFonts filteredFonts faces|
  1124 
  1135 
  1125     familyFonts := fontsPerFamily at:aFamilyName ifAbsent:nil.
  1136     familyFonts := fontsPerFamily at:aFamilyName ifAbsent:nil.
  1126     familyFonts isEmptyOrNil ifTrue:[^ nil].
  1137     familyFonts isEmptyOrNil ifTrue:[^ nil].
  1127 
  1138 
  1128     ^ familyFonts 
  1139     filteredFonts := familyFonts 
  1129         select:[:fntDescr |
  1140         select:[:fntDescr |
  1130             (filter isNil or:[filter value:fntDescr])
  1141             (filter isNil or:[filter value:fntDescr])
  1131         ]
  1142         ].
  1132         thenCollect:[:fntDescr |
  1143 
  1133             fntDescr face.
  1144     false "(filteredFonts contains:[:fntDescr | fntDescr isXftFont])" ifTrue:[
  1134         ]
  1145         ^ #(#'regular' #'medium' #'bold' #'demibold'
  1135 
  1146             #'light' #'demilight' #'extralight').  
  1136 "/    ^ self graphicsDevice facesInFamily:aFamilyName filtering:filter.
  1147     ].
       
  1148 
       
  1149     faces := filteredFonts
       
  1150         collect:[:fntDescr |
       
  1151             (fntDescr face) ? 'normal'.
       
  1152         ].
       
  1153     ^ faces
  1137 !
  1154 !
  1138 
  1155 
  1139 getFamilyList 
  1156 getFamilyList 
  1140     "the list of font families"
  1157     "the list of font families"
  1141 
  1158 
  1170 "/
  1187 "/
  1171 "/    ^ self graphicsDevice fontFamiliesFiltering:combinedFilter.
  1188 "/    ^ self graphicsDevice fontFamiliesFiltering:combinedFilter.
  1172 !
  1189 !
  1173 
  1190 
  1174 getSizesInFamily:aFamilyName face:face style:style filtering:filter
  1191 getSizesInFamily:aFamilyName face:face style:style filtering:filter
  1175     |familyFonts faceAndStyleFonts sizes hasScalableFont|
  1192     |familyFonts filteredFonts faceAndStyleFonts sizes hasScalableFont|
  1176 
  1193 
  1177     familyFonts := fontsPerFamily at:aFamilyName ifAbsent:nil.
  1194     familyFonts := fontsPerFamily at:aFamilyName ifAbsent:nil.
  1178     familyFonts isEmptyOrNil ifTrue:[^ nil].
  1195     familyFonts isEmptyOrNil ifTrue:[^ nil].
  1179 
  1196 
  1180     hasScalableFont := false.
  1197     hasScalableFont := false.
  1181 
  1198 
  1182     faceAndStyleFonts := 
  1199     filteredFonts := 
  1183         familyFonts 
  1200         familyFonts 
  1184             select:[:fntDescr |
  1201             select:[:fntDescr |
  1185                 (filter isNil or:[filter value:fntDescr])
  1202                 (filter isNil or:[filter value:fntDescr])
  1186                 and:[ fntDescr face = face 
       
  1187                 and:[ fntDescr style = style ]]
       
  1188             ].
  1203             ].
  1189 
  1204 
  1190     sizes := 
  1205     false "(filteredFonts contains:[:fntDescr | fntDescr isXftFont])" ifTrue:[
  1191         faceAndStyleFonts
  1206         hasScalableFont := true
  1192             collect:[:fntDescr |
  1207     ] ifFalse:[
  1193                 fntDescr isScaledFont ifTrue:[
  1208         filteredFonts := 
  1194                     hasScalableFont := true.
  1209             filteredFonts
       
  1210                 select:[:fntDescr |
       
  1211                     (fntDescr face = face) and:[ fntDescr style = style ]
  1195                 ].
  1212                 ].
  1196                 sizeUnit == #px 
  1213 
  1197                     ifTrue:[ fntDescr pixelSize ]
  1214         sizes := 
  1198                     ifFalse:[ fntDescr size ]
  1215             filteredFonts
  1199             ].
  1216                 collect:[:fntDescr |
       
  1217                     fntDescr isScaledFont ifTrue:[
       
  1218                         hasScalableFont := true.
       
  1219                     ].
       
  1220                     sizeUnit == #px 
       
  1221                         ifTrue:[ fntDescr pixelSize ]
       
  1222                         ifFalse:[ fntDescr size ]
       
  1223                 ].
       
  1224     ].
  1200 
  1225 
  1201     hasScalableFont ifTrue:[
  1226     hasScalableFont ifTrue:[
  1202         sizeUnit == #px ifTrue:[
  1227         sizeUnit == #px ifTrue:[
  1203             ^ #(10 16 20 24 28 32 48 56 64 72 80 92 128)
  1228             ^ #(10 16 20 24 28 32 48 56 64 72 80 92 128)
  1204         ].
  1229         ].
  1232 !
  1257 !
  1233 
  1258 
  1234 getStylesInFamily:aFamilyName face:aFace filtering:filter
  1259 getStylesInFamily:aFamilyName face:aFace filtering:filter
  1235     "the list of font styles for a given family-face"
  1260     "the list of font styles for a given family-face"
  1236 
  1261 
  1237     |familyFonts|
  1262     |familyFonts filteredFonts|
  1238 
  1263 
  1239     familyFonts := fontsPerFamily at:aFamilyName ifAbsent:nil.
  1264     familyFonts := fontsPerFamily at:aFamilyName ifAbsent:nil.
  1240     familyFonts isEmptyOrNil ifTrue:[^ nil].
  1265     familyFonts isEmptyOrNil ifTrue:[^ nil].
  1241 
  1266 
  1242     ^ familyFonts 
  1267     filteredFonts := familyFonts 
  1243         select:[:fntDescr |
  1268         select:[:fntDescr |
  1244             (filter isNil or:[filter value:fntDescr])
  1269             (filter isNil or:[filter value:fntDescr])
  1245             and:[fntDescr face = aFace]
  1270         ].
  1246         ]
  1271     false "(filteredFonts contains:[:fntDescr | fntDescr isXftFont])" ifTrue:[
  1247         thenCollect:[:fntDescr |
  1272         ^ #(#'roman' #'italic').  
       
  1273     ].
       
  1274 
       
  1275     filteredFonts := filteredFonts 
       
  1276         select:[:fntDescr | fntDescr face = aFace].
       
  1277 
       
  1278     ^ filteredFonts
       
  1279         collect:[:fntDescr |
  1248             fntDescr style.
  1280             fntDescr style.
  1249         ]
  1281         ]
  1250 
       
  1251 "/    ^ self graphicsDevice stylesInFamily:aFamilyName face:aFace filtering:filter.
       
  1252 !
  1282 !
  1253 
  1283 
  1254 showPreview
  1284 showPreview
  1255     "show the preview text"
  1285     "show the preview text"
  1256 
  1286 
  1550 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding enabled:enabled
  1580 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding enabled:enabled
  1551     "open this fontPanel with title and font-filter
  1581     "open this fontPanel with title and font-filter
  1552      and return the selected font, or nil if abort is pressed"
  1582      and return the selected font, or nil if abort is pressed"
  1553 
  1583 
  1554     ^ self 
  1584     ^ self 
  1555         fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding enabled:enabled
  1585         fontFromUserInitial:initialFont 
       
  1586         title:someTitle 
       
  1587         filter:aFilterBlock 
       
  1588         encoding:encoding 
       
  1589         enabled:enabled
  1556         withChangeAllOption:false
  1590         withChangeAllOption:false
  1557 
  1591 
  1558     "
  1592     "
  1559      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'.
  1593      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'.
  1560      
  1594