Browse Source

Accept plStrings in plDynamicTextMap for rendering and font names

Michael Hansen 11 years ago
parent
commit
939f6c3d41
  1. 12
      Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp
  2. 2
      Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.h
  3. 31
      Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.cpp
  4. 20
      Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.h
  5. 69
      Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp
  6. 23
      Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h
  7. 44
      Sources/Plasma/PubUtilLib/plGImage/plFont.cpp
  8. 26
      Sources/Plasma/PubUtilLib/plGImage/plFont.h
  9. 28
      Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp
  10. 2
      Sources/Plasma/PubUtilLib/plGImage/plFontCache.h
  11. 23
      Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp
  12. 10
      Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h
  13. 6
      Sources/Tools/plFontConverter/plFontConverterProc.cpp

12
Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp

@ -2608,10 +2608,10 @@ void pfJournalBook::IRenderPage( uint32_t page, uint32_t whichDTMap, bool sup
uint32_t idx; uint32_t idx;
uint16_t width, height, y, x, ascent, lastX, lastY; uint16_t width, height, y, x, ascent, lastX, lastY;
uint8_t fontFlags, fontSize; uint8_t fontFlags, fontSize;
const wchar_t *fontFace; plString fontFace;
hsColorRGBA fontColor; hsColorRGBA fontColor;
int16_t fontSpacing; int16_t fontSpacing;
bool needSFX = false; bool needSFX = false;
// Find and set initial font properties // Find and set initial font properties
@ -3339,7 +3339,7 @@ void pfJournalBook::ISetDecalLayers(hsGMaterial *material,hsTArray<plLayerInterf
// Starting at the given chunk, works backwards to determine the full set of current // Starting at the given chunk, works backwards to determine the full set of current
// font properties at that point, or assigns defaults if none were specified // font properties at that point, or assigns defaults if none were specified
void pfJournalBook::IFindFontProps( uint32_t chunkIdx, const wchar_t *&face, uint8_t &size, uint8_t &flags, hsColorRGBA &color, int16_t &spacing ) void pfJournalBook::IFindFontProps( uint32_t chunkIdx, plString &face, uint8_t &size, uint8_t &flags, hsColorRGBA &color, int16_t &spacing )
{ {
enum Which enum Which
{ {
@ -3369,7 +3369,7 @@ void pfJournalBook::IFindFontProps( uint32_t chunkIdx, const wchar_t *&face,
// What do we (still) need? // What do we (still) need?
if( !( found & kFace ) && chunk->fText != L"" ) if( !( found & kFace ) && chunk->fText != L"" )
{ {
face = chunk->fText.c_str(); face = plString::FromWchar(chunk->fText.c_str());
found |= kFace; found |= kFace;
} }
if( !( found & kSize ) && chunk->fFontSize > 0 ) if( !( found & kSize ) && chunk->fFontSize > 0 )
@ -3403,7 +3403,7 @@ void pfJournalBook::IFindFontProps( uint32_t chunkIdx, const wchar_t *&face,
// Set any un-found defaults // Set any un-found defaults
if( !( found & kFace ) ) if( !( found & kFace ) )
face = L"Arial"; face = "Arial";
if( !( found & kSize ) ) if( !( found & kSize ) )
size = 24; size = 24;
if( !( found & kFlags ) ) if( !( found & kFlags ) )

2
Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.h

@ -535,7 +535,7 @@ class pfJournalBook : public hsKeyedObject
// Starting at the given chunk, works backwards to determine the full set of current // Starting at the given chunk, works backwards to determine the full set of current
// font properties at that point, or assigns defaults if none were specified // font properties at that point, or assigns defaults if none were specified
void IFindFontProps( uint32_t chunkIdx, const wchar_t *&face, uint8_t &size, uint8_t &flags, hsColorRGBA &color, int16_t &spacing ); void IFindFontProps( uint32_t chunkIdx, plString &face, uint8_t &size, uint8_t &flags, hsColorRGBA &color, int16_t &spacing );
// Find the last paragraph chunk and thus the last par alignment settings // Find the last paragraph chunk and thus the last par alignment settings
uint8_t IFindLastAlignment( void ) const; uint8_t IFindLastAlignment( void ) const;

31
Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.cpp

@ -86,7 +86,6 @@ plDynSurfaceWriter::plWinSurface::plWinSurface()
fWidth = fHeight = 0; fWidth = fHeight = 0;
fSaveNum = 0; fSaveNum = 0;
fFontFace = nil;
fFontSize = 0; fFontSize = 0;
fFontFlags = 0; fFontFlags = 0;
fFontAntiAliasRGB = false; fFontAntiAliasRGB = false;
@ -207,8 +206,7 @@ void plDynSurfaceWriter::plWinSurface::Release( void )
fBits = nil; fBits = nil;
fWidth = fHeight = 0; fWidth = fHeight = 0;
delete [] fFontFace; fFontFace = plString::Null;
fFontFace = nil;
fFontSize = 0; fFontSize = 0;
fFontFlags = 0; fFontFlags = 0;
fFontAntiAliasRGB = false; fFontAntiAliasRGB = false;
@ -231,19 +229,18 @@ static int SafeStrCmp( const char *str1, const char *str2 )
return -1; return -1;
} }
bool plDynSurfaceWriter::plWinSurface::FontMatches( const char *face, uint16_t size, uint8_t flags, bool aaRGB ) bool plDynSurfaceWriter::plWinSurface::FontMatches( const plString &face, uint16_t size, uint8_t flags, bool aaRGB )
{ {
if( SafeStrCmp( face, fFontFace ) == 0 && fFontSize == size && if( face == fFontFace && fFontSize == size &&
fFontFlags == flags && fFontAntiAliasRGB == aaRGB ) fFontFlags == flags && fFontAntiAliasRGB == aaRGB )
return true; return true;
return false; return false;
} }
void plDynSurfaceWriter::plWinSurface::SetFont( const char *face, uint16_t size, uint8_t flags, bool aaRGB ) void plDynSurfaceWriter::plWinSurface::SetFont( const plString &face, uint16_t size, uint8_t flags, bool aaRGB )
{ {
delete [] fFontFace; fFontFace = face;
fFontFace = ( face != nil ) ? hsStrcpy( face ) : nil;
fFontSize = size; fFontSize = size;
fFontFlags = flags; fFontFlags = flags;
fFontAntiAliasRGB = aaRGB; fFontAntiAliasRGB = aaRGB;
@ -256,7 +253,7 @@ void plDynSurfaceWriter::plWinSurface::SetFont( const char *face, uint16_t si
fFont = nil; fFont = nil;
} }
if( face == nil ) if (face.IsEmpty())
return; return;
bool bold = ( fFontFlags & plDynSurfaceWriter::kFontBold ) ? true : false; bool bold = ( fFontFlags & plDynSurfaceWriter::kFontBold ) ? true : false;
@ -283,10 +280,10 @@ void plDynSurfaceWriter::plWinSurface::SetFont( const char *face, uint16_t si
if( fFont == nil ) if( fFont == nil )
{ {
hsAssert( false, "Cannot create Windows font for plDynSurfaceWriter" ); hsAssert( false, "Cannot create Windows font for plDynSurfaceWriter" );
plStatusLog::AddLineS( "pipeline.log", "ERROR: Cannot allocate font for RGB surface! (face: %s, size: %d %s %s)", face, nHeight, bold ? "bold" : "", italic ? "italic" : "" ); plStatusLog::AddLineS( "pipeline.log", "ERROR: Cannot allocate font for RGB surface! (face: %s, size: %d %s %s)",
face.c_str(), nHeight, bold ? "bold" : "", italic ? "italic" : "" );
delete [] fFontFace; fFontFace = plString::Null;
fFontFace = nil;
fFontSize = 0; fFontSize = 0;
return; return;
} }
@ -385,7 +382,7 @@ void plDynSurfaceWriter::IInit( void )
fJustify = kLeftJustify; fJustify = kLeftJustify;
fFlags = 0; fFlags = 0;
fFlushed = true; fFlushed = true;
fFontFace = nil; fFontFace = plString::Null;
fFontSize = 0; fFontSize = 0;
fFontBlockedRGB = false; fFontBlockedRGB = false;
} }
@ -401,8 +398,7 @@ void plDynSurfaceWriter::Reset( void )
fCurrTarget = nil; fCurrTarget = nil;
fFlushed = true; fFlushed = true;
delete [] fFontFace; fFontFace = plString::Null;
fFontFace = nil;
fFontSize = 0; fFontSize = 0;
} }
@ -514,8 +510,7 @@ void plDynSurfaceWriter::SwitchTarget( plDynamicTextMap *target )
if( hadToAllocate ) if( hadToAllocate )
{ {
delete [] fFontFace; fFontFace = plString::Null;
fFontFace = nil;
fFontSize = 0; fFontSize = 0;
fFontFlags = 0; fFontFlags = 0;
} }
@ -701,7 +696,7 @@ void plDynSurfaceWriter::SetFont( const char *face, uint16_t size, uint8_t fo
//// ISetFont ///////////////////////////////////////////////////////////////// //// ISetFont /////////////////////////////////////////////////////////////////
void plDynSurfaceWriter::ISetFont( const char *face, uint16_t size, uint8_t fontFlags, bool antiAliasRGB ) void plDynSurfaceWriter::ISetFont( const plString &face, uint16_t size, uint8_t fontFlags, bool antiAliasRGB )
{ {
fFlags = ( fFlags & ~kFontShadowed ) | ( fontFlags & kFontShadowed ); fFlags = ( fFlags & ~kFontShadowed ) | ( fontFlags & kFontShadowed );

20
Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.h

@ -148,16 +148,16 @@ class plDynSurfaceWriter
void IRefreshOSJustify( void ); void IRefreshOSJustify( void );
void ISetTextColor( hsColorRGBA &color, bool blockRGB ); void ISetTextColor( hsColorRGBA &color, bool blockRGB );
void ISetFont( const char *face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true ); void ISetFont( const plString &face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true );
plDynamicTextMap *fCurrTarget; plDynamicTextMap *fCurrTarget;
uint32_t fFlags; uint32_t fFlags;
Justify fJustify; Justify fJustify;
bool fFlushed; bool fFlushed;
char *fFontFace; plString fFontFace;
uint16_t fFontSize; uint16_t fFontSize;
uint8_t fFontFlags; uint8_t fFontFlags;
bool fFontAntiAliasRGB; bool fFontAntiAliasRGB;
bool fFontBlockedRGB; bool fFontBlockedRGB;
@ -180,11 +180,11 @@ class plDynSurfaceWriter
COLORREF fTextColor; COLORREF fTextColor;
int fSaveNum; int fSaveNum;
uint16_t fWidth, fHeight; uint16_t fWidth, fHeight;
char *fFontFace; plString fFontFace;
uint16_t fFontSize; uint16_t fFontSize;
uint8_t fFontFlags; uint8_t fFontFlags;
bool fFontAntiAliasRGB, fFontBlockedRGB; bool fFontAntiAliasRGB, fFontBlockedRGB;
plWinSurface(); plWinSurface();
@ -194,8 +194,8 @@ class plDynSurfaceWriter
void Release( void ); void Release( void );
bool WillFit( uint16_t w, uint16_t h ); bool WillFit( uint16_t w, uint16_t h );
bool FontMatches( const char *face, uint16_t size, uint8_t flags, bool aaRGB ); bool FontMatches( const plString &face, uint16_t size, uint8_t flags, bool aaRGB );
void SetFont( const char *face, uint16_t size, uint8_t flags, bool aaRGB ); void SetFont( const plString &face, uint16_t size, uint8_t flags, bool aaRGB );
}; };
class plWinRGBSurface : public plWinSurface class plWinRGBSurface : public plWinSurface

69
Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp

@ -77,7 +77,7 @@ plProfile_Extern(MemMipmaps);
plDynamicTextMap::plDynamicTextMap() plDynamicTextMap::plDynamicTextMap()
: fVisWidth(0), fVisHeight(0), fHasAlpha(false), fJustify(kLeftJustify), : fVisWidth(0), fVisHeight(0), fHasAlpha(false), fJustify(kLeftJustify),
fInitBuffer(nullptr), fFontFace(nullptr), fFontSize(0), fFontFlags(0), fInitBuffer(nullptr), fFontSize(0), fFontFlags(0),
fFontAntiAliasRGB(false), fFontBlockRGB(false), fHasCreateBeenCalled(false) fFontAntiAliasRGB(false), fFontBlockRGB(false), fHasCreateBeenCalled(false)
{ {
fFontColor.Set(0, 0, 0, 1); fFontColor.Set(0, 0, 0, 1);
@ -89,7 +89,7 @@ plDynamicTextMap::~plDynamicTextMap()
} }
plDynamicTextMap::plDynamicTextMap( uint32_t width, uint32_t height, bool hasAlpha, uint32_t extraWidth, uint32_t extraHeight ) plDynamicTextMap::plDynamicTextMap( uint32_t width, uint32_t height, bool hasAlpha, uint32_t extraWidth, uint32_t extraHeight )
: fInitBuffer(nullptr), fFontFace(nullptr) : fInitBuffer(nullptr)
{ {
Create( width, height, hasAlpha, extraWidth, extraHeight ); Create( width, height, hasAlpha, extraWidth, extraHeight );
} }
@ -163,8 +163,7 @@ void plDynamicTextMap::Reset( void )
delete [] fInitBuffer; delete [] fInitBuffer;
fInitBuffer = nil; fInitBuffer = nil;
delete [] fFontFace; fFontFace = plString::Null;
fFontFace = nil;
// Destroy the old texture ref, since we're no longer using it // Destroy the old texture ref, since we're no longer using it
SetDeviceRef( nil ); SetDeviceRef( nil );
@ -413,22 +412,21 @@ void plDynamicTextMap::SetJustify( Justify j )
//// SetFont ////////////////////////////////////////////////////////////////// //// SetFont //////////////////////////////////////////////////////////////////
void plDynamicTextMap::SetFont( const char *face, uint16_t size, uint8_t fontFlags, bool antiAliasRGB ) void plDynamicTextMap::SetFont( const plString &face, uint16_t size, uint8_t fontFlags, bool antiAliasRGB )
{ {
// ===> Don't need to validate creation // ===> Don't need to validate creation
// if( !IIsValid() ) // if( !IIsValid() )
// return; // return;
delete [] fFontFace;
if (plLocalization::UsingUnicode()) if (plLocalization::UsingUnicode())
{ {
// unicode has a bunch of chars that most fonts don't have, so we override the font choice with one // unicode has a bunch of chars that most fonts don't have, so we override the font choice with one
// that will work with the desired language // that will work with the desired language
hsStatusMessageF("We are using a unicode language, overriding font choice of %s", face ? face : "nil"); hsStatusMessageF("We are using a unicode language, overriding font choice of %s", face.c_str("nil"));
fFontFace = hsStrcpy( "Unicode" ); fFontFace = "Unicode";
} }
else else
fFontFace = ( face != nil ) ? hsStrcpy( face ) : nil; fFontFace = face;
fFontSize = size; fFontSize = size;
fFontFlags = fontFlags; fFontFlags = fontFlags;
fFontAntiAliasRGB = antiAliasRGB; fFontAntiAliasRGB = antiAliasRGB;
@ -439,11 +437,9 @@ void plDynamicTextMap::SetFont( const char *face, uint16_t size, uint8_t font
if ( fCurrFont == nil ) if ( fCurrFont == nil )
{ {
if (!fCurrFont) if (!fCurrFont)
hsStatusMessageF("Font missing - %s. Using Arial", fFontFace ? fFontFace : "nil"); hsStatusMessageF("Font missing - %s. Using Arial", fFontFace.c_str("nil"));
if ( fFontFace ) fFontFace = "Arial";
delete [] fFontFace;
fFontFace = hsStrcpy( "Arial" );
// lets try again with Arial // lets try again with Arial
fCurrFont = plFontCache::GetInstance().GetFont( fFontFace, (uint8_t)fFontSize, fCurrFont = plFontCache::GetInstance().GetFont( fFontFace, (uint8_t)fFontSize,
( ( fFontFlags & kFontBold ) ? plFont::kFlagBold : 0 ) | ( ( fFontFlags & kFontBold ) ? plFont::kFlagBold : 0 ) |
@ -458,13 +454,6 @@ void plDynamicTextMap::SetFont( const char *face, uint16_t size, uint8_t font
} }
} }
void plDynamicTextMap::SetFont( const wchar_t *face, uint16_t size, uint8_t fontFlags , bool antiAliasRGB )
{
char *sFace = hsWStringToString(face);
SetFont(sFace,size,fontFlags,antiAliasRGB);
delete [] sFace;
}
//// SetLineSpacing /////////////////////////////////////////////////////////// //// SetLineSpacing ///////////////////////////////////////////////////////////
void plDynamicTextMap::SetLineSpacing( int16_t spacing ) void plDynamicTextMap::SetLineSpacing( int16_t spacing )
@ -515,11 +504,10 @@ void plDynamicTextMap::DrawString( uint16_t x, uint16_t y, const wchar_t *tex
//// DrawClippedString //////////////////////////////////////////////////////// //// DrawClippedString ////////////////////////////////////////////////////////
void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const char *text, uint16_t width, uint16_t height ) void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const plString &text, uint16_t width, uint16_t height )
{ {
wchar_t *wText = hsStringToWString(text); // TEMP
DrawClippedString(x,y,wText,width,height); DrawClippedString(x, y, text.ToWchar().GetData(), width, height);
delete [] wText;
} }
void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t width, uint16_t height ) void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t width, uint16_t height )
@ -536,11 +524,10 @@ void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t
//// DrawClippedString //////////////////////////////////////////////////////// //// DrawClippedString ////////////////////////////////////////////////////////
void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const char *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ) void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const plString &text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height )
{ {
wchar_t *wText = hsStringToWString(text); // TEMP
DrawClippedString(x,y,wText,clipX,clipY,width,height); DrawClippedString(x, y, text.ToWchar().GetData(), width, height);
delete [] wText;
} }
void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ) void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height )
@ -556,11 +543,10 @@ void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t
//// DrawWrappedString //////////////////////////////////////////////////////// //// DrawWrappedString ////////////////////////////////////////////////////////
void plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const char *text, uint16_t width, uint16_t height, uint16_t *lastX, uint16_t *lastY ) void plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const plString &text, uint16_t width, uint16_t height, uint16_t *lastX, uint16_t *lastY )
{ {
wchar_t *wText = hsStringToWString(text); // TEMP
DrawWrappedString(x,y,wText,width,height,lastX,lastY); DrawWrappedString(x, y, text.ToWchar().GetData(), width, height, lastX, lastY);
delete [] wText;
} }
void plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const wchar_t *text, uint16_t width, uint16_t height, uint16_t *lastX, uint16_t *lastY ) void plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const wchar_t *text, uint16_t width, uint16_t height, uint16_t *lastX, uint16_t *lastY )
@ -577,12 +563,10 @@ void plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const wchar
//// CalcStringWidth ////////////////////////////////////////////////////////// //// CalcStringWidth //////////////////////////////////////////////////////////
uint16_t plDynamicTextMap::CalcStringWidth( const char *text, uint16_t *height ) uint16_t plDynamicTextMap::CalcStringWidth( const plString &text, uint16_t *height )
{ {
wchar_t *wText = hsStringToWString(text); // TEMP
uint16_t w = CalcStringWidth(wText,height); return CalcStringWidth(text.ToWchar().GetData(), height);
delete [] wText;
return w;
} }
uint16_t plDynamicTextMap::CalcStringWidth( const wchar_t *text, uint16_t *height ) uint16_t plDynamicTextMap::CalcStringWidth( const wchar_t *text, uint16_t *height )
@ -614,11 +598,10 @@ void plDynamicTextMap::SetFirstLineIndent( int16_t indent )
//// CalcWrappedStringSize //////////////////////////////////////////////////// //// CalcWrappedStringSize ////////////////////////////////////////////////////
void plDynamicTextMap::CalcWrappedStringSize( const char *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar, uint16_t *maxAscent, uint16_t *lastX, uint16_t *lastY ) void plDynamicTextMap::CalcWrappedStringSize( const plString &text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar, uint16_t *maxAscent, uint16_t *lastX, uint16_t *lastY )
{ {
wchar_t *wText = hsStringToWString(text); // TEMP
CalcWrappedStringSize(wText,width,height,firstClippedChar,maxAscent,lastX,lastY); CalcWrappedStringSize(text.ToWchar().GetData(), width, height, firstClippedChar, maxAscent, lastX, lastY);
delete [] wText;
} }
void plDynamicTextMap::CalcWrappedStringSize( const wchar_t *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar, uint16_t *maxAscent, uint16_t *lastX, uint16_t *lastY ) void plDynamicTextMap::CalcWrappedStringSize( const wchar_t *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar, uint16_t *maxAscent, uint16_t *lastX, uint16_t *lastY )
@ -816,7 +799,7 @@ bool plDynamicTextMap::MsgReceive( plMessage *msg )
SetTextColor( textMsg->fColor, textMsg->fBlockRGB ); SetTextColor( textMsg->fColor, textMsg->fBlockRGB );
if( (textMsg->fCmd & plDynamicTextMsg::kSetFont ) && !textMsg->fString.IsNull()) if( (textMsg->fCmd & plDynamicTextMsg::kSetFont ) && !textMsg->fString.IsNull())
SetFont( textMsg->fString.ToWchar(), textMsg->fX, (uint8_t)(textMsg->fFlags) ); SetFont( textMsg->fString, textMsg->fX, (uint8_t)(textMsg->fFlags) );
if( textMsg->fCmd & plDynamicTextMsg::kSetLineSpacing ) if( textMsg->fCmd & plDynamicTextMsg::kSetLineSpacing )
SetLineSpacing( textMsg->fLineSpacing ); SetLineSpacing( textMsg->fLineSpacing );
@ -902,7 +885,7 @@ void plDynamicTextMap::Swap( plDynamicTextMap *other )
SWAP_ME( bool, fShadowed, other->fShadowed ); SWAP_ME( bool, fShadowed, other->fShadowed );
SWAP_ME( Justify, fJustify, other->fJustify ); SWAP_ME( Justify, fJustify, other->fJustify );
SWAP_ME( char *, fFontFace, other->fFontFace ); SWAP_ME( plString, fFontFace, other->fFontFace );
SWAP_ME( uint16_t, fFontSize, other->fFontSize ); SWAP_ME( uint16_t, fFontSize, other->fFontSize );
SWAP_ME( uint8_t, fFontFlags, other->fFontFlags ); SWAP_ME( uint8_t, fFontFlags, other->fFontFlags );
SWAP_ME( bool, fFontAntiAliasRGB, other->fFontAntiAliasRGB ); SWAP_ME( bool, fFontAntiAliasRGB, other->fFontAntiAliasRGB );

