View Issue Details

IDProjectCategoryView StatusLast Update
0034932LazarusWidgetsetpublic2019-03-20 20:34
ReporterTimlAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformi586OSMagiea OS Version6
Product Version2.0RC3Product Build 
Target Version2.0.2Fixed in Version2.0.2 
Summary0034932: Printing not correct with gtk
DescriptionWhen printing in landscape, the first page prints correctly. Subsequent pages are rotated to portrait layout but the content is still in landscape.
Steps To ReproduceRun attached project under Lazarus 1.8.4 and printing is correct. Run under 2.0rc3 or trunk and printing is wrong.
Additional InformationPrinting works OK on the same maching running the test project as win32 with wine.
TagsNo tags attached.
Fixed in Revision60732
LazTarget2.0.2
WidgetsetGTK 2
Attached Files
  • printtest.tar.lzma (1,832 bytes)
  • gtkprnfix.diff (3,748 bytes)
    Index: lcl/printers.pas
    ===================================================================
    --- lcl/printers.pas	(revisión: 60701)
    +++ lcl/printers.pas	(copia de trabajo)
    @@ -747,7 +747,7 @@
     
     procedure TPrinter.SetOrientation(const AValue: TPrinterOrientation);
     begin
    -  CheckPrinting(False);
    +  //CheckPrinting(False);
       DoSetOrientation(aValue);
     end;
     
    Index: components/cairocanvas/cairocanvas.pas
    ===================================================================
    --- components/cairocanvas/cairocanvas.pas	(revisión: 60701)
    +++ components/cairocanvas/cairocanvas.pas	(copia de trabajo)
    @@ -163,6 +163,11 @@
       { TCairoPsCanvas }
     
       TCairoPsCanvas = class(TCairoFileCanvas)
    +  private
    +    fPaperWidth, fPaperHeight: double;
    +    fHandle: Pcairo_t;
    +    procedure GetPageProperties(out aWidth, aHeight: double; out orStr:string);
    +    procedure UpdatePageTransform;
       protected
         function CreateCairoHandle: HDC; override;
       public
    @@ -1515,21 +1520,53 @@
     
     { TCairoPsCanvas }
     
    +procedure TCairoPsCanvas.GetPageProperties(out aWidth, aHeight: double; out
    +  orStr: string);
    +begin
    +  if Orientation in [poLandscape, poReverseLandscape] then begin
    +    orStr := '%%PageOrientation: Landscape';
    +    aWidth := PaperHeight*ScaleY; //switch H, W
    +    aHeight := PaperWidth*ScaleX;
    +  end else begin
    +    orStr := '%%PageOrientation: Portait';
    +    aWidth := PaperWidth*ScaleX;
    +    aHeight := PaperHeight*ScaleY;
    +  end;
    +
    +end;
    +
    +procedure TCairoPsCanvas.UpdatePageTransform;
    +var
    +  W, H: double;
    +  Dummy: string;
    +begin
    +  GetPageProperties(W, H, Dummy);
    +
    +  cairo_identity_matrix(fHandle);
    +
    +  case Orientation of
    +    poLandscape: begin
    +      cairo_translate(fHandle, 0, H);
    +      cairo_rotate(fHandle, -PI/2);
    +    end;
    +    poReverseLandscape: begin
    +      cairo_translate(fHandle, W, 0);
    +      cairo_rotate(fHandle, PI/2);
    +    end;
    +    poReversePortrait: begin
    +      cairo_translate(fHandle, W, H);
    +      cairo_rotate(fHandle, PI);
    +    end;
    +  end;
    +
    +end;
    +
     function TCairoPsCanvas.CreateCairoHandle: HDC;
     var
       s: string;
       W, H: Double;
    -  acr: Pcairo_t;
     begin
    -  if Orientation in [poLandscape, poReverseLandscape] then begin
    -    s := '%%PageOrientation: Landscape';
    -    W := PaperHeight*ScaleY; //switch H, W
    -    H := PaperWidth*ScaleX;
    -  end else begin
    -    s := '%%PageOrientation: Portait';
    -    W := PaperWidth*ScaleX;
    -    H := PaperHeight*ScaleY;
    -  end;
    +  GetPageProperties(W, H, s);
     
       //Sizes are in Points, 72DPI (1pt = 1/72")
       if fStream<>nil then
    @@ -1536,7 +1573,7 @@
         sf := cairo_ps_surface_create_for_stream(@WriteToStream, fStream, W, H)
       else
         sf := cairo_ps_surface_create(PChar(FOutputFileName), W, H);
    -  acr := cairo_create(sf);
    +  fHandle := cairo_create(sf);
     
       cairo_ps_surface_dsc_begin_setup(sf);
       cairo_ps_surface_dsc_comment(sf, PChar(s));
    @@ -1549,26 +1586,23 @@
       end;
     
       //rotate and move
    -  case Orientation of
    -    poLandscape: begin
    -      cairo_translate(acr, 0, H);
    -      cairo_rotate(acr, -PI/2);
    -    end;
    -    poReverseLandscape: begin
    -      cairo_translate(acr, W, 0);
    -      cairo_rotate(acr, PI/2);
    -    end;
    -    poReversePortrait: begin
    -      cairo_translate(acr, W, H);
    -      cairo_rotate(acr, PI);
    -    end;
    -  end;
    -  result := {%H-}HDC(acr);
    +  UpdatePageTransform;
    +
    +  result := {%H-}HDC(fHandle);
     end;
     
     procedure TCairoPsCanvas.UpdatePageSize;
    +var
    +  W, H: Double;
    +  S: string;
     begin
    -  cairo_ps_surface_set_size(sf, PaperWidth*ScaleX, PaperHeight*ScaleY);
    +  GetPageProperties(W, H, S);
    +
    +  cairo_ps_surface_dsc_begin_page_setup(sf);
    +  cairo_ps_surface_dsc_comment(sf, PChar(s));
    +  cairo_ps_surface_set_size(sf, W, H);
    +
    +  UpdatePageTransform;
     end;
     
     constructor TCairoPngCanvas.Create(APrinter: TPrinter);
    
    gtkprnfix.diff (3,748 bytes)

