correct display of non-unicode, non-8859 encoded fonts
authorClaus Gittinger <cg@exept.de>
Fri, 05 Mar 2004 18:51:59 +0100
changeset 2930 576e73803b46
parent 2929 8298734011b6
child 2931 dcbb4ed67115
correct display of non-unicode, non-8859 encoded fonts
FontPanel.st
--- a/FontPanel.st	Fri Mar 05 15:27:33 2004 +0100
+++ b/FontPanel.st	Fri Mar 05 18:51:59 2004 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1991 by Claus Gittinger
 	      All Rights Reserved
@@ -120,6 +122,15 @@
 
 !FontPanel class methodsFor:'defaults'!
 
+defaultAsciiSampleString
+    ^ (self sampleStringWithAllLetters) , '
+
+ABCDEFGHIJKLMNOPQRSTUVWXYZ
+abcdefghijklmnopqrstuvwxyz
+1234567890    !!@#$%^&*(){}[]:"~;,./<>?
+'
+!
+
 defaultExtent
     "return the default extent of my instances.
      The value returned here is usually ignored, and
@@ -133,35 +144,18 @@
 defaultJIS0201SampleString
     "return the sample jis preview text"
 
-    ^ ('The quick brown fox
-jumps over the lazy dog
-
-ABCDEFGHIJKLMNOPQRSTUVWXYZ
-abcdefghijklmnopqrstuvwxyz
-1234567890
-!!@#$%^&*(){}[]:"~;,./<>?
-
-')
+    ^ (self defaultLatin1SampleString).
 !
 
 defaultJISSampleString
     "return the sample jis preview text"
 
-    ^ CharacterEncoder 
-        encodeString:(
+    ^ 
 'The quick brown fox
-jumps over the lazy dog
+jumps over the lazy dog.
 
-ABCDEFGHIJKLMNOPQRSTUVWXYZ
-abcdefghijklmnopqrstuvwxyz
-1234567890
-!!@#$%^&*(){}[]:"~;,./<>?
-
-' ,
+' , (self defaultAsciiSampleString) ,
 (UnicodeString fromString:(#(16r65E5 16r672C 16r8A9E) collect:[:c | Character value:c]))
-        )
-        from:#'unicode'
-        into:#'jisx0208.1983-0'
 !
 
 defaultLatin1SampleString
@@ -169,20 +163,7 @@
 
     |t|
 
-    Smalltalk language == #de ifTrue:[
-        t := 'Franz jagt im komplett verwahrlosten Taxi
-quer durch Bayern'.
-    ] ifFalse:[
-        t := 'The quick brown fox
-jumps over the lazy dog'.
-    ].
-    t := t , '
-
-ABCDEFGHIJKLMNOPQRSTUVWXYZ
-abcdefghijklmnopqrstuvwxyz
-1234567890
-!!@#$%^&*(){}[]:"~;,./<>?
-' , 
+    t := (self defaultAsciiSampleString) , 
 (Character value:16rE4) asString ,    "/ umlaut a
 (Character value:16rF6) asString ,    "/ umlaut o
 (Character value:16rFC) asString ,    "/ umlaut u
@@ -202,21 +183,34 @@
 !
 
 defaultSampleStringForEncoding:enc
+    |string lines|
+
     enc notNil ifTrue:[    
-        (enc startsWith:'jis') ifTrue:[
-            (enc includesString:'0201') ifTrue:[
-                ^ self defaultJIS0201SampleString    
-            ].
-            ^ self defaultJISSampleString
-        ].
         ((enc startsWith:'unicode') or:[enc startsWith:'iso10646-']) ifTrue:[
             ^ self defaultUnicodeSampleString.
         ].
         (enc startsWith:'ms-ansi') ifTrue:[
             ^ self defaultUnicodeSampleString.
         ].
+
+        (enc startsWith:'jis') ifTrue:[
+            (enc includesString:'0201') ifTrue:[
+                string := self defaultJIS0201SampleString    
+            ] ifFalse:[
+                string := self defaultJISSampleString
+            ]
+        ] ifFalse:[
+        ]
     ].
-    ^ self defaultLatin1SampleString.
+    string isNil ifTrue:[
+        string := self defaultLatin1SampleString.
+    ].
+    lines := string asStringCollection.
+    Error handle:[:ex |
+    ] do:[
+        lines := lines encodeFrom:#unicode into:enc
+    ].
+    ^ lines.
 !
 
 defaultUnicodeSampleString
@@ -224,19 +218,7 @@
 
     |t|
 
-    Smalltalk language == #de ifTrue:[
-        t := 'Franz jagt im komplett verwahrlosten Taxi
-quer durch Bayern'.
-    ] ifFalse:[
-        t := 'The quick brown fox
-jumps over the lazy dog'.
-    ].
-    t := t , '
-
-ABCDEFGHIJKLMNOPQRSTUVWXYZ
-abcdefghijklmnopqrstuvwxyz
-1234567890
-!!@#$%^&*(){}[]:"~;,./<>?
+    t := (self defaultAsciiSampleString) , '
 diaresis: ' , 
 (Character value:16rE4) asString ,    "/ umlaut a
 (Character value:16rF6) asString ,    "/ umlaut o
@@ -266,6 +248,10 @@
     ^ t
 
     "Modified: 29.4.1996 / 09:46:19 / cg"
+!
+
+sampleStringWithAllLetters
+    ^ (self classResources at:'CHARSET_TEST_SENTENCE' ifAbsent:'The quick brown fox jumps over the lazy dog') withCRs
 ! !
 
 !FontPanel class methodsFor:'menu specs'!
@@ -987,5 +973,5 @@
 !FontPanel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/FontPanel.st,v 1.75 2004-03-03 08:36:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/FontPanel.st,v 1.76 2004-03-05 17:51:59 cg Exp $'
 ! !