Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

font.H File Reference

#include "genesis.h"
#include "basetype.h"
#include "bitmap.h"

Go to the source code of this file.

Defines

#define GE_FONT_WRAP   0x00000001
#define GE_FONT_WORDWRAP   0x00000002
#define GE_FONT_JUST_RETURN_FIT   0x00000004
#define GE_FONT_JUSTIFY_RIGHT   0x00000008
#define GE_FONT_JUSTIFY_CENTER   0x00000010

Typedefs

typedef geFont geFont

Functions

GENESISAPI geFont *GENESISCC geFont_Create (const geEngine *Engine, const char *fontNameString, const int fontSize, const int fontWeight, const geBoolean antialiased)
GENESISAPI void GENESISCC geFont_CreateRef (geFont *font)
GENESISAPI void GENESISCC geFont_Destroy (geFont **font)
GENESISAPI geBoolean GENESISCC geFont_AddCharacters (geFont *font, unsigned char leastIndex, unsigned char mostIndex)
GENESISAPI void GENESISCC geFont_DestroyBitmapBuffer (geFont *font)
GENESISAPI geBoolean GENESISCC geFont_AddBitmapBuffer (geFont *font, const uint32 width, const uint32 height)
GENESISAPI geBoolean GENESISCC geFont_DrawText (geFont *font, const char *textString, const GE_Rect *Rect, const GE_RGBA *Color, uint32 flags, const GE_Rect *clipRect)
GENESISAPI geBoolean GENESISCC geFont_DrawTextToBitmap (geFont *font, const char *textString, const GE_Rect *Rect, const GE_RGBA *Color, uint32 flags, const GE_Rect *clipRect, geBitmap *targetBitmap)
GENESISAPI int32 GENESISCC geFont_GetStringPixelWidth (geFont *font, const char *textString)
GENESISAPI int32 GENESISCC geFont_GetStringPixelHeight (geFont *font, const char *textString)
GENESISAPI geBitmap *GENESISCC geFont_GetBuffer (geFont *font)
GENESISAPI geBoolean GENESISCC geFont_GetCharMap (geFont *font, uint8 character, GE_Rect *Rect, geBitmap **targetBitmap, int32 *fullWidth, int32 *fullHeight, int32 *offsetX, int32 *offsetY)
GENESISAPI void GENESISCC geFont_EnableAntialiasing (geFont *font, const geBoolean anti)
GENESISAPI geBoolean GENESISCC geFont_IsAntialiased (geFont *font)


Define Documentation

#define GE_FONT_JUST_RETURN_FIT   0x00000004
 

Definition at line 51 of file font.H.

Referenced by geFont_DrawText(), and geFont_DrawTextToBitmap().

#define GE_FONT_JUSTIFY_CENTER   0x00000010
 

Definition at line 53 of file font.H.

Referenced by geFont_DrawText(), and geFont_DrawTextToBitmap().

#define GE_FONT_JUSTIFY_RIGHT   0x00000008
 

Definition at line 52 of file font.H.

Referenced by geFont_DrawText(), and geFont_DrawTextToBitmap().

#define GE_FONT_WORDWRAP   0x00000002
 

Definition at line 50 of file font.H.

Referenced by geFont_DrawText(), geFont_DrawTextToBitmap(), and geFont_DrawUsingDIB().

#define GE_FONT_WRAP   0x00000001
 

Definition at line 49 of file font.H.

Referenced by geFont_DrawText(), and geFont_DrawTextToBitmap().


Typedef Documentation

typedef struct geFont geFont
 

Definition at line 60 of file font.H.


Function Documentation

GENESISAPI geBoolean GENESISCC geFont_AddBitmapBuffer geFont font,
const uint32  width,
const uint32  height
 

Definition at line 735 of file font.c.

References geFont::buffer, geFont::Engine, FALSE, GE_PIXELFORMAT_32BIT_XRGB, GE_PIXELFORMAT_8BIT, GE_TRUE, geBitmap_Create(), geBitmap_Palette_Create(), geBitmap_Palette_SetEntryColor(), geBitmap_SetColorKey(), geBitmap_SetPalette(), geBoolean, geEngine_AddBitmap(), geFont_DestroyBitmapBuffer(), GENESISAPI, GENESISCC, height, TRUE, and width.

00737 {
00738    geBoolean success;
00739    geBitmap_Palette * palette;
00740    int i;
00741 
00742    assert(font);
00743 
00744    assert(width  < 1000);  // just checking for absurd values that indicate 
00745    assert(height < 1000);  // an un-initialized state.
00746 
00747    if (font->buffer)
00748       geFont_DestroyBitmapBuffer( font );
00749 
00750    font->buffer = geBitmap_Create(width, height, 1, GE_PIXELFORMAT_8BIT); 
00751    assert(font->buffer);
00752 
00753    // and a pallette for it.
00754    palette = geBitmap_Palette_Create(GE_PIXELFORMAT_32BIT_XRGB, 256);
00755    assert(palette);
00756 
00757    for (i = 0; i < 256; i++)
00758    {
00759       success = geBitmap_Palette_SetEntryColor(palette, i, i, i, i, i);
00760       assert(success);
00761 
00762    }
00763 
00764    success = geBitmap_SetPalette(font->buffer, palette);
00765    assert(success);
00766 
00767         success = geBitmap_SetColorKey(font->buffer, TRUE, 0 ,FALSE );
00768 
00769    success = geEngine_AddBitmap((geEngine *)font->Engine, font->buffer);
00770    assert(success);
00771 
00772    return GE_TRUE;
00773 
00774 }

