|
Line 0
Source/WebCore/page/mac/SettingsMac.mm_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2012 Apple 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 |
| 6 |
* are met: |
| 7 |
* 1. Redistributions of source code must retain the above copyright |
| 8 |
* notice, this list of conditions and the following disclaimer. |
| 9 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* |
| 13 |
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 |
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 |
* THE POSSIBILITY OF SUCH DAMAGE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "config.h" |
| 27 |
#include "Settings.h" |
| 28 |
|
| 29 |
#include "LocaleToScriptMapping.h" |
| 30 |
#include <wtf/text/CString.h> |
| 31 |
|
| 32 |
namespace WebCore { |
| 33 |
|
| 34 |
static NSDictionary *defaultFontFamilyDictionary() |
| 35 |
{ |
| 36 |
static NSDictionary *fontFamilyDictionary; |
| 37 |
if (fontFamilyDictionary) |
| 38 |
return fontFamilyDictionary; |
| 39 |
|
| 40 |
NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebCore"]; |
| 41 |
NSData *fileData = [NSData dataWithContentsOfURL:[bundle URLForResource:@"DefaultFonts" withExtension:@"plist"]]; |
| 42 |
NSError *error; |
| 43 |
id propertyList = [NSPropertyListSerialization propertyListWithData:fileData options:NSPropertyListImmutable format:0 error:&error]; |
| 44 |
if (!propertyList) |
| 45 |
FATAL("Could not read font fallback file: %s", [[error description] UTF8String]); |
| 46 |
if (![propertyList isKindOfClass:[NSDictionary class]]) |
| 47 |
FATAL("Font fallback file has incorrect format - root object is not a dictionary"); |
| 48 |
|
| 49 |
fontFamilyDictionary = static_cast<NSDictionary *>(propertyList); |
| 50 |
CFRetain(fontFamilyDictionary); |
| 51 |
return fontFamilyDictionary; |
| 52 |
} |
| 53 |
|
| 54 |
void Settings::initializeDefaultFontFamilies() |
| 55 |
{ |
| 56 |
DEFINE_STATIC_LOCAL(AtomicString, standardFamily, ("standard")); |
| 57 |
DEFINE_STATIC_LOCAL(AtomicString, monospaceFamily, ("monospace")); |
| 58 |
DEFINE_STATIC_LOCAL(AtomicString, serifFamily, ("serif")); |
| 59 |
DEFINE_STATIC_LOCAL(AtomicString, sansSerifFamily, ("sans-serif")); |
| 60 |
DEFINE_STATIC_LOCAL(AtomicString, cursiveFamily, ("cursive")); |
| 61 |
DEFINE_STATIC_LOCAL(AtomicString, fantasyFamily, ("fantasy")); |
| 62 |
DEFINE_STATIC_LOCAL(AtomicString, pictographFamily, ("pictograph")); |
| 63 |
|
| 64 |
[defaultFontFamilyDictionary() enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *) { |
| 65 |
if (![key isKindOfClass:[NSString class]]) |
| 66 |
FATAL("Font fallback file has incorrect format - script name is not a string"); |
| 67 |
if (![obj isKindOfClass:[NSDictionary class]]) |
| 68 |
FATAL("Font fallback file has incorrect format - per-script value is not a dictionary"); |
| 69 |
|
| 70 |
UScriptCode script = scriptNameToCode(static_cast<NSString *>(key)); |
| 71 |
if (script == USCRIPT_UNKNOWN) |
| 72 |
FATAL("Font fallback file has incorrect format - unknown language code %s", [key UTF8String]); |
| 73 |
|
| 74 |
[obj enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *) { |
| 75 |
if (![key isKindOfClass:[NSString class]]) |
| 76 |
FATAL("Font fallback file has incorrect format - generic family name is not a string"); |
| 77 |
if (![obj isKindOfClass:[NSString class]]) |
| 78 |
FATAL("Font fallback file has incorrect format - font family name is not a string"); |
| 79 |
|
| 80 |
AtomicString genericFamily = static_cast<NSString *>(key); |
| 81 |
String familyName = static_cast<NSString *>(obj); |
| 82 |
|
| 83 |
if (genericFamily == standardFamily) |
| 84 |
setStandardFontFamily(familyName, script); |
| 85 |
else if (genericFamily == monospaceFamily) |
| 86 |
setFixedFontFamily(familyName, script); |
| 87 |
else if (genericFamily == serifFamily) |
| 88 |
setSerifFontFamily(familyName, script); |
| 89 |
else if (genericFamily == sansSerifFamily) |
| 90 |
setSansSerifFontFamily(familyName, script); |
| 91 |
else if (genericFamily == cursiveFamily) |
| 92 |
setCursiveFontFamily(familyName, script); |
| 93 |
else if (genericFamily == fantasyFamily) |
| 94 |
setFantasyFontFamily(familyName, script); |
| 95 |
else if (genericFamily == pictographFamily) |
| 96 |
setPictographFontFamily(familyName, script); |
| 97 |
else |
| 98 |
FATAL("Font fallback file has incorrect format - unknown font family name %s", familyName.utf8().data()); |
| 99 |
}]; |
| 100 |
}]; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
} // namespace WebCore |
| 0 |
+ LF |
105 |
+ LF |