author | Claus Gittinger <cg@exept.de> |
Wed, 11 Feb 2009 16:25:11 +0100 | |
changeset 2110 | 54019b63a74f |
parent 2056 | 3a6abb99746f |
child 2128 | f659bd2d462a |
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. |
2016
9ad5248e5920
Text class>>#writeStream - answer a TextStream
Stefan Vogel <sv@exept.de>
parents:
1780
diff
changeset
|
311 |
! |
9ad5248e5920
Text class>>#writeStream - answer a TextStream
Stefan Vogel <sv@exept.de>
parents:
1780
diff
changeset
|
312 |
|
9ad5248e5920
Text class>>#writeStream - answer a TextStream
Stefan Vogel <sv@exept.de>
parents:
1780
diff
changeset
|
313 |
writeStream |
9ad5248e5920
Text class>>#writeStream - answer a TextStream
Stefan Vogel <sv@exept.de>
parents:
1780
diff
changeset
|
314 |
"answer the stream, that is best used with this class" |
9ad5248e5920
Text class>>#writeStream - answer a TextStream
Stefan Vogel <sv@exept.de>
parents:
1780
diff
changeset
|
315 |
|
9ad5248e5920
Text class>>#writeStream - answer a TextStream
Stefan Vogel <sv@exept.de>
parents:
1780
diff
changeset
|
316 |
^ TextStream on:(self new:100) |
304 | 317 |
! ! |
318 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
319 |
!Text class methodsFor:'emphasis helper'! |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
320 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
321 |
addEmphasis:e1 to:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
322 |
"merge two emphasis's into one" |
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 |
|ne| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
325 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
326 |
e1 isNil ifTrue:[^ e2]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
327 |
e2 isNil ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
328 |
e1 == e2 ifTrue:[^ e1]. |
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 |
(e1 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
331 |
or:[e1 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
332 |
(e2 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
333 |
or:[e2 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
334 |
^ Array with:e1 with:e2 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
335 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
336 |
(e2 includes:e1) ifTrue:[^ e2]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
337 |
^ e2 copyWith:e1 |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
338 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
339 |
(e2 isSymbol |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
340 |
or:[e2 isAssociation]) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
341 |
(e1 includes:e2) ifTrue:[^ e1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
342 |
^ e1 copyWith:e2 |
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 |
"/ ould use: |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
345 |
"/ ^ (e1 asSet addAll:e2; asArray) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
346 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
347 |
"/ but we do it manually, to preserve the |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
348 |
"/ order. (should create longer runs, while editing) |
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 := e1. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
351 |
e2 do:[:e | |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
352 |
(ne includes:e) ifFalse:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
353 |
ne := ne copyWith:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
354 |
] |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
355 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
356 |
^ ne. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
357 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
358 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
359 |
Text addEmphasis:#bold to:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
360 |
Text addEmphasis:#bold to:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
361 |
Text addEmphasis:#bold to:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
362 |
Text addEmphasis:#italic to:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
363 |
Text addEmphasis:#(italic strikeout) to:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
364 |
Text addEmphasis:#(italic strikeout) to:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
365 |
Text addEmphasis:#(italic strikeout) to:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
366 |
Text addEmphasis:(#color->Color red) to:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
367 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
368 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
369 |
"Modified: 14.5.1996 / 17:15:44 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
370 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
371 |
|
339 | 372 |
emphasis:e1 includes:e2 |
373 |
"return true, if e1 includes e2. |
|
374 |
e2 should be a single emphasis." |
|
375 |
||
376 |
e1 isNil ifTrue:[^ false]. |
|
377 |
e2 isNil ifTrue:[^ false]. |
|
378 |
e1 == e2 ifTrue:[^ true]. |
|
379 |
||
754 | 380 |
e1 isSymbol ifTrue:[ |
381 |
^ false |
|
382 |
]. |
|
383 |
e1 isAssociation ifTrue:[ |
|
384 |
^ e1 key == e2 |
|
385 |
]. |
|
339 | 386 |
(e1 isSymbol |
387 |
or:[e1 isAssociation]) ifTrue:[ |
|
388 |
^ false |
|
389 |
]. |
|
1780 | 390 |
e2 isSymbol ifTrue:[ |
391 |
^ (e1 includes:e2) or:[e1 contains:[:e |e isAssociation and:[e key == e2]]]. |
|
392 |
]. |
|
393 |
e2 isAssociation ifTrue:[ |
|
394 |
^ (e1 includes:e2 key) or:[e1 contains:[:e |e isAssociation and:[e key == e2 key]]]. |
|
339 | 395 |
]. |
396 |
^ false |
|
397 |
||
398 |
" |
|
399 |
Text emphasis:#bold includes:#bold |
|
1780 | 400 |
Text emphasis:#bold includes:#italic |
339 | 401 |
Text emphasis:#(italic strikeout) includes:#bold |
402 |
Text emphasis:#(italic strikeout) includes:#italic |
|
754 | 403 |
Text emphasis:(#color->Color red) includes:#color |
339 | 404 |
" |
405 |
||
406 |
"Modified: 14.5.1996 / 17:45:11 / cg" |
|
407 |
! |
|
408 |
||
407 | 409 |
extractEmphasis:key from:e |
410 |
"if key is included in the emphasis, e then return the key. |
|
411 |
Otherwise, if a n association with that key is included, return the value. |
|
412 |
Otherwise, return nil." |
|
413 |
||
414 |
e isNil ifTrue:[^ nil]. |
|
415 |
key == e ifTrue:[^ e]. |
|
754 | 416 |
e isSymbol ifTrue:[^ nil]. |
407 | 417 |
|
418 |
e isAssociation ifTrue:[ |
|
419 |
e key == key ifTrue:[^ e value]. |
|
420 |
^ nil |
|
421 |
]. |
|
422 |
e do:[:entry | |
|
754 | 423 |
entry == key ifTrue:[^ key]. |
407 | 424 |
entry isAssociation ifTrue:[ |
425 |
entry key == key ifTrue:[ |
|
426 |
^ entry value |
|
427 |
] |
|
428 |
] |
|
429 |
]. |
|
430 |
^ nil |
|
431 |
||
432 |
" |
|
433 |
Text extractEmphasis:#bold from:#bold |
|
434 |
Text extractEmphasis:#bold from:#italic |
|
435 |
Text extractEmphasis:#bold from:#(italic strikeout) |
|
436 |
Text extractEmphasis:#bold from:#(italic bold) |
|
437 |
Text extractEmphasis:#color from:(#color->Color red) |
|
438 |
Text extractEmphasis:#color from:(#foo->Color red) |
|
439 |
" |
|
440 |
||
441 |
"Modified: 14.5.1996 / 17:45:11 / cg" |
|
442 |
"Created: 11.7.1996 / 09:49:58 / cg" |
|
443 |
! |
|
444 |
||
1068 | 445 |
removeEmphasis:emToRemove from:emp |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
446 |
"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
|
447 |
|
834
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
448 |
|ne idx| |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
449 |
|
1068 | 450 |
emToRemove isNil ifTrue:[^ emp]. |
451 |
emp isNil ifTrue:[^ emp]. |
|
452 |
emToRemove == emp ifTrue:[^ nil]. |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
453 |
|
1068 | 454 |
emp isSymbol ifTrue:[ |
455 |
emToRemove isSymbol ifTrue:[^ emp]. "/ knowing they are not identical |
|
456 |
emToRemove isAssociation ifTrue:[ |
|
457 |
emToRemove key == emp ifTrue:[^ nil]. |
|
458 |
^ emp |
|
755 | 459 |
]. |
1068 | 460 |
(emToRemove includes:emp) ifTrue:[^ nil]. |
461 |
^ emp |
|
755 | 462 |
]. |
1068 | 463 |
emp isAssociation ifTrue:[ |
464 |
emToRemove isSymbol ifTrue:[ |
|
465 |
emp key == emToRemove ifTrue:[^ nil]. |
|
466 |
^ emp |
|
755 | 467 |
]. |
1068 | 468 |
emToRemove isAssociation ifTrue:[ |
469 |
emToRemove key == emp key ifTrue:[^ nil]. |
|
470 |
^ emp |
|
755 | 471 |
]. |
1068 | 472 |
(emToRemove includes:emp) ifTrue:[^ nil]. |
473 |
^ emp |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
474 |
]. |
834
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
475 |
"/ e2 must be a collection |
1068 | 476 |
(emToRemove isSymbol |
477 |
or:[emToRemove isAssociation]) ifTrue:[ |
|
478 |
(emp includes:emToRemove) ifTrue:[ |
|
479 |
ne := emp copyWithout:emToRemove. |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
480 |
ne size == 1 ifTrue:[^ ne at:1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
481 |
ne size == 0 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
482 |
^ ne |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
483 |
]. |
834
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
484 |
|
1068 | 485 |
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
|
486 |
idx ~~ 0 ifTrue:[ |
1068 | 487 |
^ emp copyWithoutIndex:idx. |
834
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
488 |
]. |
1068 | 489 |
^ emp |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
490 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
491 |
|
754 | 492 |
"/ could use: |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
493 |
"/ ^ (e2 asSet removeAll:e1; asArray) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
494 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
495 |
"/ but we do it manually, to preserve the |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
496 |
"/ order. (should create longer runs, while editing) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
497 |
|
1068 | 498 |
ne := emp. |
499 |
emToRemove do:[:e | |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
500 |
(ne includes:e) ifTrue:[ |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
501 |
ne := ne copyWithout:e |
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 |
]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
504 |
ne size == 1 ifTrue:[^ ne at:1]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
505 |
ne size == 0 ifTrue:[^ nil]. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
506 |
^ ne. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
507 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
508 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
509 |
Text removeEmphasis:#bold from:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
510 |
Text removeEmphasis:#bold from:#italic |
1067 | 511 |
Text removeEmphasis:#bold from:#(italic strikeout) |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
512 |
Text removeEmphasis:#italic from:#(italic strikeout) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
513 |
Text removeEmphasis:#(italic strikeout) from:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
514 |
Text removeEmphasis:#(italic strikeout) from:#italic |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
515 |
Text removeEmphasis:#(italic strikeout) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
516 |
Text removeEmphasis:#(italic strikeout bold) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
517 |
Text removeEmphasis:#(italic strikeout bold underline) from:#(bold underline) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
518 |
Text removeEmphasis:(#color->Color red) from:#(bold underline) |
756 | 519 |
Text removeEmphasis:(#color->Color red) from:(#color->Color red) |
1067 | 520 |
Text removeEmphasis:#color from:(#color->Color red) |
521 |
Text removeEmphasis:#color from:(#backgroundColor->Color red) |
|
754 | 522 |
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
|
523 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
524 |
|
954 | 525 |
"Modified: / 14.5.1996 / 17:23:46 / cg" |
526 |
"Modified: / 25.1.2001 / 15:24:46 / ps" |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
527 |
! ! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
528 |
|
735 | 529 |
!Text methodsFor:'accessing'! |
530 |
||
531 |
at:characterIndex |
|
532 |
"return the plain character at characterIndex" |
|
533 |
||
534 |
^ string at:characterIndex |
|
535 |
||
536 |
"Created: 11.5.1996 / 14:25:41 / cg" |
|
537 |
"Modified: 16.5.1996 / 11:15:33 / cg" |
|
538 |
! |
|
539 |
||
540 |
at:characterIndex put:aCharacter |
|
541 |
"change the character at characterIndex to be aCharacter. |
|
542 |
The emphasis (if any) of that character remains unchanged." |
|
543 |
||
544 |
^ string at:characterIndex put:aCharacter |
|
545 |
||
546 |
"Created: 11.5.1996 / 14:25:49 / cg" |
|
547 |
"Modified: 16.5.1996 / 11:15:57 / cg" |
|
548 |
! ! |
|
549 |
||
304 | 550 |
!Text methodsFor:'comparing'! |
551 |
||
552 |
= aStringOrText |
|
553 |
"compare the receiver and the argument, ignoring emphasis" |
|
554 |
||
384 | 555 |
aStringOrText isString ifFalse:[^ false]. |
304 | 556 |
^ string = aStringOrText string |
557 |
||
558 |
||
559 |
" |
|
560 |
'hello' asText = 'hello' |
|
561 |
'hello' asText = 'hello' asText |
|
562 |
'hello' asText allBold = 'hello' |
|
563 |
" |
|
564 |
||
384 | 565 |
"Modified: 4.6.1996 / 11:14:58 / cg" |
662 | 566 |
! |
567 |
||
568 |
hash |
|
569 |
"return a suitable hashcode (req'd since = is redefined)" |
|
570 |
||
571 |
^ string hash |
|
572 |
||
573 |
"Created: / 19.6.1998 / 04:15:57 / cg" |
|
304 | 574 |
! ! |
575 |
||
576 |
!Text methodsFor:'converting'! |
|
577 |
||
578 |
asText |
|
1645 | 579 |
"return a Text-object (string with emphasis) from myself. |
580 |
I am already a text object." |
|
343 | 581 |
|
304 | 582 |
^ self |
583 |
||
584 |
"Created: 11.5.1996 / 14:08:36 / cg" |
|
343 | 585 |
"Modified: 16.5.1996 / 11:15:12 / cg" |
1173 | 586 |
! |
587 |
||
588 |
writeStream |
|
589 |
"return a stream for writing onto the receiver" |
|
590 |
||
591 |
^ TextStream on:self |
|
304 | 592 |
! ! |
593 |
||
594 |
!Text methodsFor:'copying'! |
|
595 |
||
596 |
, aStringOrText |
|
343 | 597 |
"concatenate the receivers characters with the arguments characters, |
598 |
and return string or text object containing those characters. |
|
599 |
If either the receiver or the argument contains emphasis information, |
|
600 |
a text object will be returned. Otherwise, a string (i.e. without emphasis) |
|
601 |
is returned." |
|
304 | 602 |
|
626 | 603 |
|newRuns| |
604 |
||
758 | 605 |
aStringOrText isCharacter ifTrue:[ |
606 |
^ self , aStringOrText asString |
|
607 |
]. |
|
615 | 608 |
aStringOrText hasChangeOfEmphasis ifTrue:[ |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
609 |
^ self species new |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
610 |
string:(string , aStringOrText) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
611 |
emphasisCollection:(runs , aStringOrText emphasisCollection) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
612 |
]. |
615 | 613 |
runs notNil "self hasChangeOfEmphasis" ifTrue:[ |
626 | 614 |
newRuns := runs copyFrom:1 to:(runs size). |
615 |
||
408 | 616 |
^ self species new |
617 |
string:(string , aStringOrText) |
|
626 | 618 |
emphasisCollection:(newRuns add:nil withOccurrences:(aStringOrText size); yourself) |
408 | 619 |
]. |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
620 |
^ string , aStringOrText string |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
621 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
622 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
623 |
('hello' asText allBold) , ' world' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
624 |
'hello' , (' world' asText allBold) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
625 |
'hello' , ' world' |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
626 |
('hello' asText allBold) , (' world' asText allBold) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
627 |
" |
304 | 628 |
|
626 | 629 |
"Modified: / 31.3.1998 / 16:34:04 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
630 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
631 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
632 |
concatenateFromString:aString |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
633 |
"return the concatenation of aString and myself. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
634 |
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
|
635 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
636 |
self hasChangeOfEmphasis ifTrue:[ |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
637 |
^ self species new |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
638 |
string:(aString , string) |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
639 |
emphasisCollection:((RunArray new:(aString size)) , runs). |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
640 |
]. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
641 |
^ aString , string |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
642 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
643 |
"Modified: 14.5.1996 / 15:56:05 / cg" |
394 | 644 |
! |
645 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
646 |
copyFrom:start to:stop |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
647 |
"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
|
648 |
at stop, anInteger." |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
649 |
|
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
650 |
self hasChangeOfEmphasis ifTrue:[ |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
651 |
^ self species new |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
652 |
string:(string copyFrom:start to:stop) |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
653 |
emphasisCollection:(runs copyFrom:start to:stop). |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
654 |
]. |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
655 |
^ string copyFrom:start to:stop |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
656 |
|
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
657 |
"Modified: 14.5.1996 / 15:56:05 / cg" |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
658 |
"Created: 22.10.1996 / 21:01:16 / cg" |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
659 |
! |
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
660 |
|
394 | 661 |
postCopy |
662 |
string := string copy. |
|
663 |
runs := runs copy |
|
307 | 664 |
! ! |
665 |
||
666 |
!Text methodsFor:'displaying'! |
|
667 |
||
963
0d5ef474ea17
draw opaque - if backgroundCOlor is set
Claus Gittinger <cg@exept.de>
parents:
954
diff
changeset
|
668 |
displayOn:aGC x:x0 y:y opaque:opaqueWanted |
307 | 669 |
"display the receiver on a GC" |
670 |
||
1000 | 671 |
|savedFont savedPaint savedFgPaint savedBgPaint font color boldFont italicFont boldItalicFont |
672 |
bgPaint etchColor ulPaint strikePaint |
|
2110 | 673 |
wasItalic overline |
702
0c2c9b9fb4aa
added support for wave-line underlining
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
674 |
bold italic underline underwave strikeout reverse |
310 | 675 |
pos "{ Class: SmallInteger }" |
676 |
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
|
677 |
x |
310 | 678 |
l "{ Class: SmallInteger }" |
963
0d5ef474ea17
draw opaque - if backgroundCOlor is set
Claus Gittinger <cg@exept.de>
parents:
954
diff
changeset
|
679 |
yL k value device opaque| |
307 | 680 |
|
681 |
savedFont := aGC basicFont. |
|
682 |
savedPaint := aGC paint. |
|
315 | 683 |
savedBgPaint := aGC backgroundPaint. |
307 | 684 |
|
963
0d5ef474ea17
draw opaque - if backgroundCOlor is set
Claus Gittinger <cg@exept.de>
parents:
954
diff
changeset
|
685 |
opaque := opaqueWanted. |
705 | 686 |
device := aGC graphicsDevice. |
687 |
||
307 | 688 |
pos := 1. |
689 |
x := x0. |
|
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
690 |
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
|
691 |
|
307 | 692 |
runs runsDo:[:len :emphasis | |
2110 | 693 |
wasItalic := italic. |
694 |
color := savedPaint. |
|
695 |
bold := italic := underline := underwave := strikeout := reverse := false. |
|
696 |
bgPaint := savedBgPaint. |
|
307 | 697 |
|
2110 | 698 |
emphasis isSymbol ifTrue:[ |
699 |
emphasis == #bold ifTrue:[bold := true] |
|
700 |
ifFalse:[emphasis == #italic ifTrue:[italic := true] |
|
701 |
ifFalse:[emphasis == #underline ifTrue:[underline := true] |
|
702 |
ifFalse:[emphasis == #overline ifTrue:[overline := true] "MB:added" |
|
703 |
ifFalse:[emphasis == #underwave ifTrue:[underwave := true] |
|
704 |
ifFalse:[emphasis == #strikeout ifTrue:[strikeout := true] |
|
705 |
ifFalse:[emphasis == #reverse ifTrue:[reverse := true] |
|
706 |
ifFalse:[emphasis == #boldUnderline ifTrue:[bold := underline := true] |
|
707 |
ifFalse:[emphasis == #boldOverline ifTrue:[bold := overline := true] "MB:added" |
|
708 |
ifFalse:[emphasis == #boldUnderwave ifTrue:[bold := underwave := true] |
|
709 |
ifFalse:[emphasis == #italicUnderline ifTrue:[italic := underline := true] |
|
710 |
ifFalse:[emphasis == #italicUnderwave ifTrue:[italic := underwave := true] |
|
711 |
]]]]]]]]]]] |
|
712 |
] ifFalse:[ |
|
713 |
(emphasis isMemberOf:Association) ifTrue:[ |
|
714 |
value := emphasis value. |
|
715 |
value notNil ifTrue:[ |
|
716 |
k := emphasis key. |
|
717 |
k == #color ifTrue:[ |
|
718 |
color := value onDevice:device. |
|
719 |
emphasis value:color. |
|
720 |
] ifFalse:[k == #backgroundColor ifTrue:[ |
|
721 |
bgPaint := value onDevice:device. |
|
722 |
emphasis value:bgPaint. |
|
723 |
opaque := true. |
|
724 |
] ifFalse:[k == #underlineColor ifTrue:[ |
|
725 |
ulPaint := value onDevice:device. |
|
726 |
emphasis value:ulPaint. |
|
727 |
] ifFalse:[k == #strikeoutColor ifTrue:[ |
|
728 |
strikePaint := value onDevice:device. |
|
729 |
emphasis value:strikePaint. |
|
730 |
] ifFalse:[k == #etchColor ifTrue:[ |
|
731 |
etchColor := value onDevice:device. |
|
732 |
emphasis value:etchColor. |
|
733 |
]]]]] |
|
734 |
] |
|
735 |
] ifFalse:[ |
|
736 |
emphasis notNil ifTrue:[ |
|
737 |
emphasis do:[:entry | |
|
738 |
entry == #bold ifTrue:[bold := true] |
|
739 |
ifFalse:[entry == #italic ifTrue:[italic := true] |
|
740 |
ifFalse:[entry == #underline ifTrue:[underline := true] |
|
741 |
ifFalse:[entry == #underwave ifTrue:[underwave := true] |
|
742 |
ifFalse:[entry == #strikeout ifTrue:[strikeout := true] |
|
743 |
ifFalse:[entry == #reverse ifTrue:[reverse := true] |
|
744 |
ifFalse:[entry == #boldUnderline ifTrue:[bold := underline := true] |
|
745 |
ifFalse:[emphasis == #boldUnderwave ifTrue:[bold := underwave := true] |
|
746 |
ifFalse:[entry == #italicUnderline ifTrue:[italic := underline := true] |
|
747 |
ifFalse:[emphasis == #italicUnderwave ifTrue:[italic := underwave := true] |
|
748 |
ifFalse:[ |
|
749 |
(entry isMemberOf:Association) ifTrue:[ |
|
750 |
value := entry value. |
|
751 |
value notNil ifTrue:[ |
|
752 |
k := entry key. |
|
753 |
k == #color ifTrue:[ |
|
754 |
color := value onDevice:device. |
|
755 |
entry value:color. |
|
756 |
] ifFalse:[k == #backgroundColor ifTrue:[ |
|
757 |
bgPaint := value onDevice:device. |
|
758 |
entry value:bgPaint. |
|
759 |
opaque := true. |
|
760 |
] ifFalse:[k == #underlineColor ifTrue:[ |
|
761 |
ulPaint := value onDevice:device. |
|
762 |
entry value:ulPaint. |
|
763 |
] ifFalse:[k == #strikeoutColor ifTrue:[ |
|
764 |
strikePaint := value onDevice:device. |
|
765 |
entry value:strikePaint. |
|
766 |
] ifFalse:[k == #etchColor ifTrue:[ |
|
767 |
etchColor := value onDevice:device. |
|
768 |
entry value:etchColor. |
|
769 |
]]]]] |
|
770 |
] |
|
771 |
] |
|
772 |
]]]]]]]]]] |
|
773 |
] |
|
774 |
] |
|
775 |
] |
|
776 |
]. |
|
307 | 777 |
|
2110 | 778 |
bold ifTrue:[ |
779 |
italic ifTrue:[ |
|
780 |
boldItalicFont isNil ifTrue:[ |
|
781 |
boldItalicFont := savedFont asBold asItalic onDevice:device |
|
782 |
]. |
|
783 |
font := boldItalicFont. |
|
784 |
] ifFalse:[ |
|
785 |
boldFont isNil ifTrue:[ |
|
786 |
boldFont := savedFont asBold onDevice:device |
|
787 |
]. |
|
788 |
font := boldFont. |
|
789 |
] |
|
790 |
] ifFalse:[ |
|
791 |
italic ifTrue:[ |
|
792 |
italicFont isNil ifTrue:[ |
|
793 |
italicFont := savedFont asItalic onDevice:device |
|
794 |
]. |
|
795 |
font := italicFont. |
|
796 |
] ifFalse:[ |
|
797 |
font := savedFont |
|
798 |
] |
|
799 |
]. |
|
800 |
font := font onDevice:device. |
|
801 |
aGC basicFont:font. |
|
802 |
reverse ifTrue:[ |
|
803 |
aGC paint:bgPaint on:color. |
|
804 |
opaque := true. |
|
805 |
] ifFalse:[ |
|
806 |
aGC paint:color on:bgPaint. |
|
807 |
]. |
|
808 |
endPos := pos + len - 1. |
|
809 |
||
810 |
wasItalic ~~ italic ifTrue:[ |
|
811 |
italic ifFalse:[ |
|
812 |
"/ going from italic to non-italic; leave some space for the shear |
|
813 |
x := x + (font width " // 2" ) |
|
814 |
]. |
|
815 |
]. |
|
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
816 |
|
2110 | 817 |
(opaque and:[etchColor isNil]) ifTrue:[ |
818 |
aGC displayOpaqueString:string from:pos to:endPos x:x y:y. |
|
819 |
] ifFalse:[ |
|
820 |
etchColor notNil ifTrue:[ |
|
821 |
opaque ifTrue:[ |
|
822 |
"/ sigh - must draw the background rectangle; |
|
823 |
"/ its easier (and faster) to draw the string twice here ... |
|
824 |
aGC displayOpaqueString:string from:pos to:endPos x:x y:y. |
|
825 |
]. |
|
826 |
savedFgPaint := aGC paint. |
|
827 |
aGC paint:etchColor. |
|
828 |
aGC displayString:string from:pos to:endPos x:x+1 y:y+1. |
|
829 |
aGC paint:savedFgPaint. |
|
830 |
]. |
|
831 |
aGC displayString:string from:pos to:endPos x:x y:y. |
|
832 |
]. |
|
833 |
l := font widthOf:string from:pos to:endPos. |
|
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
834 |
|
2110 | 835 |
underline ifTrue:[ |
836 |
ulPaint notNil ifTrue:[aGC paint:ulPaint]. |
|
837 |
yL := y+1. |
|
838 |
aGC displayLineFromX:x y:yL toX:x+l-1 y:yL |
|
839 |
]. |
|
840 |
(overline ? false) ifTrue:[ "MB:added v" |
|
841 |
ulPaint notNil ifTrue:[aGC paint:ulPaint]. |
|
842 |
yL := y-(font heightOf: string) + 2. |
|
843 |
aGC displayLineFromX:x y:yL toX:x+l-1 y:yL |
|
844 |
]. "MB:added ^" |
|
845 |
underwave ifTrue:[ |
|
846 |
ulPaint notNil ifTrue:[aGC paint:ulPaint]. |
|
847 |
yL := y+1. |
|
848 |
aGC displayHorizontalWavelineFromX:x y:yL toX:x+l-1 |
|
849 |
]. |
|
850 |
strikeout ifTrue:[ |
|
851 |
strikePaint notNil ifTrue:[aGC paint:strikePaint]. |
|
852 |
yL := y-(font ascent//2). |
|
853 |
aGC displayLineFromX:x y:yL toX:x+l-1 y:yL |
|
854 |
]. |
|
307 | 855 |
|
2110 | 856 |
x := x + l. |
857 |
pos := endPos + 1 |
|
304 | 858 |
]. |
307 | 859 |
|
860 |
aGC basicFont:savedFont. |
|
316 | 861 |
aGC paint:savedPaint on:savedBgPaint. |
307 | 862 |
|
591
dfa5c6178f6d
care to use deviceFont in width-query
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
863 |
"Created: / 12.5.1996 / 11:14:30 / cg" |
761 | 864 |
"Modified: / 7.7.1999 / 00:08:12 / cg" |
304 | 865 |
! ! |
866 |
||
867 |
!Text methodsFor:'emphasis'! |
|
868 |
||
869 |
allBold |
|
870 |
"make all characters bold" |
|
871 |
||
406 | 872 |
self emphasizeAllWith:#bold |
304 | 873 |
|
874 |
" |
|
875 |
(Text string:'hello') allBold |
|
2056 | 876 |
Transcript showCR: ('hello' allBold) |
304 | 877 |
" |
878 |
||
406 | 879 |
"Modified: 10.7.1996 / 12:07:51 / cg" |
304 | 880 |
! |
881 |
||
2110 | 882 |
allBoldOverline |
883 |
"make all characters overline" |
|
884 |
||
885 |
self emphasizeAllWith:#boldOverline |
|
886 |
! |
|
887 |
||
734 | 888 |
allItalic |
889 |
"make all characters italic" |
|
890 |
||
891 |
self emphasizeAllWith:#italic |
|
892 |
||
893 |
" |
|
894 |
(Text string:'hello') allItalic |
|
2056 | 895 |
Transcript showCR: ('hello' allItalic) |
734 | 896 |
" |
897 |
||
898 |
"Modified: 10.7.1996 / 12:07:51 / cg" |
|
899 |
! |
|
900 |
||
2110 | 901 |
allOverline |
902 |
"make all characters overline" |
|
903 |
||
904 |
self emphasizeAllWith:#overline |
|
905 |
! |
|
906 |
||
2056 | 907 |
allStrikedOut |
908 |
"strikeOut all characters" |
|
909 |
||
910 |
self emphasisAllAdd:#strikeout. |
|
911 |
||
912 |
" |
|
913 |
Transcript showCR: ('hello' allStrikedOut) |
|
914 |
" |
|
915 |
! |
|
916 |
||
1020
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
917 |
allUnderlined |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
918 |
"underline all characters" |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
919 |
|
2056 | 920 |
self emphasisAllAdd:#underline. |
1020
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
921 |
|
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
922 |
" |
2056 | 923 |
Transcript showCR:('hello' allUnderlined) |
1020
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
924 |
" |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
925 |
! |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
926 |
|
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
927 |
backgroundColorizeAllWith:aColor |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
928 |
"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
|
929 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
930 |
self emphasisAllAdd:(#backgroundColor -> aColor). |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
931 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
932 |
" |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
933 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
934 |
((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
|
935 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
936 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
937 |
('hello' allBold backgroundColorizeAllWith:(Color red)) |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
938 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
939 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
940 |
('hello' asText backgroundColorizeAllWith:(Color red)) |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
941 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
942 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
943 |
('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
|
944 |
" |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
945 |
! |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
946 |
|
999 | 947 |
colorizeAllWith:aColor |
948 |
"change the color of all characters" |
|
949 |
||
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
950 |
self emphasisAllAdd:(#color -> aColor). |
999 | 951 |
|
952 |
" |
|
953 |
Transcript showCR: |
|
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
954 |
((Text string:'hello') colorizeAllWith:(Color red)) |
999 | 955 |
|
956 |
Transcript showCR: |
|
2056 | 957 |
('hello' colorizeAllWith:(Color red)) |
958 |
||
959 |
Transcript showCR: |
|
1019
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
960 |
('hello' allBold colorizeAllWith:(Color red)) |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
961 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
962 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
963 |
('hello' asText colorizeAllWith:(Color red)) |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
964 |
|
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
965 |
Transcript showCR: |
38ec486889d9
colorizeAllWith: ADDs to the emphasis (used to SET it)
Claus Gittinger <cg@exept.de>
parents:
1000
diff
changeset
|
966 |
('hello ' , ('red' allBold colorizeAllWith:(Color red)) , ' world') |
999 | 967 |
" |
968 |
! |
|
969 |
||
1648 | 970 |
colorizeAllWith:aColor on:bgColor |
971 |
"change the color and bg-color of all characters" |
|
972 |
||
973 |
self emphasisAllAdd:(#color -> aColor). |
|
974 |
self emphasisAllAdd:(#backgroundColor -> bgColor). |
|
975 |
||
976 |
" |
|
977 |
Transcript showCR: |
|
978 |
((Text string:'hello') colorizeAllWith:(Color red) on:(Color blue)) |
|
979 |
" |
|
980 |
||
981 |
"Created: / 05-08-2006 / 14:48:13 / cg" |
|
982 |
! |
|
983 |
||
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
984 |
emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
985 |
"return the emphasis" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
986 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
987 |
^ runs |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
988 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
989 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
990 |
(Text string:'hello') allBold emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
991 |
'hello' emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
992 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
993 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
994 |
"Modified: 11.5.1996 / 14:22:31 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
995 |
"Created: 14.5.1996 / 13:59:03 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
996 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
997 |
|
1070 | 998 |
emphasis:emArray |
999 |
1 to:string size do:[:characterIndex | |
|
1000 |
self emphasisAt:characterIndex put:(emArray at:characterIndex) |
|
1001 |
]. |
|
1002 |
||
1003 |
" |
|
1004 |
(Text string:'hello') emphasis:#(italic bold italic bold bold) |
|
1005 |
" |
|
1006 |
||
1007 |
"Modified: / 31.3.1998 / 16:45:14 / cg" |
|
1008 |
! |
|
1009 |
||
778 | 1010 |
emphasisAllAdd:newEmphasis |
1011 |
"add to the emphasis to all characters. return the receiver" |
|
1012 |
||
1013 |
self emphasisFrom:1 to:(self size) add:newEmphasis |
|
1014 |
||
1015 |
" |
|
1016 |
(Text string:'hello') allBold |
|
1017 |
emphasisAllAdd:#italic |
|
1018 |
||
1019 |
Transcript show:((Text string:'hello') allBold |
|
1020 |
emphasisAllAdd:#italic) |
|
1021 |
" |
|
1022 |
! |
|
1023 |
||
1024 |
emphasisAllRemove:anEmphasis |
|
1025 |
"remove the emphasis from all characters. return the receiver" |
|
1026 |
||
1027 |
self emphasisFrom:1 to:(self size) remove:anEmphasis |
|
1028 |
||
1029 |
" |
|
1030 |
((Text string:'hello') emphasizeAllWith:#(bold italic)) |
|
1031 |
emphasisAllRemove:#italic |
|
1032 |
||
834
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1033 |
((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
|
1034 |
with:#italic)) |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1035 |
emphasisAllRemove:#italic |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1036 |
|
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1037 |
((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
|
1038 |
with:#italic)) |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1039 |
emphasisAllRemove:#color |
08c8f9d9ca0a
fixed removal of an association-emphasis by key.
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
1040 |
|
778 | 1041 |
Transcript show:(((Text string:'hello') emphasizeAllWith:#(bold italic)) |
1042 |
emphasisAllRemove:#italic) |
|
1043 |
" |
|
1044 |
! |
|
1045 |
||
304 | 1046 |
emphasisAt:characterIndex |
1047 |
"return the emphasis at some index" |
|
1048 |
||
1049 |
^ runs at:characterIndex |
|
1050 |
||
1051 |
" |
|
1052 |
(Text string:'hello') allBold emphasisAt:2 |
|
1053 |
" |
|
1054 |
||
1055 |
"Modified: 11.5.1996 / 14:22:31 / cg" |
|
1056 |
! |
|
1057 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1058 |
emphasisAt:characterIndex add:newEmphasis |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1059 |
"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
|
1060 |
|
626 | 1061 |
|e prevE| |
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1062 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1063 |
e := runs at:characterIndex. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1064 |
e := self class addEmphasis:newEmphasis to:e. |
626 | 1065 |
|
1066 |
"/ if its equal to the previous emphasis, make it identical. |
|
1067 |
||
1068 |
characterIndex > 1 ifTrue:[ |
|
1069 |
prevE := runs at:characterIndex-1. |
|
1070 |
e = prevE ifTrue:[ |
|
1071 |
e := prevE |
|
1072 |
] |
|
1073 |
]. |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1074 |
runs at:characterIndex put:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1075 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1076 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1077 |
(Text string:'hello') allBold emphasisAt:2 add:#italic |
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 |
|
626 | 1080 |
"Created: / 14.5.1996 / 16:48:39 / cg" |
1081 |
"Modified: / 31.3.1998 / 15:29:14 / cg" |
|
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1082 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1083 |
|
307 | 1084 |
emphasisAt:characterIndex put:emphasis |
1085 |
"change the emphasis at some index. return the receiver" |
|
1086 |
||
626 | 1087 |
|e prevE| |
1088 |
||
1089 |
e := emphasis. |
|
1090 |
||
1091 |
"/ if its equal to the previous emphasis, make it identical. |
|
1092 |
||
1093 |
characterIndex > 1 ifTrue:[ |
|
1094 |
prevE := runs at:characterIndex-1. |
|
1095 |
emphasis = prevE ifTrue:[ |
|
1096 |
e := prevE |
|
1097 |
] |
|
1098 |
]. |
|
1099 |
runs at:characterIndex put:e |
|
307 | 1100 |
|
1101 |
" |
|
1102 |
(Text string:'hello') allBold emphasisAt:2 put:#italic |
|
1103 |
" |
|
1104 |
||
626 | 1105 |
"Modified: / 31.3.1998 / 16:45:14 / cg" |
307 | 1106 |
! |
1107 |
||
336
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1108 |
emphasisAt:characterIndex remove:emphasisToRemove |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1109 |
"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
|
1110 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1111 |
|e| |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1112 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1113 |
e := runs at:characterIndex. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1114 |
e := self class removeEmphasis:emphasisToRemove from:e. |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1115 |
runs at:characterIndex put:e |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1116 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1117 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1118 |
(Text string:'hello') |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1119 |
allBold emphasisAt:2 remove:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1120 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1121 |
(Text string:'hello' emphasis:#(bold italic)) |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1122 |
emphasisAt:2 remove:#bold |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1123 |
" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1124 |
|
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1125 |
"Created: 14.5.1996 / 16:48:39 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1126 |
"Modified: 14.5.1996 / 17:25:04 / cg" |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1127 |
! |
5fd5fcc38eaa
helpers to add/remove emphasis
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1128 |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1129 |
emphasisCollection |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1130 |
"return the emphasis" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1131 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1132 |
^ runs |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1133 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1134 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1135 |
(Text string:'hello') allBold emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1136 |
'hello' emphasis |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1137 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1138 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1139 |
"Created: 14.5.1996 / 13:59:03 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1140 |
"Modified: 14.5.1996 / 15:02:11 / cg" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1141 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1142 |
|
777 | 1143 |
emphasisFrom:start to:stop add:newEmphasis |
1144 |
"add to the emphasis within some range. return the receiver" |
|
1145 |
||
1146 |
start to:stop do:[:characterIndex | |
|
1147 |
self emphasisAt:characterIndex add:newEmphasis |
|
1148 |
]. |
|
1149 |
||
1150 |
" |
|
1151 |
(Text string:'hello') allBold |
|
1152 |
emphasisFrom:2 to:4 add:#italic |
|
1153 |
||
1154 |
Transcript showCR:((Text string:'hello') allBold |
|
1155 |
emphasisFrom:2 to:4 add:#italic) |
|
1156 |
||
1157 |
" |
|
1158 |
! |
|
1159 |
||
1160 |
emphasisFrom:start to:stop remove:anEmphasis |
|
1161 |
"remove from the emphasis within some range. return the receiver" |
|
1162 |
||
1163 |
start to:stop do:[:characterIndex | |
|
1164 |
self emphasisAt:characterIndex remove:anEmphasis |
|
1165 |
]. |
|
1166 |
||
1167 |
" |
|
1168 |
(Text string:'hello') allBold |
|
1169 |
emphasisFrom:2 to:4 remove:#bold |
|
1170 |
||
1171 |
Transcript showCR:((Text string:'hello') allBold |
|
1172 |
emphasisFrom:2 to:4 remove:#bold) |
|
1173 |
" |
|
1174 |
! |
|
1175 |
||
304 | 1176 |
emphasizeAllWith:emphasis |
1177 |
"change the emphasis of all characters" |
|
1178 |
||
1179 |
runs := RunArray new:(string size) withAll:emphasis |
|
1180 |
||
1181 |
" |
|
1182 |
(Text string:'hello') allBold emphasizeAllWith:#italic |
|
1183 |
" |
|
1184 |
||
1185 |
"Modified: 11.5.1996 / 14:22:52 / cg" |
|
1186 |
! |
|
1187 |
||
343 | 1188 |
emphasizeFrom:start count:count with:emphasis |
1189 |
"change the emphasis of a range of characters, given startIndex and count." |
|
1190 |
||
1191 |
self emphasizeFrom:start to:(start+count-1) with:emphasis |
|
1192 |
||
1193 |
" |
|
1194 |
(Text string:'hello world') |
|
1195 |
emphasizeFrom:1 count:5 with:#bold; |
|
1196 |
emphasizeFrom:7 count:5 with:#italic |
|
1197 |
" |
|
1198 |
||
1199 |
"Modified: 11.5.1996 / 14:30:02 / cg" |
|
1200 |
"Created: 16.5.1996 / 10:52:27 / cg" |
|
1201 |
! |
|
1202 |
||
304 | 1203 |
emphasizeFrom:start to:stop with:emphasis |
1204 |
"change the emphasis of a range of characters" |
|
1205 |
||
1206 |
|newRuns| |
|
1207 |
||
631 | 1208 |
runs from:start to:stop put:emphasis. |
626 | 1209 |
|
777 | 1210 |
"/ newRuns := RunArray new. |
1211 |
"/ |
|
1212 |
"/ "/ for now - a q&d hack |
|
1213 |
"/ 1 to:start-1 do:[:i | |
|
1214 |
"/ newRuns add:(runs at:i). |
|
1215 |
"/ ]. |
|
1216 |
"/ newRuns add:emphasis withOccurrences:(stop - start + 1). |
|
1217 |
"/ stop+1 to:string size do:[:i | |
|
1218 |
"/ newRuns add:(runs at:i) |
|
1219 |
"/ ]. |
|
1220 |
"/ runs := newRuns |
|
304 | 1221 |
|
1222 |
" |
|
1223 |
(Text string:'hello world') |
|
1224 |
emphasizeFrom:1 to:5 with:#bold; |
|
1225 |
emphasizeFrom:7 to:11 with:#italic |
|
1226 |
" |
|
1227 |
||
631 | 1228 |
"Modified: / 7.4.1998 / 08:52:18 / cg" |
347 | 1229 |
! |
1230 |
||
1231 |
emphasizeFrom:start with:emphasis |
|
1232 |
"change the emphasis of some characters upTo the end" |
|
1233 |
||
1234 |
self emphasizeFrom:start to:(self size) with:emphasis |
|
1235 |
||
1236 |
" |
|
1237 |
(Text string:'hello world') |
|
1238 |
emphasizeFrom:1 count:5 with:#bold; |
|
1239 |
emphasizeFrom:7 with:#italic |
|
1240 |
" |
|
1241 |
||
1242 |
"Modified: 11.5.1996 / 14:30:02 / cg" |
|
1243 |
"Created: 17.5.1996 / 15:15:32 / cg" |
|
1020
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1244 |
! |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1245 |
|
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1246 |
strikeoutAll |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1247 |
"strikeout all characters" |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1248 |
|
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1249 |
self emphasisAllAdd:(#strikeout). |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1250 |
|
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1251 |
" |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1252 |
Transcript showCR: |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1253 |
('hello' asText strikeoutAll) |
a6304ef6b18a
more: allUnderlined; backgroundColorize and strikeoutAll
Claus Gittinger <cg@exept.de>
parents:
1019
diff
changeset
|
1254 |
" |
1069 | 1255 |
! |
1256 |
||
1257 |
withoutEmphasis:emphasisToRemove |
|
1258 |
|newText| |
|
1259 |
||
1260 |
self hasChangeOfEmphasis ifTrue:[ |
|
1261 |
newText := self copyFrom:1 to:self size. |
|
1262 |
1 to:newText size do:[:col | |
|
1263 |
|em newem| |
|
1264 |
||
1265 |
em := (newText emphasis) at:col. |
|
1266 |
em notNil ifTrue:[ |
|
1267 |
newem := Text removeEmphasis:emphasisToRemove from:em. |
|
1268 |
newem ~~ em ifTrue:[ |
|
1269 |
newText emphasisAt:col put:newem |
|
1270 |
] |
|
1271 |
]. |
|
1272 |
]. |
|
1273 |
^ newText |
|
1274 |
]. |
|
1275 |
^ self |
|
304 | 1276 |
! ! |
1277 |
||
1757 | 1278 |
|
304 | 1279 |
!Text methodsFor:'printing & storing'! |
1280 |
||
343 | 1281 |
printOn:aStream |
1282 |
"print the receivers characters (including emphasis) on |
|
409 | 1283 |
aStream. |
1077 | 1284 |
Notice, that some streams simply ignore the emphasis" |
343 | 1285 |
|
2051 | 1286 |
aStream nextPutAllText:self |
304 | 1287 |
|
343 | 1288 |
" |
407 | 1289 |
Transcript showCR:'hello world'. |
1290 |
Transcript showCR:'hello world' asText allBold. |
|
1291 |
Transcript showCR:('hello world' asText emphasizeAllWith:#italic). |
|
343 | 1292 |
" |
304 | 1293 |
|
409 | 1294 |
"Modified: 12.7.1996 / 10:15:47 / cg" |
304 | 1295 |
! |
1296 |
||
1297 |
storeOn:aStream |
|
343 | 1298 |
"append a printed representation from which the receiver can be reconstructed |
1299 |
to aStream." |
|
1300 |
||
304 | 1301 |
aStream nextPutAll:'(Text string:'. |
1302 |
string storeOn:aStream. |
|
307 | 1303 |
aStream nextPutAll:' runs:'. |
304 | 1304 |
runs storeOn:aStream. |
1305 |
aStream nextPutAll:')'. |
|
1306 |
||
1307 |
"Created: 11.5.1996 / 14:27:09 / cg" |
|
343 | 1308 |
"Modified: 16.5.1996 / 11:23:32 / cg" |
304 | 1309 |
! ! |
1310 |
||
1200 | 1311 |
!Text methodsFor:'private-accessing'! |
304 | 1312 |
|
631 | 1313 |
emphasisCollection:emphasisCollection |
1314 |
"set the string and emphasis collection. |
|
1315 |
The emphasis collection contains per-character information." |
|
1316 |
||
1317 |
runs := emphasisCollection |
|
1318 |
||
1319 |
"Created: / 7.4.1998 / 08:52:03 / cg" |
|
1320 |
! |
|
1321 |
||
872
2ca6864d13bb
new private accessor (for subclass compatibility)
Claus Gittinger <cg@exept.de>
parents:
854
diff
changeset
|
1322 |
setString:aString setRuns:anArray |
2ca6864d13bb
new private accessor (for subclass compatibility)
Claus Gittinger <cg@exept.de>
parents:
854
diff
changeset
|
1323 |
string := aString. |
2ca6864d13bb
new private accessor (for subclass compatibility)
Claus Gittinger <cg@exept.de>
parents:
854
diff
changeset
|
1324 |
runs := anArray |
2ca6864d13bb
new private accessor (for subclass compatibility)
Claus Gittinger <cg@exept.de>
parents:
854
diff
changeset
|
1325 |
|
2ca6864d13bb
new private accessor (for subclass compatibility)
Claus Gittinger <cg@exept.de>
parents:
854
diff
changeset
|
1326 |
! |
2ca6864d13bb
new private accessor (for subclass compatibility)
Claus Gittinger <cg@exept.de>
parents:
854
diff
changeset
|
1327 |
|
304 | 1328 |
string:aString emphasis:emphasis |
343 | 1329 |
"set the string and emphasis. The emphasis is applied to all characters." |
1330 |
||
428 | 1331 |
string := aString string. |
1332 |
runs := RunArray new:string size withAll:emphasis |
|
304 | 1333 |
|
1334 |
" |
|
1335 |
|t| |
|
1336 |
||
1337 |
t := Text new string:'hello' emphasis:#bold. |
|
1338 |
t emphasisAt:2. |
|
1339 |
" |
|
1340 |
||
343 | 1341 |
"Modified: 16.5.1996 / 11:24:03 / cg" |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1342 |
! |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1343 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1344 |
string:aString emphasisCollection:emphasisCollection |
343 | 1345 |
"set the string and emphasis collection. |
1346 |
The emphasis collection contains per-character information." |
|
1347 |
||
428 | 1348 |
string := aString string. |
1160 | 1349 |
string size == 0 ifTrue:[ |
1350 |
runs := RunArray new. |
|
1351 |
] ifFalse:[ |
|
1352 |
runs := emphasisCollection asRunArray |
|
1353 |
]. |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1354 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1355 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1356 |
|t| |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1357 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1358 |
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
|
1359 |
t emphasisAt:2. |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1360 |
" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1361 |
|
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1362 |
"Created: 14.5.1996 / 14:03:29 / cg" |
343 | 1363 |
"Modified: 16.5.1996 / 11:24:21 / cg" |
304 | 1364 |
! ! |
1365 |
||
1366 |
!Text methodsFor:'queries'! |
|
1367 |
||
1401 | 1368 |
encoding |
1369 |
^ string encoding |
|
1370 |
! |
|
1371 |
||
304 | 1372 |
hasChangeOfEmphasis |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1373 |
"return true, if the receiver contains non-empty emphasis information" |
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1374 |
|
2051 | 1375 |
^ (runs notEmptyOrNil |
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1376 |
and:[(runs findFirst:[:e | e notNil]) ~~ 0]) |
304 | 1377 |
|
1378 |
"Created: 11.5.1996 / 14:03:19 / cg" |
|
335
4adf1b6b4063
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1379 |
"Modified: 14.5.1996 / 15:51:01 / cg" |
304 | 1380 |
! |
1381 |
||
307 | 1382 |
heightOn:aGC |
1383 |
"return the number of device units, required on aGC's device" |
|
1384 |
||
621 | 1385 |
^ (aGC font onDevice:aGC device) heightOf:string |
307 | 1386 |
|
1387 |
"Created: 12.5.1996 / 11:02:03 / cg" |
|
1388 |
! |
|
1389 |
||
304 | 1390 |
indexOf:aCharacter startingAt:index |
343 | 1391 |
"search aCharacters index in the underlying string" |
1392 |
||
304 | 1393 |
^ string indexOf:aCharacter startingAt:index |
1394 |
||
1395 |
"Created: 11.5.1996 / 13:58:56 / cg" |
|
343 | 1396 |
"Modified: 16.5.1996 / 11:25:12 / cg" |
304 | 1397 |
! |
1398 |
||
307 | 1399 |
isText |
343 | 1400 |
"return true if this is a Text object - always true here" |
1401 |
||
307 | 1402 |
^ true |
1403 |
||
1404 |
"Created: 12.5.1996 / 10:56:24 / cg" |
|
343 | 1405 |
"Modified: 16.5.1996 / 11:25:29 / cg" |
307 | 1406 |
! |
1407 |
||
304 | 1408 |
occurrencesOf:aCharacter |
343 | 1409 |
"count & return the number of occurrences of aCharacter in the |
1410 |
underlying string" |
|
1411 |
||
304 | 1412 |
^ string occurrencesOf:aCharacter |
1413 |
||
1414 |
"Created: 11.5.1996 / 13:58:46 / cg" |
|
343 | 1415 |
"Modified: 16.5.1996 / 11:25:51 / cg" |
304 | 1416 |
! |
1417 |
||
1418 |
size |
|
343 | 1419 |
"return the number of characters in the underlying string" |
1420 |
||
304 | 1421 |
^ string size |
1422 |
||
1423 |
"Created: 11.5.1996 / 14:25:15 / cg" |
|
343 | 1424 |
"Modified: 16.5.1996 / 11:26:08 / cg" |
304 | 1425 |
! |
1426 |
||
1427 |
string |
|
343 | 1428 |
"return the receiver without any emphasis information |
1429 |
i.e. the underlying string." |
|
1430 |
||
304 | 1431 |
^ string |
1432 |
||
1433 |
"Created: 11.5.1996 / 13:58:38 / cg" |
|
343 | 1434 |
"Modified: 16.5.1996 / 11:26:30 / cg" |
307 | 1435 |
! |
1436 |
||
1069 | 1437 |
widthFrom:startIndex to:endIndex on:aGC |
1438 |
"return the number of device units, required on aGC's device" |
|
1439 |
||
1440 |
^ (self copyFrom:startIndex to:endIndex) widthOn:aGC |
|
1441 |
! |
|
1442 |
||
307 | 1443 |
widthOn:aGC |
1444 |
"return the number of device units, required on aGC's device" |
|
1445 |
||
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1446 |
|savedFont boldFont italicFont bold italic wasItalic pos f l device| |
307 | 1447 |
|
404
14cf34141532
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
395
diff
changeset
|
1448 |
device := aGC graphicsDevice. |
14cf34141532
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
395
diff
changeset
|
1449 |
|
794 | 1450 |
savedFont := aGC basicFont onDevice:device. |
307 | 1451 |
|
1452 |
pos := 1. |
|
1453 |
l := 0. |
|
975
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1454 |
italic := false. |
307 | 1455 |
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
|
1456 |
wasItalic := italic. |
307 | 1457 |
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
|
1458 |
bold := (emphasis == #bold). |
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1459 |
italic := (emphasis == #italic). |
307 | 1460 |
] ifFalse:[ |
308 | 1461 |
(emphasis isNil |
1462 |
or:[emphasis isMemberOf:Association]) ifTrue:[ |
|
307 | 1463 |
bold := italic := false |
1464 |
] ifFalse:[ |
|
1465 |
bold := emphasis includesIdentical:#bold. |
|
1466 |
italic := emphasis includesIdentical:#italic. |
|
1467 |
] |
|
1468 |
]. |
|
1469 |
||
1470 |
bold ifTrue:[ |
|
1471 |
boldFont isNil ifTrue:[ |
|
899
fe2b44d0d9c1
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
1472 |
boldFont := savedFont asBold onDevice:device |
307 | 1473 |
]. |
1474 |
f := boldFont. |
|
1475 |
] ifFalse:[ |
|
1476 |
italic ifTrue:[ |
|
1477 |
italicFont isNil ifTrue:[ |
|
899
fe2b44d0d9c1
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
1478 |
italicFont := savedFont asItalic onDevice:device |
307 | 1479 |
]. |
1480 |
f := italicFont |
|
1481 |
] ifFalse:[ |
|
1482 |
f := savedFont |
|
1483 |
] |
|
1484 |
]. |
|
899
fe2b44d0d9c1
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
1485 |
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
|
1486 |
wasItalic ~~ italic ifTrue:[ |
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1487 |
italic ifFalse:[ |
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1488 |
"/ 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
|
1489 |
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
|
1490 |
]. |
4a2048f291eb
care for some spacing, when going from italic to non-italic
Claus Gittinger <cg@exept.de>
parents:
963
diff
changeset
|
1491 |
]. |
307 | 1492 |
l := l + (f widthOf:string from:pos to:(pos + len - 1)). |
1493 |
pos := pos + len |
|
1494 |
]. |
|
1495 |
||
1496 |
^ l |
|
1497 |
||
404
14cf34141532
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
395
diff
changeset
|
1498 |
"Modified: 5.7.1996 / 17:54:58 / cg" |
307 | 1499 |
! ! |
1500 |
||
1501 |
!Text methodsFor:'replacing'! |
|
1502 |
||
1503 |
replaceFrom:start to:stop with:aCollection startingAt:startIndex |
|
343 | 1504 |
"replace a range of characters, from another string or text object. |
607 | 1505 |
The corresponding characters' emphasis information is also copied. |
1506 |
Return the receiver." |
|
343 | 1507 |
|
307 | 1508 |
|idx| |
1509 |
||
1402
2fe462e2fe8e
care for text with twobyte strings
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
1510 |
aCollection bitsPerCharacter > string bitsPerCharacter ifTrue:[ |
2fe462e2fe8e
care for text with twobyte strings
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
1511 |
string := aCollection string species fromString:string string. |
2fe462e2fe8e
care for text with twobyte strings
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
1512 |
]. |
2fe462e2fe8e
care for text with twobyte strings
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
1513 |
|
307 | 1514 |
aCollection isString ifTrue:[ |
1515 |
aCollection hasChangeOfEmphasis ifTrue:[ |
|
1516 |
string replaceFrom:start to:stop with:aCollection startingAt:startIndex. |
|
1517 |
idx := startIndex. |
|
1518 |
start to:stop do:[:col | |
|
1519 |
self emphasisAt:col put:(aCollection emphasisAt:idx). |
|
1520 |
idx := idx + 1. |
|
1521 |
]. |
|
1522 |
^ self. |
|
1523 |
] |
|
1524 |
]. |
|
1525 |
||
1526 |
string replaceFrom:start to:stop with:aCollection startingAt:startIndex. |
|
1527 |
self emphasizeFrom:start to:stop with:nil |
|
1528 |
||
1529 |
" |
|
1530 |
((Text string:'hello') allBold emphasisAt:2 put:#italic) |
|
1531 |
copyFrom:1 to:3 |
|
1532 |
" |
|
1533 |
||
607 | 1534 |
"Modified: / 28.1.1998 / 16:50:06 / cg" |
304 | 1535 |
! ! |
1536 |
||
454
ffc79ebcbb20
oops - copyFrom:to: clobbered the emphasis
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
1537 |
!Text class methodsFor:'documentation'! |
304 | 1538 |
|
1539 |
version |
|
2110 | 1540 |
^ '$Header: /cvs/stx/stx/libbasic2/Text.st,v 1.96 2009-02-11 15:25:11 cg Exp $' |
304 | 1541 |
! ! |
1160 | 1542 |
|
314 | 1543 |
Text initialize! |