1 /***************************************************************************
2 *
3 *   Copyright (C) 2013, International Business Machines
4 *   Corporation and others.  All Rights Reserved.
5 *
6 ************************************************************************/
7 
8 #include "unicode/utimer.h"
9 #include "unicode/ustdio.h"
10 #include "layout/LETypes.h"
11 #include "layout/LayoutEngine.h"
12 #include "layout/LEScripts.h"
13 #include "SimpleFontInstance.h"
14 #include "PortableFontInstance.h"
15 
16 class Params {
17 public:
18   LEFontInstance *font;
19   LEUnicode *chars;
20   le_int32 charLen;
21   ScriptCodes script;
22   le_int32 glyphCount;
23 };
24 
25 LEUnicode     ArabChars[] = {
26         0x0045, 0x006E, 0x0067, 0x006C, 0x0069, 0x0073, 0x0068, 0x0020, // "English "
27         0x0645, 0x0627, 0x0646, 0x062A, 0x0648, 0x0634,                 // MEM ALIF KAF NOON TEH WAW SHEEN
28         0x0020, 0x0074, 0x0065, 0x0078, 0x0074, 0x02E, 0                   // " text."
29     };
30 
iterate(void * p)31 void iterate(void * p) {
32   Params* params = (Params*) p;
33 
34     LEErrorCode status = LE_NO_ERROR;
35     LEFontInstance *font = params->font;
36     LayoutEngine *engine = LayoutEngine::layoutEngineFactory(font, params->script, -1, status);
37     LEGlyphID *glyphs    = NULL;
38     le_int32  *indices   = NULL;
39     float     *positions = NULL;
40     le_int32   glyphCount = 0;
41     LEUnicode *chars = params->chars;
42     glyphCount = engine->layoutChars(chars, 0, params->charLen, params->charLen, TRUE, 0.0, 0.0, status);
43     glyphs    = LE_NEW_ARRAY(LEGlyphID, glyphCount + 10);
44     indices   = LE_NEW_ARRAY(le_int32, glyphCount + 10);
45     positions = LE_NEW_ARRAY(float, glyphCount + 10);
46     engine->getGlyphs(glyphs, status);
47     params->glyphCount = glyphCount;
48 
49 
50     delete glyphs;
51     delete indices;
52     delete positions;
53     delete engine;
54     //delete font;
55 }
56 
main(int argc,const char * argv[])57 int main(int argc, const char *argv[]) {
58   double len=10.0;
59   for(int i=1;i<argc;i++) {
60     puts("arg:");
61     puts(argv[i]);
62     if(argv[i][0]=='p') {
63       printf("hit enter-pid=%d", getpid());
64       getchar();
65     } else if(argv[i][0]>='0' && argv[i][0]<='9') {
66       len = (1.0)*(argv[i][0]-'0');
67     }
68   }
69   u_printf("leperf: Testing %s for %.fs...\n", U_ICU_VERSION, len);
70   LEErrorCode status = LE_NO_ERROR;
71   //uloc_setDefault("en_US", &status);
72   Params p;
73 
74 #if 0
75   p.script = arabScriptCode;
76   p.chars = ArabChars;
77   p.charLen = sizeof(ArabChars)/sizeof(ArabChars[0]);
78 #else
79   p.script = latnScriptCode;
80   p.chars = new LEUnicode[257];
81   for(int i=0;i<256;i++) {
82     p.chars[i] = i+1;
83   }
84   p.chars[256] = 0;
85   p.charLen = 256;
86 #endif
87 
88   int32_t loopCount;
89   double timeTaken;
90   double timeNs;
91 #if 0
92   p.font = new SimpleFontInstance(12, status);
93   u_printf("leperf: Running SFI...\r");
94   timeTaken = utimer_loopUntilDone(len, &loopCount, iterate, &p);
95   u_printf("leperf: SFI .. took %.fs %.2fns/ea\nleperf: .. iter= %d\n", timeTaken, 1000000000.0*(timeTaken/(double)loopCount), (int32_t)loopCount);
96   delete p.font;
97 #endif
98     PortableFontInstance *font;
99     LEErrorCode fontStatus = LE_NO_ERROR;
100     const char *fontPath = "myfont.ttf";
101 
102     font = new PortableFontInstance(fontPath, 12, fontStatus);
103 
104     p.font = font;
105     loopCount=0;
106     u_printf("leperf: testing %s\n", fontPath);
107     u_printf("leperf: Running ...\r");
108   timeTaken = utimer_loopUntilDone(len, &loopCount, iterate, &p);
109   timeNs = 1000000000.0*(timeTaken/(double)loopCount);
110   u_printf("leperf: PFI .. took %.fs %.2fns/ea\nleperf: .. iter= %d\n", timeTaken, timeNs, (int32_t)loopCount);
111   u_printf("leperf: DATA|\"%s\"|%.2f|\n", U_ICU_VERSION, timeNs);
112   u_printf("leperf: glyphs=%d\n", p.glyphCount);
113   return 0;
114 }
115 
116 // hack - #include these for easier build.
117 #include "SimpleFontInstance.cpp"
118 #include "PortableFontInstance.cpp"
119 #include "cmaps.cpp"
120 #include "FontTableCache.cpp"
121