View Issue Details

IDProjectCategoryView StatusLast Update
0037654FPCPatchpublic2020-08-28 18:23
ReporterInoussa OUEDRAOGO Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037654: [Patch] Add "DBImageType" to specify image's type for TFPReportCustomImage's data loading with "FieldName"
DescriptionTFPReportCustomImage assumed image type was PNG when loading from TFPReportData through "FieldName".

This patch introduce a new property "DBImageType" to allow the usage of other image types. "DBImageType" defaults to "PNG" for convenience.
TagsfpReport
Fixed in Revision46722
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

Inoussa OUEDRAOGO

2020-08-28 17:51

reporter  

fpreport-image-dbimagetype.patch (3,617 bytes)   
Index: fpreport.pp
===================================================================
--- fpreport.pp	(revision 46717)
+++ fpreport.pp	(working copy)
@@ -247,6 +247,8 @@
        bmOncePerDataloop,bmOncePerPage,bmOncePerPage,bmOncePerPage,
        bmUnrestricted);
 
+  DefaultImageType = 'png';
+
 const
   cMMperInch = 25.4;
   cCMperInch = 2.54;
@@ -2090,10 +2092,12 @@
     FImage: TFPCustomImage;
     FStretched: boolean;
     FFieldName: TFPReportString;
+    FDBImageType : TFPReportString;
     FImageID: integer;
     procedure   SetImage(AValue: TFPCustomImage);
     procedure   SetStretched(AValue: boolean);
-    procedure   SetFieldName(AValue: TFPReportString);
+    procedure   SetFieldName(AValue: TFPReportString); 
+    procedure   SetDBImageType(AValue: TFPReportString);
     procedure   LoadDBData(AData: TFPReportData);
     procedure   SetImageID(AValue: integer);
     function    GetImage: TFPCustomImage;
@@ -2105,6 +2109,7 @@
     property    ImageID: integer read FImageID write SetImageID;
     property    Stretched: boolean read FStretched write SetStretched;
     property    FieldName: TFPReportString read FFieldName write SetFieldName;
+    property    DBImageType : TFPReportString read FDBImageType write SetDBImageType;
   public
     constructor Create(AOwner: TComponent); override;
     destructor  Destroy; override;
@@ -2126,6 +2131,7 @@
     property    ImageID;
     property    Stretched;
     property    FieldName;
+    property    DBImageType;
     property    OnBeforePrint;
   end;
 
@@ -5331,6 +5337,14 @@
   Changed;
 end;
 
+procedure TFPReportCustomImage.SetDBImageType(AValue: TFPReportString);
+begin
+  if FDBImageType = AValue then
+    exit;
+  FDBImageType := AValue;
+  Changed;
+end;
+
 function TryVarByteArrayToStream(var AValue : Variant; Stream : TMemoryStream) : boolean;
 var
   p : Pointer;
@@ -5357,6 +5371,7 @@
   v : Variant;
   s: string;
   lStream: TMemoryStream;
+  irc : TFPCustomImageReaderClass;
 begin
   v := AData.FieldValues[FFieldName];
   lStream := TMemoryStream.Create;
@@ -5366,7 +5381,11 @@
       s := v;
       FPReportMIMEEncodeStringToStream(s, lStream);
     end;
-    LoadPNGFromStream(lStream)
+    s := Trim(DBImageType);
+    if (s = '') then
+      s := DefaultImageType;
+    irc := TFPCustomImage.FindReaderFromExtension(s);
+    LoadFromStream(lStream,irc);
   finally
     lStream.Free;
   end;
@@ -5415,7 +5434,8 @@
   idx := TFPReportCustomBand(Parent).Page.Report.Images.GetIndexFromID(ImageID);
   AWriter.WriteInteger('ImageIndex', idx);
   AWriter.WriteBoolean('Stretched', Stretched);
-  AWriter.WriteString('FieldName', FieldName);
+  AWriter.WriteString('FieldName', FieldName);  
+  AWriter.WriteString('DBImageType', DBImageType);
 end;
 
 procedure TFPReportCustomImage.RecalcLayout;
@@ -5455,6 +5475,7 @@
   FImage := nil;
   FStretched := False;
   FImageID := -1;
+  FDBImageType := DefaultImageType;
 end;
 
 destructor TFPReportCustomImage.Destroy;
@@ -5494,6 +5515,7 @@
     end;
     FStretched := i.Stretched;
     FFieldName := i.FieldName;
+    FDBImageType := i.DBImageType;
     FImageID := i.ImageID;
   end;
 end;
@@ -5504,7 +5526,8 @@
   { See code comments in DoWriteLocalProperties() }
   ImageID := AReader.ReadInteger('ImageIndex', -1);
   Stretched := AReader.ReadBoolean('Stretched', Stretched);
-  FieldName := AReader.ReadString('FieldName', FieldName);
+  FieldName := AReader.ReadString('FieldName', FieldName);  
+  DBImageType := AReader.ReadString('DBImageType', DBImageType);
 end;
 
 procedure TFPReportCustomImage.LoadFromFile(const AFileName: string);

Michael Van Canneyt

2020-08-28 18:15

administrator   ~0125178

Checked and applied: exactly as I would have done it. Thank you very much !

Issue History

Date Modified Username Field Change
2020-08-28 17:51 Inoussa OUEDRAOGO New Issue
2020-08-28 17:51 Inoussa OUEDRAOGO File Added: fpreport-image-dbimagetype.patch
2020-08-28 17:51 Inoussa OUEDRAOGO Tag Attached: fpReport
2020-08-28 17:59 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-08-28 17:59 Michael Van Canneyt Status new => assigned
2020-08-28 18:15 Michael Van Canneyt Status assigned => resolved
2020-08-28 18:15 Michael Van Canneyt Resolution open => fixed
2020-08-28 18:15 Michael Van Canneyt Fixed in Version => 3.3.1
2020-08-28 18:15 Michael Van Canneyt Fixed in Revision => 46722
2020-08-28 18:15 Michael Van Canneyt FPCTarget => 3.2.2
2020-08-28 18:15 Michael Van Canneyt Note Added: 0125178
2020-08-28 18:23 Inoussa OUEDRAOGO Status resolved => closed