Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / shaping.h
1 #ifndef DALI_PLATFORM_TEXT_ABSTRACTION_SHAPING_H
2 #define DALI_PLATFORM_TEXT_ABSTRACTION_SHAPING_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/text-abstraction/script.h>
23 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
24
25 // EXTERNAL INCLUDES
26 #include <dali/public-api/object/base-handle.h>
27
28 namespace Dali
29 {
30 namespace TextAbstraction
31 {
32 struct GlyphInfo;
33
34 namespace Internal DALI_INTERNAL
35 {
36 class Shaping;
37
38 } // namespace DALI_INTERNAL
39
40 /**
41  * @brief Shaping provides an interface to retrieve glyphs from complex text.
42  *
43  * This module shapes text for a unique font id and script. If the text contains different fonts and scripts
44  * it needs to be split in runs of consecutive characters with the same font id and script.
45  *
46  * @code
47  * Shaping shaping = Shaping::Get();
48  *
49  * // Shapes a number of characters with the given font id and script.
50  * const Length numberOfGlyphs = shaping.Shape( text, numberOfCharacters, fontId, script );
51  *
52  * // Allocate memory to retrieve the glyphs and the character to glyph conversion map.
53  * GlyphInfo* glyphInfo = reinterpret_cast<GlyphInfo*>( malloc( numberOfGlyphs * sizeof( GlyphInfo ) ) );
54  * CharacterIndex* glyphToCharacterMap = reinterpret_cast<CharacterIndex*>( malloc( numberOfGlyphs * sizeof( CharacterIndex ) ) );
55  *
56  * // Retrieve the glyphs and the conversion map.
57  * shaping.GetGlyphs( glyphInfo, glyphToCharacterMap );
58  * @endcode
59  */
60 class DALI_ADAPTOR_API Shaping : public BaseHandle
61 {
62 public:
63   /**
64    * @brief Create an uninitialized Shaping handle.
65    *
66    */
67   Shaping();
68
69   /**
70    * @brief Destructor
71    *
72    * This is non-virtual since derived Handle types must not contain data or virtual methods.
73    */
74   ~Shaping();
75
76   /**
77    * @brief This constructor is used by Shaping::Get().
78    *
79    * @param[in] implementation A pointer to the internal shaping object.
80    */
81   explicit DALI_INTERNAL Shaping(Internal::Shaping* implementation);
82
83   /**
84    * @brief Retrieve a handle to the Shaping instance.
85    *
86    * @return A handle to the Shaping.
87    */
88   static Shaping Get();
89
90   /**
91    * Shapes the text.
92    *
93    * Call GetGlyphs() to retrieve the glyphs.
94    *
95    * @param[in] text Pointer to the first character of the text coded in UTF32.
96    * @param[in] numberOfCharacters The number of characters to be shaped
97    * @param[in] fontId The font to be used to shape the text.
98    * @param[in] script The text's script.
99    *
100    * @return The size of the buffer required to get the shaped text.
101    */
102   Length Shape(const Character* const text,
103                Length                 numberOfCharacters,
104                FontId                 fontId,
105                Script                 script);
106
107   /**
108    * Gets the shaped text data.
109    *
110    * @pre @p glyphInfo and @p glyphToCharacterMap must have enough space allocated for the number of glyphs.
111    * Call first Shape() to shape the text and get the number of glyphs.
112    *
113    * @param[out] glyphInfo Vector with indices to the glyph within the font, glyph's metrics and advance.
114    * @param[out] glyphToCharacterMap The glyph to character conversion map.
115    */
116   void GetGlyphs(GlyphInfo*      glyphInfo,
117                  CharacterIndex* glyphToCharacterMap);
118 };
119
120 } // namespace TextAbstraction
121
122 } // namespace Dali
123
124 #endif // DALI_PLATFORM_TEXT_ABSTRACTION_SHAPING_H