#import "Sonata.h"
 /* Superclass file goes here: */
#pragma .h #import "Glyph.h"
#import <math.h>

 /**
 ** abstract superclass for
 ** all images which use the Sonata font
 **/

struct _sonataMetric
{ unsigned char charVal ;
  char *name ;
  float xH, yH, w, h ;
} ;

struct _sonataMetric SonataMetrics[] =
{ {'\0',"unused",0.0,0.0,0.0,0.0},
  {'\1',"unused",0.0,0.0,0.0,0.0},
  {'\2',"unused",0.0,0.0,0.0,0.0},
  {'\3',"unused",0.0,0.0,0.0,0.0},
  {'\4',"unused",0.0,0.0,0.0,0.0},
  {'\5',"unused",0.0,0.0,0.0,0.0},
  {'\6',"unused",0.0,0.0,0.0,0.0},
  {'\7',"unused",0.0,0.0,0.0,0.0},
  {'\10',"unused",0.0,0.0,0.0,0.0},
  {'\11',"unused",0.0,0.0,0.0,0.0},
  {'\12',"unused",0.0,0.0,0.0,0.0},
  {'\13',"unused",0.0,0.0,0.0,0.0},
  {'\14',"unused",0.0,0.0,0.0,0.0},
  {'\15',"unused",0.0,0.0,0.0,0.0},
  {'\16',"unused",0.0,0.0,0.0,0.0},
  {'\17',"unused",0.0,0.0,0.0,0.0},
  {'\20',"unused",0.0,0.0,0.0,0.0},
  {'\21',"unused",0.0,0.0,0.0,0.0},
  {'\22',"unused",0.0,0.0,0.0,0.0},
  {'\23',"unused",0.0,0.0,0.0,0.0},
  {'\24',"unused",0.0,0.0,0.0,0.0},
  {'\25',"unused",0.0,0.0,0.0,0.0},
  {'\26',"unused",0.0,0.0,0.0,0.0},
  {'\27',"unused",0.0,0.0,0.0,0.0},
  {'\30',"unused",0.0,0.0,0.0,0.0},
  {'\31',"unused",0.0,0.0,0.0,0.0},
  {'\32',"unused",0.0,0.0,0.0,0.0},
  {'\33',"unused",0.0,0.0,0.0,0.0},
  {'\34',"unused",0.0,0.0,0.0,0.0},
  {'\35',"unused",0.0,0.0,0.0,0.0},
  {'\36',"unused",0.0,0.0,0.0,0.0},
  {'\37',"unused",0.0,0.0,0.0,0.0},
  {'\40',"space",0.000000,0.000000,0.000000,0.000000},
  {'\41',"largethree",0.000000,0.000000,0.210000,0.376000},
  {'\42',"grandpause",0.000000,0.000000,0.511000,0.509000},
  {'\43',"sharp",0.000000,-0.379000,0.224000,0.375000},
  {'\44',"serpent",0.000000,-0.175000,0.505000,1.158000},
  {'\45',"segno",0.000000,-0.343000,0.515000,0.336000},
  {'\46',"trebleclef",0.000000,-0.402000,0.611000,1.334000},
  {'\47',"arrowup",0.000000,0.000000,0.130000,0.162000},
  {'\50',"parenleft",0.000000,-0.050000,0.165000,0.500000},
  {'\51',"parenright",0.000000,-0.050000,0.165000,0.500000},
  {'\52',"pedaloff",0.000000,0.000000,0.361000,0.350000},
  {'\53',"cross",0.000000,-0.150000,0.300000,0.150000},
  {'\54',"pause",0.000000,-0.231000,0.182000,0.068000},
  {'\55',"tenuto",0.000000,-0.019000,0.300000,0.019000},
  {'\56',"dot",0.000000,-0.046000,0.094000,0.048000},
  {'\57',"percclef1",0.000000,0.000000,0.174000,0.500000},
  {'\60',"zero",0.000000,-0.217000,0.360000,0.218000},
  {'\61',"one",0.000000,-0.209000,0.250000,0.209000},
  {'\62',"two",0.000000,-0.217000,0.340000,0.218000},
  {'\63',"three",0.000000,-0.217000,0.324000,0.218000},
  {'\64',"four",0.000000,-0.209000,0.329000,0.209000},
  {'\65',"five",0.000000,-0.209000,0.300000,0.209000},
  {'\66',"six",0.000000,-0.217000,0.334000,0.218000},
  {'\67',"seven",0.000000,-0.215000,0.341000,0.216000},
  {'\70',"eight",0.000000,-0.217000,0.328000,0.218000},
  {'\71',"nine",0.000000,-0.217000,0.334000,0.218000},
  {'\72',"eighthdownsmall",0.000000,-0.438000,0.151000,0.062000},
  {'\73',"eighthupsmall",0.000000,-0.063000,0.274000,0.437000},
  {'\74',"unused",0.0,0.0,0.0,0.0},
  {'\75',"staff",-0.011000,-0.009000,1.011000,1.009000},
  {'\76',"accent",0.000000,0.004000,0.417000,0.257000},
  {'\77',"bassclef",0.000000,0.192000,0.691000,0.991000},
  {'\100',"largefive",0.000000,0.002000,0.197000,0.369000},
  {'\101',"quarternotedownB",0.000000,-0.759000,0.300000,0.126000},
  {'\102',"cclef",0.000000,-0.009000,0.674000,1.009000},
  {'\103',"cuttime",0.000000,-0.424000,0.421000,0.425000},
  {'\104',"dc",0.000000,-0.016000,0.811000,0.351000},
  {'\105',"eighthnotedown",0.000000,-0.874000,0.300000,0.125000},
  {'\106',"mezzoforte",0.000000,-0.172000,0.834000,0.413000},
  {'\107',"slashforgrace",0.000000,0.000000,0.150000,0.086000},
  {'\110',"halfnotedown",0.000000,-0.874000,0.300000,0.134000},
  {'\111',"smallsharp",0.000000,-0.193000,0.112000,0.188000},
  {'\112',"eighthflagdown",0.000000,-0.874000,0.271000,-0.124000},
  {'\113',"sxflagdown",0.000000,-0.874000,0.283000,-0.092000},
  {'\114',"bottombracket",0.000000,-0.296000,0.408000,0.155000},
  {'\115',"mordentslash",0.000000,-0.090000,0.586000,0.310000},
  {'\116',"unused",0.0,0.0,0.0,0.0},
  {'\117',"harmonic",0.000000,-0.131000,0.300000,0.132000},
  {'\120',"mezzopiano",0.000000,-0.172000,0.800000,0.266000},
  {'\121',"quarternotedown",0.000000,-0.874000,0.300000,0.125000},
  {'\122',"thrtynotedown",0.000000,-1.034000,0.300000,0.125000},
  {'\123',"sforzando",0.000000,-0.172000,0.599000,0.413000},
  {'\124',"turn",0.000000,-0.133000,0.618000,0.133000},
  {'\125',"fermata",0.000000,0.000000,0.658000,0.352000},
  {'\126',"octbassa",0.000000,0.000000,0.721000,0.360000},
  {'\127',"dblwholenote",0.000000,-0.166000,0.614000,0.166000},
  {'\130',"sxnotedown",0.000000,-0.874000,0.300000,0.125000},
  {'\131',"sxnotedownB",0.000000,-0.774000,0.558000,0.126000},
  {'\132',"forzando",0.000000,-0.172000,0.651000,0.413000},
  {'\133',"heavybarline",0.000000,-0.009000,0.150000,1.009000},
  {'\134',"upstem",0.275000,0.037000,0.300000,0.874000},
  {'\135',"repeat",0.000000,-0.009000,0.455000,1.009000},
  {'\136',"heavyaccent",0.000000,0.000000,0.263000,0.417000},
  {'\137',"ledgerline",0.000000,-0.015000,0.500000,0.015000},
  {'\140',"trillo",0.000000,-0.016000,0.497000,0.364000},
  {'\141',"quarternoteupB",0.000000,-0.126000,0.300000,0.759000},
  {'\142',"flat",0.000000,-0.178000,0.198000,0.491000},
  {'\143',"commontime",0.000000,-0.254000,0.421000,0.255000},
  {'\144',"ds",0.000000,-0.012000,0.746000,0.350000},
  {'\145',"eighthnoteup",0.000000,-0.125000,0.546000,0.874000},
  {'\146',"forte",0.000000,-0.172000,0.515000,0.413000},
  {'\147',"arpeggio",0.000000,0.000000,0.138000,0.534000},
  {'\150',"halfnoteup",0.000000,-0.134000,0.300000,0.874000},
  {'\151',"smallflat",0.000000,-0.089000,0.095000,0.246000},
  {'\152',"eighthflagup",0.275000,0.124000,0.546000,0.874000},
  {'\153',"sxflagup",0.275000,0.058000,0.558000,0.874000},
  {'\154',"barline",0.000000,-0.009000,0.037000,1.009000},
  {'\155',"mordent",0.000000,-0.001000,0.606000,0.240000},
  {'\156',"natural",0.000000,-0.350000,0.176000,0.350000},
  {'\157',"naturalharmonic",0.000000,-0.061000,0.120000,0.060000},
  {'\160',"piano",0.000000,-0.172000,0.445000,0.266000},
  {'\161',"quarternoteup",0.000000,-0.125000,0.300000,0.874000},
  {'\162',"thrtynoteup",0.000000,-0.125000,0.558000,1.019000},
  {'\163',"s",0.000000,-0.016000,0.226000,0.266000},
  {'\164',"tablature",0.000000,0.000000,0.557000,0.999000},
  {'\165',"fermataup",0.000000,-0.352000,0.658000,0.000000},
  {'\166',"wedgedown",0.000000,0.000000,0.263000,0.417000},
  {'\167',"wholenote",0.000000,-0.126000,0.412000,0.126000},
  {'\170',"sxnoteup",0.000000,-0.125000,0.558000,0.874000},
  {'\171',"sxnoteupB",0.000000,-0.126000,0.300000,0.988000},
  {'\172',"z",0.000000,-0.016000,0.291000,0.250000},
  {'\173',"repeatdots",0.000000,0.307000,0.126000,0.696000},
  {'\174',"downstem",0.000000,-0.874000,0.025000,-0.035000},
  {'\175',"repeatright",0.000000,-0.009000,0.455000,1.009000},
  {'\176',"trillsection",0.000000,0.000000,0.413000,0.165000},
  {'\177',"unused",0.0,0.0,0.0,0.0},
  {'\200',"unused",0.0,0.0,0.0,0.0},
  {'\201',"eighthnotedownB",0.000000,-0.774000,0.546000,0.126000},
  {'\202',"one28notedown",0.000000,-1.402000,0.300000,0.125000},
  {'\203',"unused",0.0,0.0,0.0,0.0},
  {'\204',"unused",0.0,0.0,0.0,0.0},
  {'\205',"unused",0.0,0.0,0.0,0.0},
  {'\206',"unused",0.0,0.0,0.0,0.0},
  {'\207',"unused",0.0,0.0,0.0,0.0},
  {'\210',"unused",0.0,0.0,0.0,0.0},
  {'\211',"unused",0.0,0.0,0.0,0.0},
  {'\212',"unused",0.0,0.0,0.0,0.0},
  {'\213',"unused",0.0,0.0,0.0,0.0},
 {'\214',"eighthnoteupB",0.000000,-0.126000,0.300000,0.924000},
  {'\215',"one28noteup",0.000000,-0.125000,0.558000,1.387000},
  {'\216',"unused",0.0,0.0,0.0,0.0},
  {'\217',"unused",0.0,0.0,0.0,0.0},
  {'\220',"unused",0.0,0.0,0.0,0.0},
  {'\221',"unused",0.0,0.0,0.0,0.0},
  {'\222',"unused",0.0,0.0,0.0,0.0},
  {'\223',"unused",0.0,0.0,0.0,0.0},
  {'\224',"unused",0.0,0.0,0.0,0.0},
  {'\225',"unused",0.0,0.0,0.0,0.0},
  {'\226',"unused",0.0,0.0,0.0,0.0},
  {'\227',"unused",0.0,0.0,0.0,0.0},
  {'\230',"unused",0.0,0.0,0.0,0.0},
  {'\231',"unused",0.0,0.0,0.0,0.0},
  {'\232',"unused",0.0,0.0,0.0,0.0},
  {'\233',"unused",0.0,0.0,0.0,0.0},
  {'\234',"unused",0.0,0.0,0.0,0.0},
  {'\235',"unused",0.0,0.0,0.0,0.0},
  {'\236',"unused",0.0,0.0,0.0,0.0},
  {'\237',"unused",0.0,0.0,0.0,0.0},
  {'\240',"extablature",0.000000,0.000000,0.211000,0.999000},
  {'\241',"pedal",0.000000,-0.002000,0.792000,0.458000},
  {'\242',"italicfour",0.000000,0.000000,0.248000,0.297000},
  {'\243',"italicthree",0.000000,-0.015000,0.244000,0.297000},
  {'\244',"italicsix",0.000000,-0.015000,0.205000,0.297000},
  {'\245',"italiceight",0.000000,-0.015000,0.262000,0.297000},
  {'\246',"italicseven",0.000000,0.000000,0.233000,0.297000},
  {'\247',"braceup",0.000000,-1.001000,0.300000,1.009000},
  {'\250',"thrtyscndrest",0.000000,-0.384000,0.400000,0.578000},
  {'\251',"graceup",0.000000,-0.062000,0.150000,0.438000},
  {'\252',"italictwo",0.000000,-0.015000,0.249000,0.297000},
  {'\253',"unused",0.000000,0.000000,0.000000,0.000000},
  {'\254',"dotaccentup",0.000000,0.000000,0.278000,0.416000},
  {'\255',"square",0.000000,-0.150000,0.300000,0.150000},
  {'\256',"arrowdown",0.000000,0.000000,0.130000,0.162000},
  {'\257',"halfnotedownB",0.000000,-0.759000,0.300000,0.134000},
  {'\260',"italicfive",0.000000,-0.015000,0.230000,0.297000},
  {'\261',"major",0.000000,-0.116000,0.300000,0.155000},
  {'\262',"upbow",0.000000,0.000000,0.229000,0.417000},
  {'\263',"downbow",0.000000,0.000000,0.340000,0.351000},
  {'\264',"thrtynoteupB",0.000000,-0.126000,0.300000,1.123000},
  {'\265',"mordentthree",0.000000,-0.001000,0.852000,0.238000},
  {'\266',"unused",0.000000,0.000000,0.000000,0.000000},
  {'\267',"wholerest",0.000000,0.125000,0.313000,0.250000},
  {'\270',"ppp",0.000000,-0.172000,1.197000,0.266000},
  {'\271',"pp",0.000000,-0.172000,0.821000,0.266000},
  {'\272',"dblflat",0.000000,-0.178000,0.367000,0.491000},
  {'\273',"italicnine",0.000000,-0.015000,0.215000,0.297000},
  {'\274',"italiczero",0.000000,-0.015000,0.233000,0.297000},
  {'\275',"m",0.000000,-0.016000,0.479000,0.266000},
  {'\276',"tremeloshort",0.000000,0.000000,0.300000,0.479000},
  {'\277',"halfnoteupB",0.000000,-0.134000,0.300000,0.759000},
  {'\300',"rhythmX",0.000000,-0.149000,0.300000,0.150000},
  {'\301',"italicone",0.000000,0.000000,0.198000,0.297000},
  {'\302',"topbracket",0.000000,-0.155000,0.408000,0.296000},
  {'\303',"octalta",0.000000,0.000000,0.573000,0.360000},
  {'\304',"ff",0.000000,-0.172000,0.781000,0.413000},
  {'\305',"sixteenthrest",0.000000,-0.384000,0.331000,0.322000},
  {'\306',"sxtyfournoteup",0.000000,-0.125000,0.558000,1.242000},
  {'\307',"extendstemup",0.275000,0.000000,0.300000,0.250000},
  {'\310',"extendstemdown",0.000000,-0.250000,0.025000,0.000000},
  {'\311',"eighthupslash",0.000000,-0.063000,0.284000,0.437000},
  {'\312',"stemspace",0.000000,0.000000,0.000000,0.000000},
  {'\213',"unused",0.0,0.0,0.0,0.0},
  {'\214',"unused",0.0,0.0,0.0,0.0},
  {'\215',"unused",0.0,0.0,0.0,0.0},
  {'\316',"quarterrest",0.000000,-0.355000,0.257000,0.400000},
  {'\317',"quarternotehead",0.000000,-0.125000,0.300000,0.125000},
  {'\320',"squarefill",0.000000,-0.150000,0.300000,0.150000},
  {'\321',"trianglefill",0.000000,-0.116000,0.300000,0.155000},
  {'\322',"repeatbarleft",0.000000,-0.009000,0.258000,1.009000},
  {'\323',"repeatbarright",0.197000,-0.009000,0.455000,1.009000},
  {'\324',"repsign",0.000000,0.000000,0.610000,0.509000},
  {'\325',"unused",0.0,0.0,0.0,0.0},
  {'\326',"percclef2",0.000000,0.070000,0.280000,0.930000},
  {'\327',"octbassa1",0.000000,0.000000,0.561000,0.364000},
  {'\330',"unused",0.000000,0.000000,0.000000,0.000000},
  {'\331',"trillofinno",0.000000,-0.013000,0.468000,0.369000},
  {'\332',"monsternote",0.000000,-0.125000,0.558000,0.874000},
  {'\333',"unused",0.0,0.0,0.0,0.0},
  {'\334',"dblsharp",0.000000,-0.131000,0.266000,0.131000},
  {'\335',"measurerest",0.000000,0.000000,0.500000,0.500000},
  {'\336',"coda",0.000000,-0.254000,0.443000,0.255000},
   {'\337',"unused",0.0,0.0,0.0,0.0},
 {'\340',"wedgefill",0.000000,0.000000,0.228000,0.199000},
  {'\341',"diamond",0.000000,-0.150000,0.300000,0.150000},
  {'\342',"diamondfill",0.000000,-0.150000,0.300000,0.150000},
  {'\343',"dblwholerest",0.000000,0.000000,0.150000,0.250000},
  {'\344',"eighthrest",0.000000,-0.384000,0.262000,0.078000},
  {'\345',"one28rest",0.000000,-0.384000,0.538000,1.078000},
  {'\346',"unused",0.0,0.0,0.0,0.0},
  {'\347',"thrtynotedownB",0.000000,-1.042000,0.558000,0.126000},
  {'\350',"dotaccentdown",0.000000,0.000000,0.278000,0.416000},
  {'\351',"smallnatural",0.000000,-0.192000,0.088000,0.186000},
  {'\352',"bracedown",0.000000,-1.001000,0.300000,1.009000},
  {'\353',"unused",0.0,0.0,0.0,0.0},
  {'\354',"fff",0.000000,-0.172000,1.047000,0.413000},
  {'\355',"gracedown",0.000000,-0.438000,0.150000,0.062000},
  {'\356',"halfrest",0.000000,0.000000,0.313000,0.125000},
  {'\357',"sxtyfournotedown",0.000000,-1.218000,0.300000,0.125000},
  {'\360',"extendflagdown",0.000000,-0.159000,0.272000,0.375000},
  {'\361',"dottedbarline",0.000000,-0.009000,0.037000,1.009000},
  {'\362',"metronome",0.000000,-0.062000,0.365000,0.438000},
  {'\363',"r",0.000000,0.000000,0.280000,0.266000},
  {'\364',"sxtyfourrest",0.000000,-0.384000,0.469000,0.828000},
  {'\365',"unused",0.000000,0.000000,0.000000}, 
  {'\366',"noteheadextra",0.000000,-0.125000,0.300000,0.125000},
  {'\367',"unused",0.0,0.0,0.0,0.0},
  {'\370',"unused",0.0,0.0,0.0,0.0},
  {'\371',"unused",0.0,0.0,0.0,0.0},
  {'\372',"halfnotehead",0.000000,-0.134000,0.300000,0.134000},
  {'\373',"extendflagup",0.275000,-0.360000,0.546000,0.184000}
} ;

