author | Claus Gittinger <cg@exept.de> |
Wed, 07 Jul 1999 01:58:49 +0200 | |
changeset 762 | 59768d57ab94 |
parent 761 | d77e2c17f2a1 |
child 777 | ce839c02dfb6 |
permissions | -rw-r--r-- |
304 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
14 |
CharacterArray subclass:#Text |
|
15 |
instanceVariableNames:'string runs' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Text' |
|
19 |
! |
|
20 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
21 |
!Text class methodsFor:'documentation'! |
304 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
Texts add emphasis information to a string. |
|
343 | 41 |
Texts and strings should behave interchanchably to the outside |
42 |
world, except that texts keep per-character emphasis information. |
|
43 |
(strings return nil, when asked for an elements emphasis). |
|
44 |
Use #string, to get a texts underlying string without any emphasis |
|
45 |
information. |
|
304 | 46 |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
47 |
Currently, the following attributes are supported: |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
48 |
#bold |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
49 |
#italic |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
50 |
#underline |
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
51 |
#underwave |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
52 |
#strikeout |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
53 |
(#color -> aColor) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
54 |
(#backgroundColor -> aColor) |
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
55 |
(#underlineColor -> aColor) |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
56 |
(#strikeoutColor -> aColor) |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
57 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
58 |
Attributes may be combined (pass an array of above) as emphasis. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
59 |
See examples. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
60 |
|
304 | 61 |
This class is not yet fully implemented - being constructed. |
62 |
||
63 |
[author:] |
|
64 |
Claus Gittinger |
|
65 |
||
66 |
[see also:] |
|
67 |
CharacterArray String RunArray |
|
68 |
" |
|
313 | 69 |
! |
70 |
||
71 |
examples |
|
72 |
" |
|
343 | 73 |
plain string (for comparison): |
313 | 74 |
[exBegin] |
75 |
Dialog |
|
76 |
warn:'hello' |
|
77 |
[exEnd] |
|
343 | 78 |
|
79 |
||
80 |
emphasized strings as dialog titles: |
|
313 | 81 |
[exBegin] |
82 |
Dialog |
|
83 |
warn:((Text string:'hello') allBold) |
|
84 |
[exEnd] |
|
85 |
[exBegin] |
|
86 |
Dialog |
|
87 |
warn:(Text string:'hello' emphasis:#italic) |
|
88 |
[exEnd] |
|
89 |
[exBegin] |
|
90 |
Dialog |
|
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
91 |
warn:(Text string:'hello' emphasis:#(underline)) |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
92 |
[exEnd] |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
93 |
[exBegin] |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
94 |
Dialog |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
95 |
warn:(Text string:'hello' emphasis:#(underwave)) |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
96 |
[exEnd] |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
97 |
[exBegin] |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
98 |
Dialog |
313 | 99 |
warn:(Text string:'hello' emphasis:#(bold underline)) |
100 |
[exEnd] |
|
101 |
[exBegin] |
|
102 |
Dialog |
|
103 |
warn:(Text string:'hello' |
|
104 |
emphasis:(Array with:#bold |
|
105 |
with:#strikeout |
|
106 |
with:(#color->Color red))) |
|
107 |
[exEnd] |
|
108 |
[exBegin] |
|
109 |
Dialog |
|
315 | 110 |
warn:(Text string:'hello' |
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
111 |
emphasis:(Array with:(#color->Color black) |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
112 |
with:#underwave |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
113 |
with:(#underlineColor->Color red))) |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
114 |
[exEnd] |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
115 |
[exBegin] |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
116 |
Dialog |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
117 |
warn:(Text string:'hello' |
315 | 118 |
emphasis:(Array with:#bold |
119 |
with:#strikeout |
|
120 |
with:(#color->Color red) |
|
121 |
with:(#backgroundColor->Color yellow))) |
|
122 |
[exEnd] |
|
123 |
[exBegin] |
|
124 |
Dialog |
|
313 | 125 |
warn:(Text string:'hello' color:(Color red)) |
126 |
[exEnd] |
|
127 |
||
343 | 128 |
|
129 |
in an editTextView: |
|
130 |
[exBegin] |
|
131 |
|t v| |
|
132 |
||
133 |
t := 'The quick brown fox jumps over the lazy dog' asText. |
|
134 |
t emphasizeFrom:(t findString:'quick') count:5 with:#bold. |
|
135 |
t emphasizeFrom:(t findString:'brown') count:9 |
|
136 |
with:(Array with:#color->(Color name:'brown') |
|
137 |
with:#bold). |
|
138 |
t emphasizeFrom:(t findString:'lazy') count:4 |
|
139 |
with:(Array with:#color->(Color red) |
|
140 |
with:#italic). |
|
141 |
t emphasizeFrom:(t findString:'dog') count:3 with:#underline. |
|
142 |
||
143 |
v := HVScrollableView for:EditTextView. |
|
144 |
v contents:t. |
|
145 |
||
146 |
v width:450. |
|
147 |
v open. |
|
148 |
[exEnd] |
|
313 | 149 |
" |
304 | 150 |
! ! |
151 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
152 |
!Text class methodsFor:'initialization'! |
314 | 153 |
|
154 |
initialize |
|
155 |
"initialize the class" |
|
156 |
||
157 |
" |
|
158 |
consider this a kludge: |
|
159 |
I want to inherit behavior from CharacterArray, but not |
|
160 |
its implementation (indexed access). |
|
161 |
" |
|
162 |
||
163 |
self flags:(Behavior flagRegular) |
|
164 |
||
165 |
" |
|
166 |
Text initialize |
|
167 |
" |
|
168 |
||
169 |
"Modified: 12.5.1996 / 17:53:50 / cg" |
|
170 |
! ! |
|
171 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
172 |
!Text class methodsFor:'instance creation'! |
304 | 173 |
|
174 |
fromString:aString |
|
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
175 |
"create a Text instance, for the characters in aString, |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
176 |
without emphasis." |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
177 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
178 |
^ super new string:aString emphasis:nil |
304 | 179 |
|
180 |
" |
|
181 |
Text fromString:'hello' |
|
182 |
" |
|
183 |
||
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
184 |
"Modified: 12.5.1996 / 17:05:34 / cg" |
304 | 185 |
! |
186 |
||
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
187 |
new |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
188 |
"create a new empty Text instance. |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
189 |
Redefined for string-protocol compatibility" |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
190 |
|
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
191 |
^ super new string:(String new) emphasis:nil |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
192 |
|
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
193 |
"Text new" |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
194 |
|
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
195 |
"Modified: 12.5.1996 / 17:05:17 / cg" |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
196 |
"Modified: 31.12.1996 / 12:39:57 / stefan" |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
197 |
! |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
198 |
|
307 | 199 |
new:size |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
200 |
"create a new empty Text instance. |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
201 |
Redefined for string-protocol compatibility" |
307 | 202 |
|
203 |
^ self string:(String new:size) |
|
204 |
||
205 |
"Created: 12.5.1996 / 11:57:27 / cg" |
|
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
206 |
"Modified: 12.5.1996 / 17:05:17 / cg" |
307 | 207 |
! |
208 |
||
304 | 209 |
string:aString |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
210 |
"create a Text instance, for the characters in aString, |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
211 |
without emphasis." |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
212 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
213 |
^ super new string:aString emphasis:nil |
304 | 214 |
|
215 |
" |
|
216 |
Text string:'hello' |
|
217 |
" |
|
218 |
||
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
219 |
"Modified: 12.5.1996 / 17:05:00 / cg" |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
220 |
! |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
221 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
222 |
string:aString color:aColor |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
223 |
"create a Text instance, for the characters in aString, |
345
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
224 |
which are colored as aColor (only the foregroundColor is affected). |
496 | 225 |
This is a shortCut for creating an emphasis of (#color->aColor)" |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
226 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
227 |
^ super new string:aString emphasis:(#color->aColor) |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
228 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
229 |
" |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
230 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
231 |
information:(Text string:'hello' color:(Color red)) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
232 |
" |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
233 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
234 |
"Created: 12.5.1996 / 17:03:20 / cg" |
496 | 235 |
"Modified: 27.2.1997 / 10:13:36 / cg" |
344
72fe9b7ae4b5
added #string:color:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
343
diff
changeset
|
236 |
! |
72fe9b7ae4b5
added #string:color:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
343
diff
changeset
|
237 |
|
304 | 238 |
string:aString emphasis:attribute |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
239 |
"create a Text instance, for the characters in aString, |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
240 |
which are emphasized as described by attribute." |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
241 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
242 |
^ super new string:aString emphasis:attribute |
304 | 243 |
|
244 |
" |
|
245 |
Text string:'hello' emphasis:#bold |
|
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
246 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
247 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
248 |
information:(Text string:'hello' emphasis:#bold) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
249 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
250 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
251 |
information:(Text string:'hello' emphasis:#italic) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
252 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
253 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
254 |
information:(Text string:'hello' emphasis:#underline) |
310 | 255 |
|
256 |
Dialog |
|
257 |
information:(Text string:'hello' emphasis:#strikeout) |
|
304 | 258 |
" |
259 |
||
310 | 260 |
"Modified: 12.5.1996 / 17:16:03 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
261 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
262 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
263 |
string:aString emphasisCollection:attributeCollection |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
264 |
"create a Text instance, for the characters in aString, |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
265 |
which are individually emphasized as described by attributeCollection." |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
266 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
267 |
^ super new string:aString emphasisCollection:attributeCollection |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
268 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
269 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
270 |
Text |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
271 |
string:'hello' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
272 |
emphasisCollection:#(#bold #bold #italic #italic #italic) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
273 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
274 |
Dialog |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
275 |
information:(Text |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
276 |
string:'hello' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
277 |
emphasisCollection:#(#bold #bold #italic #italic #(#underline italic))) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
278 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
279 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
280 |
"Created: 14.5.1996 / 14:02:18 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
281 |
"Modified: 14.5.1996 / 15:01:28 / cg" |
345
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
282 |
! |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
283 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
284 |
string:aString foregroundColor:fgColor backgroundColor:bgColor |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
285 |
"create a Text instance, for the characters in aString, |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
286 |
which are colored in fgColor on bgColor. |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
287 |
This is a shortCut for creating an emphasis of |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
288 |
#( #color->fgColor) (#backgroundColor->bgColor)" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
289 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
290 |
^ super new |
345
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
291 |
string:aString |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
292 |
emphasis:(Array with:#color->fgColor |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
293 |
with:#backgroundColor->bgColor) |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
294 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
295 |
" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
296 |
Dialog |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
297 |
information:(Text string:'hello' |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
298 |
foregroundColor:(Color red) |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
299 |
backgroundColor:(Color yellow)) |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
300 |
" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
301 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
302 |
"Modified: 11.5.1996 / 14:21:01 / cg" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
303 |
"Created: 16.5.1996 / 12:37:24 / cg" |
395 | 304 |
! |
305 |
||
306 |
string:aString runs:aRun |
|
307 |
"create a Text instance, for the characters in aString, |
|
308 |
which are individually emphasized as described by attributeCollection." |
|
309 |
||
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
310 |
^ super new string:aString emphasisCollection:aRun. |
304 | 311 |
! ! |
312 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
313 |
!Text class methodsFor:'emphasis helper'! |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
314 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
315 |
addEmphasis:e1 to:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
316 |
"merge two emphasis's into one" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
317 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
318 |
|ne| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
319 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
320 |
e1 isNil ifTrue:[^ e2]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
321 |
e2 isNil ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
322 |
e1 == e2 ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
323 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
324 |
(e1 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
325 |
or:[e1 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
326 |
(e2 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
327 |
or:[e2 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
328 |
^ Array with:e1 with:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
329 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
330 |
(e2 includes:e1) ifTrue:[^ e2]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
331 |
^ e2 copyWith:e1 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
332 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
333 |
(e2 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
334 |
or:[e2 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
335 |
(e1 includes:e2) ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
336 |
^ e1 copyWith:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
337 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
338 |
"/ ould use: |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
339 |
"/ ^ (e1 asSet addAll:e2; asArray) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
340 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
341 |
"/ but we do it manually, to preserve the |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
342 |
"/ order. (should create longer runs, while editing) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
343 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
344 |
ne := e1. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
345 |
e2 do:[:e | |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
346 |
(ne includes:e) ifFalse:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
347 |
ne := ne copyWith:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
348 |
] |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
349 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
350 |
^ ne. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
351 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
352 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
353 |
Text addEmphasis:#bold to:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
354 |
Text addEmphasis:#bold to:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
355 |
Text addEmphasis:#bold to:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
356 |
Text addEmphasis:#italic to:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
357 |
Text addEmphasis:#(italic strikeout) to:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
358 |
Text addEmphasis:#(italic strikeout) to:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
359 |
Text addEmphasis:#(italic strikeout) to:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
360 |
Text addEmphasis:(#color->Color red) to:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
361 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
362 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
363 |
"Modified: 14.5.1996 / 17:15:44 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
364 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
365 |
|
339 | 366 |
emphasis:e1 includes:e2 |
367 |
"return true, if e1 includes e2. |
|
368 |
e2 should be a single emphasis." |
|
369 |
||
370 |
e1 isNil ifTrue:[^ false]. |
|
371 |
e2 isNil ifTrue:[^ false]. |
|
372 |
e1 == e2 ifTrue:[^ true]. |
|
373 |
||
754 | 374 |
e1 isSymbol ifTrue:[ |
375 |
^ false |
|
376 |
]. |
|
377 |
e1 isAssociation ifTrue:[ |
|
378 |
^ e1 key == e2 |
|
379 |
]. |
|
339 | 380 |
(e1 isSymbol |
381 |
or:[e1 isAssociation]) ifTrue:[ |
|
382 |
^ false |
|
383 |
]. |
|
384 |
(e2 isSymbol |
|
385 |
or:[e2 isAssociation]) ifTrue:[ |
|
386 |
^ (e1 includes:e2) |
|
387 |
]. |
|
388 |
^ false |
|
389 |
||
390 |
" |
|
391 |
Text emphasis:#bold includes:#bold |
|
392 |
Text emphasis:#bold includes:#ialic |
|
393 |
Text emphasis:#(italic strikeout) includes:#bold |
|
394 |
Text emphasis:#(italic strikeout) includes:#italic |
|
754 | 395 |
Text emphasis:(#color->Color red) includes:#color |
339 | 396 |
" |
397 |
||
398 |
"Modified: 14.5.1996 / 17:45:11 / cg" |
|
399 |
! |
|
400 |
||
407 | 401 |
extractEmphasis:key from:e |
402 |
"if key is included in the emphasis, e then return the key. |
|
403 |
Otherwise, if a n association with that key is included, return the value. |
|
404 |
Otherwise, return nil." |
|
405 |
||
406 |
e isNil ifTrue:[^ nil]. |
|
407 |
key == e ifTrue:[^ e]. |
|
754 | 408 |
e isSymbol ifTrue:[^ nil]. |
407 | 409 |
|
410 |
e isAssociation ifTrue:[ |
|
411 |
e key == key ifTrue:[^ e value]. |
|
412 |
^ nil |
|
413 |
]. |
|
414 |
e do:[:entry | |
|
754 | 415 |
entry == key ifTrue:[^ key]. |
407 | 416 |
entry isAssociation ifTrue:[ |
417 |
entry key == key ifTrue:[ |
|
418 |
^ entry value |
|
419 |
] |
|
420 |
] |
|
421 |
]. |
|
422 |
^ nil |
|
423 |
||
424 |
" |
|
425 |
Text extractEmphasis:#bold from:#bold |
|
426 |
Text extractEmphasis:#bold from:#italic |
|
427 |
Text extractEmphasis:#bold from:#(italic strikeout) |
|
428 |
Text extractEmphasis:#bold from:#(italic bold) |
|
429 |
Text extractEmphasis:#color from:(#color->Color red) |
|
430 |
Text extractEmphasis:#color from:(#foo->Color red) |
|
431 |
" |
|
432 |
||
433 |
"Modified: 14.5.1996 / 17:45:11 / cg" |
|
434 |
"Created: 11.7.1996 / 09:49:58 / cg" |
|
435 |
! |
|
436 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
437 |
removeEmphasis:e1 from:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
438 |
"remove an emphasis; if it was not in e1, do nothing" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
439 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
440 |
|ne| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
441 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
442 |
e1 isNil ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
443 |
e2 isNil ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
444 |
e1 == e2 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
445 |
|
755 | 446 |
e2 isSymbol ifTrue:[ |
447 |
e1 isSymbol ifTrue:[^ nil]. |
|
448 |
e1 isAssociation ifTrue:[ |
|
449 |
e1 key == e2 ifTrue:[^ nil]. |
|
450 |
^ e2 |
|
451 |
]. |
|
452 |
(e1 includes:e2) ifTrue:[^ nil]. |
|
453 |
^ e2 |
|
454 |
]. |
|
455 |
e2 isAssociation ifTrue:[ |
|
456 |
e1 isSymbol ifTrue:[ |
|
457 |
e2 key == e2 ifTrue:[^ nil]. |
|
458 |
^ e2 |
|
459 |
]. |
|
460 |
e1 isAssociation ifTrue:[ |
|
461 |
e1 key == e2 key ifTrue:[^ nil]. |
|
462 |
^ e2 |
|
463 |
]. |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
464 |
(e1 includes:e2) ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
465 |
^ e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
466 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
467 |
(e1 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
468 |
or:[e1 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
469 |
(e2 includes:e1) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
470 |
ne := e2 copyWithout:e1. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
471 |
ne size == 1 ifTrue:[^ ne at:1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
472 |
ne size == 0 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
473 |
^ ne |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
474 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
475 |
^ e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
476 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
477 |
|
754 | 478 |
"/ could use: |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
479 |
"/ ^ (e2 asSet removeAll:e1; asArray) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
480 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
481 |
"/ but we do it manually, to preserve the |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
482 |
"/ order. (should create longer runs, while editing) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
483 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
484 |
ne := e2. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
485 |
e1 do:[:e | |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
486 |
(ne includes:e) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
487 |
ne := ne copyWithout:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
488 |
] |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
489 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
490 |
ne size == 1 ifTrue:[^ ne at:1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
491 |
ne size == 0 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
492 |
^ ne. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
493 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
494 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
495 |
Text removeEmphasis:#bold from:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
496 |
Text removeEmphasis:#bold from:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
497 |
Text removeEmphasis:#bold from:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
498 |
Text removeEmphasis:#italic from:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
499 |
Text removeEmphasis:#(italic strikeout) from:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
500 |
Text removeEmphasis:#(italic strikeout) from:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
501 |
Text removeEmphasis:#(italic strikeout) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
502 |
Text removeEmphasis:#(italic strikeout bold) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
503 |
Text removeEmphasis:#(italic strikeout bold underline) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
504 |
Text removeEmphasis:(#color->Color red) from:#(bold underline) |
756 | 505 |
Text removeEmphasis:(#color->Color red) from:(#color->Color red) |
754 | 506 |
Text removeEmphasis:#color from:(Array with:#bold with:#underline with:#color->Color red) |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
507 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
508 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
509 |
"Modified: 14.5.1996 / 17:23:46 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
510 |
! ! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
511 |
|
735 | 512 |
!Text methodsFor:'accessing'! |
513 |
||
514 |
at:characterIndex |
|
515 |
"return the plain character at characterIndex" |
|
516 |
||
517 |
^ string at:characterIndex |
|
518 |
||
519 |
"Created: 11.5.1996 / 14:25:41 / cg" |
|
520 |
"Modified: 16.5.1996 / 11:15:33 / cg" |
|
521 |
! |
|
522 |
||
523 |
at:characterIndex put:aCharacter |
|
524 |
"change the character at characterIndex to be aCharacter. |
|
525 |
The emphasis (if any) of that character remains unchanged." |
|
526 |
||
527 |
^ string at:characterIndex put:aCharacter |
|
528 |
||
529 |
"Created: 11.5.1996 / 14:25:49 / cg" |
|
530 |
"Modified: 16.5.1996 / 11:15:57 / cg" |
|
531 |
! ! |
|
532 |
||
304 | 533 |
!Text methodsFor:'comparing'! |
534 |
||
535 |
= aStringOrText |
|
536 |
"compare the receiver and the argument, ignoring emphasis" |
|
537 |
||
384 | 538 |
aStringOrText isString ifFalse:[^ false]. |
304 | 539 |
^ string = aStringOrText string |
540 |
||
541 |
||
542 |
" |
|
543 |
'hello' asText = 'hello' |
|
544 |
'hello' asText = 'hello' asText |
|
545 |
'hello' asText allBold = 'hello' |
|
546 |
" |
|
547 |
||
384 | 548 |
"Modified: 4.6.1996 / 11:14:58 / cg" |
662 | 549 |
! |
550 |
||
551 |
hash |
|
552 |
"return a suitable hashcode (req'd since = is redefined)" |
|
553 |
||
554 |
^ string hash |
|
555 |
||
556 |
"Created: / 19.6.1998 / 04:15:57 / cg" |
|
304 | 557 |
! ! |
558 |
||
559 |
!Text methodsFor:'converting'! |
|
560 |
||
561 |
asText |
|
343 | 562 |
"return the receiver itself - it is already a text object" |
563 |
||
304 | 564 |
^ self |
565 |
||
566 |
"Created: 11.5.1996 / 14:08:36 / cg" |
|
343 | 567 |
"Modified: 16.5.1996 / 11:15:12 / cg" |
304 | 568 |
! ! |
569 |
||
570 |
!Text methodsFor:'copying'! |
|
571 |
||
572 |
, aStringOrText |
|
343 | 573 |
"concatenate the receivers characters with the arguments characters, |
574 |
and return string or text object containing those characters. |
|
575 |
If either the receiver or the argument contains emphasis information, |
|
576 |
a text object will be returned. Otherwise, a string (i.e. without emphasis) |
|
577 |
is returned." |
|
304 | 578 |
|
626 | 579 |
|newRuns| |
580 |
||
758 | 581 |
aStringOrText isCharacter ifTrue:[ |
582 |
^ self , aStringOrText asString |
|
583 |
]. |
|
615 | 584 |
aStringOrText hasChangeOfEmphasis ifTrue:[ |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
585 |
^ self species new |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
586 |
string:(string , aStringOrText) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
587 |
emphasisCollection:(runs , aStringOrText emphasisCollection) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
588 |
]. |
615 | 589 |
runs notNil "self hasChangeOfEmphasis" ifTrue:[ |
626 | 590 |
newRuns := runs copyFrom:1 to:(runs size). |
591 |
||
408 | 592 |
^ self species new |
593 |
string:(string , aStringOrText) |
|
626 | 594 |
emphasisCollection:(newRuns add:nil withOccurrences:(aStringOrText size); yourself) |
408 | 595 |
]. |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
596 |
^ string , aStringOrText string |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
597 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
598 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
599 |
('hello' asText allBold) , ' world' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
600 |
'hello' , (' world' asText allBold) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
601 |
'hello' , ' world' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
602 |
('hello' asText allBold) , (' world' asText allBold) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
603 |
" |
304 | 604 |
|
626 | 605 |
"Modified: / 31.3.1998 / 16:34:04 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
606 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
607 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
608 |
concatenateFromString:aString |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
609 |
"return the concatenation of aString and myself. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
610 |
This may be a Text (if I have emphasis) or a string (if not)." |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
611 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
612 |
self hasChangeOfEmphasis ifTrue:[ |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
613 |
^ self species new |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
614 |
string:(aString , string) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
615 |
emphasisCollection:((RunArray new:(aString size)) , runs). |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
616 |
]. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
617 |
^ aString , string |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
618 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
619 |
"Modified: 14.5.1996 / 15:56:05 / cg" |
394 | 620 |
! |
621 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
622 |
copyFrom:start to:stop |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
623 |
"return the subcollection starting at index start, anInteger and ending |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
624 |
at stop, anInteger." |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
625 |
|
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
626 |
self hasChangeOfEmphasis ifTrue:[ |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
627 |
^ self species new |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
628 |
string:(string copyFrom:start to:stop) |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
629 |
emphasisCollection:(runs copyFrom:start to:stop). |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
630 |
]. |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
631 |
^ string copyFrom:start to:stop |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
632 |
|
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
633 |
"Modified: 14.5.1996 / 15:56:05 / cg" |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
634 |
"Created: 22.10.1996 / 21:01:16 / cg" |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
635 |
! |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
636 |
|
394 | 637 |
postCopy |
638 |
string := string copy. |
|
639 |
runs := runs copy |
|
307 | 640 |
! ! |
641 |
||
642 |
!Text methodsFor:'displaying'! |
|
643 |
||
644 |
displayOn:aGC x:x0 y:y opaque:opaque |
|
645 |
"display the receiver on a GC" |
|
646 |
||
393 | 647 |
|savedFont savedPaint savedBgPaint font color boldFont italicFont boldItalicFont |
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
648 |
bgPaint ulPaint strikePaint |
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
649 |
bold italic underline underwave strikeout reverse |
310 | 650 |
pos "{ Class: SmallInteger }" |
651 |
endPos "{ Class: SmallInteger }" |
|
410
3d42216e96b0
oops - x can be float in displayOn... in case of scaling in the GC
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
652 |
x |
310 | 653 |
l "{ Class: SmallInteger }" |
360 | 654 |
yL k value device| |
307 | 655 |
|
656 |
savedFont := aGC basicFont. |
|
657 |
savedPaint := aGC paint. |
|
315 | 658 |
savedBgPaint := aGC backgroundPaint. |
307 | 659 |
|
705 | 660 |
device := aGC graphicsDevice. |
661 |
||
307 | 662 |
pos := 1. |
663 |
x := x0. |
|
664 |
runs runsDo:[:len :emphasis | |
|
705 | 665 |
color := savedPaint. |
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
666 |
bold := italic := underline := underwave := strikeout := reverse := false. |
315 | 667 |
bgPaint := savedBgPaint. |
307 | 668 |
|
669 |
emphasis isSymbol ifTrue:[ |
|
670 |
emphasis == #bold ifTrue:[bold := true] |
|
671 |
ifFalse:[emphasis == #italic ifTrue:[italic := true] |
|
672 |
ifFalse:[emphasis == #underline ifTrue:[underline := true] |
|
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
673 |
ifFalse:[emphasis == #underwave ifTrue:[underwave := true] |
307 | 674 |
ifFalse:[emphasis == #strikeout ifTrue:[strikeout := true] |
664 | 675 |
ifFalse:[emphasis == #reverse ifTrue:[reverse := true] |
666
1c1d4014849b
added #boldUnderline & #italicUnderline emphasis-styles.
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
676 |
ifFalse:[emphasis == #boldUnderline ifTrue:[bold := underline := true] |
760
55659309577a
+boldUnderwave +italicUnderwave
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
677 |
ifFalse:[emphasis == #boldUnderwave ifTrue:[bold := underwave := true] |
666
1c1d4014849b
added #boldUnderline & #italicUnderline emphasis-styles.
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
678 |
ifFalse:[emphasis == #italicUnderline ifTrue:[italic := underline := true] |
760
55659309577a
+boldUnderwave +italicUnderwave
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
679 |
ifFalse:[emphasis == #italicUnderwave ifTrue:[italic := underwave := true] |
55659309577a
+boldUnderwave +italicUnderwave
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
680 |
]]]]]]]]] |
307 | 681 |
] ifFalse:[ |
682 |
(emphasis isMemberOf:Association) ifTrue:[ |
|
315 | 683 |
value := emphasis value. |
756 | 684 |
value notNil ifTrue:[ |
685 |
k := emphasis key. |
|
686 |
k == #color ifTrue:[ |
|
687 |
color := value onDevice:device. |
|
688 |
emphasis value:color. |
|
689 |
] ifFalse:[k == #backgroundColor ifTrue:[ |
|
690 |
bgPaint := value onDevice:device. |
|
691 |
emphasis value:bgPaint. |
|
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
692 |
] ifFalse:[k == #underlineColor ifTrue:[ |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
693 |
ulPaint := value onDevice:device. |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
694 |
emphasis value:ulPaint. |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
695 |
] ifFalse:[k == #strikeoutColor ifTrue:[ |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
696 |
strikePaint := value onDevice:device. |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
697 |
emphasis value:ulPaint. |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
698 |
]]]] |
756 | 699 |
] |
307 | 700 |
] ifFalse:[ |
701 |
emphasis notNil ifTrue:[ |
|
702 |
emphasis do:[:entry | |
|
703 |
entry == #bold ifTrue:[bold := true] |
|
704 |
ifFalse:[entry == #italic ifTrue:[italic := true] |
|
705 |
ifFalse:[entry == #underline ifTrue:[underline := true] |
|
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
706 |
ifFalse:[entry == #underwave ifTrue:[underwave := true] |
307 | 707 |
ifFalse:[entry == #strikeout ifTrue:[strikeout := true] |
664 | 708 |
ifFalse:[entry == #reverse ifTrue:[reverse := true] |
666
1c1d4014849b
added #boldUnderline & #italicUnderline emphasis-styles.
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
709 |
ifFalse:[entry == #boldUnderline ifTrue:[bold := underline := true] |
760
55659309577a
+boldUnderwave +italicUnderwave
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
710 |
ifFalse:[emphasis == #boldUnderwave ifTrue:[bold := underwave := true] |
666
1c1d4014849b
added #boldUnderline & #italicUnderline emphasis-styles.
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
711 |
ifFalse:[entry == #italicUnderline ifTrue:[italic := underline := true] |
760
55659309577a
+boldUnderwave +italicUnderwave
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
712 |
ifFalse:[emphasis == #italicUnderwave ifTrue:[italic := underwave := true] |
307 | 713 |
ifFalse:[ |
714 |
(entry isMemberOf:Association) ifTrue:[ |
|
315 | 715 |
value := entry value. |
762
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
716 |
value notNil ifTrue:[ |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
717 |
k := entry key. |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
718 |
k == #color ifTrue:[ |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
719 |
color := value onDevice:device. |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
720 |
entry value:color. |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
721 |
] ifFalse:[k == #backgroundColor ifTrue:[ |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
722 |
bgPaint := value onDevice:device. |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
723 |
entry value:bgPaint. |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
724 |
] ifFalse:[k == #underlineColor ifTrue:[ |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
725 |
ulPaint := value onDevice:device. |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
726 |
entry value:ulPaint. |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
727 |
] ifFalse:[k == #strikeoutColor ifTrue:[ |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
728 |
strikePaint := value onDevice:device. |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
729 |
entry value:ulPaint. |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
730 |
]]]] |
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
731 |
] |
307 | 732 |
] |
760
55659309577a
+boldUnderwave +italicUnderwave
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
733 |
]]]]]]]]]] |
307 | 734 |
] |
735 |
] |
|
736 |
] |
|
737 |
]. |
|
738 |
||
739 |
bold ifTrue:[ |
|
393 | 740 |
italic ifTrue:[ |
741 |
boldItalicFont isNil ifTrue:[ |
|
705 | 742 |
boldItalicFont := savedFont asBold asItalic onDevice:device |
393 | 743 |
]. |
744 |
font := boldItalicFont. |
|
745 |
] ifFalse:[ |
|
746 |
boldFont isNil ifTrue:[ |
|
705 | 747 |
boldFont := savedFont asBold onDevice:device |
393 | 748 |
]. |
749 |
font := boldFont. |
|
750 |
] |
|
307 | 751 |
] ifFalse:[ |
752 |
italic ifTrue:[ |
|
753 |
italicFont isNil ifTrue:[ |
|
705 | 754 |
italicFont := savedFont asItalic onDevice:device |
307 | 755 |
]. |
756 |
font := italicFont. |
|
757 |
] ifFalse:[ |
|
758 |
font := savedFont |
|
759 |
] |
|
760 |
]. |
|
761 |
aGC basicFont:font. |
|
664 | 762 |
reverse ifTrue:[ |
763 |
aGC paint:bgPaint on:color |
|
764 |
] ifFalse:[ |
|
765 |
aGC paint:color on:bgPaint. |
|
766 |
]. |
|
310 | 767 |
endPos := pos + len - 1. |
307 | 768 |
opaque ifTrue:[ |
310 | 769 |
aGC displayOpaqueString:string from:pos to:endPos x:x y:y. |
307 | 770 |
] ifFalse:[ |
310 | 771 |
aGC displayString:string from:pos to:endPos x:x y:y. |
307 | 772 |
]. |
705 | 773 |
l := font widthOf:string from:pos to:endPos. |
307 | 774 |
|
775 |
underline ifTrue:[ |
|
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
776 |
ulPaint notNil ifTrue:[aGC paint:ulPaint]. |
310 | 777 |
yL := y+1. |
778 |
aGC displayLineFromX:x y:yL toX:x+l-1 y:yL |
|
779 |
]. |
|
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
780 |
underwave ifTrue:[ |
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
781 |
ulPaint notNil ifTrue:[aGC paint:ulPaint]. |
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
782 |
yL := y+1. |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
783 |
aGC displayHorizontalWavelineFromX:x y:yL toX:x+l-1 |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
784 |
]. |
310 | 785 |
strikeout ifTrue:[ |
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
786 |
strikePaint notNil ifTrue:[aGC paint:strikePaint]. |
310 | 787 |
yL := y-(font ascent//2). |
788 |
aGC displayLineFromX:x y:yL toX:x+l-1 y:yL |
|
307 | 789 |
]. |
790 |
||
791 |
x := x + l. |
|
310 | 792 |
pos := endPos + 1 |
304 | 793 |
]. |
307 | 794 |
|
795 |
aGC basicFont:savedFont. |
|
316 | 796 |
aGC paint:savedPaint on:savedBgPaint. |
307 | 797 |
|
591
dfa5c6178f6d
care to use deviceFont in width-query
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
798 |
"Created: / 12.5.1996 / 11:14:30 / cg" |
761 | 799 |
"Modified: / 7.7.1999 / 00:08:12 / cg" |
304 | 800 |
! ! |
801 |
||
802 |
!Text methodsFor:'emphasis'! |
|
803 |
||
804 |
allBold |
|
805 |
"make all characters bold" |
|
806 |
||
406 | 807 |
self emphasizeAllWith:#bold |
304 | 808 |
|
809 |
" |
|
810 |
(Text string:'hello') allBold |
|
811 |
" |
|
812 |
||
406 | 813 |
"Modified: 10.7.1996 / 12:07:51 / cg" |
304 | 814 |
! |
815 |
||
734 | 816 |
allItalic |
817 |
"make all characters italic" |
|
818 |
||
819 |
self emphasizeAllWith:#italic |
|
820 |
||
821 |
" |
|
822 |
(Text string:'hello') allItalic |
|
823 |
" |
|
824 |
||
825 |
"Modified: 10.7.1996 / 12:07:51 / cg" |
|
826 |
! |
|
827 |
||
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
828 |
emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
829 |
"return the emphasis" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
830 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
831 |
^ runs |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
832 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
833 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
834 |
(Text string:'hello') allBold emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
835 |
'hello' emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
836 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
837 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
838 |
"Modified: 11.5.1996 / 14:22:31 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
839 |
"Created: 14.5.1996 / 13:59:03 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
840 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
841 |
|
304 | 842 |
emphasisAt:characterIndex |
843 |
"return the emphasis at some index" |
|
844 |
||
845 |
^ runs at:characterIndex |
|
846 |
||
847 |
" |
|
848 |
(Text string:'hello') allBold emphasisAt:2 |
|
849 |
" |
|
850 |
||
851 |
"Modified: 11.5.1996 / 14:22:31 / cg" |
|
852 |
! |
|
853 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
854 |
emphasisAt:characterIndex add:newEmphasis |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
855 |
"add to the emphasis at some index. return the receiver" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
856 |
|
626 | 857 |
|e prevE| |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
858 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
859 |
e := runs at:characterIndex. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
860 |
e := self class addEmphasis:newEmphasis to:e. |
626 | 861 |
|
862 |
"/ if its equal to the previous emphasis, make it identical. |
|
863 |
||
864 |
characterIndex > 1 ifTrue:[ |
|
865 |
prevE := runs at:characterIndex-1. |
|
866 |
e = prevE ifTrue:[ |
|
867 |
e := prevE |
|
868 |
] |
|
869 |
]. |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
870 |
runs at:characterIndex put:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
871 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
872 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
873 |
(Text string:'hello') allBold emphasisAt:2 add:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
874 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
875 |
|
626 | 876 |
"Created: / 14.5.1996 / 16:48:39 / cg" |
877 |
"Modified: / 31.3.1998 / 15:29:14 / cg" |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
878 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
879 |
|
307 | 880 |
emphasisAt:characterIndex put:emphasis |
881 |
"change the emphasis at some index. return the receiver" |
|
882 |
||
626 | 883 |
|e prevE| |
884 |
||
885 |
e := emphasis. |
|
886 |
||
887 |
"/ if its equal to the previous emphasis, make it identical. |
|
888 |
||
889 |
characterIndex > 1 ifTrue:[ |
|
890 |
prevE := runs at:characterIndex-1. |
|
891 |
emphasis = prevE ifTrue:[ |
|
892 |
e := prevE |
|
893 |
] |
|
894 |
]. |
|
895 |
runs at:characterIndex put:e |
|
307 | 896 |
|
897 |
" |
|
898 |
(Text string:'hello') allBold emphasisAt:2 put:#italic |
|
899 |
" |
|
900 |
||
626 | 901 |
"Modified: / 31.3.1998 / 16:45:14 / cg" |
307 | 902 |
! |
903 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
904 |
emphasisAt:characterIndex remove:emphasisToRemove |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
905 |
"remove from the emphasis at some index. return the receiver" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
906 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
907 |
|e| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
908 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
909 |
e := runs at:characterIndex. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
910 |
e := self class removeEmphasis:emphasisToRemove from:e. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
911 |
runs at:characterIndex put:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
912 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
913 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
914 |
(Text string:'hello') |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
915 |
allBold emphasisAt:2 remove:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
916 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
917 |
(Text string:'hello' emphasis:#(bold italic)) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
918 |
emphasisAt:2 remove:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
919 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
920 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
921 |
"Created: 14.5.1996 / 16:48:39 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
922 |
"Modified: 14.5.1996 / 17:25:04 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
923 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
924 |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
925 |
emphasisCollection |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
926 |
"return the emphasis" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
927 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
928 |
^ runs |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
929 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
930 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
931 |
(Text string:'hello') allBold emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
932 |
'hello' emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
933 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
934 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
935 |
"Created: 14.5.1996 / 13:59:03 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
936 |
"Modified: 14.5.1996 / 15:02:11 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
937 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
938 |
|
304 | 939 |
emphasizeAllWith:emphasis |
940 |
"change the emphasis of all characters" |
|
941 |
||
942 |
runs := RunArray new:(string size) withAll:emphasis |
|
943 |
||
944 |
" |
|
945 |
(Text string:'hello') allBold emphasizeAllWith:#italic |
|
946 |
" |
|
947 |
||
948 |
"Modified: 11.5.1996 / 14:22:52 / cg" |
|
949 |
! |
|
950 |
||
343 | 951 |
emphasizeFrom:start count:count with:emphasis |
952 |
"change the emphasis of a range of characters, given startIndex and count." |
|
953 |
||
954 |
self emphasizeFrom:start to:(start+count-1) with:emphasis |
|
955 |
||
956 |
" |
|
957 |
(Text string:'hello world') |
|
958 |
emphasizeFrom:1 count:5 with:#bold; |
|
959 |
emphasizeFrom:7 count:5 with:#italic |
|
960 |
" |
|
961 |
||
962 |
"Modified: 11.5.1996 / 14:30:02 / cg" |
|
963 |
"Created: 16.5.1996 / 10:52:27 / cg" |
|
964 |
! |
|
965 |
||
304 | 966 |
emphasizeFrom:start to:stop with:emphasis |
967 |
"change the emphasis of a range of characters" |
|
968 |
||
969 |
|newRuns| |
|
970 |
||
631 | 971 |
runs from:start to:stop put:emphasis. |
626 | 972 |
^ self. |
973 |
||
304 | 974 |
newRuns := RunArray new. |
975 |
||
976 |
"/ for now - a q&d hack |
|
977 |
1 to:start-1 do:[:i | |
|
978 |
newRuns add:(runs at:i). |
|
979 |
]. |
|
980 |
newRuns add:emphasis withOccurrences:(stop - start + 1). |
|
981 |
stop+1 to:string size do:[:i | |
|
982 |
newRuns add:(runs at:i) |
|
983 |
]. |
|
984 |
runs := newRuns |
|
985 |
||
986 |
" |
|
987 |
(Text string:'hello world') |
|
988 |
emphasizeFrom:1 to:5 with:#bold; |
|
989 |
emphasizeFrom:7 to:11 with:#italic |
|
990 |
" |
|
991 |
||
631 | 992 |
"Modified: / 7.4.1998 / 08:52:18 / cg" |
347 | 993 |
! |
994 |
||
995 |
emphasizeFrom:start with:emphasis |
|
996 |
"change the emphasis of some characters upTo the end" |
|
997 |
||
998 |
self emphasizeFrom:start to:(self size) with:emphasis |
|
999 |
||
1000 |
" |
|
1001 |
(Text string:'hello world') |
|
1002 |
emphasizeFrom:1 count:5 with:#bold; |
|
1003 |
emphasizeFrom:7 with:#italic |
|
1004 |
" |
|
1005 |
||
1006 |
"Modified: 11.5.1996 / 14:30:02 / cg" |
|
1007 |
"Created: 17.5.1996 / 15:15:32 / cg" |
|
661 | 1008 |
! |
1009 |
||
1010 |
makeSelectorBoldIn:aClass |
|
1011 |
"the receiver represents some source code for |
|
1012 |
a method in aClass. |
|
1013 |
Change myself to boldify the selector. |
|
1014 |
Not yet implemented (could easily use the syntaxHighlighter |
|
1015 |
for this ..." |
|
1016 |
||
1017 |
^ self |
|
1018 |
||
1019 |
"Created: / 19.6.1998 / 00:08:34 / cg" |
|
304 | 1020 |
! ! |
1021 |
||
1022 |
!Text methodsFor:'printing & storing'! |
|
1023 |
||
343 | 1024 |
printOn:aStream |
1025 |
"print the receivers characters (including emphasis) on |
|
409 | 1026 |
aStream. |
1027 |
Notice, that some streams simply ignore the emphasis |
|
1028 |
(Transcript currently does)." |
|
343 | 1029 |
|
409 | 1030 |
|pos nextPos| |
407 | 1031 |
|
1032 |
pos := 1. |
|
343 | 1033 |
|
407 | 1034 |
runs runsDo:[:len :emphasis | |
409 | 1035 |
nextPos := pos + len. |
407 | 1036 |
|
1037 |
aStream emphasis:emphasis. |
|
409 | 1038 |
aStream nextPutAll:string startingAt:pos to:nextPos - 1. |
1039 |
pos := nextPos |
|
343 | 1040 |
]. |
304 | 1041 |
|
343 | 1042 |
" |
407 | 1043 |
Transcript showCR:'hello world'. |
1044 |
Transcript showCR:'hello world' asText allBold. |
|
1045 |
Transcript showCR:('hello world' asText emphasizeAllWith:#italic). |
|
343 | 1046 |
" |
304 | 1047 |
|
409 | 1048 |
"Modified: 12.7.1996 / 10:15:47 / cg" |
304 | 1049 |
! |
1050 |
||
1051 |
storeOn:aStream |
|
343 | 1052 |
"append a printed representation from which the receiver can be reconstructed |
1053 |
to aStream." |
|
1054 |
||
304 | 1055 |
aStream nextPutAll:'(Text string:'. |
1056 |
string storeOn:aStream. |
|
307 | 1057 |
aStream nextPutAll:' runs:'. |
304 | 1058 |
runs storeOn:aStream. |
1059 |
aStream nextPutAll:')'. |
|
1060 |
||
1061 |
"Created: 11.5.1996 / 14:27:09 / cg" |
|
343 | 1062 |
"Modified: 16.5.1996 / 11:23:32 / cg" |
304 | 1063 |
! ! |
1064 |
||
1065 |
!Text methodsFor:'private accessing'! |
|
1066 |
||
631 | 1067 |
emphasisCollection:emphasisCollection |
1068 |
"set the string and emphasis collection. |
|
1069 |
The emphasis collection contains per-character information." |
|
1070 |
||
1071 |
runs := emphasisCollection |
|
1072 |
||
1073 |
"Created: / 7.4.1998 / 08:52:03 / cg" |
|
1074 |
! |
|
1075 |
||
304 | 1076 |
string:aString emphasis:emphasis |
343 | 1077 |
"set the string and emphasis. The emphasis is applied to all characters." |
1078 |
||
428 | 1079 |
string := aString string. |
1080 |
runs := RunArray new:string size withAll:emphasis |
|
304 | 1081 |
|
1082 |
" |
|
1083 |
|t| |
|
1084 |
||
1085 |
t := Text new string:'hello' emphasis:#bold. |
|
1086 |
t emphasisAt:2. |
|
1087 |
" |
|
1088 |
||
343 | 1089 |
"Modified: 16.5.1996 / 11:24:03 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1090 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1091 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1092 |
string:aString emphasisCollection:emphasisCollection |
343 | 1093 |
"set the string and emphasis collection. |
1094 |
The emphasis collection contains per-character information." |
|
1095 |
||
428 | 1096 |
string := aString string. |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1097 |
runs := emphasisCollection asRunArray |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1098 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1099 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1100 |
|t| |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1101 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1102 |
t := Text new string:'hello' emphasisCollection:(#bold #bold #bold #italic #italic). |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1103 |
t emphasisAt:2. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1104 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1105 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1106 |
"Created: 14.5.1996 / 14:03:29 / cg" |
343 | 1107 |
"Modified: 16.5.1996 / 11:24:21 / cg" |
304 | 1108 |
! ! |
1109 |
||
1110 |
!Text methodsFor:'queries'! |
|
1111 |
||
307 | 1112 |
bitsPerCharacter |
343 | 1113 |
"return the underlying strings bitsPerCharacter |
1114 |
(i.e. is it a regular String or a TwoByteString)" |
|
1115 |
||
307 | 1116 |
^ string bitsPerCharacter |
304 | 1117 |
|
307 | 1118 |
"Created: 12.5.1996 / 15:44:04 / cg" |
343 | 1119 |
"Modified: 16.5.1996 / 11:24:54 / cg" |
304 | 1120 |
! |
1121 |
||
1122 |
hasChangeOfEmphasis |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1123 |
"return true, if the receiver contains non-empty emphasis information" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1124 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1125 |
^ (runs notNil |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1126 |
and:[(runs findFirst:[:e | e notNil]) ~~ 0]) |
304 | 1127 |
|
1128 |
"Created: 11.5.1996 / 14:03:19 / cg" |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1129 |
"Modified: 14.5.1996 / 15:51:01 / cg" |
304 | 1130 |
! |
1131 |
||
307 | 1132 |
heightOn:aGC |
1133 |
"return the number of device units, required on aGC's device" |
|
1134 |
||
621 | 1135 |
^ (aGC font onDevice:aGC device) heightOf:string |
307 | 1136 |
|
1137 |
"Created: 12.5.1996 / 11:02:03 / cg" |
|
1138 |
! |
|
1139 |
||
304 | 1140 |
indexOf:aCharacter startingAt:index |
343 | 1141 |
"search aCharacters index in the underlying string" |
1142 |
||
304 | 1143 |
^ string indexOf:aCharacter startingAt:index |
1144 |
||
1145 |
"Created: 11.5.1996 / 13:58:56 / cg" |
|
343 | 1146 |
"Modified: 16.5.1996 / 11:25:12 / cg" |
304 | 1147 |
! |
1148 |
||
307 | 1149 |
isText |
343 | 1150 |
"return true if this is a Text object - always true here" |
1151 |
||
307 | 1152 |
^ true |
1153 |
||
1154 |
"Created: 12.5.1996 / 10:56:24 / cg" |
|
343 | 1155 |
"Modified: 16.5.1996 / 11:25:29 / cg" |
307 | 1156 |
! |
1157 |
||
304 | 1158 |
occurrencesOf:aCharacter |
343 | 1159 |
"count & return the number of occurrences of aCharacter in the |
1160 |
underlying string" |
|
1161 |
||
304 | 1162 |
^ string occurrencesOf:aCharacter |
1163 |
||
1164 |
"Created: 11.5.1996 / 13:58:46 / cg" |
|
343 | 1165 |
"Modified: 16.5.1996 / 11:25:51 / cg" |
304 | 1166 |
! |
1167 |
||
1168 |
size |
|
343 | 1169 |
"return the number of characters in the underlying string" |
1170 |
||
304 | 1171 |
^ string size |
1172 |
||
1173 |
"Created: 11.5.1996 / 14:25:15 / cg" |
|
343 | 1174 |
"Modified: 16.5.1996 / 11:26:08 / cg" |
304 | 1175 |
! |
1176 |
||
1177 |
string |
|
343 | 1178 |
"return the receiver without any emphasis information |
1179 |
i.e. the underlying string." |
|
1180 |
||
304 | 1181 |
^ string |
1182 |
||
1183 |
"Created: 11.5.1996 / 13:58:38 / cg" |
|
343 | 1184 |
"Modified: 16.5.1996 / 11:26:30 / cg" |
307 | 1185 |
! |
1186 |
||
1187 |
widthOn:aGC |
|
1188 |
"return the number of device units, required on aGC's device" |
|
1189 |
||
450 | 1190 |
|savedFont boldFont italicFont bold italic pos f l device| |
307 | 1191 |
|
404
14cf34141532
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
395
diff
changeset
|
1192 |
device := aGC graphicsDevice. |
14cf34141532
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
395
diff
changeset
|
1193 |
|
14cf34141532
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
395
diff
changeset
|
1194 |
savedFont := aGC basicFont on:device. |
307 | 1195 |
|
1196 |
pos := 1. |
|
1197 |
l := 0. |
|
1198 |
runs runsDo:[:len :emphasis | |
|
1199 |
emphasis isSymbol ifTrue:[ |
|
1200 |
bold := emphasis == #bold. |
|
1201 |
italic := emphasis == #italic. |
|
1202 |
] ifFalse:[ |
|
308 | 1203 |
(emphasis isNil |
1204 |
or:[emphasis isMemberOf:Association]) ifTrue:[ |
|
307 | 1205 |
bold := italic := false |
1206 |
] ifFalse:[ |
|
1207 |
bold := emphasis includesIdentical:#bold. |
|
1208 |
italic := emphasis includesIdentical:#italic. |
|
1209 |
] |
|
1210 |
]. |
|
1211 |
||
1212 |
bold ifTrue:[ |
|
1213 |
boldFont isNil ifTrue:[ |
|
360 | 1214 |
boldFont := savedFont asBold on:device |
307 | 1215 |
]. |
1216 |
f := boldFont. |
|
1217 |
] ifFalse:[ |
|
1218 |
italic ifTrue:[ |
|
1219 |
italicFont isNil ifTrue:[ |
|
360 | 1220 |
italicFont := savedFont asItalic on:device |
307 | 1221 |
]. |
1222 |
f := italicFont |
|
1223 |
] ifFalse:[ |
|
1224 |
f := savedFont |
|
1225 |
] |
|
1226 |
]. |
|
621 | 1227 |
f := f onDevice:aGC device. |
307 | 1228 |
l := l + (f widthOf:string from:pos to:(pos + len - 1)). |
1229 |
pos := pos + len |
|
1230 |
]. |
|
1231 |
||
1232 |
^ l |
|
1233 |
||
404
14cf34141532
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
395
diff
changeset
|
1234 |
"Modified: 5.7.1996 / 17:54:58 / cg" |
307 | 1235 |
! ! |
1236 |
||
1237 |
!Text methodsFor:'replacing'! |
|
1238 |
||
1239 |
replaceFrom:start to:stop with:aCollection startingAt:startIndex |
|
343 | 1240 |
"replace a range of characters, from another string or text object. |
607 | 1241 |
The corresponding characters' emphasis information is also copied. |
1242 |
Return the receiver." |
|
343 | 1243 |
|
307 | 1244 |
|idx| |
1245 |
||
1246 |
aCollection isString ifTrue:[ |
|
1247 |
aCollection hasChangeOfEmphasis ifTrue:[ |
|
1248 |
string replaceFrom:start to:stop with:aCollection startingAt:startIndex. |
|
1249 |
idx := startIndex. |
|
1250 |
start to:stop do:[:col | |
|
1251 |
self emphasisAt:col put:(aCollection emphasisAt:idx). |
|
1252 |
idx := idx + 1. |
|
1253 |
]. |
|
1254 |
^ self. |
|
1255 |
] |
|
1256 |
]. |
|
1257 |
||
1258 |
string replaceFrom:start to:stop with:aCollection startingAt:startIndex. |
|
1259 |
self emphasizeFrom:start to:stop with:nil |
|
1260 |
||
1261 |
" |
|
1262 |
((Text string:'hello') allBold emphasisAt:2 put:#italic) |
|
1263 |
copyFrom:1 to:3 |
|
1264 |
" |
|
1265 |
||
607 | 1266 |
"Modified: / 28.1.1998 / 16:50:06 / cg" |
304 | 1267 |
! ! |
1268 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
1269 |
!Text class methodsFor:'documentation'! |
304 | 1270 |
|
1271 |
version |
|
762
59768d57ab94
care for bad emphasis when displaying.
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
1272 |
^ '$Header: /cvs/stx/stx/libbasic2/Text.st,v 1.57 1999-07-06 23:58:49 cg Exp $' |
304 | 1273 |
! ! |
314 | 1274 |
Text initialize! |