author | Claus Gittinger <cg@exept.de> |
Tue, 20 Jun 2017 08:56:36 +0200 | |
changeset 4426 | 24e3f90e84ed |
parent 4425 | efa00eb073ed |
child 4510 | d9cb833dfa01 |
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 |
" |
|
891 | 12 |
"{ Package: 'stx:libbasic2' }" |
13 |
||
3472 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
4426 | 16 |
CharacterArray subclass:#Text |
963
0d5ef474ea17
draw opaque - if backgroundCOlor is set
Claus Gittinger <cg@exept.de>
parents:
954
diff
changeset
|
17 |
instanceVariableNames:'string runs' |
4425 | 18 |
classVariableNames:'BackgroundColorEmphasis BoldEmphasis BoldOverlineEmphasis |
19 |
BoldUnderlineEmphasis BoldUnderwaveEmphasis ColorEmphasis |
|
20 |
EtchColorEmphasis FontEmphasis ItalicEmphasis |
|
21 |
ItalicUnderlineEmphasis ItalicUnderwaveEmphasis OverlineEmphasis |
|
22 |
ReverseEmphasis StrikeoutColorEmphasis StrikeoutEmphasis |
|
23 |
Subscript Superscript UnderlineColorEmphasis UnderlineEmphasis |
|
24 |
UnderwaveEmphasis' |
|
963
0d5ef474ea17
draw opaque - if backgroundCOlor is set
Claus Gittinger <cg@exept.de>
parents:
954
diff
changeset
|
25 |
poolDictionaries:'' |
0d5ef474ea17
draw opaque - if backgroundCOlor is set
Claus Gittinger <cg@exept.de>
parents:
954
diff
changeset
|
26 |
category:'Collections-Text' |
304 | 27 |
! |
28 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
29 |
!Text class methodsFor:'documentation'! |
304 | 30 |
|
31 |
copyright |
|
32 |
" |
|
33 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
34 |
All Rights Reserved |
|
35 |
||
36 |
This software is furnished under a license and may be used |
|
37 |
only in accordance with the terms of that license and with the |
|
38 |
inclusion of the above copyright notice. This software may not |
|
39 |
be provided or otherwise made available to, or used by, any |
|
40 |
other person. No title to or ownership of the software is |
|
41 |
hereby transferred. |
|
42 |
" |
|
43 |
||
44 |
! |
|
45 |
||
46 |
documentation |
|
47 |
" |
|
48 |
Texts add emphasis information to a string. |
|
4015 | 49 |
|
343 | 50 |
Texts and strings should behave interchanchably to the outside |
51 |
world, except that texts keep per-character emphasis information. |
|
4015 | 52 |
(strings return nil when asked for an element's emphasis). |
3689 | 53 |
Use #string, to get a text's underlying plain string without any emphasis |
343 | 54 |
information. |
304 | 55 |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
56 |
Currently, the following attributes are supported: |
4015 | 57 |
#bold |
58 |
#italic |
|
59 |
#underline |
|
60 |
#underwave |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
61 |
#strikeout |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
62 |
(#color -> aColor) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
63 |
(#backgroundColor -> aColor) |
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
64 |
(#underlineColor -> aColor) |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
65 |
(#strikeoutColor -> aColor) |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
66 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
67 |
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
|
68 |
See examples. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
69 |
|
3689 | 70 |
This class is a hack and may need some massage. |
304 | 71 |
|
72 |
[author:] |
|
73 |
Claus Gittinger |
|
74 |
||
75 |
[see also:] |
|
76 |
CharacterArray String RunArray |
|
77 |
" |
|
313 | 78 |
! |
79 |
||
80 |
examples |
|
81 |
" |
|
3689 | 82 |
In a textView: |
83 |
[exBegin] |
|
84 |
|t v| |
|
85 |
||
86 |
t := 'The quick brown fox jumps over the lazy dog' asText. |
|
4015 | 87 |
t emphasizeFrom:(t findString:'quick') |
3689 | 88 |
count:5 with:#bold. |
4015 | 89 |
|
90 |
t emphasizeFrom:(t findString:'brown') |
|
3689 | 91 |
count:9 with:(Array with:#color->(Color name:'brown') |
92 |
with:#bold). |
|
4015 | 93 |
t emphasizeFrom:(t findString:'lazy') |
3689 | 94 |
count:4 with:(Array with:#color->(Color red) |
95 |
with:#italic). |
|
4015 | 96 |
t emphasizeFrom:(t findString:'dog') |
3689 | 97 |
count:3 with:#underline. |
98 |
||
99 |
v := HVScrollableView for:EditTextView. |
|
100 |
v contents:t. |
|
101 |
||
102 |
v width:450. |
|
103 |
v open. |
|
104 |
[exEnd] |
|
105 |
||
106 |
[exBegin] |
|
107 |
|t v| |
|
4015 | 108 |
|
3689 | 109 |
t := 'a',('1' emphasizeAllWith:#subscript),'x',('3' emphasizeAllWith:#superscript) |
110 |
,'a',('2' emphasizeAllWith:#subscript),'x',('2' emphasizeAllWith:#superscript) |
|
111 |
,'a',('3' emphasizeAllWith:#subscript),'x',('n' emphasizeAllWith:#superscript). |
|
112 |
||
113 |
Dialog information:t. |
|
114 |
[exEnd] |
|
115 |
||
343 | 116 |
plain string (for comparison): |
313 | 117 |
[exBegin] |
3689 | 118 |
Dialog information:'hello' |
313 | 119 |
[exEnd] |
343 | 120 |
|
121 |
||
122 |
emphasized strings as dialog titles: |
|
313 | 123 |
[exBegin] |
4015 | 124 |
Dialog |
3689 | 125 |
information:((Text string:'hello') allBold) |
313 | 126 |
[exEnd] |
127 |
[exBegin] |
|
128 |
Dialog |
|
3689 | 129 |
information:(Text string:'hello' emphasis:#italic) |
313 | 130 |
[exEnd] |
131 |
[exBegin] |
|
132 |
Dialog |
|
3689 | 133 |
information:(Text string:'hello' emphasis:#(underline)) |
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
134 |
[exEnd] |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
135 |
[exBegin] |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
136 |
Dialog |
3689 | 137 |
information:(Text string:'hello' emphasis:#(underwave)) |
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
138 |
[exEnd] |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
139 |
[exBegin] |
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
140 |
Dialog |
3689 | 141 |
information:(Text string:'hello' emphasis:#(bold underline)) |
313 | 142 |
[exEnd] |
143 |
[exBegin] |
|
144 |
Dialog |
|
4015 | 145 |
information:(Text string:'hello' |
313 | 146 |
emphasis:(Array with:#bold |
147 |
with:#strikeout |
|
148 |
with:(#color->Color red))) |
|
149 |
[exEnd] |
|
150 |
[exBegin] |
|
151 |
Dialog |
|
4015 | 152 |
information:(Text string:'hello' |
759
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
153 |
emphasis:(Array with:(#color->Color black) |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
154 |
with:#underwave |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
155 |
with:(#underlineColor->Color red))) |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
156 |
[exEnd] |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
157 |
[exBegin] |
3527d6b2fb6d
new emphasises: #underlineColor->aColor and
Claus Gittinger <cg@exept.de>
parents:
758
diff
changeset
|
158 |
Dialog |
4015 | 159 |
information:(Text string:'hello' |
315 | 160 |
emphasis:(Array with:#bold |
161 |
with:#strikeout |
|
162 |
with:(#color->Color red) |
|
163 |
with:(#backgroundColor->Color yellow))) |
|
164 |
[exEnd] |
|
165 |
[exBegin] |
|
166 |
Dialog |
|
3689 | 167 |
information:(Text string:'hello' color:(Color red)) |
313 | 168 |
[exEnd] |
169 |
||
170 |
" |
|
304 | 171 |
! ! |
172 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
173 |
!Text class methodsFor:'initialization'! |
314 | 174 |
|
175 |
initialize |
|
176 |
"initialize the class" |
|
177 |
||
178 |
" |
|
179 |
consider this a kludge: |
|
180 |
I want to inherit behavior from CharacterArray, but not |
|
181 |
its implementation (indexed access). |
|
182 |
" |
|
2322 | 183 |
self flags:(Behavior flagRegular). |
184 |
||
4425 | 185 |
"/ |
186 |
"/ although it looks like, these enum-symbols cannot |
|
187 |
"/ be easily renamed (they already found their way into many user-app-classes) |
|
188 |
"/ |
|
2322 | 189 |
BackgroundColorEmphasis := #backgroundColor. |
190 |
ColorEmphasis := #color. |
|
191 |
ItalicEmphasis := #italic. |
|
192 |
BoldEmphasis := #bold. |
|
193 |
UnderlineEmphasis := #underline. |
|
194 |
UnderwaveEmphasis := #underwave. |
|
195 |
OverlineEmphasis := #overline. |
|
196 |
StrikeoutEmphasis := #strikeout. |
|
197 |
ReverseEmphasis := #reverse. |
|
198 |
BoldUnderlineEmphasis := #boldUnderline. |
|
199 |
BoldOverlineEmphasis := #boldOverline. |
|
200 |
BoldUnderwaveEmphasis := #boldUnderwave. |
|
201 |
ItalicUnderlineEmphasis := #italicUnderline. |
|
202 |
ItalicUnderwaveEmphasis := #italicUnderwave. |
|
203 |
UnderlineColorEmphasis := #underlineColor. |
|
204 |
StrikeoutColorEmphasis := #strikeoutColor. |
|
205 |
EtchColorEmphasis := #etchColor. |
|
3158 | 206 |
FontEmphasis := #font. |
3689 | 207 |
Superscript := #superscript. |
208 |
Subscript := #subscript. |
|
314 | 209 |
|
210 |
" |
|
211 |
Text initialize |
|
212 |
" |
|
213 |
||
4425 | 214 |
"Modified: / 12-05-1996 / 17:53:50 / cg" |
215 |
"Modified (comment): / 20-06-2017 / 08:40:53 / cg" |
|
314 | 216 |
! ! |
217 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
218 |
!Text class methodsFor:'instance creation'! |
304 | 219 |
|
220 |
fromString:aString |
|
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
221 |
"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
|
222 |
without emphasis." |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
223 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
224 |
^ super new string:aString emphasis:nil |
304 | 225 |
|
226 |
" |
|
227 |
Text fromString:'hello' |
|
228 |
" |
|
229 |
||
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
230 |
"Modified: 12.5.1996 / 17:05:34 / cg" |
304 | 231 |
! |
232 |
||
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
233 |
new |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
234 |
"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
|
235 |
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
|
236 |
|
3598 | 237 |
^ super new string:'' emphasis:nil |
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
238 |
|
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
239 |
"Text new" |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
240 |
|
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
241 |
"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
|
242 |
"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
|
243 |
! |
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
244 |
|
307 | 245 |
new:size |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
246 |
"create a new empty Text instance. |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
247 |
Redefined for string-protocol compatibility" |
307 | 248 |
|
249 |
^ self string:(String new:size) |
|
250 |
||
251 |
"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
|
252 |
"Modified: 12.5.1996 / 17:05:17 / cg" |
307 | 253 |
! |
254 |
||
304 | 255 |
string:aString |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
256 |
"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
|
257 |
without emphasis." |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
258 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
259 |
^ super new string:aString emphasis:nil |
304 | 260 |
|
261 |
" |
|
262 |
Text string:'hello' |
|
263 |
" |
|
264 |
||
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
265 |
"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
|
266 |
! |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
267 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
268 |
string:aString color:aColor |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
269 |
"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
|
270 |
which are colored as aColor (only the foregroundColor is affected). |
496 | 271 |
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
|
272 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
273 |
^ 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
|
274 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
275 |
" |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
276 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
277 |
information:(Text string:'hello' color:(Color red)) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
278 |
" |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
279 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
280 |
"Created: 12.5.1996 / 17:03:20 / cg" |
496 | 281 |
"Modified: 27.2.1997 / 10:13:36 / cg" |
344
72fe9b7ae4b5
added #string:color:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
343
diff
changeset
|
282 |
! |
72fe9b7ae4b5
added #string:color:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
343
diff
changeset
|
283 |
|
304 | 284 |
string:aString emphasis:attribute |
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
285 |
"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
|
286 |
which are emphasized as described by attribute." |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
287 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
288 |
^ super new string:aString emphasis:attribute |
304 | 289 |
|
290 |
" |
|
291 |
Text string:'hello' emphasis:#bold |
|
309
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
292 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
293 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
294 |
information:(Text string:'hello' emphasis:#bold) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
295 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
296 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
297 |
information:(Text string:'hello' emphasis:#italic) |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
298 |
|
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
299 |
Dialog |
6458ec5cc033
added convenient #string:color: instance creation message
Claus Gittinger <cg@exept.de>
parents:
308
diff
changeset
|
300 |
information:(Text string:'hello' emphasis:#underline) |
310 | 301 |
|
302 |
Dialog |
|
303 |
information:(Text string:'hello' emphasis:#strikeout) |
|
304 | 304 |
" |
305 |
||
310 | 306 |
"Modified: 12.5.1996 / 17:16:03 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
307 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
308 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
309 |
string:aString emphasisCollection:attributeCollection |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
310 |
"create a Text instance, for the characters in aString, |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
311 |
which are individually emphasized as described by attributeCollection." |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
312 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
313 |
^ super new string:aString emphasisCollection:attributeCollection |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
314 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
315 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
316 |
Text |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
317 |
string:'hello' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
318 |
emphasisCollection:#(#bold #bold #italic #italic #italic) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
319 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
320 |
Dialog |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
321 |
information:(Text |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
322 |
string:'hello' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
323 |
emphasisCollection:#(#bold #bold #italic #italic #(#underline italic))) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
324 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
325 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
326 |
"Created: 14.5.1996 / 14:02:18 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
327 |
"Modified: 14.5.1996 / 15:01:28 / cg" |
345
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
328 |
! |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
329 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
330 |
string:aString foregroundColor:fgColor backgroundColor:bgColor |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
331 |
"create a Text instance, for the characters in aString, |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
332 |
which are colored in fgColor on bgColor. |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
333 |
This is a shortCut for creating an emphasis of |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
334 |
#( #color->fgColor) (#backgroundColor->bgColor)" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
335 |
|
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
336 |
^ super new |
345
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
337 |
string:aString |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
338 |
emphasis:(Array with:#color->fgColor |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
339 |
with:#backgroundColor->bgColor) |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
340 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
341 |
" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
342 |
Dialog |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
343 |
information:(Text string:'hello' |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
344 |
foregroundColor:(Color red) |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
345 |
backgroundColor:(Color yellow)) |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
346 |
" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
347 |
|
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
348 |
"Modified: 11.5.1996 / 14:21:01 / cg" |
062032f9e401
renamed to #string:foregroundColor:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
344
diff
changeset
|
349 |
"Created: 16.5.1996 / 12:37:24 / cg" |
395 | 350 |
! |
351 |
||
352 |
string:aString runs:aRun |
|
353 |
"create a Text instance, for the characters in aString, |
|
354 |
which are individually emphasized as described by attributeCollection." |
|
355 |
||
466
a806fe2ac753
'Text new' noe returns an empty text instead of an invalid text
Stefan Vogel <sv@exept.de>
parents:
454
diff
changeset
|
356 |
^ super new string:aString emphasisCollection:aRun. |
2016
9ad5248e5920
Text class>>#writeStream - answer a TextStream
Stefan Vogel <sv@exept.de>
parents:
1780
diff
changeset
|
357 |
! |
9ad5248e5920
Text class>>#writeStream - answer a TextStream
Stefan Vogel <sv@exept.de>
parents:
1780
diff
changeset
|
358 |
|
2259
d9b94e7b06a5
+uninitializedNew for compatibility
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
359 |
uninitializedNew:size |
d9b94e7b06a5
+uninitializedNew for compatibility
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
360 |
"for compatibility only" |
d9b94e7b06a5
+uninitializedNew for compatibility
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
361 |
|
d9b94e7b06a5
+uninitializedNew for compatibility
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
362 |
^ self new:size |
d9b94e7b06a5
+uninitializedNew for compatibility
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
363 |
! |
d9b94e7b06a5
+uninitializedNew for compatibility
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
364 |
|
2867 | 365 |
writeStreamClass |
4236 | 366 |
"the type of stream used in writeStream" |
2016
9ad5248e5920
Text class>>#writeStream - answer a TextStream
Stefan Vogel <sv@exept.de>
parents:
1780
diff
changeset
|
367 |
|
2867 | 368 |
^ TextStream |
304 | 369 |
! ! |
370 |
||
2322 | 371 |
!Text class methodsFor:'emphasis constants'! |
372 |
||
373 |
backgroundColorEmphasis |
|
374 |
^ BackgroundColorEmphasis |
|
375 |
! |
|
376 |
||
4423 | 377 |
boldEmphasis |
378 |
^ BoldEmphasis |
|
379 |
||
380 |
"Created: / 20-06-2017 / 08:13:07 / cg" |
|
381 |
! |
|
382 |
||
383 |
colorEmphasis |
|
384 |
^ ColorEmphasis |
|
385 |
||
386 |
"Created: / 20-06-2017 / 08:12:40 / cg" |
|
387 |
! |
|
388 |
||
389 |
etchColorEmphasis |
|
390 |
^ EtchColorEmphasis |
|
391 |
||
392 |
"Created: / 20-06-2017 / 08:14:30 / cg" |
|
393 |
! |
|
394 |
||
2322 | 395 |
foregroundColorEmphasis |
396 |
^ ColorEmphasis |
|
4423 | 397 |
! |
398 |
||
399 |
italicEmphasis |
|
400 |
^ ItalicEmphasis |
|
401 |
||
402 |
"Created: / 20-06-2017 / 08:12:53 / cg" |
|
403 |
! |
|
404 |
||
405 |
overlineEmphasis |
|
406 |
^ OverlineEmphasis |
|
407 |
||
408 |
"Created: / 20-06-2017 / 08:13:43 / cg" |
|
409 |
! |
|
410 |
||
411 |
reverseEmphasis |
|
412 |
^ ReverseEmphasis |
|
413 |
||
414 |
"Created: / 20-06-2017 / 08:14:05 / cg" |
|
415 |
! |
|
416 |
||
417 |
strikeoutEmphasis |
|
418 |
^ StrikeoutEmphasis |
|
419 |
||
420 |
"Created: / 20-06-2017 / 08:13:53 / cg" |
|
421 |
! |
|
422 |
||
423 |
subscriptEmphasis |
|
424 |
^ Subscript |
|
425 |
||
426 |
"Created: / 20-06-2017 / 08:11:41 / cg" |
|
427 |
! |
|
428 |
||
429 |
superscriptEmphasis |
|
430 |
^ Superscript |
|
431 |
||
432 |
"Created: / 20-06-2017 / 08:11:27 / cg" |
|
433 |
! |
|
434 |
||
435 |
underlineEmphasis |
|
436 |
^ UnderlineEmphasis |
|
437 |
||
438 |
"Created: / 20-06-2017 / 08:13:17 / cg" |
|
439 |
! |
|
440 |
||
441 |
underwaveEmphasis |
|
442 |
^ UnderwaveEmphasis |
|
443 |
||
444 |
"Created: / 20-06-2017 / 08:13:30 / cg" |
|
2322 | 445 |
! ! |
446 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
447 |
!Text class methodsFor:'emphasis helper'! |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
448 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
449 |
addEmphasis:e1 to:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
450 |
"merge two emphasis's into one" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
451 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
452 |
|ne| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
453 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
454 |
e1 isNil ifTrue:[^ e2]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
455 |
e2 isNil ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
456 |
e1 == e2 ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
457 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
458 |
(e1 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
459 |
or:[e1 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
460 |
(e2 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
461 |
or:[e2 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
462 |
^ Array with:e1 with:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
463 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
464 |
(e2 includes:e1) ifTrue:[^ e2]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
465 |
^ e2 copyWith:e1 |
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 |
(e2 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
468 |
or:[e2 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
469 |
(e1 includes:e2) ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
470 |
^ e1 copyWith:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
471 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
472 |
"/ ould use: |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
473 |
"/ ^ (e1 asSet addAll:e2; asArray) |
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 |
"/ but we do it manually, to preserve the |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
476 |
"/ order. (should create longer runs, while editing) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
477 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
478 |
ne := e1. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
479 |
e2 do:[:e | |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
480 |
(ne includes:e) ifFalse:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
481 |
ne := ne copyWith:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
482 |
] |
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. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
485 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
486 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
487 |
Text addEmphasis:#bold to:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
488 |
Text addEmphasis:#bold to:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
489 |
Text addEmphasis:#bold to:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
490 |
Text addEmphasis:#italic to:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
491 |
Text addEmphasis:#(italic strikeout) to:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
492 |
Text addEmphasis:#(italic strikeout) to:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
493 |
Text addEmphasis:#(italic strikeout) to:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
494 |
Text addEmphasis:(#color->Color red) to:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
495 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
496 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
497 |
"Modified: 14.5.1996 / 17:15:44 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
498 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
499 |
|
339 | 500 |
emphasis:e1 includes:e2 |
501 |
"return true, if e1 includes e2. |
|
502 |
e2 should be a single emphasis." |
|
503 |
||
504 |
e1 isNil ifTrue:[^ false]. |
|
505 |
e2 isNil ifTrue:[^ false]. |
|
506 |
e1 == e2 ifTrue:[^ true]. |
|
507 |
||
754 | 508 |
e1 isSymbol ifTrue:[ |
509 |
^ false |
|
510 |
]. |
|
511 |
e1 isAssociation ifTrue:[ |
|
512 |
^ e1 key == e2 |
|
513 |
]. |
|
339 | 514 |
(e1 isSymbol |
515 |
or:[e1 isAssociation]) ifTrue:[ |
|
516 |
^ false |
|
517 |
]. |
|
1780 | 518 |
e2 isSymbol ifTrue:[ |
519 |
^ (e1 includes:e2) or:[e1 contains:[:e |e isAssociation and:[e key == e2]]]. |
|
520 |
]. |
|
521 |
e2 isAssociation ifTrue:[ |
|
522 |
^ (e1 includes:e2 key) or:[e1 contains:[:e |e isAssociation and:[e key == e2 key]]]. |
|
339 | 523 |
]. |
524 |
^ false |
|
525 |
||
526 |
" |
|
527 |
Text emphasis:#bold includes:#bold |
|
1780 | 528 |
Text emphasis:#bold includes:#italic |
339 | 529 |
Text emphasis:#(italic strikeout) includes:#bold |
530 |
Text emphasis:#(italic strikeout) includes:#italic |
|
754 | 531 |
Text emphasis:(#color->Color red) includes:#color |
339 | 532 |
" |
533 |
||
534 |
"Modified: 14.5.1996 / 17:45:11 / cg" |
|
535 |
! |
|
536 |
||
407 | 537 |
extractEmphasis:key from:e |
538 |
"if key is included in the emphasis, e then return the key. |
|
539 |
Otherwise, if a n association with that key is included, return the value. |
|
540 |
Otherwise, return nil." |
|
541 |
||
542 |
e isNil ifTrue:[^ nil]. |
|
543 |
key == e ifTrue:[^ e]. |
|
754 | 544 |
e isSymbol ifTrue:[^ nil]. |
407 | 545 |
|
546 |
e isAssociation ifTrue:[ |
|
547 |
e key == key ifTrue:[^ e value]. |
|
548 |
^ nil |
|
549 |
]. |
|
550 |
e do:[:entry | |
|
754 | 551 |
entry == key ifTrue:[^ key]. |
407 | 552 |
entry isAssociation ifTrue:[ |
553 |
entry key == key ifTrue:[ |
|
554 |
^ entry value |
|
555 |
] |
|
556 |
] |
|
557 |
]. |
|
558 |
^ nil |
|
559 |
||
560 |
" |
|
561 |
Text extractEmphasis:#bold from:#bold |
|
562 |
Text extractEmphasis:#bold from:#italic |
|
563 |
Text extractEmphasis:#bold from:#(italic strikeout) |
|
564 |
Text extractEmphasis:#bold from:#(italic bold) |
|
565 |
Text extractEmphasis:#color from:(#color->Color red) |
|
566 |
Text extractEmphasis:#color from:(#foo->Color red) |
|
567 |
" |
|
568 |
||
569 |
"Modified: 14.5.1996 / 17:45:11 / cg" |
|
570 |
"Created: 11.7.1996 / 09:49:58 / cg" |
|
571 |
! |
|
572 |
||
2731
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
573 |
removeEmphasis:emToRemove from:empArg |
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
574 |
"remove an emphasis; if it was not in empArg, do nothing" |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
575 |
|
2731
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
576 |
|ne idx emp| |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
577 |
|
2731
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
578 |
emp := empArg. |
1068 | 579 |
emToRemove isNil ifTrue:[^ emp]. |
580 |
emp isNil ifTrue:[^ emp]. |
|
581 |
emToRemove == emp ifTrue:[^ nil]. |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
582 |
|
1068 | 583 |
emp isSymbol ifTrue:[ |
584 |
emToRemove isSymbol ifTrue:[^ emp]. "/ knowing they are not identical |
|
585 |
emToRemove isAssociation ifTrue:[ |
|
586 |
emToRemove key == emp ifTrue:[^ nil]. |
|
587 |
^ emp |
|
755 | 588 |
]. |
1068 | 589 |
(emToRemove includes:emp) ifTrue:[^ nil]. |
590 |
^ emp |
|
755 | 591 |
]. |
1068 | 592 |
emp isAssociation ifTrue:[ |
593 |
emToRemove isSymbol ifTrue:[ |
|
594 |
emp key == emToRemove ifTrue:[^ nil]. |
|
595 |
^ emp |
|
755 | 596 |
]. |
1068 | 597 |
emToRemove isAssociation ifTrue:[ |
598 |
emToRemove key == emp key ifTrue:[^ nil]. |
|
599 |
^ emp |
|
755 | 600 |
]. |
1068 | 601 |
(emToRemove includes:emp) ifTrue:[^ nil]. |
602 |
^ emp |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
603 |
]. |
834
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
604 |
"/ e2 must be a collection |
1068 | 605 |
(emToRemove isSymbol |
606 |
or:[emToRemove isAssociation]) ifTrue:[ |
|
607 |
(emp includes:emToRemove) ifTrue:[ |
|
608 |
ne := emp copyWithout:emToRemove. |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
609 |
ne size == 1 ifTrue:[^ ne at:1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
610 |
ne size == 0 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
611 |
^ ne |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
612 |
]. |
834
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
613 |
|
1068 | 614 |
idx := emp findFirst:[:em | em isAssociation and:[em key == emToRemove]]. |
2731
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
615 |
(idx ~~ 0) ifTrue:[ |
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
616 |
emp := emp copyWithoutIndex:idx. |
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
617 |
[ |
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
618 |
idx := emp findFirst:[:em | em isAssociation and:[em key == emToRemove]] startingAt:idx. |
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
619 |
idx ~~ 0 |
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
620 |
] whileTrue:[ |
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
621 |
emp := emp copyWithoutIndex:idx. |
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
622 |
] |
834
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
623 |
]. |
1068 | 624 |
^ emp |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
625 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
626 |
|
754 | 627 |
"/ could use: |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
628 |
"/ ^ (e2 asSet removeAll:e1; asArray) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
629 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
630 |
"/ but we do it manually, to preserve the |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
631 |
"/ order. (should create longer runs, while editing) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
632 |
|
1068 | 633 |
ne := emp. |
634 |
emToRemove do:[:e | |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
635 |
(ne includes:e) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
636 |
ne := ne copyWithout:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
637 |
] |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
638 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
639 |
ne size == 1 ifTrue:[^ ne at:1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
640 |
ne size == 0 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
641 |
^ ne. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
642 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
643 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
644 |
Text removeEmphasis:#bold from:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
645 |
Text removeEmphasis:#bold from:#italic |
1067 | 646 |
Text removeEmphasis:#bold from:#(italic strikeout) |
3472 | 647 |
Text removeEmphasis:#bold from:#(italic bold strikeout) |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
648 |
Text removeEmphasis:#italic from:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
649 |
Text removeEmphasis:#(italic strikeout) from:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
650 |
Text removeEmphasis:#(italic strikeout) from:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
651 |
Text removeEmphasis:#(italic strikeout) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
652 |
Text removeEmphasis:#(italic strikeout bold) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
653 |
Text removeEmphasis:#(italic strikeout bold underline) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
654 |
Text removeEmphasis:(#color->Color red) from:#(bold underline) |
756 | 655 |
Text removeEmphasis:(#color->Color red) from:(#color->Color red) |
1067 | 656 |
Text removeEmphasis:#color from:(#color->Color red) |
657 |
Text removeEmphasis:#color from:(#backgroundColor->Color red) |
|
754 | 658 |
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
|
659 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
660 |
|
2731
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
661 |
"Modified: / 25-01-2001 / 15:24:46 / ps" |
6dec3016c2a5
changed: #removeEmphasis:from:
Claus Gittinger <cg@exept.de>
parents:
2675
diff
changeset
|
662 |
"Modified (comment): / 06-03-2012 / 18:23:32 / cg" |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
663 |
! ! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
664 |
|
735 | 665 |
!Text methodsFor:'accessing'! |
666 |
||
667 |
at:characterIndex |
|
668 |
"return the plain character at characterIndex" |
|
669 |
||
670 |
^ string at:characterIndex |
|
671 |
||
672 |
"Created: 11.5.1996 / 14:25:41 / cg" |
|
673 |
"Modified: 16.5.1996 / 11:15:33 / cg" |
|
674 |
! |
|
675 |
||
676 |
at:characterIndex put:aCharacter |
|
677 |
"change the character at characterIndex to be aCharacter. |
|
678 |
The emphasis (if any) of that character remains unchanged." |
|
679 |
||
680 |
^ string at:characterIndex put:aCharacter |
|
681 |
||
682 |
"Created: 11.5.1996 / 14:25:49 / cg" |
|
683 |
"Modified: 16.5.1996 / 11:15:57 / cg" |
|
2734 | 684 |
! |
685 |
||
686 |
byteAt:characterIndex |
|
687 |
"return the plain character at characterIndex" |
|
688 |
||
689 |
^ string byteAt:characterIndex |
|
690 |
||
691 |
"Created: 11.5.1996 / 14:25:41 / cg" |
|
692 |
"Modified: 16.5.1996 / 11:15:33 / cg" |
|
693 |
! |
|
694 |
||
695 |
byteAt:characterIndex put:aCharacter |
|
696 |
"change the character at characterIndex to be aCharacter. |
|
697 |
The emphasis (if any) of that character remains unchanged." |
|
698 |
||
699 |
^ string byteAt:characterIndex put:aCharacter |
|
700 |
||
701 |
"Created: 11.5.1996 / 14:25:49 / cg" |
|
702 |
"Modified: 16.5.1996 / 11:15:57 / cg" |
|
735 | 703 |
! ! |
704 |
||
304 | 705 |
!Text methodsFor:'comparing'! |
706 |
||
707 |
= aStringOrText |
|
708 |
"compare the receiver and the argument, ignoring emphasis" |
|
709 |
||
384 | 710 |
aStringOrText isString ifFalse:[^ false]. |
304 | 711 |
^ string = aStringOrText string |
712 |
||
713 |
||
714 |
" |
|
715 |
'hello' asText = 'hello' |
|
716 |
'hello' asText = 'hello' asText |
|
717 |
'hello' asText allBold = 'hello' |
|
718 |
" |
|
719 |
||
384 | 720 |
"Modified: 4.6.1996 / 11:14:58 / cg" |
662 | 721 |
! |
722 |
||
723 |
hash |
|
724 |
"return a suitable hashcode (req'd since = is redefined)" |
|
725 |
||
726 |
^ string hash |
|
727 |
||
728 |
"Created: / 19.6.1998 / 04:15:57 / cg" |
|
304 | 729 |
! ! |
730 |
||
731 |
!Text methodsFor:'converting'! |
|
732 |
||
3662 | 733 |
asSingleByteString |
734 |
^ self class string:string asSingleByteString runs:runs. |
|
735 |
||
736 |
" |
|
737 |
'hello world' asUnicodeString asText asSingleByteString |
|
738 |
" |
|
739 |
! |
|
740 |
||
304 | 741 |
asText |
1645 | 742 |
"return a Text-object (string with emphasis) from myself. |
743 |
I am already a text object." |
|
343 | 744 |
|
304 | 745 |
^ self |
746 |
||
747 |
"Created: 11.5.1996 / 14:08:36 / cg" |
|
343 | 748 |
"Modified: 16.5.1996 / 11:15:12 / cg" |
304 | 749 |
! ! |
750 |
||
751 |
!Text methodsFor:'copying'! |
|
752 |
||
753 |
, aStringOrText |
|
2733 | 754 |
"concatenate the receiver's characters with the argument's characters, |
343 | 755 |
and return string or text object containing those characters. |
756 |
If either the receiver or the argument contains emphasis information, |
|
2733 | 757 |
a text object will be returned. |
758 |
Otherwise, a string (i.e. without emphasis) is returned." |
|
304 | 759 |
|
626 | 760 |
|newRuns| |
761 |
||
758 | 762 |
aStringOrText isCharacter ifTrue:[ |
763 |
^ self , aStringOrText asString |
|
764 |
]. |
|
615 | 765 |
aStringOrText hasChangeOfEmphasis ifTrue:[ |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
766 |
^ self species new |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
767 |
string:(string , aStringOrText) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
768 |
emphasisCollection:(runs , aStringOrText emphasisCollection) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
769 |
]. |
615 | 770 |
runs notNil "self hasChangeOfEmphasis" ifTrue:[ |
626 | 771 |
newRuns := runs copyFrom:1 to:(runs size). |
2852 | 772 |
newRuns add:nil withOccurrences:(aStringOrText size). |
408 | 773 |
^ self species new |
774 |
string:(string , aStringOrText) |
|
2852 | 775 |
emphasisCollection:newRuns |
408 | 776 |
]. |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
777 |
^ string , aStringOrText string |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
778 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
779 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
780 |
('hello' asText allBold) , ' world' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
781 |
'hello' , (' world' asText allBold) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
782 |
'hello' , ' world' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
783 |
('hello' asText allBold) , (' world' asText allBold) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
784 |
" |
304 | 785 |
|
2733 | 786 |
"Modified: / 31-03-1998 / 16:34:04 / cg" |
787 |
"Modified (comment): / 01-04-2012 / 13:20:02 / cg" |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
788 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
789 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
790 |
concatenateFromString:aString |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
791 |
"return the concatenation of aString and myself. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
792 |
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
|
793 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
794 |
self hasChangeOfEmphasis ifTrue:[ |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
795 |
^ self species new |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
796 |
string:(aString , string) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
797 |
emphasisCollection:((RunArray new:(aString size)) , runs). |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
798 |
]. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
799 |
^ aString , string |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
800 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
801 |
"Modified: 14.5.1996 / 15:56:05 / cg" |
394 | 802 |
! |
803 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
804 |
copyFrom:start to:stop |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
805 |
"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
|
806 |
at stop, anInteger." |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
807 |
|
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
808 |
self hasChangeOfEmphasis ifTrue:[ |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
809 |
^ self species new |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
810 |
string:(string copyFrom:start to:stop) |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
811 |
emphasisCollection:(runs copyFrom:start to:stop). |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
812 |
]. |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
813 |
^ string copyFrom:start to:stop |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
814 |
|
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
815 |
"Modified: 14.5.1996 / 15:56:05 / cg" |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
816 |
"Created: 22.10.1996 / 21:01:16 / cg" |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
817 |
! |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
818 |
|
394 | 819 |
postCopy |
820 |
string := string copy. |
|
3598 | 821 |
runs := runs copy. |
822 |
||
823 |
" |
|
824 |
|t| |
|
825 |
||
826 |
t := 'hello' emphasizeAllWith:#bold. |
|
827 |
t inspect. t copy inspect. |
|
828 |
t emphasisAllRemove:#bold. |
|
829 |
" |
|
307 | 830 |
! ! |
831 |
||
832 |
!Text methodsFor:'displaying'! |
|
833 |
||
4082 | 834 |
displayOn:aGCOrView x:x0 y:yBase opaque:opaqueWanted |
3689 | 835 |
"display the receiver on a GC. |
836 |
This is one of the ugliest pieces of code..." |
|
307 | 837 |
|
1000 | 838 |
|savedFont savedPaint savedFgPaint savedBgPaint font color boldFont italicFont boldItalicFont |
839 |
bgPaint etchColor ulPaint strikePaint |
|
3158 | 840 |
wasItalic overline altFont |
3689 | 841 |
bold italic underline underwave strikeout reverse subOrSuperscript |
310 | 842 |
pos "{ Class: SmallInteger }" |
843 |
endPos "{ Class: SmallInteger }" |
|
3689 | 844 |
x y |
4082 | 845 |
len "{ Class: SmallInteger }" |
4243 | 846 |
bgFill |
963
0d5ef474ea17
draw opaque - if backgroundCOlor is set
Claus Gittinger <cg@exept.de>
parents:
954
diff
changeset
|
847 |
yL k value device opaque| |
307 | 848 |
|
4082 | 849 |
savedFont := aGCOrView basicFont. |
850 |
savedPaint := aGCOrView paint. |
|
851 |
savedBgPaint := aGCOrView backgroundPaint. |
|
307 | 852 |
|
963
0d5ef474ea17
draw opaque - if backgroundCOlor is set
Claus Gittinger <cg@exept.de>
parents:
954
diff
changeset
|
853 |
opaque := opaqueWanted. |
4082 | 854 |
device := aGCOrView graphicsDevice. |
705 | 855 |
|
307 | 856 |
pos := 1. |
857 |
x := x0. |
|
4082 | 858 |
bold := italic := underline := underwave := strikeout := reverse := overline := false. |
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
859 |
|
3598 | 860 |
runs size > string size ifTrue:[ |
861 |
Transcript showCR:'inconsistent text: runs size > string size'. |
|
862 |
runs := runs copyTo:(string size) |
|
863 |
]. |
|
864 |
||
4082 | 865 |
runs runsDo:[:runLen :emphasis | |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
866 |
wasItalic := italic. |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
867 |
color := savedPaint. |
4082 | 868 |
bold := italic := underline := underwave := strikeout := reverse := overline := false. |
3689 | 869 |
altFont := subOrSuperscript := nil. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
870 |
bgPaint := savedBgPaint. |
3689 | 871 |
y := yBase. |
872 |
||
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
873 |
emphasis isSymbol ifTrue:[ |
2322 | 874 |
emphasis == BoldEmphasis ifTrue:[bold := true] |
875 |
ifFalse:[emphasis == ItalicEmphasis ifTrue:[italic := true] |
|
876 |
ifFalse:[emphasis == UnderlineEmphasis ifTrue:[underline := true] |
|
877 |
ifFalse:[emphasis == OverlineEmphasis ifTrue:[overline := true] "MB:added" |
|
878 |
ifFalse:[emphasis == UnderwaveEmphasis ifTrue:[underwave := true] |
|
879 |
ifFalse:[emphasis == StrikeoutEmphasis ifTrue:[strikeout := true] |
|
880 |
ifFalse:[emphasis == ReverseEmphasis ifTrue:[reverse := true] |
|
881 |
ifFalse:[emphasis == BoldUnderlineEmphasis ifTrue:[bold := underline := true] |
|
882 |
ifFalse:[emphasis == BoldOverlineEmphasis ifTrue:[bold := overline := true] "MB:added" |
|
883 |
ifFalse:[emphasis == BoldUnderwaveEmphasis ifTrue:[bold := underwave := true] |
|
884 |
ifFalse:[emphasis == ItalicUnderlineEmphasis ifTrue:[italic := underline := true] |
|
885 |
ifFalse:[emphasis == ItalicUnderwaveEmphasis ifTrue:[italic := underwave := true] |
|
3689 | 886 |
ifFalse:[emphasis == Subscript ifTrue:[subOrSuperscript := Subscript] |
887 |
ifFalse:[emphasis == Superscript ifTrue:[subOrSuperscript := Superscript] |
|
888 |
]]]]]]]]]]]]] |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
889 |
] ifFalse:[ |
4082 | 890 |
emphasis isAssociation ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
891 |
value := emphasis value. |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
892 |
value notNil ifTrue:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
893 |
k := emphasis key. |
2322 | 894 |
k == ColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
895 |
color := value onDevice:device. |
2323 | 896 |
"/ emphasis value:color. |
2322 | 897 |
] ifFalse:[k == BackgroundColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
898 |
bgPaint := value onDevice:device. |
2323 | 899 |
"/ emphasis value:bgPaint. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
900 |
opaque := true. |
2322 | 901 |
] ifFalse:[k == UnderlineColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
902 |
ulPaint := value onDevice:device. |
2323 | 903 |
"/ emphasis value:ulPaint. |
2322 | 904 |
] ifFalse:[k == StrikeoutColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
905 |
strikePaint := value onDevice:device. |
2323 | 906 |
"/ emphasis value:strikePaint. |
2322 | 907 |
] ifFalse:[k == EtchColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
908 |
etchColor := value onDevice:device. |
2323 | 909 |
"/ emphasis value:etchColor. |
3158 | 910 |
] ifFalse:[k == FontEmphasis ifTrue:[ |
911 |
altFont := value onDevice:device. |
|
912 |
"/ emphasis value:altFont. |
|
913 |
]]]]]] |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
914 |
] |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
915 |
] ifFalse:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
916 |
emphasis notNil ifTrue:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
917 |
emphasis do:[:entry | |
2322 | 918 |
entry == BoldEmphasis ifTrue:[bold := true] |
919 |
ifFalse:[entry == ItalicEmphasis ifTrue:[italic := true] |
|
920 |
ifFalse:[entry == UnderlineEmphasis ifTrue:[underline := true] |
|
921 |
ifFalse:[entry == OverlineEmphasis ifTrue:[overline := true] |
|
922 |
ifFalse:[entry == UnderwaveEmphasis ifTrue:[underwave := true] |
|
923 |
ifFalse:[entry == StrikeoutEmphasis ifTrue:[strikeout := true] |
|
924 |
ifFalse:[entry == ReverseEmphasis ifTrue:[reverse := true] |
|
925 |
ifFalse:[entry == BoldUnderlineEmphasis ifTrue:[bold := underline := true] |
|
926 |
ifFalse:[emphasis == BoldUnderwaveEmphasis ifTrue:[bold := underwave := true] |
|
927 |
ifFalse:[entry == ItalicUnderlineEmphasis ifTrue:[italic := underline := true] |
|
928 |
ifFalse:[emphasis == ItalicUnderwaveEmphasis ifTrue:[italic := underwave := true] |
|
3689 | 929 |
ifFalse:[emphasis == Subscript ifTrue:[subOrSuperscript := Subscript] |
930 |
ifFalse:[emphasis == Superscript ifTrue:[subOrSuperscript := Superscript] |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
931 |
ifFalse:[ |
4082 | 932 |
entry isAssociation ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
933 |
value := entry value. |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
934 |
value notNil ifTrue:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
935 |
k := entry key. |
2322 | 936 |
k == ColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
937 |
color := value onDevice:device. |
2323 | 938 |
"/ entry value:color. |
2322 | 939 |
] ifFalse:[k == BackgroundColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
940 |
bgPaint := value onDevice:device. |
2323 | 941 |
"/ entry value:bgPaint. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
942 |
opaque := true. |
2322 | 943 |
] ifFalse:[k == UnderlineColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
944 |
ulPaint := value onDevice:device. |
2323 | 945 |
"/ entry value:ulPaint. |
2322 | 946 |
] ifFalse:[k == StrikeoutColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
947 |
strikePaint := value onDevice:device. |
2323 | 948 |
"/ entry value:strikePaint. |
2322 | 949 |
] ifFalse:[k == EtchColorEmphasis ifTrue:[ |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
950 |
etchColor := value onDevice:device. |
2323 | 951 |
"/ entry value:etchColor. |
3158 | 952 |
] ifFalse:[k == FontEmphasis ifTrue:[ |
953 |
altFont := value onDevice:device. |
|
954 |
"/ entry value:altFont. |
|
955 |
]]]]]] |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
956 |
] |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
957 |
] |
3689 | 958 |
]]]]]]]]]]]]] |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
959 |
] |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
960 |
] |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
961 |
] |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
962 |
]. |
3158 | 963 |
altFont notNil ifTrue:[ |
964 |
font := altFont. |
|
965 |
] ifFalse:[ |
|
966 |
bold ifTrue:[ |
|
967 |
italic ifTrue:[ |
|
968 |
boldItalicFont isNil ifTrue:[ |
|
969 |
boldItalicFont := savedFont asBold asItalic onDevice:device |
|
970 |
]. |
|
971 |
font := boldItalicFont. |
|
972 |
] ifFalse:[ |
|
973 |
boldFont isNil ifTrue:[ |
|
974 |
boldFont := savedFont asBold onDevice:device |
|
975 |
]. |
|
976 |
font := boldFont. |
|
977 |
] |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
978 |
] ifFalse:[ |
3158 | 979 |
italic ifTrue:[ |
980 |
italicFont isNil ifTrue:[ |
|
981 |
italicFont := savedFont asItalic onDevice:device |
|
982 |
]. |
|
983 |
font := italicFont. |
|
984 |
] ifFalse:[ |
|
985 |
font := savedFont |
|
986 |
] |
|
987 |
]. |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
988 |
]. |
3689 | 989 |
subOrSuperscript notNil ifTrue:[ |
990 |
font := font asSize:(font size * 3 // 4). |
|
991 |
subOrSuperscript == Superscript ifTrue:[ |
|
992 |
y := y - (font height // 3). |
|
993 |
] ifFalse:[ |
|
994 |
y := y + (font height // 3). |
|
995 |
]. |
|
996 |
]. |
|
4082 | 997 |
aGCOrView basicFont:font. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
998 |
reverse ifTrue:[ |
4243 | 999 |
aGCOrView paint:bgPaint on:(bgFill := color). |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1000 |
opaque := true. |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1001 |
] ifFalse:[ |
4243 | 1002 |
aGCOrView paint:color on:(bgFill := bgPaint). |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1003 |
]. |
2323 | 1004 |
|
4082 | 1005 |
endPos := pos + runLen - 1. |
2110 | 1006 |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1007 |
"/ disabled - it is too ugly (and not handled correctly, anyway). |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1008 |
"/ wasItalic ~~ italic ifTrue:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1009 |
"/ italic ifFalse:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1010 |
"/ "/ going from italic to non-italic; leave some space for the shear |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1011 |
"/ x := x + (font width " // 2" ) |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1012 |
"/ ]. |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1013 |
"/ ]. |
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1014 |
|
4243 | 1015 |
len := font widthOf:string from:pos to:endPos. |
1016 |
||
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1017 |
(opaque and:[etchColor isNil]) ifTrue:[ |
4295 | 1018 |
aGCOrView fillRectangleX:x y:y"+1"-(font ascent) width:len height:(font descent+font ascent) color:bgFill. |
4082 | 1019 |
aGCOrView displayOpaqueString:string from:pos to:endPos x:x y:y. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1020 |
] ifFalse:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1021 |
etchColor notNil ifTrue:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1022 |
opaque ifTrue:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1023 |
"/ sigh - must draw the background rectangle; |
4243 | 1024 |
"/ it's easier (and faster) to draw the string twice here ... |
4295 | 1025 |
aGCOrView fillRectangleX:x y:y"+1"-(font ascent) width:len height:(font descent+font ascent) color:bgFill. |
4082 | 1026 |
aGCOrView displayOpaqueString:string from:pos to:endPos x:x y:y. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1027 |
]. |
4082 | 1028 |
savedFgPaint := aGCOrView paint. |
1029 |
aGCOrView paint:etchColor. |
|
1030 |
aGCOrView displayString:string from:pos to:endPos x:x+1 y:y+1. |
|
1031 |
aGCOrView paint:savedFgPaint. |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1032 |
]. |
4082 | 1033 |
aGCOrView displayString:string from:pos to:endPos x:x y:y. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1034 |
]. |
4082 | 1035 |
len := font widthOf:string from:pos to:endPos. |
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1036 |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1037 |
underline ifTrue:[ |
4082 | 1038 |
ulPaint notNil ifTrue:[aGCOrView paint:ulPaint]. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1039 |
yL := y+1. |
4082 | 1040 |
aGCOrView displayLineFromX:x y:yL toX:x+len-1 y:yL |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1041 |
]. |
4082 | 1042 |
overline ifTrue:[ "MB:added v" |
1043 |
ulPaint notNil ifTrue:[aGCOrView paint:ulPaint]. |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1044 |
yL := y-(font heightOf: string) + 2. |
4082 | 1045 |
aGCOrView displayLineFromX:x y:yL toX:x+len-1 y:yL |
2322 | 1046 |
]. "MB:added ^" |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1047 |
underwave ifTrue:[ |
4082 | 1048 |
ulPaint notNil ifTrue:[aGCOrView paint:ulPaint]. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1049 |
yL := y+1. |
4082 | 1050 |
aGCOrView displayHorizontalWavelineFromX:x y:yL toX:x+len-1 |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1051 |
]. |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1052 |
strikeout ifTrue:[ |
4082 | 1053 |
strikePaint notNil ifTrue:[aGCOrView paint:strikePaint]. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1054 |
yL := y-(font ascent//2). |
4082 | 1055 |
aGCOrView displayLineFromX:x y:yL toX:x+len-1 y:yL |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1056 |
]. |
307 | 1057 |
|
4082 | 1058 |
x := x + len. |
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1059 |
pos := endPos + 1 |
304 | 1060 |
]. |
307 | 1061 |
|
4082 | 1062 |
aGCOrView basicFont:savedFont. |
1063 |
aGCOrView paint:savedPaint on:savedBgPaint. |
|
307 | 1064 |
|
3598 | 1065 |
pos < string size ifTrue:[ |
1066 |
"/ draw rest |
|
4082 | 1067 |
aGCOrView displayString:string from:pos to:string size x:x y:y. |
3598 | 1068 |
]. |
1069 |
||
4295 | 1070 |
"Created: / 12-05-1996 / 11:14:30 / cg" |
1071 |
"Modified: / 03-02-2017 / 11:45:51 / cg" |
|
304 | 1072 |
! ! |
1073 |
||
1074 |
!Text methodsFor:'emphasis'! |
|
1075 |
||
2128 | 1076 |
actionForAll:aBlock |
2311
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1077 |
"change the actionBlock of all characters. |
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1078 |
Some widgets use this like a href if clicked onto the text." |
2128 | 1079 |
|
1080 |
self emphasisAllAdd:(#actionBlock -> aBlock). |
|
1081 |
||
2311
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1082 |
"transcript ignores this... |
2128 | 1083 |
Transcript showCR: |
2311
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1084 |
((Text string:'hello - click on me') actionForAll:[Transcript flash]) |
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1085 |
" |
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1086 |
|
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1087 |
"labels also... |
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1088 |
Label new |
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1089 |
label: ((Text string:'hello - click on me') actionForAll:[Transcript flash]); |
ffc769e95190
comment/format in: #actionForAll:
Claus Gittinger <cg@exept.de>
parents:
2305
diff
changeset
|
1090 |
open |
2128 | 1091 |
" |
1092 |
! |
|
1093 |
||
304 | 1094 |
allBold |
1095 |
"make all characters bold" |
|
1096 |
||
2852 | 1097 |
self emphasisAllAdd:BoldEmphasis |
304 | 1098 |
|
1099 |
" |
|
1100 |
(Text string:'hello') allBold |
|
2056 | 1101 |
Transcript showCR: ('hello' allBold) |
304 | 1102 |
" |
1103 |
||
406 | 1104 |
"Modified: 10.7.1996 / 12:07:51 / cg" |
304 | 1105 |
! |
1106 |
||
2110 | 1107 |
allBoldOverline |
2322 | 1108 |
"make all characters bold and overline" |
2110 | 1109 |
|
2852 | 1110 |
self emphasisAllAdd:BoldOverlineEmphasis |
2110 | 1111 |
! |
1112 |
||
734 | 1113 |
allItalic |
1114 |
"make all characters italic" |
|
1115 |
||
2852 | 1116 |
self emphasisAllAdd:ItalicEmphasis |
734 | 1117 |
|
1118 |
" |
|
1119 |
(Text string:'hello') allItalic |
|
2056 | 1120 |
Transcript showCR: ('hello' allItalic) |
734 | 1121 |
" |
1122 |
||
1123 |
"Modified: 10.7.1996 / 12:07:51 / cg" |
|
1124 |
! |
|
1125 |
||
3472 | 1126 |
allNonBold |
1127 |
"make all characters non-bold" |
|
1128 |
||
1129 |
self emphasisAllRemove:BoldEmphasis |
|
1130 |
||
1131 |
" |
|
1132 |
(Text string:'hello') allBold allNonBold |
|
1133 |
" |
|
1134 |
! |
|
1135 |
||
2110 | 1136 |
allOverline |
1137 |
"make all characters overline" |
|
1138 |
||
2852 | 1139 |
self emphasisAllAdd:OverlineEmphasis |
2322 | 1140 |
|
1141 |
" |
|
1142 |
Transcript showCR: ('hello' asText allOverline) |
|
1143 |
" |
|
2110 | 1144 |
! |
1145 |
||
2056 | 1146 |
allStrikedOut |
1147 |
"strikeOut all characters" |
|
1148 |
||
2322 | 1149 |
self emphasisAllAdd:StrikeoutEmphasis. |
2056 | 1150 |
|
1151 |
" |
|
1152 |
Transcript showCR: ('hello' allStrikedOut) |
|
1153 |
" |
|
1154 |
! |
|
1155 |
||
1020
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1156 |
allUnderlined |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1157 |
"underline all characters" |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1158 |
|
2322 | 1159 |
self emphasisAllAdd:UnderlineEmphasis. |
1020
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1160 |
|
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1161 |
" |
2056 | 1162 |
Transcript showCR:('hello' allUnderlined) |
1020
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1163 |
" |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1164 |
! |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1165 |
|
2322 | 1166 |
allUnderwaved |
1167 |
"underwave all characters" |
|
1168 |
||
1169 |
self emphasisAllAdd:UnderwaveEmphasis. |
|
1170 |
||
1171 |
" |
|
1172 |
Transcript showCR:('hello' asText allUnderwaved) |
|
1173 |
" |
|
1174 |
! |
|
1175 |
||
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1176 |
backgroundColorizeAllWith:aColor |
2552
a891a2d361b8
comment/format in: #backgroundColorizeAllWith:
Claus Gittinger <cg@exept.de>
parents:
2496
diff
changeset
|
1177 |
"change the bg-color of all characters" |
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1178 |
|
2322 | 1179 |
self emphasisAllAdd:(BackgroundColorEmphasis -> aColor). |
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1180 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1181 |
" |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1182 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1183 |
((Text string:'hello') backgroundColorizeAllWith:(Color red)) |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1184 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1185 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1186 |
('hello' allBold backgroundColorizeAllWith:(Color red)) |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1187 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1188 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1189 |
('hello' asText backgroundColorizeAllWith:(Color red)) |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1190 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1191 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1192 |
('hello ' , ('red' allBold backgroundColorizeAllWith:(Color red)) , ' world') |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1193 |
" |
2552
a891a2d361b8
comment/format in: #backgroundColorizeAllWith:
Claus Gittinger <cg@exept.de>
parents:
2496
diff
changeset
|
1194 |
|
a891a2d361b8
comment/format in: #backgroundColorizeAllWith:
Claus Gittinger <cg@exept.de>
parents:
2496
diff
changeset
|
1195 |
"Modified: / 01-04-2011 / 16:19:21 / cg" |
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1196 |
! |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1197 |
|
999 | 1198 |
colorizeAllWith:aColor |
1199 |
"change the color of all characters" |
|
1200 |
||
2322 | 1201 |
self emphasisAllAdd:(ColorEmphasis -> aColor). |
999 | 1202 |
|
1203 |
" |
|
1204 |
Transcript showCR: |
|
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1205 |
((Text string:'hello') colorizeAllWith:(Color red)) |
999 | 1206 |
|
1207 |
Transcript showCR: |
|
2056 | 1208 |
('hello' colorizeAllWith:(Color red)) |
1209 |
||
1210 |
Transcript showCR: |
|
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1211 |
('hello' allBold colorizeAllWith:(Color red)) |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1212 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1213 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1214 |
('hello' asText colorizeAllWith:(Color red)) |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1215 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1216 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
1217 |
('hello ' , ('red' allBold colorizeAllWith:(Color red)) , ' world') |
999 | 1218 |
" |
1219 |
! |
|
1220 |
||
2312
ab6ab043d9ca
comment/format in: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1221 |
colorizeAllWith:fgColor on:bgColor |
1648 | 1222 |
"change the color and bg-color of all characters" |
1223 |
||
2322 | 1224 |
self emphasisAllAdd:(ColorEmphasis -> fgColor). |
1225 |
self emphasisAllAdd:(BackgroundColorEmphasis -> bgColor). |
|
1648 | 1226 |
|
1227 |
" |
|
1228 |
Transcript showCR: |
|
2312
ab6ab043d9ca
comment/format in: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1229 |
((Text string:'hello') colorizeAllWith:(Color blue) on:(Color yellow)) |
1648 | 1230 |
" |
1231 |
||
1232 |
"Created: / 05-08-2006 / 14:48:13 / cg" |
|
1233 |
! |
|
1234 |
||
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1235 |
emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1236 |
"return the emphasis" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1237 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1238 |
^ runs |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1239 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1240 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1241 |
(Text string:'hello') allBold emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1242 |
'hello' emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1243 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1244 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1245 |
"Modified: 11.5.1996 / 14:22:31 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1246 |
"Created: 14.5.1996 / 13:59:03 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1247 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1248 |
|
1070 | 1249 |
emphasis:emArray |
1250 |
1 to:string size do:[:characterIndex | |
|
1251 |
self emphasisAt:characterIndex put:(emArray at:characterIndex) |
|
1252 |
]. |
|
1253 |
||
1254 |
" |
|
1255 |
(Text string:'hello') emphasis:#(italic bold italic bold bold) |
|
1256 |
" |
|
1257 |
||
1258 |
"Modified: / 31.3.1998 / 16:45:14 / cg" |
|
1259 |
! |
|
1260 |
||
778 | 1261 |
emphasisAllAdd:newEmphasis |
1262 |
"add to the emphasis to all characters. return the receiver" |
|
1263 |
||
3116 | 1264 |
runs isNil ifTrue:[ ^ self ]. "/ just in case: empty |
1265 |
||
1266 |
(runs conform:[:runValue | runValue isNil]) ifTrue:[ |
|
1267 |
"/ no emphasis - happens often |
|
1268 |
runs atAllPut:newEmphasis. |
|
1269 |
] ifFalse:[ |
|
1270 |
self emphasisFrom:1 to:(self size) add:newEmphasis |
|
1271 |
]. |
|
778 | 1272 |
|
1273 |
" |
|
1274 |
(Text string:'hello') allBold |
|
1275 |
emphasisAllAdd:#italic |
|
1276 |
||
1277 |
Transcript show:((Text string:'hello') allBold |
|
1278 |
emphasisAllAdd:#italic) |
|
1279 |
" |
|
1280 |
! |
|
1281 |
||
1282 |
emphasisAllRemove:anEmphasis |
|
1283 |
"remove the emphasis from all characters. return the receiver" |
|
1284 |
||
1285 |
self emphasisFrom:1 to:(self size) remove:anEmphasis |
|
1286 |
||
1287 |
" |
|
1288 |
((Text string:'hello') emphasizeAllWith:#(bold italic)) |
|
1289 |
emphasisAllRemove:#italic |
|
1290 |
||
834
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1291 |
((Text string:'hello') emphasizeAllWith:(Array with:#color->Color red |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1292 |
with:#italic)) |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1293 |
emphasisAllRemove:#italic |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1294 |
|
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1295 |
((Text string:'hello') emphasizeAllWith:(Array with:#color->Color red |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1296 |
with:#italic)) |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1297 |
emphasisAllRemove:#color |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1298 |
|
778 | 1299 |
Transcript show:(((Text string:'hello') emphasizeAllWith:#(bold italic)) |
1300 |
emphasisAllRemove:#italic) |
|
1301 |
" |
|
1302 |
! |
|
1303 |
||
304 | 1304 |
emphasisAt:characterIndex |
1305 |
"return the emphasis at some index" |
|
1306 |
||
1307 |
^ runs at:characterIndex |
|
1308 |
||
1309 |
" |
|
1310 |
(Text string:'hello') allBold emphasisAt:2 |
|
1311 |
" |
|
1312 |
||
1313 |
"Modified: 11.5.1996 / 14:22:31 / cg" |
|
1314 |
! |
|
1315 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1316 |
emphasisAt:characterIndex add:newEmphasis |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1317 |
"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
|
1318 |
|
626 | 1319 |
|e prevE| |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1320 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1321 |
e := runs at:characterIndex. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1322 |
e := self class addEmphasis:newEmphasis to:e. |
626 | 1323 |
|
4319 | 1324 |
"/ if it's equal to the previous emphasis, make it identical. |
626 | 1325 |
|
1326 |
characterIndex > 1 ifTrue:[ |
|
1327 |
prevE := runs at:characterIndex-1. |
|
1328 |
e = prevE ifTrue:[ |
|
1329 |
e := prevE |
|
1330 |
] |
|
1331 |
]. |
|
3598 | 1332 |
runs at:characterIndex put:e. |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1333 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1334 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1335 |
(Text string:'hello') allBold emphasisAt:2 add:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1336 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1337 |
|
4319 | 1338 |
"Created: / 14-05-1996 / 16:48:39 / cg" |
1339 |
"Modified: / 31-03-1998 / 15:29:14 / cg" |
|
1340 |
"Modified (comment): / 13-02-2017 / 20:31:59 / cg" |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1341 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1342 |
|
307 | 1343 |
emphasisAt:characterIndex put:emphasis |
1344 |
"change the emphasis at some index. return the receiver" |
|
1345 |
||
626 | 1346 |
|e prevE| |
1347 |
||
1348 |
e := emphasis. |
|
1349 |
||
4319 | 1350 |
"/ if it's equal to the previous emphasis, make it identical. |
626 | 1351 |
|
1352 |
characterIndex > 1 ifTrue:[ |
|
1353 |
prevE := runs at:characterIndex-1. |
|
1354 |
emphasis = prevE ifTrue:[ |
|
1355 |
e := prevE |
|
1356 |
] |
|
1357 |
]. |
|
3598 | 1358 |
runs at:characterIndex put:e. |
307 | 1359 |
|
1360 |
" |
|
1361 |
(Text string:'hello') allBold emphasisAt:2 put:#italic |
|
1362 |
" |
|
1363 |
||
4319 | 1364 |
"Modified: / 31-03-1998 / 16:45:14 / cg" |
1365 |
"Modified (comment): / 13-02-2017 / 20:32:03 / cg" |
|
307 | 1366 |
! |
1367 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1368 |
emphasisAt:characterIndex remove:emphasisToRemove |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1369 |
"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
|
1370 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1371 |
|e| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1372 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1373 |
e := runs at:characterIndex. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1374 |
e := self class removeEmphasis:emphasisToRemove from:e. |
3598 | 1375 |
runs at:characterIndex put:e. |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1376 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1377 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1378 |
(Text string:'hello') |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1379 |
allBold emphasisAt:2 remove:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1380 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1381 |
(Text string:'hello' emphasis:#(bold italic)) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1382 |
emphasisAt:2 remove:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1383 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1384 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1385 |
"Created: 14.5.1996 / 16:48:39 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1386 |
"Modified: 14.5.1996 / 17:25:04 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1387 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1388 |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1389 |
emphasisCollection |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1390 |
"return the emphasis" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1391 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1392 |
^ runs |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1393 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1394 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1395 |
(Text string:'hello') allBold emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1396 |
'hello' emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1397 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1398 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1399 |
"Created: 14.5.1996 / 13:59:03 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1400 |
"Modified: 14.5.1996 / 15:02:11 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1401 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1402 |
|
777 | 1403 |
emphasisFrom:start to:stop add:newEmphasis |
1404 |
"add to the emphasis within some range. return the receiver" |
|
1405 |
||
1406 |
start to:stop do:[:characterIndex | |
|
1407 |
self emphasisAt:characterIndex add:newEmphasis |
|
1408 |
]. |
|
1409 |
||
1410 |
" |
|
1411 |
(Text string:'hello') allBold |
|
1412 |
emphasisFrom:2 to:4 add:#italic |
|
1413 |
||
1414 |
Transcript showCR:((Text string:'hello') allBold |
|
1415 |
emphasisFrom:2 to:4 add:#italic) |
|
1416 |
||
1417 |
" |
|
1418 |
! |
|
1419 |
||
1420 |
emphasisFrom:start to:stop remove:anEmphasis |
|
1421 |
"remove from the emphasis within some range. return the receiver" |
|
1422 |
||
1423 |
start to:stop do:[:characterIndex | |
|
1424 |
self emphasisAt:characterIndex remove:anEmphasis |
|
1425 |
]. |
|
1426 |
||
1427 |
" |
|
1428 |
(Text string:'hello') allBold |
|
1429 |
emphasisFrom:2 to:4 remove:#bold |
|
1430 |
||
1431 |
Transcript showCR:((Text string:'hello') allBold |
|
1432 |
emphasisFrom:2 to:4 remove:#bold) |
|
1433 |
" |
|
1434 |
! |
|
1435 |
||
2240 | 1436 |
emphasiseFrom:start to:stop with:newEmphasis |
1437 |
"set to the emphasis within some range. return the receiver" |
|
1438 |
||
1439 |
start to:stop do:[:characterIndex | |
|
1440 |
self emphasisAt:characterIndex put:newEmphasis |
|
1441 |
]. |
|
1442 |
||
1443 |
" |
|
1444 |
(Text string:'hello') allBold |
|
1445 |
emphasiseFrom:2 to:4 with:#italic |
|
1446 |
||
1447 |
Transcript showCR:((Text string:'hello') allBold |
|
1448 |
emphasiseFrom:2 to:4 with:#italic) |
|
1449 |
||
1450 |
" |
|
1451 |
! |
|
1452 |
||
304 | 1453 |
emphasizeAllWith:emphasis |
1454 |
"change the emphasis of all characters" |
|
1455 |
||
3598 | 1456 |
runs := RunArray new:(string size) withAll:emphasis. |
304 | 1457 |
|
1458 |
" |
|
1459 |
(Text string:'hello') allBold emphasizeAllWith:#italic |
|
1460 |
" |
|
1461 |
||
1462 |
"Modified: 11.5.1996 / 14:22:52 / cg" |
|
1463 |
! |
|
1464 |
||
343 | 1465 |
emphasizeFrom:start count:count with:emphasis |
1466 |
"change the emphasis of a range of characters, given startIndex and count." |
|
1467 |
||
1468 |
self emphasizeFrom:start to:(start+count-1) with:emphasis |
|
1469 |
||
1470 |
" |
|
1471 |
(Text string:'hello world') |
|
1472 |
emphasizeFrom:1 count:5 with:#bold; |
|
1473 |
emphasizeFrom:7 count:5 with:#italic |
|
1474 |
" |
|
1475 |
||
1476 |
"Modified: 11.5.1996 / 14:30:02 / cg" |
|
1477 |
"Created: 16.5.1996 / 10:52:27 / cg" |
|
1478 |
! |
|
1479 |
||
304 | 1480 |
emphasizeFrom:start to:stop with:emphasis |
1481 |
"change the emphasis of a range of characters" |
|
1482 |
||
3010 | 1483 |
"/ |newRuns| |
304 | 1484 |
|
631 | 1485 |
runs from:start to:stop put:emphasis. |
626 | 1486 |
|
777 | 1487 |
"/ newRuns := RunArray new. |
1488 |
"/ |
|
1489 |
"/ "/ for now - a q&d hack |
|
1490 |
"/ 1 to:start-1 do:[:i | |
|
1491 |
"/ newRuns add:(runs at:i). |
|
1492 |
"/ ]. |
|
1493 |
"/ newRuns add:emphasis withOccurrences:(stop - start + 1). |
|
1494 |
"/ stop+1 to:string size do:[:i | |
|
1495 |
"/ newRuns add:(runs at:i) |
|
1496 |
"/ ]. |
|
1497 |
"/ runs := newRuns |
|
304 | 1498 |
|
1499 |
" |
|
1500 |
(Text string:'hello world') |
|
1501 |
emphasizeFrom:1 to:5 with:#bold; |
|
1502 |
emphasizeFrom:7 to:11 with:#italic |
|
1503 |
" |
|
1504 |
||
631 | 1505 |
"Modified: / 7.4.1998 / 08:52:18 / cg" |
347 | 1506 |
! |
1507 |
||
1508 |
emphasizeFrom:start with:emphasis |
|
1509 |
"change the emphasis of some characters upTo the end" |
|
1510 |
||
1511 |
self emphasizeFrom:start to:(self size) with:emphasis |
|
1512 |
||
1513 |
" |
|
1514 |
(Text string:'hello world') |
|
1515 |
emphasizeFrom:1 count:5 with:#bold; |
|
1516 |
emphasizeFrom:7 with:#italic |
|
1517 |
" |
|
1518 |
||
1519 |
"Modified: 11.5.1996 / 14:30:02 / cg" |
|
1520 |
"Created: 17.5.1996 / 15:15:32 / cg" |
|
1020
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1521 |
! |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1522 |
|
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1523 |
strikeoutAll |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1524 |
"strikeout all characters" |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1525 |
|
2322 | 1526 |
self emphasisAllAdd:StrikeoutEmphasis. |
1020
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1527 |
|
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1528 |
" |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1529 |
Transcript showCR: |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1530 |
('hello' asText strikeoutAll) |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1531 |
" |
1069 | 1532 |
! |
1533 |
||
2322 | 1534 |
withoutAnyColorEmphasis |
4052 | 1535 |
"return a copy with color emphasis removed (fg and bg)" |
1536 |
||
1537 |
^ (self withoutEmphasis:BackgroundColorEmphasis) |
|
1538 |
withoutEmphasis:ColorEmphasis |
|
2322 | 1539 |
! |
1540 |
||
1541 |
withoutBackgroundColorEmphasis |
|
4052 | 1542 |
"return a copy with bg-color emphasis removed" |
1543 |
||
2322 | 1544 |
^ self withoutEmphasis:BackgroundColorEmphasis |
1545 |
! |
|
1546 |
||
4052 | 1547 |
withoutEmphasis |
1548 |
"return my underlying plain string" |
|
1549 |
||
1550 |
^ string |
|
1551 |
! |
|
1552 |
||
1069 | 1553 |
withoutEmphasis:emphasisToRemove |
4052 | 1554 |
"return a copy with a particular emphasis removed" |
1555 |
||
2322 | 1556 |
|newText anyEmphasis| |
1069 | 1557 |
|
1558 |
self hasChangeOfEmphasis ifTrue:[ |
|
1559 |
newText := self copyFrom:1 to:self size. |
|
2322 | 1560 |
anyEmphasis := false. |
1069 | 1561 |
1 to:newText size do:[:col | |
1562 |
|em newem| |
|
1563 |
||
1564 |
em := (newText emphasis) at:col. |
|
1565 |
em notNil ifTrue:[ |
|
1566 |
newem := Text removeEmphasis:emphasisToRemove from:em. |
|
1567 |
newem ~~ em ifTrue:[ |
|
2322 | 1568 |
newText emphasisAt:col put:newem. |
2323 | 1569 |
]. |
1570 |
newem notNil ifTrue:[ anyEmphasis := true ]. |
|
1069 | 1571 |
]. |
1572 |
]. |
|
2322 | 1573 |
anyEmphasis ifFalse:[^ newText string]. |
1069 | 1574 |
^ newText |
1575 |
]. |
|
1576 |
^ self |
|
2322 | 1577 |
! |
1578 |
||
1579 |
withoutForegroundColorEmphasis |
|
4052 | 1580 |
"return a copy with fg-color emphasis removed" |
1581 |
||
2322 | 1582 |
^ self withoutEmphasis:ColorEmphasis |
304 | 1583 |
! ! |
1584 |
||
1757 | 1585 |
|
304 | 1586 |
!Text methodsFor:'printing & storing'! |
1587 |
||
2128 | 1588 |
displayOn:aGCOrStream |
1589 |
"append a printed representation from which the receiver can be reconstructed |
|
1590 |
to aStream." |
|
1591 |
||
1592 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
|
4351 | 1593 |
"/ old ST80 means: draw-yourself on a GC. |
1594 |
aGCOrStream isStream ifFalse:[ |
|
1595 |
^ super displayOn:aGCOrStream. |
|
2128 | 1596 |
]. |
1597 |
||
4351 | 1598 |
aGCOrStream nextPutAll:'(Text string:'. |
1599 |
string storeOn:aGCOrStream. |
|
1600 |
aGCOrStream nextPutAll:' runs:'. |
|
1601 |
runs displayOn:aGCOrStream. |
|
1602 |
aGCOrStream nextPutAll:')'. |
|
1603 |
||
1604 |
"Created: / 11-05-1996 / 14:27:09 / cg" |
|
1605 |
"Modified: / 22-02-2017 / 16:58:18 / cg" |
|
2128 | 1606 |
! |
1607 |
||
3273 | 1608 |
displayString |
1609 |
"return a string used when displaying the receiver in a view." |
|
1610 |
||
1611 |
^ self. |
|
1612 |
! |
|
1613 |
||
343 | 1614 |
printOn:aStream |
3784 | 1615 |
"print the receiver's characters (including emphasis) on aStream. |
1077 | 1616 |
Notice, that some streams simply ignore the emphasis" |
343 | 1617 |
|
2051 | 1618 |
aStream nextPutAllText:self |
304 | 1619 |
|
343 | 1620 |
" |
407 | 1621 |
Transcript showCR:'hello world'. |
1622 |
Transcript showCR:'hello world' asText allBold. |
|
1623 |
Transcript showCR:('hello world' asText emphasizeAllWith:#italic). |
|
343 | 1624 |
" |
304 | 1625 |
|
409 | 1626 |
"Modified: 12.7.1996 / 10:15:47 / cg" |
304 | 1627 |
! |
1628 |
||
1629 |
storeOn:aStream |
|
343 | 1630 |
"append a printed representation from which the receiver can be reconstructed |
1631 |
to aStream." |
|
1632 |
||
304 | 1633 |
aStream nextPutAll:'(Text string:'. |
1634 |
string storeOn:aStream. |
|
307 | 1635 |
aStream nextPutAll:' runs:'. |
304 | 1636 |
runs storeOn:aStream. |
4334 | 1637 |
aStream nextPut:$). |
304 | 1638 |
|
4334 | 1639 |
"Created: / 11-05-1996 / 14:27:09 / cg" |
1640 |
"Modified: / 16-05-1996 / 11:23:32 / cg" |
|
1641 |
"Modified: / 17-02-2017 / 10:36:03 / stefan" |
|
304 | 1642 |
! ! |
1643 |
||
1200 | 1644 |
!Text methodsFor:'private-accessing'! |
304 | 1645 |
|
631 | 1646 |
emphasisCollection:emphasisCollection |
1647 |
"set the string and emphasis collection. |
|
1648 |
The emphasis collection contains per-character information." |
|
1649 |
||
3598 | 1650 |
runs := emphasisCollection. |
631 | 1651 |
|
1652 |
"Created: / 7.4.1998 / 08:52:03 / cg" |
|
1653 |
! |
|
1654 |
||
2959 | 1655 |
runs |
1656 |
^ runs |
|
1657 |
! |
|
1658 |
||
3009 | 1659 |
setRuns:anArrayOrRunArray |
3598 | 1660 |
runs := anArrayOrRunArray. |
3009 | 1661 |
! |
1662 |
||
1663 |
setString:aString setRuns:anArrayOrRunArray |
|
872
2ca6864d13bb
new private accessor (for subclass compatibility)
Claus Gittinger <cg@exept.de>
parents:
854
diff
changeset
|
1664 |
string := aString. |
3598 | 1665 |
runs := anArrayOrRunArray. |
872
2ca6864d13bb
new private accessor (for subclass compatibility)
Claus Gittinger <cg@exept.de>
parents:
854
diff
changeset
|
1666 |
! |
2ca6864d13bb
new private accessor (for subclass compatibility)
Claus Gittinger <cg@exept.de>
parents:
854
diff
changeset
|
1667 |
|
304 | 1668 |
string:aString emphasis:emphasis |
343 | 1669 |
"set the string and emphasis. The emphasis is applied to all characters." |
1670 |
||
428 | 1671 |
string := aString string. |
3598 | 1672 |
runs := RunArray new:string size withAll:emphasis. |
304 | 1673 |
|
1674 |
" |
|
1675 |
|t| |
|
1676 |
||
1677 |
t := Text new string:'hello' emphasis:#bold. |
|
1678 |
t emphasisAt:2. |
|
1679 |
" |
|
1680 |
||
343 | 1681 |
"Modified: 16.5.1996 / 11:24:03 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1682 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1683 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1684 |
string:aString emphasisCollection:emphasisCollection |
343 | 1685 |
"set the string and emphasis collection. |
1686 |
The emphasis collection contains per-character information." |
|
1687 |
||
428 | 1688 |
string := aString string. |
1160 | 1689 |
string size == 0 ifTrue:[ |
1690 |
runs := RunArray new. |
|
1691 |
] ifFalse:[ |
|
1692 |
runs := emphasisCollection asRunArray |
|
1693 |
]. |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1694 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1695 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1696 |
|t| |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1697 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1698 |
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
|
1699 |
t emphasisAt:2. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1700 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1701 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1702 |
"Created: 14.5.1996 / 14:03:29 / cg" |
343 | 1703 |
"Modified: 16.5.1996 / 11:24:21 / cg" |
304 | 1704 |
! ! |
1705 |
||
1706 |
!Text methodsFor:'queries'! |
|
1707 |
||
4183 | 1708 |
bitsPerCharacter |
1709 |
"return the number of bits I (my underlying string) require for storage. |
|
1710 |
(i.e. is it a regular String or a TwoByteString)" |
|
1711 |
||
1712 |
^ string bitsPerCharacter. |
|
1713 |
! |
|
1714 |
||
4082 | 1715 |
emphasisAtPoint:aPoint on:aGCOrView |
2128 | 1716 |
"return the emphasis at a given point, or nil if there is none" |
1717 |
||
4082 | 1718 |
|pointX savedFont boldFont italicFont bold italic wasItalic pos font len gcDevice posX boldItalicFont| |
2128 | 1719 |
|
4082 | 1720 |
gcDevice := aGCOrView graphicsDevice. |
1721 |
savedFont := aGCOrView basicFont onDevice:gcDevice. |
|
2128 | 1722 |
|
1723 |
pos := 1. |
|
1724 |
posX := 0. |
|
4082 | 1725 |
pointX := aPoint x. |
1726 |
len := 0. |
|
2128 | 1727 |
italic := false. |
4082 | 1728 |
runs runsDo:[:runLen :emphasis | |
2128 | 1729 |
wasItalic := italic. |
1730 |
emphasis isSymbol ifTrue:[ |
|
4082 | 1731 |
bold := emphasis == BoldEmphasis |
1732 |
or:[emphasis == BoldUnderlineEmphasis |
|
1733 |
or:[emphasis == BoldOverlineEmphasis |
|
1734 |
or:[emphasis == BoldUnderwaveEmphasis]]]. |
|
1735 |
italic := emphasis == ItalicEmphasis |
|
1736 |
or:[emphasis == ItalicUnderlineEmphasis |
|
1737 |
or:[emphasis == ItalicUnderwaveEmphasis]]. |
|
2128 | 1738 |
] ifFalse:[ |
4082 | 1739 |
bold := italic := false. |
1740 |
(emphasis isNil or:[emphasis isAssociation]) ifFalse:[ |
|
1741 |
emphasis do:[:eachEmphasisSymbol| |
|
1742 |
eachEmphasisSymbol == BoldEmphasis ifTrue:[bold := true] |
|
1743 |
ifFalse:[eachEmphasisSymbol == ItalicEmphasis ifTrue:[italic := true] |
|
1744 |
ifFalse:[eachEmphasisSymbol == BoldUnderlineEmphasis ifTrue:[bold := true] |
|
1745 |
ifFalse:[eachEmphasisSymbol == BoldUnderwaveEmphasis ifTrue:[bold := true] |
|
1746 |
ifFalse:[eachEmphasisSymbol == ItalicUnderlineEmphasis ifTrue:[italic := true] |
|
1747 |
ifFalse:[eachEmphasisSymbol == ItalicUnderwaveEmphasis ifTrue:[italic := true]]]]]]. |
|
1748 |
]. |
|
2128 | 1749 |
] |
1750 |
]. |
|
1751 |
||
1752 |
bold ifTrue:[ |
|
4082 | 1753 |
italic ifTrue:[ |
1754 |
boldItalicFont isNil ifTrue:[ |
|
1755 |
boldItalicFont := savedFont asBold asItalic onDevice:gcDevice |
|
1756 |
]. |
|
1757 |
font := boldItalicFont. |
|
1758 |
] ifFalse:[ |
|
1759 |
boldFont isNil ifTrue:[ |
|
1760 |
boldFont := savedFont asBold onDevice:gcDevice |
|
1761 |
]. |
|
1762 |
font := boldFont. |
|
1763 |
] |
|
2128 | 1764 |
] ifFalse:[ |
1765 |
italic ifTrue:[ |
|
1766 |
italicFont isNil ifTrue:[ |
|
3790 | 1767 |
italicFont := savedFont asItalic onDevice:gcDevice |
2128 | 1768 |
]. |
4082 | 1769 |
font := italicFont |
2128 | 1770 |
] ifFalse:[ |
4082 | 1771 |
font := savedFont |
2128 | 1772 |
] |
1773 |
]. |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1774 |
"/ disabled - it is too ugly (and not handled correctly, anyway). |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1775 |
"/ wasItalic ~~ italic ifTrue:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1776 |
"/ italic ifFalse:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1777 |
"/ "/ going from italic to non-italic; leave some space for the shear |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1778 |
"/ l := l + (f width " // 2" ) |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1779 |
"/ ]. |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1780 |
"/ ]. |
4082 | 1781 |
len := font widthOf:string from:pos to:(pos + runLen - 1). |
1782 |
(pointX between:posX and:posX + len) ifTrue:[ |
|
2128 | 1783 |
^ emphasis |
1784 |
]. |
|
4082 | 1785 |
pos := pos + runLen. |
1786 |
posX := posX + len. |
|
2128 | 1787 |
]. |
1788 |
||
1789 |
^ nil |
|
1790 |
! |
|
1791 |
||
1401 | 1792 |
encoding |
1793 |
^ string encoding |
|
1794 |
! |
|
1795 |
||
304 | 1796 |
hasChangeOfEmphasis |
2830
b69f6dc901f0
comment/format in: #hasChangeOfEmphasis
Claus Gittinger <cg@exept.de>
parents:
2734
diff
changeset
|
1797 |
"return true, if the receiver contains non-empty emphasis information |
b69f6dc901f0
comment/format in: #hasChangeOfEmphasis
Claus Gittinger <cg@exept.de>
parents:
2734
diff
changeset
|
1798 |
i.e. any non-normal (=emphasized) characters" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1799 |
|
3472 | 1800 |
^ runs notEmptyOrNil |
1801 |
and:[ runs contains:[:e | e notNil] ] |
|
304 | 1802 |
|
1803 |
"Created: 11.5.1996 / 14:03:19 / cg" |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1804 |
"Modified: 14.5.1996 / 15:51:01 / cg" |
304 | 1805 |
! |
1806 |
||
2578
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1807 |
hasEmphasis: emphasis |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1808 |
"return true, if the receiver contains given emphasis" |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1809 |
|
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1810 |
"HACK!!!!!!" |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1811 |
|
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1812 |
| emphasisArray | |
2675 | 1813 |
|
2578
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1814 |
(emphasis isSymbol or:[emphasis isAssociation]) ifTrue:[ |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1815 |
emphasisArray := Array with: emphasis |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1816 |
] ifFalse:[ |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1817 |
emphasisArray := emphasis. |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1818 |
]. |
2675 | 1819 |
emphasisArray isNil ifTrue:[^false]. |
2578
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1820 |
|
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1821 |
runs do:[:runEmph| |
3116 | 1822 |
emphasisArray do:[:searchEmph| |
1823 |
(runEmph = searchEmph |
|
1824 |
or: [runEmph isCollection |
|
1825 |
and:[runEmph isSymbol not |
|
1826 |
and:[runEmph includes: searchEmph]]] |
|
1827 |
) ifTrue:[ |
|
1828 |
^ true |
|
2578
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1829 |
] |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1830 |
] |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1831 |
]. |
3116 | 1832 |
^ false |
2578
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1833 |
|
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1834 |
" |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1835 |
'Hello' asText allBold hasEmphasis: #bold. |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1836 |
'Hello' asText allBold allUnderlined hasEmphasis: #bold. |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1837 |
'Hello' asText allBold allUnderlined hasEmphasis: #italic. |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1838 |
('Hello' asText allBold allUnderlined , ' World' asText allItalic) hasEmphasis: #italic. |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1839 |
" |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1840 |
|
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1841 |
"Created: / 20-07-2011 / 17:51:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2675 | 1842 |
"Modified (format): / 18-11-2011 / 14:55:10 / cg" |
2578
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1843 |
! |
0b44903b0406
Added Text>>hasEmphasis:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2552
diff
changeset
|
1844 |
|
307 | 1845 |
heightOn:aGC |
1846 |
"return the number of device units, required on aGC's device" |
|
1847 |
||
4019 | 1848 |
^ aGC deviceFont heightOf:string |
307 | 1849 |
|
1850 |
"Created: 12.5.1996 / 11:02:03 / cg" |
|
1851 |
! |
|
1852 |
||
304 | 1853 |
indexOf:aCharacter startingAt:index |
343 | 1854 |
"search aCharacters index in the underlying string" |
1855 |
||
304 | 1856 |
^ string indexOf:aCharacter startingAt:index |
1857 |
||
1858 |
"Created: 11.5.1996 / 13:58:56 / cg" |
|
343 | 1859 |
"Modified: 16.5.1996 / 11:25:12 / cg" |
304 | 1860 |
! |
1861 |
||
3644 | 1862 |
isPlainString |
1863 |
"return true, if the receiver is a plain string - without attributes; |
|
1864 |
false is returned here." |
|
1865 |
||
1866 |
^ false |
|
1867 |
! |
|
1868 |
||
307 | 1869 |
isText |
343 | 1870 |
"return true if this is a Text object - always true here" |
1871 |
||
307 | 1872 |
^ true |
1873 |
||
1874 |
"Created: 12.5.1996 / 10:56:24 / cg" |
|
343 | 1875 |
"Modified: 16.5.1996 / 11:25:29 / cg" |
307 | 1876 |
! |
1877 |
||
304 | 1878 |
occurrencesOf:aCharacter |
343 | 1879 |
"count & return the number of occurrences of aCharacter in the |
1880 |
underlying string" |
|
1881 |
||
304 | 1882 |
^ string occurrencesOf:aCharacter |
1883 |
||
1884 |
"Created: 11.5.1996 / 13:58:46 / cg" |
|
343 | 1885 |
"Modified: 16.5.1996 / 11:25:51 / cg" |
304 | 1886 |
! |
1887 |
||
1888 |
size |
|
343 | 1889 |
"return the number of characters in the underlying string" |
1890 |
||
304 | 1891 |
^ string size |
1892 |
||
1893 |
"Created: 11.5.1996 / 14:25:15 / cg" |
|
343 | 1894 |
"Modified: 16.5.1996 / 11:26:08 / cg" |
304 | 1895 |
! |
1896 |
||
1897 |
string |
|
343 | 1898 |
"return the receiver without any emphasis information |
1899 |
i.e. the underlying string." |
|
1900 |
||
304 | 1901 |
^ string |
1902 |
||
1903 |
"Created: 11.5.1996 / 13:58:38 / cg" |
|
343 | 1904 |
"Modified: 16.5.1996 / 11:26:30 / cg" |
307 | 1905 |
! |
1906 |
||
1069 | 1907 |
widthFrom:startIndex to:endIndex on:aGC |
1908 |
"return the number of device units, required on aGC's device" |
|
1909 |
||
1910 |
^ (self copyFrom:startIndex to:endIndex) widthOn:aGC |
|
1911 |
! |
|
1912 |
||
307 | 1913 |
widthOn:aGC |
1914 |
"return the number of device units, required on aGC's device" |
|
1915 |
||
4082 | 1916 |
|savedFont boldFont italicFont bold italic wasItalic pos font len gcDevice boldItalicFont| |
307 | 1917 |
|
3790 | 1918 |
gcDevice := aGC graphicsDevice. |
1919 |
savedFont := aGC basicFont onDevice:gcDevice. |
|
307 | 1920 |
|
1921 |
pos := 1. |
|
4082 | 1922 |
len := 0. |
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1923 |
italic := false. |
4082 | 1924 |
runs runsDo:[:runLen :emphasis | |
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1925 |
wasItalic := italic. |
307 | 1926 |
emphasis isSymbol ifTrue:[ |
4082 | 1927 |
bold := emphasis == BoldEmphasis |
1928 |
or:[emphasis == BoldUnderlineEmphasis |
|
1929 |
or:[emphasis == BoldOverlineEmphasis |
|
1930 |
or:[emphasis == BoldUnderwaveEmphasis]]]. |
|
1931 |
italic := emphasis == ItalicEmphasis |
|
1932 |
or:[emphasis == ItalicUnderlineEmphasis |
|
1933 |
or:[emphasis == ItalicUnderwaveEmphasis]]. |
|
307 | 1934 |
] ifFalse:[ |
4082 | 1935 |
bold := italic := false. |
1936 |
(emphasis isNil or:[emphasis isAssociation]) ifFalse:[ |
|
1937 |
emphasis do:[:eachEmphasisSymbol| |
|
1938 |
eachEmphasisSymbol == BoldEmphasis ifTrue:[bold := true] |
|
1939 |
ifFalse:[eachEmphasisSymbol == ItalicEmphasis ifTrue:[italic := true] |
|
1940 |
ifFalse:[eachEmphasisSymbol == BoldUnderlineEmphasis ifTrue:[bold := true] |
|
1941 |
ifFalse:[eachEmphasisSymbol == BoldUnderwaveEmphasis ifTrue:[bold := true] |
|
1942 |
ifFalse:[eachEmphasisSymbol == ItalicUnderlineEmphasis ifTrue:[italic := true] |
|
1943 |
ifFalse:[eachEmphasisSymbol == ItalicUnderwaveEmphasis ifTrue:[italic := true]]]]]]. |
|
1944 |
]. |
|
307 | 1945 |
] |
1946 |
]. |
|
1947 |
||
1948 |
bold ifTrue:[ |
|
4082 | 1949 |
italic ifTrue:[ |
1950 |
boldItalicFont isNil ifTrue:[ |
|
1951 |
boldItalicFont := savedFont asBold asItalic onDevice:gcDevice |
|
1952 |
]. |
|
1953 |
font := boldItalicFont. |
|
1954 |
] ifFalse:[ |
|
1955 |
boldFont isNil ifTrue:[ |
|
1956 |
boldFont := savedFont asBold onDevice:gcDevice |
|
1957 |
]. |
|
1958 |
font := boldFont. |
|
1959 |
] |
|
307 | 1960 |
] ifFalse:[ |
1961 |
italic ifTrue:[ |
|
1962 |
italicFont isNil ifTrue:[ |
|
3790 | 1963 |
italicFont := savedFont asItalic onDevice:gcDevice |
307 | 1964 |
]. |
4082 | 1965 |
font := italicFont |
307 | 1966 |
] ifFalse:[ |
4082 | 1967 |
font := savedFont |
307 | 1968 |
] |
1969 |
]. |
|
2233
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1970 |
"/ disabled - it is too ugly (and not handled correctly, anyway). |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1971 |
"/ wasItalic ~~ italic ifTrue:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1972 |
"/ italic ifFalse:[ |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1973 |
"/ "/ going from italic to non-italic; leave some space for the shear |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1974 |
"/ l := l + (f width " // 2" ) |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1975 |
"/ ]. |
04205abedbff
space insertion at italic-nonItalic boundaries removed.
Claus Gittinger <cg@exept.de>
parents:
2181
diff
changeset
|
1976 |
"/ ]. |
4082 | 1977 |
len := len + (font widthOf:string from:pos to:(pos + runLen - 1)). |
1978 |
pos := pos + runLen |
|
307 | 1979 |
]. |
1980 |
||
4082 | 1981 |
^ len |
307 | 1982 |
|
404
14cf34141532
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
395
diff
changeset
|
1983 |
"Modified: 5.7.1996 / 17:54:58 / cg" |
307 | 1984 |
! ! |
1985 |
||
1986 |
!Text methodsFor:'replacing'! |
|
1987 |
||
1988 |
replaceFrom:start to:stop with:aCollection startingAt:startIndex |
|
343 | 1989 |
"replace a range of characters, from another string or text object. |
607 | 1990 |
The corresponding characters' emphasis information is also copied. |
1991 |
Return the receiver." |
|
343 | 1992 |
|
2181
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
1993 |
|idx maxCharacter| |
1402
2fe462e2fe8e
care for text with twobyte strings
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
1994 |
|
307 | 1995 |
aCollection isString ifTrue:[ |
2181
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
1996 |
aCollection bitsPerCharacter > string bitsPerCharacter ifTrue:[ |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
1997 |
"have to create a new string with appropriate character size" |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
1998 |
string := aCollection string species fromString:string. |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
1999 |
]. |
307 | 2000 |
aCollection hasChangeOfEmphasis ifTrue:[ |
2001 |
string replaceFrom:start to:stop with:aCollection startingAt:startIndex. |
|
2002 |
idx := startIndex. |
|
2003 |
start to:stop do:[:col | |
|
2004 |
self emphasisAt:col put:(aCollection emphasisAt:idx). |
|
2005 |
idx := idx + 1. |
|
2006 |
]. |
|
2007 |
^ self. |
|
2008 |
] |
|
2181
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2009 |
] ifFalse:[ |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2010 |
"aCollection is an arbitrary SequenceableCollection" |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2011 |
maxCharacter := $0. "some 8-bit character" |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2012 |
aCollection do:[:eachCharacter | |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2013 |
maxCharacter := maxCharacter max:eachCharacter |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2014 |
]. |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2015 |
maxCharacter bitsPerCharacter > string bitsPerCharacter ifTrue:[ |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2016 |
"have to create a new string with appropriate character size" |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2017 |
string := maxCharacter stringSpecies fromString:string. |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2018 |
]. |
307 | 2019 |
]. |
2181
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2020 |
|
307 | 2021 |
string replaceFrom:start to:stop with:aCollection startingAt:startIndex. |
3598 | 2022 |
self emphasizeFrom:start to:stop with:nil. |
307 | 2023 |
|
2024 |
" |
|
2025 |
((Text string:'hello') allBold emphasisAt:2 put:#italic) |
|
2181
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2026 |
replaceFrom:1 to:3 with:'HEL' startingAt:1 |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2027 |
|
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2028 |
((Text string:'hello') allBold emphasisAt:2 put:#italic) |
86122f38fc09
Fix #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2128
diff
changeset
|
2029 |
replaceFrom:1 to:3 with:#($H $E $L) startingAt:1 |
307 | 2030 |
" |
2031 |
||
607 | 2032 |
"Modified: / 28.1.1998 / 16:50:06 / cg" |
304 | 2033 |
! ! |
2034 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
2035 |
!Text class methodsFor:'documentation'! |
304 | 2036 |
|
2037 |
version |
|
3598 | 2038 |
^ '$Header$' |
2305
2108d674c8b2
comment/format in: #writeStream
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
2039 |
! |
2108d674c8b2
comment/format in: #writeStream
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
2040 |
|
2108d674c8b2
comment/format in: #writeStream
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
2041 |
version_CVS |
3598 | 2042 |
^ '$Header$' |
304 | 2043 |
! ! |
1160 | 2044 |
|
2867 | 2045 |
|
314 | 2046 |
Text initialize! |