1 /* 2 * Copyright (C) 2013 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 "platform/fonts/GenericFontFamilySettings.h" 33 34 namespace WebCore { 35 36 GenericFontFamilySettings::GenericFontFamilySettings(const GenericFontFamilySettings& other) 37 : m_standardFontFamilyMap(other.m_standardFontFamilyMap) 38 , m_serifFontFamilyMap(other.m_serifFontFamilyMap) 39 , m_fixedFontFamilyMap(other.m_fixedFontFamilyMap) 40 , m_sansSerifFontFamilyMap(other.m_sansSerifFontFamilyMap) 41 , m_cursiveFontFamilyMap(other.m_cursiveFontFamilyMap) 42 , m_fantasyFontFamilyMap(other.m_fantasyFontFamilyMap) 43 , m_pictographFontFamilyMap(other.m_pictographFontFamilyMap) 44 { 45 } 46 47 // Sets the entry in the font map for the given script. If family is the empty string, removes the entry instead. 48 void GenericFontFamilySettings::setGenericFontFamilyMap(ScriptFontFamilyMap& fontMap, const AtomicString& family, UScriptCode script) 49 { 50 ScriptFontFamilyMap::iterator it = fontMap.find(static_cast<int>(script)); 51 if (family.isEmpty()) { 52 if (it == fontMap.end()) 53 return; 54 fontMap.remove(it); 55 } else if (it != fontMap.end() && it->value == family) { 56 return; 57 } else { 58 fontMap.set(static_cast<int>(script), family); 59 } 60 } 61 62 const AtomicString& GenericFontFamilySettings::genericFontFamilyForScript(const ScriptFontFamilyMap& fontMap, UScriptCode script) const 63 { 64 ScriptFontFamilyMap::const_iterator it = fontMap.find(static_cast<int>(script)); 65 if (it != fontMap.end()) 66 return it->value; 67 if (script != USCRIPT_COMMON) 68 return genericFontFamilyForScript(fontMap, USCRIPT_COMMON); 69 return emptyAtom; 70 } 71 72 const AtomicString& GenericFontFamilySettings::standard(UScriptCode script) const 73 { 74 return genericFontFamilyForScript(m_standardFontFamilyMap, script); 75 } 76 77 void GenericFontFamilySettings::setStandard(const AtomicString& family, UScriptCode script) 78 { 79 setGenericFontFamilyMap(m_standardFontFamilyMap, family, script); 80 } 81 82 const AtomicString& GenericFontFamilySettings::fixed(UScriptCode script) const 83 { 84 return genericFontFamilyForScript(m_fixedFontFamilyMap, script); 85 } 86 87 void GenericFontFamilySettings::setFixed(const AtomicString& family, UScriptCode script) 88 { 89 setGenericFontFamilyMap(m_fixedFontFamilyMap, family, script); 90 } 91 92 const AtomicString& GenericFontFamilySettings::serif(UScriptCode script) const 93 { 94 return genericFontFamilyForScript(m_serifFontFamilyMap, script); 95 } 96 97 void GenericFontFamilySettings::setSerif(const AtomicString& family, UScriptCode script) 98 { 99 setGenericFontFamilyMap(m_serifFontFamilyMap, family, script); 100 } 101 102 const AtomicString& GenericFontFamilySettings::sansSerif(UScriptCode script) const 103 { 104 return genericFontFamilyForScript(m_sansSerifFontFamilyMap, script); 105 } 106 107 void GenericFontFamilySettings::setSansSerif(const AtomicString& family, UScriptCode script) 108 { 109 setGenericFontFamilyMap(m_sansSerifFontFamilyMap, family, script); 110 } 111 112 const AtomicString& GenericFontFamilySettings::cursive(UScriptCode script) const 113 { 114 return genericFontFamilyForScript(m_cursiveFontFamilyMap, script); 115 } 116 117 void GenericFontFamilySettings::setCursive(const AtomicString& family, UScriptCode script) 118 { 119 setGenericFontFamilyMap(m_cursiveFontFamilyMap, family, script); 120 } 121 122 const AtomicString& GenericFontFamilySettings::fantasy(UScriptCode script) const 123 { 124 return genericFontFamilyForScript(m_fantasyFontFamilyMap, script); 125 } 126 127 void GenericFontFamilySettings::setFantasy(const AtomicString& family, UScriptCode script) 128 { 129 setGenericFontFamilyMap(m_fantasyFontFamilyMap, family, script); 130 } 131 132 const AtomicString& GenericFontFamilySettings::pictograph(UScriptCode script) const 133 { 134 return genericFontFamilyForScript(m_pictographFontFamilyMap, script); 135 } 136 137 void GenericFontFamilySettings::setPictograph(const AtomicString& family, UScriptCode script) 138 { 139 setGenericFontFamilyMap(m_pictographFontFamilyMap, family, script); 140 } 141 142 void GenericFontFamilySettings::reset() 143 { 144 m_standardFontFamilyMap.clear(); 145 m_serifFontFamilyMap.clear(); 146 m_fixedFontFamilyMap.clear(); 147 m_sansSerifFontFamilyMap.clear(); 148 m_cursiveFontFamilyMap.clear(); 149 m_fantasyFontFamilyMap.clear(); 150 m_pictographFontFamilyMap.clear(); 151 } 152 153 } 154