Browse Source

Accept plStrings in plDynamicTextMap for rendering and font names

Michael Hansen 11 years ago
parent
commit
939f6c3d41
  1. 8
      Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp
  2. 2
      Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.h
  3. 31
      Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.cpp
  4. 10
      Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.h
  5. 69
      Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp
  6. 17
      Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h
  7. 44
      Sources/Plasma/PubUtilLib/plGImage/plFont.cpp
  8. 14
      Sources/Plasma/PubUtilLib/plGImage/plFont.h
  9. 26
      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

8
Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp

@ -2609,7 +2609,7 @@ void pfJournalBook::IRenderPage( uint32_t page, uint32_t whichDTMap, bool sup
uint16_t width, height, y, x, ascent, lastX, lastY;
uint8_t fontFlags, fontSize;
const wchar_t *fontFace;
plString fontFace;
hsColorRGBA fontColor;
int16_t fontSpacing;
bool needSFX = false;
@ -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
// 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
{
@ -3369,7 +3369,7 @@ void pfJournalBook::IFindFontProps( uint32_t chunkIdx, const wchar_t *&face,
// What do we (still) need?
if( !( found & kFace ) && chunk->fText != L"" )
{
face = chunk->fText.c_str();
face = plString::FromWchar(chunk->fText.c_str());
found |= kFace;
}
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
if( !( found & kFace ) )
face = L"Arial";
face = "Arial";
if( !( found & kSize ) )
size = 24;
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
// 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
uint8_t IFindLastAlignment( void ) const;

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

@ -86,7 +86,6 @@ plDynSurfaceWriter::plWinSurface::plWinSurface()
fWidth = fHeight = 0;
fSaveNum = 0;
fFontFace = nil;
fFontSize = 0;
fFontFlags = 0;
fFontAntiAliasRGB = false;
@ -207,8 +206,7 @@ void plDynSurfaceWriter::plWinSurface::Release( void )
fBits = nil;
fWidth = fHeight = 0;
delete [] fFontFace;
fFontFace = nil;
fFontFace = plString::Null;
fFontSize = 0;
fFontFlags = 0;
fFontAntiAliasRGB = false;
@ -231,19 +229,18 @@ static int SafeStrCmp( const char *str1, const char *str2 )
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 )
return true;
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 != nil ) ? hsStrcpy( face ) : nil;
fFontFace = face;
fFontSize = size;
fFontFlags = flags;
fFontAntiAliasRGB = aaRGB;
@ -256,7 +253,7 @@ void plDynSurfaceWriter::plWinSurface::SetFont( const char *face, uint16_t si
fFont = nil;
}
if( face == nil )
if (face.IsEmpty())
return;
bool bold = ( fFontFlags & plDynSurfaceWriter::kFontBold ) ? true : false;
@ -283,10 +280,10 @@ void plDynSurfaceWriter::plWinSurface::SetFont( const char *face, uint16_t si
if( fFont == nil )
{
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 = nil;
fFontFace = plString::Null;
fFontSize = 0;
return;
}
@ -385,7 +382,7 @@ void plDynSurfaceWriter::IInit( void )
fJustify = kLeftJustify;
fFlags = 0;
fFlushed = true;
fFontFace = nil;
fFontFace = plString::Null;
fFontSize = 0;
fFontBlockedRGB = false;
}
@ -401,8 +398,7 @@ void plDynSurfaceWriter::Reset( void )
fCurrTarget = nil;
fFlushed = true;
delete [] fFontFace;
fFontFace = nil;
fFontFace = plString::Null;
fFontSize = 0;
}
@ -514,8 +510,7 @@ void plDynSurfaceWriter::SwitchTarget( plDynamicTextMap *target )
if( hadToAllocate )
{
delete [] fFontFace;
fFontFace = nil;
fFontFace = plString::Null;
fFontSize = 0;
fFontFlags = 0;
}
@ -701,7 +696,7 @@ void plDynSurfaceWriter::SetFont( const char *face, uint16_t size, uint8_t fo
//// 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 );

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

@ -148,14 +148,14 @@ class plDynSurfaceWriter
void IRefreshOSJustify( void );
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;
uint32_t fFlags;
Justify fJustify;
bool fFlushed;
char *fFontFace;
plString fFontFace;
uint16_t fFontSize;
uint8_t fFontFlags;
bool fFontAntiAliasRGB;
@ -182,7 +182,7 @@ class plDynSurfaceWriter
uint16_t fWidth, fHeight;
char *fFontFace;
plString fFontFace;
uint16_t fFontSize;
uint8_t fFontFlags;
bool fFontAntiAliasRGB, fFontBlockedRGB;
@ -194,8 +194,8 @@ class plDynSurfaceWriter
void Release( void );
bool WillFit( uint16_t w, uint16_t h );
bool FontMatches( const char *face, uint16_t size, uint8_t flags, bool aaRGB );
void SetFont( 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 plString &face, uint16_t size, uint8_t flags, bool aaRGB );
};
class plWinRGBSurface : public plWinSurface

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

