• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     static std::string ToHtml(const std::list<RefPtr<NG::SpanItem>>& spanItems);
26     static std::string ToHtmlForNormalType(const NG::FontStyle& fontStyle,
27         const NG::TextLineStyle& textLineStyle, const std::u16string& contentStr);
28 
29 private:
30     static std::string NormalStyleToHtml(
31         const NG::FontStyle& fontStyle, const OHOS::Ace::NG::TextLineStyle& textLineStyle);
32     static std::string ImageToHtml(RefPtr<NG::SpanItem> item);
33     static std::string FontStyleToHtml(const std::optional<Ace::FontStyle>& value);
34     static std::string FontSizeToHtml(const std::optional<Dimension>& value);
35     static std::string FontWeightToHtml(const std::optional<FontWeight>& value);
36     static std::string ColorToHtml(const std::optional<Color>& value);
37     static std::string StrokeWidthToHtml(const std::optional<Dimension>& value);
38     static std::string StrokeColorToHtml(const std::optional<Color>& value);
39     static std::string FontSuperscriptToHtml(const std::optional<SuperscriptStyle>& value);
40     static std::string FontFamilyToHtml(const std::optional<std::vector<std::string>>& value);
41     static std::string TextDecorationToHtml(const std::vector<TextDecoration>& decoration);
42     static std::string TextDecorationStyleToHtml(TextDecorationStyle decorationStyle);
43     static std::string ToHtml(const std::string& key, const std::optional<Dimension>& value);
44     static std::string DecorationToHtml(const NG::FontStyle& fontStyle);
45     static std::string ToHtml(const std::optional<std::vector<Shadow>>& shadows);
46     static std::string ToHtml(const std::string& key, const std::optional<CalcDimension>& dimesion);
47     static std::string ToHtml(const std::optional<ImageSpanSize>& size);
48     static std::string ToHtml(const std::optional<OHOS::Ace::TextAlign>& object);
49     static std::string ToHtml(const std::optional<OHOS::Ace::TextVerticalAlign>& object);
50     static std::string ToHtml(const std::optional<OHOS::Ace::WordBreak>& object);
51     static std::string ToHtml(const std::optional<OHOS::Ace::TextOverflow>& object);
52     static std::string ToHtml(const std::optional<OHOS::Ace::NG::BorderRadiusProperty>& borderRadius);
53     static std::string ToHtml(const std::string& key, const std::optional<OHOS::Ace::NG::MarginProperty>& prop);
54     static std::string ToHtml(const std::optional<ImageFit>& objectFit);
55     static std::string ToHtml(const std::optional<VerticalAlign>& verticalAlign);
56     static std::string ToHtml(const std::string& key, bool syncLoad);
57     static std::string ParagraphStyleToHtml(const OHOS::Ace::NG::TextLineStyle& textLineStyle);
58     static std::string LeadingMarginToHtml(const OHOS::Ace::NG::TextLineStyle& style);
59     static int WriteLocalFile(RefPtr<PixelMap> pixelMap, std::string& filePath, std::string& fileUri);
60     static std::string ToHtmlImgSizeAttribute(const std::string& key, const std::optional<CalcDimension>& dimesion);
61 
62     static void ToHtmlColor(std::string& color);
63     static std::string DimensionToString(const Dimension& dimension);
64     static std::string DimensionToStringWithoutUnit(const Dimension& dimension);
ToHtmlStyleFormat(const std::string & key,const std::string & value)65     static std::string ToHtmlStyleFormat(const std::string& key, const std::string& value)
66     {
67         return key + std::string(": ") + value + ";";
68     }
69 
ToHtmlAttributeFormat(const std::string & key,const std::string & value)70     static std::string ToHtmlAttributeFormat(const std::string& key, const std::string& value)
71     {
72         return key + "=\"" + value + "\" ";
73     }
74 
75     static bool CreateDirectory(const std::string& path);
76     static void HandleSingleSpanItemHtml(const RefPtr<NG::SpanItem>& item, std::string& out,
77         size_t& paragrapStart, bool& newLine);
78     static std::string BackgroundColorToHtml(const std::optional<TextBackgroundStyle>& value);
79     static std::string NormalStyleToHtml(const RefPtr<NG::SpanItem>& item);
80     static std::string WrapWithAnchorIfNeeded(const RefPtr<NG::SpanItem>& item, const std::string& content);
81 };
82 }; // namespace OHOS::Ace
83 #endif