PoDoFo  0.9.4
Public Types | Public Member Functions | Protected Member Functions | List of all members
PoDoFo::PdfTable Class Reference

#include <PdfTable.h>

Public Types

typedef PdfPage *(* CreatePageCallback) (PdfRect &rClipRect, void *pCustom)
 

Public Member Functions

 PdfTable (int nCols, int nRows)
 
virtual void Draw (double dX, double dY, PdfPainter *pPainter, const PdfRect &rClipRect=PdfRect(), double *pdLastX=NULL, double *pdLastY=NULL)
 
virtual double GetWidth (double dX, double dY, PdfCanvas *pPage) const
 
virtual double GetHeight (double dX, double dY, PdfCanvas *pPage) const
 
void SetModel (PdfTableModel *pModel)
 
const PdfTableModelGetModel () const
 
void SetColumnWidths (double *pdWidths)
 
void SetRowHeights (double *pdHeights)
 
void SetColumnWidth (double dWidth)
 
void SetRowHeight (double dHeight)
 
void SetTableWidth (double dWidth)
 
void SetTableHeight (double dHeight)
 
void SetAutoPageBreak (bool bPageBreak, CreatePageCallback callback, void *pCustomData=NULL)
 
bool GetAutoPageBreak () const
 
int GetCols () const
 
int GetRows () const
 

Protected Member Functions

void CalculateTableSize (const double dX, const double dY, const PdfCanvas *pCanvas, double *pdWidths, double *pdHeights, double *pdWidth, double *pdHeight) const
 
void DrawHorizontalBorders (int nRow, double dX, double dY, PdfPainter *pPainter, double *pdColWidths)
 
bool CheckForNewPage (double *pdY, double *pdCurY, double dRowHeight, PdfPainter *pPainter)
 

Detailed Description

This is a high level class of a table which can be drawn to a PdfPainter.

Use this class if you have to include data into your PDF as an table.

Member Typedef Documentation

typedef PdfPage*(* PoDoFo::PdfTable::CreatePageCallback) (PdfRect &rClipRect, void *pCustom)

Callback to create a new page for PdfTable.

See also
SetAutoPageBreak
Parameters
rClipRectthis is an output parameter which has to be set to the clipping rectangle of the new page. If the new page has no clipping rectangle set it to PdfRect( 0, 0, PdfPage::GetPageSize().GetWidth(), PdfPage::GetPageSize().GetHeight() )
pCustompointer to user defined data

Constructor & Destructor Documentation

PoDoFo::PdfTable::PdfTable ( int  nCols,
int  nRows 
)

Create a new PdfTable object.

Parameters
nColsnumber of columns in the table.
nRowsnumber of rows in the table.

Member Function Documentation

void PoDoFo::PdfTable::CalculateTableSize ( const double  dX,
const double  dY,
const PdfCanvas pCanvas,
double *  pdWidths,
double *  pdHeights,
double *  pdWidth,
double *  pdHeight 
) const
protected

Internal functions that calculates the total table size for a table with the current settings when drawn on a certain page.

Parameters
dXthe X coordinate of top left at which is drawn
dYthe Y coordinate of top left at which is drawn
pCanvasthe canvas object (usually a page) on which the table will be drawn.
pdWidthspointer to an array with GetCols() doubles where the width for each column will be stored
pdHeightspointer to an array with GetRows() doublesd where the height for each row will be stored
pdWidthpointer to a double where the total width of the table will be stored
pdHeightpointer to a double where the total height of the table will be stored
bool PoDoFo::PdfTable::CheckForNewPage ( double *  pdY,
double *  pdCurY,
double  dRowHeight,
PdfPainter pPainter 
)
protected

Checks if there is enough space on the current page for one row! If necessary a new page is created.

If GetAutoPageBreak is false, this method does nothing.

Parameters
pdYtop of the table
pdCurYpointer to the current y position on the page. Might be reset to a new y position.
dRowHeightheight of the next row.
pPainterpainter used for drawing
Returns
true if a new page was created, otherwise false
void PoDoFo::PdfTable::Draw ( double  dX,
double  dY,
PdfPainter pPainter,
const PdfRect rClipRect = PdfRect(),
double *  pdLastX = NULL,
double *  pdLastY = NULL 
)
virtual

Draw the table with its current settings on a PdfPainter.