GENESISAPI geBoolean GENESISCC geFont_AddCharacters geFont font,
unsigned char  leastIndex,
unsigned char  mostIndex
 

Definition at line 344 of file font.c.

References geFont::antialiased, geFont::bitmapList, DWORD, geFont::Engine, FALSE, geFont::fontNameString, geFont::fontSize, geFont::fontWeight, geFontBitmap::freeX, geFontBitmap::freeY, GE_PIXELFORMAT_32BIT_XRGB, GE_PIXELFORMAT_8BIT, GE_RAM_ALLOCATE_ARRAY, GE_RAM_ALLOCATE_STRUCT, geBitmap_Create(), geBitmap_Height(), geBitmap_Palette_Create(), geBitmap_Palette_Destroy(), geBitmap_Palette_SetEntryColor(), geBitmap_SetColorKey(), geBitmap_SetPalette(), geBitmap_Width(), geBoolean, geEngine_AddBitmap(), GENESISAPI, GENESISCC, geRam_Free, int16, int32, geFontBitmap::map, geFontBitmap::next, PlaceLetter(), TRUE, and uint32.

00348 {
00349    MAT2 mat2;
00350    GLYPHMETRICS glyphMetrics;
00351    HDC hdc;
00352    DWORD success;
00353    unsigned char asciiValue;
00354    int placedLetter;
00355    int16 mapWidth, mapHeight;
00356    HFONT win32Font, win32OldFont;
00357    geFontBitmap *fontBitmap;
00358    geBitmap_Palette *Palette;
00359    int i;
00360    unsigned char *cellBuffer;
00361    DWORD bufferSize;
00362 
00363    uint32 ggoFormat;
00364 
00365    mat2.eM11.fract = 0;
00366    mat2.eM11.value = 1;
00367    mat2.eM12.fract = 0;
00368    mat2.eM12.value = 0;
00369    mat2.eM21.fract = 0;
00370    mat2.eM21.value = 0;
00371    mat2.eM22.fract = 0;
00372    mat2.eM22.value = 1;
00373 
00374    // get the character bitmap
00375    bufferSize = 32768;
00376    cellBuffer = GE_RAM_ALLOCATE_ARRAY(unsigned char, bufferSize);
00377    memset(cellBuffer,0xee,bufferSize);
00378 
00379 
00380    for (asciiValue = leastIndex; asciiValue <= mostIndex; asciiValue++)
00381    {
00382       placedLetter = FALSE;
00383 
00384       if (font->antialiased)
00385          ggoFormat = GGO_GRAY8_BITMAP;
00386       else
00387          ggoFormat = GGO_BITMAP;                        
00388 
00389       // find out the dimensions of the character
00390         win32Font = CreateFont( -1 * font->fontSize,
00391                                             0,0,0, font->fontWeight,
00392                                             0,0,0,0,OUT_TT_ONLY_PRECIS ,0,0,0, font->fontNameString);
00393 
00394       hdc = GetDC(GetDesktopWindow());
00395       assert(hdc);
00396 
00397       win32OldFont = SelectObject( hdc, win32Font); 
00398       success    = GetGlyphOutline( hdc, asciiValue, ggoFormat, 
00399                                  &glyphMetrics, bufferSize, cellBuffer, &mat2);
00400       SelectObject( hdc, win32OldFont); 
00401 
00402       ReleaseDC(GetDesktopWindow(),hdc);
00403 
00404       DeleteObject(win32Font);
00405 
00406       fontBitmap = font->bitmapList;
00407       while (fontBitmap)
00408       {
00409          // will it fit into the current bitmap?
00410          mapWidth  = geBitmap_Width (fontBitmap->map);
00411          mapHeight = geBitmap_Height(fontBitmap->map);
00412 
00413          // if there's enough vertical space...
00414          if ((int32)glyphMetrics.gmBlackBoxY <= (mapHeight-1) - fontBitmap->freeY)
00415          {
00416             // if there's enough horizontal space...
00417             if (glyphMetrics.gmCellIncX <= (mapWidth-1) - fontBitmap->freeX)
00418             {
00419                // place the letter!
00420                PlaceLetter(fontBitmap->freeX, fontBitmap->freeY, font,
00421                            fontBitmap, asciiValue, cellBuffer, bufferSize); 
00422                placedLetter = TRUE;
00423                fontBitmap->freeX = fontBitmap->freeX + glyphMetrics.gmBlackBoxX;
00424             }
00425             else
00426             {
00427                fontBitmap->freeY = fontBitmap->freeY + font->fontSize;
00428                fontBitmap->freeX = 0;
00429                // if there's enough vertical space...
00430                if ((int32)glyphMetrics.gmBlackBoxY <= (mapHeight-1) - fontBitmap->freeY)
00431                {
00432                   // if there's enough horizontal space...
00433                   if (glyphMetrics.gmCellIncX <= (mapWidth-1) - fontBitmap->freeX)
00434                   {
00435                      // place the letter!
00436                      PlaceLetter(fontBitmap->freeX, fontBitmap->freeY, font,
00437                                  fontBitmap, asciiValue, cellBuffer, bufferSize);
00438                      placedLetter = TRUE;
00439                      fontBitmap->freeX = fontBitmap->freeX + glyphMetrics.gmBlackBoxX;
00440                   }
00441                }
00442             }
00443          }
00444          fontBitmap = fontBitmap->next;
00445       }
00446 
00447       if (!placedLetter)
00448       {
00449          // gotta create a new font bitmap.
00450          fontBitmap = GE_RAM_ALLOCATE_STRUCT(geFontBitmap);
00451          assert(fontBitmap);
00452          fontBitmap->next = font->bitmapList;
00453          font->bitmapList = fontBitmap;
00454          fontBitmap->freeX = 0;
00455          fontBitmap->freeY = 0;
00456          fontBitmap->map = geBitmap_Create(256,256, 1, GE_PIXELFORMAT_8BIT); 
00457 
00458          // and a pallette for it.
00459          Palette = geBitmap_Palette_Create(GE_PIXELFORMAT_32BIT_XRGB, 256);
00460 
00461          for (i = 0; i < 256; i++)
00462          {
00463             success = geBitmap_Palette_SetEntryColor(Palette, i, i, i, i, i);
00464             assert(success);
00465 
00466          }
00467 
00468          success = geBitmap_SetPalette(fontBitmap->map, Palette);
00469          assert(success);
00470 
00471                 success = geBitmap_SetColorKey(fontBitmap->map, TRUE, 0 ,FALSE );
00472 
00473 
00474          success = geBitmap_Palette_Destroy(&Palette);         
00475          assert(success);
00476 
00477 
00478          success = geEngine_AddBitmap((geEngine *)font->Engine, fontBitmap->map);
00479          assert(success);
00480 
00481          PlaceLetter(fontBitmap->freeX, fontBitmap->freeY,  font,
00482                      fontBitmap, asciiValue, cellBuffer, bufferSize);
00483          fontBitmap->freeX = fontBitmap->freeX + glyphMetrics.gmBlackBoxX;
00484 
00485      
00486       }
00487 
00488    }
00489 
00490    geRam_Free(cellBuffer);
00491 
00492    return TRUE;
00493 }

GENESISAPI geFont* GENESISCC geFont_Create const geEngine Engine,
const char *  fontNameString,
const int  fontSize,
const int  fontWeight,
const geBoolean  antialiased
 

Definition at line 104 of file font.c.

References geFont::antialiased, geFont::bitmapList, geFontCharacterRecord::bitmapUsed, geFont::buffer, geFont::characterArray, Engine, geFont::Engine, geFont::fontNameString, geFont::fontSize, geFont::fontWeight, GE_RAM_ALLOCATE_STRUCT, GENESISAPI, GENESISCC, NULL, and geFont::refCount.

00107 {
00108    geFont *font;
00109    int i;
00110 
00111    // create a new font
00112    font = GE_RAM_ALLOCATE_STRUCT(geFont);
00113    assert(font);
00114 
00115    // initalize the new font to having no data in it.
00116    font->bitmapList = NULL;
00117    for (i = 0; i < 256; i++)
00118       font->characterArray[i].bitmapUsed = NULL;
00119 
00120    strncpy(font->fontNameString, fontNameString,64);
00121    font->fontNameString[63] = 0;
00122 
00123    font->fontSize = fontSize;
00124    font->fontWeight = fontWeight;
00125 
00126    font->Engine = Engine;
00127 
00128    font->buffer = NULL;
00129 
00130    font->refCount = 1;
00131 
00132    font->antialiased = anti;
00133 
00134    return font;
00135 }

GENESISAPI void GENESISCC geFont_CreateRef geFont font  ) 
 

Definition at line 138 of file font.c.

References GENESISAPI, GENESISCC, and geFont::refCount.

00139 {
00140    assert(font);
00141    font->refCount++;
00142 }

GENESISAPI void GENESISCC geFont_Destroy geFont **  font  ) 
 

Definition at line 146 of file font.c.

References geBitmap_Destroy(), geEngine_RemoveBitmap(), geFont_DestroyBitmapBuffer(), GENESISAPI, GENESISCC, geRam_Free, geFontBitmap::map, geFontBitmap::next, and NULL.

