RDK Documentation (Open Sourced RDK Components)
TextStyleAttributes.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2022 RDK Management
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  * @file TextStyleAttributes.cpp
22  *
23  * @brief This file provides implementation of class methods related to subtitle text attributes
24  *
25  */
26 
27 #include <assert.h>
28 #include <cctype>
29 #include <algorithm>
30 #include <string>
31 #include "TextStyleAttributes.h"
32 #include "AampJsonObject.h" // For JSON parsing
33 
34 
35 TextStyleAttributes::TextStyleAttributes(AampLogManager* logObj) : mLogObj(logObj)
36 {
37 }
38 
39 /**
40  * @brief Get font size value from input string
41  *
42  * @param[in] input - input font size value
43  * @param[out] fontSizeOut - font size option for the input value
44  * @return int - 0 for success, -1 for failure
45  */
46 int TextStyleAttributes::getFontSize(std::string input, FontSize *fontSizeOut)
47 {
48  int retVal = 0;
49 
50  if (!input.empty() && fontSizeOut)
51  {
52  transform(input.begin(), input.end(), input.begin(), ::tolower); /* Makes sure that string is in lower case before comparison */
53 
54  if (input == "small")
55  {
56  *fontSizeOut = FONT_SIZE_SMALL;
57  }
58  else if ((input == "standard") || (input =="medium"))
59  {
60  *fontSizeOut = FONT_SIZE_STANDARD;
61  }
62  else if (input == "large")
63  {
64  *fontSizeOut = FONT_SIZE_LARGE;
65  }
66  else if (input == "extra_large")
67  {
68  *fontSizeOut = FONT_SIZE_EXTRALARGE;
69  }
70  else if (input == "auto")
71  {
72  *fontSizeOut = FONT_SIZE_EMBEDDED;
73  }
74  else
75  {
76  AAMPLOG_ERR("Unsupported font size type %s", input.c_str());
77  retVal = -1;
78  }
79  }
80  else
81  {
82  AAMPLOG_ERR("Input is NULL");
83  retVal = -1;
84  }
85  return retVal;
86 }
87 
88 /**
89  * @brief Gets Attributes of the subtitle
90  *
91  * @param[in] options - Json string containing the attributes
92  * @param[out] attributesValues - Extracted Attribute values (for now they are font size and position)
93  * @param[out] attributesMask - Mask corresponding to extracted attribute values
94  * @return int - 0 for success, -1 for failure
95  */
96 int TextStyleAttributes::getAttributes(std::string options, attributesType &attributesValues, uint32_t &attributesMask)
97 {
98  int retVal = 0;
99  attributesMask = 0;
100 
101  AAMPLOG_WARN("TextStyleAttributes::getAttributes");
102 
103  if (!options.empty())
104  {
105  std::string optionValue;
106  Attributes attribute;
107  try
108  {
109  AampJsonObject inputOptions(options);
110 
111  if (inputOptions.get("penSize", optionValue))
112  {
113  if(!getFontSize(optionValue, &(attribute.fontSize)))
114  {
115  attributesMask |= (1 << FONT_SIZE_ARR_POSITION);
116  attributesValues[FONT_SIZE_ARR_POSITION] = attribute.fontSize;
117  AAMPLOG_INFO("The font size is %d", attributesValues[FONT_SIZE_ARR_POSITION]);
118  }
119  else
120  {
121  AAMPLOG_WARN("Can not parse penSize value of %s", optionValue.c_str());
122  }
123  }
124  }
125  catch(const AampJsonParseException& e)
126  {
127  AAMPLOG_ERR("TextStyleAttributes: AampJsonParseException - %s", e.what());
128  return -1;
129  }
130  }
131  else
132  {
133  retVal = -1;
134  AAMPLOG_WARN("Empty input Json string");
135  }
136  return retVal;
137 }
AampJsonParseException
Handles the exception for JSON parser.
Definition: AampJsonObject.h:252
AampJsonObject::get
bool get(const std::string &name, std::vector< std::string > &values)
Get a string value.
Definition: AampJsonObject.cpp:291
TextStyleAttributes::Attributes
Attributes, so far fontSize only.
Definition: TextStyleAttributes.h:74
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
TextStyleAttributes::getFontSize
int getFontSize(std::string input, FontSize *fontSizeOut)
Get font size value from input string.
Definition: TextStyleAttributes.cpp:46
TextStyleAttributes::FontSize
FontSize
Available Fontsize.
Definition: TextStyleAttributes.h:42
TextStyleAttributes::getAttributes
int getAttributes(std::string options, attributesType &attributesValues, uint32_t &attributesMask)
Gets Attributes of the subtitle.
Definition: TextStyleAttributes.cpp:96
AampJsonObject.h
File to handle Json format.
attributesType
std::array< uint32_t, 14 > attributesType
Definition: SubtecAttribute.hpp:30
TextStyleAttributes.h
This file provides class and other definition related to subtitle text attributes.
AampJsonObject
Utility class to construct a JSON string.
Definition: AampJsonObject.h:37