00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef GR_COCOAGRAPHICS_H
00024 #define GR_COCOAGRAPHICS_H
00025
00026 #import <Cocoa/Cocoa.h>
00027
00028 #include "xap_CocoaApp.h"
00029 #include "xap_Frame.h"
00030 #include "gr_Graphics.h"
00031
00032 class UT_ByteBuf;
00033
00034 class GR_CocoaGraphics;
00035
00036 class XAP_CocoaFont;
00037
00038 class StNSViewLocker;
00039
00040 @class XAP_CocoaNSView;
00041
00042 class GR_CocoaAllocInfo : public GR_AllocInfo
00043 {
00044 public:
00045 GR_CocoaAllocInfo(XAP_CocoaNSView * v)
00046 : GR_AllocInfo(),
00047 m_view(v)
00048 {
00049 }
00050
00051 virtual GR_GraphicsId getType() const {return GRID_COCOA;}
00052 virtual bool isPrinterGraphics() const { return false; }
00053
00054 XAP_CocoaNSView *m_view;
00055 };
00056
00057 class GR_CocoaGraphics : public GR_Graphics
00058 {
00059
00060
00061 public:
00062 ~GR_CocoaGraphics();
00063
00064
00065 static UT_uint32 s_getClassId() {return GRID_COCOA;}
00066 virtual UT_uint32 getClassId() {return s_getClassId();}
00067
00068 virtual GR_Capability getCapability(){UT_ASSERT(UT_NOT_IMPLEMENTED); return GRCAP_UNKNOWN;}
00069
00070 static const char * graphicsDescriptor(void){return "Cocoa Default";}
00071 static GR_Graphics * graphicsAllocator(GR_AllocInfo&);
00072
00073
00074 virtual void drawGlyph(UT_uint32 , UT_sint32 , UT_sint32 )
00075 { UT_ASSERT (UT_NOT_IMPLEMENTED); };
00076 virtual void drawChars(const UT_UCSChar* pChars, int iCharOffset,
00077 int iLength, UT_sint32 xoff, UT_sint32 yoff,
00078 int * pCharWidhths = NULL);
00079
00080 virtual void setFont(const GR_Font* pFont);
00081 virtual void clearFont(void) { m_pFont = NULL;}
00082 virtual UT_uint32 getFontHeight();
00083
00084 virtual UT_sint32 measureUnRemappedChar(const UT_UCSChar c, UT_uint32 * height = NULL);
00085 virtual void getCoverage(UT_NumberVector& coverage);
00086
00087 virtual void setColor(const UT_RGBColor& clr);
00088 virtual void getColor(UT_RGBColor& clr);
00089
00090
00091 static NSColor * HBlue()
00092 {
00093 return m_colorBlue16x15;
00094 }
00095 static NSColor * VBlue()
00096 {
00097 return m_colorBlue11x16;
00098 }
00099 static NSColor * HGrey()
00100 {
00101 return m_colorGrey16x15;
00102 }
00103 static NSColor * VGrey()
00104 {
00105 return m_colorGrey11x16;
00106 }
00107
00108 virtual GR_Font* getGUIFont();
00109
00110 virtual UT_uint32 getFontAscent();
00111 virtual UT_uint32 getFontDescent();
00112 virtual void drawLine(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00113 virtual void setLineWidth(UT_sint32);
00114 virtual void polyLine(UT_Point * pts, UT_uint32 nPoints);
00115 void rawPolyAtOffset(NSPoint * point, int npoint, UT_sint32 offset_x, UT_sint32 offset_y, NSColor * color, bool bFill);
00116 void fillNSRect (NSRect & aRect, NSColor * color);
00117 virtual void fillRect(const UT_RGBColor& c,
00118 UT_sint32 x, UT_sint32 y,
00119 UT_sint32 w, UT_sint32 h);
00120 virtual void invertRect(const UT_Rect* pRect);
00121 virtual void setClipRect(const UT_Rect* pRect);
00122 virtual void scroll(UT_sint32, UT_sint32);
00123 virtual void scroll(UT_sint32 x_dest, UT_sint32 y_dest,
00124 UT_sint32 x_src, UT_sint32 y_src,
00125 UT_sint32 width, UT_sint32 height);
00126 virtual void clearArea(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00127
00128 virtual void drawImage(GR_Image* pImg, UT_sint32 xDest, UT_sint32 yDest);
00129 virtual GR_Image* createNewImage(const char* pszName, const UT_ByteBuf* pBB,
00130 UT_sint32 iDisplayWidth, UT_sint32 iDisplayHeight,
00131 GR_Image::GRType = GR_Image::GRT_Raster);
00132
00133 virtual void setLineProperties ( double inWidthPixels,
00134 JoinStyle inJoinStyle,
00135 CapStyle inCapStyle,
00136 LineStyle inLineStyle);
00137
00138 virtual bool queryProperties(GR_Graphics::Properties gp) const;
00139 virtual bool startPrint(void);
00140 virtual bool startPage(const char * szPageLabel, UT_uint32 pageNumber,
00141 bool bPortrait, UT_uint32 iWidth, UT_uint32 iHeight);
00142 virtual void setZoomPercentage(UT_uint32 iZoom);
00143 virtual bool endPrint(void);
00144
00145 virtual void flush(void);
00146
00147 virtual void setColorSpace(GR_Graphics::ColorSpace c);
00148 virtual GR_Graphics::ColorSpace getColorSpace(void) const;
00149
00150 virtual void setCursor(GR_Graphics::Cursor c);
00151 virtual GR_Graphics::Cursor getCursor(void) const;
00152
00153 void setGrabCursor(GR_Graphics::Cursor c) { m_GrabCursor = c; }
00154
00155 virtual void setColor3D(GR_Color3D c);
00156 void init3dColors();
00157 virtual void fillRect(GR_Color3D c,
00158 UT_sint32 x, UT_sint32 y,
00159 UT_sint32 w, UT_sint32 h);
00160 virtual void fillRect(GR_Color3D c, UT_Rect &r);
00161
00162 virtual void polygon(UT_RGBColor& c,UT_Point *pts,UT_uint32 nPoints);
00163
00164
00165 virtual UT_uint32 getFontAscent(const GR_Font *);
00166 virtual UT_uint32 getFontDescent(const GR_Font *);
00167 virtual UT_uint32 getFontHeight(const GR_Font *);
00168
00169 virtual GR_Image * genImageFromRectangle(const UT_Rect & r);
00170 virtual void saveRectangle(UT_Rect & r, UT_uint32 iIndx);
00171 virtual void restoreRectangle(UT_uint32 iIndx);
00172 virtual UT_uint32 getDeviceResolution(void) const;
00173
00174
00175 typedef bool (*gr_cocoa_graphics_update) (NSRect * rect, GR_CocoaGraphics *pGr, void * param);
00176 void _setUpdateCallback (gr_cocoa_graphics_update callback, void * param);
00177 bool _callUpdateCallback(NSRect *aRect);
00178 XAP_CocoaNSView * _getView () { return m_pWin; };
00179
00180 static bool _isFlipped();
00181 static NSColor *_utRGBColorToNSColor (const UT_RGBColor& clr);
00182 static void _utNSColorToRGBColor (NSColor *c, UT_RGBColor &clr);
00183 void setIsPrinting(bool _isPrinting) { m_bIsPrinting = _isPrinting; };
00184 bool isPrinting(void) const { return m_bIsPrinting; };
00185
00186 static float _getScreenResolution(void);
00187
00188 protected:
00189
00190 GR_CocoaGraphics(XAP_CocoaNSView * view);
00191 virtual GR_Font* _findFont(const char* pszFontFamily,
00192 const char* pszFontStyle,
00193 const char* pszFontVariant,
00194 const char* pszFontWeight,
00195 const char* pszFontStretch,
00196 const char* pszFontSize,
00197 const char* pszLang);
00198
00199 virtual UT_uint32 _getResolution(void) const;
00200 void _setColor(NSColor * c);
00201 virtual void _beginPaint (void);
00202 virtual void _endPaint (void);
00203 private:
00204 void _setClipRectImpl(const UT_Rect* pRect);
00205
00206
00207 NSImage* _makeNewCacheImage()
00208 {
00209 NSImage * cache = [[NSImage alloc] initWithSize:NSMakeSize(0,0)];
00210 [cache setFlipped:YES];
00211 return cache;
00212 }
00213
00214 void _resetContext(CGContextRef context);
00215
00216 gr_cocoa_graphics_update m_updateCallback;
00217 void *m_updateCBparam;
00218 XAP_CocoaNSView * m_pWin;
00219 ATSUStyle m_atsuStyle;
00220 CGContextRef m_CGContext;
00221 UT_GenericVector<id> m_cacheArray;
00222 UT_GenericVector<NSRect*> m_cacheRectArray;
00223 NSColor * m_currentColor;
00224
00225 static void _initColorAndImage(void);
00226 static bool m_colorAndImageInited;
00227 static NSImage * m_imageBlue16x15;
00228 static NSImage * m_imageBlue11x16;
00229 static NSImage * m_imageGrey16x15;
00230 static NSImage * m_imageGrey11x16;
00231 static NSColor * m_colorBlue16x15;
00232 static NSColor * m_colorBlue11x16;
00233 static NSColor * m_colorGrey16x15;
00234 static NSColor * m_colorGrey11x16;
00235
00236 static NSCursor * m_Cursor_E;
00237 static NSCursor * m_Cursor_N;
00238 static NSCursor * m_Cursor_NE;
00239 static NSCursor * m_Cursor_NW;
00240 static NSCursor * m_Cursor_S;
00241 static NSCursor * m_Cursor_SE;
00242 static NSCursor * m_Cursor_SW;
00243 static NSCursor * m_Cursor_W;
00244
00245 static NSCursor * m_Cursor_Wait;
00246 static NSCursor * m_Cursor_LeftArrow;
00247 static NSCursor * m_Cursor_RightArrow;
00248 static NSCursor * m_Cursor_Compass;
00249 static NSCursor * m_Cursor_Exchange;
00250 static NSCursor * m_Cursor_LeftRight;
00251 static NSCursor * m_Cursor_UpDown;
00252 static NSCursor * m_Cursor_Crosshair;
00253 static NSCursor * m_Cursor_HandPointer;
00254 static NSCursor * m_Cursor_DownArrow;
00255
00256
00257 XAP_CocoaFont * m_pFont;
00258 NSFont* m_fontForGraphics;
00259
00260 XAP_CocoaFont* m_pFontGUI;
00261 static UT_uint32 s_iInstanceCount;
00262
00263 float m_fLineWidth;
00264
00265 JoinStyle m_joinStyle;
00266 CapStyle m_capStyle;
00267 LineStyle m_lineStyle;
00268
00269 GR_Graphics::Cursor m_cursor;
00270 GR_Graphics::Cursor m_GrabCursor;
00271
00272 GR_Graphics::ColorSpace m_cs;
00273
00274 UT_uint32 m_screenResolution;
00275 bool m_bIsPrinting;
00276 bool m_bIsDrawing;
00277
00278 public:
00279 NSColor * m_3dColors[COUNT_3D_COLORS];
00280 private:
00281
00282 float _measureUnRemappedCharCached(const UT_UCSChar c);
00283 void _setCapStyle(CapStyle inCapStyle, CGContextRef * context = 0);
00284 void _setJoinStyle(JoinStyle inJoinStyle, CGContextRef * context = 0);
00285 void _setLineStyle (LineStyle inLineStyle, CGContextRef * context = 0);
00286 void _restartPaint(void);
00287
00299 void _realDrawChars(ATSUTextLayout atsuLayout,
00300 float x, float y, int begin, int rangelen,
00301 float xOffset);
00302
00303 StNSViewLocker* m_viewLocker;
00304 };
00305
00306 #endif