! ILAP routines for annotation

! System specifics (for 5 lines)
!%const %string (1) SNL = "
!"
!%external %intger %fn %spec REM (%integer A, B)

%include "nmos.inc"

{#########################################################################}
{#                                                                       #}
{#      This program is part of the ILAP library, and was written in     #}
{#   The Department of Computer Science at the University of Edinburgh   #}
{#       (James Clerk Maxwell Building, Kings Buildings, Edinburgh)      #}
{#                                                                       #}
{#   This software is available free to other educational establisments  #}
{#   but the University of Edinburgh, retains all commercial rights.     #}
{#   It is a condition of having this software is that the sources are   #}
{#   not passed on to any other site, and that Edinburgh University is   #}
{#   given credit in any re-implementations of any of the algorithms     #}
{#   used, or articles published which refer to the software.            #}
{#                                                                       #}
{#   There is no formal support for this software, but any bugs should   #}
{#   be reported to Gordon Hughes or David Rees at the above address,    #}
{#   and these are likely to be fixed in a future release.               #}
{#                                                                       #}
{#########################################################################}

%const %integer no drc = 7
%own %string (4) layer for text = "M"

%external %routine crest %alias "ILAP_CREST" (%string (31) name, %integer box width, box height)
   %const %integer swidth = 34
   %const %integer sheight = 43
   %const %integer cy = 24 {extent of crest in -ve y direction}
   %integer widthscale, heightscale, s, lambda
   %integer x, y {origin of crest in box)
   %integer i, old control, bheight, bwidth
   %constintegerarray c(1:360)=
    -4, -24, -3, -21, -3, -24, -2, -21, -2, -24, 2, -23, -2, -23, 2, -22, 
    -6, -23, -5, -20, -5, -23, -4, -21, 4, -23, 5, -21, 5, -23, 6, -20,
    -8, -22, -7, -19, -7, -22, -6, -20, 2, -24, 3, -21, 3, -24, 4, -21, 
     6, -22, 7, -20, 7, -22, 8, -19, -9, -21, -8, -18, 8, -21, 9, -18, 
   -10, -20, -9, -17, 9, -20, 10, -17, -11, -19, -10, -16, 10, -19, 11, -16, 
   -12, -18, -11, -14, -6, -18, -1, -11, 1, -18, 6, -11, 11, -18, 12, -14, 
   -13, -17, -12, -5, 12, -17, 13, -5, -14, -16, -13, -6, 13, -16, 14, -6, 
    -1, -15, 1, -8, -15, -14, -14, -7, 14, -14, 15, -7, -16, -12, -15, 19, 
    15, -12, 16, 19, -12, -11, -11, -4, -6, -11, -5, -9, -5, -11, -4, -9, 
    -2, -11, -1, -7, 1, -11, 2, -7, 4, -11, 5, -9, 11, -11, 12, -4, 
   -11, -10, -10, -3, 5, -11, 6, -9, 10, -10, 11, -3, -17, -9, -16, 19, 
   -10, -9, -9, -2, 9, -9, 10, -2, 16, -9, 17, 19, -9, -8, -8, -1, 
     8, -8, 9, -1, -8, -7, -7, 0, 7, -7, 8, 0, -7, -6, -6, 7, 
     6, -6, 7, 7, -5, -5, 5, -4, -5, -4, 5, -3, -6, -5, -5, 6, 
    -1, -3, 1, -2, 5, -5, 6, 6, -8, 1, -7, 8, 7, 1, 8, 8,
    -9, 2, -8, 9, -1, 2, 1, 3, 8, 2, 9, 9, -10, 3, -9, 10, 
    -5, 3, 5, 4, -5, 4, 5, 5, 9, 3, 10, 10, -11, 4, -10, 11,
    10, 4, 11, 11, -12, 5, -11, 12, 11, 5, 12, 12, -13, 6, -12, 13, 
    12, 6, 13, 13, -14, 7, -13, 19, -3, 7, -2, 9, -2, 7, 3, 8,
    13, 7, 14, 19, -15, 8, -14, 19, -4, 8, -3, 11, -1, 8, 1, 12, 
     2, 8, 4, 9, 14, 8, 15, 19, 3, 9, 4, 11, -6, 10, -4, 13, 
     4, 10, 6, 13, -2, 12, 2, 15, -8, 12, -6, 15, 6, 12, 8, 15, 
   -13, 17, 13, 18, -13, 18, 13, 19

   ! This symbol is in 10ths of microns to allow it to be small.
   get lambda (lambda)
   bwidth = box width * lambda // 10
   bheight = box height * lambda // 10
   ! First check bounding box
   %if bwidth >= swidth %and bheight >= sheight %start
       ! Multiples of swidth
       widthscale = bwidth // swidth
       ! Multiples of sheight
       heightscale = bheight // sheight
       ! Scale of crest
       %if width scale < height scale %then s = widthscale %else s = heightscale
       ! Find coordinates of crest origin in box
       x = bwidth // 2
       y = s * cy + (bheight - s * sheight) // 2
       ! Define symbol
       Old control = ILAP control
       ILAP control = ILAP control & no drc
       set lambda (10)
       symbol(name)
          layer(metal)
          box(s*c(i)+x, s*c(i+1)+y, s*c(i+2)+x, s*c(i+3)+y) %for i = 1, 4, 357
          fix mbb (0, 0, box width, box height)
       endsymbol
       set lambda (lambda)
       ILAP control = old control
   %finish %else %start
       ! Here bounding box too small
       warning ("Crest is too large for area supplied (no symbol generated)")
   %finish
%end

%const %integer spacing = 10
%const %integer space width = 20
%own %integer edge space = 10
%own %byte starts initialised = false
%own %integerarray starts(0:127) = 0(128)
%const %integer points = 2628
%const %byte %array coords (1:points) =
 33,   4,   { ! }
     0,     0,     0,     8,     8,     8,     8,     0,
 33,   4,   { ! }
     0,    14,     0,    40,     8,    40,     8,    14,
 34,   4,   { " }
     0,    30,     0,    40,     6,    40,     6,    30,
 34,   4,   { " }
    12,    30,    12,    40,    18,    40,    18,    30,
 35,  20,   { # }
     4,     0,     4,    16,     0,    16,     0,    24,     4,    24,
     4,    34,    10,    40,    24,    40,    30,    34,    30,    28,
    22,    28,    22,    32,    12,    32,    12,    24,    18,    24,
    18,    16,    12,    16,    12,     8,    30,     8,    30,     0,
 36,  38,   { $ }
     0,     6,     0,    12,     6,    12,     6,     8,    10,     8,
    10,    16,    16,    16,    16,     8,    20,     8,    20,    16,
     4,    16,     0,    20,     0,    32,     4,    36,    10,    36,
    10,    40,    16,    40,    16,    36,    22,    36,    26,    32,
    26,    26,    20,    26,    20,    30,    16,    30,    16,    22,
    10,    22,    10,    30,     6,    30,     6,    22,    22,    22,
    26,    18,    26,     6,    22,     2,    16,     2,    16,     0,
    10,     0,    10,     2,     4,     2,
 37,   4,   { % }
     0,     0,     0,    10,    30,    40,    30,    30,
 37,  13,   { % }
     0,    32,     0,    36,     4,    40,     8,    40,    12,    36,
    12,    32,     8,    28,     4,    28,     4,    32,     8,    32,
     8,    36,     4,    36,     4,    28,
 37,  13,   { % }
    18,     4,    18,     8,    22,    12,    26,    12,    30,     8,
    30,     4,    26,     0,    22,     0,    22,     4,    26,     4,
    26,     8,    22,     8,    22,     0,
 38,  30,   { & }
     0,     4,     0,    16,    16,    32,    16,    34,     6,    34,
     6,    28,     9,    25,     5,    21,     0,    26,     0,    34,
     6,    40,    18,    40,    22,    36,    22,    28,     6,    12,
     6,     8,     8,     6,    10,     6,    15,    11,    10,    16,
    14,    20,    19,    15,    22,    18,    26,    14,    23,    11,
    26,     8,    26,     0,    19,     7,    12,     0,     4,     0,
 39,   6,   { ' }
     0,    28,     4,    32,     4,    40,    10,    40,    10,    32,
     6,    28,
 40,  10,   { ( }
     0,     6,     0,    34,     6,    40,    14,    40,    14,    32,
     8,    32,     8,     8,    14,     8,    14,     0,     6,     0,
 41,  10,   { ) }
     0,     0,     0,     8,     6,     8,     6,    32,     0,    32,
     0,    40,     8,    40,    14,    34,    14,     6,     8,     0,
 42,  18,   { * }
     0,    16,     0,    22,     8,    22,     2,    28,     6,    32,
    12,    26,    18,    32,    22,    28,    16,    22,    24,    22,
    24,    16,    16,    16,    22,    10,    18,     6,    12,    12,
     6,     6,     2,    10,     8,    16,
 43,  12,   { + }
     0,    16,     0,    22,     9,    22,     9,    31,    15,    31,
    15,    22,    24,    22,    24,    16,    15,    16,    15,     7,
     9,     7,     9,    16,
 44,   6,   { , }
     0,     0,     0,     8,     8,     8,     8,  64+2,     2,  64+8,
     2,     0,
 45,   4,   { - }
     0,    16,     0,    22,    20,    22,    20,    16,
 46,   4,   { . }
     0,     0,     0,     8,     8,     8,     8,     0,
 47,   4,   { / }
     0,     0,     0,    10,    30,    40,    30,    30,
 48,  14,   { 0 }
     0,     6,     0,    34,     6,    40,    18,    40,    24,    34,
    24,     6,    18,     0,     8,     0,     8,     8,    16,     8,
    16,    32,     8,    32,     8,     0,     6,     0,
 49,   6,   { 1 }
     4,     0,     4,    32,     0,    32,     0,    40,    12,    40,
    12,     0,
 50,  15,   { 2 }
     0,     0,     0,     8,    18,    26,    18,    32,     8,    32,
     8,    28,     0,    28,     0,    34,     6,    40,    20,    40,
    26,    34,    26,    22,    12,     8,    26,     8,    26,     0,
 51,  23,   { 3 }
     0,     6,     0,    12,     8,    12,     8,     8,    18,     8,
    18,    16,    10,    16,    10,    24,    18,    24,    18,    32,
     8,    32,     8,    28,     0,    28,     0,    34,     6,    40,
    20,    40,    26,    34,    26,    24,    22,    20,    26,    16,
    26,     6,    20,     0,     6,     0,
 52,  17,   { 4 }
     0,    10,     0,    20,    20,    40,    28,    40,    28,    18,
    32,    18,    32,    10,    28,    10,    28,     0,    20,     0,
    20,    10,     8,    10,     8,    18,    20,    18,    20,    30,
     8,    18,     8,    10,
 53,  17,   { 5 }
     0,     6,     0,    12,     8,    12,     8,     8,    18,     8,
    18,    18,     0,    18,     0,    40,    26,    40,    26,    32,
     8,    32,     8,    26,    20,    26,    26,    20,    26,     6,
    20,     0,     6,     0,
 54,  21,   { 6 }
     0,     6,     0,    34,     6,    40,    20,    40,    26,    34,
    26,    28,    18,    28,    18,    32,     8,    32,     8,    24,
    20,    24,    26,    18,    26,     6,    20,     0,     8,     0,
     8,     8,    18,     8,    18,    16,     8,    16,     8,     0,
     6,     0,
 55,   9,   { 7 }
     0,     0,     0,    14,    18,    32,     0,    32,     0,    40,
    26,    40,    26,    28,     8,    10,     8,     0,
 56,  24,   { 8 }
     0,     6,     0,    16,     4,    20,     0,    24,     0,    34,
     6,    40,    20,    40,    26,    34,    26,    24,    22,    20,
    26,    16,    26,     6,    20,     0,     8,     0,     8,     8,
    18,     8,    18,    16,     8,    16,     8,    24,    18,    24,
    18,    32,     8,    32,     8,     0,     6,     0,
 57,  21,   { 9 }
     0,     6,     0,    12,     8,    12,     8,     8,    18,     8,
    18,    16,     8,    16,     8,    24,    18,    24,    18,    32,
     8,    32,     8,    16,     6,    16,     0,    22,     0,    34,
     6,    40,    20,    40,    26,    34,    26,     6,    20,     0,
     6,     0,
 58,   4,   { : }
     0,     0,     0,     8,     8,     8,     8,     0,
 58,   4,   { : }
     0,    14,     0,    22,     8,    22,     8,    14,
 59,   6,   { ; }
     0,     0,     0,     8,     8,     8,     8,  64+2,     2,  64+8,
     2,     0,
 59,   4,   { ; }
     0,    14,     0,    22,     8,    22,     8,    14,
 60,   8,   { < }
     0,    16,    16,    32,    20,    32,    20,    26,    10,    16,
    20,     6,    20,     0,    16,     0,
 61,   4,   { = }
     0,     8,     0,    14,    20,    14,    20,     8,
 61,   4,   { = }
     0,    20,     0,    26,    20,    26,    20,    20,
 62,   8,   { > }
     0,     0,     0,     6,    10,    16,     0,    26,     0,    32,
     4,    32,    20,    16,     4,     0,
 63,  14,   { ? }
     0,    28,     0,    34,     6,    40,    20,    40,    26,    34,
    26,    26,    18,    18,    18,    12,    10,    12,    10,    22,
    18,    30,    18,    32,     8,    32,     8,    28,
 63,   4,   { ? }
    10,     0,    10,     6,    18,     6,    18,     0,
 64,  19,   { @ }
     0,     6,     0,    14,     6,    20,    18,    20,    18,    14,
     8,    14,     8,     8,    18,     8,    18,    26,     6,    26,
     6,    24,     0,    24,     0,    28,     6,    34,    20,    34,
    26,    28,    26,     6,    20,     0,     6,     0,
 65,  14,   { A }
     0,     0,     0,    34,     6,    40,    20,    40,    26,    34,
    26,     0,    18,     0,    18,    10,     8,    10,     8,    18,
    18,    18,    18,    32,     8,    32,     8,     0,
 66,  19,   { B }
     0,     0,     0,    40,    20,    40,    26,    34,    26,    24,
    22,    20,    26,    16,    26,     6,    20,     0,     8,     0,
     8,     8,    18,     8,    18,    16,     8,    16,     8,    24,
    18,    24,    18,    32,     8,    32,     8,     0,
 67,  16,   { C }
     0,     6,     0,    34,     6,    40,    20,    40,    26,    34,
    26,    26,    18,    26,    18,    32,     8,    32,     8,     8,
    18,     8,    18,    14,    26,    14,    26,     6,    20,     0,
     6,     0,
 68,  12,   { D }
     0,     0,     0,    40,    20,    40,    26,    34,    26,     6,
    20,     0,     8,     0,     8,     8,    18,     8,    18,    32,
     8,    32,     8,     0,
 69,  12,   { E }
     0,     0,     0,    40,    26,    40,    26,    32,     8,    32,
     8,    24,    24,    24,    24,    16,     8,    16,     8,     8,
    26,     8,    26,     0,
 70,  10,   { F }
     0,     0,     0,    40,    26,    40,    26,    32,     8,    32,
     8,    24,    24,    24,    24,    16,     8,    16,     8,     0,
 71,  18,   { G }
     0,     6,     0,    34,     6,    40,    20,    40,    26,    34,
    26,    28,    18,    28,    18,    32,     8,    32,     8,     8,
    18,     8,    18,    12,    14,    12,    14,    20,    26,    20,
    26,     6,    20,     0,     6,     0,
 72,  12,   { H }
     0,     0,     0,    40,     8,    40,     8,    24,    18,    24,
    18,    40,    26,    40,    26,     0,    18,     0,    18,    16,
     8,    16,     8,     0,
 73,   4,   { I }
     0,     0,     0,    40,     8,    40,     8,     0,
 74,  10,   { J }
     0,     6,     0,    14,     8,    14,     8,     8,    18,     8,
    18,    40,    26,    40,    26,     6,    20,     0,     6,     0,
 75,  16,   { K }
     0,     0,     0,    40,     8,    40,     8,    24,    18,    34,
    18,    40,    26,    40,    26,    30,    18,    22,    26,    14,
    26,     0,    18,     0,    18,    10,    12,    16,     8,    16,
     8,     0,
 76,   6,   { L }
     0,     0,     0,    40,     8,    40,     8,     8,    26,     8,
    26,     0,
 77,  12,   { M }
     0,     0,     0,    40,     6,    40,    16,    30,    26,    40,
    32,    40,    32,     0,    24,     0,    24,    28,    16,    20,
     8,    28,     8,     0,
 78,  11,   { N }
     0,     0,     0,    40,     4,    40,    18,    26,    18,    40,
    26,    40,    26,     0,    18,     0,    18,    14,     8,    24,
     8,     0,
 79,  14,   { O }
     0,     6,     0,    34,     6,    40,    20,    40,    26,    34,
    26,     6,    20,     0,     8,     0,     8,     8,    18,     8,
    18,    32,     8,    32,     8,     0,     6,     0,
 80,  12,   { P }
     0,     0,     0,    40,    20,    40,    26,    34,    26,    22,
    20,    16,     8,    16,     8,    24,    18,    24,    18,    32,
     8,    32,     8,     0,
 81,  15,   { Q }
     0,     6,     0,    34,     6,    40,    18,    40,    24,    34,
    24,     8,    26,     8,    26,     0,     8,     0,     8,     8,
    16,     8,    16,    32,     8,    32,     8,     0,     6,     0,
 82,  16,   { R }
     0,     0,     0,    40,    20,    40,    26,    34,    26,    24,
    22,    20,    26,    16,    26,     0,    18,     0,    18,    16,
     8,    16,     8,    24,    18,    24,    18,    32,     8,    32,
     8,     0,
 83,  22,   { S }
     0,     6,     0,    12,     8,    12,     8,     8,    18,     8,
    18,    16,     6,    16,     0,    22,     0,    34,     6,    40,
    20,    40,    26,    34,    26,    28,    18,    28,    18,    32,
     8,    32,     8,    24,    20,    24,    26,    18,    26,     6,
    20,     0,     6,     0,
 84,   8,   { T }
     8,     0,     8,    32,     0,    32,     0,    40,    24,    40,
    24,    32,    16,    32,    16,     0,
 85,  10,   { U }
     0,     6,     0,    40,     8,    40,     8,     8,    18,     8,
    18,    40,    26,    40,    26,     6,    20,     0,     6,     0,
 86,  10,   { V }
     0,    14,     0,    40,     8,    40,     8,    18,    14,    12,
    20,    18,    20,    40,    28,    40,    28,    14,    14,     0,
 87,  14,   { W }
     0,     4,     0,    40,     8,    40,     8,    12,    16,    20,
    24,    12,    24,    40,    32,    40,    32,     4,    28,     0,
    24,     0,    16,     8,     8,     0,     4,     0,
 88,  20,   { X }
     0,     0,     0,    14,     6,    20,     0,    26,     0,    40,
     8,    40,     8,    30,    13,    25,    18,    30,    18,    40,
    26,    40,    26,    26,    20,    20,    26,    14,    26,     0,
    18,     0,    18,    10,    13,    15,     8,    10,     8,     0,
 89,  14,   { Y }
     9,     0,     9,    16,     0,    25,     0,    40,     8,    40,
     8,    28,    12,    24,    14,    24,    18,    28,    18,    40,
    26,    40,    26,    25,    17,    16,    17,     0,
 90,  10,   { Z }
     0,     0,     0,    13,    19,    32,     0,    32,     0,    40,
    26,    40,    26,    27,     7,     8,    26,     8,    26,     0,
 91,   8,   { [ }
     0,     0,     0,    40,    14,    40,    14,    32,     8,    32,
     8,     8,    14,     8,    14,     0,
 92,   4,   { \ }
     0,    30,     0,    40,    30,    10,    30,     0,
 93,   8,   { ] }
     0,     0,     0,     8,     6,     8,     6,    32,     0,    32,
     0,    40,    14,    40,    14,     0,
 94,   9,   { ^ }
     0,    18,     0,    28,    12,    40,    24,    28,    24,    18,
    16,    26,    16,     0,     8,     0,     8,    26,
 95,   4,   { _ }
      0,     0,    36,     0,    36,     8,     0,     8,
 96,   6,   { ` }
     0,    32,     0,    40,     6,    40,     6,    32,    10,    28,
     4,    28,
 97,  12,   { a }
     0,     6,     0,    18,     6,    24,    26,    24,    26,     0,
     8,     0,     8,     8,    18,     8,    18,    16,     8,    16,
     8,     0,     6,     0,
 98,  14,   { b }
     0,     0,     0,    36,     8,    36,     8,    24,    20,    24,
    26,    18,    26,     6,    20,     0,     8,     0,     8,     8,
    18,     8,    18,    16,     8,    16,     8,     0,
 99,  10,   { c }
     0,     6,     0,    18,     6,    24,    22,    24,    22,    16,
     8,    16,     8,     8,    22,     8,    22,     0,     6,     0,
 100,  14,   { d }
     0,     6,     0,    18,     6,    24,    18,    24,    18,    36,
    26,    36,    26,     0,     8,     0,     8,     8,    18,     8,
    18,    16,     8,    16,     8,     0,     6,     0,
 101,  16,   { e }
     0,     4,     0,    20,     4,    24,    18,    24,    22,    20,
    22,    14,    18,    10,     6,    10,     6,    14,    16,    14,
    16,    20,     6,    20,     6,     6,    22,     6,    22,     0,
     4,     0,
 102,  15,   { f }
     4,     0,     4,    12,     0,    12,     0,    20,     4,    20,
     4,    30,    10,    36,    18,    36,    18,    28,    12,    28,
    12,    20,    16,    20,    16,    12,    12,    12,    12,     0,
 103,  17,   { g }
     0,     6,     0,    18,     6,    24,    26,    24,    26,  64+8,
    20, 64+14,     0, 64+14,     0,  64+6,    18,  64+6,    18,     0,
     8,     0,     8,     8,    18,     8,    18,    16,     8,    16,
     8,     0,     6,     0,
 104,  11,   { h }
     0,     0,     0,    36,     8,    36,     8,    24,    20,    24,
    26,    18,    26,     0,    18,     0,    18,    16,     8,    16,
     8,     0,
 105,   4,   { i }
     0,     0,     0,    22,     8,    22,     8,     0,
 105,   4,   { i }
     0,    28,     0,    36,     8,    36,     8,    28,
 106,   7,   { j }
     0,     0,     8,     0,     8,    22,    16,    22,    16,  64+2,
    10,  64+8,     0,  64+8,
 106,   4,   { j }
     8,    28,     8,    36,    16,    36,    16,    28,
 107,  17,   { k }
     0,     0,     0,    36,     8,    36,     8,    22,    12,    22,
    18,    28,    18,    32,    26,    32,    26,    24,    21,    19,
    26,    14,    26,     0,    18,     0,    18,    10,    14,    14,
     8,    14,     8,     0,
 108,   4,   { l }
     0,     0,     0,    36,     8,    36,     8,     0,
 109,  16,   { m }
     0,     0,     0,    24,    14,    24,    18,    20,    22,    24,
    32,    24,    36,    20,    36,     0,    28,     0,    28,    16,
    22,    16,    22,     0,    14,     0,    14,    16,     8,    16,
     8,     0,
 110,   9,   { n }
     0,     0,     0,    24,    20,    24,    26,    18,    26,     0,
    18,     0,    18,    16,     8,    16,     8,     0,
 111,  14,   { o }
     0,     6,     0,    18,     6,    24,    20,    24,    26,    18,
    26,     6,    20,     0,     8,     0,     8,     8,    18,     8,
    18,    16,     8,    16,     8,     0,     6,     0,
 112,  12,   { p }
     0, 64+14,     0,    24,    20,    24,    26,    18,    26,     6,
    20,     0,     8,     0,     8,     8,    18,     8,    18,    16,
     8,    16,     8, 64+14,
 113,  14,   { q }
     0,     6,     0,    18,     6,    24,    26,    24,    26, 64+14,
    18, 64+14,    18,     0,     8,     0,     8,     8,    18,     8,
    18,    16,     8,    16,     8,     0,     6,     0,
 114,   7,   { r }
     0,     0,     0,    18,     6,    24,    22,    24,    22,    16,
     8,    16,     8,     0,
 115,  16,   { s }
     0,     0,     0,     6,    16,     6,    16,    10,     4,    10,
     0,    14,     0,    20,     4,    24,    24,    24,    24,    18,
     8,    18,     8,    14,    20,    14,    24,    10,    24,     4,
    20,     0,
 116,  11,   { t }
     0,     6,     0,    36,     8,    36,     8,    28,    16,    28,
    16,    20,     8,    20,     8,     8,    16,     8,    16,     0,
     6,     0,
 117,   9,   { u }
     0,     6,     0,    24,     8,    24,     8,     8,    18,     8,
    18,    24,    26,    24,    26,     0,     6,     0,
 118,  12,   { v }
     0,    12,     0,    24,     8,    24,     8,    14,    12,    10,
    14,    10,    18,    14,    18,    24,    26,    24,    26,    12,
    14,     0,    12,     0,
 119,  17,   { w }
     0,     4,     0,    24,     8,    24,     8,     8,    14,     8,
    14,    24,    22,    24,    22,     8,    28,     8,    28,    24,
    36,    24,    36,     4,    32,     0,    22,     0,    18,     4,
    14,     0,     4,     0,
 120,  20,   { x }
     0,     0,     0,     6,     6,    12,     0,    18,     0,    24,
     8,    24,     8,    20,    13,    15,    18,    20,    18,    24,
    26,    24,    26,    18,    20,    12,    26,     6,    26,     0,
    18,     0,    18,     4,    13,     9,     8,     4,     8,     0,
 121,  14,   { y }
     0,     6,     0,    24,     8,    24,     8,     8,    18,     8,
    18,    24,    26,    24,    26,  64+8,    20, 64+14,     0, 64+14,
     0,  64+6,    18,  64+6,    18,     0,     6,     0,
 122,  10,   { z }
     0,     0,     0,     4,    12,    16,     0,    16,     0,    24,
    24,    24,    24,    20,    12,     8,    24,     8,    24,     0,
 123,  16,   { left curly bracket }
     4,     4,     4,    16,     0,    20,     4,    24,     4,    36,
     8,    40,    16,    40,    16,    32,    12,    32,    12,    24,
     8,    20,    12,    16,    12,     8,    16,     8,    16,     0,
     8,     0,
 124,   4,   { | }
     0,     0,     0,    40,     8,    40,     8,     0,
 125,  16,   { right curly bracket }
     0,     0,     0,     8,     4,     8,     4,    16,     8,    20,
     4,    24,     4,    32,     0,    32,     0,    40,     8,    40,
    12,    36,    12,    24,    16,    20,    12,    16,    12,     4,
     8,     0,
 126,  14,   { ~ }
     0,    12,     0,    20,     6,    26,    10,    26,    14,    22,
    16,    22,    22,    28,    24,    28,    24,    20,    18,    14,
    14,    14,    10,    18,     8,    18,     2,    12

%integer %fn draw sym (%integer s, x, y, scale)
   %integer xx, yy, l, ox, oy, i, j

   %if starts initialised # true %start
       starts initialised = true
       i = 1
       %while i <points %cycle
         starts(coords(i)) = i %if starts(coords(i)) = 0
         i = i + coords(i+1)*2+2
       %repeat
   %finish
   l = 0
   i = starts(s&127)
   %if i # 0 %start
       %while i<= points %and coords(i) = s&127 %cycle
          j = coords(i+1)
          i = i+2
          xx = coords(i) * scale
          yy = coords(i+1)
          yy =  64-yy %if yy>= 64;         !deal with descenders
          yy = yy * scale
          ox = x + xx;   oy = y + yy
          polygon (ox, oy)
          l = |xx| %if |xx|> l
          i = i+2
          j = j-1
          %while j>0 %cycle
             xx = coords(i);   yy = coords(i+1)
             yy = 64-yy %if yy>= 64;       !deal with descenders
             xx = xx * scale;   yy = yy * scale
             axy (x+xx, y+yy)
             l = |xx| %if |xx| >l
             i = i+2
             j = j-1
          %repeat
          axy (ox, oy)
       %repeat
   %finish %else %result = |space width*scale|
   %result = l + |spacing*scale|
%end

%routine draw syms (%string (255) s, %integer x, y, scale)
   %integer i, l
   l = 0
   l = l + draw sym(charno(s,i),x+l,y,scale) %for i = 1,1,length(s)
%end

%external %routine set text margin %alias "ILAP_SET_TEXT_MARGIN" (%integer margin)
   %if margin < 0 %start
       warning ("Negative text margin ignored")
   %else
       edge space = margin
   %finish
%end

%external %routine text %alias "ILAP_TEXT" (%string(31) cell name, 
   %string(255) contents, %integer box width, box height)
   %const %byte %array width(32:126) =
   20, 9,14,20,18,20,18,10,12,12,17,17, 9,15, 9,20,
   17,11,18,18,21,18,18,18,18,18, 9, 9,15,15,15,18,
   18,18,18,18,18,18,18,18,18, 9,18,18,18,21,18,18,
   18,18,18,18,17,18,19,21,18,18,18,12,20,12,17,18,
   10,18,18,16,18,16,14,18,18, 9,13,18, 9,23,18,18,
   18,18,16,17,13,18,18,23,18,18,17,13, 9,13,17
   %const %byte %array above(32:126) =
   0,20,20,20,20,20,20,20,20,20,16,16,4 ,11,4 ,20,20,20,20,20,20,20,20,20,20,20,
   11,11,16,13,16,20,17,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
   20,20,20,20,20,20,20,20,20,20,20,16,20,12,18,12,18,12,18,12,18,18,18,18,18,12,
   12,12,12,12,12,12,18,12,12,12,12,12,12,20,20,20,14
   %const %byte %array below(32:126) =
   0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,4,0,0,0,
   0,0,7,7,0,0,0,0,0,0,0,7,0,0,0,0,0
   %const %integer line space = 12
   %record %format data(%string(*)%name text, %integer width, chars, above, below)
   %const %integer max lines = 31
   %record (data) %array line(1:max lines)
   %integer lines, i, j, twidth, theight, worth starting, cc, old control
   %integer height scale, width scale, s, xstart, ystart, xnext, ynext
   %integer spacing, line spacing, lambda, bwidth, bheight
   %byte %name LP, CP
   %byte SL
  
   lp == sl                 { Save the length, so length of contents unaltered }
   lp = 0
   lines = 1
   line (1) = 0
   line (1)_text == contents
   %for i = 1, 1, length(contents) %cycle
        cp == charno (contents, i)
        %if cp = nl %start
            lines = lines + 1
            line (lines) = 0
            LP == CP
            LP = 0
            LINE (LINES)_TEXT == string(addr(LP))
        %finish %else %start
            CP = ' ' %unless 32 <= CP <= 126
            LP = LP + 1
        %finish
   %repeat
   length(contents) = sl
   ! Check that there is text to draw
   worth starting = false
   ! Scan each line of text to discover lengths, heights etc.
   twidth = 0
   theight = 0
   %for i = 1, 1, lines %cycle
      { Note that LINE has already been zeroed }
      line(i)_chars = length(line(i)_text) {no of chars}
      %if line(i)_chars = 0 %start
          line(i)_above = 20  {blank line !!!!}
          line(i)_width = 1   {avoids errors}
      %finish %else %start
          worth starting = true
          %for j = 1, 1,line(i)_chars %cycle
             cc = charno (line(i)_text, j)
             line(i)_width = line(i)_width + width(cc)
             line(i)_above = above(cc) %if above(cc) > line(i)_above
             line(i)_below = below(cc) %if below(cc) > line(i)_below
          %repeat
      %finish
      twidth = line(i)_width %if line(i)_width > twidth
      theight = theight + line(i)_above + line(i)_below
   %repeat
   %if worth starting = true %start
       twidth = twidth - 5           {adjusts for space on last char}
       ! Determine largest possible scale factor
       get lambda (lambda)
       bwidth = box width * lambda // 10;   bheight = box height * lambda // 10
       widthscale = bwidth // (twidth + edge space + edge space)
       heightscale = bheight // (theight + edge space + edge space)
       %if heightscale>width scale %then s=widthscale %else s=heightscale
       ! Calculate line spacing and positioning
       line spacing = 0
       spacing = bheight - s * theight
       %if lines # 1 %then line spacing = spacing // (lines-1)
       line spacing = s * line space %if line spacing > s * line space
       ystart = (spacing - (lines - 1) * line spacing) // 2
       xstart = (bwidth - s * twidth) // 2
       old control = ILAP control
       ILAP control = 0  {NO merge + NO DRC }
       set lambda (10)
       symbol(cell name)
          layer(layer for text)
          ynext = line(lines)_below * s + ystart
          xnext = (twidth-line(lines)_width+edge space)*s//2 + xstart
          draw syms (line(lines)_text, xnext, ynext, s//2)
          %for i = lines - 1, -1, 1 %cycle
               ynext = ynext+linespacing+(line(i+1)_above+line(i)_below)*s
               xnext = (twidth-line(i)_width+edge space)*s//2 + xstart
               draw syms (line(i)_text, xnext, ynext, s//2)
          %repeat
          Fix Mbb (0, 0, box width, box height)
        endsymbol
       set lambda (lambda)
       ILAP control = old control
   %else
       warning ("No printable text supplied,   Symbol ".cell name." not generated")
   %finish
%end

%external %routine TEXT LAYER %alias "ILAP_TEXT_LAYER" (%string (4) LAYER)
   layer for text = layer
%end

%external %routine COPYRIGHT %alias "ILAP_COPYRIGHT" (%string (31) name, %integer AX, AY)
   %integer sc, xre, yre, lambda
   Get lambda (lambda)
   ax = ax * lambda // 10;   ay = ay * lambda // 10
   ! The symbol is scaled from a 9 x 10 basic picture.
   %if AX//9>AY//10 %then SC=AY//10 %else SC=AX//9
   xre = (ax - sc * 9)//2;   yre = (ay - sc * 10)//2
   set lambda (10)
   Symbol (name)
      layer (layer for text)
      { The C }
      Polygon (3*sc+xre, 3*sc+yre);   dx (3*sc); dy (sc); dx(-2*sc); dy (2*sc)
                                      dx (2*sc); dy (sc); dx(-3*sc); dy (-4*sc)
      { The border }
      Polygon (3*sc+xre, yre);   dx (3*sc);  dxy (3*sc, 3*sc)
                                 dy (4*sc);  dxy (-3*sc, 3*sc)
                                 dx (-3*sc);  dxy (-3*sc, -3*sc)
                                 dy (-4*sc);  dxy (3*sc, -3*sc)
                                 dy (sc)
                                 dxy (-2*sc, 2*sc);  dy (4*sc)
                                 dxy (2*sc, 2*sc);  dx (3*sc)
                                 dxy (2*sc, -2*sc);  dy (-4*sc)
                                 dxy (-2*sc, -2*sc);  dx (-3*sc)
                                 dy (-sc)
   end symbol
   set Lambda (lambda)
%end

%end %of %file
