Home | History | Annotate | Download | only in win
      1 /*
      2  * Copyright (C) 2010 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 "ActivateFonts.h"
     28 
     29 #include <string>
     30 #include <wtf/Vector.h>
     31 
     32 static LPCWSTR fontsEnvironmentVariable = L"WEBKIT_TESTFONTS";
     33 
     34 namespace WTR {
     35 
     36 using namespace std;
     37 
     38 static const wstring& fontsPath()
     39 {
     40     static wstring path;
     41     static bool initialized;
     42 
     43     if (initialized)
     44         return path;
     45     initialized = true;
     46 
     47     DWORD size = ::GetEnvironmentVariableW(fontsEnvironmentVariable, 0, 0);
     48     Vector<WCHAR> buffer(size);
     49     if (!::GetEnvironmentVariableW(fontsEnvironmentVariable, buffer.data(), buffer.size()))
     50         return path;
     51 
     52     path = buffer.data();
     53     if (path[path.length() - 1] != '\\')
     54         path.append(L"\\");
     55 
     56     return path;
     57 }
     58 
     59 
     60 void activateFonts()
     61 {
     62     static LPCWSTR fontsToInstall[] = {
     63         TEXT("AHEM____.ttf"),
     64         TEXT("Apple Chancery.ttf"),
     65         TEXT("Courier Bold.ttf"),
     66         TEXT("Courier.ttf"),
     67         TEXT("Helvetica Bold Oblique.ttf"),
     68         TEXT("Helvetica Bold.ttf"),
     69         TEXT("Helvetica Oblique.ttf"),
     70         TEXT("Helvetica.ttf"),
     71         TEXT("Helvetica Neue Bold Italic.ttf"),
     72         TEXT("Helvetica Neue Bold.ttf"),
     73         TEXT("Helvetica Neue Condensed Black.ttf"),
     74         TEXT("Helvetica Neue Condensed Bold.ttf"),
     75         TEXT("Helvetica Neue Italic.ttf"),
     76         TEXT("Helvetica Neue Light Italic.ttf"),
     77         TEXT("Helvetica Neue Light.ttf"),
     78         TEXT("Helvetica Neue UltraLight Italic.ttf"),
     79         TEXT("Helvetica Neue UltraLight.ttf"),
     80         TEXT("Helvetica Neue.ttf"),
     81         TEXT("Lucida Grande.ttf"),
     82         TEXT("Lucida Grande Bold.ttf"),
     83         TEXT("Monaco.ttf"),
     84         TEXT("Papyrus.ttf"),
     85         TEXT("Times Bold Italic.ttf"),
     86         TEXT("Times Bold.ttf"),
     87         TEXT("Times Italic.ttf"),
     88         TEXT("Times Roman.ttf"),
     89         TEXT("WebKit Layout Tests 2.ttf"),
     90         TEXT("WebKit Layout Tests.ttf"),
     91         TEXT("WebKitWeightWatcher100.ttf"),
     92         TEXT("WebKitWeightWatcher200.ttf"),
     93         TEXT("WebKitWeightWatcher300.ttf"),
     94         TEXT("WebKitWeightWatcher400.ttf"),
     95         TEXT("WebKitWeightWatcher500.ttf"),
     96         TEXT("WebKitWeightWatcher600.ttf"),
     97         TEXT("WebKitWeightWatcher700.ttf"),
     98         TEXT("WebKitWeightWatcher800.ttf"),
     99         TEXT("WebKitWeightWatcher900.ttf")
    100     };
    101 
    102     wstring resourcesPath = fontsPath();
    103 
    104     for (unsigned i = 0; i < ARRAYSIZE(fontsToInstall); ++i)
    105         ::AddFontResourceExW(wstring(resourcesPath + fontsToInstall[i]).c_str(), FR_PRIVATE, 0);
    106 }
    107 
    108 }
    109