00147 {
00148 
00149    geFontBitmap *curFontBitmap, *tempFontBitmap;
00150 
00151    assert(*font);
00152 
00153    (*font)->refCount--;
00154 
00155    // don't destroy this font if there's still a reference out there.
00156    if ((*font)->refCount > 0)
00157       return;
00158 
00159    geFont_DestroyBitmapBuffer(*font);
00160 
00161    curFontBitmap = (*font)->bitmapList;
00162    while (curFontBitmap)
00163    {
00164       tempFontBitmap = curFontBitmap->next;
00165 
00166       geEngine_RemoveBitmap((geEngine *) (*font)->Engine, curFontBitmap->map);
00167 
00168       geBitmap_Destroy(&(curFontBitmap->map));
00169       geRam_Free(curFontBitmap);
00170       curFontBitmap = tempFontBitmap;
00171    }
00172 
00173    geRam_Free(*font);
00174    (*font) = NULL;
00175 
00176 }

GENESISAPI void GENESISCC geFont_DestroyBitmapBuffer geFont font  ) 
 

Definition at line 720 of file font.c.

References geFont::buffer, geFont::Engine, geBitmap_Destroy(), geBoolean, geEngine_RemoveBitmap(), GENESISAPI, and GENESISCC.

Referenced by geFont_AddBitmapBuffer(), and geFont_Destroy().

00721 {
00722    geBoolean success;
00723    assert(font);
00724    if (font->buffer)
00725    {
00726       success = geEngine_RemoveBitmap((geEngine *)font->Engine, font->buffer);
00727       assert(success);
00728 
00729       geBitmap_Destroy(&font->buffer);
00730    }
00731 
00732 }

GENESISAPI geBoolean GENESISCC geFont_DrawText geFont font,
const char *  textString,
const GE_Rect Rect,
const GE_RGBA Color,
uint32  flags,
const GE_Rect clipRect
 

Definition at line 496 of file font.c.

References GE_RGBA::a, GE_RGBA::b, geFont::bitmapList, geFontCharacterRecord::bitmapRect, geFontCharacterRecord::bitmapUsed, GE_Rect::Bottom, tagRECT::bottom, geFont::buffer, CalculateClipping(), geFont::characterArray, geFont::Engine, FALSE, geFont::fontSize, geFontCharacterRecord::fullWidth, GE_RGBA::g, GE_CLIP_CORNER, GE_FONT_JUST_RETURN_FIT, GE_FONT_JUSTIFY_CENTER, GE_FONT_JUSTIFY_RIGHT, GE_FONT_WORDWRAP, GE_FONT_WRAP, GE_PIXELFORMAT_32BIT_XRGB, geBitmap_GetPalette(), geBitmap_Height(), geBitmap_Palette_SetData(), geBitmap_SetPalette(), geBitmap_Width(), geBoolean, geEngine_DrawBitmap(), geFloat, geFont_DrawTextToBitmap(), GENESISAPI, GENESISCC, gePixelFormat_ComposePixel(), int32, tagRECT::left, GE_Rect::Left, geFontBitmap::map, NULL, geFontCharacterRecord::offsetX, geFontCharacterRecord::offsetY, GE_RGBA::r, tagRECT::right, GE_Rect::Right, tagRECT::top, GE_Rect::Top, TRUE, uint32, and y.

