SET(TC_SOURCES
utc-Dali-PushButton.cpp
utc-Dali-Text-CharacterSetConversion.cpp
+ utc-Dali-Text-Cursor.cpp
utc-Dali-Text-Segmentation.cpp
utc-Dali-Text-MultiLanguage.cpp
utc-Dali-LogicalModel.cpp
#include <dali-toolkit/internal/text/character-set-conversion.h>
#include <dali-toolkit/internal/text/layouts/layout-engine.h>
#include <dali-toolkit/internal/text/layouts/layout-parameters.h>
-#include <dali-toolkit/internal/text/metrics.h>
#include <dali-toolkit/internal/text/multi-language-support.h>
#include <dali-toolkit/internal/text/segmentation.h>
#include <dali-toolkit/internal/text/shaper.h>
const Vector<FontDescriptionRun>& fontDescriptions,
const LayoutOptions& options,
Size& layoutSize,
- LogicalModelPtr logicalModel,
- VisualModelPtr visualModel )
+ LogicalModelPtr& logicalModel,
+ VisualModelPtr& visualModel,
+ MetricsPtr& metrics )
{
+ logicalModel = LogicalModel::New();
+ visualModel = VisualModel::New();
+
// 1) Convert to utf32
Vector<Character>& utf32Characters = logicalModel->mText;
utf32Characters.Resize( text.size() );
const Length numberOfGlyphs = glyphs.Count();
// 8) Get the glyph metrics
- MetricsPtr metrics = Metrics::New( fontClient );
+ metrics = Metrics::New( fontClient );
GlyphInfo* glyphsBuffer = glyphs.Begin();
metrics->GetGlyphMetrics( glyphsBuffer, numberOfGlyphs );
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/logical-model-impl.h>
+#include <dali-toolkit/internal/text/metrics.h>
#include <dali-toolkit/internal/text/visual-model-impl.h>
namespace Dali
* @param[out] layoutSize The laid-out size.
* @param[out] logicalModel Pointer to a logical text model instance.
* @param[out] visualModel Pointer to a visual text model instance.
+ * @param[out] metrics Pointer to a wrapper around FontClient used to get metrics.
*/
void CreateTextModel( const std::string& text,
const Size& textArea,
const Vector<FontDescriptionRun>& fontDescriptions,
const LayoutOptions& options,
Size& layoutSize,
- LogicalModelPtr logicalModel,
- VisualModelPtr visualModel );
+ LogicalModelPtr& logicalModel,
+ VisualModelPtr& visualModel,
+ MetricsPtr& metrics );
} // namespace Text
bool SetBidirectionalInfoTest( const SetBidirectionalInfoData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
// 2) Clear the bidirectional paragraph info data.
Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo;
bool ReorderLinesTest( const ReorderLinesData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 300.f);
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
// 2) Clear the bidirectional line info data.
uint32_t startRemoveIndex = logicalModel->mBidirectionalLineInfo.Count();
bool GetMirroredTextTest( const GetMirroredTextData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
// 2) Call the GetMirroredText() function for the whole text
Vector<Character> mirroredText;
bool GetCharactersDirectionTest( const GetCharactersDirectionData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo;
int UtcDaliSetBidirectionalInfo(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliSetBidirectionalInfo");
unsigned int indices01[] = {};
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !SetBidirectionalInfoTest( data[index] ) )
{
tet_result(TET_FAIL);
int UtcDaliReorderLines(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliSetBidirectionalInfo");
unsigned int visualToLogical0301[] = { 0u, 1u, 2u, 3u, 4u, 5u, 9u, 8u, 7u, 6u, 10u };
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !ReorderLinesTest( data[index] ) )
{
tet_result(TET_FAIL);
int UtcDaliGetMirroredText(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliGetMirroredText");
struct GetMirroredTextData data[] =
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !GetMirroredTextTest( data[index] ) )
{
tet_result(TET_FAIL);
int UtcDaliGetCharactersDirection(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliGetCharactersDirection");
bool directions01[] = {};
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !GetCharactersDirectionTest( data[index] ) )
{
tet_result(TET_FAIL);
bool CreateParagraphTest( const CreateParagraphData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
// 2) Clear the paragraphs.
Vector<ParagraphRun>& paragraphs = logicalModel->mParagraphInfo;
bool FindParagraphTest( const FindParagraphData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
// 2) Find the paragraphs.
Vector<ParagraphRunIndex> paragraphs;
{
std::cout << " testing : " << data.description << std::endl;
// Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea( 100.f, 300.f );
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
for( unsigned int index = 0; index < data.numberOfTests; ++index )
{
{
std::cout << " testing : " << data.description << std::endl;
// Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size layoutSize;
// Create the model with the whole text.
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
for( unsigned int index = 0u; index < data.numberOfIndices; ++index )
{
{
std::cout << " testing : " << data.description << std::endl;
// Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size layoutSize;
// Create the model with the whole text.
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
for( unsigned int index = 0u; index < data.numberOfIndices; ++index )
{
--- /dev/null
+/*
+ * Copyright (c) 2016 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.
+ *
+ */
+
+#include <iostream>
+
+#include <stdlib.h>
+
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/internal/text/cursor-helper-functions.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <toolkit-text-model.h>
+
+
+using namespace Dali;
+using namespace Toolkit;
+using namespace Text;
+
+// Tests the following functions.
+//
+// LineIndex GetClosestLine( VisualModelPtr visualModel,
+// float visualY )
+// CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel,
+// LogicalModelPtr logicalModel,
+// MetricsPtr metrics,
+// float visualX,
+// float visualY )
+
+//////////////////////////////////////////////////////////
+
+namespace
+{
+
+struct GetClosestLineData
+{
+ std::string description; ///< Description of the test.
+ std::string text; ///< Input text.
+ unsigned int numberOfTests; ///< The number of tests.
+ float* visualY; ///< The visual 'y' position for each test.
+ LineIndex* lineIndex; ///< The expected line index for each test.
+};
+
+struct GetClosestCursorIndexData
+{
+ std::string description; ///< Description of the test.
+ std::string text; ///< Input text.
+ unsigned int numberOfTests; ///< The number of tests.
+ float* visualX; ///< The visual 'x' position for each test.
+ float* visualY; ///< The visual 'y' position for each test.
+ CharacterIndex* logicalIndex; ///< The expected logical cursor index for each test.
+};
+
+bool GetClosestLineTest( const GetClosestLineData& data )
+{
+ std::cout << " testing : " << data.description << std::endl;
+
+ // 1) Create the model.
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
+ Size textArea(400.f, 600.f);
+ Size layoutSize;
+
+ Vector<FontDescriptionRun> fontDescriptionRuns;
+ LayoutOptions options;
+ CreateTextModel( data.text,
+ textArea,
+ fontDescriptionRuns,
+ options,
+ layoutSize,
+ logicalModel,
+ visualModel,
+ metrics );
+
+ for( unsigned int index = 0u; index < data.numberOfTests; ++index )
+ {
+ const LineIndex lineIndex = GetClosestLine( visualModel,
+ data.visualY[index] );
+
+ if( lineIndex != data.lineIndex[index] )
+ {
+ std::cout << " test " << index << " failed. Different line index : " << lineIndex << ", expected : " << data.lineIndex[index] << std::endl;
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool GetClosestCursorIndexTest( const GetClosestCursorIndexData& data )
+{
+ std::cout << " testing : " << data.description << std::endl;
+
+ // 1) Create the model.
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
+ Size textArea(400.f, 600.f);
+ Size layoutSize;
+
+ Vector<FontDescriptionRun> fontDescriptionRuns;
+ LayoutOptions options;
+ CreateTextModel( data.text,
+ textArea,
+ fontDescriptionRuns,
+ options,
+ layoutSize,
+ logicalModel,
+ visualModel,
+ metrics );
+
+ for( unsigned int index = 0u; index < data.numberOfTests; ++index )
+ {
+ const CharacterIndex logicalCursorIndex = GetClosestCursorIndex( visualModel,
+ logicalModel,
+ metrics,
+ data.visualX[index],
+ data.visualY[index] );
+
+ if( logicalCursorIndex != data.logicalIndex[index] )
+ {
+ std::cout << " test " << index << " failed. Different logical cursor index : " << logicalCursorIndex << ", expected : " << data.logicalIndex[index] << std::endl;
+ return false;
+ }
+ }
+
+ return true;
+}
+
+} // namespace
+
+//////////////////////////////////////////////////////////
+//
+// UtcDaliGetClosestLine
+// UtcDaliGetClosestCursorIndex
+//
+//////////////////////////////////////////////////////////
+
+int UtcDaliGetClosestLine(void)
+{
+ tet_infoline(" UtcDaliGetClosestLine");
+
+ float visualY01[] = { -4.f, 3.f, 1000.f };
+ LineIndex lineIndices01[] = { 0u, 0u, 0u };
+
+ float visualY02[] = { -4.f, 3.f, 1000.f };
+ LineIndex lineIndices02[] = { 0u, 0u, 0u };
+
+ float visualY03[] = { -4.f, 11.f, 30.f, 51.f, 68.f, 87.f, 109.f, 130.f };
+ LineIndex lineIndices03[] = { 0u, 0u, 1u, 2u, 3u, 4u, 5u, 5u };
+
+ struct GetClosestLineData data[] =
+ {
+ {
+ "void text.",
+ "",
+ 3u,
+ visualY01,
+ lineIndices01,
+ },
+ {
+ "Single line text.",
+ "hello world",
+ 3u,
+ visualY02,
+ lineIndices02,
+ },
+ {
+ "Multi-line text.",
+ "abcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuדאוvwxה"
+ "סתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuד"
+ "אוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqr"
+ "פרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmno"
+ "צמםpqrפרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjkl"
+ "חלךmnoצמםpqrפרףstuדאוvwxהסתyzטזץ",
+ 8u,
+ visualY03,
+ lineIndices03
+ }
+ };
+ const unsigned int numberOfTests = 3u;
+
+ for( unsigned int index = 0u; index < numberOfTests; ++index )
+ {
+ ToolkitTestApplication application;
+ if( !GetClosestLineTest( data[index] ) )
+ {
+ tet_result(TET_FAIL);
+ }
+ }
+
+ tet_result(TET_PASS);
+ END_TEST;
+}
+
+int UtcDaliGetClosestCursorIndex(void)
+{
+ tet_infoline(" UtcDaliGetClosestCursorIndex");
+ float visualX01[] = { -100.f };
+ float visualY01[] = { -100.f };
+ CharacterIndex logicalIndex01[] = { 0u };
+
+ float visualX02[] = { -100.f, 1000.f, 60.f, 79.f, 83.f, 148.f, 99.f };
+ float visualY02[] = { -100.f, 1000.f, 12.f, 12.f, 12.f, 12.f, 12.f };
+ CharacterIndex logicalIndex02[] = { 0u, 21u, 7u, 10u, 11u, 13u, 20u };
+
+ float visualX03[] = { 19.f, 104.f, -2.f, 127.f };
+ float visualY03[] = { 12.f, 12.f, 12.f, 12.f };
+ CharacterIndex logicalIndex03[] = { 3u, 12u, 0u, 18u };
+
+ // 0 5 _ 6 11 12
+ // Hello world \n
+ // 12 16 _ 17 21 22
+ // שלום עולם \n
+ // 22 31_32 40 41
+ // different الأربعاء \n
+ float visualX04[] = { -100.f, 40.f, 44.f, 85.f, 500.f,
+ 500.f, 367.f, 359.f, 329.f, -100.f,
+ -100.f, 19.f, 64.f, 72.f, 104.f, 111.f, 500.f};
+ float visualY04[] = { -100.f, 12.f, 12.f, 12.f, 12.f,
+ 30.f, 30.f, 30.f, 30.f, 30.f,
+ 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f };
+ CharacterIndex logicalIndex04[] = { 0u, 5u, 6u, 11u, 11u,
+ 12u, 16u, 17u, 21u, 21u,
+ 22u, 25u, 31u, 32u, 34u, 40u, 40u,
+ 41u };
+
+ // 0 10 20 30 40 46
+ // abcשנבdefג קכghiעיןjk lחלךmnoצמם pqrפרףstuד אוvwxה
+ // 46 50 60 70 80 93
+ // סתyz טזץabcשנבd efגקכghiעי ןjklחלךmno צמםpqrפרףstuד
+ // 93 100 110 120 130 139
+ // אוvwxהס תyzטזץabcש נבdefגקכgh iעיןjklחלך mnoצמםpqr
+ // 139 150 160 170 180 186
+ // פרףstuדאוvw xהסתyzטזץa bcשנבdefגק כghiעיןjkl חלךmno
+ // 186 190 200 210 220 233
+ // צמםp qrפרףstuדא וvwxהסתyzט זץabcשנבde fגקכghiעיןjkl
+ // 233 240 250 260 265
+ // חלךmnoצ מםpqrפרףst uדאוvwxהסת yzטזץ
+
+ float visualX05[] = { -100.f, 96.f, 155.f, 250.f, 344.f, 500.f,
+ -100.f, 36.f, 124.f, 190.f, 280.f, 500.f,
+ -100.f, 56.f, 158.f, 237.f, 303.f, 500.f,
+ -100.f, 98.f, 184.f, 261.f, 337.f, 500.f,
+ -100.f, 40.f, 113.f, 223.f, 302.f, 500.f,
+ -100.f, 82.f, 160.f, 253.f, 500.f };
+ float visualY05[] = { -100.f, 12.f, 12.f, 12.f, 12.f, 12.f,
+ 30.f, 30.f, 30.f, 30.f, 30.f, 30.f,
+ 50.f, 50.f, 50.f, 50.f, 50.f, 50.f,
+ 67.f, 67.f, 67.f, 67.f, 67.f, 67.f,
+ 87.f, 87.f, 87.f, 87.f, 87.f, 87.f,
+ 107.f, 107.f, 107.f, 107.f, 107.f };
+ CharacterIndex logicalIndex05[] = { 0u, 10u, 20u, 30u, 40u, 45u,
+ 46u, 50u, 60u, 70u, 80u, 92u,
+ 93u, 100u, 110u, 120u, 130u, 138u,
+ 139u, 150u, 160u, 170u, 180u, 185u,
+ 186u, 190u, 200u, 210u, 220u, 232u,
+ 233u, 240u, 250u, 260u, 265u };
+
+ // 0 10 20 30 40 46
+ // שנבabcגקכd efעיןghiחל ךjklצמםmno פרףpqrדאוs tuהסתv
+ // 46 50 60 70 80 93
+ // wxטז ץyzשנבabcג קכdefעיןgh iחלךjklצמם mnoפרףpqrדאוs
+ // 93 100 110 120 130 139
+ // tuהסתvw xטזץyzשנבa bcגקכdefעי ןghiחלךjkl צמםmnoפרף
+ // 139 150 160 170 180 186
+ // pqrדאוstuהס תvwxטזץyzש נבabcגקכde fעיןghiחלך jklצמם
+ // 186 190 200 210 220 232
+ // mnoפ רףpqrדאוst uהסתvwxטזץ yzשנבabcגק כdefעיןghiחל
+ // 232 240 250 260 265
+ // ךjklצמםm noפרףpqrדא וstuהסתvwx טזץyz
+
+ float visualX06[] = { 500.f, 307.f, 237.f, 148.f, 55.f, -100.f,
+ 500.f, 362.f, 276.f, 213.f, 121.f, -100.f,
+ 500.f, 344.f, 238.f, 167.f, 93.f, -100.f,
+ 500.f, 306.f, 216.f, 142.f, 58.f, -100.f,
+ 500.f, 355.f, 279.f, 182.f, 92.f, -100.f,
+ 500.f, 326.f, 238.f, 150.f, -100.f };
+ float visualY06[] = { -100.f, 12.f, 12.f, 12.f, 12.f, 12.f,
+ 30.f, 30.f, 30.f, 30.f, 30.f, 30.f,
+ 50.f, 50.f, 50.f, 50.f, 50.f, 50.f,
+ 67.f, 67.f, 67.f, 67.f, 67.f, 67.f,
+ 87.f, 87.f, 87.f, 87.f, 87.f, 87.f,
+ 107.f, 107.f, 107.f, 107.f, 107.f };
+ CharacterIndex logicalIndex06[] = { 0u, 10u, 20u, 30u, 40u, 45u,
+ 46u, 50u, 60u, 70u, 80u, 92u,
+ 93u, 100u, 110u, 120u, 130u, 138u,
+ 139u, 150u, 160u, 170u, 180u, 185u,
+ 186u, 190u, 200u, 210u, 220u, 231u,
+ 232u, 240u, 250u, 260u, 265u };
+
+ struct GetClosestCursorIndexData data[] =
+ {
+ {
+ "Void text.",
+ "",
+ 1u,
+ visualX01,
+ visualY01,
+ logicalIndex01
+ },
+ {
+ "Single line text.",
+ "Hello world שלום עולם",
+ 7u,
+ visualX02,
+ visualY02,
+ logicalIndex02
+ },
+ {
+ "Single line with ligatures",
+ "different الأربعاء",
+ 4u,
+ visualX03,
+ visualY03,
+ logicalIndex03
+ },
+ {
+ "Multiline. Single line paragraphs",
+ "Hello world\n"
+ "שלום עולם\n"
+ "different الأربعاء\n",
+ 17u,
+ visualX04,
+ visualY04,
+ logicalIndex04
+ },
+ {
+ "Multiline. Single bidirectional paragraph, starts LTR, wrapped lines",
+ "abcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuדאוvwxה"
+ "סתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuד"
+ "אוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqr"
+ "פרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmno"
+ "צמםpqrפרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjkl"
+ "חלךmnoצמםpqrפרףstuדאוvwxהסתyzטזץ",
+ 35u,
+ visualX05,
+ visualY05,
+ logicalIndex05
+ },
+ {
+ "Multiline. Single bidirectional paragraph, starts RTL, wrapped lines",
+ "שנבabcגקכdefעיןghiחלךjklצמםmnoפרףpqrדאוstuהסתv"
+ "wxטזץyzשנבabcגקכdefעיןghiחלךjklצמםmnoפרףpqrדאוs"
+ "tuהסתvwxטזץyzשנבabcגקכdefעיןghiחלךjklצמםmnoפרף"
+ "pqrדאוstuהסתvwxטזץyzשנבabcגקכdefעיןghiחלךjklצמם"
+ "mnoפרףpqrדאוstuהסתvwxטזץyzשנבabcגקכdefעיןghiחל"
+ "ךjklצמםmnoפרףpqrדאוstuהסתvwxטזץyz",
+ 35u,
+ visualX06,
+ visualY06,
+ logicalIndex06
+ }
+ };
+ const unsigned int numberOfTests = 6u;
+
+ for( unsigned int index = 0u; index < numberOfTests; ++index )
+ {
+ ToolkitTestApplication application;
+ if( !GetClosestCursorIndexTest( data[index] ) )
+ {
+ tet_result(TET_FAIL);
+ }
+ }
+
+ tet_result(TET_PASS);
+ END_TEST;
+}
fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" );
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size layoutSize;
Vector<FontDescriptionRun> fontDescriptionRuns;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
// 2) Clear the layout.
Vector<LineRun>& lines = visualModel->mLines;
glyphPositions.Begin() + data.startIndex + data.numberOfGlyphs );
// 3) Layout
- MetricsPtr metrics = Metrics::New( fontClient );
-
LayoutEngine engine;
engine.SetMetrics( metrics );
engine.SetTextEllipsisEnabled( data.ellipsis );
fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" );
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size layoutSize;
Vector<FontDescriptionRun> fontDescriptionRuns;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
// 2) Call the ReLayoutRightToLeftLines() method.
- MetricsPtr metrics = Metrics::New( fontClient );
-
LayoutEngine engine;
engine.SetMetrics( metrics );
fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" );
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size layoutSize;
Vector<FontDescriptionRun> fontDescriptionRuns;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
// Call the Align method.
- MetricsPtr metrics = Metrics::New( fontClient );
-
LayoutEngine engine;
engine.SetMetrics( metrics );
bool ShapeInfoTest( const ShapeInfoData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
// 2) Clear the model.
int UtcDaliTextShape(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliTextShape");
struct GlyphInfoData glyphs02[] =
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !ShapeInfoTest( data[index] ) )
{
tet_result(TET_FAIL);
bool SetGlyphsPerCharacterTest( const SetGlyphsPerCharacterData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
bool SetCharacterToGlyphTest( const SetCharacterToGlyphData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics );
Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
int UtcDaliSetGlyphsPerCharacter(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliSetGlyphsPerCharacter");
Length glyphsPerCharacter02[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u };
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !SetGlyphsPerCharacterTest( data[index] ) )
{
tet_result(TET_FAIL);
int UtcDaliSetCharacterToGlyph(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliSetGlyphsPerCharacter");
GlyphIndex glyphIndices02[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u };
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !SetCharacterToGlyphTest( data[index] ) )
{
tet_result(TET_FAIL);
if( mRenderableActor )
{
- // TODO: Scroll and alignment needs to be refactored.
- const Vector2& alignmentOffset = mController->GetAlignmentOffset();
const Vector2& scrollOffset = mController->GetScrollPosition();
- mRenderableActor.SetPosition( scrollOffset.x, alignmentOffset.y + scrollOffset.y );
+ mRenderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
Actor clipRootActor;
if( mClipper )
if( mRenderableActor )
{
- // TODO: Scroll and alignment needs to be refactored.
- const Vector2& alignmentOffset = mController->GetAlignmentOffset();
const Vector2& scrollOffset = mController->GetScrollPosition();
- mRenderableActor.SetPosition( scrollOffset.x, alignmentOffset.y + scrollOffset.y );
+ mRenderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
Actor clipRootActor;
if( mClipper )
if( renderableActor )
{
- // TODO: Scroll and alignment needs to be refactored.
- const Vector2& alignmentOffset = mController->GetAlignmentOffset();
- renderableActor.SetPosition( 0.f, alignmentOffset.y );
+ const Vector2& scrollOffset = mController->GetScrollPosition();
+ renderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
self.Add( renderableActor );
}
{
const Size& controlSize = mController->GetView().GetControlSize();
const Size offScreenSize = GetNaturalSize().GetVectorXY(); // As relayout of text may not be done at this point natural size is used to get size. Single line scrolling only.
- const Vector2& alignmentOffset = mController->GetAlignmentOffset();
+ const float alignmentOffset = mController->GetAutoScrollLineAlignment();
const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
- DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f,%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
- alignmentOffset.x, alignmentOffset.y, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y);
+ DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
+ alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
if ( !mTextScroller )
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n");
+ DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
// If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
mTextScroller = Text::TextScroller::New( *this );
Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
#endif
-} // namespace
+const Dali::Toolkit::Text::CharacterDirection LTR = false; ///< Left To Right direction.
+
+} //namespace
namespace Dali
{
LineIndex lineIndex = 0u;
const Vector<LineRun>& lines = visualModel->mLines;
- for( LineIndex endLine = lines.Count();
- lineIndex < endLine;
- ++lineIndex )
+
+ for( Vector<LineRun>::ConstIterator it = lines.Begin(),
+ endIt = lines.End();
+ it != endIt;
+ ++it, ++lineIndex )
{
- const LineRun& lineRun = lines[lineIndex];
- totalHeight += lineRun.ascender + -lineRun.descender;
+ const LineRun& lineRun = *it;
+
+ // The line height is the addition of the line ascender and the line descender.
+ // However, the line descender has a negative value, hence the subtraction.
+ totalHeight += lineRun.ascender - lineRun.descender;
+
if( visualY < totalHeight )
{
return lineIndex;
}
}
- if( lineIndex == 0 )
+ if( lineIndex == 0u )
{
return 0;
}
return lineIndex-1;
}
+float CalculateLineOffset( const Vector<LineRun>& lines,
+ LineIndex lineIndex )
+{
+ float offset = 0.f;
+
+ for( Vector<LineRun>::ConstIterator it = lines.Begin(),
+ endIt = lines.Begin() + lineIndex;
+ it != endIt;
+ ++it )
+ {
+ const LineRun& lineRun = *it;
+
+ // The line height is the addition of the line ascender and the line descender.
+ // However, the line descender has a negative value, hence the subtraction.
+ offset += lineRun.ascender - lineRun.descender;
+ }
+
+ return offset;
+}
+
CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel,
LogicalModelPtr logicalModel,
MetricsPtr metrics,
// Find which line is closest.
const LineIndex lineIndex = Text::GetClosestLine( visualModel,
visualY );
- const LineRun& line = visualModel->mLines[lineIndex];
+
+ // Convert from text's coords to line's coords.
+ const LineRun& line = *( visualModel->mLines.Begin() + lineIndex );
+
+ // Transform the tap point from text's coords to line's coords.
+ visualX -= line.alignmentOffset;
// Get the positions of the glyphs.
- const Vector<Vector2>& positions = visualModel->mGlyphPositions;
- const Vector2* const positionsBuffer = positions.Begin();
+ const Vector2* const positionsBuffer = visualModel->mGlyphPositions.Begin();
// Get the character to glyph conversion table.
const GlyphIndex* const charactersToGlyphBuffer = visualModel->mCharactersToGlyph.Begin();
// Get the glyphs per character table.
const Length* const glyphsPerCharacterBuffer = visualModel->mGlyphsPerCharacter.Begin();
+ // Get the characters per glyph table.
+ const Length* const charactersPerGlyphBuffer = visualModel->mCharactersPerGlyph.Begin();
+
// Get the glyph's info buffer.
const GlyphInfo* const glyphInfoBuffer = visualModel->mGlyphs.Begin();
// Whether this line is a bidirectional line.
const bool bidiLineFetched = logicalModel->FetchBidirectionalLineInfo( startCharacter );
+ // The character's direction buffer.
+ const CharacterDirection* const directionsBuffer = bidiLineFetched ? logicalModel->mCharacterDirections.Begin() : NULL;
+
// Whether there is a hit on a glyph.
bool matched = false;
// Traverses glyphs in visual order. To do that use the visual to logical conversion table.
CharacterIndex visualIndex = startCharacter;
- Length numberOfCharacters = 0u;
- for( ; !matched && ( visualIndex < endCharacter ); ++visualIndex )
+ Length numberOfVisualCharacters = 0u;
+ for( ; visualIndex < endCharacter; ++visualIndex )
{
// The character in logical order.
const CharacterIndex characterLogicalOrderIndex = ( bidiLineFetched ? logicalModel->GetLogicalCharacterIndex( visualIndex ) : visualIndex );
-
- // Get the script of the character.
- const Script script = logicalModel->GetScript( characterLogicalOrderIndex );
+ const CharacterDirection direction = ( bidiLineFetched ? *( directionsBuffer + characterLogicalOrderIndex ) : LTR );
// The number of glyphs for that character
const Length numberOfGlyphs = *( glyphsPerCharacterBuffer + characterLogicalOrderIndex );
- ++numberOfCharacters;
-
+ ++numberOfVisualCharacters;
if( 0u != numberOfGlyphs )
{
// Get the first character/glyph of the group of glyphs.
- const CharacterIndex firstVisualCharacterIndex = 1u + visualIndex - numberOfCharacters;
+ const CharacterIndex firstVisualCharacterIndex = 1u + visualIndex - numberOfVisualCharacters;
const CharacterIndex firstLogicalCharacterIndex = ( bidiLineFetched ? logicalModel->GetLogicalCharacterIndex( firstVisualCharacterIndex ) : firstVisualCharacterIndex );
const GlyphIndex firstLogicalGlyphIndex = *( charactersToGlyphBuffer + firstLogicalCharacterIndex );
const Vector2& position = *( positionsBuffer + firstLogicalGlyphIndex );
// Whether the glyph can be split, like Latin ligatures fi, ff or Arabic ﻻ.
+ const Length numberOfCharacters = *( charactersPerGlyphBuffer + firstLogicalGlyphIndex );
+ if( direction != LTR )
+ {
+ // As characters are being traversed in visual order,
+ // for right to left ligatures, the character which contains the
+ // number of glyphs in the table is found first.
+ // Jump the number of characters to the next glyph is needed.
+ visualIndex += numberOfCharacters - 1u;
+ }
+
+ // Get the script of the character.
+ const Script script = logicalModel->GetScript( characterLogicalOrderIndex );
+
const bool isInterglyphIndex = ( numberOfCharacters > numberOfGlyphs ) && HasLigatureMustBreak( script );
const Length numberOfBlocks = isInterglyphIndex ? numberOfCharacters : 1u;
const float glyphAdvance = glyphMetrics.advance / static_cast<float>( numberOfBlocks );
- GlyphIndex index = 0u;
- for( ; !matched && ( index < numberOfBlocks ); ++index )
+ CharacterIndex index = 0u;
+ for( ; index < numberOfBlocks; ++index )
{
// Find the mid-point of the area containing the glyph
const float glyphCenter = -glyphMetrics.xBearing + position.x + ( static_cast<float>( index ) + 0.5f ) * glyphAdvance;
if( matched )
{
+ // If the glyph is shaped from more than one character, it matches the character of the glyph.
visualIndex = firstVisualCharacterIndex + index;
break;
}
- numberOfCharacters = 0u;
+ numberOfVisualCharacters = 0u;
}
-
}
+ // The number of characters of the whole text.
+ const Length totalNumberOfCharacters = logicalModel->mText.Count();
+
// Return the logical position of the cursor in characters.
if( !matched )
{
+ // If no character is matched, then the last character (in visual order) of the line is used.
visualIndex = endCharacter;
}
+ // Get the paragraph direction.
+ const CharacterDirection paragraphDirection = line.direction;
+
+ if( totalNumberOfCharacters != visualIndex )
+ {
+ // The visual index is not at the end of the text.
+
+ if( LTR == paragraphDirection )
+ {
+ // The paragraph direction is left to right.
+
+ if( visualIndex == endCharacter )
+ {
+ // It places the cursor just before the last character in visual order.
+ // i.e. it places the cursor just before the '\n' or before the last character
+ // if there is a long line with no word breaks which is wrapped.
+
+ // It doesn't check if the closest line is the last one like the RTL branch below
+ // because the total number of characters is different than the visual index and
+ // the visual index is the last character of the line.
+ --visualIndex;
+ }
+ }
+ else
+ {
+ // The paragraph direction is right to left.
+
+ if( ( lineIndex != numberOfLines - 1u ) && // is not the last line.
+ ( visualIndex == startCharacter ) )
+ {
+ // It places the cursor just after the first character in visual order.
+ // i.e. it places the cursor just after the '\n' or after the last character
+ // if there is a long line with no word breaks which is wrapped.
+
+ // If the last line doesn't end with '\n' it won't increase the visual index
+ // placing the cursor at the beginning of the line (in visual order).
+ ++visualIndex;
+ }
+ }
+ }
+ else
+ {
+ // The visual index is at the end of text.
+
+ // If the text ends with a new paragraph character i.e. a '\n', an extra line with no characters is added at the end of the text.
+ // This branch checks if the closest line is the one with the last '\n'. If it is, it decrements the visual index to place
+ // the cursor just before the last '\n'.
+
+ if( ( lineIndex != numberOfLines - 1u ) &&
+ TextAbstraction::IsNewParagraph( *( logicalModel->mText.Begin() + visualIndex - 1u ) ) )
+ {
+ --visualIndex;
+ }
+ }
+
logicalIndex = ( bidiLineFetched ? logicalModel->GetLogicalCursorIndex( visualIndex ) : visualIndex );
+
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "closest visualIndex %d logicalIndex %d\n", visualIndex, logicalIndex );
DALI_ASSERT_DEBUG( ( logicalIndex <= logicalModel->mText.Count() && logicalIndex >= 0 ) && "GetClosestCursorIndex - Out of bounds index" );
CharacterIndex logical,
CursorInfo& cursorInfo )
{
- // TODO: Check for multiline with \n, etc...
+ // Whether the logical cursor position is at the end of the whole text.
+ const bool isLastPosition = logicalModel->mText.Count() == logical;
- const Length numberOfCharacters = logicalModel->mText.Count();
-
- // Check if the logical position is the first or the last one of the text.
- const bool isFirstPosition = 0u == logical;
- const bool isLastPosition = numberOfCharacters == logical;
-
- // 'logical' is the logical 'cursor' index.
- // Get the next and current logical 'character' index.
- const CharacterIndex nextCharacterIndex = logical;
- const CharacterIndex characterIndex = isFirstPosition ? logical : logical - 1u;
+ // Get the line where the character is laid-out.
+ const CharacterIndex characterOfLine = isLastPosition ? ( logical - 1u ) : logical;
- // Get the direction of the character and the next one.
- const CharacterDirection* const modelCharacterDirectionsBuffer = ( 0u != logicalModel->mCharacterDirections.Count() ) ? logicalModel->mCharacterDirections.Begin() : NULL;
+ // Whether the cursor is in the last position and the last position is a new paragraph character.
+ const bool isLastNewParagraph = isLastPosition && TextAbstraction::IsNewParagraph( *( logicalModel->mText.Begin() + characterOfLine ) );
- CharacterDirection isCurrentRightToLeft = false;
- CharacterDirection isNextRightToLeft = false;
- if( NULL != modelCharacterDirectionsBuffer ) // If modelCharacterDirectionsBuffer is NULL, it means the whole text is left to right.
- {
- isCurrentRightToLeft = *( modelCharacterDirectionsBuffer + characterIndex );
- isNextRightToLeft = *( modelCharacterDirectionsBuffer + nextCharacterIndex );
- }
-
- // Get the line where the character is laid-out.
const LineRun* const modelLines = visualModel->mLines.Begin();
- const LineIndex lineIndex = visualModel->GetLineOfCharacter( characterIndex );
+ const LineIndex lineIndex = visualModel->GetLineOfCharacter( characterOfLine );
const LineRun& line = *( modelLines + lineIndex );
- // Get the paragraph's direction.
- const CharacterDirection isRightToLeftParagraph = line.direction;
+ if( isLastNewParagraph )
+ {
+ // The cursor is in a new line with no characters. Place the cursor in that line.
+ const LineIndex newLineIndex = lineIndex + 1u;
+ const LineRun& newLine = *( modelLines + newLineIndex );
+
+ cursorInfo.isSecondaryCursor = false;
- // Check whether there is an alternative position:
+ // Set the line offset and height.
+ cursorInfo.lineOffset = CalculateLineOffset( visualModel->mLines,
+ newLineIndex );
- cursorInfo.isSecondaryCursor = ( !isLastPosition && ( isCurrentRightToLeft != isNextRightToLeft ) ) ||
- ( isLastPosition && ( isRightToLeftParagraph != isCurrentRightToLeft ) );
+ // The line height is the addition of the line ascender and the line descender.
+ // However, the line descender has a negative value, hence the subtraction.
+ cursorInfo.lineHeight = newLine.ascender - newLine.descender;
- // Set the line offset and height.
- cursorInfo.lineOffset = 0.f;
- cursorInfo.lineHeight = line.ascender + -line.descender;
+ // Set the primary cursor's height.
+ cursorInfo.primaryCursorHeight = cursorInfo.lineHeight;
- // Calculate the primary cursor.
+ // Set the primary cursor's position.
+ cursorInfo.primaryPosition.x = 0.f;
+ cursorInfo.primaryPosition.y = cursorInfo.lineOffset;
- CharacterIndex index = characterIndex;
- if( cursorInfo.isSecondaryCursor )
+ // Transform the cursor info from line's coords to text's coords.
+ cursorInfo.primaryPosition.x += ( LTR == line.direction ) ? 0.f : visualModel->mControlSize.width;
+ }
+ else
{
- // If there is a secondary position, the primary cursor may be in a different place than the logical index.
+ // Whether this line is a bidirectional line.
+ const bool bidiLineFetched = logicalModel->FetchBidirectionalLineInfo( characterOfLine );
- if( isLastPosition )
- {
- // The position of the cursor after the last character needs special
- // care depending on its direction and the direction of the paragraph.
+ // Check if the logical position is the first or the last one of the line.
+ const bool isFirstPositionOfLine = line.characterRun.characterIndex == logical;
+ const bool isLastPositionOfLine = line.characterRun.characterIndex + line.characterRun.numberOfCharacters == logical;
- // Need to find the first character after the last character with the paragraph's direction.
- // i.e l0 l1 l2 r0 r1 should find r0.
+ // 'logical' is the logical 'cursor' index.
+ // Get the next and current logical 'character' index.
+ const CharacterIndex characterIndex = isFirstPositionOfLine ? logical : logical - 1u;
+ const CharacterIndex nextCharacterIndex = isLastPositionOfLine ? characterIndex : logical;
- // TODO: check for more than one line!
- index = isRightToLeftParagraph ? line.characterRun.characterIndex : line.characterRun.characterIndex + line.characterRun.numberOfCharacters - 1u;
- index = logicalModel->GetLogicalCharacterIndex( index );
- }
- else
+ // The character's direction buffer.
+ const CharacterDirection* const directionsBuffer = bidiLineFetched ? logicalModel->mCharacterDirections.Begin() : NULL;
+
+ CharacterDirection isCurrentRightToLeft = false;
+ CharacterDirection isNextRightToLeft = false;
+ if( bidiLineFetched ) // If bidiLineFetched is false, it means the whole text is left to right.
{
- index = ( isRightToLeftParagraph == isCurrentRightToLeft ) ? characterIndex : nextCharacterIndex;
+ isCurrentRightToLeft = *( directionsBuffer + characterIndex );
+ isNextRightToLeft = *( directionsBuffer + nextCharacterIndex );
}
- }
- const GlyphIndex* const charactersToGlyphBuffer = visualModel->mCharactersToGlyph.Begin();
- const Length* const glyphsPerCharacterBuffer = visualModel->mGlyphsPerCharacter.Begin();
- const Length* const charactersPerGlyphBuffer = visualModel->mCharactersPerGlyph.Begin();
- const CharacterIndex* const glyphsToCharactersBuffer = visualModel->mGlyphsToCharacters.Begin();
- const Vector2* const glyphPositionsBuffer = visualModel->mGlyphPositions.Begin();
- const GlyphInfo* const glyphInfoBuffer = visualModel->mGlyphs.Begin();
+ // Get the paragraph's direction.
+ const CharacterDirection isRightToLeftParagraph = line.direction;
- // Convert the cursor position into the glyph position.
- const GlyphIndex primaryGlyphIndex = *( charactersToGlyphBuffer + index );
- const Length primaryNumberOfGlyphs = *( glyphsPerCharacterBuffer + index );
- const Length primaryNumberOfCharacters = *( charactersPerGlyphBuffer + primaryGlyphIndex );
-
- // Get the metrics for the group of glyphs.
- GlyphMetrics glyphMetrics;
- GetGlyphsMetrics( primaryGlyphIndex,
- primaryNumberOfGlyphs,
- glyphMetrics,
- glyphInfoBuffer,
- metrics );
-
- // 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,
- // if the logical cursor is one, the position is the position of the first glyph and the advance is added.
- // A 'truth table' was build and an online Karnaugh map tool was used to simplify the logic.
- //
- // FLCP A
- // ------
- // 0000 1
- // 0001 1
- // 0010 0
- // 0011 0
- // 0100 1
- // 0101 0
- // 0110 1
- // 0111 0
- // 1000 0
- // 1001 x
- // 1010 x
- // 1011 1
- // 1100 x
- // 1101 x
- // 1110 x
- // 1111 x
- //
- // Where F -> isFirstPosition
- // L -> isLastPosition
- // C -> isCurrentRightToLeft
- // P -> isRightToLeftParagraph
- // A -> Whether to add the glyph's advance.
-
- const bool addGlyphAdvance = ( ( isLastPosition && !isRightToLeftParagraph ) ||
- ( isFirstPosition && isRightToLeftParagraph ) ||
- ( !isFirstPosition && !isLastPosition && !isCurrentRightToLeft ) );
-
- float glyphAdvance = addGlyphAdvance ? glyphMetrics.advance : 0.f;
-
- if( !isLastPosition &&
- ( primaryNumberOfCharacters > 1u ) )
- {
- const CharacterIndex firstIndex = *( glyphsToCharactersBuffer + primaryGlyphIndex );
+ // Check whether there is an alternative position:
+ cursorInfo.isSecondaryCursor = ( ( !isLastPositionOfLine && ( isCurrentRightToLeft != isNextRightToLeft ) ) ||
+ ( isLastPositionOfLine && ( isRightToLeftParagraph != isCurrentRightToLeft ) ) ||
+ ( isFirstPositionOfLine && ( isRightToLeftParagraph != isCurrentRightToLeft ) ) );
+
+ // Set the line offset and height.
+ cursorInfo.lineOffset = CalculateLineOffset( visualModel->mLines,
+ lineIndex );
- bool isCurrentRightToLeft = false;
- if( NULL != modelCharacterDirectionsBuffer ) // If modelCharacterDirectionsBuffer is NULL, it means the whole text is left to right.
+ // The line height is the addition of the line ascender and the line descender.
+ // However, the line descender has a negative value, hence the subtraction.
+ cursorInfo.lineHeight = line.ascender - line.descender;
+
+ // Calculate the primary cursor.
+
+ CharacterIndex index = characterIndex;
+ if( cursorInfo.isSecondaryCursor )
{
- isCurrentRightToLeft = *( modelCharacterDirectionsBuffer + index );
+ // If there is a secondary position, the primary cursor may be in a different place than the logical index.
+
+ if( isLastPositionOfLine )
+ {
+ // The position of the cursor after the last character needs special
+ // care depending on its direction and the direction of the paragraph.
+
+ // Need to find the first character after the last character with the paragraph's direction.
+ // i.e l0 l1 l2 r0 r1 should find r0.
+
+ index = isRightToLeftParagraph ? line.characterRun.characterIndex : line.characterRun.characterIndex + line.characterRun.numberOfCharacters - 1u;
+ if( bidiLineFetched )
+ {
+ index = logicalModel->GetLogicalCharacterIndex( index );
+ }
+ }
+ else if( isFirstPositionOfLine )
+ {
+ index = isRightToLeftParagraph ? line.characterRun.characterIndex + line.characterRun.numberOfCharacters - 1u : line.characterRun.characterIndex;
+ if( bidiLineFetched )
+ {
+ index = logicalModel->GetLogicalCharacterIndex( index );
+ }
+ }
+ else
+ {
+ index = ( isRightToLeftParagraph == isCurrentRightToLeft ) ? characterIndex : nextCharacterIndex;
+ }
}
- Length numberOfGlyphAdvance = ( isFirstPosition ? 0u : 1u ) + characterIndex - firstIndex;
- if( isCurrentRightToLeft )
+ const GlyphIndex* const charactersToGlyphBuffer = visualModel->mCharactersToGlyph.Begin();
+ const Length* const glyphsPerCharacterBuffer = visualModel->mGlyphsPerCharacter.Begin();
+ const Length* const charactersPerGlyphBuffer = visualModel->mCharactersPerGlyph.Begin();
+ const CharacterIndex* const glyphsToCharactersBuffer = visualModel->mGlyphsToCharacters.Begin();
+ const Vector2* const glyphPositionsBuffer = visualModel->mGlyphPositions.Begin();
+ const GlyphInfo* const glyphInfoBuffer = visualModel->mGlyphs.Begin();
+
+ // Convert the cursor position into the glyph position.
+ const GlyphIndex primaryGlyphIndex = *( charactersToGlyphBuffer + index );
+ const Length primaryNumberOfGlyphs = *( glyphsPerCharacterBuffer + index );
+ const Length primaryNumberOfCharacters = *( charactersPerGlyphBuffer + primaryGlyphIndex );
+
+ // Get the metrics for the group of glyphs.
+ GlyphMetrics glyphMetrics;
+ GetGlyphsMetrics( primaryGlyphIndex,
+ primaryNumberOfGlyphs,
+ glyphMetrics,
+ glyphInfoBuffer,
+ metrics );
+
+ // 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,
+ // if the logical cursor is one, the position is the position of the first glyph and the advance is added.
+ // A 'truth table' was build and an online Karnaugh map tool was used to simplify the logic.
+ //
+ // FLCP A
+ // ------
+ // 0000 1
+ // 0001 1
+ // 0010 0
+ // 0011 0
+ // 0100 1
+ // 0101 0
+ // 0110 1
+ // 0111 0
+ // 1000 0
+ // 1001 1
+ // 1010 0
+ // 1011 1
+ // 1100 x
+ // 1101 x
+ // 1110 x
+ // 1111 x
+ //
+ // Where F -> isFirstPosition
+ // L -> isLastPosition
+ // C -> isCurrentRightToLeft
+ // P -> isRightToLeftParagraph
+ // A -> Whether to add the glyph's advance.
+
+ const bool addGlyphAdvance = ( ( isLastPositionOfLine && !isRightToLeftParagraph ) ||
+ ( isFirstPositionOfLine && isRightToLeftParagraph ) ||
+ ( !isFirstPositionOfLine && !isLastPosition && !isCurrentRightToLeft ) );
+
+ float glyphAdvance = addGlyphAdvance ? glyphMetrics.advance : 0.f;
+
+ if( !isLastPositionOfLine &&
+ ( primaryNumberOfCharacters > 1u ) )
{
- numberOfGlyphAdvance = primaryNumberOfCharacters - numberOfGlyphAdvance;
- }
+ const CharacterIndex firstIndex = *( glyphsToCharactersBuffer + primaryGlyphIndex );
- glyphAdvance = static_cast<float>( numberOfGlyphAdvance ) * glyphMetrics.advance / static_cast<float>( primaryNumberOfCharacters );
- }
+ bool isCurrentRightToLeft = false;
+ if( bidiLineFetched ) // If bidiLineFetched is false, it means the whole text is left to right.
+ {
+ isCurrentRightToLeft = *( directionsBuffer + index );
+ }
- // Get the glyph position and x bearing.
- const Vector2& primaryPosition = *( glyphPositionsBuffer + primaryGlyphIndex );
+ Length numberOfGlyphAdvance = ( isFirstPositionOfLine ? 0u : 1u ) + characterIndex - firstIndex;
+ if( isCurrentRightToLeft )
+ {
+ numberOfGlyphAdvance = primaryNumberOfCharacters - numberOfGlyphAdvance;
+ }
- // Set the primary cursor's height.
- cursorInfo.primaryCursorHeight = cursorInfo.isSecondaryCursor ? 0.5f * glyphMetrics.fontHeight : glyphMetrics.fontHeight;
+ glyphAdvance = static_cast<float>( numberOfGlyphAdvance ) * glyphMetrics.advance / static_cast<float>( primaryNumberOfCharacters );
+ }
- // Set the primary cursor's position.
- cursorInfo.primaryPosition.x = -glyphMetrics.xBearing + primaryPosition.x + glyphAdvance;
- cursorInfo.primaryPosition.y = line.ascender - glyphMetrics.ascender;
+ // Get the glyph position and x bearing (in the line's coords).
+ const Vector2& primaryPosition = *( glyphPositionsBuffer + primaryGlyphIndex );
- // Calculate the secondary cursor.
+ // Set the primary cursor's height.
+ cursorInfo.primaryCursorHeight = cursorInfo.isSecondaryCursor ? 0.5f * glyphMetrics.fontHeight : glyphMetrics.fontHeight;
- if( cursorInfo.isSecondaryCursor )
- {
- // Set the secondary cursor's height.
- cursorInfo.secondaryCursorHeight = 0.5f * glyphMetrics.fontHeight;
+ // Set the primary cursor's position.
+ cursorInfo.primaryPosition.x = -glyphMetrics.xBearing + primaryPosition.x + glyphAdvance;
+ cursorInfo.primaryPosition.y = cursorInfo.lineOffset + line.ascender - glyphMetrics.ascender;
- CharacterIndex index = characterIndex;
- if( !isLastPosition )
+ // Transform the cursor info from line's coords to text's coords.
+ cursorInfo.primaryPosition.x += line.alignmentOffset;
+
+ // Calculate the secondary cursor.
+ if( cursorInfo.isSecondaryCursor )
{
- index = ( isRightToLeftParagraph == isCurrentRightToLeft ) ? nextCharacterIndex : characterIndex;
- }
+ // Set the secondary cursor's height.
+ cursorInfo.secondaryCursorHeight = 0.5f * glyphMetrics.fontHeight;
- const GlyphIndex secondaryGlyphIndex = *( charactersToGlyphBuffer + index );
- const Length secondaryNumberOfGlyphs = *( glyphsPerCharacterBuffer + index );
+ CharacterIndex index = characterIndex;
+ if( !isLastPositionOfLine )
+ {
+ index = ( isRightToLeftParagraph == isCurrentRightToLeft ) ? nextCharacterIndex : characterIndex;
+ }
- const Vector2& secondaryPosition = *( glyphPositionsBuffer + secondaryGlyphIndex );
+ const GlyphIndex secondaryGlyphIndex = *( charactersToGlyphBuffer + index );
+ const Length secondaryNumberOfGlyphs = *( glyphsPerCharacterBuffer + index );
- GetGlyphsMetrics( secondaryGlyphIndex,
- secondaryNumberOfGlyphs,
- glyphMetrics,
- glyphInfoBuffer,
- metrics );
+ const Vector2& secondaryPosition = *( glyphPositionsBuffer + secondaryGlyphIndex );
+
+ GetGlyphsMetrics( secondaryGlyphIndex,
+ secondaryNumberOfGlyphs,
+ glyphMetrics,
+ glyphInfoBuffer,
+ metrics );
- // Set the secondary cursor's position.
- cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + ( isCurrentRightToLeft ? 0.f : glyphMetrics.advance );
- cursorInfo.secondaryPosition.y = cursorInfo.lineHeight - cursorInfo.secondaryCursorHeight - line.descender - ( glyphMetrics.fontHeight - glyphMetrics.ascender );
+ // Set the secondary cursor's position.
+
+ // FCP A
+ // ------
+ // 000 1
+ // 001 x
+ // 010 0
+ // 011 0
+ // 100 x
+ // 101 0
+ // 110 1
+ // 111 x
+ //
+ // Where F -> isFirstPosition
+ // C -> isCurrentRightToLeft
+ // P -> isRightToLeftParagraph
+ // A -> Whether to add the glyph's advance.
+
+ const bool addGlyphAdvance = ( ( !isFirstPositionOfLine && !isCurrentRightToLeft ) ||
+ ( isFirstPositionOfLine && !isRightToLeftParagraph ) );
+
+ cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + ( addGlyphAdvance ? glyphMetrics.advance : 0.f );
+ cursorInfo.secondaryPosition.y = cursorInfo.lineOffset + cursorInfo.lineHeight - cursorInfo.secondaryCursorHeight - line.descender - ( glyphMetrics.fontHeight - glyphMetrics.ascender );
+
+ // Transform the cursor info from line's coords to text's coords.
+ cursorInfo.secondaryPosition.x += line.alignmentOffset;
+ }
}
}
~CursorInfo()
{}
- Vector2 primaryPosition; ///< The primary cursor's position.
- Vector2 secondaryPosition; ///< The secondary cursor's position.
+ Vector2 primaryPosition; ///< The primary cursor's position (in text's coords).
+ Vector2 secondaryPosition; ///< The secondary cursor's position (in text's coords).
float lineOffset; ///< The vertical offset where the line containing the cursor starts.
float lineHeight; ///< The height of the line where the cursor is placed.
float primaryCursorHeight; ///< The primary cursor's height.
*
* It returns the first line if the touch point is above the text and the last line if the touch point is below.
*
+ * @param[in] visualModel The visual model.
+ * @param[in] visualY The touch point 'y' in text's coords.
+ *
* @return A line index.
*/
LineIndex GetClosestLine( VisualModelPtr visualModel,
float visualY );
/**
+ * @brief Calculates the vertical line's offset for a given line.
+ *
+ * @pre @p lineIndex must be between 0 and the number of lines (both inclusive).
+ *
+ * @param[in] lines The laid-out lines.
+ * @param[in] lineIndex Index to the line.
+ *
+ * @return The vertical offset of the given line.
+ */
+float CalculateLineOffset( const Vector<LineRun>& lines,
+ LineIndex lineIndex );
+
+/**
* @brief Retrieves the cursor's logical position for a given touch point x,y
*
* @param[in] visualModel The visual model.
* @param[in] logicalModel The logical model.
* @param[in] metrics A wrapper around FontClient used to get metrics.
- * @param[in] visualX The touch point x.
- * @param[in] visualY The touch point y.
+ * @param[in] visualX The touch point 'x' in text's coords.
+ * @param[in] visualY The touch point 'y' in text's coords.
*
* @return The logical cursor position (in characters). 0 is just before the first character, a value equal to the number of characters is just after the last character.
*/
* It retrieves as well the line's height and the cursor's height and
* if there is a valid alternative cursor, its position and height.
*
+ * @param[in] visualModel The visual model.
+ * @param[in] logicalModel The logical model.
+ * @param[in] metrics A wrapper around FontClient used to get metrics.
* @param[in] logical The logical cursor position (in characters). 0 is just before the first character, a value equal to the number of characters is just after the last character.
* @param[out] cursorInfo The line's height, the cursor's height, the cursor's position and whether there is an alternative cursor.
*/
CursorInfo& cursorInfo );
/**
+ * @brief Find the indices to the first and last characters of a word for the given touch point.
*
+ * @param[in] visualModel The visual model.
+ * @param[in] logicalModel The logical model.
+ * @param[in] metrics A wrapper around FontClient used to get metrics.
+ * @param[in] visualX The touch point 'x' in text's coords.
+ * @param[in] visualY The touch point 'y' in text's coords.
+ * @param[out] startIndex Index to the first character of the selected word.
+ * @param[out] endIndex Index to the last character of the selected word.
*/
void FindSelectionIndices( VisualModelPtr visualModel,
LogicalModelPtr logicalModel,
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/bidirectional-line-info-run.h>
+#include <dali-toolkit/internal/text/cursor-helper-functions.h>
#include <dali-toolkit/internal/text/glyph-metrics-helper.h>
#include <dali-toolkit/internal/text/layouts/layout-parameters.h>
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--GetLineLayoutForBox\n" );
}
- /**
- * @brief Calculates the vertical offset to add to the new laid-out glyphs.
- *
- * @pre @p lineIndex must be between 0 and the number of lines (both inclusive).
- *
- * @param[in] lines The previously laid-out lines.
- * @param[in] lineIndex Index to the line where the new laid-out lines are inserted.
- *
- * @return The vertical offset of the lines starting from the beginning to the line @p lineIndex.
- */
- float SetParagraphOffset( const Vector<LineRun>& lines,
- LineIndex lineIndex )
- {
- float offset = 0.f;
-
- for( Vector<LineRun>::ConstIterator it = lines.Begin(),
- endIt = lines.Begin() + lineIndex;
- it != endIt;
- ++it )
- {
- const LineRun& line = *it;
-
- offset += line.ascender + -line.descender;
- }
-
- return offset;
- }
-
void SetGlyphPositions( const GlyphInfo* const glyphsBuffer,
Length numberOfGlyphs,
Vector2* glyphPositionsBuffer )
linesBuffer = lines.Begin();
}
- float penY = SetParagraphOffset( lines,
- layoutParameters.startLineIndex );
+ float penY = CalculateLineOffset( lines,
+ layoutParameters.startLineIndex );
for( GlyphIndex index = layoutParameters.startGlyphIndex; index < lastGlyphPlusOne; )
{
mPlaceholderTextInactive(),
mPlaceholderTextColor( 0.8f, 0.8f, 0.8f, 0.8f ),
mEventQueue(),
- mScrollPosition(),
mState( INACTIVE ),
mPrimaryCursorPosition( 0u ),
mLeftSelectionPosition( 0u ),
{
if( IsShowingRealText() )
{
- const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x;
- const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y;
+ // Convert from control's coords to text's coords.
+ const float xPosition = event.p2.mFloat - mScrollPosition.x;
+ const float yPosition = event.p3.mFloat - mScrollPosition.y;
mEventData->mPrimaryCursorPosition = Text::GetClosestCursorIndex( mVisualModel,
mLogicalModel,
int state = event.p1.mInt;
- if( Gesture::Started == state ||
- Gesture::Continuing == state )
+ if( ( Gesture::Started == state ) ||
+ ( Gesture::Continuing == state ) )
{
const Vector2& actualSize = mVisualModel->GetLayoutSize();
- const Vector2 currentScroll = mEventData->mScrollPosition;
+ const Vector2 currentScroll = mScrollPosition;
if( mEventData->mHorizontalScrollingEnabled )
{
const float displacementX = event.p2.mFloat;
- mEventData->mScrollPosition.x += displacementX;
+ mScrollPosition.x += displacementX;
ClampHorizontalScroll( actualSize );
}
if( mEventData->mVerticalScrollingEnabled )
{
const float displacementY = event.p3.mFloat;
- mEventData->mScrollPosition.y += displacementY;
+ mScrollPosition.y += displacementY;
ClampVerticalScroll( actualSize );
}
if( mEventData->mDecorator )
{
- mEventData->mDecorator->UpdatePositions( mEventData->mScrollPosition - currentScroll );
+ mEventData->mDecorator->UpdatePositions( mScrollPosition - currentScroll );
}
}
}
if( HANDLE_PRESSED == state )
{
- // The event.p2 and event.p3 are in decorator coords. Need to transforms to text coords.
- const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x;
- const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y;
+ // Convert from decorator's coords to text's coords.
+ const float xPosition = event.p2.mFloat - mScrollPosition.x;
+ const float yPosition = event.p3.mFloat - mScrollPosition.y;
const CharacterIndex handleNewPosition = Text::GetClosestCursorIndex( mVisualModel,
mLogicalModel,
CharacterIndex handlePosition = 0u;
if( handleStopScrolling )
{
- // The event.p2 and event.p3 are in decorator coords. Need to transforms to text coords.
- const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x;
- const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y;
+ // Convert from decorator's coords to text's coords.
+ const float xPosition = event.p2.mFloat - mScrollPosition.x;
+ const float yPosition = event.p3.mFloat - mScrollPosition.y;
handlePosition = Text::GetClosestCursorIndex( mVisualModel,
mLogicalModel,
{
const float xSpeed = event.p2.mFloat;
const Vector2& actualSize = mVisualModel->GetLayoutSize();
- const Vector2 currentScrollPosition = mEventData->mScrollPosition;
+ const Vector2 currentScrollPosition = mScrollPosition;
- mEventData->mScrollPosition.x += xSpeed;
+ mScrollPosition.x += xSpeed;
ClampHorizontalScroll( actualSize );
bool endOfScroll = false;
- if( Vector2::ZERO == ( currentScrollPosition - mEventData->mScrollPosition ) )
+ if( Vector2::ZERO == ( currentScrollPosition - mScrollPosition ) )
{
// Notify the decorator there is no more text to scroll.
// The decorator won't send more scroll events.
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.
+ // The grab handle's position is in decorator's coords. Need to transforms to text's coords.
const CharacterIndex handlePosition = Text::GetClosestCursorIndex( mVisualModel,
mLogicalModel,
mMetrics,
- position.x - mEventData->mScrollPosition.x - mAlignmentOffset.x,
- position.y - mEventData->mScrollPosition.y - mAlignmentOffset.y );
+ position.x - mScrollPosition.x,
+ position.y - mScrollPosition.y );
mEventData->mUpdateCursorPosition = mEventData->mPrimaryCursorPosition != handlePosition;
mEventData->mScrollAfterUpdatePosition = mEventData->mUpdateCursorPosition;
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.
+ // The selection handle's position is in decorator's coords. Need to transform to text's coords.
const CharacterIndex handlePosition = Text::GetClosestCursorIndex( mVisualModel,
mLogicalModel,
mMetrics,
- position.x - mEventData->mScrollPosition.x - mAlignmentOffset.x,
- position.y - mEventData->mScrollPosition.y - mAlignmentOffset.y );
+ position.x - mScrollPosition.x,
+ position.y - mScrollPosition.y );
if( leftSelectionHandleEvent )
{
if( mEventData->mSelectionEnabled )
{
- // The event.p2 and event.p3 are in decorator coords. Need to transforms to text coords.
- const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x;
- const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y;
+ // Convert from control's coords to text's coords.
+ const float xPosition = event.p2.mFloat - mScrollPosition.x;
+ const float yPosition = event.p3.mFloat - mScrollPosition.y;
// Calculates the logical position from the x,y coords.
RepositionSelectionHandles( xPosition,
const Length numberOfCharactersEnd = *( charactersPerGlyphBuffer + glyphEnd );
bool splitEndGlyph = ( glyphStart != glyphEnd ) && ( numberOfCharactersEnd > 1u ) && HasLigatureMustBreak( mLogicalModel->GetScript( selectionEndMinusOne ) );
- const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
-
// Traverse the glyphs.
for( GlyphIndex index = glyphStart; index <= glyphEnd; ++index )
{
// Calculate the number of characters selected.
const Length numberOfCharacters = ( glyphStart == glyphEnd ) ? ( selectionEnd - selectionStart ) : ( numberOfCharactersStart - interGlyphIndex );
- const float xPosition = position.x - glyph.xBearing + offset.x + glyphAdvance * static_cast<float>( isCurrentRightToLeft ? ( numberOfCharactersStart - interGlyphIndex - numberOfCharacters ) : interGlyphIndex );
+ const float xPosition = firstLine.alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + glyphAdvance * static_cast<float>( isCurrentRightToLeft ? ( numberOfCharactersStart - interGlyphIndex - numberOfCharacters ) : interGlyphIndex );
mEventData->mDecorator->AddHighlight( xPosition,
- offset.y,
+ mScrollPosition.y,
xPosition + static_cast<float>( numberOfCharacters ) * glyphAdvance,
- offset.y + height );
+ mScrollPosition.y + height );
splitStartGlyph = false;
continue;
const Length numberOfCharacters = numberOfCharactersEnd - interGlyphIndex;
- const float xPosition = position.x - glyph.xBearing + offset.x + ( isCurrentRightToLeft ? ( glyphAdvance * static_cast<float>( numberOfCharacters ) ) : 0.f );
+ const float xPosition = firstLine.alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + ( isCurrentRightToLeft ? ( glyphAdvance * static_cast<float>( numberOfCharacters ) ) : 0.f );
mEventData->mDecorator->AddHighlight( xPosition,
- offset.y,
+ mScrollPosition.y,
xPosition + static_cast<float>( interGlyphIndex ) * glyphAdvance,
- offset.y + height );
+ mScrollPosition.y + height );
splitEndGlyph = false;
continue;
}
- const float xPosition = position.x - glyph.xBearing + offset.x;
+ const float xPosition = firstLine.alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x;
mEventData->mDecorator->AddHighlight( xPosition,
- offset.y,
+ mScrollPosition.y,
xPosition + glyph.advance,
- offset.y + height );
+ mScrollPosition.y + height );
}
CursorInfo primaryCursorInfo;
GetCursorPosition( mEventData->mRightSelectionPosition,
secondaryCursorInfo );
- const Vector2 primaryPosition = primaryCursorInfo.primaryPosition + offset;
- const Vector2 secondaryPosition = secondaryCursorInfo.primaryPosition + offset;
+ const Vector2 primaryPosition = primaryCursorInfo.primaryPosition + mScrollPosition;
+ const Vector2 secondaryPosition = secondaryCursorInfo.primaryPosition + mScrollPosition;
mEventData->mDecorator->SetPosition( LEFT_SELECTION_HANDLE,
primaryPosition.x,
- primaryCursorInfo.lineOffset + offset.y,
+ primaryCursorInfo.lineOffset + mScrollPosition.y,
primaryCursorInfo.lineHeight );
mEventData->mDecorator->SetPosition( RIGHT_SELECTION_HANDLE,
secondaryPosition.x,
- secondaryCursorInfo.lineOffset + offset.y,
+ secondaryCursorInfo.lineOffset + mScrollPosition.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
}
}
- switch( mLayoutEngine.GetVerticalAlignment() )
- {
- case LayoutEngine::VERTICAL_ALIGN_TOP:
- {
- cursorInfo.primaryPosition.y = 0.f;
- break;
- }
- case LayoutEngine::VERTICAL_ALIGN_CENTER:
- {
- cursorInfo.primaryPosition.y = floorf( 0.5f * ( mVisualModel->mControlSize.height - cursorInfo.lineHeight ) );
- break;
- }
- case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
- {
- cursorInfo.primaryPosition.y = mVisualModel->mControlSize.height - cursorInfo.lineHeight;
- break;
- }
- }
-
// Nothing else to do.
return;
}
return;
}
- const Vector2 offset = mEventData->mScrollPosition + ( IsShowingRealText() ? mAlignmentOffset : Vector2::ZERO );
- const Vector2 cursorPosition = cursorInfo.primaryPosition + offset;
+ const Vector2 cursorPosition = cursorInfo.primaryPosition + mScrollPosition;
// Sets the cursor position.
mEventData->mDecorator->SetPosition( PRIMARY_CURSOR,
// Sets the grab handle position.
mEventData->mDecorator->SetPosition( GRAB_HANDLE,
cursorPosition.x,
- cursorInfo.lineOffset + offset.y,
+ cursorInfo.lineOffset + mScrollPosition.y,
cursorInfo.lineHeight );
if( cursorInfo.isSecondaryCursor )
{
mEventData->mDecorator->SetPosition( SECONDARY_CURSOR,
- cursorInfo.secondaryPosition.x + offset.x,
- cursorInfo.secondaryPosition.y + offset.y,
+ cursorInfo.secondaryPosition.x + mScrollPosition.x,
+ cursorInfo.secondaryPosition.y + mScrollPosition.y,
cursorInfo.secondaryCursorHeight,
cursorInfo.lineHeight );
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Secondary cursor position: %f,%f\n", cursorInfo.secondaryPosition.x + offset.x, cursorInfo.secondaryPosition.y + offset.y );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Secondary cursor position: %f,%f\n", cursorInfo.secondaryPosition.x + mScrollPosition.x, cursorInfo.secondaryPosition.y + mScrollPosition.y );
}
// Set which cursors are active according the state.
return;
}
- const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
- const Vector2 cursorPosition = cursorInfo.primaryPosition + offset;
+ const Vector2 cursorPosition = cursorInfo.primaryPosition + mScrollPosition;
// Sets the handle's position.
mEventData->mDecorator->SetPosition( handleType,
cursorPosition.x,
- cursorInfo.lineOffset + offset.y,
+ cursorInfo.lineOffset + mScrollPosition.y,
cursorInfo.lineHeight );
// If selection handle at start of the text and other at end of the text then all text is selected.
void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )
{
- // Clamp between -space & 0 (and the text alignment).
+ // Clamp between -space & 0.
if( actualSize.width > mVisualModel->mControlSize.width )
{
- 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;
+ const float space = ( actualSize.width - mVisualModel->mControlSize.width );
+ mScrollPosition.x = ( mScrollPosition.x < -space ) ? -space : mScrollPosition.x;
+ mScrollPosition.x = ( mScrollPosition.x > 0.f ) ? 0.f : mScrollPosition.x;
mEventData->mDecoratorUpdated = true;
}
else
{
- mEventData->mScrollPosition.x = 0.f;
+ mScrollPosition.x = 0.f;
}
}
void Controller::Impl::ClampVerticalScroll( const Vector2& actualSize )
{
- // Clamp between -space & 0 (and the text alignment).
+ // Clamp between -space & 0.
if( actualSize.height > mVisualModel->mControlSize.height )
{
- 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;
+ const float space = ( actualSize.height - mVisualModel->mControlSize.height );
+ mScrollPosition.y = ( mScrollPosition.y < -space ) ? -space : mScrollPosition.y;
+ mScrollPosition.y = ( mScrollPosition.y > 0.f ) ? 0.f : mScrollPosition.y;
mEventData->mDecoratorUpdated = true;
}
else
{
- mEventData->mScrollPosition.y = 0.f;
+ mScrollPosition.y = 0.f;
}
}
const float positionEnd = position.x + cursorWidth;
// Transform the position to decorator coords.
- const float alignment = IsShowingRealText() ? mAlignmentOffset.x : 0.f;
- const float offset = mEventData->mScrollPosition.x + alignment;
- const float decoratorPositionBegin = position.x + offset;
- const float decoratorPositionEnd = positionEnd + offset;
+ const float decoratorPositionBegin = position.x + mScrollPosition.x;
+ const float decoratorPositionEnd = positionEnd + mScrollPosition.x;
if( decoratorPositionBegin < 0.f )
{
- mEventData->mScrollPosition.x = -position.x - alignment;
+ mScrollPosition.x = -position.x;
}
else if( decoratorPositionEnd > mVisualModel->mControlSize.width )
{
- mEventData->mScrollPosition.x = mVisualModel->mControlSize.width - positionEnd - alignment;
+ mScrollPosition.x = mVisualModel->mControlSize.width - positionEnd;
}
}
const Vector2& currentCursorPosition = mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
// Calculate the offset to match the cursor position before the character was deleted.
- mEventData->mScrollPosition.x = currentCursorPosition.x - cursorInfo.primaryPosition.x - mAlignmentOffset.x;
+ mScrollPosition.x = currentCursorPosition.x - cursorInfo.primaryPosition.x;
ClampHorizontalScroll( mVisualModel->GetLayoutSize() );
InputStyle mInputStyle; ///< The style to be set to the new inputed text.
- /**
- * 0,0 means that the top-left corner of the layout matches the top-left corner of the UI control.
- * Typically this will have a negative value with scrolling occurs.
- */
- Vector2 mScrollPosition; ///< The text is offset by this position when scrolling.
-
State mState; ///< Selection mode, edit mode etc.
CharacterIndex mPrimaryCursorPosition; ///< Index into logical model for primary cursor.
mLayoutEngine(),
mModifyEvents(),
mTextColor( Color::BLACK ),
- mAlignmentOffset(),
mTextUpdateInfo(),
mOperationsPending( NO_OPERATION ),
mMaximumNumberOfCharacters( 50u ),
LayoutEngine mLayoutEngine; ///< The layout engine.
Vector<ModifyEvent> 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.
+ /**
+ * 0,0 means that the top-left corner of the layout matches the top-left corner of the UI control.
+ * Typically this will have a negative value with scrolling occurs.
+ */
+ Vector2 mScrollPosition; ///< The text is offset by this position when scrolling.
TextUpdateInfo mTextUpdateInfo; ///< Info of the characters updated.
OperationsMask mOperationsPending; ///< Operations pending to be done to layout the text.
Length mMaximumNumberOfCharacters; ///< Maximum number of characters that can be inserted.
return mImpl->mAutoScrollDirectionRTL;
}
+float Controller::GetAutoScrollLineAlignment() const
+{
+ float offset = 0.f;
+
+ if( mImpl->mVisualModel &&
+ ( 0u != mImpl->mVisualModel->mLines.Count() ) )
+ {
+ offset = ( *mImpl->mVisualModel->mLines.Begin() ).alignmentOffset;
+ }
+
+ return offset;
+}
+
void Controller::SetText( const std::string& text )
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
const Vector2& Controller::GetScrollPosition() const
{
- if( NULL != mImpl->mEventData )
- {
- return mImpl->mEventData->mScrollPosition;
- }
-
- return Vector2::ZERO;
-}
-
-const Vector2& Controller::GetAlignmentOffset() const
-{
- return mImpl->mAlignmentOffset;
+ return mImpl->mScrollPosition;
}
Vector3 Controller::GetNaturalSize()
// Whether the text control is editable
const bool isEditable = NULL != mImpl->mEventData;
- // Keep the current offset and alignment as it will be used to update the decorator's positions (if the size changes).
+ // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
Vector2 offset;
if( newSize && isEditable )
{
- offset = mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition;
+ offset = mImpl->mScrollPosition;
}
- // After doing the text layout, the alignment offset to place the actor in the desired position can be calculated.
- CalculateTextAlignment( size );
+ if( !isEditable || !IsMultiLineEnabled() )
+ {
+ // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
+ CalculateVerticalOffset( size );
+ }
if( isEditable )
{
mImpl->ClampHorizontalScroll( layoutSize );
// Update the decorator's positions is needed if there is a new size.
- mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition - offset );
+ mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mScrollPosition - offset );
}
// Move the cursor, grab handle etc.
if( NULL != mImpl->mEventData )
{
// Reset the scroll position.
- mImpl->mEventData->mScrollPosition = Vector2::ZERO;
+ mImpl->mScrollPosition = Vector2::ZERO;
mImpl->mEventData->mScrollAfterUpdatePosition = true;
}
}
return mImpl->mLayoutEngine.GetVerticalAlignment();
}
-void Controller::CalculateTextAlignment( const Size& controlSize )
+void Controller::CalculateVerticalOffset( const Size& controlSize )
{
Size layoutSize = mImpl->mVisualModel->GetLayoutSize();
layoutSize.height = mImpl->GetDefaultFontLineHeight();
}
- if( LayoutEngine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
- {
- // Get the direction of the first character.
- const CharacterDirection firstParagraphDirection = mImpl->mLogicalModel->GetCharacterDirection( 0u );
-
- // If the first paragraph is right to left swap ALIGN_BEGIN and ALIGN_END;
- LayoutEngine::HorizontalAlignment horizontalAlignment = mImpl->mLayoutEngine.GetHorizontalAlignment();
- if( firstParagraphDirection )
- {
- switch( horizontalAlignment )
- {
- case LayoutEngine::HORIZONTAL_ALIGN_BEGIN:
- {
- horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_END;
- break;
- }
- case LayoutEngine::HORIZONTAL_ALIGN_CENTER:
- {
- // Nothing to do.
- break;
- }
- case LayoutEngine::HORIZONTAL_ALIGN_END:
- {
- horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_BEGIN;
- break;
- }
- }
- }
-
- switch( horizontalAlignment )
- {
- case LayoutEngine::HORIZONTAL_ALIGN_BEGIN:
- {
- mImpl->mAlignmentOffset.x = 0.f;
- break;
- }
- case LayoutEngine::HORIZONTAL_ALIGN_CENTER:
- {
- mImpl->mAlignmentOffset.x = floorf( 0.5f * ( controlSize.width - layoutSize.width ) ); // try to avoid pixel alignment.
- break;
- }
- case LayoutEngine::HORIZONTAL_ALIGN_END:
- {
- mImpl->mAlignmentOffset.x = controlSize.width - layoutSize.width;
- break;
- }
- }
- }
-
- const LayoutEngine::VerticalAlignment verticalAlignment = mImpl->mLayoutEngine.GetVerticalAlignment();
- switch( verticalAlignment )
+ switch( mImpl->mLayoutEngine.GetVerticalAlignment() )
{
case LayoutEngine::VERTICAL_ALIGN_TOP:
{
- mImpl->mAlignmentOffset.y = 0.f;
+ mImpl->mScrollPosition.y = 0.f;
break;
}
case LayoutEngine::VERTICAL_ALIGN_CENTER:
{
- mImpl->mAlignmentOffset.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
+ mImpl->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
break;
}
case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
{
- mImpl->mAlignmentOffset.y = controlSize.height - layoutSize.height;
+ mImpl->mScrollPosition.y = controlSize.height - layoutSize.height;
break;
}
}
CharacterDirection GetAutoScrollDirection() const;
/**
+ * @brief Get the alignment offset of the first line of text.
+ *
+ * @return The alignment offset.
+ */
+ float GetAutoScrollLineAlignment() const;
+
+ /**
* @brief Replaces any text previously set.
*
* @note This will be converted into UTF-32 when stored in the text model.
const Vector2& GetScrollPosition() const;
/**
- * @brief Query the alignment offset.
- *
- * @return The alignmnet offset.
- */
- const Vector2& GetAlignmentOffset() const;
-
- /**
* @copydoc Control::GetNaturalSize()
*/
Vector3 GetNaturalSize();
LayoutEngine::VerticalAlignment GetVerticalAlignment() const;
/**
- * @brief Calulates the alignment of the whole text inside the bounding box.
+ * @brief Calulates the vertical offset to align the text inside the bounding box.
*
* @param[in] size The size of the bounding box.
*/
- void CalculateTextAlignment( const Size& size );
+ void CalculateVerticalOffset( const Size& size );
/**
* @brief Return the layout engine.
CleanUp();
}
-void TextScroller::SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, const Vector2 alignmentOffset )
+void TextScroller::SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, float alignmentOffset )
{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters controlSize[%f,%f] offscreenSize[%f,%f] direction[%d] alignmentOffset[%f,%f]\n",
- controlSize.x, controlSize.y, offScreenSize.x, offScreenSize.y, direction, alignmentOffset.x, alignmentOffset.y );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters controlSize[%f,%f] offscreenSize[%f,%f] direction[%d] alignmentOffset[%f]\n",
+ controlSize.x, controlSize.y, offScreenSize.x, offScreenSize.y, direction, alignmentOffset );
FrameBufferImage offscreenRenderTargetForText = FrameBufferImage::New( offScreenSize.width, offScreenSize.height, Pixel::RGBA8888, Dali::Image::UNUSED );
Renderer renderer;
// Reposition camera to match alignment of target, RTL text has direction=true
if ( direction )
{
- mOffscreenCameraActor.SetX( alignmentOffset.x + offScreenSize.width*0.5f );
+ mOffscreenCameraActor.SetX( alignmentOffset + offScreenSize.width*0.5f );
}
else
{
* @param[in] alignmentOffset alignment of source text
*
*/
- void SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, const Vector2 alignmentOffset );
+ void SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, float alignmentOffset );
/**
* @brief Set the gap distance to elapse before the text wraps around