1+ /*
2+ * Copyright (C) 2006 Apple Computer, 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+ *
8+ * 1. Redistributions of source code must retain the above copyright
9+ * notice, this list of conditions and the following disclaimer.
10+ * 2. Redistributions in binary form must reproduce the above copyright
11+ * notice, this list of conditions and the following disclaimer in the
12+ * documentation and/or other materials provided with the distribution.
13+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14+ * its contributors may be used to endorse or promote products derived
15+ * from this software without specific prior written permission.
16+ *
17+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
28+
29+ #include " config.h"
30+ #include " FontCache.h"
31+ #include " FontPlatformData.h"
32+ #include " Font.h"
33+ #include < windows.h>
34+
35+ namespace WebCore
36+ {
37+
38+ void FontCache::platformInit ()
39+ {
40+ // Not needed on Windows.
41+ }
42+
43+ const FontData* FontCache::getFontDataForCharacters (const Font& font, const UChar* characters, int length)
44+ {
45+ // FIXME: IMLangFontLink::MapFont Method does what we want. Font has to be released
46+ // when we're done with it (using IMLangFontLink::ReleaseFont).
47+ return 0 ;
48+ }
49+
50+ FontPlatformData* FontCache::getSimilarFontPlatformData (const Font& font)
51+ {
52+ // FIXME: Worth trying to map fonts like Courier to Courier New if missing?
53+ return 0 ;
54+ }
55+
56+ FontPlatformData* FontCache::getLastResortFallbackFont (const Font& font)
57+ {
58+ // FIXME: Would be even better to somehow get the user's default font here. For now we'll pick
59+ // the default that the user would get without changing any prefs.
60+ static AtomicString timesStr (" Times New Roman" );
61+ return getCachedFontPlatformData (font.fontDescription (), timesStr);
62+ }
63+
64+ FontPlatformData* FontCache::createFontPlatformData (const FontDescription& fontDescription, const AtomicString& family)
65+ {
66+ LOGFONT winfont;
67+
68+ // The size here looks unusual. The negative number is intentional. The logical size constant is 32 and
69+ // is used to make a much larger font so that sub-pixel accuracy can be attained.
70+ winfont.lfHeight = WIN32_FONT_LOGICAL_SCALE * -fontDescription.computedPixelSize ();
71+ winfont.lfWidth = 0 ;
72+ winfont.lfEscapement = 0 ;
73+ winfont.lfOrientation = 0 ;
74+ winfont.lfUnderline = false ;
75+ winfont.lfStrikeOut = false ;
76+ winfont.lfCharSet = DEFAULT_CHARSET;
77+ winfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
78+ winfont.lfQuality = 5 ; // Force cleartype.
79+ winfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
80+ winfont.lfItalic = fontDescription.italic ();
81+ winfont.lfWeight = fontDescription.bold () ? 700 : 400 ; // FIXME: Support weights for real.
82+ int len = min (family.length (), LF_FACESIZE - 1 );
83+ memcpy (winfont.lfFaceName , family.characters (), len * sizeof (WORD));
84+ winfont.lfFaceName [len] = ' \0 ' ;
85+
86+ HFONT hfont = CreateFontIndirect (&winfont);
87+ // Windows will always give us a valid pointer here, even if the face name is non-existent. We have to double-check
88+ // and see if the family name was really used.
89+ HDC dc = GetDC ((HWND)0 );
90+ SaveDC (dc);
91+ SelectObject (dc, hfont);
92+ WCHAR name[LF_FACESIZE];
93+ unsigned resultLength = GetTextFace (dc, LF_FACESIZE, name);
94+ if (resultLength > 0 )
95+ resultLength--; // ignore the null terminator
96+ RestoreDC (dc, -1 );
97+ ReleaseDC (0 , dc);
98+ if (!equalIgnoringCase (family, String (name, resultLength))) {
99+ DeleteObject (hfont);
100+ return 0 ;
101+ }
102+
103+ return new FontPlatformData (hfont, fontDescription.computedPixelSize ());
104+ }
105+
106+ }
0 commit comments