paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/src/font pgfont.cpp,1.3.2.3,1.3.2.4


From: Teunis Peters <address@hidden>
Subject: [paragui-cvs] CVS: paragui/src/font pgfont.cpp,1.3.2.3,1.3.2.4
Date: Mon, 07 Oct 2002 18:23:28 -0400

Update of /cvsroot/paragui/paragui/src/font
In directory subversions:/tmp/cvs-serv21228/src/font

Modified Files:
      Tag: devel-opengl
        pgfont.cpp 
Log Message:
Add driver support
expand debugging code (but mostly disabled)
Some more clarification....  hope I got everything - T


Index: pgfont.cpp
===================================================================
RCS file: /cvsroot/paragui/paragui/src/font/pgfont.cpp,v
retrieving revision 1.3.2.3
retrieving revision 1.3.2.4
diff -C2 -r1.3.2.3 -r1.3.2.4
*** pgfont.cpp  31 Aug 2002 04:01:23 -0000      1.3.2.3
--- pgfont.cpp  7 Oct 2002 22:23:26 -0000       1.3.2.4
***************
*** 33,38 ****
  #include "pgdraw.h"
  
- //#define OLD_TEXTRENDERING
- 
  //PG_Draw::PG_DrawableSurface* PG_FontEngine::my_charSurface = NULL;
  PG_FontEngine::MAP_FONTS PG_FontEngine::my_fontcache;
--- 33,36 ----
***************
*** 119,473 ****
  }
  
