Skip to content

Commit

Permalink
GafferImage::Text : Fixed vertical alignment issue
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldresser committed Oct 10, 2017
1 parent f5c69cd commit c645e66
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/GafferImage/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ IECore::ConstCompoundObjectPtr Text::computeLayout( const Gaffer::Context *conte
vector<Line> lines;
lines.push_back( Line( pen.y ) );

int penYCutoff = area.min.y - face->size->metrics.descender;

const std::string text = textPlug()->getValue();
typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
boost::char_separator<char> separator( "", " \n\t" );
Expand All @@ -394,6 +396,13 @@ IECore::ConstCompoundObjectPtr Text::computeLayout( const Gaffer::Context *conte
if( *it == "\n" )
{
pen.x = area.min.x;

if( pen.y - face->size->metrics.height < penYCutoff )
{
// We ran out of vertical space.
break;
}

pen.y -= face->size->metrics.height;
lines.push_back( Line( pen.y ) );
}
Expand All @@ -407,14 +416,16 @@ IECore::ConstCompoundObjectPtr Text::computeLayout( const Gaffer::Context *conte
if( pen.x + width > area.max.x )
{
pen.x = area.min.x;

if( pen.y - face->size->metrics.height < penYCutoff )
{
// We ran out of vertical space.
break;
}

pen.y -= face->size->metrics.height;
lines.push_back( Line( pen.y ) );
}
if( ( pen.y + face->size->metrics.descender ) < area.min.y )
{
// We ran out of vertical space.
break;
}

lines.back().words.push_back( Word( *it, pen.x ) );
pen.x += width;
Expand Down

0 comments on commit c645e66

Please sign in to comment.