@ -77,7 +77,7 @@ plProfile_Extern(MemMipmaps);
plDynamicTextMap::plDynamicTextMap()
: 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)
{
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 )
: fInitBuffer(nullptr), fFontFace(nullptr)
: fInitBuffer(nullptr)
{
Create( width, height, hasAlpha, extraWidth, extraHeight );
}
@ -163,8 +163,7 @@ void plDynamicTextMap::Reset( void )
delete [] fInitBuffer;
fInitBuffer = nil;
delete [] fFontFace;
fFontFace = nil;
fFontFace = plString::Null;
// Destroy the old texture ref, since we're no longer using it
SetDeviceRef( nil );
@ -413,22 +412,21 @@ void plDynamicTextMap::SetJustify( Justify j )
//// 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
// if( !IIsValid() )
// return;
delete [] fFontFace;
if (plLocalization::UsingUnicode())
{
// 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
hsStatusMessageF("We are using a unicode language, overriding font choice of %s", face ? face : "nil");
fFontFace = hsStrcpy( "Unicode" );
hsStatusMessageF("We are using a unicode language, overriding font choice of %s", face.c_str("nil"));
fFontFace = "Unicode";
}
else
fFontFace = ( face != nil ) ? hsStrcpy( face ) : nil;
fFontFace = face;
fFontSize = size;
fFontFlags = fontFlags;
fFontAntiAliasRGB = antiAliasRGB;
@ -439,11 +437,9 @@ void plDynamicTextMap::SetFont( const char *face, uint16_t size, uint8_t font
if ( fCurrFont == nil )
{
if (!fCurrFont)
hsStatusMessageF("Font missing - %s. Using Arial", fFontFace ? fFontFace : "nil");
hsStatusMessageF("Font missing - %s. Using Arial", fFontFace.c_str("nil"));
if ( fFontFace )
delete [] fFontFace;
fFontFace = hsStrcpy( "Arial" );
fFontFace = "Arial";
// lets try again with Arial
fCurrFont = plFontCache::GetInstance().GetFont( fFontFace, (uint8_t)fFontSize,
( ( 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 ///////////////////////////////////////////////////////////
void plDynamicTextMap::SetLineSpacing( int16_t spacing )
@ -515,11 +504,10 @@ void plDynamicTextMap::DrawString( uint16_t x, uint16_t y, const wchar_t *tex
//// 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);
DrawClippedString(x,y,wText,width,height);
delete [] wText;
// TEMP
DrawClippedString(x, y, text.ToWchar().GetData(), width, 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 ////////////////////////////////////////////////////////
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);
DrawClippedString(x,y,wText,clipX,clipY,width,height);
delete [] wText;
// TEMP
DrawClippedString(x, y, text.ToWchar().GetData(), width, 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 ////////////////////////////////////////////////////////
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);
DrawWrappedString(x,y,wText,width,height,lastX,lastY);
delete [] wText;
// TEMP
DrawWrappedString(x, y, text.ToWchar().GetData(), width, height, lastX, 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 //////////////////////////////////////////////////////////
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);
uint16_t w = CalcStringWidth(wText,height);
delete [] wText;
return w;
// TEMP
return CalcStringWidth(text.ToWchar().GetData(), height);
}
uint16_t plDynamicTextMap::CalcStringWidth( const wchar_t *text, uint16_t *height )
@ -614,11 +598,10 @@ void plDynamicTextMap::SetFirstLineIndent( int16_t indent )
//// 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);
CalcWrappedStringSize(wText,width,height,firstClippedChar,maxAscent,lastX,lastY);
delete [] wText;
// TEMP
CalcWrappedStringSize(text.ToWchar().GetData(), width, height, firstClippedChar, maxAscent, lastX, 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 );
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 )
SetLineSpacing( textMsg->fLineSpacing );
@ -902,7 +885,7 @@ void plDynamicTextMap::Swap( plDynamicTextMap *other )
SWAP_ME( bool, fShadowed, other->fShadowed );
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( uint8_t, fFontFlags, other->fFontFlags );
SWAP_ME( bool, fFontAntiAliasRGB, other->fFontAntiAliasRGB );

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

@ -152,23 +152,22 @@ class plDynamicTextMap : public plMipmap
kFontShadowed = 0x04
};
void SetFont( const char *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 SetFont( const plString &face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true );
void SetLineSpacing( int16_t spacing );
void SetTextColor( hsColorRGBA &color, bool blockRGB = false );
void SetJustify( Justify j );
void DrawString( uint16_t x, uint16_t y, const char *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 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 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 );
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 );
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 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 );
@ -201,7 +200,7 @@ class plDynamicTextMap : public plMipmap
// Gets for font values
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; }
bool GetFontAARGB( void ) const { return fFontAntiAliasRGB; }
hsColorRGBA GetFontColor( void ) const { return fFontColor; }
@ -225,7 +224,7 @@ class plDynamicTextMap : public plMipmap
bool fHasAlpha, fShadowed;
Justify fJustify;
char *fFontFace;
plString fFontFace;
uint16_t fFontSize;
uint8_t fFontFlags;
bool fFontAntiAliasRGB;

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

@ -117,7 +117,7 @@ void plFont::IClear( bool onConstruct )
if( !onConstruct )
delete [] fBMapData;
memset( fFace, 0, sizeof( fFace ) );
fFace = plString::Null;
fSize = 0;
fFlags = 0;
@ -141,16 +141,6 @@ void plFont::IClear( bool onConstruct )
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 )
{
hsKeyedObject::Read( s, mgr );
@ -232,12 +222,10 @@ static inline bool IIsDrawableWordBreak( const char c )
// The base render function. Additional options are specified externally,
// 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
wchar_t *wideString = hsStringToWString(string);
RenderString(mip,x,y,wideString,lastX,lastY);
delete [] wideString;
// TEMP
RenderString(mip, x, y, string.ToWchar().GetData(), lastX, lastY);
}
@ -990,7 +978,7 @@ void plFont::IRenderCharNull( const plCharacter &c )
//// CalcString Variations ////////////////////////////////////////////////////
uint16_t plFont::CalcStringWidth( const char *string )
uint16_t plFont::CalcStringWidth( const plString &string )
{
uint16_t w, h, a, lX, lY;
uint32_t s;
@ -1006,12 +994,10 @@ uint16_t plFont::CalcStringWidth( const wchar_t *string )
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
wchar_t *wideString = hsStringToWString(string);
CalcStringExtents(wideString,width,height,ascent,firstClippedChar,lastX,lastY);
delete [] wideString;
CalcStringExtents(string.ToWchar().GetData(), width, height, ascent, firstClippedChar, lastX, 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();
}
char faceName[ 256 ], deviceName[ 256 ];
char faceName[ 257 ], deviceName[ 256 ];
if( fntInfo.face != 0 )
{
stream->SetPosition( fntInfo.face );
@ -1207,7 +1193,8 @@ bool plFont::LoadFromFNTStream( hsStream *stream )
if( faceName[ i ] == 0 )
break;
}
strncpy( fFace, faceName, sizeof( fFace ) );
faceName[256] = 0;
fFace = faceName;
}
if( fntInfo.device != 0 )
{
@ -1926,7 +1913,11 @@ bool plFont::LoadFromBDF( const char *path, plBDFConvertCallback *callback )
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();
s->ReadLE( &fFlags );
@ -1959,7 +1950,10 @@ bool plFont::ReadRaw( 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->WriteLE( fFlags );

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

@ -131,7 +131,7 @@ class plFont : public hsKeyedObject
friend class plBDFCharsParser;
// Font face and size. This is just used for IDing purposes, not for rendering
char fFace[ 256 ];
plString fFace;
uint8_t fSize;
uint32_t fFlags;
@ -244,7 +244,7 @@ class plFont : public hsKeyedObject
virtual void Read( 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; }
uint16_t GetFirstChar( void ) const { return fFirstChar; }
uint16_t GetNumChars( void ) const { return fCharacters.GetCount(); }
@ -256,8 +256,8 @@ class plFont : public hsKeyedObject
uint32_t GetBitmapHeight( void ) const { return fHeight; }
uint8_t GetBitmapBPP( void ) const { return fBPP; }
void SetFace( const char *face );
void SetSize( uint8_t size );
void SetFace( const plString &face ) { fFace = face; }
void SetSize( uint8_t size ) { fSize = size; }
void SetFlags( uint32_t flags ) { fFlags = flags; }
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; }
@ -275,12 +275,12 @@ class plFont : public hsKeyedObject
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 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 );
uint16_t CalcStringWidth( const char *string );
uint16_t CalcStringWidth( const plString &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 );
bool LoadFromFNT( const char *path );