- #ifndef OLD_TEXTRENDERING
- 
- template < class DT >
- inline void BlitTemplate(DT pixels, PG_Draw::PG_DrawableSurface* Surface, 
FT_Bitmap *Bitmap, int PosX, int PosY, int x0, int x1, int y0, int y1, PG_Font 
*Param) {
-       int xw = x1-x0;
- 
-       SDL_PixelFormat* format = Surface->getScreen()->format;
-       Uint8 Rloss = format->Rloss;
-       Uint8 Gloss = format->Gloss;
-       Uint8 Bloss = format->Bloss;
-       Uint8 Aloss = format->Aloss;
-       Uint8 Rloss8 = 8-Rloss;
-       Uint8 Gloss8 = 8-Gloss;
-       Uint8 Bloss8 = 8-Bloss;
-       Uint8 Aloss8 = 8-Aloss;
-       Uint8 Rshift = format->Rshift;
-       Uint8 Gshift = format->Gshift;
-       Uint8 Bshift = format->Bshift;
-       Uint8 Ashift = format->Ashift;
-       Uint32 Rmask = format->Rmask;
-       Uint32 Gmask = format->Gmask;
-       Uint32 Bmask = format->Bmask;
-       Uint32 Amask = format->Amask;
- 
-       Uint8 bpp = format->BytesPerPixel;
-       Uint32 pitch = Surface->getScreen()->pitch;
-       Uint32 src_pitch = Bitmap->pitch;
-       register Uint8* src_pixels = Bitmap->buffer + x0 + y0*Bitmap->pitch;
-       register Uint8* dst_pixels = (Uint8*)pixels + (PosX+x0)*bpp + 
(PosY+y0)*pitch;
-       Uint8* line;
- 
-       Uint8 r,g,b,a;
-       unsigned rv,gv,bv,av;
-       Sint32 cr,cg,cb;
-       Uint32 color = 0;
-       Sint32 v;
- 
-       SDL_Color fc = Param->GetColor();
-       cr = fc.r;
-       cg = fc.g;
-       cb = fc.b;
-       int alpha = Param->GetAlpha();
- 
-       line = dst_pixels;
-       for (register int y = y0; y <y1; y++, src_pixels += src_pitch) {
- 
-               dst_pixels = line;
- 
-               for (register int x = x0; x < x1; x++, dst_pixels += bpp) {
- 
-                       // get source pixel value
-                       v = *(Uint8 *)(src_pixels++);
- 
-                       // don't do anything if the pixel is fully transparent
-                       if(v == 0) {
-                               continue;
-                       }
- 
-                       if(alpha != 255) {
-                               v = (v * alpha) >> 8;
-                       }
- 
-                       // Get the pixel
-                       color = *((DT) (dst_pixels));
-                       if ( Surface->getScreen()->format->BytesPerPixel > 1 ) {
- 
-                               // get the RGBA values
-                               rv = (color & Rmask) >> Rshift;
-                               r = (rv << Rloss) + (rv >> Rloss8);
-                               gv = (color & Gmask) >> Gshift;
-                               g = (gv << Gloss) + (gv >> Gloss8);
-                               bv = (color & Bmask) >> Bshift;
-                               b = (bv << Bloss) + (bv >> Bloss8);
-                               if(Amask) {
-                                       av = (color & Amask) >> Ashift;
-                                       a = (av << Aloss) + (av >> Aloss8);
-                               } else
-                                       a = SDL_ALPHA_OPAQUE;
- 
-                               //SDL_GetRGBA(color, format, &r, &g, &b, &a);
- 
-                               // calculate new RGBA values
-                               if(v == 255) {
-                                       r = cr;
-                                       g = cg;
-                                       b = cb;
-                               }
-                               else {
-                                       //r += ((cr - r) * v) / 255;
-                                       //g += ((cg - g) * v) / 255;
-                                       //b += ((cb - b) * v) / 255;
-                                       r += ((cr - r) * v) >> 8;
-                                       g += ((cg - g) * v) >> 8;
-                                       b += ((cb - b) * v) >> 8;
-                               }
- 
-                               // if the destination pixel is full transparent
-                               // use the pixel shading as alpha
-                               if(a == 0) {
-                                       a = v;
-                               }
- 
-                               // get the destination color
-                               color = (r >> Rloss) << Rshift
-                           | (g >> Gloss) << Gshift
-                           | (b >> Bloss) << Bshift
-                           | ((a >> Aloss) << Ashift & Amask);
-                               // Set the pixel
-                       } else {
-                               SDL_GetRGBA(color, format, &r, &g, &b, &a);
- 
-                               // calculate new RGBA values
-                               if(v == 255) {
-                                       r = cr;
-                                       g = cg;
-                                       b = cb;
-                               }
-                               else {
-                                       //r += ((cr - r) * v) / 255;
-                                       //g += ((cg - g) * v) / 255;
-                                       //b += ((cb - b) * v) / 255;
-                                       r += ((cr - r) * v) >> 8;
-                                       g += ((cg - g) * v) >> 8;
-                                       b += ((cb - b) * v) >> 8;
-                               }
- 
-                               // if the destination pixel is full transparent
-                               // use the pixel shading as alpha
-                               if(a == 0) {
-                                       a = v;
-                               }
-                               color = SDL_MapRGBA(format, r,g,b, a);
-                       }
-                       *((DT) (dst_pixels)) = color;
- 
-               }
-               src_pixels -= xw;
-               line += pitch;
-       }
- }
- 
  bool PG_FontEngine::BlitFTBitmap(PG_Draw::PG_DrawableSurface *Surface, 
FT_Bitmap *Bitmap, int PosX, int PosY, PG_Font *Param, PG_Rect* ClipRect) {
!       int BitmapRealWidth;
! 
!       // i think we can skip that test
!       /*if(Bitmap->pixel_mode != ft_pixel_mode_grays) {
!               return false;
!       }*/
! 
!       // do nothing if we're fully transparent
!       if (Param->GetAlpha() == 0)
!               return true;
! 
!       BitmapRealWidth = Bitmap->width;
! 
!       // get the cliprectangle of the surface
!       static PG_Rect srfclip;
!       Surface->GetClipRect(srfclip);
! 
!       // the real clipping rectangle = surfaceclip  / ClipRect
!       static PG_Rect clip;
!       clip = *ClipRect / srfclip;
! 
!       //Italic font is widther than normal
!       //if (Param->Style & PG_FSTYLE_ITALIC) {
!       //      BitmapRealWidth += (int)(Bitmap->rows * PG_FITALIC_ANGLE);
!       //}
! 
!       int x0 = 0;
!       int x1 = BitmapRealWidth;
!       int y0 = 0;
!       int y1 = Bitmap->rows;
! 
!       if(PosX < clip.x) {
!               x0 = clip.x - PosX;
!       }
! 
!       if(PosX+BitmapRealWidth > clip.x + clip.w) {
!               x1 = (clip.x + clip.w) - PosX;
!       }
! 
!       if(PosY < clip.y) {
!               y0 = clip.y - PosY;
!       }
! 
!       if(PosY+Bitmap->rows > clip.y + clip.h) {
!               y1 = (clip.y + clip.h) - PosY;
!       }
! 
!       if((x1 <= x0) || (y1 <= y0)) {
!               return false;
!       }
!       
!       switch(Surface->getScreen()->format->BytesPerPixel) {
!               case 1:
!                       BlitTemplate((Uint8*)Surface->getScreen()->pixels, 
Surface, Bitmap, PosX, PosY, x0, x1, y0, y1, Param);
!                       break;
!               case 2:
!                       BlitTemplate((Uint16*)Surface->getScreen()->pixels, 
Surface, Bitmap, PosX, PosY, x0, x1, y0, y1, Param);
!                       break;
!               case 4:
!                       BlitTemplate((Uint32*)Surface->getScreen()->pixels, 
Surface, Bitmap, PosX, PosY, x0, x1, y0, y1, Param);
!                       break;
!       }
! 
!       return true;
  }
