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 constexpr auto EXAMPLE_TEXT = "宽度限制过小导致省略号填充的bug"; 25 26 struct WidthInfo { 27 double widthLimit = 0; 28 std::string title = ""; 29 } g_infos[] = { 30 { 31 .widthLimit = 400, 32 .title = "宽度限制可以容纳整个文本", 33 }, 34 { 35 .widthLimit = 50, 36 .title = "容纳部分文本", 37 }, 38 { 39 .widthLimit = 5, 40 .title = "小于一个字符的宽度", 41 }, 42 }; 43 44 class EllipsisBug1 : public TestFeature { 45 public: EllipsisBug1()46 EllipsisBug1() : TestFeature("EllipsisBug1") 47 { 48 } 49 Layout()50 void Layout() 51 { 52 for (auto &info : g_infos) { 53 TypographyStyle ys = { .maxLines = 1, .ellipsis = u"..." }; 54 55 auto builder = TypographyBuilder::Create(ys); 56 TextStyle tstyle; 57 builder->PushStyle(tstyle); 58 builder->AppendSpan(EXAMPLE_TEXT); 59 auto typography = builder->Build(); 60 typography->Layout(info.widthLimit); 61 62 typographies_.push_back({ 63 .typography = typography, 64 .comment = info.title, 65 }); 66 } 67 } 68 } g_test; 69 } // namespace 70