23
Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h

@ -152,23 +152,22 @@ class plDynamicTextMap : public plMipmap
kFontShadowed = 0x04 kFontShadowed = 0x04
}; };
void SetFont( const char *face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true ); void SetFont( const plString &face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true );
void SetFont( const wchar_t *face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true );
void SetLineSpacing( int16_t spacing ); void SetLineSpacing( int16_t spacing );
void SetTextColor( hsColorRGBA &color, bool blockRGB = false ); void SetTextColor( hsColorRGBA &color, bool blockRGB = false );
void SetJustify( Justify j ); void SetJustify( Justify j );
void DrawString( uint16_t x, uint16_t y, const char *text ); void DrawString( uint16_t x, uint16_t y, const char *text );
void DrawString( uint16_t x, uint16_t y, const wchar_t *text ); void DrawString( uint16_t x, uint16_t y, const wchar_t *text );
void DrawClippedString( int16_t x, int16_t y, const char *text, uint16_t width, uint16_t height ); void DrawClippedString( int16_t x, int16_t y, const plString &text, uint16_t width, uint16_t height );
void DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t width, uint16_t height ); void DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t width, uint16_t height );
void DrawClippedString( int16_t x, int16_t y, const char *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ); void DrawClippedString( int16_t x, int16_t y, const plString &text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height );
void DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ); void DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height );
void DrawWrappedString( uint16_t x, uint16_t y, const char *text, uint16_t width, uint16_t height, uint16_t *lastX = nil, uint16_t *lastY = nil ); void DrawWrappedString( uint16_t x, uint16_t y, const plString &text, uint16_t width, uint16_t height, uint16_t *lastX = nil, uint16_t *lastY = nil );
void DrawWrappedString( uint16_t x, uint16_t y, const wchar_t *text, uint16_t width, uint16_t height, uint16_t *lastX = nil, uint16_t *lastY = nil ); void DrawWrappedString( uint16_t x, uint16_t y, const wchar_t *text, uint16_t width, uint16_t height, uint16_t *lastX = nil, uint16_t *lastY = nil );
uint16_t CalcStringWidth( const char *text, uint16_t *height = nil ); uint16_t CalcStringWidth( const plString &text, uint16_t *height = nil );
uint16_t CalcStringWidth( const wchar_t *text, uint16_t *height = nil ); uint16_t CalcStringWidth( const wchar_t *text, uint16_t *height = nil );
void CalcWrappedStringSize( const char *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar = nil, uint16_t *maxAscent = nil, uint16_t *lastX = nil, uint16_t *lastY = nil ); void CalcWrappedStringSize( const plString &text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar = nil, uint16_t *maxAscent = nil, uint16_t *lastX = nil, uint16_t *lastY = nil );
void CalcWrappedStringSize( const wchar_t *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar = nil, uint16_t *maxAscent = nil, uint16_t *lastX = nil, uint16_t *lastY = nil ); void CalcWrappedStringSize( const wchar_t *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar = nil, uint16_t *maxAscent = nil, uint16_t *lastX = nil, uint16_t *lastY = nil );
void FillRect( uint16_t x, uint16_t y, uint16_t width, uint16_t height, hsColorRGBA &color ); void FillRect( uint16_t x, uint16_t y, uint16_t width, uint16_t height, hsColorRGBA &color );
void FrameRect( uint16_t x, uint16_t y, uint16_t width, uint16_t height, hsColorRGBA &color ); void FrameRect( uint16_t x, uint16_t y, uint16_t width, uint16_t height, hsColorRGBA &color );
@ -201,8 +200,8 @@ class plDynamicTextMap : public plMipmap
// Gets for font values // Gets for font values
Justify GetFontJustify( void ) const { return fJustify; } Justify GetFontJustify( void ) const { return fJustify; }
const char *GetFontFace( void ) const { return fFontFace; } plString GetFontFace( void ) const { return fFontFace; }
uint16_t GetFontSize( void ) const { return fFontSize; } uint16_t GetFontSize( void ) const { return fFontSize; }
bool GetFontAARGB( void ) const { return fFontAntiAliasRGB; } bool GetFontAARGB( void ) const { return fFontAntiAliasRGB; }
hsColorRGBA GetFontColor( void ) const { return fFontColor; } hsColorRGBA GetFontColor( void ) const { return fFontColor; }
bool GetFontBlockRGB( void ) const { return fFontBlockRGB; } bool GetFontBlockRGB( void ) const { return fFontBlockRGB; }
@ -225,9 +224,9 @@ class plDynamicTextMap : public plMipmap
bool fHasAlpha, fShadowed; bool fHasAlpha, fShadowed;
Justify fJustify; Justify fJustify;
char *fFontFace; plString fFontFace;
uint16_t fFontSize; uint16_t fFontSize;
uint8_t fFontFlags; uint8_t fFontFlags;
bool fFontAntiAliasRGB; bool fFontAntiAliasRGB;
hsColorRGBA fFontColor; hsColorRGBA fFontColor;
bool fFontBlockRGB; bool fFontBlockRGB;

