[Fwd: CVS: commit msevior abi/src/af/gr/unix gr_UnixPangoGraphics.cpp gr_UnixPangoGraphics.h]

From: <msevior_at_physics.unimelb.edu.au>
Date: Wed Apr 25 2007 - 09:48:16 CEST

---------------------------- Original Message ----------------------------
Subject: CVS: commit msevior abi/src/af/gr/unix gr_UnixPangoGraphics.cpp
gr_UnixPangoGraphics.h
From: cvs@abisource.com
Date: Wed, April 25, 2007 17:44
To: abisource-cvs-commit@abisource.com
--------------------------------------------------------------------------

Update of /cvsroot/abi/src/af/gr/unix
In directory abiword.snt.utwente.nl:/tmp/cvs-serv24819/src/af/gr/unix

Modified Files:
        gr_UnixPangoGraphics.cpp gr_UnixPangoGraphics.h
Log Message:

New graphics class GR_UnixPangoPixmapGraphics. This can be used to draw
into offscreen buffers. Useful for presentations where we can turn pages
and various graphics elements into images which can be animated.

Index: gr_UnixPangoGraphics.h
===================================================================
RCS file: /cvsroot/abi/src/af/gr/unix/gr_UnixPangoGraphics.h,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- gr_UnixPangoGraphics.h 3 Apr 2007 13:30:00 -0000 1.48
+++ gr_UnixPangoGraphics.h 25 Apr 2007 07:44:25 -0000 1.49
@@ -131,6 +131,19 @@
         bool m_bPrinter;
 };

+
+class GR_UnixPixmapAllocInfo : public GR_AllocInfo
+{
+public:
+ GR_UnixPixmapAllocInfo(GdkPixmap * pix)
+ : m_pix(pix){}
+ virtual GR_GraphicsId getType() const {return GRID_UNIX_PANGO_PIXMAP;}
+ virtual bool isPrinterGraphics() const {return false;}
+
+ GdkPixmap * m_pix;
+};
+
+
 class ABI_EXPORT GR_UnixPangoGraphics : public GR_Graphics
 {
         friend class GR_UnixImage;
@@ -302,8 +315,9 @@
         // all instances have to be created via GR_GraphicsFactory; see
gr_Graphics.h
         GR_UnixPangoGraphics(GdkWindow * win);
         GR_UnixPangoGraphics();
-
         inline bool _scriptBreak(GR_UnixPangoRenderInfo &ri);
+ virtual GdkDrawable * _getDrawable(void)
+ { return static_cast<GdkDrawable *>(m_pWin);}

         void _scaleCharacterMetrics(GR_UnixPangoRenderInfo & RI);
         void _scaleJustification(GR_UnixPangoRenderInfo & RI);
@@ -375,6 +389,35 @@
         static int s_iMaxScript;
 };

+//
+// Class to draw into offscreen Pixbuf
+//
+class ABI_EXPORT GR_UnixPangoPixmapGraphics : public GR_UnixPangoGraphics
+{
+ friend class GR_UnixImage;
+public:
+ virtual ~GR_UnixPangoPixmapGraphics();
+
+ static UT_uint32 s_getClassId() {return GRID_UNIX_PANGO_PIXMAP;}
+ virtual UT_uint32 getClassId() {return s_getClassId();}
+ static const char * graphicsDescriptor(){return "Unix Pango Pixmap";}
+ static GR_Graphics * graphicsAllocator(GR_AllocInfo&);
+ virtual void scroll(UT_sint32, UT_sint32) {};
+ virtual void scroll(UT_sint32 x_dest, UT_sint32 y_dest,
+ UT_sint32 x_src, UT_sint32 y_src,
+ UT_sint32 width, UT_sint32 height) {};
+
+ virtual void setCursor(GR_Graphics::Cursor c){};
+ virtual GR_Graphics::Cursor getCursor(void) const;
+ virtual bool queryProperties(GR_Graphics::Properties gp) const;
+
+protected:
+ GR_UnixPangoPixmapGraphics(GdkPixmap * pix);
+ virtual GdkDrawable * _getDrawable(void)
+ { return static_cast<GdkDrawable *>(m_pPixmap);}
+ GdkPixmap * m_pPixmap;
+ virtual void init();
+};

 #ifndef WITHOUT_PRINTING