Parameters
dXx coordinate of top left of the table
dYy coordinate of top left of the table
pPainterthe painter to draw on. The painter has to have a page set currently.
rClipRectthe clipping rectangle on the current page
pdLastXthe last used X position by the table on the current page will be written to this value (usually bottom right)
pdLastYthe last used Y positon by the table on the current page will be written to this value (usually bottom right)
void PoDoFo::PdfTable::DrawHorizontalBorders ( int  nRow,
double  dX,
double  dY,
PdfPainter pPainter,
double *  pdColWidths 
)
protected

Draw one row of horizontal cell borders using the correct color for each cell.

Parameters
nRowthe current row
dXleft x coordinate
dYy coordinate
pPainteruse this painter object
pdColWidthsan array containing all colomun widths
bool PoDoFo::PdfTable::GetAutoPageBreak ( ) const
inline
Returns
true if a new page is created automatically if more space is required to draw the table.
See also
SetAutoPageBreak
int PoDoFo::PdfTable::GetCols ( ) const
inline
Returns
the number of columns in the table.
double PoDoFo::PdfTable::GetHeight ( double  dX,
double  dY,
PdfCanvas pPage 
) const
virtual

Get the width of the table when drawn with the current settings at a certain position.

Parameters
dXx coordinate of top left of the table
dYy coordinate of top left of the table
pPagethe page on which the table will be drawn
Returns
the width of the table
const PdfTableModel * PoDoFo::PdfTable::GetModel ( ) const
inline

Get the current PdfTableModel

Returns
the currently set PdfTableModel or NULL if none was set
int PoDoFo::PdfTable::GetRows ( ) const
inline
Returns
the number of rows in the table.
double PoDoFo::PdfTable::GetWidth ( double  dX,
double  dY,
PdfCanvas pPage 
) const
virtual

Get the width of the table when drawn with the current settings at a certain position.

Parameters
dXx coordinate of top left of the table
dYy coordinate of top left of the table
pPagethe page on which the table will be drawn
Returns
the width of the table
void PoDoFo::PdfTable::SetAutoPageBreak ( bool  bPageBreak,
CreatePageCallback  callback,
void *  pCustomData = NULL 
)
inline

Automatically create a new page and continue drawing the table on the new page, if there is not enough space on the current page.

The newly created page will be set as the current page on the painter used to draw and will be created using the same size as the old page.

Parameters
bPageBreakif true automatically create new pages if required.
callbacka callback function that is called to create a new page. Please note: PdfTable cannot create new pages on its own. You always have to implement a callback which does the new page creation for the PdfTable.
pCustomDatacustom data that is passed to the callback

By default this feature is turned off and contents are clipped that do not fit on the current page.

See also
GetAutoPageBreak
void PoDoFo::PdfTable::SetColumnWidth ( double  dWidth)
inline

Set all columns to have the same width.

Parameters
dWidththe width of every column

By default the column with is calculated automatically from either the table width or if no table width is set from the width of the page on which the table is drawn.

void PoDoFo::PdfTable::SetColumnWidths ( double *  pdWidths)

Set the width of all columns.

Parameters
pdWidthsa pointer to an array of GetCols() doubles which are the individual width of a column.
See also
GetCols()
void PoDoFo::PdfTable::SetModel ( PdfTableModel pModel)
inline

Set the PdfTableModel that will supply all contents and formatting informations to the table.

Parameters
pModela PdfTableModel

The model will not be owned by the PdfTable and has to be deleted by the caller.

See also
GetModel
void PoDoFo::PdfTable::SetRowHeight ( double  dHeight)
inline

Set all rows to have the same height.

Parameters
dHeightthe height of every row

By default the row height is calculated automatically from either the table height or if no table height is set from the height of the page on which the table is drawn.

void PoDoFo::PdfTable::SetRowHeights ( double *  pdHeights)

Set the height of all rows.

Parameters
pdHeightsa pointer to an array of GetRows() doubles which are the individual heights of a row.
See also
GetRows()
void PoDoFo::PdfTable::SetTableHeight ( double  dHeight)
inline

Set the height of the table.

Parameters
dHeightthe height of the whole table.

This height is used if no row height is set to calculate the height of every row. If this height is not set, the height of the page on which this table is drawn is used.

void PoDoFo::PdfTable::SetTableWidth ( double  dWidth)
inline

Set the width of the table.

Parameters
dWidththe width of the whole table.

This width is used if no column width is set to calculate the width of every column. If this width is not set, the width of the page on which this table is drawn is used.