X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-view%2Ftext-view-processor-helper-functions.cpp;h=43a5f4e3722a67fc5f1bd3e29b9f7e776b6e8fca;hp=63360b7037d4cd72a9504930cd17534f41fb7592;hb=56c2c6b9998a38276bd619ef7ca4e20522cf0da8;hpb=ded2cfc2cce82645c2b7f8d1b666900b0ff10399 diff --git a/dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.cpp b/dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.cpp index 63360b7..43a5f4e 100644 --- a/dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.cpp +++ b/dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.cpp @@ -1,22 +1,25 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.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://floralicense.org/license/ -// -// 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. -// +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// FILE HEADER +#include // INTERNAL INCLUDES -#include "text-view-processor-helper-functions.h" -#include "text-view-processor-dbg.h" +#include namespace Dali { @@ -51,24 +54,24 @@ void UpdateSize( Size& size1, const Size& size2, const SizeGrowType type ) TextSeparatorType GetTextSeparatorType( const Character& character ) { - // returns if the given character is a line separator '\n', a word separator ' ' or if is not a separator (any other character). - return ( character.IsNewLine() ? LineSeparator : ( character.IsWhiteSpace() ? WordSeparator : NoSeparator ) ); + // returns if the given character is a paragraph separator '\n', a word separator ' ' or if is not a separator (any other character). + return ( character.IsNewLine() ? ParagraphSeparator : ( character.IsWhiteSpace() ? WordSeparator : NoSeparator ) ); } -void ChooseFontFamilyName( MarkupProcessor::StyledText& text ) +void ChooseFontFamilyName( const Character& character, TextStyle& style ) { DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, "-->TextViewProcessor::ChooseFontFamilyName\n" ); - DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, " input font name: [%s]\n", text.mStyle.GetFontName().c_str() ); + DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, " input font name: [%s]\n", style.GetFontName().c_str() ); bool userDefinedFontFamilyName = false; // First check if there is a font defined in the style and it supports the given text. - if( !text.mStyle.GetFontName().empty() ) + if( !style.GetFontName().empty() ) { - const FontParameters fontParams( text.mStyle.GetFontName(), text.mStyle.GetFontStyle() , text.mStyle.GetFontPointSize() ); + const FontParameters fontParams( style.GetFontName(), style.GetFontStyle() , style.GetFontPointSize() ); const Font font = Font::New( fontParams ); - if( !font.IsDefaultSystemFont() && font.AllGlyphsSupported( text.mText ) ) + if( !font.IsDefaultSystemFont() && font.AllGlyphsSupported( character ) ) { userDefinedFontFamilyName = true; } @@ -79,20 +82,20 @@ void ChooseFontFamilyName( MarkupProcessor::StyledText& text ) const Font defaultSystemFont = Font::New(); // At this point no font is set or doesn't support the given text. - if( !defaultSystemFont.AllGlyphsSupported( text.mText ) ) + if( !defaultSystemFont.AllGlyphsSupported( character ) ) { // If the default system font doesn't support the given text, // an appropiate font is selected. - text.mStyle.SetFontName( Font::GetFamilyForText( text.mText ) ); + style.SetFontName( Font::GetFamilyForText( character ) ); // @TODO Font::GetFamilyForText() should return font family and font style. } else { // All characters are supported with default font, so use it - text.mStyle.SetFontName( "" ); + style.SetFontName( "" ); } } - DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, " output font name: [%s]\n", text.mStyle.GetFontName().c_str() ); + DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, " output font name: [%s]\n", style.GetFontName().c_str() ); DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, "<--TextViewProcessor::ChooseFontFamilyName\n" ); } @@ -100,88 +103,67 @@ void GetIndicesFromGlobalCharacterIndex( const std::size_t index, const TextLayoutInfo& textLayoutInfo, TextInfoIndices& indices ) { - // TODO : Check for mixed LTR and RTL. - // clear all indices indices = TextInfoIndices(); // Early return. - if( textLayoutInfo.mLinesLayoutInfo.empty() ) + if( textLayoutInfo.mParagraphsLayoutInfo.empty() ) { // Text is empty. All indices are 0. return; } - std::size_t currentIndex = 0; // stores how many characters have been traversed. + std::size_t currentIndex = 0u; // stores how many characters have been traversed (within the whole text). - // Traverse all lines, groups of words and words until global index is found. + // Traverse all paragraphs and words until global index is found. bool found = false; - for( LineLayoutInfoContainer::const_iterator lineIt = textLayoutInfo.mLinesLayoutInfo.begin(), - lineEndIt = textLayoutInfo.mLinesLayoutInfo.end(); - ( !found ) && ( lineIt != lineEndIt ); - ++lineIt, ++indices.mLineIndex ) + for( ParagraphLayoutInfoContainer::const_iterator paragraphIt = textLayoutInfo.mParagraphsLayoutInfo.begin(), + paragraphEndIt = textLayoutInfo.mParagraphsLayoutInfo.end(); + ( !found ) && ( paragraphIt != paragraphEndIt ); + ++paragraphIt, ++indices.mParagraphIndex ) { - const LineLayoutInfo& lineLayoutInfo( *lineIt ); + const ParagraphLayoutInfo& paragraphLayoutInfo( *paragraphIt ); + std::size_t currentCharactersTraversed = currentIndex; // stores how many characters have been traversed until this paragraph. - if( currentIndex + lineLayoutInfo.mNumberOfCharacters > index ) + if( currentIndex + paragraphLayoutInfo.mNumberOfCharacters > index ) { - // The character is in this line - for( WordGroupLayoutInfoContainer::const_iterator groupIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(), - groupEndIt = lineLayoutInfo.mWordGroupsLayoutInfo.end(); - ( !found ) && ( groupIt != groupEndIt ); - ++groupIt, ++indices.mGroupIndex ) + // The character is in this paragraph + for( WordLayoutInfoContainer::const_iterator wordIt = paragraphLayoutInfo.mWordsLayoutInfo.begin(), + wordEndIt = paragraphLayoutInfo.mWordsLayoutInfo.end(); + ( !found ) && ( wordIt != wordEndIt ); + ++wordIt, ++indices.mWordIndex ) { - const WordGroupLayoutInfo& wordGroupLayoutInfo( *groupIt ); + const WordLayoutInfo& wordLayoutInfo( *wordIt ); - if( currentIndex + wordGroupLayoutInfo.mNumberOfCharacters > index ) + if( currentIndex + wordLayoutInfo.mCharactersLayoutInfo.size() > index ) { - // The character is in this group of words. - for( WordLayoutInfoContainer::const_iterator wordIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(), - wordEndIt = wordGroupLayoutInfo.mWordsLayoutInfo.end(); - ( !found ) && ( wordIt != wordEndIt ); - ++wordIt, ++indices.mWordIndex ) - { - const WordLayoutInfo& wordLayoutInfo( *wordIt ); - - if( currentIndex + wordLayoutInfo.mCharactersLayoutInfo.size() > index ) - { - // The character is in this word - indices.mCharacterIndex = index - currentIndex; - found = true; - } - else - { - // check in the next word. - currentIndex += wordLayoutInfo.mCharactersLayoutInfo.size(); - } - } // end words. - if( !wordGroupLayoutInfo.mWordsLayoutInfo.empty() ) - { - --indices.mWordIndex; - } + // The character is in this word + indices.mCharacterIndex = index - currentIndex; + indices.mCharacterParagraphIndex = index - currentCharactersTraversed; + found = true; } else { - // check in the next group of words - currentIndex += wordGroupLayoutInfo.mNumberOfCharacters; + // check in the next word. + currentIndex += wordLayoutInfo.mCharactersLayoutInfo.size(); } - } // end groups of words. - if( !lineLayoutInfo.mWordGroupsLayoutInfo.empty() ) + } // end words. + if( !paragraphLayoutInfo.mWordsLayoutInfo.empty() ) { - --indices.mGroupIndex; + --indices.mWordIndex; } } else { - // check in the next line - currentIndex += lineLayoutInfo.mNumberOfCharacters; + // check in the next paragraph + currentIndex += paragraphLayoutInfo.mNumberOfCharacters; } - } // end lines. + } // end paragraphs. // Need to decrease indices as they have been increased in the last loop. - if( !textLayoutInfo.mLinesLayoutInfo.empty() ) + if( !textLayoutInfo.mParagraphsLayoutInfo.empty() ) { - --indices.mLineIndex; + --indices.mParagraphIndex; } }