Commit bf0685f8 authored by Cyril Deguet's avatar Cyril Deguet

* src/ft2_font.cpp: initialize some members to avoid a segfault in the

    destructor when the font cannot be opened. drawString() now returns
    NULL if the initialization failed.
  * all: check if drawString() returns NULL
parent 2de4918c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ctrl_list.cpp * ctrl_list.cpp
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: ctrl_list.cpp,v 1.3 2004/02/29 16:49:55 asmax Exp $ * $Id$
* *
* Authors: Cyril Deguet <asmax@via.ecp.fr> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr> * Olivier Teulire <ipkiss@via.ecp.fr>
...@@ -372,6 +372,10 @@ void CtrlList::makeImage() ...@@ -372,6 +372,10 @@ void CtrlList::makeImage()
// Draw the text // Draw the text
GenericBitmap *pText = m_rFont.drawString( *pStr, color, width ); GenericBitmap *pText = m_rFont.drawString( *pStr, color, width );
if( !pText )
{
return;
}
yPos += itemHeight - pText->getHeight(); yPos += itemHeight - pText->getHeight();
int ySrc = 0; int ySrc = 0;
if( yPos < 0 ) if( yPos < 0 )
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ctrl_text.cpp * ctrl_text.cpp
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: ctrl_text.cpp,v 1.2 2004/02/29 16:49:55 asmax Exp $ * $Id$
* *
* Authors: Cyril Deguet <asmax@via.ecp.fr> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr> * Olivier Teulire <ipkiss@via.ecp.fr>
...@@ -193,6 +193,10 @@ void CtrlText::displayText( const UString &rText ) ...@@ -193,6 +193,10 @@ void CtrlText::displayText( const UString &rText )
delete m_pImg; delete m_pImg;
} }
m_pImg = m_rFont.drawString( rText, m_color ); m_pImg = m_rFont.drawString( rText, m_color );
if( !m_pImg )
{
return;
}
// 'Double' image // 'Double' image
const UString doubleStringWithSep = rText + SEPARATOR_STRING + rText; const UString doubleStringWithSep = rText + SEPARATOR_STRING + rText;
if( m_pImgDouble ) if( m_pImgDouble )
...@@ -212,7 +216,7 @@ void CtrlText::displayText( const UString &rText ) ...@@ -212,7 +216,7 @@ void CtrlText::displayText( const UString &rText )
void CtrlText::onChangePosition() void CtrlText::onChangePosition()
{ {
if( getPosition() ) if( m_pImg && getPosition() )
{ {
if( m_pImg->getWidth() < getPosition()->getWidth() ) if( m_pImg->getWidth() < getPosition()->getWidth() )
{ {
...@@ -252,7 +256,8 @@ void CtrlText::transManualMoving( SkinObject *pCtrl ) ...@@ -252,7 +256,8 @@ void CtrlText::transManualMoving( SkinObject *pCtrl )
// Start the automatic movement, but only if the text is wider than the // Start the automatic movement, but only if the text is wider than the
// control // control
if( pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() ) if( pThis->m_pImg &&
pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
{ {
// The current image may have been set incorrectly in displayText(), so // The current image may have been set incorrectly in displayText(), so
// set the correct value // set the correct value
...@@ -276,7 +281,8 @@ void CtrlText::transMove( SkinObject *pCtrl ) ...@@ -276,7 +281,8 @@ void CtrlText::transMove( SkinObject *pCtrl )
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt; EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Do nothing if the text fits in the control // Do nothing if the text fits in the control
if( pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() ) if( pThis->m_pImg &&
pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
{ {
// The current image may have been set incorrectly in displayText(), so // The current image may have been set incorrectly in displayText(), so
// we set the correct value // we set the correct value
...@@ -308,6 +314,10 @@ void CtrlText::adjust( int &position ) ...@@ -308,6 +314,10 @@ void CtrlText::adjust( int &position )
// {m_pImgDouble->getWidth() - m_pImg->getWidth()} is the period of the // {m_pImgDouble->getWidth() - m_pImg->getWidth()} is the period of the
// bitmap; remember that the string used to generate m_pImgDouble is of the // bitmap; remember that the string used to generate m_pImgDouble is of the
// form: "foo foo", the number of spaces being a parameter // form: "foo foo", the number of spaces being a parameter
if( !m_pImg )
{
return;
}
position %= m_pImgDouble->getWidth() - m_pImg->getWidth(); position %= m_pImgDouble->getWidth() - m_pImg->getWidth();
if( position > 0 ) if( position > 0 )
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ft2_font.cpp * ft2_font.cpp
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: ft2_font.cpp,v 1.2 2004/02/27 13:24:12 gbazin Exp $ * $Id$
* *
* Authors: Cyril Deguet <asmax@via.ecp.fr> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr> * Olivier Teulire <ipkiss@via.ecp.fr>
...@@ -28,17 +28,26 @@ ...@@ -28,17 +28,26 @@
FT2Font::FT2Font( intf_thread_t *pIntf, const string &rName, int size ): FT2Font::FT2Font( intf_thread_t *pIntf, const string &rName, int size ):
GenericFont( pIntf ), m_name( rName ), m_buffer( NULL ), m_size( size ) GenericFont( pIntf ), m_name( rName ), m_buffer( NULL ), m_size( size ),
m_lib( NULL ), m_face( NULL ), m_dotGlyph( NULL )
{ {
} }
FT2Font::~FT2Font() FT2Font::~FT2Font()
{ {
if( m_dotGlyph )
FT_Done_Glyph( m_dotGlyph ); {
FT_Done_Face( m_face ); FT_Done_Glyph( m_dotGlyph );
FT_Done_FreeType( m_lib ); }
if( m_face )
{
FT_Done_Face( m_face );
}
if( m_lib )
{
FT_Done_FreeType( m_lib );
}
if( m_buffer ) if( m_buffer )
{ {
free( m_buffer ); free( m_buffer );
...@@ -138,6 +147,12 @@ GenericBitmap *FT2Font::drawString( const UString &rString, uint32_t color, ...@@ -138,6 +147,12 @@ GenericBitmap *FT2Font::drawString( const UString &rString, uint32_t color,
int yMin = 0, yMax = 0; int yMin = 0, yMax = 0;
uint32_t *pString = (uint32_t*)rString.u_str(); uint32_t *pString = (uint32_t*)rString.u_str();
// Check if freetype has been initialized
if( !m_face )
{
return NULL;
}
// Get the length of the string // Get the length of the string
int len = rString.length(); int len = rString.length();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* tooltip.cpp * tooltip.cpp
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: tooltip.cpp,v 1.3 2004/01/25 11:44:19 asmax Exp $ * $Id$
* *
* Authors: Cyril Deguet <asmax@via.ecp.fr> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr> * Olivier Teulire <ipkiss@via.ecp.fr>
...@@ -98,6 +98,10 @@ void Tooltip::makeImage( const UString &rText ) ...@@ -98,6 +98,10 @@ void Tooltip::makeImage( const UString &rText )
{ {
// Render the text on a bitmap // Render the text on a bitmap
GenericBitmap *pBmpTip = m_rFont.drawString( rText, 0 ); GenericBitmap *pBmpTip = m_rFont.drawString( rText, 0 );
if( !pBmpTip )
{
return;
}
int w = pBmpTip->getWidth() + 10; int w = pBmpTip->getWidth() + 10;
int h = m_rFont.getSize() + 8; int h = m_rFont.getSize() + 8;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment