1 /*
2  * Copyright (c) 2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_HTML_HTML_CONVERT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_HTML_HTML_CONVERT_H
18 
19 #include "core/components_ng/pattern/text/span/span_string.h"
20 namespace OHOS::Ace {
21 class SpanToHtml {
22 public:
23     static std::string ToHtml(const SpanString& spanString);
24     static std::string ToHtml(std::vector<uint8_t>& values);
25 
26 private:
27     static std::string NormalStyleToHtml(
28         const NG::FontStyle& fontStyle, const OHOS::Ace::NG::TextLineStyle& textLineStyle);
29     static std::string ImageToHtml(RefPtr<NG::SpanItem> item);
30     static std::string FontStyleToHtml(const std::optional<Ace::FontStyle>& value);
31     static std::string FontSizeToHtml(const std::optional<Dimension>& value);
32     static std::string FontWeightToHtml(const std::optional<FontWeight>& value);
33     static std::string ColorToHtml(const std::optional<Color>& value);
34     static std::string FontFamilyToHtml(const std::optional<std::vector<std::string>>& value);
35     static std::string TextDecorationToHtml(TextDecoration decoration);
36     static std::string TextDecorationStyleToHtml(TextDecorationStyle decorationStyle);
37     static std::string ToHtml(const std::string& key, const std::optional<Dimension>& value);
38     static std::string DeclarationToHtml(const NG::FontStyle& fontStyle);
39     static std::string ToHtml(const std::optional<std::vector<Shadow>>& shadows);
40     static std::string ToHtml(const std::string& key, const std::optional<CalcDimension>& dimesion);
41     static std::string ToHtml(const std::optional<ImageSpanSize>& size);
42     static std::string ToHtml(const std::optional<OHOS::Ace::TextAlign>& object);
43     static std::string ToHtml(const std::optional<OHOS::Ace::WordBreak>& object);
44     static std::string ToHtml(const std::optional<OHOS::Ace::TextOverflow>& object);
45     static std::string ToHtml(const std::optional<OHOS::Ace::NG::BorderRadiusProperty>& borderRadius);
46     static std::string ToHtml(const std::string& key, const std::optional<OHOS::Ace::NG::MarginProperty>& prop);
47     static std::string ToHtml(const std::optional<ImageFit>& objectFit);
48     static std::string ToHtml(const std::optional<VerticalAlign>& verticalAlign);
49     static std::string ParagraphStyleToHtml(const OHOS::Ace::NG::TextLineStyle& textLineStyle);
50     static std::string LeadingMarginToHtml(const OHOS::Ace::NG::TextLineStyle& style);
51     static int WriteLocalFile(RefPtr<PixelMap> pixelMap, std::string& filePath, std::string& fileUri);
52     static std::string ToHtmlImgSizeAttribute(const std::string& key, const std::optional<CalcDimension>& dimesion);
53 
54     static void ToHtmlColor(std::string& color);
55     static std::string DimensionToString(const Dimension& dimension);
56     static std::string DimensionToStringWithoutUnit(const Dimension& dimension);
ToHtmlStyleFormat(const std::string & key,const std::string & value)57     static std::string ToHtmlStyleFormat(const std::string& key, const std::string& value)
58     {
59         return key + std::string(": ") + value + ";";
60     }
61 
ToHtmlAttributeFormat(const std::string & key,const std::string & value)62     static std::string ToHtmlAttributeFormat(const std::string& key, const std::string& value)
63     {
64         return key + "=\"" + value + "\" ";
65     }
66 
67     static bool CreateDirectory(const std::string& path);
68 };
69 }; // namespace OHOS::Ace
70 #endif