Text.st
author Claus Gittinger <cg@exept.de>
Sun, 12 May 1996 16:01:23 +0200
changeset 307 8d58cb6e618b
parent 304 dee14fa0f2f7
child 308 bb9472eec501
permissions -rw-r--r--
fixes & addons
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996 by Claus Gittinger
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
CharacterArray subclass:#Text
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'string runs'
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Collections-Text'
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!Text class methodsFor:'documentation'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
 COPYRIGHT (c) 1996 by Claus Gittinger
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
              All Rights Reserved
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
documentation
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    Texts add emphasis information to a string.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    This class is not yet fully implemented - being constructed.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    [author:]
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
        Claus Gittinger
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    [see also:]
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
        CharacterArray String RunArray
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
! !
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
!Text class methodsFor:'instance creation'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
fromString:aString 
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    ^ self new string:aString emphasis:nil
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
     Text fromString:'hello'
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    "Modified: 11.5.1996 / 14:20:35 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
    64
new:size
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
    65
    "redefined for string-protocol compatibility"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
    66
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
    67
    ^ self string:(String new:size)
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
    68
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
    69
    "Created: 12.5.1996 / 11:57:27 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
    70
!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
    71
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
string:aString 
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    ^ self new string:aString emphasis:nil
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
     Text string:'hello'
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    "Modified: 11.5.1996 / 14:20:48 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
string:aString emphasis:attribute
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    ^ self new string:aString emphasis:attribute
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
     Text string:'hello' emphasis:#bold
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    "Modified: 11.5.1996 / 14:21:01 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
! !
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
!Text methodsFor:'comparing'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
= aStringOrText
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    "compare the receiver and the argument, ignoring emphasis"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    ^ string = aStringOrText string
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
     'hello' asText = 'hello'        
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
     'hello' asText = 'hello' asText 
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
     'hello' asText allBold = 'hello' 
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    "Modified: 11.5.1996 / 14:33:00 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
! !
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
!Text methodsFor:'converting'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
asText
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    ^ self
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    "Created: 11.5.1996 / 14:08:36 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
at:characterIndex
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
    ^ string at:characterIndex
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    "Created: 11.5.1996 / 14:25:41 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
at:characterIndex put:aCharacter
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
    ^ string at:characterIndex put:aCharacter
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    "Created: 11.5.1996 / 14:25:49 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
! !
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
!Text methodsFor:'copying'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
, aStringOrText
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    "for now, return a string ..."
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
    ^ self species new
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
        string:(string , aStringOrText)
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
        runs:(runs , aStringOrText runs)
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
    "Created: 11.5.1996 / 13:59:54 / cg"
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   139
! !
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   140
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   141
!Text methodsFor:'displaying'!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   142
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   143
displayOn:aGC x:x y:y
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   144
    "display the receiver on a GC"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   145
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   146
    self displayOn:aGC x:x y:y opaque:false
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   147
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   148
    "Modified: 12.5.1996 / 11:14:57 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   149
!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   150
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   151
displayOn:aGC x:x y:y from:start to:stop
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   152
    "display the receiver on a GC"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   153
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   154
    "q&d hack"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   155
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   156
    (self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:false
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   157
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   158
    "Modified: 12.5.1996 / 12:49:33 / cg"
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   161
displayOn:aGC x:x0 y:y opaque:opaque
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   162
    "display the receiver on a GC"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   163
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   164
    |savedFont font color boldFont italicFont savedPaint 
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   165
     bold italic underline strikeout pos x l|
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   166
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   167
    savedFont := aGC basicFont.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   168
    savedPaint := aGC paint.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   169
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   170
    pos := 1.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   171
    x := x0.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   172
    runs runsDo:[:len :emphasis |
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   173
        color := nil.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   174
        bold := italic := underline := strikeout := false.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   175
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   176
        emphasis isSymbol ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   177
            emphasis == #bold ifTrue:[bold := true]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   178
            ifFalse:[emphasis == #italic ifTrue:[italic := true]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   179
            ifFalse:[emphasis == #underline ifTrue:[underline := true]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   180
            ifFalse:[emphasis == #strikeout ifTrue:[strikeout := true]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   181
            ]]]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   182
        ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   183
            (emphasis isMemberOf:Association) ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   184
                emphasis key == #color ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   185
                    color := emphasis value
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   186
                ]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   187
            ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   188
                emphasis notNil ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   189
                    emphasis do:[:entry |
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   190
                        entry == #bold ifTrue:[bold := true]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   191
                        ifFalse:[entry == #italic ifTrue:[italic := true]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   192
                        ifFalse:[entry == #underline ifTrue:[underline := true]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   193
                        ifFalse:[entry == #strikeout ifTrue:[strikeout := true]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   194
                        ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   195
                            (entry isMemberOf:Association) ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   196
                                entry key == #color ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   197
                                    color := entry value
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   198
                            ]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   199
                        ]]]]]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   200
                    ]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   201
                ]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   202
            ]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   203
        ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   204
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   205
        color isNil ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   206
            color := savedPaint.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   207
        ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   208
            color := color on:aGC device.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   209
        ].
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   211
        bold ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   212
            boldFont isNil ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   213
                boldFont := savedFont asBold on:aGC device
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   214
            ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   215
            font := boldFont.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   216
        ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   217
            italic ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   218
                italicFont isNil ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   219
                    italicFont := savedFont asItalic on:aGC device
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   220
                ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   221
                font := italicFont.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   222
            ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   223
                font := savedFont
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   224
            ]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   225
        ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   226
        aGC basicFont:font.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   227
        aGC paint:color.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   228
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   229
        opaque ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   230
            aGC displayOpaqueString:string from:pos to:(pos + len - 1) x:x y:y.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   231
        ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   232
            aGC displayString:string from:pos to:(pos + len - 1) x:x y:y.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   233
        ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   234
        l := aGC font widthOf:string from:pos to:(pos + len - 1).
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   235
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   236
        underline ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   237
            aGC displayLineFromX:x y:y toX:x+l-1 y:y
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   238
        ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   239
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   240
        x := x + l.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   241
        pos := pos + len
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    ].
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   243
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   244
    aGC basicFont:savedFont.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   245
    aGC paint:savedPaint.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   246
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   247
    "Created: 12.5.1996 / 11:14:30 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   248
    "Modified: 12.5.1996 / 11:55:06 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   249
!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   250
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   251
displayOpaqueOn:aGC x:x y:y
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   252
    "display the receiver on a GC"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   253
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   254
    self displayOn:aGC x:x y:y opaque:true
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   256
    "Modified: 12.5.1996 / 11:14:52 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   257
