Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef _SKIA_SUPPORT_ | 7 #ifndef _SKIA_SUPPORT_ |
| 8 #include "core/fxge/agg/fx_agg_driver.h" | 8 #include "core/fxge/agg/fx_agg_driver.h" |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include <memory> | |
| 12 | |
| 11 #include "core/fxge/ge/cfx_folderfontinfo.h" | 13 #include "core/fxge/ge/cfx_folderfontinfo.h" |
| 12 #include "core/fxge/ge/fx_text_int.h" | 14 #include "core/fxge/ge/fx_text_int.h" |
| 13 #include "core/fxge/include/fx_ge.h" | 15 #include "core/fxge/include/fx_ge.h" |
| 14 #include "core/fxge/include/ifx_systemfontinfo.h" | 16 #include "core/fxge/include/ifx_systemfontinfo.h" |
| 15 | 17 |
| 16 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ | 18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ |
| 19 namespace { | |
| 20 | |
| 17 class CFX_LinuxFontInfo : public CFX_FolderFontInfo { | 21 class CFX_LinuxFontInfo : public CFX_FolderFontInfo { |
| 18 public: | 22 public: |
| 19 void* MapFont(int weight, | 23 void* MapFont(int weight, |
| 20 FX_BOOL bItalic, | 24 FX_BOOL bItalic, |
| 21 int charset, | 25 int charset, |
| 22 int pitch_family, | 26 int pitch_family, |
| 23 const FX_CHAR* family, | 27 const FX_CHAR* family, |
| 24 int& iExact) override; | 28 int& iExact) override; |
| 25 FX_BOOL ParseFontCfg(const char** pUserPaths); | 29 FX_BOOL ParseFontCfg(const char** pUserPaths); |
| 26 }; | 30 }; |
| 27 #define LINUX_GPNAMESIZE 6 | 31 |
| 28 static const struct { | 32 const size_t kLinuxGpNameSize = 6; |
| 29 const FX_CHAR* NameArr[LINUX_GPNAMESIZE]; | 33 |
| 30 } LinuxGpFontList[] = { | 34 const struct { |
| 35 const FX_CHAR* NameArr[kLinuxGpNameSize]; | |
|
Tom Sepez
2016/08/04 19:20:18
drive-by: wouldn't a 2D array of char* be simpler
Lei Zhang
2016/08/04 19:22:25
Probably. Who wants to send the next CL? :)
| |
| 36 } g_LinuxGpFontList[] = { | |
| 31 {{"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic", | 37 {{"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic", |
| 32 "VL Gothic regular"}}, | 38 "VL Gothic regular"}}, |
| 33 {{"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", nullptr, | 39 {{"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", nullptr, |
| 34 "VL Gothic regular"}}, | 40 "VL Gothic regular"}}, |
| 35 {{"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", nullptr, | 41 {{"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", nullptr, |
| 36 "VL Gothic regular"}}, | 42 "VL Gothic regular"}}, |
| 37 {{"TakaoMincho", "IPAMincho", "VL Gothic", "Kochi Mincho", nullptr, | 43 {{"TakaoMincho", "IPAMincho", "VL Gothic", "Kochi Mincho", nullptr, |
| 38 "VL Gothic regular"}}, | 44 "VL Gothic regular"}}, |
| 39 }; | 45 }; |
| 40 static const FX_CHAR* const g_LinuxGbFontList[] = { | 46 |
| 47 const FX_CHAR* const g_LinuxGbFontList[] = { | |
| 41 "AR PL UMing CN Light", "WenQuanYi Micro Hei", "AR PL UKai CN", | 48 "AR PL UMing CN Light", "WenQuanYi Micro Hei", "AR PL UKai CN", |
| 42 }; | 49 }; |
| 43 static const FX_CHAR* const g_LinuxB5FontList[] = { | 50 |
| 51 const FX_CHAR* const g_LinuxB5FontList[] = { | |
| 44 "AR PL UMing TW Light", "WenQuanYi Micro Hei", "AR PL UKai TW", | 52 "AR PL UMing TW Light", "WenQuanYi Micro Hei", "AR PL UKai TW", |
| 45 }; | 53 }; |
| 46 static const FX_CHAR* const g_LinuxHGFontList[] = { | 54 |
| 55 const FX_CHAR* const g_LinuxHGFontList[] = { | |
| 47 "UnDotum", | 56 "UnDotum", |
| 48 }; | 57 }; |
| 49 static int32_t GetJapanesePreference(const FX_CHAR* facearr, | 58 |
| 50 int weight, | 59 size_t GetJapanesePreference(const FX_CHAR* facearr, |
| 51 int picth_family) { | 60 int weight, |
| 61 int pitch_family) { | |
| 52 CFX_ByteString face = facearr; | 62 CFX_ByteString face = facearr; |
| 53 if (face.Find("Gothic") >= 0 || | 63 if (face.Find("Gothic") >= 0 || |
| 54 face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) { | 64 face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) { |
| 55 if (face.Find("PGothic") >= 0 || | 65 if (face.Find("PGothic") >= 0 || |
| 56 face.Find("\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) { | 66 face.Find("\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) { |
| 57 return 0; | 67 return 0; |
| 58 } | 68 } |
| 59 return 1; | 69 return 1; |
| 60 } | 70 } |
| 61 if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) { | 71 if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) { |
| 62 if (face.Find("PMincho") >= 0 || | 72 if (face.Find("PMincho") >= 0 || |
| 63 face.Find("\x82\x6f\x96\xbe\x92\xa9") >= 0) { | 73 face.Find("\x82\x6f\x96\xbe\x92\xa9") >= 0) { |
| 64 return 2; | 74 return 2; |
| 65 } | 75 } |
| 66 return 3; | 76 return 3; |
| 67 } | 77 } |
| 68 if (!(picth_family & FXFONT_FF_ROMAN) && weight > 400) { | 78 if (!(pitch_family & FXFONT_FF_ROMAN) && weight > 400) { |
| 69 return 0; | 79 return 0; |
| 70 } | 80 } |
| 71 return 2; | 81 return 2; |
| 72 } | 82 } |
| 83 | |
| 84 } // namespace | |
| 85 | |
| 73 void* CFX_LinuxFontInfo::MapFont(int weight, | 86 void* CFX_LinuxFontInfo::MapFont(int weight, |
| 74 FX_BOOL bItalic, | 87 FX_BOOL bItalic, |
| 75 int charset, | 88 int charset, |
| 76 int pitch_family, | 89 int pitch_family, |
| 77 const FX_CHAR* cstr_face, | 90 const FX_CHAR* cstr_face, |
| 78 int& iExact) { | 91 int& iExact) { |
| 79 void* font = GetSubstFont(cstr_face); | 92 void* font = GetSubstFont(cstr_face); |
| 80 if (font) { | 93 if (font) { |
| 81 iExact = 1; | 94 iExact = 1; |
| 82 return font; | 95 return font; |
| 83 } | 96 } |
| 84 FX_BOOL bCJK = TRUE; | 97 FX_BOOL bCJK = TRUE; |
| 85 switch (charset) { | 98 switch (charset) { |
| 86 case FXFONT_SHIFTJIS_CHARSET: { | 99 case FXFONT_SHIFTJIS_CHARSET: { |
| 87 int32_t index = GetJapanesePreference(cstr_face, weight, pitch_family); | 100 size_t index = GetJapanesePreference(cstr_face, weight, pitch_family); |
| 88 if (index < 0) { | 101 ASSERT(index < FX_ArraySize(g_LinuxGpFontList)); |
|
npm_g
2016/08/04 17:53:16
Maybe also include the condition index >= 0
Lei Zhang
2016/08/04 17:59:26
size_t is unsigned, always >= 0.
| |
| 89 break; | 102 for (size_t i = 0; i < kLinuxGpNameSize; i++) { |
| 90 } | 103 auto it = m_FontList.find(g_LinuxGpFontList[index].NameArr[i]); |
| 91 for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++) { | |
| 92 auto it = m_FontList.find(LinuxGpFontList[index].NameArr[i]); | |
| 93 if (it != m_FontList.end()) { | 104 if (it != m_FontList.end()) { |
| 94 return it->second; | 105 return it->second; |
| 95 } | 106 } |
| 96 } | 107 } |
| 97 } break; | 108 break; |
| 109 } | |
| 98 case FXFONT_GB2312_CHARSET: { | 110 case FXFONT_GB2312_CHARSET: { |
| 99 for (size_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) { | 111 for (size_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) { |
| 100 auto it = m_FontList.find(g_LinuxGbFontList[i]); | 112 auto it = m_FontList.find(g_LinuxGbFontList[i]); |
| 101 if (it != m_FontList.end()) { | 113 if (it != m_FontList.end()) { |
| 102 return it->second; | 114 return it->second; |
| 103 } | 115 } |
| 104 } | 116 } |
| 105 } break; | 117 break; |
| 118 } | |
| 106 case FXFONT_CHINESEBIG5_CHARSET: { | 119 case FXFONT_CHINESEBIG5_CHARSET: { |
| 107 for (size_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) { | 120 for (size_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) { |
| 108 auto it = m_FontList.find(g_LinuxB5FontList[i]); | 121 auto it = m_FontList.find(g_LinuxB5FontList[i]); |
| 109 if (it != m_FontList.end()) { | 122 if (it != m_FontList.end()) { |
| 110 return it->second; | 123 return it->second; |
| 111 } | 124 } |
| 112 } | 125 } |
| 113 } break; | 126 break; |
| 127 } | |
| 114 case FXFONT_HANGEUL_CHARSET: { | 128 case FXFONT_HANGEUL_CHARSET: { |
| 115 for (size_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) { | 129 for (size_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) { |
| 116 auto it = m_FontList.find(g_LinuxHGFontList[i]); | 130 auto it = m_FontList.find(g_LinuxHGFontList[i]); |
| 117 if (it != m_FontList.end()) { | 131 if (it != m_FontList.end()) { |
| 118 return it->second; | 132 return it->second; |
| 119 } | 133 } |
| 120 } | 134 } |
| 121 } break; | 135 break; |
| 136 } | |
| 122 default: | 137 default: |
| 123 bCJK = FALSE; | 138 bCJK = FALSE; |
| 124 break; | 139 break; |
| 125 } | 140 } |
| 126 return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK); | 141 return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK); |
| 127 } | 142 } |
| 128 | 143 |
| 129 std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault( | 144 std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault( |
| 130 const char** pUserPaths) { | 145 const char** pUserPaths) { |
| 131 CFX_LinuxFontInfo* pInfo = new CFX_LinuxFontInfo; | 146 CFX_LinuxFontInfo* pInfo = new CFX_LinuxFontInfo; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 144 | 159 |
| 145 for (const char** pPath = pUserPaths; *pPath; ++pPath) | 160 for (const char** pPath = pUserPaths; *pPath; ++pPath) |
| 146 AddPath(*pPath); | 161 AddPath(*pPath); |
| 147 return TRUE; | 162 return TRUE; |
| 148 } | 163 } |
| 149 | 164 |
| 150 void CFX_GEModule::InitPlatform() { | 165 void CFX_GEModule::InitPlatform() { |
| 151 m_pFontMgr->SetSystemFontInfo( | 166 m_pFontMgr->SetSystemFontInfo( |
| 152 IFX_SystemFontInfo::CreateDefault(m_pUserFontPaths)); | 167 IFX_SystemFontInfo::CreateDefault(m_pUserFontPaths)); |
| 153 } | 168 } |
| 169 | |
| 154 void CFX_GEModule::DestroyPlatform() {} | 170 void CFX_GEModule::DestroyPlatform() {} |
| 155 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ | 171 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ |
| OLD | NEW |