2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/text/markup-processor-font.h>
22 #include <dali/public-api/common/dali-vector.h>
26 #include <dali-toolkit/internal/text/font-description-run.h>
27 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
28 #include <dali-toolkit/internal/text/text-font-style.h>
38 const std::string XHTML_FAMILY_ATTRIBUTE("family");
39 const std::string XHTML_SIZE_ATTRIBUTE("size");
40 const std::string XHTML_WEIGHT_ATTRIBUTE("weight");
41 const std::string XHTML_WIDTH_ATTRIBUTE("width");
42 const std::string XHTML_SLANT_ATTRIBUTE("slant");
44 const unsigned int MAX_FONT_ATTRIBUTE_SIZE = 15u; ///< The maximum length of any of the possible 'weight', 'width' or 'slant' values.
47 void ProcessFontTag(const Tag& tag, FontDescriptionRun& fontRun)
49 for(Vector<Attribute>::ConstIterator it = tag.attributes.Begin(),
50 endIt = tag.attributes.End();
54 const Attribute& attribute(*it);
55 if(TokenComparison(XHTML_FAMILY_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
57 fontRun.familyDefined = true;
58 fontRun.familyLength = attribute.valueLength;
59 fontRun.familyName = new char[fontRun.familyLength];
60 memcpy(fontRun.familyName, attribute.valueBuffer, fontRun.familyLength);
61 // The memory is freed when the font run is removed from the logical model.
63 else if(TokenComparison(XHTML_SIZE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
65 // 64.f is used to convert from point size to 26.6 pixel format.
66 fontRun.size = static_cast<PointSize26Dot6>(StringToFloat(attribute.valueBuffer) * 64.f);
67 fontRun.sizeDefined = true;
69 else if(TokenComparison(XHTML_WEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
71 // The StringToWeight() uses the Scripting::GetEnumeration() function which requires the input string to end with a '\0' char.
72 char value[MAX_FONT_ATTRIBUTE_SIZE + 1u];
73 const Length length = attribute.valueLength > MAX_FONT_ATTRIBUTE_SIZE ? MAX_FONT_ATTRIBUTE_SIZE : attribute.valueLength;
74 memcpy(value, attribute.valueBuffer, length);
77 fontRun.weight = StringToWeight(value);
78 fontRun.weightDefined = true;
80 else if(TokenComparison(XHTML_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
82 // The StringToWidth() uses the Scripting::GetEnumeration() function which requires the input string to end with a '\0' char.
83 char value[MAX_FONT_ATTRIBUTE_SIZE + 1u];
84 const Length length = attribute.valueLength > MAX_FONT_ATTRIBUTE_SIZE ? MAX_FONT_ATTRIBUTE_SIZE : attribute.valueLength;
85 memcpy(value, attribute.valueBuffer, length);
88 fontRun.width = StringToWidth(value);
89 fontRun.widthDefined = true;
91 else if(TokenComparison(XHTML_SLANT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
93 // The StringToSlant() uses the Scripting::GetEnumeration() function which requires the input string to end with a '\0' char.
94 char value[MAX_FONT_ATTRIBUTE_SIZE + 1u];
95 const Length length = attribute.valueLength > MAX_FONT_ATTRIBUTE_SIZE ? MAX_FONT_ATTRIBUTE_SIZE : attribute.valueLength;
96 memcpy(value, attribute.valueBuffer, length);
99 fontRun.slant = StringToSlant(value);
100 fontRun.slantDefined = true;
107 } // namespace Toolkit