Merge "Fix RemoveText issue in text controller" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / markup-processor-paragraph.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // FILE HEADER
19 #include <dali-toolkit/internal/text/markup-processor-paragraph.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/bounded-paragraph-run.h>
26 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
27 #include <dali-toolkit/internal/text/markup-tags-and-attributes.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Text
34 {
35 void ProcessHorizontalAlignment(const Attribute& attribute, BoundedParagraphRun& boundedParagraphRun)
36 {
37   boundedParagraphRun.horizontalAlignmentDefined = HorizontalAlignmentTypeStringToTypeValue(attribute.valueBuffer,
38                                                                                             attribute.valueLength,
39                                                                                             boundedParagraphRun.horizontalAlignment);
40 }
41
42 void ProcessRelativeLineHeight(const Attribute& attribute, BoundedParagraphRun& boundedParagraphRun)
43 {
44   boundedParagraphRun.relativeLineSize        = StringToFloat(attribute.valueBuffer);
45   boundedParagraphRun.relativeLineSizeDefined = true;
46 }
47
48 void ProcessAttributesOfParagraphTag(const Tag& tag, BoundedParagraphRun& boundedParagraphRun)
49 {
50   // By default the align attribute is not defined until it's parsed.
51   boundedParagraphRun.horizontalAlignmentDefined = false;
52
53   for(Vector<Attribute>::ConstIterator it    = tag.attributes.Begin(),
54                                        endIt = tag.attributes.End();
55       it != endIt;
56       ++it)
57   {
58     const Attribute& attribute(*it);
59     if(TokenComparison(MARKUP::PARAGRAPH_ATTRIBUTES::ALIGN, attribute.nameBuffer, attribute.nameLength))
60     {
61       ProcessHorizontalAlignment(attribute, boundedParagraphRun);
62     }
63     else if(TokenComparison(MARKUP::PARAGRAPH_ATTRIBUTES::RELATIVE_LINE_HEIGHT, attribute.nameBuffer, attribute.nameLength))
64     {
65       ProcessRelativeLineHeight(attribute, boundedParagraphRun);
66     }
67   }
68 }
69 } // namespace Text
70
71 } // namespace Toolkit
72
73 } // namespace Dali