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