!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   258
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   259
displayOpaqueOn:aGC x:x y:y from:start to:stop
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   260
    "display the receiver on a GC"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   261
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   262
    "q&d hack"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   263
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   264
    (self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:true
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   265
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   266
    "Created: 12.5.1996 / 12:29:37 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   267
    "Modified: 12.5.1996 / 12:49:19 / cg"
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
! !
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
!Text methodsFor:'emphasis'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
allBold
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    "make all characters bold"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
    runs := RunArray new:(string size) withAll:#bold
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
     (Text string:'hello') allBold
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
    "Modified: 11.5.1996 / 14:22:12 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
emphasisAt:characterIndex
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
    "return the emphasis at some index"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
    ^ runs at:characterIndex
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
     (Text string:'hello') allBold emphasisAt:2 
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
    "Modified: 11.5.1996 / 14:22:31 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   296
emphasisAt:characterIndex put:emphasis
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   297
    "change the emphasis at some index. return the receiver"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   298
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   299
    runs at:characterIndex put:emphasis
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   300
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   301
    "
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   302
     (Text string:'hello') allBold emphasisAt:2 put:#italic
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   303
    "
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   304
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   305
    "Modified: 12.5.1996 / 12:40:31 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   306
!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   307
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
emphasizeAllWith:emphasis
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
    "change the emphasis of all characters"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
    runs := RunArray new:(string size) withAll:emphasis
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
     (Text string:'hello') allBold emphasizeAllWith:#italic 
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
    "Modified: 11.5.1996 / 14:22:52 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
emphasizeFrom:start to:stop with:emphasis
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
    "change the emphasis of a range of characters"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
    |newRuns|
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
    newRuns := RunArray new.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
    "/ for now - a q&d hack
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
    1 to:start-1 do:[:i |
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
        newRuns add:(runs at:i).
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
    ].
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
    newRuns add:emphasis withOccurrences:(stop - start + 1).
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
    stop+1 to:string size do:[:i |
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
        newRuns add:(runs at:i)
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
    ].
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
    runs := newRuns
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
     (Text string:'hello world') 
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
        emphasizeFrom:1 to:5 with:#bold;
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
        emphasizeFrom:7 to:11 with:#italic
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
    "Modified: 11.5.1996 / 14:30:02 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
! !
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
!Text methodsFor:'printing & storing'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
displayString
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
    ^ self storeString
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
    "Created: 11.5.1996 / 14:24:48 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
printOn:aStream
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
    string printOn:aStream
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
    "Created: 11.5.1996 / 14:27:25 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
storeOn:aStream
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
    aStream nextPutAll:'(Text string:'.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
    string storeOn:aStream.
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   363
    aStream nextPutAll:' runs:'.
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
    runs storeOn:aStream.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    aStream nextPutAll:')'.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
    "Created: 11.5.1996 / 14:27:09 / cg"
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   368
    "Modified: 12.5.1996 / 12:45:16 / cg"
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
! !
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
!Text methodsFor:'private accessing'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
string:aString emphasis:emphasis
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
    string := aString.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
    runs := RunArray new:string size withAll:emphasis
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
     |t|
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
     t := Text new string:'hello' emphasis:#bold.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
     t emphasisAt:2.
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
    "
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
    "Modified: 11.5.1996 / 14:19:38 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
! !
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
!Text methodsFor:'queries'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   389
bitsPerCharacter
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   390
    ^ string bitsPerCharacter
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   392
    "Created: 12.5.1996 / 15:44:04 / cg"
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
hasChangeOfEmphasis
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
    ^ runs notNil
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
    "Created: 11.5.1996 / 14:03:19 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   401
heightOn:aGC
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   402
    "return the number of device units, required on aGC's device"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   403
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   404
    ^ aGC font heightOf:string
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   405
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   406
    "Created: 12.5.1996 / 11:02:03 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   407
!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   408
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
indexOf:aCharacter startingAt:index
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
    ^ string indexOf:aCharacter startingAt:index
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
    "Created: 11.5.1996 / 13:58:56 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   415
isText
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   416
    ^ true
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   417
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   418
    "Created: 12.5.1996 / 10:56:24 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   419
!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   420
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
occurrencesOf:aCharacter
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
    ^ string occurrencesOf:aCharacter
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
    "Created: 11.5.1996 / 13:58:46 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
size
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
    ^ string size
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
    "Created: 11.5.1996 / 14:25:15 / cg"
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
string
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
    ^ string
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
    "Created: 11.5.1996 / 13:58:38 / cg"
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   437
!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   438
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   439
widthOn:aGC
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   440
    "return the number of device units, required on aGC's device"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   441
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   442
    |savedFont savedPaint boldFont italicFont bold italic pos f l|
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   443
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   444
    savedFont := aGC basicFont on:aGC device.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   445
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   446
    pos := 1.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   447
    l := 0.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   448
    runs runsDo:[:len :emphasis |
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   449
        emphasis isSymbol ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   450
            bold := emphasis == #bold.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   451
            italic := emphasis == #italic.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   452
        ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   453
            emphasis isNil ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   454
                bold := italic := false
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   455
            ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   456
                bold := emphasis includesIdentical:#bold.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   457
                italic := emphasis includesIdentical:#italic.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   458
            ]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   459
        ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   460
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   461
        bold ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   462
            boldFont isNil ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   463
                boldFont := savedFont asBold on:aGC device
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   464
            ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   465
            f := boldFont.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   466
        ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   467
            italic ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   468
                italicFont isNil ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   469
                    italicFont := savedFont asItalic on:aGC device
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   470
                ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   471
                f := italicFont
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   472
            ] ifFalse:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   473
                f := savedFont
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   474
            ]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   475
        ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   476
        l := l + (f widthOf:string from:pos to:(pos + len - 1)).
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   477
        pos := pos + len
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   478
    ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   479
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   480
    ^ l
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   481
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   482
    "Modified: 12.5.1996 / 11:21:09 / cg"
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   483
! !
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   484
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   485
!Text methodsFor:'replacing'!
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   486
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   487
replaceFrom:start to:stop with:aCollection startingAt:startIndex
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   488
    |idx|
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   489
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   490
    aCollection isString ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   491
        aCollection hasChangeOfEmphasis ifTrue:[
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   492
            string replaceFrom:start to:stop with:aCollection startingAt:startIndex.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   493
            idx := startIndex.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   494
            start to:stop do:[:col |
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   495
                self emphasisAt:col put:(aCollection emphasisAt:idx).
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   496
                idx := idx + 1.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   497
            ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   498
            ^ self.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   499
        ]
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   500
    ].
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   501
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   502
    string replaceFrom:start to:stop with:aCollection startingAt:startIndex.
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   503
    self emphasizeFrom:start to:stop with:nil
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   504
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   505
    "
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   506
     ((Text string:'hello') allBold emphasisAt:2 put:#italic)
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   507
        copyFrom:1 to:3
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   508
    "
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   509
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   510
    "Modified: 12.5.1996 / 12:44:53 / cg"
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
! !
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
!Text class methodsFor:'documentation'!
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
version
307
8d58cb6e618b fixes & addons
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   516
    ^ '$Header: /cvs/stx/stx/libbasic2/Text.st,v 1.2 1996-05-12 14:01:23 cg Exp $'
304
dee14fa0f2f7 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
! !