From 126922a5711d91b605a6158246daf6ffbba4df33 Mon Sep 17 00:00:00 2001 From: w200200 Date: Thu, 13 Apr 2023 09:51:15 +0800 Subject: [PATCH 1/2] Replace libtxt: add adapter 1 Change-Id: Ib6fbcc9fc332513d4d8a78abed1efd9d44c06d8d Signed-off-by: w200200 --- .../rosen_text/adapter/common/text_style.cpp | 102 ++++++++++++++++++ .../adapter/common/typography_style.cpp | 59 ++++++++++ 2 files changed, 161 insertions(+) create mode 100644 rosen/modules/2d_engine/rosen_text/adapter/common/text_style.cpp create mode 100644 rosen/modules/2d_engine/rosen_text/adapter/common/typography_style.cpp diff --git a/rosen/modules/2d_engine/rosen_text/adapter/common/text_style.cpp b/rosen/modules/2d_engine/rosen_text/adapter/common/text_style.cpp new file mode 100644 index 0000000000..c65a75766c --- /dev/null +++ b/rosen/modules/2d_engine/rosen_text/adapter/common/text_style.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rosen_text/text_style.h" + +#include + +namespace OHOS { +namespace Rosen { +void FontFeatures::SetFeature(std::string tag, int value) +{ + featureMap_[tag] = value; +} + +std::string FontFeatures::GetFeatureSettings() const +{ + if (featureMap_.empty()) { + return ""; + } + + std::stringstream ss; + for (const auto &[tag, value] : featureMap_) { + if (ss.tellp()) { + ss << ','; + } + ss << tag << '=' << value; + } + return ss.str(); +} + +const std::map &FontFeatures::GetFontFeatures() const +{ + return featureMap_; +} + +bool FontFeatures::operator ==(const FontFeatures& rhs) const +{ + return featureMap_ == rhs.featureMap_; +} + +TextShadow::TextShadow() +{ +} + +TextShadow::TextShadow(Drawing::Color color, Drawing::Point offset, double blurRadius) +{ + color_ = color; + offset_ = offset; + blurRadius_ = blurRadius; +} + +bool TextShadow::operator ==(const TextShadow& rhs) const +{ + return color_ == rhs.color_ && offset_ == rhs.offset_ && blurRadius_ == rhs.blurRadius_; +} + +bool TextShadow::operator !=(const TextShadow& rhs) const +{ + return !(*this == rhs); +} + +bool TextShadow::HasShadow() const +{ + return offset_.GetX() != 0 || offset_.GetY() != 0 || blurRadius_ != 0.0; +} + +bool TextStyle::operator ==(const TextStyle &rhs) const +{ + return color_ == rhs.color_ && + decoration_ == rhs.decoration_ && + decorationColor_ == rhs.decorationColor_ && + decorationStyle_ == rhs.decorationStyle_ && + decorationThicknessScale_ == rhs.decorationThicknessScale_ && + fontWeight_ == rhs.fontWeight_ && + fontStyle_ == rhs.fontStyle_ && + baseline_ == rhs.baseline_ && + fontFamilies_ == rhs.fontFamilies_ && + fontSize_ == rhs.fontSize_ && + letterSpacing_ == rhs.letterSpacing_ && + wordSpacing_ == rhs.wordSpacing_ && + heightScale_ == rhs.heightScale_ && + heightOnly_ == rhs.heightOnly_ && + locale_ == rhs.locale_ && + background_ == rhs.background_ && + foreground_ == rhs.foreground_ && + shadows_ == rhs.shadows_ && + fontFeatures_ == rhs.fontFeatures_; +} +} // namespace Rosen +} // namespace OHOS diff --git a/rosen/modules/2d_engine/rosen_text/adapter/common/typography_style.cpp b/rosen/modules/2d_engine/rosen_text/adapter/common/typography_style.cpp new file mode 100644 index 0000000000..ae22e7d691 --- /dev/null +++ b/rosen/modules/2d_engine/rosen_text/adapter/common/typography_style.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rosen_text/typography_style.h" + +namespace OHOS { +namespace Rosen { +TextStyle TypographyStyle::GetTextStyle() const +{ + TextStyle style = { + .fontWeight_ = fontWeight_, + .fontStyle_ = fontStyle_, + .fontFamilies_ = { fontFamily_ }, + .fontSize_ = fontSize_, + .heightScale_ = heightScale_, + .heightOnly_ = heightOnly_, + .locale_ = locale_, + }; + if (fontSize_ >= 0) { + style.fontSize_ = fontSize_; + } + + return style; +} + +TextAlign TypographyStyle::GetEffectiveAlign() const +{ + if (textAlign_ == TextAlign::START) { + return (textDirection_ == TextDirection::LTR) ? TextAlign::LEFT : TextAlign::RIGHT; + } else if (textAlign_ == TextAlign::END) { + return (textDirection_ == TextDirection::RTL) ? TextAlign::LEFT : TextAlign::RIGHT; + } else { + return textAlign_; + } +} + +bool TypographyStyle::IsUnlimitedLines() const +{ + return maxLines_ == 1e9; +} + +bool TypographyStyle::IsEllipsized() const +{ + return !ellipsis_.empty(); +} +} // namespace Rosen +} // namespace OHOS -- Gitee From 4517e8c5e96db681a3741eea18bfb5d9bed7c935 Mon Sep 17 00:00:00 2001 From: w200200 Date: Fri, 14 Apr 2023 17:12:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I452344ff87289a104c8ec05a7c90b1a026ec90b7 Signed-off-by: w200200 --- .../2d_engine/rosen_text/adapter/common/text_style.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rosen/modules/2d_engine/rosen_text/adapter/common/text_style.cpp b/rosen/modules/2d_engine/rosen_text/adapter/common/text_style.cpp index c65a75766c..6f751f7236 100644 --- a/rosen/modules/2d_engine/rosen_text/adapter/common/text_style.cpp +++ b/rosen/modules/2d_engine/rosen_text/adapter/common/text_style.cpp @@ -40,7 +40,7 @@ std::string FontFeatures::GetFeatureSettings() const return ss.str(); } -const std::map &FontFeatures::GetFontFeatures() const +const std::map& FontFeatures::GetFontFeatures() const { return featureMap_; } @@ -76,7 +76,7 @@ bool TextShadow::HasShadow() const return offset_.GetX() != 0 || offset_.GetY() != 0 || blurRadius_ != 0.0; } -bool TextStyle::operator ==(const TextStyle &rhs) const +bool TextStyle::operator ==(const TextStyle& rhs) const { return color_ == rhs.color_ && decoration_ == rhs.decoration_ && -- Gitee