Text.st
changeset 335 4adf1b6b4063
parent 316 628f72ebc5bc
child 336 5fd5fcc38eaa
--- a/Text.st	Tue May 14 15:55:10 1996 +0200
+++ b/Text.st	Tue May 14 16:39:47 1996 +0200
@@ -39,6 +39,17 @@
 "
     Texts add emphasis information to a string.
 
+    Currently, the following attributes are supported:
+        #bold     
+        #italic  
+        #underline  
+        #strikeout
+        (#color -> aColor)
+        (#backgroundColor -> aColor)
+
+    Attributes may be combined (pass an array of above) as emphasis.
+    See examples.
+
     This class is not yet fully implemented - being constructed.
 
     [author:]
@@ -189,6 +200,27 @@
     "
 
     "Modified: 12.5.1996 / 17:16:03 / cg"
+!
+
+string:aString emphasisCollection:attributeCollection
+    "create a Text instance, for the characters in aString,
+     which are individually emphasized as described by attributeCollection."
+
+    ^ self new string:aString emphasisCollection:attributeCollection
+
+    "
+     Text 
+        string:'hello' 
+        emphasisCollection:#(#bold #bold #italic #italic #italic)
+
+     Dialog
+        information:(Text 
+                        string:'hello' 
+                        emphasisCollection:#(#bold #bold #italic #italic #(#underline italic)))
+    "
+
+    "Created: 14.5.1996 / 14:02:18 / cg"
+    "Modified: 14.5.1996 / 15:01:28 / cg"
 ! !
 
 !Text methodsFor:'comparing'!
@@ -233,11 +265,36 @@
 , aStringOrText
     "for now, return a string ..."
 
-    ^ self species new
-        string:(string , aStringOrText)
-        runs:(runs , aStringOrText runs)
+    (aStringOrText hasChangeOfEmphasis 
+    or:[self hasChangeOfEmphasis]) ifTrue:[
+        ^ self species new
+            string:(string , aStringOrText)
+            emphasisCollection:(runs , aStringOrText emphasisCollection)
+    ].
+    ^ string , aStringOrText string
+
+    "
+     ('hello' asText allBold) , ' world'    
+     'hello' , (' world' asText allBold)
+     'hello' , ' world'
+     ('hello' asText allBold) , (' world' asText allBold)
+    "
 
-    "Created: 11.5.1996 / 13:59:54 / cg"
+    "Modified: 14.5.1996 / 15:56:00 / cg"
+!
+
+concatenateFromString:aString
+    "return the concatenation of aString and myself.
+     This may be a Text (if I have emphasis) or a string (if not)."
+
+    self hasChangeOfEmphasis ifTrue:[
+        ^ self species new
+                string:(aString , string)
+                emphasisCollection:((RunArray new:(aString size)) , runs).
+    ].
+    ^ aString , string
+
+    "Modified: 14.5.1996 / 15:56:05 / cg"
 ! !
 
 !Text methodsFor:'displaying'!
@@ -406,6 +463,20 @@
     "Modified: 11.5.1996 / 14:22:12 / cg"
 !
 
+emphasis
+    "return the emphasis"
+
+    ^ runs
+
+    "
+     (Text string:'hello') allBold emphasis 
+     'hello' emphasis   
+    "
+
+    "Modified: 11.5.1996 / 14:22:31 / cg"
+    "Created: 14.5.1996 / 13:59:03 / cg"
+!
+
 emphasisAt:characterIndex
     "return the emphasis at some index"
 
@@ -430,6 +501,20 @@
     "Modified: 12.5.1996 / 12:40:31 / cg"
 !
 
+emphasisCollection
+    "return the emphasis"
+
+    ^ runs
+
+    "
+     (Text string:'hello') allBold emphasis 
+     'hello' emphasis   
+    "
+
+    "Created: 14.5.1996 / 13:59:03 / cg"
+    "Modified: 14.5.1996 / 15:02:11 / cg"
+!
+
 emphasizeAllWith:emphasis
     "change the emphasis of all characters"
 
@@ -507,6 +592,21 @@
     "
 
     "Modified: 11.5.1996 / 14:19:38 / cg"
+!
+
+string:aString emphasisCollection:emphasisCollection
+    string := aString.
+    runs := emphasisCollection asRunArray
+
+    "
+     |t|
+
+     t := Text new string:'hello' emphasisCollection:(#bold #bold #bold #italic #italic).
+     t emphasisAt:2.
+    "
+
+    "Created: 14.5.1996 / 14:03:29 / cg"
+    "Modified: 14.5.1996 / 14:57:45 / cg"
 ! !
 
 !Text methodsFor:'queries'!
@@ -518,9 +618,13 @@
 !
 
 hasChangeOfEmphasis
-    ^ runs notNil
+    "return true, if the receiver contains non-empty emphasis information"
+
+    ^ (runs notNil
+       and:[(runs findFirst:[:e | e notNil]) ~~ 0])
 
     "Created: 11.5.1996 / 14:03:19 / cg"
+    "Modified: 14.5.1996 / 15:51:01 / cg"
 !
 
 heightOn:aGC
@@ -639,6 +743,6 @@
 !Text class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Text.st,v 1.9 1996-05-12 18:45:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Text.st,v 1.10 1996-05-14 14:39:47 cg Exp $'
 ! !
 Text initialize!