00499 {
00500 
00501    int32 x,y,i;
00502    int32 tempX;//, tempY;
00503    int32 lineLen;
00504 
00505    uint32 colorArray[256];
00506    geFloat  fcolorX, fcolorR, fcolorG, fcolorB;
00507 
00508    int32 stringLen;
00509    int32 currentCharIndex;
00510    int32 lineEndIndex=0;
00511    geFontCharacterRecord *charRec;
00512 
00513    geBoolean success;
00514    geBoolean longEnough, endOfText;
00515 
00516    GE_Rect artRect;
00517    RECT box;
00518    int32 resultX, resultY;
00519 
00520    geFontBitmap *lastBitmap;
00521    geBitmap_Palette * palette;
00522 
00523    // unimplemented flags which we don't want you to use yet.
00524    assert(!(flags & GE_FONT_WRAP           ));
00525    assert(!(flags & GE_FONT_JUST_RETURN_FIT));
00526    assert(!(flags & GE_FONT_JUSTIFY_RIGHT  ));
00527    assert(!(flags & GE_FONT_JUSTIFY_CENTER ));
00528 
00529    lastBitmap = NULL;
00530    x = 0;
00531    y = 0;
00532    stringLen = strlen(textString);
00533    currentCharIndex = 0;
00534 
00535    if (font->bitmapList)  // if this font has character bitmaps...
00536    {
00537 
00538       while (currentCharIndex < stringLen)
00539       {
00540          // skip leading white space for this line.
00541          while (isspace(textString[currentCharIndex]) && currentCharIndex < stringLen)
00542             currentCharIndex++;
00543 
00544          // if, because of the whitespace skip, we're out of text, exit the loop.
00545          if (currentCharIndex >= stringLen)
00546             break;
00547 
00548          lineLen = 0;
00549          lineEndIndex = currentCharIndex;
00550          longEnough = FALSE;
00551          endOfText = FALSE;
00552          while (!longEnough)
00553          {
00554             charRec = &(font->characterArray[textString[lineEndIndex]]);
00555 
00556             // if the character has art...
00557             if (charRec->bitmapUsed)
00558             {
00559 
00560                if (Rect->Left + lineLen + (charRec->fullWidth) >
00561                    Rect->Right)
00562                    longEnough = TRUE;
00563                else
00564                {
00565                   lineLen = lineLen + (charRec->fullWidth);
00566                   lineEndIndex++;
00567                   if (lineEndIndex >= stringLen)
00568                   {
00569                      longEnough = TRUE;
00570                      endOfText = TRUE;
00571                   }
00572                }
00573             }
00574             else
00575             {
00576                lineEndIndex++;
00577                if (lineEndIndex >= stringLen)
00578                {
00579                   longEnough = TRUE;
00580                   endOfText = TRUE;
00581                }
00582             }
00583          }
00584 
00585          // if we're word-wrapping, back up to BEFORE the last hunk of whitespace.
00586          if (flags & GE_FONT_WORDWRAP && !endOfText)
00587          {
00588             tempX = lineEndIndex;
00589             while (tempX > currentCharIndex && !isspace(textString[tempX]))
00590                tempX--;
00591 
00592             if (isspace(textString[tempX]))
00593             {
00594                while (tempX > currentCharIndex && isspace(textString[tempX]))
00595                   tempX--;
00596 
00597                lineEndIndex = tempX;
00598             }
00599          }
00600 
00601          // aaannnddd,  DRAW!
00602          for (; currentCharIndex <= lineEndIndex && currentCharIndex < stringLen; currentCharIndex++)
00603          {
00604             charRec = &(font->characterArray[textString[currentCharIndex]]);
00605 
00606             if (charRec->bitmapUsed)
00607             {
00608 
00609                if (charRec->bitmapUsed != lastBitmap)
00610                {
00611 
00612                   lastBitmap = charRec->bitmapUsed;
00613 
00614                   palette = geBitmap_GetPalette(lastBitmap->map);
00615                   assert(palette);
00616 
00617                   for (i = 0; i < 256; i++)
00618                   {
00619 
00620                      fcolorR = Color->r * i / 255;
00621                      fcolorG = Color->g * i / 255;
00622                      fcolorB = Color->b * i / 255;
00623                      fcolorX = Color->a * i / 255;
00624 
00625                      colorArray[i] = gePixelFormat_ComposePixel(        GE_PIXELFORMAT_32BIT_XRGB, (int)fcolorR, (int)fcolorG, (int)fcolorB, (int)fcolorX);
00626                   }
00627 
00628                   success = geBitmap_Palette_SetData(   palette ,colorArray,GE_PIXELFORMAT_32BIT_XRGB, 256);
00629            
00630                   success = geBitmap_SetPalette(lastBitmap->map, palette);
00631                   assert(success);
00632 
00633                }
00634             
00635             
00636                if (clipRect)
00637                {
00638                   artRect = charRec->bitmapRect;
00639 
00640                   if ( CalculateClipping( &artRect, &resultX, &resultY, 
00641                               Rect->Left + x + charRec->offsetX, 
00642                               Rect->Top + y + (font->fontSize - charRec->offsetY),
00643                               *clipRect, GE_CLIP_CORNER)
00644                      )
00645                   {
00646                      success = geEngine_DrawBitmap(font->Engine, charRec->bitmapUsed->map,
00647                                                                    &artRect, resultX, resultY);
00648                   }
00649 
00650                }
00651                else
00652                {
00653                  success = geEngine_DrawBitmap(font->Engine, charRec->bitmapUsed->map,
00654                                                                    &(charRec->bitmapRect), Rect->Left + x + charRec->offsetX, 
00655                               Rect->Top + y + (font->fontSize - charRec->offsetY));
00656                }
00657                x += charRec->fullWidth;
00658             }
00659             else
00660             {
00661                // we reached this point because we're trying to draw a character that
00662                // hasn't been added to the font yet using geFont_AddCharacters().
00663                assert(0);
00664             }
00665          
00666          }
00667          y += font->fontSize;
00668          x = 0;
00669       }
00670    }
00671    else // this font has no attached bitmaps, sooo, we do it another way!
00672    {
00673 
00674       // at this point, we're trying to put text to the screen using DrawText() and
00675       // a DIB.  This process REQUIRES an initialized geBitmap as a go-between.
00676       // Is it initialized?
00677       assert(font->buffer);
00678 
00679       box.left   = 0;
00680       box.right  = Rect->Right - Rect->Left;
00681       box.top    = 0;
00682       box.bottom = Rect->Bottom - Rect->Top;
00683 
00684       // does the buffer have sufficient dimensions?
00685       assert (box.right  <= geBitmap_Width (font->buffer)); 
00686       assert (box.bottom <= geBitmap_Height(font->buffer)); 
00687 
00688       artRect.Left   = box.left;
00689       artRect.Right  = box.right;
00690       artRect.Top    = box.top;
00691       artRect.Bottom = box.bottom;
00692 
00693       success = geFont_DrawTextToBitmap(font, textString, &artRect, Color,
00694                                           flags, NULL, font->buffer);
00695 
00696       if (clipRect)
00697       {
00698          if ( CalculateClipping( &artRect, &resultX, &resultY, 
00699                      Rect->Left, 
00700                      Rect->Top,
00701                      *clipRect, GE_CLIP_CORNER)
00702             )
00703          {
00704             success = geEngine_DrawBitmap(font->Engine, font->buffer,
00705                                                 &artRect, resultX, resultY);
00706          }
00707       }
00708       else
00709       {
00710          success = geEngine_DrawBitmap(font->Engine, font->buffer,
00711                                                 &artRect, Rect->Left, Rect->Top);
00712       }
00713    }
00714 
00715    return lineEndIndex;
00716 }

