• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The PDFium Authors
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/cfgas_txtbreak.h"
6 
7 #include <memory>
8 #include <utility>
9 
10 #include "core/fxcrt/fx_codepage.h"
11 #include "core/fxge/cfx_font.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "xfa/fgas/font/cfgas_fontmgr.h"
14 #include "xfa/fgas/font/cfgas_gefont.h"
15 #include "xfa/fgas/layout/cfgas_char.h"
16 
17 class CFGASTxtBreakTest : public testing::Test {
18  public:
SetUp()19   void SetUp() override {
20     const wchar_t kFontFamily[] = L"Arimo Bold";
21     font_ = CFGAS_GEFont::LoadFont(kFontFamily, 0, FX_CodePage::kDefANSI);
22     ASSERT_TRUE(font_);
23   }
24 
CreateBreak()25   std::unique_ptr<CFGAS_TxtBreak> CreateBreak() {
26     auto txt_break = std::make_unique<CFGAS_TxtBreak>();
27     txt_break->SetFont(font_);
28     return txt_break;
29   }
30 
31  private:
32   RetainPtr<CFGAS_GEFont> font_;
33 };
34 
TEST_F(CFGASTxtBreakTest,BidiLine)35 TEST_F(CFGASTxtBreakTest, BidiLine) {
36   auto txt_break = CreateBreak();
37   txt_break->SetLineBreakTolerance(1);
38   txt_break->SetFontSize(12);
39 
40   // SAFETY: known fixed-length string.
41   WideString input =
42       WideString::FromUTF8(UNSAFE_BUFFERS(ByteStringView("\xa\x0\xa\xa", 4)));
43   for (wchar_t ch : input)
44     txt_break->AppendChar(ch);
45 
46   std::vector<CFGAS_Char> chars =
47       txt_break->GetCurrentLineForTesting()->m_LineChars;
48   CFGAS_Char::BidiLine(&chars, chars.size());
49   EXPECT_EQ(3u, chars.size());
50 }
51