1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
|
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.
Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.
File: main.cpp
Responsibility: Sharon Correll
Description:
Main function that runs the compiler.
Compiler versions:
1.0 - Initial
2.0 - justification, measuring (Silf table 2.0)
3.0? - Silf table 3.1
4.0 - pass constraints (Silf table 3.1)
- large set (> 256) of replacement classes
4.1 - mirror glyph attributes (Silf table 2.1 or 3.2)
4.2 - large number of glyphs (> 64K) in replacement classes (Silf table 4.0);
segsplit and extra LB flag
4.3 - handle &= and -= for class definitions; multiple justification levels
4.3.1 - added *skipPasses* glyph attribute and passKeySlot slot attribute for
optimization; don't output xoffset, yoffset, or gpoint att fields
5.0 - collision fixing (Glat table 3.0, Gloc table 1.1; feat-set operator;
Silf table 4.1 for collision fixing, 5.0 for compression)
5.1 - disallow duplicates in LHS classes that are used for substitution; added -e option
5.2 - many changes (see GitHub commit history)
-------------------------------------------------------------------------------*//*:End Ignore*/
/***********************************************************************************************
Include files
***********************************************************************************************/
#include "main.h"
// Version: bldinc.h holds the current copyright number and it is created by executing
// bin\mkverrsc.exe from within the bin\mkcle.bat file. The major and minor version
// numbers are hard-coded in mkcle.bat.
#ifdef GR_FW
#include "..\..\..\..\Output\Common\bldinc.h"
#endif // GR_FW
#if !defined(_WIN32) && !HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
#include <libgen.h>
char* program_invocation_name;
char* program_invocation_short_name;
#endif
#ifdef _MSC_VER
#pragma hdrstop
#endif
#undef THIS_FILE
DEFINE_THIS_FILE
/***********************************************************************************************
Forward declarations
***********************************************************************************************/
/***********************************************************************************************
Local Constants and static variables
***********************************************************************************************/
/***********************************************************************************************
Methods and functions
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Run the compiler over the specified GDL and font files.
----------------------------------------------------------------------------------------------*/
int main(int argc, char * argv[])
{
#ifdef _WIN32
// CRTDebug thing
// _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
// _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_CHECK_ALWAYS_DF);
// COM thing
::CoInitialize(NULL);
#endif
#if !defined(_WIN32) && !HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
program_invocation_name = argv[0];
program_invocation_short_name = basename(argv[0]);
#endif
char * pchGdlppFile = getenv("GDLPP");
std::string staGdlppFile(pchGdlppFile ? pchGdlppFile : "");
#ifdef _WIN32
if (staGdlppFile.empty())
{
char rgchGdlppFile[1024];
DWORD cch = GetModuleFileName(NULL, rgchGdlppFile, sizeof(rgchGdlppFile)-1);
rgchGdlppFile[cch] = '\0';
staGdlppFile = rgchGdlppFile;
std::string::size_type pos = staGdlppFile.rfind('\\');
if (pos == staGdlppFile.npos)
pos = 0;
staGdlppFile.erase(pos, staGdlppFile.npos);
if (!staGdlppFile.empty())
staGdlppFile += '\\';
staGdlppFile += "gdlpp.exe";
}
#else
// On Linux just use the PATH since grcompiler has probably been run
// via the PATH and it allows people to use things like /usr/local/bin
if (staGdlppFile.empty())
{
staGdlppFile = "gdlpp";
}
#endif
char * pchGdlFile = NULL;
char * pchFontFile = NULL;
char rgchOutputFile[128];
utf16 rgchwOutputFontFamily[128];
memset(rgchOutputFile, 0, sizeof *rgchOutputFile * 128);
memset(rgchwOutputFontFamily, 0, sizeof *rgchwOutputFontFamily * 128);
int cargExtra = 0;
bool fModFontName = false;
g_cman.SetOutputDebugFiles(false, false);
g_cman.SetSilfTableVersion(g_cman.DefaultSilfVersion(), false);
g_cman.SetSeparateControlFile(false);
g_cman.SetVerbose(true);
g_cman.SetPassOptimizations(true);
g_cman.SetOffsetAttrs(false);
g_cman.SetCompressor(ktcNone);
// Ignore these warnings by default:
g_errorList.SetIgnoreWarning(510); // Cannot find point number for coordinates...
g_errorList.SetIgnoreWarning(3521); // Vertical overlap between
g_cman.SetErrorFileName("gdlerr.txt");
// On linux systems an argument starting with a / may be a path
// so use - for options. On Windows allow both / or -.
#ifdef _WIN32
while (argc >= 2 + cargExtra
&& (argv[1 + cargExtra][0] == '/' || argv[1 + cargExtra][0] == '-'))
#else
while (argc >= 2 + cargExtra && argv[1 + cargExtra][0] == '-')
#endif
{
cargExtra = HandleCompilerOptions(cargExtra, argv[1 + cargExtra],
(2 + cargExtra > argc) ? NULL : argv[2 + cargExtra]);
}
if (g_cman.IsVerbose())
{
std::cout << "Graphite Compiler Version 5.2.1";
#ifdef _DEBUG
std::cout << " [debug build]";
#else
std::cout << " [release build]";
#endif
// \xc2\xa9 = copyright symbol
std::cout << "\n"
<< "Copyright (c) 2002-2021, by SIL International. All rights reserved.\n";
}
if (argc < 3 + cargExtra)
{
std::cout << "\nusage: grcompiler [options] gdl-file input-font-file [output-font-file] [output-font-name]\n";
std::cout << "\nOptions:\n";
std::cout << " -c - compress graphite tables\n";
std::cout << " -d - output XML debugger file\n";
std::cout << " -D - output all debugger files\n";
std::cout << " -e - error message file; gdlerr.txt by default\n";
std::cout << " -g - permit and ignore invalid glyph definitions\n";
std::cout << " -nNNNN - set name table start location\n";
std::cout << " -p - omit pass-avoidance optimizations\n";
std::cout << " -q - quiet mode (no messages except on error)\n";
std::cout << " -vN - set Silf table version number\n";
std::cout << " -wNNNN - ignore warning with the given number\n";
std::cout << " -wall - display all warnings\n";
std::cout << " -offsets - generate xoffset, yoffset, and gpoint glyph attributes\n";
return 2;
}
bool fFatalErr = false;
SetGdlAndFontFileNames(argv[1 + cargExtra], (argc > 2 + cargExtra) ? argv[2 + cargExtra] : NULL,
&pchGdlFile, &pchFontFile);
g_errorList.SetFileNameFromGdlFile(&g_cman, pchGdlFile);
if (argc > 3 + cargExtra)
{
char * pch = argv[3 + cargExtra];
strcpy(rgchOutputFile, pch);
if (argc > 4 + cargExtra)
{
pch = argv[4 + cargExtra];
Platform_AnsiToUnicode(pch, strlen(pch), rgchwOutputFontFamily, strlen(pch));
fModFontName = true;
// Give a warning if the font name has something bigger than 7-bit data.
// The font-output routines can't handle that.
for (char * pchLp = pch; pchLp - pch < signed(strlen(pch)); pchLp++)
{
if ((unsigned char)(*pchLp) > 0x7F)
{
g_errorList.AddWarning(511, NULL, "Non-ASCII font names are not supported");
break;
}
}
}
//else // nice idea, but don't do this for now
//{
// // output file and no font family; but if the string looks more like a font name, switch
// if (LooksLikeFontFamily(rgchOutputFile))
// {
// //std::string sta(pch);
// //StrUni stu = sta;
// //wcscpy(rgchwOutputFontFamily, stu.Chars());
// ::MultiByteToWideChar(CP_ACP, 0, rgchOutputFile, -1,
// rgchwOutputFontFamily, strlen(rgchOutputFile));
// rgchOutputFile[0] = 0;
// }
//}
}
// Is GDL file path absolute? So will be paths in GDX.
bool fAbsGdlFilePaths = (pchGdlFile[1] == ':' || pchGdlFile[0] == '/' || pchGdlFile[0] == '\\');
if (strcmp(rgchOutputFile, pchFontFile) == 0)
{
g_errorList.AddError(142, NULL, "Input and output font files cannot be the same.");
fFatalErr = true;
}
if (rgchOutputFile[0] == 0)
{
// Calculate output file name from the input file name.
if (g_cman.SeparateControlFile())
GenerateOutputControlFileName(pchFontFile, rgchOutputFile); // gtf
else
GenerateOutputFontFileName(pchFontFile, rgchOutputFile); // ttf
}
std::string staVersion = VersionString(g_cman.SilfTableVersion());
if (g_cman.IsVerbose())
{
std::cout << "Reading input font...\n\n";
}
GrcFont * pfont = new GrcFont(pchFontFile);
int nFontError = pfont->Init(&g_cman);
// Calculate output font-family name.
utf16 rgchwInputFontFamily[128];
if (utf16len(rgchwOutputFontFamily) > 0)
{
Assert(fModFontName); //////// ????????
}
else if (nFontError == 0)
{
// Assert(fModFontName); // seems to be false in regression tests
pfont->GetFontFamilyName(rgchwInputFontFamily, 128);
if (g_cman.SeparateControlFile())
GenerateOutputControlFontFamily(rgchwInputFontFamily, rgchwOutputFontFamily);
else
utf16cpy(rgchwOutputFontFamily, rgchwInputFontFamily);
}
else
{
std::wstring stu(L"unknown");
//utf16cpy(rgchwOutputFontFamily, (const utf16*)stu.Chars());
std::copy(stu.data(), stu.data() + stu.length() + 1, rgchwOutputFontFamily);
}
if (utf16len(rgchwOutputFontFamily) > kMaxFontNameLength)
g_errorList.AddError(141, NULL, "Font name is longer than 32 characters.");
//std::string staFamily((char*)rgchwOutputFontFamily);
char rgchFamily[128];
memset(rgchFamily, 0, sizeof(char) * 128);
int cchw = 0;
utf16 * pchw = rgchwOutputFontFamily;
while (*pchw++)
cchw++;
Platform_UnicodeToANSI(rgchwOutputFontFamily, cchw, rgchFamily, 128);
std::string staFamily(rgchFamily);
if (g_cman.IsVerbose())
{
std::cout << "GDL file: " << pchGdlFile << "\n"
<< "PreProcessor: " << staGdlppFile << "\n"
<< "Input TT file: " << (pchFontFile ? pchFontFile : "none") << "\n"
<< "Output TT file: " << rgchOutputFile << "\n"
<< "Output font name: " << staFamily << ((fModFontName) ? "" : " (unchanged)") << "\n"
<< "Silf table version " << (g_cman.UserSpecifiedVersion() ? "requested" : "(default)")
<< ": " << staVersion << "\n\n";
}
// Simple test for illegal UTF encoding in file. GDL requires 7 bit codepoints
gr::byte bFirst, bSecond, bThird;
std::ifstream strmGdl;
strmGdl.open(pchGdlFile, std::ios_base::in | std::ios_base::binary);
if (strmGdl.fail())
{
fFatalErr = true;
g_errorList.AddError(1105, NULL,
"File ",
pchGdlFile,
" does not exist--compilation aborted");
}
bool fEncodingErr = false;
if (!fFatalErr)
{
strmGdl >> bFirst >> bSecond >> bThird;
strmGdl.close();
if ((bFirst == 0xFF && bSecond == 0xFE) || (bFirst == 0xFE && bSecond == 0xFF))
{
fEncodingErr = true;
g_errorList.AddError(130, NULL, "Illegal encoding in GDL file - probably UTF-16 encoding.");
}
else if (bFirst == 0xEF && bSecond == 0xBB && bThird == 0xBF)
{
fEncodingErr = true;
g_errorList.AddError(131, NULL, "Illegal encoding in GDL file - probably UTF-8 encoding.");
}
else if (bFirst & 0x80 || bSecond & 0x80 || bThird & 0x80)
{ // not really a UTF check but might as well test for illegal values here
fEncodingErr = true;
g_errorList.AddError(132, NULL, "Illegal encoding in GDL file - only 7 bit characters are legal.");
}
if (fEncodingErr)
{
fFatalErr = true;
std::cout << "Illegal encoding in GDL file.\n";
g_errorList.AddError(140, NULL,
"Illegal encoding in GDL file");
}
}
char rgchOutputPath[128];
if (!fFatalErr)
{
// Calculate the length of the path part of the output file name.
auto cchOutputPath = strlen(rgchOutputFile);
while (cchOutputPath > 0 && rgchOutputFile[cchOutputPath] != '\\' && rgchOutputFile[cchOutputPath] != '/')
cchOutputPath--;
memset(rgchOutputPath, 0, sizeof *rgchOutputPath * 128);
memcpy(rgchOutputPath, rgchOutputFile, cchOutputPath); /* don't include \ */
if (g_cman.IsVerbose())
std::cout << "Parsing file " << pchGdlFile << "...\n";
if (!g_cman.Parse(pchGdlFile, staGdlppFile, rgchOutputPath))
{
fFatalErr = true;
std::cout << "Parsing failed.\n";
g_errorList.AddError(139, NULL,
"Parsing failed");
}
}
if (!fFatalErr)
{
if (g_cman.IsVerbose())
std::cout << "Initial processing...\n";
if (!g_cman.PostParse())
{
fFatalErr = true;
std::cout << "Initial processing failed.\n";
g_errorList.AddError(138, NULL,
"Initial processing failed");
}
}
if (!fFatalErr)
{
if (nFontError != 0)
{
fFatalErr = true;
if (nFontError == 7)
{ // special case - want to avoid font copyright violations
std::cout << "Font already contains Graphite table(s).\n";
std::cout << "Please recompile with original (non-Graphite) font.\n";
// similar error msg already in g_errorList
}
std::cout << std::dec << "Could not open font--error code = " << nFontError << std::endl;
g_errorList.AddError(137, NULL,
"Could not open font--error code = ", std::to_string(nFontError));
}
}
if (!fFatalErr)
{
if (g_cman.IsVerbose())
std::cout << "Checking for errors...\n";
if (g_cman.SilfTableVersion() > g_cman.MaxSilfVersion())
{
g_errorList.AddError(133, NULL,
"Invalid font table version: ",
VersionString(g_cman.SilfTableVersion()));
}
if (g_cman.NameTableStart() != -1
&& (g_cman.NameTableStart() < g_cman.NameTableStartMin()
|| g_cman.NameTableStart() > 32767))
{
g_errorList.AddError(134, NULL,
"Invalid name table start ID: ", std::to_string(g_cman.NameTableStart()),
"; must be in range 256 - 32767.");
}
fFatalErr = g_errorList.AnyFatalErrors();
}
if (!fFatalErr)
{
fFatalErr = !g_cman.PreCompile(pfont);
fFatalErr = fFatalErr || g_errorList.AnyFatalErrors();
if (fFatalErr)
{
std::cout << "Compilation failed.\n";
if (g_errorList.NumberOfErrors() == 0)
// Make sure some error message comes out.
g_errorList.AddError(136, NULL, "Compilation failed");
}
}
if (!fFatalErr)
{
if (g_cman.IsVerbose())
std::cout << "Compiling...\n";
if (strlen(rgchOutputPath) == 0)
{
rgchOutputPath[0] = '.'; rgchOutputPath[1] = 0; // avoid empty path on Linux
}
g_cman.Compile(pfont, rgchOutputPath);
if (g_cman.OutputDebugFiles())
{
g_cman.DebugEngineCode(rgchOutputPath);
g_cman.DebugRulePrecedence(rgchOutputPath);
g_cman.DebugGlyphAttributes(rgchOutputPath);
g_cman.DebugClasses(rgchOutputPath);
//g_cman.DebugOutput(rgchOutputPath);
g_cman.DebugCmap(pfont, rgchOutputPath);
if (g_cman.IsVerbose())
std::cout << "Debug files generated.\n";
}
if (g_cman.OutputDebugXml())
{
bool f = g_cman.DebugXml(pfont, rgchOutputFile, fAbsGdlFilePaths);
if ( g_cman.IsVerbose())
{
if (f)
std::cout << "Debugger XML file generated.\n";
else
std::cout << "Error in generating debugger XML.\n";
}
}
int nRet = g_cman.OutputToFont(pchFontFile, rgchOutputFile,
rgchwOutputFontFamily, fModFontName, rgchwInputFontFamily);
if (nRet == 0)
{
if (g_cman.IsVerbose())
std::cout << "Compilation successful!\n";
}
else
{
std::cout << "ERROR IN WRITING FONT FILE.\n";
g_errorList.AddError(135, NULL,
"Error in writing font file--error code = ", std::to_string(nRet));
}
}
g_errorList.SortErrors();
g_errorList.WriteErrorsToFile(pchGdlFile, pchFontFile,
rgchOutputFile, staFamily,
VersionString(g_cman.SilfTableVersion()), g_cman.SeparateControlFile());
auto cerrFatal = g_errorList.NumberOfErrors();
auto cerrWarning = g_errorList.NumberOfWarnings();
auto cerrWarningGiven = g_errorList.NumberOfWarningsGiven(); // ie, not ignored
cerrFatal -= cerrWarning;
auto cerrWarningIgnored = cerrWarning - cerrWarningGiven;
if (cerrFatal > 0)
{
std::cout << cerrFatal << " error" << (cerrFatal > 1 ? "s " : " ");
if (cerrWarningGiven > 0)
std::cout << "and " << cerrWarningGiven << " warning" << (cerrWarningGiven > 1 ? "s " : " ");
std::cout << ((cerrFatal + cerrWarningGiven > 1) ? "have" : "has")
<< " been output to " << g_errorList.ErrFileName();
if (cerrWarningIgnored > 0)
std::cout << " (" << cerrWarningIgnored
<< ((cerrWarningIgnored > 1) ? " warnings" : " warning") << " ignored)";
std::cout << ".\n";
}
else if (cerrWarningGiven > 0)
{
std::cout << cerrWarningGiven << " warning"
<< (cerrWarningGiven > 1 ? "s have" : " has") << " been output to " << g_errorList.ErrFileName();
if (cerrWarningIgnored > 0)
std::cout << " (" << cerrWarningIgnored
<< ((cerrWarningIgnored > 1) ? " warnings" : " warning") << " ignored)";
std::cout << ".\n";
}
else if (cerrWarningIgnored > 0 && g_cman.IsVerbose())
{
std::cout << cerrWarningIgnored
<< ((cerrWarningIgnored > 1) ? " warnings" : " warning") << " ignored.\n";
}
delete pfont;
#ifdef _WIN32 // COM thing
::CoUninitialize();
#endif
if (g_errorList.AnyFatalErrors())
return 1;
else
return 0;
}
/*----------------------------------------------------------------------------------------------
Interpret the compiler options, which are preceded by slashes or hyphens
in the argument list.
----------------------------------------------------------------------------------------------*/
int HandleCompilerOptions(int cargExtra, char * arg, char * arg2)
{
if (arg[1] == 'c')
{
g_cman.SetCompressor(ktcLZ4);
}
else if (arg[1] == 'd') // XML debugger file
{
g_cman.SetOutputDebugFiles(true, false);
}
else if (arg[1] == 'D') // all debugger files
{
g_cman.SetOutputDebugFiles(true, true);
}
else if (arg[1] == 'e') // error file
{
g_cman.SetErrorFileName(arg2);
cargExtra++; // skip file name
}
else if (arg[1] == 'g') // ignore bad glyphs
{
g_cman.SetIgnoreBadGlyphs(true);
}
else if (strcmp(arg+1, "wall") == 0)
{
g_errorList.ClearIgnoreWarnings();
}
else if (arg[1] == 'n' || arg[1] == 'v' || arg[1] == 'w')
{
int nValue = 0;
char rgch[20];
int i = 2;
while (arg[i] >= '0' && arg[i] <= '9')
{
rgch[i - 2] = arg[i];
nValue = (nValue * 10) + (arg[i] - '0');
i++;
}
rgch[i - 2] = 0;
if (arg[1] == 'n')
{
g_cman.SetNameTableStart(nValue);
}
else if (arg[1] == 'v')
{
int fxdVersion = nValue << 16; // put in "fixed" format
// Give an error later if the version is invalid.
g_cman.SetSilfTableVersion(fxdVersion, true);
}
else if (arg[1] == 'w')
{
g_errorList.SetIgnoreWarning(nValue);
}
}
else if (arg[1] == 'q')
{
g_cman.SetVerbose(false);
}
else if (arg[1] == 'p')
{
g_cman.SetPassOptimizations(false);
}
else if (strcmp(arg+1, "offsets") == 0)
{
g_cman.SetOffsetAttrs(true);
}
//else if (arg[1] == 's')
//{
// g_cman.SetSeparateControlFile(true);
//}
cargExtra++;
return cargExtra;
}
/*----------------------------------------------------------------------------------------------
Try to be clever about the GDL-file and TTF-file arguments.
Don't do this for now, because it can confuse the user. Just given a warning.
----------------------------------------------------------------------------------------------*/
void SetGdlAndFontFileNames(char * pchFile1, char * pchFile2,
char ** ppchGdlFile, char ** ppchFontFile)
{
gr::byte bFirst1, bSecond1, bThird1, bFourth1, bFirst2, bSecond2;
std::ifstream strm1;
strm1.open(pchFile1, std::ios_base::in | std::ios_base::binary);
strm1 >> bFirst1 >> bSecond1 >> bThird1 >> bFourth1;
strm1.close();
std::ifstream strm2;
strm2.open(pchFile2, std::ios_base::in | std::ios_base::binary);
strm2 >> bFirst2 >> bSecond2;
strm2.close();
//if (bFirst1 == 0 && bThird1 == 0 && bFourth1 == 0 // && bSecond = 1 -- this can change with the version number
// && bFirst2 != 0 && bSecond2 != 0)
//{
// // pchFile1 looks like the beginning of a TTF file, and pchFile2 could be a GDL file.
// // So swap the arguments.
// *ppchFontFile = pchFile1;
// *ppchGdlFile = pchFile2;
//}
//else
//{
// *ppchGdlFile = pchFile1;
// *ppchFontFile = pchFile2;
//}
if (bFirst1 == 0 && bThird1 == 0 && bFourth1 == 0 // && bSecond = 1 -- this can change with the version number
&& bFirst2 != 0 && bSecond2 != 0)
{
g_errorList.AddWarning(512, NULL, "Did you switch the names of the GDL and TTF files?");
}
*ppchGdlFile = pchFile1;
*ppchFontFile = pchFile2;
}
/*----------------------------------------------------------------------------------------------
Calculate the default name of the output font, based on the input font. If the
original font is name xyz.ttf, the Graphite version will be xyz_gr.ttf. If we are
putting the Graphite font tables into a separate control file, the file name will
be xyz.gtf.
----------------------------------------------------------------------------------------------*/
void GenerateOutputFontFileName(char * pchFontFile, char * pchOutputFont)
{
char * pchIn = pchFontFile;
while (*pchIn != 0)
pchIn++;
while (*pchIn != '\\' && *pchIn != ':' && pchIn >= pchFontFile)
pchIn--;
pchIn++;
char * pchOut = pchOutputFont;
while (*pchIn != '.' && *pchIn != 0)
{
*pchOut++ = *pchIn++;
}
*pchOut++ = '_';
*pchOut++ = 'g';
*pchOut++ = 'r';
while (*pchIn != 0)
*pchOut++ = *pchIn++;
*pchOut = 0;
}
/*----------------------------------------------------------------------------------------------
Calculate the default name of the output control file, based on the input font. We remove
the extension and append ".gtf".
----------------------------------------------------------------------------------------------*/
void GenerateOutputControlFileName(char * pchFontFile, char * pchOutputFont)
{
char * pchIn = pchFontFile;
while (*pchIn != 0)
pchIn++;
while (*pchIn != '\\' && *pchIn != ':' && pchIn >= pchFontFile)
pchIn--;
pchIn++;
char * pchOut = pchOutputFont;
while (*pchIn != '.' && *pchIn != 0)
{
*pchOut++ = *pchIn++;
}
*pchOut++ = '.';
*pchOut++ = 'g';
*pchOut++ = 't';
*pchOut++ = 'f';
*pchOut = 0;
}
/*----------------------------------------------------------------------------------------------
Calculate the font name that will be put into the output control file,
based on the input font name. We append "Graphite" to the font name.
----------------------------------------------------------------------------------------------*/
void GenerateOutputControlFontFamily(utf16 * pchFontName, utf16 * pchOutputName)
{
wchar_t rgchw[120];
std::copy(pchFontName, pchFontName + 120, rgchw);
std::wstring stu(rgchw);
stu.append(L" Graphite");
std::copy(stu.data(), stu.data() + stu.length() + 1, pchOutputName);
//utf16cpy(pchOutputName, (const utf16*)stu.Chars());
//pchOutputName[stu.Length() + 1] = 0;
}
/*----------------------------------------------------------------------------------------------
Return true if what is supposedly the output file name looks more like the family name;
ie, if it has spaces in it and doesn't have '.' or '\'
----------------------------------------------------------------------------------------------*/
bool LooksLikeFontFamily(char * pch)
{
bool fSpaces = false;
while (*pch != 0)
{
if (*pch == ' ')
fSpaces = true;
else if (*pch == '\\' || *pch == '.')
return false;
pch++;
}
return fSpaces;
}
/*----------------------------------------------------------------------------------------------
Generate a string containing the version number, eg: 0x00030002 -> "3.2"
----------------------------------------------------------------------------------------------*/
std::string VersionString(int fxdVersion)
{
return std::to_string(fxdVersion >> 16)
+ '.'
+ std::to_string(fxdVersion & 0x0000FFFF);
}
|