author | Claus Gittinger <cg@exept.de> |
Tue, 04 Jun 1996 11:25:50 +0200 | |
changeset 384 | 866650ee29fd |
parent 360 | 170352b4c53e |
child 393 | e9723971f6f2 |
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 |
||
21 |
!Text class methodsFor:'documentation'! |
|
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 |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
51 |
#strikeout |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
52 |
(#color -> aColor) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
53 |
(#backgroundColor -> aColor) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
54 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
55 |
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
|
56 |
See examples. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
57 |
|
304 | 58 |
This class is not yet fully implemented - being constructed. |
59 |
||
60 |
[author:] |
|
61 |
Claus Gittinger |
|
62 |
||
63 |
[see also:] |
|
64 |
CharacterArray String RunArray |
|
65 |
" |
|
313 | 66 |
! |
67 |
||
68 |
examples |
|
69 |
" |
|
343 | 70 |
plain string (for comparison): |
313 | 71 |
[exBegin] |
72 |
Dialog |
|
73 |
warn:'hello' |
|
74 |
[exEnd] |
|
343 | 75 |
|
76 |
||
77 |
emphasized strings as dialog titles: |
|
313 | 78 |
[exBegin] |
79 |
Dialog |
|
80 |
warn:((Text string:'hello') allBold) |
|
81 |
[exEnd] |
|
82 |
[exBegin] |
|
83 |
Dialog |
|
84 |
warn:(Text string:'hello' emphasis:#italic) |
|
85 |
[exEnd] |
|
86 |
[exBegin] |
|
87 |
Dialog |
|
88 |
warn:(Text string:'hello' emphasis:#(bold underline)) |
|
89 |
[exEnd] |
|
90 |
[exBegin] |
|
91 |
Dialog |
|
92 |
warn:(Text string:'hello' |
|
93 |
emphasis:(Array with:#bold |
|
94 |
with:#strikeout |
|
95 |
with:(#color->Color red))) |
|
96 |
[exEnd] |
|
97 |
[exBegin] |
|
98 |
Dialog |
|
315 | 99 |
warn:(Text string:'hello' |
100 |
emphasis:(Array with:#bold |
|
101 |
with:#strikeout |
|
102 |
with:(#color->Color red) |
|
103 |
with:(#backgroundColor->Color yellow))) |
|
104 |
[exEnd] |
|
105 |
[exBegin] |
|
106 |
Dialog |
|
313 | 107 |
warn:(Text string:'hello' color:(Color red)) |
108 |
[exEnd] |
|
109 |
||
343 | 110 |
|
111 |
in an editTextView: |
|
112 |
[exBegin] |
|
113 |
|t v| |
|
114 |
||
115 |
t := 'The quick brown fox jumps over the lazy dog' asText. |
|
116 |
t emphasizeFrom:(t findString:'quick') count:5 with:#bold. |
|
117 |
t emphasizeFrom:(t findString:'brown') count:9 |
|
118 |
with:(Array with:#color->(Color name:'brown') |
|
119 |
with:#bold). |
|
120 |
t emphasizeFrom:(t findString:'lazy') count:4 |
|
121 |
with:(Array with:#color->(Color red) |
|
122 |
with:#italic). |
|
123 |
t emphasizeFrom:(t findString:'dog') count:3 with:#underline. |
|
124 |
||
125 |
v := HVScrollableView for:EditTextView. |
|
126 |
v contents:t. |
|
127 |
||
128 |
v width:450. |
|
129 |
v open. |
|
130 |
[exEnd] |
|
313 | 131 |
" |
304 | 132 |
! ! |
133 |
||
314 | 134 |
!Text class methodsFor:'initialization'! |
135 |
||
136 |
initialize |
|
137 |
"initialize the class" |
|
138 |
||
139 |
" |
|
140 |
consider this a kludge: |
|
141 |
I want to inherit behavior from CharacterArray, but not |
|
142 |
its implementation (indexed access). |
|
143 |
" |
|
144 |
||
145 |
self flags:(Behavior flagRegular) |
|
146 |
||
147 |
" |
|
148 |
Text initialize |
|
149 |
" |
|
150 |
||
151 |
"Modified: 12.5.1996 / 17:53:50 / cg" |
|
152 |
! ! |
|
153 |
||
304 | 154 |
!Text class methodsFor:'instance creation'! |
155 |
||
156 |
fromString:aString |
|
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
157 |
"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
|
158 |
without emphasis." |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
159 |
|
304 | 160 |
^ self new string:aString emphasis:nil |
161 |
||
162 |
" |
|
163 |
Text fromString:'hello' |
|
164 |
" |
|
165 |
||
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
166 |
"Modified: 12.5.1996 / 17:05:34 / cg" |
304 | 167 |
! |
168 |
||
307 | 169 |
new:size |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
170 |
"create a new empty Text instance. |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
171 |
Redefined for string-protocol compatibility" |
307 | 172 |
|
173 |
^ self string:(String new:size) |
|
174 |
||
175 |
"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
|
176 |
"Modified: 12.5.1996 / 17:05:17 / cg" |
307 | 177 |
! |
178 |
||
304 | 179 |
string:aString |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
180 |
"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
|
181 |
without emphasis." |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
182 |
|
304 | 183 |
^ self new string:aString emphasis:nil |
184 |
||
185 |
" |
|
186 |
Text string:'hello' |
|
187 |
" |
|
188 |
||
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
189 |
"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
|
190 |
! |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
191 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
192 |
string:aString color:aColor |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
193 |
"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
|
194 |
which are colored as aColor (only the foregroundColor is affected). |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
195 |
This is a shortCut for creating an emphasis of #color->aColor)" |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
196 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
197 |
^ self new string:aString emphasis:(#color->aColor) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
198 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
199 |
" |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
200 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
201 |
information:(Text string:'hello' color:(Color red)) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
202 |
" |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
203 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
204 |
"Created: 12.5.1996 / 17:03:20 / cg" |
345
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
205 |
"Modified: 16.5.1996 / 12:37:46 / cg" |
344
72fe9b7ae4b5
added #string:color:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
343
diff
changeset
|
206 |
! |
72fe9b7ae4b5
added #string:color:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
343
diff
changeset
|
207 |
|
304 | 208 |
string:aString emphasis:attribute |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
209 |
"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
|
210 |
which are emphasized as described by attribute." |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
211 |
|
304 | 212 |
^ self new string:aString emphasis:attribute |
213 |
||
214 |
" |
|
215 |
Text string:'hello' emphasis:#bold |
|
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
216 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
217 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
218 |
information:(Text string:'hello' emphasis:#bold) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
219 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
220 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
221 |
information:(Text string:'hello' emphasis:#italic) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
222 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
223 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
224 |
information:(Text string:'hello' emphasis:#underline) |
310 | 225 |
|
226 |
Dialog |
|
227 |
information:(Text string:'hello' emphasis:#strikeout) |
|
304 | 228 |
" |
229 |
||
310 | 230 |
"Modified: 12.5.1996 / 17:16:03 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
231 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
232 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
233 |
string:aString emphasisCollection:attributeCollection |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
234 |
"create a Text instance, for the characters in aString, |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
235 |
which are individually emphasized as described by attributeCollection." |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
236 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
237 |
^ self new string:aString emphasisCollection:attributeCollection |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
238 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
239 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
240 |
Text |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
241 |
string:'hello' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
242 |
emphasisCollection:#(#bold #bold #italic #italic #italic) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
243 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
244 |
Dialog |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
245 |
information:(Text |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
246 |
string:'hello' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
247 |
emphasisCollection:#(#bold #bold #italic #italic #(#underline italic))) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
248 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
249 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
250 |
"Created: 14.5.1996 / 14:02:18 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
251 |
"Modified: 14.5.1996 / 15:01:28 / cg" |
345
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
252 |
! |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
253 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
254 |
string:aString foregroundColor:fgColor backgroundColor:bgColor |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
255 |
"create a Text instance, for the characters in aString, |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
256 |
which are colored in fgColor on bgColor. |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
257 |
This is a shortCut for creating an emphasis of |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
258 |
#( #color->fgColor) (#backgroundColor->bgColor)" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
259 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
260 |
^ self new |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
261 |
string:aString |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
262 |
emphasis:(Array with:#color->fgColor |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
263 |
with:#backgroundColor->bgColor) |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
264 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
265 |
" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
266 |
Dialog |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
267 |
information:(Text string:'hello' |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
268 |
foregroundColor:(Color red) |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
269 |
backgroundColor:(Color yellow)) |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
270 |
" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
271 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
272 |
"Modified: 11.5.1996 / 14:21:01 / cg" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
273 |
"Created: 16.5.1996 / 12:37:24 / cg" |
304 | 274 |
! ! |
275 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
276 |
!Text class methodsFor:'emphasis helper'! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
277 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
278 |
addEmphasis:e1 to:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
279 |
"merge two emphasis's into one" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
280 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
281 |
|ne| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
282 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
283 |
e1 isNil ifTrue:[^ e2]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
284 |
e2 isNil ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
285 |
e1 == e2 ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
286 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
287 |
(e1 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
288 |
or:[e1 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
289 |
(e2 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
290 |
or:[e2 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
291 |
^ Array with:e1 with:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
292 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
293 |
(e2 includes:e1) ifTrue:[^ e2]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
294 |
^ e2 copyWith:e1 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
295 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
296 |
(e2 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
297 |
or:[e2 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
298 |
(e1 includes:e2) ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
299 |
^ e1 copyWith:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
300 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
301 |
"/ ould use: |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
302 |
"/ ^ (e1 asSet addAll:e2; asArray) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
303 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
304 |
"/ but we do it manually, to preserve the |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
305 |
"/ order. (should create longer runs, while editing) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
306 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
307 |
ne := e1. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
308 |
e2 do:[:e | |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
309 |
(ne includes:e) ifFalse:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
310 |
ne := ne copyWith:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
311 |
] |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
312 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
313 |
^ ne. |
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 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
316 |
Text addEmphasis:#bold to:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
317 |
Text addEmphasis:#bold to:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
318 |
Text addEmphasis:#bold to:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
319 |
Text addEmphasis:#italic to:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
320 |
Text addEmphasis:#(italic strikeout) to:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
321 |
Text addEmphasis:#(italic strikeout) to:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
322 |
Text addEmphasis:#(italic strikeout) to:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
323 |
Text addEmphasis:(#color->Color red) to:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
324 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
325 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
326 |
"Modified: 14.5.1996 / 17:15:44 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
327 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
328 |
|
339 | 329 |
emphasis:e1 includes:e2 |
330 |
"return true, if e1 includes e2. |
|
331 |
e2 should be a single emphasis." |
|
332 |
||
333 |
|ne| |
|
334 |
||
335 |
e1 isNil ifTrue:[^ false]. |
|
336 |
e2 isNil ifTrue:[^ false]. |
|
337 |
e1 == e2 ifTrue:[^ true]. |
|
338 |
||
339 |
(e1 isSymbol |
|
340 |
or:[e1 isAssociation]) ifTrue:[ |
|
341 |
^ false |
|
342 |
]. |
|
343 |
(e2 isSymbol |
|
344 |
or:[e2 isAssociation]) ifTrue:[ |
|
345 |
^ (e1 includes:e2) |
|
346 |
]. |
|
347 |
^ false |
|
348 |
||
349 |
" |
|
350 |
Text emphasis:#bold includes:#bold |
|
351 |
Text emphasis:#bold includes:#ialic |
|
352 |
Text emphasis:#(italic strikeout) includes:#bold |
|
353 |
Text emphasis:#(italic strikeout) includes:#italic |
|
354 |
" |
|
355 |
||
356 |
"Modified: 14.5.1996 / 17:45:11 / cg" |
|
357 |
! |
|
358 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
359 |
removeEmphasis:e1 from:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
360 |
"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
|
361 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
362 |
|ne| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
363 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
364 |
e1 isNil ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
365 |
e2 isNil ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
366 |
e1 == e2 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
367 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
368 |
(e2 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
369 |
or:[e2 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
370 |
(e1 includes:e2) ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
371 |
^ e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
372 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
373 |
(e1 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
374 |
or:[e1 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
375 |
(e2 includes:e1) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
376 |
ne := e2 copyWithout:e1. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
377 |
ne size == 1 ifTrue:[^ ne at:1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
378 |
ne size == 0 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
379 |
^ ne |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
380 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
381 |
^ e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
382 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
383 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
384 |
"/ ould use: |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
385 |
"/ ^ (e2 asSet removeAll:e1; asArray) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
386 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
387 |
"/ but we do it manually, to preserve the |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
388 |
"/ order. (should create longer runs, while editing) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
389 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
390 |
ne := e2. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
391 |
e1 do:[:e | |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
392 |
(ne includes:e) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
393 |
ne := ne copyWithout:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
394 |
] |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
395 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
396 |
ne size == 1 ifTrue:[^ ne at:1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
397 |
ne size == 0 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
398 |
^ ne. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
399 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
400 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
401 |
Text removeEmphasis:#bold from:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
402 |
Text removeEmphasis:#bold from:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
403 |
Text removeEmphasis:#bold from:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
404 |
Text removeEmphasis:#italic from:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
405 |
Text removeEmphasis:#(italic strikeout) from:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
406 |
Text removeEmphasis:#(italic strikeout) from:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
407 |
Text removeEmphasis:#(italic strikeout) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
408 |
Text removeEmphasis:#(italic strikeout bold) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
409 |
Text removeEmphasis:#(italic strikeout bold underline) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
410 |
Text removeEmphasis:(#color->Color red) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
411 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
412 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
413 |
"Modified: 14.5.1996 / 17:23:46 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
414 |
! ! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
415 |
|
304 | 416 |
!Text methodsFor:'comparing'! |
417 |
||
418 |
= aStringOrText |
|
419 |
"compare the receiver and the argument, ignoring emphasis" |
|
420 |
||
384 | 421 |
aStringOrText isString ifFalse:[^ false]. |
304 | 422 |
^ string = aStringOrText string |
423 |
||
424 |
||
425 |
" |
|
426 |
'hello' asText = 'hello' |
|
427 |
'hello' asText = 'hello' asText |
|
428 |
'hello' asText allBold = 'hello' |
|
429 |
" |
|
430 |
||
384 | 431 |
"Modified: 4.6.1996 / 11:14:58 / cg" |
304 | 432 |
! ! |
433 |
||
434 |
!Text methodsFor:'converting'! |
|
435 |
||
436 |
asText |
|
343 | 437 |
"return the receiver itself - it is already a text object" |
438 |
||
304 | 439 |
^ self |
440 |
||
441 |
"Created: 11.5.1996 / 14:08:36 / cg" |
|
343 | 442 |
"Modified: 16.5.1996 / 11:15:12 / cg" |
304 | 443 |
! |
444 |
||
445 |
at:characterIndex |
|
343 | 446 |
"return the plain character at characterIndex" |
447 |
||
304 | 448 |
^ string at:characterIndex |
449 |
||
450 |
"Created: 11.5.1996 / 14:25:41 / cg" |
|
343 | 451 |
"Modified: 16.5.1996 / 11:15:33 / cg" |
304 | 452 |
! |
453 |
||
454 |
at:characterIndex put:aCharacter |
|
343 | 455 |
"change the character at characterIndex to be aCharacter. |
456 |
The emphasis (if any) of that character remains unchanged." |
|
457 |
||
304 | 458 |
^ string at:characterIndex put:aCharacter |
459 |
||
460 |
"Created: 11.5.1996 / 14:25:49 / cg" |
|
343 | 461 |
"Modified: 16.5.1996 / 11:15:57 / cg" |
304 | 462 |
! ! |
463 |
||
464 |
!Text methodsFor:'copying'! |
|
465 |
||
466 |
, aStringOrText |
|
343 | 467 |
"concatenate the receivers characters with the arguments characters, |
468 |
and return string or text object containing those characters. |
|
469 |
If either the receiver or the argument contains emphasis information, |
|
470 |
a text object will be returned. Otherwise, a string (i.e. without emphasis) |
|
471 |
is returned." |
|
304 | 472 |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
473 |
(aStringOrText hasChangeOfEmphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
474 |
or:[self hasChangeOfEmphasis]) ifTrue:[ |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
475 |
^ self species new |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
476 |
string:(string , aStringOrText) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
477 |
emphasisCollection:(runs , aStringOrText emphasisCollection) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
478 |
]. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
479 |
^ string , aStringOrText string |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
480 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
481 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
482 |
('hello' asText allBold) , ' world' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
483 |
'hello' , (' world' asText allBold) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
484 |
'hello' , ' world' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
485 |
('hello' asText allBold) , (' world' asText allBold) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
486 |
" |
304 | 487 |
|
343 | 488 |
"Modified: 16.5.1996 / 11:17:40 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
489 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
490 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
491 |
concatenateFromString:aString |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
492 |
"return the concatenation of aString and myself. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
493 |
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
|
494 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
495 |
self hasChangeOfEmphasis ifTrue:[ |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
496 |
^ self species new |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
497 |
string:(aString , string) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
498 |
emphasisCollection:((RunArray new:(aString size)) , runs). |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
499 |
]. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
500 |
^ aString , string |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
501 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
502 |
"Modified: 14.5.1996 / 15:56:05 / cg" |
307 | 503 |
! ! |
504 |
||
505 |
!Text methodsFor:'displaying'! |
|
506 |
||
507 |
displayOn:aGC x:x y:y |
|
508 |
"display the receiver on a GC" |
|
509 |
||
510 |
self displayOn:aGC x:x y:y opaque:false |
|
511 |
||
512 |
"Modified: 12.5.1996 / 11:14:57 / cg" |
|
513 |
! |
|
514 |
||
515 |
displayOn:aGC x:x y:y from:start to:stop |
|
516 |
"display the receiver on a GC" |
|
517 |
||
518 |
"q&d hack" |
|
519 |
||
520 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:false |
|
521 |
||
522 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
304 | 523 |
! |
524 |
||
307 | 525 |
displayOn:aGC x:x0 y:y opaque:opaque |
526 |
"display the receiver on a GC" |
|
527 |
||
315 | 528 |
|savedFont savedPaint savedBgPaint font color boldFont italicFont |
529 |
bgPaint |
|
310 | 530 |
bold italic underline strikeout |
531 |
pos "{ Class: SmallInteger }" |
|
532 |
endPos "{ Class: SmallInteger }" |
|
533 |
x "{ Class: SmallInteger }" |
|
534 |
l "{ Class: SmallInteger }" |
|
360 | 535 |
yL k value device| |
307 | 536 |
|
537 |
savedFont := aGC basicFont. |
|
538 |
savedPaint := aGC paint. |
|
315 | 539 |
savedBgPaint := aGC backgroundPaint. |
307 | 540 |
|
541 |
pos := 1. |
|
542 |
x := x0. |
|
543 |
runs runsDo:[:len :emphasis | |
|
544 |
color := nil. |
|
545 |
bold := italic := underline := strikeout := false. |
|
315 | 546 |
bgPaint := savedBgPaint. |
307 | 547 |
|
548 |
emphasis isSymbol ifTrue:[ |
|
549 |
emphasis == #bold ifTrue:[bold := true] |
|
550 |
ifFalse:[emphasis == #italic ifTrue:[italic := true] |
|
551 |
ifFalse:[emphasis == #underline ifTrue:[underline := true] |
|
552 |
ifFalse:[emphasis == #strikeout ifTrue:[strikeout := true] |
|
553 |
]]] |
|
554 |
] ifFalse:[ |
|
555 |
(emphasis isMemberOf:Association) ifTrue:[ |
|
315 | 556 |
value := emphasis value. |
557 |
k := emphasis key. |
|
558 |
k == #color ifTrue:[ |
|
559 |
color := value |
|
560 |
] ifFalse:[k == #backgroundColor ifTrue:[ |
|
561 |
bgPaint := value |
|
562 |
]] |
|
307 | 563 |
] ifFalse:[ |
564 |
emphasis notNil ifTrue:[ |
|
565 |
emphasis do:[:entry | |
|
566 |
entry == #bold ifTrue:[bold := true] |
|
567 |
ifFalse:[entry == #italic ifTrue:[italic := true] |
|
568 |
ifFalse:[entry == #underline ifTrue:[underline := true] |
|
569 |
ifFalse:[entry == #strikeout ifTrue:[strikeout := true] |
|
570 |
ifFalse:[ |
|
571 |
(entry isMemberOf:Association) ifTrue:[ |
|
315 | 572 |
value := entry value. |
573 |
k := entry key. |
|
574 |
k == #color ifTrue:[ |
|
575 |
color := value |
|
576 |
] ifFalse:[k == #backgroundColor ifTrue:[ |
|
577 |
bgPaint := value |
|
578 |
]] |
|
307 | 579 |
] |
315 | 580 |
]]]] |
307 | 581 |
] |
582 |
] |
|
583 |
] |
|
584 |
]. |
|
585 |
||
360 | 586 |
device := aGC graphicsDevice. |
587 |
||
307 | 588 |
color isNil ifTrue:[ |
589 |
color := savedPaint. |
|
590 |
] ifFalse:[ |
|
360 | 591 |
color := color on:device. |
307 | 592 |
]. |
304 | 593 |
|
307 | 594 |
bold ifTrue:[ |
595 |
boldFont isNil ifTrue:[ |
|
360 | 596 |
boldFont := savedFont asBold on:device |
307 | 597 |
]. |
598 |
font := boldFont. |
|
599 |
] ifFalse:[ |
|
600 |
italic ifTrue:[ |
|
601 |
italicFont isNil ifTrue:[ |
|
360 | 602 |
italicFont := savedFont asItalic on:device |
307 | 603 |
]. |
604 |
font := italicFont. |
|
605 |
] ifFalse:[ |
|
606 |
font := savedFont |
|
607 |
] |
|
608 |
]. |
|
609 |
aGC basicFont:font. |
|
315 | 610 |
aGC paint:color on:bgPaint. |
307 | 611 |
|
310 | 612 |
endPos := pos + len - 1. |
307 | 613 |
opaque ifTrue:[ |
310 | 614 |
aGC displayOpaqueString:string from:pos to:endPos x:x y:y. |
307 | 615 |
] ifFalse:[ |
310 | 616 |
aGC displayString:string from:pos to:endPos x:x y:y. |
307 | 617 |
]. |
310 | 618 |
l := aGC font widthOf:string from:pos to:endPos. |
307 | 619 |
|
620 |
underline ifTrue:[ |
|
310 | 621 |
yL := y+1. |
622 |
aGC displayLineFromX:x y:yL toX:x+l-1 y:yL |
|
623 |
]. |
|
624 |
strikeout ifTrue:[ |
|
625 |
yL := y-(font ascent//2). |
|
626 |
aGC displayLineFromX:x y:yL toX:x+l-1 y:yL |
|
307 | 627 |
]. |
628 |
||
629 |
x := x + l. |
|
310 | 630 |
pos := endPos + 1 |
304 | 631 |
]. |
307 | 632 |
|
633 |
aGC basicFont:savedFont. |
|
316 | 634 |
aGC paint:savedPaint on:savedBgPaint. |
307 | 635 |
|
636 |
"Created: 12.5.1996 / 11:14:30 / cg" |
|
360 | 637 |
"Modified: 28.5.1996 / 20:26:20 / cg" |
307 | 638 |
! |
639 |
||
640 |
displayOpaqueOn:aGC x:x y:y |
|
641 |
"display the receiver on a GC" |
|
642 |
||
643 |
self displayOn:aGC x:x y:y opaque:true |
|
304 | 644 |
|
307 | 645 |
"Modified: 12.5.1996 / 11:14:52 / cg" |
646 |
! |
|
647 |
||
648 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
|
649 |
"display the receiver on a GC" |
|
650 |
||
651 |
"q&d hack" |
|
652 |
||
653 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:true |
|
654 |
||
655 |
"Created: 12.5.1996 / 12:29:37 / cg" |
|
656 |
"Modified: 12.5.1996 / 12:49:19 / cg" |
|
304 | 657 |
! ! |
658 |
||
659 |
!Text methodsFor:'emphasis'! |
|
660 |
||
661 |
allBold |
|
662 |
"make all characters bold" |
|
663 |
||
664 |
runs := RunArray new:(string size) withAll:#bold |
|
665 |
||
666 |
" |
|
667 |
(Text string:'hello') allBold |
|
668 |
" |
|
669 |
||
670 |
"Modified: 11.5.1996 / 14:22:12 / cg" |
|
671 |
! |
|
672 |
||
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
673 |
emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
674 |
"return the emphasis" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
675 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
676 |
^ runs |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
677 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
678 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
679 |
(Text string:'hello') allBold emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
680 |
'hello' emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
681 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
682 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
683 |
"Modified: 11.5.1996 / 14:22:31 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
684 |
"Created: 14.5.1996 / 13:59:03 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
685 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
686 |
|
304 | 687 |
emphasisAt:characterIndex |
688 |
"return the emphasis at some index" |
|
689 |
||
690 |
^ runs at:characterIndex |
|
691 |
||
692 |
" |
|
693 |
(Text string:'hello') allBold emphasisAt:2 |
|
694 |
" |
|
695 |
||
696 |
"Modified: 11.5.1996 / 14:22:31 / cg" |
|
697 |
! |
|
698 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
699 |
emphasisAt:characterIndex add:newEmphasis |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
700 |
"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
|
701 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
702 |
|e| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
703 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
704 |
e := runs at:characterIndex. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
705 |
e := self class addEmphasis:newEmphasis to:e. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
706 |
runs at:characterIndex put:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
707 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
708 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
709 |
(Text string:'hello') allBold emphasisAt:2 add:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
710 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
711 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
712 |
"Created: 14.5.1996 / 16:48:39 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
713 |
"Modified: 14.5.1996 / 17:13:47 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
714 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
715 |
|
307 | 716 |
emphasisAt:characterIndex put:emphasis |
717 |
"change the emphasis at some index. return the receiver" |
|
718 |
||
719 |
runs at:characterIndex put:emphasis |
|
720 |
||
721 |
" |
|
722 |
(Text string:'hello') allBold emphasisAt:2 put:#italic |
|
723 |
" |
|
724 |
||
725 |
"Modified: 12.5.1996 / 12:40:31 / cg" |
|
726 |
! |
|
727 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
728 |
emphasisAt:characterIndex remove:emphasisToRemove |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
729 |
"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
|
730 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
731 |
|e| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
732 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
733 |
e := runs at:characterIndex. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
734 |
e := self class removeEmphasis:emphasisToRemove from:e. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
735 |
runs at:characterIndex put:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
736 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
737 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
738 |
(Text string:'hello') |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
739 |
allBold emphasisAt:2 remove:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
740 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
741 |
(Text string:'hello' emphasis:#(bold italic)) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
742 |
emphasisAt:2 remove:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
743 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
744 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
745 |
"Created: 14.5.1996 / 16:48:39 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
746 |
"Modified: 14.5.1996 / 17:25:04 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
747 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
748 |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
749 |
emphasisCollection |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
750 |
"return the emphasis" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
751 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
752 |
^ runs |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
753 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
754 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
755 |
(Text string:'hello') allBold emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
756 |
'hello' emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
757 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
758 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
759 |
"Created: 14.5.1996 / 13:59:03 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
760 |
"Modified: 14.5.1996 / 15:02:11 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
761 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
762 |
|
304 | 763 |
emphasizeAllWith:emphasis |
764 |
"change the emphasis of all characters" |
|
765 |
||
766 |
runs := RunArray new:(string size) withAll:emphasis |
|
767 |
||
768 |
" |
|
769 |
(Text string:'hello') allBold emphasizeAllWith:#italic |
|
770 |
" |
|
771 |
||
772 |
"Modified: 11.5.1996 / 14:22:52 / cg" |
|
773 |
! |
|
774 |
||
343 | 775 |
emphasizeFrom:start count:count with:emphasis |
776 |
"change the emphasis of a range of characters, given startIndex and count." |
|
777 |
||
778 |
self emphasizeFrom:start to:(start+count-1) with:emphasis |
|
779 |
||
780 |
" |
|
781 |
(Text string:'hello world') |
|
782 |
emphasizeFrom:1 count:5 with:#bold; |
|
783 |
emphasizeFrom:7 count:5 with:#italic |
|
784 |
" |
|
785 |
||
786 |
"Modified: 11.5.1996 / 14:30:02 / cg" |
|
787 |
"Created: 16.5.1996 / 10:52:27 / cg" |
|
788 |
! |
|
789 |
||
304 | 790 |
emphasizeFrom:start to:stop with:emphasis |
791 |
"change the emphasis of a range of characters" |
|
792 |
||
793 |
|newRuns| |
|
794 |
||
795 |
newRuns := RunArray new. |
|
796 |
||
797 |
"/ for now - a q&d hack |
|
798 |
1 to:start-1 do:[:i | |
|
799 |
newRuns add:(runs at:i). |
|
800 |
]. |
|
801 |
newRuns add:emphasis withOccurrences:(stop - start + 1). |
|
802 |
stop+1 to:string size do:[:i | |
|
803 |
newRuns add:(runs at:i) |
|
804 |
]. |
|
805 |
runs := newRuns |
|
806 |
||
807 |
" |
|
808 |
(Text string:'hello world') |
|
809 |
emphasizeFrom:1 to:5 with:#bold; |
|
810 |
emphasizeFrom:7 to:11 with:#italic |
|
811 |
" |
|
812 |
||
813 |
"Modified: 11.5.1996 / 14:30:02 / cg" |
|
347 | 814 |
! |
815 |
||
816 |
emphasizeFrom:start with:emphasis |
|
817 |
"change the emphasis of some characters upTo the end" |
|
818 |
||
819 |
self emphasizeFrom:start to:(self size) with:emphasis |
|
820 |
||
821 |
" |
|
822 |
(Text string:'hello world') |
|
823 |
emphasizeFrom:1 count:5 with:#bold; |
|
824 |
emphasizeFrom:7 with:#italic |
|
825 |
" |
|
826 |
||
827 |
"Modified: 11.5.1996 / 14:30:02 / cg" |
|
828 |
"Created: 17.5.1996 / 15:15:32 / cg" |
|
304 | 829 |
! ! |
830 |
||
831 |
!Text methodsFor:'printing & storing'! |
|
832 |
||
343 | 833 |
printOn:aStream |
834 |
"print the receivers characters (including emphasis) on |
|
835 |
aStream. Notice, that some streams simply ignore the emphasis." |
|
836 |
||
837 |
"/ this could be implemented in a more efficient way ... |
|
838 |
||
839 |
self keysAndValuesDo:[:i :c | |
|
840 |
aStream emphasis:(self emphasisAt:i). |
|
841 |
aStream nextPut:c. |
|
842 |
]. |
|
304 | 843 |
|
343 | 844 |
" |
845 |
(notice: (currently) the Transcript ignores any emphasis ...) |
|
304 | 846 |
|
343 | 847 |
'hello world' printOn:Transcript. |
848 |
Transcript cr. |
|
849 |
'hello world' asText allBold printOn:Transcript. |
|
850 |
Transcript cr. |
|
851 |
('hello world' asText emphasizeAllWith:#italic) printOn:Transcript. |
|
852 |
Transcript cr. |
|
853 |
" |
|
304 | 854 |
|
343 | 855 |
"Modified: 16.5.1996 / 11:23:04 / cg" |
304 | 856 |
! |
857 |
||
858 |
storeOn:aStream |
|
343 | 859 |
"append a printed representation from which the receiver can be reconstructed |
860 |
to aStream." |
|
861 |
||
304 | 862 |
aStream nextPutAll:'(Text string:'. |
863 |
string storeOn:aStream. |
|
307 | 864 |
aStream nextPutAll:' runs:'. |
304 | 865 |
runs storeOn:aStream. |
866 |
aStream nextPutAll:')'. |
|
867 |
||
868 |
"Created: 11.5.1996 / 14:27:09 / cg" |
|
343 | 869 |
"Modified: 16.5.1996 / 11:23:32 / cg" |
304 | 870 |
! ! |
871 |
||
872 |
!Text methodsFor:'private accessing'! |
|
873 |
||
874 |
string:aString emphasis:emphasis |
|
343 | 875 |
"set the string and emphasis. The emphasis is applied to all characters." |
876 |
||
304 | 877 |
string := aString. |
878 |
runs := RunArray new:string size withAll:emphasis |
|
879 |
||
880 |
" |
|
881 |
|t| |
|
882 |
||
883 |
t := Text new string:'hello' emphasis:#bold. |
|
884 |
t emphasisAt:2. |
|
885 |
" |
|
886 |
||
343 | 887 |
"Modified: 16.5.1996 / 11:24:03 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
888 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
889 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
890 |
string:aString emphasisCollection:emphasisCollection |
343 | 891 |
"set the string and emphasis collection. |
892 |
The emphasis collection contains per-character information." |
|
893 |
||
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
894 |
string := aString. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
895 |
runs := emphasisCollection asRunArray |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
896 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
897 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
898 |
|t| |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
899 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
900 |
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
|
901 |
t emphasisAt:2. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
902 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
903 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
904 |
"Created: 14.5.1996 / 14:03:29 / cg" |
343 | 905 |
"Modified: 16.5.1996 / 11:24:21 / cg" |
304 | 906 |
! ! |
907 |
||
908 |
!Text methodsFor:'queries'! |
|
909 |
||
307 | 910 |
bitsPerCharacter |
343 | 911 |
"return the underlying strings bitsPerCharacter |
912 |
(i.e. is it a regular String or a TwoByteString)" |
|
913 |
||
307 | 914 |
^ string bitsPerCharacter |
304 | 915 |
|
307 | 916 |
"Created: 12.5.1996 / 15:44:04 / cg" |
343 | 917 |
"Modified: 16.5.1996 / 11:24:54 / cg" |
304 | 918 |
! |
919 |
||
920 |
hasChangeOfEmphasis |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
921 |
"return true, if the receiver contains non-empty emphasis information" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
922 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
923 |
^ (runs notNil |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
924 |
and:[(runs findFirst:[:e | e notNil]) ~~ 0]) |
304 | 925 |
|
926 |
"Created: 11.5.1996 / 14:03:19 / cg" |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
927 |
"Modified: 14.5.1996 / 15:51:01 / cg" |
304 | 928 |
! |
929 |
||
307 | 930 |
heightOn:aGC |
931 |
"return the number of device units, required on aGC's device" |
|
932 |
||
933 |
^ aGC font heightOf:string |
|
934 |
||
935 |
"Created: 12.5.1996 / 11:02:03 / cg" |
|
936 |
! |
|
937 |
||
304 | 938 |
indexOf:aCharacter startingAt:index |
343 | 939 |
"search aCharacters index in the underlying string" |
940 |
||
304 | 941 |
^ string indexOf:aCharacter startingAt:index |
942 |
||
943 |
"Created: 11.5.1996 / 13:58:56 / cg" |
|
343 | 944 |
"Modified: 16.5.1996 / 11:25:12 / cg" |
304 | 945 |
! |
946 |
||
307 | 947 |
isText |
343 | 948 |
"return true if this is a Text object - always true here" |
949 |
||
307 | 950 |
^ true |
951 |
||
952 |
"Created: 12.5.1996 / 10:56:24 / cg" |
|
343 | 953 |
"Modified: 16.5.1996 / 11:25:29 / cg" |
307 | 954 |
! |
955 |
||
304 | 956 |
occurrencesOf:aCharacter |
343 | 957 |
"count & return the number of occurrences of aCharacter in the |
958 |
underlying string" |
|
959 |
||
304 | 960 |
^ string occurrencesOf:aCharacter |
961 |
||
962 |
"Created: 11.5.1996 / 13:58:46 / cg" |
|
343 | 963 |
"Modified: 16.5.1996 / 11:25:51 / cg" |
304 | 964 |
! |
965 |
||
966 |
size |
|
343 | 967 |
"return the number of characters in the underlying string" |
968 |
||
304 | 969 |
^ string size |
970 |
||
971 |
"Created: 11.5.1996 / 14:25:15 / cg" |
|
343 | 972 |
"Modified: 16.5.1996 / 11:26:08 / cg" |
304 | 973 |
! |
974 |
||
975 |
string |
|
343 | 976 |
"return the receiver without any emphasis information |
977 |
i.e. the underlying string." |
|
978 |
||
304 | 979 |
^ string |
980 |
||
981 |
"Created: 11.5.1996 / 13:58:38 / cg" |
|
343 | 982 |
"Modified: 16.5.1996 / 11:26:30 / cg" |
307 | 983 |
! |
984 |
||
985 |
widthOn:aGC |
|
986 |
"return the number of device units, required on aGC's device" |
|
987 |
||
360 | 988 |
|savedFont savedPaint boldFont italicFont bold italic pos f l device| |
307 | 989 |
|
990 |
savedFont := aGC basicFont on:aGC device. |
|
991 |
||
992 |
pos := 1. |
|
993 |
l := 0. |
|
994 |
runs runsDo:[:len :emphasis | |
|
995 |
emphasis isSymbol ifTrue:[ |
|
996 |
bold := emphasis == #bold. |
|
997 |
italic := emphasis == #italic. |
|
998 |
] ifFalse:[ |
|
308 | 999 |
(emphasis isNil |
1000 |
or:[emphasis isMemberOf:Association]) ifTrue:[ |
|
307 | 1001 |
bold := italic := false |
1002 |
] ifFalse:[ |
|
1003 |
bold := emphasis includesIdentical:#bold. |
|
1004 |
italic := emphasis includesIdentical:#italic. |
|
1005 |
] |
|
1006 |
]. |
|
1007 |
||
360 | 1008 |
device := aGC graphicsDevice. |
307 | 1009 |
bold ifTrue:[ |
1010 |
boldFont isNil ifTrue:[ |
|
360 | 1011 |
boldFont := savedFont asBold on:device |
307 | 1012 |
]. |
1013 |
f := boldFont. |
|
1014 |
] ifFalse:[ |
|
1015 |
italic ifTrue:[ |
|
1016 |
italicFont isNil ifTrue:[ |
|
360 | 1017 |
italicFont := savedFont asItalic on:device |
307 | 1018 |
]. |
1019 |
f := italicFont |
|
1020 |
] ifFalse:[ |
|
1021 |
f := savedFont |
|
1022 |
] |
|
1023 |
]. |
|
1024 |
l := l + (f widthOf:string from:pos to:(pos + len - 1)). |
|
1025 |
pos := pos + len |
|
1026 |
]. |
|
1027 |
||
1028 |
^ l |
|
1029 |
||
360 | 1030 |
"Modified: 28.5.1996 / 20:26:46 / cg" |
307 | 1031 |
! ! |
1032 |
||
1033 |
!Text methodsFor:'replacing'! |
|
1034 |
||
1035 |
replaceFrom:start to:stop with:aCollection startingAt:startIndex |
|
343 | 1036 |
"replace a range of characters, from another string or text object. |
1037 |
The corresponding characters' emphasis information is also copied." |
|
1038 |
||
307 | 1039 |
|idx| |
1040 |
||
1041 |
aCollection isString ifTrue:[ |
|
1042 |
aCollection hasChangeOfEmphasis ifTrue:[ |
|
1043 |
string replaceFrom:start to:stop with:aCollection startingAt:startIndex. |
|
1044 |
idx := startIndex. |
|
1045 |
start to:stop do:[:col | |
|
1046 |
self emphasisAt:col put:(aCollection emphasisAt:idx). |
|
1047 |
idx := idx + 1. |
|
1048 |
]. |
|
1049 |
^ self. |
|
1050 |
] |
|
1051 |
]. |
|
1052 |
||
1053 |
string replaceFrom:start to:stop with:aCollection startingAt:startIndex. |
|
1054 |
self emphasizeFrom:start to:stop with:nil |
|
1055 |
||
1056 |
" |
|
1057 |
((Text string:'hello') allBold emphasisAt:2 put:#italic) |
|
1058 |
copyFrom:1 to:3 |
|
1059 |
" |
|
1060 |
||
343 | 1061 |
"Modified: 16.5.1996 / 11:27:19 / cg" |
304 | 1062 |
! ! |
1063 |
||
1064 |
!Text class methodsFor:'documentation'! |
|
1065 |
||
1066 |
version |
|
384 | 1067 |
^ '$Header: /cvs/stx/stx/libbasic2/Text.st,v 1.18 1996-06-04 09:25:50 cg Exp $' |
304 | 1068 |
! ! |
314 | 1069 |
Text initialize! |