'From Cuis 1.0 of 21 August 2009 [latest update: #268] on 26 August 2009 at 11:35:16 am'!
!classDefinition: #TextComposer category: #'Morphic-Text Support'!
Object subclass: #TextComposer
	instanceVariableNames: 'lines maxRightX currentY scanner possibleSlide nowSliding prevIndex prevLines currCharIndex startCharIndex stopCharIndex deltaCharIndex theText theContainer isFirstLine defaultLineHeight actualHeight anythingComposed '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Text Support'!

!TextComposer methodsFor: 'as yet unclassified' stamp: 'jmv 8/26/2009 11:32'!
composeAllRectangles: rectangles

	| charIndexBeforeLine numberOfLinesBefore reasonForStopping |

	actualHeight _ defaultLineHeight.
	charIndexBeforeLine _ currCharIndex.
	numberOfLinesBefore _ lines size.
	reasonForStopping _ self composeEachRectangleIn: rectangles.

	currentY _ currentY + actualHeight.
	currentY > theContainer bottom ifTrue: [
		"Oops -- the line is really too high to fit -- back out"
		currCharIndex _ charIndexBeforeLine.
		lines size - numberOfLinesBefore timesRepeat: [lines removeLast].
		^self
	].
	
	"It's OK -- the line still fits."
	maxRightX _ maxRightX max: scanner rightX.
	1 to: rectangles size - 1 do: [ :i |
		"Adjust heights across rectangles if necessary"
		(lines at: lines size - rectangles size + i)
			lineHeight: lines last lineHeight
			baseline: lines last baseline
	].

	anythingComposed _ true.
	isFirstLine _ currCharIndex = 1 or: [
		 (theText at: currCharIndex-1) = Character cr].

	reasonForStopping == #columnBreak ifTrue: [^nil].
	currCharIndex > theText size ifTrue: [
		^nil		"we are finished composing"
	]! !

!TextComposer methodsFor: 'as yet unclassified' stamp: 'jmv 8/26/2009 11:32'!
composeLinesFrom: argStart to: argStop delta: argDelta into: argLinesCollection priorLines: argPriorLines atY: argStartY text: argText container: argContainer

	lines _ argLinesCollection.
	theText _ argText.
	theContainer _ argContainer.
	deltaCharIndex _ argDelta.
	currCharIndex _ startCharIndex _ argStart.
	stopCharIndex _ argStop.
	prevLines _ argPriorLines.
	currentY _ argStartY.
	defaultLineHeight _ theText initialStyle initialLineGrid.
	maxRightX _ theContainer left.
	possibleSlide _ stopCharIndex < theText size and: [theContainer isMemberOf: Rectangle].
	nowSliding _ false.
	prevIndex _ 1.
	scanner _ CompositionScanner new text: theText.
	isFirstLine _ currCharIndex = 1 or: [
		 (theText at: currCharIndex-1) = Character cr].
	anythingComposed _ false.
	self composeAllLines.
	anythingComposed 
		ifTrue: [ self fixupLastLineIfCR ]
		ifFalse: [	"No space in container or empty text"
			self 
				addNullLineWithIndex: startCharIndex
				andRectangle: (theContainer topLeft extent: 0@defaultLineHeight) ].
	^{lines asArray. maxRightX}

! !

!classDefinition: #TextComposer category: #'Morphic-Text Support'!
Object subclass: #TextComposer
	instanceVariableNames: 'lines maxRightX currentY scanner possibleSlide nowSliding prevIndex prevLines currCharIndex startCharIndex stopCharIndex deltaCharIndex theText theContainer isFirstLine defaultLineHeight actualHeight anythingComposed'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Text Support'!
