Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

pdfxml.h

Go to the documentation of this file.
///////////////////////////////////////////////////////////////////////////////
// Name:        pdfxml.h
// Purpose:     
// Author:      Ulrich Telle
// Modified by:
// Created:     2005-12-03
// Copyright:   (c) Ulrich Telle
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

/// \file pdfxml.h Interface of the wxPdfDocument markup

#ifndef _PDFXML_H_
#define _PDFXML_H_

// wxWidgets headers
#include <wx/string.h>
#include <wx/wfstream.h>

#include "wx/pdfdocdef.h"
#include "wx/pdfdoc.h"

class wxPdfTable;

/// Class representing cell context objects. (For internal use only)
00026 class wxPdfCellContext
{
public:
  /// Constructor
  wxPdfCellContext(double maxWidth, wxPdfAlignment hAlign = wxPDF_ALIGN_JUSTIFY, wxPdfAlignment vAlign = wxPDF_ALIGN_TOP);

  /// Destructor
  virtual ~wxPdfCellContext();

  /// Increase total height of cell
00036   void AddHeight(double height) { m_height += height; }

  /// Get total height of cell
00039   double GetHeight() { return m_height; }

  /// Get maximal width of cell
00042   double GetMaxWidth() { return m_maxWidth; }

  /// Get horizontal alignment
00045   wxPdfAlignment GetHAlign() { return m_hAlign; }

  /// Set vertical alignment
00048   void SetVAlign(wxPdfAlignment vAlign) { m_vAlign = vAlign; }

  /// Get vertical alignment
00051   wxPdfAlignment GetVAlign() { return m_vAlign; }

  /// Add a line to cell
  void AddLine();

  /// Get number of lines in cell
00057   size_t GetLineCount() { return m_linewidth.GetCount(); }

  /// Add width and number of spaces of the last line of the current context
  void AddLastLineValues(double width, int spaces);

  /// Get the width of the last line
  double GetLastLineWidth();

  /// Mark the current line as the last line
  void MarkLastLine();

  /// Check whether current line is marked as last line
  bool IsCurrentLineMarked();
  
  /// Adjust width of current line
  void AddCurrentLineWidth(double width);

  /// Adjust number of spaces of current line
  void AddCurrentLineSpaces(int spaces);

  /// Get width of current line
  double GetCurrentLineWidth();

  /// Get number of spaces of current line
  int    GetCurrentLineSpaces();

  /// Get number of current line
00084   size_t GetCurrentLine() { return m_currentLine; }

  /// Increment line counter
  void IncrementCurrentLine();

  /// Get line delta measure
  double GetLineDelta();

  /// Check whether alignment has been taken care of
00093   bool GetAligned() { return m_aligned; }

  /// Set flag that alignment has been taken care of
00096   void SetAligned() { m_aligned = true; }

  /// Get the number of contexts
00099   size_t GetContextCount() { return m_contexts.GetCount(); }

  /// Increment current context
  void IncrementCurrentContext();

  /// Get current context
  wxPdfCellContext* GetCurrentContext();

  /// Append context to context list
  void AppendContext(wxPdfCellContext* context);

  /// Remember the last character of the last chunk
00111   void SetLastChar(wxChar c) { m_lastChar = c; }

  /// Get last character of previous chunk
00114   wxChar GetLastChar() { return m_lastChar; }

  /// Remember the width of the last space character
00117   void SetLastSpaceWidth(double w) { m_spaceWidth = w; }

  /// Get width of last space character
00120   double GetLastSpaceWidth() { return m_spaceWidth; }

  /// Set hyper link reference
00123   void SetHRef(const wxString& href) { m_href = href; }

  /// Get hyper link reference
00126   wxString& GetHRef() { return m_href; }

  /// Set table reference
00129   void SetTable(wxPdfTable* table) { m_table = table; }

  /// Get table reference
00132   wxPdfTable* GetTable() { return m_table; }

private:
00135   double           m_maxWidth;        ///< maximal line width
00136   double           m_lineDelta;       ///< line delta measure
00137   wxPdfAlignment   m_hAlign;          ///< horizontal alignment
00138   wxPdfAlignment   m_vAlign;          ///< vertical alignment
00139   double           m_height;          ///< height of cell
00140   size_t           m_currentContext;  ///< index of current context
00141   wxArrayPtrVoid   m_contexts;        ///< list of contexts
00142   size_t           m_currentLine;     ///< index of current line
00143   bool             m_aligned;         ///< alignment flag
00144   wxPdfArrayDouble m_linewidth;       ///< list of line widths
00145   wxArrayInt       m_spaces;          ///< list of space counters
00146   wxChar           m_lastChar;        ///< last character of a chunk
00147   double           m_spaceWidth;      ///< width of space character
00148   wxString         m_href;            ///< hyper link reference
00149   wxPdfTable*      m_table;           ///< table reference
};

