支持symbol资源编译

Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
fangyunzhong
2023-10-26 11:28:42 +00:00
parent 763c994258
commit a1aa816b37
6 changed files with 55 additions and 5 deletions
+2
View File
@@ -45,10 +45,12 @@ private:
bool HandleTheme(const Json::Value &objectNode, ResourceItem &resourceItem) const;
bool HandlePattern(const Json::Value &objectNode, ResourceItem &resourceItem) const;
bool HandlePlural(const Json::Value &objectNode, ResourceItem &resourceItem) const;
bool HandleSymbol(const Json::Value &objectNode, ResourceItem &resourceItem) const;
bool PushString(const std::string &value, ResourceItem &resourceItem) const;
bool CheckJsonStringValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const;
bool CheckJsonIntegerValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const;
bool CheckJsonSymbolValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const;
using HandleValue = std::function<bool(const Json::Value&, const ResourceItem&, std::vector<std::string>&)>;
bool ParseValueArray(const Json::Value &objectNode, ResourceItem &resourceItem,
const std::vector<std::string> &extra, HandleValue callback) const;
+5 -2
View File
@@ -39,7 +39,7 @@ const static std::string LONG_PATH_HEAD = "\\\\?\\";
const static std::string ID_DEFINED_INDENTATION = " ";
const static int32_t VERSION_MAX_LEN = 128;
const static int32_t INT_TO_BYTES = sizeof(uint32_t);
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 4.102" };
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 4.103" };
const static int32_t TAG_LEN = 4;
enum class KeyType {
@@ -73,6 +73,7 @@ enum class ResType {
MEDIA = 19,
PROF = 20,
PATTERN = 22,
SYMBOL = 23,
INVALID_RES_TYPE = -1,
};
@@ -192,7 +193,8 @@ const std::map<std::string, ResType> g_contentClusterMap = {
{ "boolean", ResType::BOOLEAN },
{ "pattern", ResType::PATTERN },
{ "theme", ResType::THEME },
{ "float", ResType::FLOAT }
{ "float", ResType::FLOAT },
{ "symbol", ResType::SYMBOL }
};
const std::map<int32_t, ResType> g_resTypeMap = {
@@ -211,6 +213,7 @@ const std::map<int32_t, ResType> g_resTypeMap = {
{ static_cast<int32_t>(ResType::MEDIA), ResType::MEDIA},
{ static_cast<int32_t>(ResType::PROF), ResType::PROF},
{ static_cast<int32_t>(ResType::PATTERN), ResType::PATTERN},
{ static_cast<int32_t>(ResType::SYMBOL), ResType::SYMBOL},
{ static_cast<int32_t>(ResType::INVALID_RES_TYPE), ResType::INVALID_RES_TYPE},
};
+7
View File
@@ -209,6 +209,13 @@ public:
*/
static uint32_t GetNormalSize(const std::vector<KeyParam> &keyParams, uint32_t index);
/**
* @brief Check if the Unicode code belongs to the 15 plane or 16 plane
* @param int unicode
* @return ture Unicode code belongs to the 15 plane or 16 plane, other false;
*/
static bool isUnicodeInPlane15or16(int unicode);
private:
enum class IgnoreType {
IGNORE_FILE,
+30
View File
@@ -90,6 +90,7 @@ void JsonCompiler::InitParser()
handles_.emplace(ResType::THEME, bind(&JsonCompiler::HandleTheme, this, _1, _2));
handles_.emplace(ResType::PATTERN, bind(&JsonCompiler::HandlePattern, this, _1, _2));
handles_.emplace(ResType::PLURAL, bind(&JsonCompiler::HandlePlural, this, _1, _2));
handles_.emplace(ResType::SYMBOL, bind(&JsonCompiler::HandleSymbol, this, _1, _2));
}
bool JsonCompiler::ParseJsonArrayLevel(const Json::Value &arrayNode, const FileInfo &fileInfo)
@@ -273,6 +274,15 @@ bool JsonCompiler::HandlePlural(const Json::Value &objectNode, ResourceItem &res
return true;
}
bool JsonCompiler::HandleSymbol(const Json::Value &objectNode, ResourceItem &resourceItem) const
{
Json::Value valueNode = objectNode[TAG_VALUE];
if (!CheckJsonSymbolValue(valueNode, resourceItem)) {
return false;
}
return PushString(valueNode.asString(), resourceItem);
}
bool JsonCompiler::PushString(const string &value, ResourceItem &resourceItem) const
{
if (!resourceItem.SetData(reinterpret_cast<const int8_t *>(value.c_str()), value.length())) {
@@ -333,6 +343,26 @@ bool JsonCompiler::CheckJsonIntegerValue(const Json::Value &valueNode, const Res
return true;
}
bool JsonCompiler::CheckJsonSymbolValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const
{
if (!valueNode.isString()) {
cerr << "Error: '" << resourceItem.GetName() << "' value not string.";
cerr << NEW_LINE_PATH << resourceItem.GetFilePath() << endl;
return false;
}
string unicodeStr = valueNode.asString();
if (regex_match(unicodeStr, regex("^\\$(ohos:)?symbol:.*"))) {
return true;
}
int unicode = strtol(unicodeStr.c_str(), nullptr, 16);
if (!ResourceUtil::isUnicodeInPlane15or16(unicode)) {
cerr << "Error: '" << resourceItem.GetName() << "' value must in 0xF0000 ~ 0xFFFFF or 0x100000 ~ 0x10FFFF.";
cerr << NEW_LINE_PATH << resourceItem.GetFilePath() << endl;
return false;
}
return true;
}
bool JsonCompiler::ParseValueArray(const Json::Value &objectNode, ResourceItem &resourceItem,
const vector<string> &extra, HandleValue callback) const
{
+6 -3
View File
@@ -34,7 +34,8 @@ const map<string, ResType> ReferenceParser::ID_REFS = {
{ "^\\$string:", ResType::STRING },
{ "^\\$pattern:", ResType::PATTERN },
{ "^\\$plural:", ResType::PLURAL },
{ "^\\$theme:", ResType::THEME }
{ "^\\$theme:", ResType::THEME },
{ "^\\$symbol:", ResType::SYMBOL }
};
const map<string, ResType> ReferenceParser::ID_OHOS_REFS = {
@@ -48,7 +49,8 @@ const map<string, ResType> ReferenceParser::ID_OHOS_REFS = {
{ "^\\$ohos:string:", ResType::STRING },
{ "^\\$ohos:pattern:", ResType::PATTERN },
{ "^\\$ohos:plural:", ResType::PLURAL },
{ "^\\$ohos:theme:", ResType::THEME }
{ "^\\$ohos:theme:", ResType::THEME },
{ "^\\$ohos:symbol:", ResType::SYMBOL }
};
ReferenceParser::ReferenceParser() : idWorker_(IdWorker::GetInstance())
@@ -197,7 +199,8 @@ bool ReferenceParser::IsStringOfResourceItem(ResType resType) const
resType == ResType::INTEGER ||
resType == ResType::BOOLEAN ||
resType == ResType::COLOR ||
resType == ResType::FLOAT) {
resType == ResType::FLOAT ||
resType == ResType::SYMBOL) {
return true;
}
return false;
+5
View File
@@ -423,6 +423,11 @@ uint32_t ResourceUtil::GetNormalSize(const vector<KeyParam> &keyParams, uint32_t
return g_normalIconMap.find(dpi + "-" + device)->second[index];
}
bool ResourceUtil::isUnicodeInPlane15or16(int unicode)
{
return (unicode >= 0xF0000 && unicode <= 0xFFFFF) || (unicode >= 0x100000 && unicode <= 0x10FFFF);
}
}
}
}