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 <sstream> 17 18 #include <texgine/dynamic_file_font_provider.h> 19 #include <texgine/system_font_provider.h> 20 #include <texgine/typography_builder.h> 21 22 #include "feature_test_framework.h" 23 #include "text_define.h" 24 25 using namespace OHOS::Rosen::TextEngine; 26 27 namespace { 28 constexpr auto EXAMPLE_TEXT = "hello" WATCH PERSON " wolrd تحول " WOMAN_SPORT_VARIANT 29 " كبير! hello 123 آخر الأخبار من محطة سكة حديد شيان هنا!" WATCH; 30 31 class DirectionTest : public TestFeature { 32 public: DirectionTest()33 DirectionTest() : TestFeature("DirectionTest") 34 { 35 } 36 Layout()37 void Layout() 38 { 39 for (const auto &dir : {TextDirection::LTR, TextDirection::RTL}) { 40 TypographyStyle tystyle = { 41 .direction = dir, 42 }; 43 44 auto dfProvider = DynamicFileFontProvider::Create(); 45 dfProvider->LoadFont("Segoe UI Emoji", RESOURCE_PATH_PREFIX "seguiemj.ttf"); 46 auto fps = FontProviders::Create(); 47 fps->AppendFontProvider(dfProvider); 48 fps->AppendFontProvider(SystemFontProvider::GetInstance()); 49 auto builder = TypographyBuilder::Create(tystyle, std::move(fps)); 50 51 TextStyle style = { 52 .fontFamilies = {"Segoe UI Emoji"}, 53 .fontSize = 24, 54 }; 55 56 builder->PushStyle(style); 57 builder->AppendSpan(EXAMPLE_TEXT); 58 builder->PopStyle(); 59 60 std::stringstream ss; 61 ss << "typography direction: " << (dir == TextDirection::LTR ? "LTR" : "RTL"); 62 63 auto typography = builder->Build(); 64 double widthLimit = 600.0; 65 typography->Layout(widthLimit); 66 typographies_.push_back({ 67 .typography = typography, 68 .comment = ss.str(), 69 }); 70 } 71 } 72 } g_test; 73 } // namespace 74