diff options
author | Jean-Marc Levecque <jean-marc.levecque@jmlesite.fr> | 2011-01-20 10:32:17 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2011-01-20 10:32:17 +0200 |
commit | 3db3fc8cad32b4d84164b6089db196f955be721a (patch) | |
tree | a9368a9eccded273f9ab0b2d7e365d443fac0fe2 /extras | |
parent | 9fd8c8491a9b1662e288e34058cb58f942f55a32 (diff) | |
download | fpGUI-3db3fc8cad32b4d84164b6089db196f955be721a.tar.xz |
PDF reporting: it is now possible to paint a surface delimited by a polygon.
Diffstat (limited to 'extras')
4 files changed, 282 insertions, 12 deletions
diff --git a/extras/contributed/report_tool/demo/u_demo.pas b/extras/contributed/report_tool/demo/u_demo.pas index c2084820..d5deec82 100644 --- a/extras/contributed/report_tool/demo/u_demo.pas +++ b/extras/contributed/report_tool/demo/u_demo.pas @@ -26,6 +26,7 @@ type Bt_PdfLines: TfpgButton; Bt_PdfGrid: TfpgButton; Bt_PdfGraph: TfpgButton; + Bt_PdfSurf: TfpgButton; L_Visu: TfpgLabel; Bt_VisuEmptyPage: TfpgButton; Bt_VisuSimpleText: TfpgButton; @@ -37,6 +38,7 @@ type Bt_VisuLines: TfpgButton; Bt_VisuGrid: TfpgButton; Bt_VisuGraph: TfpgButton; + Bt_VisuSurf: TfpgButton; L_Print: TfpgLabel; Bt_PrintEmptyPage: TfpgButton; Bt_PrintSimpleText: TfpgButton; @@ -48,6 +50,7 @@ type Bt_PrintLines: TfpgButton; Bt_PrintGrid: TfpgButton; Bt_PrintGraph: TfpgButton; + Bt_PrintSurf: TfpgButton; Bt_Fermer: TfpgButton; procedure Bt_PdfEmptyPageClick(Sender: TObject); procedure Bt_PdfSimpleTextClick(Sender: TObject); @@ -59,6 +62,7 @@ type procedure Bt_PdfLinesClick(Sender: TObject); procedure Bt_PdfGridClick(Sender: TObject); procedure Bt_PdfGraphClick(Sender: TObject); + procedure Bt_PdfSurfClick(Sender: TObject); procedure Bt_VisuEmptyPageClick(Sender: TObject); procedure Bt_VisuSimpleTextClick(Sender: TObject); procedure Bt_VisuMultiPagesClick(Sender: TObject); @@ -69,6 +73,7 @@ type procedure Bt_VisuLinesClick(Sender: TObject); procedure Bt_VisuGridClick(Sender: TObject); procedure Bt_VisuGraphClick(Sender: TObject); + procedure Bt_VisuSurfClick(Sender: TObject); procedure Bt_PrintEmptyPageClick(Sender: TObject); procedure Bt_PrintSimpleTextClick(Sender: TObject); procedure Bt_PrintMultiPagesClick(Sender: TObject); @@ -79,6 +84,7 @@ type procedure Bt_PrintLinesClick(Sender: TObject); procedure Bt_PrintGridClick(Sender: TObject); procedure Bt_PrintGraphClick(Sender: TObject); + procedure Bt_PrintSurfClick(Sender: TObject); procedure Bt_FermerClick(Sender: TObject); procedure ImprimeEmptyPage(Preview: Boolean); procedure ImprimeSimpleText(Preview: Boolean); @@ -90,6 +96,7 @@ type procedure ImprimeLines(Preview: Boolean); procedure ImprimeGrid(Preview: Boolean); procedure ImprimeGraph(Preview: Boolean); + procedure ImprimeSurf(Preview: Boolean); public constructor Create(AOwner: TComponent); override; end; @@ -628,6 +635,58 @@ with Imprime do end; end; +procedure TF_Demo.Bt_PdfSurfClick(Sender: TObject); +var + Fd_SauvePdf: TfpgFileDialog; + FichierPdf: string; + FluxFichier: TFileStream; +begin +Imprime:= T_Imprime.Create; +with Imprime do + begin +// Langue:= Version; + ImprimeSurf(False); + if T_Section(Sections[Pred(Sections.Count)]).TotPages= 0 + then + begin + ShowMessage('There is no file to print'); + Exit; + end; + Fd_SauvePdf:= TfpgFileDialog.Create(nil); + Fd_SauvePdf.InitialDir:= ExtractFilePath(Paramstr(0)); + Fd_SauvePdf.FontDesc:= 'bitstream vera sans-9'; + Fd_SauvePdf.Filter:= 'Fichiers pdf |*.pdf'; + Fd_SauvePdf.FileName:= 'Surface.pdf'; + try + if Fd_SauvePdf.RunSaveFile + then + begin + FichierPdf:= Fd_SauvePdf.FileName; + if Lowercase(Copy(FichierPdf,Length(FichierPdf)-3,4))<> '.pdf' + then + FichierPdf:= FichierPdf+'.pdf'; + Document:= TPdfDocument.CreateDocument; + with Document do + begin + FluxFichier:= TFileStream.Create(FichierPdf,fmCreate); + EcritDocument(FluxFichier); + FluxFichier.Free; + Free; + end; + {$ifdef linux} + fpgOpenURL(FichierPdf); + {$endif} + {$ifdef win32} + ShellExecute(0,PChar('OPEN'),PChar(FichierPdf),PChar(''),PChar(''),1); + {$endif} + end; + finally + Fd_SauvePdf.Free; + end; + Free; + end; +end; + procedure TF_Demo.Bt_VisuEmptyPageClick(Sender: TObject); begin Imprime:= T_Imprime.Create; @@ -748,6 +807,18 @@ with Imprime do end; end; +procedure TF_Demo.Bt_VisuSurfClick(Sender: TObject); +begin +Imprime:= T_Imprime.Create; +with Imprime do + begin + //Langue:= Version; + DefaultFile:= 'Surface.pdf'; + ImprimeSurf(True); + Free; + end; +end; + procedure TF_Demo.Bt_PrintEmptyPageClick(Sender: TObject); begin @@ -798,6 +869,11 @@ begin end; +procedure TF_Demo.Bt_PrintSurfClick(Sender: TObject); +begin + +end; + procedure TF_Demo.Bt_FermerClick(Sender: TObject); begin Close; @@ -1278,6 +1354,34 @@ with Imprime do end; end; +procedure TF_Demo.ImprimeSurf(Preview: Boolean); +var + FtTitre,FtTexte: Integer; + IlTitre,IlTexte: Integer; + begin + with Imprime do + begin + // define orientation, page format, measurement unit, language, preview (true) or print (false) + Debut(oPortrait,A4,msMM,Langue,Preview); + // create a new section and define the margins with an additional one due to frames drawing + Section(10,10,10,10); + // create the fonts to be used (use one of the 14 Adobe PDF standard fonts) + FtTitre:= Fonte('helvetica-15:bold',clBlack); + FtTexte:= Fonte('helvetica-7',clBlack); + // create line spacings to be used + IlTitre:= Interligne(3,0,3); + IlTexte:= Interligne(1,0,0); + EcritEnTete(cnCenter,lnFin,'SHOWING SURFACE',ColDefaut,FtTitre,IlTitre); + // write page number and total of pages on each page + NumPagePied(cnRight,lnFin,'Page','of',True,ColDefaut,FtTexte,IlTexte); + // paint some surfaces + SurfPage([40,40,100],[50,110,80],clGreen); + SurfPage([30,50,150,80,120,130],[120,180,180,160,140,120],clFuchsia); + // preparation is finished, so create PDF objects + Fin; + end; + end; + constructor TF_Demo.Create(AOwner: TComponent); var Cpt: Integer; @@ -1285,7 +1389,7 @@ begin inherited Create(AOwner); Name := 'F_Demo'; WindowTitle:= 'PDF demo'; -SetPosition(0, 0, 650, 500); +SetPosition(0, 0, 650, 550); WindowPosition:= wpScreenCenter; Sizeable:= False; CreateReportImages; @@ -1307,6 +1411,7 @@ Bt_PdfColor:= CreateButton(Self,50,270,150,'Show colors',@Bt_PdfColorClick,'repi Bt_PdfLines:= CreateButton(Self,50,310,150,'Draw lines',@Bt_PdfLinesClick,'repimg.Adobe_pdf'); Bt_PdfGrid:= CreateButton(Self,50,350,150,'Show grid',@Bt_PdfGridClick,'repimg.Adobe_pdf'); Bt_PdfGraph:= CreateButton(Self,50,390,150,'Show graph',@Bt_PdfGraphClick,'repimg.Adobe_pdf'); +Bt_PdfSurf:= CreateButton(Self,50,430,150,'Show surface',@Bt_PdfSurfClick,'repimg.Adobe_pdf'); L_Pdf:= CreateLabel(Self,250,5,'Preview',150,20,taCenter); Bt_VisuEmptyPage:= CreateButton(Self,250,30,150,'Empty page',@Bt_VisuEmptyPageClick,'repimg.Preview'); Bt_VisuSimpleText:= CreateButton(Self,250,70,150,'Simple text',@Bt_VisuSimpleTextClick,'repimg.Preview'); @@ -1318,6 +1423,7 @@ Bt_VisuColor:= CreateButton(Self,250,270,150,'Show colors',@Bt_VisuColorClick,'r Bt_VisuLines:= CreateButton(Self,250,310,150,'Draw lines',@Bt_VisuLinesClick,'repimg.Preview'); Bt_VisuGrid:= CreateButton(Self,250,350,150,'Show grid',@Bt_VisuGridClick,'repimg.Preview'); Bt_VisuGraph:= CreateButton(Self,250,390,150,'Show graph',@Bt_VisuGraphClick,'repimg.Preview'); +Bt_VisuSurf:= CreateButton(Self,250,430,150,'Show surface',@Bt_VisuSurfClick,'repimg.Preview'); L_Print:= CreateLabel(Self,450,5,'Print to printer',150,20,taCenter); Bt_PrintEmptyPage:= CreateButton(Self,450,30,150,'Empty page',@Bt_PrintEmptyPageClick,'repimg.Imprimer'); Bt_PrintEmptyPage.Enabled:= False; @@ -1339,7 +1445,9 @@ Bt_PrintGrid:= CreateButton(Self,450,350,150,'Show grid',@Bt_PrintGridClick,'rep Bt_PrintGrid.Enabled:= False; Bt_PrintGraph:= CreateButton(Self,450,390,150,'Show graph',@Bt_PrintGraphClick,'repimg.Imprimer'); Bt_PrintGraph.Enabled:= False; -Bt_Fermer:= CreateButton(Self,450,450,150,'Fermer',@Bt_FermerClick,'repimg.Fermer'); +Bt_PrintSurf:= CreateButton(Self,450,430,150,'Show surface',@Bt_PrintSurfClick,'repimg.Imprimer'); +Bt_PrintSurf.Enabled:= False; +Bt_Fermer:= CreateButton(Self,450,500,150,'Fermer',@Bt_FermerClick,'repimg.Fermer'); Bt_Fermer.BackgroundColor:= clTomato; Randomize; for Cpt:= 0 to 18 do diff --git a/extras/contributed/report_tool/reportengine/u_commande.pas b/extras/contributed/report_tool/reportengine/u_commande.pas index 0e119879..447fc5f7 100644 --- a/extras/contributed/report_tool/reportengine/u_commande.pas +++ b/extras/contributed/report_tool/reportengine/u_commande.pas @@ -22,7 +22,7 @@ interface uses Classes, SysUtils, - fpg_base, fpg_main; + fpg_base, fpg_main, U_Pdf; type TZone = (zEnTete,zPied,zPage,zMarges); @@ -79,6 +79,7 @@ type procedure LoadTraitHorizPage(APosXDeb,APosYDeb,AColonne,APosXFin,APosYFin,AStyle: Integer); procedure LoadTraitHorizPied(APosXDeb,APosYDeb,AColonne,APosXFin,APosYFin,AStyle: Integer); procedure LoadTraitHorizGroupe(AHeight: Integer); + procedure LoadSurf(APos: array of TPoint; AColor: TfpgColor); function GetCmdPage(NumPage: Integer): TList; property CmdEnTete: TList read FEntete; property CmdPied: TList read FPied; @@ -323,6 +324,16 @@ type property GetZone: TZone read FZone; end; + T_Surface = class(T_Commande) + private + FPoints: T_Points; + FColor: TfpgColor; + public + constructor Create(APoints: array of TPoint; AColor: TfpgColor); + property GetPoints: T_Points read FPoints; + property GetColor: TfpgColor read FColor; + end; + var Sections: TList; // Colonnes: TList; @@ -520,6 +531,12 @@ begin AGroupe.FGroupeHeight:= AGroupe.FGroupeHeight+AHeight; end; +procedure T_Section.LoadSurf(APos: array of TPoint; AColor: TfpgColor); +begin +Acommande:= T_Surface.Create(APos,AColor); +T_Page(Pages[Pred(Pages.Count)]).Commandes.Add(ACommande); +end; + function T_Section.GetCmdPage(NumPage: Integer): TList; begin Result:= T_Page(Pages[Pred(NumPage)]).Commandes; @@ -700,6 +717,17 @@ FHeight:= AHeight; FFond:= AFond; end; +constructor T_Surface.Create(APoints: array of TPoint; AColor: TfpgColor); +var + Cpt: Integer; +begin +inherited Create; +SetLength(FPoints,Length(APoints)); +for Cpt:= 0 to Pred(Length(FPoints)) do + FPoints[Cpt]:= APoints[Cpt]; +FColor:= AColor; +end; + procedure T_Espace.SetPosY(const AValue: Integer); begin if FPosY<> AValue diff --git a/extras/contributed/report_tool/reportengine/u_imprime.pas b/extras/contributed/report_tool/reportengine/u_imprime.pas index b5de5730..02c1f1a5 100644 --- a/extras/contributed/report_tool/reportengine/u_imprime.pas +++ b/extras/contributed/report_tool/reportengine/u_imprime.pas @@ -77,6 +77,7 @@ type procedure TraceCadre(StTrait: Integer; Zone: TZone); procedure TraceTrait(XDebut,YDebut,XFin,YFin,StTrait: Integer); procedure TraceTraitHoriz(XDebut,YDebut,Colonne,XFin,StTrait: Integer; Zone: TZone); + procedure PaintSurface(Points: T_Points; Couleur: TfpgColor); function GetTitreSection: string; procedure SetTitreSection(ATitre: string); public @@ -293,23 +294,24 @@ type // ColColor = new background color for the column procedure CadreMarges(AStyle: Integer); // draw a frame at the page margins - // AStyle = line style of the frame + // AStyle = reference of the line style of the frame procedure CadreEnTete(AStyle: Integer); // draw a frame at the limits of the header - // AStyle = line style of the frame + // AStyle = reference of the line style of the frame procedure CadrePage(AStyle: Integer); // draw a frame at the page limits : left and right margins, header bottom and footer top - // AStyle = line style of the frame + // AStyle = reference of the line style of the frame procedure CadrePied(AStyle: Integer); // draw a frame at the limits of the footer - // AStyle = line style of the frame + // AStyle = reference of the line style of the frame procedure TraitPage(XDebut,YDebut,XFin,YFin: Single; AStyle: Integer); // draw a line at absolute position // XDebut = horizontal position of starting point in numeric value in the measurement unit (msMM or msInch) // YDebut = vertical position of starting point in numeric value in the measurement unit (msMM or msInch) // XFin = horizontal position of ending point in numeric value in the measurement unit (msMM or msInch) // YFin = vertical position of ending point in numeric value in the measurement unit (msMM or msInch) - // AStyle = reference of the line style of the frame + // AStyle = reference of the line style of the line + procedure SurfPage(XLimits,YLimits: array of Single; AColor: TfpgColor); property Langue: Char read FVersion write FVersion; property Visualiser: Boolean read FVisualisation write FVisualisation; property NumeroSection: Integer read FNmSection write FNmSection; @@ -396,6 +398,18 @@ type property LineStyle: TfpgLineStyle read FStyle write FStyle; end; + TPdfSurf = class(TPdfElement) + private + FPage: Integer; + FPoints: T_Points; + FColor: Integer; + protected + public + property PageId: Integer read FPage write FPage; + property Points: T_Points read FPoints; + property SurfColor: Integer read FColor write FColor; + end; + var Imprime: T_Imprime; @@ -408,6 +422,7 @@ var PdfTexte: TPdfTexte; PdfRect: TPdfRect; PdfLine: TPdfLine; + PdfSurf: TPdfSurf; const FontDefaut= 0; @@ -788,6 +803,10 @@ with T_Section(Sections[Pred(NumeroSection)]) do then with Cmd as T_Trait do TraceTrait(GetPosX,GetPosY,GetEndX,GetEndY,GetStyle); + if Cmd is T_Surface + then + with Cmd as T_Surface do + PaintSurface(GetPoints,GetColor); end; if CmdPied.Count> 0 then @@ -2013,6 +2032,47 @@ with T_Section(Sections[Pred(NumeroSection)]) do end; end; +procedure T_Imprime.PaintSurface(Points: T_Points; Couleur: TfpgColor); +var + OldColor: TfpgColor; + Cpt: Integer; +begin +with T_Section(Sections[Pred(NumeroSection)]) do + case FPreparation of + ppPrepare: + LoadSurf(Points,Couleur); + ppVisualise: + begin + OldColor:= FCanevas.Color; + FCanevas.SetColor(Couleur); + FCanevas.DrawPolygon(Points); + FCanevas.SetColor(OldColor); + end; + ppFichierPdf: + begin + PdfSurf:= TPdfSurf.Create; + SetLength(PdfSurf.FPoints,Length(Points)); + for Cpt:= 0 to Pred(Length(Points)) do + begin + PdfSurf.FPoints[Cpt].X:= Points[Cpt].X; + PdfSurf.FPoints[Cpt].Y:= Paper.H-Points[Cpt].Y; + end; + with PdfSurf do + begin + PageId:= NumeroPage; + //SetLength(FPoints,Length(Points)); + //for Cpt:= 0 to Pred(Length(Points)) do // weird behaviour: points gets length= 0 inside the with clause ! + // begin + // FPoints[Cpt].X:= Points[Cpt].X; + // FPoints[Cpt].Y:= Paper.H-Points[Cpt].Y; + // end; + FColor:= Couleur; + end; + PdfPage.Add(PdfSurf); + end; + end; +end; + function T_Imprime.GetTitreSection: string; begin Result:= T_Section(Sections[Pred(Sections.Count)]).Titre; @@ -2037,8 +2097,6 @@ Bords:= TList.Create; Textes:= TStringList.Create; ALigne:= T_Ligne.Create; PdfPage:= TList.Create; -OldDecSeparator:= DecimalSeparator; -DecimalSeparator:= '.'; Outline:= False; end; @@ -2046,7 +2104,6 @@ destructor T_Imprime.Destroy; var Cpt: Integer; begin -DecimalSeparator:= OldDecSeparator; if Sections.Count> 0 then begin @@ -2725,5 +2782,28 @@ YEnd:= Dim2Pixels(YFin); TraceTrait(XDeb,YDeb,XEnd,YEnd,AStyle); end; +procedure T_Imprime.SurfPage(XLimits,YLimits: array of Single; AColor: TfpgColor); +var + Taille,Cpt: Integer; + Ends: array of TPoint; +begin +if Length(XLimits)< Length(YLimits) +then + Taille:= Length(XLimits) +else + if Length(XLimits)> Length(YLimits) + then + Taille:= Length(YLimits) + else + Taille:= Length(XLimits); +SetLength(Ends,Taille); +for Cpt:= 0 to Pred(Taille) do + begin + Ends[Cpt].X:= Dim2Pixels(XLimits[Cpt]); + Ends[Cpt].Y:= Dim2Pixels(YLimits[Cpt]); + end; +PaintSurface(Ends,AColor); +end; + end. diff --git a/extras/contributed/report_tool/reportengine/u_pdf.pas b/extras/contributed/report_tool/reportengine/u_pdf.pas index 07921e2d..00a1a1a8 100644 --- a/extras/contributed/report_tool/reportengine/u_pdf.pas +++ b/extras/contributed/report_tool/reportengine/u_pdf.pas @@ -160,6 +160,18 @@ type destructor Destroy; override; end; + T_Points = array of TPoint; + + TPdfSurface = class(TPdfObjet) + private + FPoints: array of TPoint; + protected + procedure EcritSurface(const AFlux: TStream); + public + constructor CreateSurface(const APoints: T_Points); + destructor Destroy; override; + end; + TPdfLineStyle = class(TPdfObjet) private FDash: TfpgLineStyle; @@ -512,6 +524,9 @@ for Cpt:= 0 to Pred(FStream.Count) do if TPdfObjet(FStream[Cpt]) is TPdfLineStyle then TPdfLineStyle(FStream[Cpt]).EcritLineStyle(AFlux); + if TPdfObjet(FStream[Cpt]) is TPdfSurface + then + TPdfSurface(FStream[Cpt]).EcritSurface(AFlux); end; end; @@ -638,6 +653,28 @@ begin inherited; end; +procedure TPdfSurface.EcritSurface(const AFlux: TStream); +var + Cpt: Integer; +begin +EcritChaine(IntToStr(FPoints[0].X)+' '+IntToStr(FPoints[0].Y)+' m'+CRLF,AFlux); +for Cpt:= 1 to Pred(Length(FPoints)) do + EcritChaine(IntToStr(FPoints[Cpt].X)+' '+IntToStr(FPoints[Cpt].Y)+' l'+CRLF,AFlux); +EcritChaine('h'+CRLF,AFlux); +EcritChaine('f'+CRLF,AFlux); +end; + +constructor TPdfSurface.CreateSurface(const APoints: T_Points); +begin +inherited Create; +FPoints:= APoints; +end; + +destructor TPdfSurface.Destroy; +begin +inherited; +end; + procedure TPdfLineStyle.EcritLineStyle(const AFlux: TStream); begin EcritChaine('[',AFlux); @@ -688,13 +725,18 @@ else end; constructor TPdfColor.CreateColor(const AStroke: Boolean; Couleur: Longint); +var + OldSeparator: Char; begin inherited Create; +OldSeparator:= DecimalSeparator; +DecimalSeparator:= '.'; FBlue:= FormatFloat('0.##',Couleur mod 256/256); Couleur:= Couleur div 256; FGreen:= FormatFloat('0.##',Couleur mod 256/256); FRed:= FormatFloat('0.##',Couleur div 256/256); FStroke:= AStroke; +DecimalSeparator:= OldSeparator; end; destructor TPdfColor.Destroy; @@ -1184,6 +1226,7 @@ var Fnt: TPdfFonte; Rct: TPdfRectangle; Lin: TPdfLigne; + Srf: TPdfSurface; Sty: TpdfLineStyle; begin for Cpt:= 0 to Pred(PdfPage.Count) do @@ -1249,6 +1292,17 @@ for Cpt:= 0 to Pred(PdfPage.Count) do Lin:= TPdfLigne.CreateLigne(LineEpais,LineStartX,LineStartY,LineEndX,LineEndY); TPdfStream(TPdfXRef(FXRefObjets[PageNum]).FStream).AddItem(Lin); end; + if TPdfElement(PdfPage[Cpt]) is TPdfSurf + then + if TPdfSurf(PdfPage[Cpt]).PageId= NumeroPage + then + with TPdfSurf(PdfPage[Cpt]) do + begin + Clr:= TPdfColor.CreateColor(True,SurfColor); + TPdfStream(TPdfXRef(FXRefObjets[PageNum]).FStream).AddItem(Clr); + Srf:= TPdfSurface.CreateSurface(Points); + TPdfStream(TPdfXRef(FXRefObjets[PageNum]).FStream).AddItem(Srf); + end; end; end; @@ -1330,7 +1384,7 @@ for CptSect:= 0 to Pred(Sections.Count) do with T_Section(Sections[CptSect]) do NewPage:= CreatePage(ParentPage,Paper.H,Paper.W); Inc(NumPage); - PageNum:= CreateContents; // pagenum = numéro d'objet dans le fichier PDF + PageNum:= CreateContents; // pagenum = object number in the pdf file CreateStream(NumPage,PageNum); if (Sections.Count> 1) and Outline then |