View Issue Details

IDProjectCategoryView StatusLast Update
0023138LazarusLazReportpublic2012-11-02 19:01
ReporterTony Whyman Assigned ToJesus Reyes  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.0.2 
Target Version1.2.0Fixed in Version1.1 (SVN) 
Summary0023138: PDF Export Addon Print Right Justified text raggedly
DescriptionExporting a form with right justified text to PDF using the PDF addon results in ragged right printing even though the text appears correct in the preview.
Additional InformationThe problem is due to the InternalOnExportText method being called with a position computed using the screen text metrics - which are almost guaranteed to be different from the PDF metrics. The position needs to be passed unadjusted to the export function and the export function has to computed the correct text alignment.

The attached patch makes this change and changes the PDF add on to compute correct alignment.
TagsNo tags attached.
Fixed in Revision39231
LazTarget1.2
WidgetsetGTK 2
Attached Files

Activities

2012-10-16 09:42

 

pdfraggedright.diff (2,737 bytes)   
diff -urpN lazarus.orig/components/lazreport/source/addons/pdfexport/lr_e_pdf.pas lazarus/components/lazreport/source/addons/pdfexport/lr_e_pdf.pas
--- lazarus.orig/components/lazreport/source/addons/pdfexport/lr_e_pdf.pas	2011-12-19 19:25:27.000000000 +0000
+++ lazarus/components/lazreport/source/addons/pdfexport/lr_e_pdf.pas	2012-10-14 16:38:28.565722675 +0100
@@ -438,25 +438,29 @@ end;
 procedure TfrTNPDFExportFilter.OnText(X, Y: Integer; const Text: string;
     View: TfrView);
 var
-    PRTLabel: TPRText;
+    PRTLabel: TPRLabel;
     nx, ny,
         ndx, ndy: Integer;
+    gapx, gapy: integer;
 begin
-    nx := Round(x  * PDFEscx) + 1;
-    ny := Round(y * PDFEscy) + 1;
-    ndx := Round(View.dx * PDFEscx);
-    ndy := Round(View.dy * PDFEscy);
+    gapx := Round(View.FrameWidth / 2) + 2;
+    gapy := Round(View.FrameWidth / 2) div 2 + 1;
+    nx := Round((x+gapx)  * PDFEscx) + 1;
+    ny := Round((y+gapy) * PDFEscy) + 1;
+    ndx := Round((View.dx-gapx) * PDFEscx);
+    ndy := Round((View.dy-gapy) * PDFEscy);
 
-    PRTLabel := TPRText.Create(PRPanel);
+    PRTLabel := TPRLabel.Create(PRPanel);
     PRTLabel.Parent := PRPanel;
     try
-        PRTLabel.Text := Text;
+        PRTLabel.Caption := Text;
         PRTLabel.Left := nx;
         PRTLabel.Top := ny;
         PRTLabel.Width := ndx;
         PRTLabel.Height := ndy;
         if View is TfrMemoView then
         begin
+            PRTLabel.Alignment :=  TfrMemoView_(View).Alignment;
             if Pos('Arial', TfrMemoView_(View).Font.Name) > 0 then
                 PRTLabel.FontName := fnArial
             else if Pos('Courier', TfrMemoView_(View).Font.Name) > 0 then
@@ -474,6 +479,8 @@ begin
     end;
 end;
 
+
+
 initialization
     frRegisterExportFilter(TfrTNPDFExportFilter, 'Adobe Acrobat PDF ' + ' (*.pdf)',
         '*.pdf');
diff -urpN lazarus.orig/components/lazreport/source/lr_class.pas lazarus/components/lazreport/source/lr_class.pas
--- lazarus.orig/components/lazreport/source/lr_class.pas	2012-05-06 09:15:33.000000000 +0100
+++ lazarus/components/lazreport/source/lr_class.pas	2012-10-15 19:20:00.599498994 +0100
@@ -2895,6 +2904,6 @@ var
         if not Exporting then
           Canvas.TextRect(DR, CurX, CurY, St)
         else
-          CurReport.InternalOnExportText(curx, cury, St, Self);
-          
+          CurReport.InternalOnExportText(X, CurY, St, Self);
+
         Inc(CurStrNo);
         Result := False;
       end
@@ -2948,5 +2965,5 @@ var
       if not Exporting then
          canvas.TextOut(curx,cury,str)
       else
-        CurReport.InternalOnExportText(curx, cury, str, Self);
+        CurReport.InternalOnExportText(CurX, Y, str, Self);
       Inc(CurStrNo);
       curx := curx + th;
     end;


pdfraggedright.diff (2,737 bytes)   

Jesus Reyes

2012-11-02 19:01

developer   ~0063643

Applied to trunk, will try later to merge to fixes.

Thanks.

Issue History

Date Modified Username Field Change
2012-10-16 09:42 Tony Whyman New Issue
2012-10-16 09:42 Tony Whyman File Added: pdfraggedright.diff
2012-10-16 09:42 Tony Whyman Widgetset => GTK 2
2012-10-16 13:40 Jesus Reyes Status new => assigned
2012-10-16 13:40 Jesus Reyes Assigned To => Jesus Reyes
2012-11-02 19:01 Jesus Reyes Fixed in Revision => 39231
2012-11-02 19:01 Jesus Reyes LazTarget => 1.2
2012-11-02 19:01 Jesus Reyes Status assigned => resolved
2012-11-02 19:01 Jesus Reyes Fixed in Version => 1.1 (SVN)
2012-11-02 19:01 Jesus Reyes Resolution open => fixed
2012-11-02 19:01 Jesus Reyes Note Added: 0063643
2012-11-02 19:01 Jesus Reyes Target Version => 1.2.0