John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | 95e854f | 2015-06-13 00:58:06 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 7 | #include <memory> |
Tom Sepez | a0a6923 | 2017-05-01 11:39:33 -0700 | [diff] [blame] | 8 | #include <utility> |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 9 | |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 10 | #include "core/fxcrt/fx_codepage.h" |
Dan Sinclair | 92e2276 | 2017-07-10 15:14:26 -0400 | [diff] [blame] | 11 | #include "core/fxge/cfx_folderfontinfo.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 12 | #include "core/fxge/cfx_gemodule.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 13 | #include "core/fxge/ifx_systemfontinfo.h" |
Tom Sepez | a0a6923 | 2017-05-01 11:39:33 -0700 | [diff] [blame] | 14 | #include "third_party/base/ptr_util.h" |
Tom Sepez | b7d358b | 2015-06-17 10:01:00 -0700 | [diff] [blame] | 15 | |
John Abd-El-Malek | 207299b | 2014-12-15 12:13:45 -0800 | [diff] [blame] | 16 | #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 17 | namespace { |
| 18 | |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 19 | const size_t kLinuxGpNameSize = 6; |
| 20 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 21 | const char* const g_LinuxGpFontList[][kLinuxGpNameSize] = { |
npm | c6833c2 | 2016-08-12 10:29:31 -0700 | [diff] [blame] | 22 | {"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic", |
| 23 | "VL Gothic regular"}, |
| 24 | {"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", nullptr, |
| 25 | "VL Gothic regular"}, |
| 26 | {"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", nullptr, |
| 27 | "VL Gothic regular"}, |
| 28 | {"TakaoMincho", "IPAMincho", "VL Gothic", "Kochi Mincho", nullptr, |
| 29 | "VL Gothic regular"}, |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | }; |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 31 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 32 | const char* const g_LinuxGbFontList[] = { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | "AR PL UMing CN Light", "WenQuanYi Micro Hei", "AR PL UKai CN", |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | }; |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 35 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 36 | const char* const g_LinuxB5FontList[] = { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 37 | "AR PL UMing TW Light", "WenQuanYi Micro Hei", "AR PL UKai TW", |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | }; |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 39 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 40 | const char* const g_LinuxHGFontList[] = { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 41 | "UnDotum", |
| 42 | }; |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 43 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 44 | size_t GetJapanesePreference(const char* facearr, |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 45 | int weight, |
| 46 | int pitch_family) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | CFX_ByteString face = facearr; |
Ryan Harrison | da129ab | 2017-08-01 15:16:59 -0400 | [diff] [blame] | 48 | if (face.Find("Gothic") != FX_STRNPOS || |
| 49 | face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e") != FX_STRNPOS) { |
| 50 | if (face.Find("PGothic") != FX_STRNPOS || |
| 51 | face.Find("\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e") != FX_STRNPOS) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | return 0; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 53 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 54 | return 1; |
| 55 | } |
Ryan Harrison | da129ab | 2017-08-01 15:16:59 -0400 | [diff] [blame] | 56 | if (face.Find("Mincho") != FX_STRNPOS || |
| 57 | face.Find("\x96\xbe\x92\xa9") != FX_STRNPOS) { |
| 58 | if (face.Find("PMincho") != FX_STRNPOS || |
| 59 | face.Find("\x82\x6f\x96\xbe\x92\xa9") != FX_STRNPOS) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | return 2; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 61 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | return 3; |
| 63 | } |
npm | 80ddd61 | 2016-11-28 11:27:14 -0800 | [diff] [blame] | 64 | if (!(pitch_family & FXFONT_FF_ROMAN) && weight > 400) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 65 | return 0; |
npm | 80ddd61 | 2016-11-28 11:27:14 -0800 | [diff] [blame] | 66 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | return 2; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | } |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 69 | |
npm | 80ddd61 | 2016-11-28 11:27:14 -0800 | [diff] [blame] | 70 | class CFX_LinuxFontInfo : public CFX_FolderFontInfo { |
| 71 | public: |
| 72 | CFX_LinuxFontInfo() {} |
| 73 | ~CFX_LinuxFontInfo() override {} |
| 74 | |
| 75 | void* MapFont(int weight, |
| 76 | bool bItalic, |
| 77 | int charset, |
| 78 | int pitch_family, |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 79 | const char* family, |
npm | 80ddd61 | 2016-11-28 11:27:14 -0800 | [diff] [blame] | 80 | int& iExact) override; |
| 81 | bool ParseFontCfg(const char** pUserPaths); |
| 82 | }; |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 83 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | void* CFX_LinuxFontInfo::MapFont(int weight, |
tsepez | 12f3e4a | 2016-11-02 15:17:29 -0700 | [diff] [blame] | 85 | bool bItalic, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | int charset, |
| 87 | int pitch_family, |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 88 | const char* cstr_face, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | int& iExact) { |
Tom Sepez | 563f7f8 | 2015-10-05 13:11:43 -0700 | [diff] [blame] | 90 | void* font = GetSubstFont(cstr_face); |
| 91 | if (font) { |
| 92 | iExact = 1; |
| 93 | return font; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | } |
tsepez | 12f3e4a | 2016-11-02 15:17:29 -0700 | [diff] [blame] | 95 | bool bCJK = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | switch (charset) { |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 97 | case FX_CHARSET_ShiftJIS: { |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 98 | size_t index = GetJapanesePreference(cstr_face, weight, pitch_family); |
| 99 | ASSERT(index < FX_ArraySize(g_LinuxGpFontList)); |
| 100 | for (size_t i = 0; i < kLinuxGpNameSize; i++) { |
npm | c6833c2 | 2016-08-12 10:29:31 -0700 | [diff] [blame] | 101 | auto it = m_FontList.find(g_LinuxGpFontList[index][i]); |
npm | 80ddd61 | 2016-11-28 11:27:14 -0800 | [diff] [blame] | 102 | if (it != m_FontList.end()) |
Tom Sepez | 2569483 | 2017-04-21 15:42:49 -0700 | [diff] [blame] | 103 | return it->second.get(); |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 104 | } |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 105 | break; |
| 106 | } |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 107 | case FX_CHARSET_ChineseSimplified: { |
Tom Sepez | 24e733e | 2015-10-16 14:18:50 -0700 | [diff] [blame] | 108 | for (size_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) { |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 109 | auto it = m_FontList.find(g_LinuxGbFontList[i]); |
npm | 80ddd61 | 2016-11-28 11:27:14 -0800 | [diff] [blame] | 110 | if (it != m_FontList.end()) |
Tom Sepez | 2569483 | 2017-04-21 15:42:49 -0700 | [diff] [blame] | 111 | return it->second.get(); |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 112 | } |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 113 | break; |
| 114 | } |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 115 | case FX_CHARSET_ChineseTraditional: { |
Tom Sepez | 24e733e | 2015-10-16 14:18:50 -0700 | [diff] [blame] | 116 | for (size_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) { |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 117 | auto it = m_FontList.find(g_LinuxB5FontList[i]); |
npm | 80ddd61 | 2016-11-28 11:27:14 -0800 | [diff] [blame] | 118 | if (it != m_FontList.end()) |
Tom Sepez | 2569483 | 2017-04-21 15:42:49 -0700 | [diff] [blame] | 119 | return it->second.get(); |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 120 | } |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 121 | break; |
| 122 | } |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 123 | case FX_CHARSET_Hangul: { |
Tom Sepez | 24e733e | 2015-10-16 14:18:50 -0700 | [diff] [blame] | 124 | for (size_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) { |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 125 | auto it = m_FontList.find(g_LinuxHGFontList[i]); |
npm | 80ddd61 | 2016-11-28 11:27:14 -0800 | [diff] [blame] | 126 | if (it != m_FontList.end()) |
Tom Sepez | 2569483 | 2017-04-21 15:42:49 -0700 | [diff] [blame] | 127 | return it->second.get(); |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 128 | } |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 129 | break; |
| 130 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 131 | default: |
tsepez | 12f3e4a | 2016-11-02 15:17:29 -0700 | [diff] [blame] | 132 | bCJK = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 133 | break; |
| 134 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK); |
| 136 | } |
thestig | 24508df | 2016-05-27 15:14:20 -0700 | [diff] [blame] | 137 | |
npm | 80ddd61 | 2016-11-28 11:27:14 -0800 | [diff] [blame] | 138 | bool CFX_LinuxFontInfo::ParseFontCfg(const char** pUserPaths) { |
| 139 | if (!pUserPaths) |
| 140 | return false; |
| 141 | |
| 142 | for (const char** pPath = pUserPaths; *pPath; ++pPath) |
| 143 | AddPath(*pPath); |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | } // namespace |
| 148 | |
thestig | 24508df | 2016-05-27 15:14:20 -0700 | [diff] [blame] | 149 | std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault( |
| 150 | const char** pUserPaths) { |
Tom Sepez | a0a6923 | 2017-05-01 11:39:33 -0700 | [diff] [blame] | 151 | auto pInfo = pdfium::MakeUnique<CFX_LinuxFontInfo>(); |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 152 | if (!pInfo->ParseFontCfg(pUserPaths)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 153 | pInfo->AddPath("/usr/share/fonts"); |
| 154 | pInfo->AddPath("/usr/share/X11/fonts/Type1"); |
| 155 | pInfo->AddPath("/usr/share/X11/fonts/TTF"); |
| 156 | pInfo->AddPath("/usr/local/share/fonts"); |
| 157 | } |
Tom Sepez | a0a6923 | 2017-05-01 11:39:33 -0700 | [diff] [blame] | 158 | return std::move(pInfo); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 159 | } |
thestig | 24508df | 2016-05-27 15:14:20 -0700 | [diff] [blame] | 160 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | void CFX_GEModule::InitPlatform() { |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 162 | m_pFontMgr->SetSystemFontInfo( |
| 163 | IFX_SystemFontInfo::CreateDefault(m_pUserFontPaths)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 164 | } |
thestig | 6115972 | 2016-08-04 10:59:55 -0700 | [diff] [blame] | 165 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | void CFX_GEModule::DestroyPlatform() {} |
Tom Sepez | b7d358b | 2015-06-17 10:01:00 -0700 | [diff] [blame] | 167 | #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ |