Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp

Issue 13642009: WebCore: Remove PLATFORM(WIN) files we do not use. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * This file is part of the internal font implementation. It should not be inclu ded by anyone other than
3 * FontMac.cpp, FontWin.cpp and Font.cpp.
4 *
5 * Copyright (C) 2006, 2007, 2008, 2009 Apple 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., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24 #include "config.h"
25 #include "FontPlatformData.h"
26
27 #include <ApplicationServices/ApplicationServices.h>
28 #include <WebKitSystemInterface/WebKitSystemInterface.h>
29 #include <wtf/HashMap.h>
30 #include <wtf/RetainPtr.h>
31 #include <wtf/Vector.h>
32 #include <wtf/text/StringHash.h>
33 #include <wtf/text/WTFString.h>
34
35 using std::min;
36
37 namespace WebCore {
38
39 static inline USHORT readBigEndianWord(const BYTE* word) { return (word[0] << 8) | word[1]; }
40
41 static CFStringRef getPostScriptName(CFStringRef faceName, HDC dc)
42 {
43 const DWORD cMaxNameTableSize = 1024 * 1024;
44
45 static HashMap<String, RetainPtr<CFStringRef> > nameMap;
46
47 // Check our hash first.
48 String faceString(faceName);
49 RetainPtr<CFStringRef> result = nameMap.get(faceString);
50 if (result)
51 return result.get();
52
53 // We need to obtain the PostScript name from the name table and use it inst ead,.
54 DWORD bufferSize = GetFontData(dc, 'eman', 0, NULL, 0); // "name" backwards
55 if (bufferSize == 0 || bufferSize == GDI_ERROR || bufferSize > cMaxNameTable Size)
56 return NULL;
57
58 Vector<BYTE> bufferVector(bufferSize);
59 BYTE* buffer = bufferVector.data();
60 if (GetFontData(dc, 'eman', 0, buffer, bufferSize) == GDI_ERROR)
61 return NULL;
62
63 if (bufferSize < 6)
64 return NULL;
65
66 USHORT numberOfRecords = readBigEndianWord(buffer + 2);
67 UINT stringsOffset = readBigEndianWord(buffer + 4);
68 if (bufferSize < stringsOffset)
69 return NULL;
70
71 BYTE* strings = buffer + stringsOffset;
72
73 // Now walk each name record looking for a Mac or Windows PostScript name.
74 UINT offset = 6;
75 for (int i = 0; i < numberOfRecords; i++) {
76 if (bufferSize < offset + 12)
77 return NULL;
78
79 USHORT platformID = readBigEndianWord(buffer + offset);
80 USHORT encodingID = readBigEndianWord(buffer + offset + 2);
81 USHORT languageID = readBigEndianWord(buffer + offset + 4);
82 USHORT nameID = readBigEndianWord(buffer + offset + 6);
83 USHORT length = readBigEndianWord(buffer + offset + 8);
84 USHORT nameOffset = readBigEndianWord(buffer + offset + 10);
85
86 if (platformID == 3 && encodingID == 1 && languageID == 0x409 && nameID == 6) {
87 // This is a Windows PostScript name and is therefore UTF-16.
88 // Pass Big Endian as the encoding.
89 if (bufferSize < stringsOffset + nameOffset + length)
90 return NULL;
91 result.adoptCF(CFStringCreateWithBytes(NULL, strings + nameOffset, l ength, kCFStringEncodingUTF16BE, false));
92 break;
93 } else if (platformID == 1 && encodingID == 0 && languageID == 0 && name ID == 6) {
94 // This is a Mac PostScript name and is therefore ASCII.
95 // See http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6name. html
96 if (bufferSize < stringsOffset + nameOffset + length)
97 return NULL;
98 result.adoptCF(CFStringCreateWithBytes(NULL, strings + nameOffset, l ength, kCFStringEncodingASCII, false));
99 break;
100 }
101
102 offset += 12;
103 }
104
105 if (result)
106 nameMap.set(faceString, result);
107 return result.get();
108 }
109
110 void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR* faceName)
111 {
112 LOGFONT logfont;
113 GetObject(font, sizeof(logfont), &logfont);
114 m_cgFont.adoptCF(CGFontCreateWithPlatformFont(&logfont));
115 }
116
117 FontPlatformData::FontPlatformData(HFONT hfont, CGFontRef font, float size, bool bold, bool oblique, bool useGDI)
118 : m_syntheticBold(bold)
119 , m_syntheticOblique(oblique)
120 , m_orientation(Horizontal)
121 , m_size(size)
122 , m_widthVariant(RegularWidth)
123 , m_font(RefCountedGDIHandle<HFONT>::create(hfont))
124 , m_cgFont(font)
125 , m_isColorBitmapFont(false)
126 , m_useGDI(useGDI)
127 {
128 }
129
130 FontPlatformData::~FontPlatformData()
131 {
132 }
133
134 void FontPlatformData::platformDataInit(const FontPlatformData& source)
135 {
136 m_font = source.m_font;
137 m_cgFont = source.m_cgFont;
138 m_useGDI = source.m_useGDI;
139 }
140
141 const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformD ata& other)
142 {
143 m_font = other.m_font;
144 m_cgFont = other.m_cgFont;
145 m_useGDI = other.m_useGDI;
146
147 return *this;
148 }
149
150 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const
151 {
152 return m_font == other.m_font
153 && m_cgFont == other.m_cgFont
154 && m_useGDI == other.m_useGDI;
155 }
156
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698