44
Sources/Plasma/PubUtilLib/plGImage/plFont.cpp

@ -117,7 +117,7 @@ void plFont::IClear( bool onConstruct )
if( !onConstruct ) if( !onConstruct )
delete [] fBMapData; delete [] fBMapData;
memset( fFace, 0, sizeof( fFace ) ); fFace = plString::Null;
fSize = 0; fSize = 0;
fFlags = 0; fFlags = 0;
@ -141,16 +141,6 @@ void plFont::IClear( bool onConstruct )
fRenderInfo.fLineSpacing = 0; fRenderInfo.fLineSpacing = 0;
} }
void plFont::SetFace( const char *face )
{
strncpy( fFace, face, sizeof( fFace ) );
}
void plFont::SetSize( uint8_t size )
{
fSize = size;
}
void plFont::Read( hsStream *s, hsResMgr *mgr ) void plFont::Read( hsStream *s, hsResMgr *mgr )
{ {
hsKeyedObject::Read( s, mgr ); hsKeyedObject::Read( s, mgr );
@ -232,12 +222,10 @@ static inline bool IIsDrawableWordBreak( const char c )
// The base render function. Additional options are specified externally, // The base render function. Additional options are specified externally,
// so that their effects can be cached for optimization // so that their effects can be cached for optimization
void plFont::RenderString( plMipmap *mip, uint16_t x, uint16_t y, const char *string, uint16_t *lastX, uint16_t *lastY ) void plFont::RenderString( plMipmap *mip, uint16_t x, uint16_t y, const plString &string, uint16_t *lastX, uint16_t *lastY )
{ {
// convert the char string to a wchar_t string // TEMP
wchar_t *wideString = hsStringToWString(string); RenderString(mip, x, y, string.ToWchar().GetData(), lastX, lastY);
RenderString(mip,x,y,wideString,lastX,lastY);
delete [] wideString;
} }
@ -990,7 +978,7 @@ void plFont::IRenderCharNull( const plCharacter &c )
//// CalcString Variations //////////////////////////////////////////////////// //// CalcString Variations ////////////////////////////////////////////////////
uint16_t plFont::CalcStringWidth( const char *string ) uint16_t plFont::CalcStringWidth( const plString &string )
{ {
uint16_t w, h, a, lX, lY; uint16_t w, h, a, lX, lY;
uint32_t s; uint32_t s;
@ -1006,12 +994,10 @@ uint16_t plFont::CalcStringWidth( const wchar_t *string )
return w; return w;
} }
void plFont::CalcStringExtents( const char *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ) void plFont::CalcStringExtents( const plString &string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY )
{ {
// convert the char string to a wchar_t string // convert the char string to a wchar_t string
wchar_t *wideString = hsStringToWString(string); CalcStringExtents(string.ToWchar().GetData(), width, height, ascent, firstClippedChar, lastX, lastY);
CalcStringExtents(wideString,width,height,ascent,firstClippedChar,lastX,lastY);
delete [] wideString;
} }
void plFont::CalcStringExtents( const wchar_t *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ) void plFont::CalcStringExtents( const wchar_t *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY )
@ -1197,7 +1183,7 @@ bool plFont::LoadFromFNTStream( hsStream *stream )
charEntries[ i ].offset = stream->ReadLE32(); charEntries[ i ].offset = stream->ReadLE32();
} }
char faceName[ 256 ], deviceName[ 256 ]; char faceName[ 257 ], deviceName[ 256 ];
if( fntInfo.face != 0 ) if( fntInfo.face != 0 )
{ {
stream->SetPosition( fntInfo.face ); stream->SetPosition( fntInfo.face );
@ -1207,7 +1193,8 @@ bool plFont::LoadFromFNTStream( hsStream *stream )
if( faceName[ i ] == 0 ) if( faceName[ i ] == 0 )
break; break;
} }
strncpy( fFace, faceName, sizeof( fFace ) ); faceName[256] = 0;
fFace = faceName;
} }
if( fntInfo.device != 0 ) if( fntInfo.device != 0 )
{ {
@ -1926,7 +1913,11 @@ bool plFont::LoadFromBDF( const char *path, plBDFConvertCallback *callback )
bool plFont::ReadRaw( hsStream *s ) bool plFont::ReadRaw( hsStream *s )
{ {
s->Read( sizeof( fFace ), fFace ); char face_buf[257];
s->Read(256, face_buf);
face_buf[256] = 0;
fFace = face_buf;
fSize = s->ReadByte(); fSize = s->ReadByte();
s->ReadLE( &fFlags ); s->ReadLE( &fFlags );
@ -1959,7 +1950,10 @@ bool plFont::ReadRaw( hsStream *s )
bool plFont::WriteRaw( hsStream *s ) bool plFont::WriteRaw( hsStream *s )
{ {
s->Write( sizeof( fFace ), fFace ); char face_buf[256] = { 0 };
memcpy(face_buf, fFace.c_str(), fFace.GetSize() * sizeof(char));
s->Write(sizeof(face_buf), face_buf);
s->WriteByte( fSize ); s->WriteByte( fSize );
s->WriteLE( fFlags ); s->WriteLE( fFlags );

26
Sources/Plasma/PubUtilLib/plGImage/plFont.h

@ -131,7 +131,7 @@ class plFont : public hsKeyedObject
friend class plBDFCharsParser; friend class plBDFCharsParser;
// Font face and size. This is just used for IDing purposes, not for rendering // Font face and size. This is just used for IDing purposes, not for rendering
char fFace[ 256 ]; plString fFace;
uint8_t fSize; uint8_t fSize;
uint32_t fFlags; uint32_t fFlags;
@ -244,20 +244,20 @@ class plFont : public hsKeyedObject
virtual void Read( hsStream *s, hsResMgr *mgr ); virtual void Read( hsStream *s, hsResMgr *mgr );
virtual void Write( hsStream *s, hsResMgr *mgr ); virtual void Write( hsStream *s, hsResMgr *mgr );
const char *GetFace( void ) const { return fFace; } plString GetFace( void ) const { return fFace; }
uint8_t GetSize( void ) const { return fSize; } uint8_t GetSize( void ) const { return fSize; }
uint16_t GetFirstChar( void ) const { return fFirstChar; } uint16_t GetFirstChar( void ) const { return fFirstChar; }
uint16_t GetNumChars( void ) const { return fCharacters.GetCount(); } uint16_t GetNumChars( void ) const { return fCharacters.GetCount(); }
uint32_t GetFlags( void ) const { return fFlags; } uint32_t GetFlags( void ) const { return fFlags; }
float GetDescent( void ) const { return (float)fFontDescent; } float GetDescent( void ) const { return (float)fFontDescent; }
float GetAscent( void ) const { return (float)fFontAscent; } float GetAscent( void ) const { return (float)fFontAscent; }
uint32_t GetBitmapWidth( void ) const { return fWidth; } uint32_t GetBitmapWidth( void ) const { return fWidth; }
uint32_t GetBitmapHeight( void ) const { return fHeight; } uint32_t GetBitmapHeight( void ) const { return fHeight; }
uint8_t GetBitmapBPP( void ) const { return fBPP; } uint8_t GetBitmapBPP( void ) const { return fBPP; }
void SetFace( const char *face ); void SetFace( const plString &face ) { fFace = face; }
void SetSize( uint8_t size ); void SetSize( uint8_t size ) { fSize = size; }
void SetFlags( uint32_t flags ) { fFlags = flags; } void SetFlags( uint32_t flags ) { fFlags = flags; }
void SetFlag( uint32_t flag, bool on ) { if( on ) fFlags |= flag; else fFlags &= ~flag; } void SetFlag( uint32_t flag, bool on ) { if( on ) fFlags |= flag; else fFlags &= ~flag; }
bool IsFlagSet( uint32_t flag ) { if( fFlags & flag ) return true; return false; } bool IsFlagSet( uint32_t flag ) { if( fFlags & flag ) return true; return false; }
@ -275,12 +275,12 @@ class plFont : public hsKeyedObject
void SetRenderClipping( int16_t x, int16_t y, int16_t width, int16_t height ); void SetRenderClipping( int16_t x, int16_t y, int16_t width, int16_t height );
void SetRenderWrapping( int16_t x, int16_t y, int16_t width, int16_t height ); void SetRenderWrapping( int16_t x, int16_t y, int16_t width, int16_t height );
void RenderString( plMipmap *mip, uint16_t x, uint16_t y, const char *string, uint16_t *lastX = nil, uint16_t *lastY = nil ); void RenderString( plMipmap *mip, uint16_t x, uint16_t y, const plString &string, uint16_t *lastX = nil, uint16_t *lastY = nil );
void RenderString( plMipmap *mip, uint16_t x, uint16_t y, const wchar_t *string, uint16_t *lastX = nil, uint16_t *lastY = nil ); void RenderString( plMipmap *mip, uint16_t x, uint16_t y, const wchar_t *string, uint16_t *lastX = nil, uint16_t *lastY = nil );
uint16_t CalcStringWidth( const char *string ); uint16_t CalcStringWidth( const plString &string );
uint16_t CalcStringWidth( const wchar_t *string ); uint16_t CalcStringWidth( const wchar_t *string );
void CalcStringExtents( const char *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ); void CalcStringExtents( const plString &string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY );
void CalcStringExtents( const wchar_t *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ); void CalcStringExtents( const wchar_t *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY );
bool LoadFromFNT( const char *path ); bool LoadFromFNT( const char *path );

28
Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp

@ -89,23 +89,16 @@ void plFontCache::Clear( void )
{ {
} }
plFont *plFontCache::GetFont( const char *face, uint8_t size, uint32_t fontFlags ) plFont *plFontCache::GetFont( const plString &face, uint8_t size, uint32_t fontFlags )
{ {
uint32_t i, currIdx = (uint32_t)-1; uint32_t i, currIdx = (uint32_t)-1;
int currDeltaSize = 100000; int currDeltaSize = 100000;
char toFind[ 256 ];
strcpy( toFind, face );
strlwr( toFind );
for( i = 0; i < fCache.GetCount(); i++ ) for( i = 0; i < fCache.GetCount(); i++ )
{ {
char thisOne[ 256 ]; if (fCache[i]->GetFace().CompareNI(face, face.GetSize()) == 0 &&
strcpy( thisOne, fCache[ i ]->GetFace() ); (fCache[i]->GetFlags() == fontFlags))
strlwr( thisOne );
if( strncmp( thisOne, toFind, strlen( toFind ) ) == 0 &&
( fCache[ i ]->GetFlags() == fontFlags ) )
{ {
int delta = fCache[ i ]->GetSize() - size; int delta = fCache[ i ]->GetSize() - size;
if( delta < 0 ) if( delta < 0 )
@ -125,18 +118,17 @@ plFont *plFontCache::GetFont( const char *face, uint8_t size, uint32_t fontFlag
return fCache[ currIdx ]; return fCache[ currIdx ];
} }
// If we failed, it's possible we have a face saved as "Times", for example, and someone's // If we failed, it's possible we have a face saved as "Times", for example, and someone's
// asking for "Times New Roman", so strip all but the first uint16_t from our font and try the search again // asking for "Times New Roman", so strip all but the first word from our font and try the search again
char *c = strchr( toFind, ' ' ); ssize_t sp = face.Find(' ');
if( c != nil ) if (sp >= 0)
{ {
*c = 0; return GetFont(face.Left(sp), size, fontFlags);
return GetFont( toFind, size, fontFlags );
} }
else if( fontFlags != 0 ) else if( fontFlags != 0 )
{ {
// Hmm, well ok, just to be nice, try without our flags // Hmm, well ok, just to be nice, try without our flags
plFont *f = GetFont( toFind, size, 0 ); plFont *f = GetFont( face, size, 0 );
if( f != nil ) if( f != nil )
{ {
//plStatusLog::AddLineS( "pipeline.log", "Warning: plFontCache is substituting %s %d regular (flags 0x%x could not be matched)", f->GetFace(), f->GetSize(), fontFlags ); //plStatusLog::AddLineS( "pipeline.log", "Warning: plFontCache is substituting %s %d regular (flags 0x%x could not be matched)", f->GetFace(), f->GetSize(), fontFlags );
@ -171,7 +163,7 @@ void plFontCache::ILoadCustomFonts( void )
plString keyName; plString keyName;
if (font->GetKey() == nil) if (font->GetKey() == nil)
{ {
keyName = plString::Format( "%s-%d", font->GetFace(), font->GetSize() ); keyName = plString::Format( "%s-%d", font->GetFace().c_str(), font->GetSize() );
hsgResMgr::ResMgr()->NewKey( keyName, font, plLocation::kGlobalFixedLoc ); hsgResMgr::ResMgr()->NewKey( keyName, font, plLocation::kGlobalFixedLoc );
} }

2
Sources/Plasma/PubUtilLib/plGImage/plFontCache.h

@ -91,7 +91,7 @@ class plFontCache : public hsKeyedObject
static plFontCache &GetInstance( void ); static plFontCache &GetInstance( void );
plFont *GetFont( const char *face, uint8_t size, uint32_t fontFlags ); plFont *GetFont( const plString &face, uint8_t size, uint32_t fontFlags );
// HFONT GetMeAFont( const char *face, int height, int weight, bool italic, uint32_t quality ); // HFONT GetMeAFont( const char *face, int height, int weight, bool italic, uint32_t quality );
// void FreeFont( HFONT font ); // void FreeFont( HFONT font );

23
Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp

@ -92,7 +92,7 @@ plWinFontCache &plWinFontCache::GetInstance( void )
return cache; return cache;
} }
HFONT plWinFontCache::IFindFont( const char *face, int height, int weight, bool italic, uint32_t quality ) HFONT plWinFontCache::IFindFont( const plString &face, int height, int weight, bool italic, uint32_t quality )
{ {
int i; int i;
@ -105,7 +105,7 @@ HFONT plWinFontCache::IFindFont( const char *face, int height, int weight, boo
fFontCache[ i ].fItalic == italic && fFontCache[ i ].fItalic == italic &&
fFontCache[ i ].fQuality == quality ) fFontCache[ i ].fQuality == quality )
{ {
if( strcmp( fFontCache[ i ].fFace, face ) == 0 ) if (fFontCache[i].fFace == face)
return fFontCache[ i ].fFont; return fFontCache[ i ].fFont;
} }
} }
@ -113,7 +113,7 @@ HFONT plWinFontCache::IFindFont( const char *face, int height, int weight, boo
return nil; return nil;
} }
HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, bool italic, uint32_t quality ) HFONT plWinFontCache::IMakeFont( const plString &face, int height, int weight, bool italic, uint32_t quality )
{ {
plFontRecord myRec; plFontRecord myRec;
int i; int i;
@ -122,12 +122,12 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo
// Find a cached name for us // Find a cached name for us
for( i = 0; i < fFontNameCache.GetCount(); i++ ) for( i = 0; i < fFontNameCache.GetCount(); i++ )
{ {
if( strcmp( face, fFontNameCache[ i ] ) == 0 ) if (face == fFontNameCache[i])
break; break;
} }
if( i == fFontNameCache.GetCount() ) if( i == fFontNameCache.GetCount() )
fFontNameCache.Append( hsStrcpy( face ) ); fFontNameCache.Append(face);
myRec.fFace = fFontNameCache[ i ]; myRec.fFace = fFontNameCache[ i ];
myRec.fHeight = height; myRec.fHeight = height;
@ -135,8 +135,8 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo
myRec.fItalic = italic; myRec.fItalic = italic;
myRec.fQuality = quality; myRec.fQuality = quality;
myRec.fFont = CreateFont( height, 0, 0, 0, weight, italic ? TRUE : FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, myRec.fFont = CreateFontW( height, 0, 0, 0, weight, italic ? TRUE : FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, face ); CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, face.ToWchar().GetData() );
if( myRec.fFont != nil ) if( myRec.fFont != nil )
{ {
@ -156,7 +156,7 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo
err = "Weight of created font does not match"; err = "Weight of created font does not match";
if( static_cast<bool>(fontInfo.lfItalic) != italic ) if( static_cast<bool>(fontInfo.lfItalic) != italic )
err = "Italic-ness of created font does not match"; err = "Italic-ness of created font does not match";
if( stricmp( fontInfo.lfFaceName, face ) != 0 ) if( face.CompareI(fontInfo.lfFaceName) != 0 )
err = "Face of created font does not match"; err = "Face of created font does not match";
if( err != nil ) if( err != nil )
@ -199,13 +199,14 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo
} }
else else
{ {
plStatusLog::AddLineS( "pipeline.log", "ERROR: CreateFont() call FAILED (face: %s, size: %d %s %s)", face, -height, weight == FW_BOLD ? "bold" : "", italic ? "italic" : "" ); plStatusLog::AddLineS( "pipeline.log", "ERROR: CreateFont() call FAILED (face: %s, size: %d %s %s)",
face.c_str(), -height, weight == FW_BOLD ? "bold" : "", italic ? "italic" : "" );
} }
return myRec.fFont; return myRec.fFont;
} }
HFONT plWinFontCache::GetMeAFont( const char *face, int height, int weight, bool italic, uint32_t quality ) HFONT plWinFontCache::GetMeAFont( const plString &face, int height, int weight, bool italic, uint32_t quality )
{ {
HFONT font = IFindFont( face, height, weight, italic, quality ); HFONT font = IFindFont( face, height, weight, italic, quality );
if( font == nil ) if( font == nil )
@ -226,8 +227,6 @@ void plWinFontCache::Clear( void )
DeleteObject( fFontCache[ i ].fFont ); DeleteObject( fFontCache[ i ].fFont );
fFontCache.Reset(); fFontCache.Reset();
for( i = 0; i < fFontNameCache.GetCount(); i++ )
delete [] fFontNameCache[ i ];
fFontNameCache.Reset(); fFontNameCache.Reset();
for( i = 0; i < fCustFonts.GetCount(); i++ ) for( i = 0; i < fCustFonts.GetCount(); i++ )

10
Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h

@ -80,7 +80,7 @@ class plWinFontCache
public: public:
HFONT fFont; HFONT fFont;
char *fFace; // Pointer is owned by fFontNameCache plString fFace;
int fHeight; int fHeight;
int fWeight; int fWeight;
bool fItalic; bool fItalic;
@ -98,15 +98,15 @@ class plWinFontCache
bool fInShutdown; bool fInShutdown;
hsTArray<plFontRecord> fFontCache; hsTArray<plFontRecord> fFontCache;
hsTArray<char *> fFontNameCache; hsTArray<plString> fFontNameCache;
char *fCustFontDir; char *fCustFontDir;
hsTArray<plCustFont *> fCustFonts; hsTArray<plCustFont *> fCustFonts;
plWinFontCache(); plWinFontCache();
HFONT IFindFont( const char *face, int height, int weight, bool italic, uint32_t quality ); HFONT IFindFont( const plString &face, int height, int weight, bool italic, uint32_t quality );
HFONT IMakeFont( const char *face, int height, int weight, bool italic, uint32_t quality ); HFONT IMakeFont( const plString &face, int height, int weight, bool italic, uint32_t quality );
void ILoadCustomFonts( void ); void ILoadCustomFonts( void );
@ -115,7 +115,7 @@ class plWinFontCache
virtual ~plWinFontCache(); virtual ~plWinFontCache();
static plWinFontCache &GetInstance( void ); static plWinFontCache &GetInstance( void );
HFONT GetMeAFont( const char *face, int height, int weight, bool italic, uint32_t quality ); HFONT GetMeAFont( const plString &face, int height, int weight, bool italic, uint32_t quality );
void FreeFont( HFONT font ); void FreeFont( HFONT font );
void Clear( void ); void Clear( void );

6
Sources/Tools/plFontConverter/plFontConverterProc.cpp

@ -135,7 +135,7 @@ void IUpdateInfo( HWND hDlg )
return; return;
} }
SetDlgItemText( hDlg, IDC_FACE, gFont->GetFace() ); SetDlgItemText( hDlg, IDC_FACE, gFont->GetFace().c_str() );
SetDlgItemInt( hDlg, IDC_FSIZE, gFont->GetSize(), false ); SetDlgItemInt( hDlg, IDC_FSIZE, gFont->GetSize(), false );
SetDlgItemInt( hDlg, IDC_STARTG, gFont->GetFirstChar(), false ); SetDlgItemInt( hDlg, IDC_STARTG, gFont->GetFirstChar(), false );
SetDlgItemInt( hDlg, IDC_GCOUNT, gFont->GetNumChars(), false ); SetDlgItemInt( hDlg, IDC_GCOUNT, gFont->GetNumChars(), false );
@ -598,7 +598,7 @@ void IBatchFreeType( HWND hWnd, const char *path )
gFont->SetFace(sFontName); gFont->SetFace(sFontName);
char fileName[ MAX_PATH ]; char fileName[ MAX_PATH ];
sprintf( fileName, "%s\\%s-%d.p2f", destPath, gFont->GetFace(), gFont->GetSize() ); sprintf( fileName, "%s\\%s-%d.p2f", destPath, gFont->GetFace().c_str(), gFont->GetSize() );
hsUNIXStream stream; hsUNIXStream stream;
if( !stream.Open( fileName, "wb" ) ) if( !stream.Open( fileName, "wb" ) )
MessageBox( hWnd, "Can't open file for writing", "Error", MB_OK | MB_ICONEXCLAMATION ); MessageBox( hWnd, "Can't open file for writing", "Error", MB_OK | MB_ICONEXCLAMATION );
@ -688,7 +688,7 @@ BOOL CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
gFont->SetFlag( plFont::kFlagItalic, IsDlgButtonChecked( hWnd, IDC_ITALIC ) == BST_CHECKED ); gFont->SetFlag( plFont::kFlagItalic, IsDlgButtonChecked( hWnd, IDC_ITALIC ) == BST_CHECKED );
// Write out // Write out
sprintf( fileName, "%s-%d.p2f", gFont->GetFace(), gFont->GetSize() ); sprintf( fileName, "%s-%d.p2f", gFont->GetFace().c_str(), gFont->GetSize() );
if( PromptForFile( hWnd, "Specify a file to export to", "Plasma 2 font files\0*.p2f\0", fileName, sizeof( fileName ), true ) ) if( PromptForFile( hWnd, "Specify a file to export to", "Plasma 2 font files\0*.p2f\0", fileName, sizeof( fileName ), true ) )
{ {
hsUNIXStream stream; hsUNIXStream stream;

Loading…
Cancel
Save