Text.st
changeset 3598 04be25181a2e
parent 3472 a61d50c15405
child 3644 baa4ec9a3b28
equal deleted inserted replaced
3597:6b1167c90973 3598:04be25181a2e
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1996 by Claus Gittinger
     4  COPYRIGHT (c) 1996 by Claus Gittinger
     3               All Rights Reserved
     5               All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
   213 
   215 
   214 new
   216 new
   215     "create a new empty Text instance.
   217     "create a new empty Text instance.
   216      Redefined for string-protocol compatibility"
   218      Redefined for string-protocol compatibility"
   217 
   219 
   218     ^ super new string:(String new) emphasis:nil
   220     ^ super new string:'' emphasis:nil
   219 
   221 
   220     "Text new"
   222     "Text new"
   221 
   223 
   222     "Modified: 12.5.1996 / 17:05:17 / cg"
   224     "Modified: 12.5.1996 / 17:05:17 / cg"
   223     "Modified: 31.12.1996 / 12:39:57 / stefan"
   225     "Modified: 31.12.1996 / 12:39:57 / stefan"
   723     "Created: 22.10.1996 / 21:01:16 / cg"
   725     "Created: 22.10.1996 / 21:01:16 / cg"
   724 !
   726 !
   725 
   727 
   726 postCopy
   728 postCopy
   727     string := string copy.
   729     string := string copy.
   728     runs := runs copy
   730     runs := runs copy.
       
   731 
       
   732     "
       
   733      |t|
       
   734 
       
   735      t := 'hello' emphasizeAllWith:#bold.
       
   736      t inspect. t copy inspect.
       
   737      t emphasisAllRemove:#bold.
       
   738     "
   729 ! !
   739 ! !
   730 
   740 
   731 !Text methodsFor:'displaying'!
   741 !Text methodsFor:'displaying'!
   732 
   742 
   733 displayOn:aGC x:x0 y:y opaque:opaqueWanted
   743 displayOn:aGC x:x0 y:y opaque:opaqueWanted
   751     device := aGC graphicsDevice.
   761     device := aGC graphicsDevice.
   752 
   762 
   753     pos := 1.
   763     pos := 1.
   754     x := x0.
   764     x := x0.
   755     bold := italic := underline := underwave := strikeout := reverse := false.
   765     bold := italic := underline := underwave := strikeout := reverse := false.
       
   766 
       
   767     runs size > string size ifTrue:[
       
   768         Transcript showCR:'inconsistent text: runs size > string size'.
       
   769         runs := runs copyTo:(string size)
       
   770     ].
   756 
   771 
   757     runs runsDo:[:len :emphasis |
   772     runs runsDo:[:len :emphasis |
   758         wasItalic := italic.
   773         wasItalic := italic.
   759         color := savedPaint.
   774         color := savedPaint.
   760         bold := italic := underline := underwave := strikeout := reverse := false.
   775         bold := italic := underline := underwave := strikeout := reverse := false.
   935     ].
   950     ].
   936 
   951 
   937     aGC basicFont:savedFont.
   952     aGC basicFont:savedFont.
   938     aGC paint:savedPaint on:savedBgPaint.
   953     aGC paint:savedPaint on:savedBgPaint.
   939 
   954 
       
   955     pos < string size ifTrue:[
       
   956        "/ draw rest
       
   957        aGC displayString:string from:pos to:string size x:x y:y.
       
   958     ].
       
   959 
   940     "Created: / 12.5.1996 / 11:14:30 / cg"
   960     "Created: / 12.5.1996 / 11:14:30 / cg"
   941     "Modified: / 7.7.1999 / 00:08:12 / cg"
   961     "Modified: / 7.7.1999 / 00:08:12 / cg"
   942 ! !
   962 ! !
   943 
   963 
   944 !Text methodsFor:'emphasis'!
   964 !Text methodsFor:'emphasis'!
  1197         prevE := runs at:characterIndex-1.
  1217         prevE := runs at:characterIndex-1.
  1198         e = prevE ifTrue:[
  1218         e = prevE ifTrue:[
  1199             e := prevE
  1219             e := prevE
  1200         ]
  1220         ]
  1201     ].
  1221     ].
  1202     runs at:characterIndex put:e
  1222     runs at:characterIndex put:e.
  1203 
  1223 
  1204     "
  1224     "
  1205      (Text string:'hello') allBold emphasisAt:2 add:#italic
  1225      (Text string:'hello') allBold emphasisAt:2 add:#italic
  1206     "
  1226     "
  1207 
  1227 
  1222         prevE := runs at:characterIndex-1.
  1242         prevE := runs at:characterIndex-1.
  1223         emphasis = prevE ifTrue:[
  1243         emphasis = prevE ifTrue:[
  1224             e := prevE
  1244             e := prevE
  1225         ]
  1245         ]
  1226     ].
  1246     ].
  1227     runs at:characterIndex put:e
  1247     runs at:characterIndex put:e.
  1228 
  1248 
  1229     "
  1249     "
  1230      (Text string:'hello') allBold emphasisAt:2 put:#italic
  1250      (Text string:'hello') allBold emphasisAt:2 put:#italic
  1231     "
  1251     "
  1232 
  1252 
  1238 
  1258 
  1239     |e|
  1259     |e|
  1240 
  1260 
  1241     e := runs at:characterIndex.
  1261     e := runs at:characterIndex.
  1242     e := self class removeEmphasis:emphasisToRemove from:e.
  1262     e := self class removeEmphasis:emphasisToRemove from:e.
  1243     runs at:characterIndex put:e
  1263     runs at:characterIndex put:e.
  1244 
  1264 
  1245     "
  1265     "
  1246      (Text string:'hello') 
  1266      (Text string:'hello') 
  1247         allBold emphasisAt:2 remove:#bold
  1267         allBold emphasisAt:2 remove:#bold
  1248 
  1268 
  1319 !
  1339 !
  1320 
  1340 
  1321 emphasizeAllWith:emphasis
  1341 emphasizeAllWith:emphasis
  1322     "change the emphasis of all characters"
  1342     "change the emphasis of all characters"
  1323 
  1343 
  1324     runs := RunArray new:(string size) withAll:emphasis
  1344     runs := RunArray new:(string size) withAll:emphasis.
  1325 
  1345 
  1326     "
  1346     "
  1327      (Text string:'hello') allBold emphasizeAllWith:#italic 
  1347      (Text string:'hello') allBold emphasizeAllWith:#italic 
  1328     "
  1348     "
  1329 
  1349 
  1521 
  1541 
  1522 emphasisCollection:emphasisCollection
  1542 emphasisCollection:emphasisCollection
  1523     "set the string and emphasis collection.
  1543     "set the string and emphasis collection.
  1524      The emphasis collection contains per-character information."
  1544      The emphasis collection contains per-character information."
  1525 
  1545 
  1526     runs := emphasisCollection
  1546     runs := emphasisCollection.
  1527 
  1547 
  1528     "Created: / 7.4.1998 / 08:52:03 / cg"
  1548     "Created: / 7.4.1998 / 08:52:03 / cg"
  1529 !
  1549 !
  1530 
  1550 
  1531 runs
  1551 runs
  1532     ^ runs
  1552     ^ runs
  1533 !
  1553 !
  1534 
  1554 
  1535 setRuns:anArrayOrRunArray
  1555 setRuns:anArrayOrRunArray
  1536     runs := anArrayOrRunArray
  1556     runs := anArrayOrRunArray.
  1537 !
  1557 !
  1538 
  1558 
  1539 setString:aString setRuns:anArrayOrRunArray
  1559 setString:aString setRuns:anArrayOrRunArray
  1540     string := aString.
  1560     string := aString.
  1541     runs := anArrayOrRunArray
  1561     runs := anArrayOrRunArray.
  1542 !
  1562 !
  1543 
  1563 
  1544 string:aString emphasis:emphasis
  1564 string:aString emphasis:emphasis
  1545     "set the string and emphasis. The emphasis is applied to all characters."
  1565     "set the string and emphasis. The emphasis is applied to all characters."
  1546 
  1566 
  1547     string := aString string.
  1567     string := aString string.
  1548     runs   := RunArray new:string size withAll:emphasis
  1568     runs   := RunArray new:string size withAll:emphasis.
  1549 
  1569 
  1550     "
  1570     "
  1551      |t|
  1571      |t|
  1552 
  1572 
  1553      t := Text new string:'hello' emphasis:#bold.
  1573      t := Text new string:'hello' emphasis:#bold.
  1851             string := maxCharacter stringSpecies fromString:string.
  1871             string := maxCharacter stringSpecies fromString:string.
  1852         ].
  1872         ].
  1853     ].
  1873     ].
  1854         
  1874         
  1855     string replaceFrom:start to:stop with:aCollection startingAt:startIndex.
  1875     string replaceFrom:start to:stop with:aCollection startingAt:startIndex.
  1856     self emphasizeFrom:start to:stop with:nil
  1876     self emphasizeFrom:start to:stop with:nil.
  1857 
  1877 
  1858     "
  1878     "
  1859      ((Text string:'hello') allBold emphasisAt:2 put:#italic)
  1879      ((Text string:'hello') allBold emphasisAt:2 put:#italic)
  1860         replaceFrom:1 to:3 with:'HEL' startingAt:1
  1880         replaceFrom:1 to:3 with:'HEL' startingAt:1
  1861 
  1881 
  1867 ! !
  1887 ! !
  1868 
  1888 
  1869 !Text class methodsFor:'documentation'!
  1889 !Text class methodsFor:'documentation'!
  1870 
  1890 
  1871 version
  1891 version
  1872     ^ '$Header: /cvs/stx/stx/libbasic2/Text.st,v 1.128 2015-01-29 17:54:22 cg Exp $'
  1892     ^ '$Header$'
  1873 !
  1893 !
  1874 
  1894 
  1875 version_CVS
  1895 version_CVS
  1876     ^ '$Header: /cvs/stx/stx/libbasic2/Text.st,v 1.128 2015-01-29 17:54:22 cg Exp $'
  1896     ^ '$Header$'
  1877 ! !
  1897 ! !
  1878 
  1898 
  1879 
  1899 
  1880 Text initialize!
  1900 Text initialize!