Rave - Imprimindo texto na diagonal |
Top Previous Next |
|
Para imprimir texto na diagonal em uma página do Rave Reports podemos utilizar o método abaixo, que basicamente consiste em criar um bitmap em runtime, escrever o texto nele e imprimir em escala utilizando um ângulo.
// esta rotina escreve o texto sobre o bitmap no ângulo passado por parâmetro // o bitmap é passado pelo perâmetro Superficie (em forma de canvas) procedure EscreveDiagonal(const Texto: string; const X, Y: Integer; Angulo: Integer; Superficie: TCanvas; Fonte: string = 'Tahoma'; Tamanho: Integer = 10); var lf : TLogFont; tf : TFont; OldBkMode : integer; begin with Superficie do begin Font.Name := Fonte; Font.Size := Tamanho; tf := TFont.Create; tf.Assign(Font); GetObject(tf.Handle, sizeof(lf), @lf); lf.lfEscapement := Angulo * 10; lf.lfOrientation := Angulo * 10; tf.Handle := CreateFontIndirect(lf); Font.Assign(tf); tf.Free; OldBkMode := SetBkMode(Handle, TRANSPARENT); //<--- Se nao quer transparente tire esta linha TextOut(X, Y, Texto); SetBkMode(Handle, OldBkMode); //<--- Se nao quer transparente tire esta linha end; end;
// esta rotina imprime o bitmap em escala procedure PrintBitmapScaled(BaseReport: TBaseReport; X1, Y1, DesiredWidth, DesiredHeight: Double; Bitmap: TBitmap); var Calc: double; begin with BaseReport do begin if DesiredWidth <= 0.0 then begin Calc := DesiredHeight * (Bitmap.Width / XDPI) / (Bitmap.Height / YDPI); PrintBitmapRect(X1,Y1,X1 + Calc,Y1 + DesiredHeight, Bitmap); end else if DesiredHeight <= 0.0 then begin Calc := DesiredWidth * (Bitmap.Height / YDPI) / (Bitmap.Width / XDPI); PrintBitmapRect(X1,Y1,X1 + DesiredWidth,Y1 + Calc, Bitmap); end else PrintBitmapRect(X1,Y1,X1 + DesiredWidth,Y1 + DesiredHeight, Bitmap); end; end;
// no evento OnPrint do componente Rave programe assim: procedure TForm1.RvSystem1Print(Sender: TObject); var Bitmap: TBitmap; B : TBaseReport; I : Integer; begin B := Sender as TBaseReport; Bitmap := TBitmap.Create; Bitmap.Width := 500; Bitmap.Height := 400; Bitmap.Canvas.Font.Color := Cor; // Cor, aqui, é uma variável que recebeu o resultado do diálogo ColorDlg EscreveDiagonal('Texto em diagonal', 1, 300, 45, Bitmap.Canvas, 'Arial', 40);
PrintBitmapScaled(B, 1, 1, B.PageWidth, B.PageHeight, Bitmap);
for I := 1 to 50 do B.Println('Este é um texto de exemplo de impressão com bitmap no fundo, este texto foi feito para ficar sobre o bitmap de fundo');
Bitmap.Free; end;
-------- Autor: Júnior, juntando várias dicas Data : 19/02/2008 |