накидал тут примитивный код для вставки пробелов до нужной ширины... может пригодиться)
| Код | function DoJustifyString( const AText: string; ACanvas: TCanvas; AWidth: Integer ): string; const C_DELIM :set of char = [' ',',','.','-',';',':']; var lLastPos: Integer; i: Integer; lPrevInDelim: Boolean; begin Result := ''; if (AText = '') or not Assigned(ACanvas) or (AWidth = 0) then Exit; Result := AText; lLastPos := 0; lPrevInDelim := False; while ACanvas.TextWidth( Result+' ' ) < AWidth do begin if lLastPos > Length( Result ) then lLastPos := 0; lPrevInDelim := False; for i := lLastPos + 1 to length( Result ) do begin lLastPos := i + 1; if Result[i] in C_DELIM then begin lPrevInDelim := True; Continue; end else if lPrevInDelim then begin Result := Copy(Result, 1, i-1)+' ' + Copy(Result, i, MaxInt ); Break; end; end; end; end;
function DoJustifyText( const AText: string; ACanvas: TCanvas; AWidth: Integer ): string; var lSL: TStringList; i: Integer; begin Result := ''; if (AText = '') or not Assigned(ACanvas) or (AWidth = 0) then Exit; lSL := TStringList.Create; try lSL.Text := AText; for i := 0 to pred( lSL.Count ) do lSL[i] := DoJustifyString( lSL[i], ACanvas, AWidth ); Result := lSL.Text; finally lSL.Free; end; end;
|
|