Back to index

lightning-sunbird  0.9+nobinonly
nsAntiAliasedGlyph.h
Go to the documentation of this file.
00001 
00002 #ifndef NSANTIALIASEDGLYPH_H
00003 #define NSANTIALIASEDGLYPH_H
00004 
00005 #include "gfx-config.h"
00006 #include "nscore.h"
00007 
00008 #ifdef MOZ_ENABLE_FREETYPE2
00009 #include <ft2build.h>
00010 #include FT_GLYPH_H
00011 #endif
00012 
00013 struct _XImage;
00014 
00015 #ifndef MIN
00016 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
00017 #endif
00018 #ifndef MAX
00019 #define MAX(a,b) (((a) >= (b)) ? (a) : (b))
00020 #endif
00021 
00022 #define GLYPH_LEFT_EDGE(m) MIN(0, (m)->lbearing)
00023 #define GLYPH_RIGHT_EDGE(m) MAX((m)->width, (m)->rbearing)
00024 
00025 typedef struct _GlyphMetrics {
00026   PRUint32 width;
00027   PRUint32 height;
00028   PRInt32 lbearing;
00029   PRInt32 rbearing;
00030   PRInt32 advance;
00031   PRInt32 ascent;
00032   PRInt32 descent;
00033 } GlyphMetrics;
00034 
00035 //
00036 // Grey scale image
00037 //
00038 class nsAntiAliasedGlyph {
00039 public:
00040   nsAntiAliasedGlyph(PRUint32 aWidth, PRUint32 aHeight, PRUint32 aBorder);
00041   ~nsAntiAliasedGlyph();
00042 
00043   PRBool Init();                                      // alloc a buffer
00044   PRBool Init(PRUint8 *aBuffer, PRUint32 aBufferLen); // use this buffer
00045 #ifdef MOZ_ENABLE_FREETYPE2
00046   PRBool WrapFreeType(FT_BBox *aBbox, FT_BitmapGlyph aSlot, 
00047                       PRUint8 *aBuffer, PRUint32 aBufLen);
00048 #endif
00049 
00050   inline PRUint32 GetBorder()       { return mBorder; };
00051   inline PRUint8 *GetBuffer()       { return mBuffer; };
00052   inline PRUint32 GetBufferLen()    { return mBufferLen; };
00053   inline PRUint32 GetBufferWidth()  { return mBufferWidth; };
00054   inline PRUint32 GetBufferHeight() { return mBufferHeight; };
00055 
00056   inline PRInt32 GetAdvance()       { return mAdvance; };
00057   inline PRInt32 GetLBearing()      { return mLBearing; };
00058   inline PRInt32 GetRBearing()      { return mRBearing; };
00059   inline PRUint32 GetWidth()        { return mWidth; };
00060   inline PRUint32 GetHeight()       { return mHeight; };
00061 
00062   PRBool SetImage(XCharStruct *, _XImage *);
00063   PRBool SetSize(GlyphMetrics *);
00064 
00065 protected:
00066   PRUint32 mBorder;
00067   PRInt32  mAscent;
00068   PRInt32  mDescent;
00069   PRInt32  mLBearing;
00070   PRInt32  mRBearing;
00071   PRInt32  mAdvance;
00072   PRUint32 mWidth;
00073   PRUint32 mHeight;
00074   PRUint32 mMaxWidth;
00075   PRUint32 mMaxHeight;
00076   PRUint32 mBufferWidth;  // mWidth may be smaller
00077   PRUint32 mBufferHeight; // mHeight may be smaller
00078   PRBool   mOwnBuffer;
00079   PRUint8 *mBuffer;
00080   PRUint32 mBufferLen;
00081 };
00082 
00083 
00084 
00085 #endif /* NSANTIALIASEDGLYPH_H */