00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GR_WIN32GRAPHICS_H
00021 #define GR_WIN32GRAPHICS_H
00022
00023 #include <windows.h>
00024 #include "ut_misc.h"
00025 #include "gr_Graphics.h"
00026 #include "gr_Win32CharWidths.h"
00027 #include "ut_vector.h"
00028
00029 class UT_ByteBuf;
00030
00031 #define _MAX_CACHE_PENS 64
00032
00035
00036 class ABI_EXPORT GR_Win32Font : public GR_Font
00037 {
00038 public:
00039 static GR_Win32Font * newFont(LOGFONT & lf, double fPoints, HDC hdc, HDC printDC);
00040 virtual ~GR_Win32Font();
00041
00042
00043 void setAscent(UT_uint32 n) { m_tm.tmAscent = n; }
00044 void setDescent(UT_uint32 n) { m_tm.tmDescent = n; }
00045 void setHeight(UT_uint32 n) { m_tm.tmHeight = n; }
00046
00047 UT_uint32 getAscent(HDC hdc, HDC printHDC);
00048 UT_uint32 getDescent(HDC hdc, HDC printHDC);
00049 UT_uint32 getHeight(HDC hdc, HDC printHDC);
00050 UT_uint32 getUnscaledHeight() const { return m_iHeight;}
00051
00052 HFONT getDisplayFont(GR_Graphics * pGr);
00053
00054 virtual UT_sint32 measureUnremappedCharForCache(UT_UCSChar cChar) const;
00055 UT_sint32 measureUnRemappedChar(UT_UCSChar c, UT_uint32 * height = 0);
00056 virtual GR_CharWidths* newFontWidths(void) const;
00057
00058
00059
00060
00061
00062
00063
00064 virtual bool glyphBox(UT_UCS4Char g, UT_Rect & rec, GR_Graphics * pG);
00065
00066 void selectFontIntoDC(GR_Graphics * pGr, HDC hdc);
00067
00068 void markGUIFont() {m_bGUIFont = true;}
00069 bool isFontGUI() const {return m_bGUIFont;}
00070
00071 const HDC getPrimaryHDC() const {return m_hdc;}
00072 const HDC getXHDC() const {return m_xhdc;}
00073 const HDC getYHDC() const {return m_yhdc;}
00074
00075 void setPrimaryHDC(const HDC hdc) {m_hdc = hdc;}
00076 void setXHDC(const HDC hdc) {m_xhdc = hdc;}
00077 void setYHDC(const HDC hdc) {m_yhdc = hdc;}
00078
00079
00080
00081
00082
00083
00084
00085
00086 HFONT getFontHandle() const {return m_layoutFont;}
00087 double getPointSize() const {return m_fPointSize;}
00088
00089 protected:
00090
00091 GR_Win32Font(LOGFONT & lf, double fPoints, HDC hdc, HDC printHDC);
00092
00093 GR_Win32CharWidths * _getCharWidths() const
00094 {
00095 #ifndef ABI_GRAPHICS_PLUGIN_NO_WIDTHS
00096 return reinterpret_cast<GR_Win32CharWidths *>(GR_Font::_getCharWidths());
00097 #else
00098 UT_return_val_if_fail(UT_NOT_IMPLEMENTED,NULL);
00099 #endif
00100 }
00101
00102
00103
00104
00105 virtual void _clearAnyCachedInfo() {};
00106 void _updateFontYMetrics(HDC hdc, HDC printHDC);
00107
00108
00109 public:
00110 HFONT getFontFromCache(UT_uint32 pixelsize, bool bIsLayout,
00111 UT_uint32 zoomPercentage) const;
00112
00113 void fetchFont(UT_uint32 pixelsize) const;
00114
00115 const TEXTMETRIC & getTextMetric() const {return m_tm;}
00116
00117 private:
00118
00119 struct allocFont
00120 {
00121 UT_uint32 pixelSize;
00122 HFONT hFont;
00123 };
00124
00125 void insertFontInCache(UT_uint32 pixelsize, HFONT pFont) const;
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 HDC m_hdc;
00136 HDC m_xhdc;
00137 HDC m_yhdc;
00138
00139 UT_uint32 m_defaultCharWidth;
00140 HFONT m_layoutFont;
00141 TEXTMETRIC m_tm;
00142 UT_uint32 m_iHeight;
00143
00144
00145 mutable UT_Vector m_allocFonts;
00146 bool m_bGUIFont;
00147 double m_fPointSize;
00148 };
00149
00152
00153 class ABI_EXPORT GR_Win32AllocInfo : public GR_AllocInfo
00154 {
00155 public:
00156 GR_Win32AllocInfo():
00157 m_hdc(0), m_hwnd(0), m_pDocInfo(NULL), m_hDevMode(NULL) {};
00158
00159 GR_Win32AllocInfo(HDC hdc, HWND hwnd):
00160 m_hdc(hdc), m_hwnd(hwnd), m_pDocInfo(NULL), m_hDevMode(NULL) {};
00161
00162 GR_Win32AllocInfo(HDC hdc, const DOCINFO* pDoc, HGLOBAL devmode):
00163 m_hdc(hdc), m_hwnd(0), m_pDocInfo(pDoc), m_hDevMode(devmode) {};
00164
00165 virtual GR_GraphicsId getType() const {return GRID_WIN32;}
00166 virtual bool isPrinterGraphics() const {return (m_pDocInfo != 0);}
00167
00168 HDC m_hdc;
00169 HWND m_hwnd;
00170 const DOCINFO * m_pDocInfo;
00171 HGLOBAL m_hDevMode;
00172 };
00173
00174
00175 class ABI_EXPORT GR_Win32Graphics : public GR_Graphics
00176 {
00177
00178
00179 public:
00180 virtual ~GR_Win32Graphics();
00181
00182 static UT_uint32 s_getClassId() {return GRID_WIN32;}
00183 virtual UT_uint32 getClassId() {return s_getClassId();}
00184
00185 virtual GR_Capability getCapability() {return GRCAP_SCREEN_AND_PRINTER;}
00186
00187 static const char * graphicsDescriptor(){return "Win32 Default";}
00188 static GR_Graphics * graphicsAllocator(GR_AllocInfo&);
00189
00190 static GR_Graphics * getPrinterGraphics(const char * pPrinterName,
00191 const char * pDocName);
00192
00193 virtual void drawGlyph(UT_uint32 glyph_idx, UT_sint32 xoff, UT_sint32 yoff);
00194 virtual void drawChar(UT_UCSChar Char, UT_sint32 xoff, UT_sint32 yoff);
00195 virtual void drawChars(const UT_UCSChar* pChars,
00196 int iCharOffset, int iLength,
00197 UT_sint32 xoff, UT_sint32 yoff,
00198 int * pCharWidth);
00199 virtual void setFont(const GR_Font* pFont);
00200 virtual void clearFont(void) { m_pFont = NULL;}
00201 virtual UT_uint32 getFontHeight();
00202 virtual UT_sint32 measureUnRemappedChar(const UT_UCSChar c, UT_uint32 * height = 0);
00203 virtual void setColor(const UT_RGBColor& clr);
00204 virtual void getColor(UT_RGBColor& clr);
00205 virtual GR_Font* getGUIFont();
00206
00207 virtual UT_uint32 getFontAscent();
00208 virtual UT_uint32 getFontDescent();
00209 virtual void getCoverage(UT_NumberVector& coverage);
00210 virtual void drawLine(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00211 virtual void xorLine(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00212 virtual void setLineWidth(UT_sint32);
00213
00214 virtual void setLineProperties ( double inWidthPixels,
00215 JoinStyle inJoinStyle = JOIN_MITER,
00216 CapStyle inCapStyle = CAP_BUTT,
00217 LineStyle inLineStyle = LINE_SOLID );
00218
00219 virtual void polyLine(UT_Point * pts, UT_uint32 nPoints);
00220 virtual void fillRect(const UT_RGBColor& c,
00221 UT_sint32 x, UT_sint32 y,
00222 UT_sint32 w, UT_sint32 h);
00223 virtual void invertRect(const UT_Rect* pRect);
00224 virtual void setClipRect(const UT_Rect* pRect);
00225 virtual void scroll(UT_sint32 dx, UT_sint32 dy);
00226 virtual void scroll(UT_sint32 x_dest, UT_sint32 y_dest,
00227 UT_sint32 x_src, UT_sint32 y_src,
00228 UT_sint32 width, UT_sint32 height);
00229 virtual void clearArea(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00230
00231 virtual void drawImage(GR_Image* pImg, UT_sint32 xDest, UT_sint32 yDest);
00232 virtual GR_Image* createNewImage(const char* pszName, const UT_ByteBuf* pBB,
00233 UT_sint32 iDisplayWidth, UT_sint32 iDisplayHeight, GR_Image::GRType iType = GR_Image::GRT_Raster);
00234
00235 virtual bool queryProperties(GR_Graphics::Properties gp) const;
00236
00237 virtual bool startPrint(void);
00238 virtual bool startPage(const char * szPageLabel, UT_uint32 pageNumber,
00239 bool bPortrait, UT_uint32 iWidth, UT_uint32 iHeight);
00240 virtual bool endPrint(void);
00241
00242 virtual HWND getHwnd(void) const;
00243
00244 virtual void setColorSpace(GR_Graphics::ColorSpace c);
00245 virtual GR_Graphics::ColorSpace getColorSpace(void) const;
00246
00247 virtual void setCursor(GR_Graphics::Cursor c);
00248 virtual GR_Graphics::Cursor getCursor(void) const;
00249 virtual void handleSetCursorMessage(void);
00250
00251 virtual void setColor3D(GR_Color3D c);
00252 void init3dColors(void);
00253 virtual void fillRect(GR_Color3D c,
00254 UT_sint32 x, UT_sint32 y,
00255 UT_sint32 w, UT_sint32 h);
00256 virtual void fillRect(GR_Color3D c, UT_Rect &r);
00257 virtual void polygon(UT_RGBColor& c,UT_Point *pts,UT_uint32 nPoints);
00258 virtual UT_uint32 getFontAscent(const GR_Font *);
00259 virtual UT_uint32 getFontDescent(const GR_Font *);
00260 virtual UT_uint32 getFontHeight(const GR_Font *);
00261
00262 virtual GR_Image * genImageFromRectangle(const UT_Rect & r);
00263 virtual void saveRectangle(UT_Rect & r, UT_uint32 iIndx);
00264 virtual void restoreRectangle(UT_uint32 iIndx);
00265 virtual void flush(void);
00266 void setBrush(HBRUSH hBrush){ m_hClearBrush = hBrush;};
00267
00268
00269 virtual void setPrintDC(HDC dc);
00270 HDC getPrintDC() const {return m_printHDC;}
00271 HDC getPrimaryDC() const {return m_hdc;}
00272
00273 void setPrintDCFontAllocNo(UT_uint32 i){m_iPrintDCFontAllocNo = i;}
00274 void setDCFontAllocNo(UT_uint32 i){m_iDCFontAllocNo = i;}
00275
00276 double getXYRatio() const {return m_fXYRatio;}
00277 double getXYRatioPrint() const {return m_fXYRatioPrint;}
00278
00279 static bool fixDevMode(HGLOBAL hModDev);
00280
00281 static DOCINFO *getDocInfo();
00282 static HDC createbestmetafilehdc();
00283
00284 protected:
00285
00286 GR_Win32Graphics(HDC, HWND);
00287 GR_Win32Graphics(HDC, const DOCINFO *, HGLOBAL hDevMode = NULL);
00288
00289 BITMAPINFO * ConvertDDBToDIB(HBITMAP bitmap, HPALETTE hPal, DWORD dwCompression);
00290
00291 virtual GR_Font* _findFont(const char* pszFontFamily,
00292 const char* pszFontStyle,
00293 const char* pszFontVariant,
00294 const char* pszFontWeight,
00295 const char* pszFontStretch,
00296 const char* pszFontSize,
00297 const char* pszLang);
00298
00299 virtual UT_uint32 getDeviceResolution(void) const;
00300 void _setColor(DWORD clrRef);
00301
00302 private:
00303 virtual GR_Win32Font * _newFont(LOGFONT & lf, double fPointSize, HDC hdc, HDC printDC);
00304
00305 protected:
00306
00307 UT_uint32 m_iDCFontAllocNo;
00308 UT_uint32 m_iPrintDCFontAllocNo;
00309 HDC m_hdc;
00310 HDC m_printHDC;
00311 static HDC m_defPrintHDC;
00312 static UT_uint32 s_iInstanceCount;
00313 HWND m_hwnd;
00314 const DOCINFO * m_pDocInfo;
00315 bool m_bPrint;
00316 bool m_bStartPrint;
00317 bool m_bStartPage;
00318 GR_Win32Font* m_pFont;
00319 GR_Win32Font* m_pFontGUI;
00320 UT_sint32 m_iLineWidth;
00321 JoinStyle m_eJoinStyle;
00322 CapStyle m_eCapStyle;
00323 LineStyle m_eLineStyle;
00324
00325 GR_Graphics::ColorSpace m_cs;
00326 GR_Graphics::Cursor m_cursor;
00327
00328 DWORD m_clrCurrent;
00329 DWORD m_3dColors[COUNT_3D_COLORS];
00330 int m_nPrintLogPixelsY;
00331 double m_fXYRatio;
00332 double m_fXYRatioPrint;
00333
00334
00335 private:
00336 void _constructorCommonCode(HDC);
00337 UT_uint16* _remapGlyphs(const UT_UCSChar* pChars, int iCharOffset, int &iLength);
00338 virtual bool _setTransform(const GR_Transform & tr);
00339
00340 DWORD m_clrXorPen;
00341 HPEN m_hXorPen;
00342
00343 UT_UCS2Char* m_remapBuffer;
00344 UT_uint32 m_remapBufferSize;
00345 UT_UCS2Char* m_remapIndices;
00346
00347 UT_RGBColor m_curColor;
00348 UT_Vector m_vSaveRect;
00349 UT_Vector m_vSaveRectBuf;
00350 HBRUSH m_hClearBrush;
00351 int m_nLogPixelsY;
00352 HGLOBAL m_hDevMode;
00353
00354 typedef struct
00355 {
00356 HPEN hPen;
00357 int nStyle;
00358 int nWidth;
00359 DWORD dwColour;
00360
00361 } CACHE_PEN;
00362
00363 CACHE_PEN* m_pArPens;
00364 int m_nArPenPos;
00365 bool m_bIsPreview;
00366 };
00367
00368 #endif