Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfgas_rtfbreak_unittest.cpp
Go to the documentation of this file.
1// Copyright 2017 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// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "xfa/fgas/layout/cfgas_rtfbreak.h"
8
9#include <memory>
10#include <utility>
11
12#include "core/fxcrt/fx_codepage.h"
13#include "core/fxge/cfx_font.h"
14#include "core/fxge/cfx_gemodule.h"
15#include "testing/gtest/include/gtest/gtest.h"
16#include "xfa/fgas/font/cfgas_fontmgr.h"
17#include "xfa/fgas/font/cfgas_gefont.h"
18#include "xfa/fgas/layout/cfgas_char.h"
19
21 public:
22 void SetUp() override {
23 const wchar_t kFontFamily[] = L"Arimo Bold";
24 font_ = CFGAS_GEFont::LoadFont(kFontFamily, 0, FX_CodePage::kDefANSI);
25 ASSERT_TRUE(font_);
26 }
27
29 Mask<CFGAS_Break::LayoutStyle> layout_styles) {
30 auto rtf_break = std::make_unique<CFGAS_RTFBreak>(layout_styles);
31 rtf_break->SetFont(font_);
32 return rtf_break;
33 }
34
35 private:
36 RetainPtr<CFGAS_GEFont> font_;
37};
38
39// As soon as you get one of the control characters the break is complete
40// and must be consumed before you get any more characters ....
41
43 auto rtf_break = CreateBreak(CFGAS_Break::LayoutStyle::kExpandTab);
44 WideString str(L"Input String.");
45 for (wchar_t ch : str)
46 EXPECT_EQ(CFGAS_Char::BreakType::kNone, rtf_break->AppendChar(ch));
47
48 EXPECT_EQ(CFGAS_Char::BreakType::kParagraph, rtf_break->AppendChar(L'\n'));
49 ASSERT_EQ(1, rtf_break->CountBreakPieces());
50 EXPECT_EQ(str + L"\n", rtf_break->GetBreakPieceUnstable(0)->GetString());
51
52 rtf_break->ClearBreakPieces();
53 rtf_break->Reset();
54 EXPECT_EQ(0, rtf_break->GetCurrentLineForTesting()->GetLineEnd());
55
56 str = L"Second str.";
57 for (wchar_t ch : str)
58 EXPECT_EQ(CFGAS_Char::BreakType::kNone, rtf_break->AppendChar(ch));
59
60 // Force the end of the break at the end of the string.
61 rtf_break->EndBreak(CFGAS_Char::BreakType::kParagraph);
62 ASSERT_EQ(1, rtf_break->CountBreakPieces());
63 EXPECT_EQ(str, rtf_break->GetBreakPieceUnstable(0)->GetString());
64}
65
67 auto rtf_break = CreateBreak(CFGAS_Break::LayoutStyle::kExpandTab);
68 EXPECT_EQ(CFGAS_Char::BreakType::kLine, rtf_break->AppendChar(L'\v'));
69 EXPECT_EQ(CFGAS_Char::BreakType::kPage, rtf_break->AppendChar(L'\f'));
71 rtf_break->AppendChar(pdfium::unicode::kParagraphSeparator));
72 EXPECT_EQ(CFGAS_Char::BreakType::kParagraph, rtf_break->AppendChar(L'\n'));
73
74 ASSERT_EQ(1, rtf_break->CountBreakPieces());
75 EXPECT_EQ(L"\v", rtf_break->GetBreakPieceUnstable(0)->GetString());
76}
77
79 auto rtf_break = CreateBreak(CFGAS_Break::LayoutStyle::kExpandTab);
80 rtf_break->SetLineBreakTolerance(1);
81 rtf_break->SetFontSize(12);
82
83 WideString input = WideString::FromUTF8(ByteStringView("\xa\x0\xa\xa", 4));
84 for (wchar_t ch : input)
85 rtf_break->AppendChar(ch);
86
87 std::vector<CFGAS_Char> chars =
88 rtf_break->GetCurrentLineForTesting()->m_LineChars;
89 CFGAS_Char::BidiLine(&chars, chars.size());
90 EXPECT_EQ(3u, chars.size());
91}
TEST_F(CFGAS_RTFBreakTest, AddChars)
std::unique_ptr< CFGAS_RTFBreak > CreateBreak(Mask< CFGAS_Break::LayoutStyle > layout_styles)
static WideString FromUTF8(ByteStringView str)
WideString(const wchar_t *ptr)
WideString & operator=(const wchar_t *str)
WideString operator+(const WideString &str1, const wchar_t *str2)
Definition widestring.h:278
constexpr wchar_t kParagraphSeparator
Definition fx_unicode.h:101