graphicstools/bitmapfonttools/src/PDRREADR.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Header PDRREADR.CPP
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "PDRREADR.H"
       
    21 
       
    22 const int NumResources=34;
       
    23 
       
    24 String IdentResource[NumResources] =
       
    25 	{
       
    26 	"Reset",
       
    27 	"SetPageSize",
       
    28 	"PreAmble",
       
    29 	"PostAmble",
       
    30 	"SetTextColor",	//  !!
       
    31 	"BoldOn",
       
    32 	"BoldOff",
       
    33 	"ItalicOn",
       
    34 	"ItalicOff",
       
    35 	"UnderlineOn",
       
    36 	"UnderlineOff",
       
    37 	"StrikethroughOn",
       
    38 	"StrikethroughOff",
       
    39 	"NewPage",
       
    40 	"Portrait",
       
    41 	"Landscape",
       
    42 	"SetXPos",
       
    43 	"SetYPos",
       
    44 	"IncrementXPos",
       
    45 	"IncrementYPos",
       
    46 	"CarriageReturn",
       
    47 	"SetGraphicsColor",	//  !!
       
    48 	"BitmapStart",
       
    49 	"BitmapEnd",
       
    50 	"ScanLine",
       
    51 	"EndScanLine",	//  !!
       
    52 	"Resource1",
       
    53 	"Resource2",
       
    54 	"Resource3",
       
    55 	"Resource4",
       
    56 	"Resource5",
       
    57 	"Resource6",
       
    58 	"Resource7",
       
    59 	"Resource8"
       
    60 	};
       
    61 
       
    62 const int NumDisplayModeValues = 11;
       
    63 
       
    64 String IdentDisplayModeValue[NumDisplayModeValues] =
       
    65 	{
       
    66 	"None",
       
    67 	"Gray2",
       
    68 	"Gray4",
       
    69 	"Gray16",
       
    70 	"Gray256",
       
    71 	"Color16",
       
    72 	"Color256",
       
    73 	"Color64K",
       
    74 	"Color16M",
       
    75 	"Rgb",
       
    76 	"Color4K"
       
    77 	};
       
    78 
       
    79 EXPORT_C PdrReader::PdrReader()
       
    80  :	Reader(),
       
    81 	iPdrModelStore(),
       
    82 	iPdrStoreFile(NULL),
       
    83 	iResources(NULL),
       
    84 	iTranslates(NULL),
       
    85 	iCodeSection(NULL),
       
    86 	iFontInfo(NULL),
       
    87 	iIndex(Normal),
       
    88 	iFontHeight(NULL),
       
    89 	iTypefaceFonts(NULL),
       
    90 	iModel(NULL)
       
    91 	{
       
    92 	}
       
    93 
       
    94 EXPORT_C boolean PdrReader::Read(const String& aFilename)
       
    95 	{
       
    96 	boolean state = Open(aFilename);
       
    97 
       
    98 	while (!_EOF() && state)
       
    99 		{
       
   100 		if (IdentComp(IdentResources))
       
   101 			state = ReadResources();
       
   102 		else if (IdentComp(IdentTranslates))
       
   103 			state = ReadTranslates();
       
   104 		else if (IdentComp(IdentFontInfo))
       
   105 			state = ReadFontInfo();
       
   106 		else if (IdentComp(IdentTypefaceFonts))
       
   107 			state = ReadTypefaceFonts();
       
   108 //		else if (IdentComp(IdentExtraInfo))
       
   109 //			state = ReadExtraInfo();
       
   110 		else if (IdentComp(IdentModel))
       
   111 			state = ReadModel();
       
   112 		else if (IdentComp(IdentPdrStoreFile))
       
   113 			state = ReadPdrStoreFile();
       
   114 		else
       
   115 			{
       
   116 			Error("Resource identifier expected");
       
   117 			state = efalse;
       
   118 			}
       
   119 		if (state)
       
   120 			state = NewLine();
       
   121 		}
       
   122 	return state;
       
   123 	}
       
   124 
       
   125 EXPORT_C PdrReader::~PdrReader()
       
   126 	{
       
   127 	}
       
   128 
       
   129 boolean PdrReader::ReadResources()
       
   130 	{
       
   131 	boolean state = etrue;
       
   132 	iResources = PdrResources::New();
       
   133 	state = IdentCopy(iResources->iLabel);
       
   134 	if (state)
       
   135 		state = NewLine();
       
   136 	while (!IdentComp(IdentEndResources) && !_EOF() && state)
       
   137 		{
       
   138    	    int i; // DEF102183: Graphics tools fail to build using MS VC8.
       
   139 		for (i = 0; (i < NumResources) && !IdentComp(IdentResource[i]); i++)
       
   140 			{	//	Tries to match resources identifier
       
   141 			}
       
   142 		if (i < NumResources)
       
   143 			{
       
   144 			PdrResource *resource = PdrResource::New();
       
   145 			state = Command(resource->iString);
       
   146 			resource->iId = i;
       
   147 			if (state)
       
   148 				{
       
   149 				iResources->AddResource(resource);
       
   150 				state = NewLine();
       
   151 				}
       
   152 			else
       
   153 				resource->Delete();
       
   154 			}
       
   155 		else
       
   156 			{
       
   157 			state = efalse;
       
   158 			Error("Resources identifier expected");
       
   159 			}
       
   160 		}
       
   161 	if (state)
       
   162 		{
       
   163 		iPdrModelStore.AddResources(iResources);
       
   164 		cout << "Resources read\n";
       
   165 		}
       
   166 	else 
       
   167 		iResources->Delete();
       
   168 	return state;
       
   169 	}
       
   170 
       
   171 boolean PdrReader::ReadTranslates()
       
   172 	{
       
   173 	int num;
       
   174 	boolean state = etrue;
       
   175 	iTranslates = PdrTranslates::New();
       
   176 	state = IdentCopy(iTranslates->iLabel);
       
   177 	if (state)
       
   178 		state = NewLine();
       
   179 	while (!IdentComp(IdentEndTranslates) && !_EOF() && state)
       
   180 		{
       
   181 		if (iLex->iType == ELexNumber)
       
   182 			{
       
   183 			PdrTranslation *translation = PdrTranslation::New();
       
   184 			Number(num);
       
   185 			translation->iFrom = uint16(num);
       
   186 			char ch;
       
   187 			state = Operator(ch);
       
   188 			if (state)
       
   189 				{
       
   190 				state = (ch == ':');
       
   191 				if (state)
       
   192 					{
       
   193 					if (iLex->iType == ELexNumber)
       
   194 						{
       
   195 						state = Number(num);
       
   196 						translation->iTo += char(num);
       
   197 						}
       
   198 					else 
       
   199 						{
       
   200 						state = Command(translation->iTo);
       
   201 						}
       
   202 					if (state)
       
   203 						state = NewLine();
       
   204 					}
       
   205 				else
       
   206 					{
       
   207 					Error("Operator ':' expected");
       
   208 					}
       
   209 				}
       
   210 			if (state)
       
   211 				iTranslates->AddTranslation(translation);
       
   212 			else
       
   213 				translation->Delete();
       
   214 			}
       
   215 		}
       
   216 	if (state)
       
   217 		{
       
   218 		iPdrModelStore.AddTranslates(iTranslates);
       
   219 		cout << "Translates read\n";
       
   220 		}
       
   221 	else 
       
   222 		iTranslates->Delete();
       
   223 	return state;
       
   224 	}
       
   225 
       
   226 boolean PdrReader::ReadCodeSection(int aCode)
       
   227 	{
       
   228 	boolean state = etrue;
       
   229 	int code;
       
   230 	int num;
       
   231 	iCodeSection = WidthsCodeSection::New();
       
   232 	char ch = 0;
       
   233 	state = Number(num);
       
   234 	if ((num<aCode) && state)
       
   235 		{
       
   236 		Error("CodeSection out of sequence");
       
   237 		state = efalse;
       
   238 		}
       
   239 	if (state)
       
   240 		{
       
   241 		iCodeSection->iStart = uint16(num);
       
   242 		state = Operator(ch);
       
   243 		if (state)
       
   244 			state = (ch == ':');
       
   245 		if (state)
       
   246 			{
       
   247 			state = Number(num);
       
   248 			iCodeSection->iEnd = uint16(num);
       
   249 			state = NewLine();
       
   250 			}
       
   251 		else
       
   252 			{
       
   253 			state = efalse;
       
   254 			Error("Operator ':' expected");
       
   255 			}
       
   256 		}
       
   257 	else
       
   258 		state = efalse;
       
   259 	while (!IdentComp(IdentEndCodeSection) && !_EOF() && state)
       
   260 		{
       
   261 		if (iLex->iType != ELexNL)
       
   262 			{
       
   263 			state = Number(code);
       
   264 			if ((code != iCodeSection->iStart + iCodeSection->NumWidths()) && state)
       
   265 				{
       
   266 				state = efalse;
       
   267 				Error("Width out of sequence");
       
   268 				}
       
   269 			if (state)
       
   270 				state = Operator(ch);
       
   271 			if (state)
       
   272 				state = (ch == ':');
       
   273 			if (state)
       
   274 				{
       
   275 				Width *width = Width::New();
       
   276 				if (Number(num))
       
   277 					{
       
   278 					width->iWidthInPixels = (uint16) num;
       
   279 					iCodeSection->AddWidth(width);
       
   280 					}
       
   281 				else
       
   282 					{
       
   283 					state = efalse;
       
   284 					width->Delete();
       
   285 					}
       
   286 				}
       
   287 			}
       
   288 		else
       
   289 			state = NewLine();
       
   290 		}
       
   291 	if (state)
       
   292 		{
       
   293 		num = ((iCodeSection->iEnd + 1) - iCodeSection->iStart);
       
   294 		if ((num != iCodeSection->NumWidths()) && (iCodeSection->NumWidths() != 1))
       
   295 			{
       
   296 			Error("Wrong number of widths in codesection");
       
   297 			state = efalse;
       
   298 			}
       
   299 		}
       
   300 	if (state)
       
   301 		{
       
   302 		iFontInfo->AddCodeSection(iCodeSection);
       
   303 //		cout << "Codesection read\n";
       
   304 		}
       
   305 	else 
       
   306 		iCodeSection->Delete();
       
   307 	return state;
       
   308 	}
       
   309 
       
   310 boolean PdrReader::ReadFontInfo()
       
   311 	{
       
   312 	boolean state = etrue;
       
   313 	iFontInfo = FontInfo::New();
       
   314 	int num;
       
   315 	state = IdentCopy(iFontInfo->iLabel);
       
   316 	if (state)
       
   317 		state = NewLine();
       
   318 	while (!IdentComp(IdentEndFontInfo) && !_EOF() && state)
       
   319 		{
       
   320 		if (iLex->iType == ELexIdent)
       
   321 			{
       
   322 			if (IdentComp(IdentCodeSection))
       
   323 				{
       
   324 				int code = 0,size = iFontInfo->NumCodeSections();
       
   325 				if (size)
       
   326 					code = iFontInfo->CodeSectionList(size - 1)->iEnd + 1;
       
   327 				state = ReadCodeSection(code);
       
   328 				}
       
   329 			else if (IdentComp(IdentAscent))
       
   330 				{
       
   331 				if (Number(num))
       
   332 					iFontInfo->iAscentInPixels = uint16(num);
       
   333 				else
       
   334 					state = efalse;
       
   335 				}
       
   336 			else if (IdentComp(IdentMaxNormalCharWidth))
       
   337 				{
       
   338 				state = Number(num);
       
   339 				if (state)
       
   340 					iFontInfo->iMaxNormalCharWidthInPixels = uint16(num);
       
   341 				}
       
   342 			else
       
   343 				{
       
   344 				Error("Unrecognised fontinfo identifier");
       
   345 				state = efalse;
       
   346 				}
       
   347 			}
       
   348 		else
       
   349 			{
       
   350 			Error("Fontinfo identifier expected");
       
   351 			state = efalse;
       
   352 			}
       
   353 		if (state)
       
   354 			state = NewLine();
       
   355 		}	  
       
   356 	if (state)
       
   357 		{
       
   358 		iFontInfo->iMaxCharWidthInPixels = 0;
       
   359 		for (int i = 0; i < iFontInfo->NumCodeSections(); i++)
       
   360 			{
       
   361 			WidthsCodeSection* codesection = iFontInfo->CodeSectionList(i);
       
   362 			for (int j = 0; j < codesection->NumWidths(); j++)
       
   363 				{
       
   364 				int width = codesection->WidthList(j)->iWidthInPixels;
       
   365 				if (width > iFontInfo->iMaxCharWidthInPixels)
       
   366 					iFontInfo->iMaxCharWidthInPixels = (uint16) width;
       
   367 				}
       
   368 			}
       
   369 		}
       
   370 	if (state)
       
   371 		{
       
   372 		iPdrModelStore.AddFontInfo(iFontInfo);
       
   373 		cout << "Fontinfo read\n";
       
   374 		}
       
   375 	else
       
   376 		iFontInfo->Delete();
       
   377 	return state;
       
   378 	}
       
   379 
       
   380 boolean PdrReader::ReadStyle()
       
   381 	{
       
   382 	boolean state = etrue;
       
   383 	Record *fontinfo;
       
   384 	PdrStyle *style;
       
   385 	String label;
       
   386 	if (!iTypefaceFonts->iIsScalable)
       
   387 		style = &iFontHeight->iStyle[iIndex];
       
   388 	else
       
   389 		style = &iTypefaceFonts->iScalableFontHeight.iStyle[iIndex];
       
   390 	style->iIsAvailable = etrue;
       
   391 	state = IdentCopy(label);
       
   392 	if (state)
       
   393 		{
       
   394 		fontinfo = iPdrModelStore.FindFontInfo(label);
       
   395 		if (fontinfo)
       
   396 			style->iFontInfo = fontinfo;
       
   397 		else
       
   398 			{
       
   399 			Error("Fontinfo not found");
       
   400 			state = efalse;
       
   401 			}
       
   402 		}
       
   403 	return state;
       
   404 	}
       
   405 
       
   406 boolean PdrReader::ReadFontHeight()
       
   407 	{
       
   408 	boolean state = etrue;
       
   409 	int num;
       
   410 	if (iTypefaceFonts->iIsScalable == etrue)
       
   411 		{
       
   412 		state = efalse;
       
   413 		Error("Scalablefontheight already defined");
       
   414 		}
       
   415 	else
       
   416 		iFontHeight = PdrFontHeight::New();
       
   417 	if (state)
       
   418 		state = NewLine();
       
   419 
       
   420 	while (!IdentComp(IdentEndFontHeight) && !_EOF() && state)
       
   421 		{
       
   422 		if (iLex->iType == ELexIdent)
       
   423 			{
       
   424 			if (IdentComp(IdentHeight))
       
   425 				{
       
   426 				if (Number(num))
       
   427 					iFontHeight->iHeightInTwips = num;
       
   428 				else
       
   429 					state = efalse;
       
   430 				}
       
   431 			else if (IdentComp(IdentWidthScale))
       
   432 				{
       
   433 				if (Number(num))
       
   434 					iFontHeight->iWidthScale = num;
       
   435 				else
       
   436 					state = efalse;
       
   437 				}
       
   438 			else if (IdentComp(IdentNormal))
       
   439 				{
       
   440 				iIndex = Normal;
       
   441 				state = ReadStyle();
       
   442 				}
       
   443 			else if (IdentComp(IdentBold))
       
   444 				{
       
   445 				iIndex = Bold;
       
   446 				state = ReadStyle();
       
   447 				}
       
   448 			else if (IdentComp(IdentItalic))
       
   449 				{
       
   450 				iIndex = Italic;
       
   451 				state = ReadStyle();
       
   452 				}
       
   453 			else if (IdentComp(IdentBoldItalic))
       
   454 				{
       
   455 				iIndex = BoldItalic;
       
   456 				state = ReadStyle();
       
   457 				}
       
   458 			else if (IdentComp(IdentCommand))
       
   459 				{
       
   460 				state = Command(iFontHeight->iCommandString);
       
   461 				}
       
   462 			else
       
   463 				{
       
   464 				Error("Unrecognised fontheight identifier");
       
   465 				state = efalse;
       
   466 				}
       
   467 			}
       
   468 		else
       
   469 			{
       
   470 			Error("Fontheight identifier expected");
       
   471 			state = efalse;
       
   472 			}
       
   473 		if (state)
       
   474 			state = NewLine();
       
   475 		}
       
   476 	if (state)
       
   477 		{
       
   478 		iTypefaceFonts->AddFontHeight(iFontHeight);
       
   479 		cout << "Fontheight read\n";
       
   480 		}
       
   481 	else
       
   482 		iFontHeight->Delete();
       
   483 	return state;
       
   484 	}
       
   485 
       
   486 boolean PdrReader::ReadScalableFontHeight()
       
   487 	{
       
   488 	boolean state = etrue;
       
   489 	int num;
       
   490 	if (iTypefaceFonts->NumFontHeights())
       
   491 		{
       
   492 		state = efalse;
       
   493 		Error("Non-scalable fontheights already defined");
       
   494 		}
       
   495 	else if (iTypefaceFonts->iIsScalable == etrue)
       
   496 		{
       
   497 		state = efalse;
       
   498 		Error("Scalablefontheight already defined");
       
   499 		}
       
   500 	iTypefaceFonts->iIsScalable=etrue;
       
   501 	if (state)
       
   502 		state = NewLine();
       
   503 
       
   504 	while (!IdentComp(IdentEndScalableFontHeight) && !_EOF() && state)
       
   505 		{
       
   506 		if (iLex->iType == ELexIdent)
       
   507 			{
       
   508 			if (IdentComp(IdentHeightMin))
       
   509 				{
       
   510 				if (Number(num))
       
   511 					iTypefaceFonts->iScalableFontHeight.iHeightMinInTwips = num;
       
   512 				else
       
   513 					state = efalse;
       
   514 				}
       
   515 			else if (IdentComp(IdentHeightMax))
       
   516 				{
       
   517 				if (Number(num))
       
   518 					iTypefaceFonts->iScalableFontHeight.iHeightMaxInTwips = num;
       
   519 				else
       
   520 					state = efalse;
       
   521 				}
       
   522 			else if (IdentComp(IdentHeightDelta))
       
   523 				{
       
   524 				if (Number(num))
       
   525 					iTypefaceFonts->iScalableFontHeight.iHeightDeltaInTwips = num;
       
   526 				else
       
   527 					state = efalse;
       
   528 				}
       
   529 			else if (IdentComp(IdentNormal))
       
   530 				{
       
   531 				iIndex = Normal;
       
   532 				state = ReadStyle();
       
   533 				}
       
   534 			else if (IdentComp(IdentBold))
       
   535 				{
       
   536 				iIndex = Bold;
       
   537 				state = ReadStyle();
       
   538 				}
       
   539 			else if (IdentComp(IdentItalic))
       
   540 				{
       
   541 				iIndex = Italic;
       
   542 				state = ReadStyle();
       
   543 				}
       
   544 			else if (IdentComp(IdentBoldItalic))
       
   545 				{
       
   546 				iIndex = BoldItalic;
       
   547 				state = ReadStyle();
       
   548 				}
       
   549 			else if (IdentComp(IdentCommand))
       
   550 				{
       
   551 				state = Command(iTypefaceFonts->iScalableFontHeight.iCommandString);
       
   552 				}
       
   553 			else
       
   554 				{
       
   555 				Error("Unrecognised scalablefontheight identifier");
       
   556 				state = efalse;
       
   557 				}
       
   558 			}
       
   559 		else
       
   560 			{
       
   561 			Error("Scalablefontheight identifier expected");
       
   562 			state = efalse;
       
   563 			}
       
   564 		if (state)
       
   565 			state = NewLine();
       
   566 		}	  
       
   567 	if (state)
       
   568 		{
       
   569 		cout << "Scalablefontheight read\n";
       
   570 		}
       
   571 	else
       
   572 		{
       
   573 		if (!iTypefaceFonts->iIsScalable)
       
   574 			iFontHeight->Delete();
       
   575 		}
       
   576 	return state;
       
   577 	}
       
   578 
       
   579 boolean PdrReader::ReadTypefaceFonts()
       
   580 	{
       
   581 	boolean state = etrue;
       
   582 	Record* translates;
       
   583 	String label;
       
   584 	iTypefaceFonts = TypefaceFonts::New();
       
   585 	state = IdentCopy(iTypefaceFonts->iLabel);
       
   586 	if (state)
       
   587 		state = NewLine();
       
   588 	while (!IdentComp(IdentEndTypefaceFonts) && !_EOF() && state)
       
   589 		{
       
   590 		if (iLex->iType == ELexIdent)
       
   591 			{
       
   592 			if (IdentComp(IdentTypefaceName))
       
   593 				{
       
   594 				if (StringCopy(iTypefaceFonts->iTypeface.iName))
       
   595 					while (iLex->iType != ELexNL)
       
   596 					{	if (IdentComp(IdentProportional))
       
   597 							iTypefaceFonts->iTypeface.iFlags = boolean(iTypefaceFonts->iTypeface.iFlags | Proportional);
       
   598 						else if (IdentComp(IdentSerif))
       
   599 							iTypefaceFonts->iTypeface.iFlags = boolean(iTypefaceFonts->iTypeface.iFlags | Serif);
       
   600 						else if (IdentComp(IdentSymbol))
       
   601 							iTypefaceFonts->iTypeface.iFlags = boolean(iTypefaceFonts->iTypeface.iFlags | Symbol);
       
   602 						else
       
   603 							{ 
       
   604 							Error("Typefacefonts identifier or newline expected");
       
   605 							state = efalse;
       
   606 							}
       
   607 					}
       
   608 				else
       
   609 					state = efalse;
       
   610 				}
       
   611 			else if (IdentComp(IdentTypefaceTranslates))
       
   612 				{
       
   613 				state = IdentCopy(label);
       
   614 				if (state)
       
   615 					{
       
   616 					translates = iPdrModelStore.FindTranslates(label);
       
   617 					if (translates)
       
   618 						iTypefaceFonts->iTranslates = translates;
       
   619 					else
       
   620 						{
       
   621 						Error("Translates not found");
       
   622 						state = efalse;
       
   623 						}
       
   624 					}
       
   625 				}
       
   626 			else if (IdentComp(IdentFontHeight))
       
   627 				{
       
   628 				state = ReadFontHeight();
       
   629 				}
       
   630 			else if (IdentComp(IdentScalableFontHeight))
       
   631 				{
       
   632 				state = ReadScalableFontHeight();
       
   633 				}
       
   634 			else
       
   635 				{
       
   636 				Error("Unrecognised typefacefonts identifier");
       
   637 				state = efalse;
       
   638 				}
       
   639 			}
       
   640 		else
       
   641 			{
       
   642 			Error("Typefacefonts identifier expected");
       
   643 			state = efalse;
       
   644 			}
       
   645 		if (state)
       
   646 			state = NewLine();
       
   647 		}	  
       
   648 	if (state)
       
   649 		{
       
   650 		iPdrModelStore.AddTypefaceFonts(iTypefaceFonts);
       
   651 		cout << "Typefacefonts read\n";
       
   652 		}
       
   653 	else
       
   654 		iTypefaceFonts->Delete();
       
   655 	return state;
       
   656 	}
       
   657 
       
   658 boolean PdrReader::ReadModel()
       
   659 	{
       
   660 	boolean state = etrue;
       
   661 	int num;
       
   662 	iModel = PrinterModelHeader::New();
       
   663 	Record* resources;
       
   664 //	Record* extrainfo;
       
   665 	String label;
       
   666 	state = IdentCopy(iModel->iLabel);
       
   667 	if (state)
       
   668 		state = NewLine();
       
   669 	while (!IdentComp(IdentEndModel) && !_EOF() && state)
       
   670 		{
       
   671 		if (iLex->iType == ELexIdent)
       
   672 			{
       
   673 			if	(IdentComp(IdentModelName))
       
   674 				{
       
   675 				if (StringCopy(iModel->iEntry.iName))
       
   676 					while (iLex->iType != ELexNL)
       
   677 						{
       
   678 						if (IdentComp(IdentRequiresPrinterPort))
       
   679 							iModel->iEntry.iRequiresPrinterPort = etrue;
       
   680 						else
       
   681 							{
       
   682 							Error("Model identifier or newline expected");
       
   683 							state = efalse;
       
   684 							}
       
   685 						}
       
   686 				else
       
   687 					state = efalse;
       
   688 				}
       
   689 			else if (IdentComp(IdentModelUid))
       
   690 				state = Number(iModel->iEntry.iUid);
       
   691 			else if (IdentComp(IdentModelFlags))
       
   692 				{
       
   693 				state = Number(num);
       
   694 				iModel->iInfo.iFlags = num;
       
   695 				}
       
   696 			else if (IdentComp(IdentModelResources))
       
   697 				{
       
   698 				state = IdentCopy(label);
       
   699 				if (state)
       
   700 					{
       
   701 					resources = iPdrModelStore.FindResources(label);
       
   702 					if (resources)
       
   703 						iModel->iInfo.iResources = resources;
       
   704 					else
       
   705 						{
       
   706 						Error("Resources not found");
       
   707 						state = efalse;
       
   708 						}
       
   709 					}
       
   710 				}
       
   711 /*			else if (IdentComp(IdentSpareRecord))
       
   712 				{
       
   713 				state = IdentCopy(label);
       
   714 				if (state)
       
   715 					{
       
   716 					extrainfo = iPdrModelStore.FindExtraInfo(label);
       
   717 					if (extrainfo)
       
   718 						iModel->iInfo.iSpareRecord = extrainfo;
       
   719 					else
       
   720 						{
       
   721 						Error("Spare record not found");
       
   722 						state = efalse;
       
   723 						}
       
   724 					}
       
   725 				}
       
   726 */
       
   727 			else if (IdentComp(IdentKPixelWidth))
       
   728 				{
       
   729 				if (Number(num))
       
   730 					iModel->iInfo.iKPixelWidthInTwips = num;
       
   731 				else
       
   732 					state = efalse;
       
   733 				}
       
   734 			else if (IdentComp(IdentKPixelHeight))
       
   735 				{
       
   736 				if (Number(num))
       
   737 					iModel->iInfo.iKPixelHeightInTwips = num;
       
   738 				else
       
   739 					state = efalse;
       
   740 				}
       
   741 			else if (IdentComp(IdentPortraitOffset))
       
   742 				{
       
   743 				if (Number(num))
       
   744 					{
       
   745 					iModel->iInfo.iPortraitOffsetInPixels.iX = num;
       
   746 					if (Number(num))
       
   747 						iModel->iInfo.iPortraitOffsetInPixels.iY = num;
       
   748 					else
       
   749 						state = efalse;
       
   750 					}
       
   751 				else
       
   752 					state = efalse;
       
   753 				}
       
   754 			else if (IdentComp(IdentLandscapeOffset))
       
   755 				{
       
   756 				if (Number(num))
       
   757 					{
       
   758 					iModel->iInfo.iLandscapeOffsetInPixels.iX = num;
       
   759 					if (Number(num))
       
   760 						iModel->iInfo.iLandscapeOffsetInPixels.iY = num;
       
   761 					else
       
   762 						state = efalse;
       
   763 					}
       
   764 				else
       
   765 					state = efalse;
       
   766 				}
       
   767 			else if (IdentComp(IdentMinMarginLeft))
       
   768 				{
       
   769 				if (Number(num))
       
   770 					iModel->iInfo.iMinMarginsInPixels.iLeft = num;
       
   771 				else
       
   772 					state = efalse;
       
   773 				}
       
   774 			else if (IdentComp(IdentMinMarginRight))
       
   775 				{
       
   776 				if (Number(num))
       
   777 					iModel->iInfo.iMinMarginsInPixels.iRight = num;
       
   778 				else
       
   779 					state = efalse;
       
   780 				}
       
   781 			else if (IdentComp(IdentMinMarginTop))
       
   782 				{
       
   783 				if (Number(num))
       
   784 					iModel->iInfo.iMinMarginsInPixels.iTop = num;
       
   785 				else
       
   786 					state = efalse;
       
   787 				}
       
   788 			else if (IdentComp(IdentMinMarginBottom))
       
   789 				{
       
   790 				if (Number(num))
       
   791 					iModel->iInfo.iMinMarginsInPixels.iBottom = num;
       
   792 				else
       
   793 					state = efalse;
       
   794 				}
       
   795 			else if (IdentComp(IdentDisplayMode))
       
   796 				{
       
   797         	    int i; // DEF102183: Graphics tools fail to build using MS VC8.
       
   798 				for (i = 0; (i < NumDisplayModeValues) && !IdentComp(IdentDisplayModeValue[i]); i++)
       
   799 					{	// Tries to match display mode identifier
       
   800 					}
       
   801 				if (i < NumDisplayModeValues)
       
   802 					{
       
   803 					iModel->iInfo.iDisplayMode = i;
       
   804 					}
       
   805 				else
       
   806 					{
       
   807 					state = efalse;
       
   808 					Error("Display mode identifier expected");
       
   809 					}
       
   810 				}
       
   811 			else if (IdentComp(IdentTypefaceFontss))
       
   812 				{
       
   813 				state = NewLine();
       
   814 				while (!IdentComp(IdentEndTypefaceFontss) && !_EOF() && state)
       
   815 					{
       
   816 					TypefaceFontsEntry* typefacefontsentry = NULL;
       
   817 					if (iLex->iType == ELexIdent)
       
   818 						{
       
   819 						state = IdentCopy(label);
       
   820 						Record* typefacefonts = iPdrModelStore.FindTypefaceFonts(label);
       
   821 						if (typefacefonts)
       
   822 							{
       
   823 							typefacefontsentry = TypefaceFontsEntry::New(typefacefonts);
       
   824 							state = etrue;
       
   825 							}
       
   826 						else
       
   827 							{
       
   828 							Error("Typefacefonts not found");
       
   829 							state = efalse;
       
   830 							}
       
   831 						}
       
   832 					if (state)
       
   833 						{
       
   834 						while ((iLex->iType != ELexNL) && !_EOF() && state)
       
   835 							{
       
   836 							if (IdentComp(IdentNotInPortrait))
       
   837 								{
       
   838 								typefacefontsentry->iNotInPortrait = etrue;
       
   839 								}
       
   840 							else if (IdentComp(IdentNotInLandscape))
       
   841 								{
       
   842 								typefacefontsentry->iNotInLandscape = etrue;
       
   843 								}
       
   844 							else
       
   845 								{
       
   846 								Error("Typefacefontsentry identifier or newline expected");
       
   847 								state = efalse;
       
   848 								}
       
   849 							}
       
   850 						if (state)
       
   851 							iModel->iInfo.AddTypefaceFontsEntry(typefacefontsentry);
       
   852 						else
       
   853 							typefacefontsentry->Delete();
       
   854 						}
       
   855 					if (state)
       
   856 						state = NewLine();
       
   857 					}
       
   858 				}
       
   859 			else
       
   860 				{
       
   861 				Error("unrecognised model identifier");
       
   862 				state = efalse;
       
   863 				}
       
   864 			}
       
   865 		else
       
   866 			{
       
   867 			Error("Model identifier expected");
       
   868 			state = efalse;
       
   869 			}
       
   870 		if (state)
       
   871 			state = NewLine();
       
   872 		}
       
   873 	if (state)
       
   874 		{
       
   875 		iPdrModelStore.AddModel(iModel);
       
   876 		cout << "Model read\n";
       
   877 		}
       
   878 	else
       
   879 		iModel->Delete();
       
   880 	return state;
       
   881 	}
       
   882 
       
   883 boolean PdrReader::ReadPdrStoreFile()
       
   884 	{
       
   885 	boolean state = etrue;
       
   886 	if (iPdrStoreFile)
       
   887 		{
       
   888 		state = efalse;
       
   889 		Error("Pdrstorefile already read");
       
   890 		}
       
   891 	else
       
   892 		{
       
   893 		iPdrStoreFile = PdrStoreFile::New();
       
   894 		String label;
       
   895 		Record* model;
       
   896 		state = NewLine();
       
   897 		while (!IdentComp(IdentEndPdrStoreFile) && !_EOF() && state)
       
   898 			{
       
   899 			if (IdentComp(IdentPDLName))
       
   900 				{
       
   901 				state = StringCopy(iPdrStoreFile->iPDLName);
       
   902 				}
       
   903 			else if (IdentComp(IdentPDLUid))
       
   904 				{
       
   905 				state = Number(iPdrStoreFile->iPDLUid);
       
   906 				}
       
   907 			else if (IdentComp(IdentModels))
       
   908 				{
       
   909 				state = NewLine();
       
   910 				while (!IdentComp(IdentEndModels) && !_EOF() && state)
       
   911 					{
       
   912 					state = IdentCopy(label);
       
   913 					if (state)
       
   914 						{
       
   915 						model = iPdrModelStore.FindModel(label);
       
   916 						if (model)
       
   917 							{
       
   918 							iPdrStoreFile->AddModel((PrinterModelHeader*)model);
       
   919 							}
       
   920 						else
       
   921 							{
       
   922 							Error("model not found");
       
   923 							state = efalse;
       
   924 							}
       
   925 						}
       
   926 					if (state)
       
   927 						state = NewLine();
       
   928 					}
       
   929 				}
       
   930 			else
       
   931 				{
       
   932 				Error("Pdrstorefile identifier expected");
       
   933 				state = efalse;
       
   934 				}
       
   935 			if (state)
       
   936 				state = NewLine();
       
   937 			}
       
   938 		if (state)
       
   939 			{
       
   940 			iPdrModelStore.AddPdrStoreFile(iPdrStoreFile);
       
   941 			cout << "Pdrstorefile read\n";
       
   942 			}	
       
   943 		else
       
   944 			iPdrStoreFile->Delete();
       
   945 		}
       
   946 	return state;
       
   947 	}
       
   948 
       
   949 EXPORT_C boolean PdrReader::Store(const String& aFilename)
       
   950 	{
       
   951 	boolean state = etrue;
       
   952 	if (!iPdrStoreFile)
       
   953 		{
       
   954 		state = efalse;
       
   955 		Error("No pdrstore file record");
       
   956 		}
       
   957 	else
       
   958 		state = iPdrModelStore.Store(aFilename);
       
   959 	return state;
       
   960 	}
       
   961 
       
   962 boolean PdrReader::Command(String& aCommand)
       
   963 	{
       
   964 	boolean state = etrue;
       
   965 	String string;
       
   966 	state = StringCopy(string);
       
   967 	int length = string.Length();
       
   968 	for (int i = 0; i < length; i++)
       
   969 		{
       
   970 		char ch = string[i];
       
   971 		if (ch == '<')	// Read control character
       
   972 			{
       
   973 			ch = 0;
       
   974 			for (i = i + 1; (i < length) && (string[i] != '>'); i++)
       
   975 				ch = char((ch * 10) + (string[i] - '0'));
       
   976 			}
       
   977 		aCommand += ch;
       
   978 		}
       
   979 	return state;
       
   980 	}
       
   981 /*
       
   982 boolean PdrReader::ReadExtraInfo()
       
   983 	{
       
   984 	boolean state = etrue;
       
   985 	String label;
       
   986 	PdrExtraInfo* extrainfo = new PdrExtraInfo();
       
   987 	state = IdentCopy(extrainfo->iLabel);
       
   988 	if (state)
       
   989 		state = NewLine();
       
   990 	while (!IdentComp(IdentEndExtraInfo) && !_EOF() && state)
       
   991 		{
       
   992 		String* string = new String;
       
   993 		state = Command(*string);
       
   994 		if (state)
       
   995 			extrainfo->iInfo.Add(string);
       
   996 		else
       
   997 			delete string;
       
   998 		state = NewLine();
       
   999 		}
       
  1000 	if (state)
       
  1001 		{
       
  1002 		iPdrModelStore.AddExtraInfo(extrainfo);
       
  1003 		cout << "Extra info read\n";
       
  1004 		}
       
  1005 	else
       
  1006 		delete extrainfo;
       
  1007 	return state;
       
  1008 	}
       
  1009 */