Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 #include <fcntl.h> | 5 #include <fcntl.h> |
| 6 #include <fontconfig/fontconfig.h> | 6 #include <fontconfig/fontconfig.h> |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
| 15 #include "ppapi/c/private/pp_private_font_charset.h" | |
| 15 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" | 16 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" |
| 16 #include "third_party/npapi/bindings/npapi_extensions.h" | |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // MSCharSetToFontconfig translates a Microsoft charset identifier to a | 20 // MSCharSetToFontconfig translates a Microsoft charset identifier to a |
| 21 // fontconfig language set by appending to |langset|. | 21 // fontconfig language set by appending to |langset|. |
| 22 // Returns true if |langset| is Latin/Greek/Cyrillic. | 22 // Returns true if |langset| is Latin/Greek/Cyrillic. |
| 23 bool MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { | 23 bool MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { |
| 24 // We have need to translate raw fdwCharSet values into terms that | 24 // We have need to translate raw fdwCharSet values into terms that |
| 25 // fontconfig can understand. (See the description of fdwCharSet in the MSDN | 25 // fontconfig can understand. (See the description of fdwCharSet in the MSDN |
| 26 // documentation for CreateFont: | 26 // documentation for CreateFont: |
| 27 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx ) | 27 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx ) |
| 28 // | 28 // |
| 29 // Although the argument is /called/ 'charset', the actual values conflate | 29 // Although the argument is /called/ 'charset', the actual values conflate |
| 30 // character sets (which are sets of Unicode code points) and character | 30 // character sets (which are sets of Unicode code points) and character |
| 31 // encodings (which are algorithms for turning a series of bits into a | 31 // encodings (which are algorithms for turning a series of bits into a |
| 32 // series of code points.) Sometimes the values will name a language, | 32 // series of code points.) Sometimes the values will name a language, |
| 33 // sometimes they'll name an encoding. In the latter case I'm assuming that | 33 // sometimes they'll name an encoding. In the latter case I'm assuming that |
| 34 // they mean the set of code points in the domain of that encoding. | 34 // they mean the set of code points in the domain of that encoding. |
| 35 // | 35 // |
| 36 // fontconfig deals with ISO 639-1 language codes: | 36 // fontconfig deals with ISO 639-1 language codes: |
| 37 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | 37 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes |
| 38 // | 38 // |
| 39 // So, for each of the documented fdwCharSet values I've had to take a | 39 // So, for each of the documented fdwCharSet values I've had to take a |
| 40 // guess at the set of ISO 639-1 languages intended. | 40 // guess at the set of ISO 639-1 languages intended. |
| 41 | 41 |
| 42 bool is_lgc = false; | 42 bool is_lgc = false; |
| 43 switch (fdwCharSet) { | 43 switch (fdwCharSet) { |
| 44 case NPCharsetAnsi: | 44 case PP_PRIVATEFONTCHARSET_ANSI: |
|
piman
2016/04/04 21:30:42
The PPAPI enum has the same values as the correspo
| |
| 45 // These values I don't really know what to do with, so I'm going to map | 45 // These values I don't really know what to do with, so I'm going to map |
| 46 // them to English also. | 46 // them to English also. |
| 47 case NPCharsetDefault: | 47 case PP_PRIVATEFONTCHARSET_DEFAULT: |
| 48 case NPCharsetMac: | 48 case PP_PRIVATEFONTCHARSET_MAC: |
| 49 case NPCharsetOEM: | 49 case PP_PRIVATEFONTCHARSET_OEM: |
| 50 case NPCharsetSymbol: | 50 case PP_PRIVATEFONTCHARSET_SYMBOL: |
| 51 is_lgc = true; | 51 is_lgc = true; |
| 52 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); | 52 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); |
| 53 break; | 53 break; |
| 54 case NPCharsetBaltic: | 54 case PP_PRIVATEFONTCHARSET_BALTIC: |
| 55 // The three baltic languages. | 55 // The three baltic languages. |
| 56 is_lgc = true; | 56 is_lgc = true; |
| 57 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); | 57 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); |
| 58 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); | 58 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); |
| 59 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); | 59 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); |
| 60 break; | 60 break; |
| 61 case NPCharsetChineseBIG5: | 61 case PP_PRIVATEFONTCHARSET_CHINESEBIG5: |
| 62 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-tw")); | 62 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-tw")); |
| 63 break; | 63 break; |
| 64 case NPCharsetGB2312: | 64 case PP_PRIVATEFONTCHARSET_GB2312: |
| 65 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-cn")); | 65 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-cn")); |
| 66 break; | 66 break; |
| 67 case NPCharsetEastEurope: | 67 case PP_PRIVATEFONTCHARSET_EASTEUROPE: |
| 68 // A scattering of eastern European languages. | 68 // A scattering of eastern European languages. |
| 69 is_lgc = true; | 69 is_lgc = true; |
| 70 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); | 70 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); |
| 71 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); | 71 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); |
| 72 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); | 72 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); |
| 73 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu")); | 73 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu")); |
| 74 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); | 74 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); |
| 75 break; | 75 break; |
| 76 case NPCharsetGreek: | 76 case PP_PRIVATEFONTCHARSET_GREEK: |
| 77 is_lgc = true; | 77 is_lgc = true; |
| 78 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el")); | 78 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el")); |
| 79 break; | 79 break; |
| 80 case NPCharsetHangul: | 80 case PP_PRIVATEFONTCHARSET_HANGUL: |
| 81 case NPCharsetJohab: | 81 case PP_PRIVATEFONTCHARSET_JOHAB: |
| 82 // Korean | 82 // Korean |
| 83 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko")); | 83 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko")); |
| 84 break; | 84 break; |
| 85 case NPCharsetRussian: | 85 case PP_PRIVATEFONTCHARSET_RUSSIAN: |
| 86 is_lgc = true; | 86 is_lgc = true; |
| 87 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru")); | 87 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru")); |
| 88 break; | 88 break; |
| 89 case NPCharsetShiftJIS: | 89 case PP_PRIVATEFONTCHARSET_SHIFTJIS: |
| 90 // Japanese | 90 // Japanese |
| 91 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja")); | 91 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja")); |
| 92 break; | 92 break; |
| 93 case NPCharsetTurkish: | 93 case PP_PRIVATEFONTCHARSET_TURKISH: |
| 94 is_lgc = true; | 94 is_lgc = true; |
| 95 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr")); | 95 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr")); |
| 96 break; | 96 break; |
| 97 case NPCharsetVietnamese: | 97 case PP_PRIVATEFONTCHARSET_VIETNAMESE: |
| 98 is_lgc = true; | 98 is_lgc = true; |
| 99 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi")); | 99 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi")); |
| 100 break; | 100 break; |
| 101 case NPCharsetArabic: | 101 case PP_PRIVATEFONTCHARSET_ARABIC: |
| 102 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ar")); | 102 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ar")); |
| 103 break; | 103 break; |
| 104 case NPCharsetHebrew: | 104 case PP_PRIVATEFONTCHARSET_HEBREW: |
| 105 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he")); | 105 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he")); |
| 106 break; | 106 break; |
| 107 case NPCharsetThai: | 107 case PP_PRIVATEFONTCHARSET_THAI: |
| 108 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th")); | 108 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th")); |
| 109 break; | 109 break; |
| 110 // default: | 110 // default: |
| 111 // Don't add any languages in that case that we don't recognise the | 111 // Don't add any languages in that case that we don't recognise the |
| 112 // constant. | 112 // constant. |
| 113 } | 113 } |
| 114 return is_lgc; | 114 return is_lgc; |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace | 117 } // namespace |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 } | 253 } |
| 254 | 254 |
| 255 if (font_set) | 255 if (font_set) |
| 256 FcFontSetDestroy(font_set); | 256 FcFontSetDestroy(font_set); |
| 257 FcPatternDestroy(pattern); | 257 FcPatternDestroy(pattern); |
| 258 | 258 |
| 259 return font_fd; | 259 return font_fd; |
| 260 } | 260 } |
| 261 | 261 |
| 262 } // namespace content | 262 } // namespace content |
| OLD | NEW |