1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "frameworks/bridge/common/manifest/manifest_window.h"
17
18 #include <regex>
19 #include "core/common/resource/resource_manager.h"
20
21 namespace OHOS::Ace::Framework {
22
WindowParse(const std::unique_ptr<JsonValue> & root)23 void ManifestWindow::WindowParse(const std::unique_ptr<JsonValue>& root)
24 {
25 if (!root) {
26 LOGE("the root manifest is nullptr");
27 return;
28 }
29 auto window = root->GetObject("window");
30 if (!window || window->IsNull()) {
31 return;
32 }
33 int32_t designWidth = 0;
34 auto designWidthValue = window->GetValue("designWidth");
35 if (designWidthValue->IsNumber()) {
36 designWidth = designWidthValue->GetInt();
37 } else if (designWidthValue->IsString()) {
38 std::string designString = window->GetString("designWidth");
39 std::regex reg("\\$(\\S+):(\\S+)");
40 std::smatch results;
41
42 auto resourceObject = AceType::MakeRefPtr<Ace::ResourceObject>("", "");
43 auto resourceAdapter = ResourceManager::GetInstance().GetOrCreateResourceAdapter(resourceObject);
44 if (std::regex_match(designString, results, reg) && resourceAdapter) {
45 designWidth = resourceAdapter->GetInt(StringUtils::StringToInt(results[2].str()));
46 }
47 }
48 if (designWidth <= 0) {
49 LOGW("[designWidth] of [window] in main_pages.json set error. use default value: %{public}d",
50 DEFAULT_DESIGN_WIDTH);
51 designWidth = DEFAULT_DESIGN_WIDTH;
52 }
53 windowConfig_.designWidth = designWidth;
54 windowConfig_.autoDesignWidth = window->GetBool("autoDesignWidth", false);
55 }
56
PrintInfo()57 void ManifestWindow::PrintInfo() {}
58
59 } // namespace OHOS::Ace::Framework
60