'From Cuis 2.6 of 10 August 2010 [latest update: #540] on 26 August 2010 at 10:30:39 pm'!
!classDefinition: #DisplayScanner category: #'Graphics-Text'!
CharacterScanner subclass: #DisplayScanner
	instanceVariableNames: 'bitBlt lineY runX foregroundColor lineHeight paragraphColor morphicOffset ignoreColorChanges lastBulletNumber '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Graphics-Text'!

!DisplayScanner methodsFor: 'scanning' stamp: 'jmv 8/26/2010 22:29'!
displayBulletIfAppropriateFor: textLine offset: offset
	| paragraphEnd count pattern |
	(textLine isFirstLine and: [ actualTextStyle isListStyle ]) ifTrue: [
		pattern _ actualTextStyle listBulletPattern.
		"Count how many paragraphs before this one already used the pattern"
		count _ 0.
		paragraphEnd _ textLine first-1.
		[
		paragraphEnd > 0 and: [ (text textStyleAt: paragraphEnd) listBulletPattern = pattern ]] whileTrue: [
			count _ count + 1.
			paragraphEnd _ text string endOfParagraphBefore: paragraphEnd ].
		"Our number in the list, is one more than the count of previous contiguous paragraphs with this pattern"
		self
			displayBulletOffset: offset
			number: count + 1]! !

!DisplayScanner methodsFor: 'scanning' stamp: 'jmv 8/26/2010 22:11'!
displayBulletOffset: offset number: bulletNumber
	| pattern i bullet bulletPos |
	pattern _ actualTextStyle listBulletPattern.
	(i _ pattern indexOf: $%) > 0
		ifTrue: [ bullet _ bulletNumber asString]
		ifFalse: [
			(i _ pattern indexOf: $z) > 0
				ifTrue: [ bullet _ (Character value: 96 + bulletNumber) asString ]
				ifFalse: [
					(i _ pattern indexOf: $Z) > 0
						ifTrue: [ bullet _ (Character value: 64 + bulletNumber) asString ]]].
	bullet _ i > 0
		ifTrue: [ (pattern copyFrom: 1 to: i-1), bullet, (pattern copyFrom: i+1 to: pattern size) ]
		ifFalse: [ pattern ].
	bulletPos _ actualTextStyle firstIndent + offset x@destY.
	font displayString: bullet on: bitBlt from: 1 to: bullet size at: bulletPos kern: kern.
		! !


!String methodsFor: 'paragraph support' stamp: 'jmv 8/26/2010 19:12'!
endOfParagraphBefore: aNumber
	"Return the index of the last Character cr before position aNumber, or zero if this is the first paragraph.
	'ddd' endOfParagraphBefore: 3
	'dd
	d' endOfParagraphBefore: 4
	"
	^ self lastIndexOf: Character cr startingAt: aNumber - 1 ifAbsent: [ 0 ]! !

DisplayScanner removeSelector: #displayBulletOffset:!
DisplayScanner removeSelector: #nextBulletLowerChar!
DisplayScanner removeSelector: #nextBulletNumber!
DisplayScanner removeSelector: #nextBulletUpperChar!
!classDefinition: #DisplayScanner category: #'Graphics-Text'!
CharacterScanner subclass: #DisplayScanner
	instanceVariableNames: 'bitBlt lineY runX foregroundColor lineHeight paragraphColor morphicOffset ignoreColorChanges'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Graphics-Text'!
