1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstools/bitmapfonttools/src/PDRREADR.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1009 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Header PDRREADR.CPP
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +#include "PDRREADR.H"
1.24 +
1.25 +const int NumResources=34;
1.26 +
1.27 +String IdentResource[NumResources] =
1.28 + {
1.29 + "Reset",
1.30 + "SetPageSize",
1.31 + "PreAmble",
1.32 + "PostAmble",
1.33 + "SetTextColor", // !!
1.34 + "BoldOn",
1.35 + "BoldOff",
1.36 + "ItalicOn",
1.37 + "ItalicOff",
1.38 + "UnderlineOn",
1.39 + "UnderlineOff",
1.40 + "StrikethroughOn",
1.41 + "StrikethroughOff",
1.42 + "NewPage",
1.43 + "Portrait",
1.44 + "Landscape",
1.45 + "SetXPos",
1.46 + "SetYPos",
1.47 + "IncrementXPos",
1.48 + "IncrementYPos",
1.49 + "CarriageReturn",
1.50 + "SetGraphicsColor", // !!
1.51 + "BitmapStart",
1.52 + "BitmapEnd",
1.53 + "ScanLine",
1.54 + "EndScanLine", // !!
1.55 + "Resource1",
1.56 + "Resource2",
1.57 + "Resource3",
1.58 + "Resource4",
1.59 + "Resource5",
1.60 + "Resource6",
1.61 + "Resource7",
1.62 + "Resource8"
1.63 + };
1.64 +
1.65 +const int NumDisplayModeValues = 11;
1.66 +
1.67 +String IdentDisplayModeValue[NumDisplayModeValues] =
1.68 + {
1.69 + "None",
1.70 + "Gray2",
1.71 + "Gray4",
1.72 + "Gray16",
1.73 + "Gray256",
1.74 + "Color16",
1.75 + "Color256",
1.76 + "Color64K",
1.77 + "Color16M",
1.78 + "Rgb",
1.79 + "Color4K"
1.80 + };
1.81 +
1.82 +EXPORT_C PdrReader::PdrReader()
1.83 + : Reader(),
1.84 + iPdrModelStore(),
1.85 + iPdrStoreFile(NULL),
1.86 + iResources(NULL),
1.87 + iTranslates(NULL),
1.88 + iCodeSection(NULL),
1.89 + iFontInfo(NULL),
1.90 + iIndex(Normal),
1.91 + iFontHeight(NULL),
1.92 + iTypefaceFonts(NULL),
1.93 + iModel(NULL)
1.94 + {
1.95 + }
1.96 +
1.97 +EXPORT_C boolean PdrReader::Read(const String& aFilename)
1.98 + {
1.99 + boolean state = Open(aFilename);
1.100 +
1.101 + while (!_EOF() && state)
1.102 + {
1.103 + if (IdentComp(IdentResources))
1.104 + state = ReadResources();
1.105 + else if (IdentComp(IdentTranslates))
1.106 + state = ReadTranslates();
1.107 + else if (IdentComp(IdentFontInfo))
1.108 + state = ReadFontInfo();
1.109 + else if (IdentComp(IdentTypefaceFonts))
1.110 + state = ReadTypefaceFonts();
1.111 +// else if (IdentComp(IdentExtraInfo))
1.112 +// state = ReadExtraInfo();
1.113 + else if (IdentComp(IdentModel))
1.114 + state = ReadModel();
1.115 + else if (IdentComp(IdentPdrStoreFile))
1.116 + state = ReadPdrStoreFile();
1.117 + else
1.118 + {
1.119 + Error("Resource identifier expected");
1.120 + state = efalse;
1.121 + }
1.122 + if (state)
1.123 + state = NewLine();
1.124 + }
1.125 + return state;
1.126 + }
1.127 +
1.128 +EXPORT_C PdrReader::~PdrReader()
1.129 + {
1.130 + }
1.131 +
1.132 +boolean PdrReader::ReadResources()
1.133 + {
1.134 + boolean state = etrue;
1.135 + iResources = PdrResources::New();
1.136 + state = IdentCopy(iResources->iLabel);
1.137 + if (state)
1.138 + state = NewLine();
1.139 + while (!IdentComp(IdentEndResources) && !_EOF() && state)
1.140 + {
1.141 + int i; // DEF102183: Graphics tools fail to build using MS VC8.
1.142 + for (i = 0; (i < NumResources) && !IdentComp(IdentResource[i]); i++)
1.143 + { // Tries to match resources identifier
1.144 + }
1.145 + if (i < NumResources)
1.146 + {
1.147 + PdrResource *resource = PdrResource::New();
1.148 + state = Command(resource->iString);
1.149 + resource->iId = i;
1.150 + if (state)
1.151 + {
1.152 + iResources->AddResource(resource);
1.153 + state = NewLine();
1.154 + }
1.155 + else
1.156 + resource->Delete();
1.157 + }
1.158 + else
1.159 + {
1.160 + state = efalse;
1.161 + Error("Resources identifier expected");
1.162 + }
1.163 + }
1.164 + if (state)
1.165 + {
1.166 + iPdrModelStore.AddResources(iResources);
1.167 + cout << "Resources read\n";
1.168 + }
1.169 + else
1.170 + iResources->Delete();
1.171 + return state;
1.172 + }
1.173 +
1.174 +boolean PdrReader::ReadTranslates()
1.175 + {
1.176 + int num;
1.177 + boolean state = etrue;
1.178 + iTranslates = PdrTranslates::New();
1.179 + state = IdentCopy(iTranslates->iLabel);
1.180 + if (state)
1.181 + state = NewLine();
1.182 + while (!IdentComp(IdentEndTranslates) && !_EOF() && state)
1.183 + {
1.184 + if (iLex->iType == ELexNumber)
1.185 + {
1.186 + PdrTranslation *translation = PdrTranslation::New();
1.187 + Number(num);
1.188 + translation->iFrom = uint16(num);
1.189 + char ch;
1.190 + state = Operator(ch);
1.191 + if (state)
1.192 + {
1.193 + state = (ch == ':');
1.194 + if (state)
1.195 + {
1.196 + if (iLex->iType == ELexNumber)
1.197 + {
1.198 + state = Number(num);
1.199 + translation->iTo += char(num);
1.200 + }
1.201 + else
1.202 + {
1.203 + state = Command(translation->iTo);
1.204 + }
1.205 + if (state)
1.206 + state = NewLine();
1.207 + }
1.208 + else
1.209 + {
1.210 + Error("Operator ':' expected");
1.211 + }
1.212 + }
1.213 + if (state)
1.214 + iTranslates->AddTranslation(translation);
1.215 + else
1.216 + translation->Delete();
1.217 + }
1.218 + }
1.219 + if (state)
1.220 + {
1.221 + iPdrModelStore.AddTranslates(iTranslates);
1.222 + cout << "Translates read\n";
1.223 + }
1.224 + else
1.225 + iTranslates->Delete();
1.226 + return state;
1.227 + }
1.228 +
1.229 +boolean PdrReader::ReadCodeSection(int aCode)
1.230 + {
1.231 + boolean state = etrue;
1.232 + int code;
1.233 + int num;
1.234 + iCodeSection = WidthsCodeSection::New();
1.235 + char ch = 0;
1.236 + state = Number(num);
1.237 + if ((num<aCode) && state)
1.238 + {
1.239 + Error("CodeSection out of sequence");
1.240 + state = efalse;
1.241 + }
1.242 + if (state)
1.243 + {
1.244 + iCodeSection->iStart = uint16(num);
1.245 + state = Operator(ch);
1.246 + if (state)
1.247 + state = (ch == ':');
1.248 + if (state)
1.249 + {
1.250 + state = Number(num);
1.251 + iCodeSection->iEnd = uint16(num);
1.252 + state = NewLine();
1.253 + }
1.254 + else
1.255 + {
1.256 + state = efalse;
1.257 + Error("Operator ':' expected");
1.258 + }
1.259 + }
1.260 + else
1.261 + state = efalse;
1.262 + while (!IdentComp(IdentEndCodeSection) && !_EOF() && state)
1.263 + {
1.264 + if (iLex->iType != ELexNL)
1.265 + {
1.266 + state = Number(code);
1.267 + if ((code != iCodeSection->iStart + iCodeSection->NumWidths()) && state)
1.268 + {
1.269 + state = efalse;
1.270 + Error("Width out of sequence");
1.271 + }
1.272 + if (state)
1.273 + state = Operator(ch);
1.274 + if (state)
1.275 + state = (ch == ':');
1.276 + if (state)
1.277 + {
1.278 + Width *width = Width::New();
1.279 + if (Number(num))
1.280 + {
1.281 + width->iWidthInPixels = (uint16) num;
1.282 + iCodeSection->AddWidth(width);
1.283 + }
1.284 + else
1.285 + {
1.286 + state = efalse;
1.287 + width->Delete();
1.288 + }
1.289 + }
1.290 + }
1.291 + else
1.292 + state = NewLine();
1.293 + }
1.294 + if (state)
1.295 + {
1.296 + num = ((iCodeSection->iEnd + 1) - iCodeSection->iStart);
1.297 + if ((num != iCodeSection->NumWidths()) && (iCodeSection->NumWidths() != 1))
1.298 + {
1.299 + Error("Wrong number of widths in codesection");
1.300 + state = efalse;
1.301 + }
1.302 + }
1.303 + if (state)
1.304 + {
1.305 + iFontInfo->AddCodeSection(iCodeSection);
1.306 +// cout << "Codesection read\n";
1.307 + }
1.308 + else
1.309 + iCodeSection->Delete();
1.310 + return state;
1.311 + }
1.312 +
1.313 +boolean PdrReader::ReadFontInfo()
1.314 + {
1.315 + boolean state = etrue;
1.316 + iFontInfo = FontInfo::New();
1.317 + int num;
1.318 + state = IdentCopy(iFontInfo->iLabel);
1.319 + if (state)
1.320 + state = NewLine();
1.321 + while (!IdentComp(IdentEndFontInfo) && !_EOF() && state)
1.322 + {
1.323 + if (iLex->iType == ELexIdent)
1.324 + {
1.325 + if (IdentComp(IdentCodeSection))
1.326 + {
1.327 + int code = 0,size = iFontInfo->NumCodeSections();
1.328 + if (size)
1.329 + code = iFontInfo->CodeSectionList(size - 1)->iEnd + 1;
1.330 + state = ReadCodeSection(code);
1.331 + }
1.332 + else if (IdentComp(IdentAscent))
1.333 + {
1.334 + if (Number(num))
1.335 + iFontInfo->iAscentInPixels = uint16(num);
1.336 + else
1.337 + state = efalse;
1.338 + }
1.339 + else if (IdentComp(IdentMaxNormalCharWidth))
1.340 + {
1.341 + state = Number(num);
1.342 + if (state)
1.343 + iFontInfo->iMaxNormalCharWidthInPixels = uint16(num);
1.344 + }
1.345 + else
1.346 + {
1.347 + Error("Unrecognised fontinfo identifier");
1.348 + state = efalse;
1.349 + }
1.350 + }
1.351 + else
1.352 + {
1.353 + Error("Fontinfo identifier expected");
1.354 + state = efalse;
1.355 + }
1.356 + if (state)
1.357 + state = NewLine();
1.358 + }
1.359 + if (state)
1.360 + {
1.361 + iFontInfo->iMaxCharWidthInPixels = 0;
1.362 + for (int i = 0; i < iFontInfo->NumCodeSections(); i++)
1.363 + {
1.364 + WidthsCodeSection* codesection = iFontInfo->CodeSectionList(i);
1.365 + for (int j = 0; j < codesection->NumWidths(); j++)
1.366 + {
1.367 + int width = codesection->WidthList(j)->iWidthInPixels;
1.368 + if (width > iFontInfo->iMaxCharWidthInPixels)
1.369 + iFontInfo->iMaxCharWidthInPixels = (uint16) width;
1.370 + }
1.371 + }
1.372 + }
1.373 + if (state)
1.374 + {
1.375 + iPdrModelStore.AddFontInfo(iFontInfo);
1.376 + cout << "Fontinfo read\n";
1.377 + }
1.378 + else
1.379 + iFontInfo->Delete();
1.380 + return state;
1.381 + }
1.382 +
1.383 +boolean PdrReader::ReadStyle()
1.384 + {
1.385 + boolean state = etrue;
1.386 + Record *fontinfo;
1.387 + PdrStyle *style;
1.388 + String label;
1.389 + if (!iTypefaceFonts->iIsScalable)
1.390 + style = &iFontHeight->iStyle[iIndex];
1.391 + else
1.392 + style = &iTypefaceFonts->iScalableFontHeight.iStyle[iIndex];
1.393 + style->iIsAvailable = etrue;
1.394 + state = IdentCopy(label);
1.395 + if (state)
1.396 + {
1.397 + fontinfo = iPdrModelStore.FindFontInfo(label);
1.398 + if (fontinfo)
1.399 + style->iFontInfo = fontinfo;
1.400 + else
1.401 + {
1.402 + Error("Fontinfo not found");
1.403 + state = efalse;
1.404 + }
1.405 + }
1.406 + return state;
1.407 + }
1.408 +
1.409 +boolean PdrReader::ReadFontHeight()
1.410 + {
1.411 + boolean state = etrue;
1.412 + int num;
1.413 + if (iTypefaceFonts->iIsScalable == etrue)
1.414 + {
1.415 + state = efalse;
1.416 + Error("Scalablefontheight already defined");
1.417 + }
1.418 + else
1.419 + iFontHeight = PdrFontHeight::New();
1.420 + if (state)
1.421 + state = NewLine();
1.422 +
1.423 + while (!IdentComp(IdentEndFontHeight) && !_EOF() && state)
1.424 + {
1.425 + if (iLex->iType == ELexIdent)
1.426 + {
1.427 + if (IdentComp(IdentHeight))
1.428 + {
1.429 + if (Number(num))
1.430 + iFontHeight->iHeightInTwips = num;
1.431 + else
1.432 + state = efalse;
1.433 + }
1.434 + else if (IdentComp(IdentWidthScale))
1.435 + {
1.436 + if (Number(num))
1.437 + iFontHeight->iWidthScale = num;
1.438 + else
1.439 + state = efalse;
1.440 + }
1.441 + else if (IdentComp(IdentNormal))
1.442 + {
1.443 + iIndex = Normal;
1.444 + state = ReadStyle();
1.445 + }
1.446 + else if (IdentComp(IdentBold))
1.447 + {
1.448 + iIndex = Bold;
1.449 + state = ReadStyle();
1.450 + }
1.451 + else if (IdentComp(IdentItalic))
1.452 + {
1.453 + iIndex = Italic;
1.454 + state = ReadStyle();
1.455 + }
1.456 + else if (IdentComp(IdentBoldItalic))
1.457 + {
1.458 + iIndex = BoldItalic;
1.459 + state = ReadStyle();
1.460 + }
1.461 + else if (IdentComp(IdentCommand))
1.462 + {
1.463 + state = Command(iFontHeight->iCommandString);
1.464 + }
1.465 + else
1.466 + {
1.467 + Error("Unrecognised fontheight identifier");
1.468 + state = efalse;
1.469 + }
1.470 + }
1.471 + else
1.472 + {
1.473 + Error("Fontheight identifier expected");
1.474 + state = efalse;
1.475 + }
1.476 + if (state)
1.477 + state = NewLine();
1.478 + }
1.479 + if (state)
1.480 + {
1.481 + iTypefaceFonts->AddFontHeight(iFontHeight);
1.482 + cout << "Fontheight read\n";
1.483 + }
1.484 + else
1.485 + iFontHeight->Delete();
1.486 + return state;
1.487 + }
1.488 +
1.489 +boolean PdrReader::ReadScalableFontHeight()
1.490 + {
1.491 + boolean state = etrue;
1.492 + int num;
1.493 + if (iTypefaceFonts->NumFontHeights())
1.494 + {
1.495 + state = efalse;
1.496 + Error("Non-scalable fontheights already defined");
1.497 + }
1.498 + else if (iTypefaceFonts->iIsScalable == etrue)
1.499 + {
1.500 + state = efalse;
1.501 + Error("Scalablefontheight already defined");
1.502 + }
1.503 + iTypefaceFonts->iIsScalable=etrue;
1.504 + if (state)
1.505 + state = NewLine();
1.506 +
1.507 + while (!IdentComp(IdentEndScalableFontHeight) && !_EOF() && state)
1.508 + {
1.509 + if (iLex->iType == ELexIdent)
1.510 + {
1.511 + if (IdentComp(IdentHeightMin))
1.512 + {
1.513 + if (Number(num))
1.514 + iTypefaceFonts->iScalableFontHeight.iHeightMinInTwips = num;
1.515 + else
1.516 + state = efalse;
1.517 + }
1.518 + else if (IdentComp(IdentHeightMax))
1.519 + {
1.520 + if (Number(num))
1.521 + iTypefaceFonts->iScalableFontHeight.iHeightMaxInTwips = num;
1.522 + else
1.523 + state = efalse;
1.524 + }
1.525 + else if (IdentComp(IdentHeightDelta))
1.526 + {
1.527 + if (Number(num))
1.528 + iTypefaceFonts->iScalableFontHeight.iHeightDeltaInTwips = num;
1.529 + else
1.530 + state = efalse;
1.531 + }
1.532 + else if (IdentComp(IdentNormal))
1.533 + {
1.534 + iIndex = Normal;
1.535 + state = ReadStyle();
1.536 + }
1.537 + else if (IdentComp(IdentBold))
1.538 + {
1.539 + iIndex = Bold;
1.540 + state = ReadStyle();
1.541 + }
1.542 + else if (IdentComp(IdentItalic))
1.543 + {
1.544 + iIndex = Italic;
1.545 + state = ReadStyle();
1.546 + }
1.547 + else if (IdentComp(IdentBoldItalic))
1.548 + {
1.549 + iIndex = BoldItalic;
1.550 + state = ReadStyle();
1.551 + }
1.552 + else if (IdentComp(IdentCommand))
1.553 + {
1.554 + state = Command(iTypefaceFonts->iScalableFontHeight.iCommandString);
1.555 + }
1.556 + else
1.557 + {
1.558 + Error("Unrecognised scalablefontheight identifier");
1.559 + state = efalse;
1.560 + }
1.561 + }
1.562 + else
1.563 + {
1.564 + Error("Scalablefontheight identifier expected");
1.565 + state = efalse;
1.566 + }
1.567 + if (state)
1.568 + state = NewLine();
1.569 + }
1.570 + if (state)
1.571 + {
1.572 + cout << "Scalablefontheight read\n";
1.573 + }
1.574 + else
1.575 + {
1.576 + if (!iTypefaceFonts->iIsScalable)
1.577 + iFontHeight->Delete();
1.578 + }
1.579 + return state;
1.580 + }
1.581 +
1.582 +boolean PdrReader::ReadTypefaceFonts()
1.583 + {
1.584 + boolean state = etrue;
1.585 + Record* translates;
1.586 + String label;
1.587 + iTypefaceFonts = TypefaceFonts::New();
1.588 + state = IdentCopy(iTypefaceFonts->iLabel);
1.589 + if (state)
1.590 + state = NewLine();
1.591 + while (!IdentComp(IdentEndTypefaceFonts) && !_EOF() && state)
1.592 + {
1.593 + if (iLex->iType == ELexIdent)
1.594 + {
1.595 + if (IdentComp(IdentTypefaceName))
1.596 + {
1.597 + if (StringCopy(iTypefaceFonts->iTypeface.iName))
1.598 + while (iLex->iType != ELexNL)
1.599 + { if (IdentComp(IdentProportional))
1.600 + iTypefaceFonts->iTypeface.iFlags = boolean(iTypefaceFonts->iTypeface.iFlags | Proportional);
1.601 + else if (IdentComp(IdentSerif))
1.602 + iTypefaceFonts->iTypeface.iFlags = boolean(iTypefaceFonts->iTypeface.iFlags | Serif);
1.603 + else if (IdentComp(IdentSymbol))
1.604 + iTypefaceFonts->iTypeface.iFlags = boolean(iTypefaceFonts->iTypeface.iFlags | Symbol);
1.605 + else
1.606 + {
1.607 + Error("Typefacefonts identifier or newline expected");
1.608 + state = efalse;
1.609 + }
1.610 + }
1.611 + else
1.612 + state = efalse;
1.613 + }
1.614 + else if (IdentComp(IdentTypefaceTranslates))
1.615 + {
1.616 + state = IdentCopy(label);
1.617 + if (state)
1.618 + {
1.619 + translates = iPdrModelStore.FindTranslates(label);
1.620 + if (translates)
1.621 + iTypefaceFonts->iTranslates = translates;
1.622 + else
1.623 + {
1.624 + Error("Translates not found");
1.625 + state = efalse;
1.626 + }
1.627 + }
1.628 + }
1.629 + else if (IdentComp(IdentFontHeight))
1.630 + {
1.631 + state = ReadFontHeight();
1.632 + }
1.633 + else if (IdentComp(IdentScalableFontHeight))
1.634 + {
1.635 + state = ReadScalableFontHeight();
1.636 + }
1.637 + else
1.638 + {
1.639 + Error("Unrecognised typefacefonts identifier");
1.640 + state = efalse;
1.641 + }
1.642 + }
1.643 + else
1.644 + {
1.645 + Error("Typefacefonts identifier expected");
1.646 + state = efalse;
1.647 + }
1.648 + if (state)
1.649 + state = NewLine();
1.650 + }
1.651 + if (state)
1.652 + {
1.653 + iPdrModelStore.AddTypefaceFonts(iTypefaceFonts);
1.654 + cout << "Typefacefonts read\n";
1.655 + }
1.656 + else
1.657 + iTypefaceFonts->Delete();
1.658 + return state;
1.659 + }
1.660 +
1.661 +boolean PdrReader::ReadModel()
1.662 + {
1.663 + boolean state = etrue;
1.664 + int num;
1.665 + iModel = PrinterModelHeader::New();
1.666 + Record* resources;
1.667 +// Record* extrainfo;
1.668 + String label;
1.669 + state = IdentCopy(iModel->iLabel);
1.670 + if (state)
1.671 + state = NewLine();
1.672 + while (!IdentComp(IdentEndModel) && !_EOF() && state)
1.673 + {
1.674 + if (iLex->iType == ELexIdent)
1.675 + {
1.676 + if (IdentComp(IdentModelName))
1.677 + {
1.678 + if (StringCopy(iModel->iEntry.iName))
1.679 + while (iLex->iType != ELexNL)
1.680 + {
1.681 + if (IdentComp(IdentRequiresPrinterPort))
1.682 + iModel->iEntry.iRequiresPrinterPort = etrue;
1.683 + else
1.684 + {
1.685 + Error("Model identifier or newline expected");
1.686 + state = efalse;
1.687 + }
1.688 + }
1.689 + else
1.690 + state = efalse;
1.691 + }
1.692 + else if (IdentComp(IdentModelUid))
1.693 + state = Number(iModel->iEntry.iUid);
1.694 + else if (IdentComp(IdentModelFlags))
1.695 + {
1.696 + state = Number(num);
1.697 + iModel->iInfo.iFlags = num;
1.698 + }
1.699 + else if (IdentComp(IdentModelResources))
1.700 + {
1.701 + state = IdentCopy(label);
1.702 + if (state)
1.703 + {
1.704 + resources = iPdrModelStore.FindResources(label);
1.705 + if (resources)
1.706 + iModel->iInfo.iResources = resources;
1.707 + else
1.708 + {
1.709 + Error("Resources not found");
1.710 + state = efalse;
1.711 + }
1.712 + }
1.713 + }
1.714 +/* else if (IdentComp(IdentSpareRecord))
1.715 + {
1.716 + state = IdentCopy(label);
1.717 + if (state)
1.718 + {
1.719 + extrainfo = iPdrModelStore.FindExtraInfo(label);
1.720 + if (extrainfo)
1.721 + iModel->iInfo.iSpareRecord = extrainfo;
1.722 + else
1.723 + {
1.724 + Error("Spare record not found");
1.725 + state = efalse;
1.726 + }
1.727 + }
1.728 + }
1.729 +*/
1.730 + else if (IdentComp(IdentKPixelWidth))
1.731 + {
1.732 + if (Number(num))
1.733 + iModel->iInfo.iKPixelWidthInTwips = num;
1.734 + else
1.735 + state = efalse;
1.736 + }
1.737 + else if (IdentComp(IdentKPixelHeight))
1.738 + {
1.739 + if (Number(num))
1.740 + iModel->iInfo.iKPixelHeightInTwips = num;
1.741 + else
1.742 + state = efalse;
1.743 + }
1.744 + else if (IdentComp(IdentPortraitOffset))
1.745 + {
1.746 + if (Number(num))
1.747 + {
1.748 + iModel->iInfo.iPortraitOffsetInPixels.iX = num;
1.749 + if (Number(num))
1.750 + iModel->iInfo.iPortraitOffsetInPixels.iY = num;
1.751 + else
1.752 + state = efalse;
1.753 + }
1.754 + else
1.755 + state = efalse;
1.756 + }
1.757 + else if (IdentComp(IdentLandscapeOffset))
1.758 + {
1.759 + if (Number(num))
1.760 + {
1.761 + iModel->iInfo.iLandscapeOffsetInPixels.iX = num;
1.762 + if (Number(num))
1.763 + iModel->iInfo.iLandscapeOffsetInPixels.iY = num;
1.764 + else
1.765 + state = efalse;
1.766 + }
1.767 + else
1.768 + state = efalse;
1.769 + }
1.770 + else if (IdentComp(IdentMinMarginLeft))
1.771 + {
1.772 + if (Number(num))
1.773 + iModel->iInfo.iMinMarginsInPixels.iLeft = num;
1.774 + else
1.775 + state = efalse;
1.776 + }
1.777 + else if (IdentComp(IdentMinMarginRight))
1.778 + {
1.779 + if (Number(num))
1.780 + iModel->iInfo.iMinMarginsInPixels.iRight = num;
1.781 + else
1.782 + state = efalse;
1.783 + }
1.784 + else if (IdentComp(IdentMinMarginTop))
1.785 + {
1.786 + if (Number(num))
1.787 + iModel->iInfo.iMinMarginsInPixels.iTop = num;
1.788 + else
1.789 + state = efalse;
1.790 + }
1.791 + else if (IdentComp(IdentMinMarginBottom))
1.792 + {
1.793 + if (Number(num))
1.794 + iModel->iInfo.iMinMarginsInPixels.iBottom = num;
1.795 + else
1.796 + state = efalse;
1.797 + }
1.798 + else if (IdentComp(IdentDisplayMode))
1.799 + {
1.800 + int i; // DEF102183: Graphics tools fail to build using MS VC8.
1.801 + for (i = 0; (i < NumDisplayModeValues) && !IdentComp(IdentDisplayModeValue[i]); i++)
1.802 + { // Tries to match display mode identifier
1.803 + }
1.804 + if (i < NumDisplayModeValues)
1.805 + {
1.806 + iModel->iInfo.iDisplayMode = i;
1.807 + }
1.808 + else
1.809 + {
1.810 + state = efalse;
1.811 + Error("Display mode identifier expected");
1.812 + }
1.813 + }
1.814 + else if (IdentComp(IdentTypefaceFontss))
1.815 + {
1.816 + state = NewLine();
1.817 + while (!IdentComp(IdentEndTypefaceFontss) && !_EOF() && state)
1.818 + {
1.819 + TypefaceFontsEntry* typefacefontsentry = NULL;
1.820 + if (iLex->iType == ELexIdent)
1.821 + {
1.822 + state = IdentCopy(label);
1.823 + Record* typefacefonts = iPdrModelStore.FindTypefaceFonts(label);
1.824 + if (typefacefonts)
1.825 + {
1.826 + typefacefontsentry = TypefaceFontsEntry::New(typefacefonts);
1.827 + state = etrue;
1.828 + }
1.829 + else
1.830 + {
1.831 + Error("Typefacefonts not found");
1.832 + state = efalse;
1.833 + }
1.834 + }
1.835 + if (state)
1.836 + {
1.837 + while ((iLex->iType != ELexNL) && !_EOF() && state)
1.838 + {
1.839 + if (IdentComp(IdentNotInPortrait))
1.840 + {
1.841 + typefacefontsentry->iNotInPortrait = etrue;
1.842 + }
1.843 + else if (IdentComp(IdentNotInLandscape))
1.844 + {
1.845 + typefacefontsentry->iNotInLandscape = etrue;
1.846 + }
1.847 + else
1.848 + {
1.849 + Error("Typefacefontsentry identifier or newline expected");
1.850 + state = efalse;
1.851 + }
1.852 + }
1.853 + if (state)
1.854 + iModel->iInfo.AddTypefaceFontsEntry(typefacefontsentry);
1.855 + else
1.856 + typefacefontsentry->Delete();
1.857 + }
1.858 + if (state)
1.859 + state = NewLine();
1.860 + }
1.861 + }
1.862 + else
1.863 + {
1.864 + Error("unrecognised model identifier");
1.865 + state = efalse;
1.866 + }
1.867 + }
1.868 + else
1.869 + {
1.870 + Error("Model identifier expected");
1.871 + state = efalse;
1.872 + }
1.873 + if (state)
1.874 + state = NewLine();
1.875 + }
1.876 + if (state)
1.877 + {
1.878 + iPdrModelStore.AddModel(iModel);
1.879 + cout << "Model read\n";
1.880 + }
1.881 + else
1.882 + iModel->Delete();
1.883 + return state;
1.884 + }
1.885 +
1.886 +boolean PdrReader::ReadPdrStoreFile()
1.887 + {
1.888 + boolean state = etrue;
1.889 + if (iPdrStoreFile)
1.890 + {
1.891 + state = efalse;
1.892 + Error("Pdrstorefile already read");
1.893 + }
1.894 + else
1.895 + {
1.896 + iPdrStoreFile = PdrStoreFile::New();
1.897 + String label;
1.898 + Record* model;
1.899 + state = NewLine();
1.900 + while (!IdentComp(IdentEndPdrStoreFile) && !_EOF() && state)
1.901 + {
1.902 + if (IdentComp(IdentPDLName))
1.903 + {
1.904 + state = StringCopy(iPdrStoreFile->iPDLName);
1.905 + }
1.906 + else if (IdentComp(IdentPDLUid))
1.907 + {
1.908 + state = Number(iPdrStoreFile->iPDLUid);
1.909 + }
1.910 + else if (IdentComp(IdentModels))
1.911 + {
1.912 + state = NewLine();
1.913 + while (!IdentComp(IdentEndModels) && !_EOF() && state)
1.914 + {
1.915 + state = IdentCopy(label);
1.916 + if (state)
1.917 + {
1.918 + model = iPdrModelStore.FindModel(label);
1.919 + if (model)
1.920 + {
1.921 + iPdrStoreFile->AddModel((PrinterModelHeader*)model);
1.922 + }
1.923 + else
1.924 + {
1.925 + Error("model not found");
1.926 + state = efalse;
1.927 + }
1.928 + }
1.929 + if (state)
1.930 + state = NewLine();
1.931 + }
1.932 + }
1.933 + else
1.934 + {
1.935 + Error("Pdrstorefile identifier expected");
1.936 + state = efalse;
1.937 + }
1.938 + if (state)
1.939 + state = NewLine();
1.940 + }
1.941 + if (state)
1.942 + {
1.943 + iPdrModelStore.AddPdrStoreFile(iPdrStoreFile);
1.944 + cout << "Pdrstorefile read\n";
1.945 + }
1.946 + else
1.947 + iPdrStoreFile->Delete();
1.948 + }
1.949 + return state;
1.950 + }
1.951 +
1.952 +EXPORT_C boolean PdrReader::Store(const String& aFilename)
1.953 + {
1.954 + boolean state = etrue;
1.955 + if (!iPdrStoreFile)
1.956 + {
1.957 + state = efalse;
1.958 + Error("No pdrstore file record");
1.959 + }
1.960 + else
1.961 + state = iPdrModelStore.Store(aFilename);
1.962 + return state;
1.963 + }
1.964 +
1.965 +boolean PdrReader::Command(String& aCommand)
1.966 + {
1.967 + boolean state = etrue;
1.968 + String string;
1.969 + state = StringCopy(string);
1.970 + int length = string.Length();
1.971 + for (int i = 0; i < length; i++)
1.972 + {
1.973 + char ch = string[i];
1.974 + if (ch == '<') // Read control character
1.975 + {
1.976 + ch = 0;
1.977 + for (i = i + 1; (i < length) && (string[i] != '>'); i++)
1.978 + ch = char((ch * 10) + (string[i] - '0'));
1.979 + }
1.980 + aCommand += ch;
1.981 + }
1.982 + return state;
1.983 + }
1.984 +/*
1.985 +boolean PdrReader::ReadExtraInfo()
1.986 + {
1.987 + boolean state = etrue;
1.988 + String label;
1.989 + PdrExtraInfo* extrainfo = new PdrExtraInfo();
1.990 + state = IdentCopy(extrainfo->iLabel);
1.991 + if (state)
1.992 + state = NewLine();
1.993 + while (!IdentComp(IdentEndExtraInfo) && !_EOF() && state)
1.994 + {
1.995 + String* string = new String;
1.996 + state = Command(*string);
1.997 + if (state)
1.998 + extrainfo->iInfo.Add(string);
1.999 + else
1.1000 + delete string;
1.1001 + state = NewLine();
1.1002 + }
1.1003 + if (state)
1.1004 + {
1.1005 + iPdrModelStore.AddExtraInfo(extrainfo);
1.1006 + cout << "Extra info read\n";
1.1007 + }
1.1008 + else
1.1009 + delete extrainfo;
1.1010 + return state;
1.1011 + }
1.1012 +*/