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