Relationships

related to 0034680 closedJesus Reyes Regression. Printing under linux broken. 

Activities

Timl

2019-01-23 10:23

reporter  

printtest.tar.lzma (1,832 bytes)

Anton Kavalenka

2019-01-23 21:24

reporter   ~0113601

Can confirm. FPC 3.3.1 and Lazarus 2.1 svn
2nd page is wrongly rotated.

with strange warning
cairoprinter.pas(238,8) Warning: (4040) Class types "TCairoFileCanvas" and "TDocAccess" are not related

Juha Manninen

2019-01-24 01:04

developer   ~0113605

Last edited: 2019-01-24 21:20

View 2 revisions

May be related to 0034680 and r59492.

I removed the useless accessor class TDocAccess completely in r60207.

Juha Manninen

2019-03-16 18:22

developer   ~0114872

Jesus, could you please look into this.

Jesus Reyes

2019-03-19 15:31

developer  

gtkprnfix.diff (3,748 bytes)
Index: lcl/printers.pas
===================================================================
--- lcl/printers.pas	(revisión: 60701)
+++ lcl/printers.pas	(copia de trabajo)
@@ -747,7 +747,7 @@
 
 procedure TPrinter.SetOrientation(const AValue: TPrinterOrientation);
 begin
-  CheckPrinting(False);
+  //CheckPrinting(False);
   DoSetOrientation(aValue);
 end;
 
Index: components/cairocanvas/cairocanvas.pas
===================================================================
--- components/cairocanvas/cairocanvas.pas	(revisión: 60701)
+++ components/cairocanvas/cairocanvas.pas	(copia de trabajo)
@@ -163,6 +163,11 @@
   { TCairoPsCanvas }
 
   TCairoPsCanvas = class(TCairoFileCanvas)
+  private
+    fPaperWidth, fPaperHeight: double;
+    fHandle: Pcairo_t;
+    procedure GetPageProperties(out aWidth, aHeight: double; out orStr:string);
+    procedure UpdatePageTransform;
   protected
     function CreateCairoHandle: HDC; override;
   public
@@ -1515,21 +1520,53 @@
 
 { TCairoPsCanvas }
 
+procedure TCairoPsCanvas.GetPageProperties(out aWidth, aHeight: double; out
+  orStr: string);
+begin
+  if Orientation in [poLandscape, poReverseLandscape] then begin
+    orStr := '%%PageOrientation: Landscape';
+    aWidth := PaperHeight*ScaleY; //switch H, W
+    aHeight := PaperWidth*ScaleX;
+  end else begin
+    orStr := '%%PageOrientation: Portait';
+    aWidth := PaperWidth*ScaleX;
+    aHeight := PaperHeight*ScaleY;
+  end;
+
+end;
+
+procedure TCairoPsCanvas.UpdatePageTransform;
+var
+  W, H: double;
+  Dummy: string;
+begin
+  GetPageProperties(W, H, Dummy);
+
+  cairo_identity_matrix(fHandle);
+
+  case Orientation of
+    poLandscape: begin
+      cairo_translate(fHandle, 0, H);
+      cairo_rotate(fHandle, -PI/2);
+    end;
+    poReverseLandscape: begin
+      cairo_translate(fHandle, W, 0);
+      cairo_rotate(fHandle, PI/2);
+    end;
+    poReversePortrait: begin
+      cairo_translate(fHandle, W, H);
+      cairo_rotate(fHandle, PI);
+    end;
+  end;
+
+end;
+
 function TCairoPsCanvas.CreateCairoHandle: HDC;
 var
   s: string;
   W, H: Double;
