Skip to content

Commit 8a0aee6

Browse files
committed
[Win] Add tests for linked fonts.
https://bugs.webkit.org/show_bug.cgi?id=160898 Reviewed by Brent Fulgham. Add tests for https://trac.webkit.org/changeset/204502. Source/WebCore: * platform/graphics/win/FontCacheWin.cpp: (WebCore::appendLinkedFonts): (WebCore::getLinkedFonts): Tools: * TestWebKitAPI/PlatformWin.cmake: * TestWebKitAPI/Tests/WebCore/win/LinkedFonts.cpp: Added. (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/179054@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204558 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent a29291b commit 8a0aee6

5 files changed

Lines changed: 110 additions & 15 deletions

File tree

Source/WebCore/ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2016-08-17 Per Arne Vollan <[email protected]>
2+
3+
[Win] Add tests for linked fonts.
4+
https://bugs.webkit.org/show_bug.cgi?id=160898
5+
6+
Reviewed by Brent Fulgham.
7+
8+
Add tests for https://trac.webkit.org/changeset/204502.
9+
10+
* platform/graphics/win/FontCacheWin.cpp:
11+
(WebCore::appendLinkedFonts):
12+
(WebCore::getLinkedFonts):
13+
114
2016-08-17 Carlos Garcia Campos <[email protected]>
215

316
Unreviewed. Fix GObject DOM bindings API break after r204449, r204450 and r204451.

Source/WebCore/platform/graphics/win/FontCacheWin.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ static int CALLBACK linkedFontEnumProc(CONST LOGFONT* logFont, CONST TEXTMETRIC*
9696
return false;
9797
}
9898

99+
WEBCORE_EXPORT void appendLinkedFonts(WCHAR* linkedFonts, unsigned length, Vector<String>* result)
100+
{
101+
unsigned i = 0;
102+
while (i < length) {
103+
while (i < length && linkedFonts[i] != ',')
104+
i++;
105+
// Break if we did not find a comma.
106+
if (i == length)
107+
break;
108+
i++;
109+
unsigned j = i;
110+
while (j < length && linkedFonts[j])
111+
j++;
112+
result->append(String(linkedFonts + i, j - i));
113+
i = j + 1;
114+
}
115+
}
116+
99117
static const Vector<String>* getLinkedFonts(String& family)
100118
{
101119
static HashMap<String, Vector<String>*> systemLinkMap;
@@ -106,7 +124,7 @@ static const Vector<String>* getLinkedFonts(String& family)
106124
result = new Vector<String>;
107125
systemLinkMap.set(family, result);
108126
HKEY fontLinkKey = nullptr;
109-
if (FAILED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\FontLink\\SystemLink", 0, KEY_READ, &fontLinkKey)))
127+
if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\FontLink\\SystemLink", 0, KEY_READ, &fontLinkKey) != ERROR_SUCCESS)
110128
return result;
111129

112130
DWORD linkedFontsBufferSize = 0;
@@ -117,21 +135,8 @@ static const Vector<String>* getLinkedFonts(String& family)
117135

118136
WCHAR* linkedFonts = reinterpret_cast<WCHAR*>(malloc(linkedFontsBufferSize));
119137
if (::RegQueryValueEx(fontLinkKey, family.charactersWithNullTermination().data(), 0, nullptr, reinterpret_cast<BYTE*>(linkedFonts), &linkedFontsBufferSize) == ERROR_SUCCESS) {
120-
unsigned i = 0;
121138
unsigned length = linkedFontsBufferSize / sizeof(*linkedFonts);
122-
while (i < length) {
123-
while (i < length && linkedFonts[i] != ',')
124-
i++;
125-
// Break if we did not find a comma.
126-
if (i == length)
127-
break;
128-
i++;
129-
unsigned j = i;
130-
while (j < length && linkedFonts[j])
131-
j++;
132-
result->append(String(linkedFonts + i, j - i));
133-
i = j + 1;
134-
}
139+
appendLinkedFonts(linkedFonts, length, result);
135140
}
136141
free(linkedFonts);
137142
RegCloseKey(fontLinkKey);

Tools/ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2016-08-17 Per Arne Vollan <[email protected]>
2+
3+
[Win] Add tests for linked fonts.
4+
https://bugs.webkit.org/show_bug.cgi?id=160898
5+
6+
Reviewed by Brent Fulgham.
7+
8+
Add tests for https://trac.webkit.org/changeset/204502.
9+
10+
* TestWebKitAPI/PlatformWin.cmake:
11+
* TestWebKitAPI/Tests/WebCore/win/LinkedFonts.cpp: Added.
12+
(TestWebKitAPI::TEST):
13+
114
2016-08-16 Daniel Bates <[email protected]>
215

316
prepare-ChangeLog: Extract logic from generateFunctionLists() into a function that takes a delegate object

Tools/TestWebKitAPI/PlatformWin.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ set(TestWebCoreLib_SOURCES
5050
${TESTWEBKITAPI_DIR}/Tests/WebCore/URL.cpp
5151
${TESTWEBKITAPI_DIR}/Tests/WebCore/URLParser.cpp
5252
${TESTWEBKITAPI_DIR}/Tests/WebCore/win/DIBPixelData.cpp
53+
${TESTWEBKITAPI_DIR}/Tests/WebCore/win/LinkedFonts.cpp
5354
)
5455

5556
if (${WTF_PLATFORM_WIN_CAIRO})
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (C) 2016 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+
28+
#include <WebCore/FontCache.h>
29+
30+
using namespace WebCore;
31+
32+
namespace WebCore {
33+
void appendLinkedFonts(WCHAR* linkedFonts, unsigned length, Vector<String>* result);
34+
}
35+
36+
namespace TestWebKitAPI {
37+
38+
// Test the appendLinkedFonts function with normal input data (string with pairs of font filenames and font names separated with \0).
39+
TEST(WebCore, appendLinkedFontsTest)
40+
{
41+
Vector<String> result;
42+
WCHAR linkedFonts[] = L"MICROSS.TTF,Microsoft Sans Serif,128,140\0MICROSS.TTF,Microsoft Sans Serif\0MSGOTHIC.TTC,MS UI Gothic\0MINGLIU.TTC,PMingLiU\0SIMSUN.TTC,SimSun";
43+
44+
appendLinkedFonts(linkedFonts, sizeof(linkedFonts) / sizeof(WCHAR), &result);
45+
ASSERT(result.size() == 5);
46+
ASSERT(result[0] == String(L"Microsoft Sans Serif,128,140"));
47+
ASSERT(result[1] == String(L"Microsoft Sans Serif"));
48+
ASSERT(result[2] == String(L"MS UI Gothic"));
49+
ASSERT(result[3] == String(L"PMingLiU"));
50+
ASSERT(result[4] == String(L"SimSun"));
51+
}
52+
53+
// Test the appendLinkedFonts function when the input data does not contain the expected comma separator.
54+
TEST(WebCore, appendLinkedFontsWithMissingCommaTest)
55+
{
56+
Vector<String> result;
57+
WCHAR linkedFonts[] = L"MICROSS.TTF Microsoft Sans Serif";
58+
59+
appendLinkedFonts(linkedFonts, sizeof(linkedFonts) / sizeof(WCHAR), &result);
60+
ASSERT(!result.size());
61+
}
62+
63+
} // namespace TestWebKitAPI

0 commit comments

Comments
 (0)