<commit_before>/*
 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * @file text-memory-profiling-example.cpp
 * @brief Memory consumption profiling for TextLabel
 */

// EXTERNAL INCLUDES
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
#include <dali-toolkit/devel-api/controls/navigation-view/navigation-view.h>

// INTERNAL INCLUDES
#include "shared/view.h"

using namespace Dali;
using namespace Dali::Toolkit;

namespace
{

enum TextType
{
  SINGLE_COLOR_TEXT,
  SINGLE_COLOR_TEXT_WITH_STYLE,
  SINGLE_COLOR_TEXT_WITH_EMOJI,
  SINGLE_COLOR_TEXT_WITH_STYLE_EMOJI,
  MULTI_COLOR_TEXT,
  MULTI_COLOR_TEXT_WITH_STYLE,
  MULTI_COLOR_TEXT_WITH_EMOJI,
  MULTI_COLOR_TEXT_WITH_STYLE_EMOJI,
  NUMBER_OF_TYPES
};

std::string TEXT_TYPE_STRING[ NUMBER_OF_TYPES ] =
{
  "Single color text",
  "Single color text with style",
  "Single color text with emoji",
  "Single color text with style and emoji",
  "Multi color text",
  "Multi color text with style",
  "Multi color text with emoji",
  "Multi color text with style and emoji"
};

const int NUMBER_OF_LABELS = 500;

const char* BACKGROUND_IMAGE( "" );
const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
const char* BACK_IMAGE( DEMO_IMAGE_DIR "icon-change.png" );
const char* BACK_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
const char* INDICATOR_IMAGE( DEMO_IMAGE_DIR "loading.png" );

} // anonymous namespace

/**
 * @brief The main class of the demo.
 */
class TextMemoryProfilingExample : public ConnectionTracker, public Toolkit::ItemFactory
{
public:

  TextMemoryProfilingExample( Application& application )
  : mApplication( application ),
    mCurrentTextStyle( SINGLE_COLOR_TEXT )
  {
    // Connect to the Application's Init signal
    mApplication.InitSignal().Connect( this, &TextMemoryProfilingExample::Create );
  }

  ~TextMemoryProfilingExample()
  {
    // Nothing to do here.
  }

  /**
   * @brief Create a text label in the given type
   */
  TextLabel SetupTextLabel( int type )
  {
    TextLabel label = TextLabel::New();
    label.SetAnchorPoint( ParentOrigin::TOP_LEFT );
    label.SetAnchorPoint( AnchorPoint::TOP_LEFT );
    label.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK );
    label.SetProperty( TextLabel::Property::POINT_SIZE, 12.0f );
    label.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::YELLOW );
    label.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );

    Vector2 stageSize = Stage::GetCurrent().GetSize();
    label.SetPosition( Vector3( Random::Range( 0.0f, stageSize.x ), Random::Range( 0.0f, stageSize.y ), 0.0f) );

    switch ( type )
    {
      case SINGLE_COLOR_TEXT:
      {
        label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.0f, 0.0f ) );
        break;
      }
      case SINGLE_COLOR_TEXT_WITH_STYLE:
      {
        label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 2.0f, 2.0f ) );
        break;
      }
      case SINGLE_COLOR_TEXT_WITH_EMOJI:
      {
        label.SetProperty( TextLabel::Property::TEXT, "\xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.0f, 0.0f ) );
        break;
      }
      case SINGLE_COLOR_TEXT_WITH_STYLE_EMOJI:
      {
        label.SetProperty( TextLabel::Property::TEXT, "\xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 2.0f, 2.0f ) );
        break;
      }
      case MULTI_COLOR_TEXT:
      {
        label.SetProperty( TextLabel::Property::TEXT, "A <color value='cyan'>Quick Brown Fox</color> Jumps Over The <color value='yellow'>Lazy Dog</color>" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.0f, 0.0f ) );
        break;
      }
      case MULTI_COLOR_TEXT_WITH_STYLE:
      {
        label.SetProperty( TextLabel::Property::TEXT, "A <color value='cyan'>Quick Brown Fox</color> Jumps Over The <color value='yellow'>Lazy Dog</color>" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 2.0f, 2.0f ) );
        break;
      }
      case MULTI_COLOR_TEXT_WITH_EMOJI:
      {
        label.SetProperty( TextLabel::Property::TEXT, " \xF0\x9F\x98\x81 A <color value='cyan'>Quick Brown Fox</color> Jumps Over The <color value='yellow'>Lazy Dog</color>" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.0f, 0.0f ) );
        break;
      }
      case MULTI_COLOR_TEXT_WITH_STYLE_EMOJI:
      {
        label.SetProperty( TextLabel::Property::TEXT, " \xF0\x9F\x98\x81 A <color value='cyan'>Quick Brown Fox</color> Jumps Over The <color value='yellow'>Lazy Dog</color>" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 2.0f, 2.0f ) );
        break;
      }
      default:
        break;
    }

    return label;
  }

  /**
   * @brief Create the main menu
   */
  void CreateMainMenu()
  {
    Stage stage = Stage::GetCurrent();
    Vector2 stageSize = stage.GetSize();

    mTapDetector = TapGestureDetector::New();
    mTapDetector.DetectedSignal().Connect( this, &TextMemoryProfilingExample::OnTap );

    // Create an item view for the main menu
    mItemView = ItemView::New( *this );

    mItemView.SetParentOrigin( ParentOrigin::CENTER );
    mItemView.SetAnchorPoint( AnchorPoint::CENTER );

    mLayout = DefaultItemLayout::New( DefaultItemLayout::LIST );<commit_msg>Added memory consumption test for small text in large TextLabel<commit_after>/*
 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * @file text-memory-profiling-example.cpp
 * @brief Memory consumption profiling for TextLabel
 */

// EXTERNAL INCLUDES
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
#include <dali-toolkit/devel-api/controls/navigation-view/navigation-view.h>

// INTERNAL INCLUDES
#include "shared/view.h"

using namespace Dali;
using namespace Dali::Toolkit;

namespace
{

enum TextType
{
  SINGLE_COLOR_TEXT,
  SINGLE_COLOR_TEXT_WITH_STYLE,
  SINGLE_COLOR_TEXT_WITH_EMOJI,
  SINGLE_COLOR_TEXT_WITH_STYLE_EMOJI,
  MULTI_COLOR_TEXT,
  MULTI_COLOR_TEXT_WITH_STYLE,
  MULTI_COLOR_TEXT_WITH_EMOJI,
  MULTI_COLOR_TEXT_WITH_STYLE_EMOJI,
  SMALL_TEXT_IN_LARGE_TEXT_LABEL,
  NUMBER_OF_TYPES
};

std::string TEXT_TYPE_STRING[ NUMBER_OF_TYPES ] =
{
  "Single color text",
  "Single color text with style",
  "Single color text with emoji",
  "Single color text with style and emoji",
  "Multi color text",
  "Multi color text with style",
  "Multi color text with emoji",
  "Multi color text with style and emoji",
  "Small text in large Text Label"
};

const int NUMBER_OF_LABELS = 500;

const char* BACKGROUND_IMAGE( "" );
const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
const char* BACK_IMAGE( DEMO_IMAGE_DIR "icon-change.png" );
const char* BACK_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
const char* INDICATOR_IMAGE( DEMO_IMAGE_DIR "loading.png" );

} // anonymous namespace

/**
 * @brief The main class of the demo.
 */
class TextMemoryProfilingExample : public ConnectionTracker, public Toolkit::ItemFactory
{
public:

  TextMemoryProfilingExample( Application& application )
  : mApplication( application ),
    mCurrentTextStyle( SINGLE_COLOR_TEXT )
  {
    // Connect to the Application's Init signal
    mApplication.InitSignal().Connect( this, &TextMemoryProfilingExample::Create );
  }

  ~TextMemoryProfilingExample()
  {
    // Nothing to do here.
  }

  /**
   * @brief Create a text label in the given type
   */
  TextLabel SetupTextLabel( int type )
  {
    TextLabel label = TextLabel::New();
    label.SetAnchorPoint( ParentOrigin::TOP_LEFT );
    label.SetAnchorPoint( AnchorPoint::TOP_LEFT );
    label.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK );
    label.SetProperty( TextLabel::Property::POINT_SIZE, 12.0f );
    label.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::YELLOW );
    label.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );

    Vector2 stageSize = Stage::GetCurrent().GetSize();
    label.SetPosition( Vector3( Random::Range( 0.0f, stageSize.x ), Random::Range( 0.0f, stageSize.y ), 0.0f) );

    switch ( type )
    {
      case SINGLE_COLOR_TEXT:
      {
        label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.0f, 0.0f ) );
        break;
      }
      case SINGLE_COLOR_TEXT_WITH_STYLE:
      {
        label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 2.0f, 2.0f ) );
        break;
      }
      case SINGLE_COLOR_TEXT_WITH_EMOJI:
      {
        label.SetProperty( TextLabel::Property::TEXT, "\xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.0f, 0.0f ) );
        break;
      }
      case SINGLE_COLOR_TEXT_WITH_STYLE_EMOJI:
      {
        label.SetProperty( TextLabel::Property::TEXT, "\xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 2.0f, 2.0f ) );
        break;
      }
      case MULTI_COLOR_TEXT:
      {
        label.SetProperty( TextLabel::Property::TEXT, "A <color value='cyan'>Quick Brown Fox</color> Jumps Over The <color value='yellow'>Lazy Dog</color>" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.0f, 0.0f ) );
        break;
      }
      case MULTI_COLOR_TEXT_WITH_STYLE:
      {
        label.SetProperty( TextLabel::Property::TEXT, "A <color value='cyan'>Quick Brown Fox</color> Jumps Over The <color value='yellow'>Lazy Dog</color>" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 2.0f, 2.0f ) );
        break;
      }
      case MULTI_COLOR_TEXT_WITH_EMOJI:
      {
        label.SetProperty( TextLabel::Property::TEXT, " \xF0\x9F\x98\x81 A <color value='cyan'>Quick Brown Fox</color> Jumps Over The <color value='yellow'>Lazy Dog</color>" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.0f, 0.0f ) );
        break;
      }
      case MULTI_COLOR_TEXT_WITH_STYLE_EMOJI:
      {
        label.SetProperty( TextLabel::Property::TEXT, " \xF0\x9F\x98\x81 A <color value='cyan'>Quick Brown Fox</color> Jumps Over The <color value='yellow'>Lazy Dog</color>" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 2.0f, 2.0f ) );
        break;
      }
      case SMALL_TEXT_IN_LARGE_TEXT_LABEL:
      {
        label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
        label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.0f, 0.0f ) );
        label.SetSize(stageSize.x, stageSize.y * 0.25f); // Set the text label in larger size
        break;
      }
      default:
        break;
    }

    return label;
  }

  /**
   * @brief Create the main menu
   */
  void CreateMainMenu()
  {
    Stage stage = Stage::GetCurrent();
    Vector2 stageSize = stage.GetSize();

    mTapDetector = TapGestureDetector::New();
    mTapDetector.DetectedSignal().Connect( this, &TextMemoryProfilingExample::OnTap );

    // Create an item view for the main menu
    mItemView = ItemView::New( *this );

    mItemView.SetParentOrigin( ParentOrigin::CENTER );
    mItemView.SetAnchorPoint( AnchorPoint::CENTER );

    mLayout = DefaultItemLayout::New( DefaultItemLayout::LIST );
{'fraction_non_alphanumeric': 0.11636700362682306, 'fraction_numerical': 0.0140442935411683, 'mean_word_length': 3.65016146393972, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6960364', 'n_tokens_mistral': 4439, 'n_tokens_neox': 4232, 'n_words': 1011}