GENESISAPI geBoolean GENESISCC geFont_DrawTextToBitmap geFont font,
const char *  textString,
const GE_Rect Rect,
const GE_RGBA Color,
uint32  flags,
const GE_Rect clipRect,
geBitmap targetBitmap
 

Definition at line 777 of file font.c.

References GE_RGBA::a, GE_RGBA::b, geFont::bitmapList, geFontCharacterRecord::bitmapRect, geFontCharacterRecord::bitmapUsed, tagRECT::bottom, GE_Rect::Bottom, CalculateClipping(), geFont::characterArray, FALSE, geFont::fontSize, geFontCharacterRecord::fullWidth, GE_RGBA::g, GE_CLIP_CORNER, GE_FONT_JUST_RETURN_FIT, GE_FONT_JUSTIFY_CENTER, GE_FONT_JUSTIFY_RIGHT, GE_FONT_WORDWRAP, GE_FONT_WRAP, GE_PIXELFORMAT_32BIT_XRGB, geBitmap_Blit(), geBitmap_GetPalette(), geBitmap_Palette_SetData(), geBitmap_SetPalette(), geBoolean, geFloat, geFont_DrawUsingDIB(), GENESISAPI, GENESISCC, gePixelFormat_ComposePixel(), int32, tagRECT::left, GE_Rect::Left, geFontBitmap::map, NULL, geFontCharacterRecord::offsetX, geFontCharacterRecord::offsetY, GE_RGBA::r, tagRECT::right, GE_Rect::Right, tagRECT::top, GE_Rect::Top, TRUE, uint32, and y.

Referenced by geFont_DrawText().

