Changeset 30441 in webkit
- Timestamp:
- Feb 20, 2008 6:10:56 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 added
- 1 deleted
- 10 edited
- 2 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r30440 r30441 1 2008-02-20 Brent Fulgham <bfulgham@gmail.com> 2 3 Reviewed by Dan. 4 5 http://bugs.webkit.org/show_bug.cgi?id=17336 6 Provide implementations for Windows (Cairo) build of WebKit that 7 handles font formatting. 8 - Split font implementation files to allow maximal code sharing 9 between CG and Cairo back-ends. 10 11 * WebCore.vcproj/WebCore.vcproj: 12 * platform/graphics/SimpleFontData.h: Add signatures for private win 13 initialization functions. 14 * platform/graphics/win/FontCacheWin.cpp: 15 (WebCore::FontCache::platformInit): 16 (WebCore::FontCache::createFontPlatformData): 17 * platform/graphics/win/FontCairoWin.cpp: Removed. Universal version 18 is now part of platform/graphics/cairo. 19 * platform/graphics/win/FontCustomPlatformDataCairo.cpp: Added. 20 (WebCore::FontCustomPlatformDataCairo::~FontCustomPlatformDataCairo): 21 (WebCore::FontCustomPlatformDataCairo::fontPlatformData): 22 (WebCore::releaseData): 23 (WebCore::createFontCustomPlatformData): 24 * platform/graphics/win/FontCustomPlatformDataCairo.h: Added. 25 (WebCore::FontCustomPlatformDataCairo::FontCustomPlatformDataCairo): 26 * platform/graphics/win/FontPlatformData.h: 27 (WebCore::FontPlatformData::FontPlatformData): 28 (WebCore::FontPlatformData::fontFace): 29 (WebCore::FontPlatformData::scaledFont): 30 (WebCore::FontPlatformData::operator==): 31 * platform/graphics/win/FontPlatformDataCGWin.cpp: Copied from WebCore/platform/graphics/win/FontPlatformDataWin.cpp. 32 (WebCore::FontPlatformData::platformDataInit): 33 * platform/graphics/win/FontPlatformDataCairoWin.cpp: Added. 34 (WebCore::FontPlatformData::platformDataInit): 35 (WebCore::FontPlatformData::FontPlatformData): 36 (WebCore::FontPlatformData::setFont): 37 * platform/graphics/win/FontPlatformDataWin.cpp: Moved CG-specific 38 code to FontPlatformDataCG.cpp. 39 (WebCore::FontPlatformData::FontPlatformData): 40 * platform/graphics/win/GlyphPageTreeNodeCGWin.cpp: Copied from WebCore/platform/graphics/win/GlyphPageTreeNodeWin.cpp. 41 * platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp: Copied from WebCore/platform/graphics/win/GlyphPageTreeNodeWin.cpp. 42 (WebCore::GlyphPage::fill): 43 * platform/graphics/win/GlyphPageTreeNodeWin.cpp: Removed. Replaced 44 with CG- and Cairo-specific versions. 45 * platform/graphics/win/SimpleFontDataCGWin.cpp: 46 (WebCore::SimpleFontData::platformInit): 47 (WebCore::SimpleFontData::platformDestroy): 48 (WebCore::SimpleFontData::platformWidthForGlyph): 49 * platform/graphics/win/SimpleFontDataCairoWin.cpp: 50 (WebCore::SimpleFontData::platformInit): 51 (WebCore::SimpleFontData::platformDestroy): 52 (WebCore::SimpleFontData::platformWidthForGlyph): 53 (WebCore::SimpleFontData::setFont): 54 * platform/graphics/win/SimpleFontDataWin.cpp: 55 (WebCore::SimpleFontData::initGDIFont): 56 (WebCore::SimpleFontData::platformCommonDestroy): 57 (WebCore::SimpleFontData::widthForGDIGlyph): 58 1 59 2008-02-20 Darin Adler <darin@apple.com> 2 60 … … 32 90 Consider it an error when a 404 is encountered on a CachedResource load. 33 91 92 >>>>>>> .r30440 34 93 2008-02-20 Anders Carlsson <andersca@apple.com> 35 94 -
trunk/WebCore/WebCore.vcproj/WebCore.vcproj
r30377 r30441 3901 3901 </File> 3902 3902 <File 3903 RelativePath="..\platform\graphics\win\FontPlatformDataCGWin.cpp" 3904 > 3905 </File> 3906 <File 3903 3907 RelativePath="..\platform\graphics\win\FontPlatformDataWin.cpp" 3904 3908 > … … 3933 3937 </File> 3934 3938 <File 3935 RelativePath="..\platform\graphics\win\GlyphPageTreeNode Win.cpp"3939 RelativePath="..\platform\graphics\win\GlyphPageTreeNodeCGWin.cpp" 3936 3940 > 3937 3941 </File> -
trunk/WebCore/platform/graphics/SimpleFontData.h
r30056 r30441 2 2 * This file is part of the internal font implementation. 3 3 * 4 * Copyright (C) 2006 Apple Computer, Inc.4 * Copyright (C) 2006, 2008 Apple Computer, Inc. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 36 36 #if PLATFORM(WIN) 37 37 #include <usp10.h> 38 #endif 39 40 #if PLATFORM(CAIRO) 41 #include <cairo.h> 38 42 #endif 39 43 … … 107 111 #endif 108 112 109 #if PLATFORM( GTK)113 #if PLATFORM(CAIRO) 110 114 void setFont(cairo_t*) const; 111 115 #endif … … 120 124 121 125 void commonInit(); 126 127 #if PLATFORM(WIN) 128 void initGDIFont(); 129 void platformCommonDestroy(); 130 float widthForGDIGlyph(Glyph glyph) const; 131 #endif 122 132 123 133 public: -
trunk/WebCore/platform/graphics/win/FontCacheWin.cpp
r30179 r30441 1 1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 36 36 #include <windows.h> 37 37 #include <mlang.h> 38 #if PLATFORM(CG) 38 39 #include <ApplicationServices/ApplicationServices.h> 39 40 #include <WebKitSystemInterface/WebKitSystemInterface.h> 41 #endif 40 42 41 43 using std::min; … … 46 48 void FontCache::platformInit() 47 49 { 50 #if PLATFORM(CG) 48 51 wkSetUpFontCache(1536 * 1024 * 4); // This size matches Mac. 52 #endif 49 53 } 50 54 … … 415 419 FontPlatformData* result = new FontPlatformData(hfont, fontDescription.computedPixelSize(), 416 420 fontDescription.bold(), fontDescription.italic(), useGDI); 417 if (!result->cgFont()) { 421 422 #if PLATFORM(CG) 423 bool fontCreationFailed = !result->cgFont(); 424 #elif PLATFORM(CAIRO) 425 bool fontCreationFailed = !result->fontFace(); 426 #endif 427 428 if (fontCreationFailed) { 418 429 // The creation of the CGFontRef failed for some reason. We already asserted in debug builds, but to make 419 430 // absolutely sure that we don't use this font, go ahead and return 0 so that we can fall back to the next -
trunk/WebCore/platform/graphics/win/FontCustomPlatformData.h
r28251 r30441 33 33 struct FontCustomPlatformData : Noncopyable { 34 34 FontCustomPlatformData(CGFontRef cgFont) 35 : m_cgFont(cgFont) 36 {} 35 : m_cgFont(cgFont) 36 { 37 } 37 38 ~FontCustomPlatformData(); 38 39 … … 42 43 }; 43 44 44 FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer);45 FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer*); 45 46 46 47 } -
trunk/WebCore/platform/graphics/win/FontPlatformData.h
r29700 r30441 3 3 * FontMac.cpp, FontWin.cpp and Font.cpp. 4 4 * 5 * Copyright (C) 2006, 2007 Apple Inc.5 * Copyright (C) 2006, 2007, 2008 Apple Inc. 6 6 * 7 7 * This library is free software; you can redistribute it and/or … … 27 27 #include "StringImpl.h" 28 28 29 typedef struct HFONT__ *HFONT; 30 typedef struct CGFont *CGFontRef; 29 #if PLATFORM(CAIRO) 30 #include <cairo-win32.h> 31 #endif 32 33 typedef struct HFONT__* HFONT; 34 typedef struct CGFont* CGFontRef; 31 35 32 36 namespace WebCore { … … 41 45 // Used for deleted values in the font cache's hash tables. 42 46 FontPlatformData(Deleted) 43 : m_font((HFONT)-1) 44 , m_cgFont(NULL) 45 , m_size(0) 46 , m_syntheticBold(false) 47 , m_syntheticOblique(false) 48 , m_useGDI(false) 49 {} 47 : m_font((HFONT)-1) 48 #if PLATFORM(CG) 49 , m_cgFont(0) 50 #elif PLATFORM(CAIRO) 51 , m_fontFace(0) 52 #endif 53 , m_size(0) 54 , m_syntheticBold(false) 55 , m_syntheticOblique(false) 56 , m_useGDI(false) 57 { 58 } 50 59 51 60 FontPlatformData() 52 : m_font(0) 53 , m_cgFont(NULL) 54 , m_size(0) 55 , m_syntheticBold(false) 56 , m_syntheticOblique(false) 57 , m_useGDI(false) 58 {} 61 : m_font(0) 62 #if PLATFORM(CG) 63 , m_cgFont(0) 64 #elif PLATFORM(CAIRO) 65 , m_fontFace(0) 66 #endif 67 , m_size(0) 68 , m_syntheticBold(false) 69 , m_syntheticOblique(false) 70 , m_useGDI(false) 71 { 72 } 59 73 60 74 FontPlatformData(HFONT, float size, bool bold, bool oblique, bool useGDI); 61 75 FontPlatformData(float size, bool bold, bool oblique); 76 77 #if PLATFORM(CG) 62 78 FontPlatformData(CGFontRef, float size, bool bold, bool oblique); 79 #elif PLATFORM(CAIRO) 80 FontPlatformData(cairo_font_face_t*, float size, bool bold, bool oblique); 81 #endif 63 82 ~FontPlatformData(); 64 83 84 void platformDataInit(HFONT font, float size, HDC hdc, WCHAR* faceName); 85 65 86 HFONT hfont() const { return m_font; } 87 #if PLATFORM(CG) 66 88 CGFontRef cgFont() const { return m_cgFont; } 89 #elif PLATFORM(CAIRO) 90 void setFont(cairo_t* ft) const; 91 cairo_font_face_t* fontFace() const { return m_fontFace; } 92 cairo_scaled_font_t* scaledFont() const { return m_scaledFont; } 93 #endif 67 94 68 95 float size() const { return m_size; } … … 79 106 bool operator==(const FontPlatformData& other) const 80 107 { 81 return m_font == other.m_font && m_cgFont ==other.m_cgFont && m_size == other.m_size && 108 return m_font == other.m_font && 109 #if PLATFORM(CG) 110 m_cgFont == other.m_cgFont && 111 #elif PLATFORM(CAIRO) 112 m_fontFace == other.m_fontFace && 113 m_scaledFont == other.m_scaledFont && 114 #endif 115 m_size == other.m_size && 82 116 m_syntheticBold == other.m_syntheticBold && m_syntheticOblique == other.m_syntheticOblique && 83 117 m_useGDI == other.m_useGDI; … … 86 120 private: 87 121 HFONT m_font; 122 #if PLATFORM(CG) 88 123 CGFontRef m_cgFont; 124 #elif PLATFORM(CAIRO) 125 cairo_font_face_t* m_fontFace; 126 cairo_scaled_font_t* m_scaledFont; 127 #endif 89 128 90 129 float m_size; -
trunk/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp
r30434 r30441 3 3 * FontMac.cpp, FontWin.cpp and Font.cpp. 4 4 * 5 * Copyright (C) 2006, 2007 Apple Inc.5 * Copyright (C) 2006, 2007, 2008 Apple Inc. 6 6 * 7 7 * This library is free software; you can redistribute it and/or … … 35 35 36 36 namespace WebCore { 37 38 static const int Bold = (1 << 0);39 static const int Italic = (1 << 1);40 static const int BoldOblique = (1 << 2);41 37 42 38 static inline USHORT readBigEndianWord(const BYTE* word) { return (word[0] << 8) | word[1]; } … … 111 107 } 112 108 113 static int CALLBACK enumStylesCallback(const LOGFONT* logFont, const TEXTMETRIC* metrics, DWORD fontType, LPARAM lParam)109 void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR* faceName) 114 110 { 115 int *style = reinterpret_cast<int*>(lParam); 116 117 // FIXME: In order to accommodate Lucida we go ahead and consider a weight of 600 to be bold. 118 // This does mean we'll consider demibold and semibold fonts on windows to also be bold. This 119 // is rare enough that it seems like an ok hack for now. 120 if (logFont->lfWeight >= 600) { 121 if (logFont->lfItalic) 122 *style |= BoldOblique; 123 else 124 *style |= Bold; 125 } else if (logFont->lfItalic) 126 *style |= Italic; 127 128 return 1; 129 } 130 131 FontPlatformData::FontPlatformData(HFONT font, float size, bool bold, bool oblique, bool useGDI) 132 : m_font(font) 133 , m_size(size) 134 , m_cgFont(0) 135 , m_syntheticBold(false) 136 , m_syntheticOblique(false) 137 , m_useGDI(useGDI) 138 { 139 HDC hdc = GetDC(0); 140 SaveDC(hdc); 141 142 SelectObject(hdc, font); 143 UINT bufferSize = GetOutlineTextMetrics(hdc, 0, NULL); 144 145 ASSERT_WITH_MESSAGE(bufferSize != 0, "Bitmap fonts not supported with CoreGraphics."); 146 147 if (bufferSize != 0) { 148 OUTLINETEXTMETRICW* metrics = (OUTLINETEXTMETRICW*)malloc(bufferSize); 149 150 GetOutlineTextMetricsW(hdc, bufferSize, metrics); 151 WCHAR* faceName = (WCHAR*)((uintptr_t)metrics + (uintptr_t)metrics->otmpFaceName); 152 153 if (!useGDI && (bold || oblique)) { 154 LOGFONT logFont; 155 156 int len = min((int)wcslen(faceName), LF_FACESIZE - 1); 157 memcpy(logFont.lfFaceName, faceName, len * sizeof(WORD)); 158 logFont.lfFaceName[len] = '\0'; 159 logFont.lfCharSet = metrics->otmTextMetrics.tmCharSet; 160 logFont.lfPitchAndFamily = 0; 161 162 int styles = 0; 163 EnumFontFamiliesEx(hdc, &logFont, enumStylesCallback, reinterpret_cast<LPARAM>(&styles), 0); 164 165 // Check if we need to synthesize bold or oblique. The rule that complicates things here 166 // is that if the requested font is bold and oblique, and both a bold font and an oblique font 167 // exist, the bold font should be used, and oblique synthesized. 168 if (bold && oblique) { 169 if (styles == 0) { 170 m_syntheticBold = true; 171 m_syntheticOblique = true; 172 } else if (styles & Bold) 173 m_syntheticOblique = true; 174 else if (styles & Italic) 175 m_syntheticBold = true; 176 } else if (bold && (!(styles & Bold))) 177 m_syntheticBold = true; 178 else if (oblique && !(styles & Italic)) 179 m_syntheticOblique = true; 111 // Try the face name first. Windows may end up localizing this name, and CG doesn't know about 112 // the localization. If the create fails, we'll try the PostScript name. 113 RetainPtr<CFStringRef> fullName(AdoptCF, CFStringCreateWithCharacters(NULL, (const UniChar*)faceName, wcslen(faceName))); 114 m_cgFont = CGFontCreateWithFontName(fullName.get()); 115 if (!m_cgFont) { 116 CFStringRef postScriptName = getPostScriptName(fullName.get(), hdc); 117 if (postScriptName) { 118 m_cgFont = CGFontCreateWithFontName(postScriptName); 119 ASSERT(m_cgFont); 180 120 } 181 182 // Try the face name first. Windows may end up localizing this name, and CG doesn't know about183 // the localization. If the create fails, we'll try the PostScript name.184 RetainPtr<CFStringRef> fullName(AdoptCF, CFStringCreateWithCharacters(NULL, (const UniChar*)faceName, wcslen(faceName)));185 m_cgFont = CGFontCreateWithFontName(fullName.get());186 if (!m_cgFont) {187 CFStringRef postScriptName = getPostScriptName(fullName.get(), hdc);188 if (postScriptName) {189 m_cgFont = CGFontCreateWithFontName(postScriptName);190 ASSERT(m_cgFont);191 }192 }193 free(metrics);194 121 } 195 196 RestoreDC(hdc, -1);197 ReleaseDC(0, hdc);198 }199 200 FontPlatformData::FontPlatformData(float size, bool bold, bool oblique)201 : m_font(0)202 , m_size(size)203 , m_cgFont(0)204 , m_syntheticBold(bold)205 , m_syntheticOblique(oblique)206 , m_useGDI(false)207 {208 122 } 209 123 … … 218 132 } 219 133 220 FontPlatformData::~FontPlatformData()221 {222 134 } 223 224 } -
trunk/WebCore/platform/graphics/win/FontPlatformDataWin.cpp
r29700 r30441 3 3 * FontMac.cpp, FontWin.cpp and Font.cpp. 4 4 * 5 * Copyright (C) 2006, 2007 Apple Inc. 5 * Copyright (C) 2006, 2007, 2008 Apple Inc. 6 * Copyright (C) 2008 Brent Fulgham 6 7 * 7 8 * This library is free software; you can redistribute it and/or … … 27 28 #include "PlatformString.h" 28 29 #include "StringHash.h" 29 #include <ApplicationServices/ApplicationServices.h>30 30 #include <wtf/HashMap.h> 31 31 #include <wtf/RetainPtr.h> … … 39 39 static const int Italic = (1 << 1); 40 40 static const int BoldOblique = (1 << 2); 41 42 static inline USHORT readBigEndianWord(const BYTE* word) { return (word[0] << 8) | word[1]; }43 44 static CFStringRef getPostScriptName(CFStringRef faceName, HDC dc)45 {46 const DWORD cMaxNameTableSize = 1024 * 1024;47 48 static HashMap<String, RetainPtr<CFStringRef> > nameMap;49 50 // Check our hash first.51 String faceString(faceName);52 RetainPtr<CFStringRef> result = nameMap.get(faceString);53 if (result)54 return result.get();55 56 // We need to obtain the PostScript name from the name table and use it instead,.57 DWORD bufferSize = GetFontData(dc, 'eman', 0, NULL, 0); // "name" backwards58 if (bufferSize == 0 || bufferSize == GDI_ERROR || bufferSize > cMaxNameTableSize)59 return NULL;60 61 Vector<BYTE> bufferVector(bufferSize);62 BYTE* buffer = bufferVector.data();63 if (GetFontData(dc, 'eman', 0, buffer, bufferSize) == GDI_ERROR)64 return NULL;65 66 if (bufferSize < 6)67 return NULL;68 69 USHORT numberOfRecords = readBigEndianWord(buffer + 2);70 UINT stringsOffset = readBigEndianWord(buffer + 4);71 if (bufferSize < stringsOffset)72 return NULL;73 74 BYTE* strings = buffer + stringsOffset;75 76 // Now walk each name record looking for a Mac or Windows PostScript name.77 UINT offset = 6;78 for (int i = 0; i < numberOfRecords; i++) {79 if (bufferSize < offset + 12)80 return NULL;81 82 USHORT platformID = readBigEndianWord(buffer + offset);83 USHORT encodingID = readBigEndianWord(buffer + offset + 2);84 USHORT languageID = readBigEndianWord(buffer + offset + 4);85 USHORT nameID = readBigEndianWord(buffer + offset + 6);86 USHORT length = readBigEndianWord(buffer + offset + 8);87 USHORT nameOffset = readBigEndianWord(buffer + offset + 10);88 89 if (platformID == 3 && encodingID == 1 && languageID == 0x409 && nameID == 6) {90 // This is a Windows PostScript name and is therefore UTF-16.91 // Pass Big Endian as the encoding.92 if (bufferSize < stringsOffset + nameOffset + length)93 return NULL;94 result.adoptCF(CFStringCreateWithBytes(NULL, strings + nameOffset, length, kCFStringEncodingUTF16BE, false));95 break;96 } else if (platformID == 1 && encodingID == 0 && languageID == 0 && nameID == 6) {97 // This is a Mac PostScript name and is therefore ASCII.98 // See http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6name.html99 if (bufferSize < stringsOffset + nameOffset + length)100 return NULL;101 result.adoptCF(CFStringCreateWithBytes(NULL, strings + nameOffset, length, kCFStringEncodingASCII, false));102 break;103 }104 105 offset += 12;106 }107 108 if (result)109 nameMap.set(faceString, result);110 return result.get();111 }112 41 113 42 static int CALLBACK enumStylesCallback(const LOGFONT* logFont, const TEXTMETRIC* metrics, DWORD fontType, LPARAM lParam) … … 132 61 : m_font(font) 133 62 , m_size(size) 63 #if PLATFORM(CG) 134 64 , m_cgFont(0) 65 #elif PLATFORM(CAIRO) 66 , m_fontFace(0) 67 , m_scaledFont(0) 68 #endif 135 69 , m_syntheticBold(false) 136 70 , m_syntheticOblique(false) … … 180 114 } 181 115 182 // Try the face name first. Windows may end up localizing this name, and CG doesn't know about 183 // the localization. If the create fails, we'll try the PostScript name. 184 RetainPtr<CFStringRef> fullName(AdoptCF, CFStringCreateWithCharacters(NULL, (const UniChar*)faceName, wcslen(faceName))); 185 m_cgFont = CGFontCreateWithFontName(fullName.get()); 186 if (!m_cgFont) { 187 CFStringRef postScriptName = getPostScriptName(fullName.get(), hdc); 188 if (postScriptName) { 189 m_cgFont = CGFontCreateWithFontName(postScriptName); 190 ASSERT(m_cgFont); 191 } 192 } 116 platformDataInit(font, size, hdc, faceName); 117 193 118 free(metrics); 194 119 } … … 201 126 : m_font(0) 202 127 , m_size(size) 128 #if PLATFORM(CG) 203 129 , m_cgFont(0) 204 , m_syntheticBold(bold) 205 , m_syntheticOblique(oblique) 206 , m_useGDI(false) 207 { 208 } 209 210 FontPlatformData::FontPlatformData(CGFontRef font, float size, bool bold, bool oblique) 211 : m_font(0) 212 , m_size(size) 213 , m_cgFont(font) 130 #elif PLATFORM(CAIRO) 131 , m_fontFace(0) 132 , m_scaledFont(0) 133 #endif 214 134 , m_syntheticBold(bold) 215 135 , m_syntheticOblique(oblique) -
trunk/WebCore/platform/graphics/win/GlyphPageTreeNodeCGWin.cpp
r30434 r30441 1 1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without -
trunk/WebCore/platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp
r30434 r30441 1 1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 31 31 32 32 #include "SimpleFontData.h" 33 #include <WebKitSystemInterface/WebKitSystemInterface.h>34 33 35 34 namespace WebCore { … … 43 42 44 43 bool haveGlyphs = false; 45 CGGlyph localGlyphBuffer[GlyphPage::size]; 46 wkGetGlyphs(fontData->platformData().cgFont(), buffer, localGlyphBuffer, bufferLength); 47 for (unsigned i = 0; i < length; i++) { 48 Glyph glyph = localGlyphBuffer[i]; 49 if (!glyph) 50 setGlyphDataForIndex(offset + i, 0, 0); 51 else { 52 setGlyphDataForIndex(offset + i, glyph, fontData); 53 haveGlyphs = true; 44 45 HDC dc = GetDC((HWND)0); 46 SaveDC(dc); 47 SelectObject(dc, fontData->platformData().hfont()); 48 49 TEXTMETRIC tm; 50 GetTextMetrics(dc, &tm); 51 52 WORD localGlyphBuffer[GlyphPage::size * 2]; 53 DWORD result = GetGlyphIndices(dc, buffer, bufferLength, localGlyphBuffer, 0); 54 bool success = result != GDI_ERROR && static_cast<unsigned>(result) == bufferLength; 55 if (success) { 56 for (unsigned i = 0; i < length; i++) { 57 Glyph glyph = localGlyphBuffer[i]; 58 if (!glyph) 59 setGlyphDataForIndex(offset + i, 0, 0); 60 else { 61 setGlyphDataForIndex(offset + i, glyph, fontData); 62 haveGlyphs = true; 63 } 54 64 } 55 65 } 66 RestoreDC(dc, -1); 67 ReleaseDC(0, dc); 68 56 69 return haveGlyphs; 57 70 } -
trunk/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp
r30056 r30441 55 55 m_scriptFontProperties = 0; 56 56 m_isSystemFont = false; 57 58 if (m_font.useGDI()) {59 HDC hdc = GetDC(0);60 HGDIOBJ oldFont = SelectObject(hdc, m_font.hfont());61 OUTLINETEXTMETRIC metrics;62 GetOutlineTextMetrics(hdc, sizeof(metrics), &metrics);63 TEXTMETRIC& textMetrics = metrics.otmTextMetrics;64 m_ascent = textMetrics.tmAscent;65 m_descent = textMetrics.tmDescent;66 m_lineGap = textMetrics.tmExternalLeading;67 m_lineSpacing = m_ascent + m_descent + m_lineGap;68 m_xHeight = m_ascent * 0.56f; // Best guess for xHeight if no x glyph is present.69 57 70 GLYPHMETRICS gm; 71 MAT2 mat = { 1, 0, 0, 1 }; 72 DWORD len = GetGlyphOutline(hdc, 'x', GGO_METRICS, &gm, 0, 0, &mat); 73 if (len != GDI_ERROR && gm.gmptGlyphOrigin.y > 0) 74 m_xHeight = gm.gmptGlyphOrigin.y; 75 76 m_unitsPerEm = metrics.otmEMSquare; 77 78 SelectObject(hdc, oldFont); 79 ReleaseDC(0, hdc); 80 81 return; 82 } 58 if (m_font.useGDI()) 59 return initGDIFont(); 83 60 84 61 CGFontRef font = m_font.cgFont(); … … 145 122 } 146 123 147 // We don't hash this on Win32, so it's effectively owned by us. 148 delete m_smallCapsFontData; 149 150 ScriptFreeCache(&m_scriptCache); 151 delete m_scriptFontProperties; 124 platformCommonDestroy(); 152 125 } 153 126 154 127 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const 155 128 { 156 if (m_font.useGDI()) { 157 HDC hdc = GetDC(0); 158 HGDIOBJ oldFont = SelectObject(hdc, m_font.hfont()); 159 int width; 160 GetCharWidthI(hdc, glyph, 1, 0, &width); 161 SelectObject(hdc, oldFont); 162 ReleaseDC(0, hdc); 163 return width; 164 } 129 if (m_font.useGDI()) 130 return widthForGDIGlyph(glyph); 165 131 166 132 CGFontRef font = m_font.cgFont(); -
trunk/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp
r30056 r30441 35 35 #include "FontCache.h" 36 36 #include "FontDescription.h" 37 #include "MathExtras.h" 37 38 #include "NotImplemented.h" 39 #include <cairo.h> 40 #include <cairo-win32.h> 38 41 #include <mlang.h> 39 42 #include <tchar.h> … … 46 49 m_scriptFontProperties = 0; 47 50 m_isSystemFont = false; 48 49 if (m_font.useGDI()) {50 HDC hdc = GetDC(0);51 HGDIOBJ oldFont = SelectObject(hdc, m_font.hfont());52 OUTLINETEXTMETRIC metrics;53 GetOutlineTextMetrics(hdc, sizeof(metrics), &metrics);54 TEXTMETRIC& textMetrics = metrics.otmTextMetrics;55 m_ascent = textMetrics.tmAscent;56 m_descent = textMetrics.tmDescent;57 m_lineGap = textMetrics.tmExternalLeading;58 m_lineSpacing = m_ascent + m_descent + m_lineGap;59 m_xHeight = m_ascent * 0.56f; // Best guess for xHeight if no x glyph is present.60 51 52 if (m_font.useGDI()) 53 return initGDIFont(); 54 55 HDC hdc = GetDC(0); 56 SaveDC(hdc); 57 58 cairo_scaled_font_t* scaledFont = m_font.scaledFont(); 59 const double metricsMultiplier = cairo_win32_scaled_font_get_metrics_factor(scaledFont) * m_font.size(); 60 61 cairo_win32_scaled_font_select_font(scaledFont, hdc); 62 63 TEXTMETRIC textMetrics; 64 GetTextMetrics(hdc, &textMetrics); 65 m_ascent = lroundf(textMetrics.tmAscent * metricsMultiplier); 66 m_descent = lroundf(textMetrics.tmDescent * metricsMultiplier); 67 m_xHeight = m_ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts. 68 m_lineGap = lroundf(textMetrics.tmExternalLeading * metricsMultiplier); 69 m_lineSpacing = m_ascent + m_descent + m_lineGap; 70 71 OUTLINETEXTMETRIC metrics; 72 if (GetOutlineTextMetrics(hdc, sizeof(metrics), &metrics) > 0) { 73 // This is a TrueType font. We might be able to get an accurate xHeight 61 74 GLYPHMETRICS gm; 62 75 MAT2 mat = { 1, 0, 0, 1 }; 63 76 DWORD len = GetGlyphOutline(hdc, 'x', GGO_METRICS, &gm, 0, 0, &mat); 64 77 if (len != GDI_ERROR && gm.gmptGlyphOrigin.y > 0) 65 m_xHeight = gm.gmptGlyphOrigin.y; 66 67 m_unitsPerEm = metrics.otmEMSquare; 68 69 SelectObject(hdc, oldFont); 70 ReleaseDC(0, hdc); 71 72 return; 78 m_xHeight = gm.gmptGlyphOrigin.y * metricsMultiplier; 73 79 } 74 80 75 // FIXME: This section should determine font dimensions (see CG implementation). 76 notImplemented(); 81 cairo_win32_scaled_font_done_font(scaledFont); 82 83 m_isSystemFont = false; 84 m_scriptCache = 0; 85 m_scriptFontProperties = 0; 86 87 RestoreDC(hdc, -1); 88 ReleaseDC(0, hdc); 77 89 } 78 90 79 91 void SimpleFontData::platformDestroy() 80 92 { 81 notImplemented(); 93 cairo_font_face_destroy(m_font.fontFace()); 94 cairo_scaled_font_destroy(m_font.scaledFont()); 95 96 DeleteObject(m_font.hfont()); 97 98 platformCommonDestroy(); 82 99 } 83 100 84 101 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const 85 102 { 86 if (m_font.useGDI()) { 87 HDC hdc = GetDC(0); 88 HGDIOBJ oldFont = SelectObject(hdc, m_font.hfont()); 89 int width; 90 GetCharWidthI(hdc, glyph, 1, 0, &width); 91 SelectObject(hdc, oldFont); 92 ReleaseDC(0, hdc); 93 return width; 94 } 103 if (m_font.useGDI()) 104 return widthForGDIGlyph(glyph); 95 105 96 // FIXME: Flesh out with Cairo/win32 font implementation97 notImplemented();106 HDC hdc = GetDC(0); 107 SaveDC(hdc); 98 108 99 return 0; 109 cairo_scaled_font_t* scaledFont = m_font.scaledFont(); 110 cairo_win32_scaled_font_select_font(scaledFont, hdc); 111 112 int width; 113 GetCharWidthI(hdc, glyph, 1, 0, &width); 114 115 cairo_win32_scaled_font_done_font(scaledFont); 116 117 RestoreDC(hdc, -1); 118 ReleaseDC(0, hdc); 119 120 const double metricsMultiplier = cairo_win32_scaled_font_get_metrics_factor(scaledFont) * m_font.size(); 121 return width * metricsMultiplier; 122 } 123 124 void SimpleFontData::setFont(cairo_t* cr) const 125 { 126 ASSERT(cr); 127 m_font.setFont(cr); 100 128 } 101 129 -
trunk/WebCore/platform/graphics/win/SimpleFontDataWin.cpp
r30056 r30441 61 61 } 62 62 63 void SimpleFontData::initGDIFont() 64 { 65 HDC hdc = GetDC(0); 66 HGDIOBJ oldFont = SelectObject(hdc, m_font.hfont()); 67 OUTLINETEXTMETRIC metrics; 68 GetOutlineTextMetrics(hdc, sizeof(metrics), &metrics); 69 TEXTMETRIC& textMetrics = metrics.otmTextMetrics; 70 m_ascent = textMetrics.tmAscent; 71 m_descent = textMetrics.tmDescent; 72 m_lineGap = textMetrics.tmExternalLeading; 73 m_lineSpacing = m_ascent + m_descent + m_lineGap; 74 m_xHeight = m_ascent * 0.56f; // Best guess for xHeight if no x glyph is present. 75 76 GLYPHMETRICS gm; 77 MAT2 mat = { 1, 0, 0, 1 }; 78 DWORD len = GetGlyphOutline(hdc, 'x', GGO_METRICS, &gm, 0, 0, &mat); 79 if (len != GDI_ERROR && gm.gmptGlyphOrigin.y > 0) 80 m_xHeight = gm.gmptGlyphOrigin.y; 81 82 m_unitsPerEm = metrics.otmEMSquare; 83 84 SelectObject(hdc, oldFont); 85 ReleaseDC(0, hdc); 86 87 return; 88 } 89 90 void SimpleFontData::platformCommonDestroy() 91 { 92 // We don't hash this on Win32, so it's effectively owned by us. 93 delete m_smallCapsFontData; 94 95 ScriptFreeCache(&m_scriptCache); 96 delete m_scriptFontProperties; 97 } 98 63 99 SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const 64 100 { … … 138 174 } 139 175 176 float SimpleFontData::widthForGDIGlyph(Glyph glyph) const 177 { 178 HDC hdc = GetDC(0); 179 HGDIOBJ oldFont = SelectObject(hdc, m_font.hfont()); 180 int width; 181 GetCharWidthI(hdc, glyph, 1, 0, &width); 182 SelectObject(hdc, oldFont); 183 ReleaseDC(0, hdc); 184 return width; 185 } 186 140 187 SCRIPT_FONTPROPERTIES* SimpleFontData::scriptFontProperties() const 141 188 {
Note: See TracChangeset
for help on using the changeset viewer.