// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/bidirectional-support.h>
#include <dali-toolkit/internal/text/character-set-conversion.h>
-#include <dali-toolkit/internal/text/layouts/layout-parameters.h>
#include <dali-toolkit/internal/text/multi-language-support.h>
-#include <dali-toolkit/internal/text/script-run.h>
#include <dali-toolkit/internal/text/segmentation.h>
#include <dali-toolkit/internal/text/shaper.h>
-#include <dali-toolkit/internal/text/text-io.h>
-#include <dali-toolkit/internal/text/text-view.h>
namespace
{
#if defined(DEBUG_ENABLED)
- Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
+ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
#endif
/**
float xBearing; ///< The x bearing of the first glyph.
};
-const std::string EMPTY_STRING("");
-
} // namespace
namespace Dali
* @param[in] numberOfGlyphs The number of glyphs.
* @param[out] glyphMetrics Some glyph metrics (font height, advance, ascender and x bearing).
* @param[in] visualModel The visual model.
- * @param[in] fontClient The font client.
+ * @param[in] metrics Used to access metrics from FontClient.
*/
void GetGlyphsMetrics( GlyphIndex glyphIndex,
Length numberOfGlyphs,
GlyphMetrics& glyphMetrics,
- VisualModelPtr visualModel,
- TextAbstraction::FontClient& fontClient )
+ VisualModelPtr& visualModel,
+ MetricsPtr& metrics )
{
const GlyphInfo* glyphsBuffer = visualModel->mGlyphs.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;
void Controller::Impl::UpdateModel( OperationsMask operationsRequired )
{
+ DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::UpdateModel\n" );
+
// Calculate the operations to be done.
const OperationsMask operations = static_cast<OperationsMask>( mOperationsPending & operationsRequired );
{
// Retrieves the scripts used in the text.
multilanguageSupport.SetScripts( utf32Characters,
- lineBreakInfo,
scripts );
}
Vector<Character> mirroredUtf32Characters;
bool textMirrored = false;
+ Length numberOfParagraphs = 0u;
if( BIDI_INFO & operations )
{
// Count the number of LINE_NO_BREAK to reserve some space for the vector of paragraph's
// bidirectional info.
- Length numberOfParagraphs = 0u;
-
const TextAbstraction::LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin();
for( Length index = 0u; index < numberOfCharacters; ++index )
{
// This paragraph has right to left text. Some characters may need to be mirrored.
// TODO: consider if the mirrored string can be stored as well.
- textMirrored = GetMirroredText( utf32Characters, mirroredUtf32Characters );
+ textMirrored = GetMirroredText( utf32Characters,
+ mirroredUtf32Characters,
+ bidirectionalInfo );
// Only set the character directions if there is right to left characters.
Vector<CharacterDirection>& directions = mLogicalModel->mCharacterDirections;
Vector<GlyphInfo>& glyphs = mVisualModel->mGlyphs;
Vector<CharacterIndex>& glyphsToCharactersMap = mVisualModel->mGlyphsToCharacters;
Vector<Length>& charactersPerGlyph = mVisualModel->mCharactersPerGlyph;
+ Vector<GlyphIndex> newParagraphGlyphs;
+ newParagraphGlyphs.Reserve( numberOfParagraphs );
+
if( SHAPE_TEXT & operations )
{
const Vector<Character>& textToShape = textMirrored ? mirroredUtf32Characters : utf32Characters;
validFonts,
glyphs,
glyphsToCharactersMap,
- charactersPerGlyph );
+ charactersPerGlyph,
+ newParagraphGlyphs );
// Create the 'number of glyphs' per character and the glyph to character conversion tables.
mVisualModel->CreateGlyphsPerCharacterTable( numberOfCharacters );
if( GET_GLYPH_METRICS & operations )
{
- mFontClient.GetGlyphMetrics( glyphs.Begin(), numberOfGlyphs );
+ GlyphInfo* glyphsBuffer = glyphs.Begin();
+ mMetrics->GetGlyphMetrics( glyphsBuffer, numberOfGlyphs );
+
+ // Update the width and advance of all new paragraph characters.
+ for( Vector<GlyphIndex>::ConstIterator it = newParagraphGlyphs.Begin(), endIt = newParagraphGlyphs.End(); it != endIt; ++it )
+ {
+ const GlyphIndex index = *it;
+ GlyphInfo& glyph = *( glyphsBuffer + index );
+
+ glyph.xBearing = 0.f;
+ glyph.width = 0.f;
+ glyph.advance = 0.f;
+ }
+ }
+
+ if( mEventData &&
+ mEventData->mPreEditFlag &&
+ ( 0u != mVisualModel->mCharactersToGlyph.Count() ) )
+ {
+ // Add the underline for the pre-edit text.
+ const GlyphIndex* const charactersToGlyphBuffer = mVisualModel->mCharactersToGlyph.Begin();
+ const Length* const glyphsPerCharacterBuffer = mVisualModel->mGlyphsPerCharacter.Begin();
+
+ const GlyphIndex glyphStart = *( charactersToGlyphBuffer + mEventData->mPreEditStartPosition );
+ const CharacterIndex lastPreEditCharacter = mEventData->mPreEditStartPosition + ( ( mEventData->mPreEditLength > 0u ) ? mEventData->mPreEditLength - 1u : 0u );
+ const Length numberOfGlyphsLastCharacter = *( glyphsPerCharacterBuffer + lastPreEditCharacter );
+ const GlyphIndex glyphEnd = *( charactersToGlyphBuffer + lastPreEditCharacter ) + ( numberOfGlyphsLastCharacter > 1u ? numberOfGlyphsLastCharacter - 1u : 0u );
+
+ GlyphRun underlineRun;
+ underlineRun.glyphIndex = glyphStart;
+ underlineRun.numberOfGlyphs = 1u + glyphEnd - glyphStart;
+
+ // TODO: At the moment the underline runs are only for pre-edit.
+ mVisualModel->mUnderlineRuns.PushBack( underlineRun );
}
}
{
if( mFontDefaults )
{
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::GetDefaultFonts font family(%s)\n", mFontDefaults->mFontDescription.family.c_str() );
FontRun fontRun;
fontRun.characterRun.characterIndex = 0;
fontRun.characterRun.numberOfCharacters = numberOfCharacters;
FontId defaultFontId = 0u;
if( NULL == mFontDefaults )
{
- defaultFontId = mFontClient.GetFontId( EMPTY_STRING,
- EMPTY_STRING );
+ TextAbstraction::FontDescription fontDescription;
+ defaultFontId = mFontClient.GetFontId( fontDescription );
}
else
{
}
Text::FontMetrics fontMetrics;
- mFontClient.GetFontMetrics( defaultFontId, fontMetrics );
+ mMetrics->GetFontMetrics( defaultFontId, fontMetrics );
return( fontMetrics.ascender - fontMetrics.descender );
}
if( 1u == tapCount )
{
- if( ! IsShowingPlaceholderText() )
+ if( IsShowingRealText() )
{
const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x;
const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y;
mEventData->mPrimaryCursorPosition = GetClosestCursorIndex( xPosition,
yPosition );
+
+ // When the cursor position is changing, delay cursor blinking
+ mEventData->mDecorator->DelayCursorBlink();
}
else
{
Vector2 position = mEventData->mDecorator->GetPosition( GRAB_HANDLE );
// Position the grag handle close to either the left or right edge.
- position.x = scrollRightDirection ? 0.f : mControlSize.width;
+ position.x = scrollRightDirection ? 0.f : mVisualModel->mControlSize.width;
// Get the new handle position.
// The grab handle's position is in decorator coords. Need to transforms to text coords.
Vector2 position = mEventData->mDecorator->GetPosition( leftSelectionHandleEvent ? Text::LEFT_SELECTION_HANDLE : Text::RIGHT_SELECTION_HANDLE );
// Position the selection handle close to either the left or right edge.
- position.x = scrollRightDirection ? 0.f : mControlSize.width;
+ position.x = scrollRightDirection ? 0.f : mVisualModel->mControlSize.width;
// Get the new handle position.
// The selection handle's position is in decorator coords. Need to transforms to text coords.
return;
}
+ const bool handlesCrossed = mEventData->mLeftSelectionPosition > mEventData->mRightSelectionPosition;
+
//Get start and end position of selection
- uint32_t startOfSelectedText = mEventData->mLeftSelectionPosition;
- uint32_t lengthOfSelectedText = mEventData->mRightSelectionPosition - startOfSelectedText;
+ uint32_t startOfSelectedText = handlesCrossed ? mEventData->mRightSelectionPosition : mEventData->mLeftSelectionPosition;
+ uint32_t lengthOfSelectedText = ( handlesCrossed ? mEventData->mLeftSelectionPosition : mEventData->mRightSelectionPosition ) - startOfSelectedText;
// Validate the start and end selection points
- if( ( startOfSelectedText >= 0 ) && ( ( startOfSelectedText + lengthOfSelectedText ) <= mLogicalModel->mText.Count() ) )
+ if( ( startOfSelectedText + lengthOfSelectedText ) <= mLogicalModel->mText.Count() )
{
//Get text as a UTF8 string
Vector<Character>& utf32Characters = mLogicalModel->mText;
Vector<Character>::Iterator first = currentText.Begin() + startOfSelectedText;
Vector<Character>::Iterator last = first + lengthOfSelectedText;
currentText.Erase( first, last );
+
+ // Scroll after delete.
+ mEventData->mPrimaryCursorPosition = handlesCrossed ? mEventData->mRightSelectionPosition : mEventData->mLeftSelectionPosition;
+ mEventData->mScrollAfterDelete = true;
+ mEventData->mDecoratorUpdated = true;
}
- mEventData->mPrimaryCursorPosition = mEventData->mLeftSelectionPosition;
- mEventData->mScrollAfterDelete = true;
- mEventData->mDecoratorUpdated = true;
}
}
const LineRun& firstLine = *lines.Begin();
const float height = firstLine.ascender + -firstLine.descender;
+ const bool isLastCharacter = selectionEnd >= mLogicalModel->mText.Count();
+ const bool startDirection = ( ( NULL == modelCharacterDirectionsBuffer ) ? false : *( modelCharacterDirectionsBuffer + selectionStart ) );
+ const bool endDirection = ( ( NULL == modelCharacterDirectionsBuffer ) ? false : *( modelCharacterDirectionsBuffer + ( selectionEnd - ( isLastCharacter ? 1u : 0u ) ) ) );
+
// Swap the indices if the start is greater than the end.
- const bool indicesSwapped = ( selectionStart > selectionEnd );
+ const bool indicesSwapped = selectionStart > selectionEnd;
+
+ // Tell the decorator to flip the selection handles if needed.
+ mEventData->mDecorator->SetSelectionHandleFlipState( indicesSwapped, startDirection, endDirection );
+
if( indicesSwapped )
{
std::swap( selectionStart, selectionEnd );
const Length numberOfCharactersEnd = *( charactersPerGlyphBuffer + glyphEnd );
bool splitEndGlyph = ( glyphStart != glyphEnd ) && ( numberOfCharactersEnd > 1u ) && HasLigatureMustBreak( mLogicalModel->GetScript( selectionEndMinusOne ) );
- // Tell the decorator to swap the selection handles if needed.
- mEventData->mDecorator->SwapSelectionHandlesEnabled( firstLine.direction != indicesSwapped );
-
const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
// Traverse the glyphs.
mEventData->mDecorator->AddHighlight( xPosition,
offset.y,
xPosition + static_cast<float>( numberOfCharacters ) * glyphAdvance,
- height );
+ offset.y + height );
splitStartGlyph = false;
continue;
mEventData->mDecorator->AddHighlight( xPosition,
offset.y,
xPosition + static_cast<float>( interGlyphIndex ) * glyphAdvance,
- height );
+ offset.y + height );
splitEndGlyph = false;
continue;
}
const float xPosition = position.x - glyph.xBearing + offset.x;
- mEventData->mDecorator->AddHighlight( xPosition, offset.y, xPosition + glyph.advance, height );
+ mEventData->mDecorator->AddHighlight( xPosition,
+ offset.y,
+ xPosition + glyph.advance,
+ offset.y + height );
}
CursorInfo primaryCursorInfo;
mEventData->mDecorator->SetPosition( RIGHT_SELECTION_HANDLE, secondaryPosition.x, secondaryPosition.y, secondaryCursorInfo.lineHeight );
+ // Cursor to be positioned at end of selection so if selection interrupted and edit mode restarted the cursor will be at end of selection
+ mEventData->mPrimaryCursorPosition = ( indicesSwapped ) ? mEventData->mLeftSelectionPosition : mEventData->mRightSelectionPosition;
+
// Set the flag to update the decorator.
mEventData->mDecoratorUpdated = true;
}
void Controller::Impl::FindSelectionIndices( float visualX, float visualY, CharacterIndex& startIndex, CharacterIndex& endIndex )
{
CharacterIndex hitCharacter = GetClosestCursorIndex( visualX, visualY );
+ DALI_ASSERT_DEBUG( hitCharacter <= mLogicalModel->mText.Count() && "GetClosestCursorIndex returned out of bounds index" );
+
+ if ( mLogicalModel->mText.Count() == 0 )
+ {
+ return; // if model empty
+ }
+
if( hitCharacter >= mLogicalModel->mText.Count() )
{
- // Selection out of bounds.
- return;
+ // Closest hit character is the last character.
+ if ( hitCharacter == mLogicalModel->mText.Count() )
+ {
+ hitCharacter--; //Hit character index set to last character in logical model
+ }
+ else
+ {
+ // hitCharacter is out of bounds
+ return;
+ }
}
startIndex = hitCharacter;
CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX,
float visualY )
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GetClosestCursorIndex %p closest visualX %f visualY %f\n", this, visualX, visualY );
+
if( NULL == mEventData )
{
// Nothing to do if there is no text input.
numberOfGlyphs,
glyphMetrics,
mVisualModel,
- mFontClient );
+ mMetrics );
const Vector2& position = *( positionsBuffer + glyphLogicalOrderIndex );
logicalIndex = hasRightToLeftCharacters ? *( visualToLogicalCursorBuffer + visualIndex ) : visualIndex;
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%p closest visualIndex %d logicalIndex %d\n", this, visualIndex, logicalIndex );
+ DALI_ASSERT_DEBUG( ( logicalIndex <= mLogicalModel->mText.Count() && logicalIndex >= 0 ) && "GetClosestCursorIndex - Out of bounds index" );
+
return logicalIndex;
}
cursorInfo.lineHeight = GetDefaultFontLineHeight();
cursorInfo.primaryCursorHeight = cursorInfo.lineHeight;
- cursorInfo.primaryPosition.x = 1.f;
+ cursorInfo.primaryPosition.x = 0.f;
cursorInfo.primaryPosition.y = 0.f;
// Nothing else to do.
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,
secondaryNumberOfGlyphs,
glyphMetrics,
mVisualModel,
- mFontClient );
+ mMetrics );
// Set the secondary cursor's position.
cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + ( isCurrentRightToLeft ? 0.f : glyphMetrics.advance );
return;
}
- if( IsShowingPlaceholderText() )
+ if( IsShowingPlaceholderText() || ( 0u == mLogicalModel->mText.Count() ) )
{
// Do not want to use the place-holder text to set the cursor position.
FontId defaultFontId = 0u;
if( NULL == mFontDefaults )
{
- defaultFontId = mFontClient.GetFontId( EMPTY_STRING,
- EMPTY_STRING );
+ TextAbstraction::FontDescription fontDescription;
+ defaultFontId = mFontClient.GetFontId( fontDescription );
}
else
{
}
Text::FontMetrics fontMetrics;
- mFontClient.GetFontMetrics( defaultFontId, fontMetrics );
+ mMetrics->GetFontMetrics( defaultFontId, fontMetrics );
lineHeight = fontMetrics.ascender - fontMetrics.descender;
{
case LayoutEngine::HORIZONTAL_ALIGN_BEGIN:
{
- cursorPosition.x = 1.f;
+ cursorPosition.x = 0.f;
break;
}
case LayoutEngine::HORIZONTAL_ALIGN_CENTER:
{
- cursorPosition.x = floor( 0.5f * mControlSize.width );
+ cursorPosition.x = floor( 0.5f * mVisualModel->mControlSize.width );
break;
}
case LayoutEngine::HORIZONTAL_ALIGN_END:
{
- cursorPosition.x = mControlSize.width;
+ cursorPosition.x = mVisualModel->mControlSize.width - mEventData->mDecorator->GetCursorWidth();
break;
}
}
}
case LayoutEngine::VERTICAL_ALIGN_CENTER:
{
- cursorPosition.y = floorf( 0.5f * ( mControlSize.height - lineHeight ) );
+ cursorPosition.y = floorf( 0.5f * ( mVisualModel->mControlSize.height - lineHeight ) );
break;
}
case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
{
- cursorPosition.y = mControlSize.height - lineHeight;
+ cursorPosition.y = mVisualModel->mControlSize.height - lineHeight;
break;
}
}
void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )
{
// Clamp between -space & 0 (and the text alignment).
- if( actualSize.width > mControlSize.width )
+ if( actualSize.width > mVisualModel->mControlSize.width )
{
- const float space = ( actualSize.width - mControlSize.width ) + mAlignmentOffset.x;
+ const float space = ( actualSize.width - mVisualModel->mControlSize.width ) + mAlignmentOffset.x;
mEventData->mScrollPosition.x = ( mEventData->mScrollPosition.x < -space ) ? -space : mEventData->mScrollPosition.x;
mEventData->mScrollPosition.x = ( mEventData->mScrollPosition.x > -mAlignmentOffset.x ) ? -mAlignmentOffset.x : mEventData->mScrollPosition.x;
void Controller::Impl::ClampVerticalScroll( const Vector2& actualSize )
{
// Clamp between -space & 0 (and the text alignment).
- if( actualSize.height > mControlSize.height )
+ if( actualSize.height > mVisualModel->mControlSize.height )
{
- const float space = ( actualSize.height - mControlSize.height ) + mAlignmentOffset.y;
+ const float space = ( actualSize.height - mVisualModel->mControlSize.height ) + mAlignmentOffset.y;
mEventData->mScrollPosition.y = ( mEventData->mScrollPosition.y < -space ) ? -space : mEventData->mScrollPosition.y;
mEventData->mScrollPosition.y = ( mEventData->mScrollPosition.y > -mAlignmentOffset.y ) ? -mAlignmentOffset.y : mEventData->mScrollPosition.y;
mEventData->mScrollPosition.x += offset.x;
updateDecorator = true;
}
- else if( position.x > mControlSize.width )
+ else if( position.x > mVisualModel->mControlSize.width )
{
- offset.x = mControlSize.width - position.x;
+ offset.x = mVisualModel->mControlSize.width - position.x;
mEventData->mScrollPosition.x += offset.x;
updateDecorator = true;
}
}
// Set which cursors are active according the state.
- if( ( EventData::EDITING == mEventData->mState ) ||
- ( EventData::EDITING_WITH_POPUP == mEventData->mState ) ||
+ if( ( EventData::EDITING == mEventData->mState ) ||
+ ( EventData::EDITING_WITH_POPUP == mEventData->mState ) ||
+ ( EventData::EDITING_WITH_GRAB_HANDLE == mEventData->mState ) ||
( EventData::GRAB_HANDLE_PANNING == mEventData->mState ) )
{
if( cursorInfo.isSecondaryCursor )