unit bitmap_painters; {$M+} interface uses painters, buffers { TTextBufferItem }, textfitters { TTextLayoutRectangle }; type TDummyBitmapContinuousCharacterPainter = class private // TODO break position. fRectangle : TTextLayoutRectangle; fNextRectangles : ITextLayoutRectanglesIterator; fCurrentWidth : Cardinal; fCurrentHeight : Cardinal; fPositionX : Cardinal; fPositionY : Cardinal; fRowHeight : Cardinal; protected function GetCurrentWidth : Cardinal; procedure SetCurrentWidth(aValue : Cardinal); function GetCurrentHeight : Cardinal; procedure SetCurrentHeight(aValue : Cardinal); function GetRectangle : TTextLayoutRectangle; procedure SetRectangle(aValue : TTextLayoutRectangle); function GetNextRectangles : ITextLayoutRectanglesIterator; procedure SetNextRectangles(aValue : ITextLayoutRectanglesIterator); function GetPositionX : Cardinal; procedure SetPositionX(aValue : Cardinal); function GetPositionY : Cardinal; procedure SetPositionY(aValue : Cardinal); function GetRowHeight : Cardinal; procedure SetRowHeight(aValue : Cardinal); procedure GotoNextRectangle; published constructor Create(aDeviceName : string { the terminal to use; TODO: use UNIX terminal fd }); procedure EmitLineFeed(); procedure ProcessItem(item : TTextBufferItem); private procedure RenderItem(item : TTextBufferItem); virtual; // no checks. published property Width : Cardinal read GetCurrentWidth write SetCurrentWidth; property Height : Cardinal read GetCurrentHeight write SetCurrentHeight; property PositionX : Cardinal read GetPositionX write SetPositionX; property PositionY : Cardinal read GetPositionY write SetPositionY; property Rectangle : TTextLayoutRectangle read GetRectangle write SetRectangle; property NextRectangles : ITextLayoutRectanglesIterator read GetNextRectangles write SetNextRectangles; end; TBitmapContinuousCharacterPainter = class(TDummyBitmapContinuousCharacterPainter) private procedure RenderItem(item : TTextBufferItem); override; // no checks. end; implementation { TDummyBitmapContinuousCharacterPainter. } constructor TDummyBitmapContinuousCharacterPainter.Create(aDeviceName : string { the terminal to use; TODO: use UNIX terminal fd }); begin {fRectangle : TTextLayoutRectangle; fNextRectangles : ITextLayoutRectanglesIterator;} fCurrentWidth := 0; fCurrentHeight := 0; end; function TDummyBitmapContinuousCharacterPainter.GetCurrentWidth : Cardinal; begin Result := fCurrentWidth; end; procedure TDummyBitmapContinuousCharacterPainter.SetCurrentWidth(aValue : Cardinal); begin fCurrentWidth := aValue; end; function TDummyBitmapContinuousCharacterPainter.GetCurrentHeight : Cardinal; begin Result := fCurrentHeight; end; procedure TDummyBitmapContinuousCharacterPainter.SetCurrentHeight(aValue : Cardinal); begin fCurrentHeight := aValue; end; function TDummyBitmapContinuousCharacterPainter.GetRectangle : TTextLayoutRectangle; begin Result := fRectangle; end; procedure TDummyBitmapContinuousCharacterPainter.SetRectangle(aValue : TTextLayoutRectangle); begin fRectangle := aValue; end; function TDummyBitmapContinuousCharacterPainter.GetNextRectangles : ITextLayoutRectanglesIterator; begin Result := fNextRectangles; end; procedure TDummyBitmapContinuousCharacterPainter.SetNextRectangles(aValue : ITextLayoutRectanglesIterator); begin fNextRectangles := aValue; end; function TDummyBitmapContinuousCharacterPainter.GetRowHeight : Cardinal; begin Result := fRowHeight; end; procedure TDummyBitmapContinuousCharacterPainter.SetRowHeight(aValue : Cardinal); begin fRowHeight := aValue; end; function TDummyBitmapContinuousCharacterPainter.GetPositionX : Cardinal; begin Result := fPositionX; end; procedure TDummyBitmapContinuousCharacterPainter.SetPositionX(aValue : Cardinal); begin fPositionX := aValue; end; function TDummyBitmapContinuousCharacterPainter.GetPositionY : Cardinal; begin Result := fPositionY; end; procedure TDummyBitmapContinuousCharacterPainter.SetPositionY(aValue : Cardinal); begin fPositionY := aValue; end; procedure TDummyBitmapContinuousCharacterPainter.GotoNextRectangle; begin fRectangle := fNextRectangles.Next; end; procedure TDummyBitmapContinuousCharacterPainter.EmitLineFeed(); begin // TODO take orientation into account (fRectangle.#"DirectionX", #"DirectionY"). fPositionX := 0; if (fPositionY + fRowHeight) <= fRectangle.Height then begin fPositionY := fPositionY + fRowHeight; // TODO take orientation into account. end else begin { doesn't fit, Y-direction-wise. } { try to go to next rectangle } end; end; procedure TDummyBitmapContinuousCharacterPainter.ProcessItem(item : TTextBufferItem); var itemWidth : Cardinal; itemHeight : Cardinal; begin // TODO take orientation into account (fRectangle.#"DirectionX", #"DirectionY"). { TODO proper UTF-8 handling, proper dead-char handling... } itemWidth := 1; itemHeight := 1; if (fPositionX + itemWidth) <= fRectangle.Width then begin { fits, X-direction-wise. } end else begin { doesn't fit, X-direction-wise. } if fPositionX > 0 then Self.EmitLineFeed(); end; if (fPositionY + fRowHeight) <= fRectangle.Height then begin end else begin { doesn't fit, Y-direction-wise. } { try to go to next rectangle } end; {fRectangle.Width fRectangle.Height} // TODO. Inc(fCurrentWidth); Inc(fPositionX); //fCurrentPositionY fCurrentHeight end; procedure TDummyBitmapContinuousCharacterPainter.RenderItem(item : TTextBufferItem); // no checks. begin end; { TBitmapContinuousCharacterPainter. } procedure TBitmapContinuousCharacterPainter.RenderItem(item : TTextBufferItem); // no checks. begin end; end.