FontPanel.st
changeset 5900 d880e4b3a36d
parent 5626 7b87b3d3ecbc
child 5901 d575ae9a1102
child 5903 9f80a35511a4
--- a/FontPanel.st	Thu Oct 06 23:14:38 2016 +0200
+++ b/FontPanel.st	Tue Oct 11 20:10:07 2016 +0200
@@ -18,10 +18,12 @@
 		faceList sizeList revertButton currentFamily currentFace
 		currentStyle currentFaceAndStyle currentSize sizeUnit
 		currentEncoding selectedFont nameLabel encodingFilter
-		encodingLabel filter combinedFilter encoding sizeLabelHolder
-		pixelPointSwitch xftFontsOnlyHolder changeFontInAllViewsHolder
-		withChangeFontInAllViewsCheckBox
-		withChangeFontInAllViewsCheckBoxVisibleHolder'
+		encodingFilterField encodingLabel combinedFilter encoding
+		sizeLabelHolder pixelPointSwitch xftFontsOnlyHolder
+		changeFontInAllViewsHolder withChangeFontInAllViewsCheckBox
+		withChangeFontInAllViewsCheckBoxVisibleHolder
+		decorativeOnlyHolder nonDecorativeOnlyHolder monospacedOnlyHolder
+		nonMonospacedOnlyHolder'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-DialogBoxes'
@@ -419,11 +421,24 @@
     ^ changeFontInAllViewsHolder
 !
 
+decorativeOnlyHolder
+    decorativeOnlyHolder isNil ifTrue:[
+        decorativeOnlyHolder := false asValue
+    ].
+    ^ decorativeOnlyHolder
+!
+
 encoding:aPattern
     "set the encoding goal"
 
