1 // Copyright 2014 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 "../../../include/fxge/fx_ge.h"
8 #include "text_int.h"
9 static CFX_GEModule* g_pGEModule = NULL;
CFX_GEModule()10 CFX_GEModule::CFX_GEModule()
11 {
12     m_pFontCache = NULL;
13     m_pFontMgr = NULL;
14     m_FTLibrary = NULL;
15     m_pCodecModule = NULL;
16     m_pPlatformData = NULL;
17 }
~CFX_GEModule()18 CFX_GEModule::~CFX_GEModule()
19 {
20     if (m_pFontCache) {
21         delete m_pFontCache;
22     }
23     m_pFontCache = NULL;
24     if (m_pFontMgr) {
25         delete m_pFontMgr;
26     }
27     m_pFontMgr = NULL;
28     DestroyPlatform();
29 }
Get()30 CFX_GEModule* CFX_GEModule::Get()
31 {
32     return g_pGEModule;
33 }
Create()34 void CFX_GEModule::Create()
35 {
36     g_pGEModule = new CFX_GEModule;
37     g_pGEModule->m_pFontMgr = new CFX_FontMgr;
38     g_pGEModule->InitPlatform();
39     g_pGEModule->SetTextGamma(2.2f);
40 }
Use(CFX_GEModule * pModule)41 void CFX_GEModule::Use(CFX_GEModule* pModule)
42 {
43     g_pGEModule = pModule;
44 }
Destroy()45 void CFX_GEModule::Destroy()
46 {
47     if (g_pGEModule) {
48         delete g_pGEModule;
49     }
50     g_pGEModule = NULL;
51 }
GetFontCache()52 CFX_FontCache* CFX_GEModule::GetFontCache()
53 {
54     if (m_pFontCache == NULL) {
55         m_pFontCache = new CFX_FontCache();
56     }
57     return m_pFontCache;
58 }
SetTextGamma(FX_FLOAT gammaValue)59 void CFX_GEModule::SetTextGamma(FX_FLOAT gammaValue)
60 {
61     gammaValue /= 2.2f;
62     int i = 0;
63     while (i < 256) {
64         m_GammaValue[i] = (FX_BYTE)(FXSYS_pow((FX_FLOAT)i / 255, gammaValue) * 255.0f + 0.5f);
65         i++;
66     }
67 }
GetTextGammaTable()68 FX_LPCBYTE CFX_GEModule::GetTextGammaTable()
69 {
70     return m_GammaValue;
71 }
SetExtFontMapper(IFX_FontMapper * pFontMapper)72 void CFX_GEModule::SetExtFontMapper(IFX_FontMapper* pFontMapper)
73 {
74     GetFontMgr()->m_pExtMapper = pFontMapper;
75     pFontMapper->m_pFontMgr = m_pFontMgr;
76 }
77