| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "core/platform/text/transcoder/FontTranscoder.h" | |
| 33 | |
| 34 #include "core/platform/graphics/FontDescription.h" | |
| 35 #include "wtf/text/TextEncoding.h" | |
| 36 #include "wtf/unicode/CharacterNames.h" | |
| 37 | |
| 38 namespace WebCore { | |
| 39 | |
| 40 FontTranscoder::FontTranscoder() | |
| 41 { | |
| 42 m_converterTypes.add("MS PGothic", BackslashToYenSign); | |
| 43 UChar unicodeNameMSPGothic[] = {0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30
B7, 0x30C3, 0x30AF}; | |
| 44 m_converterTypes.add(AtomicString(unicodeNameMSPGothic, WTF_ARRAY_LENGTH(uni
codeNameMSPGothic)), BackslashToYenSign); | |
| 45 | |
| 46 m_converterTypes.add("MS PMincho", BackslashToYenSign); | |
| 47 UChar unicodeNameMSPMincho[] = {0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x660E, 0x67
1D}; | |
| 48 m_converterTypes.add(AtomicString(unicodeNameMSPMincho, WTF_ARRAY_LENGTH(uni
codeNameMSPMincho)), BackslashToYenSign); | |
| 49 | |
| 50 m_converterTypes.add("MS Gothic", BackslashToYenSign); | |
| 51 UChar unicodeNameMSGothic[] = {0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C
3, 0x30AF}; | |
| 52 m_converterTypes.add(AtomicString(unicodeNameMSGothic, WTF_ARRAY_LENGTH(unic
odeNameMSGothic)), BackslashToYenSign); | |
| 53 | |
| 54 m_converterTypes.add("MS Mincho", BackslashToYenSign); | |
| 55 UChar unicodeNameMSMincho[] = {0xFF2D, 0xFF33, 0x0020, 0x660E, 0x671D}; | |
| 56 m_converterTypes.add(AtomicString(unicodeNameMSMincho, WTF_ARRAY_LENGTH(unic
odeNameMSMincho)), BackslashToYenSign); | |
| 57 | |
| 58 m_converterTypes.add("Meiryo", BackslashToYenSign); | |
| 59 UChar unicodeNameMeiryo[] = {0x30E1, 0x30A4, 0x30EA, 0x30AA}; | |
| 60 m_converterTypes.add(AtomicString(unicodeNameMeiryo, WTF_ARRAY_LENGTH(unicod
eNameMeiryo)), BackslashToYenSign); | |
| 61 } | |
| 62 | |
| 63 FontTranscoder::ConverterType FontTranscoder::converterType(const FontDescriptio
n& fontDescription, const WTF::TextEncoding* encoding) const | |
| 64 { | |
| 65 const AtomicString& fontFamily = fontDescription.family().family().string(); | |
| 66 if (!fontFamily.isNull()) { | |
| 67 HashMap<AtomicString, ConverterType>::const_iterator found = m_converter
Types.find(fontFamily); | |
| 68 if (found != m_converterTypes.end()) | |
| 69 return found->value; | |
| 70 } | |
| 71 | |
| 72 // IE's default fonts for Japanese encodings change backslashes into yen sig
ns. | |
| 73 // We emulate this behavior only when no font is explicitly specified. | |
| 74 if (encoding && encoding->backslashAsCurrencySymbol() != '\\' && !fontDescri
ption.isSpecifiedFont()) | |
| 75 return BackslashToYenSign; | |
| 76 | |
| 77 return NoConversion; | |
| 78 } | |
| 79 | |
| 80 void FontTranscoder::convert(String& text, const FontDescription& fontDescriptio
n, const WTF::TextEncoding* encoding) const | |
| 81 { | |
| 82 switch (converterType(fontDescription, encoding)) { | |
| 83 case BackslashToYenSign: { | |
| 84 // FIXME: wtf/text/TextEncoding.h has similar code. We need to factor th
em out. | |
| 85 text.replace('\\', yenSign); | |
| 86 break; | |
| 87 } | |
| 88 case NoConversion: | |
| 89 default: | |
| 90 ASSERT_NOT_REACHED(); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 bool FontTranscoder::needsTranscoding(const FontDescription& fontDescription, co
nst WTF::TextEncoding* encoding) const | |
| 95 { | |
| 96 ConverterType type = converterType(fontDescription, encoding); | |
| 97 return type != NoConversion; | |
| 98 } | |
| 99 | |
| 100 FontTranscoder& fontTranscoder() | |
| 101 { | |
| 102 static FontTranscoder* transcoder = new FontTranscoder; | |
| 103 return *transcoder; | |
| 104 } | |
| 105 | |
| 106 } // namespace WebCore | |
| OLD | NEW |