• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "xfa/fgas/layout/cfx_txtbreak.h"
6 
7 #include <memory>
8 #include <utility>
9 
10 #include "core/fxge/cfx_font.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/xfa_unit_test_support.h"
13 #include "third_party/base/ptr_util.h"
14 #include "xfa/fgas/font/cfgas_fontmgr.h"
15 #include "xfa/fgas/font/cfgas_gefont.h"
16 #include "xfa/fgas/layout/cfx_char.h"
17 
18 class CFX_TxtBreakTest : public testing::Test {
19  public:
SetUp()20   void SetUp() override {
21     font_ =
22         CFGAS_GEFont::LoadFont(L"Arial Black", 0, 0, GetGlobalFontManager());
23     ASSERT_TRUE(font_.Get());
24   }
25 
CreateBreak()26   std::unique_ptr<CFX_TxtBreak> CreateBreak() {
27     auto txt_break = pdfium::MakeUnique<CFX_TxtBreak>();
28     txt_break->SetFont(font_);
29     return txt_break;
30   }
31 
32  private:
33   RetainPtr<CFGAS_GEFont> font_;
34 };
35 
TEST_F(CFX_TxtBreakTest,BidiLine)36 TEST_F(CFX_TxtBreakTest, BidiLine) {
37   auto txt_break = CreateBreak();
38   txt_break->SetLineBreakTolerance(1);
39   txt_break->SetFontSize(12);
40 
41   WideString input = WideString::FromUTF8(ByteStringView("\xa\x0\xa\xa", 4));
42   for (wchar_t ch : input)
43     txt_break->AppendChar(ch);
44 
45   std::vector<CFX_Char> chars =
46       txt_break->GetCurrentLineForTesting()->m_LineChars;
47   CFX_Char::BidiLine(&chars, chars.size());
48   EXPECT_EQ(3u, chars.size());
49 }
50