/usr/share/xml/xgridfit/lib/xgridfit-python.xsl is in xgridfit 2.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 | <?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xgf="http://xgridfit.sourceforge.net/Xgridfit2"
xmlns:xgfd="http://www.engl.virginia.edu/OE/xgridfit-data"
xmlns:excom="http://exslt.org/common"
version="1.0"
exclude-result-prefixes="xgf"
extension-element-prefixes="excom">
<!--
xgridfit, an XML-based language for instructing TrueType fonts
Copyright (c) 2006-11 by Peter S. Baker
Issued under the GNU Public License, v. 2.
No warranty here! Back up your fonts!
-->
<xsl:output method="text" encoding="UTF-8"/>
<xsl:param name="glyph_select">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:glyph-select">
<xsl:value-of select="/xgf:xgridfit/xgf:glyph-select"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="compile_globals">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:default[@type='compile-globals']">
<xsl:value-of select="/xgf:xgridfit/xgf:default[@type='compile-globals']/@value"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'yes'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="init_graphics">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:default[@type='init-graphics']">
<xsl:value-of select="/xgf:xgridfit/xgf:default[@type='init-graphics']/@value"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'yes'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<!-- How many points permitted in the twilight zone. This is generous,
I think. -->
<xsl:param name="max_twilight_points">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:default[@type='max-twilight-points']">
<xsl:value-of select="/xgf:xgridfit/xgf:default[@type=
'max-twilight-points']/@value"/>
</xsl:when>
<xsl:otherwise>25</xsl:otherwise>
</xsl:choose>
</xsl:param>
<!-- How many storage spaces to allocate. These are used for variables.
Increase the number if you use variables a lot. -->
<xsl:param name="max_storage">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:default[@type='max-storage']">
<xsl:value-of select="/xgf:xgridfit/xgf:default[@type=
'max-storage']/@value"/>
</xsl:when>
<xsl:otherwise>64</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="max_stack">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:default[@type='max-stack']">
<xsl:value-of select="/xgf:xgridfit/xgf:default[@type=
'max-stack']/@value"/>
</xsl:when>
<xsl:otherwise>256</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="push_break">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:default[@type='push-break']">
<xsl:value-of select="/xgf:xgridfit/xgf:default[@type=
'push-break']/@value"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="255"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="color">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:default[@type='color']">
<xsl:value-of select="/xgf:xgridfit/xgf:default[@type=
'color']/@value"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'gray'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="infile">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:infile">
<xsl:value-of select="/xgf:xgridfit/xgf:infile"/>
</xsl:when>
<xsl:otherwise>!!nofile!!</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="outfile">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:outfile">
<xsl:value-of select="/xgf:xgridfit/xgf:outfile"/>
</xsl:when>
<xsl:otherwise>!!nofile!!</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="outfile_base">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:outfile-base">
<xsl:value-of select="/xgf:xgridfit/xgf:outfile-base"/>
</xsl:when>
<xsl:otherwise>!!nofile!!</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="mp-containers"
select="//xgf:call-macro[not(param-set)]|
//xgf:call-macro/xgf:param-set|
//xgf:call-glyph"/>
<!-- <xsl:variable name="outfile_base" select="'!!nofile!!'"/> -->
<xsl:param name="outfile_script_name">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:outfile-script-name">
<xsl:value-of select="/xgf:xgridfit/xgf:outfile-script-name"/>
</xsl:when>
<xsl:when test="$outfile_base != '!!nofile!!'">
<xsl:value-of select="concat($outfile_base,'_outfile.py')"/>
</xsl:when>
<xsl:otherwise>!!nofile!!</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:variable name="merge-mode" select="false()"/>
<xsl:key name="cvt" match="xgf:control-value" use="@name"/>
<xsl:key name="function-index" match="xgf:function" use="@name"/>
<xsl:key name="macro-index" match="xgf:macro" use="@name"/>
<xsl:key name="glyph-index" match="xgf:glyph|xgf:no-compile/xgf:glyph"
use="@ps-name"/>
<!-- We'll do our own formatting of all TT instructions, providing all
line breaks and spacing. So no space or line breaks kept from source
file. -->
<xsl:strip-space elements="*"/>
<xsl:variable name="newline">
<xsl:text>\n</xsl:text>
</xsl:variable>
<xsl:variable name="inst-newline">
<xsl:text>\n\
</xsl:text>
</xsl:variable>
<xsl:variable name="push-num-separator" select="$inst-newline"/>
<xsl:variable name="text-newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<!--
<xsl:variable name="leading-newline"
select="concat($inst-newline,'"+\',$text-newline)"/>
-->
<xsl:variable name="leading-newline" select="$inst-newline"/>
<xsl:variable name="cv-num-in-compile-if" select="'yes'"/>
<xsl:variable name="file-extension" select="'.py'"/>
<!-- These will be found in func-predef.xsl. -->
<xsl:variable name="predefined-functions" select="4"/>
<xsl:variable name="auto-function-base">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:default[@type = 'function-base']">
<xsl:value-of select="/xgf:xgridfit/xgf:default[@type =
'function-base-num']/@value"/>
</xsl:when>
<xsl:when test="/xgf:xgridfit/xgf:function[@num]">
<xsl:variable name="n">
<xsl:call-template name="get-highest-function-number">
<xsl:with-param name="current-function"
select="/xgf:xgridfit/xgf:function[@num][1]"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="number($n) + 1"/>
</xsl:when>
<xsl:when test="/xgf:xgridfit/xgf:legacy-functions/@max-function-defs">
<xsl:value-of select="/xgf:xgridfit/xgf:legacy-functions/@max-function-defs"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="var-legacy-storage">
<xsl:choose>
<xsl:when test="/xgf:xgridfit/xgf:default[@type = 'legacy-storage']">
<xsl:value-of select="/xgf:xgridfit/xgf:default[@type =
'legacy-storage']/@value"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="function-round-restore"
select="$auto-function-base"/>
<xsl:variable name="function-glyph-prolog"
select="number($auto-function-base) + 1"/>
<xsl:variable name="function-push-range"
select="number($auto-function-base) + 2"/>
<xsl:variable name="function-order-range"
select="number($auto-function-base) + 3"/>
<xsl:include href="std-vars.xsl"/>
<xsl:include href="numbers.xsl"/>
<xsl:include href="expressions.xsl"/>
<xsl:include href="arithmetic.xsl"/>
<xsl:include href="points.xsl"/>
<xsl:include href="flow.xsl"/>
<xsl:include href="function.xsl"/>
<xsl:include href="func-predef.xsl"/>
<xsl:include href="prep.xsl"/>
<xsl:include href="graphics.xsl"/>
<xsl:include href="measure.xsl"/>
<xsl:include href="primitives.xsl"/>
<xsl:include href="delta.xsl"/>
<xsl:include href="move-lib.xsl"/>
<xsl:include href="move-els.xsl"/>
<xsl:include href="messages.xsl"/>
<xsl:include href="misc.xsl"/>
<!--
simple-command
A very simple, one-line command, with optional modifier.
-->
<xsl:template name="simple-command">
<xsl:param name="cmd"/>
<xsl:param name="modifier"/>
<xsl:value-of select="$leading-newline"/>
<xsl:value-of select="$cmd"/>
<xsl:if test="$modifier">
<xsl:text>[</xsl:text>
<xsl:value-of select="$modifier"/>
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:template>
<!--
push-command
Generates the command for a PUSH instruction.
-->
<xsl:template name="push-command">
<xsl:param name="size" select="'B'"/>
<xsl:param name="count" select="1"/>
<xsl:variable name="cmd">
<xsl:choose>
<xsl:when test="number($count) <= 8">
<xsl:value-of select="concat('PUSH',$size,'_',$count)"/>
</xsl:when>
<xsl:otherwise>
<xsl:if test="number($count) > 255">
<xsl:call-template name="error-message">
<xsl:with-param name="msg">
<xsl:text>You may not push more than 255 numbers at one time.</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:value-of select="concat('NPUSH',$size)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="simple-command">
<xsl:with-param name="cmd" select="$cmd"/>
</xsl:call-template>
<xsl:if test="number($count) > 8">
<xsl:value-of select="$inst-newline"/>
<xsl:value-of select="$count"/>
</xsl:if>
</xsl:template>
<!-- The following templates are for the bit-flags that accompany
certain instructions. -->
<xsl:template name="color-bits">
<xsl:param name="l-color"/>
<xsl:choose>
<xsl:when test="$l-color='black'">
<xsl:text>01</xsl:text>
</xsl:when>
<xsl:when test="$l-color='white'">
<xsl:text>10</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>00</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="to-line-bit">
<xsl:param name="tlb"/>
<xsl:choose>
<xsl:when test="$tlb='orthogonal'">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="axis-bit">
<xsl:param name="axis"/>
<xsl:choose>
<xsl:when test="$axis='x'">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:when test="$axis='y'">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="error-message">
<xsl:with-param name="msg">
<xsl:text>When setting a vector, the "axis" </xsl:text>
<xsl:text>attribute must be either "x" or "y."</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="round-and-cut-in-bit">
<xsl:param name="b" select="true()"/>
<xsl:choose>
<xsl:when test="$b">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="rp0-bit">
<xsl:param name="set-rp0"/>
<xsl:choose>
<xsl:when test="$set-rp0">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="mirp-mdrp-bits">
<xsl:param name="set-rp0"/>
<xsl:param name="min-distance"/>
<xsl:param name="round-cut-in"/>
<xsl:param name="l-color"/>
<xsl:call-template name="rp0-bit">
<xsl:with-param name="set-rp0" select="$set-rp0"/>
</xsl:call-template>
<xsl:choose>
<xsl:when test="$min-distance">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="round-and-cut-in-bit">
<xsl:with-param name="b" select="$round-cut-in"/>
</xsl:call-template>
<xsl:call-template name="color-bits">
<xsl:with-param name="l-color" select="$l-color"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="ref-ptr-bit">
<xsl:param name="ref-ptr"/>
<xsl:choose>
<xsl:when test="$ref-ptr='1'">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="grid-fitted-bit">
<xsl:param name="grid-fitted"/>
<xsl:choose>
<xsl:when test="$grid-fitted">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>1</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="resolve-std-variable-loc">
<xsl:param name="n"/>
<xsl:param name="add" select="0"/>
<xsl:choose>
<xsl:when test="number($n) or number($n) = 0">
<xsl:value-of select="number($n) + number($var-legacy-storage) + $add"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(document('xgfdata.xml')/*/xgfd:var-locations/xgfd:loc[@name=$n]/@val) +
number($var-legacy-storage) + $add"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="get-cvt-index">
<xsl:param name="name"/>
<xsl:param name="need-number-now"/>
<xsl:value-of
select="count(key('cvt',$name)/preceding-sibling::xgf:control-value)"/>
</xsl:template>
<xsl:template name="debug-start"></xsl:template>
<xsl:template name="debug-end"></xsl:template>
<!-- ========================================================================= -->
<!-- ============== TOP-LEVEL ELEMENTS OF THE INSTRUCTION FILE =============== -->
<!-- ========================================================================= -->
<xsl:template match="/">
<!--
<xsl:message>
<xsl:text>mp-containers: </xsl:text>
<xsl:value-of select="count($mp-containers)"/>
<xsl:value-of select="$text-newline"/>
<xsl:for-each select="$mp-containers">
<xsl:value-of select="name()"/>
<xsl:text> : </xsl:text>
<xsl:value-of select="generate-id()"/>
<xsl:value-of select="$text-newline"/>
</xsl:for-each>
</xsl:message>
-->
<xsl:if test="not(xgf:xgridfit)">
<xsl:call-template name="error-message">
<xsl:with-param name="msg" select="$no-namespace-error"/>
</xsl:call-template>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="xgf:xgridfit">
<xsl:param name="all-functions" select="/xgf:xgridfit/xgf:function"/>
<xsl:param name="leg"
select="/xgf:xgridfit/xgf:legacy-functions"/>
<xsl:if test="not(xgf:pre-program) and $compile_globals='yes'">
<xsl:call-template name="error-message">
<xsl:with-param name="msg">
<xsl:text>A <pre-program> element must be present, even if empty.</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:text>import fontforge</xsl:text>
<xsl:value-of select="$text-newline"/>
<xsl:value-of select="$py-start-message"/>
<xsl:value-of select="$text-newline"/>
<xsl:choose>
<xsl:when test="$infile != '!!nofile!!'">
<xsl:text>CURRENT_FONT = fontforge.open("</xsl:text>
<xsl:value-of select="$infile"/>
<xsl:text>")</xsl:text>
<xsl:value-of select="$text-newline"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="warning">
<xsl:with-param name="msg">
<xsl:text>No font file specified. Use an infile element to identify</xsl:text>
<xsl:text> a font to add instructions to.</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$compile_globals='yes'">
<xsl:text>for g in CURRENT_FONT.glyphs():
g.ttinstrs = ""
CURRENT_FONT.setTableData('cvt', None)
CURRENT_FONT.setTableData('fpgm', None)
CURRENT_FONT.setTableData('prep', None)
CURRENT_FONT.maxp_FDEFs = 0
CURRENT_FONT.maxp_storageCnt = 0
CURRENT_FONT.maxp_twilightPtCnt = 0
CURRENT_FONT.maxp_maxStackDepth = 0
</xsl:text>
</xsl:if>
<xsl:text>def install_glyph_program(name, instrs):
try:
CURRENT_FONT[name].ttinstrs = fontforge.parseTTInstrs(instrs)
except TypeError as detail:
print "Warning: can't install instructions for glyph ", name
print detail
except ValueError as detail:
print "Warning: can't install instructions for glyph ", name
print detail
</xsl:text>
<xsl:if test="$compile_globals='yes'">
<xsl:text>CURRENT_FONT.cvt = (</xsl:text>
<xsl:for-each select="xgf:control-value">
<xsl:if test="position() > 1">
<xsl:text>,
</xsl:text>
</xsl:if>
<xsl:value-of select="@value"/>
</xsl:for-each>
<xsl:text>)</xsl:text>
<xsl:value-of select="$text-newline"/>
<!--
We need an fpgm table with our predefined functions even if
user has defined no functions.
-->
<xsl:variable name="new-fpgm">
<xsl:choose>
<xsl:when test="$all-functions[@num]">
<xsl:apply-templates select="$all-functions[@num]"/>
</xsl:when>
<xsl:when test="$leg[@max-function-defs]">
<xsl:apply-templates select="$leg"/>
</xsl:when>
</xsl:choose>
<xsl:call-template name="function-zero"/>
<xsl:call-template name="function-one"/>
<xsl:call-template name="function-two"/>
<xsl:call-template name="function-three"/>
<xsl:apply-templates select="$all-functions[not(@num) and
not(xgf:variant)]"/>
</xsl:variable>
<xsl:text>CURRENT_FONT.setTableData('fpgm', fontforge.parseTTInstrs('</xsl:text>
<xsl:value-of select="substring-after($new-fpgm,$leading-newline)"/>
<xsl:text>'))</xsl:text>
<xsl:value-of select="$text-newline"/>
<xsl:apply-templates select="xgf:pre-program"/>
</xsl:if>
<xsl:choose>
<xsl:when test="string-length($glyph_select)">
<xsl:call-template name="glyph-list">
<xsl:with-param name="list" select="$glyph_select"/>
<xsl:with-param name="separator">
<xsl:choose>
<xsl:when test="contains($glyph_select,'+')">
<xsl:value-of select="'+'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="' '"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$outfile_base = '!!nofile!!'">
<xsl:apply-templates select="xgf:glyph"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="element-available('excom:document')">
<xsl:for-each select="xgf:glyph">
<xsl:variable name="new-filename"
select="concat($outfile_base,'_',@ps-name,$file-extension)"/>
<xsl:call-template name="display-message">
<xsl:with-param name="msg">
<xsl:text>Saving to file </xsl:text>
<xsl:value-of select="$new-filename"/>
</xsl:with-param>
</xsl:call-template>
<excom:document href="{$new-filename}" method="text">
<xsl:apply-templates select="."/>
</excom:document>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="error-message">
<xsl:with-param name="msg">
<xsl:text>Your XSLT engine does not support -S (outfile_base)</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$compile_globals='yes'">
<!-- maxTwilightPoints -->
<xsl:text>CURRENT_FONT.maxp_twilightPtCnt = </xsl:text>
<xsl:value-of select="$max_twilight_points"/>
<xsl:value-of select="$text-newline"/>
<!-- maxStorage -->
<xsl:text>CURRENT_FONT.maxp_storageCnt = </xsl:text>
<xsl:variable name="gvb">
<xsl:call-template name="resolve-std-variable-loc">
<xsl:with-param name="n" select="$global-variable-base"/>
<xsl:with-param name="add" select="1"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="number($max_storage) >= number($gvb)">
<xsl:value-of select="$max_storage"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$gvb"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$text-newline"/>
<!-- depth of stack -->
<xsl:text>CURRENT_FONT.maxp_maxStackDepth = </xsl:text>
<xsl:value-of select="$max_stack"/>
<xsl:value-of select="$text-newline"/>
<!-- maxFunctionDefs -->
<xsl:variable name="v-legacy-functions">
<xsl:choose>
<xsl:when test="xgf:legacy-functions">
<xsl:value-of select="xgf:legacy-functions/@max-function-defs"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:text>CURRENT_FONT.maxp_FDEFs = </xsl:text>
<xsl:value-of select="number($v-legacy-functions) +
number($predefined-functions) +
count(/xgf:xgridfit/xgf:function)"/>
<xsl:value-of select="$text-newline"/>
</xsl:if>
<xsl:if test="$outfile != '!!nofile!!'">
<xsl:variable name="o" select="normalize-space($outfile)"/>
<xsl:variable name="ext" select="substring($o,string-length($o)-3)"/>
<xsl:choose>
<xsl:when test="$outfile_base = '!!nofile!!'">
<xsl:call-template name="do-outfile">
<xsl:with-param name="o" select="$o"/>
<xsl:with-param name="ext" select="$ext"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="element-available('excom:document')">
<xsl:call-template name="display-message">
<xsl:with-param name="msg">
<xsl:text>Saving to file </xsl:text>
<xsl:value-of select="$outfile_script_name"/>
</xsl:with-param>
</xsl:call-template>
<excom:document href="{$outfile_script_name}" method="text">
<xsl:call-template name="do-outfile">
<xsl:with-param name="o" select="$o"/>
<xsl:with-param name="ext" select="$ext"/>
</xsl:call-template>
</excom:document>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="error-message">
<xsl:with-param name="msg">
<xsl:text>Your XSLT engine does not support -S (outfile_base)</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template name="make-flags-tuple">
<xsl:param name="f"/>
<xsl:param name="count" select="0"/>
<xsl:variable name="current-flag">
<xsl:choose>
<xsl:when test="contains($f,' ')">
<xsl:value-of select="substring-before($f,' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$f"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="remaining-flags">
<xsl:choose>
<xsl:when test="contains($f,' ')">
<xsl:value-of select="substring-after($f,' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$count = 0">
<xsl:text>(</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>, </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>'</xsl:text>
<xsl:value-of select="$current-flag"/>
<xsl:text>'</xsl:text>
<xsl:choose>
<xsl:when test="string-length($remaining-flags) = 0">
<xsl:if test="$count = 0">
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="make-flags-tuple">
<xsl:with-param name="f" select="$remaining-flags"/>
<xsl:with-param name="count" select="$count + 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="do-outfile">
<xsl:param name="o"/>
<xsl:param name="ext"/>
<xsl:choose>
<xsl:when test="not(string-length($o))">
<xsl:text>CURRENT_FONT.save()</xsl:text>
</xsl:when>
<xsl:when test="$ext = '.sfd'">
<xsl:text>CURRENT_FONT.save("</xsl:text>
<xsl:value-of select="$o"/>
<xsl:text>")</xsl:text>
</xsl:when>
<xsl:when test="$ext = '.ttf'">
<xsl:text>CURRENT_FONT.generate("</xsl:text>
<xsl:value-of select="$o"/>
<xsl:text>"</xsl:text>
<xsl:if test="/xgf:xgridfit/xgf:outfile/@pyflags">
<xsl:text>,flags=</xsl:text>
<xsl:call-template name="make-flags-tuple">
<xsl:with-param name="f" select="/xgf:xgridfit/xgf:outfile/@pyflags"/>
</xsl:call-template>
</xsl:if>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="warning">
<xsl:with-param name="msg">
<xsl:text>Unrecognized file extension </xsl:text>
<xsl:value-of select="$ext"/>
<xsl:text>. No file will be saved.</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$text-newline"/>
</xsl:template>
<xsl:template match="xgf:pre-program">
<xsl:text>CURRENT_FONT.setTableData('prep', fontforge.parseTTInstrs('</xsl:text>
<xsl:variable name="current-inst">
<xsl:call-template name="pre-program-instructions"/>
</xsl:variable>
<xsl:value-of select="substring-after($current-inst,$leading-newline)"/>
<xsl:text>'))</xsl:text>
<xsl:value-of select="$text-newline"/>
</xsl:template>
<!--
N.B. template "glyph" with mode "called" will be in
function.xsl. There will be nothing non-portable in it, and we
don't want to write it twice.
-->
<xsl:template match="xgf:glyph">
<xsl:variable name="var-string">
<xsl:text>x</xsl:text>
<xsl:apply-templates select="." mode="survey-vars"/>
</xsl:variable>
<xsl:variable name="need-variable-frame" select="contains($var-string,'v')"/>
<xsl:variable name="init-g">
<xsl:choose>
<xsl:when test="@init-graphics">
<xsl:value-of select="@init-graphics"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$init_graphics"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="display-message">
<xsl:with-param name="msg">
<xsl:text>Compiling glyph </xsl:text>
<xsl:value-of select="@ps-name"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>install_glyph_program("</xsl:text>
<xsl:value-of select="@ps-name"/>
<xsl:text>", "</xsl:text>
<xsl:variable name="current-inst">
<xsl:if test="$need-variable-frame">
<xsl:call-template name="set-up-variable-frame"/>
<xsl:apply-templates select="xgf:variable" mode="initialize"/>
</xsl:if>
<xsl:if test="$init-g = 'yes'">
<xsl:call-template name="number-command">
<xsl:with-param name="num" select="$function-glyph-prolog"/>
<xsl:with-param name="cmd" select="'CALL'"/>
</xsl:call-template>
</xsl:if>
<xsl:apply-templates/>
</xsl:variable>
<xsl:value-of select="substring-after($current-inst,$leading-newline)"/>
<xsl:text>")</xsl:text>
<xsl:value-of select="$text-newline"/>
</xsl:template>
<!-- The following elements are declarations, read only
by this script and never converted to code. -->
<xsl:template match="xgf:no-compile"></xsl:template>
</xsl:stylesheet>
|