00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GR_UNIX_PANGOGRAPHICS_H
00022 #define GR_UNIX_PANGOGRAPHICS_H
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include "config.h"
00026 #endif
00027
00028 #include <vector>
00029
00030 #include "ut_types.h"
00031 #include "ut_string_class.h"
00032 #include "gr_RenderInfo.h"
00033
00034 #include <pango/pango-font.h>
00035
00036 #include <gtk/gtk.h>
00037 #include <gdk/gdk.h>
00038
00039 #include <X11/Xft/Xft.h>
00040
00041 #ifdef ENABLE_PRINT
00042 #include <libgnomeprint/gnome-print.h>
00043 #include <libgnomeprint/gnome-print-job.h>
00044 #endif
00045
00046
00047 #define GR_UNIXPANGO_BUILTIN
00048
00049 #ifndef GR_UNIXPANGO_BUILTIN
00050 #define PLUGIN_NAME "Pango graphics class for Unix"
00051 #endif
00052
00053
00054
00055
00056 class GR_UnixPangoRenderInfo;
00057 class GR_UnixPangoGraphics;
00058 class XAP_Frame;
00059
00060 class ABI_EXPORT GR_UnixPangoFont : public GR_Font
00061 {
00062
00063 public:
00064 GR_UnixPangoFont(const char * pDesc, double dSize,
00065 GR_UnixPangoGraphics * pG,
00066 const char * pLang,
00067 bool bGuiFont = false);
00068
00069 virtual ~GR_UnixPangoFont();
00070
00075 virtual UT_sint32 measureUnremappedCharForCache(UT_UCS4Char cChar) const;
00076 virtual bool doesGlyphExist(UT_UCS4Char g);
00077 virtual bool glyphBox(UT_UCS4Char g, UT_Rect & rec, GR_Graphics * pG);
00078 PangoFont * getPangoFont() const {return m_pf;}
00079 PangoFont * getPangoLayoutFont() const {return m_pLayoutF;}
00080
00081 void reloadFont(GR_UnixPangoGraphics * pG);
00082 double getPointSize() const {return m_dPointSize;}
00083 UT_uint32 getZoom() const {return m_iZoom;}
00084 bool isGuiFont () const {return m_bGuiFont;}
00085 const UT_String & getDescription() const {return m_sDesc;}
00086
00087 virtual const char* getFamily() const;
00088 const PangoFontDescription * getPangoDescription() const {return m_pfdLay;}
00089
00090
00091 UT_uint32 getAscent() const {return m_iAscent;}
00092 UT_uint32 getDescent() const {return m_iDescent;}
00093
00094 PangoCoverage * getPangoCoverage() const;
00095 PangoLanguage * getPangoLanguage() const {return m_pPLang;}
00096 void setLanguage(const char * pLang);
00097
00098 private:
00099 UT_String m_sDesc;
00100 UT_String m_sLayoutDesc;
00101 double m_dPointSize;
00102 UT_uint32 m_iZoom;
00103 PangoFont * m_pf;
00104 bool m_bGuiFont;
00105 mutable PangoCoverage *m_pCover;
00106 PangoFontDescription * m_pfdDev;
00107 PangoFontDescription * m_pfdLay;
00108 PangoLanguage * m_pPLang;
00109
00110 UT_uint32 m_iAscent;
00111 UT_uint32 m_iDescent;
00112 PangoFont * m_pLayoutF;
00113 };
00114
00115 class GR_UnixPangoRenderInfo;
00116
00117 class ABI_EXPORT GR_UnixAllocInfo : public GR_AllocInfo
00118 {
00119 public:
00120 GR_UnixAllocInfo(GdkWindow * win)
00121 : m_win(win),
00122 #ifdef ENABLE_PRINT
00123 m_gpm (NULL),
00124 #endif
00125 m_bPreview (false), m_bPrinter (false){};
00126
00127 #ifdef ENABLE_PRINT
00128 GR_UnixAllocInfo(GnomePrintJob * gpm, bool bPreview)
00129 : m_win(NULL), m_gpm (gpm), m_bPreview (bPreview), m_bPrinter (true){};
00130 #endif
00131 virtual GR_GraphicsId getType() const {return GRID_UNIX;}
00132 virtual bool isPrinterGraphics() const {return m_bPrinter;}
00133
00134 GdkWindow * m_win;
00135 #ifdef ENABLE_PRINT
00136 GnomePrintJob * m_gpm;
00137 #endif
00138 bool m_bPreview;
00139 bool m_bPrinter;
00140 };
00141
00142
00143 class ABI_EXPORT GR_UnixPangoGraphics : public GR_Graphics
00144 {
00145 friend class GR_UnixImage;
00146
00147
00148
00149 public:
00150 virtual ~GR_UnixPangoGraphics();
00151
00152 static UT_uint32 s_getClassId() {return GRID_UNIX_PANGO;}
00153 virtual UT_uint32 getClassId() {return s_getClassId();}
00154
00155 virtual GR_Capability getCapability() {return GRCAP_SCREEN_ONLY;}
00156 static const char * graphicsDescriptor(){return "Unix Pango";}
00157 static GR_Graphics * graphicsAllocator(GR_AllocInfo&);
00158
00159 virtual UT_sint32 measureUnRemappedChar(const UT_UCSChar c, UT_uint32 * height = 0);
00160
00161 virtual void drawChars(const UT_UCSChar* pChars,
00162 int iCharOffset, int iLength,
00163 UT_sint32 xoff, UT_sint32 yoff,
00164 int * pCharWidth);
00165
00166 virtual void drawGlyph(UT_uint32 glyph_idx,
00167 UT_sint32 xoff, UT_sint32 yoff);
00168
00169 virtual UT_uint32 measureString(const UT_UCSChar* s, int iOffset,
00170 int num, UT_GrowBufElement* pWidths, UT_uint32 * height = 0);
00171
00172 virtual GR_Font* getDefaultFont(UT_String& fontFamily,
00173 const char * pszLang);
00174
00175 virtual void setFont(const GR_Font *);
00176 virtual void clearFont(void) {m_pPFont = NULL;}
00177
00178 virtual void setZoomPercentage(UT_uint32 iZoom);
00179
00181
00182
00183 virtual bool itemize(UT_TextIterator & text, GR_Itemization & I);
00184 virtual bool shape(GR_ShapingInfo & si, GR_RenderInfo *& ri);
00185 virtual void prepareToRenderChars(GR_RenderInfo & ri);
00186 virtual void renderChars(GR_RenderInfo & ri);
00187 virtual void measureRenderedCharWidths(GR_RenderInfo & ri);
00188 virtual void appendRenderedCharsToBuff(GR_RenderInfo & ri, UT_GrowBuf & buf) const;
00189 virtual bool canBreak(GR_RenderInfo & ri, UT_sint32 &iNext, bool bAfter);
00190
00191 virtual bool needsSpecialCaretPositioning(GR_RenderInfo & ri);
00192 virtual UT_uint32 adjustCaretPosition(GR_RenderInfo & ri, bool bForward);
00193 virtual void adjustDeletePosition(GR_RenderInfo & ri);
00194 virtual bool nativeBreakInfoForRightEdge() {return false;}
00195
00196 virtual UT_sint32 resetJustification(GR_RenderInfo & ri, bool bPermanent);
00197 virtual UT_sint32 countJustificationPoints(const GR_RenderInfo & ri) const;
00198 virtual void justify(GR_RenderInfo & ri);
00199
00200 virtual UT_uint32 XYToPosition(const GR_RenderInfo & ri, UT_sint32 x, UT_sint32 y) const;
00201 virtual void positionToXY(const GR_RenderInfo & ri,
00202 UT_sint32& x, UT_sint32& y,
00203 UT_sint32& x2, UT_sint32& y2,
00204 UT_sint32& height, bool& bDirection) const;
00205 virtual UT_sint32 getTextWidth(GR_RenderInfo & ri);
00206
00207 virtual const UT_VersionInfo & getVersion() const {return s_Version;}
00208
00209 virtual void setColor(const UT_RGBColor& clr);
00210 virtual void getColor(UT_RGBColor &clr);
00211
00212 virtual GR_Font * getGUIFont(void);
00213
00214 PangoFontMap * getFontMap() const {return m_pFontMap;}
00215 PangoContext * getContext() const {return m_pContext;}
00216 PangoFontMap * getLayoutFontMap() const {return m_pLayoutFontMap;}
00217 PangoContext * getLayoutContext() const {return m_pLayoutContext;}
00218
00219 virtual UT_uint32 getFontAscent();
00220 virtual UT_uint32 getFontDescent();
00221 virtual UT_uint32 getFontHeight();
00222
00223 virtual UT_uint32 getFontAscent(const GR_Font *);
00224 virtual UT_uint32 getFontDescent(const GR_Font *);
00225 virtual UT_uint32 getFontHeight(const GR_Font *);
00226
00227 virtual void fillRect(GR_Color3D c,
00228 UT_sint32 x, UT_sint32 y,
00229 UT_sint32 w, UT_sint32 h);
00230 virtual void fillRect(GR_Color3D c, UT_Rect &r);
00231 virtual void polygon(UT_RGBColor& c,UT_Point *pts,UT_uint32 nPoints);
00232 virtual void clearArea(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00233 virtual void drawImage(GR_Image* pImg, UT_sint32 xDest, UT_sint32 yDest);
00234 virtual void xorLine(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00235 virtual void polyLine(UT_Point * pts, UT_uint32 nPoints);
00236 virtual void fillRect(const UT_RGBColor& c,
00237 UT_sint32 x, UT_sint32 y,
00238 UT_sint32 w, UT_sint32 h);
00239 virtual void invertRect(const UT_Rect* pRect);
00240 virtual void drawLine(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00241
00242 bool isDingbat(void) const {return m_bIsDingbat;}
00243 bool isSymbol(void) const {return m_bIsSymbol;};
00244
00245 virtual GR_Font* _findFont(const char* pszFontFamily,
00246 const char* pszFontStyle,
00247 const char* pszFontVariant,
00248 const char* pszFontWeight,
00249 const char* pszFontStretch,
00250 const char* pszFontSize,
00251 const char* pszLang);
00252
00253 virtual void getCoverage(UT_NumberVector& coverage);
00254 virtual void setLineWidth(UT_sint32);
00255 virtual void setClipRect(const UT_Rect* pRect);
00256 virtual UT_uint32 getDeviceResolution(void) const;
00257
00258 static const std::vector<const char *> & getAllFontNames(void);
00259 static UT_uint32 getAllFontCount();
00260 virtual GR_Font * getDefaultFont(GR_Font::FontFamilyEnum f = GR_Font::FF_Roman,
00261 const char * pszLang = NULL);
00262
00263 int dtpu(int d) const;
00264 int ptdu(int p) const;
00265 int ptlu(int p) const;
00266 int ptlunz(int p) const;
00267 int ltpu(int l) const;
00268 int ltpunz(int l) const;
00269 int pftlu(int pf) const;
00270
00271 virtual bool queryProperties(GR_Graphics::Properties gp) const;
00272 virtual GR_Image* createNewImage(const char* pszName,
00273 const UT_ByteBuf* pBB,
00274 UT_sint32 iDisplayWidth,
00275 UT_sint32 iDisplayHeight,
00276 GR_Image::GRType =GR_Image::GRT_Raster);
00277
00278 virtual bool startPrint(void);
00279 virtual bool endPrint(void);
00280 virtual bool startPage(const char * szPageLabel,
00281 UT_uint32 pageNumber,
00282 bool bPortrait,
00283 UT_uint32 iWidth, UT_uint32 iHeight);
00284
00285 virtual void setColorSpace(GR_Graphics::ColorSpace c);
00286 virtual GR_Graphics::ColorSpace getColorSpace(void) const;
00287
00288 virtual void setCursor(GR_Graphics::Cursor c);
00289 virtual GR_Graphics::Cursor getCursor(void) const;
00290
00291 virtual void setColor3D(GR_Color3D c);
00292 virtual bool getColor3D(GR_Color3D name, UT_RGBColor &color);
00293 void init3dColors(GtkStyle * pStyle);
00294
00295 void createPixmapFromXPM(char ** pXPM,GdkPixmap *source,
00296 GdkBitmap * mask);
00297
00298 virtual void scroll(UT_sint32, UT_sint32);
00299 virtual void scroll(UT_sint32 x_dest, UT_sint32 y_dest,
00300 UT_sint32 x_src, UT_sint32 y_src,
00301 UT_sint32 width, UT_sint32 height);
00302
00303 virtual void saveRectangle(UT_Rect & r, UT_uint32 iIndx);
00304 virtual void restoreRectangle(UT_uint32 iIndx);
00305 virtual GR_Image * genImageFromRectangle(const UT_Rect & r);
00306
00307 virtual void setLineProperties(double inWidth,
00308 GR_Graphics::JoinStyle inJoinStyle = JOIN_MITER,
00309 GR_Graphics::CapStyle inCapStyle = CAP_BUTT,
00310 GR_Graphics::LineStyle inLineStyle = LINE_SOLID);
00311 GdkWindow * getWindow () {return m_pWin;}
00312
00313
00314 protected:
00315
00316 GR_UnixPangoGraphics(GdkWindow * win);
00317 GR_UnixPangoGraphics();
00318 inline bool _scriptBreak(GR_UnixPangoRenderInfo &ri);
00319 virtual GdkDrawable * _getDrawable(void)
00320 { return static_cast<GdkDrawable *>(m_pWin);}
00321
00322 void _scaleCharacterMetrics(GR_UnixPangoRenderInfo & RI);
00323 void _scaleJustification(GR_UnixPangoRenderInfo & RI);
00324
00325 inline UT_uint32 _measureExtent (PangoGlyphString * pg,
00326 PangoFont * pf,
00327 UT_BidiCharType iDir,
00328 const char * pUtf8,
00329 int * & pLogOffsets,
00330 UT_sint32 & iStart,
00331 UT_sint32 & iEnd);
00332
00333 inline int * _calculateLogicalOffsets (PangoGlyphString * pGlyphs,
00334 UT_BidiCharType iVisDir,
00335 const char * pUtf8);
00336
00337 void _setIsSymbol(bool b) {m_bIsSymbol = b;}
00338 void _setIsDingbat(bool b) {m_bIsDingbat = b;}
00339
00340 void _setColor(GdkColor & c);
00341
00342 PangoFont * _adjustedPangoFont (GR_UnixPangoFont * pFont, PangoFont * pf);
00343 PangoFont * _adjustedLayoutPangoFont (GR_UnixPangoFont * pFont, PangoFont * pf);
00344
00345 protected:
00346 PangoFontMap * m_pFontMap;
00347 PangoContext * m_pContext;
00348 PangoFontMap * m_pLayoutFontMap;
00349 PangoContext * m_pLayoutContext;
00350 bool m_bOwnsFontMap;
00351 GR_UnixPangoFont* m_pPFont;
00352 GR_UnixPangoFont* m_pPFontGUI;
00353
00354 PangoFont * m_pAdjustedPangoFont;
00355 PangoFont * m_pAdjustedLayoutPangoFont;
00356 GR_UnixPangoFont* m_pAdjustedPangoFontSource;
00357 UT_uint32 m_iAdjustedPangoFontZoom;
00358
00359 UT_uint32 m_iDeviceResolution;
00360
00361 GdkWindow * m_pWin;
00362 GdkGC* m_pGC;
00363 GdkGC* m_pXORGC;
00364
00365 GdkColormap* m_pColormap;
00366 int m_iWindowHeight;
00367 int m_iWindowWidth;
00368 UT_sint32 m_iLineWidth;
00369
00370 GR_Graphics::Cursor m_cursor;
00371 GR_Graphics::ColorSpace m_cs;
00372 GdkColor m_3dColors[COUNT_3D_COLORS];
00373 Drawable m_Drawable;
00374 Visual* m_pVisual;
00375 Colormap m_Colormap;
00376
00377 UT_GenericVector<UT_Rect*> m_vSaveRect;
00378 UT_GenericVector<GdkPixbuf *> m_vSaveRectBuf;
00379
00380 XftDraw* m_pXftDraw;
00381 XftColor m_XftColor;
00382 UT_RGBColor m_curColor;
00383 UT_sint32 m_iXoff;
00384 UT_sint32 m_iYoff;
00385 bool m_bIsSymbol;
00386 bool m_bIsDingbat;
00387
00388 void init();
00389
00390 private:
00391 static UT_uint32 s_iInstanceCount;
00392 static UT_VersionInfo s_Version;
00393 static int s_iMaxScript;
00394 };
00395
00396 #ifdef ENABLE_PRINT
00397
00404 class ABI_EXPORT GR_UnixPangoPrintGraphics : public GR_UnixPangoGraphics
00405 {
00406 friend class GR_UnixPangoFont;
00407 public:
00408
00409 GR_UnixPangoPrintGraphics(GnomePrintJob *gpm, bool isPreview = false);
00410 GR_UnixPangoPrintGraphics(GnomePrintContext *ctx, double inWidthDevice,
00411 double inHeightDevice);
00412
00413 virtual ~GR_UnixPangoPrintGraphics();
00414
00415 static UT_uint32 s_getClassId() {return GRID_UNIX_PANGO_PRINT;}
00416 virtual UT_uint32 getClassId() {return s_getClassId();}
00417
00418 virtual GR_Capability getCapability() {return GRCAP_PRINTER_ONLY;}
00419 static const char * graphicsDescriptor(){return "Unix Pango Print";}
00420 static GR_Graphics * graphicsAllocator(GR_AllocInfo&);
00421
00422 GnomePrintContext * getGnomePrintContext() const;
00423 UT_sint32 scale_ydir (UT_sint32 in) const;
00424 UT_sint32 scale_xdir (UT_sint32 in) const;
00425 virtual void setColor(const UT_RGBColor& clr);
00426 virtual void getColor(UT_RGBColor& clr);
00427
00428 virtual void drawChars(const UT_UCSChar* pChars,
00429 int iCharOffset, int iLength,
00430 UT_sint32 xoff, UT_sint32 yoff,
00431 int * pCharWidths = NULL);
00432
00433 virtual bool shape(GR_ShapingInfo & si, GR_RenderInfo *& ri);
00434 virtual void renderChars(GR_RenderInfo & ri);
00435
00436 virtual void drawLine(UT_sint32 x1, UT_sint32 y1, UT_sint32 x2, UT_sint32 y2);
00437 virtual void setLineWidth(UT_sint32);
00438 virtual void setLineProperties ( double inWidthPixels,
00439 JoinStyle inJoinStyle,
00440 CapStyle inCapStyle,
00441 LineStyle inLineStyle);
00442
00443 virtual GR_Font* getGUIFont();
00444 virtual void xorLine(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00445 virtual void polyLine(UT_Point * pts, UT_uint32 nPoints);
00446 virtual void fillRect(const UT_RGBColor& c, UT_sint32 x, UT_sint32 y, UT_sint32 w, UT_sint32 h);
00447 virtual void invertRect(const UT_Rect*);
00448 virtual void setClipRect(const UT_Rect*);
00449 virtual void scroll(UT_sint32, UT_sint32);
00450 virtual void scroll(UT_sint32 x_dest, UT_sint32 y_dest,
00451 UT_sint32 x_src, UT_sint32 y_src,
00452 UT_sint32 width, UT_sint32 height);
00453 virtual void clearArea(UT_sint32, UT_sint32, UT_sint32, UT_sint32);
00454
00455 virtual void drawImage(GR_Image* pImg, UT_sint32 xDest, UT_sint32 yDest);
00456 virtual GR_Image* createNewImage(const char* pszName, const UT_ByteBuf* pBBPNG, UT_sint32 iDisplayWidth, UT_sint32 iDisplayHeight, GR_Image::GRType iType);
00457
00458 virtual bool queryProperties(GR_Graphics::Properties gp) const;
00459
00460 virtual bool startPrint(void);
00461 virtual bool startPage(const char * szPagelabel, UT_uint32 pageNumber,
00462 bool bPortrait, UT_uint32 iWidth, UT_uint32 iHeight);
00463 virtual bool endPrint(void);
00464
00465 virtual void setColorSpace(GR_Graphics::ColorSpace c);
00466 virtual GR_Graphics::ColorSpace getColorSpace(void) const;
00467
00468 virtual void setCursor(GR_Graphics::Cursor c);
00469 virtual GR_Graphics::Cursor getCursor(void) const;
00470
00471 virtual void setColor3D(GR_Color3D c);
00472 virtual UT_RGBColor * getColor3D(GR_Color3D c);
00473 virtual void fillRect(GR_Color3D c, UT_sint32 x, UT_sint32 y, UT_sint32 w, UT_sint32 h);
00474 virtual void fillRect(GR_Color3D c, UT_Rect &r);
00475 virtual void setPageSize(char* pageSizeName, UT_uint32 iwidth = 0, UT_uint32 iheight=0);
00476
00477 virtual GR_Image * genImageFromRectangle(const UT_Rect & ) { return NULL;}
00478 virtual void saveRectangle(UT_Rect & , UT_uint32 ) {}
00479 virtual void restoreRectangle(UT_uint32 ) {}
00480
00481 virtual UT_uint32 getDeviceResolution(void) const;
00482 virtual bool canQuickPrint(void)
00483 { return true;}
00484 virtual UT_uint32 getFontAscent();
00485 virtual UT_uint32 getFontDescent();
00486 virtual UT_uint32 getFontHeight();
00487
00488 virtual UT_uint32 getFontAscent(const GR_Font *);
00489 virtual UT_uint32 getFontDescent(const GR_Font *);
00490 virtual UT_uint32 getFontHeight(const GR_Font *);
00491 virtual double getResolutionRatio(void)
00492 { return _getResolutionRatio();}
00493 GnomePrintContext * getGnomePrintContext(void) { return m_gpc;}
00494
00495 static GnomePrintConfig * s_setup_config (double mrgnTop,
00496 double mrgnBottom,
00497 double mrgnLeft,
00498 double mrgnRight,
00499 double width, double height,
00500 int copies, bool portrait);
00501
00502 static void s_setup_config (GnomePrintConfig *cfg,
00503 double mrgnTop,
00504 double mrgnBottom,
00505 double mrgnLeft,
00506 double mrgnRight,
00507 double width, double height,
00508 int copies, bool portrait);
00509
00510 void setPdfWorkaround(void)
00511 { m_bPdfLandscapeWorkaround = true;}
00512
00513 protected:
00514 double _getResolutionRatio(void)
00515 {
00516 return m_dResRatio;
00517 }
00518
00519 UT_uint32 _getResolution(void) const;
00520 void _drawAnyImage (GR_Image* pImg, UT_sint32 xDest,
00521 UT_sint32 yDest, bool rgb);
00522 bool _startDocument(void);
00523 bool _startPage(const char * szPageLabel);
00524 bool _endPage(void);
00525 bool _endDocument(void);
00526
00527
00528 private:
00529 void _constructorCommon ();
00530
00531 PangoFontMap * m_pGPFontMap;
00532 PangoContext * m_pGPContext;
00533 UT_uint32 m_iScreenResolution;
00534 double m_dResRatio;
00535
00536 bool m_bIsPreview;
00537 bool m_bStartPrint;
00538 bool m_bStartPage;
00539 bool m_bNeedStroked;
00540 double m_dLineWidth;
00541
00542 GnomePrintJob *m_gpm;
00543 GnomePrintContext *m_gpc;
00544 double m_width, m_height;
00545 bool m_bPdfLandscapeWorkaround;
00546 };
00547 #endif // ifdef ENABLE_PRINT
00548
00549 #endif