os/textandloc/fontservices/textshaperplugin/test/CreateTestData/T_SHAP_createTestData.cpp
Update contrib.
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Creates test data files that are used by TC_SHAP_shapeText.cpp test.
16 * This tool uses the Unicode test input text defined in inputData.h and
17 * shapes the text by calling the IcuLayoutEngine API ShapeText().
18 * The result, along with the input text is stored in the test data files with
20 * First, the reference input data is stored in the data files in the following format, seperated by a delimiter - | :
21 * Length (of the input data string) Font typeface name | Font file name | Starting offset in the input string | End offset in the input string | Input text string
22 * Then the result of the shaping is stored in data files in the following format:
23 * Output glyph count Output glyphs Glyph X and Y coordinates Glyph advances Glyph indices Output character count
24 * The TC_SHAP_shape_Text test is programmed to read in files in this format, and this format only.
25 * This tool needs to be run, and new test data files need to be created everytime the
26 * IcuLayoutEngine shaping rules are changed/edited/appended.
27 * IN ORDER TO CREATE NEW TEST DATA FILES USING THIS UTILITY, YOU WILL NEED TO:
28 * 1. Add a new TInputData entry in inputData.txt
29 * 2. Delete any old data files in %EPOCROOT%epoc32\winscw\c\
31 * IN ORDER TO GET THE TC_SHAP_shapeText TEST FILE TO USE THIS NEW DATA, YOU WILL NEED TO:
32 * 1. Add your new test file in perforce to:
33 * IcuLayoutEngine/test/testdata/...
34 * They will have been added to %EPOCROOT%epoc32\winscw\c
35 * 2. Update the bld.inf file for IcuLayoutEngine to export this file to z:\test\data\...
36 * 3. Update the .cpp file by adding the a new literal at the top of the file with the new filename to be used.
37 * 4. Update the TC_SHAP_shapeText.iby file in IcuLayoutEngine/test to include the new file.
38 * THIS TOOL SHOULD ONLY BE RUN BY SOMEONE WHO KNOWS WHAT HE/SHE IS DOING!!
50 #include <graphics/openfontrasterizer.h>
51 #include <graphics/openfontconstants.h>
52 #include <graphics/shapeimpl.h>
53 #include "inputData.h"
55 const TUint32 KDevanagariScriptCode = 0x64657661;
56 const TUint32 KKannadaScriptCode = 0x6B6E6461;
57 const TUint32 KHindiLanguageCode = 0x48494E20;
58 const TUint32 KKannadaLanguageCode = 0x4B414E20;
59 const TUint32 KGujaratiScriptCode = 0x67756A72;
60 const TUint32 KGujaratiLanguageCode = 0x47554A20;
61 const TUint32 KBengaliScriptCode = 0x62656E67;
62 const TUint32 KBengaliLanguageCode = 0x42454E20;
63 const TUint32 KTamilScriptCode = 0x74616D6C;
64 const TUint32 KTamilLanguageCode = 0x54414D20;
65 const TUint32 KTeluguScriptCode = 0x74656C75;
66 const TUint32 KTeluguLanguageCode = 0x54454C20;
67 const TUint32 KGurmukhiScriptCode = 0x67757275;
68 const TUint32 KGurmukhiLanguageCode = 0;
69 const TUint32 KMalayalamScriptCode = 0x6d6c796d;
70 const TUint32 KMalayalamLanguageCode = 0x4d4c5220;
73 _LIT16(KDelimiter, "|");
76 static RTest TheTest(_L("T_SHAP_createTestData"));
77 static void Check(TInt aValue, TInt aLine)
81 TheTest(EFalse, aLine);
85 static void Check(TInt aValue, TInt aExpected, TInt aLine)
87 if(aValue != aExpected)
89 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
90 TheTest(EFalse, aLine);
94 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
95 #define TEST(arg) ::Check((arg), __LINE__)
98 Used for cleanup of RImplInfoArray implementationArray below
99 This method is stolen from FbsTop.cpp
101 LOCAL_C void ResetAndDestroyRImplInfoPtrArray(TAny* aPtr)
103 RImplInfoPtrArray* array = reinterpret_cast <RImplInfoPtrArray*> (aPtr);
104 array->ResetAndDestroy();
108 Load all ECOM implemented rasterizer DLLs.
109 This method is stolen from CFbTop::LoadOpenFontLibraries()
111 LOCAL_C void LoadOpenFontLibraries(CFontStore* aFontStore)
114 RImplInfoPtrArray implementationArray;
115 TCleanupItem cleanup(ResetAndDestroyRImplInfoPtrArray, &implementationArray);
116 CleanupStack::PushL(cleanup);
120 TUid uid = {KUidOpenFontRasterizerPlunginInterface};
122 // Making sure that no race situation arises
123 // If ECom is not ready, give it another chance and try again. if it still doesn't work
124 // after the third try, then it just carries on quietly and fails...
125 for (ecomnotready =0; ecomnotready <3; ecomnotready++)
127 TRAP(ecomerror,REComSession::ListImplementationsL(uid,implementationArray));
139 const TInt availCount = implementationArray.Count();
140 for (TInt count=0;count<availCount;++count)
142 const CImplementationInformation* info = implementationArray[count];
143 TUid rasterizerUid = info->ImplementationUid();
144 // Create a rasterizer
145 COpenFontRasterizer* rasterizer=0;
146 TRAP(error,rasterizer = COpenFontRasterizer::NewL(rasterizerUid));
149 // Install it in the font store.
150 TRAP(error,aFontStore->InstallRasterizerL(rasterizer));
155 CleanupStack::PopAndDestroy(&implementationArray);
159 LOCAL_C void WriteInputData(RWriteStream& aStream, const TInputData& aInputData)
161 //output the input data to the file
162 TPtrC input = aInputData.TextInput();
163 TInt length = input.Length();
164 TInt start = aInputData.iStart;
167 TInt end = aInputData.iEnd;
171 aStream.WriteInt16L(length);
173 aStream.WriteL(aInputData.TypeFaceName());
174 aStream.WriteL(KDelimiter);
176 aStream.WriteL(aInputData.FontFilename());
177 aStream.WriteL(KDelimiter);
179 aStream.WriteInt16L(start);
180 aStream.WriteL(KDelimiter);
181 aStream.WriteInt16L(end);
182 aStream.WriteL(KDelimiter);
184 aStream.WriteL(input);
185 aStream.WriteL(KDelimiter);
188 static void WriteOutputData(RWriteStream& aStream, const TInputData& aInputData,
189 TUint32 aScript, TUint32 aLanguage)
193 TPtrC input = aInputData.TextInput();
194 TInt length = input.Length();
195 TInt start = aInputData.iStart;
198 TInt end = aInputData.iEnd;
202 //set up font store and install rasterizer(s)
203 CFontStore* fontStore = CFontStore::NewL(&User::Heap());
204 fontStore->iKPixelWidthInTwips = 11860;
205 fontStore->iKPixelHeightInTwips = 11860;
206 CleanupStack::PushL(fontStore);
207 LoadOpenFontLibraries(fontStore);
209 //add required font file
210 TRAPD( err, fontStore->AddFileL(aInputData.FontFilename()) );
214 TFontSpec fontSpec(aInputData.TypeFaceName(), 12);
215 fontStore->GetNearestFontToDesignHeightInPixels((CFont*&)font, fontSpec);
216 CleanupStack::PushL(font);
218 CShaper* theShaper = NULL;
219 CShaperFactory* shaperFactory = NULL;
221 RImplInfoPtrArray implementationArray;
222 TCleanupItem cleanup(ResetAndDestroyRImplInfoPtrArray, &implementationArray);
223 CleanupStack::PushL(cleanup);
227 TUid uid = {KUidShaperFactoryPlunginInterface};
229 // Making sure that no race situation arises between FBserv and Ecom
230 // If ECom is not ready, give it another chance and try again. if it still doesn't work
231 // after the third try, then it just carries on quietly and fails...
232 for (ecomnotready =0; ecomnotready <3; ecomnotready++)
234 TRAP(ecomerror,REComSession::ListImplementationsL(uid,implementationArray));
246 const TInt availCount = implementationArray.Count();
247 for (TInt count=0;count<availCount;++count)
249 const CImplementationInformation* info = implementationArray[count];
250 TUid shaperFactoryUid = info->ImplementationUid();
251 // Create a shaper factory
252 //CShaperFactory* shaperFactory = 0;
253 TRAP(error,shaperFactory = CShaperFactory::NewL(shaperFactoryUid));
254 TEST2(error, KErrNone);
256 TRAPD(err, theShaper = shaperFactory->NewShaperL(font, aScript, aLanguage, &User::Heap()));
257 TEST2(err, KErrNone);
259 CleanupStack::PopAndDestroy(&implementationArray);
261 CleanupStack::PushL(shaperFactory);
262 CleanupStack::PushL(theShaper);
264 // create the data to be shaped
265 // this uses testData, defined in testData.h
266 CShaper::TInput shaperInput;
267 shaperInput.iText = &input;
268 shaperInput.iStart = start;
269 shaperInput.iEnd = end;
271 TShapeHeader* output = NULL;
272 err = theShaper->ShapeText(output, shaperInput, &User::Heap());
274 CleanupStack::PushL(output);
277 //AND FILL THE FILE UP WITH THE RESULTS
279 //first the glyph count
280 aStream.WriteInt16L(output->iGlyphCount);
281 TInt glyphCount(output->iGlyphCount);
285 TUint32* shapePtr32 = (reinterpret_cast<TUint32*>(&output->iBuffer[0]));
286 for(i=0; i <glyphCount; i++)
288 aStream.WriteInt32L(*shapePtr32);
292 //then the X and Y positions
293 TUint16* shapePtr16 = (reinterpret_cast<TUint16*>(shapePtr32));
294 for(i=0; i<glyphCount*2; i++)
296 aStream.WriteInt16L(*shapePtr16);
301 aStream.WriteInt16L(*shapePtr16);
303 aStream.WriteInt16L(*shapePtr16);
307 for(i=0; i<glyphCount; i++)
309 aStream.WriteInt16L(*shapePtr16);
313 //then the character count
314 aStream.WriteInt16L(output->iCharacterCount);
316 CleanupStack::PopAndDestroy(output);
317 CleanupStack::PopAndDestroy(theShaper);
318 CleanupStack::PopAndDestroy(shaperFactory);
319 REComSession::FinalClose();
321 CleanupStack::Pop(font);
322 fontStore->ReleaseFont(font);
323 CleanupStack::PopAndDestroy(fontStore);
325 //close the ecom session opened by LoadOpenFontLibraries()
326 REComSession::FinalClose();
335 // Create the Devanagari test data files
336 const TInt numberOfTests
337 = sizeof(TNR_Dev_OTInputData)/sizeof(TNR_Dev_OTInputData[0]);
338 for (TInt i = 0; i != numberOfTests; ++i)
340 const TInputData& data = TNR_Dev_OTInputData[i];
341 User::LeaveIfError(fs.Connect());
342 CleanupClosePushL(fs);
343 // note this uses RFile::Create so that users of this utility cannot accidentally write over
344 // files created before. If this test fails, you need to ensure that the file specified by
345 // KFileName is correct, and if so delete it before running this utility.
346 TEST2(file.Create(fs, data.OutputFilename(), EFileWrite), KErrNone);
348 CleanupClosePushL(buf);
350 RWriteStream stream(&buf);
352 //write to the stream
353 WriteInputData(stream, data);
354 WriteOutputData(stream, data, KDevanagariScriptCode, KHindiLanguageCode);
356 CleanupStack::PopAndDestroy(2); //buf, fs
359 // Create the Kannada test data files
360 const TInt numberOfKanTests = sizeof(Kannada_InputData)/sizeof(Kannada_InputData[0]);
361 for (TInt i = 0; i != numberOfKanTests; i++)
363 const TInputData& kan_data = Kannada_InputData[i];
364 User::LeaveIfError(fs.Connect());
365 CleanupClosePushL(fs);
366 TEST2(file.Create(fs, kan_data.OutputFilename(), EFileWrite), KErrNone);
367 CleanupClosePushL(buf);
369 RWriteStream stream(&buf);
371 WriteInputData(stream, kan_data);
372 WriteOutputData(stream, kan_data, KKannadaScriptCode, KKannadaLanguageCode);
374 CleanupStack::PopAndDestroy(2);
378 // Create the Gujarati test data files
379 const TInt numberOfGujTests = sizeof(Gujarati_InputData)/sizeof(Gujarati_InputData[0]);
380 for (TInt i = 0; i != numberOfGujTests; i++)
382 const TInputData& kan_data = Gujarati_InputData[i];
383 User::LeaveIfError(fs.Connect());
384 CleanupClosePushL(fs);
385 TEST2(file.Create(fs, kan_data.OutputFilename(), EFileWrite), KErrNone);
386 CleanupClosePushL(buf);
388 RWriteStream stream(&buf);
390 WriteInputData(stream, kan_data);
391 WriteOutputData(stream, kan_data, KGujaratiScriptCode, KGujaratiLanguageCode);
393 CleanupStack::PopAndDestroy(2);
397 // Create the Bengali test data files
398 const TInt numberOfBenTests = sizeof(Bengali_InputData)/sizeof(Bengali_InputData[0]);
399 for (TInt i = 0; i != numberOfBenTests; i++)
401 const TInputData& ben_data = Bengali_InputData[i];
402 User::LeaveIfError(fs.Connect());
403 CleanupClosePushL(fs);
404 TEST2(file.Create(fs, ben_data.OutputFilename(), EFileWrite), KErrNone);
405 CleanupClosePushL(buf);
407 RWriteStream stream(&buf);
409 WriteInputData(stream, ben_data);
410 WriteOutputData(stream, ben_data, KBengaliScriptCode, KBengaliLanguageCode);
412 CleanupStack::PopAndDestroy(2);
415 // Create the Tamil test data files
416 const TInt numberOfTamTests = sizeof(Tamil_InputData)/sizeof(Tamil_InputData[0]);
417 for (TInt i = 0; i != numberOfTamTests; i++)
419 const TInputData& tam_data = Tamil_InputData[i];
420 User::LeaveIfError(fs.Connect());
421 CleanupClosePushL(fs);
422 TEST2(file.Create(fs, tam_data.OutputFilename(), EFileWrite), KErrNone);
423 CleanupClosePushL(buf);
425 RWriteStream stream(&buf);
427 WriteInputData(stream, tam_data);
428 WriteOutputData(stream, tam_data, KTamilScriptCode, KTamilLanguageCode);
430 CleanupStack::PopAndDestroy(2);
433 // Create the Telugu test data files
434 const TInt numberOfTelTests = sizeof(Telugu_InputData)/sizeof(Telugu_InputData[0]);
435 for (TInt i = 0; i != numberOfTelTests; i++)
437 const TInputData& tel_data = Telugu_InputData[i];
438 User::LeaveIfError(fs.Connect());
439 CleanupClosePushL(fs);
440 TEST2(file.Create(fs, tel_data.OutputFilename(), EFileWrite), KErrNone);
441 CleanupClosePushL(buf);
443 RWriteStream stream(&buf);
445 WriteInputData(stream, tel_data);
446 WriteOutputData(stream, tel_data, KTeluguScriptCode, KTeluguLanguageCode);
448 CleanupStack::PopAndDestroy(2);
451 // Create the Gurmukhi test data files
452 const TInt numberOfGurTests = sizeof(Gurmukhi_InputData)/sizeof(Gurmukhi_InputData[0]);
453 for (TInt i = 0; i != numberOfGurTests; i++)
455 const TInputData& tel_data = Gurmukhi_InputData[i];
456 User::LeaveIfError(fs.Connect());
457 CleanupClosePushL(fs);
458 TEST2(file.Create(fs, tel_data.OutputFilename(), EFileWrite), KErrNone);
459 CleanupClosePushL(buf);
461 RWriteStream stream(&buf);
463 WriteInputData(stream, tel_data);
464 WriteOutputData(stream, tel_data, KGurmukhiScriptCode, KGurmukhiLanguageCode);
466 CleanupStack::PopAndDestroy(2);
469 // Create the Malayalam test data files
470 const TInt numberOfMalaTests = sizeof(Malayalam_InputData)/sizeof(Malayalam_InputData[0]);
471 for (TInt i = 0; i != numberOfMalaTests; i++)
473 const TInputData& tel_data = Malayalam_InputData[i];
474 User::LeaveIfError(fs.Connect());
475 CleanupClosePushL(fs);
476 TEST2(file.Create(fs, tel_data.OutputFilename(), EFileWrite), KErrNone);
477 CleanupClosePushL(buf);
479 RWriteStream stream(&buf);
481 WriteInputData(stream, tel_data);
482 WriteOutputData(stream, tel_data, KMalayalamScriptCode, KMalayalamLanguageCode);
484 CleanupStack::PopAndDestroy(2);
492 CTrapCleanup* cleanup = CTrapCleanup::New();
497 TEST2(err, KErrNone);