Skip to content

Commit b0fee21

Browse files
author
David Hyatt
committed
Fix win32 bustage.
Canonical link: https://commits.webkit.org/12239@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14512 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 1c2389e commit b0fee21

8 files changed

Lines changed: 287 additions & 18 deletions

File tree

WebCore/ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2006-05-21 Dave Hyatt <hyatt@apple.com>
2+
3+
Fix Win32 bustage. I forgot to add a bunch of files.
4+
Also tweak some existing functions a bit (just cleanup).
5+
6+
* platform/FontCache.cpp:
7+
(WebCore::FontCache::getCachedFontPlatformData):
8+
(WebCore::FontCache::getFontData):
9+
* platform/FontCache.h:
10+
* platform/mac/FontCacheMac.mm:
11+
(WebCore::FontCache::createFontPlatformData):
12+
* platform/win/FontDataWin.cpp:
13+
(WebCore::FontData::platformDestroy):
14+
(WebCore::FontData::smallCapsFontData):
15+
116
2006-05-21 Adele Peterson <adele@apple.com>
217

318
Reviewed by Maciej.

WebCore/platform/FontCache.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCac
9595

9696
static FontPlatformDataCache* gFontPlatformDataCache = 0;
9797

98-
FontPlatformData* FontCache::getCachedFontPlatformData(const Font& font, const AtomicString& familyName)
98+
FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fontDescription,
99+
const AtomicString& familyName)
99100
{
100101
if (!gFontPlatformDataCache) {
101102
gFontPlatformDataCache = new FontPlatformDataCache;
102103
platformInit();
103104
}
104105

105-
const FontDescription& desc = font.fontDescription();
106-
FontPlatformDataCacheKey key(familyName, desc.computedPixelSize(), desc.bold(), desc.italic());
106+
FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.bold(), fontDescription.italic());
107107
FontPlatformData* result = 0;
108108
FontPlatformDataCache::iterator it = gFontPlatformDataCache->find(key);
109109
if (it == gFontPlatformDataCache->end()) {
110-
result = createFontPlatformData(font, familyName);
110+
result = createFontPlatformData(fontDescription, familyName);
111111
gFontPlatformDataCache->set(key, result);
112112
} else
113113
result = it->second;
@@ -174,7 +174,7 @@ const FontData* FontCache::getFontData(const Font& font, int& familyIndex)
174174
while (currFamily && !result) {
175175
familyIndex++;
176176
if (currFamily->family().length())
177-
result = getCachedFontPlatformData(font, currFamily->family());
177+
result = getCachedFontPlatformData(font.fontDescription(), currFamily->family());
178178
currFamily = currFamily->next();
179179
}
180180

WebCore/platform/FontCache.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class AtomicString;
3838
class FontData;
3939
class FontPlatformData;
4040
class Font;
41+
class FontDescription;
4142

