X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Flogical-model-impl.h;h=3c01dc6f6f6a81c8ccbcd227feefa22f956c19be;hp=6baf44e98148ccbb1dece070bf51ea11dc89b9d8;hb=528aa3699cd51dab5115bca1aaebb65d4bc67c15;hpb=cc82bd9b187cda8fe2c8336b73fd1fa9376cfebd diff --git a/dali-toolkit/internal/text/logical-model-impl.h b/dali-toolkit/internal/text/logical-model-impl.h old mode 100644 new mode 100755 index 6baf44e..3c01dc6 --- a/dali-toolkit/internal/text/logical-model-impl.h +++ b/dali-toolkit/internal/text/logical-model-impl.h @@ -1,8 +1,8 @@ -#ifndef __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H__ -#define __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H__ +#ifndef DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H +#define DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -26,7 +26,11 @@ // INTERNAL INCLUDES #include #include +#include +#include #include +#include +#include #include namespace Dali @@ -38,12 +42,9 @@ namespace Toolkit namespace Text { -struct BidirectionalLineInfoRun; -struct BidirectionalParagraphInfoRun; -struct FontRun; class LogicalModel; typedef IntrusivePtr LogicalModelPtr; -struct ScriptRun; +struct InputStyle; /** * @brief A logical text model contains layout independent information. @@ -62,110 +63,9 @@ public: */ static LogicalModelPtr New(); - // Text interface. - - /** - * @brief Replaces any text previously set. - * - * @note If the number of characters is zero the text buffer is cleared. - * - * @param[in] text An array of UTF-32 characters. - * @param[in] numberOfCharacters The length of the array. - */ - void SetText( const Character* const text, - Length numberOfCharacters ); - - /** - * @brief Retrieves the number of characters of the text. - * - * @return The number of characters. - */ - Length GetNumberOfCharacters() const; - - /** - * @brief Retrieves characters from the text in the given buffer. - * - * @pre The size of the @p text buffer needs to be big enough to copy the @p numberOfCharacters. - * @param[out] text Pointer to a buffer where the text is copied. - * @param[in] characterIndex The index to the first character to copy. - * @param[in] numberOfCharacters The number of characters to be copied. - */ - void GetText( Character* text, - CharacterIndex characterIndex, - Length numberOfCharacters ) const; - - /** - * @brief Retrieves a character. - * - * @param[in] characterIndex Index to a character. - * - * @return A character. - */ - Character GetCharacter( CharacterIndex characterIndex ) const; - - /** - * @brief Replaces characters from the text. - * - * If the @p numberOfCharactersToRemove is zero, this operation is like an insert. - * If the @p numberOfCharactersToInsert is zero, this operation is like a remove. - * - * @param[in] characterIndex Where to replace the text. - * @param[in] numberOfCharactersToRemove The number of characters to be removed. - * @param[in] text Pointer to a buffer with the text encoded in utf32. - * @param[in] numberOfCharactersToInsert The number of characters in the buffer. - */ - void ReplaceText( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const Character* const text, - Length numberOfCharactersToInsert ); - // Language support interface. /** - * @brief Sets the script runs. - * - * Replaces any scripts previously set. - * - * A run is a group of consecutive characters. A script run contains the script for a run. - * - * @note If the number of runs is zero the script buffer is cleared. - * - * @param[in] scripts Pointer to a buffer with all the script runs. - * @param[in] numberOfRuns The number of script runs. - */ - void SetScripts( const ScriptRun* const scripts, - Length numberOfRuns ); - - /** - * @brief Retrieves the number of script runs and the index to the first one for the given range of characters. - * - * A run is a group of consecutive characters. A script run contains the script for a run. - * - * @param[in] characterIndex Index to the first character. - * @param[in] numberOfCharacters The number of characters. - * @param[out] firstScriptRun Index to the script run containing the character index. - * @param[out] numberOfScriptRuns The number of script runs. - */ - void GetNumberOfScriptRuns( CharacterIndex characterIndex, - Length numberOfCharacters, - ScriptRunIndex& firstScriptRun, - Length& numberOfScriptRuns ) const; - - /** - * @brief Retrieves the script runs for the given range of characters. - * - * The @p scriptRuns buffer needs to be big enough to copy the number of script runs. - * Call GetNumberOfScriptRuns() to retrieve the number of script runs. - * - * @param[out] scriptRuns Pointer to a buffer where the script runs are copied. - * @param[in] characterIndex Index to the first character. - * @param[in] numberOfCharacters The number of characters. - */ - void GetScriptRuns( ScriptRun* scriptRuns, - CharacterIndex characterIndex, - Length numberOfCharacters ) const; - - /** * @brief Retrieves the script for the given character index. * * @param[in] characterIndex Index to the character. @@ -174,406 +74,116 @@ public: */ Script GetScript( CharacterIndex characterIndex ) const; - /** - * @brief Replaces script runs for the given range of characters. - * - * If the @p numberOfCharactersToRemove is zero, this operation is like an insert. - * If the @p numberOfCharactersToInsert is zero, this operation is like a remove. - * - * @param[in] characterIndex Index of the first character where to replace the scripts. - * @param[in] numberOfCharactersToRemove The number of characters to be the script removed. - * @param[in] scriptRuns Pointer to a buffer with the script runs. - * @param[in] numberOfCharactersToInsert The number of characters to be the script inserted. - */ - void ReplaceScripts( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const ScriptRun* const scriptRuns, - Length numberOfCharactersToInsert ); - - /** - * @brief Sets the font runs. - * - * Replaces any fonts previously set. - * - * A run is a group of consecutive characters. A font run contains the font id for a run. - * - * @note If the number of runs is zero the font buffer is cleared. - * - * @param[in] fonts Pointer to a buffer with all the font runs. - * @param[in] numberOfRuns The number of font runs. - */ - void SetFonts( const FontRun* const fonts, - Length numberOfRuns ); - - /** - * @brief Retrieves the number of font runs and the index of the first one for the given range of characters. - * - * A run is a group of consecutive characters. A font run contains the font id for a run. - * - * @param[in] characterIndex Index to the first character. - * @param[in] numberOfCharacters The number of characters. - * @param[out] firstFontRun Index to the font run containing the character index. - * @param[out] numberOfFontRuns The number of font runs. - */ - void GetNumberOfFontRuns( CharacterIndex characterIndex, - Length numberOfCharacters, - FontRunIndex& firstFontRun, - Length& numberOfFontRuns ) const; - - /** - * @brief Retrieves the font runs for the given range of characters. - * - * The @p fontRuns buffer needs to be big enough to copy the number of font runs. - * Call GetNumberOfFontRuns() to retrieve the number of font runs. - * - * @param[out] fontRuns Pointer to a buffer where the font runs are copied. - * @param[in] characterIndex Index to the first character. - * @param[in] numberOfCharacters The number of characters. - */ - void GetFontRuns( FontRun* fontRuns, - CharacterIndex characterIndex, - Length numberOfCharacters ) const; - - /** - * @brief Retrieves the font id for the given character index. - * - * @param[in] characterIndex Index to the first character. - * - * @return The font id. - */ - FontId GetFont( CharacterIndex characterIndex ) const; - - /** - * @brief Replaces font runs for the given range of characters. - * - * If the @p numberOfCharactersToRemove is zero, this operation is like an insert. - * If the @p numberOfCharactersToInsert is zero, this operation is like a remove. - * - * @param[in] characterIndex Index of the first character where to replace the fonts. - * @param[in] numberOfCharactersToRemove The number of characters to be the font removed. - * @param[in] fontRuns Pointer to a buffer with the font runs. - * @param[in] numberOfCharactersToInsert The number of characters to be the font inserted. - */ - void ReplaceFonts( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const FontRun* const fontRuns, - Length numberOfCharactersToInsert ); - - // Break info interface. - - /** - * @brief Sets the line break info. - * - * See GetLineBreakInfo() to get how the line break info is encoded. - * - * Replaces any line break info previously set. - * - * @note If the @length is zero the break info buffer is cleared. - * - * @param[in] lineBreakInfo Pointer to a buffer with the line break info. - * @param[in] length The size of the buffer. - */ - void SetLineBreakInfo( const LineBreakInfo* const lineBreakInfo, - Length length ); + // Bidirectional support interface. /** - * @brief Retrieves the line break info in the given buffer. - * - * The size of the @p lineBreakInfo buffer needs to be big enough to copy the @p numberOfItems. - * - * Possible values for LineBreakInfo are: + * @brief Retrieves the direction of a characters. * - * - 0 is a LINE_MUST_BREAK. Text must be broken into a new line. - * - 1 is a LINE_ALLOW_BREAK. Is possible to break the text into a new line. - * - 2 is a LINE_NO_BREAK. Text can't be broken into a new line. + * See GetCharacterDirections(). * - @verbatim - i.e. Hello big\nworld produces: - 2222212220 22220 - @endverbatim + * @param[in] characterIndex Index to a character. * - * @param[out] lineBreakInfo Pointer to a buffer where the line break info is copied. - * @param[in] characterIndex Index to the first line break info item. - * @param[in] numberOfItems The number of items to be copied. + * @return The character's direction. */ - void GetLineBreakInfo( LineBreakInfo* lineBreakInfo, - CharacterIndex characterIndex, - Length numberOfItems ) const; + CharacterDirection GetCharacterDirection( CharacterIndex characterIndex ) const; - /** - * @brief Retrieves the line break info for the given item index. - * - * @param[in] characterIndex Index to the line break info item. - */ - LineBreakInfo GetLineBreakInfo( CharacterIndex characterIndex ) const; + // Visual <--> Logical conversion tables. /** - * @brief Replaces line break info. + * @brief Retrieves the logical cursor index for the given visual cursor index. * - * See GetLineBreakInfo() to get how the line break info is encoded. + * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false, + * then the character is not in a bidirectional line and the result will be invalid. * - * If the @p numberOfItemsToRemove is zero, this operation is like an insert. - * If the @p numberOfItemsToInsert is zero, this operation is like a remove. + * @param[in] visualCursorIndex The visual cursor index. * - * @param[in] characterIndex Where to replace the line break info. - * @param[in] numberOfItemsToRemove The number of items to be removed. - * @param[in] lineBreakInfo Pointer to a buffer with the line break info. - * @param[in] numberOfItemsToInsert The number of items in the buffer. + * @return The logical cursor index. */ - void ReplaceLineBreakInfo( CharacterIndex characterIndex, - Length numberOfItemsToRemove, - const LineBreakInfo* const lineBreakInfo, - Length numberOfItemsToInsert ); + CharacterIndex GetLogicalCursorIndex( CharacterIndex visualCursorIndex ); /** - * @brief Sets the word break info. - * - * See GetWordBreakInfo() to get how the word break info is encoded. + * @brief Retrieves the logical character index for the given visual character index. * - * Replaces any word break info previously set. + * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false, + * then the character is not in a bidirectional line and the result will be invalid. * - * @note If the @length is zero the break info buffer is cleared. + * @param[in] visualCharacterIndex The visual character index. * - * @param[in] wordBreakInfo Pointer to a buffer with the word break info. - * @param[in] length The size of the buffer. + * @return The logical character index. */ - void SetWordBreakInfo( const WordBreakInfo* const wordBreakInfo, - Length length ); + CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ); /** - * @brief Retrieves the word break info in the given buffer. - * - * The size of the @p wordBreakInfo buffer needs to be big enough to copy the @p numberOfItems. + * @brief Fetch the bidirectional line info for the given character. * - * The size of the buffer has to be big enough to store the whole word break info per character. - * Call GetNumberOfCharacters() to get the number of characters. + * Call GetBidirectionalLineInfo() to retrieve the last fetched line. * - * Possible values for WordBreakInfo are: + * @param[in] characterIndex The character index. * - * - 0 is a WORD_BREAK. Text can be broken into a new word. - * - 1 is a WORD_NO_BREAK. Text can't be broken into a new word. - * - @verbatim - i.e. Hello big\nworld produces: - 1111001100 11110 - @endverbatim - * - * @param[out] wordBreakInfo Pointer to a buffer where the word break info is copied. - * @param[in] characterIndex Index to the first word break info item. - * @param[in] numberOfItems The number of items to be copied. + * @return @e true if the given @e character is in a bidirectional line. */ - void GetWordBreakInfo( WordBreakInfo* wordBreakInfo, - CharacterIndex characterIndex, - Length numberOfItems ) const; + bool FetchBidirectionalLineInfo( CharacterIndex characterIndex ); /** - * @brief Retrieves the word break info for the given item index. - * - * @param[in] characterIndex Index to the word break info item. - */ - WordBreakInfo GetWordBreakInfo( CharacterIndex characterIndex ) const; - - /** - * @brief Replaces word break info. - * - * See GetWordBreakInfo() to get how the word break info is encoded. - * - * If the @p numberOfItemsToRemove is zero, this operation is like an insert. - * If the @p numberOfItemsToInsert is zero, this operation is like a remove. + * @brief Retrieves the last fetched bidirectional line info. * - * @param[in] characterIndex Where to replace the word break info. - * @param[in] numberOfItemsToRemove The number of items to be removed. - * @param[in] wordBreakInfo Pointer to a buffer with the word break info. - * @param[in] numberOfItemsToInsert The number of items in the buffer. + * @return The index of the bidirectional line info. */ - void ReplaceWordBreakInfo( CharacterIndex characterIndex, - Length numberOfItemsToRemove, - const WordBreakInfo* const wordBreakInfo, - Length numberOfItemsToInsert ); + BidirectionalLineRunIndex GetBidirectionalLineInfo() const; - // Bidirectional support interface. + // Text style. /** - * @brief Sets the bidirectional info runs. - * - * Replaces any bidirectional info previously set. - * - * Each bidirectional info run stores bidirectional info for a whole 'paragraph' of text which contains right to left scripts. - - * In terms of the bidirectional algorithm, a 'paragraph' is understood as a run of characters between Paragraph Separators or appropriate Newline Functions. - * A 'paragraph' may also be determined by higher-level protocols like a mark-up tag. - * - * @note If the number of runs is zero the bidirectional info buffer is cleared. + * @brief Updates the text's style runs with the added or removed text. * - * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs. - * @param[in] numberOfRuns The number of bidirectional info runs. + * @param[in] index The character's index. + * @param[in] numberOfCharacters The number of characters added or removed. If the value is negative the characters are removed. */ - void SetBidirectionalInfo( const BidirectionalParagraphInfoRun* const bidirectionalInfo, - Length numberOfRuns ); + void UpdateTextStyleRuns( CharacterIndex index, int numberOfCharacters ); /** - * @brief Retrieves the number of bidirectional info runs and the index to the first one for the given range of characters. - * - * It may be zero if there is no right to left scripts. + * @brief Retrieves the text's style for the given character index. * - * @param[in] characterIndex Index to the first character. - * @param[in] numberOfCharacters The number of characters. - * - * @return The number of bidirectional info runs. + * @param[in] index The character index. + * @param[out] style The text's style in the given style. */ - void GetNumberOfBidirectionalInfoRuns( CharacterIndex characterIndex, - Length numberOfCharacters, - BidirectionalRunIndex& firstBidirectionalRun, - Length& numberOfFontRuns ) const; + void RetrieveStyle( CharacterIndex index, InputStyle& style ); /** - * @brief Retrieves the bidirectional paragraph info runs for the given range of characters. - * - * The @p bidirectionalInfo buffer needs to be big enough to copy the number of bidirectional - * paragraph info runs. - * Call GetNumberOfBidirectionalInfoRuns() to retrieve the number of bidirectional runs. - * - * @param[out] bidirectionalInfo Pointer to a buffer where the bidirectional info runs are copied. - * @param[in] characterIndex Index to the first character. - * @param[in] numberOfCharacters The number of characters. + * @brief Clears the font description runs. */ - void GetBidirectionalInfo( BidirectionalParagraphInfoRun* bidirectionalInfo, - CharacterIndex characterIndex, - Length numberOfCharacters ) const; + void ClearFontDescriptionRuns(); - /** - * @brief Replaces bidirectional info runs for the given range of characters. - * - * If the @p numberOfCharactersToRemove is zero, this operation is like an insert. - * If the @p numberOfCharactersToInsert is zero, this operation is like a remove. - * - * @param[in] characterIndex Index of the first character where to replace the bidirectional info. - * @param[in] numberOfCharactersToRemove The number of characters to be the bidirectional info removed. - * @param[in] bidirectionalInfo Pointer to a buffer with the bidirectional info runs. - * @param[in] numberOfCharactersToInsert The number of characters to be the bidirectional info inserted. - */ - void ReplaceBidirectionalInfo( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const BidirectionalParagraphInfoRun* const bidirectionalInfo, - Length numberOfCharactersToInsert ); + // Paragraphs /** - * @brief Replaces the direction of the characters. + * @brief Creates the paragraph info. * - * @note If the number of characters is zero the directions buffer is cleared. + * @pre The line break info must be set. * - * @param[in] directions The directions of the characters. + * @param[in] startIndex The character from where the paragraph info is set. * @param[in] numberOfCharacters The number of characters. */ - void SetCharacterDirections( const CharacterDirection* const directions, - Length numberOfCharacters ); + void CreateParagraphInfo( CharacterIndex startIndex, + Length numberOfCharacters ); /** - * @brief Retrieves the direction of the characters. - * - * It sets @e true for right to left characters and @e false for left to right. - * For neutral characters it check's the next and previous character's directions: - * - If they are equals set that direction. If they are not, sets the paragraph's direction. - * - If there is no next, sets the paragraph's direction. - * - * See SetBidirectionalInfo() to get an explanation of the 'paragraph' meaning in the bidirectional algorithm. + * @brief Find the paragraphs which contains the given characters. * - * @pre the @p directions vector should be initialized to @e false (left to right) as this method is not going - * to update it if there is no right to left characters. - * - * @param[out] directions Whether the characters are right to left or left to right. - * @param[in] characterIndex Index to the first character. - * @param[in] numberOfCharacters The number of characters. + * @param[in] index The first character's index of the run. + * @param[in] numberOfCharacters The number of characters of the run. + * @param[out] paragraphs Indices to the paragraphs which contain the characters. */ - void GetCharacterDirections( CharacterDirection* directions, - CharacterIndex characterIndex, - Length numberOfCharacters ) const; + void FindParagraphs( CharacterIndex index, + Length numberOfCharacters, + Vector& paragraphs ); - /** - * @brief Retrieves the direction of a characters. - * - * See GetCharacterDirections(). - * - * @param[in] characterIndex Index to a character. - * - * @return The character's direction. - */ - CharacterDirection GetCharacterDirection( CharacterIndex characterIndex ) const; - - // Visual <--> Logical conversion tables. - - /** - * @brief Sets the visual to logical and the logical to visual map tables. - * - * Replaces any map tables previously set. - * - * @note If the number of runs is zero the bidirectional info buffer is cleared. - * - * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs. - * @param[in] numberOfRuns The number of bidirectional info runs. - */ - void SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo, - Length numberOfRuns ); + // Embedded images /** - * @brief Replaces the visual to logical and logical to visual map tables for the given range of characters. - * - * If the @p numberOfCharactersToRemove is zero, this operation is like an insert. - * If the @p numberOfCharactersToInsert is zero, this operation is like a remove. - * - * @param[in] characterIndex Index of the first character where to replace the map tables. - * @param[in] numberOfCharactersToRemove The number of characters to be removed. - * @param[in] bidirectionalInfo Pointer to a buffer with the bidirectional info runs. - * @param[in] numberOfCharactersToInsert The number of characters to be inserted. - */ - void ReplaceVisualToLogicalMap( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const BidirectionalLineInfoRun* const bidirectionalInfo, - Length numberOfCharactersToInsert ); - - /** - * @brief Retrieves the visual character index for the given logical character index. - * - * @param[in] logicalCharacterIndex The logical character index. - * - * @return The visual character index. + * @brief Clears the embedded images. */ - CharacterIndex GetVisualCharacterIndex( CharacterIndex logicalCharacterIndex ) const; - - /** - * @brief Retrieves the logical character index for the given visual character index. - * - * @param[in] visualCharacterIndex The visual character index. - * - * @return The logical character index. - */ - CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const; - - /** - * @brief Retrieves the whole or part of the logical to visual conversion map. - * - * The size of the buffer needs to be big enough to copy the @p numberOfCharacters. - * - * @param[out] logicalToVisualMap Pointer to a buffer where the conversion map is copied. - * @param[in] characterIndex Index to the first character. - * @param[in] numberOfCharacters The number of characters. - */ - void GetLogicalToVisualMap( CharacterIndex* logicalToVisualMap, - CharacterIndex characterIndex, - Length numberOfCharacters ) const; - - /** - * @brief Retrieves the whole or part of the visual to logical conversion map. - * - * The size of the buffer needs to be big enough to copy the @p numberOfCharacters. - * - * @param[out] visualToLogicalMap Pointer to a buffer where the conversion map is copied. - * @param[in] characterIndex Index to the first character. - * @param[in] numberOfCharacters The number of characters. - */ - void GetVisualToLogicalMap( CharacterIndex* visualToLogicalMap, - CharacterIndex characterIndex, - Length numberOfCharacters ) const; + void ClearEmbeddedImages(); protected: @@ -600,13 +210,17 @@ public: Vector mText; Vector mScriptRuns; Vector mFontRuns; + Vector mColorRuns; + Vector mBackgroundColorRuns; + Vector mFontDescriptionRuns; Vector mLineBreakInfo; - Vector mWordBreakInfo; + Vector mParagraphInfo; Vector mBidirectionalParagraphInfo; - Vector mCharacterDirections; ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ). + Vector mCharacterDirections; ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ). Vector mBidirectionalLineInfo; - Vector mLogicalToVisualMap; ///< Bidirectional logical to visual conversion table. - Vector mVisualToLogicalMap; ///< Bidirectional visual to logical conversion table. + Vector mEmbeddedItems; + + BidirectionalLineRunIndex mBidirectionalLineIndex; ///< The last fetched bidirectional line info. }; } // namespace Text @@ -615,4 +229,4 @@ public: } // namespace Dali -#endif // __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H__ +#endif // DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H