1 // Copyright 2018 The 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 <cstdint>
6 
7 #include "core/fxcrt/widestring.h"
8 #include "core/fxge/cfx_font.h"
9 #include "core/fxge/fx_font.h"
10 #include "third_party/base/ptr_util.h"
11 #include "xfa/fgas/font/cfgas_fontmgr.h"
12 #include "xfa/fgas/font/cfgas_gefont.h"
13 #include "xfa/fgas/layout/cfx_char.h"
14 #include "xfa/fgas/layout/cfx_rtfbreak.h"
15 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
17   auto fontmgr = pdfium::MakeUnique<CFGAS_FontMgr>();
18 
19   auto font = pdfium::MakeUnique<CFX_Font>();
20   font->LoadSubst("Arial", true, 0, FXFONT_FW_NORMAL, 0, 0, 0);
21   assert(font);
22 
23   CFX_RTFBreak rtf_break(FX_LAYOUTSTYLE_ExpandTab);
24   rtf_break.SetLineBreakTolerance(1);
25   rtf_break.SetFont(CFGAS_GEFont::LoadFont(std::move(font), fontmgr.get()));
26   rtf_break.SetFontSize(12);
27 
28   WideString input =
29       WideString::FromUTF16LE(reinterpret_cast<const unsigned short*>(data),
30                               size / sizeof(unsigned short));
31   for (wchar_t ch : input)
32     rtf_break.AppendChar(ch);
33 
34   std::vector<CFX_Char> chars =
35       rtf_break.GetCurrentLineForTesting()->m_LineChars;
36   CFX_Char::BidiLine(&chars, chars.size());
37   return 0;
38 }
39