00781 {
00782 
00783    int32 x,y,i;
00784    int32 tempX;//, tempY;
00785    int32 lineLen;
00786 
00787    uint32 colorArray[256];
00788    geFloat  fcolorX, fcolorR, fcolorG, fcolorB;
00789 
00790    int32 stringLen;
00791    int32 currentCharIndex;
00792    int32 lineEndIndex=0;
00793    geFontCharacterRecord *charRec;
00794 
00795    geBoolean success;
00796    geBoolean longEnough, endOfText;
00797 
00798    GE_Rect artRect;
00799    RECT box;
00800    int32 resultX, resultY;
00801 
00802    geFontBitmap *lastBitmap;
00803    geBitmap_Palette * palette;
00804 
00805 
00806    // unimplemented flags which we don't want you to use yet.
00807    assert(!(flags & GE_FONT_WRAP           ));
00808    assert(!(flags & GE_FONT_JUST_RETURN_FIT));
00809    assert(!(flags & GE_FONT_JUSTIFY_RIGHT  ));
00810    assert(!(flags & GE_FONT_JUSTIFY_CENTER ));
00811 
00812    assert(targetBitmap);
00813 
00814    lastBitmap = NULL;
00815    x = 0;
00816    y = 0;
00817    stringLen = strlen(textString);
00818    currentCharIndex = 0;
00819 
00820    if (font->bitmapList)  // if this font has character bitmaps...
00821    {
00822 
00823       while (currentCharIndex < stringLen)
00824       {
00825          // skip leading white space for this line.
00826          while (isspace(textString[currentCharIndex]) && currentCharIndex < stringLen)
00827             currentCharIndex++;
00828 
00829          // if, because of the whitespace skip, we're out of text, exit the loop.
00830          if (currentCharIndex >= stringLen)
00831             break;
00832 
00833          lineLen = 0;
00834          lineEndIndex = currentCharIndex;
00835          longEnough = FALSE;
00836          endOfText = FALSE;
00837          while (!longEnough)
00838          {
00839             charRec = &(font->characterArray[textString[lineEndIndex]]);
00840 
00841             // if the character has art...
00842             if (charRec->bitmapUsed)
00843             {
00844 
00845                if (Rect->Left + lineLen + (charRec->fullWidth) >
00846                    Rect->Right)
00847                    longEnough = TRUE;
00848                else
00849                {
00850                   lineLen = lineLen + (charRec->fullWidth);
00851                   lineEndIndex++;
00852                   if (lineEndIndex >= stringLen)
00853                   {
00854                      longEnough = TRUE;
00855                      endOfText = TRUE;
00856                   }
00857                }
00858             }
00859             else
00860             {
00861                lineEndIndex++;
00862                if (lineEndIndex >= stringLen)
00863                {
00864                   longEnough = TRUE;
00865                   endOfText = TRUE;
00866                }
00867             }
00868          }
00869 
00870          // if we're word-wrapping, back up to BEFORE the last hunk of whitespace.
00871          if (flags & GE_FONT_WORDWRAP && !endOfText)
00872          {
00873             tempX = lineEndIndex;
00874             while (tempX > currentCharIndex && !isspace(textString[tempX]))
00875                tempX--;
00876 
00877             if (isspace(textString[tempX]))
00878             {
00879                while (tempX > currentCharIndex && isspace(textString[tempX]))
00880                   tempX--;
00881 
00882                lineEndIndex = tempX;
00883             }
00884          }
00885 
00886          // aaannnddd,  DRAW!
00887          for (; currentCharIndex <= lineEndIndex && currentCharIndex < stringLen; currentCharIndex++)
00888          {
00889             charRec = &(font->characterArray[textString[currentCharIndex]]);
00890 
00891             if (charRec->bitmapUsed)
00892             {
00893 
00894                if (charRec->bitmapUsed != lastBitmap)
00895                {
00896 
00897                   lastBitmap = charRec->bitmapUsed;
00898 
00899                   palette = geBitmap_GetPalette(lastBitmap->map);
00900                   assert(palette);
00901 
00902                   for (i = 0; i < 256; i++)
00903                   {
00904 
00905                      fcolorR = Color->r * i / 255;
00906                      fcolorG = Color->g * i / 255;
00907                      fcolorB = Color->b * i / 255;
00908                      fcolorX = Color->a * i / 255;
00909 
00910                      colorArray[i] = gePixelFormat_ComposePixel(        GE_PIXELFORMAT_32BIT_XRGB, (int)fcolorR, (int)fcolorG, (int)fcolorB, (int)fcolorX);
00911                   }
00912 
00913                   success = geBitmap_Palette_SetData(   palette ,colorArray,GE_PIXELFORMAT_32BIT_XRGB, 256);
00914            
00915                   success = geBitmap_SetPalette(lastBitmap->map, palette);
00916                   assert(success);
00917 
00918                }
00919             
00920             
00921                if (clipRect)
00922                {
00923                   artRect = charRec->bitmapRect;
00924 
00925                   if ( CalculateClipping( &artRect, &resultX, &resultY, 
00926                               Rect->Left + x + charRec->offsetX, 
00927                               Rect->Top + y + (font->fontSize - charRec->offsetY),
00928                               *clipRect, GE_CLIP_CORNER)
00929                      )
00930                   {
00931                      success = geBitmap_Blit(charRec->bitmapUsed->map, artRect.Left, artRect.Top,
00932                                                                                    targetBitmap, resultX, resultY,
00933                                                                                    artRect.Right - artRect.Left, artRect.Bottom - artRect.Top );
00934                   }
00935 
00936                }
00937                else
00938                {
00939                   success = geBitmap_Blit(charRec->bitmapUsed->map, charRec->bitmapRect.Left, 
00940                               charRec->bitmapRect.Top, targetBitmap, 
00941                               Rect->Left + x + charRec->offsetX, Rect->Top + y + (font->fontSize - charRec->offsetY),
00942                                                                            charRec->bitmapRect.Right  - charRec->bitmapRect.Left, 
00943                               charRec->bitmapRect.Bottom - charRec->bitmapRect.Top );
00944                }
00945                x += charRec->fullWidth;
00946             }
00947             else
00948             {
00949                // we reached this point because we're trying to draw a character that
00950                // hasn't been added to the font yet using geFont_AddCharacters().
00951                assert(0);
00952             }
00953          
00954          }
00955          y += font->fontSize;
00956          x = 0;
00957       }
00958    }
00959    else // this font has no attached bitmaps, sooo, we do it another way!
00960    {
00961       box.left   = Rect->Left;
00962       box.right  = Rect->Right;
00963       box.top    = Rect->Top;
00964       box.bottom = Rect->Bottom;
00965       success = geFont_DrawUsingDIB(font, textString, box, targetBitmap, Color, flags);
00966    }
00967 
00968    return lineEndIndex;
00969 }

GENESISAPI void GENESISCC geFont_EnableAntialiasing geFont font,
const geBoolean  anti
 

