/*  
	BeOS Front-end du PDF file reader xpdf.
    Copyright (C) 1997 Benoit Triquet
    Copyright (C) 1998 Hubert Figuiere
	Copyright (C) 2000 Michael Pfeiffer

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//
// Be OutputDev : device for BeOS output
//
//
//
// (c) Hubert Figuiere
//



#ifndef _BE_OUTPUT_DEV_
#define _BE_OUTPUT_DEV_

#include "OutputDev.h"

#include <interface/Region.h>
#include <interface/Font.h>

#include "BeFontEncoding.h"
#include "BeOutputFont.h"

class GString;
class GfxState;
class GfxColorSpace;
class GfxImageColorMap;
class Stream;
class GfxSubpath;
class TextPage;
class PDFView;

extern GBool useEUCJP;

class BeOutputDev
	: public OutputDev
{
public:
	// Constructor.
	BeOutputDev(BView * view, PDFView *parent);

	// Destructor.
virtual ~BeOutputDev();

	//----- get info about output device

	// Does this device use upside-down coordinates?
	// (Upside-down means (0,0) is the top left corner of the page.)
virtual GBool upsideDown();

	// Does this device use drawChar() or drawString()?
virtual GBool useDrawChar();

	//----- initialization and control

	// Set default transform matrix.
/*
virtual void setDefaultCTM(double *ctm1) {};
*/
	void startDoc();
	// Start a page.
virtual void startPage(int pageNum, GfxState *state);

	// End a page.
virtual void endPage();

	// Dump page contents to display.
virtual void dump();

	//----- coordinate conversion

	// Convert between device and user coordinates.
/*
virtual void cvtDevToUser(int dx, int dy, double *ux, double *uy);
virtual void cvtUserToDev(double ux, double uy, int *dx, int *dy);
*/
	//----- link borders
virtual void drawLinkBorder(double x1, double y1, double x2, double y2,
							double w);

	//----- save/restore graphics state
virtual void saveState(GfxState *state);
virtual void restoreState(GfxState *state);

	//----- update graphics state
virtual void updateAll(GfxState *state);
virtual void updateCTM(GfxState *state, double m11, double m12,
			 double m21, double m22, double m31, double m32); //
virtual void updateLineDash(GfxState *state); //
virtual void updateFlatness(GfxState *state);
virtual void updateLineJoin(GfxState *state); //
virtual void updateLineCap(GfxState *state); //
virtual void updateMiterLimit(GfxState *state); //
virtual void updateLineWidth(GfxState *state);
virtual void updateFillColor(GfxState *state);
virtual void updateStrokeColor(GfxState *state);

	//----- update text state
virtual void updateFont(GfxState *state);
virtual void updateTextMat(GfxState *state) {};
virtual void updateCharSpace(GfxState *state) {};
virtual void updateRender(GfxState *state) {};
virtual void updateRise(GfxState *state) {};
virtual void updateWordSpace(GfxState *state) {};
virtual void updateHorizScaling(GfxState *state) {};
virtual void updateTextPos(GfxState *state) {};
virtual void updateTextShift(GfxState *state, double shift) {};

	//----- path painting
virtual void stroke(GfxState *state);
virtual void fill(GfxState *state);
virtual void eoFill(GfxState *state);

	//----- path clipping
virtual void clip(GfxState *state);
virtual void eoClip(GfxState *state);

	//----- text drawing
virtual void beginString(GfxState *state, GString *s);
virtual void endString(GfxState *state);
virtual void drawChar(GfxState *state, double x, double y,
			double dx, double dy, Guchar c);
virtual void drawChar16(GfxState *state, double x, double y,
                        double dx, double dy, int c);
virtual void drawString(GfxState *state, GString *s) {};

	//----- image drawing
virtual void drawImageMask(GfxState *state, Stream *str,
			     int width, int height, GBool invert,
			     GBool inlineImg);
virtual void drawImage(GfxState *state, Stream *str, int width,
			 int height, GfxImageColorMap *colorMap,
			 GBool inlineImg);
			 
	// Find a string.  If <top> is true, starts looking at <xMin>,<yMin>;
	// otherwise starts looking at top of page.  If <bottom> is true,
	// stops looking at <xMax>,<yMax>; otherwise stops looking at bottom
	// of page.  If found, sets the text bounding rectange and returns
	// true; otherwise returns false.
	GBool findText(char *s, GBool top, GBool bottom,
		int *xMin, int *yMin, int *xMax, int *yMax);

	// Get the text which is inside the specified rectangle.
	GString *getText(int xMin, int yMin, int xMax, int yMax);

private:
	// uint8 mKludgedEncoding;
	
	class _State {
	public:
		_State()
			{ next = NULL; };
		_State *next;
		BRegion clip;
		rgb_color low, high;
	};

	GfxFont *gfxFont;		// current PDF font
	BeOutputFont *font;		// current font
	BeOutputFontCache *fontCache;	// font cache
	
	BView * mView;
	_State * mState;
	int mFlatness;
	BFont mFont;
	BRegion * mClip;
	rgb_color mFill, mStroke;
	PDFView *mParent;
	TextPage *mText;
	
	void AddSubPathToPoly (GfxState *state, /*const*/ GfxSubpath * subPath, 
							BPolygon * poly);
	void SubPathToShape (GfxState *state, /*const*/ GfxSubpath * subPath, 
						BShape * shape);
	void SubPathToStrokeBezier (GfxState *state, GfxSubpath * subPath, 
								BView * view);

};


#endif
