|
|
Class: Text
Object
|
+--Collection
|
+--SequenceableCollection
|
+--ArrayedCollection
|
+--UninterpretedBytes
|
+--ByteArray
|
+--CharacterArray
|
+--Text
- Package:
- stx:libbasic2
- Category:
- Collections-Text
- Version:
- rev:
1.106
date: 2009/10/29 17:23:09
- user: cg
- file: Text.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Claus Gittinger
Texts add emphasis information to a string.
Texts and strings should behave interchanchably to the outside
world, except that texts keep per-character emphasis information.
(strings return nil, when asked for an elements emphasis).
Use #string, to get a texts underlying string without any emphasis
information.
Currently, the following attributes are supported:
#bold
#italic
#underline
#underwave
#strikeout
(#color -> aColor)
(#backgroundColor -> aColor)
(#underlineColor -> aColor)
(#strikeoutColor -> aColor)
Attributes may be combined (pass an array of above) as emphasis.
See examples.
This class is not yet fully implemented - being constructed.
CharacterArray
String
RunArray
emphasis constants
-
backgroundColorEmphasis
-
-
foregroundColorEmphasis
-
emphasis helper
-
addEmphasis: e1 to: e2
-
merge two emphasis's into one
-
emphasis: e1 includes: e2
-
return true, if e1 includes e2.
e2 should be a single emphasis.
-
extractEmphasis: key from: e
-
if key is included in the emphasis, e then return the key.
Otherwise, if a n association with that key is included, return the value.
Otherwise, return nil.
-
removeEmphasis: emToRemove from: emp
-
remove an emphasis; if it was not in e1, do nothing
initialization
-
initialize
-
initialize the class
instance creation
-
fromString: aString
-
create a Text instance, for the characters in aString,
without emphasis.
-
new
-
create a new empty Text instance.
Redefined for string-protocol compatibility
-
new: size
-
create a new empty Text instance.
Redefined for string-protocol compatibility
-
string: aString
-
create a Text instance, for the characters in aString,
without emphasis.
-
string: aString color: aColor
-
create a Text instance, for the characters in aString,
which are colored as aColor (only the foregroundColor is affected).
This is a shortCut for creating an emphasis of (#color->aColor)
-
string: aString emphasis: attribute
-
create a Text instance, for the characters in aString,
which are emphasized as described by attribute.
-
string: aString emphasisCollection: attributeCollection
-
create a Text instance, for the characters in aString,
which are individually emphasized as described by attributeCollection.
-
string: aString foregroundColor: fgColor backgroundColor: bgColor
-
create a Text instance, for the characters in aString,
which are colored in fgColor on bgColor.
This is a shortCut for creating an emphasis of
#( #color->fgColor) (#backgroundColor->bgColor)
-
string: aString runs: aRun
-
create a Text instance, for the characters in aString,
which are individually emphasized as described by attributeCollection.
-
uninitializedNew: size
-
for compatibility only
-
writeStream
-
answer the stream, that is best used with this class
accessing
-
at: characterIndex
-
return the plain character at characterIndex
-
at: characterIndex put: aCharacter
-
change the character at characterIndex to be aCharacter.
The emphasis (if any) of that character remains unchanged.
comparing
-
= aStringOrText
-
compare the receiver and the argument, ignoring emphasis
-
hash
-
return a suitable hashcode (req'd since = is redefined)
converting
-
asHtmlDocumentForRequest: request
-
-
asText
-
return a Text-object (string with emphasis) from myself.
I am already a text object.
-
writeStream
-
return a stream for writing onto the receiver.
Redefined to return a TextStream which deals with emphasis change messages
copying
-
, aStringOrText
-
concatenate the receivers characters with the arguments characters,
and return string or text object containing those characters.
If either the receiver or the argument contains emphasis information,
a text object will be returned. Otherwise, a string (i.e. without emphasis)
is returned.
-
concatenateFromString: aString
-
return the concatenation of aString and myself.
This may be a Text (if I have emphasis) or a string (if not).
-
copyFrom: start to: stop
-
return the subcollection starting at index start, anInteger and ending
at stop, anInteger.
-
postCopy
-
displaying
-
displayOn: aGC x: x0 y: y opaque: opaqueWanted
-
display the receiver on a GC
emphasis
-
actionForAll: aBlock
-
change the actionBlock of all characters.
Some widgets use this like a href if clicked onto the text.
-
allBold
-
make all characters bold
-
allBoldOverline
-
make all characters bold and overline
-
allItalic
-
make all characters italic
-
allOverline
-
make all characters overline
-
allStrikedOut
-
strikeOut all characters
-
allUnderlined
-
underline all characters
-
allUnderwaved
-
underwave all characters
-
backgroundColorizeAllWith: aColor
-
change the bc-color of all characters
-
colorizeAllWith: aColor
-
change the color of all characters
-
colorizeAllWith: fgColor on: bgColor
-
change the color and bg-color of all characters
-
emphasis
-
return the emphasis
-
emphasis: emArray
-
-
emphasisAllAdd: newEmphasis
-
add to the emphasis to all characters. return the receiver
-
emphasisAllRemove: anEmphasis
-
remove the emphasis from all characters. return the receiver
-
emphasisAt: characterIndex
-
return the emphasis at some index
-
emphasisAt: characterIndex add: newEmphasis
-
add to the emphasis at some index. return the receiver
-
emphasisAt: characterIndex put: emphasis
-
change the emphasis at some index. return the receiver
-
emphasisAt: characterIndex remove: emphasisToRemove
-
remove from the emphasis at some index. return the receiver
-
emphasisCollection
-
return the emphasis
-
emphasisFrom: start to: stop add: newEmphasis
-
add to the emphasis within some range. return the receiver
-
emphasisFrom: start to: stop remove: anEmphasis
-
remove from the emphasis within some range. return the receiver
-
emphasiseFrom: start to: stop with: newEmphasis
-
set to the emphasis within some range. return the receiver
-
emphasizeAllWith: emphasis
-
change the emphasis of all characters
-
emphasizeFrom: start count: count with: emphasis
-
change the emphasis of a range of characters, given startIndex and count.
-
emphasizeFrom: start to: stop with: emphasis
-
change the emphasis of a range of characters
-
emphasizeFrom: start with: emphasis
-
change the emphasis of some characters upTo the end
-
strikeoutAll
-
strikeout all characters
-
withoutAnyColorEmphasis
-
-
withoutBackgroundColorEmphasis
-
-
withoutEmphasis: emphasisToRemove
-
-
withoutForegroundColorEmphasis
-
inspecting
-
inspectorExtraAttributes
-
extra (pseudo instvar) entries to be shown in an inspector.
printing & storing
-
displayOn: aGCOrStream
-
append a printed representation from which the receiver can be reconstructed
to aStream.
-
displayString
-
-
printOn: aStream
-
print the receivers characters (including emphasis) on
aStream.
Notice, that some streams simply ignore the emphasis
-
storeOn: aStream
-
append a printed representation from which the receiver can be reconstructed
to aStream.
private-accessing
-
emphasisCollection: emphasisCollection
-
set the string and emphasis collection.
The emphasis collection contains per-character information.
-
setString: aString setRuns: anArray
-
-
string: aString emphasis: emphasis
-
set the string and emphasis. The emphasis is applied to all characters.
-
string: aString emphasisCollection: emphasisCollection
-
set the string and emphasis collection.
The emphasis collection contains per-character information.
queries
-
emphasisAtPoint: aPoint on: aGC
-
return the emphasis at a given point, or nil if there is none
-
encoding
-
-
hasChangeOfEmphasis
-
return true, if the receiver contains non-empty emphasis information
-
heightOn: aGC
-
return the number of device units, required on aGC's device
-
indexOf: aCharacter startingAt: index
-
search aCharacters index in the underlying string
-
isText
-
return true if this is a Text object - always true here
-
occurrencesOf: aCharacter
-
count & return the number of occurrences of aCharacter in the
underlying string
-
size
-
return the number of characters in the underlying string
-
string
-
return the receiver without any emphasis information
i.e. the underlying string.
-
widthFrom: startIndex to: endIndex on: aGC
-
return the number of device units, required on aGC's device
-
widthOn: aGC
-
return the number of device units, required on aGC's device
replacing
-
replaceFrom: start to: stop with: aCollection startingAt: startIndex
-
replace a range of characters, from another string or text object.
The corresponding characters' emphasis information is also copied.
Return the receiver.
plain string (for comparison):
emphasized strings as dialog titles:
Dialog
warn:((Text string:'hello') allBold)
|
Dialog
warn:(Text string:'hello' emphasis:#italic)
|
Dialog
warn:(Text string:'hello' emphasis:#(underline))
|
Dialog
warn:(Text string:'hello' emphasis:#(underwave))
|
Dialog
warn:(Text string:'hello' emphasis:#(bold underline))
|
Dialog
warn:(Text string:'hello'
emphasis:(Array with:#bold
with:#strikeout
with:(#color->Color red)))
|
Dialog
warn:(Text string:'hello'
emphasis:(Array with:(#color->Color black)
with:#underwave
with:(#underlineColor->Color red)))
|
Dialog
warn:(Text string:'hello'
emphasis:(Array with:#bold
with:#strikeout
with:(#color->Color red)
with:(#backgroundColor->Color yellow)))
|
Dialog
warn:(Text string:'hello' color:(Color red))
|
in an editTextView:
|t v|
t := 'The quick brown fox jumps over the lazy dog' asText.
t emphasizeFrom:(t findString:'quick') count:5 with:#bold.
t emphasizeFrom:(t findString:'brown') count:9
with:(Array with:#color->(Color name:'brown')
with:#bold).
t emphasizeFrom:(t findString:'lazy') count:4
with:(Array with:#color->(Color red)
with:#italic).
t emphasizeFrom:(t findString:'dog') count:3 with:#underline.
v := HVScrollableView for:EditTextView.
v contents:t.
v width:450.
v open.
|
|