• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

gr_Graphics.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 /* AbiWord
00003  * Copyright (C) 1998 AbiSource, Inc.
00004  * Copyright (C) 2002 Tomas Frydrych, <tomas@frydrych.uklinux.net>
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019  * 02111-1307, USA.
00020  */
00021 
00022 #ifndef GR_GRAPHICS_H
00023 #define GR_GRAPHICS_H
00024 
00025 #include "xap_Features.h"
00026 
00027 #include "ut_types.h"
00028 #include "ut_units.h"
00029 #include "ut_growbuf.h"
00030 #include "ut_misc.h"
00031 #include "gr_Image.h"
00032 #include "gr_Caret.h"
00033 #include "gr_Transform.h"
00034 #include "gr_CharWidthsCache.h"
00035 #include "ut_hash.h"
00036 #include "ut_vector.h"
00037 #include "ut_stack.h"
00038 #include "ut_TextIterator.h"
00039 
00040 #ifdef ABI_GRAPHICS_PLUGIN
00041 #define VIRTUAL_SFX = 0
00042 #else
00043 #define VIRTUAL_SFX
00044 #endif
00045 
00046 class UT_RGBColor;
00047 class XAP_PrefsScheme;
00048 class XAP_Frame;
00049 class UT_String;
00050 class GR_RenderInfo;
00051 class GR_Itemization;
00052 class GR_ShapingInfo;
00053 
00054 
00069 class GR_Graphics;
00070 class GR_Painter;
00071 class GR_Caret;
00072 
00073 typedef enum {
00074     GR_FONT_UNSET=0,
00075     GR_FONT_UNIX,
00076     GR_FONT_UNIX_PANGO,
00077     GR_FONT_WIN32,
00078     GR_FONT_WIN32_USP
00079 } GrFontType;
00080 
00081 class ABI_EXPORT GR_Font
00082 {
00083     friend class GR_Graphics;
00084     friend class UT_GenericStringMap<GR_Font*>;
00085 
00086  public:
00087     // want the destructor public so that the derrived graphics classes can delete font
00088     // objects without having to be declared here as friends
00089     virtual ~GR_Font();
00090 
00091 
00092     typedef enum { FF_Unknown = 0, FF_Roman, FF_Swiss, FF_Modern,
00093                    FF_Script, FF_Decorative, FF_Technical, FF_BiDi, FF_Last } FontFamilyEnum;
00094     typedef enum { FP_Unknown = 0, FP_Fixed, FP_Variable } FontPitchEnum;
00095 
00096     // The following is actually implemented in platform code.
00097     // It is primarily used to characterize fonts for RTF export.
00098     static void s_getGenericFontProperties(const char * szFontName,
00099                                            FontFamilyEnum * pff,
00100                                            FontPitchEnum * pfp,
00101                                            bool * pbTrueType);
00102 
00103     virtual const char* getFamily() const { return NULL; }
00104     UT_uint32           getAllocNumber() const {return m_iAllocNo;}
00109     virtual UT_sint32 measureUnremappedCharForCache(UT_UCSChar cChar) const = 0;
00110     virtual const UT_String & hashKey(void) const;
00111     UT_sint32 getCharWidthFromCache (UT_UCSChar c) const;
00112 
00113     /*reimplement if you want to instanciate something else */
00114     virtual GR_CharWidths* newFontWidths(void) const;
00115     /*
00116        implemented using character widths; platforms might want to
00117        provide different implementation
00118        NB: it is essential that this function is fast
00119     */
00120     virtual bool doesGlyphExist(UT_UCS4Char g) const;
00121 //
00122 // UT_Rect of glyph in Logical units.
00123 // rec.left = bearing Left (distance from origin to start)
00124 // rec.width = width of the glyph
00125 // rec.top = distance from the origin to the top of the glyph
00126 // rec.height = total height of the glyph
00127 
00128     virtual bool glyphBox(UT_UCS4Char g, UT_Rect & rec, GR_Graphics * pG) = 0;
00129     static  bool s_doesGlyphExist(UT_UCS4Char g, void *instance)
00130     {
00131         UT_return_val_if_fail(instance, false);
00132         GR_Font * pThis = static_cast<GR_Font*>(instance);
00133         return pThis->doesGlyphExist(g);
00134     }
00135 
00136     GrFontType getType()const {return m_eType;}
00137 
00138   protected:
00139 
00140     GR_Font();
00141 
00142     GR_CharWidths * _getCharWidths() const {return m_pCharWidths;}
00147     mutable UT_String       m_hashKey;
00148 
00149     GrFontType               m_eType;
00150 
00151 private:
00152 
00153     static UT_uint32 s_iAllocCount;
00154     UT_uint32        m_iAllocNo;
00155     mutable GR_CharWidths*  m_pCharWidths;
00156 };
00157 
00158 
00159 /*
00160     GR_GraphicsId defines IDs returned by GR_Graphics::getClassId()
00161     used to identify the class in communication with GR_GraphicsFactory.
00162 
00163     There are three types of IDs: default, built-in and plugin.
00164 
00165     Default IDs are not assigned permanently to any class and are used
00166     by the factory to allocate default graphics. These IDs are
00167     reallocable -- if the factory receives a request to register a
00168     class under one of these IDs, it will automatically unregister any
00169     class currently registered under that ID.
00170 
00171     Built-in IDs are permanently assinged to specific derrived
00172     classes. The factory will refuse to register a class under one of
00173     these IDs if another class is already registered with it.
00174 
00175     Plugin IDs are dynamically generated for a graphics class by the
00176     factory. The main draw-back of plugin IDs is that they cannot be
00177     stored in preference profiles. A plugin desinger might prefer to
00178     request a fixed ID from the built-in range (we could use UUIDs to
00179     identify graphics, but that seems an overkill).
00180  */
00181 enum GR_GraphicsId
00182 {
00183     /* default id's */
00184     /* these id's can be reregistered at will */
00185     GRID_DEFAULT         =  0x0,
00186     GRID_DEFAULT_PRINT   =  0x1,
00187 
00188     GRID_LAST_DEFAULT    =  0xff,
00189 
00190     /* IDs for built-in classes: DO NOT CHANGE THE ASSIGNED VALUES !!!*/
00191     /* (these classes cannot be unregistered) */
00192     GRID_COCOA           =  0x102,
00193     GRID_WIN32           =  0x104,
00194     GRID_UNIX            =  0x105,
00195     GRID_UNIX_PS         =  0x106,
00196     GRID_CAIRO_NULL      =  0x107,
00197 
00198     /*add new built-in ids here*/
00199 
00200     GRID_LAST_BUILT_IN = 0x200,
00201 
00202     /* IDs for extension classes (can be both built-in and plugins) */
00203     /* (these classes can be unregistered by explicit call to
00204        unregisterClass()) */
00205     GRID_UNIX_PANGO      =  0x201,
00206     GRID_WIN32_UNISCRIBE =  0x202,
00207     GRID_UNIX_PANGO_PRINT = 0x203,
00208     GRID_UNIX_PANGO_PIXMAP = 0x204,
00209         GRID_COCOA_PANGO     = 0x205,
00210 
00211     GRID_LAST_EXTENSION = 0x0000ffff,
00212 
00213     /* id's for plugins will be auto-generatoed from between here */
00214 
00215     GRID_UNKNOWN = 0xffffffff
00216 };
00217 
00218 // or-able graphics type
00219 enum GR_Capability
00220 {
00221     GRCAP_UNKNOWN            = 0,
00222     GRCAP_SCREEN_ONLY        = 1,
00223     GRCAP_PRINTER_ONLY       = 2,
00224     GRCAP_SCREEN_AND_PRINTER = 3
00225 };
00226 
00270 class ABI_EXPORT GR_AllocInfo
00271 {
00272   public:
00273     virtual ~GR_AllocInfo() {}
00274 
00275     virtual GR_GraphicsId getType() const {UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); return GRID_UNKNOWN;}
00276     virtual bool isPrinterGraphics()const {UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); return false;}
00277 };
00278 
00279 typedef GR_Graphics * (*GR_Allocator)(GR_AllocInfo&);
00280 typedef const char *  (*GR_Descriptor)(void);
00281 /*
00282    The purpose of GR_GraphicsFactory is to allow us to have parallel
00283    graphics implementations. For example, on win32 we could have a
00284    graphics class using Uniscribe, graphics class without shaping
00285    support and graphics class using SIL Graphite. The user then could
00286    specify through preferences which shaping engine s/he wishes to
00287    use. The factory provides access to all graphics classes known to
00288    the application.
00289 */
00290 class ABI_EXPORT GR_GraphicsFactory
00291 {
00292 
00293   public:
00294     GR_GraphicsFactory(){};
00295     virtual ~GR_GraphicsFactory(){};
00296 
00297     UT_uint32     getClassCount() const {return m_vClassIds.getItemCount();}
00298 
00299     bool          registerClass(GR_Allocator, GR_Descriptor, UT_uint32 iClassId);
00300     UT_uint32     registerPluginClass(GR_Allocator, GR_Descriptor);
00301 
00302     void          registerAsDefault(UT_uint32 iClassId, bool bScreen)
00303                          {
00304                              if(bScreen)
00305                                  m_iDefaultScreen = iClassId;
00306                              else
00307                                  m_iDefaultPrinter = iClassId;
00308                          }
00309 
00310     UT_uint32     getDefaultClass(bool bScreen) const {if(bScreen) return m_iDefaultScreen; else return m_iDefaultPrinter;}
00311     bool          unregisterClass(UT_uint32 iClassId);
00312     bool          isRegistered(UT_uint32 iClassId) const;
00313 
00314     GR_Graphics * newGraphics(UT_uint32 iClassId, GR_AllocInfo &param) const;
00315     const char *  getClassDescription(UT_uint32 iClassId) const;
00316 
00317 
00318   private:
00319     UT_GenericVector<GR_Allocator>       m_vAllocators;
00320     UT_GenericVector<GR_Descriptor>       m_vDescriptors;
00321     UT_NumberVector m_vClassIds;
00322 
00323     UT_uint32       m_iDefaultScreen;
00324     UT_uint32       m_iDefaultPrinter;
00325 };
00326 
00327 
00328 enum GRShapingResult
00329 {
00330     GRSR_BufferClean = 0x00,                  // clear all bits; see notes above !!!
00331     GRSR_None = 0x01,                         // bit 0 set
00332     GRSR_ContextSensitive = 0x02,             // bit 1 set
00333     GRSR_Ligatures = 0x04,                    // bit 2 set
00334     GRSR_ContextSensitiveAndLigatures = 0x06, // bit 1, 2 set
00335     GRSR_Unknown = 0xef,                      // bits 0-6 set, initial value for text in our runs
00336     GRSR_Error = 0xff                         // bits 0-7 set
00337 };
00338 
00339 /*
00340   GR_Graphics is a portable interface to a simple 2-d graphics layer.  It is not
00341   an attempt at a general purpose portability layer.  Rather, it contains only
00342   functions which are needed.
00343 */
00344 
00345 #define GR_OC_LEFT_FLUSHED 0x40000000 // flip bit 31
00346 #define GR_OC_MAX_WIDTH    0x3fffffff
00347 
00348 class ABI_EXPORT AllCarets
00349 {
00350     friend class GR_Graphics;
00351  public:
00352     AllCarets(GR_Graphics * pG,
00353               GR_Caret ** pCaret,
00354               UT_GenericVector<GR_Caret *>* vecCarets  );
00355     virtual ~AllCarets(){}
00356     GR_Caret *  getBaseCaret(void);
00357     void        enable(void);
00358     void        disable(bool bNoMulti = false);
00359     void        setBlink(bool bBlink);
00360     void        JustErase(UT_sint32 xPoint,UT_sint32 yPoint);
00361     void        setWindowSize(UT_uint32 width, UT_uint32 height);
00362     void        setCoords(UT_sint32 x, UT_sint32 y, UT_uint32 h,
00363                           UT_sint32 x2 = 0, UT_sint32 y2 = 0, UT_uint32 h2 = 0,
00364                           bool bPointDirection = false,
00365                           const UT_RGBColor * pClr = NULL);
00366     void        setInsertMode (bool mode);
00367     void        forceDraw(void);
00368 
00369  private:
00370     GR_Graphics * m_pG;
00371     GR_Caret **    m_pLocalCaret;
00372     UT_GenericVector<GR_Caret *>* m_vecCarets;
00373 };
00374 
00375 
00376 class ABI_EXPORT GR_Graphics
00377 {
00378     friend class GR_Painter;
00379     friend class GR_Caret;
00380     friend class AllCarets;
00381  public:
00382     virtual ~GR_Graphics();
00383 
00384     // the static method allows us to retrive the the class id for
00385     // purposes of registration; we also need the virtual to identify
00386     // the class from a generic GR_Graphics pointer
00387 //  static UT_uint32 s_getClassId() {UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); return GRID_UNKNOWN;}
00388     virtual UT_uint32 getClassId() = 0;
00389 
00390     virtual GR_Capability getCapability() {UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); return GRCAP_UNKNOWN;}
00391 #if 0
00392     // the following two static functions have to be implemented by all
00393     // derrived classes and registered with GR_GraphicsFactory
00394     static const char *    graphicsDescriptor(void){UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); return "???";}
00395     static GR_Graphics *   graphicsAllocator(GR_AllocInfo&){UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); return NULL;}
00396 #endif
00397 
00398     AllCarets * allCarets();
00399     void        disableAllCarets();
00400     void        enableAllCarets();
00401 
00402     UT_sint32   tdu(UT_sint32 layoutUnits) const;
00403     UT_sint32   tlu(UT_sint32 deviceUnits) const;
00404     double      tduD(double layoutUnits) const;
00405     double      tluD(double deviceUnits) const;
00406     void        antiAliasAlways(bool bAntiAlias)
00407     { m_bAntiAliasAlways = bAntiAlias;}
00408     bool        getAntiAliasAlways(void)
00409     { return m_bAntiAliasAlways;}
00410 
00415     UT_sint32   ftlu(UT_sint32 fontUnits) const;
00416     double      ftluD(double fontUnits) const;
00417 
00418     virtual void      setFont(const GR_Font* pFont) = 0;
00419     virtual void      clearFont(void) = 0;
00420     virtual UT_uint32 getFontAscent() = 0;
00421     virtual UT_uint32 getFontDescent() = 0;
00422     virtual UT_uint32 getFontHeight() = 0;
00423     void              invalidateCache(void);
00424     virtual bool      canQuickPrint(void) const { return false;}
00425     virtual UT_uint32 measureString(const UT_UCSChar*s,
00426                                     int iOffset,
00427                                     int num,
00428                                     UT_GrowBufElement* pWidths, UT_uint32 *height = 0);
00429 
00430     virtual UT_sint32 measureUnRemappedChar(const UT_UCSChar c, UT_uint32 * height = 0) = 0;
00431     virtual void getCoverage(UT_NumberVector& coverage) = 0;
00432 
00433     /* GR_Font versions of the above -- TODO: should I add drawChar* methods too? */
00434     virtual UT_uint32 getFontAscent(const GR_Font *)  = 0;
00435     virtual UT_uint32 getFontDescent(const GR_Font *) = 0;
00436     virtual UT_uint32 getFontHeight(const GR_Font *)  = 0;
00437     virtual double    getResolutionRatio(void) const {return 1.0;}
00438 
00439     void         getMaxCharacterDimension (const UT_UCSChar*s, UT_uint32 Length, UT_uint32 &width, UT_uint32 &height);
00440 
00441     virtual void      setColor(const UT_RGBColor& clr) = 0;
00442     virtual void      getColor(UT_RGBColor& clr) = 0;
00443     virtual GR_Font*  getGUIFont() = 0;
00444 
00445     GR_Font*  findFont(const char* pszFontFamily,
00446                        const char* pszFontStyle,
00447                        const char* pszFontVariant,
00448                        const char* pszFontWeight,
00449                        const char* pszFontStretch,
00450                        const char* pszFontSize,
00451                        const char* pszLang);
00452 
00453     /* Static 'virtual' -- if you are providing an implementation for this
00454      * function in a derrived graphics class, please define
00455      * XAP_HAVE_GR_findNearestFont in platform xap_*Features.h file
00456      */
00457 #ifdef XAP_HAVE_GR_findNearestFont
00458     static const char* findNearestFont(const char* pszFontFamily,
00459                                        const char* pszFontStyle,
00460                                        const char* pszFontVariant,
00461                                        const char* pszFontWeight,
00462                                        const char* pszFontStretch,
00463                                        const char* pszFontSize,
00464                                        const char* pszLang);
00465 #else
00466     static const char* findNearestFont(const char* pszFontFamily,
00467                                        const char* /*pszFontStyle*/,
00468                                        const char* /*pszFontVariant*/,
00469                                        const char* /*pszFontWeight*/,
00470                                        const char* /*pszFontStretch*/,
00471                                        const char* /*pszFontSize*/,
00472                                        const char* /*pszLang*/)
00473         {return pszFontFamily;}
00474 #endif
00475 
00476     const char *      invertDimension(UT_Dimension, double) const;
00477 
00478     bool              scaleDimensions(const char * szLeftIn,
00479                                       const char * szWidthIn,
00480                                       UT_uint32 iWidthAvail,
00481                                       UT_sint32 * piLeft,
00482                                       UT_uint32 * piWidth) const;
00483 
00484     virtual GR_Image* createNewImage(const char* pszName,
00485                                      const UT_ByteBuf* pBB,
00486                                      const std::string& mimetype,
00487                                      UT_sint32 iWidth,
00488                                      UT_sint32 iHeight,
00489                                      GR_Image::GRType iType = GR_Image::GRT_Raster);
00490 
00491     virtual void      setLineWidth(UT_sint32) = 0;
00492 
00493     virtual void      setClipRect(const UT_Rect* pRect) = 0;
00494     const UT_Rect *   getClipRect(void) const { return m_pRect;}
00495     virtual void      scroll(UT_sint32, UT_sint32) = 0;
00496     virtual void      scroll(UT_sint32 x_dest,
00497                              UT_sint32 y_dest,
00498                              UT_sint32 x_src,
00499                              UT_sint32 y_src,
00500                              UT_sint32 width,
00501                              UT_sint32 height) = 0;
00502 
00503     typedef enum { DGP_SCREEN, DGP_PAPER, DGP_OPAQUEOVERLAY } Properties;
00504 
00505     typedef enum
00506       {
00507         JOIN_MITER,
00508         JOIN_ROUND,
00509         JOIN_BEVEL
00510       } JoinStyle ;
00511 
00512     typedef enum
00513       {
00514         CAP_BUTT,
00515         CAP_ROUND,
00516         CAP_PROJECTING
00517       } CapStyle ;
00518 
00519     typedef enum
00520       {
00521         LINE_SOLID,
00522         LINE_ON_OFF_DASH,
00523         LINE_DOUBLE_DASH,
00524         LINE_DOTTED
00525       } LineStyle ;
00526 
00527     virtual void setLineProperties ( double inWidthPixels,
00528                      JoinStyle inJoinStyle = JOIN_MITER,
00529                      CapStyle inCapStyle   = CAP_BUTT,
00530                      LineStyle inLineStyle = LINE_SOLID ) ;
00531 
00532     virtual bool      queryProperties(GR_Graphics::Properties gp) const = 0;
00533     /* the following 3 are only used for printing */
00534 
00535     virtual bool      startPrint(void) = 0;
00536 
00537     virtual bool      startPage(const char * szPageLabel,
00538                                 UT_uint32 pageNumber,
00539                                 bool bPortrait,
00540                                 UT_uint32 iWidth,
00541                                 UT_uint32 iHeight) = 0;
00542 
00543     virtual bool      endPrint(void) = 0;
00544 
00545     virtual void      flush(void);
00546 
00547     /* specific color space support */
00548 
00549     typedef enum { GR_COLORSPACE_COLOR,
00550                    GR_COLORSPACE_GRAYSCALE,
00551                    GR_COLORSPACE_BW
00552     } ColorSpace;
00553 
00554     virtual void      setColorSpace(GR_Graphics::ColorSpace c) = 0;
00555     virtual GR_Graphics::ColorSpace getColorSpace(void) const = 0;
00556 
00557     /* multiple cursor support */
00558 
00559     typedef enum { GR_CURSOR_INVALID=0,
00560                    GR_CURSOR_DEFAULT,
00561                    GR_CURSOR_IBEAM,
00562                    GR_CURSOR_RIGHTARROW,
00563                    GR_CURSOR_IMAGE,
00564                    GR_CURSOR_IMAGESIZE_NW,
00565                    GR_CURSOR_IMAGESIZE_N,
00566                    GR_CURSOR_IMAGESIZE_NE,
00567                    GR_CURSOR_IMAGESIZE_E,
00568                    GR_CURSOR_IMAGESIZE_SE,
00569                    GR_CURSOR_IMAGESIZE_S,
00570                    GR_CURSOR_IMAGESIZE_SW,
00571                    GR_CURSOR_IMAGESIZE_W,
00572                    GR_CURSOR_LEFTRIGHT,
00573                    GR_CURSOR_UPDOWN,
00574                    GR_CURSOR_EXCHANGE,
00575                    GR_CURSOR_GRAB,
00576                    GR_CURSOR_LINK,
00577                    GR_CURSOR_WAIT,
00578                    GR_CURSOR_LEFTARROW,
00579                    GR_CURSOR_VLINE_DRAG,
00580                    GR_CURSOR_HLINE_DRAG,
00581                    GR_CURSOR_CROSSHAIR,
00582                            GR_CURSOR_DOWNARROW,
00583                            GR_CURSOR_DRAGTEXT,
00584                            GR_CURSOR_COPYTEXT
00585     } Cursor;
00586 
00587     virtual void      setCursor(GR_Graphics::Cursor c) = 0;
00588     virtual GR_Graphics::Cursor getCursor(void) const = 0;
00589 
00590     virtual void      setZoomPercentage(UT_uint32 iZoom);
00591     inline UT_uint32  getZoomPercentage(void) const {return m_iZoomPercentage; }
00592     static UT_uint32  getResolution(void) { return UT_LAYOUT_RESOLUTION; }
00593     inline void       setPortrait (bool b) {m_bIsPortrait = b;}
00594     inline bool       isPortrait (void) const {return m_bIsPortrait;}
00595 
00596     typedef enum { CLR3D_Foreground=0,              /* color of text/foreground on a 3d object */
00597                    CLR3D_Background=1,              /* color of face/background on a 3d object */
00598                    CLR3D_BevelUp=2,                 /* color of bevel-up  */
00599                    CLR3D_BevelDown=3,               /* color of bevel-down */
00600                    CLR3D_Highlight=4                /* color half-way between up and down */
00601     } GR_Color3D;
00602 #define COUNT_3D_COLORS 5
00603 
00604     virtual void      setColor3D(GR_Color3D c) = 0;
00605     virtual bool      getColor3D(GR_Color3D /*name*/, UT_RGBColor & /*color*/)
00606     { return false; }
00607 
00608     const GR_Transform & getTransform() const {return m_Transform;}
00609 
00610     /* returns true on success, false on failure */
00611     bool              setTransform(const GR_Transform & tr)
00612                          {
00613                              bool ret = _setTransform(tr);
00614                              if(!ret)
00615                                  return false;
00616                              m_Transform = tr;
00617                              return true;
00618                          }
00619 
00620     void              createCaret()
00621         {
00622             UT_ASSERT_HARMLESS(!m_pCaret);
00623             m_pCaret = new GR_Caret(this);
00624         }
00625 
00626     GR_Caret *        createCaret(const std::string& sID);
00627     GR_Caret *        getCaret(const std::string& sID) const;
00628     GR_Caret *        getNthCaret(UT_sint32 i) const;
00629     void              removeCaret(const std::string& sID);
00630 
00631     virtual void      saveRectangle(UT_Rect & r, UT_uint32 iIndx) = 0;
00632     virtual void      restoreRectangle(UT_uint32 iIndx) = 0;
00633     virtual UT_uint32 getDeviceResolution(void) const = 0;
00634 //
00635 // Use these methods to fix off by 1 errors while scrolling. Add the
00636 // the logical difference to these first, then calculate how much
00637 // the screen needs to scroll in device units
00638 //
00639     UT_sint32         getPrevYOffset(void) const { return m_iPrevYOffset;}
00640     UT_sint32         getPrevXOffset(void) const { return m_iPrevXOffset;}
00641     void              setPrevYOffset(UT_sint32 y) { m_iPrevYOffset = y;}
00642     void              setPrevXOffset(UT_sint32 x) { m_iPrevXOffset = x;}
00643 
00644     UT_sint32         _tduX(UT_sint32 layoutUnits) const;
00645 
00646 
00648     // complex script processing; see default implementations of these
00649     // functions for documentation
00650     //
00651     virtual bool itemize(UT_TextIterator & text, GR_Itemization & I) VIRTUAL_SFX;
00652 
00653     // translates GR_ShapingInfo into GR_RenderInfo which then can be
00654     // passed to renderChars()
00655     virtual bool shape(GR_ShapingInfo & si, GR_RenderInfo *& ri) VIRTUAL_SFX;
00656 
00657     // like drawChars, except uses generic (platform specific) input
00658     // the default implementation simply maps to drawChars and needs
00659     // to be replaced by platform code
00660     virtual void prepareToRenderChars(GR_RenderInfo & ri) VIRTUAL_SFX;
00661     virtual void renderChars(GR_RenderInfo & ri) VIRTUAL_SFX;
00662 
00663     virtual void appendRenderedCharsToBuff(GR_RenderInfo & ri, UT_GrowBuf & buf) const VIRTUAL_SFX;
00664     virtual void measureRenderedCharWidths(GR_RenderInfo & ri) VIRTUAL_SFX;
00665 
00666     // expects ri.m_iOffset set to the run offset condsidered for break
00667     //         ri.m_pText set positioned at start of the run
00668     //         represented by ri, its uper limit set appropriately
00669     //         ri.m_iLength is set to the run length
00670     // iNext -- if break is not possible at the given offset, the
00671     //          class might return the next possible break offset in
00672     //          iNext, relative to start of the text represented by ri
00673     //          (not relative to m_iOffset); if the class does not
00674     //          know where the next break point lies, it should set
00675     //          iNext to -1; if it knows that there is no break in this run, it should set
00676     //          iNext to -2
00677     // bAfter indicates whether we are quering for a break after the character at given offset
00678 
00679     virtual bool canBreak(GR_RenderInfo & ri, UT_sint32 &iNext, bool bAfter) VIRTUAL_SFX;
00680 
00681     // indicates if special caret positioning has to be done for the run of text; this allows us
00682     // to speed things up when this is not needed
00683     virtual bool needsSpecialCaretPositioning(GR_RenderInfo & /*ri*/) VIRTUAL_SFX {return false;}
00684 
00685     // adjusts caret position if given script restricts where caret can be placed
00686     // the caller has to set initial position within the run in ri.m_iOffset, overall length of
00687     // the run in ri.m_iLength and provide a text iterator over the text of the run in ri.m_pText
00688     //
00689     // return value is the adjusted offset
00690     // the default implementation simply returns the passed value
00691     virtual UT_uint32 adjustCaretPosition(GR_RenderInfo & ri, bool bForward) VIRTUAL_SFX;
00692 
00693     // Adjusts position for delete if given script restricts deletion to character clusters.
00694     // The caller has to set initial position within the run in ri.m_iOffset, overall length to be
00695     // deleted in ri.m_iLength and provide a text iterator over the text of the run in ri.m_pText
00696     // on return ri.m_iOffset contains the adjusted (run-relative) position and ri.m_iLength the count
00697     // the adjusted length of the delete
00698     //
00699     // the default implementation simply returns the passed value
00700     virtual void adjustDeletePosition(GR_RenderInfo & ri) VIRTUAL_SFX;
00701 
00702     // the AbiWord line breaking was designed looking for breaks at the right edge of a character,
00703     // i.e., the character that can break is included with the left part of the split run.
00704     // the Uniscribe library, however, holds breaking info for left edge, and sometimes it is useful
00705     // to know what system we are dealing with.
00706     virtual bool nativeBreakInfoForRightEdge() VIRTUAL_SFX {return true;}
00707 
00708     virtual UT_sint32 resetJustification(GR_RenderInfo & ri, bool bPermanent) VIRTUAL_SFX;
00709     virtual UT_sint32 countJustificationPoints(const GR_RenderInfo & ri) const VIRTUAL_SFX;
00710     virtual void justify(GR_RenderInfo & ri) VIRTUAL_SFX;
00711 
00712     virtual UT_uint32 XYToPosition(const GR_RenderInfo & ri, UT_sint32 x, UT_sint32 y) const VIRTUAL_SFX;
00713     virtual void      positionToXY(const GR_RenderInfo & ri,
00714                                    UT_sint32& x, UT_sint32& y,
00715                                    UT_sint32& x2, UT_sint32& y2,
00716                                    UT_sint32& height, bool& bDirection) const VIRTUAL_SFX;
00717 
00718     virtual UT_sint32 getTextWidth(GR_RenderInfo & ri) VIRTUAL_SFX;
00719 
00720     // should be overriden by any classes implemented as plugins
00721     // NB: you must not use s_Version to store the version of derrived
00722     // classes, but have your own static variable for the derrived
00723     // class !!!
00724     virtual const UT_VersionInfo & getVersion() const {UT_ASSERT_HARMLESS( UT_NOT_IMPLEMENTED ); return s_Version;}
00725     UT_uint32         getPaintCount(void) const
00726         { return  m_paintCount;}
00727 
00728     /* all drawing should happen between calls to these two functions. this
00729      * arranges for cairo contexts to be created/destroyed etc.  if you don't
00730      * call these functions, bad things can and will happen */
00731     void beginPaint ();
00732     void endPaint ();
00733 
00734     static GR_Graphics* newNullGraphics();
00735 
00736  protected:
00737 
00738     GR_Graphics();
00739     GR_Caret *        getCaret() { return m_pCaret; }
00740 
00741     // todo: make these pure virtual
00742     virtual void _beginPaint () {}
00743     virtual void _endPaint () {}
00744 
00745     UT_sint32         _tduY(UT_sint32 layoutUnits) const;
00746     UT_sint32         _tduR(UT_sint32 layoutUnits) const;
00747 
00748     void _destroyFonts ();
00749 
00750     virtual GR_Font* _findFont(const char* pszFontFamily,
00751                                const char* pszFontStyle,
00752                                const char* pszFontVariant,
00753                                const char* pszFontWeight,
00754                                const char* pszFontStretch,
00755                                const char* pszFontSize,
00756                                const char* pszLang) = 0;
00757 
00758     // only called by GR_Painter
00759     virtual void drawLine(UT_sint32 x1, UT_sint32 y1, UT_sint32 x2, UT_sint32 y2) = 0;
00760 #if XAP_DONTUSE_XOR
00761 #else
00762     virtual void xorLine(UT_sint32 x1, UT_sint32 y1, UT_sint32 x2, UT_sint32 y2) = 0;
00763 #endif
00764     virtual void invertRect(const UT_Rect* pRect) = 0;
00765 #if XAP_DONTUSE_XOR
00766 #else
00767     void xorRect(UT_sint32 x, UT_sint32 y, UT_sint32 w, UT_sint32 h);
00768     void xorRect(const UT_Rect& r);
00769 #endif
00770 
00771     virtual void fillRect(GR_Image *pImg, const UT_Rect &src, const UT_Rect & dest);
00772     virtual void fillRect(const UT_RGBColor& c, const UT_Rect &r);
00773     virtual void fillRect(const UT_RGBColor& c, UT_sint32 x, UT_sint32 y,
00774                           UT_sint32 w, UT_sint32 h) = 0;
00775 
00776     virtual void clearArea(UT_sint32 x, UT_sint32 y, UT_sint32 w, UT_sint32 h) = 0;
00777     virtual void drawImage(GR_Image* pImg, UT_sint32 xDest, UT_sint32 yDest);
00778     virtual void fillRect(GR_Color3D c, UT_Rect &r) = 0;
00779     virtual void fillRect(GR_Color3D c,
00780                           UT_sint32 x, UT_sint32 y,
00781                           UT_sint32 w, UT_sint32 h) = 0;
00782     virtual void polygon(UT_RGBColor& c, UT_Point *pts, UT_uint32 nPoints);
00783     virtual void polyLine(UT_Point * pts, UT_uint32 nPoints) = 0;
00784     virtual void drawGlyph(UT_uint32 glyph_idx, UT_sint32 xoff, UT_sint32 yoff) = 0;
00785     virtual void drawChars(const UT_UCSChar* pChars,
00786                            int iCharOffset,
00787                            int iLength,
00788                            UT_sint32 xoff,
00789                            UT_sint32 yoff,
00790                            int* pCharWidths = NULL) = 0;
00791 
00792     virtual void drawCharsRelativeToBaseline(const UT_UCSChar* pChars,
00793                                              int iCharOffset,
00794                                              int iLength,
00795                                              UT_sint32 xoff,
00796                                              UT_sint32 yoff,
00797                                              int* pCharWidths = NULL);
00798 
00799     virtual GR_Image *    genImageFromRectangle(const UT_Rect & r) = 0;
00800 
00801  private:
00802     virtual bool _setTransform(const GR_Transform & /*tr*/)
00803         {
00804             UT_ASSERT_HARMLESS( UT_NOT_IMPLEMENTED );
00805             return false;
00806         }
00807 
00808  public:
00809     // TODO -- this should not be public, create access methods !!!
00810     //
00811     // Postscript context positions graphics wrt top of current PAGE, NOT
00812     // wrt top of document. The screen graphics engine, though positions
00813     // graphics wrt the top of the document, therefore if we are printing
00814     // page 5 we need to adjust the vertical position of the graphic in the
00815     // postscript image printing routine by (current_page_number-1) * page_height
00816     // I'm going to call this variable m_iRasterPosition, for want of a better name,
00817     // it's not acutally a rasterposition --- any better names would be a good idea,
00818     // I jusy can't think of one right now.
00819     UT_uint32         m_iRasterPosition;
00820 
00821  protected:
00822     UT_uint32         m_iZoomPercentage;
00823     UT_uint32         m_iFontAllocNo;
00824 
00825     static XAP_PrefsScheme *m_pPrefsScheme;
00826     static UT_uint32 m_uTick;
00827 
00828     const UT_Rect *  m_pRect;
00829 
00830     bool m_bHave3DColors;
00831 
00832     UT_uint32 m_paintCount;
00833 
00834     // Double buffering infrastructure.
00835 
00836     // The default implementation here leads to no double buffering,
00837     // as they perform no action at all. Should be overriden in derived
00838     // classes
00839     virtual void _DeviceContext_SwitchToBuffer() { };
00840     virtual void _DeviceContext_SwitchToScreen() { };
00841 
00842     // returns the token for the current call
00843     bool beginDoubleBuffering();
00844 
00845     // does the actual buffer-to-screen switch only when it gets
00846     // the correct token
00847     void endDoubleBuffering(bool token);
00848 
00849     // SUSPEND / RESUME drawings infrastructure
00850     // Drawing code (through gr_Graphics) will have no effect between SUSPEND - RESUME.
00851     // The default implementation does not suspend anything
00852     // (ie. changes are still taking effect)
00853 
00854     virtual void _DeviceContext_SuspendDrawing() { };
00855     virtual void _DeviceContext_ResumeDrawing() { };
00856 
00857     bool suspendDrawing();
00858     void resumeDrawing(bool token);
00859 
00860     // Device context switch management
00861     bool m_bDoubleBufferingActive;
00862     bool m_bDrawingSuspended;
00863 
00864     typedef enum {
00865         SWITCHED_TO_BUFFER = 0,
00866         DRAWING_SUSPENDED
00867     } DeviceContextSwitchType;
00868 
00869     UT_NumberStack m_DCSwitchManagementStack;
00870 
00871  private:
00872     GR_Caret *       m_pCaret;
00873     bool             _PtInPolygon(UT_Point * pts,UT_uint32 nPoints,UT_sint32 x,UT_sint32 y);
00874     bool             m_bIsPortrait;
00875     bool             m_bSpawnedRedraw;
00876     UT_Rect          m_PendingExposeArea;
00877     UT_Rect          m_RecentExposeArea;
00878     bool             m_bExposePending;
00879     bool             m_bIsExposedAreaAccessed;
00880     bool             m_bDontRedraw;
00881     bool             m_bDoMerge;
00882 //
00883 // These hold the previous x and Y offset calculated from the scrolling code
00884 // in Logical units. We need them to avoid off by 1 errors in scrolling.
00885 //
00886     UT_sint32        m_iPrevYOffset;
00887     UT_sint32        m_iPrevXOffset;
00888     GR_Transform     m_Transform;
00889 
00890     UT_GenericStringMap<GR_Font*> m_hashFontCache;
00891 
00892     static UT_VersionInfo   s_Version;
00893     static UT_uint32        s_iInstanceCount;
00894     static UT_UCS4Char      s_cDefaultGlyph;
00895     UT_GenericVector<GR_Caret *>  m_vecCarets;
00896     AllCarets               m_AllCarets;
00897     bool                    m_bAntiAliasAlways;
00898 };
00899 
00900 #endif /* GR_GRAPHICS_H */

Generated on Mon May 28 2012 for AbiWord by  doxygen 1.7.1