26
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;
int currDeltaSize = 100000;
char toFind[ 256 ];
strcpy( toFind, face );
strlwr( toFind );
for( i = 0; i < fCache.GetCount(); i++ )
{
char thisOne[ 256 ];
strcpy( thisOne, fCache[ i ]->GetFace() );
strlwr( thisOne );
if( strncmp( thisOne, toFind, strlen( toFind ) ) == 0 &&
( fCache[ i ]->GetFlags() == fontFlags ) )
if (fCache[i]->GetFace().CompareNI(face, face.GetSize()) == 0 &&
(fCache[i]->GetFlags() == fontFlags))
{
int delta = fCache[ i ]->GetSize() - size;
if( delta < 0 )
@ -126,17 +119,16 @@ plFont *plFontCache::GetFont( const char *face, uint8_t size, uint32_t fontFlag
}
// 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
char *c = strchr( toFind, ' ' );
if( c != nil )
// asking for "Times New Roman", so strip all but the first word from our font and try the search again
ssize_t sp = face.Find(' ');
if (sp >= 0)
{
*c = 0;
return GetFont( toFind, size, fontFlags );
return GetFont(face.Left(sp), size, fontFlags);
}
else if( fontFlags != 0 )
{
// 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 )
{
//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;
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 );
}

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

@ -91,7 +91,7 @@ class plFontCache : public hsKeyedObject
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 );
// void FreeFont( HFONT font );

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

@ -92,7 +92,7 @@ plWinFontCache &plWinFontCache::GetInstance( void )
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;
@ -105,7 +105,7 @@ HFONT plWinFontCache::IFindFont( const char *face, int height, int weight, boo
fFontCache[ i ].fItalic == italic &&
fFontCache[ i ].fQuality == quality )
{
if( strcmp( fFontCache[ i ].fFace, face ) == 0 )
if (fFontCache[i].fFace == face)
return fFontCache[ i ].fFont;
}
}
@ -113,7 +113,7 @@ HFONT plWinFontCache::IFindFont( const char *face, int height, int weight, boo
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;
int i;
@ -122,12 +122,12 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo
// Find a cached name for us
for( i = 0; i < fFontNameCache.GetCount(); i++ )
{
if( strcmp( face, fFontNameCache[ i ] ) == 0 )
if (face == fFontNameCache[i])
break;
}
if( i == fFontNameCache.GetCount() )
fFontNameCache.Append( hsStrcpy( face ) );
fFontNameCache.Append(face);
myRec.fFace = fFontNameCache[ i ];
myRec.fHeight = height;
@ -135,8 +135,8 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo
myRec.fItalic = italic;
myRec.fQuality = quality;
myRec.fFont = CreateFont( height, 0, 0, 0, weight, italic ? TRUE : FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, face );
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.ToWchar().GetData() );
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";
if( static_cast<bool>(fontInfo.lfItalic) != italic )
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";
if( err != nil )
@ -199,13 +199,14 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo
}
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;
}
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 );
if( font == nil )
@ -226,8 +227,6 @@ void plWinFontCache::Clear( void )
DeleteObject( fFontCache[ i ].fFont );
fFontCache.Reset();
for( i = 0; i < fFontNameCache.GetCount(); i++ )
delete [] fFontNameCache[ i ];
fFontNameCache.Reset();
for( i = 0; i < fCustFonts.GetCount(); i++ )

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