-    encoding := aPattern.
-    encodingFilter contents:encoding.
+    ((aPattern = #'iso8859-1')
+    or:[ (aPattern = #'iso10646-1') ]) ifFalse:[
+        encoding := aPattern
+    ] ifTrue:[
+        encoding := #'*'
+    ].    
+
+    encodingFilterField contents:encoding.
 
     self encodingFilterSelected:encoding.
     shown ifTrue:[
@@ -434,28 +449,61 @@
     "Modified: 29.4.1996 / 09:40:18 / cg"
 !
 
+encodingFilter:aOneArgBlockOrNil
+    "set a filter"
+
+    encodingFilter := aOneArgBlockOrNil.
+    self filterChanged
+
+    "Created: 27.2.1996 / 01:40:08 / cg"
+    "Modified: 29.4.1996 / 09:40:49 / cg"
+!
+
 filter:aOneArgBlockOrNil
+    <resource: #obsolete>
     "set a filter; if non-nil, only fonts for which the filterBlock
      returns true will be offered"
 
-    filter := aOneArgBlockOrNil.
-    filter isNil ifTrue:[
+    self obsoleteMethodWarning:'use encodingFilter:'.
+    self filter:aOneArgBlockOrNil.
+!
+
+filterChanged
+    "construct a combined a filter"
+
+    |filter1 filter2 filter3|
+    
+    encodingFilter isNil ifTrue:[
         xftFontsOnlyHolder value 
-            ifTrue:[ combinedFilter := [:fd | fd isXftFont] ]
-            ifFalse:[ combinedFilter := [:fd | true] ]                                     
+            ifTrue:[ filter1 := [:fd | fd isXftFont] ]
+            ifFalse:[ filter1 := [:fd | true] ]                                     
     ] ifFalse:[
         xftFontsOnlyHolder value 
-            ifTrue:[ combinedFilter := [:fd | fd isXftFont and:[filter value:fd]] ]
-            ifFalse:[ combinedFilter := filter ]
+            ifTrue:[ filter1 := [:fd | fd isXftFont and:[encodingFilter value:fd]] ]
+            ifFalse:[ filter1 := encodingFilter ]
     ].
-
-    familyList list:nil.
-    shown ifTrue:[
-        self updateFamilyList
-    ].
-
-    "Created: 27.2.1996 / 01:40:08 / cg"
-    "Modified: 29.4.1996 / 09:40:49 / cg"
+    filter2 := filter1.
+    
+    self decorativeOnlyHolder value ifTrue:[
+        self nonDecorativeOnlyHolder value:false withoutNotifying:self.
+        filter2 := [:fd | fd isDecorativeFont and:[filter1 value:fd]]
+    ] ifFalse:[
+        self nonDecorativeOnlyHolder value ifTrue:[    
+            filter2 := [:fd | fd isDecorativeFont not and:[filter1 value:fd]]
+        ].    
+    ].    
+    filter3 := filter2.
+    
+    self monospacedOnlyHolder value ifTrue:[
+        self nonMonospacedOnlyHolder value:false withoutNotifying:self.
+        filter3 := [:fd | fd isFixedWidth and:[filter2 value:fd]]
+    ] ifFalse:[
+        self nonMonospacedOnlyHolder value ifTrue:[    
+            filter3 := [:fd | fd isFixedWidth not and:[filter2 value:fd]]
+        ].    
+    ].    
+    combinedFilter := filter3.
+    self refreshFamilyList
 !
 
 initialFont:aFont
@@ -479,13 +527,42 @@
     ].
 
 "/ self halt.
-    encodingFilter contents:fontEncoding.
-    self encodingFilterSelected:fontEncoding.
+    self encoding:fontEncoding. 
+    "/    encodingFilter contents:fontEncoding.
+    "/    self encodingFilterSelected:fontEncoding.
     self showSelectedFont.
 
     "Modified: 23.2.1996 / 00:51:32 / cg"
 !
 
+monospacedOnlyHolder
+    monospacedOnlyHolder isNil ifTrue:[
+        monospacedOnlyHolder := false asValue
+    ].
+    ^ monospacedOnlyHolder
+!
+
+nonDecorativeOnlyHolder
+    nonDecorativeOnlyHolder isNil ifTrue:[
+        nonDecorativeOnlyHolder := false asValue
+    ].
+    ^ nonDecorativeOnlyHolder
+!
+
+nonMonospacedOnlyHolder
+    nonMonospacedOnlyHolder isNil ifTrue:[
+        nonMonospacedOnlyHolder := false asValue
+    ].
+    ^ nonMonospacedOnlyHolder
+!
+
+refreshFamilyList
+    familyList list:nil.
+    shown ifTrue:[
+        self updateFamilyList
+    ].
+!
+
 withChangeFontInAllViewsCheckBoxVisibleHolder
     withChangeFontInAllViewsCheckBoxVisibleHolder isNil ifTrue:[
         withChangeFontInAllViewsCheckBoxVisibleHolder := false asValue
@@ -513,8 +590,8 @@
     familyList enabled:aBoolean.
     faceList enabled:aBoolean.
     sizeList enabled:aBoolean.
-    encodingFilter notNil ifTrue:[
-        encodingFilter enabled:aBoolean.
+    encodingFilterField notNil ifTrue:[
+        encodingFilterField enabled:aBoolean.
     ].
     aBoolean ifTrue:[
         self abortButton label:(resources string:'Cancel').
@@ -535,8 +612,8 @@
     "sigh: hand-crafted box creation; TODO: rewrite using UI painter"
     
     |familyLabel faceLabel sizeLabel panel panel2 fontBrowserView fp v1 v2 v3
-     mm fH l box1 box2 showFontNameLabel xftCheckBox vPanel changeInAllCheckBox
-     xftFlushFontList|
+     mm fH l box1 box2 box3 box4 showFontNameLabel xftCheckBox vPanel changeInAllCheckBox
+     xftFlushFontList decorativeCheckBox nonDecorativeCheckBox monospacedCheckBox nonMonospacedCheckBox|
 
     super initialize.
 
@@ -570,85 +647,112 @@
     panel2 horizontalLayout:#fit.
     panel2 verticalLayout:#top.
 
-    box2 := HorizontalPanelView in:panel2.
-    box2 height:25.
-    box2 horizontalLayout:#right.
-
     box1 := HorizontalPanelView in:panel2.
     box1 height:25.
-    box1 horizontalLayout:#leftSpace.
+    box1 horizontalLayout:#rightFit.
 
-    l := Label label:(resources string:'Encoding:') in:box1.
-    l borderWidth:0.
-    l adjust:#left.
+        showFontNameLabel ifTrue:[
+            nameLabel := Label label:'' in:box1.
+            "/ nameLabel origin:0.0@1.0 corner:1.0@1.0.
+            "/ nameLabel bottomInset:(buttonPanel preferredHeight + (mm*2)).
+            "/ nameLabel topInset:(buttonPanel preferredHeight + (mm*2) + 24) negated; horizontalInset:mm.
+            nameLabel level:0; adjust:#left.
+        ].
+
+        pixelPointSwitch := ComboListView in:box1.
+        "/ encodingFilter font:l font.
+        pixelPointSwitch level:-1.
+        pixelPointSwitch contents:'pt'.
+        pixelPointSwitch list:#(#pt #px).
+        pixelPointSwitch action:[:sizeUnit | self sizeUnitSelected:sizeUnit].
+        "/ box2 topInset:(pixelPointSwitch preferredHeight negated-4); horizontalInset:mm.
+        "/ encodingFilter editor font:l font.
 
-    encodingFilter := ComboBoxView in:box1.
-    "/ encodingFilter font:l font.
-    encodingFilter level:-1.
-    encodingFilter contents:'*'.
-    encodingFilter list:(self listOfEncodingsInFilterCombo).
-    encodingFilter action:[:pattern | self encodingFilterSelected:pattern].
-    encodingFilter immediateAccept:true.
-    "/ encodingFilter editor font:l font.
+    panel2 add:(View new height:8).
+    
+    "/    self showEncodingFilter ifFalse:[
+    "/        encodingFilter beInvisible
+    "/    ].
+
+    box2 := HorizontalPanelView in:panel2.
+    box2 height:25.
+    box2 horizontalLayout:#leftSpace.
 
-    self showEncodingFilter ifFalse:[
-        encodingFilter beInvisible
-    ].
+        l := Label label:(resources string:'Encoding:') in:box2.
+        l borderWidth:0.
+        l adjust:#left.
 
-"/    encodingFilter acceptOnReturn:true.
-"/    encodingFilter acceptOnTab:true.
-"/    encodingFilter acceptOnLeave:true.
-"/    encodingFilter acceptOnLostFocus:true.
-"/    encodingFilter acceptOnPointerLeave:true.
+        encodingFilterField := ComboBoxView in:box2.
+        "/ encodingFilterField font:l font.
+        encodingFilterField level:-1.
+        encodingFilterField contents:'*'.
+        encodingFilterField list:(self listOfEncodingsInFilterCombo).
+        encodingFilterField action:[:pattern | self encodingFilterSelected:pattern].
+        encodingFilterField immediateAccept:true.
+        "/ encodingFilterField editor font:l font.
 
-    encodingLabel := Label label:' ' in:box1.
+        self showEncodingFilter ifFalse:[
+            encodingFilterField beInvisible
+        ].
 
-    encodingLabel level:0; adjust:#left.
-    encodingLabel adjust:#right.
-    self showEncodingFilter ifFalse:[
-        encodingLabel beInvisible
-    ].
+        "/    encodingFilterField acceptOnReturn:true.
+        "/    encodingFilterField acceptOnTab:true.
+        "/    encodingFilterField acceptOnLeave:true.
+        "/    encodingFilterField acceptOnLostFocus:true.
+        "/    encodingFilterField acceptOnPointerLeave:true.
+
+        encodingLabel := Label label:' ' in:box2.
 
-    device supportsXftFonts ifTrue:[
-        self xftFontsOnlyHolder value: (UserPreferences current useXftFontsOnly).
-        xftCheckBox := CheckBox label:(resources string:'XFT Fonts Only') in:box1.
-        xftCheckBox model:xftFontsOnlyHolder.
-        xftFontsOnlyHolder onChangeEvaluate:[ self xftFontsOnlyChanged ].
+        encodingLabel level:0; adjust:#left.
+        encodingLabel adjust:#right.
+        self showEncodingFilter ifFalse:[
+            encodingLabel beInvisible
+        ].
 
-        xftFlushFontList := Button label:(resources string:'Flush Cached List of Fonts') in:box1.
-        xftFlushFontList action:[ self flushListOfAvailableFonts].
-    ].
+        device supportsXftFonts ifTrue:[
+            self xftFontsOnlyHolder value: (UserPreferences current useXftFontsOnly).
+            xftCheckBox := CheckBox label:(resources string:'XFT Fonts Only') in:box2.
+            xftCheckBox model:xftFontsOnlyHolder.
+            xftFontsOnlyHolder onChangeEvaluate:[ self xftFontsOnlyChanged ].
+
+            xftFlushFontList := Button label:(resources string:'Flush Cached List of Fonts') in:box2.
+            xftFlushFontList action:[ self flushListOfAvailableFonts].
+        ].
 
-"/    sep := View in:box1.
-"/    sep width:10 height:10.
+false ifTrue:[
+    decorativeCheckBox := CheckBox label:(resources string:'Decorative Fonts Only').
+    box3 := View new height:(decorativeCheckBox preferredHeight).
+    panel2 add:box3.
+    
+    decorativeCheckBox origin:0.0@0.0 corner:0.5@1.0.
+    box3 add:decorativeCheckBox.
+    decorativeCheckBox model:self decorativeOnlyHolder.
+    self decorativeOnlyHolder onChangeEvaluate:[ self filterChanged ].
+
+    nonDecorativeCheckBox := CheckBox label:(resources string:'Non Decorative Fonts Only') in:box3.
+    nonDecorativeCheckBox origin:0.5@0.0 corner:1.0@1.0.
+    nonDecorativeCheckBox model:self nonDecorativeOnlyHolder.
+    self nonDecorativeOnlyHolder onChangeEvaluate:[ self filterChanged ].
 
-    pixelPointSwitch := ComboListView in:box2.
-    "/ encodingFilter font:l font.
-    pixelPointSwitch level:-1.
-    pixelPointSwitch contents:'pt'.
-    pixelPointSwitch list:#(#pt #px).
-    pixelPointSwitch action:[:sizeUnit | self sizeUnitSelected:sizeUnit].
-    "/ box2 topInset:(pixelPointSwitch preferredHeight negated-4); horizontalInset:mm.
-    "/ encodingFilter editor font:l font.
+    monospacedCheckBox := CheckBox label:(resources string:'Monospaced Fonts Only').
+    box4 := View new height:(monospacedCheckBox preferredHeight).
+    panel2 add:box4.
 
-"/    self showEncodingFilter ifFalse:[
-"/        encodingFilter beInvisible
-"/    ].
+    monospacedCheckBox origin:0.0@0.0 corner:0.5@1.0.
+    box4 add:monospacedCheckBox.
+    monospacedCheckBox model:self monospacedOnlyHolder.
+    self monospacedOnlyHolder onChangeEvaluate:[ self filterChanged ].
 
-    (View in:panel2) height:8. "/ separator
+    nonMonospacedCheckBox := CheckBox label:(resources string:'Non Monospaced Fonts Only') in:box4.
+    nonMonospacedCheckBox origin:0.5@0.0 corner:1.0@1.0.
+    nonMonospacedCheckBox model:self nonMonospacedOnlyHolder.
+    self nonMonospacedOnlyHolder onChangeEvaluate:[ self filterChanged ].
+].
+
     changeInAllCheckBox := CheckBox label:(resources string:'Change all Textviews and Default for New Views') in:panel2.
     changeInAllCheckBox model:self changeFontInAllViewsHolder.
     changeInAllCheckBox visibilityChannel:self withChangeFontInAllViewsCheckBoxVisibleHolder.
     
-    showFontNameLabel ifTrue:[
-        (View in:panel2) height:8. "/ separator
-        nameLabel := Label label:'' in:panel2.
-        "/ nameLabel origin:0.0@1.0 corner:1.0@1.0.
-        "/ nameLabel bottomInset:(buttonPanel preferredHeight + (mm*2)).
-        "/ nameLabel topInset:(buttonPanel preferredHeight + (mm*2) + 24) negated; horizontalInset:mm.
-        nameLabel level:0; adjust:#left.
-    ].
-
     "/ previewField origin:0.0@0.0 corner:1.0@0.4.
     previewField autoHideScrollBars:true.
     previewField := previewField scrolledView.
@@ -1192,7 +1296,7 @@
 !
 
 xftFontsOnlyChanged
-    self filter:filter. "/ will update combinedFilter
+    self filterChanged. "/ will update combinedFilter
 ! !
 
 !FontPanel methodsFor:'queries'!
@@ -1335,7 +1439,7 @@
 
     |selectedFont|
 
-    self filter:aFilterBlock.
+    self encodingFilter:aFilterBlock.
     someTitle notNil ifTrue:[
         self label:someTitle
     ].
@@ -1347,7 +1451,10 @@
         self encoding:encoding.
     ] ifFalse:[
         initialFont notNil ifTrue:[
-            self encoding:initialFont encoding
+            ((initialFont encoding = #'iso8859-1')
+            or:[ (initialFont encoding = #'iso10646-1') ]) ifFalse:[
+                self encoding:initialFont encoding
+            ].
         ].
     ].
     self enabled:enabled.
@@ -1379,7 +1486,7 @@
     |pattern|
 
     anEncodingPattern isNil ifTrue:[
-        self filter:nil.
+        self encodingFilter:nil.
         ^ self.
     ].
 
@@ -1391,7 +1498,7 @@
         pattern := (pattern isEmptyOrNil ifTrue:'*' ifFalse:pattern).
     ].
     self 
-        filter:
+        encodingFilter:
             [:f | 
                 |doesMatch encoding|
 
@@ -1408,7 +1515,10 @@
                     (encoding = 'iso8859-1' 
                     or:[encoding = 'iso10646-1' 
                     or:[encoding = 'unicode']]) ifTrue:[
-                       doesMatch := (pattern = 'ms-ansi')
+                       doesMatch := (pattern = 'ms-ansi').
+                       "/ unicode can show all iso charas as well...
+                       doesMatch := doesMatch or:[ pattern = 'iso8859-1' ].
+                       doesMatch := doesMatch or:[ pattern = 'ascii' ].
                     ].
                 ].
                 doesMatch
@@ -1573,6 +1683,12 @@
     ].
 !
 
+fontAttributeFilterChanged
+    "a filter toggled (decorative/monospaced etc.)"
+
+^ self.
+!
+
 okPressed
     "ok was pressed; hide myself and evaluate the okAction, passing
      family, face, style and size as arguments"