Page 1 of 1

Print Preview and the preview of MM_LOMETRIC

PostPosted: May 17th, 2010, 7:43 pm
by Gabberkooij
Hi,

I'm using TPrintPreview in PictoSelector and so far it has been working very well. (http://www.PictoSelector.eu) Thanks for this nice component!

But now I want to put symbols on exact locations on my print. (position and size) and somehow I get different results from 'the real' print.

in the case below i try to paint a rectangle from (12,4) - (224.5, 192) (and soem other things. When priting to the printer it works ok (oPreview = nil) but printing to the preview is giving different results (on my work computer it is different from my home computer = different printers? )

What i'm i missing here?

Code: Select all
begin
  bDefaultLayoutTemplate := (LayoutTemplate = CLayoutTemplateDefault) or (LayoutTemplate = '');

  orgOrientation := Printer.Orientation;
  try
    if not bDefaultLayoutTemplate then begin
      Printer.Orientation := poLandscape;
    end;

    if Assigned(oPreview) then begin
      oPreview.Units := mmLoMetric;
      oPreview.BeginDoc;
      oCanvas := oPreview.Canvas;
      iPrinterPageHeight := oPreview.PaperHeight;
      iPrinterPageWidth := oPreview.PaperWidth;
      if not bDefaultLayoutTemplate then begin
        oPreview.Orientation := poLandscape;
      end;
    end else begin
      Printer.BeginDoc;
      oCanvas := Printer.Canvas;
      iPrinterPageHeight := Printer.PageHeight;
      iPrinterPageWidth := Printer.PageWidth;
    end;

    iOldMapMode := GetMapMode(oCanvas.Handle);
    if not bDefaultLayoutTemplate then begin
      SetMapMode( oCanvas.Handle, MM_LOMETRIC );
      xPerMM := 10;
      yPerMM := -10;
    end;


    bmp := TBitmap.Create;
    png := TPNGObject.Create;
    oCurrentRow := TPictoSheetItems.Create;
    try


      if bDefaultLayoutTemplate then begin
        iColumnCount := ColumnCount;
        iRowCount := RowCount;
      end else begin

        oCanvas.MoveTo( round(12    * xPerMM), round(4     * yPerMM) );
        oCanvas.LineTo( round(12    * xPerMM), round((188 + 4) * yPerMM) );
        oCanvas.LineTo( round((212.5 + 12) * xPerMM), round((188 + 4) * yPerMM) );
        oCanvas.LineTo( round((212.5 + 12) * xPerMM), round(4     * yPerMM) );
        oCanvas.LineTo( round(12    * xPerMM), round(4     * yPerMM) );

        SetLength(aDestinationRects, CLayoutTemplate_GoTalk9plus_Rows * CLayoutTemplate_GoTalk9plus_Columns);
        for iCurRow := 0 to CLayoutTemplate_GoTalk9plus_Rows - 1 do begin
          for iCurCol := 0 to CLayoutTemplate_GoTalk9plus_Columns - 1 do begin

            if iCurRow = 0 then begin
              rectDest.Top := round((4 + 2) * yPerMM);
              rectDest.Bottom := round(rectDest.Top + 29 * yPerMM);
            end else begin
              rectDest.Top := round((4 + 35) * yPerMM + (iCurRow -1) * 50 * yPerMM);
              rectDest.Bottom := round(rectDest.Top + 45 * yPerMM);
            end;

            rectDest.Left := round((12 + 10) * xPerMM + iCurCol * 64 * xPerMM);
            rectDest.Right := round(rectDest.Left + 58 * xPerMM);

            aDestinationRects[iCurRow * CLayoutTemplate_GoTalk9plus_Columns + iCurCol] := rectDest;
          end;
        end;

        strCopyRight := Title + ' - ' +_('Printed by Picto Selector - www.PECSforAll.com');
        oCanvas.Font.Name := 'Arial';
        oCanvas.Font.Size := 4;
        oCanvas.Font.Style := [];
        oCanvas.Font.Color := clBlack;

        sizeTextTitle := oCanvas.TextExtent(strCopyRight);
        oCanvas.TextOut(round((212.5 / 2 + 12) * xPerMM) - sizeTextTitle.cx div 2,
                        round((188 + 4) * yPerMM + Round(sizeTextTitle.cy * 1.1)),
                        strCopyRight );

        iColumnCount := CLayoutTemplate_GoTalk9plus_Columns;
        iRowCount := CLayoutTemplate_GoTalk9plus_Rows;
      end;
<skipped rest of method>


Re: Print Preview and the preview of MM_LOMETRIC

PostPosted: May 18th, 2010, 10:56 am
by Kambiz
Here are some hints that may help you to resolve the issue:

  • Use mmHiMetric instead of mmLoMetric for the Units property
  • Never call SetMapMode on preview's canvas
  • Set preview's orientation before calling BeginDoc
  • Use preview unit conversion methods for converting values from one unit to another one
  • Use PrintPreview control for both print and preview (Set DirectPrint property to True if you just want to print)

Re: Print Preview and the preview of MM_LOMETRIC

PostPosted: May 18th, 2010, 2:36 pm
by Gabberkooij
I've moved the

oPreview.Orientation := poLandscape;
oPreview.Units := mmLoMetric;

before the BeginDoc method

And i've removed the SetMapMode for the preview.

It seems to be ok now. Thanks for your input!!

Martijn