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