From: Bowon Ryu Date: Tue, 31 May 2022 10:55:22 +0000 (+0000) Subject: Merge "Refactoring related-runs for the mutable-markup (Spannable)" into devel/master X-Git-Tag: dali_2.1.25~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=96d0515d26859b6ca0e4b8a6cdb6dce13d6f6281;hp=04ed06538a1461d2ccdbd132c4902e4572b9960a Merge "Refactoring related-runs for the mutable-markup (Spannable)" into devel/master --- diff --git a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt index ebed7c6..ed393f0 100755 --- a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt @@ -19,6 +19,7 @@ SET(TC_SOURCES utc-Dali-LineHelperFunctions.cpp utc-Dali-LogicalModel.cpp utc-Dali-PropertyHelper.cpp + utc-Dali-Text-AbstractStyleCharacterRun.cpp utc-Dali-Text-Characters.cpp utc-Dali-Text-CharacterSetConversion.cpp utc-Dali-Text-Circular.cpp diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-AbstractStyleCharacterRun.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-AbstractStyleCharacterRun.cpp new file mode 100644 index 0000000..f6d1827 --- /dev/null +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-AbstractStyleCharacterRun.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace Dali; +using namespace Toolkit; +using namespace Text; + +// Tests the following functions for AbstractStyleCharacterRun. +// CharacterIndex GetStartCharacterIndex() const; +// Length GetNumberOfCharacters() const; +// CharacterIndex GetEndCharacterIndex() const; + +template +void TestAbstractStyleCharacterRunEmptyCharacterRun(std::string test_name) +{ + tet_infoline(" TestAbstractStyleCharacterRunEmptyCharacterRun "); + std::cout << " testing " << test_name << std::endl; + + tet_infoline(" Default Constructor "); + TYPE_OF_RUN abstractStyleCharacterRun; + + tet_infoline(" AbstractStyleCharacterRun_GetStartCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetStartCharacterIndex(), 0u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetNumberOfCharacters "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetNumberOfCharacters(), 0u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetEndCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetEndCharacterIndex(), 0u, TEST_LOCATION); +} + +template +void TestAbstractStyleCharacterRunOneCharacter(std::string test_name) +{ + tet_infoline(" TestAbstractStyleCharacterRunOneCharacter "); + std::cout << " testing " << test_name << std::endl; + + TYPE_OF_RUN abstractStyleCharacterRun; + abstractStyleCharacterRun.characterRun.numberOfCharacters = 1u; + tet_infoline(" AbstractStyleCharacterRun_GetStartCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetStartCharacterIndex(), 0u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetNumberOfCharacters "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetNumberOfCharacters(), 1u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetEndCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetEndCharacterIndex(), 0u, TEST_LOCATION); + + abstractStyleCharacterRun.characterRun.characterIndex = 5u; + tet_infoline(" AbstractStyleCharacterRun_GetStartCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetStartCharacterIndex(), 5u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetNumberOfCharacters "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetNumberOfCharacters(), 1u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetEndCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetEndCharacterIndex(), 5u, TEST_LOCATION); +} + +template +void TestAbstractStyleCharacterRunMoreThanOneCharacter(std::string test_name) +{ + tet_infoline(" TestAbstractStyleCharacterRunOneCharacter "); + std::cout << " testing " << test_name << std::endl; + + TYPE_OF_RUN abstractStyleCharacterRun; + abstractStyleCharacterRun.characterRun.numberOfCharacters = 15u; + tet_infoline(" AbstractStyleCharacterRun_GetStartCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetStartCharacterIndex(), 0u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetNumberOfCharacters "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetNumberOfCharacters(), 15u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetEndCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetEndCharacterIndex(), 14u, TEST_LOCATION); + + abstractStyleCharacterRun.characterRun.characterIndex = 5u; + tet_infoline(" AbstractStyleCharacterRun_GetStartCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetStartCharacterIndex(), 5u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetNumberOfCharacters "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetNumberOfCharacters(), 15u, TEST_LOCATION); + + tet_infoline(" AbstractStyleCharacterRun_GetEndCharacterIndex "); + DALI_TEST_EQUALS(abstractStyleCharacterRun.GetEndCharacterIndex(), 19u, TEST_LOCATION); +} + +int UtcDaliTextAbstractStyleCharacterRun(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextAbstractStyleCharacterRun"); + + TestAbstractStyleCharacterRunEmptyCharacterRun("ColorRun"); + TestAbstractStyleCharacterRunEmptyCharacterRun("CharacterSpacingCharacterRun"); + TestAbstractStyleCharacterRunEmptyCharacterRun("FontDescriptionRun"); + TestAbstractStyleCharacterRunEmptyCharacterRun("UnderlinedCharacterRun"); + TestAbstractStyleCharacterRunEmptyCharacterRun("StrikethroughCharacterRun"); + TestAbstractStyleCharacterRunEmptyCharacterRun("BoundedParagraphRun"); + + TestAbstractStyleCharacterRunOneCharacter("ColorRun"); + TestAbstractStyleCharacterRunOneCharacter("CharacterSpacingCharacterRun"); + TestAbstractStyleCharacterRunOneCharacter("FontDescriptionRun"); + TestAbstractStyleCharacterRunOneCharacter("UnderlinedCharacterRun"); + TestAbstractStyleCharacterRunOneCharacter("StrikethroughCharacterRun"); + TestAbstractStyleCharacterRunOneCharacter("BoundedParagraphRun"); + + TestAbstractStyleCharacterRunMoreThanOneCharacter("ColorRun"); + TestAbstractStyleCharacterRunMoreThanOneCharacter("CharacterSpacingCharacterRun"); + TestAbstractStyleCharacterRunMoreThanOneCharacter("FontDescriptionRun"); + TestAbstractStyleCharacterRunMoreThanOneCharacter("UnderlinedCharacterRun"); + TestAbstractStyleCharacterRunMoreThanOneCharacter("StrikethroughCharacterRun"); + TestAbstractStyleCharacterRunMoreThanOneCharacter("BoundedParagraphRun"); + + END_TEST; +} diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index 5d6926f..41d8c0d 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -139,6 +139,7 @@ SET( toolkit_src_files ${toolkit_src_dir}/image-loader/image-load-thread.cpp ${toolkit_src_dir}/image-loader/image-url-impl.cpp ${toolkit_src_dir}/styling/style-manager-impl.cpp + ${toolkit_src_dir}/text/abstract-style-character-run.cpp ${toolkit_src_dir}/text/bidirectional-support.cpp ${toolkit_src_dir}/text/bounded-paragraph-helper-functions.cpp ${toolkit_src_dir}/text/character-set-conversion.cpp diff --git a/dali-toolkit/internal/text/abstract-style-character-run.cpp b/dali-toolkit/internal/text/abstract-style-character-run.cpp new file mode 100644 index 0000000..60b7a8a --- /dev/null +++ b/dali-toolkit/internal/text/abstract-style-character-run.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 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 +{ +CharacterIndex AbstractStyleCharacterRun::GetStartCharacterIndex() const +{ + return characterRun.characterIndex; +} + +Length AbstractStyleCharacterRun::GetNumberOfCharacters() const +{ + return characterRun.numberOfCharacters; +} + +CharacterIndex AbstractStyleCharacterRun::GetEndCharacterIndex() const +{ + return characterRun.GetEndCharacterIndex(); +} + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/internal/text/abstract-style-character-run.h b/dali-toolkit/internal/text/abstract-style-character-run.h new file mode 100644 index 0000000..7822679 --- /dev/null +++ b/dali-toolkit/internal/text/abstract-style-character-run.h @@ -0,0 +1,117 @@ +#ifndef DALI_TOOLKIT_TEXT_ABSTRACT_STYLE_CHARACTER_RUN_H +#define DALI_TOOLKIT_TEXT_ABSTRACT_STYLE_CHARACTER_RUN_H + +/* + * Copyright (c) 2022 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Toolkit +{ +namespace Text +{ +/** + * @brief Run of characters with the same style. + */ +struct AbstractStyleCharacterRun +{ + CharacterRun characterRun; ///< The initial character index and the number of characters of the run. + + // Constructors + +protected: + /** + * @brief Constructor. + * Default constructor to set the default values + */ + AbstractStyleCharacterRun() + : characterRun{} + { + } + + /** + * @brief Constructor. + * Default constructor to set the default values + * + * @param[in] characterRun the character run + */ + AbstractStyleCharacterRun(const CharacterRun& characterRun) + : characterRun{characterRun} + { + } + +public: + AbstractStyleCharacterRun(const AbstractStyleCharacterRun&) = default; + + AbstractStyleCharacterRun(AbstractStyleCharacterRun&&) noexcept = default; + + // Operators + + AbstractStyleCharacterRun& operator=(const AbstractStyleCharacterRun&) = default; + + AbstractStyleCharacterRun& operator=(AbstractStyleCharacterRun&&) noexcept = default; + + /** + * @brief Destructor. + */ + virtual ~AbstractStyleCharacterRun() = default; + + //Methods + + /** + * @brief Retrive the first index in run. + * @return the end character index in run. + */ + CharacterIndex GetStartCharacterIndex() const; + + /** + * @brief Retrive the number of characters in the run. + * @return the the number of characters in run. + */ + Length GetNumberOfCharacters() const; + + /** + * @brief Calculate the end index in run. + * @return the end character index in run. + */ + CharacterIndex GetEndCharacterIndex() const; +}; + +} // namespace Text + +} // namespace Toolkit + +// Allow AbstractStyleCharacterRun to be treated as a POD type +template<> +struct TypeTraits : public Dali::BasicTypes +{ + enum + { + IS_TRIVIAL_TYPE = true + }; +}; + +} // namespace Dali + +#endif // DALI_TOOLKIT_TEXT_ABSTRACT_STYLE_CHARACTER_RUN_H diff --git a/dali-toolkit/internal/text/bounded-paragraph-run.h b/dali-toolkit/internal/text/bounded-paragraph-run.h index 4b3150e..3547095 100644 --- a/dali-toolkit/internal/text/bounded-paragraph-run.h +++ b/dali-toolkit/internal/text/bounded-paragraph-run.h @@ -22,7 +22,7 @@ #include // INTERNAL INCLUDES -#include +#include #include namespace Dali @@ -40,13 +40,13 @@ namespace Text * Bounded-paragraph could contain multi paragraphs that have been breaked by Paragraph Separators or appropriate Newline Functions. * This will be used to handle information for the attributes of markup tag. Like TextAlign, TextDirection, TextIndent, LineHeight, etc. */ -struct BoundedParagraphRun +struct BoundedParagraphRun : public AbstractStyleCharacterRun { /** * Default constructor to set the default values of bitfields */ BoundedParagraphRun() - : characterRun{}, + : AbstractStyleCharacterRun(), horizontalAlignment(Text::HorizontalAlignment::BEGIN), relativeLineSize(1), horizontalAlignmentDefined{false}, @@ -54,7 +54,6 @@ struct BoundedParagraphRun { } - CharacterRun characterRun; ///< The initial character index within the whole text and the number of characters of the run. Text::HorizontalAlignment::Type horizontalAlignment; ///< The paragraph horizontal alignment. Values "BEGIN" "CENTER" "END". float relativeLineSize; ///< The relative line height to be used for this paragaraph. bool horizontalAlignmentDefined : 1; ///< Whether the horizontal alignment is defined. @@ -65,6 +64,16 @@ struct BoundedParagraphRun } // namespace Toolkit +// Allow BoundedParagraphRun to be treated as a POD type +template<> +struct TypeTraits : public Dali::BasicTypes +{ + enum + { + IS_TRIVIAL_TYPE = true + }; +}; + } // namespace Dali #endif // DALI_TOOLKIT_TEXT_BOUNDED_PARAGRAPH_RUN_H diff --git a/dali-toolkit/internal/text/character-spacing-character-run.h b/dali-toolkit/internal/text/character-spacing-character-run.h index 5c4238e..f256c6a 100644 --- a/dali-toolkit/internal/text/character-spacing-character-run.h +++ b/dali-toolkit/internal/text/character-spacing-character-run.h @@ -18,11 +18,8 @@ * */ -// EXTERNAL INCLUDES -#include - // INTERNAL INCLUDES -#include +#include namespace Dali { @@ -33,19 +30,19 @@ namespace Text /** * @brief Run of character-spacing characters with same properties. */ -struct CharacterSpacingCharacterRun +struct CharacterSpacingCharacterRun : public AbstractStyleCharacterRun { /** - * Default constructor to set the default values of bitfields + * @brief Constructor. + * Default constructor to set the default values */ CharacterSpacingCharacterRun() - : characterRun{}, + : AbstractStyleCharacterRun(), value{0.f} //The default value is 0.f which does nothing. { } - CharacterRun characterRun; ///< The initial character index and the number of characters of the run. - float value; /// The spaces between characters in Pixels. A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed). + float value; /// The spaces between characters in Pixels. A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed). //TODO: Add unit property to choose between Pixel or Scale (%) }; @@ -54,6 +51,16 @@ struct CharacterSpacingCharacterRun } // namespace Toolkit +// Allow ColorRun to be treated as a POD type +template<> +struct TypeTraits : public Dali::BasicTypes +{ + enum + { + IS_TRIVIAL_TYPE = true + }; +}; + } // namespace Dali #endif // DALI_TOOLKIT_TEXT_CHARACTER_SPACING_CHARACTER_RUN_H diff --git a/dali-toolkit/internal/text/color-run.h b/dali-toolkit/internal/text/color-run.h index edae1e2..75bd27b 100644 --- a/dali-toolkit/internal/text/color-run.h +++ b/dali-toolkit/internal/text/color-run.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_TEXT_COLOR_RUN_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -18,12 +18,8 @@ * */ -// EXTERNAL INCLUDES -#include - // INTERNAL INCLUDES -#include -#include +#include namespace Dali { @@ -34,16 +30,33 @@ namespace Text /** * @brief Run of characters with the same color. */ -struct ColorRun +struct ColorRun : public AbstractStyleCharacterRun { - CharacterRun characterRun; ///< The initial character index and the number of characters of the run. - Vector4 color; ///< The color of the characters. + /** + * @brief Constructor. + * Default constructor to set the default values + */ + ColorRun() + : AbstractStyleCharacterRun() + { + } + Vector4 color; ///< The color of the characters. }; } // namespace Text } // namespace Toolkit +// Allow ColorRun to be treated as a POD type +template<> +struct TypeTraits : public Dali::BasicTypes +{ + enum + { + IS_TRIVIAL_TYPE = true + }; +}; + } // namespace Dali #endif // DALI_TOOLKIT_TEXT_COLOR_RUN_H diff --git a/dali-toolkit/internal/text/font-description-run.h b/dali-toolkit/internal/text/font-description-run.h index 04a5e91..77b8db8 100644 --- a/dali-toolkit/internal/text/font-description-run.h +++ b/dali-toolkit/internal/text/font-description-run.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_TEXT_FONT_DESCRIPTION_RUN_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -22,7 +22,7 @@ #include // INTERNAL INCLUDES -#include +#include #include namespace Dali @@ -34,13 +34,13 @@ namespace Text /** * @brief Run of characters with the same font. */ -struct FontDescriptionRun +struct FontDescriptionRun : public AbstractStyleCharacterRun { /** * Default constructor to set the default values of bitfields */ FontDescriptionRun() - : characterRun{}, + : AbstractStyleCharacterRun(), familyName{nullptr}, familyLength{0u}, weight{FontWeight::NONE}, @@ -67,7 +67,7 @@ struct FontDescriptionRun bool widthDefined, bool slantDefined, bool sizeDefined) - : characterRun{characterRun}, + : AbstractStyleCharacterRun(characterRun), familyName{familyName}, familyLength{familyLength}, weight{weight}, @@ -82,7 +82,6 @@ struct FontDescriptionRun { } - CharacterRun characterRun; ///< The initial character index and the number of characters of the run. char* familyName; ///< The font's family name. Length familyLength; ///< The length of the font's family name. FontWeight weight; ///< The font's weight. @@ -101,6 +100,16 @@ struct FontDescriptionRun } // namespace Toolkit +// Allow FontDescriptionRun to be treated as a POD type +template<> +struct TypeTraits : public Dali::BasicTypes +{ + enum + { + IS_TRIVIAL_TYPE = true + }; +}; + } // namespace Dali #endif // DALI_TOOLKIT_TEXT_FONT_DESCRIPTION_RUN_H diff --git a/dali-toolkit/internal/text/strikethrough-character-run.h b/dali-toolkit/internal/text/strikethrough-character-run.h index 66214b7..1d0bc87 100644 --- a/dali-toolkit/internal/text/strikethrough-character-run.h +++ b/dali-toolkit/internal/text/strikethrough-character-run.h @@ -22,7 +22,7 @@ #include // INTERNAL INCLUDES -#include +#include #include namespace Dali @@ -34,25 +34,34 @@ namespace Text /** * @brief Run of strikethrough characters with same properties. */ -struct StrikethroughCharacterRun +struct StrikethroughCharacterRun : public AbstractStyleCharacterRun { /** * Default constructor to set the default values of bitfields */ StrikethroughCharacterRun() - : characterRun{}, + : AbstractStyleCharacterRun(), properties{} { } - CharacterRun characterRun; ///< The initial character index and the number of characters of the run. - StrikethroughStyleProperties properties; /// The properties of strikethrough style + StrikethroughStyleProperties properties; /// The properties of strikethrough style }; } // namespace Text } // namespace Toolkit +// Allow StrikethroughCharacterRun to be treated as a POD type +template<> +struct TypeTraits : public Dali::BasicTypes +{ + enum + { + IS_TRIVIAL_TYPE = true + }; +}; + } // namespace Dali #endif // DALI_TOOLKIT_TEXT_STRIKETHROUGH_CHARACTER_RUN_H diff --git a/dali-toolkit/internal/text/underlined-character-run.h b/dali-toolkit/internal/text/underlined-character-run.h index 4024dff..c16bca6 100644 --- a/dali-toolkit/internal/text/underlined-character-run.h +++ b/dali-toolkit/internal/text/underlined-character-run.h @@ -22,7 +22,7 @@ #include // INTERNAL INCLUDES -#include +#include #include namespace Dali @@ -34,25 +34,34 @@ namespace Text /** * @brief Run of underlined characters with same properties. */ -struct UnderlinedCharacterRun +struct UnderlinedCharacterRun : public AbstractStyleCharacterRun { /** * Default constructor to set the default values of bitfields */ UnderlinedCharacterRun() - : characterRun{}, + : AbstractStyleCharacterRun(), properties{} { } - CharacterRun characterRun; ///< The initial character index and the number of characters of the run. - UnderlineStyleProperties properties; /// The properties of underline style + UnderlineStyleProperties properties; /// The properties of underline style }; } // namespace Text } // namespace Toolkit +// Allow UnderlinedCharacterRun to be treated as a POD type +template<> +struct TypeTraits : public Dali::BasicTypes +{ + enum + { + IS_TRIVIAL_TYPE = true + }; +}; + } // namespace Dali #endif // DALI_TOOLKIT_TEXT_UNDERLINED_CHARACTER_RUN_H