00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef GR_UNIX_PANGOGRAPHICS_H
00023 #define GR_UNIX_PANGOGRAPHICS_H
00024
00025 #ifdef HAVE_CONFIG_H
00026 #include "config.h"
00027 #endif
00028
00029 #include <vector>
00030
00031 #include "ut_types.h"
00032 #include "ut_color.h"
00033 #include "ut_string_class.h"
00034 #include "gr_RenderInfo.h"
00035
00036 #include <cairo.h>
00037 #include <pango/pango.h>
00038
00039
00040 #define GR_UNIXPANGO_BUILTIN
00041
00042 #ifndef GR_UNIXPANGO_BUILTIN
00043 #define PLUGIN_NAME "Cairo Pango graphics"
00044 #endif
00045
00046
00047
00048
00049 class GR_PangoRenderInfo;
00050 class GR_CairoGraphics;
00051 class XAP_Frame;
00052
00053 class GR_CairoPatternImpl
00054 : public UT_ColorPatImpl
00055 {
00056 public:
00057 GR_CairoPatternImpl(const char * fileName);
00058
00059 GR_CairoPatternImpl(cairo_surface_t * surf);
00060 GR_CairoPatternImpl(const GR_CairoPatternImpl &);
00061 virtual ~GR_CairoPatternImpl();
00062 virtual UT_ColorPatImpl * clone() const;
00063 cairo_pattern_t *getPattern() const
00064 {
00065 return m_pattern;
00066 }
00067 private:
00068 GR_CairoPatternImpl & operator=(const GR_CairoPatternImpl &);
00069 cairo_pattern_t *m_pattern;
00070 };
00071
00072
00073 class GR_CairoVectorImage
00074 : public GR_VectorImage
00075 {
00076 public:
00077 virtual void cairoSetSource(cairo_t *) = 0;
00078 };
00079
00081 class GR_CairoRasterImage
00082 : public GR_RasterImage
00083 {
00084 public:
00085 virtual GR_Image * createImageSegment(GR_Graphics * pG,const UT_Rect & rec);
00086 virtual void cairoSetSource(cairo_t *) = 0;
00087 protected:
00088
00089 virtual GR_CairoRasterImage *makeSubimage(const std::string & n,
00090 UT_sint32 x, UT_sint32 y,
00091 UT_sint32 w, UT_sint32 h) const = 0;
00092 };
00093
00094 class ABI_EXPORT GR_PangoFont : public GR_Font
00095 {
00096
00097 public:
00098 GR_PangoFont(const char * pDesc, double dSize,
00099 GR_CairoGraphics * pG,
00100 const char * pLang,
00101 bool bGuiFont = false);
00102
00103 virtual ~GR_PangoFont();
00104
00109 virtual UT_sint32 measureUnremappedCharForCache(UT_UCS4Char cChar) const;
00110 virtual bool doesGlyphExist(UT_UCS4Char g) const;
00111 virtual bool glyphBox(UT_UCS4Char g, UT_Rect & rec, GR_Graphics * pG);
00112 PangoFont * getPangoFont() const {return m_pf;}
00113 PangoFont * getPangoLayoutFont() const {return m_pLayoutF;}
00114
00115 void reloadFont(GR_CairoGraphics * pG);
00116 double getPointSize() const {return m_dPointSize;}
00117 UT_uint32 getZoom() const {return m_iZoom;}
00118 bool isGuiFont () const {return m_bGuiFont;}
00119 const UT_String & getDescription() const {return m_sDesc;}
00120
00121 virtual const char* getFamily() const;
00122 const PangoFontDescription * getPangoDescription() const {return m_pfdLay;}
00123
00124
00125 UT_uint32 getAscent() const {return m_iAscent;}
00126 UT_uint32 getDescent() const {return m_iDescent;}
00127
00128 PangoCoverage * getPangoCoverage() const;
00129 PangoLanguage * getPangoLanguage() const {return m_pPLang;}
00130 void setLanguage(const char * pLang);
00131 private:
00132 UT_String m_sDesc;
00133 UT_String m_sLayoutDesc;
00134 double m_dPointSize;
00135 UT_uint32 m_iZoom;
00136 PangoFont * m_pf;
00137 bool m_bGuiFont;
00138 mutable PangoCoverage *m_pCover;
00139 PangoFontDescription * m_pfdDev;
00140 PangoFontDescription * m_pfdLay;
00141 PangoLanguage * m_pPLang;
00142
00143 UT_uint32 m_iAscent;
00144 UT_uint32 m_iDescent;
00145 PangoFont * m_pLayoutF;
00146 };
00147
00148 class GR_PangoRenderInfo;
00149
00150
00151 class ABI_EXPORT GR_CairoAllocInfo
00152 : public GR_AllocInfo
00153 {
00154 public:
00155 GR_CairoAllocInfo(bool bPreview, bool bPrinter, bool double_buffered)
00156 : m_bPreview(bPreview),
00157 m_bPrinter(bPrinter),
00158 m_double_buffered(double_buffered)
00159 {
00160 }
00161 virtual GR_GraphicsId getType() const {return GRID_UNIX;}
00162 virtual bool isPrinterGraphics() const {return m_bPrinter;}
00163 virtual cairo_t *createCairo() = 0;
00164
00165 bool m_bPreview;
00166 bool m_bPrinter;
00167 bool m_double_buffered;
00168 };
00169
00170
00171 class ABI_EXPORT GR_CairoGraphics : public GR_Graphics
00172 {
00173 friend class GR_UnixImage;
00174
00175
00176
00177 public:
00178 virtual ~GR_CairoGraphics();
00179
00180 virtual GR_Capability getCapability() {return GRCAP_SCREEN_ONLY;}
00181
00182 virtual UT_sint32 measureUnRemappedChar(const UT_UCSChar c, UT_uint32 * height = 0);
00183
00184 virtual void drawChars(const UT_UCSChar* pChars,
00185 int iCharOffset, int iLength,
00186 UT_sint32 xoff, UT_sint32 yoff,
00187 int * pCharWidth);
00188
00189 virtual void drawGlyph(UT_uint32 glyph_idx,
00190 UT_sint32 xoff, UT_sint32 yoff);
00191
00192 virtual UT_uint32 measureString(const UT_UCSChar* s, int iOffset,
00193 int num, UT_GrowBufElement* pWidths, UT_uint32 * height = 0);
00194
00195 virtual GR_Font* getDefaultFont(UT_String& fontFamily,
00196 const char * pszLang);
00197
00198 virtual void setFont(const GR_Font *);
00199 virtual void clearFont(void) {m_pPFont = NULL;}
00200
00201 virtual void setZoomPercentage(UT_uint32 iZoom);
00202
00204
00205
00206 virtual bool itemize(UT_TextIterator & text, GR_Itemization & I);
00207 virtual bool shape(GR_ShapingInfo & si, GR_RenderInfo *& ri);
00208 virtual void prepareToRenderChars(GR_RenderInfo & ri);
00209 virtual void renderChars(GR_RenderInfo & ri);
00210 virtual void measureRenderedCharWidths(GR_RenderInfo & ri);
00211 virtual void appendRenderedCharsToBuff(GR_RenderInfo & ri, UT_GrowBuf & buf) const;
00212 virtual bool canBreak(GR_RenderInfo & ri, UT_sint32 &iNext, bool bAfter);
00213
00214 virtual bool needsSpecialCaretPositioning(GR_RenderInfo & ri);
00215 virtual UT_uint32 adjustCaretPosition(GR_RenderInfo & ri, bool bForward);
00216 virtual void adjustDeletePosition(GR_RenderInfo & ri);
00217 virtual bool nativeBreakInfoForRightEdge() {return false;}
00218
00219 virtual UT_sint32 resetJustification(GR_RenderInfo & ri, bool bPermanent);
00220 virtual UT_sint32 countJustificationPoints(const GR_RenderInfo & ri) const;
00221 virtual void justify(GR_RenderInfo & ri);
00222
00223 virtual UT_uint32 XYToPosition(const GR_RenderInfo & ri, UT_sint32 x, UT_sint32 y) const;
00224 virtual void positionToXY(const GR_RenderInfo & ri,
00225 UT_sint32& x, UT_sint32& y,
00226 UT_sint32& x2, UT_sint32& y2,
00227 UT_sint32& height, bool& bDirection) const;
00228 virtual UT_sint32 getTextWidth(GR_RenderInfo & ri);
00229
00230 virtual const UT_VersionInfo & getVersion() const {return s_Version;}
00231
00232 virtual void setColor(const UT_RGBColor& clr);
00233 virtual void getColor(UT_RGBColor &clr);
00234
00235 PangoFontMap * getFontMap() const {return m_pFontMap;}
00236 PangoContext * getContext() const {return m_pContext;}
00237 PangoFontMap * getLayoutFontMap() const {return m_pLayoutFontMap;}
00238 PangoContext * getLayoutContext() const {return m_pLayoutContext;}
00239
00240 virtual UT_uint32 getFontAscent();
00241 virtual UT_uint32 getFontDescent();
00242 virtual UT_uint32 getFontHeight();
00243
00244 virtual UT_uint32 getFontAscent(const GR_Font *);
00245 virtual UT_uint32 getFontDescent(const GR_Font *);
00246 virtual UT_uint32 getFontHeight(const GR_Font *);
00247
00248 virtual void fillRect(GR_Color3D c,
00249 UT_sint32 x, UT_sint32 y,
00250 UT_sint32 w, UT_sint32 h);
00251 virtual void fillRect(GR_Color3D c, UT_Rect &r);
00252 virtual void polygon(UT_RGBColor& c,UT_Point *pts,UT_uint32 nPoints);
00253 virtual void clearArea(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00254 virtual void drawImage(GR_Image* pImg, UT_sint32 xDest, UT_sint32 yDest);
00255 virtual void xorLine(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00256 virtual void polyLine(UT_Point * pts, UT_uint32 nPoints);
00257 virtual void fillRect(const UT_RGBColor& c,
00258 UT_sint32 x, UT_sint32 y,
00259 UT_sint32 w, UT_sint32 h);
00260 virtual void invertRect(const UT_Rect* pRect);
00261 virtual void drawLine(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00262
00263 bool isDingbat(void) const {return m_bIsDingbat;}
00264 bool isSymbol(void) const {return m_bIsSymbol;};
00265
00266 void resetFontMapResolution(void);
00267
00268 virtual GR_Font* _findFont(const char* pszFontFamily,
00269 const char* pszFontStyle,
00270 const char* pszFontVariant,
00271 const char* pszFontWeight,
00272 const char* pszFontStretch,
00273 const char* pszFontSize,
00274 const char* pszLang);
00275
00276 virtual void getCoverage(UT_NumberVector& coverage);
00277 virtual void setLineWidth(UT_sint32);
00278 virtual void setClipRect(const UT_Rect* pRect);
00279 virtual UT_uint32 getDeviceResolution(void) const;
00280 double getResolutionRatio(void) const { return 1.0;}
00281
00282 static const std::vector<std::string> & getAllFontNames(void);
00283 static UT_uint32 getAllFontCount();
00284 virtual GR_Font * getDefaultFont(GR_Font::FontFamilyEnum f = GR_Font::FF_Roman,
00285 const char * pszLang = NULL);
00286
00287 int dtpu(int d) const;
00288 int ptdu(int p) const;
00289 int ptlu(int p) const;
00290 int ptlunz(int p) const;
00291 int ltpu(int l) const;
00292 int ltpunz(int l) const;
00293 int pftlu(int pf) const;
00294
00295 virtual bool queryProperties(GR_Graphics::Properties gp) const;
00296
00297
00298
00299
00300
00301
00302 virtual bool startPrint(void);
00303 virtual bool endPrint(void);
00304 virtual bool startPage(const char * szPageLabel,
00305 UT_uint32 pageNumber,
00306 bool bPortrait,
00307 UT_uint32 iWidth, UT_uint32 iHeight);
00308
00309 virtual void setColorSpace(GR_Graphics::ColorSpace c);
00310 virtual GR_Graphics::ColorSpace getColorSpace(void) const;
00311
00312
00313 virtual GR_Graphics::Cursor getCursor(void) const;
00314
00315 virtual void setColor3D(GR_Color3D c);
00316 virtual bool getColor3D(GR_Color3D name, UT_RGBColor &color);
00317
00318
00319
00320
00321
00322
00323 virtual void saveRectangle(UT_Rect & r, UT_uint32 iIndx);
00324 virtual void restoreRectangle(UT_uint32 iIndx);
00325
00326
00327 virtual void setLineProperties(double inWidth,
00328 GR_Graphics::JoinStyle inJoinStyle = JOIN_MITER,
00329 GR_Graphics::CapStyle inCapStyle = CAP_BUTT,
00330 GR_Graphics::LineStyle inLineStyle = LINE_SOLID);
00331 cairo_t* getCairo ();
00332 void setCairo(cairo_t *cr);
00333
00334 static UT_uint32 getDefaultDeviceResolution();
00335
00336 protected:
00337
00338 void _setProps();
00339 virtual void _resetClip(void);
00340
00341
00342 static cairo_surface_t * _getCairoSurfaceFromContext(cairo_t *cr,
00343 const cairo_rectangle_t & rect);
00344 static void _setSource(cairo_t *, const UT_RGBColor &);
00345
00346
00347 GR_CairoGraphics(cairo_t *cr, UT_uint32 iDeviceResolution);
00348 GR_CairoGraphics();
00349 inline bool _scriptBreak(GR_PangoRenderInfo &ri);
00350
00351 void _scaleCharacterMetrics(GR_PangoRenderInfo & RI);
00352 void _scaleJustification(GR_PangoRenderInfo & RI);
00353
00354 inline UT_uint32 _measureExtent (PangoGlyphString * pg,
00355 PangoFont * pf,
00356 UT_BidiCharType iDir,
00357 const char * pUtf8,
00358 int * & pLogOffsets,
00359 UT_sint32 & iStart,
00360 UT_sint32 & iEnd);
00361
00362 inline int * _calculateLogicalOffsets (PangoGlyphString * pGlyphs,
00363 UT_BidiCharType iVisDir,
00364 const char * pUtf8);
00365
00366 void _setIsSymbol(bool b) {m_bIsSymbol = b;}
00367 void _setIsDingbat(bool b) {m_bIsDingbat = b;}
00368
00369 PangoFont * _adjustedPangoFont (GR_PangoFont * pFont, PangoFont * pf);
00370 PangoFont * _adjustedLayoutPangoFont (GR_PangoFont * pFont, PangoFont * pf);
00371
00372 double _tdudX(UT_sint32 layoutUnits) const;
00373 double _tdudY(UT_sint32 layoutUnits) const;
00374
00375 PangoFontMap * m_pFontMap;
00376 PangoContext * m_pContext;
00377 PangoFontMap * m_pLayoutFontMap;
00378 PangoContext * m_pLayoutContext;
00379 GR_PangoFont* m_pPFont;
00380 GR_PangoFont* m_pPFontGUI;
00381
00382
00383 PangoFont * m_pAdjustedPangoFont;
00384 PangoFontDescription* m_pAdjustedPangoFontDescription;
00385 UT_sint32 m_iAdjustedPangoFontSize;
00386
00387
00388 PangoFont * m_pAdjustedLayoutPangoFont;
00389 PangoFontDescription* m_pAdjustedLayoutPangoFontDescription;
00390 UT_sint32 m_iAdjustedLayoutPangoFontSize;
00391
00392 UT_uint32 m_iDeviceResolution;
00393
00394 cairo_t * m_cr;
00395
00396 GR_Graphics::Cursor m_cursor;
00397 GR_Graphics::ColorSpace m_cs;
00398
00399 UT_RGBColor m_3dColors[COUNT_3D_COLORS];
00400
00401 UT_RGBColor m_curColor;
00402 bool m_curColorDirty;
00403 bool m_clipRectDirty;
00404 double m_lineWidth;
00405 GR_Graphics::JoinStyle m_joinStyle;
00406 GR_Graphics::CapStyle m_capStyle;
00407 GR_Graphics::LineStyle m_lineStyle;
00408 bool m_linePropsDirty;
00409 bool m_bIsSymbol;
00410 bool m_bIsDingbat;
00411 UT_sint32 m_iPrevX1;
00412 UT_sint32 m_iPrevX2;
00413 UT_sint32 m_iPrevY1;
00414 UT_sint32 m_iPrevY2;
00415 UT_uint32 m_iPrevRect;
00416 UT_sint32 m_iXORCount;
00417
00419 void _initCairo();
00420
00421
00422 void _DeviceContext_SwitchToBuffer();
00423 void _DeviceContext_SwitchToScreen();
00424
00425
00426 void _DeviceContext_SuspendDrawing();
00427 void _DeviceContext_ResumeDrawing();
00428
00429
00430 std::vector<UT_Rect*> m_vSaveRect;
00431 std::vector<cairo_surface_t*> m_vSaveRectBuf;
00432
00433 private:
00434 static UT_uint32 s_iInstanceCount;
00435 static UT_VersionInfo s_Version;
00436 static int s_iMaxScript;
00438 void _initPango();
00439 };
00440
00441
00442 #endif