@implementation Sonata:Glyph
{ @public
  unsigned char charVal ; // char code for this glyph
}

+ sonataMetricFor: (unsigned char) code inRect: (NXRect *) aRect ;
{ // return the sonata metrics xH,wH,w,h in aRect
  aRect->origin.x = SonataMetrics[code].xH ;
  aRect->origin.y = SonataMetrics[code].yH ;
  aRect->size.width = SonataMetrics[code].w ;
  aRect->size.width = SonataMetrics[code].h ;
  return self ;
}


- drawSelf: (NXRect *) aRect ;
{ // print a character from the font
  static char theText[2] = " " ;
  theText[0] = charVal ;
  [Nu showString:theText font: "Sonata"
    width: scale.width height: scale.height
    x:hotSpot.x y:hotSpot.y] ;
  return self ;
}


- init: (float) width :(float) height ;
{ [super init: width  :height] ;
  [self setCharVal: '\43'] ; 
  return self ;
}

- (const char *) name ;
{ return SonataMetrics[charVal].name ;
}

- setCharVal: (unsigned char) aChar ;
{ // unsigned char index ;
  // index = aChar - ' ' ;
  charVal = aChar ;
  hotSpot.x = ceil(-scale.width * SonataMetrics[charVal].xH) ;
  hotSpot.y = ceil(-scale.height * SonataMetrics[charVal].yH) ;
  frame.size.width = scale.width * SonataMetrics[charVal].w + hotSpot.x  ;
  frame.size.height = scale.height * SonataMetrics[charVal].h + hotSpot.y  ;
  frame.size.width = ceil(frame.size.width ) ;
  frame.size.height = ceil(frame.size.height) ;
  return self ;
}

