From 2014d90aac11fd31f9d91aaebd208dfd2efe5637 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Mon, 2 Feb 2015 11:43:12 +0000 Subject: [PATCH] Bidirectional support interface added. Change-Id: I123154d9a17e2d4c1f9dcc60a8f3f73dee865ac6 Signed-off-by: Victor Cebollada --- base/dali-toolkit/public-api/file.list | 2 + .../public-api/text/bidirectional-line-info-run.h | 49 +++++++++ .../text/bidirectional-paragraph-info-run.h | 51 +++++++++ .../public-api/text/bidirectional-support.cpp | 43 ++++++++ .../public-api/text/bidirectional-support.h | 69 ++++++++++++ .../dali-toolkit/public-api/text/logical-model.cpp | 49 +++++++++ base/dali-toolkit/public-api/text/logical-model.h | 118 +++++++++++++++++++++ .../public-api/text/text-definitions.h | 7 +- 8 files changed, 385 insertions(+), 3 deletions(-) create mode 100644 base/dali-toolkit/public-api/text/bidirectional-line-info-run.h create mode 100644 base/dali-toolkit/public-api/text/bidirectional-paragraph-info-run.h create mode 100644 base/dali-toolkit/public-api/text/bidirectional-support.cpp create mode 100644 base/dali-toolkit/public-api/text/bidirectional-support.h diff --git a/base/dali-toolkit/public-api/file.list b/base/dali-toolkit/public-api/file.list index 0c43428..6754a2a 100755 --- a/base/dali-toolkit/public-api/file.list +++ b/base/dali-toolkit/public-api/file.list @@ -38,6 +38,7 @@ public_api_base_src_files = \ $(public_api_base_src_dir)/controls/scrollable/scroll-view/scroll-view-wobble-effect.cpp \ $(public_api_base_src_dir)/controls/table-view/table-view.cpp \ $(public_api_base_src_dir)/controls/text-controls/text-label.cpp \ + $(public_api_base_src_dir)/text/bidirectional-support.cpp \ $(public_api_base_src_dir)/text/character-set-conversion.cpp \ $(public_api_base_src_dir)/text/logical-model.cpp \ $(public_api_base_src_dir)/text/multi-language-support.cpp \ @@ -124,6 +125,7 @@ public_api_base_text_controls_header_files = \ $(public_api_base_src_dir)/controls/text-controls/text-label.h public_api_base_text_header_files = \ + $(public_api_base_src_dir)/text/bidirectional-support.h \ $(public_api_base_src_dir)/text/character-run.h \ $(public_api_base_src_dir)/text/character-set-conversion.h \ $(public_api_base_src_dir)/text/font-run.h \ diff --git a/base/dali-toolkit/public-api/text/bidirectional-line-info-run.h b/base/dali-toolkit/public-api/text/bidirectional-line-info-run.h new file mode 100644 index 0000000..46e2fa3 --- /dev/null +++ b/base/dali-toolkit/public-api/text/bidirectional-line-info-run.h @@ -0,0 +1,49 @@ +#ifndef __DALI_TOOLKIT_TEXT_BIDIRECTIONAL_LINE_INFO_RUN_H__ +#define __DALI_TOOLKIT_TEXT_BIDIRECTIONAL_LINE_INFO_RUN_H__ + +/* + * Copyright (c) 2015 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Text +{ + +/** + * @brief BidirectionalLineInfoRun + */ +struct BidirectionalLineInfoRun +{ + CharacterRun characterRun; ///< The initial character index within the whole text and the number of characters of the run. + CharacterIndex* visualToLogicalMap; ///< Pointer to the visual to logical map table. + CharacterIndex* logicalToVisualMap; ///< Pointer to the logical to visual map table. +}; + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_TEXT_BIDIRECTIONAL_LINE_INFO_RUN_H__ diff --git a/base/dali-toolkit/public-api/text/bidirectional-paragraph-info-run.h b/base/dali-toolkit/public-api/text/bidirectional-paragraph-info-run.h new file mode 100644 index 0000000..055df82 --- /dev/null +++ b/base/dali-toolkit/public-api/text/bidirectional-paragraph-info-run.h @@ -0,0 +1,51 @@ +#ifndef __DALI_TOOLKIT_TEXT_BIDIRECTIONAL_PARAGRAPH_INFO_RUN_H__ +#define __DALI_TOOLKIT_TEXT_BIDIRECTIONAL_PARAGRAPH_INFO_RUN_H__ + +/* + * Copyright (c) 2015 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Text +{ + +/** + * @brief BidirectionalParagraphInfoRun + * + * 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. + */ +struct BidirectionalParagraphInfoRun +{ + CharacterRun characterRun; ///< The initial character index within the whole text and the number of characters of the run. + BidiInfoIndex bidirectionalInfoIndex; ///< Index to the table with the bidirectional info per paragraph. +}; + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_TEXT_BIDIRECTIONAL_PARAGRAPH_INFO_RUN_H__ diff --git a/base/dali-toolkit/public-api/text/bidirectional-support.cpp b/base/dali-toolkit/public-api/text/bidirectional-support.cpp new file mode 100644 index 0000000..d328511 --- /dev/null +++ b/base/dali-toolkit/public-api/text/bidirectional-support.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015 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 + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Text +{ + +void SetBidirectionalInfo( LogicalModel& model ) +{ +} + +void ReorderLines( LogicalModel& logicalModel, + const VisualModel& visualModel ) +{ +} + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali diff --git a/base/dali-toolkit/public-api/text/bidirectional-support.h b/base/dali-toolkit/public-api/text/bidirectional-support.h new file mode 100644 index 0000000..5cb557e --- /dev/null +++ b/base/dali-toolkit/public-api/text/bidirectional-support.h @@ -0,0 +1,69 @@ +#ifndef __DALI_TOOLKIT_TEXT_BIDIRECTIONAL_SUPPORT_H__ +#define __DALI_TOOLKIT_TEXT_BIDIRECTIONAL_SUPPORT_H__ + +/* + * Copyright (c) 2015 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Text +{ + +class LogicalModel; +class VisualModel; + +/** + * Sets the bidirectional info into the logical model. + * + * Any bidirectional info previously set is removed. + * + * @pre The @p model needs to have a text set. + * @pre The @p model needs to have the line break info set. + * + * @param[in,out] model The text's logical model. + */ +void SetBidirectionalInfo( LogicalModel& model ); + +/** + * Sets the visual to logical and logical to visual map tables. + * + * Any map tables previously set are removed. + * + * @pre The @p logicalModel needs to have a text set. + * @pre The @p logicalModel needs to have the line break info set. + * @pre The @p visualModel needs to have the laid-out lines info set. + * + * @param[in,out] logicalModel The text's logical model. + * @param[in] visualModel The text's visual model. + */ +void ReorderLines( LogicalModel& logicalModel, + const VisualModel& visualModel ); + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_TEXT_BIDIRECTIONAL_SUPPORT_H__ diff --git a/base/dali-toolkit/public-api/text/logical-model.cpp b/base/dali-toolkit/public-api/text/logical-model.cpp index 6d7694a..db30d05 100644 --- a/base/dali-toolkit/public-api/text/logical-model.cpp +++ b/base/dali-toolkit/public-api/text/logical-model.cpp @@ -265,6 +265,55 @@ WordBreakInfo LogicalModel::GetWordBreakInfo( CharacterIndex characterIndex ) co return 0; } +void LogicalModel::SetBidirectionalInfo( const BidirectionalParagraphInfoRun* const bidirectionalInfo, + Length numberOfRuns ) +{ +} + +Length LogicalModel::GetNumberOfBidirectionalInfoRuns( CharacterIndex characterIndex, + Length numberOfCharacters ) const +{ + return 0u; +} + +void LogicalModel::GetCharacterDirections( CharacterDirection* directions, + CharacterIndex characterIndex, + Length numberOfCharacters ) const +{ +} + +CharacterDirection LogicalModel::GetCharacterDirection( CharacterIndex characterIndex ) const +{ + return false; +} + +void LogicalModel::SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo, + Length numberOfRuns ) +{ +} + +CharacterIndex LogicalModel::GetVisualCharacterIndex( CharacterIndex logicalCharacterIndex ) const +{ + return 0u; +} + +CharacterIndex LogicalModel::GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const +{ + return 0u; +} + +void LogicalModel::GetLogicalToVisualMap( CharacterIndex* logicalToVisualMap, + CharacterIndex characterIndex, + Length numberOfCharacters ) const +{ +} + +void LogicalModel::GetVisualToLogicalMap( CharacterIndex* visualToLogicalMap, + CharacterIndex characterIndex, + Length numberOfCharacters ) const +{ +} + LogicalModel::~LogicalModel() { delete mImpl; diff --git a/base/dali-toolkit/public-api/text/logical-model.h b/base/dali-toolkit/public-api/text/logical-model.h index 2d8a66a..f573014 100644 --- a/base/dali-toolkit/public-api/text/logical-model.h +++ b/base/dali-toolkit/public-api/text/logical-model.h @@ -33,6 +33,8 @@ namespace Toolkit namespace Text { +struct BidirectionalLineInfoRun; +struct BidirectionalParagraphInfoRun; struct FontRun; class LogicalModel; typedef IntrusivePtr LogicalModelPtr; @@ -277,6 +279,122 @@ public: */ WordBreakInfo GetWordBreakInfo( CharacterIndex characterIndex ) const; + // Bidirectional support interface. + + /** + * 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. + * + * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs. + * @param[in] numberOfRuns The number of bidirectional info runs. + */ + void SetBidirectionalInfo( const BidirectionalParagraphInfoRun* const bidirectionalInfo, + Length numberOfRuns ); + + /** + * Retrieves the number of bidirectional info runs for the given range of characters. + * + * It may be zero if there is no right to left scripts. + * + * @param[in] characterIndex Index to the first character. + * @param[in] numberOfCharacters The number of characters. + * + * @return The number of bidirectional info runs. + */ + Length GetNumberOfBidirectionalInfoRuns( CharacterIndex characterIndex, + Length numberOfCharacters ) const; + + /** + * Retrieves the direction of the characters. + * + * It sets @c true for right to left characters and @c 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. + * + * @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. + */ + void GetCharacterDirections( CharacterDirection* directions, + CharacterIndex characterIndex, + Length numberOfCharacters ) const; + + /** + * 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. + + /** + * Sets the visual to logical and the logical to visual map tables. + * + * Replaces any map tables previously set. + * + * @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 ); + + /** + * Retrieves the visual character index for the given logical character index. + * + * @param[in] logicalCharacterIndex The logical character index. + * + * @return The visual character index. + */ + CharacterIndex GetVisualCharacterIndex( CharacterIndex logicalCharacterIndex ) const; + + /** + * 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; + + /** + * 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; + + /** + * 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; protected: /** diff --git a/base/dali-toolkit/public-api/text/text-definitions.h b/base/dali-toolkit/public-api/text/text-definitions.h index 0ec2554..bf13293 100644 --- a/base/dali-toolkit/public-api/text/text-definitions.h +++ b/base/dali-toolkit/public-api/text/text-definitions.h @@ -41,10 +41,11 @@ typedef TextAbstraction::CharacterIndex CharacterIndex; ///< An index into an typedef TextAbstraction::Length Length; ///< The length of an array typedef TextAbstraction::BidiInfoIndex BidiInfoIndex; ///< Index to the bidirectional info for a paragraph. typedef TextAbstraction::Script Script; ///< The character's script. -typedef TextAbstraction::LineBreakInfo LineBreakInfo; ///< Line break info (must break, allow break, no break). Possible values are: LINE_MUST_BREAK, LINE_ALLOW_BREAK and LINE_NO_BREAK (in the TextAbstraction namespace). -typedef TextAbstraction::WordBreakInfo WordBreakInfo; ///< Word break info (break, no break). Possible values are: WORD_BREAK and WORD_NO_BREAK (in the TextAbstraction namespace). +typedef TextAbstraction::LineBreakInfo LineBreakInfo; ///< Line break info (must break, allow break, no break). Possible values are: @e LINE_MUST_BREAK, @e LINE_ALLOW_BREAK and @e LINE_NO_BREAK (in the TextAbstraction namespace). +typedef TextAbstraction::WordBreakInfo WordBreakInfo; ///< Word break info (break, no break). Possible values are: @e WORD_BREAK and @e WORD_NO_BREAK (in the TextAbstraction namespace). -typedef uint32_t GlyphIndex; ///< An index into an array of glyphs +typedef uint32_t GlyphIndex; ///< An index into an array of glyphs +typedef bool CharacterDirection; ///< The character's direction: @e false is left to right, @e true is right to left. } // namespace Text -- 2.7.4