1 /* 2 * Copyright (c) 2023 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 <texgine/system_font_provider.h> 17 #include <texgine/typography_builder.h> 18 19 #include "feature_test_framework.h" 20 21 using namespace OHOS::Rosen::TextEngine; 22 23 namespace { 24 struct Info { 25 std::string span; 26 TextStyle style; 27 } g_infos[] = { 28 { 29 .span = " hello", 30 .style = { 31 .fontSize = 16, 32 .decoration = TextDecoration::BASELINE, 33 }, 34 }, 35 { 36 .span = " world", 37 .style = { 38 .fontSize = 32, 39 .decoration = TextDecoration::BASELINE, 40 }, 41 }, 42 { 43 .span = " hello", 44 .style = { 45 .fontSize = 64, 46 .decoration = TextDecoration::BASELINE, 47 }, 48 }, 49 { 50 .span = " world", 51 .style = { 52 .fontSize = 32, 53 .decoration = TextDecoration::BASELINE, 54 }, 55 }, 56 { 57 .span = " HELLO", 58 .style = { 59 .fontSize = 16, 60 .decoration = TextDecoration::BASELINE, 61 }, 62 }, 63 }; 64 65 struct StyleData { 66 TextRectHeightStyle heightstyle; 67 TextRectWidthStyle widthstyle; 68 std::string title; 69 } g_styleDatas [] = { 70 { 71 .heightstyle = TextRectHeightStyle::TIGHT, 72 .widthstyle = TextRectWidthStyle::TIGHT, 73 .title = "字体大小不同,最终的布局显示基线位置相同", 74 }, 75 { 76 .heightstyle = TextRectHeightStyle::COVER_TOP_AND_BOTTOM, 77 .widthstyle = TextRectWidthStyle::TIGHT, 78 .title = "复现MaxHeight现象", 79 } 80 }; 81 82 class CalibratePositionTest : public TestFeature { 83 public: CalibratePositionTest()84 CalibratePositionTest() : TestFeature("CalibratePositionTest") 85 { 86 } 87 Layout()88 void Layout() 89 { 90 option_.needRainbowChar = true; 91 92 auto builder = TypographyBuilder::Create(); 93 for (const auto &[span, style] : g_infos) { 94 builder->PushStyle(style); 95 builder->AppendSpan(span); 96 builder->PopStyle(); 97 } 98 99 auto typography = builder->Build(); 100 double widthLimit = 300.0; 101 typography->Layout(widthLimit); 102 103 for (const auto &style : g_styleDatas) { 104 typographies_.push_back({ 105 .typography = typography, 106 .comment = style.title, 107 .ws = style.widthstyle, 108 .hs = style.heightstyle, 109 }); 110 } 111 } 112 } g_test; 113 } // namespace 114