2007-03-22 23:04:48 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Corporation code.
|
|
|
|
*
|
2009-12-21 21:50:30 +00:00
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
2007-03-22 23:04:48 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
2007-04-02 19:06:16 +00:00
|
|
|
#if defined(XP_MACOSX)
|
2007-03-22 23:04:48 +00:00
|
|
|
#include "gfxTestCocoaHelper.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
|
|
|
#include "gtk/gtk.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct TestEntry {
|
|
|
|
const char* mFamilies;
|
|
|
|
const char* mString;
|
|
|
|
};
|
|
|
|
|
|
|
|
TestEntry testList[] = {
|
|
|
|
#include "per-word-runs.h"
|
|
|
|
{ nsnull, nsnull } // terminator
|
|
|
|
};
|
|
|
|
|
|
|
|
already_AddRefed<gfxContext>
|
|
|
|
MakeContext ()
|
|
|
|
{
|
|
|
|
const int size = 200;
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> surface;
|
|
|
|
|
2010-09-16 21:34:53 +00:00
|
|
|
surface = gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenSurface(gfxIntSize(size, size),
|
|
|
|
gfxASurface::ContentFromFormat(gfxASurface::ImageFormatRGB24));
|
2007-03-22 23:04:48 +00:00
|
|
|
gfxContext *ctx = new gfxContext(surface);
|
|
|
|
NS_IF_ADDREF(ctx);
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxFontGroup> fontGroup;
|
|
|
|
const char* lastFamilies = nsnull;
|
|
|
|
|
|
|
|
void
|
|
|
|
RunTest (TestEntry *test, gfxContext *ctx) {
|
|
|
|
if (!lastFamilies || strcmp(lastFamilies, test->mFamilies)) {
|
|
|
|
gfxFontStyle style_western_normal_16 (FONT_STYLE_NORMAL,
|
2009-01-29 20:39:18 +00:00
|
|
|
NS_FONT_STRETCH_NORMAL,
|
2007-03-22 23:04:48 +00:00
|
|
|
400,
|
|
|
|
16.0,
|
2010-03-08 15:45:00 +00:00
|
|
|
NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
|
2007-03-22 23:04:48 +00:00
|
|
|
0.0,
|
2010-07-13 20:31:31 +00:00
|
|
|
PR_FALSE, PR_FALSE, PR_FALSE,
|
|
|
|
NS_LITERAL_STRING(""),
|
|
|
|
NS_LITERAL_STRING(""));
|
2007-03-22 23:04:48 +00:00
|
|
|
|
2008-10-01 03:01:53 +00:00
|
|
|
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nsnull);
|
2007-03-22 23:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoPtr<gfxTextRun> textRun;
|
|
|
|
PRUint32 i;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isASCII = true;
|
2007-03-22 23:04:48 +00:00
|
|
|
for (i = 0; test->mString[i]; ++i) {
|
2007-03-29 21:48:46 +00:00
|
|
|
if (test->mString[i] & 0x80) {
|
2007-03-22 23:04:48 +00:00
|
|
|
isASCII = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gfxTextRunFactory::Parameters params = {
|
2007-05-08 22:46:14 +00:00
|
|
|
ctx, nsnull, nsnull, nsnull, 0, 60
|
2007-03-22 23:04:48 +00:00
|
|
|
};
|
2007-05-08 22:46:14 +00:00
|
|
|
PRUint32 flags = gfxTextRunFactory::TEXT_IS_PERSISTENT;
|
2007-03-22 23:04:48 +00:00
|
|
|
PRUint32 length;
|
|
|
|
if (isASCII) {
|
2007-05-08 22:46:14 +00:00
|
|
|
flags |= gfxTextRunFactory::TEXT_IS_ASCII |
|
|
|
|
gfxTextRunFactory::TEXT_IS_8BIT;
|
2007-03-22 23:04:48 +00:00
|
|
|
length = strlen(test->mString);
|
2007-07-08 07:08:04 +00:00
|
|
|
textRun = fontGroup->MakeTextRun(reinterpret_cast<const PRUint8*>(test->mString), length, ¶ms, flags);
|
2007-03-22 23:04:48 +00:00
|
|
|
} else {
|
|
|
|
NS_ConvertUTF8toUTF16 str(nsDependentCString(test->mString));
|
|
|
|
length = str.Length();
|
2007-05-08 22:46:14 +00:00
|
|
|
textRun = fontGroup->MakeTextRun(str.get(), length, ¶ms, flags);
|
2007-03-22 23:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should we test drawing?
|
|
|
|
// textRun->Draw(ctx, gfxPoint(0,0), 0, length, nsnull, nsnull, nsnull);
|
|
|
|
|
|
|
|
textRun->GetAdvanceWidth(0, length, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 iterations = 20;
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv) {
|
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
CocoaPoolInit();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Initialize XPCOM
|
|
|
|
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return -1;
|
|
|
|
|
2007-03-29 21:48:46 +00:00
|
|
|
rv = gfxPlatform::Init();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return -1;
|
|
|
|
|
2007-03-22 23:04:48 +00:00
|
|
|
// let's get all the xpcom goop out of the system
|
|
|
|
fflush (stderr);
|
|
|
|
fflush (stdout);
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> context = MakeContext();
|
|
|
|
|
|
|
|
// Start timing
|
|
|
|
PRIntervalTime start = PR_IntervalNow();
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < iterations; ++i) {
|
|
|
|
for (uint test = 0;
|
2011-10-12 19:21:53 +00:00
|
|
|
test < NS_ARRAY_LENGTH(testList) - 1;
|
2007-03-22 23:04:48 +00:00
|
|
|
test++)
|
|
|
|
{
|
|
|
|
RunTest(&testList[test], context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntervalTime end = PR_IntervalNow();
|
|
|
|
|
|
|
|
printf("Elapsed time (ms): %d\n", PR_IntervalToMilliseconds(end - start));
|
|
|
|
|
|
|
|
fflush (stderr);
|
|
|
|
fflush (stdout);
|
|
|
|
}
|