Ver Mensaje Individual
  #2  
Antiguo 05-06-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 26
seoane Va por buen camino
Un ejemplo secillo:

Código Delphi [-]
uses Printers;

begin
  Printer.BeginDoc;
  try
    Printer.Canvas.TextOut(100,100,'Hola mundo');
    Printer.EndDoc;
  except
    Printer.Abort;
  end;
end;

Algo un poco mas complicado, usando medidas reales:
Código Delphi [-]
uses Printers;

function mmToPixelsX(X: Real): Integer;
var
  PixelsPerInchX: Integer;
  OffsetX: Integer;
begin
  PixelsPerInchX := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
  OffsetX := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
  Result:= Round((X / 25.4) * PixelsPerInchX) - OffsetX;
end;

function mmToPixelsY(Y: Real): Integer;
var
  PixelsPerInchY: Integer;
  OffsetY: Integer;
begin
  PixelsPerInchY := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
  OffsetY := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);
  Result:= Round((Y / 25.4) * PixelsPerInchY) - OffsetY;
end;

var
  x1, y1, x2, y2: Integer;
begin
  Printer.BeginDoc;
  try
    x1:= mmToPixelsX(30);
    x2:= mmToPixelsX(100);
    y1:= mmToPixelsY(30);
    y2:= mmToPixelsY(100);
    // Dibujamos un circulo de 7 cm
    Printer.Canvas.Ellipse(x1,y1,x2,y2);
    Printer.EndDoc;
  except
    Printer.Abort;
  end;
end;

Y a partir de esto solo hay que utilizar cualquier otro metodo de dibujo sobre el canvas que te apetezca, el unico que no funciona es FloodFill pero el resto creo que funciona bien.

Por ultimo aqui te dejo otro, este dibuja una bonita espiral:

Código Delphi [-]
procedure Espiral(Canvas: TCanvas; X,Y,Ancho: Integer; V: Real);
var
  i: integer;
begin
  Ancho:= Ancho * 16;
  V:= (2*V*pi)/Ancho;
  Canvas.MoveTo(x,y);
  for i:= 1 to Ancho do
  begin
    Canvas.LineTo(x + (Round(i*cos(V*i))) shr 4,y + (Round(i*sin(V*i)) shr 4));
  end;
end;

var
  x, y: Integer;
begin
  Printer.BeginDoc;
  try
    x:= Printer.PageWidth div 2;
    y:= Printer.PageHeight div 2;
    Espiral(Printer.Canvas,x,y,x,100);
    Printer.EndDoc;
  except
    Printer.Abort;
  end;
end;

Última edición por seoane fecha: 05-06-2006 a las 20:56:28.
Responder Con Cita