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