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
embedder_test_environment.cpp
Go to the documentation of this file.
1// Copyright 2020 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 "testing/embedder_test_environment.h"
6
7#include <ostream>
8
9#include "core/fxcrt/fx_system.h"
10#include "public/fpdfview.h"
11#include "testing/command_line_helpers.h"
12#include "third_party/base/check.h"
13
14#ifdef PDF_ENABLE_V8
15#include "testing/v8_test_environment.h"
16#endif // PDF_ENABLE_V8
17
18namespace {
19
20EmbedderTestEnvironment* g_environment = nullptr;
21
22} // namespace
23
25 : renderer_type_(GetDefaultRendererType()) {
26 DCHECK(!g_environment);
27 g_environment = this;
28}
29
31 DCHECK(g_environment);
32 g_environment = nullptr;
33}
34
35// static
39
41 FPDF_LIBRARY_CONFIG config = {
42 .version = 4,
43 .m_pUserFontPaths = test_fonts_.font_paths(),
44
45#ifdef PDF_ENABLE_V8
46 .m_pIsolate = V8TestEnvironment::GetInstance()->isolate(),
47 .m_v8EmbedderSlot = 0,
48 .m_pPlatform = V8TestEnvironment::GetInstance()->platform(),
49#else // PDF_ENABLE_V8
50 .m_pIsolate = nullptr,
51 .m_v8EmbedderSlot = 0,
52 .m_pPlatform = nullptr,
53#endif // PDF_ENABLE_V8
54
55 .m_RendererType = renderer_type_,
56 };
57
59
60 test_fonts_.InstallFontMapper();
61}
62
66
67void EmbedderTestEnvironment::AddFlags(int argc, char** argv) {
68 for (int i = 1; i < argc; ++i)
69 AddFlag(argv[i]);
70}
71
72void EmbedderTestEnvironment::AddFlag(const std::string& flag) {
73 if (flag == "--write-pngs") {
74 write_pngs_ = true;
75 return;
76 }
77#if defined(PDF_USE_SKIA)
78 std::string value;
79 if (ParseSwitchKeyValue(flag, "--use-renderer=", &value)) {
80 if (value == "agg") {
81 renderer_type_ = FPDF_RENDERERTYPE_AGG;
82 } else if (value == "skia") {
83 renderer_type_ = FPDF_RENDERERTYPE_SKIA;
84 } else {
85 std::cerr << "Invalid --use-renderer argument, value must be one of agg "
86 "or skia\n";
87 }
88 return;
89 }
90#endif // defined(PDF_USE_SKIA)
91
92 std::cerr << "Unknown flag: " << flag << "\n";
93}
void AddFlags(int argc, char **argv)
static EmbedderTestEnvironment * GetInstance()
FPDF_RENDERER_TYPE GetDefaultRendererType()
FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyLibrary()
FPDF_EXPORT void FPDF_CALLCONV FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG *config)