-read: (NXTypedStream *) stream ;
{ [super read: stream] ;
  NXReadTypes(stream,"c",&charVal) ;
  return self ;
}


-write: (NXTypedStream *) stream ;
{ [super write: stream] ;
  NXWriteTypes(stream,"c",&charVal) ;
  return self ;
}


@end

/***
@makePallet
	`
#import "Sonata.h"
#import <math.h>
#import <strings.h>

// make a pallet with the entire font 

struct _sonataMetric
{ unsigned char charVal ;
  char *name ;
  float xH, yH, w, h ;
} ; 
extern struct _sonataMetric SonataMetrics[] ;

#define SCALE 28.0
NXPoint aPnt = {0.0,0.0} ;
NXRect aRect ;
float increment ;
int i, j, knt, sideLen ;
id rootGlyph, aGlyph ;

[Nu loadIfNeeded: "Sonata"] ;
[Nu glyphWindow] ;
knt = 0 ;
for(i = 0 ; i < 252 ; i++)
{ if(strcmp(SonataMetrics[i].name, "unused"))
    knt++ ;
}
increment = 1.5 * SCALE ;
sideLen = (int) sqrt(knt) ;
rootGlyph = [Nu rootGlyph] ;
for(i = 0, j = 0 ; j < 252 ; j++)
{ if(!strcmp(SonataMetrics[j].name,"unused"))
    continue ;
  aGlyph = [[objc_getClass("Sonata") alloc]
          init: SCALE :SCALE] ;
  [aGlyph setCharVal: (char) j] ;
  if(i % sideLen)
    aPnt.x += increment ;
  else
  { aPnt.y += increment ;
    aPnt.x = increment ;
  }
  i++ ;
  [aGlyph moveOriginTo: &aPnt ofGlyph: rootGlyph] ;
}
[rootGlyph enclose] ;
[rootGlyph getFrame: &aRect] ;
[rootGlyph display: &aRect from: nil] ;
	`

// print to transcript a list of Sonata characters
// and their codes in decimal
int i ;
struct _sonataMetric
{ unsigned char charVal ;
  char *name ;
  float xH, yH, w, h ;
} ;
extern struct _sonataMetric SonataMetrics[] ;

[Nu loadIfNeeded: "Sonata"] ;
for(i = 0 ; i < 0373 ; i++)
{ if(strcmp(SonataMetrics[i].name,"unused"))
  { [Nu printf: "case %d: // %s\n", SonataMetrics[i].charVal, SonataMetrics[i].name] ;
  }
}
	`



****/