-  acr: Pcairo_t;
 begin
-  if Orientation in [poLandscape, poReverseLandscape] then begin
-    s := '%%PageOrientation: Landscape';
-    W := PaperHeight*ScaleY; //switch H, W
-    H := PaperWidth*ScaleX;
-  end else begin
-    s := '%%PageOrientation: Portait';
-    W := PaperWidth*ScaleX;
-    H := PaperHeight*ScaleY;
-  end;
+  GetPageProperties(W, H, s);
 
   //Sizes are in Points, 72DPI (1pt = 1/72")
   if fStream<>nil then
@@ -1536,7 +1573,7 @@
     sf := cairo_ps_surface_create_for_stream(@WriteToStream, fStream, W, H)
   else
     sf := cairo_ps_surface_create(PChar(FOutputFileName), W, H);
-  acr := cairo_create(sf);
+  fHandle := cairo_create(sf);
 
   cairo_ps_surface_dsc_begin_setup(sf);
   cairo_ps_surface_dsc_comment(sf, PChar(s));
@@ -1549,26 +1586,23 @@
   end;
 
   //rotate and move
-  case Orientation of
-    poLandscape: begin
-      cairo_translate(acr, 0, H);
-      cairo_rotate(acr, -PI/2);
-    end;
-    poReverseLandscape: begin
-      cairo_translate(acr, W, 0);
-      cairo_rotate(acr, PI/2);
-    end;
-    poReversePortrait: begin
-      cairo_translate(acr, W, H);
-      cairo_rotate(acr, PI);
-    end;
-  end;
-  result := {%H-}HDC(acr);
+  UpdatePageTransform;
+
+  result := {%H-}HDC(fHandle);
 end;
 
 procedure TCairoPsCanvas.UpdatePageSize;
+var
+  W, H: Double;
+  S: string;
 begin
-  cairo_ps_surface_set_size(sf, PaperWidth*ScaleX, PaperHeight*ScaleY);
+  GetPageProperties(W, H, S);
+
+  cairo_ps_surface_dsc_begin_page_setup(sf);
+  cairo_ps_surface_dsc_comment(sf, PChar(s));
+  cairo_ps_surface_set_size(sf, W, H);
+
+  UpdatePageTransform;
 end;
 
 constructor TCairoPngCanvas.Create(APrinter: TPrinter);
gtkprnfix.diff (3,748 bytes)

Jesus Reyes

2019-03-19 15:36

developer   ~0114926

Attached is a patch for fixing this problem, please test.

Julio Jiménez Borreguero

2019-03-19 16:40

reporter   ~0114927

Last edited: 2019-03-19 16:41

View 2 revisions

I have applied the patch to lazarus trunk and all looks OK. Attached image with the results (printing to PDF).

Julio Jiménez Borreguero

2019-03-19 16:41

reporter  

Jesus Reyes

2019-03-20 04:15

developer   ~0114934

I applied the change, please test.

Issue History

Date Modified Username Field Change
2019-01-23 10:23 Timl New Issue
2019-01-23 10:23 Timl File Added: printtest.tar.lzma
2019-01-23 21:24 Anton Kavalenka Note Added: 0113601
2019-01-24 01:02 Juha Manninen Relationship added related to 0034680
2019-01-24 01:04 Juha Manninen Note Added: 0113605
2019-01-24 21:20 Juha Manninen Note Edited: 0113605 View Revisions
2019-03-16 18:21 Juha Manninen Assigned To => Jesus Reyes
2019-03-16 18:21 Juha Manninen Status new => assigned
2019-03-16 18:22 Juha Manninen Note Added: 0114872
2019-03-19 15:31 Jesus Reyes File Added: gtkprnfix.diff
2019-03-19 15:36 Jesus Reyes LazTarget => -
2019-03-19 15:36 Jesus Reyes Note Added: 0114926
2019-03-19 15:36 Jesus Reyes Status assigned => feedback
2019-03-19 16:40 Julio Jiménez Borreguero Note Added: 0114927
2019-03-19 16:41 Julio Jiménez Borreguero File Added: Captura de pantalla de 2019-03-19 16-35-39.png
2019-03-19 16:41 Julio Jiménez Borreguero Note Edited: 0114927 View Revisions
2019-03-20 04:15 Jesus Reyes Fixed in Revision => 60732
2019-03-20 04:15 Jesus Reyes LazTarget - => 2.0.2
2019-03-20 04:15 Jesus Reyes Note Added: 0114934
2019-03-20 04:15 Jesus Reyes Status feedback => resolved
2019-03-20 04:15 Jesus Reyes Fixed in Version => 2.0.2
2019-03-20 04:15 Jesus Reyes Resolution open => fixed
2019-03-20 04:15 Jesus Reyes Target Version => 2.0.2