From: Adeel Kazmi Date: Fri, 28 Aug 2015 17:24:20 +0000 (-0700) Subject: Merge "Fix prevent issues" into devel/master X-Git-Tag: dali_1.1.2~12 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=2047844bb3b4a84231905c8c540d34d4c468e5ad;hp=3e39b3bd20678fc2aba9618f782a830014f2062a Merge "Fix prevent issues" into devel/master --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp index d5baabb..cf3e163 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp @@ -1324,8 +1324,11 @@ int UtcDaliToolkitScrollViewSetMaxOvershootP(void) currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 105, false); overshootXValue = scrollView.GetProperty(ScrollView::Property::OVERSHOOT_X); overshootYValue = scrollView.GetProperty(ScrollView::Property::OVERSHOOT_Y); - DALI_TEST_CHECK(overshootXValue > 0.49f && overshootXValue < 0.51f); - DALI_TEST_CHECK(overshootYValue > 0.49f && overshootYValue < 0.51f); + // The overshoot value is a 0.0f - 1.0f ranged value of the amount overshot related to the maximum overshoot. + // EG. If we move 105, max overshoot is 50, then we overshot 50 / 105. + float correctOvershootValue = 50.0f / 105.f; + DALI_TEST_EQUALS( overshootXValue, correctOvershootValue, 0.001f, TEST_LOCATION ); + DALI_TEST_EQUALS( overshootYValue, correctOvershootValue, 0.001f, TEST_LOCATION ); // Scroll page further in NW (-30,-30 pixels), then check that overshoot should be now 1.0. (don't release touch) currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 30, false); @@ -1373,7 +1376,8 @@ int UtcDaliToolkitScrollViewSetScrollingDirectionP(void) Wait(application); // Try a vertical swipe. PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true); - DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(10.0f, -50.0f), TEST_LOCATION ); + // Take into account resampling done when prediction is off. + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition() - Vector2(0.0f, 0.5f), Vector2(10.0f, -50.0f), 0.25f, TEST_LOCATION ); scrollView.SetScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL); @@ -1389,7 +1393,7 @@ int UtcDaliToolkitScrollViewSetScrollingDirectionP(void) Wait(application); // Try a vertical swipe. PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true); - DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(10.0f, -50.0f), TEST_LOCATION ); + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition() - Vector2(0.0f, 0.5f), Vector2(10.0f, -50.0f), 0.25f, TEST_LOCATION ); END_TEST; } @@ -1423,7 +1427,8 @@ int UtcDaliToolkitScrollViewRemoveScrollingDirectionP(void) Wait(application); // Try a vertical swipe. PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true); - DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(10.0f, -50.0f), TEST_LOCATION ); + // Take into account resampling done when prediction is off. + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition() - Vector2(0.0f, 0.5f), Vector2(10.0f, -50.0f), 0.25f, TEST_LOCATION ); END_TEST; } diff --git a/dali-toolkit/devel-api/styling/style-manager.cpp b/dali-toolkit/devel-api/styling/style-manager.cpp index b3a0028..19e2f1f 100644 --- a/dali-toolkit/devel-api/styling/style-manager.cpp +++ b/dali-toolkit/devel-api/styling/style-manager.cpp @@ -58,6 +58,11 @@ void StyleManager::SetOrientation( Orientation orientation ) GetImpl(*this).SetOrientation( orientation ); } +std::string StyleManager::GetDefaultFontFamily() const +{ + return GetImpl(*this).GetDefaultFontFamily(); +} + Orientation StyleManager::GetOrientation() { return GetImpl(*this).GetOrientation(); diff --git a/dali-toolkit/devel-api/styling/style-manager.h b/dali-toolkit/devel-api/styling/style-manager.h index a568bba..a1596e1 100644 --- a/dali-toolkit/devel-api/styling/style-manager.h +++ b/dali-toolkit/devel-api/styling/style-manager.h @@ -115,6 +115,12 @@ public: Orientation GetOrientation(); /** + * @brief Retrieves the default font family. + * @return The default font family. + */ + std::string GetDefaultFontFamily() const; + + /** * @brief Make a request to set the theme JSON file to one that exists in the Toolkit package. * * Multiple requests per event processing cycle can be made, but only the final one will be acted diff --git a/dali-toolkit/internal/controls/bubble-effect/bubble-actor.cpp b/dali-toolkit/internal/controls/bubble-effect/bubble-actor.cpp index 50df6af..0b3a186 100644 --- a/dali-toolkit/internal/controls/bubble-effect/bubble-actor.cpp +++ b/dali-toolkit/internal/controls/bubble-effect/bubble-actor.cpp @@ -36,7 +36,8 @@ namespace Internal BubbleActor::BubbleActor( unsigned int numberOfBubble, const Vector2& movementArea) : mMovementArea( movementArea ), - mNumBubble( numberOfBubble ) + mNumBubble( numberOfBubble ), + mRandomSeed( 0 ) { mActor = Actor::New(); } @@ -61,18 +62,20 @@ void BubbleActor::MakeRenderable( Geometry geometry, Material material ) mIndexInvertedMovementArea = mActor.RegisterProperty( "uInvertedMovementArea", Vector2(1.f,1.f) / mMovementArea ); - srand(time(NULL)); mIndicesOffset.resize(9); int offset = mMovementArea.Length() / 10.f; - mIndicesOffset[0] = mActor.RegisterProperty( "uOffset[0]", Vector2(0.f,0.f)); - mIndicesOffset[1] = mActor.RegisterProperty( "uOffset[1]", Vector2(rand()%offset,rand()%offset) ); - mIndicesOffset[2] = mActor.RegisterProperty( "uOffset[2]", Vector2(rand()%offset,-rand()%offset) ); - mIndicesOffset[3] = mActor.RegisterProperty( "uOffset[3]", Vector2(-rand()%offset,rand()%offset) ); - mIndicesOffset[4] = mActor.RegisterProperty( "uOffset[4]", Vector2(-rand()%offset,-rand()%offset) ); - mIndicesOffset[5] = mActor.RegisterProperty( "uOffset[5]", Vector2(rand()%offset,0.f)); - mIndicesOffset[6] = mActor.RegisterProperty( "uOffset[6]", Vector2(-rand()%offset,0.f)); - mIndicesOffset[7] = mActor.RegisterProperty( "uOffset[7]", Vector2(0.f,rand()%offset)); - mIndicesOffset[8] = mActor.RegisterProperty( "uOffset[8]", Vector2(0.f,-rand()%offset)); + + mRandomSeed = time( NULL ); + + mIndicesOffset[0] = mActor.RegisterProperty( "uOffset[0]", Vector2( 0.f,0.f ) ); + mIndicesOffset[1] = mActor.RegisterProperty( "uOffset[1]", Vector2( rand_r( &mRandomSeed ) % offset, rand_r( &mRandomSeed ) % offset ) ); + mIndicesOffset[2] = mActor.RegisterProperty( "uOffset[2]", Vector2( rand_r( &mRandomSeed ) % offset, -rand_r( &mRandomSeed ) % offset ) ); + mIndicesOffset[3] = mActor.RegisterProperty( "uOffset[3]", Vector2(-rand_r( &mRandomSeed ) % offset, rand_r( &mRandomSeed ) % offset ) ); + mIndicesOffset[4] = mActor.RegisterProperty( "uOffset[4]", Vector2(-rand_r( &mRandomSeed ) % offset, -rand_r( &mRandomSeed ) % offset ) ); + mIndicesOffset[5] = mActor.RegisterProperty( "uOffset[5]", Vector2( rand_r( &mRandomSeed ) % offset, 0.f ) ); + mIndicesOffset[6] = mActor.RegisterProperty( "uOffset[6]", Vector2(-rand_r( &mRandomSeed ) % offset, 0.f ) ); + mIndicesOffset[7] = mActor.RegisterProperty( "uOffset[7]", Vector2( 0.f, rand_r( &mRandomSeed ) % offset ) ); + mIndicesOffset[8] = mActor.RegisterProperty( "uOffset[8]", Vector2( 0.f, -rand_r( &mRandomSeed ) % offset ) ); Vector4 zeroVector; mIndiceStartEndPos.resize( mNumBubble ); @@ -111,14 +114,15 @@ void BubbleActor::SetMovementArea( const Vector2& movementArea ) mActor.SetProperty( mIndexInvertedMovementArea, Vector2(1.f,1.f) / mMovementArea ); int offset = mMovementArea.Length() / 10.f; - mActor.SetProperty( mIndicesOffset[1], Vector2(rand()%offset,rand()%offset) ); - mActor.SetProperty( mIndicesOffset[2], Vector2(rand()%offset,-rand()%offset) ); - mActor.SetProperty( mIndicesOffset[3], Vector2(-rand()%offset,rand()%offset) ); - mActor.SetProperty( mIndicesOffset[4], Vector2(-rand()%offset,-rand()%offset) ); - mActor.SetProperty( mIndicesOffset[5], Vector2(rand()%offset,0.f)); - mActor.SetProperty( mIndicesOffset[6], Vector2(-rand()%offset,0.f)); - mActor.SetProperty( mIndicesOffset[7], Vector2(0.f,rand()%offset)); - mActor.SetProperty( mIndicesOffset[8], Vector2(0.f,-rand()%offset)); + + mActor.SetProperty( mIndicesOffset[1], Vector2( rand_r( &mRandomSeed ) % offset, rand_r( &mRandomSeed ) % offset ) ); + mActor.SetProperty( mIndicesOffset[2], Vector2( rand_r( &mRandomSeed ) % offset, -rand_r( &mRandomSeed ) % offset ) ); + mActor.SetProperty( mIndicesOffset[3], Vector2(-rand_r( &mRandomSeed ) % offset, rand_r( &mRandomSeed ) % offset ) ); + mActor.SetProperty( mIndicesOffset[4], Vector2(-rand_r( &mRandomSeed ) % offset, -rand_r( &mRandomSeed ) % offset ) ); + mActor.SetProperty( mIndicesOffset[5], Vector2( rand_r( &mRandomSeed ) % offset, 0.f ) ); + mActor.SetProperty( mIndicesOffset[6], Vector2(-rand_r( &mRandomSeed ) % offset, 0.f ) ); + mActor.SetProperty( mIndicesOffset[7], Vector2( 0.f, rand_r( &mRandomSeed ) % offset ) ); + mActor.SetProperty( mIndicesOffset[8], Vector2( 0.f, -rand_r( &mRandomSeed ) % offset ) ); } void BubbleActor::SetStartAndEndPosition( unsigned int index, const Vector4& startAndEndPosition ) diff --git a/dali-toolkit/internal/controls/bubble-effect/bubble-actor.h b/dali-toolkit/internal/controls/bubble-effect/bubble-actor.h index a0938f0..357cddf 100644 --- a/dali-toolkit/internal/controls/bubble-effect/bubble-actor.h +++ b/dali-toolkit/internal/controls/bubble-effect/bubble-actor.h @@ -139,6 +139,7 @@ private: Property::Index mIndexInvertedMovementArea; ///< Index of the property mapping to uniform 'uInvertedMovementArea' unsigned int mNumBubble; ///< How many groups of uniforms are used to control the bubble movement. + unsigned int mRandomSeed; ///< Seed to generate random number. }; } // namespace Internal diff --git a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp index a9b9aa9..9fed7cc 100644 --- a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp +++ b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp @@ -48,11 +48,12 @@ struct Vertex * Return a random value between the given interval. * @param[in] f0 The low bound * @param[in] f1 The up bound + * @param[in] seed The seed to genergate random number * @return A random value between the given interval */ -float RandomRange(float f0, float f1) +float RandomRange(float f0, float f1, unsigned int& seed) { - return f0 + (rand() & 0xfff) * (f1-f0) * (1.0f/4095.0f); + return f0 + (rand_r( &seed ) & 0xfff) * (f1-f0) * (1.0f/4095.0f); } } @@ -76,6 +77,7 @@ BubbleEmitter::BubbleEmitter( const Vector2& movementArea, mDensity( 5 ), mTotalNumOfBubble( maximumNumberOfBubble ), mCurrentBubble( 0 ), + mRandomSeed( 0 ), mRenderTaskRunning(false) { // Calculate how many shaders are required @@ -95,6 +97,8 @@ BubbleEmitter::BubbleEmitter( const Vector2& movementArea, mNumBubblePerActor = mTotalNumOfBubble; mNumActor = 1; } + + mRandomSeed = time( NULL ); } BubbleEmitter::~BubbleEmitter() @@ -297,7 +301,7 @@ Geometry BubbleEmitter::CreateGeometry( unsigned int numOfPatch ) for(unsigned int i = 0; i < numOfPatch; i++) { - float curSize = RandomRange(mBubbleSizeRange.x, mBubbleSizeRange.y); + float curSize = RandomRange(mBubbleSizeRange.x, mBubbleSizeRange.y, mRandomSeed); float index = static_cast( i ); vertexData.push_back( Vertex( index, Vector2(0.f,0.f), Vector2(0.f,0.f) ) ); @@ -340,7 +344,7 @@ void BubbleEmitter::SetBubbleParameter( BubbleActorPtr bubbleActor, unsigned int int halfRange = displacement.x / 2; // for the y coordinate, always negative, so bubbles always go upwards - Vector2 randomVec(rand()%static_cast(displacement.x) - halfRange, -rand()%static_cast(displacement.y)); + Vector2 randomVec( rand_r( &mRandomSeed ) % static_cast(displacement.x) - halfRange, -rand_r( &mRandomSeed ) % static_cast(displacement.y) ); dir.Normalize(); randomVec.x -= dir.x*halfRange; randomVec.y *= 1.0f - fabsf(dir.x)*0.33f; diff --git a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.h b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.h index 91158b2..40b4b74 100644 --- a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.h +++ b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.h @@ -178,6 +178,7 @@ private: unsigned int mDensity; ///< How many bubbles will emit at each time, they are controlled by same uniforms in the shader. unsigned int mTotalNumOfBubble; ///< mNumBubblePerShader*mNumShader. unsigned int mCurrentBubble; ///< Keep track of the index for the newly emitted bubble + unsigned int mRandomSeed; ///< Seed to generate random number. bool mRenderTaskRunning; ///< If the background render task is currently running diff --git a/dali-toolkit/internal/controls/scrollable/item-view/depth-layout.h b/dali-toolkit/internal/controls/scrollable/item-view/depth-layout.h index 82ce8fc..6ce8c73 100644 --- a/dali-toolkit/internal/controls/scrollable/item-view/depth-layout.h +++ b/dali-toolkit/internal/controls/scrollable/item-view/depth-layout.h @@ -214,6 +214,14 @@ protected: private: + // Undefined + DepthLayout( const DepthLayout& depthLayout ); + + // Undefined + DepthLayout& operator=( const DepthLayout& depthLayout ); + +private: + struct Impl; Impl* mImpl; }; diff --git a/dali-toolkit/internal/controls/scrollable/item-view/grid-layout.h b/dali-toolkit/internal/controls/scrollable/item-view/grid-layout.h index 8cbdd33..7476822 100644 --- a/dali-toolkit/internal/controls/scrollable/item-view/grid-layout.h +++ b/dali-toolkit/internal/controls/scrollable/item-view/grid-layout.h @@ -257,6 +257,14 @@ protected: private: + // Undefined + GridLayout( const GridLayout& itemLayout ); + + // Undefined + GridLayout& operator=( const GridLayout& rhs ); + +private: + struct Impl; Impl* mImpl; }; diff --git a/dali-toolkit/internal/controls/scrollable/item-view/spiral-layout.h b/dali-toolkit/internal/controls/scrollable/item-view/spiral-layout.h index 00f550a..1a3e30c 100644 --- a/dali-toolkit/internal/controls/scrollable/item-view/spiral-layout.h +++ b/dali-toolkit/internal/controls/scrollable/item-view/spiral-layout.h @@ -187,6 +187,14 @@ protected: private: + // Undefined + SpiralLayout( const SpiralLayout& spiralLayout ); + + // Undefined + SpiralLayout& operator=( const SpiralLayout& spiralLayout ); + +private: + struct Impl; Impl* mImpl; }; diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index d633e9b..eb12543 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -149,6 +149,9 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr { Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n"); + + if( textField ) { TextField& impl( GetImpl( textField ) ); @@ -210,7 +213,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr if( impl.mController->GetDefaultFontFamily() != fontFamily ) { - impl.mController->SetDefaultFontFamily( fontFamily ); + impl.mController->SetDefaultFontFamily( fontFamily, true ); // "true" as SetProperty means user defined font so don't change when system font changes. } } break; @@ -234,7 +237,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr if( impl.mController ) { const float pointSize = value.Get< float >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %f\n", impl.mController.Get(), pointSize ); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize ); if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) ) { @@ -929,12 +932,10 @@ void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange:: { case StyleChange::DEFAULT_FONT_CHANGE: { - DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE\n"); - if ( mController->GetDefaultFontFamily() == "" ) - { - // Property system did not set the font so should update it. - // todo instruct text-controller to update model - } + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n"); + std::string newFont = styleManager.GetDefaultFontFamily(); + // Property system did not set the font so should update it. + mController->UpdateAfterFontChange( newFont ); break; } @@ -969,6 +970,8 @@ float TextField::GetHeightForWidth( float width ) void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n"); + if( mController->Relayout( size ) || !mRenderer ) { @@ -1130,7 +1133,15 @@ void TextField::OnPan( const PanGesture& gesture ) void TextField::OnLongPress( const LongPressGesture& gesture ) { + // Show the keyboard if it was hidden. + if (!VirtualKeyboard::IsVisible()) + { + VirtualKeyboard::Show(); + } + mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y ); + + SetKeyInputFocus(); } bool TextField::OnKeyEvent( const KeyEvent& event ) diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index 81a5c97..ce08f89 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -151,7 +151,7 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr if( impl.mController->GetDefaultFontFamily() != fontFamily ) { - impl.mController->SetDefaultFontFamily( fontFamily ); + impl.mController->SetDefaultFontFamily( fontFamily, true ); } } break; diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index 08d61fd..41f20e3 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -100,6 +100,7 @@ Toolkit::StyleManager StyleManager::Get() StyleManager::StyleManager() : mOrientationDegrees( 0 ), // Portrait mDefaultFontSize( -1 ), + mDefaultFontFamily(""), mThemeFile( DEFAULT_THEME ), mFeedbackStyle( NULL ) { @@ -155,6 +156,11 @@ void StyleManager::SetOrientation( Orientation orientation ) } } +std::string StyleManager::GetDefaultFontFamily() const +{ + return mDefaultFontFamily; +} + Orientation StyleManager::GetOrientation() { return mOrientation; @@ -417,6 +423,7 @@ void StyleManager::StyleMonitorChange( StyleMonitor styleMonitor, StyleChange::T { case StyleChange::DEFAULT_FONT_CHANGE: { + mDefaultFontFamily = styleMonitor.GetDefaultFontFamily(); break; } diff --git a/dali-toolkit/internal/styling/style-manager-impl.h b/dali-toolkit/internal/styling/style-manager-impl.h index 86c6d4c..ab5e24d 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.h +++ b/dali-toolkit/internal/styling/style-manager-impl.h @@ -81,6 +81,11 @@ public: Orientation GetOrientation(); /** + * @copydoc Toolkit::StyleManager::GetDefaultFontFamily + */ + std::string GetDefaultFontFamily() const; + + /** * @copydoc Toolkit::StyleManager::SetStyleConstant */ void SetStyleConstant( const std::string& key, const Property::Value& value ); @@ -254,6 +259,8 @@ private: int mDefaultFontSize; ///< Logical size, not a point-size + std::string mDefaultFontFamily; + std::string mThemeFile; ///< The full path of the current theme file Property::Map mThemeBuilderConstants; ///< Contants to give the theme builder diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index 9ec055e..69ecac3 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -410,7 +410,6 @@ struct Decorator::Impl : public ConnectionTracker mHandle[ LEFT_SELECTION_HANDLE ].position += scrollOffset; mHandle[ RIGHT_SELECTION_HANDLE ].position += scrollOffset; mHighlightPosition += scrollOffset; - DeterminePositionPopup(); } void ShowPopup() diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index 5ee4992..9062b07 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -105,7 +105,6 @@ struct LayoutEngine::Impl mCursorWidth( CURSOR_WIDTH ), mEllipsisEnabled( false ) { - mFontClient = TextAbstraction::FontClient::Get(); } /** @@ -117,7 +116,7 @@ struct LayoutEngine::Impl void UpdateLineHeight( FontId fontId, LineLayout& lineLayout ) { Text::FontMetrics fontMetrics; - mFontClient.GetFontMetrics( fontId, fontMetrics ); + mMetrics->GetFontMetrics( fontId, fontMetrics ); // Sets the maximum ascender. if( fontMetrics.ascender > lineLayout.ascender ) @@ -634,7 +633,7 @@ struct LayoutEngine::Impl const GlyphInfo& glyphInfo = *( layoutParameters.glyphsBuffer + layoutParameters.totalNumberOfGlyphs - 1u ); Text::FontMetrics fontMetrics; - mFontClient.GetFontMetrics( glyphInfo.fontId, fontMetrics ); + mMetrics->GetFontMetrics( glyphInfo.fontId, fontMetrics ); LineRun lineRun; lineRun.glyphRun.glyphIndex = 0u; @@ -821,7 +820,7 @@ struct LayoutEngine::Impl LayoutEngine::VerticalAlignment mVerticalAlignment; float mCursorWidth; - TextAbstraction::FontClient mFontClient; + IntrusivePtr mMetrics; bool mEllipsisEnabled:1; }; @@ -837,6 +836,11 @@ LayoutEngine::~LayoutEngine() delete mImpl; } +void LayoutEngine::SetMetrics( MetricsPtr& metrics ) +{ + mImpl->mMetrics = metrics; +} + void LayoutEngine::SetLayout( Layout layout ) { mImpl->mLayout = layout; diff --git a/dali-toolkit/internal/text/layouts/layout-engine.h b/dali-toolkit/internal/text/layouts/layout-engine.h index d0f1ab6..f866f3e 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.h +++ b/dali-toolkit/internal/text/layouts/layout-engine.h @@ -24,6 +24,7 @@ // INTERNAL INCLUDE #include +#include namespace Dali { @@ -74,6 +75,13 @@ public: ~LayoutEngine(); /** + * @brief Provide the wrapper around FontClient used to get metrics + * + * @param[in] metrics Used to get metrics + */ + void SetMetrics( MetricsPtr& metrics ); + + /** * @brief Choose the required layout. * * @param[in] layout The required layout. diff --git a/dali-toolkit/internal/text/metrics.h b/dali-toolkit/internal/text/metrics.h new file mode 100644 index 0000000..147ae79 --- /dev/null +++ b/dali-toolkit/internal/text/metrics.h @@ -0,0 +1,134 @@ +#ifndef __DALI_TOOLKIT_TEXT_METRICS_H__ +#define __DALI_TOOLKIT_TEXT_METRICS_H__ + +/* + * Copyright (c) 2015 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Text +{ + +class Metrics; +typedef IntrusivePtr MetricsPtr; + +/** + * @brief A wrapper around FontClient used to get metrics & potentially down-scaled Emoji metrics. + */ +class Metrics : public RefObject +{ +public: + + /** + * Create a new Metrics object + */ + static Metrics* New( TextAbstraction::FontClient& fontClient ) + { + return new Metrics( fontClient ); + } + + /** + * @brief Set the maximum Emoji size. + * + * @param[in] emojiSize Emoticons will be scaled to fit this size in pixels. + */ + void SetMaxEmojiSize( int emojiSize ) + { + mEmojiSize = emojiSize; + } + + /** + * @brief Get the maximum Emoji size. + * + * @return The maximum Emoji size. + */ + int GetMaxEmojiSize() const + { + return mEmojiSize; + } + + /** + * @brief Query the metrics for a font. + * + * @param[in] fontId The ID of the font for the required glyph. + * @param[out] metrics The font metrics. + */ + void GetFontMetrics( FontId fontId, FontMetrics& metrics ) + { + mFontClient.GetFontMetrics( fontId, metrics, mEmojiSize ); // inline for performance + } + + /** + * @brief Retrieve the metrics for a series of glyphs. + * + * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values. + * It may contain the advance and an offset set into the bearing from the shaping tool. + * On return, the glyph's size value will be initialized. The bearing value will be updated by adding the font's glyph bearing to the one set by the shaping tool. + * @param[in] size The size of the array. + * @return True if all of the requested metrics were found. + */ + bool GetGlyphMetrics( GlyphInfo* array, uint32_t size ) + { + return mFontClient.GetGlyphMetrics( array, size, true, mEmojiSize ); // inline for performance + } + +protected: + + /** + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~Metrics() {} + +private: + + /** + * Constructor. + */ + Metrics( TextAbstraction::FontClient& fontClient ) + : mFontClient( fontClient ), + mEmojiSize( 0 ) + { + } + + // Undefined + Metrics(const Metrics&); + + // Undefined + Metrics& operator=(const Metrics& rhs); + +private: + + TextAbstraction::FontClient mFontClient; + + int mEmojiSize; +}; + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_TEXT_METRICS_H__ diff --git a/dali-toolkit/internal/text/multi-language-support-impl.cpp b/dali-toolkit/internal/text/multi-language-support-impl.cpp index d730c9e..bb33981 100644 --- a/dali-toolkit/internal/text/multi-language-support-impl.cpp +++ b/dali-toolkit/internal/text/multi-language-support-impl.cpp @@ -363,7 +363,7 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, // Copy the fonts set by application developers. const Length numberOfFontRuns = fonts.Count(); - const Vector definedFonts = fonts; + const Vector userSetFonts = fonts; fonts.Clear(); // Traverse the characters and validate/set the fonts. @@ -386,8 +386,8 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); // Iterators of the font and script runs. - Vector::ConstIterator fontRunIt = definedFonts.Begin(); - Vector::ConstIterator fontRunEndIt = definedFonts.End(); + Vector::ConstIterator fontRunIt = userSetFonts.Begin(); + Vector::ConstIterator fontRunEndIt = userSetFonts.End(); Vector::ConstIterator scriptRunIt = scripts.Begin(); Vector::ConstIterator scriptRunEndIt = scripts.End(); diff --git a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp index a4fc1d8..026b4d6 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -331,6 +331,16 @@ struct AtlasRenderer::Impl : public ConnectionTracker textCacheEntry.mIndex = glyph.index; newTextCache.PushBack( textCacheEntry ); + // Adjust the vertices if the fixed-size font should be down-scaled + if( glyph.scaleFactor > 0 ) + { + for( unsigned int i=0; imGlyphs.Begin(); const GlyphInfo& firstGlyph = *( glyphsBuffer + glyphIndex ); Text::FontMetrics fontMetrics; - fontClient.GetFontMetrics( firstGlyph.fontId, fontMetrics ); + metrics->GetFontMetrics( firstGlyph.fontId, fontMetrics ); glyphMetrics.fontHeight = fontMetrics.height; glyphMetrics.advance = firstGlyph.advance; @@ -423,7 +423,7 @@ void Controller::Impl::UpdateModel( OperationsMask operationsRequired ) if( GET_GLYPH_METRICS & operations ) { GlyphInfo* glyphsBuffer = glyphs.Begin(); - mFontClient.GetGlyphMetrics( glyphsBuffer, numberOfGlyphs ); + mMetrics->GetGlyphMetrics( glyphsBuffer, numberOfGlyphs ); // Update the width and advance of all new paragraph characters. for( Vector::ConstIterator it = newParagraphGlyphs.Begin(), endIt = newParagraphGlyphs.End(); it != endIt; ++it ) @@ -487,7 +487,7 @@ float Controller::Impl::GetDefaultFontLineHeight() } Text::FontMetrics fontMetrics; - mFontClient.GetFontMetrics( defaultFontId, fontMetrics ); + mMetrics->GetFontMetrics( defaultFontId, fontMetrics ); return( fontMetrics.ascender - fontMetrics.descender ); } @@ -1462,7 +1462,7 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, numberOfGlyphs, glyphMetrics, mVisualModel, - mFontClient ); + mMetrics ); const Vector2& position = *( positionsBuffer + glyphLogicalOrderIndex ); @@ -1601,7 +1601,7 @@ void Controller::Impl::GetCursorPosition( CharacterIndex logical, primaryNumberOfGlyphs, glyphMetrics, mVisualModel, - mFontClient ); + mMetrics ); // Whether to add the glyph's advance to the cursor position. // i.e if the paragraph is left to right and the logical cursor is zero, the position is the position of the first glyph and the advance is not added, @@ -1691,7 +1691,7 @@ void Controller::Impl::GetCursorPosition( CharacterIndex logical, secondaryNumberOfGlyphs, glyphMetrics, mVisualModel, - mFontClient ); + mMetrics ); // Set the secondary cursor's position. cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + ( isCurrentRightToLeft ? 0.f : glyphMetrics.advance ); @@ -1777,7 +1777,7 @@ void Controller::Impl::UpdateCursorPosition() } Text::FontMetrics fontMetrics; - mFontClient.GetFontMetrics( defaultFontId, fontMetrics ); + mMetrics->GetFontMetrics( defaultFontId, fontMetrics ); lineHeight = fontMetrics.ascender - fontMetrics.descender; diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 3073611..e60fe37 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include // INTERNAL INCLUDES #include @@ -174,7 +175,9 @@ struct ModifyEvent struct FontDefaults { FontDefaults() - : mDefaultPointSize(0.0f), + : mDefaultFontFamily(""), + mDefaultFontStyle(""), + mDefaultPointSize(0.0f), mFontId(0u) { } @@ -207,13 +210,15 @@ struct Controller::Impl mFontClient(), mClipboard(), mView(), + mMetrics(), mLayoutEngine(), mModifyEvents(), mTextColor( Color::BLACK ), mAlignmentOffset(), mOperationsPending( NO_OPERATION ), mMaximumNumberOfCharacters( 50 ), - mRecalculateNaturalSize( true ) + mRecalculateNaturalSize( true ), + mUserDefinedFontFamily( false) { mLogicalModel = LogicalModel::New(); mVisualModel = VisualModel::New(); @@ -223,6 +228,10 @@ struct Controller::Impl mView.SetVisualModel( mVisualModel ); + // Use this to access FontClient i.e. to get down-scaled Emoji metrics. + mMetrics = Metrics::New( mFontClient ); + mLayoutEngine.SetMetrics( mMetrics ); + // Set the text properties to default mVisualModel->SetUnderlineEnabled( false ); mVisualModel->SetUnderlineHeight( 0.0f ); @@ -468,15 +477,18 @@ struct Controller::Impl FontDefaults* mFontDefaults; ///< Avoid allocating this when the user does not specify a font. EventData* mEventData; ///< Avoid allocating everything for text input until EnableTextInput(). TextAbstraction::FontClient mFontClient; ///< Handle to the font client. - Clipboard mClipboard; ///< Handle to the system clipboard + Clipboard mClipboard; ///< Handle to the system clipboard View mView; ///< The view interface to the rendering back-end. + MetricsPtr mMetrics; ///< A wrapper around FontClient used to get metrics & potentially down-scaled Emoji metrics. LayoutEngine mLayoutEngine; ///< The layout engine. std::vector mModifyEvents; ///< Temporary stores the text set until the next relayout. Vector4 mTextColor; ///< The regular text color Vector2 mAlignmentOffset; ///< Vertical and horizontal offset of the whole text inside the control due to alignment. OperationsMask mOperationsPending; ///< Operations pending to be done to layout the text. Length mMaximumNumberOfCharacters; ///< Maximum number of characters that can be inserted. + bool mRecalculateNaturalSize:1; ///< Whether the natural size needs to be recalculated. + bool mUserDefinedFontFamily:1; ///< Whether the Font family was Set by the user instead of being left as sytem default }; } // namespace Text diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index e3b29bd..47afc96 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -38,6 +38,7 @@ namespace #endif const float MAX_FLOAT = std::numeric_limits::max(); +const unsigned int POINTS_PER_INCH = 72; const std::string EMPTY_STRING(""); @@ -73,6 +74,8 @@ void Controller::EnableTextInput( DecoratorPtr decorator ) void Controller::SetText( const std::string& text ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" ); + // Remove the previously set text ResetText(); @@ -222,7 +225,7 @@ int Controller::GetMaximumNumberOfCharacters() return mImpl->mMaximumNumberOfCharacters; } -void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily ) +void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily, bool userDefined ) { if( !mImpl->mFontDefaults ) { @@ -230,7 +233,7 @@ void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily ) } mImpl->mFontDefaults->mDefaultFontFamily = defaultFontFamily; - + mImpl->mUserDefinedFontFamily = userDefined; // Clear the font-specific data ClearFontData(); @@ -287,6 +290,15 @@ void Controller::SetDefaultPointSize( float pointSize ) mImpl->mFontDefaults->mDefaultPointSize = pointSize; + unsigned int horizontalDpi( 0u ); + unsigned int verticalDpi( 0u ); + mImpl->mFontClient.GetDpi( horizontalDpi, verticalDpi ); + + // Adjust the metrics if the fixed-size font should be down-scaled + int maxEmojiSize( pointSize/POINTS_PER_INCH * verticalDpi ); + DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultPointSize %p setting MaxEmojiSize %d\n", this, maxEmojiSize ); + mImpl->mMetrics->SetMaxEmojiSize( maxEmojiSize ); + // Clear the font-specific data ClearFontData(); @@ -306,6 +318,23 @@ float Controller::GetDefaultPointSize() const return 0.0f; } +void Controller::UpdateAfterFontChange( std::string& newDefaultFont ) +{ + DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange"); + + ClearFontData(); + + if ( !mImpl->mUserDefinedFontFamily ) // If user defined font then should not update when system font changes + { + DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() ); + mImpl->mFontDefaults->mDefaultFontFamily=newDefaultFont; + mImpl->UpdateModel( ALL_OPERATIONS ); + mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED ); + mImpl->mRecalculateNaturalSize = true; + mImpl->RequestRelayout(); + } +} + void Controller::SetTextColor( const Vector4& textColor ) { mImpl->mTextColor = textColor; @@ -641,11 +670,24 @@ bool Controller::Relayout( const Size& size ) // Do not re-do any operation until something changes. mImpl->mOperationsPending = NO_OPERATION; + // Keep the current offset and alignment as it will be used to update the decorator's positions. + Vector2 offset; + if( mImpl->mEventData ) + { + offset = mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition; + } + // After doing the text layout, the alignment offset to place the actor in the desired position can be calculated. CalculateTextAlignment( size ); if( mImpl->mEventData ) { + // If there is a nex size, the scroll position needs to be clamped. + mImpl->ClampHorizontalScroll( layoutSize ); + + // Update the decorator's positions. + mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition - offset ); + // Move the cursor, grab handle etc. updated = mImpl->ProcessInputEvents() || updated; } diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 99c2ab0..fa4f966 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -178,8 +178,9 @@ public: * @brief Set the default font family. * * @param[in] defaultFontFamily The default font family. + * @param[in] userDefined If set by the user */ - void SetDefaultFontFamily( const std::string& defaultFontFamily ); + void SetDefaultFontFamily( const std::string& defaultFontFamily, bool userDefined ); /** * @brief Retrieve the default font family. @@ -217,6 +218,12 @@ public: float GetDefaultPointSize() const; /** + * @ brief Update the text after a font change + * @param[in] newDefaultFont The new font to change to + */ + void UpdateAfterFontChange( std::string& newDefaultFont ); + + /** * @brief Set the text color * * @param textColor The text color diff --git a/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h b/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h index cc1a2ae..39370ac 100644 --- a/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h +++ b/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h @@ -346,6 +346,18 @@ protected: */ DALI_IMPORT_API ItemLayout(); +private: + + /** + * Don't allow copy constructor + */ + ItemLayout( const ItemLayout& handle ); + + /** + * Don't allow copy operator + */ + ItemLayout& operator=( const ItemLayout& handle ); + protected: struct Impl;