1// Copyright 2016 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// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "core/fxge/cfx_gemodule.h"
8
9#include "core/fxge/cfx_fontcache.h"
10#include "core/fxge/cfx_fontmgr.h"
11#include "core/fxge/ge/cfx_folderfontinfo.h"
12#include "core/fxge/ge/fx_text_int.h"
13
14namespace {
15
16CFX_GEModule* g_pGEModule = nullptr;
17
18}  // namespace
19
20CFX_GEModule::CFX_GEModule()
21    : m_FTLibrary(nullptr),
22      m_pFontCache(nullptr),
23      m_pFontMgr(new CFX_FontMgr),
24      m_pCodecModule(nullptr),
25      m_pPlatformData(nullptr),
26      m_pUserFontPaths(nullptr) {}
27
28CFX_GEModule::~CFX_GEModule() {
29  delete m_pFontCache;
30  DestroyPlatform();
31}
32
33// static
34CFX_GEModule* CFX_GEModule::Get() {
35  if (!g_pGEModule)
36    g_pGEModule = new CFX_GEModule();
37  return g_pGEModule;
38}
39
40// static
41void CFX_GEModule::Destroy() {
42  ASSERT(g_pGEModule);
43  delete g_pGEModule;
44  g_pGEModule = nullptr;
45}
46
47void CFX_GEModule::Init(const char** userFontPaths,
48                        CCodec_ModuleMgr* pCodecModule) {
49  ASSERT(g_pGEModule);
50  m_pCodecModule = pCodecModule;
51  m_pUserFontPaths = userFontPaths;
52  InitPlatform();
53  SetTextGamma(2.2f);
54}
55
56CFX_FontCache* CFX_GEModule::GetFontCache() {
57  if (!m_pFontCache)
58    m_pFontCache = new CFX_FontCache();
59  return m_pFontCache;
60}
61
62void CFX_GEModule::SetTextGamma(FX_FLOAT gammaValue) {
63  gammaValue /= 2.2f;
64  for (int i = 0; i < 256; ++i) {
65    m_GammaValue[i] = static_cast<uint8_t>(
66        FXSYS_pow(static_cast<FX_FLOAT>(i) / 255, gammaValue) * 255.0f + 0.5f);
67  }
68}
69
70const uint8_t* CFX_GEModule::GetTextGammaTable() const {
71  return m_GammaValue;
72}
73