View Issue Details

IDProjectCategoryView StatusLast Update
0037996PackagesLazReportpublic2020-10-28 17:40
ReporterStefan Sinne Assigned ToJesus Reyes  
PrioritynormalSeverityminorReproducibilityhave not tried
Status assignedResolutionopen 
Summary0037996: Package lazreportpdfexport new feature: Create link annotation for TfrMemoView.URLInfo
DescriptionWith the added patch the exporter will create a link annotation for a TfrMemoView that has a valid URI given in property URLInfo.
For this patch to work it is necesarry to first apply the patches of ticket 0037995 for ccr package powerpdf.
TagsNo tags attached.
Fixed in Revision
LazTarget
Widgetset
Attached Files

Relationships

related to 0037995 assignedJesus Reyes Lazarus CCR PowerPDF new feature: Link (URI Action) annotations 

Activities

Stefan Sinne

2020-10-27 15:39

reporter  

lr_e_pdf.pas.diff (3,318 bytes)   
Index: lr_e_pdf.pas
===================================================================
--- lr_e_pdf.pas	(revisi�n: 64044)
+++ lr_e_pdf.pas	(copia de trabajo)
@@ -11,6 +11,15 @@
 { http://www.base2ti.com/zlib.htm                    }
 {                                                    }
 {****************************************************}
+{*
+ * 2020.10.23 added export of annotation links for TfrMemoView.URLInfo.
+ *                                           (<setfan[at]smartsoftware[dot]com>)
+ *            The URI put into URLInfo must start with a common scheme
+ *            identifier (http://, ftp://, etc.) and must be a valid uri with
+ *            all special characters already escaped. You could use for example
+ *            the functions EncodeURL and EncodeURLElement from the Synapse
+ *            project, unit synacode.
+ *}
 
 unit lr_e_pdf;
 
@@ -72,7 +81,7 @@
 
 implementation
 
-uses lr_Const;
+uses lr_Const, PRAnnotation;
 
 type
     TfrMemoView_ = class(TfrMemoView);
@@ -485,9 +494,39 @@
     View: TfrView);
 var
     PRTLabel: TPRLabel;
+    PRTAnno: TPRAnnotation;
     nx, ny, ndx, ndy: Integer;
     gapx, gapy: integer;
     memo: TfrMemoView;
+
+    // Simple uri check, since TfrMemoView.URLInfo may be used in other projects
+    // to store other data than an URI.
+    function IsValidURI(uri: PChar): Boolean;
+    const
+      cHTTP:     PChar = 'http://';
+      cHTTPS:    PChar = 'https://';
+      cFTP:      PChar = 'ftp://';
+      cFILE:     PChar = 'file://';
+      cGOPHER:   PChar = 'gopher://';
+      cMAILTO:   PChar = 'mailto:';
+      cNEWS:     PChar = 'news:';
+      cNNTP:     PChar = 'nntp://';
+      cTELNET:   PChar = 'telnet://';
+      cWAIS:     PChar = 'wais://';
+      cPROSPERO: PChar = 'prospero://';
+    begin
+      result := (strlicomp(uri, cHTTP, strlen(cHTTP)) = 0) or
+                (strlicomp(uri, cHTTPS, strlen(cHTTPS)) = 0) or
+                (strlicomp(uri, cFTP, strlen(cFTP)) = 0) or
+                (strlicomp(uri, cFILE, strlen(cFILE)) = 0) or
+                (strlicomp(uri, cGOPHER, strlen(cGOPHER)) = 0) or
+                (strlicomp(uri, cMAILTO, strlen(cMAILTO)) = 0) or
+                (strlicomp(uri, cNEWS, strlen(cNEWS)) = 0) or
+                (strlicomp(uri, cNNTP, strlen(cNNTP)) = 0) or
+                (strlicomp(uri, cTELNET, strlen(cTELNET)) = 0) or
+                (strlicomp(uri, cWAIS, strlen(cWAIS)) = 0) or
+                (strlicomp(uri, cPROSPERO, strlen(cPROSPERO)) = 0);
+    end;
 begin
     gapx := trunc(View.FrameWidth / 2 + 0.5) + 2;
     gapy := trunc(View.FrameWidth / 4 + 0.5) + 1;
@@ -522,6 +561,17 @@
         PRTLabel.FontUnderline := fsUnderline in memo.Font.Style;
         PRTLabel.Angle:= memo.Angle;
         PRTLabel.AlignJustified :=  memo.Justify and not memo.LastLine;
+        if IsValidURI(PChar(memo.URLInfo)) then begin
+          // create link annotation
+          PRTAnno := TPRAnnotation.Create(PRPanel);
+          PRTAnno.Parent := PRPanel;
+          PRTAnno.SubType := asLink;
+          PRTAnno.Action.URI := memo.URLInfo;
+          PRTAnno.Left := PRTLabel.Left;
+          PRTAnno.Top := PRTLabel.Top;
+          PRTAnno.Width := PRTLabel.Width;
+          PRTAnno.Height := PRTLabel.Height;
+        end;
       end;
     finally
     end;
lr_e_pdf.pas.diff (3,318 bytes)   
test.pdf (2,291 bytes)

Stefan Sinne

2020-10-28 17:40

reporter   ~0126608

This is a new versión, which supposes that TfrMemoView.URLInfo, if filled, is a valid URI and so will be used for the link annotation. No need to test if the uri is valid, which is quite complicated. The user has to assure the right format.
lr_e_pdf.pas-2.diff (1,888 bytes)   
Index: lr_e_pdf.pas
===================================================================
--- lr_e_pdf.pas	(revisi�n: 64044)
+++ lr_e_pdf.pas	(copia de trabajo)
@@ -11,6 +11,14 @@
 { http://www.base2ti.com/zlib.htm                    }
 {                                                    }
 {****************************************************}
+{*
+ * 2020.10.23 added export of annotation links for TfrMemoView.URLInfo.
+ *                                           (<setfan[at]smartsoftware[dot]com>)
+ *            The URI put into URLInfo is supposed to be a valid uri
+ *            (http://..., ftp://..., etc.) with all special characters already
+ *            escaped. You could use for example the functions EncodeURL and
+ *            EncodeURLElement from the Synapse project, unit synacode.
+ *}
 
 unit lr_e_pdf;
 
@@ -72,7 +80,7 @@
 
 implementation
 
-uses lr_Const;
+uses lr_Const, PRAnnotation;
 
 type
     TfrMemoView_ = class(TfrMemoView);
@@ -485,6 +493,7 @@
     View: TfrView);
 var
     PRTLabel: TPRLabel;
+    PRTAnno: TPRAnnotation;
     nx, ny, ndx, ndy: Integer;
     gapx, gapy: integer;
     memo: TfrMemoView;
@@ -522,6 +531,18 @@
         PRTLabel.FontUnderline := fsUnderline in memo.Font.Style;
         PRTLabel.Angle:= memo.Angle;
         PRTLabel.AlignJustified :=  memo.Justify and not memo.LastLine;
+        // suppose that URLInfo always contains a valid URI
+        if Trim(memo.URLInfo) <> '' then begin
+          // create link annotation
+          PRTAnno := TPRAnnotation.Create(PRPanel);
+          PRTAnno.Parent := PRPanel;
+          PRTAnno.SubType := asLink;
+          PRTAnno.Action.URI := memo.URLInfo;
+          PRTAnno.Left := PRTLabel.Left;
+          PRTAnno.Top := PRTLabel.Top;
+          PRTAnno.Width := PRTLabel.Width;
+          PRTAnno.Height := PRTLabel.Height;
+        end;
       end;
     finally
     end;
lr_e_pdf.pas-2.diff (1,888 bytes)   

Issue History

Date Modified Username Field Change
2020-10-27 15:39 Stefan Sinne New Issue
2020-10-27 15:39 Stefan Sinne File Added: lr_e_pdf.pas.diff
2020-10-27 15:39 Stefan Sinne File Added: test.pdf
2020-10-27 16:06 Marco van de Voort Relationship added related to 0037995
2020-10-27 22:56 Jesus Reyes Assigned To => Jesus Reyes
2020-10-27 22:56 Jesus Reyes Status new => assigned
2020-10-28 17:40 Stefan Sinne Note Added: 0126608
2020-10-28 17:40 Stefan Sinne File Added: lr_e_pdf.pas-2.diff