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