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