@ -80,7 +80,7 @@ class plWinFontCache
public:
HFONT fFont;
char *fFace; // Pointer is owned by fFontNameCache
plString fFace;
int fHeight;
int fWeight;
bool fItalic;
@ -98,15 +98,15 @@ class plWinFontCache
bool fInShutdown;
hsTArray<plFontRecord> fFontCache;
hsTArray<char *> fFontNameCache;
hsTArray<plString> fFontNameCache;
char *fCustFontDir;
hsTArray<plCustFont *> fCustFonts;
plWinFontCache();
HFONT IFindFont( const char *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 IFindFont( const plString &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 );
@ -115,7 +115,7 @@ class plWinFontCache
virtual ~plWinFontCache();
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 Clear( void );

6
Sources/Tools/plFontConverter/plFontConverterProc.cpp

@ -135,7 +135,7 @@ void IUpdateInfo( HWND hDlg )
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_STARTG, gFont->GetFirstChar(), false );
SetDlgItemInt( hDlg, IDC_GCOUNT, gFont->GetNumChars(), false );
@ -598,7 +598,7 @@ void IBatchFreeType( HWND hWnd, const char *path )
gFont->SetFace(sFontName);
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;
if( !stream.Open( fileName, "wb" ) )
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 );
// 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 ) )
{
hsUNIXStream stream;

Loading…
Cancel
Save