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