#ifndef DOC_VISITOR_H
#define DOC_VISITOR_H


#include <stack>
#include "tinyxml.h"
#include "DocStyle.h"
#include "DocTemplate.h"


class DocVisitor : public TiXmlVisitor
{
public:
	DocVisitor(DocOutputDevice* doc, DocStyle* style, DocTemplate* templ);
	virtual ~DocVisitor();
	/// Visit a document.
	virtual bool VisitEnter( const TiXmlDocument& doc );
	/// Visit a document.
	virtual bool VisitExit( const TiXmlDocument& doc );
	/// Visit a declaration
	virtual bool Visit( const TiXmlDeclaration& declaration );
	/// Visit a stylesheet reference
	virtual bool Visit( const TiXmlStylesheetReference& stylesheet );
	/// Visit a comment node
	virtual bool Visit( const TiXmlComment& comment );
	/// Visit an unknow node
	virtual bool Visit( const TiXmlUnknown& unknown );
	
	/// Visit an element.
	virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
	/// Visit an element.
	virtual bool VisitExit( const TiXmlElement& element );
	/// Visit a text node
	virtual bool Visit( const TiXmlText& text );

private:
	DocOutputDevice* m_doc;
	DocOutputPage* m_page;
	//HPDF_Doc pdf;
	//HPDF_Page page;

	float OutputTextHelper(const char* str);
	void OutputCurrentWord(const char* str);
	void CheckIfEndOfPage();
	void AddPage();
	void NewLine();

	float x, y;
	DocStyle* m_style;
	DocTemplate* m_templ;
	std::stack<int> currentStyle;
	std::stack<int> currentHeadingLevel;
	float indentLevels[32];
	int indentLevel;
	int insideCode;
	int insideLink;
};


#endif // DOC_VISITOR_H