Index: gr_UnixPangoGraphics.cpp
===================================================================
RCS file: /cvsroot/abi/src/af/gr/unix/gr_UnixPangoGraphics.cpp,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- gr_UnixPangoGraphics.cpp 3 Apr 2007 13:30:00 -0000 1.83
+++ gr_UnixPangoGraphics.cpp 25 Apr 2007 07:44:25 -0000 1.84
@@ -320,17 +320,26 @@
         GdkDisplay * gDisplay = NULL;
         GdkScreen * gScreen = NULL;

- if (m_pWin)
+ if (_getDrawable())
         {
                 m_pColormap = gdk_rgb_get_colormap();
                 m_Colormap = GDK_COLORMAP_XCOLORMAP(m_pColormap);

- gDisplay = gdk_drawable_get_display(m_pWin);
- gScreen = gdk_drawable_get_screen(m_pWin);
+ gDisplay = gdk_drawable_get_display(_getDrawable());
+ gScreen = gdk_drawable_get_screen(_getDrawable());

                 GdkDrawable * realDraw;
- gdk_window_get_internal_paint_info (m_pWin, &realDraw,
+ if(GDK_IS_WINDOW((_getDrawable())))
+ {
+ gdk_window_get_internal_paint_info (_getDrawable(), &realDraw,
                                                                                         &m_iXoff, &m_iYoff);
+ }
+ else
+ {
+ realDraw = _getDrawable();
+ m_iXoff = 0;
+ m_iYoff = 0;
+ }

                 //
                 // Martin's attempt to make double buffering work.with xft
@@ -686,7 +695,7 @@
                                                                                    GdkBitmap * mask)
 {
         source
- = gdk_pixmap_colormap_create_from_xpm_d(m_pWin,NULL,
+ = gdk_pixmap_colormap_create_from_xpm_d(_getDrawable(),NULL,
                                                         &mask, NULL,
                                                         pXPM);
 }
@@ -729,7 +738,7 @@
                                                   UT_sint32 width, UT_sint32 height)
 {
         GR_CaretDisabler caretDisabler(getCaret());
- gdk_draw_drawable(m_pWin, m_pGC, m_pWin, tdu(x_src), tdu(y_src),
+ gdk_draw_drawable(_getDrawable(), m_pGC, _getDrawable(), tdu(x_src),
tdu(y_src),
                                      tdu(x_dest), tdu(y_dest), tdu(width), tdu(height));
 }

@@ -2163,7 +2172,7 @@
         UT_sint32 idh = _tduR(r.height);

         GdkPixbuf * pix = gdk_pixbuf_get_from_drawable(NULL,
- m_pWin,
+ _getDrawable(),
                                                                                                    NULL,
                                                                                                    idx, idy, 0, 0,
                                                                                                    idw, idh);
@@ -2182,7 +2191,7 @@

         if (p && r)
- gdk_draw_pixbuf (m_pWin, NULL, p, 0, 0,
+ gdk_draw_pixbuf (_getDrawable(), NULL, p, 0, 0,
                                                  idx, idy,
                                                  -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
 }
@@ -2199,7 +2208,7 @@
         UT_return_val_if_fail (idw > 0 && idh > 0 && idx >= 0 && idy >= 0, NULL);
         GdkColormap* cmp = gdk_colormap_get_system();
         GdkPixbuf * pix = gdk_pixbuf_get_from_drawable(NULL,
- m_pWin,
+ _getDrawable(),
                                                                                                    cmp,
                                                                                                    idx, idy, 0, 0,
                                                                                                    idw, idh);
@@ -2256,13 +2265,13 @@
         xDest = idx; yDest = idy;

         if (gdk_pixbuf_get_has_alpha (image))
- gdk_draw_pixbuf (m_pWin, NULL, image,
+ gdk_draw_pixbuf (_getDrawable(), NULL, image,
                                                  0, 0, xDest, yDest,
                                                  iImageWidth, iImageHeight,
                                                  GDK_RGB_DITHER_NORMAL,
                                                  0, 0);
         else
- gdk_draw_pixbuf (m_pWin, m_pGC, image,
+ gdk_draw_pixbuf (_getDrawable(), m_pGC, image,
                                                  0, 0, xDest, yDest,
                                                  iImageWidth, iImageHeight,
                                                  GDK_RGB_DITHER_NORMAL,
@@ -2801,7 +2810,7 @@
         UT_sint32 idy1 = _tduY(y1);
         UT_sint32 idy2 = _tduY(y2);

- gdk_draw_line(m_pWin, m_pGC, idx1, idy1, idx2, idy2);
+ gdk_draw_line(_getDrawable(), m_pGC, idx1, idy1, idx2, idy2);
 }

 void GR_UnixPangoGraphics::setLineWidth(UT_sint32 iLineWidth)
@@ -2907,7 +2916,7 @@
         UT_sint32 idy1 = _tduY(y1);
         UT_sint32 idy2 = _tduY(y2);

- gdk_draw_line(m_pWin, m_pXORGC, idx1, idy1, idx2, idy2);
+ gdk_draw_line(_getDrawable(), m_pXORGC, idx1, idy1, idx2, idy2);
 }

 void GR_UnixPangoGraphics::polyLine(UT_Point * pts, UT_uint32 nPoints)
@@ -2932,7 +2941,7 @@
                 points[i].y = idy1 - 1;
         }

- gdk_draw_lines(m_pWin, m_pGC, points, nPoints);
+ gdk_draw_lines(_getDrawable(), m_pGC, points, nPoints);

         FREEP(points);
 }
@@ -2946,7 +2955,7 @@
         UT_sint32 idw = _tduR(pRect->width);
         UT_sint32 idh = _tduR(pRect->height);

- gdk_draw_rectangle(m_pWin, m_pXORGC, 1, idx, idy,
+ gdk_draw_rectangle(_getDrawable(), m_pXORGC, 1, idx, idy,
                            idw, idh);
 }

@@ -3008,7 +3017,7 @@
         UT_sint32 idy = _tduY(y);
         UT_sint32 idw = _tduR(w);
         UT_sint32 idh = _tduR(h);
- gdk_draw_rectangle(m_pWin, m_pGC, 1, idx, idy, idw, idh);
+ gdk_draw_rectangle(_getDrawable(), m_pGC, 1, idx, idy, idw, idh);

         gdk_gc_set_foreground(m_pGC, &oColor);
 }
@@ -3107,7 +3116,7 @@
 {
         UT_ASSERT(c < COUNT_3D_COLORS);
         gdk_gc_set_foreground(m_pGC, &m_3dColors[c]);
- gdk_draw_rectangle(m_pWin, m_pGC, 1, tdu(x), tdu(y), tdu(w), tdu(h));
+ gdk_draw_rectangle(_getDrawable(), m_pGC, 1, tdu(x), tdu(y), tdu(w),
tdu(h));
 }

 void GR_UnixPangoGraphics::polygon(UT_RGBColor& c, UT_Point *pts,
@@ -3143,7 +3152,7 @@
                 UT_sint32 idy = _tduY(pts[i].y);
         points[i].y = idy;
     }
- gdk_draw_polygon(m_pWin, m_pGC, 1, points, nPoints);
+ gdk_draw_polygon(_getDrawable(), m_pGC, 1, points, nPoints);
         delete[] points;

         gdk_gc_set_foreground(m_pGC, &oColor);
@@ -4222,6 +4231,191 @@

 #endif

+
+/*!
+ * The GR_UnixPangoPixmapGraphics is used to draw onto an offscreen
+ * buffer.
+ */
+
+GR_UnixPangoPixmapGraphics::GR_UnixPangoPixmapGraphics(GdkPixmap * pix):
+ GR_UnixPangoGraphics(),
+ m_pPixmap(pix)
+{
+ init();
+}
+
+GR_UnixPangoPixmapGraphics::~GR_UnixPangoPixmapGraphics(void)
+{
+ gdk_pixmap_unref (m_pPixmap);
+}
+
+GR_Graphics *
GR_UnixPangoPixmapGraphics::graphicsAllocator(GR_AllocInfo& info)
+{
+ UT_return_val_if_fail(info.getType() == GRID_UNIX_PANGO_PIXMAP,NULL);
+ xxx_UT_DEBUGMSG(("GR_UnixPangoPixmapGraphics::graphicsAllocator\n"));
+
+ GR_UnixPixmapAllocInfo &AI = (GR_UnixPixmapAllocInfo&)info;
+
+ return new GR_UnixPangoPixmapGraphics(AI.m_pix);
+}
+
+
+void GR_UnixPangoPixmapGraphics::init(void)
+{
+ UT_DEBUGMSG(("Initializing UnixPangoPixmapGraphics %x \n",this));
+ GdkDisplay * gDisplay = NULL;
+ GdkScreen * gScreen = NULL;
+ UT_return_if_fail(_getDrawable());
+
+ m_pColormap = gdk_rgb_get_colormap();
+ m_Colormap = GDK_COLORMAP_XCOLORMAP(m_pColormap);
+
+ gDisplay = gdk_drawable_get_display(_getDrawable());
+ gScreen = gdk_drawable_get_screen(_getDrawable());
+
+ if(!gDisplay)
+ gDisplay = gdk_display_get_default();
+ if(!gScreen)
+ gScreen = gdk_screen_get_default();
+
+ GdkDrawable * realDraw;
+ realDraw = _getDrawable();
+ m_iXoff = 0;
+ m_iYoff = 0;
+ //
+ // Martin's attempt to make double buffering work.with xft
+ //
+ m_pGC = gdk_gc_new(realDraw);
+ m_pXORGC = gdk_gc_new(realDraw);
+ m_pVisual = GDK_VISUAL_XVISUAL( gdk_drawable_get_visual(realDraw));
+ m_Drawable = gdk_x11_drawable_get_xid(realDraw);
+
+ m_pXftDraw = XftDrawCreate(GDK_DISPLAY(), m_Drawable,
+ m_pVisual, m_Colormap);
+
+ gdk_gc_set_function(m_pXORGC, GDK_XOR);
+
+ GdkColor clrWhite;
+ clrWhite.red = clrWhite.green = clrWhite.blue = 65535;
+ gdk_colormap_alloc_color (m_pColormap, &clrWhite, FALSE, TRUE);
+ gdk_gc_set_foreground(m_pXORGC, &clrWhite);
+
+ GdkColor clrBlack;
+ clrBlack.red = clrBlack.green = clrBlack.blue = 0;
+ gdk_colormap_alloc_color (m_pColormap, &clrBlack, FALSE, TRUE);
+ gdk_gc_set_foreground(m_pGC, &clrBlack);
+
+ m_XftColor.color.red = clrBlack.red;
+ m_XftColor.color.green = clrBlack.green;
+ m_XftColor.color.blue = clrBlack.blue;
+ m_XftColor.color.alpha = 0xffff;
+ m_XftColor.pixel = clrBlack.pixel;
+
+ // I only want to set CAP_NOT_LAST, but the call takes all
+ // arguments (and doesn't have a default value). Set the
+ // line attributes to not draw the last pixel.
+
+ // We force the line width to be zero because the CAP_NOT_LAST
+ // stuff does not seem to work correctly when the width is set
+ // to one.
+
+ gdk_gc_set_line_attributes(m_pGC, 0,
+ GDK_LINE_SOLID,
+ GDK_CAP_NOT_LAST,
+ GDK_JOIN_MITER);
+
+ gdk_gc_set_line_attributes(m_pXORGC, 0,
+ GDK_LINE_SOLID,
+ GDK_CAP_NOT_LAST,
+ GDK_JOIN_MITER);
+
+ // Set GraphicsExposes so that XCopyArea() causes an expose on
+ // obscured regions rather than just tiling in the default background.
+ gdk_gc_set_exposures(m_pGC, 1);
+ gdk_gc_set_exposures(m_pXORGC, 1);
+
+ m_cs = GR_Graphics::GR_COLORSPACE_COLOR;
+ m_cursor = GR_CURSOR_INVALID;
+ setCursor(GR_CURSOR_DEFAULT);
+
+ m_bIsSymbol = false;
+ m_bIsDingbat = false;
+
+ bool bGotResolution = false;
+
+ if (gScreen && gDisplay)
+ {
+ int iScreen = gdk_x11_screen_get_screen_number(gScreen);
+ Display * disp = GDK_DISPLAY_XDISPLAY(gDisplay);
+ UT_DEBUGMSG(("PangoPixmap init gScreen %x gDisplay %x Screen %d
Display %x \n",gScreen,gDisplay,iScreen,disp));
+ m_pContext = pango_xft_get_context(disp, iScreen);
+ m_pFontMap = pango_xft_get_font_map(disp, iScreen);
+
+ FcPattern *pattern = FcPatternCreate();
+ if (pattern)
+ {
+ double dpi;
+ XftDefaultSubstitute (GDK_SCREEN_XDISPLAY (gScreen),
+ iScreen,
+ pattern);
+
+ if(FcResultMatch == FcPatternGetDouble (pattern,
+ FC_DPI, 0, &dpi))
+ {
+ m_iDeviceResolution = (UT_uint32)round(dpi);
+ bGotResolution = true;
+ }
+
+ FcPatternDestroy (pattern);
+ }
+
+ if (!bGotResolution)
+ {
+ // that didn't work. try getting it from the screen
+ m_iDeviceResolution =
+ (UT_uint32)round((gdk_screen_get_width(gScreen) * 25.4) /
+ gdk_screen_get_width_mm (gScreen));
+ }
+
+ UT_DEBUGMSG(("@@@@@@@@@@@@@ retrieved DPI %d @@@@@@@@@@@@@@@@@ \n",
+ m_iDeviceResolution));
+
+ }
+#ifdef HAVE_PANGOFT2
+ else
+ {
+ m_iDeviceResolution = 72;
+ m_pFontMap = pango_ft2_font_map_new ();
+ pango_ft2_font_map_set_resolution(reinterpret_cast<PangoFT2FontMap*>(m_pFontMap),
+ m_iDeviceResolution,
+ m_iDeviceResolution);
+ m_pContext =
pango_ft2_font_map_create_context(reinterpret_cast<PangoFT2FontMap*>(m_pFontMap));
+ m_bOwnsFontMap = true;
+ }
+#endif
+}
+
+bool GR_UnixPangoPixmapGraphics::queryProperties(GR_Graphics::Properties
gp) const
+{
+ switch (gp)
+ {
+ case DGP_SCREEN:
+ return false;
+ case DGP_OPAQUEOVERLAY:
+ return true;
+ case DGP_PAPER:
+ return true;
+ default:
+ UT_ASSERT(0);
+ return false;
+ }
+}
+
+GR_Graphics::Cursor GR_UnixPangoPixmapGraphics::getCursor(void) const
+{
+ return GR_CURSOR_DEFAULT;
+}
+
 static const UT_uint32 adobeDUni[/*202*/][2] =
         {
                 {0x0020,0x0020},

-----------------------------------------------
To unsubscribe from this list, send a message to
abisource-cvs-commit-request@abisource.com with the word
unsubscribe in the message body.
Received on Wed Apr 25 09:47:37 2007

This archive was generated by hypermail 2.1.8 : Wed Apr 25 2007 - 09:47:37 CEST