예제 #1
0
Vector3 GetNaturalSize( Actor actor )
{
  Vector3 size = actor.GetCurrentSize();
  const float depth = size.depth;

  // Get natural size for TextActor.
  TextActor textActor = TextActor::DownCast( actor );
  if( textActor )
  {
    Font font = textActor.GetFont();
    if( !font )
    {
      font = Font::New();
    }
    size = font.MeasureText( textActor.GetText() );
    size.depth = depth;
  }

  // Get natural size for ImageActor.
  // TODO: currently it doesn't work as expected.
  ImageActor imageActor = ImageActor::DownCast( actor );
  if( ( imageActor ) && ( imageActor.GetImage() ) )
  {
    Image image = imageActor.GetImage();
    size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), depth );
  }

  return size;
}
예제 #2
0
float GetHeightForWidth( Actor actor, float width )
{
  Vector3 size = actor.GetCurrentSize();
  float height = 0.f;

  TextActor textActor = TextActor::DownCast( actor );
  if( textActor )
  {
    Font font = textActor.GetFont();
    if( !font )
    {
      font = Font::New();
    }
    size = font.MeasureText( textActor.GetText() );
  }

  ImageActor imageActor = ImageActor::DownCast( actor );
  if( ( imageActor ) && ( imageActor.GetImage() ) )
  {
    Image image = imageActor.GetImage();
    size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), 0.f );
  }

  height = size.height / ( size.width / width );

  return height;
}
void dbgPrint( const WordLayoutInfo& word )
{
  for( CharacterLayoutInfoContainer::const_iterator characterIt = word.mCharactersLayoutInfo.begin(), endCharacterIt = word.mCharactersLayoutInfo.end();
       characterIt != endCharacterIt;
       ++characterIt )
  {
    const CharacterLayoutInfo& character( *characterIt );

    std::cout << "[" << character.mSize << std::endl;
    std::cout << " ascender " << character.mAscender << std::endl;

    TextActor textActor = TextActor::DownCast( character.mGlyphActor );
    if( textActor )
    {
      std::cout << "[" << textActor.GetText() << "]";
    }
    else
    {
      std::cout << "[ImageActor]" << std::endl;
    }
    std::cout << "{" << character.mStyledText.mText.GetText() << "}";
  }
  std::cout << "     size " << word.mSize << std::endl;
  std::cout << " ascender " << word.mAscender << std::endl;
  std::cout << " num char " << word.mCharactersLayoutInfo.size() << std::endl;
  std::cout << "     type ";
  switch( word.mType )
  {
    case NoSeparator:
    {
      std::cout << "NoSeparator" << std::endl;
      break;
    }
    case LineSeparator:
    {
      std::cout << "LineSeparator" << std::endl;
      break;
    }
    case WordSeparator:
    {
      std::cout << "WordSeparator" << std::endl;
      break;
    }
  }
}