/// Class representing table cells. (For internal use only)
00153 class wxPdfTableCell
{
public:
  /// Constructor
  wxPdfTableCell(wxXmlNode* cell, int row, int col, int rows, int cols);

  /// Destructor
  virtual ~wxPdfTableCell();

  /// Get row of cell
00163   int GetRow() const { return m_row; }

  /// Get column of cell
00166   int GetCol() const { return m_col; }

  /// Get row span of cell
00169   int GetRowSpan() const { return m_rowSpan;};

  /// Get column span of cell
00172   int GetColSpan() const { return m_colSpan;};

  /// Set width of cell
00175   void SetWidth(double w) { m_width = w;};

  /// Set height of cell
00178   void SetHeight(double h) { m_height = h;};
  
  /// Get height of cell
00181   double GetHeight() const { return m_height;};

  /// Get width of cell
00184   double GetWidth() const { return m_width;};

  /// Set cell context
00187   void SetContext(wxPdfCellContext* context) { m_context = context; }

  /// Get cell context
00190   wxPdfCellContext* GetContext() { return m_context; }

  /// Set horizontal alignment
00193   void SetHAlign(wxPdfAlignment hAlign) { m_hAlign = hAlign; }

  /// Get horizontal alignment
00196   wxPdfAlignment GetHAlign() { return m_hAlign; }

  /// Set vertical alignment
00199   void SetVAlign(wxPdfAlignment vAlign) { m_vAlign = vAlign; }

  /// Get vertical alignment
00202   wxPdfAlignment GetVAlign() { return m_vAlign; }

  /// Set border
00205   void SetBorder(int border) { m_border = border; }

  /// Get border
00208   int GetBorder() { return m_border; }

  /// Check whether cell has a colored or transparent background
00211   bool HasCellColor() const { return m_hasCellColor; };

  /// Set background color of cell
00214   void SetCellColor(wxPdfColour color) { m_hasCellColor = true; m_colorCell = color;};

  /// Get background color of cell
00217   wxPdfColour GetCellColor() const { return m_colorCell; };

  /// Get root node of cell
00220   wxXmlNode* GetXmlNode() { return m_cell; }

private:
00223   int               m_row;           ///< row index
00224   int               m_col;           ///< column index
00225   int               m_rowSpan;       ///< row span
00226   int               m_colSpan;       ///< column span

00228   wxPdfCellContext* m_context;       ///< table cell context
00229   wxXmlNode*        m_cell;          ///< xml root node of cell
00230   wxPdfAlignment    m_hAlign;        ///< horizontal alignment
00231   wxPdfAlignment    m_vAlign;        ///< vertical alignment
00232   int               m_border;        ///< border
00233   double            m_width;         ///< cell width
00234   double            m_height;        ///< cell height
  
00236   bool              m_hasCellColor;  ///< flag whether cell has background color or is transparent
00237   wxPdfColour       m_colorCell;     ///< cell background color
}; 

/// Hashmap class for document links
WX_DECLARE_HASH_MAP(long, wxPdfTableCell*, wxIntegerHash, wxIntegerEqual, wxPdfCellHashMap);

/// Class representing tables within a cell. (For internal use only)
00244 class wxPdfTable
{
public:
  /// Constructor
  wxPdfTable(wxPdfDocument* document);

  /// Destructor
  virtual ~wxPdfTable();

  /// Set minimal required row height
00254   void SetMinRowHeight(int row, double height) { m_minHeights[row] = height; }

  /// Set width of column
  void SetColumnWidth(int col, double width);

  /// Calculate cell dimensions respecting a maximal allowed width
  void SetCellDimensions(double maxWidth);

  /// Insert a cell into the cell array
  void InsertCell(wxPdfTableCell* c);

  /// Get height of row
00266   double GetRowHeight(int row) { const double height = m_rowHeights[row]; return height; };

  /// Write table to document
  void Write();

  /// Write one table row to the document
  void WriteRow(size_t row, double x, double y);

  /// Set cell padding
00275   void SetPad(double pad) { m_pad = pad; }

  /// Get cell padding
00278   double GetPad() { return m_pad; }

  /// Set border
00281   void SetBorder(bool border) { m_border = border; }

  /// Check whether border should be drawn
00284   bool HasBorder() { return m_border; }

  /// Get total width of table
00287   double GetTotalWidth() { return m_totalWidth; }

  /// Get total height of table
00290   double GetTotalHeight() { return m_totalHeight; }

  /// Set index of first header row
00293   void SetHeadRowFirst(size_t row) { m_headRowFirst = row; }

  /// Set index of last header row
00296   void SetHeadRowLast(size_t row) { m_headRowLast = row; }

  /// Set index of first body row
00299   void SetBodyRowFirst(size_t row) { m_bodyRowFirst = row; }

  /// Set index of last body row
00302   void SetBodyRowLast(size_t row) { m_bodyRowLast = row; }

private:
00305   wxPdfDocument*     m_document;     ///< document reference
00306   wxPdfDoubleHashMap m_minHeights;   ///< array of minimal row heights
00307   wxPdfDoubleHashMap m_rowHeights;   ///< array of row heights
00308   wxPdfDoubleHashMap m_colWidths;    ///< array of column widths

00310   double             m_maxWidth;     ///< maximal allowed width
00311   double             m_totalWidth;   ///< total width
00312   double             m_totalHeight;  ///< total height
00313   double             m_headHeight;   ///< total height of table header

00315   size_t             m_headRowFirst; ///< index of first header row
00316   size_t             m_headRowLast;  ///< index of last header row
00317   size_t             m_bodyRowFirst; ///< index of first body row
00318   size_t             m_bodyRowLast;  ///< index of last body row

00320   size_t             m_nRows;        ///< number of rows
00321   size_t             m_nCols;        ///< number of columns
00322   wxPdfCellHashMap   m_table;        ///< array of table cells
00323   double             m_pad;          ///< cell padding
00324   bool               m_border;       ///< border flag
};
 
#endif

Generated by  Doxygen 1.6.0   Back to index