1bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)/* 2bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 3bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 4bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * Copyright (C) 2013 Google, Inc. All rights reserved. 5bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * 6bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 7bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * modification, are permitted provided that the following conditions 8bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * are met: 9bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * 10bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 11bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 12bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 13bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 14bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 15bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 16bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * its contributors may be used to endorse or promote products derived 17bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * from this software without specific prior written permission. 18bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * 19bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) */ 30bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 31bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#ifndef AlternateFontFamily_h 32bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#define AlternateFontFamily_h 33bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 34f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/fonts/FontDescription.h" 35bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "wtf/text/AtomicString.h" 36bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 37c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 38bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 39d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)// We currently do not support bitmap fonts on windows. 40bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)// Instead of trying to construct a bitmap font and then going down the fallback path map 41d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)// certain common bitmap fonts to their truetype equivalent up front. 4251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)inline const AtomicString& adjustFamilyNameToAvoidUnsupportedFonts(const AtomicString& familyName) 43bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){ 44bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#if OS(WIN) 45bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // On Windows, 'Courier New' (truetype font) is always present and 46bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // 'Courier' is a bitmap font. On Mac on the other hand 'Courier' is 47bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // a truetype font. Thus pages asking for Courier are better of 48bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // using 'Courier New' on windows. 49bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::ConstructFromLiteral)); 50bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::ConstructFromLiteral)); 51bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) if (equalIgnoringCase(familyName, courier)) 52bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return courierNew; 53bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 54bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // Alias 'MS Sans Serif' (bitmap font) -> 'Microsoft Sans Serif' 55bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // (truetype font). 56bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, msSans, ("MS Sans Serif", AtomicString::ConstructFromLiteral)); 57bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, microsoftSans, ("Microsoft Sans Serif", AtomicString::ConstructFromLiteral)); 58bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) if (equalIgnoringCase(familyName, msSans)) 59bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return microsoftSans; 60bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 61bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // Alias 'MS Serif' (bitmap) -> 'Times New Roman' (truetype font). 62d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) // Alias 'Times' -> 'Times New Roman' (truetype font). 63bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // There's no 'Microsoft Sans Serif-equivalent' for Serif. 64bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, msSerif, ("MS Serif", AtomicString::ConstructFromLiteral)); 65d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, times, ("Times", AtomicString::ConstructFromLiteral)); 66bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicString::ConstructFromLiteral)); 67d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) if (equalIgnoringCase(familyName, msSerif) || equalIgnoringCase(familyName, times)) 68bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return timesNewRoman; 69bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#endif 70bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 7151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return familyName; 72bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)} 73bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 7419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)inline const AtomicString& alternateFamilyName(const AtomicString& familyName) 75bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){ 76bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // Alias Courier <-> Courier New 77bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::ConstructFromLiteral)); 78bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::ConstructFromLiteral)); 79bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) if (equalIgnoringCase(familyName, courier)) 80bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return courierNew; 81bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#if !OS(WIN) 82bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // On Windows, Courier New (truetype font) is always present and 83bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // Courier is a bitmap font. So, we don't want to map Courier New to 84bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // Courier. 85bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) if (equalIgnoringCase(familyName, courierNew)) 86bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return courier; 87bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#endif 88bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 89bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // Alias Times and Times New Roman. 90bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, times, ("Times", AtomicString::ConstructFromLiteral)); 91bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicString::ConstructFromLiteral)); 92bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) if (equalIgnoringCase(familyName, times)) 93bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return timesNewRoman; 94bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) if (equalIgnoringCase(familyName, timesNewRoman)) 95bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return times; 96bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 97bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // Alias Arial and Helvetica 98bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, arial, ("Arial", AtomicString::ConstructFromLiteral)); 99bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_STATIC_LOCAL(AtomicString, helvetica, ("Helvetica", AtomicString::ConstructFromLiteral)); 100bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) if (equalIgnoringCase(familyName, arial)) 101bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return helvetica; 102bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) if (equalIgnoringCase(familyName, helvetica)) 103bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return arial; 104bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 105bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return emptyAtom; 106bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)} 107bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 108bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 10919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)inline const AtomicString getFallbackFontFamily(const FontDescription& description) 110bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){ 111d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("sans-serif", AtomicString::ConstructFromLiteral)); 112d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) DEFINE_STATIC_LOCAL(const AtomicString, serifStr, ("serif", AtomicString::ConstructFromLiteral)); 113d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) DEFINE_STATIC_LOCAL(const AtomicString, monospaceStr, ("monospace", AtomicString::ConstructFromLiteral)); 114d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) DEFINE_STATIC_LOCAL(const AtomicString, cursiveStr, ("cursive", AtomicString::ConstructFromLiteral)); 115d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) DEFINE_STATIC_LOCAL(const AtomicString, fantasyStr, ("fantasy", AtomicString::ConstructFromLiteral)); 116bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 117bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) switch (description.genericFamily()) { 118d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) case FontDescription::SansSerifFamily: 119d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return sansStr; 120bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) case FontDescription::SerifFamily: 121bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return serifStr; 122bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) case FontDescription::MonospaceFamily: 123bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return monospaceStr; 124d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) case FontDescription::CursiveFamily: 125d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return cursiveStr; 126d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) case FontDescription::FantasyFamily: 127d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return fantasyStr; 128bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) default: 129d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) // Let the caller use the system default font. 130d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return emptyAtom; 131bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) } 132bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)} 133bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 134c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 135bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 136bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#endif // AlternateFontFamily_h 137