4243
class FontCache {
4344
public:
@@ -50,13 +51,13 @@ class FontCache {
5051
static void platformInit();
5152

5253
private:
53-
static FontPlatformData* getCachedFontPlatformData(const Font&, const AtomicString& family);
54+
static FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family);
5455
static FontData* getCachedFontData(const FontPlatformData*);
5556

5657
// These three methods are implemented by each platform.
5758
static FontPlatformData* getSimilarFontPlatformData(const Font&);
5859
static FontPlatformData* getLastResortFallbackFont(const Font&);
59-
static FontPlatformData* createFontPlatformData(const Font&, const AtomicString& family);
60+
static FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
6061

6162
friend class FontData;
6263
friend class FontFallbackList;

WebCore/platform/mac/FontCacheMac.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,27 +196,27 @@ FontPlatformData alternateFont(substituteFont,
196196
return platformFont;
197197
}
198198

199-
FontPlatformData* FontCache::createFontPlatformData(const Font& font, const AtomicString& family)
199+
FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
200200
{
201201
NSFontTraitMask traits = 0;
202-
if (font.italic())
202+
if (fontDescription.italic())
203203
traits |= NSItalicFontMask;
204-
if (font.bold())
204+
if (fontDescription.bold())
205205
traits |= NSBoldFontMask;
206-
float size = font.fontDescription().computedPixelSize();
206+
float size = fontDescription.computedPixelSize();
207207

208208
NSFont* nsFont = [WebFontCache fontWithFamily:family traits:traits size:size];
209209
if (!nsFont)
210210
return 0;
211211

212212
NSFontTraitMask actualTraits = 0;
213-
if (font.bold() || font.italic())
213+
if (fontDescription.bold() || fontDescription.italic())
214214
actualTraits = [[NSFontManager sharedFontManager] traitsOfFont:nsFont];
215215

216216
FontPlatformData* result = new FontPlatformData;
217217

218218
// Use the correct font for print vs. screen.
219-
result->font = font.fontDescription().usePrinterFont() ? [nsFont printerFont] : [nsFont screenFont];
219+
result->font = fontDescription.usePrinterFont() ? [nsFont printerFont] : [nsFont screenFont];
220220
result->syntheticBold = (traits & NSBoldFontMask) && !(actualTraits & NSBoldFontMask);
221221
result->syntheticOblique = (traits & NSItalicFontMask) && !(actualTraits & NSItalicFontMask);
222222
return result;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
}

WebCore/platform/win/FontDataWin.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,14 @@ void FontData::platformInit()
7676

7777
void FontData::platformDestroy()
7878
{
79+
// We don't hash this on Win32, so it's effectively owned by us.
80+
delete m_smallCapsFontData;
7981
}
8082

8183
FontData* FontData::smallCapsFontData(const FontDescription& fontDescription) const
8284
{
83-
if (!m_smallCapsFontData) {
84-
// Need to make this cross-platform instead.
85-
// FIXME: For now just return ourselves.
86-
return (FontData*)this;
87-
}
85+
if (!m_smallCapsFontData)
86+
return this; // FIXME: Implement.
8887
return m_smallCapsFontData;
8988
}
9089

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* This file is part of the internal font implementation. It should not be included by anyone other than
3+
* FontMac.cpp, FontWin.cpp and Font.cpp.
4+
*
5+
* Copyright (C) 2006 Apple Computer, Inc.
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Library General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2 of the License, or (at your option) any later version.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Library General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Library General Public License
18+
* along with this library; see the file COPYING.LIB. If not, write to
19+
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20+
* Boston, MA 02111-1307, USA.
21+
*
22+
*/
23+
24+
#ifndef FontPlatformData_H
25+
#define FontPlatformData_H
26+
27+
#include "StringImpl.h"
28+
29+
typedef struct HFONT__ *HFONT;
30+
typedef struct _cairo_scaled_font cairo_scaled_font_t;
31+
typedef struct _cairo_font_face cairo_font_face_t;
32+
33+
#define WIN32_FONT_LOGICAL_SCALE 32
34+
35+
namespace WebCore {
36+
37+
class FontDescription;
38+
39+
class FontPlatformData
40+
{
41+
public:
42+
class Deleted {};
43+
44+
// Used for deleted values in the font cache's hash tables.
45+
FontPlatformData(Deleted)
46+
: m_font((HFONT)-1), m_fontFace(0), m_scaledFont(0), m_size(0)
47+
{}
48+
49+
FontPlatformData()
50+
: m_font(0), m_fontFace(0), m_scaledFont(0), m_size(0)
51+
{}
52+
53+
FontPlatformData(HFONT, int size);
54+
~FontPlatformData();
55+
56+
HFONT hfont() const { return m_font; }
57+
cairo_font_face_t* fontFace() const { return m_fontFace; }
58+
cairo_scaled_font_t* scaledFont() const { return m_scaledFont; }
59+
60+
int size() const { return m_size; }
61+
62+
unsigned hash() const
63+
{
64+
return StringImpl::computeHash((UChar*)(&m_font), sizeof(HFONT) / sizeof(UChar));
65+
}
66+
67+
bool operator==(const FontPlatformData& other) const
68+
{
69+
return m_font == other.m_font && m_fontFace == other.m_fontFace &&
70+
m_scaledFont == other.m_scaledFont && m_size == other.m_size;
71+
}
72+
73+
private:
74+
HFONT m_font;
75+
cairo_font_face_t* m_fontFace;
76+
cairo_scaled_font_t* m_scaledFont;
77+
int m_size;
78+
};
79+
80+
}
81+
82+
#endif
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 "GlyphMap.h"
31+
#include "FontData.h"
32+
#include <windows.h>
33+
34+
namespace WebCore
35+
{
36+
37+
bool GlyphMap::fillPage(GlyphPage* page, UChar* buffer, unsigned bufferLength, const FontData* fontData)
38+
{
39+
HDC dc = GetDC((HWND)0);
40+
SaveDC(dc);
41+
SelectObject(dc, fontData->m_font.hfont());
42+
43+
TEXTMETRIC tm;
44+
GetTextMetrics(dc, &tm);
45+
if ((tm.tmPitchAndFamily & TMPF_VECTOR) == 0) {
46+
// The "glyph" for a bitmap font is just the character itself.
47+
// FIXME: Need to check character ranges and fill in a glyph of 0 for
48+
// any characters not in range. Otherwise bitmap fonts will never fall
49+
// back.
50+
// IMLangFontLink2::GetFontUnicodeRanges does what we want.
51+
for (unsigned i = 0; i < cGlyphPageSize; i++)
52+
page->setGlyphDataForIndex(i, buffer[i], fontData);
53+
} else {
54+
WORD localGlyphBuffer[cGlyphPageSize];
55+
GetGlyphIndices(dc, buffer, bufferLength, localGlyphBuffer, 0);
56+
57+
for (unsigned i = 0; i < cGlyphPageSize; i++)
58+
page->setGlyphDataForIndex(i, localGlyphBuffer[i], fontData);
59+
}
60+
61+
RestoreDC(dc, -1);
62+
ReleaseDC(0, dc);
63+
return true;
64+
}
65+
66+
}

0 commit comments

Comments
 (0)