- 
- #else
- 
- bool PG_FontEngine::BlitFTBitmap(PG_Draw::PG_DrawableSurface *Surface, 
FT_Bitmap *Bitmap, int PosX, int PosY, PG_Font *Param, PG_Rect *ClipRect) {
-       PG_Draw* draw = PG_Draw::GetDefaultDrawable();
-       int             x,y;
-       Uint32          *raw_pixels;
-       SDL_Rect        TargetPos;
-       SDL_Rect        SourcePos;
-       int             BitmapRealWidth;
- 
-       if (Param->Alpha == 0)
-               return true;
- 
-       TargetPos.x = PosX;
-       TargetPos.y = PosY;
- 
-       //Italic font is widther than normal
-       BitmapRealWidth = Bitmap->width;
-       if (Param->Style & PG_FSTYLE_ITALIC) {
-               BitmapRealWidth += (int)(Bitmap->rows * PG_FITALIC_ANGLE);
-       }
- 
-       //There is no need to draw
-       if ((TargetPos.x > (ClipRect->x + ClipRect->w)) || (TargetPos.y > 
(ClipRect->y +ClipRect->h )) || ((TargetPos.y+Bitmap->rows) < ClipRect->y) || 
((TargetPos.x+BitmapRealWidth) < ClipRect->x))
-               return true;
- 
-       //Is my_charSurface big enough ??
-       if (my_charSurface != NULL) {
-               if ((my_charSurface->w < BitmapRealWidth)||(my_charSurface->h < 
Bitmap->rows)) {
-                       delete my_charSurface; // 
SDL_FreeSurface(my_charSurface);
-                       my_charSurface = NULL;
-               }
-       }
- 
-       if (my_charSurface == NULL) {
-               my_charSurface = draw->CreateDrawableSurface(SDL_SRCALPHA , 
BitmapRealWidth, Bitmap->rows, 32, 0xff0000, 0xff00, 0xff, 0xff000000);
-               if (my_charSurface == NULL) {
-                       PG_LogWRN("Can`t get char surface : %s",SDL_GetError());
-                       return false;
-               }
-       }
- 
-       if (Param->Style & PG_FSTYLE_ITALIC) {
-               PG_Rect emptyrect;
-               my_charSurface->FillRect(emptyrect, 0);
-       }
- 
-       SourcePos.x = 0; // = my_charSurface->clip_rect;
-       SourcePos.y = 0;
-       SourcePos.w = BitmapRealWidth;
-       SourcePos.h = Bitmap->rows;
- 
-       //Clipping
-       if ((TargetPos.x + SourcePos.w) > (ClipRect->x + ClipRect->w))
-               SourcePos.w = ClipRect->w - (TargetPos.x - ClipRect->x);
-       if ((TargetPos.y + SourcePos.h) > (ClipRect->y + ClipRect->h))
-               SourcePos.h = ClipRect->h - (TargetPos.y - ClipRect->y);
-       if (TargetPos.x < ClipRect->x) {
-               int     delta;
- 
-               delta = ClipRect->x - TargetPos.x;
-               SourcePos.w -= delta;
-               TargetPos.x += delta;
-               SourcePos.x += delta;
-       }
- 
-       if (TargetPos.y < ClipRect->y) {
-               int     delta;
- 
-               delta = ClipRect->y - TargetPos.y;
-               SourcePos.h -= delta;
-               TargetPos.y += delta;
-               SourcePos.y += delta;
-       }
- 
-       raw_pixels = (Uint32 *) my_charSurface->pixels;
-       Uint32 pitch_diff = 0;
- 
-       switch (Bitmap->pixel_mode) {
-               case ft_pixel_mode_grays: {
-                               Uint8   *SrcPix = Bitmap->buffer;
-                               int     a;
- 
- 
-                               if (Param->Style & PG_FSTYLE_ITALIC) {
-                                       double ioffset = Bitmap->rows * 
PG_FITALIC_ANGLE;
- 
-                                       for (y = 0; y < Bitmap->rows; y++, 
SrcPix += Bitmap->getScreen()->pitch, ioffset -= PG_FITALIC_ANGLE) {
-                                               for (x = 0; x <  Bitmap->width; 
x++) {
-                                                       a = *(Uint8 
*)(SrcPix++);
- 
-                                                       // What the hell should 
do this ?
-                                                       //if (Param->Alpha != 
255)
-                                                       //      a = (a * 
Param->Alpha) / 255;
- 
-                                                       raw_pixels[int(ioffset) 
+ x + (my_charSurface->getScreen()->pitch/4)*(y)] = 
SDL_MapRGBA(my_charSurface->getScreen()->format, Param->Color.r, 
Param->Color.g, Param->Color.b, a);
-                                               }
-                                               SrcPix -= x;
-                                       }
-                               } else
-                                       pitch_diff = 
(my_charSurface->getScreen()->pitch/4);
- 
-                               for (y = 0; y < Bitmap->rows; y++, SrcPix += 
Bitmap->getScreen()->pitch) {
-                                       for (x = 0; x <  Bitmap->width; x++) {
-                                               a = *(Uint8 *)(SrcPix++);
- 
-                                               // Q: What the hell should do 
this ?
-                                               // A: This allows for alpha
-                                               // rendering of text. // Neo
-                                       
-                                               if (Param->Alpha != 255)
-                                                       a = (a * Param->Alpha) 
/ 255;
- 
-                                               *raw_pixels = 
SDL_MapRGBA(my_charSurface->getScreen()->format, Param->Color.r, 
Param->Color.g, Param->Color.b, a);
-                                               raw_pixels++;
-                                       }
-                                       SrcPix -= x;
-                                       raw_pixels -= x;
-                                       raw_pixels += pitch_diff;
-                               }
-                               break;
-                       }
- 
-               default:
-                       PG_LogWRN("Unknown pixel type in font !");
-                       return false;
-       }
- 
-       // Final blit
-       PG_Rect BoldTarget = TargetPos;
-       Surface->BlitSurface(my_charSurface, SourcePos, TargetPos);
- 
-       //BOLD
-       if (Param->Style & PG_FSTYLE_BOLD) {
-               BoldTarget.x += Param->FaceCache->Bold_Offset;
-               Surface->BlitSurface(my_charSurface, SourcePos, BoldTarget);
-       }
- 
-       return true;
- }
- 
- #endif
- 
  
  bool PG_FontEngine::RenderText(PG_Draw::PG_DrawableSurface *Surface, const 
PG_Rect& ClipRect, int BaseLineX, int BaseLineY, const char *Text, PG_Font 
*ParamIn) {
--- 117,123 ----
  }
  
  bool PG_FontEngine::BlitFTBitmap(PG_Draw::PG_DrawableSurface *Surface, 
FT_Bitmap *Bitmap, int PosX, int PosY, PG_Font *Param, PG_Rect* ClipRect) {
!       return Surface->BlitFTBitmap(Bitmap,PosX,PosY,Param,ClipRect);
  }
  
  bool PG_FontEngine::RenderText(PG_Draw::PG_DrawableSurface *Surface, const 
PG_Rect& ClipRect, int BaseLineX, int BaseLineY, const char *Text, PG_Font 
*ParamIn) {





reply via email to

[Prev in Thread] Current Thread [Next in Thread]