Recent

Author Topic: What to use instead of TMetaFile and TMetaFileCanvas  (Read 6730 times)

andrejsilva

  • New Member
  • *
  • Posts: 14
What to use instead of TMetaFile and TMetaFileCanvas
« on: July 06, 2009, 01:49:25 pm »
I'm trying to convert a component and I know I can use instead of TMetaFile and TMetaFileCanvas, follows the code.
Code: [Select]
procedure TiSoftPrinter.CriarFolha(Numero : integer; Folha : TMetaFile;ToPrint:boolean);
var
  EA            : integer;
  Pagina        : pPage;
  Escritura     : PEscritura;
  Texto         : TMetafile;
  Ancho, Alto   : Integer;

  MargenIzquierdo, MargenSuperior : integer;
  AltoDeLinha, AnchoDeColuna     : double;
  CantColunas   : integer;
begin

  if tpfComprimido in FastFont then
    CantColunas  := 140
  else
    CantColunas  := 83;

  if ToPrint then
  begin

      With TMetaFileCanvas.Create(Folha,0) do
        try
          Brush.Color      := clWhite;
          Folha.Width      := PrintingWidth div 4;
          Folha.Height     := PrintingHeight div 4;
          AnchoDeColuna   := (Folha.Width)/CantColunas ;
          AltoDeLinha      := (Folha.Height)/Lines;
          Font.Name        := 'Courrier';
          Font.Size        := 10;
          Font.Pitch       := fpFixed;
          Ancho            := TextWidth('X');
          Alto             := TextHeight('X');
          FillRect(Rect(0,0,(Folha.Width)-1,(Folha.Height-1)));
          Pagina           := StoragePages.Items[Numero-1];

          For EA := 0 to Pagina^.Escritura.Count-1 do
            begin
              Escritura := Pagina^.Escritura.Items[EA];
              if Escritura^.Y <= Lines then
                begin
                  Texto := TMetaFile.Create;
                  Texto.Width := Ancho*Length(Escritura^.Texto);
                  Texto.Height := Alto;

                  With TMetaFileCanvas.Create(Texto,0) do
                    try
                      Font.Name := 'Courrier';
                      Font.Size := 10;
                      Font.Pitch := fpFixed;

                      if tpfNegrito in Escritura^.PrinterFont then
                        Font.Style := Font.Style + [fsBold]
                      else
                        Font.Style := Font.Style - [fsBold];

                      if tpfItalico in Escritura^.PrinterFont then
                        Font.Style := Font.Style + [fsItalic]
                      else
                        Font.Style := Font.Style - [fsItalic];

                      if tpfSublinhado in Escritura^.PrinterFont then
                        Font.Style := Font.Style + [fsUnderline]
                      else
                        Font.Style := Font.Style - [fsUnderline];
                        TextOut(0,0,Escritura^.Texto);

                    finally
                      Free
                    end;
                    if (tpfComprimido in Escritura^.PrinterFont) and not (tpfComprimido in FastFont) then
                       StretchDraw(rect(Round(AnchoDeColuna*(Escritura^.X-1)),Round(AltoDeLinha*(Escritura^.Y-1)),Round(AnchoDeColuna*(Escritura^.X-1)+Length(Escritura^.Texto)*Folha.Width/140),Round(AltoDeLinha*(Escritura^.Y))),Texto)
                    else
                       StretchDraw(rect(Round(AnchoDeColuna*(Escritura^.X-1)),Round(AltoDeLinha*(Escritura^.Y-1)),Round(AnchoDeColuna*(Escritura^.X+Length(Escritura^.Texto)-1)),Round(AltoDeLinha*(Escritura^.Y))),Texto);

                  Texto.Free;
                end
            end;
        finally
          Free;
        end;
  end
  else
  begin
      With TMetaFileCanvas.Create(Folha,0) do
        try
          Brush.Color      := clWhite;
          //MargenIzquierdo  := Round(GetDeviceCaps(Printer.Handle,PHYSICALOFFSETX) / GetDeviceCaps(Printer.Handle,LOGPIXELSX) * 80);
          MargenIzquierdo  := Round(Printer.PaperSize.PaperRect.WorkRect.Left / Printer.XDPI * 80);
          MargenSuperior   := Round(Printer.PaperSize.PaperRect.WorkRect.Top / Printer.YDPI * 80);
          Folha.Width      := Round(Printer.PaperSize.PaperRect.PhysicalRect.Right / Printer.XDPI * 80);
          Folha.Height     := Round(Printer.PaperSize.PaperRect.PhysicalRect.Bottom  / Printer.YDPI * 80);
          AnchoDeColuna   := (Folha.Width-(2*MargenIzquierdo)) / CantColunas;
          AltoDeLinha      := (Folha.Height-(2*MargenSuperior))/Lines;
          Font.Name        := 'Courrier';
          Font.Size        := 10;
          Font.Pitch       := fpFixed;
          Ancho            := TextWidth('X');
          Alto             := TextHeight('X');
          FillRect(Rect(0,0,(Folha.Width)-1,(Folha.Height)-1));

          Pen.Color        := clSilver;
          Pen.Style        := psDot;

          if (MargenIzquierdo > 2) and (MargenSuperior > 2) then
            Rectangle(MargenIzquierdo-2,MargenSuperior-2,Round(MargenIzquierdo+CantColunas*AnchoDeColuna)+2,Round(MargenSuperior+Lines*AltoDeLinha)+2)
          else
          begin
            Rectangle(MargenIzquierdo,MargenSuperior,Round(MargenIzquierdo+CantColunas*AnchoDeColuna),Round(MargenSuperior+Lines*AltoDeLinha));
          end;
          Pen.Style := psSolid;
          Pen.Color := clBlack;
          Pagina := StoragePages.Items[Numero-1];
          For EA := 0 to Pagina^.Escritura.Count-1 do
            begin
              Escritura := Pagina^.Escritura.Items[EA];
              if Escritura^.Y <= Lines then
                begin
                  Texto := TMetaFile.Create;
                  Texto.Width := Ancho*Length(Escritura^.Texto);
                  Texto.Height := Alto;
                  With TMetaFileCanvas.Create(Texto,0) do
                    try
                      Font.Name := 'Courrier';
                      Font.Size := 10;
                      Font.Pitch := fpFixed;
                      if tpfNegrito in Escritura^.PrinterFont then
                        Font.Style := Font.Style + [fsBold]
                      else
                        Font.Style := Font.Style - [fsBold];
                      if tpfItalico in Escritura^.PrinterFont then
                        Font.Style := Font.Style + [fsItalic]
                      else
                        Font.Style := Font.Style - [fsItalic];
                      if tpfSublinhado in Escritura^.PrinterFont then
                        Font.Style := Font.Style + [fsUnderline]
                      else
                        Font.Style := Font.Style - [fsUnderline];
                        TextOut(0,0,Escritura^.Texto);
                    finally
                      Free
                    end;
                  if (tpfComprimido in Escritura^.PrinterFont) and not (tpfComprimido in FastFont) then
                  begin
                    StretchDraw(rect(Round(MargenIzquierdo+AnchoDeColuna*(Escritura^.X)),
                                Round(MargenSuperior+AltoDeLinha*(Escritura^.Y-1)),
                                Round(MargenIzquierdo+AnchoDeColuna*(Escritura^.X)+Length(Escritura^.Texto)*Folha.Width/140),
                                Round(MargenSuperior+AltoDeLinha*(Escritura^.Y))),
                                Texto)
                  end
                  else
                  begin
                    StretchDraw(rect(Round(MargenIzquierdo+AnchoDeColuna*(Escritura^.X)),
                                Round(MargenSuperior+AltoDeLinha*(Escritura^.Y-1)),
                                Round(MargenIzquierdo+AnchoDeColuna*(Escritura^.X+Length(Escritura^.Texto))),
                                Round(MargenSuperior+AltoDeLinha*(Escritura^.Y))),
                                Texto);
                  end;
                  Texto.Free;
                end
            end;
         finally
          Free;
        end;
  end;
--
Edit: I put the source code in a code tag. (Vincent)      
« Last Edit: July 06, 2009, 07:54:48 pm by Vincent Snijders »

 

TinyPortal © 2005-2018