Skip to content

Commit 264fd2b

Browse files
authored
Merge pull request #1291 from danieldresser-ie/fontError
IECoreScene::Font : Replace invalid chars with X instead of crashing
2 parents e942b79 + f03b278 commit 264fd2b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/IECoreScene/Font.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ class Font::Implementation : public IECore::RefCounted
522522

523523
const Mesh *cachedMesh( char c ) const
524524
{
525+
if( c < 0 )
526+
{
527+
// Map all invalid characters to capital X
528+
c = 'X';
529+
}
525530
FreeTypeMutex::scoped_lock lock( g_freeTypeMutex );
526531

527532
// see if we have it cached

test/IECoreScene/FontTest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,12 @@ def testLineSpacing( self ) :
107107

108108
self.assertGreater( font.bound( "T\nT" ).size().y, font.bound( "TT" ).size().y )
109109

110+
def testInvalidChar( self ) :
111+
112+
font = IECoreScene.Font( os.path.join( "test", "IECore", "data", "fonts", "Vera.ttf" ) )
113+
114+
self.assertEqual( font.bound( "X" ), font.bound( b"\xff" ) )
115+
self.assertEqual( font.mesh( "X" ), font.mesh( b"\xff" ) )
116+
110117
if __name__ == "__main__":
111118
unittest.main()

0 commit comments

Comments
 (0)