+bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
+{
+ Size textSize;
+ mImpl->mFontDefaults->mFitPointSize = pointSize;
+ mImpl->mFontDefaults->sizeDefined = true;
+ ClearFontData();
+
+ // Operations that can be done only once until the text changes.
+ const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
+ GET_SCRIPTS |
+ VALIDATE_FONTS |
+ GET_LINE_BREAKS |
+ BIDI_INFO |
+ SHAPE_TEXT|
+ GET_GLYPH_METRICS );
+
+ mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
+ mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
+
+ // Make sure the model is up-to-date before layouting
+ mImpl->UpdateModel( onlyOnceOperations );
+
+ DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
+ static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
+ textSize);
+
+ // Clear the update info. This info will be set the next time the text is updated.
+ mImpl->mTextUpdateInfo.Clear();
+ mImpl->mTextUpdateInfo.mClearAll = true;
+
+ if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
+ {
+ return false;
+ }
+ return true;
+}
+
+void Controller::FitPointSizeforLayout( Size layoutSize )
+{
+ const OperationsMask operations = mImpl->mOperationsPending;
+ if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
+ {
+ bool actualellipsis = mImpl->mModel->mElideEnabled;
+ float minPointSize = mImpl->mTextFitMinSize;
+ float maxPointSize = mImpl->mTextFitMaxSize;
+ float pointInterval = mImpl->mTextFitStepSize;
+
+ mImpl->mModel->mElideEnabled = false;
+ Vector<float> pointSizeArray;
+
+ // check zero value
+ if( pointInterval < 1.f )
+ {
+ mImpl->mTextFitStepSize = pointInterval = 1.0f;
+ }
+
+ pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
+
+ for( float i = minPointSize; i < maxPointSize; i += pointInterval )
+ {
+ pointSizeArray.PushBack( i );
+ }
+
+ pointSizeArray.PushBack( maxPointSize );
+
+ int bestSizeIndex = 0;
+ int min = bestSizeIndex + 1;
+ int max = pointSizeArray.Size() - 1;
+ while( min <= max )
+ {
+ int destI = ( min + max ) / 2;
+
+ if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
+ {
+ bestSizeIndex = min;
+ min = destI + 1;
+ }
+ else
+ {
+ max = destI - 1;
+ bestSizeIndex = max;
+ }
+ }
+
+ mImpl->mModel->mElideEnabled = actualellipsis;
+ mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
+ mImpl->mFontDefaults->sizeDefined = true;
+ ClearFontData();
+ }
+}
+