Definition at line 1356 of file font.c.

References geFont::antialiased, GENESISAPI, and GENESISCC.

01357 {
01358    font->antialiased = anti;
01359 }

GENESISAPI geBitmap* GENESISCC geFont_GetBuffer geFont font  ) 
 

Definition at line 1325 of file font.c.

References geFont::buffer, GENESISAPI, and GENESISCC.

01326 {
01327 
01328    return font->buffer;
01329 }

GENESISAPI geBoolean GENESISCC geFont_GetCharMap geFont font,
uint8  character,
GE_Rect Rect,
geBitmap **  targetBitmap,
int32 fullWidth,
int32 fullHeight,
int32 offsetX,
int32 offsetY
 

Definition at line 1333 of file font.c.

References geFontCharacterRecord::bitmapRect, geFontCharacterRecord::bitmapUsed, geFont::characterArray, geFont::fontSize, geFontCharacterRecord::fullWidth, GE_TRUE, geBoolean, GENESISAPI, GENESISCC, geFontBitmap::map, geFontCharacterRecord::offsetX, and geFontCharacterRecord::offsetY.

01336 {
01337 
01338 
01339         assert(font);
01340         assert(font->characterArray[character].bitmapUsed);
01341 
01342         *targetBitmap = font->characterArray[character].bitmapUsed->map;
01343 
01344         *Rect = font->characterArray[character].bitmapRect;
01345 
01346         *fullWidth = font->characterArray[character].fullWidth;
01347         *fullHeight = font->fontSize;
01348         *offsetX = font->characterArray[character].offsetX;
01349         *offsetY = font->characterArray[character].offsetY;
01350 
01351         return GE_TRUE;
01352 }

GENESISAPI int32 GENESISCC geFont_GetStringPixelHeight geFont font,
const char *  textString
 

Definition at line 1299 of file font.c.

References geFont::fontNameString, geFont::fontSize, geFont::fontWeight, GENESISAPI, GENESISCC, and int32.

01300 {
01301 
01302       SIZE sizeInfo;
01303       HDC hdc;
01304            HFONT oldFont, winFont;
01305 
01306       hdc = GetDC(GetDesktopWindow());
01307         winFont = CreateFont( -1 * font->fontSize,
01308                                             0,0,0, font->fontWeight,
01309                                             0,0,0,0,OUT_TT_ONLY_PRECIS ,0,0,0, font->fontNameString);
01310       assert(winFont);
01311 
01312       oldFont = SelectObject( hdc, winFont); 
01313 
01314       GetTextExtentPoint32(  hdc, textString, strlen(textString), &sizeInfo);
01315 
01316         SelectObject(hdc,oldFont);
01317       DeleteObject(winFont);
01318 
01319       ReleaseDC(GetDesktopWindow(), hdc);
01320 
01321       return sizeInfo.cy;
01322 }

GENESISAPI int32 GENESISCC geFont_GetStringPixelWidth geFont font,
const char *  textString
 

Definition at line 1256 of file font.c.

References geFont::bitmapList, geFontCharacterRecord::bitmapUsed, geFont::characterArray, geFont::fontNameString, geFont::fontSize, geFont::fontWeight, geFontCharacterRecord::fullWidth, GENESISAPI, GENESISCC, int32, and width.

01257 {
01258 
01259    if (font->bitmapList)
01260    {
01261       int32 i, width;
01262 
01263       width = 0;
01264       for (i = 0; i < (int32)strlen(textString); i++)
01265       {
01266          assert (font->characterArray[textString[i]].bitmapUsed);
01267 
01268          width += font->characterArray[textString[i]].fullWidth;
01269       }
01270 
01271       return width;
01272    }
01273    else
01274    {
01275       SIZE sizeInfo;
01276       HDC hdc;
01277            HFONT oldFont, winFont;
01278 
01279       hdc = GetDC(GetDesktopWindow());
01280         winFont = CreateFont( -1 * font->fontSize,
01281                                             0,0,0, font->fontWeight,
01282                                             0,0,0,0,OUT_TT_ONLY_PRECIS ,0,0,0, font->fontNameString);
01283       assert(winFont);
01284 
01285       oldFont = SelectObject( hdc, winFont); 
01286 
01287       GetTextExtentPoint32(  hdc, textString, strlen(textString), &sizeInfo);
01288 
01289         SelectObject(hdc,oldFont);
01290       DeleteObject(winFont);
01291 
01292       ReleaseDC(GetDesktopWindow(), hdc);
01293 
01294       return sizeInfo.cx;
01295    }
01296 }

GENESISAPI geBoolean GENESISCC geFont_IsAntialiased geFont font  ) 
 

Definition at line 1362 of file font.c.

References geFont::antialiased, geBoolean, GENESISAPI, and GENESISCC.

01363 {
01364    return font->antialiased;
01365 }


Generated on Tue Sep 30 12:37:31 2003 for GTestAndEngine by doxygen 1.3.2