зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 651dbded7f74 (bug 1341490) for build bustage. r=backout on a CLOSED TREE
This commit is contained in:
Родитель
20815686f2
Коммит
016a385444
|
@ -0,0 +1,320 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsDependentString.h"
|
||||
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#include "gfxContext.h"
|
||||
#include "gfxFont.h"
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
#include "gfxFontTest.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
enum {
|
||||
S_UTF8 = 0,
|
||||
S_ASCII = 1
|
||||
};
|
||||
|
||||
class FrameTextRunCache;
|
||||
|
||||
struct LiteralArray {
|
||||
LiteralArray (unsigned long l1) {
|
||||
data.AppendElement(l1);
|
||||
}
|
||||
LiteralArray (unsigned long l1, unsigned long l2) {
|
||||
data.AppendElement(l1);
|
||||
data.AppendElement(l2);
|
||||
}
|
||||
LiteralArray (unsigned long l1, unsigned long l2, unsigned long l3) {
|
||||
data.AppendElement(l1);
|
||||
data.AppendElement(l2);
|
||||
data.AppendElement(l3);
|
||||
}
|
||||
LiteralArray (unsigned long l1, unsigned long l2, unsigned long l3, unsigned long l4) {
|
||||
data.AppendElement(l1);
|
||||
data.AppendElement(l2);
|
||||
data.AppendElement(l3);
|
||||
data.AppendElement(l4);
|
||||
}
|
||||
LiteralArray (unsigned long l1, unsigned long l2, unsigned long l3, unsigned long l4, unsigned long l5) {
|
||||
data.AppendElement(l1);
|
||||
data.AppendElement(l2);
|
||||
data.AppendElement(l3);
|
||||
data.AppendElement(l4);
|
||||
data.AppendElement(l5);
|
||||
}
|
||||
|
||||
LiteralArray (const LiteralArray& other) {
|
||||
data = other.data;
|
||||
}
|
||||
|
||||
nsTArray<unsigned long> data;
|
||||
};
|
||||
|
||||
#define GLYPHS LiteralArray
|
||||
|
||||
struct TestEntry {
|
||||
TestEntry (const char *aUTF8FamilyString,
|
||||
const gfxFontStyle& aFontStyle,
|
||||
const char *aString)
|
||||
: utf8FamilyString(aUTF8FamilyString),
|
||||
fontStyle(aFontStyle),
|
||||
stringType(S_ASCII),
|
||||
string(aString),
|
||||
isRTL(false)
|
||||
{
|
||||
}
|
||||
|
||||
TestEntry (const char *aUTF8FamilyString,
|
||||
const gfxFontStyle& aFontStyle,
|
||||
int stringType,
|
||||
const char *aString)
|
||||
: utf8FamilyString(aUTF8FamilyString),
|
||||
fontStyle(aFontStyle),
|
||||
stringType(stringType),
|
||||
string(aString),
|
||||
isRTL(false)
|
||||
{
|
||||
}
|
||||
|
||||
struct ExpectItem {
|
||||
ExpectItem(const nsCString& aFontName,
|
||||
const LiteralArray& aGlyphs)
|
||||
: fontName(aFontName), glyphs(aGlyphs)
|
||||
{ }
|
||||
|
||||
bool Compare(const nsCString& aFontName,
|
||||
cairo_glyph_t *aGlyphs,
|
||||
int num_glyphs)
|
||||
{
|
||||
// bit that allowed for empty fontname to match all is commented
|
||||
// out
|
||||
if (/*!fontName.IsEmpty() &&*/ !fontName.Equals(aFontName))
|
||||
return false;
|
||||
|
||||
if (num_glyphs != int(glyphs.data.Length()))
|
||||
return false;
|
||||
|
||||
for (int j = 0; j < num_glyphs; j++) {
|
||||
if (glyphs.data[j] != aGlyphs[j].index)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCString fontName;
|
||||
LiteralArray glyphs;
|
||||
};
|
||||
|
||||
void SetRTL()
|
||||
{
|
||||
isRTL = true;
|
||||
}
|
||||
|
||||
// Empty/nullptr fontName means ignore font name
|
||||
void Expect (const char *platform,
|
||||
const char *fontName,
|
||||
const LiteralArray& glyphs)
|
||||
{
|
||||
if (fontName)
|
||||
Expect (platform, nsDependentCString(fontName), glyphs);
|
||||
else
|
||||
Expect (platform, nsCString(), glyphs);
|
||||
}
|
||||
|
||||
void Expect (const char *platform,
|
||||
const nsCString& fontName,
|
||||
const LiteralArray& glyphs)
|
||||
{
|
||||
#if defined(XP_WIN)
|
||||
if (strcmp(platform, "win32"))
|
||||
return;
|
||||
#elif defined(XP_MACOSX)
|
||||
if (strcmp(platform, "macosx"))
|
||||
return;
|
||||
#elif defined(XP_UNIX)
|
||||
if (strcmp(platform, "gtk2-pango"))
|
||||
return;
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
|
||||
expectItems.AppendElement(ExpectItem(fontName, glyphs));
|
||||
}
|
||||
|
||||
bool Check (gfxFontTestStore *store) {
|
||||
if (expectItems.Length() == 0 ||
|
||||
store->items.Length() != expectItems.Length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < expectItems.Length(); i++) {
|
||||
if (!expectItems[i].Compare(store->items[i].platformFont,
|
||||
store->items[i].glyphs,
|
||||
store->items[i].num_glyphs))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *utf8FamilyString;
|
||||
gfxFontStyle fontStyle;
|
||||
|
||||
int stringType;
|
||||
const char *string;
|
||||
bool isRTL;
|
||||
|
||||
nsTArray<ExpectItem> expectItems;
|
||||
};
|
||||
|
||||
static already_AddRefed<gfxContext>
|
||||
MakeContext ()
|
||||
{
|
||||
const int size = 200;
|
||||
|
||||
RefPtr<DrawTarget> drawTarget = gfxPlatform::GetPlatform()->
|
||||
CreateOffscreenContentDrawTarget(IntSize(size, size),
|
||||
SurfaceFormat::B8G8R8X8);
|
||||
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(drawTarget);
|
||||
if (!ctx) {
|
||||
MOZ_CRASH("gfxContext creation failed");
|
||||
}
|
||||
|
||||
return ctx.forget();
|
||||
}
|
||||
|
||||
TestEntry*
|
||||
AddTest (nsTArray<TestEntry>& testList,
|
||||
const char *utf8FamilyString,
|
||||
const gfxFontStyle& fontStyle,
|
||||
int stringType,
|
||||
const char *string)
|
||||
{
|
||||
TestEntry te (utf8FamilyString,
|
||||
fontStyle,
|
||||
stringType,
|
||||
string);
|
||||
|
||||
testList.AppendElement(te);
|
||||
|
||||
return &(testList[testList.Length()-1]);
|
||||
}
|
||||
|
||||
void
|
||||
DumpStore (gfxFontTestStore *store) {
|
||||
if (store->items.Length() == 0) {
|
||||
printf ("(empty)\n");
|
||||
}
|
||||
|
||||
for (uint32_t i = 0;
|
||||
i < store->items.Length();
|
||||
i++)
|
||||
{
|
||||
printf ("Run[% 2d]: '%s' ", i, store->items[i].platformFont.BeginReading());
|
||||
|
||||
for (int j = 0; j < store->items[i].num_glyphs; j++)
|
||||
printf ("%d ", int(store->items[i].glyphs[j].index));
|
||||
|
||||
printf ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DumpTestExpect (TestEntry *test) {
|
||||
for (uint32_t i = 0; i < test->expectItems.Length(); i++) {
|
||||
printf ("Run[% 2d]: '%s' ", i, test->expectItems[i].fontName.BeginReading());
|
||||
for (uint32_t j = 0; j < test->expectItems[i].glyphs.data.Length(); j++)
|
||||
printf ("%d ", int(test->expectItems[i].glyphs.data[j]));
|
||||
|
||||
printf ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void SetupTests(nsTArray<TestEntry>& testList);
|
||||
|
||||
static bool
|
||||
RunTest (TestEntry *test, gfxContext *ctx) {
|
||||
RefPtr<gfxFontGroup> fontGroup;
|
||||
|
||||
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->utf8FamilyString), &test->fontStyle, nullptr, nullptr, 1.0);
|
||||
|
||||
RefPtr<gfxTextRun> textRun;
|
||||
gfxTextRunFactory::Parameters params = {
|
||||
ctx, nullptr, nullptr, nullptr, 0, 60
|
||||
};
|
||||
uint32_t flags = gfxTextRunFactory::TEXT_IS_PERSISTENT;
|
||||
if (test->isRTL) {
|
||||
flags |= gfxTextRunFactory::TEXT_IS_RTL;
|
||||
}
|
||||
uint32_t length;
|
||||
if (test->stringType == S_ASCII) {
|
||||
flags |= gfxTextRunFactory::TEXT_IS_ASCII | gfxTextRunFactory::TEXT_IS_8BIT;
|
||||
length = strlen(test->string);
|
||||
textRun = fontGroup->MakeTextRun(
|
||||
reinterpret_cast<const uint8_t*>(test->string), length, ¶ms, flags);
|
||||
} else {
|
||||
NS_ConvertUTF8toUTF16 str(nsDependentCString(test->string));
|
||||
length = str.Length();
|
||||
textRun = fontGroup->MakeTextRun(str.get(), length, ¶ms, flags);
|
||||
}
|
||||
|
||||
gfxFontTestStore::NewStore();
|
||||
textRun->Draw(ctx, gfxPoint(0,0), DrawMode::GLYPH_FILL, 0, length, nullptr, nullptr, nullptr);
|
||||
gfxFontTestStore *s = gfxFontTestStore::CurrentStore();
|
||||
|
||||
if (!test->Check(s)) {
|
||||
DumpStore(s);
|
||||
printf (" expected:\n");
|
||||
DumpTestExpect(test);
|
||||
gfxFontTestStore::DeleteStore();
|
||||
return false;
|
||||
}
|
||||
|
||||
gfxFontTestStore::DeleteStore();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(Gfx, FontSelection) {
|
||||
int passed = 0;
|
||||
int failed = 0;
|
||||
|
||||
// set up the tests
|
||||
nsTArray<TestEntry> testList;
|
||||
SetupTests(testList);
|
||||
|
||||
RefPtr<gfxContext> context = MakeContext();
|
||||
|
||||
for (uint32_t test = 0;
|
||||
test < testList.Length();
|
||||
test++)
|
||||
{
|
||||
bool result = RunTest (&testList[test], context);
|
||||
if (result) {
|
||||
passed++;
|
||||
} else {
|
||||
printf ("Test %d failed\n", test);
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The tests themselves
|
||||
|
||||
#include "gfxFontSelectionTests.h"
|
|
@ -0,0 +1,210 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
*
|
||||
* This file is #included directly by gfxFontSelectionTest.cpp, and as
|
||||
* such does not need any #include files or similar. (However, should
|
||||
* any extra ones be required, it should be ok to do so, as well as
|
||||
* defining new functions, etc.
|
||||
*
|
||||
* To add a new test, call AddTest with the following arguments: the
|
||||
* CSS font-family string, the gfxFontStyle, an enum (either S_ASCII
|
||||
* or S_UTF8) indicating the string type, and then the text string
|
||||
* itself as a string literal. Unfortunately there is no good way to
|
||||
* embed UTF8 directly into C code, so hex literals will need to be
|
||||
* placed in the string. Because of the way \x is parsed things like
|
||||
* "\xabcd" won't work -- you have to do "\xab""cd". "\xab\x01\x03"
|
||||
* will work fine, though.
|
||||
*
|
||||
* The result of AddTest should be assigned to the variable t; after
|
||||
* AddTest, one or more calls to t->Expect() should be added to define
|
||||
* the expected result. Multiple Expect() calls in a row for the same
|
||||
* platform mean that the resulting glyph/font selection items needs
|
||||
* to have as many items as there are Expect() calls. (See below for
|
||||
* examples.)
|
||||
*
|
||||
* The arguments to Expect are:
|
||||
*
|
||||
* platform - a string identifying the platform.
|
||||
* Valid strings are "win32", "macosx", and "gtk2-pango".
|
||||
* font - a string (UTF8) giving the unique name of the font.
|
||||
* See below for how the unique name is constructed.
|
||||
* glyphs - a set of glyph IDs that are expected.
|
||||
* This array is constructed using a GLYPHS() macro.
|
||||
*
|
||||
* GLYPHS() is just a #define for LiteralArray, which is defined
|
||||
* in gfxFontSelectionTest.cpp -- if you need more array elements
|
||||
* than available, just extend LiteralArray with a new constructor
|
||||
* with the required number of unsigned longs.
|
||||
*
|
||||
* The unique font name is a platform-specific constructed string for
|
||||
* (mostly) identifying a font. On Mac, it's created by taking the
|
||||
* Postscript name of the font. On Windows, it's created by taking
|
||||
* the family name, and then appending attributes such as ":Bold",
|
||||
* ":Italic", etc.
|
||||
*
|
||||
* The easiest way to create a test is to add a call to AddTest, and
|
||||
* then run the test. The output will include a list like:
|
||||
*
|
||||
* ==== Test 1
|
||||
* expected:
|
||||
* Run[ 0]: 'Verdana' 73 82 82
|
||||
* Run[ 1]: 'MS UI Gothic' 19401
|
||||
* Run[ 2]: 'Verdana' 69 68 85
|
||||
* Test 1 failed
|
||||
*
|
||||
* This gives you the information needed for the calls to Expect() --
|
||||
* the unique name, and the glyphs. Appropriate calls to expect for
|
||||
* the above would be:
|
||||
*
|
||||
* t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82));
|
||||
* t->Expect ("win32", "MS UI Gothic", GLYPHS(19401));
|
||||
* t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85));
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
void
|
||||
SetupTests(nsTArray<TestEntry>& testList)
|
||||
{
|
||||
TestEntry *t;
|
||||
|
||||
/* some common styles */
|
||||
gfxFontStyle style_western_normal_16 (mozilla::gfx::FontStyle::NORMAL,
|
||||
400,
|
||||
0,
|
||||
16.0,
|
||||
NS_Atomize(NS_LITERAL_STRING("en")),
|
||||
0.0,
|
||||
false, false,
|
||||
NS_LITERAL_STRING(""));
|
||||
|
||||
gfxFontStyle style_western_bold_16 (mozilla::gfx::FontStyle::NORMAL,
|
||||
700,
|
||||
0,
|
||||
16.0,
|
||||
NS_Atomize(NS_LITERAL_STRING("en")),
|
||||
0.0,
|
||||
false, false,
|
||||
NS_LITERAL_STRING(""));
|
||||
|
||||
/* Test 0 */
|
||||
t = AddTest (testList, "sans-serif",
|
||||
style_western_normal_16,
|
||||
S_ASCII,
|
||||
"ABCD");
|
||||
|
||||
t->Expect ("win32", "Arial", GLYPHS(36, 37, 38, 39));
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(36, 37, 38, 39));
|
||||
t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(36, 37, 38, 39));
|
||||
|
||||
/* Test 1 */
|
||||
t = AddTest (testList, "verdana,sans-serif",
|
||||
style_western_normal_16,
|
||||
S_UTF8,
|
||||
"foo\xe2\x80\x91""bar");
|
||||
|
||||
t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82));
|
||||
t->Expect ("win32", "Arial Unicode MS", GLYPHS(3236));
|
||||
t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85));
|
||||
|
||||
t->Expect ("macosx", "Verdana", GLYPHS(73, 82, 82));
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(587));
|
||||
t->Expect ("macosx", "Verdana", GLYPHS(69, 68, 85));
|
||||
|
||||
/* Test 2 */
|
||||
t = AddTest (testList, "sans-serif",
|
||||
style_western_bold_16,
|
||||
S_ASCII,
|
||||
"ABCD");
|
||||
|
||||
t->Expect ("win32", "Arial:700", GLYPHS(36, 37, 38, 39));
|
||||
t->Expect ("macosx", "Helvetica-Bold", GLYPHS(36, 37, 38, 39));
|
||||
t->Expect ("gtk2-pango", "Albany AMT Bold", GLYPHS(36, 37, 38, 39));
|
||||
|
||||
/* Test 3: RTL Arabic with a ligature and leading and trailing whitespace */
|
||||
t = AddTest (testList, "sans-serif",
|
||||
style_western_normal_16,
|
||||
S_UTF8,
|
||||
" \xd8\xaa\xd9\x85 ");
|
||||
t->SetRTL();
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3));
|
||||
t->Expect ("macosx", "ArialMT", GLYPHS(919, 993));
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3));
|
||||
t->Expect ("win32", "Arial", GLYPHS(3, 919, 994, 3));
|
||||
|
||||
/* Test 4: LTR Arabic with leading and trailing whitespace */
|
||||
t = AddTest (testList, "sans-serif",
|
||||
style_western_normal_16,
|
||||
S_UTF8,
|
||||
" \xd9\x85\xd8\xaa ");
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3));
|
||||
t->Expect ("macosx", "ArialMT", GLYPHS(993, 919));
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3));
|
||||
t->Expect ("win32", "Arial", GLYPHS(3, 994, 919, 3));
|
||||
|
||||
/* Test 5: RTL ASCII with leading whitespace */
|
||||
t = AddTest (testList, "sans-serif",
|
||||
style_western_normal_16,
|
||||
S_ASCII,
|
||||
" ab");
|
||||
t->SetRTL();
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3, 68, 69));
|
||||
t->Expect ("win32", "Arial", GLYPHS(3, 68, 69));
|
||||
t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(3, 68, 69));
|
||||
|
||||
/* Test 6: RTL ASCII with trailing whitespace */
|
||||
t = AddTest (testList, "sans-serif",
|
||||
style_western_normal_16,
|
||||
S_ASCII,
|
||||
"ab ");
|
||||
t->SetRTL();
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(68, 69, 3));
|
||||
t->Expect ("win32", "Arial", GLYPHS(68, 69, 3));
|
||||
t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(68, 69, 3));
|
||||
|
||||
/* Test 7: Simple ASCII ligature */
|
||||
/* Do we have a Windows font with ligatures? Can we use DejaVu Sans? */
|
||||
t = AddTest (testList, "sans-serif",
|
||||
style_western_normal_16,
|
||||
S_ASCII,
|
||||
"fi");
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(192));
|
||||
t->Expect ("win32", "Arial", GLYPHS(73, 76));
|
||||
|
||||
/* Test 8: DEVANAGARI VOWEL I reordering */
|
||||
/* The glyph for DEVANAGARI VOWEL I 2367 (101) is displayed before the glyph for 2361 (99) */
|
||||
t = AddTest (testList, "sans-serif",
|
||||
style_western_normal_16,
|
||||
S_UTF8,
|
||||
"\xe0\xa4\x9a\xe0\xa4\xbe\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\x8f"); // 2330 2366 2361 2367 2319
|
||||
t->Expect ("macosx", "DevanagariMT", GLYPHS(71, 100, 101, 99, 60));
|
||||
t->Expect ("win32", "Mangal", GLYPHS(133, 545, 465, 161, 102));
|
||||
|
||||
// Disabled Test 9 & 10 because these appear to vary on mac
|
||||
|
||||
/* Test 9: NWJ test */
|
||||
//t = AddTest (testList, "Kartika",
|
||||
// style_western_normal_16,
|
||||
// S_UTF8,
|
||||
// "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
|
||||
//t->Expect ("macosx", "MalayalamMN", GLYPHS(360));
|
||||
//t->Expect ("win32", "Kartika", GLYPHS(332));
|
||||
|
||||
/* Test 10: NWJ fallback test */
|
||||
/* it isn't clear what we should actually do in this case. Ideally
|
||||
we would have the same results as the previous test, but because
|
||||
we use sans-serif (i.e. Arial) CSS says we should should really
|
||||
use Arial for U+200D.
|
||||
*/
|
||||
//t = AddTest (testList, "sans-serif",
|
||||
// style_western_normal_16,
|
||||
// S_UTF8,
|
||||
// "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
|
||||
// Disabled because these appear to vary
|
||||
//t->Expect ("macosx", "MalayalamMN", GLYPHS(360));
|
||||
//t->Expect ("win32", "Kartika", GLYPHS(332));
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsDependentString.h"
|
||||
|
||||
#include "prinrval.h"
|
||||
|
||||
#include "gfxContext.h"
|
||||
#include "gfxFont.h"
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
#include "gfxFontTest.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
struct TestEntry {
|
||||
const char* mFamilies;
|
||||
const char* mString;
|
||||
};
|
||||
|
||||
TestEntry testList[] = {
|
||||
#include "per-word-runs.h"
|
||||
{ nullptr, nullptr } // terminator
|
||||
};
|
||||
|
||||
static already_AddRefed<gfxContext>
|
||||
MakeContext ()
|
||||
{
|
||||
const int size = 200;
|
||||
|
||||
RefPtr<DrawTarget> drawTarget = gfxPlatform::GetPlatform()->
|
||||
CreateOffscreenContentDrawTarget(IntSize(size, size),
|
||||
SurfaceFormat::B8G8R8X8);
|
||||
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(drawTarget);
|
||||
if (!ctx) {
|
||||
MOZ_CRASH("gfxContext creation failed");
|
||||
}
|
||||
|
||||
return ctx.forget();
|
||||
}
|
||||
|
||||
const char* lastFamilies = nullptr;
|
||||
|
||||
static void
|
||||
RunTest (TestEntry *test, gfxContext *ctx) {
|
||||
RefPtr<gfxFontGroup> fontGroup;
|
||||
if (!lastFamilies || strcmp(lastFamilies, test->mFamilies)) {
|
||||
gfxFontStyle style_western_normal_16 (mozilla::gfx::FontStyle::NORMAL,
|
||||
400,
|
||||
0,
|
||||
16.0,
|
||||
NS_Atomize(NS_LITERAL_STRING("en")),
|
||||
0.0,
|
||||
false, false,
|
||||
NS_LITERAL_STRING(""));
|
||||
|
||||
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nullptr, nullptr, 1.0);
|
||||
}
|
||||
|
||||
RefPtr<gfxTextRun> textRun;
|
||||
uint32_t i;
|
||||
bool isASCII = true;
|
||||
for (i = 0; test->mString[i]; ++i) {
|
||||
if (test->mString[i] & 0x80) {
|
||||
isASCII = false;
|
||||
}
|
||||
}
|
||||
gfxTextRunFactory::Parameters params = {
|
||||
ctx, nullptr, nullptr, nullptr, 0, 60
|
||||
};
|
||||
uint32_t flags = gfxTextRunFactory::TEXT_IS_PERSISTENT;
|
||||
uint32_t length;
|
||||
gfxFontTestStore::NewStore();
|
||||
if (isASCII) {
|
||||
flags |= gfxTextRunFactory::TEXT_IS_ASCII |
|
||||
gfxTextRunFactory::TEXT_IS_8BIT;
|
||||
length = strlen(test->mString);
|
||||
textRun = fontGroup->MakeTextRun(
|
||||
reinterpret_cast<const uint8_t*>(test->mString), length, ¶ms, flags);
|
||||
} else {
|
||||
NS_ConvertUTF8toUTF16 str(nsDependentCString(test->mString));
|
||||
length = str.Length();
|
||||
textRun = fontGroup->MakeTextRun(str.get(), length, ¶ms, flags);
|
||||
}
|
||||
|
||||
// Should we test drawing?
|
||||
// textRun->Draw(ctx, gfxPoint(0,0), 0, length, nullptr, nullptr, nullptr);
|
||||
|
||||
textRun->GetAdvanceWidth(0, length, nullptr);
|
||||
gfxFontTestStore::DeleteStore();
|
||||
}
|
||||
|
||||
uint32_t iterations = 1;
|
||||
|
||||
TEST(Gfx, TextRunPref) {
|
||||
RefPtr<gfxContext> context = MakeContext();
|
||||
|
||||
// Start timing
|
||||
PRIntervalTime start = PR_IntervalNow();
|
||||
|
||||
for (uint32_t i = 0; i < iterations; ++i) {
|
||||
for (uint test = 0;
|
||||
test < ArrayLength(testList) - 1;
|
||||
test++)
|
||||
{
|
||||
RunTest(&testList[test], context);
|
||||
}
|
||||
}
|
||||
|
||||
PRIntervalTime end = PR_IntervalNow();
|
||||
|
||||
printf("Elapsed time (ms): %d\n", PR_IntervalToMilliseconds(end - start));
|
||||
|
||||
}
|
|
@ -25,9 +25,13 @@ UNIFIED_SOURCES += [
|
|||
'TestRegion.cpp',
|
||||
'TestSkipChars.cpp',
|
||||
'TestSwizzle.cpp',
|
||||
# Hangs on linux in ApplyGdkScreenFontOptions
|
||||
#'gfxFontSelectionTest.cpp',
|
||||
'TestTextureCompatibility.cpp',
|
||||
'TestTextures.cpp',
|
||||
'TestTreeTraversal.cpp',
|
||||
# Test works but it doesn't assert anything
|
||||
#'gfxTextRunPerfTest.cpp',
|
||||
# Bug 1179287 - PGO bustage on Linux
|
||||
#'TestTiledLayerBuffer.cpp',
|
||||
'TestVsync.cpp',
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,8 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
#include "gfxFontTest.h"
|
||||
|
||||
gfxFontTestStore* gfxFontTestStore::sCurrentStore = nullptr;
|
|
@ -0,0 +1,84 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef GFX_FONT_TEST_H
|
||||
#define GFX_FONT_TEST_H
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
#include "cairo.h"
|
||||
|
||||
struct gfxFontTestItem {
|
||||
gfxFontTestItem(const nsCString& fontName,
|
||||
cairo_glyph_t *cglyphs, int nglyphs)
|
||||
: platformFont(fontName)
|
||||
{
|
||||
glyphs = new cairo_glyph_t[nglyphs];
|
||||
memcpy (glyphs, cglyphs, sizeof(cairo_glyph_t) * nglyphs);
|
||||
num_glyphs = nglyphs;
|
||||
}
|
||||
|
||||
gfxFontTestItem(const gfxFontTestItem& other) {
|
||||
platformFont = other.platformFont;
|
||||
num_glyphs = other.num_glyphs;
|
||||
glyphs = new cairo_glyph_t[num_glyphs];
|
||||
memcpy (glyphs, other.glyphs, sizeof(cairo_glyph_t) * num_glyphs);
|
||||
}
|
||||
|
||||
~gfxFontTestItem() {
|
||||
delete [] glyphs;
|
||||
}
|
||||
|
||||
nsCString platformFont;
|
||||
cairo_glyph_t *glyphs;
|
||||
int num_glyphs;
|
||||
};
|
||||
|
||||
|
||||
class gfxFontTestStore {
|
||||
public:
|
||||
gfxFontTestStore() { }
|
||||
|
||||
void AddItem (const nsCString& fontString,
|
||||
cairo_glyph_t *cglyphs, int nglyphs)
|
||||
{
|
||||
items.AppendElement(gfxFontTestItem(fontString, cglyphs, nglyphs));
|
||||
}
|
||||
|
||||
void AddItem (const nsString& fontString,
|
||||
cairo_glyph_t *cglyphs, int nglyphs)
|
||||
{
|
||||
items.AppendElement(gfxFontTestItem(NS_ConvertUTF16toUTF8(fontString), cglyphs, nglyphs));
|
||||
}
|
||||
|
||||
nsTArray<gfxFontTestItem> items;
|
||||
|
||||
public:
|
||||
static gfxFontTestStore *CurrentStore() {
|
||||
return sCurrentStore;
|
||||
}
|
||||
|
||||
static gfxFontTestStore *NewStore() {
|
||||
if (sCurrentStore)
|
||||
delete sCurrentStore;
|
||||
|
||||
sCurrentStore = new gfxFontTestStore;
|
||||
return sCurrentStore;
|
||||
}
|
||||
|
||||
static void DeleteStore() {
|
||||
if (sCurrentStore)
|
||||
delete sCurrentStore;
|
||||
|
||||
sCurrentStore = nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
static gfxFontTestStore *sCurrentStore;
|
||||
};
|
||||
|
||||
|
||||
#endif /* GFX_FONT_TEST_H */
|
|
@ -30,6 +30,7 @@ EXPORTS += [
|
|||
'gfxFontFeatures.h',
|
||||
'gfxFontInfoLoader.h',
|
||||
'gfxFontPrefLangList.h',
|
||||
'gfxFontTest.h',
|
||||
'gfxFontUtils.h',
|
||||
'gfxFontVariations.h',
|
||||
'gfxGradientCache.h',
|
||||
|
@ -197,6 +198,7 @@ UNIFIED_SOURCES += [
|
|||
'gfxFontFeatures.cpp',
|
||||
'gfxFontInfoLoader.cpp',
|
||||
'gfxFontMissingGlyphs.cpp',
|
||||
'gfxFontTest.cpp',
|
||||
'gfxGlyphExtents.cpp',
|
||||
'gfxGradientCache.cpp',
|
||||
'gfxGraphiteShaper.cpp',
|
||||
|
|
Загрузка…
Ссылка в новой задаче