ttinterp.c 241 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496
  1. /***************************************************************************/
  2. /* */
  3. /* ttinterp.c */
  4. /* */
  5. /* TrueType bytecode interpreter (body). */
  6. /* */
  7. /* Copyright 1996-2001, 2002 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  10. /* This file is part of the FreeType project, and may only be used, */
  11. /* modified, and distributed under the terms of the FreeType project */
  12. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  13. /* this file you indicate that you have read the license and */
  14. /* understand and accept it fully. */
  15. /* */
  16. /***************************************************************************/
  17. #include <ft2build.h>
  18. #include FT_INTERNAL_DEBUG_H
  19. #include FT_INTERNAL_CALC_H
  20. #include FT_TRIGONOMETRY_H
  21. #include FT_SYSTEM_H
  22. #include "ttinterp.h"
  23. #include "tterrors.h"
  24. #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  25. #define TT_MULFIX FT_MulFix
  26. #define TT_MULDIV FT_MulDiv
  27. #define TT_INT64 FT_Int64
  28. /*************************************************************************/
  29. /* */
  30. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  31. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  32. /* messages during execution. */
  33. /* */
  34. #undef FT_COMPONENT
  35. #define FT_COMPONENT trace_ttinterp
  36. #undef NO_APPLE_PATENT
  37. #define APPLE_THRESHOLD 0x4000000L
  38. /*************************************************************************/
  39. /* */
  40. /* In order to detect infinite loops in the code, we set up a counter */
  41. /* within the run loop. A single stroke of interpretation is now */
  42. /* limitet to a maximal number of opcodes defined below. */
  43. /* */
  44. #define MAX_RUNNABLE_OPCODES 1000000L
  45. /*************************************************************************/
  46. /* */
  47. /* There are two kinds of implementations: */
  48. /* */
  49. /* a. static implementation */
  50. /* */
  51. /* The current execution context is a static variable, which fields */
  52. /* are accessed directly by the interpreter during execution. The */
  53. /* context is named `cur'. */
  54. /* */
  55. /* This version is non-reentrant, of course. */
  56. /* */
  57. /* b. indirect implementation */
  58. /* */
  59. /* The current execution context is passed to _each_ function as its */
  60. /* first argument, and each field is thus accessed indirectly. */
  61. /* */
  62. /* This version is fully re-entrant. */
  63. /* */
  64. /* The idea is that an indirect implementation may be slower to execute */
  65. /* on low-end processors that are used in some systems (like 386s or */
  66. /* even 486s). */
  67. /* */
  68. /* As a consequence, the indirect implementation is now the default, as */
  69. /* its performance costs can be considered negligible in our context. */
  70. /* Note, however, that we kept the same source with macros because: */
  71. /* */
  72. /* - The code is kept very close in design to the Pascal code used for */
  73. /* development. */
  74. /* */
  75. /* - It's much more readable that way! */
  76. /* */
  77. /* - It's still open to experimentation and tuning. */
  78. /* */
  79. /*************************************************************************/
  80. #ifndef TT_CONFIG_OPTION_STATIC_INTERPRETER /* indirect implementation */
  81. #define CUR (*exc) /* see ttobjs.h */
  82. #else /* static implementation */
  83. #define CUR cur
  84. static
  85. TT_ExecContextRec cur; /* static exec. context variable */
  86. /* apparently, we have a _lot_ of direct indexing when accessing */
  87. /* the static `cur', which makes the code bigger (due to all the */
  88. /* four bytes addresses). */
  89. #endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */
  90. /*************************************************************************/
  91. /* */
  92. /* The instruction argument stack. */
  93. /* */
  94. #define INS_ARG EXEC_OP_ FT_Long* args /* see ttobjs.h for EXEC_OP_ */
  95. /*************************************************************************/
  96. /* */
  97. /* This macro is used whenever `exec' is unused in a function, to avoid */
  98. /* stupid warnings from pedantic compilers. */
  99. /* */
  100. #define FT_UNUSED_EXEC FT_UNUSED( CUR )
  101. /*************************************************************************/
  102. /* */
  103. /* This macro is used whenever `args' is unused in a function, to avoid */
  104. /* stupid warnings from pedantic compilers. */
  105. /* */
  106. #define FT_UNUSED_ARG FT_UNUSED_EXEC; FT_UNUSED( args )
  107. /*************************************************************************/
  108. /* */
  109. /* The following macros hide the use of EXEC_ARG and EXEC_ARG_ to */
  110. /* increase readabilty of the code. */
  111. /* */
  112. /*************************************************************************/
  113. #define SKIP_Code() \
  114. SkipCode( EXEC_ARG )
  115. #define GET_ShortIns() \
  116. GetShortIns( EXEC_ARG )
  117. #define NORMalize( x, y, v ) \
  118. Normalize( EXEC_ARG_ x, y, v )
  119. #define SET_SuperRound( scale, flags ) \
  120. SetSuperRound( EXEC_ARG_ scale, flags )
  121. #define ROUND_None( d, c ) \
  122. Round_None( EXEC_ARG_ d, c )
  123. #define INS_Goto_CodeRange( range, ip ) \
  124. Ins_Goto_CodeRange( EXEC_ARG_ range, ip )
  125. #define CUR_Func_project( x, y ) \
  126. CUR.func_project( EXEC_ARG_ x, y )
  127. #define CUR_Func_move( z, p, d ) \
  128. CUR.func_move( EXEC_ARG_ z, p, d )
  129. #define CUR_Func_dualproj( x, y ) \
  130. CUR.func_dualproj( EXEC_ARG_ x, y )
  131. #define CUR_Func_freeProj( x, y ) \
  132. CUR.func_freeProj( EXEC_ARG_ x, y )
  133. #define CUR_Func_round( d, c ) \
  134. CUR.func_round( EXEC_ARG_ d, c )
  135. #define CUR_Func_read_cvt( index ) \
  136. CUR.func_read_cvt( EXEC_ARG_ index )
  137. #define CUR_Func_write_cvt( index, val ) \
  138. CUR.func_write_cvt( EXEC_ARG_ index, val )
  139. #define CUR_Func_move_cvt( index, val ) \
  140. CUR.func_move_cvt( EXEC_ARG_ index, val )
  141. #define CURRENT_Ratio() \
  142. Current_Ratio( EXEC_ARG )
  143. #define CURRENT_Ppem() \
  144. Current_Ppem( EXEC_ARG )
  145. #define CUR_Ppem() \
  146. Cur_PPEM( EXEC_ARG )
  147. #define INS_SxVTL( a, b, c, d ) \
  148. Ins_SxVTL( EXEC_ARG_ a, b, c, d )
  149. #define COMPUTE_Funcs() \
  150. Compute_Funcs( EXEC_ARG )
  151. #define COMPUTE_Round( a ) \
  152. Compute_Round( EXEC_ARG_ a )
  153. #define COMPUTE_Point_Displacement( a, b, c, d ) \
  154. Compute_Point_Displacement( EXEC_ARG_ a, b, c, d )
  155. #define MOVE_Zp2_Point( a, b, c, t ) \
  156. Move_Zp2_Point( EXEC_ARG_ a, b, c, t )
  157. /*************************************************************************/
  158. /* */
  159. /* Instruction dispatch function, as used by the interpreter. */
  160. /* */
  161. typedef void (*TInstruction_Function)( INS_ARG );
  162. /*************************************************************************/
  163. /* */
  164. /* A simple bounds-checking macro. */
  165. /* */
  166. #define BOUNDS( x, n ) ( (FT_UInt)(x) >= (FT_UInt)(n) )
  167. #undef SUCCESS
  168. #define SUCCESS 0
  169. #undef FAILURE
  170. #define FAILURE 1
  171. /*************************************************************************/
  172. /* */
  173. /* CODERANGE FUNCTIONS */
  174. /* */
  175. /*************************************************************************/
  176. /*************************************************************************/
  177. /* */
  178. /* <Function> */
  179. /* TT_Goto_CodeRange */
  180. /* */
  181. /* <Description> */
  182. /* Switches to a new code range (updates the code related elements in */
  183. /* `exec', and `IP'). */
  184. /* */
  185. /* <Input> */
  186. /* range :: The new execution code range. */
  187. /* */
  188. /* IP :: The new IP in the new code range. */
  189. /* */
  190. /* <InOut> */
  191. /* exec :: The target execution context. */
  192. /* */
  193. /* <Return> */
  194. /* FreeType error code. 0 means success. */
  195. /* */
  196. FT_LOCAL_DEF( FT_Error )
  197. TT_Goto_CodeRange( TT_ExecContext exec,
  198. FT_Int range,
  199. FT_Long IP )
  200. {
  201. TT_CodeRange* coderange;
  202. FT_ASSERT( range >= 1 && range <= 3 );
  203. coderange = &exec->codeRangeTable[range - 1];
  204. FT_ASSERT( coderange->base != NULL );
  205. /* NOTE: Because the last instruction of a program may be a CALL */
  206. /* which will return to the first byte *after* the code */
  207. /* range, we test for IP <= Size instead of IP < Size. */
  208. /* */
  209. FT_ASSERT( (FT_ULong)IP <= coderange->size );
  210. exec->code = coderange->base;
  211. exec->codeSize = coderange->size;
  212. exec->IP = IP;
  213. exec->curRange = range;
  214. return TT_Err_Ok;
  215. }
  216. /*************************************************************************/
  217. /* */
  218. /* <Function> */
  219. /* TT_Set_CodeRange */
  220. /* */
  221. /* <Description> */
  222. /* Sets a code range. */
  223. /* */
  224. /* <Input> */
  225. /* range :: The code range index. */
  226. /* */
  227. /* base :: The new code base. */
  228. /* */
  229. /* length :: The range size in bytes. */
  230. /* */
  231. /* <InOut> */
  232. /* exec :: The target execution context. */
  233. /* */
  234. /* <Return> */
  235. /* FreeType error code. 0 means success. */
  236. /* */
  237. FT_LOCAL_DEF( FT_Error )
  238. TT_Set_CodeRange( TT_ExecContext exec,
  239. FT_Int range,
  240. void* base,
  241. FT_Long length )
  242. {
  243. FT_ASSERT( range >= 1 && range <= 3 );
  244. exec->codeRangeTable[range - 1].base = (FT_Byte*)base;
  245. exec->codeRangeTable[range - 1].size = length;
  246. return TT_Err_Ok;
  247. }
  248. /*************************************************************************/
  249. /* */
  250. /* <Function> */
  251. /* TT_Clear_CodeRange */
  252. /* */
  253. /* <Description> */
  254. /* Clears a code range. */
  255. /* */
  256. /* <Input> */
  257. /* range :: The code range index. */
  258. /* */
  259. /* <InOut> */
  260. /* exec :: The target execution context. */
  261. /* */
  262. /* <Return> */
  263. /* FreeType error code. 0 means success. */
  264. /* */
  265. /* <Note> */
  266. /* Does not set the Error variable. */
  267. /* */
  268. FT_LOCAL_DEF( FT_Error )
  269. TT_Clear_CodeRange( TT_ExecContext exec,
  270. FT_Int range )
  271. {
  272. FT_ASSERT( range >= 1 && range <= 3 );
  273. exec->codeRangeTable[range - 1].base = NULL;
  274. exec->codeRangeTable[range - 1].size = 0;
  275. return TT_Err_Ok;
  276. }
  277. /*************************************************************************/
  278. /* */
  279. /* EXECUTION CONTEXT ROUTINES */
  280. /* */
  281. /*************************************************************************/
  282. /*************************************************************************/
  283. /* */
  284. /* <Function> */
  285. /* TT_Destroy_Context */
  286. /* */
  287. /* <Description> */
  288. /* Destroys a given context. */
  289. /* */
  290. /* <Input> */
  291. /* exec :: A handle to the target execution context. */
  292. /* */
  293. /* memory :: A handle to the parent memory object. */
  294. /* */
  295. /* <Return> */
  296. /* FreeType error code. 0 means success. */
  297. /* */
  298. /* <Note> */
  299. /* Only the glyph loader and debugger should call this function. */
  300. /* */
  301. FT_LOCAL_DEF( FT_Error )
  302. TT_Destroy_Context( TT_ExecContext exec,
  303. FT_Memory memory )
  304. {
  305. /* free composite load stack */
  306. FT_FREE( exec->loadStack );
  307. exec->loadSize = 0;
  308. /* points zone */
  309. exec->maxPoints = 0;
  310. exec->maxContours = 0;
  311. /* free stack */
  312. FT_FREE( exec->stack );
  313. exec->stackSize = 0;
  314. /* free call stack */
  315. FT_FREE( exec->callStack );
  316. exec->callSize = 0;
  317. exec->callTop = 0;
  318. /* free glyph code range */
  319. FT_FREE( exec->glyphIns );
  320. exec->glyphSize = 0;
  321. exec->size = NULL;
  322. exec->face = NULL;
  323. FT_FREE( exec );
  324. return TT_Err_Ok;
  325. }
  326. /*************************************************************************/
  327. /* */
  328. /* <Function> */
  329. /* Init_Context */
  330. /* */
  331. /* <Description> */
  332. /* Initializes a context object. */
  333. /* */
  334. /* <Input> */
  335. /* memory :: A handle to the parent memory object. */
  336. /* */
  337. /* face :: A handle to the source TrueType face object. */
  338. /* */
  339. /* <InOut> */
  340. /* exec :: A handle to the target execution context. */
  341. /* */
  342. /* <Return> */
  343. /* FreeType error code. 0 means success. */
  344. /* */
  345. static FT_Error
  346. Init_Context( TT_ExecContext exec,
  347. TT_Face face,
  348. FT_Memory memory )
  349. {
  350. FT_Error error;
  351. FT_TRACE1(( "Init_Context: new object at 0x%08p, parent = 0x%08p\n",
  352. exec, face ));
  353. exec->memory = memory;
  354. exec->callSize = 32;
  355. if ( FT_NEW_ARRAY( exec->callStack, exec->callSize ) )
  356. goto Fail_Memory;
  357. /* all values in the context are set to 0 already, but this is */
  358. /* here as a remainder */
  359. exec->maxPoints = 0;
  360. exec->maxContours = 0;
  361. exec->stackSize = 0;
  362. exec->loadSize = 0;
  363. exec->glyphSize = 0;
  364. exec->stack = NULL;
  365. exec->loadStack = NULL;
  366. exec->glyphIns = NULL;
  367. exec->face = face;
  368. exec->size = NULL;
  369. return TT_Err_Ok;
  370. Fail_Memory:
  371. FT_ERROR(( "Init_Context: not enough memory for 0x%08lx\n",
  372. (FT_Long)exec ));
  373. TT_Destroy_Context( exec, memory );
  374. return error;
  375. }
  376. /*************************************************************************/
  377. /* */
  378. /* <Function> */
  379. /* Update_Max */
  380. /* */
  381. /* <Description> */
  382. /* Checks the size of a buffer and reallocates it if necessary. */
  383. /* */
  384. /* <Input> */
  385. /* memory :: A handle to the parent memory object. */
  386. /* */
  387. /* multiplier :: The size in bytes of each element in the buffer. */
  388. /* */
  389. /* new_max :: The new capacity (size) of the buffer. */
  390. /* */
  391. /* <InOut> */
  392. /* size :: The address of the buffer's current size expressed */
  393. /* in elements. */
  394. /* */
  395. /* buff :: The address of the buffer base pointer. */
  396. /* */
  397. /* <Return> */
  398. /* FreeType error code. 0 means success. */
  399. /* */
  400. static FT_Error
  401. Update_Max( FT_Memory memory,
  402. FT_ULong* size,
  403. FT_Long multiplier,
  404. void** buff,
  405. FT_ULong new_max )
  406. {
  407. FT_Error error;
  408. if ( *size < new_max )
  409. {
  410. FT_FREE( *buff );
  411. if ( FT_ALLOC( *buff, new_max * multiplier ) )
  412. return error;
  413. *size = new_max;
  414. }
  415. return TT_Err_Ok;
  416. }
  417. /*************************************************************************/
  418. /* */
  419. /* <Function> */
  420. /* TT_Load_Context */
  421. /* */
  422. /* <Description> */
  423. /* Prepare an execution context for glyph hinting. */
  424. /* */
  425. /* <Input> */
  426. /* face :: A handle to the source face object. */
  427. /* */
  428. /* size :: A handle to the source size object. */
  429. /* */
  430. /* <InOut> */
  431. /* exec :: A handle to the target execution context. */
  432. /* */
  433. /* <Return> */
  434. /* FreeType error code. 0 means success. */
  435. /* */
  436. /* <Note> */
  437. /* Only the glyph loader and debugger should call this function. */
  438. /* */
  439. FT_LOCAL_DEF( FT_Error )
  440. TT_Load_Context( TT_ExecContext exec,
  441. TT_Face face,
  442. TT_Size size )
  443. {
  444. FT_Int i;
  445. FT_ULong tmp;
  446. TT_MaxProfile* maxp;
  447. FT_Error error;
  448. exec->face = face;
  449. maxp = &face->max_profile;
  450. exec->size = size;
  451. if ( size )
  452. {
  453. exec->numFDefs = size->num_function_defs;
  454. exec->maxFDefs = size->max_function_defs;
  455. exec->numIDefs = size->num_instruction_defs;
  456. exec->maxIDefs = size->max_instruction_defs;
  457. exec->FDefs = size->function_defs;
  458. exec->IDefs = size->instruction_defs;
  459. exec->tt_metrics = size->ttmetrics;
  460. exec->metrics = size->root.metrics;
  461. exec->maxFunc = size->max_func;
  462. exec->maxIns = size->max_ins;
  463. for ( i = 0; i < TT_MAX_CODE_RANGES; i++ )
  464. exec->codeRangeTable[i] = size->codeRangeTable[i];
  465. /* set graphics state */
  466. exec->GS = size->GS;
  467. exec->cvtSize = size->cvt_size;
  468. exec->cvt = size->cvt;
  469. exec->storeSize = size->storage_size;
  470. exec->storage = size->storage;
  471. exec->twilight = size->twilight;
  472. }
  473. error = Update_Max( exec->memory,
  474. &exec->loadSize,
  475. sizeof ( TT_SubGlyphRec ),
  476. (void**)&exec->loadStack,
  477. exec->face->max_components + 1 );
  478. if ( error )
  479. return error;
  480. /* XXX: We reserve a little more elements on the stack to deal safely */
  481. /* with broken fonts like arialbs, courbs, timesbs, etc. */
  482. tmp = exec->stackSize;
  483. error = Update_Max( exec->memory,
  484. &tmp,
  485. sizeof ( FT_F26Dot6 ),
  486. (void**)&exec->stack,
  487. maxp->maxStackElements + 32 );
  488. exec->stackSize = (FT_UInt)tmp;
  489. if ( error )
  490. return error;
  491. tmp = exec->glyphSize;
  492. error = Update_Max( exec->memory,
  493. &tmp,
  494. sizeof ( FT_Byte ),
  495. (void**)&exec->glyphIns,
  496. maxp->maxSizeOfInstructions );
  497. exec->glyphSize = (FT_UShort)tmp;
  498. if ( error )
  499. return error;
  500. exec->pts.n_points = 0;
  501. exec->pts.n_contours = 0;
  502. exec->instruction_trap = FALSE;
  503. return TT_Err_Ok;
  504. }
  505. /*************************************************************************/
  506. /* */
  507. /* <Function> */
  508. /* TT_Save_Context */
  509. /* */
  510. /* <Description> */
  511. /* Saves the code ranges in a `size' object. */
  512. /* */
  513. /* <Input> */
  514. /* exec :: A handle to the source execution context. */
  515. /* */
  516. /* <InOut> */
  517. /* size :: A handle to the target size object. */
  518. /* */
  519. /* <Return> */
  520. /* FreeType error code. 0 means success. */
  521. /* */
  522. /* <Note> */
  523. /* Only the glyph loader and debugger should call this function. */
  524. /* */
  525. FT_LOCAL_DEF( FT_Error )
  526. TT_Save_Context( TT_ExecContext exec,
  527. TT_Size size )
  528. {
  529. FT_Int i;
  530. /* XXXX: Will probably disappear soon with all the code range */
  531. /* management, which is now rather obsolete. */
  532. /* */
  533. size->num_function_defs = exec->numFDefs;
  534. size->num_instruction_defs = exec->numIDefs;
  535. size->max_func = exec->maxFunc;
  536. size->max_ins = exec->maxIns;
  537. for ( i = 0; i < TT_MAX_CODE_RANGES; i++ )
  538. size->codeRangeTable[i] = exec->codeRangeTable[i];
  539. return TT_Err_Ok;
  540. }
  541. /*************************************************************************/
  542. /* */
  543. /* <Function> */
  544. /* TT_Run_Context */
  545. /* */
  546. /* <Description> */
  547. /* Executes one or more instructions in the execution context. */
  548. /* */
  549. /* <Input> */
  550. /* debug :: A Boolean flag. If set, the function sets some internal */
  551. /* variables and returns immediately, otherwise TT_RunIns() */
  552. /* is called. */
  553. /* */
  554. /* This is commented out currently. */
  555. /* */
  556. /* <Input> */
  557. /* exec :: A handle to the target execution context. */
  558. /* */
  559. /* <Return> */
  560. /* TrueTyoe error code. 0 means success. */
  561. /* */
  562. /* <Note> */
  563. /* Only the glyph loader and debugger should call this function. */
  564. /* */
  565. FT_LOCAL_DEF( FT_Error )
  566. TT_Run_Context( TT_ExecContext exec,
  567. FT_Bool debug )
  568. {
  569. FT_Error error;
  570. if ( ( error = TT_Goto_CodeRange( exec, tt_coderange_glyph, 0 ) )
  571. != TT_Err_Ok )
  572. return error;
  573. exec->zp0 = exec->pts;
  574. exec->zp1 = exec->pts;
  575. exec->zp2 = exec->pts;
  576. exec->GS.gep0 = 1;
  577. exec->GS.gep1 = 1;
  578. exec->GS.gep2 = 1;
  579. exec->GS.projVector.x = 0x4000;
  580. exec->GS.projVector.y = 0x0000;
  581. exec->GS.freeVector = exec->GS.projVector;
  582. exec->GS.dualVector = exec->GS.projVector;
  583. exec->GS.round_state = 1;
  584. exec->GS.loop = 1;
  585. /* some glyphs leave something on the stack. so we clean it */
  586. /* before a new execution. */
  587. exec->top = 0;
  588. exec->callTop = 0;
  589. #if 1
  590. FT_UNUSED( debug );
  591. return exec->face->interpreter( exec );
  592. #else
  593. if ( !debug )
  594. return TT_RunIns( exec );
  595. else
  596. return TT_Err_Ok;
  597. #endif
  598. }
  599. const TT_GraphicsState tt_default_graphics_state =
  600. {
  601. 0, 0, 0,
  602. { 0x4000, 0 },
  603. { 0x4000, 0 },
  604. { 0x4000, 0 },
  605. 1, 64, 1,
  606. TRUE, 68, 0, 0, 9, 3,
  607. 0, FALSE, 2, 1, 1, 1
  608. };
  609. /* documentation is in ttinterp.h */
  610. FT_EXPORT_DEF( TT_ExecContext )
  611. TT_New_Context( TT_Face face )
  612. {
  613. TT_Driver driver;
  614. TT_ExecContext exec;
  615. FT_Memory memory;
  616. if ( !face )
  617. return 0;
  618. driver = (TT_Driver)face->root.driver;
  619. memory = driver->root.root.memory;
  620. exec = driver->context;
  621. if ( !driver->context )
  622. {
  623. FT_Error error;
  624. /* allocate object */
  625. if ( FT_NEW( exec ) )
  626. goto Exit;
  627. /* initialize it */
  628. error = Init_Context( exec, face, memory );
  629. if ( error )
  630. goto Fail;
  631. /* store it into the driver */
  632. driver->context = exec;
  633. }
  634. Exit:
  635. return driver->context;
  636. Fail:
  637. FT_FREE( exec );
  638. return 0;
  639. }
  640. /*************************************************************************/
  641. /* */
  642. /* <Function> */
  643. /* TT_Done_Context */
  644. /* */
  645. /* <Description> */
  646. /* Discards an execution context. */
  647. /* */
  648. /* <Input> */
  649. /* exec :: A handle to the target execution context. */
  650. /* */
  651. /* <Return> */
  652. /* FreeType error code. 0 means success. */
  653. /* */
  654. /* <Note> */
  655. /* Only the glyph loader and debugger should call this function. */
  656. /* */
  657. FT_LOCAL_DEF( FT_Error )
  658. TT_Done_Context( TT_ExecContext exec )
  659. {
  660. /* Nothing at all for now */
  661. FT_UNUSED( exec );
  662. return TT_Err_Ok;
  663. }
  664. /*************************************************************************/
  665. /* */
  666. /* Before an opcode is executed, the interpreter verifies that there are */
  667. /* enough arguments on the stack, with the help of the Pop_Push_Count */
  668. /* table. */
  669. /* */
  670. /* For each opcode, the first column gives the number of arguments that */
  671. /* are popped from the stack; the second one gives the number of those */
  672. /* that are pushed in result. */
  673. /* */
  674. /* Note that for opcodes with a varying number of parameters, either 0 */
  675. /* or 1 arg is verified before execution, depending on the nature of the */
  676. /* instruction: */
  677. /* */
  678. /* - if the number of arguments is given by the bytecode stream or the */
  679. /* loop variable, 0 is chosen. */
  680. /* */
  681. /* - if the first argument is a count n that is followed by arguments */
  682. /* a1 .. an, then 1 is chosen. */
  683. /* */
  684. /*************************************************************************/
  685. #undef PACK
  686. #define PACK( x, y ) ( ( x << 4 ) | y )
  687. static
  688. const FT_Byte Pop_Push_Count[256] =
  689. {
  690. /* opcodes are gathered in groups of 16 */
  691. /* please keep the spaces as they are */
  692. /* SVTCA y */ PACK( 0, 0 ),
  693. /* SVTCA x */ PACK( 0, 0 ),
  694. /* SPvTCA y */ PACK( 0, 0 ),
  695. /* SPvTCA x */ PACK( 0, 0 ),
  696. /* SFvTCA y */ PACK( 0, 0 ),
  697. /* SFvTCA x */ PACK( 0, 0 ),
  698. /* SPvTL // */ PACK( 2, 0 ),
  699. /* SPvTL + */ PACK( 2, 0 ),
  700. /* SFvTL // */ PACK( 2, 0 ),
  701. /* SFvTL + */ PACK( 2, 0 ),
  702. /* SPvFS */ PACK( 2, 0 ),
  703. /* SFvFS */ PACK( 2, 0 ),
  704. /* GPV */ PACK( 0, 2 ),
  705. /* GFV */ PACK( 0, 2 ),
  706. /* SFvTPv */ PACK( 0, 0 ),
  707. /* ISECT */ PACK( 5, 0 ),
  708. /* SRP0 */ PACK( 1, 0 ),
  709. /* SRP1 */ PACK( 1, 0 ),
  710. /* SRP2 */ PACK( 1, 0 ),
  711. /* SZP0 */ PACK( 1, 0 ),
  712. /* SZP1 */ PACK( 1, 0 ),
  713. /* SZP2 */ PACK( 1, 0 ),
  714. /* SZPS */ PACK( 1, 0 ),
  715. /* SLOOP */ PACK( 1, 0 ),
  716. /* RTG */ PACK( 0, 0 ),
  717. /* RTHG */ PACK( 0, 0 ),
  718. /* SMD */ PACK( 1, 0 ),
  719. /* ELSE */ PACK( 0, 0 ),
  720. /* JMPR */ PACK( 1, 0 ),
  721. /* SCvTCi */ PACK( 1, 0 ),
  722. /* SSwCi */ PACK( 1, 0 ),
  723. /* SSW */ PACK( 1, 0 ),
  724. /* DUP */ PACK( 1, 2 ),
  725. /* POP */ PACK( 1, 0 ),
  726. /* CLEAR */ PACK( 0, 0 ),
  727. /* SWAP */ PACK( 2, 2 ),
  728. /* DEPTH */ PACK( 0, 1 ),
  729. /* CINDEX */ PACK( 1, 1 ),
  730. /* MINDEX */ PACK( 1, 0 ),
  731. /* AlignPTS */ PACK( 2, 0 ),
  732. /* INS_$28 */ PACK( 0, 0 ),
  733. /* UTP */ PACK( 1, 0 ),
  734. /* LOOPCALL */ PACK( 2, 0 ),
  735. /* CALL */ PACK( 1, 0 ),
  736. /* FDEF */ PACK( 1, 0 ),
  737. /* ENDF */ PACK( 0, 0 ),
  738. /* MDAP[0] */ PACK( 1, 0 ),
  739. /* MDAP[1] */ PACK( 1, 0 ),
  740. /* IUP[0] */ PACK( 0, 0 ),
  741. /* IUP[1] */ PACK( 0, 0 ),
  742. /* SHP[0] */ PACK( 0, 0 ),
  743. /* SHP[1] */ PACK( 0, 0 ),
  744. /* SHC[0] */ PACK( 1, 0 ),
  745. /* SHC[1] */ PACK( 1, 0 ),
  746. /* SHZ[0] */ PACK( 1, 0 ),
  747. /* SHZ[1] */ PACK( 1, 0 ),
  748. /* SHPIX */ PACK( 1, 0 ),
  749. /* IP */ PACK( 0, 0 ),
  750. /* MSIRP[0] */ PACK( 2, 0 ),
  751. /* MSIRP[1] */ PACK( 2, 0 ),
  752. /* AlignRP */ PACK( 0, 0 ),
  753. /* RTDG */ PACK( 0, 0 ),
  754. /* MIAP[0] */ PACK( 2, 0 ),
  755. /* MIAP[1] */ PACK( 2, 0 ),
  756. /* NPushB */ PACK( 0, 0 ),
  757. /* NPushW */ PACK( 0, 0 ),
  758. /* WS */ PACK( 2, 0 ),
  759. /* RS */ PACK( 1, 1 ),
  760. /* WCvtP */ PACK( 2, 0 ),
  761. /* RCvt */ PACK( 1, 1 ),
  762. /* GC[0] */ PACK( 1, 1 ),
  763. /* GC[1] */ PACK( 1, 1 ),
  764. /* SCFS */ PACK( 2, 0 ),
  765. /* MD[0] */ PACK( 2, 1 ),
  766. /* MD[1] */ PACK( 2, 1 ),
  767. /* MPPEM */ PACK( 0, 1 ),
  768. /* MPS */ PACK( 0, 1 ),
  769. /* FlipON */ PACK( 0, 0 ),
  770. /* FlipOFF */ PACK( 0, 0 ),
  771. /* DEBUG */ PACK( 1, 0 ),
  772. /* LT */ PACK( 2, 1 ),
  773. /* LTEQ */ PACK( 2, 1 ),
  774. /* GT */ PACK( 2, 1 ),
  775. /* GTEQ */ PACK( 2, 1 ),
  776. /* EQ */ PACK( 2, 1 ),
  777. /* NEQ */ PACK( 2, 1 ),
  778. /* ODD */ PACK( 1, 1 ),
  779. /* EVEN */ PACK( 1, 1 ),
  780. /* IF */ PACK( 1, 0 ),
  781. /* EIF */ PACK( 0, 0 ),
  782. /* AND */ PACK( 2, 1 ),
  783. /* OR */ PACK( 2, 1 ),
  784. /* NOT */ PACK( 1, 1 ),
  785. /* DeltaP1 */ PACK( 1, 0 ),
  786. /* SDB */ PACK( 1, 0 ),
  787. /* SDS */ PACK( 1, 0 ),
  788. /* ADD */ PACK( 2, 1 ),
  789. /* SUB */ PACK( 2, 1 ),
  790. /* DIV */ PACK( 2, 1 ),
  791. /* MUL */ PACK( 2, 1 ),
  792. /* ABS */ PACK( 1, 1 ),
  793. /* NEG */ PACK( 1, 1 ),
  794. /* FLOOR */ PACK( 1, 1 ),
  795. /* CEILING */ PACK( 1, 1 ),
  796. /* ROUND[0] */ PACK( 1, 1 ),
  797. /* ROUND[1] */ PACK( 1, 1 ),
  798. /* ROUND[2] */ PACK( 1, 1 ),
  799. /* ROUND[3] */ PACK( 1, 1 ),
  800. /* NROUND[0] */ PACK( 1, 1 ),
  801. /* NROUND[1] */ PACK( 1, 1 ),
  802. /* NROUND[2] */ PACK( 1, 1 ),
  803. /* NROUND[3] */ PACK( 1, 1 ),
  804. /* WCvtF */ PACK( 2, 0 ),
  805. /* DeltaP2 */ PACK( 1, 0 ),
  806. /* DeltaP3 */ PACK( 1, 0 ),
  807. /* DeltaCn[0] */ PACK( 1, 0 ),
  808. /* DeltaCn[1] */ PACK( 1, 0 ),
  809. /* DeltaCn[2] */ PACK( 1, 0 ),
  810. /* SROUND */ PACK( 1, 0 ),
  811. /* S45Round */ PACK( 1, 0 ),
  812. /* JROT */ PACK( 2, 0 ),
  813. /* JROF */ PACK( 2, 0 ),
  814. /* ROFF */ PACK( 0, 0 ),
  815. /* INS_$7B */ PACK( 0, 0 ),
  816. /* RUTG */ PACK( 0, 0 ),
  817. /* RDTG */ PACK( 0, 0 ),
  818. /* SANGW */ PACK( 1, 0 ),
  819. /* AA */ PACK( 1, 0 ),
  820. /* FlipPT */ PACK( 0, 0 ),
  821. /* FlipRgON */ PACK( 2, 0 ),
  822. /* FlipRgOFF */ PACK( 2, 0 ),
  823. /* INS_$83 */ PACK( 0, 0 ),
  824. /* INS_$84 */ PACK( 0, 0 ),
  825. /* ScanCTRL */ PACK( 1, 0 ),
  826. /* SDVPTL[0] */ PACK( 2, 0 ),
  827. /* SDVPTL[1] */ PACK( 2, 0 ),
  828. /* GetINFO */ PACK( 1, 1 ),
  829. /* IDEF */ PACK( 1, 0 ),
  830. /* ROLL */ PACK( 3, 3 ),
  831. /* MAX */ PACK( 2, 1 ),
  832. /* MIN */ PACK( 2, 1 ),
  833. /* ScanTYPE */ PACK( 1, 0 ),
  834. /* InstCTRL */ PACK( 2, 0 ),
  835. /* INS_$8F */ PACK( 0, 0 ),
  836. /* INS_$90 */ PACK( 0, 0 ),
  837. /* INS_$91 */ PACK( 0, 0 ),
  838. /* INS_$92 */ PACK( 0, 0 ),
  839. /* INS_$93 */ PACK( 0, 0 ),
  840. /* INS_$94 */ PACK( 0, 0 ),
  841. /* INS_$95 */ PACK( 0, 0 ),
  842. /* INS_$96 */ PACK( 0, 0 ),
  843. /* INS_$97 */ PACK( 0, 0 ),
  844. /* INS_$98 */ PACK( 0, 0 ),
  845. /* INS_$99 */ PACK( 0, 0 ),
  846. /* INS_$9A */ PACK( 0, 0 ),
  847. /* INS_$9B */ PACK( 0, 0 ),
  848. /* INS_$9C */ PACK( 0, 0 ),
  849. /* INS_$9D */ PACK( 0, 0 ),
  850. /* INS_$9E */ PACK( 0, 0 ),
  851. /* INS_$9F */ PACK( 0, 0 ),
  852. /* INS_$A0 */ PACK( 0, 0 ),
  853. /* INS_$A1 */ PACK( 0, 0 ),
  854. /* INS_$A2 */ PACK( 0, 0 ),
  855. /* INS_$A3 */ PACK( 0, 0 ),
  856. /* INS_$A4 */ PACK( 0, 0 ),
  857. /* INS_$A5 */ PACK( 0, 0 ),
  858. /* INS_$A6 */ PACK( 0, 0 ),
  859. /* INS_$A7 */ PACK( 0, 0 ),
  860. /* INS_$A8 */ PACK( 0, 0 ),
  861. /* INS_$A9 */ PACK( 0, 0 ),
  862. /* INS_$AA */ PACK( 0, 0 ),
  863. /* INS_$AB */ PACK( 0, 0 ),
  864. /* INS_$AC */ PACK( 0, 0 ),
  865. /* INS_$AD */ PACK( 0, 0 ),
  866. /* INS_$AE */ PACK( 0, 0 ),
  867. /* INS_$AF */ PACK( 0, 0 ),
  868. /* PushB[0] */ PACK( 0, 1 ),
  869. /* PushB[1] */ PACK( 0, 2 ),
  870. /* PushB[2] */ PACK( 0, 3 ),
  871. /* PushB[3] */ PACK( 0, 4 ),
  872. /* PushB[4] */ PACK( 0, 5 ),
  873. /* PushB[5] */ PACK( 0, 6 ),
  874. /* PushB[6] */ PACK( 0, 7 ),
  875. /* PushB[7] */ PACK( 0, 8 ),
  876. /* PushW[0] */ PACK( 0, 1 ),
  877. /* PushW[1] */ PACK( 0, 2 ),
  878. /* PushW[2] */ PACK( 0, 3 ),
  879. /* PushW[3] */ PACK( 0, 4 ),
  880. /* PushW[4] */ PACK( 0, 5 ),
  881. /* PushW[5] */ PACK( 0, 6 ),
  882. /* PushW[6] */ PACK( 0, 7 ),
  883. /* PushW[7] */ PACK( 0, 8 ),
  884. /* MDRP[00] */ PACK( 1, 0 ),
  885. /* MDRP[01] */ PACK( 1, 0 ),
  886. /* MDRP[02] */ PACK( 1, 0 ),
  887. /* MDRP[03] */ PACK( 1, 0 ),
  888. /* MDRP[04] */ PACK( 1, 0 ),
  889. /* MDRP[05] */ PACK( 1, 0 ),
  890. /* MDRP[06] */ PACK( 1, 0 ),
  891. /* MDRP[07] */ PACK( 1, 0 ),
  892. /* MDRP[08] */ PACK( 1, 0 ),
  893. /* MDRP[09] */ PACK( 1, 0 ),
  894. /* MDRP[10] */ PACK( 1, 0 ),
  895. /* MDRP[11] */ PACK( 1, 0 ),
  896. /* MDRP[12] */ PACK( 1, 0 ),
  897. /* MDRP[13] */ PACK( 1, 0 ),
  898. /* MDRP[14] */ PACK( 1, 0 ),
  899. /* MDRP[15] */ PACK( 1, 0 ),
  900. /* MDRP[16] */ PACK( 1, 0 ),
  901. /* MDRP[17] */ PACK( 1, 0 ),
  902. /* MDRP[18] */ PACK( 1, 0 ),
  903. /* MDRP[19] */ PACK( 1, 0 ),
  904. /* MDRP[20] */ PACK( 1, 0 ),
  905. /* MDRP[21] */ PACK( 1, 0 ),
  906. /* MDRP[22] */ PACK( 1, 0 ),
  907. /* MDRP[23] */ PACK( 1, 0 ),
  908. /* MDRP[24] */ PACK( 1, 0 ),
  909. /* MDRP[25] */ PACK( 1, 0 ),
  910. /* MDRP[26] */ PACK( 1, 0 ),
  911. /* MDRP[27] */ PACK( 1, 0 ),
  912. /* MDRP[28] */ PACK( 1, 0 ),
  913. /* MDRP[29] */ PACK( 1, 0 ),
  914. /* MDRP[30] */ PACK( 1, 0 ),
  915. /* MDRP[31] */ PACK( 1, 0 ),
  916. /* MIRP[00] */ PACK( 2, 0 ),
  917. /* MIRP[01] */ PACK( 2, 0 ),
  918. /* MIRP[02] */ PACK( 2, 0 ),
  919. /* MIRP[03] */ PACK( 2, 0 ),
  920. /* MIRP[04] */ PACK( 2, 0 ),
  921. /* MIRP[05] */ PACK( 2, 0 ),
  922. /* MIRP[06] */ PACK( 2, 0 ),
  923. /* MIRP[07] */ PACK( 2, 0 ),
  924. /* MIRP[08] */ PACK( 2, 0 ),
  925. /* MIRP[09] */ PACK( 2, 0 ),
  926. /* MIRP[10] */ PACK( 2, 0 ),
  927. /* MIRP[11] */ PACK( 2, 0 ),
  928. /* MIRP[12] */ PACK( 2, 0 ),
  929. /* MIRP[13] */ PACK( 2, 0 ),
  930. /* MIRP[14] */ PACK( 2, 0 ),
  931. /* MIRP[15] */ PACK( 2, 0 ),
  932. /* MIRP[16] */ PACK( 2, 0 ),
  933. /* MIRP[17] */ PACK( 2, 0 ),
  934. /* MIRP[18] */ PACK( 2, 0 ),
  935. /* MIRP[19] */ PACK( 2, 0 ),
  936. /* MIRP[20] */ PACK( 2, 0 ),
  937. /* MIRP[21] */ PACK( 2, 0 ),
  938. /* MIRP[22] */ PACK( 2, 0 ),
  939. /* MIRP[23] */ PACK( 2, 0 ),
  940. /* MIRP[24] */ PACK( 2, 0 ),
  941. /* MIRP[25] */ PACK( 2, 0 ),
  942. /* MIRP[26] */ PACK( 2, 0 ),
  943. /* MIRP[27] */ PACK( 2, 0 ),
  944. /* MIRP[28] */ PACK( 2, 0 ),
  945. /* MIRP[29] */ PACK( 2, 0 ),
  946. /* MIRP[30] */ PACK( 2, 0 ),
  947. /* MIRP[31] */ PACK( 2, 0 )
  948. };
  949. static
  950. const FT_Char opcode_length[256] =
  951. {
  952. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  953. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  954. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  955. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  956. -1,-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  957. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  958. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  959. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  960. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  961. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  962. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  963. 2, 3, 4, 5, 6, 7, 8, 9, 3, 5, 7, 9, 11,13,15,17,
  964. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  965. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  966. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  967. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  968. };
  969. static
  970. const FT_Vector Null_Vector = {0,0};
  971. #undef PACK
  972. #undef NULL_Vector
  973. #define NULL_Vector (FT_Vector*)&Null_Vector
  974. /* compute (a*b)/2^14 with maximal accuracy and rounding */
  975. static FT_Int32
  976. TT_MulFix14( FT_Int32 a,
  977. FT_Int b )
  978. {
  979. FT_Int32 m, s, hi;
  980. FT_UInt32 l, lo;
  981. /* compute ax*bx as 64-bit value */
  982. l = (FT_UInt32)( ( a & 0xFFFFU ) * b );
  983. m = ( a >> 16 ) * b;
  984. lo = l + (FT_UInt32)( m << 16 );
  985. hi = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo < l );
  986. /* divide the result by 2^14 with rounding */
  987. s = hi >> 31;
  988. l = lo + (FT_UInt32)s;
  989. hi += s + ( l < lo );
  990. lo = l;
  991. l = lo + 0x2000U;
  992. hi += (l < lo);
  993. return ( hi << 18 ) | ( l >> 14 );
  994. }
  995. /* compute (ax*bx+ay*by)/2^14 with maximal accuracy and rounding */
  996. static FT_Int32
  997. TT_DotFix14( FT_Int32 ax,
  998. FT_Int32 ay,
  999. FT_Int bx,
  1000. FT_Int by )
  1001. {
  1002. FT_Int32 m, s, hi1, hi2, hi;
  1003. FT_UInt32 l, lo1, lo2, lo;
  1004. /* compute ax*bx as 64-bit value */
  1005. l = (FT_UInt32)( ( ax & 0xFFFFU ) * bx );
  1006. m = ( ax >> 16 ) * bx;
  1007. lo1 = l + (FT_UInt32)( m << 16 );
  1008. hi1 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo1 < l );
  1009. /* compute ay*by as 64-bit value */
  1010. l = (FT_UInt32)( ( ay & 0xFFFFU ) * by );
  1011. m = ( ay >> 16 ) * by;
  1012. lo2 = l + (FT_UInt32)( m << 16 );
  1013. hi2 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo2 < l );
  1014. /* add them */
  1015. lo = lo1 + lo2;
  1016. hi = hi1 + hi2 + ( lo < lo1 );
  1017. /* divide the result by 2^14 with rounding */
  1018. s = hi >> 31;
  1019. l = lo + (FT_UInt32)s;
  1020. hi += s + ( l < lo );
  1021. lo = l;
  1022. l = lo + 0x2000U;
  1023. hi += ( l < lo );
  1024. return ( hi << 18 ) | ( l >> 14 );
  1025. }
  1026. /* return length of given vector */
  1027. #if 0
  1028. static FT_Int32
  1029. TT_VecLen( FT_Int32 x,
  1030. FT_Int32 y )
  1031. {
  1032. FT_Int32 m, hi1, hi2, hi;
  1033. FT_UInt32 l, lo1, lo2, lo;
  1034. /* compute x*x as 64-bit value */
  1035. lo = (FT_UInt32)( x & 0xFFFFU );
  1036. hi = x >> 16;
  1037. l = lo * lo;
  1038. m = hi * lo;
  1039. hi = hi * hi;
  1040. lo1 = l + (FT_UInt32)( m << 17 );
  1041. hi1 = hi + ( m >> 15 ) + ( lo1 < l );
  1042. /* compute y*y as 64-bit value */
  1043. lo = (FT_UInt32)( y & 0xFFFFU );
  1044. hi = y >> 16;
  1045. l = lo * lo;
  1046. m = hi * lo;
  1047. hi = hi * hi;
  1048. lo2 = l + (FT_UInt32)( m << 17 );
  1049. hi2 = hi + ( m >> 15 ) + ( lo2 < l );
  1050. /* add them to get 'x*x+y*y' as 64-bit value */
  1051. lo = lo1 + lo2;
  1052. hi = hi1 + hi2 + ( lo < lo1 );
  1053. /* compute the square root of this value */
  1054. {
  1055. FT_UInt32 root, rem, test_div;
  1056. FT_Int count;
  1057. root = 0;
  1058. {
  1059. rem = 0;
  1060. count = 32;
  1061. do
  1062. {
  1063. rem = ( rem << 2 ) | ( (FT_UInt32)hi >> 30 );
  1064. hi = ( hi << 2 ) | ( lo >> 30 );
  1065. lo <<= 2;
  1066. root <<= 1;
  1067. test_div = ( root << 1 ) + 1;
  1068. if ( rem >= test_div )
  1069. {
  1070. rem -= test_div;
  1071. root += 1;
  1072. }
  1073. } while ( --count );
  1074. }
  1075. return (FT_Int32)root;
  1076. }
  1077. }
  1078. #else
  1079. /* this version uses FT_Vector_Length which computes the same value */
  1080. /* much, much faster.. */
  1081. /* */
  1082. static FT_F26Dot6
  1083. TT_VecLen( FT_F26Dot6 X,
  1084. FT_F26Dot6 Y )
  1085. {
  1086. FT_Vector v;
  1087. v.x = X;
  1088. v.y = Y;
  1089. return FT_Vector_Length( &v );
  1090. }
  1091. #endif
  1092. /*************************************************************************/
  1093. /* */
  1094. /* <Function> */
  1095. /* Current_Ratio */
  1096. /* */
  1097. /* <Description> */
  1098. /* Returns the current aspect ratio scaling factor depending on the */
  1099. /* projection vector's state and device resolutions. */
  1100. /* */
  1101. /* <Return> */
  1102. /* The aspect ratio in 16.16 format, always <= 1.0 . */
  1103. /* */
  1104. static FT_Long
  1105. Current_Ratio( EXEC_OP )
  1106. {
  1107. if ( CUR.tt_metrics.ratio )
  1108. return CUR.tt_metrics.ratio;
  1109. if ( CUR.GS.projVector.y == 0 )
  1110. CUR.tt_metrics.ratio = CUR.tt_metrics.x_ratio;
  1111. else if ( CUR.GS.projVector.x == 0 )
  1112. CUR.tt_metrics.ratio = CUR.tt_metrics.y_ratio;
  1113. else
  1114. {
  1115. FT_Long x, y;
  1116. x = TT_MULDIV( CUR.GS.projVector.x, CUR.tt_metrics.x_ratio, 0x4000 );
  1117. y = TT_MULDIV( CUR.GS.projVector.y, CUR.tt_metrics.y_ratio, 0x4000 );
  1118. CUR.tt_metrics.ratio = TT_VecLen( x, y );
  1119. }
  1120. return CUR.tt_metrics.ratio;
  1121. }
  1122. static FT_Long
  1123. Current_Ppem( EXEC_OP )
  1124. {
  1125. return TT_MULFIX( CUR.tt_metrics.ppem, CURRENT_Ratio() );
  1126. }
  1127. /*************************************************************************/
  1128. /* */
  1129. /* Functions related to the control value table (CVT). */
  1130. /* */
  1131. /*************************************************************************/
  1132. FT_CALLBACK_DEF( FT_F26Dot6 )
  1133. Read_CVT( EXEC_OP_ FT_ULong idx )
  1134. {
  1135. return CUR.cvt[idx];
  1136. }
  1137. FT_CALLBACK_DEF( FT_F26Dot6 )
  1138. Read_CVT_Stretched( EXEC_OP_ FT_ULong idx )
  1139. {
  1140. return TT_MULFIX( CUR.cvt[idx], CURRENT_Ratio() );
  1141. }
  1142. FT_CALLBACK_DEF( void )
  1143. Write_CVT( EXEC_OP_ FT_ULong idx,
  1144. FT_F26Dot6 value )
  1145. {
  1146. CUR.cvt[idx] = value;
  1147. }
  1148. FT_CALLBACK_DEF( void )
  1149. Write_CVT_Stretched( EXEC_OP_ FT_ULong idx,
  1150. FT_F26Dot6 value )
  1151. {
  1152. CUR.cvt[idx] = FT_DivFix( value, CURRENT_Ratio() );
  1153. }
  1154. FT_CALLBACK_DEF( void )
  1155. Move_CVT( EXEC_OP_ FT_ULong idx,
  1156. FT_F26Dot6 value )
  1157. {
  1158. CUR.cvt[idx] += value;
  1159. }
  1160. FT_CALLBACK_DEF( void )
  1161. Move_CVT_Stretched( EXEC_OP_ FT_ULong idx,
  1162. FT_F26Dot6 value )
  1163. {
  1164. CUR.cvt[idx] += FT_DivFix( value, CURRENT_Ratio() );
  1165. }
  1166. /*************************************************************************/
  1167. /* */
  1168. /* <Function> */
  1169. /* GetShortIns */
  1170. /* */
  1171. /* <Description> */
  1172. /* Returns a short integer taken from the instruction stream at */
  1173. /* address IP. */
  1174. /* */
  1175. /* <Return> */
  1176. /* Short read at code[IP]. */
  1177. /* */
  1178. /* <Note> */
  1179. /* This one could become a macro. */
  1180. /* */
  1181. static FT_Short
  1182. GetShortIns( EXEC_OP )
  1183. {
  1184. /* Reading a byte stream so there is no endianess (DaveP) */
  1185. CUR.IP += 2;
  1186. return (FT_Short)( ( CUR.code[CUR.IP - 2] << 8 ) +
  1187. CUR.code[CUR.IP - 1] );
  1188. }
  1189. /*************************************************************************/
  1190. /* */
  1191. /* <Function> */
  1192. /* Ins_Goto_CodeRange */
  1193. /* */
  1194. /* <Description> */
  1195. /* Goes to a certain code range in the instruction stream. */
  1196. /* */
  1197. /* <Input> */
  1198. /* aRange :: The index of the code range. */
  1199. /* */
  1200. /* aIP :: The new IP address in the code range. */
  1201. /* */
  1202. /* <Return> */
  1203. /* SUCCESS or FAILURE. */
  1204. /* */
  1205. static FT_Bool
  1206. Ins_Goto_CodeRange( EXEC_OP_ FT_Int aRange,
  1207. FT_ULong aIP )
  1208. {
  1209. TT_CodeRange* range;
  1210. if ( aRange < 1 || aRange > 3 )
  1211. {
  1212. CUR.error = TT_Err_Bad_Argument;
  1213. return FAILURE;
  1214. }
  1215. range = &CUR.codeRangeTable[aRange - 1];
  1216. if ( range->base == NULL ) /* invalid coderange */
  1217. {
  1218. CUR.error = TT_Err_Invalid_CodeRange;
  1219. return FAILURE;
  1220. }
  1221. /* NOTE: Because the last instruction of a program may be a CALL */
  1222. /* which will return to the first byte *after* the code */
  1223. /* range, we test for AIP <= Size, instead of AIP < Size. */
  1224. if ( aIP > range->size )
  1225. {
  1226. CUR.error = TT_Err_Code_Overflow;
  1227. return FAILURE;
  1228. }
  1229. CUR.code = range->base;
  1230. CUR.codeSize = range->size;
  1231. CUR.IP = aIP;
  1232. CUR.curRange = aRange;
  1233. return SUCCESS;
  1234. }
  1235. /*************************************************************************/
  1236. /* */
  1237. /* <Function> */
  1238. /* Direct_Move */
  1239. /* */
  1240. /* <Description> */
  1241. /* Moves a point by a given distance along the freedom vector. The */
  1242. /* point will be `touched'. */
  1243. /* */
  1244. /* <Input> */
  1245. /* point :: The index of the point to move. */
  1246. /* */
  1247. /* distance :: The distance to apply. */
  1248. /* */
  1249. /* <InOut> */
  1250. /* zone :: The affected glyph zone. */
  1251. /* */
  1252. static void
  1253. Direct_Move( EXEC_OP_ TT_GlyphZone zone,
  1254. FT_UShort point,
  1255. FT_F26Dot6 distance )
  1256. {
  1257. FT_F26Dot6 v;
  1258. v = CUR.GS.freeVector.x;
  1259. if ( v != 0 )
  1260. {
  1261. #ifdef NO_APPLE_PATENT
  1262. if ( ABS( CUR.F_dot_P ) > APPLE_THRESHOLD )
  1263. zone->cur[point].x += distance;
  1264. #else
  1265. zone->cur[point].x += TT_MULDIV( distance,
  1266. v * 0x10000L,
  1267. CUR.F_dot_P );
  1268. #endif
  1269. zone->tags[point] |= FT_CURVE_TAG_TOUCH_X;
  1270. }
  1271. v = CUR.GS.freeVector.y;
  1272. if ( v != 0 )
  1273. {
  1274. #ifdef NO_APPLE_PATENT
  1275. if ( ABS( CUR.F_dot_P ) > APPLE_THRESHOLD )
  1276. zone->cur[point].y += distance;
  1277. #else
  1278. zone->cur[point].y += TT_MULDIV( distance,
  1279. v * 0x10000L,
  1280. CUR.F_dot_P );
  1281. #endif
  1282. zone->tags[point] |= FT_CURVE_TAG_TOUCH_Y;
  1283. }
  1284. }
  1285. /*************************************************************************/
  1286. /* */
  1287. /* Special versions of Direct_Move() */
  1288. /* */
  1289. /* The following versions are used whenever both vectors are both */
  1290. /* along one of the coordinate unit vectors, i.e. in 90% of the cases. */
  1291. /* */
  1292. /*************************************************************************/
  1293. static void
  1294. Direct_Move_X( EXEC_OP_ TT_GlyphZone zone,
  1295. FT_UShort point,
  1296. FT_F26Dot6 distance )
  1297. {
  1298. FT_UNUSED_EXEC;
  1299. zone->cur[point].x += distance;
  1300. zone->tags[point] |= FT_CURVE_TAG_TOUCH_X;
  1301. }
  1302. static void
  1303. Direct_Move_Y( EXEC_OP_ TT_GlyphZone zone,
  1304. FT_UShort point,
  1305. FT_F26Dot6 distance )
  1306. {
  1307. FT_UNUSED_EXEC;
  1308. zone->cur[point].y += distance;
  1309. zone->tags[point] |= FT_CURVE_TAG_TOUCH_Y;
  1310. }
  1311. /*************************************************************************/
  1312. /* */
  1313. /* <Function> */
  1314. /* Round_None */
  1315. /* */
  1316. /* <Description> */
  1317. /* Does not round, but adds engine compensation. */
  1318. /* */
  1319. /* <Input> */
  1320. /* distance :: The distance (not) to round. */
  1321. /* */
  1322. /* compensation :: The engine compensation. */
  1323. /* */
  1324. /* <Return> */
  1325. /* The compensated distance. */
  1326. /* */
  1327. /* <Note> */
  1328. /* The TrueType specification says very few about the relationship */
  1329. /* between rounding and engine compensation. However, it seems from */
  1330. /* the description of super round that we should add the compensation */
  1331. /* before rounding. */
  1332. /* */
  1333. static FT_F26Dot6
  1334. Round_None( EXEC_OP_ FT_F26Dot6 distance,
  1335. FT_F26Dot6 compensation )
  1336. {
  1337. FT_F26Dot6 val;
  1338. FT_UNUSED_EXEC;
  1339. if ( distance >= 0 )
  1340. {
  1341. val = distance + compensation;
  1342. if ( val < 0 )
  1343. val = 0;
  1344. }
  1345. else {
  1346. val = distance - compensation;
  1347. if ( val > 0 )
  1348. val = 0;
  1349. }
  1350. return val;
  1351. }
  1352. /*************************************************************************/
  1353. /* */
  1354. /* <Function> */
  1355. /* Round_To_Grid */
  1356. /* */
  1357. /* <Description> */
  1358. /* Rounds value to grid after adding engine compensation. */
  1359. /* */
  1360. /* <Input> */
  1361. /* distance :: The distance to round. */
  1362. /* */
  1363. /* compensation :: The engine compensation. */
  1364. /* */
  1365. /* <Return> */
  1366. /* Rounded distance. */
  1367. /* */
  1368. static FT_F26Dot6
  1369. Round_To_Grid( EXEC_OP_ FT_F26Dot6 distance,
  1370. FT_F26Dot6 compensation )
  1371. {
  1372. FT_F26Dot6 val;
  1373. FT_UNUSED_EXEC;
  1374. if ( distance >= 0 )
  1375. {
  1376. val = distance + compensation + 32;
  1377. if ( val > 0 )
  1378. val &= ~63;
  1379. else
  1380. val = 0;
  1381. }
  1382. else
  1383. {
  1384. val = -( ( compensation - distance + 32 ) & -64 );
  1385. if ( val > 0 )
  1386. val = 0;
  1387. }
  1388. return val;
  1389. }
  1390. /*************************************************************************/
  1391. /* */
  1392. /* <Function> */
  1393. /* Round_To_Half_Grid */
  1394. /* */
  1395. /* <Description> */
  1396. /* Rounds value to half grid after adding engine compensation. */
  1397. /* */
  1398. /* <Input> */
  1399. /* distance :: The distance to round. */
  1400. /* */
  1401. /* compensation :: The engine compensation. */
  1402. /* */
  1403. /* <Return> */
  1404. /* Rounded distance. */
  1405. /* */
  1406. static FT_F26Dot6
  1407. Round_To_Half_Grid( EXEC_OP_ FT_F26Dot6 distance,
  1408. FT_F26Dot6 compensation )
  1409. {
  1410. FT_F26Dot6 val;
  1411. FT_UNUSED_EXEC;
  1412. if ( distance >= 0 )
  1413. {
  1414. val = ( ( distance + compensation ) & -64 ) + 32;
  1415. if ( val < 0 )
  1416. val = 0;
  1417. }
  1418. else
  1419. {
  1420. val = -( ( (compensation - distance) & -64 ) + 32 );
  1421. if ( val > 0 )
  1422. val = 0;
  1423. }
  1424. return val;
  1425. }
  1426. /*************************************************************************/
  1427. /* */
  1428. /* <Function> */
  1429. /* Round_Down_To_Grid */
  1430. /* */
  1431. /* <Description> */
  1432. /* Rounds value down to grid after adding engine compensation. */
  1433. /* */
  1434. /* <Input> */
  1435. /* distance :: The distance to round. */
  1436. /* */
  1437. /* compensation :: The engine compensation. */
  1438. /* */
  1439. /* <Return> */
  1440. /* Rounded distance. */
  1441. /* */
  1442. static FT_F26Dot6
  1443. Round_Down_To_Grid( EXEC_OP_ FT_F26Dot6 distance,
  1444. FT_F26Dot6 compensation )
  1445. {
  1446. FT_F26Dot6 val;
  1447. FT_UNUSED_EXEC;
  1448. if ( distance >= 0 )
  1449. {
  1450. val = distance + compensation;
  1451. if ( val > 0 )
  1452. val &= ~63;
  1453. else
  1454. val = 0;
  1455. }
  1456. else
  1457. {
  1458. val = -( ( compensation - distance ) & -64 );
  1459. if ( val > 0 )
  1460. val = 0;
  1461. }
  1462. return val;
  1463. }
  1464. /*************************************************************************/
  1465. /* */
  1466. /* <Function> */
  1467. /* Round_Up_To_Grid */
  1468. /* */
  1469. /* <Description> */
  1470. /* Rounds value up to grid after adding engine compensation. */
  1471. /* */
  1472. /* <Input> */
  1473. /* distance :: The distance to round. */
  1474. /* */
  1475. /* compensation :: The engine compensation. */
  1476. /* */
  1477. /* <Return> */
  1478. /* Rounded distance. */
  1479. /* */
  1480. static FT_F26Dot6
  1481. Round_Up_To_Grid( EXEC_OP_ FT_F26Dot6 distance,
  1482. FT_F26Dot6 compensation )
  1483. {
  1484. FT_F26Dot6 val;
  1485. FT_UNUSED_EXEC;
  1486. if ( distance >= 0 )
  1487. {
  1488. val = distance + compensation + 63;
  1489. if ( val > 0 )
  1490. val &= ~63;
  1491. else
  1492. val = 0;
  1493. }
  1494. else
  1495. {
  1496. val = -( ( compensation - distance + 63 ) & -64 );
  1497. if ( val > 0 )
  1498. val = 0;
  1499. }
  1500. return val;
  1501. }
  1502. /*************************************************************************/
  1503. /* */
  1504. /* <Function> */
  1505. /* Round_To_Double_Grid */
  1506. /* */
  1507. /* <Description> */
  1508. /* Rounds value to double grid after adding engine compensation. */
  1509. /* */
  1510. /* <Input> */
  1511. /* distance :: The distance to round. */
  1512. /* */
  1513. /* compensation :: The engine compensation. */
  1514. /* */
  1515. /* <Return> */
  1516. /* Rounded distance. */
  1517. /* */
  1518. static FT_F26Dot6
  1519. Round_To_Double_Grid( EXEC_OP_ FT_F26Dot6 distance,
  1520. FT_F26Dot6 compensation )
  1521. {
  1522. FT_F26Dot6 val;
  1523. FT_UNUSED_EXEC;
  1524. if ( distance >= 0 )
  1525. {
  1526. val = distance + compensation + 16;
  1527. if ( val > 0 )
  1528. val &= ~31;
  1529. else
  1530. val = 0;
  1531. }
  1532. else
  1533. {
  1534. val = -( ( compensation - distance + 16 ) & -32 );
  1535. if ( val > 0 )
  1536. val = 0;
  1537. }
  1538. return val;
  1539. }
  1540. /*************************************************************************/
  1541. /* */
  1542. /* <Function> */
  1543. /* Round_Super */
  1544. /* */
  1545. /* <Description> */
  1546. /* Super-rounds value to grid after adding engine compensation. */
  1547. /* */
  1548. /* <Input> */
  1549. /* distance :: The distance to round. */
  1550. /* */
  1551. /* compensation :: The engine compensation. */
  1552. /* */
  1553. /* <Return> */
  1554. /* Rounded distance. */
  1555. /* */
  1556. /* <Note> */
  1557. /* The TrueType specification says very few about the relationship */
  1558. /* between rounding and engine compensation. However, it seems from */
  1559. /* the description of super round that we should add the compensation */
  1560. /* before rounding. */
  1561. /* */
  1562. static FT_F26Dot6
  1563. Round_Super( EXEC_OP_ FT_F26Dot6 distance,
  1564. FT_F26Dot6 compensation )
  1565. {
  1566. FT_F26Dot6 val;
  1567. if ( distance >= 0 )
  1568. {
  1569. val = ( distance - CUR.phase + CUR.threshold + compensation ) &
  1570. -CUR.period;
  1571. if ( val < 0 )
  1572. val = 0;
  1573. val += CUR.phase;
  1574. }
  1575. else
  1576. {
  1577. val = -( ( CUR.threshold - CUR.phase - distance + compensation ) &
  1578. -CUR.period );
  1579. if ( val > 0 )
  1580. val = 0;
  1581. val -= CUR.phase;
  1582. }
  1583. return val;
  1584. }
  1585. /*************************************************************************/
  1586. /* */
  1587. /* <Function> */
  1588. /* Round_Super_45 */
  1589. /* */
  1590. /* <Description> */
  1591. /* Super-rounds value to grid after adding engine compensation. */
  1592. /* */
  1593. /* <Input> */
  1594. /* distance :: The distance to round. */
  1595. /* */
  1596. /* compensation :: The engine compensation. */
  1597. /* */
  1598. /* <Return> */
  1599. /* Rounded distance. */
  1600. /* */
  1601. /* <Note> */
  1602. /* There is a separate function for Round_Super_45() as we may need */
  1603. /* greater precision. */
  1604. /* */
  1605. static FT_F26Dot6
  1606. Round_Super_45( EXEC_OP_ FT_F26Dot6 distance,
  1607. FT_F26Dot6 compensation )
  1608. {
  1609. FT_F26Dot6 val;
  1610. if ( distance >= 0 )
  1611. {
  1612. val = ( ( distance - CUR.phase + CUR.threshold + compensation ) /
  1613. CUR.period ) * CUR.period;
  1614. if ( val < 0 )
  1615. val = 0;
  1616. val += CUR.phase;
  1617. }
  1618. else
  1619. {
  1620. val = -( ( ( CUR.threshold - CUR.phase - distance + compensation ) /
  1621. CUR.period ) * CUR.period );
  1622. if ( val > 0 )
  1623. val = 0;
  1624. val -= CUR.phase;
  1625. }
  1626. return val;
  1627. }
  1628. /*************************************************************************/
  1629. /* */
  1630. /* <Function> */
  1631. /* Compute_Round */
  1632. /* */
  1633. /* <Description> */
  1634. /* Sets the rounding mode. */
  1635. /* */
  1636. /* <Input> */
  1637. /* round_mode :: The rounding mode to be used. */
  1638. /* */
  1639. static void
  1640. Compute_Round( EXEC_OP_ FT_Byte round_mode )
  1641. {
  1642. switch ( round_mode )
  1643. {
  1644. case TT_Round_Off:
  1645. CUR.func_round = (TT_Round_Func)Round_None;
  1646. break;
  1647. case TT_Round_To_Grid:
  1648. CUR.func_round = (TT_Round_Func)Round_To_Grid;
  1649. break;
  1650. case TT_Round_Up_To_Grid:
  1651. CUR.func_round = (TT_Round_Func)Round_Up_To_Grid;
  1652. break;
  1653. case TT_Round_Down_To_Grid:
  1654. CUR.func_round = (TT_Round_Func)Round_Down_To_Grid;
  1655. break;
  1656. case TT_Round_To_Half_Grid:
  1657. CUR.func_round = (TT_Round_Func)Round_To_Half_Grid;
  1658. break;
  1659. case TT_Round_To_Double_Grid:
  1660. CUR.func_round = (TT_Round_Func)Round_To_Double_Grid;
  1661. break;
  1662. case TT_Round_Super:
  1663. CUR.func_round = (TT_Round_Func)Round_Super;
  1664. break;
  1665. case TT_Round_Super_45:
  1666. CUR.func_round = (TT_Round_Func)Round_Super_45;
  1667. break;
  1668. }
  1669. }
  1670. /*************************************************************************/
  1671. /* */
  1672. /* <Function> */
  1673. /* SetSuperRound */
  1674. /* */
  1675. /* <Description> */
  1676. /* Sets Super Round parameters. */
  1677. /* */
  1678. /* <Input> */
  1679. /* GridPeriod :: Grid period */
  1680. /* selector :: SROUND opcode */
  1681. /* */
  1682. static void
  1683. SetSuperRound( EXEC_OP_ FT_F26Dot6 GridPeriod,
  1684. FT_Long selector )
  1685. {
  1686. switch ( (FT_Int)( selector & 0xC0 ) )
  1687. {
  1688. case 0:
  1689. CUR.period = GridPeriod / 2;
  1690. break;
  1691. case 0x40:
  1692. CUR.period = GridPeriod;
  1693. break;
  1694. case 0x80:
  1695. CUR.period = GridPeriod * 2;
  1696. break;
  1697. /* This opcode is reserved, but... */
  1698. case 0xC0:
  1699. CUR.period = GridPeriod;
  1700. break;
  1701. }
  1702. switch ( (FT_Int)( selector & 0x30 ) )
  1703. {
  1704. case 0:
  1705. CUR.phase = 0;
  1706. break;
  1707. case 0x10:
  1708. CUR.phase = CUR.period / 4;
  1709. break;
  1710. case 0x20:
  1711. CUR.phase = CUR.period / 2;
  1712. break;
  1713. case 0x30:
  1714. CUR.phase = GridPeriod * 3 / 4;
  1715. break;
  1716. }
  1717. if ( (selector & 0x0F) == 0 )
  1718. CUR.threshold = CUR.period - 1;
  1719. else
  1720. CUR.threshold = ( (FT_Int)( selector & 0x0F ) - 4 ) * CUR.period / 8;
  1721. CUR.period /= 256;
  1722. CUR.phase /= 256;
  1723. CUR.threshold /= 256;
  1724. }
  1725. /*************************************************************************/
  1726. /* */
  1727. /* <Function> */
  1728. /* Project */
  1729. /* */
  1730. /* <Description> */
  1731. /* Computes the projection of vector given by (v2-v1) along the */
  1732. /* current projection vector. */
  1733. /* */
  1734. /* <Input> */
  1735. /* v1 :: First input vector. */
  1736. /* v2 :: Second input vector. */
  1737. /* */
  1738. /* <Return> */
  1739. /* The distance in F26dot6 format. */
  1740. /* */
  1741. static FT_F26Dot6
  1742. Project( EXEC_OP_ FT_Vector* v1,
  1743. FT_Vector* v2 )
  1744. {
  1745. return TT_DotFix14( v1->x - v2->x,
  1746. v1->y - v2->y,
  1747. CUR.GS.projVector.x,
  1748. CUR.GS.projVector.y );
  1749. }
  1750. /*************************************************************************/
  1751. /* */
  1752. /* <Function> */
  1753. /* Dual_Project */
  1754. /* */
  1755. /* <Description> */
  1756. /* Computes the projection of the vector given by (v2-v1) along the */
  1757. /* current dual vector. */
  1758. /* */
  1759. /* <Input> */
  1760. /* v1 :: First input vector. */
  1761. /* v2 :: Second input vector. */
  1762. /* */
  1763. /* <Return> */
  1764. /* The distance in F26dot6 format. */
  1765. /* */
  1766. static FT_F26Dot6
  1767. Dual_Project( EXEC_OP_ FT_Vector* v1,
  1768. FT_Vector* v2 )
  1769. {
  1770. return TT_DotFix14( v1->x - v2->x,
  1771. v1->y - v2->y,
  1772. CUR.GS.dualVector.x,
  1773. CUR.GS.dualVector.y );
  1774. }
  1775. /*************************************************************************/
  1776. /* */
  1777. /* <Function> */
  1778. /* Free_Project */
  1779. /* */
  1780. /* <Description> */
  1781. /* Computes the projection of the vector given by (v2-v1) along the */
  1782. /* current freedom vector. */
  1783. /* */
  1784. /* <Input> */
  1785. /* v1 :: First input vector. */
  1786. /* v2 :: Second input vector. */
  1787. /* */
  1788. /* <Return> */
  1789. /* The distance in F26dot6 format. */
  1790. /* */
  1791. static FT_F26Dot6
  1792. Free_Project( EXEC_OP_ FT_Vector* v1,
  1793. FT_Vector* v2 )
  1794. {
  1795. return TT_DotFix14( v1->x - v2->x,
  1796. v1->y - v2->y,
  1797. CUR.GS.freeVector.x,
  1798. CUR.GS.freeVector.y );
  1799. }
  1800. /*************************************************************************/
  1801. /* */
  1802. /* <Function> */
  1803. /* Project_x */
  1804. /* */
  1805. /* <Description> */
  1806. /* Computes the projection of the vector given by (v2-v1) along the */
  1807. /* horizontal axis. */
  1808. /* */
  1809. /* <Input> */
  1810. /* v1 :: First input vector. */
  1811. /* v2 :: Second input vector. */
  1812. /* */
  1813. /* <Return> */
  1814. /* The distance in F26dot6 format. */
  1815. /* */
  1816. static FT_F26Dot6
  1817. Project_x( EXEC_OP_ FT_Vector* v1,
  1818. FT_Vector* v2 )
  1819. {
  1820. FT_UNUSED_EXEC;
  1821. return ( v1->x - v2->x );
  1822. }
  1823. /*************************************************************************/
  1824. /* */
  1825. /* <Function> */
  1826. /* Project_y */
  1827. /* */
  1828. /* <Description> */
  1829. /* Computes the projection of the vector given by (v2-v1) along the */
  1830. /* vertical axis. */
  1831. /* */
  1832. /* <Input> */
  1833. /* v1 :: First input vector. */
  1834. /* v2 :: Second input vector. */
  1835. /* */
  1836. /* <Return> */
  1837. /* The distance in F26dot6 format. */
  1838. /* */
  1839. static FT_F26Dot6
  1840. Project_y( EXEC_OP_ FT_Vector* v1,
  1841. FT_Vector* v2 )
  1842. {
  1843. FT_UNUSED_EXEC;
  1844. return ( v1->y - v2->y );
  1845. }
  1846. /*************************************************************************/
  1847. /* */
  1848. /* <Function> */
  1849. /* Compute_Funcs */
  1850. /* */
  1851. /* <Description> */
  1852. /* Computes the projection and movement function pointers according */
  1853. /* to the current graphics state. */
  1854. /* */
  1855. static void
  1856. Compute_Funcs( EXEC_OP )
  1857. {
  1858. if ( CUR.GS.freeVector.x == 0x4000 )
  1859. {
  1860. CUR.func_freeProj = (TT_Project_Func)Project_x;
  1861. CUR.F_dot_P = CUR.GS.projVector.x * 0x10000L;
  1862. }
  1863. else
  1864. {
  1865. if ( CUR.GS.freeVector.y == 0x4000 )
  1866. {
  1867. CUR.func_freeProj = (TT_Project_Func)Project_y;
  1868. CUR.F_dot_P = CUR.GS.projVector.y * 0x10000L;
  1869. }
  1870. else
  1871. {
  1872. CUR.func_freeProj = (TT_Project_Func)Free_Project;
  1873. CUR.F_dot_P = (FT_Long)CUR.GS.projVector.x * CUR.GS.freeVector.x * 4 +
  1874. (FT_Long)CUR.GS.projVector.y * CUR.GS.freeVector.y * 4;
  1875. }
  1876. }
  1877. if ( CUR.GS.projVector.x == 0x4000 )
  1878. CUR.func_project = (TT_Project_Func)Project_x;
  1879. else
  1880. {
  1881. if ( CUR.GS.projVector.y == 0x4000 )
  1882. CUR.func_project = (TT_Project_Func)Project_y;
  1883. else
  1884. CUR.func_project = (TT_Project_Func)Project;
  1885. }
  1886. if ( CUR.GS.dualVector.x == 0x4000 )
  1887. CUR.func_dualproj = (TT_Project_Func)Project_x;
  1888. else
  1889. {
  1890. if ( CUR.GS.dualVector.y == 0x4000 )
  1891. CUR.func_dualproj = (TT_Project_Func)Project_y;
  1892. else
  1893. CUR.func_dualproj = (TT_Project_Func)Dual_Project;
  1894. }
  1895. CUR.func_move = (TT_Move_Func)Direct_Move;
  1896. if ( CUR.F_dot_P == 0x40000000L )
  1897. {
  1898. if ( CUR.GS.freeVector.x == 0x4000 )
  1899. CUR.func_move = (TT_Move_Func)Direct_Move_X;
  1900. else
  1901. {
  1902. if ( CUR.GS.freeVector.y == 0x4000 )
  1903. CUR.func_move = (TT_Move_Func)Direct_Move_Y;
  1904. }
  1905. }
  1906. /* at small sizes, F_dot_P can become too small, resulting */
  1907. /* in overflows and `spikes' in a number of glyphs like `w'. */
  1908. if ( ABS( CUR.F_dot_P ) < 0x4000000L )
  1909. CUR.F_dot_P = 0x40000000L;
  1910. /* Disable cached aspect ratio */
  1911. CUR.tt_metrics.ratio = 0;
  1912. }
  1913. /*************************************************************************/
  1914. /* */
  1915. /* <Function> */
  1916. /* Normalize */
  1917. /* */
  1918. /* <Description> */
  1919. /* Norms a vector. */
  1920. /* */
  1921. /* <Input> */
  1922. /* Vx :: The horizontal input vector coordinate. */
  1923. /* Vy :: The vertical input vector coordinate. */
  1924. /* */
  1925. /* <Output> */
  1926. /* R :: The normed unit vector. */
  1927. /* */
  1928. /* <Return> */
  1929. /* Returns FAILURE if a vector parameter is zero. */
  1930. /* */
  1931. /* <Note> */
  1932. /* In case Vx and Vy are both zero, Normalize() returns SUCCESS, and */
  1933. /* R is undefined. */
  1934. /* */
  1935. static FT_Bool
  1936. Normalize( EXEC_OP_ FT_F26Dot6 Vx,
  1937. FT_F26Dot6 Vy,
  1938. FT_UnitVector* R )
  1939. {
  1940. FT_F26Dot6 W;
  1941. FT_Bool S1, S2;
  1942. FT_UNUSED_EXEC;
  1943. if ( ABS( Vx ) < 0x10000L && ABS( Vy ) < 0x10000L )
  1944. {
  1945. Vx *= 0x100;
  1946. Vy *= 0x100;
  1947. W = TT_VecLen( Vx, Vy );
  1948. if ( W == 0 )
  1949. {
  1950. /* XXX: UNDOCUMENTED! It seems that it is possible to try */
  1951. /* to normalize the vector (0,0). Return immediately. */
  1952. return SUCCESS;
  1953. }
  1954. R->x = (FT_F2Dot14)FT_MulDiv( Vx, 0x4000L, W );
  1955. R->y = (FT_F2Dot14)FT_MulDiv( Vy, 0x4000L, W );
  1956. return SUCCESS;
  1957. }
  1958. W = TT_VecLen( Vx, Vy );
  1959. Vx = FT_MulDiv( Vx, 0x4000L, W );
  1960. Vy = FT_MulDiv( Vy, 0x4000L, W );
  1961. W = Vx * Vx + Vy * Vy;
  1962. /* Now, we want that Sqrt( W ) = 0x4000 */
  1963. /* Or 0x1000000 <= W < 0x1004000 */
  1964. if ( Vx < 0 )
  1965. {
  1966. Vx = -Vx;
  1967. S1 = TRUE;
  1968. }
  1969. else
  1970. S1 = FALSE;
  1971. if ( Vy < 0 )
  1972. {
  1973. Vy = -Vy;
  1974. S2 = TRUE;
  1975. }
  1976. else
  1977. S2 = FALSE;
  1978. while ( W < 0x1000000L )
  1979. {
  1980. /* We need to increase W by a minimal amount */
  1981. if ( Vx < Vy )
  1982. Vx++;
  1983. else
  1984. Vy++;
  1985. W = Vx * Vx + Vy * Vy;
  1986. }
  1987. while ( W >= 0x1004000L )
  1988. {
  1989. /* We need to decrease W by a minimal amount */
  1990. if ( Vx < Vy )
  1991. Vx--;
  1992. else
  1993. Vy--;
  1994. W = Vx * Vx + Vy * Vy;
  1995. }
  1996. /* Note that in various cases, we can only */
  1997. /* compute a Sqrt(W) of 0x3FFF, eg. Vx = Vy */
  1998. if ( S1 )
  1999. Vx = -Vx;
  2000. if ( S2 )
  2001. Vy = -Vy;
  2002. R->x = (FT_F2Dot14)Vx; /* Type conversion */
  2003. R->y = (FT_F2Dot14)Vy; /* Type conversion */
  2004. return SUCCESS;
  2005. }
  2006. /*************************************************************************/
  2007. /* */
  2008. /* Here we start with the implementation of the various opcodes. */
  2009. /* */
  2010. /*************************************************************************/
  2011. static FT_Bool
  2012. Ins_SxVTL( EXEC_OP_ FT_UShort aIdx1,
  2013. FT_UShort aIdx2,
  2014. FT_Int aOpc,
  2015. FT_UnitVector* Vec )
  2016. {
  2017. FT_Long A, B, C;
  2018. FT_Vector* p1;
  2019. FT_Vector* p2;
  2020. if ( BOUNDS( aIdx1, CUR.zp2.n_points ) ||
  2021. BOUNDS( aIdx2, CUR.zp1.n_points ) )
  2022. {
  2023. if ( CUR.pedantic_hinting )
  2024. CUR.error = TT_Err_Invalid_Reference;
  2025. return FAILURE;
  2026. }
  2027. p1 = CUR.zp1.cur + aIdx2;
  2028. p2 = CUR.zp2.cur + aIdx1;
  2029. A = p1->x - p2->x;
  2030. B = p1->y - p2->y;
  2031. if ( ( aOpc & 1 ) != 0 )
  2032. {
  2033. C = B; /* counter clockwise rotation */
  2034. B = A;
  2035. A = -C;
  2036. }
  2037. NORMalize( A, B, Vec );
  2038. return SUCCESS;
  2039. }
  2040. /* When not using the big switch statements, the interpreter uses a */
  2041. /* call table defined later below in this source. Each opcode must */
  2042. /* thus have a corresponding function, even trivial ones. */
  2043. /* */
  2044. /* They are all defined there. */
  2045. #define DO_SVTCA \
  2046. { \
  2047. FT_Short A, B; \
  2048. \
  2049. \
  2050. A = (FT_Short)( CUR.opcode & 1 ) << 14; \
  2051. B = A ^ (FT_Short)0x4000; \
  2052. \
  2053. CUR.GS.freeVector.x = A; \
  2054. CUR.GS.projVector.x = A; \
  2055. CUR.GS.dualVector.x = A; \
  2056. \
  2057. CUR.GS.freeVector.y = B; \
  2058. CUR.GS.projVector.y = B; \
  2059. CUR.GS.dualVector.y = B; \
  2060. \
  2061. COMPUTE_Funcs(); \
  2062. }
  2063. #define DO_SPVTCA \
  2064. { \
  2065. FT_Short A, B; \
  2066. \
  2067. \
  2068. A = (FT_Short)( CUR.opcode & 1 ) << 14; \
  2069. B = A ^ (FT_Short)0x4000; \
  2070. \
  2071. CUR.GS.projVector.x = A; \
  2072. CUR.GS.dualVector.x = A; \
  2073. \
  2074. CUR.GS.projVector.y = B; \
  2075. CUR.GS.dualVector.y = B; \
  2076. \
  2077. COMPUTE_Funcs(); \
  2078. }
  2079. #define DO_SFVTCA \
  2080. { \
  2081. FT_Short A, B; \
  2082. \
  2083. \
  2084. A = (FT_Short)( CUR.opcode & 1 ) << 14; \
  2085. B = A ^ (FT_Short)0x4000; \
  2086. \
  2087. CUR.GS.freeVector.x = A; \
  2088. CUR.GS.freeVector.y = B; \
  2089. \
  2090. COMPUTE_Funcs(); \
  2091. }
  2092. #define DO_SPVTL \
  2093. if ( INS_SxVTL( (FT_UShort)args[1], \
  2094. (FT_UShort)args[0], \
  2095. CUR.opcode, \
  2096. &CUR.GS.projVector ) == SUCCESS ) \
  2097. { \
  2098. CUR.GS.dualVector = CUR.GS.projVector; \
  2099. COMPUTE_Funcs(); \
  2100. }
  2101. #define DO_SFVTL \
  2102. if ( INS_SxVTL( (FT_UShort)args[1], \
  2103. (FT_UShort)args[0], \
  2104. CUR.opcode, \
  2105. &CUR.GS.freeVector ) == SUCCESS ) \
  2106. COMPUTE_Funcs();
  2107. #define DO_SFVTPV \
  2108. CUR.GS.freeVector = CUR.GS.projVector; \
  2109. COMPUTE_Funcs();
  2110. #define DO_SPVFS \
  2111. { \
  2112. FT_Short S; \
  2113. FT_Long X, Y; \
  2114. \
  2115. \
  2116. /* Only use low 16bits, then sign extend */ \
  2117. S = (FT_Short)args[1]; \
  2118. Y = (FT_Long)S; \
  2119. S = (FT_Short)args[0]; \
  2120. X = (FT_Long)S; \
  2121. \
  2122. NORMalize( X, Y, &CUR.GS.projVector ); \
  2123. \
  2124. CUR.GS.dualVector = CUR.GS.projVector; \
  2125. COMPUTE_Funcs(); \
  2126. }
  2127. #define DO_SFVFS \
  2128. { \
  2129. FT_Short S; \
  2130. FT_Long X, Y; \
  2131. \
  2132. \
  2133. /* Only use low 16bits, then sign extend */ \
  2134. S = (FT_Short)args[1]; \
  2135. Y = (FT_Long)S; \
  2136. S = (FT_Short)args[0]; \
  2137. X = S; \
  2138. \
  2139. NORMalize( X, Y, &CUR.GS.freeVector ); \
  2140. COMPUTE_Funcs(); \
  2141. }
  2142. #define DO_GPV \
  2143. args[0] = CUR.GS.projVector.x; \
  2144. args[1] = CUR.GS.projVector.y;
  2145. #define DO_GFV \
  2146. args[0] = CUR.GS.freeVector.x; \
  2147. args[1] = CUR.GS.freeVector.y;
  2148. #define DO_SRP0 \
  2149. CUR.GS.rp0 = (FT_UShort)args[0];
  2150. #define DO_SRP1 \
  2151. CUR.GS.rp1 = (FT_UShort)args[0];
  2152. #define DO_SRP2 \
  2153. CUR.GS.rp2 = (FT_UShort)args[0];
  2154. #define DO_RTHG \
  2155. CUR.GS.round_state = TT_Round_To_Half_Grid; \
  2156. CUR.func_round = (TT_Round_Func)Round_To_Half_Grid;
  2157. #define DO_RTG \
  2158. CUR.GS.round_state = TT_Round_To_Grid; \
  2159. CUR.func_round = (TT_Round_Func)Round_To_Grid;
  2160. #define DO_RTDG \
  2161. CUR.GS.round_state = TT_Round_To_Double_Grid; \
  2162. CUR.func_round = (TT_Round_Func)Round_To_Double_Grid;
  2163. #define DO_RUTG \
  2164. CUR.GS.round_state = TT_Round_Up_To_Grid; \
  2165. CUR.func_round = (TT_Round_Func)Round_Up_To_Grid;
  2166. #define DO_RDTG \
  2167. CUR.GS.round_state = TT_Round_Down_To_Grid; \
  2168. CUR.func_round = (TT_Round_Func)Round_Down_To_Grid;
  2169. #define DO_ROFF \
  2170. CUR.GS.round_state = TT_Round_Off; \
  2171. CUR.func_round = (TT_Round_Func)Round_None;
  2172. #define DO_SROUND \
  2173. SET_SuperRound( 0x4000, args[0] ); \
  2174. CUR.GS.round_state = TT_Round_Super; \
  2175. CUR.func_round = (TT_Round_Func)Round_Super;
  2176. #define DO_S45ROUND \
  2177. SET_SuperRound( 0x2D41, args[0] ); \
  2178. CUR.GS.round_state = TT_Round_Super_45; \
  2179. CUR.func_round = (TT_Round_Func)Round_Super_45;
  2180. #define DO_SLOOP \
  2181. if ( args[0] < 0 ) \
  2182. CUR.error = TT_Err_Bad_Argument; \
  2183. else \
  2184. CUR.GS.loop = args[0];
  2185. #define DO_SMD \
  2186. CUR.GS.minimum_distance = args[0];
  2187. #define DO_SCVTCI \
  2188. CUR.GS.control_value_cutin = (FT_F26Dot6)args[0];
  2189. #define DO_SSWCI \
  2190. CUR.GS.single_width_cutin = (FT_F26Dot6)args[0];
  2191. /* XXX: UNDOCUMENTED! or bug in the Windows engine? */
  2192. /* */
  2193. /* It seems that the value that is read here is */
  2194. /* expressed in 16.16 format rather than in font */
  2195. /* units. */
  2196. /* */
  2197. #define DO_SSW \
  2198. CUR.GS.single_width_value = (FT_F26Dot6)( args[0] >> 10 );
  2199. #define DO_FLIPON \
  2200. CUR.GS.auto_flip = TRUE;
  2201. #define DO_FLIPOFF \
  2202. CUR.GS.auto_flip = FALSE;
  2203. #define DO_SDB \
  2204. CUR.GS.delta_base = (FT_Short)args[0];
  2205. #define DO_SDS \
  2206. CUR.GS.delta_shift = (FT_Short)args[0];
  2207. #define DO_MD /* nothing */
  2208. #define DO_MPPEM \
  2209. args[0] = CURRENT_Ppem();
  2210. /* Note: The pointSize should be irrelevant in a given font program; */
  2211. /* we thus decide to return only the ppem. */
  2212. #if 0
  2213. #define DO_MPS \
  2214. args[0] = CUR.metrics.pointSize;
  2215. #else
  2216. #define DO_MPS \
  2217. args[0] = CURRENT_Ppem();
  2218. #endif /* 0 */
  2219. #define DO_DUP \
  2220. args[1] = args[0];
  2221. #define DO_CLEAR \
  2222. CUR.new_top = 0;
  2223. #define DO_SWAP \
  2224. { \
  2225. FT_Long L; \
  2226. \
  2227. \
  2228. L = args[0]; \
  2229. args[0] = args[1]; \
  2230. args[1] = L; \
  2231. }
  2232. #define DO_DEPTH \
  2233. args[0] = CUR.top;
  2234. #define DO_CINDEX \
  2235. { \
  2236. FT_Long L; \
  2237. \
  2238. \
  2239. L = args[0]; \
  2240. \
  2241. if ( L <= 0 || L > CUR.args ) \
  2242. CUR.error = TT_Err_Invalid_Reference; \
  2243. else \
  2244. args[0] = CUR.stack[CUR.args - L]; \
  2245. }
  2246. #define DO_JROT \
  2247. if ( args[1] != 0 ) \
  2248. { \
  2249. CUR.IP += args[0]; \
  2250. CUR.step_ins = FALSE; \
  2251. }
  2252. #define DO_JMPR \
  2253. CUR.IP += args[0]; \
  2254. CUR.step_ins = FALSE;
  2255. #define DO_JROF \
  2256. if ( args[1] == 0 ) \
  2257. { \
  2258. CUR.IP += args[0]; \
  2259. CUR.step_ins = FALSE; \
  2260. }
  2261. #define DO_LT \
  2262. args[0] = ( args[0] < args[1] );
  2263. #define DO_LTEQ \
  2264. args[0] = ( args[0] <= args[1] );
  2265. #define DO_GT \
  2266. args[0] = ( args[0] > args[1] );
  2267. #define DO_GTEQ \
  2268. args[0] = ( args[0] >= args[1] );
  2269. #define DO_EQ \
  2270. args[0] = ( args[0] == args[1] );
  2271. #define DO_NEQ \
  2272. args[0] = ( args[0] != args[1] );
  2273. #define DO_ODD \
  2274. args[0] = ( ( CUR_Func_round( args[0], 0 ) & 127 ) == 64 );
  2275. #define DO_EVEN \
  2276. args[0] = ( ( CUR_Func_round( args[0], 0 ) & 127 ) == 0 );
  2277. #define DO_AND \
  2278. args[0] = ( args[0] && args[1] );
  2279. #define DO_OR \
  2280. args[0] = ( args[0] || args[1] );
  2281. #define DO_NOT \
  2282. args[0] = !args[0];
  2283. #define DO_ADD \
  2284. args[0] += args[1];
  2285. #define DO_SUB \
  2286. args[0] -= args[1];
  2287. #define DO_DIV \
  2288. if ( args[1] == 0 ) \
  2289. CUR.error = TT_Err_Divide_By_Zero; \
  2290. else \
  2291. args[0] = TT_MULDIV( args[0], 64L, args[1] );
  2292. #define DO_MUL \
  2293. args[0] = TT_MULDIV( args[0], args[1], 64L );
  2294. #define DO_ABS \
  2295. args[0] = ABS( args[0] );
  2296. #define DO_NEG \
  2297. args[0] = -args[0];
  2298. #define DO_FLOOR \
  2299. args[0] &= -64;
  2300. #define DO_CEILING \
  2301. args[0] = ( args[0] + 63 ) & -64;
  2302. #define DO_RS \
  2303. { \
  2304. FT_ULong I = (FT_ULong)args[0]; \
  2305. \
  2306. \
  2307. if ( BOUNDS( I, CUR.storeSize ) ) \
  2308. { \
  2309. if ( CUR.pedantic_hinting ) \
  2310. { \
  2311. ARRAY_BOUND_ERROR; \
  2312. } \
  2313. else \
  2314. args[0] = 0; \
  2315. } \
  2316. else \
  2317. args[0] = CUR.storage[I]; \
  2318. }
  2319. #define DO_WS \
  2320. { \
  2321. FT_ULong I = (FT_ULong)args[0]; \
  2322. \
  2323. \
  2324. if ( BOUNDS( I, CUR.storeSize ) ) \
  2325. { \
  2326. if ( CUR.pedantic_hinting ) \
  2327. { \
  2328. ARRAY_BOUND_ERROR; \
  2329. } \
  2330. } \
  2331. else \
  2332. CUR.storage[I] = args[1]; \
  2333. }
  2334. #define DO_RCVT \
  2335. { \
  2336. FT_ULong I = (FT_ULong)args[0]; \
  2337. \
  2338. \
  2339. if ( BOUNDS( I, CUR.cvtSize ) ) \
  2340. { \
  2341. if ( CUR.pedantic_hinting ) \
  2342. { \
  2343. ARRAY_BOUND_ERROR; \
  2344. } \
  2345. else \
  2346. args[0] = 0; \
  2347. } \
  2348. else \
  2349. args[0] = CUR_Func_read_cvt( I ); \
  2350. }
  2351. #define DO_WCVTP \
  2352. { \
  2353. FT_ULong I = (FT_ULong)args[0]; \
  2354. \
  2355. \
  2356. if ( BOUNDS( I, CUR.cvtSize ) ) \
  2357. { \
  2358. if ( CUR.pedantic_hinting ) \
  2359. { \
  2360. ARRAY_BOUND_ERROR; \
  2361. } \
  2362. } \
  2363. else \
  2364. CUR_Func_write_cvt( I, args[1] ); \
  2365. }
  2366. #define DO_WCVTF \
  2367. { \
  2368. FT_ULong I = (FT_ULong)args[0]; \
  2369. \
  2370. \
  2371. if ( BOUNDS( I, CUR.cvtSize ) ) \
  2372. { \
  2373. if ( CUR.pedantic_hinting ) \
  2374. { \
  2375. ARRAY_BOUND_ERROR; \
  2376. } \
  2377. } \
  2378. else \
  2379. CUR.cvt[I] = TT_MULFIX( args[1], CUR.tt_metrics.scale ); \
  2380. }
  2381. #define DO_DEBUG \
  2382. CUR.error = TT_Err_Debug_OpCode;
  2383. #define DO_ROUND \
  2384. args[0] = CUR_Func_round( \
  2385. args[0], \
  2386. CUR.tt_metrics.compensations[CUR.opcode - 0x68] );
  2387. #define DO_NROUND \
  2388. args[0] = ROUND_None( args[0], \
  2389. CUR.tt_metrics.compensations[CUR.opcode - 0x6C] );
  2390. #define DO_MAX \
  2391. if ( args[1] > args[0] ) \
  2392. args[0] = args[1];
  2393. #define DO_MIN \
  2394. if ( args[1] < args[0] ) \
  2395. args[0] = args[1];
  2396. #ifndef TT_CONFIG_OPTION_INTERPRETER_SWITCH
  2397. #undef ARRAY_BOUND_ERROR
  2398. #define ARRAY_BOUND_ERROR \
  2399. { \
  2400. CUR.error = TT_Err_Invalid_Reference; \
  2401. return; \
  2402. }
  2403. /*************************************************************************/
  2404. /* */
  2405. /* SVTCA[a]: Set (F and P) Vectors to Coordinate Axis */
  2406. /* Opcode range: 0x00-0x01 */
  2407. /* Stack: --> */
  2408. /* */
  2409. static void
  2410. Ins_SVTCA( INS_ARG )
  2411. {
  2412. DO_SVTCA
  2413. }
  2414. /*************************************************************************/
  2415. /* */
  2416. /* SPVTCA[a]: Set PVector to Coordinate Axis */
  2417. /* Opcode range: 0x02-0x03 */
  2418. /* Stack: --> */
  2419. /* */
  2420. static void
  2421. Ins_SPVTCA( INS_ARG )
  2422. {
  2423. DO_SPVTCA
  2424. }
  2425. /*************************************************************************/
  2426. /* */
  2427. /* SFVTCA[a]: Set FVector to Coordinate Axis */
  2428. /* Opcode range: 0x04-0x05 */
  2429. /* Stack: --> */
  2430. /* */
  2431. static void
  2432. Ins_SFVTCA( INS_ARG )
  2433. {
  2434. DO_SFVTCA
  2435. }
  2436. /*************************************************************************/
  2437. /* */
  2438. /* SPVTL[a]: Set PVector To Line */
  2439. /* Opcode range: 0x06-0x07 */
  2440. /* Stack: uint32 uint32 --> */
  2441. /* */
  2442. static void
  2443. Ins_SPVTL( INS_ARG )
  2444. {
  2445. DO_SPVTL
  2446. }
  2447. /*************************************************************************/
  2448. /* */
  2449. /* SFVTL[a]: Set FVector To Line */
  2450. /* Opcode range: 0x08-0x09 */
  2451. /* Stack: uint32 uint32 --> */
  2452. /* */
  2453. static void
  2454. Ins_SFVTL( INS_ARG )
  2455. {
  2456. DO_SFVTL
  2457. }
  2458. /*************************************************************************/
  2459. /* */
  2460. /* SFVTPV[]: Set FVector To PVector */
  2461. /* Opcode range: 0x0E */
  2462. /* Stack: --> */
  2463. /* */
  2464. static void
  2465. Ins_SFVTPV( INS_ARG )
  2466. {
  2467. DO_SFVTPV
  2468. }
  2469. /*************************************************************************/
  2470. /* */
  2471. /* SPVFS[]: Set PVector From Stack */
  2472. /* Opcode range: 0x0A */
  2473. /* Stack: f2.14 f2.14 --> */
  2474. /* */
  2475. static void
  2476. Ins_SPVFS( INS_ARG )
  2477. {
  2478. DO_SPVFS
  2479. }
  2480. /*************************************************************************/
  2481. /* */
  2482. /* SFVFS[]: Set FVector From Stack */
  2483. /* Opcode range: 0x0B */
  2484. /* Stack: f2.14 f2.14 --> */
  2485. /* */
  2486. static void
  2487. Ins_SFVFS( INS_ARG )
  2488. {
  2489. DO_SFVFS
  2490. }
  2491. /*************************************************************************/
  2492. /* */
  2493. /* GPV[]: Get Projection Vector */
  2494. /* Opcode range: 0x0C */
  2495. /* Stack: ef2.14 --> ef2.14 */
  2496. /* */
  2497. static void
  2498. Ins_GPV( INS_ARG )
  2499. {
  2500. DO_GPV
  2501. }
  2502. /*************************************************************************/
  2503. /* GFV[]: Get Freedom Vector */
  2504. /* Opcode range: 0x0D */
  2505. /* Stack: ef2.14 --> ef2.14 */
  2506. /* */
  2507. static void
  2508. Ins_GFV( INS_ARG )
  2509. {
  2510. DO_GFV
  2511. }
  2512. /*************************************************************************/
  2513. /* */
  2514. /* SRP0[]: Set Reference Point 0 */
  2515. /* Opcode range: 0x10 */
  2516. /* Stack: uint32 --> */
  2517. /* */
  2518. static void
  2519. Ins_SRP0( INS_ARG )
  2520. {
  2521. DO_SRP0
  2522. }
  2523. /*************************************************************************/
  2524. /* */
  2525. /* SRP1[]: Set Reference Point 1 */
  2526. /* Opcode range: 0x11 */
  2527. /* Stack: uint32 --> */
  2528. /* */
  2529. static void
  2530. Ins_SRP1( INS_ARG )
  2531. {
  2532. DO_SRP1
  2533. }
  2534. /*************************************************************************/
  2535. /* */
  2536. /* SRP2[]: Set Reference Point 2 */
  2537. /* Opcode range: 0x12 */
  2538. /* Stack: uint32 --> */
  2539. /* */
  2540. static void
  2541. Ins_SRP2( INS_ARG )
  2542. {
  2543. DO_SRP2
  2544. }
  2545. /*************************************************************************/
  2546. /* */
  2547. /* RTHG[]: Round To Half Grid */
  2548. /* Opcode range: 0x19 */
  2549. /* Stack: --> */
  2550. /* */
  2551. static void
  2552. Ins_RTHG( INS_ARG )
  2553. {
  2554. DO_RTHG
  2555. }
  2556. /*************************************************************************/
  2557. /* */
  2558. /* RTG[]: Round To Grid */
  2559. /* Opcode range: 0x18 */
  2560. /* Stack: --> */
  2561. /* */
  2562. static void
  2563. Ins_RTG( INS_ARG )
  2564. {
  2565. DO_RTG
  2566. }
  2567. /*************************************************************************/
  2568. /* RTDG[]: Round To Double Grid */
  2569. /* Opcode range: 0x3D */
  2570. /* Stack: --> */
  2571. /* */
  2572. static void
  2573. Ins_RTDG( INS_ARG )
  2574. {
  2575. DO_RTDG
  2576. }
  2577. /*************************************************************************/
  2578. /* RUTG[]: Round Up To Grid */
  2579. /* Opcode range: 0x7C */
  2580. /* Stack: --> */
  2581. /* */
  2582. static void
  2583. Ins_RUTG( INS_ARG )
  2584. {
  2585. DO_RUTG
  2586. }
  2587. /*************************************************************************/
  2588. /* */
  2589. /* RDTG[]: Round Down To Grid */
  2590. /* Opcode range: 0x7D */
  2591. /* Stack: --> */
  2592. /* */
  2593. static void
  2594. Ins_RDTG( INS_ARG )
  2595. {
  2596. DO_RDTG
  2597. }
  2598. /*************************************************************************/
  2599. /* */
  2600. /* ROFF[]: Round OFF */
  2601. /* Opcode range: 0x7A */
  2602. /* Stack: --> */
  2603. /* */
  2604. static void
  2605. Ins_ROFF( INS_ARG )
  2606. {
  2607. DO_ROFF
  2608. }
  2609. /*************************************************************************/
  2610. /* */
  2611. /* SROUND[]: Super ROUND */
  2612. /* Opcode range: 0x76 */
  2613. /* Stack: Eint8 --> */
  2614. /* */
  2615. static void
  2616. Ins_SROUND( INS_ARG )
  2617. {
  2618. DO_SROUND
  2619. }
  2620. /*************************************************************************/
  2621. /* */
  2622. /* S45ROUND[]: Super ROUND 45 degrees */
  2623. /* Opcode range: 0x77 */
  2624. /* Stack: uint32 --> */
  2625. /* */
  2626. static void
  2627. Ins_S45ROUND( INS_ARG )
  2628. {
  2629. DO_S45ROUND
  2630. }
  2631. /*************************************************************************/
  2632. /* */
  2633. /* SLOOP[]: Set LOOP variable */
  2634. /* Opcode range: 0x17 */
  2635. /* Stack: int32? --> */
  2636. /* */
  2637. static void
  2638. Ins_SLOOP( INS_ARG )
  2639. {
  2640. DO_SLOOP
  2641. }
  2642. /*************************************************************************/
  2643. /* */
  2644. /* SMD[]: Set Minimum Distance */
  2645. /* Opcode range: 0x1A */
  2646. /* Stack: f26.6 --> */
  2647. /* */
  2648. static void
  2649. Ins_SMD( INS_ARG )
  2650. {
  2651. DO_SMD
  2652. }
  2653. /*************************************************************************/
  2654. /* */
  2655. /* SCVTCI[]: Set Control Value Table Cut In */
  2656. /* Opcode range: 0x1D */
  2657. /* Stack: f26.6 --> */
  2658. /* */
  2659. static void
  2660. Ins_SCVTCI( INS_ARG )
  2661. {
  2662. DO_SCVTCI
  2663. }
  2664. /*************************************************************************/
  2665. /* */
  2666. /* SSWCI[]: Set Single Width Cut In */
  2667. /* Opcode range: 0x1E */
  2668. /* Stack: f26.6 --> */
  2669. /* */
  2670. static void
  2671. Ins_SSWCI( INS_ARG )
  2672. {
  2673. DO_SSWCI
  2674. }
  2675. /*************************************************************************/
  2676. /* */
  2677. /* SSW[]: Set Single Width */
  2678. /* Opcode range: 0x1F */
  2679. /* Stack: int32? --> */
  2680. /* */
  2681. static void
  2682. Ins_SSW( INS_ARG )
  2683. {
  2684. DO_SSW
  2685. }
  2686. /*************************************************************************/
  2687. /* */
  2688. /* FLIPON[]: Set auto-FLIP to ON */
  2689. /* Opcode range: 0x4D */
  2690. /* Stack: --> */
  2691. /* */
  2692. static void
  2693. Ins_FLIPON( INS_ARG )
  2694. {
  2695. DO_FLIPON
  2696. }
  2697. /*************************************************************************/
  2698. /* */
  2699. /* FLIPOFF[]: Set auto-FLIP to OFF */
  2700. /* Opcode range: 0x4E */
  2701. /* Stack: --> */
  2702. /* */
  2703. static void
  2704. Ins_FLIPOFF( INS_ARG )
  2705. {
  2706. DO_FLIPOFF
  2707. }
  2708. /*************************************************************************/
  2709. /* */
  2710. /* SANGW[]: Set ANGle Weight */
  2711. /* Opcode range: 0x7E */
  2712. /* Stack: uint32 --> */
  2713. /* */
  2714. static void
  2715. Ins_SANGW( INS_ARG )
  2716. {
  2717. /* instruction not supported anymore */
  2718. }
  2719. /*************************************************************************/
  2720. /* */
  2721. /* SDB[]: Set Delta Base */
  2722. /* Opcode range: 0x5E */
  2723. /* Stack: uint32 --> */
  2724. /* */
  2725. static void
  2726. Ins_SDB( INS_ARG )
  2727. {
  2728. DO_SDB
  2729. }
  2730. /*************************************************************************/
  2731. /* */
  2732. /* SDS[]: Set Delta Shift */
  2733. /* Opcode range: 0x5F */
  2734. /* Stack: uint32 --> */
  2735. /* */
  2736. static void
  2737. Ins_SDS( INS_ARG )
  2738. {
  2739. DO_SDS
  2740. }
  2741. /*************************************************************************/
  2742. /* */
  2743. /* MPPEM[]: Measure Pixel Per EM */
  2744. /* Opcode range: 0x4B */
  2745. /* Stack: --> Euint16 */
  2746. /* */
  2747. static void
  2748. Ins_MPPEM( INS_ARG )
  2749. {
  2750. DO_MPPEM
  2751. }
  2752. /*************************************************************************/
  2753. /* */
  2754. /* MPS[]: Measure Point Size */
  2755. /* Opcode range: 0x4C */
  2756. /* Stack: --> Euint16 */
  2757. /* */
  2758. static void
  2759. Ins_MPS( INS_ARG )
  2760. {
  2761. DO_MPS
  2762. }
  2763. /*************************************************************************/
  2764. /* */
  2765. /* DUP[]: DUPlicate the top stack's element */
  2766. /* Opcode range: 0x20 */
  2767. /* Stack: StkElt --> StkElt StkElt */
  2768. /* */
  2769. static void
  2770. Ins_DUP( INS_ARG )
  2771. {
  2772. DO_DUP
  2773. }
  2774. /*************************************************************************/
  2775. /* */
  2776. /* POP[]: POP the stack's top element */
  2777. /* Opcode range: 0x21 */
  2778. /* Stack: StkElt --> */
  2779. /* */
  2780. static void
  2781. Ins_POP( INS_ARG )
  2782. {
  2783. /* nothing to do */
  2784. }
  2785. /*************************************************************************/
  2786. /* */
  2787. /* CLEAR[]: CLEAR the entire stack */
  2788. /* Opcode range: 0x22 */
  2789. /* Stack: StkElt... --> */
  2790. /* */
  2791. static void
  2792. Ins_CLEAR( INS_ARG )
  2793. {
  2794. DO_CLEAR
  2795. }
  2796. /*************************************************************************/
  2797. /* */
  2798. /* SWAP[]: SWAP the stack's top two elements */
  2799. /* Opcode range: 0x23 */
  2800. /* Stack: 2 * StkElt --> 2 * StkElt */
  2801. /* */
  2802. static void
  2803. Ins_SWAP( INS_ARG )
  2804. {
  2805. DO_SWAP
  2806. }
  2807. /*************************************************************************/
  2808. /* */
  2809. /* DEPTH[]: return the stack DEPTH */
  2810. /* Opcode range: 0x24 */
  2811. /* Stack: --> uint32 */
  2812. /* */
  2813. static void
  2814. Ins_DEPTH( INS_ARG )
  2815. {
  2816. DO_DEPTH
  2817. }
  2818. /*************************************************************************/
  2819. /* */
  2820. /* CINDEX[]: Copy INDEXed element */
  2821. /* Opcode range: 0x25 */
  2822. /* Stack: int32 --> StkElt */
  2823. /* */
  2824. static void
  2825. Ins_CINDEX( INS_ARG )
  2826. {
  2827. DO_CINDEX
  2828. }
  2829. /*************************************************************************/
  2830. /* */
  2831. /* EIF[]: End IF */
  2832. /* Opcode range: 0x59 */
  2833. /* Stack: --> */
  2834. /* */
  2835. static void
  2836. Ins_EIF( INS_ARG )
  2837. {
  2838. /* nothing to do */
  2839. }
  2840. /*************************************************************************/
  2841. /* */
  2842. /* JROT[]: Jump Relative On True */
  2843. /* Opcode range: 0x78 */
  2844. /* Stack: StkElt int32 --> */
  2845. /* */
  2846. static void
  2847. Ins_JROT( INS_ARG )
  2848. {
  2849. DO_JROT
  2850. }
  2851. /*************************************************************************/
  2852. /* */
  2853. /* JMPR[]: JuMP Relative */
  2854. /* Opcode range: 0x1C */
  2855. /* Stack: int32 --> */
  2856. /* */
  2857. static void
  2858. Ins_JMPR( INS_ARG )
  2859. {
  2860. DO_JMPR
  2861. }
  2862. /*************************************************************************/
  2863. /* */
  2864. /* JROF[]: Jump Relative On False */
  2865. /* Opcode range: 0x79 */
  2866. /* Stack: StkElt int32 --> */
  2867. /* */
  2868. static void
  2869. Ins_JROF( INS_ARG )
  2870. {
  2871. DO_JROF
  2872. }
  2873. /*************************************************************************/
  2874. /* */
  2875. /* LT[]: Less Than */
  2876. /* Opcode range: 0x50 */
  2877. /* Stack: int32? int32? --> bool */
  2878. /* */
  2879. static void
  2880. Ins_LT( INS_ARG )
  2881. {
  2882. DO_LT
  2883. }
  2884. /*************************************************************************/
  2885. /* */
  2886. /* LTEQ[]: Less Than or EQual */
  2887. /* Opcode range: 0x51 */
  2888. /* Stack: int32? int32? --> bool */
  2889. /* */
  2890. static void
  2891. Ins_LTEQ( INS_ARG )
  2892. {
  2893. DO_LTEQ
  2894. }
  2895. /*************************************************************************/
  2896. /* */
  2897. /* GT[]: Greater Than */
  2898. /* Opcode range: 0x52 */
  2899. /* Stack: int32? int32? --> bool */
  2900. /* */
  2901. static void
  2902. Ins_GT( INS_ARG )
  2903. {
  2904. DO_GT
  2905. }
  2906. /*************************************************************************/
  2907. /* */
  2908. /* GTEQ[]: Greater Than or EQual */
  2909. /* Opcode range: 0x53 */
  2910. /* Stack: int32? int32? --> bool */
  2911. /* */
  2912. static void
  2913. Ins_GTEQ( INS_ARG )
  2914. {
  2915. DO_GTEQ
  2916. }
  2917. /*************************************************************************/
  2918. /* */
  2919. /* EQ[]: EQual */
  2920. /* Opcode range: 0x54 */
  2921. /* Stack: StkElt StkElt --> bool */
  2922. /* */
  2923. static void
  2924. Ins_EQ( INS_ARG )
  2925. {
  2926. DO_EQ
  2927. }
  2928. /*************************************************************************/
  2929. /* */
  2930. /* NEQ[]: Not EQual */
  2931. /* Opcode range: 0x55 */
  2932. /* Stack: StkElt StkElt --> bool */
  2933. /* */
  2934. static void
  2935. Ins_NEQ( INS_ARG )
  2936. {
  2937. DO_NEQ
  2938. }
  2939. /*************************************************************************/
  2940. /* */
  2941. /* ODD[]: Is ODD */
  2942. /* Opcode range: 0x56 */
  2943. /* Stack: f26.6 --> bool */
  2944. /* */
  2945. static void
  2946. Ins_ODD( INS_ARG )
  2947. {
  2948. DO_ODD
  2949. }
  2950. /*************************************************************************/
  2951. /* */
  2952. /* EVEN[]: Is EVEN */
  2953. /* Opcode range: 0x57 */
  2954. /* Stack: f26.6 --> bool */
  2955. /* */
  2956. static void
  2957. Ins_EVEN( INS_ARG )
  2958. {
  2959. DO_EVEN
  2960. }
  2961. /*************************************************************************/
  2962. /* */
  2963. /* AND[]: logical AND */
  2964. /* Opcode range: 0x5A */
  2965. /* Stack: uint32 uint32 --> uint32 */
  2966. /* */
  2967. static void
  2968. Ins_AND( INS_ARG )
  2969. {
  2970. DO_AND
  2971. }
  2972. /*************************************************************************/
  2973. /* */
  2974. /* OR[]: logical OR */
  2975. /* Opcode range: 0x5B */
  2976. /* Stack: uint32 uint32 --> uint32 */
  2977. /* */
  2978. static void
  2979. Ins_OR( INS_ARG )
  2980. {
  2981. DO_OR
  2982. }
  2983. /*************************************************************************/
  2984. /* */
  2985. /* NOT[]: logical NOT */
  2986. /* Opcode range: 0x5C */
  2987. /* Stack: StkElt --> uint32 */
  2988. /* */
  2989. static void
  2990. Ins_NOT( INS_ARG )
  2991. {
  2992. DO_NOT
  2993. }
  2994. /*************************************************************************/
  2995. /* */
  2996. /* ADD[]: ADD */
  2997. /* Opcode range: 0x60 */
  2998. /* Stack: f26.6 f26.6 --> f26.6 */
  2999. /* */
  3000. static void
  3001. Ins_ADD( INS_ARG )
  3002. {
  3003. DO_ADD
  3004. }
  3005. /*************************************************************************/
  3006. /* */
  3007. /* SUB[]: SUBtract */
  3008. /* Opcode range: 0x61 */
  3009. /* Stack: f26.6 f26.6 --> f26.6 */
  3010. /* */
  3011. static void
  3012. Ins_SUB( INS_ARG )
  3013. {
  3014. DO_SUB
  3015. }
  3016. /*************************************************************************/
  3017. /* */
  3018. /* DIV[]: DIVide */
  3019. /* Opcode range: 0x62 */
  3020. /* Stack: f26.6 f26.6 --> f26.6 */
  3021. /* */
  3022. static void
  3023. Ins_DIV( INS_ARG )
  3024. {
  3025. DO_DIV
  3026. }
  3027. /*************************************************************************/
  3028. /* */
  3029. /* MUL[]: MULtiply */
  3030. /* Opcode range: 0x63 */
  3031. /* Stack: f26.6 f26.6 --> f26.6 */
  3032. /* */
  3033. static void
  3034. Ins_MUL( INS_ARG )
  3035. {
  3036. DO_MUL
  3037. }
  3038. /*************************************************************************/
  3039. /* */
  3040. /* ABS[]: ABSolute value */
  3041. /* Opcode range: 0x64 */
  3042. /* Stack: f26.6 --> f26.6 */
  3043. /* */
  3044. static void
  3045. Ins_ABS( INS_ARG )
  3046. {
  3047. DO_ABS
  3048. }
  3049. /*************************************************************************/
  3050. /* */
  3051. /* NEG[]: NEGate */
  3052. /* Opcode range: 0x65 */
  3053. /* Stack: f26.6 --> f26.6 */
  3054. /* */
  3055. static void
  3056. Ins_NEG( INS_ARG )
  3057. {
  3058. DO_NEG
  3059. }
  3060. /*************************************************************************/
  3061. /* */
  3062. /* FLOOR[]: FLOOR */
  3063. /* Opcode range: 0x66 */
  3064. /* Stack: f26.6 --> f26.6 */
  3065. /* */
  3066. static void
  3067. Ins_FLOOR( INS_ARG )
  3068. {
  3069. DO_FLOOR
  3070. }
  3071. /*************************************************************************/
  3072. /* */
  3073. /* CEILING[]: CEILING */
  3074. /* Opcode range: 0x67 */
  3075. /* Stack: f26.6 --> f26.6 */
  3076. /* */
  3077. static void
  3078. Ins_CEILING( INS_ARG )
  3079. {
  3080. DO_CEILING
  3081. }
  3082. /*************************************************************************/
  3083. /* */
  3084. /* RS[]: Read Store */
  3085. /* Opcode range: 0x43 */
  3086. /* Stack: uint32 --> uint32 */
  3087. /* */
  3088. static void
  3089. Ins_RS( INS_ARG )
  3090. {
  3091. DO_RS
  3092. }
  3093. /*************************************************************************/
  3094. /* */
  3095. /* WS[]: Write Store */
  3096. /* Opcode range: 0x42 */
  3097. /* Stack: uint32 uint32 --> */
  3098. /* */
  3099. static void
  3100. Ins_WS( INS_ARG )
  3101. {
  3102. DO_WS
  3103. }
  3104. /*************************************************************************/
  3105. /* */
  3106. /* WCVTP[]: Write CVT in Pixel units */
  3107. /* Opcode range: 0x44 */
  3108. /* Stack: f26.6 uint32 --> */
  3109. /* */
  3110. static void
  3111. Ins_WCVTP( INS_ARG )
  3112. {
  3113. DO_WCVTP
  3114. }
  3115. /*************************************************************************/
  3116. /* */
  3117. /* WCVTF[]: Write CVT in Funits */
  3118. /* Opcode range: 0x70 */
  3119. /* Stack: uint32 uint32 --> */
  3120. /* */
  3121. static void
  3122. Ins_WCVTF( INS_ARG )
  3123. {
  3124. DO_WCVTF
  3125. }
  3126. /*************************************************************************/
  3127. /* */
  3128. /* RCVT[]: Read CVT */
  3129. /* Opcode range: 0x45 */
  3130. /* Stack: uint32 --> f26.6 */
  3131. /* */
  3132. static void
  3133. Ins_RCVT( INS_ARG )
  3134. {
  3135. DO_RCVT
  3136. }
  3137. /*************************************************************************/
  3138. /* */
  3139. /* AA[]: Adjust Angle */
  3140. /* Opcode range: 0x7F */
  3141. /* Stack: uint32 --> */
  3142. /* */
  3143. static void
  3144. Ins_AA( INS_ARG )
  3145. {
  3146. /* intentionally no longer supported */
  3147. }
  3148. /*************************************************************************/
  3149. /* */
  3150. /* DEBUG[]: DEBUG. Unsupported. */
  3151. /* Opcode range: 0x4F */
  3152. /* Stack: uint32 --> */
  3153. /* */
  3154. /* Note: The original instruction pops a value from the stack. */
  3155. /* */
  3156. static void
  3157. Ins_DEBUG( INS_ARG )
  3158. {
  3159. DO_DEBUG
  3160. }
  3161. /*************************************************************************/
  3162. /* */
  3163. /* ROUND[ab]: ROUND value */
  3164. /* Opcode range: 0x68-0x6B */
  3165. /* Stack: f26.6 --> f26.6 */
  3166. /* */
  3167. static void
  3168. Ins_ROUND( INS_ARG )
  3169. {
  3170. DO_ROUND
  3171. }
  3172. /*************************************************************************/
  3173. /* */
  3174. /* NROUND[ab]: No ROUNDing of value */
  3175. /* Opcode range: 0x6C-0x6F */
  3176. /* Stack: f26.6 --> f26.6 */
  3177. /* */
  3178. static void
  3179. Ins_NROUND( INS_ARG )
  3180. {
  3181. DO_NROUND
  3182. }
  3183. /*************************************************************************/
  3184. /* */
  3185. /* MAX[]: MAXimum */
  3186. /* Opcode range: 0x68 */
  3187. /* Stack: int32? int32? --> int32 */
  3188. /* */
  3189. static void
  3190. Ins_MAX( INS_ARG )
  3191. {
  3192. DO_MAX
  3193. }
  3194. /*************************************************************************/
  3195. /* */
  3196. /* MIN[]: MINimum */
  3197. /* Opcode range: 0x69 */
  3198. /* Stack: int32? int32? --> int32 */
  3199. /* */
  3200. static void
  3201. Ins_MIN( INS_ARG )
  3202. {
  3203. DO_MIN
  3204. }
  3205. #endif /* !TT_CONFIG_OPTION_INTERPRETER_SWITCH */
  3206. /*************************************************************************/
  3207. /* */
  3208. /* The following functions are called as is within the switch statement. */
  3209. /* */
  3210. /*************************************************************************/
  3211. /*************************************************************************/
  3212. /* */
  3213. /* MINDEX[]: Move INDEXed element */
  3214. /* Opcode range: 0x26 */
  3215. /* Stack: int32? --> StkElt */
  3216. /* */
  3217. static void
  3218. Ins_MINDEX( INS_ARG )
  3219. {
  3220. FT_Long L, K;
  3221. L = args[0];
  3222. if ( L <= 0 || L > CUR.args )
  3223. {
  3224. CUR.error = TT_Err_Invalid_Reference;
  3225. return;
  3226. }
  3227. K = CUR.stack[CUR.args - L];
  3228. FT_MEM_MOVE( &CUR.stack[CUR.args - L ],
  3229. &CUR.stack[CUR.args - L + 1],
  3230. ( L - 1 ) * sizeof ( FT_Long ) );
  3231. CUR.stack[CUR.args - 1] = K;
  3232. }
  3233. /*************************************************************************/
  3234. /* */
  3235. /* ROLL[]: ROLL top three elements */
  3236. /* Opcode range: 0x8A */
  3237. /* Stack: 3 * StkElt --> 3 * StkElt */
  3238. /* */
  3239. static void
  3240. Ins_ROLL( INS_ARG )
  3241. {
  3242. FT_Long A, B, C;
  3243. FT_UNUSED_EXEC;
  3244. A = args[2];
  3245. B = args[1];
  3246. C = args[0];
  3247. args[2] = C;
  3248. args[1] = A;
  3249. args[0] = B;
  3250. }
  3251. /*************************************************************************/
  3252. /* */
  3253. /* MANAGING THE FLOW OF CONTROL */
  3254. /* */
  3255. /* Instructions appear in the specification's order. */
  3256. /* */
  3257. /*************************************************************************/
  3258. static FT_Bool
  3259. SkipCode( EXEC_OP )
  3260. {
  3261. CUR.IP += CUR.length;
  3262. if ( CUR.IP < CUR.codeSize )
  3263. {
  3264. CUR.opcode = CUR.code[CUR.IP];
  3265. CUR.length = opcode_length[CUR.opcode];
  3266. if ( CUR.length < 0 )
  3267. {
  3268. if ( CUR.IP + 1 > CUR.codeSize )
  3269. goto Fail_Overflow;
  3270. CUR.length = CUR.code[CUR.IP + 1] + 2;
  3271. }
  3272. if ( CUR.IP + CUR.length <= CUR.codeSize )
  3273. return SUCCESS;
  3274. }
  3275. Fail_Overflow:
  3276. CUR.error = TT_Err_Code_Overflow;
  3277. return FAILURE;
  3278. }
  3279. /*************************************************************************/
  3280. /* */
  3281. /* IF[]: IF test */
  3282. /* Opcode range: 0x58 */
  3283. /* Stack: StkElt --> */
  3284. /* */
  3285. static void
  3286. Ins_IF( INS_ARG )
  3287. {
  3288. FT_Int nIfs;
  3289. FT_Bool Out;
  3290. if ( args[0] != 0 )
  3291. return;
  3292. nIfs = 1;
  3293. Out = 0;
  3294. do
  3295. {
  3296. if ( SKIP_Code() == FAILURE )
  3297. return;
  3298. switch ( CUR.opcode )
  3299. {
  3300. case 0x58: /* IF */
  3301. nIfs++;
  3302. break;
  3303. case 0x1B: /* ELSE */
  3304. Out = FT_BOOL( nIfs == 1 );
  3305. break;
  3306. case 0x59: /* EIF */
  3307. nIfs--;
  3308. Out = FT_BOOL( nIfs == 0 );
  3309. break;
  3310. }
  3311. } while ( Out == 0 );
  3312. }
  3313. /*************************************************************************/
  3314. /* */
  3315. /* ELSE[]: ELSE */
  3316. /* Opcode range: 0x1B */
  3317. /* Stack: --> */
  3318. /* */
  3319. static void
  3320. Ins_ELSE( INS_ARG )
  3321. {
  3322. FT_Int nIfs;
  3323. FT_UNUSED_ARG;
  3324. nIfs = 1;
  3325. do
  3326. {
  3327. if ( SKIP_Code() == FAILURE )
  3328. return;
  3329. switch ( CUR.opcode )
  3330. {
  3331. case 0x58: /* IF */
  3332. nIfs++;
  3333. break;
  3334. case 0x59: /* EIF */
  3335. nIfs--;
  3336. break;
  3337. }
  3338. } while ( nIfs != 0 );
  3339. }
  3340. /*************************************************************************/
  3341. /* */
  3342. /* DEFINING AND USING FUNCTIONS AND INSTRUCTIONS */
  3343. /* */
  3344. /* Instructions appear in the specification's order. */
  3345. /* */
  3346. /*************************************************************************/
  3347. /*************************************************************************/
  3348. /* */
  3349. /* FDEF[]: Function DEFinition */
  3350. /* Opcode range: 0x2C */
  3351. /* Stack: uint32 --> */
  3352. /* */
  3353. static void
  3354. Ins_FDEF( INS_ARG )
  3355. {
  3356. FT_ULong n;
  3357. TT_DefRecord* rec;
  3358. TT_DefRecord* limit;
  3359. /* some font programs are broken enough to redefine functions! */
  3360. /* We will then parse the current table. */
  3361. rec = CUR.FDefs;
  3362. limit = rec + CUR.numFDefs;
  3363. n = args[0];
  3364. for ( ; rec < limit; rec++ )
  3365. {
  3366. if ( rec->opc == n )
  3367. break;
  3368. }
  3369. if ( rec == limit )
  3370. {
  3371. /* check that there is enough room for new functions */
  3372. if ( CUR.numFDefs >= CUR.maxFDefs )
  3373. {
  3374. CUR.error = TT_Err_Too_Many_Function_Defs;
  3375. return;
  3376. }
  3377. CUR.numFDefs++;
  3378. }
  3379. rec->range = CUR.curRange;
  3380. rec->opc = n;
  3381. rec->start = CUR.IP + 1;
  3382. rec->active = TRUE;
  3383. if ( n > CUR.maxFunc )
  3384. CUR.maxFunc = n;
  3385. /* Now skip the whole function definition. */
  3386. /* We don't allow nested IDEFS & FDEFs. */
  3387. while ( SKIP_Code() == SUCCESS )
  3388. {
  3389. switch ( CUR.opcode )
  3390. {
  3391. case 0x89: /* IDEF */
  3392. case 0x2C: /* FDEF */
  3393. CUR.error = TT_Err_Nested_DEFS;
  3394. return;
  3395. case 0x2D: /* ENDF */
  3396. return;
  3397. }
  3398. }
  3399. }
  3400. /*************************************************************************/
  3401. /* */
  3402. /* ENDF[]: END Function definition */
  3403. /* Opcode range: 0x2D */
  3404. /* Stack: --> */
  3405. /* */
  3406. static void
  3407. Ins_ENDF( INS_ARG )
  3408. {
  3409. TT_CallRec* pRec;
  3410. FT_UNUSED_ARG;
  3411. if ( CUR.callTop <= 0 ) /* We encountered an ENDF without a call */
  3412. {
  3413. CUR.error = TT_Err_ENDF_In_Exec_Stream;
  3414. return;
  3415. }
  3416. CUR.callTop--;
  3417. pRec = &CUR.callStack[CUR.callTop];
  3418. pRec->Cur_Count--;
  3419. CUR.step_ins = FALSE;
  3420. if ( pRec->Cur_Count > 0 )
  3421. {
  3422. CUR.callTop++;
  3423. CUR.IP = pRec->Cur_Restart;
  3424. }
  3425. else
  3426. /* Loop through the current function */
  3427. INS_Goto_CodeRange( pRec->Caller_Range,
  3428. pRec->Caller_IP );
  3429. /* Exit the current call frame. */
  3430. /* NOTE: If the last intruction of a program is a */
  3431. /* CALL or LOOPCALL, the return address is */
  3432. /* always out of the code range. This is a */
  3433. /* valid address, and it is why we do not test */
  3434. /* the result of Ins_Goto_CodeRange() here! */
  3435. }
  3436. /*************************************************************************/
  3437. /* */
  3438. /* CALL[]: CALL function */
  3439. /* Opcode range: 0x2B */
  3440. /* Stack: uint32? --> */
  3441. /* */
  3442. static void
  3443. Ins_CALL( INS_ARG )
  3444. {
  3445. FT_ULong F;
  3446. TT_CallRec* pCrec;
  3447. TT_DefRecord* def;
  3448. /* first of all, check the index */
  3449. F = args[0];
  3450. if ( BOUNDS( F, CUR.maxFunc + 1 ) )
  3451. goto Fail;
  3452. /* Except for some old Apple fonts, all functions in a TrueType */
  3453. /* font are defined in increasing order, starting from 0. This */
  3454. /* means that we normally have */
  3455. /* */
  3456. /* CUR.maxFunc+1 == CUR.numFDefs */
  3457. /* CUR.FDefs[n].opc == n for n in 0..CUR.maxFunc */
  3458. /* */
  3459. /* If this isn't true, we need to look up the function table. */
  3460. def = CUR.FDefs + F;
  3461. if ( CUR.maxFunc + 1 != CUR.numFDefs || def->opc != F )
  3462. {
  3463. /* look up the FDefs table */
  3464. TT_DefRecord* limit;
  3465. def = CUR.FDefs;
  3466. limit = def + CUR.numFDefs;
  3467. while ( def < limit && def->opc != F )
  3468. def++;
  3469. if ( def == limit )
  3470. goto Fail;
  3471. }
  3472. /* check that the function is active */
  3473. if ( !def->active )
  3474. goto Fail;
  3475. /* check the call stack */
  3476. if ( CUR.callTop >= CUR.callSize )
  3477. {
  3478. CUR.error = TT_Err_Stack_Overflow;
  3479. return;
  3480. }
  3481. pCrec = CUR.callStack + CUR.callTop;
  3482. pCrec->Caller_Range = CUR.curRange;
  3483. pCrec->Caller_IP = CUR.IP + 1;
  3484. pCrec->Cur_Count = 1;
  3485. pCrec->Cur_Restart = def->start;
  3486. CUR.callTop++;
  3487. INS_Goto_CodeRange( def->range,
  3488. def->start );
  3489. CUR.step_ins = FALSE;
  3490. return;
  3491. Fail:
  3492. CUR.error = TT_Err_Invalid_Reference;
  3493. }
  3494. /*************************************************************************/
  3495. /* */
  3496. /* LOOPCALL[]: LOOP and CALL function */
  3497. /* Opcode range: 0x2A */
  3498. /* Stack: uint32? Eint16? --> */
  3499. /* */
  3500. static void
  3501. Ins_LOOPCALL( INS_ARG )
  3502. {
  3503. FT_ULong F;
  3504. TT_CallRec* pCrec;
  3505. TT_DefRecord* def;
  3506. /* first of all, check the index */
  3507. F = args[1];
  3508. if ( BOUNDS( F, CUR.maxFunc + 1 ) )
  3509. goto Fail;
  3510. /* Except for some old Apple fonts, all functions in a TrueType */
  3511. /* font are defined in increasing order, starting from 0. This */
  3512. /* means that we normally have */
  3513. /* */
  3514. /* CUR.maxFunc+1 == CUR.numFDefs */
  3515. /* CUR.FDefs[n].opc == n for n in 0..CUR.maxFunc */
  3516. /* */
  3517. /* If this isn't true, we need to look up the function table. */
  3518. def = CUR.FDefs + F;
  3519. if ( CUR.maxFunc + 1 != CUR.numFDefs || def->opc != F )
  3520. {
  3521. /* look up the FDefs table */
  3522. TT_DefRecord* limit;
  3523. def = CUR.FDefs;
  3524. limit = def + CUR.numFDefs;
  3525. while ( def < limit && def->opc != F )
  3526. def++;
  3527. if ( def == limit )
  3528. goto Fail;
  3529. }
  3530. /* check that the function is active */
  3531. if ( !def->active )
  3532. goto Fail;
  3533. /* check stack */
  3534. if ( CUR.callTop >= CUR.callSize )
  3535. {
  3536. CUR.error = TT_Err_Stack_Overflow;
  3537. return;
  3538. }
  3539. if ( args[0] > 0 )
  3540. {
  3541. pCrec = CUR.callStack + CUR.callTop;
  3542. pCrec->Caller_Range = CUR.curRange;
  3543. pCrec->Caller_IP = CUR.IP + 1;
  3544. pCrec->Cur_Count = (FT_Int)args[0];
  3545. pCrec->Cur_Restart = def->start;
  3546. CUR.callTop++;
  3547. INS_Goto_CodeRange( def->range, def->start );
  3548. CUR.step_ins = FALSE;
  3549. }
  3550. return;
  3551. Fail:
  3552. CUR.error = TT_Err_Invalid_Reference;
  3553. }
  3554. /*************************************************************************/
  3555. /* */
  3556. /* IDEF[]: Instruction DEFinition */
  3557. /* Opcode range: 0x89 */
  3558. /* Stack: Eint8 --> */
  3559. /* */
  3560. static void
  3561. Ins_IDEF( INS_ARG )
  3562. {
  3563. TT_DefRecord* def;
  3564. TT_DefRecord* limit;
  3565. /* First of all, look for the same function in our table */
  3566. def = CUR.IDefs;
  3567. limit = def + CUR.numIDefs;
  3568. for ( ; def < limit; def++ )
  3569. if ( def->opc == (FT_ULong)args[0] )
  3570. break;
  3571. if ( def == limit )
  3572. {
  3573. /* check that there is enough room for a new instruction */
  3574. if ( CUR.numIDefs >= CUR.maxIDefs )
  3575. {
  3576. CUR.error = TT_Err_Too_Many_Instruction_Defs;
  3577. return;
  3578. }
  3579. CUR.numIDefs++;
  3580. }
  3581. def->opc = args[0];
  3582. def->start = CUR.IP+1;
  3583. def->range = CUR.curRange;
  3584. def->active = TRUE;
  3585. if ( (FT_ULong)args[0] > CUR.maxIns )
  3586. CUR.maxIns = args[0];
  3587. /* Now skip the whole function definition. */
  3588. /* We don't allow nested IDEFs & FDEFs. */
  3589. while ( SKIP_Code() == SUCCESS )
  3590. {
  3591. switch ( CUR.opcode )
  3592. {
  3593. case 0x89: /* IDEF */
  3594. case 0x2C: /* FDEF */
  3595. CUR.error = TT_Err_Nested_DEFS;
  3596. return;
  3597. case 0x2D: /* ENDF */
  3598. return;
  3599. }
  3600. }
  3601. }
  3602. /*************************************************************************/
  3603. /* */
  3604. /* PUSHING DATA ONTO THE INTERPRETER STACK */
  3605. /* */
  3606. /* Instructions appear in the specification's order. */
  3607. /* */
  3608. /*************************************************************************/
  3609. /*************************************************************************/
  3610. /* */
  3611. /* NPUSHB[]: PUSH N Bytes */
  3612. /* Opcode range: 0x40 */
  3613. /* Stack: --> uint32... */
  3614. /* */
  3615. static void
  3616. Ins_NPUSHB( INS_ARG )
  3617. {
  3618. FT_UShort L, K;
  3619. L = (FT_UShort)CUR.code[CUR.IP + 1];
  3620. if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) )
  3621. {
  3622. CUR.error = TT_Err_Stack_Overflow;
  3623. return;
  3624. }
  3625. for ( K = 1; K <= L; K++ )
  3626. args[K - 1] = CUR.code[CUR.IP + K + 1];
  3627. CUR.new_top += L;
  3628. }
  3629. /*************************************************************************/
  3630. /* */
  3631. /* NPUSHW[]: PUSH N Words */
  3632. /* Opcode range: 0x41 */
  3633. /* Stack: --> int32... */
  3634. /* */
  3635. static void
  3636. Ins_NPUSHW( INS_ARG )
  3637. {
  3638. FT_UShort L, K;
  3639. L = (FT_UShort)CUR.code[CUR.IP + 1];
  3640. if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) )
  3641. {
  3642. CUR.error = TT_Err_Stack_Overflow;
  3643. return;
  3644. }
  3645. CUR.IP += 2;
  3646. for ( K = 0; K < L; K++ )
  3647. args[K] = GET_ShortIns();
  3648. CUR.step_ins = FALSE;
  3649. CUR.new_top += L;
  3650. }
  3651. /*************************************************************************/
  3652. /* */
  3653. /* PUSHB[abc]: PUSH Bytes */
  3654. /* Opcode range: 0xB0-0xB7 */
  3655. /* Stack: --> uint32... */
  3656. /* */
  3657. static void
  3658. Ins_PUSHB( INS_ARG )
  3659. {
  3660. FT_UShort L, K;
  3661. L = (FT_UShort)(CUR.opcode - 0xB0 + 1);
  3662. if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) )
  3663. {
  3664. CUR.error = TT_Err_Stack_Overflow;
  3665. return;
  3666. }
  3667. for ( K = 1; K <= L; K++ )
  3668. args[K - 1] = CUR.code[CUR.IP + K];
  3669. }
  3670. /*************************************************************************/
  3671. /* */
  3672. /* PUSHW[abc]: PUSH Words */
  3673. /* Opcode range: 0xB8-0xBF */
  3674. /* Stack: --> int32... */
  3675. /* */
  3676. static void
  3677. Ins_PUSHW( INS_ARG )
  3678. {
  3679. FT_UShort L, K;
  3680. L = (FT_UShort)(CUR.opcode - 0xB8 + 1);
  3681. if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) )
  3682. {
  3683. CUR.error = TT_Err_Stack_Overflow;
  3684. return;
  3685. }
  3686. CUR.IP++;
  3687. for ( K = 0; K < L; K++ )
  3688. args[K] = GET_ShortIns();
  3689. CUR.step_ins = FALSE;
  3690. }
  3691. /*************************************************************************/
  3692. /* */
  3693. /* MANAGING THE GRAPHICS STATE */
  3694. /* */
  3695. /* Instructions appear in the specs' order. */
  3696. /* */
  3697. /*************************************************************************/
  3698. /*************************************************************************/
  3699. /* */
  3700. /* GC[a]: Get Coordinate projected onto */
  3701. /* Opcode range: 0x46-0x47 */
  3702. /* Stack: uint32 --> f26.6 */
  3703. /* */
  3704. /* BULLSHIT: Measures from the original glyph must be taken along the */
  3705. /* dual projection vector! */
  3706. /* */
  3707. static void
  3708. Ins_GC( INS_ARG )
  3709. {
  3710. FT_ULong L;
  3711. FT_F26Dot6 R;
  3712. L = (FT_ULong)args[0];
  3713. if ( BOUNDS( L, CUR.zp2.n_points ) )
  3714. {
  3715. if ( CUR.pedantic_hinting )
  3716. {
  3717. CUR.error = TT_Err_Invalid_Reference;
  3718. return;
  3719. }
  3720. else
  3721. R = 0;
  3722. }
  3723. else
  3724. {
  3725. if ( CUR.opcode & 1 )
  3726. R = CUR_Func_dualproj( CUR.zp2.org + L, NULL_Vector );
  3727. else
  3728. R = CUR_Func_project( CUR.zp2.cur + L, NULL_Vector );
  3729. }
  3730. args[0] = R;
  3731. }
  3732. /*************************************************************************/
  3733. /* */
  3734. /* SCFS[]: Set Coordinate From Stack */
  3735. /* Opcode range: 0x48 */
  3736. /* Stack: f26.6 uint32 --> */
  3737. /* */
  3738. /* Formula: */
  3739. /* */
  3740. /* OA := OA + ( value - OA.p )/( f.p ) * f */
  3741. /* */
  3742. static void
  3743. Ins_SCFS( INS_ARG )
  3744. {
  3745. FT_Long K;
  3746. FT_UShort L;
  3747. L = (FT_UShort)args[0];
  3748. if ( BOUNDS( L, CUR.zp2.n_points ) )
  3749. {
  3750. if ( CUR.pedantic_hinting )
  3751. CUR.error = TT_Err_Invalid_Reference;
  3752. return;
  3753. }
  3754. K = CUR_Func_project( CUR.zp2.cur + L, NULL_Vector );
  3755. CUR_Func_move( &CUR.zp2, L, args[1] - K );
  3756. /* not part of the specs, but here for safety */
  3757. if ( CUR.GS.gep2 == 0 )
  3758. CUR.zp2.org[L] = CUR.zp2.cur[L];
  3759. }
  3760. /*************************************************************************/
  3761. /* */
  3762. /* MD[a]: Measure Distance */
  3763. /* Opcode range: 0x49-0x4A */
  3764. /* Stack: uint32 uint32 --> f26.6 */
  3765. /* */
  3766. /* BULLSHIT: Measure taken in the original glyph must be along the dual */
  3767. /* projection vector. */
  3768. /* */
  3769. /* Second BULLSHIT: Flag attributes are inverted! */
  3770. /* 0 => measure distance in original outline */
  3771. /* 1 => measure distance in grid-fitted outline */
  3772. /* */
  3773. /* Third one: `zp0 - zp1', and not `zp2 - zp1! */
  3774. /* */
  3775. static void
  3776. Ins_MD( INS_ARG )
  3777. {
  3778. FT_UShort K, L;
  3779. FT_F26Dot6 D;
  3780. K = (FT_UShort)args[1];
  3781. L = (FT_UShort)args[0];
  3782. if( BOUNDS( L, CUR.zp0.n_points ) ||
  3783. BOUNDS( K, CUR.zp1.n_points ) )
  3784. {
  3785. if ( CUR.pedantic_hinting )
  3786. {
  3787. CUR.error = TT_Err_Invalid_Reference;
  3788. return;
  3789. }
  3790. D = 0;
  3791. }
  3792. else
  3793. {
  3794. if ( CUR.opcode & 1 )
  3795. D = CUR_Func_project( CUR.zp0.cur + L, CUR.zp1.cur + K );
  3796. else
  3797. D = CUR_Func_dualproj( CUR.zp0.org + L, CUR.zp1.org + K );
  3798. }
  3799. args[0] = D;
  3800. }
  3801. /*************************************************************************/
  3802. /* */
  3803. /* SDPVTL[a]: Set Dual PVector to Line */
  3804. /* Opcode range: 0x86-0x87 */
  3805. /* Stack: uint32 uint32 --> */
  3806. /* */
  3807. static void
  3808. Ins_SDPVTL( INS_ARG )
  3809. {
  3810. FT_Long A, B, C;
  3811. FT_UShort p1, p2; /* was FT_Int in pas type ERROR */
  3812. p1 = (FT_UShort)args[1];
  3813. p2 = (FT_UShort)args[0];
  3814. if ( BOUNDS( p2, CUR.zp1.n_points ) ||
  3815. BOUNDS( p1, CUR.zp2.n_points ) )
  3816. {
  3817. if ( CUR.pedantic_hinting )
  3818. CUR.error = TT_Err_Invalid_Reference;
  3819. return;
  3820. }
  3821. {
  3822. FT_Vector* v1 = CUR.zp1.org + p2;
  3823. FT_Vector* v2 = CUR.zp2.org + p1;
  3824. A = v1->x - v2->x;
  3825. B = v1->y - v2->y;
  3826. }
  3827. if ( ( CUR.opcode & 1 ) != 0 )
  3828. {
  3829. C = B; /* counter clockwise rotation */
  3830. B = A;
  3831. A = -C;
  3832. }
  3833. NORMalize( A, B, &CUR.GS.dualVector );
  3834. {
  3835. FT_Vector* v1 = CUR.zp1.cur + p2;
  3836. FT_Vector* v2 = CUR.zp2.cur + p1;
  3837. A = v1->x - v2->x;
  3838. B = v1->y - v2->y;
  3839. }
  3840. if ( ( CUR.opcode & 1 ) != 0 )
  3841. {
  3842. C = B; /* counter clockwise rotation */
  3843. B = A;
  3844. A = -C;
  3845. }
  3846. NORMalize( A, B, &CUR.GS.projVector );
  3847. COMPUTE_Funcs();
  3848. }
  3849. /*************************************************************************/
  3850. /* */
  3851. /* SZP0[]: Set Zone Pointer 0 */
  3852. /* Opcode range: 0x13 */
  3853. /* Stack: uint32 --> */
  3854. /* */
  3855. static void
  3856. Ins_SZP0( INS_ARG )
  3857. {
  3858. switch ( (FT_Int)args[0] )
  3859. {
  3860. case 0:
  3861. CUR.zp0 = CUR.twilight;
  3862. break;
  3863. case 1:
  3864. CUR.zp0 = CUR.pts;
  3865. break;
  3866. default:
  3867. if ( CUR.pedantic_hinting )
  3868. CUR.error = TT_Err_Invalid_Reference;
  3869. return;
  3870. }
  3871. CUR.GS.gep0 = (FT_UShort)args[0];
  3872. }
  3873. /*************************************************************************/
  3874. /* */
  3875. /* SZP1[]: Set Zone Pointer 1 */
  3876. /* Opcode range: 0x14 */
  3877. /* Stack: uint32 --> */
  3878. /* */
  3879. static void
  3880. Ins_SZP1( INS_ARG )
  3881. {
  3882. switch ( (FT_Int)args[0] )
  3883. {
  3884. case 0:
  3885. CUR.zp1 = CUR.twilight;
  3886. break;
  3887. case 1:
  3888. CUR.zp1 = CUR.pts;
  3889. break;
  3890. default:
  3891. if ( CUR.pedantic_hinting )
  3892. CUR.error = TT_Err_Invalid_Reference;
  3893. return;
  3894. }
  3895. CUR.GS.gep1 = (FT_UShort)args[0];
  3896. }
  3897. /*************************************************************************/
  3898. /* */
  3899. /* SZP2[]: Set Zone Pointer 2 */
  3900. /* Opcode range: 0x15 */
  3901. /* Stack: uint32 --> */
  3902. /* */
  3903. static void
  3904. Ins_SZP2( INS_ARG )
  3905. {
  3906. switch ( (FT_Int)args[0] )
  3907. {
  3908. case 0:
  3909. CUR.zp2 = CUR.twilight;
  3910. break;
  3911. case 1:
  3912. CUR.zp2 = CUR.pts;
  3913. break;
  3914. default:
  3915. if ( CUR.pedantic_hinting )
  3916. CUR.error = TT_Err_Invalid_Reference;
  3917. return;
  3918. }
  3919. CUR.GS.gep2 = (FT_UShort)args[0];
  3920. }
  3921. /*************************************************************************/
  3922. /* */
  3923. /* SZPS[]: Set Zone PointerS */
  3924. /* Opcode range: 0x16 */
  3925. /* Stack: uint32 --> */
  3926. /* */
  3927. static void
  3928. Ins_SZPS( INS_ARG )
  3929. {
  3930. switch ( (FT_Int)args[0] )
  3931. {
  3932. case 0:
  3933. CUR.zp0 = CUR.twilight;
  3934. break;
  3935. case 1:
  3936. CUR.zp0 = CUR.pts;
  3937. break;
  3938. default:
  3939. if ( CUR.pedantic_hinting )
  3940. CUR.error = TT_Err_Invalid_Reference;
  3941. return;
  3942. }
  3943. CUR.zp1 = CUR.zp0;
  3944. CUR.zp2 = CUR.zp0;
  3945. CUR.GS.gep0 = (FT_UShort)args[0];
  3946. CUR.GS.gep1 = (FT_UShort)args[0];
  3947. CUR.GS.gep2 = (FT_UShort)args[0];
  3948. }
  3949. /*************************************************************************/
  3950. /* */
  3951. /* INSTCTRL[]: INSTruction ConTRoL */
  3952. /* Opcode range: 0x8e */
  3953. /* Stack: int32 int32 --> */
  3954. /* */
  3955. static void
  3956. Ins_INSTCTRL( INS_ARG )
  3957. {
  3958. FT_Long K, L;
  3959. K = args[1];
  3960. L = args[0];
  3961. if ( K < 1 || K > 2 )
  3962. {
  3963. if ( CUR.pedantic_hinting )
  3964. CUR.error = TT_Err_Invalid_Reference;
  3965. return;
  3966. }
  3967. if ( L != 0 )
  3968. L = K;
  3969. CUR.GS.instruct_control = FT_BOOL(
  3970. ( (FT_Byte)CUR.GS.instruct_control & ~(FT_Byte)K ) | (FT_Byte)L );
  3971. }
  3972. /*************************************************************************/
  3973. /* */
  3974. /* SCANCTRL[]: SCAN ConTRoL */
  3975. /* Opcode range: 0x85 */
  3976. /* Stack: uint32? --> */
  3977. /* */
  3978. static void
  3979. Ins_SCANCTRL( INS_ARG )
  3980. {
  3981. FT_Int A;
  3982. /* Get Threshold */
  3983. A = (FT_Int)( args[0] & 0xFF );
  3984. if ( A == 0xFF )
  3985. {
  3986. CUR.GS.scan_control = TRUE;
  3987. return;
  3988. }
  3989. else if ( A == 0 )
  3990. {
  3991. CUR.GS.scan_control = FALSE;
  3992. return;
  3993. }
  3994. A *= 64;
  3995. #if 0
  3996. if ( (args[0] & 0x100) != 0 && CUR.metrics.pointSize <= A )
  3997. CUR.GS.scan_control = TRUE;
  3998. #endif
  3999. if ( (args[0] & 0x200) != 0 && CUR.tt_metrics.rotated )
  4000. CUR.GS.scan_control = TRUE;
  4001. if ( (args[0] & 0x400) != 0 && CUR.tt_metrics.stretched )
  4002. CUR.GS.scan_control = TRUE;
  4003. #if 0
  4004. if ( (args[0] & 0x800) != 0 && CUR.metrics.pointSize > A )
  4005. CUR.GS.scan_control = FALSE;
  4006. #endif
  4007. if ( (args[0] & 0x1000) != 0 && CUR.tt_metrics.rotated )
  4008. CUR.GS.scan_control = FALSE;
  4009. if ( (args[0] & 0x2000) != 0 && CUR.tt_metrics.stretched )
  4010. CUR.GS.scan_control = FALSE;
  4011. }
  4012. /*************************************************************************/
  4013. /* */
  4014. /* SCANTYPE[]: SCAN TYPE */
  4015. /* Opcode range: 0x8D */
  4016. /* Stack: uint32? --> */
  4017. /* */
  4018. static void
  4019. Ins_SCANTYPE( INS_ARG )
  4020. {
  4021. /* for compatibility with future enhancements, */
  4022. /* we must ignore new modes */
  4023. if ( args[0] >= 0 && args[0] <= 5 )
  4024. {
  4025. if ( args[0] == 3 )
  4026. args[0] = 2;
  4027. CUR.GS.scan_type = (FT_Int)args[0];
  4028. }
  4029. }
  4030. /*************************************************************************/
  4031. /* */
  4032. /* MANAGING OUTLINES */
  4033. /* */
  4034. /* Instructions appear in the specification's order. */
  4035. /* */
  4036. /*************************************************************************/
  4037. /*************************************************************************/
  4038. /* */
  4039. /* FLIPPT[]: FLIP PoinT */
  4040. /* Opcode range: 0x80 */
  4041. /* Stack: uint32... --> */
  4042. /* */
  4043. static void
  4044. Ins_FLIPPT( INS_ARG )
  4045. {
  4046. FT_UShort point;
  4047. FT_UNUSED_ARG;
  4048. if ( CUR.top < CUR.GS.loop )
  4049. {
  4050. CUR.error = TT_Err_Too_Few_Arguments;
  4051. return;
  4052. }
  4053. while ( CUR.GS.loop > 0 )
  4054. {
  4055. CUR.args--;
  4056. point = (FT_UShort)CUR.stack[CUR.args];
  4057. if ( BOUNDS( point, CUR.pts.n_points ) )
  4058. {
  4059. if ( CUR.pedantic_hinting )
  4060. {
  4061. CUR.error = TT_Err_Invalid_Reference;
  4062. return;
  4063. }
  4064. }
  4065. else
  4066. CUR.pts.tags[point] ^= FT_CURVE_TAG_ON;
  4067. CUR.GS.loop--;
  4068. }
  4069. CUR.GS.loop = 1;
  4070. CUR.new_top = CUR.args;
  4071. }
  4072. /*************************************************************************/
  4073. /* */
  4074. /* FLIPRGON[]: FLIP RanGe ON */
  4075. /* Opcode range: 0x81 */
  4076. /* Stack: uint32 uint32 --> */
  4077. /* */
  4078. static void
  4079. Ins_FLIPRGON( INS_ARG )
  4080. {
  4081. FT_UShort I, K, L;
  4082. K = (FT_UShort)args[1];
  4083. L = (FT_UShort)args[0];
  4084. if ( BOUNDS( K, CUR.pts.n_points ) ||
  4085. BOUNDS( L, CUR.pts.n_points ) )
  4086. {
  4087. if ( CUR.pedantic_hinting )
  4088. CUR.error = TT_Err_Invalid_Reference;
  4089. return;
  4090. }
  4091. for ( I = L; I <= K; I++ )
  4092. CUR.pts.tags[I] |= FT_CURVE_TAG_ON;
  4093. }
  4094. /*************************************************************************/
  4095. /* */
  4096. /* FLIPRGOFF: FLIP RanGe OFF */
  4097. /* Opcode range: 0x82 */
  4098. /* Stack: uint32 uint32 --> */
  4099. /* */
  4100. static void
  4101. Ins_FLIPRGOFF( INS_ARG )
  4102. {
  4103. FT_UShort I, K, L;
  4104. K = (FT_UShort)args[1];
  4105. L = (FT_UShort)args[0];
  4106. if ( BOUNDS( K, CUR.pts.n_points ) ||
  4107. BOUNDS( L, CUR.pts.n_points ) )
  4108. {
  4109. if ( CUR.pedantic_hinting )
  4110. CUR.error = TT_Err_Invalid_Reference;
  4111. return;
  4112. }
  4113. for ( I = L; I <= K; I++ )
  4114. CUR.pts.tags[I] &= ~FT_CURVE_TAG_ON;
  4115. }
  4116. static FT_Bool
  4117. Compute_Point_Displacement( EXEC_OP_ FT_F26Dot6* x,
  4118. FT_F26Dot6* y,
  4119. TT_GlyphZone zone,
  4120. FT_UShort* refp )
  4121. {
  4122. TT_GlyphZoneRec zp;
  4123. FT_UShort p;
  4124. FT_F26Dot6 d;
  4125. if ( CUR.opcode & 1 )
  4126. {
  4127. zp = CUR.zp0;
  4128. p = CUR.GS.rp1;
  4129. }
  4130. else
  4131. {
  4132. zp = CUR.zp1;
  4133. p = CUR.GS.rp2;
  4134. }
  4135. if ( BOUNDS( p, zp.n_points ) )
  4136. {
  4137. if ( CUR.pedantic_hinting )
  4138. CUR.error = TT_Err_Invalid_Reference;
  4139. return FAILURE;
  4140. }
  4141. *zone = zp;
  4142. *refp = p;
  4143. d = CUR_Func_project( zp.cur + p, zp.org + p );
  4144. #ifdef NO_APPLE_PATENT
  4145. *x = TT_MulFix14( d, CUR.GS.freeVector.x );
  4146. *y = TT_MulFix14( d, CUR.GS.freeVector.y );
  4147. #else
  4148. *x = TT_MULDIV( d,
  4149. (FT_Long)CUR.GS.freeVector.x * 0x10000L,
  4150. CUR.F_dot_P );
  4151. *y = TT_MULDIV( d,
  4152. (FT_Long)CUR.GS.freeVector.y * 0x10000L,
  4153. CUR.F_dot_P );
  4154. #endif /* NO_APPLE_PATENT */
  4155. return SUCCESS;
  4156. }
  4157. static void
  4158. Move_Zp2_Point( EXEC_OP_ FT_UShort point,
  4159. FT_F26Dot6 dx,
  4160. FT_F26Dot6 dy,
  4161. FT_Bool touch )
  4162. {
  4163. if ( CUR.GS.freeVector.x != 0 )
  4164. {
  4165. CUR.zp2.cur[point].x += dx;
  4166. if ( touch )
  4167. CUR.zp2.tags[point] |= FT_CURVE_TAG_TOUCH_X;
  4168. }
  4169. if ( CUR.GS.freeVector.y != 0 )
  4170. {
  4171. CUR.zp2.cur[point].y += dy;
  4172. if ( touch )
  4173. CUR.zp2.tags[point] |= FT_CURVE_TAG_TOUCH_Y;
  4174. }
  4175. }
  4176. /*************************************************************************/
  4177. /* */
  4178. /* SHP[a]: SHift Point by the last point */
  4179. /* Opcode range: 0x32-0x33 */
  4180. /* Stack: uint32... --> */
  4181. /* */
  4182. static void
  4183. Ins_SHP( INS_ARG )
  4184. {
  4185. TT_GlyphZoneRec zp;
  4186. FT_UShort refp;
  4187. FT_F26Dot6 dx,
  4188. dy;
  4189. FT_UShort point;
  4190. FT_UNUSED_ARG;
  4191. if ( CUR.top < CUR.GS.loop )
  4192. {
  4193. CUR.error = TT_Err_Invalid_Reference;
  4194. return;
  4195. }
  4196. if ( COMPUTE_Point_Displacement( &dx, &dy, &zp, &refp ) )
  4197. return;
  4198. while ( CUR.GS.loop > 0 )
  4199. {
  4200. CUR.args--;
  4201. point = (FT_UShort)CUR.stack[CUR.args];
  4202. if ( BOUNDS( point, CUR.zp2.n_points ) )
  4203. {
  4204. if ( CUR.pedantic_hinting )
  4205. {
  4206. CUR.error = TT_Err_Invalid_Reference;
  4207. return;
  4208. }
  4209. }
  4210. else
  4211. /* XXX: UNDOCUMENTED! SHP touches the points */
  4212. MOVE_Zp2_Point( point, dx, dy, TRUE );
  4213. CUR.GS.loop--;
  4214. }
  4215. CUR.GS.loop = 1;
  4216. CUR.new_top = CUR.args;
  4217. }
  4218. /*************************************************************************/
  4219. /* */
  4220. /* SHC[a]: SHift Contour */
  4221. /* Opcode range: 0x34-35 */
  4222. /* Stack: uint32 --> */
  4223. /* */
  4224. static void
  4225. Ins_SHC( INS_ARG )
  4226. {
  4227. TT_GlyphZoneRec zp;
  4228. FT_UShort refp;
  4229. FT_F26Dot6 dx,
  4230. dy;
  4231. FT_Short contour;
  4232. FT_UShort first_point, last_point, i;
  4233. contour = (FT_UShort)args[0];
  4234. if ( BOUNDS( contour, CUR.pts.n_contours ) )
  4235. {
  4236. if ( CUR.pedantic_hinting )
  4237. CUR.error = TT_Err_Invalid_Reference;
  4238. return;
  4239. }
  4240. if ( COMPUTE_Point_Displacement( &dx, &dy, &zp, &refp ) )
  4241. return;
  4242. if ( contour == 0 )
  4243. first_point = 0;
  4244. else
  4245. first_point = (FT_UShort)(CUR.pts.contours[contour - 1] + 1);
  4246. last_point = CUR.pts.contours[contour];
  4247. /* XXX: this is probably wrong... at least it prevents memory */
  4248. /* corruption when zp2 is the twilight zone */
  4249. if ( last_point > CUR.zp2.n_points )
  4250. {
  4251. if ( CUR.zp2.n_points > 0 )
  4252. last_point = (FT_UShort)(CUR.zp2.n_points - 1);
  4253. else
  4254. last_point = 0;
  4255. }
  4256. /* XXX: UNDOCUMENTED! SHC doesn't touch the points */
  4257. for ( i = first_point; i <= last_point; i++ )
  4258. {
  4259. if ( zp.cur != CUR.zp2.cur || refp != i )
  4260. MOVE_Zp2_Point( i, dx, dy, FALSE );
  4261. }
  4262. }
  4263. /*************************************************************************/
  4264. /* */
  4265. /* SHZ[a]: SHift Zone */
  4266. /* Opcode range: 0x36-37 */
  4267. /* Stack: uint32 --> */
  4268. /* */
  4269. static void
  4270. Ins_SHZ( INS_ARG )
  4271. {
  4272. TT_GlyphZoneRec zp;
  4273. FT_UShort refp;
  4274. FT_F26Dot6 dx,
  4275. dy;
  4276. FT_UShort last_point, i;
  4277. if ( BOUNDS( args[0], 2 ) )
  4278. {
  4279. if ( CUR.pedantic_hinting )
  4280. CUR.error = TT_Err_Invalid_Reference;
  4281. return;
  4282. }
  4283. if ( COMPUTE_Point_Displacement( &dx, &dy, &zp, &refp ) )
  4284. return;
  4285. if ( CUR.zp2.n_points > 0 )
  4286. last_point = (FT_UShort)(CUR.zp2.n_points - 1);
  4287. else
  4288. last_point = 0;
  4289. /* XXX: UNDOCUMENTED! SHZ doesn't touch the points */
  4290. for ( i = 0; i <= last_point; i++ )
  4291. {
  4292. if ( zp.cur != CUR.zp2.cur || refp != i )
  4293. MOVE_Zp2_Point( i, dx, dy, FALSE );
  4294. }
  4295. }
  4296. /*************************************************************************/
  4297. /* */
  4298. /* SHPIX[]: SHift points by a PIXel amount */
  4299. /* Opcode range: 0x38 */
  4300. /* Stack: f26.6 uint32... --> */
  4301. /* */
  4302. static void
  4303. Ins_SHPIX( INS_ARG )
  4304. {
  4305. FT_F26Dot6 dx, dy;
  4306. FT_UShort point;
  4307. if ( CUR.top < CUR.GS.loop + 1 )
  4308. {
  4309. CUR.error = TT_Err_Invalid_Reference;
  4310. return;
  4311. }
  4312. dx = TT_MulFix14( args[0], CUR.GS.freeVector.x );
  4313. dy = TT_MulFix14( args[0], CUR.GS.freeVector.y );
  4314. while ( CUR.GS.loop > 0 )
  4315. {
  4316. CUR.args--;
  4317. point = (FT_UShort)CUR.stack[CUR.args];
  4318. if ( BOUNDS( point, CUR.zp2.n_points ) )
  4319. {
  4320. if ( CUR.pedantic_hinting )
  4321. {
  4322. CUR.error = TT_Err_Invalid_Reference;
  4323. return;
  4324. }
  4325. }
  4326. else
  4327. MOVE_Zp2_Point( point, dx, dy, TRUE );
  4328. CUR.GS.loop--;
  4329. }
  4330. CUR.GS.loop = 1;
  4331. CUR.new_top = CUR.args;
  4332. }
  4333. /*************************************************************************/
  4334. /* */
  4335. /* MSIRP[a]: Move Stack Indirect Relative Position */
  4336. /* Opcode range: 0x3A-0x3B */
  4337. /* Stack: f26.6 uint32 --> */
  4338. /* */
  4339. static void
  4340. Ins_MSIRP( INS_ARG )
  4341. {
  4342. FT_UShort point;
  4343. FT_F26Dot6 distance;
  4344. point = (FT_UShort)args[0];
  4345. if ( BOUNDS( point, CUR.zp1.n_points ) ||
  4346. BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) )
  4347. {
  4348. if ( CUR.pedantic_hinting )
  4349. CUR.error = TT_Err_Invalid_Reference;
  4350. return;
  4351. }
  4352. /* XXX: UNDOCUMENTED! behaviour */
  4353. if ( CUR.GS.gep0 == 0 ) /* if in twilight zone */
  4354. {
  4355. CUR.zp1.org[point] = CUR.zp0.org[CUR.GS.rp0];
  4356. CUR.zp1.cur[point] = CUR.zp1.org[point];
  4357. }
  4358. distance = CUR_Func_project( CUR.zp1.cur + point,
  4359. CUR.zp0.cur + CUR.GS.rp0 );
  4360. CUR_Func_move( &CUR.zp1, point, args[1] - distance );
  4361. CUR.GS.rp1 = CUR.GS.rp0;
  4362. CUR.GS.rp2 = point;
  4363. if ( (CUR.opcode & 1) != 0 )
  4364. CUR.GS.rp0 = point;
  4365. }
  4366. /*************************************************************************/
  4367. /* */
  4368. /* MDAP[a]: Move Direct Absolute Point */
  4369. /* Opcode range: 0x2E-0x2F */
  4370. /* Stack: uint32 --> */
  4371. /* */
  4372. static void
  4373. Ins_MDAP( INS_ARG )
  4374. {
  4375. FT_UShort point;
  4376. FT_F26Dot6 cur_dist,
  4377. distance;
  4378. point = (FT_UShort)args[0];
  4379. if ( BOUNDS( point, CUR.zp0.n_points ) )
  4380. {
  4381. if ( CUR.pedantic_hinting )
  4382. CUR.error = TT_Err_Invalid_Reference;
  4383. return;
  4384. }
  4385. /* XXX: Is there some undocumented feature while in the */
  4386. /* twilight zone? ? */
  4387. if ( ( CUR.opcode & 1 ) != 0 )
  4388. {
  4389. cur_dist = CUR_Func_project( CUR.zp0.cur + point, NULL_Vector );
  4390. distance = CUR_Func_round( cur_dist,
  4391. CUR.tt_metrics.compensations[0] ) - cur_dist;
  4392. }
  4393. else
  4394. distance = 0;
  4395. CUR_Func_move( &CUR.zp0, point, distance );
  4396. CUR.GS.rp0 = point;
  4397. CUR.GS.rp1 = point;
  4398. }
  4399. /*************************************************************************/
  4400. /* */
  4401. /* MIAP[a]: Move Indirect Absolute Point */
  4402. /* Opcode range: 0x3E-0x3F */
  4403. /* Stack: uint32 uint32 --> */
  4404. /* */
  4405. static void
  4406. Ins_MIAP( INS_ARG )
  4407. {
  4408. FT_ULong cvtEntry;
  4409. FT_UShort point;
  4410. FT_F26Dot6 distance,
  4411. org_dist;
  4412. cvtEntry = (FT_ULong)args[1];
  4413. point = (FT_UShort)args[0];
  4414. if ( BOUNDS( point, CUR.zp0.n_points ) ||
  4415. BOUNDS( cvtEntry, CUR.cvtSize ) )
  4416. {
  4417. if ( CUR.pedantic_hinting )
  4418. CUR.error = TT_Err_Invalid_Reference;
  4419. return;
  4420. }
  4421. /* UNDOCUMENTED! */
  4422. /* */
  4423. /* The behaviour of an MIAP instruction is quite */
  4424. /* different when used in the twilight zone. */
  4425. /* */
  4426. /* First, no control value cutin test is performed */
  4427. /* as it would fail anyway. Second, the original */
  4428. /* point, i.e. (org_x,org_y) of zp0.point, is set */
  4429. /* to the absolute, unrounded distance found in */
  4430. /* the CVT. */
  4431. /* */
  4432. /* This is used in the CVT programs of the Microsoft */
  4433. /* fonts Arial, Times, etc., in order to re-adjust */
  4434. /* some key font heights. It allows the use of the */
  4435. /* IP instruction in the twilight zone, which */
  4436. /* otherwise would be `illegal' according to the */
  4437. /* specification. */
  4438. /* */
  4439. /* We implement it with a special sequence for the */
  4440. /* twilight zone. This is a bad hack, but it seems */
  4441. /* to work. */
  4442. distance = CUR_Func_read_cvt( cvtEntry );
  4443. if ( CUR.GS.gep0 == 0 ) /* If in twilight zone */
  4444. {
  4445. CUR.zp0.org[point].x = TT_MulFix14( distance, CUR.GS.freeVector.x );
  4446. CUR.zp0.org[point].y = TT_MulFix14( distance, CUR.GS.freeVector.y ),
  4447. CUR.zp0.cur[point] = CUR.zp0.org[point];
  4448. }
  4449. org_dist = CUR_Func_project( CUR.zp0.cur + point, NULL_Vector );
  4450. if ( ( CUR.opcode & 1 ) != 0 ) /* rounding and control cutin flag */
  4451. {
  4452. if ( ABS( distance - org_dist ) > CUR.GS.control_value_cutin )
  4453. distance = org_dist;
  4454. distance = CUR_Func_round( distance, CUR.tt_metrics.compensations[0] );
  4455. }
  4456. CUR_Func_move( &CUR.zp0, point, distance - org_dist );
  4457. CUR.GS.rp0 = point;
  4458. CUR.GS.rp1 = point;
  4459. }
  4460. /*************************************************************************/
  4461. /* */
  4462. /* MDRP[abcde]: Move Direct Relative Point */
  4463. /* Opcode range: 0xC0-0xDF */
  4464. /* Stack: uint32 --> */
  4465. /* */
  4466. static void
  4467. Ins_MDRP( INS_ARG )
  4468. {
  4469. FT_UShort point;
  4470. FT_F26Dot6 org_dist, distance;
  4471. point = (FT_UShort)args[0];
  4472. if ( BOUNDS( point, CUR.zp1.n_points ) ||
  4473. BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) )
  4474. {
  4475. if ( CUR.pedantic_hinting )
  4476. CUR.error = TT_Err_Invalid_Reference;
  4477. return;
  4478. }
  4479. /* XXX: Is there some undocumented feature while in the */
  4480. /* twilight zone? */
  4481. org_dist = CUR_Func_dualproj( CUR.zp1.org + point,
  4482. CUR.zp0.org + CUR.GS.rp0 );
  4483. /* single width cutin test */
  4484. if ( ABS( org_dist ) < CUR.GS.single_width_cutin )
  4485. {
  4486. if ( org_dist >= 0 )
  4487. org_dist = CUR.GS.single_width_value;
  4488. else
  4489. org_dist = -CUR.GS.single_width_value;
  4490. }
  4491. /* round flag */
  4492. if ( ( CUR.opcode & 4 ) != 0 )
  4493. distance = CUR_Func_round(
  4494. org_dist,
  4495. CUR.tt_metrics.compensations[CUR.opcode & 3] );
  4496. else
  4497. distance = ROUND_None(
  4498. org_dist,
  4499. CUR.tt_metrics.compensations[CUR.opcode & 3] );
  4500. /* minimum distance flag */
  4501. if ( ( CUR.opcode & 8 ) != 0 )
  4502. {
  4503. if ( org_dist >= 0 )
  4504. {
  4505. if ( distance < CUR.GS.minimum_distance )
  4506. distance = CUR.GS.minimum_distance;
  4507. }
  4508. else
  4509. {
  4510. if ( distance > -CUR.GS.minimum_distance )
  4511. distance = -CUR.GS.minimum_distance;
  4512. }
  4513. }
  4514. /* now move the point */
  4515. org_dist = CUR_Func_project( CUR.zp1.cur + point,
  4516. CUR.zp0.cur + CUR.GS.rp0 );
  4517. CUR_Func_move( &CUR.zp1, point, distance - org_dist );
  4518. CUR.GS.rp1 = CUR.GS.rp0;
  4519. CUR.GS.rp2 = point;
  4520. if ( ( CUR.opcode & 16 ) != 0 )
  4521. CUR.GS.rp0 = point;
  4522. }
  4523. /*************************************************************************/
  4524. /* */
  4525. /* MIRP[abcde]: Move Indirect Relative Point */
  4526. /* Opcode range: 0xE0-0xFF */
  4527. /* Stack: int32? uint32 --> */
  4528. /* */
  4529. static void
  4530. Ins_MIRP( INS_ARG )
  4531. {
  4532. FT_UShort point;
  4533. FT_ULong cvtEntry;
  4534. FT_F26Dot6 cvt_dist,
  4535. distance,
  4536. cur_dist,
  4537. org_dist;
  4538. point = (FT_UShort)args[0];
  4539. cvtEntry = (FT_ULong)( args[1] + 1 );
  4540. /* XXX: UNDOCUMENTED! cvt[-1] = 0 always */
  4541. if ( BOUNDS( point, CUR.zp1.n_points ) ||
  4542. BOUNDS( cvtEntry, CUR.cvtSize + 1 ) ||
  4543. BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) )
  4544. {
  4545. if ( CUR.pedantic_hinting )
  4546. CUR.error = TT_Err_Invalid_Reference;
  4547. return;
  4548. }
  4549. if ( !cvtEntry )
  4550. cvt_dist = 0;
  4551. else
  4552. cvt_dist = CUR_Func_read_cvt( cvtEntry - 1 );
  4553. /* single width test */
  4554. if ( ABS( cvt_dist ) < CUR.GS.single_width_cutin )
  4555. {
  4556. if ( cvt_dist >= 0 )
  4557. cvt_dist = CUR.GS.single_width_value;
  4558. else
  4559. cvt_dist = -CUR.GS.single_width_value;
  4560. }
  4561. /* XXX: UNDOCUMENTED! -- twilight zone */
  4562. if ( CUR.GS.gep1 == 0 )
  4563. {
  4564. CUR.zp1.org[point].x = CUR.zp0.org[CUR.GS.rp0].x +
  4565. TT_MulFix14( cvt_dist, CUR.GS.freeVector.x );
  4566. CUR.zp1.org[point].y = CUR.zp0.org[CUR.GS.rp0].y +
  4567. TT_MulFix14( cvt_dist, CUR.GS.freeVector.y );
  4568. CUR.zp1.cur[point] = CUR.zp1.org[point];
  4569. }
  4570. org_dist = CUR_Func_dualproj( CUR.zp1.org + point,
  4571. CUR.zp0.org + CUR.GS.rp0 );
  4572. cur_dist = CUR_Func_project( CUR.zp1.cur + point,
  4573. CUR.zp0.cur + CUR.GS.rp0 );
  4574. /* auto-flip test */
  4575. if ( CUR.GS.auto_flip )
  4576. {
  4577. if ( ( org_dist ^ cvt_dist ) < 0 )
  4578. cvt_dist = -cvt_dist;
  4579. }
  4580. /* control value cutin and round */
  4581. if ( ( CUR.opcode & 4 ) != 0 )
  4582. {
  4583. /* XXX: UNDOCUMENTED! Only perform cut-in test when both points */
  4584. /* refer to the same zone. */
  4585. if ( CUR.GS.gep0 == CUR.GS.gep1 )
  4586. if ( ABS( cvt_dist - org_dist ) >= CUR.GS.control_value_cutin )
  4587. cvt_dist = org_dist;
  4588. distance = CUR_Func_round(
  4589. cvt_dist,
  4590. CUR.tt_metrics.compensations[CUR.opcode & 3] );
  4591. }
  4592. else
  4593. distance = ROUND_None(
  4594. cvt_dist,
  4595. CUR.tt_metrics.compensations[CUR.opcode & 3] );
  4596. /* minimum distance test */
  4597. if ( ( CUR.opcode & 8 ) != 0 )
  4598. {
  4599. if ( org_dist >= 0 )
  4600. {
  4601. if ( distance < CUR.GS.minimum_distance )
  4602. distance = CUR.GS.minimum_distance;
  4603. }
  4604. else
  4605. {
  4606. if ( distance > -CUR.GS.minimum_distance )
  4607. distance = -CUR.GS.minimum_distance;
  4608. }
  4609. }
  4610. CUR_Func_move( &CUR.zp1, point, distance - cur_dist );
  4611. CUR.GS.rp1 = CUR.GS.rp0;
  4612. if ( ( CUR.opcode & 16 ) != 0 )
  4613. CUR.GS.rp0 = point;
  4614. /* XXX: UNDOCUMENTED! */
  4615. CUR.GS.rp2 = point;
  4616. }
  4617. /*************************************************************************/
  4618. /* */
  4619. /* ALIGNRP[]: ALIGN Relative Point */
  4620. /* Opcode range: 0x3C */
  4621. /* Stack: uint32 uint32... --> */
  4622. /* */
  4623. static void
  4624. Ins_ALIGNRP( INS_ARG )
  4625. {
  4626. FT_UShort point;
  4627. FT_F26Dot6 distance;
  4628. FT_UNUSED_ARG;
  4629. if ( CUR.top < CUR.GS.loop ||
  4630. BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) )
  4631. {
  4632. if ( CUR.pedantic_hinting )
  4633. CUR.error = TT_Err_Invalid_Reference;
  4634. return;
  4635. }
  4636. while ( CUR.GS.loop > 0 )
  4637. {
  4638. CUR.args--;
  4639. point = (FT_UShort)CUR.stack[CUR.args];
  4640. if ( BOUNDS( point, CUR.zp1.n_points ) )
  4641. {
  4642. if ( CUR.pedantic_hinting )
  4643. {
  4644. CUR.error = TT_Err_Invalid_Reference;
  4645. return;
  4646. }
  4647. }
  4648. else
  4649. {
  4650. distance = CUR_Func_project( CUR.zp1.cur + point,
  4651. CUR.zp0.cur + CUR.GS.rp0 );
  4652. CUR_Func_move( &CUR.zp1, point, -distance );
  4653. }
  4654. CUR.GS.loop--;
  4655. }
  4656. CUR.GS.loop = 1;
  4657. CUR.new_top = CUR.args;
  4658. }
  4659. /*************************************************************************/
  4660. /* */
  4661. /* ISECT[]: moves point to InterSECTion */
  4662. /* Opcode range: 0x0F */
  4663. /* Stack: 5 * uint32 --> */
  4664. /* */
  4665. static void
  4666. Ins_ISECT( INS_ARG )
  4667. {
  4668. FT_UShort point,
  4669. a0, a1,
  4670. b0, b1;
  4671. FT_F26Dot6 discriminant;
  4672. FT_F26Dot6 dx, dy,
  4673. dax, day,
  4674. dbx, dby;
  4675. FT_F26Dot6 val;
  4676. FT_Vector R;
  4677. point = (FT_UShort)args[0];
  4678. a0 = (FT_UShort)args[1];
  4679. a1 = (FT_UShort)args[2];
  4680. b0 = (FT_UShort)args[3];
  4681. b1 = (FT_UShort)args[4];
  4682. if ( BOUNDS( b0, CUR.zp0.n_points ) ||
  4683. BOUNDS( b1, CUR.zp0.n_points ) ||
  4684. BOUNDS( a0, CUR.zp1.n_points ) ||
  4685. BOUNDS( a1, CUR.zp1.n_points ) ||
  4686. BOUNDS( point, CUR.zp2.n_points ) )
  4687. {
  4688. if ( CUR.pedantic_hinting )
  4689. CUR.error = TT_Err_Invalid_Reference;
  4690. return;
  4691. }
  4692. dbx = CUR.zp0.cur[b1].x - CUR.zp0.cur[b0].x;
  4693. dby = CUR.zp0.cur[b1].y - CUR.zp0.cur[b0].y;
  4694. dax = CUR.zp1.cur[a1].x - CUR.zp1.cur[a0].x;
  4695. day = CUR.zp1.cur[a1].y - CUR.zp1.cur[a0].y;
  4696. dx = CUR.zp0.cur[b0].x - CUR.zp1.cur[a0].x;
  4697. dy = CUR.zp0.cur[b0].y - CUR.zp1.cur[a0].y;
  4698. CUR.zp2.tags[point] |= FT_CURVE_TAG_TOUCH_BOTH;
  4699. discriminant = TT_MULDIV( dax, -dby, 0x40 ) +
  4700. TT_MULDIV( day, dbx, 0x40 );
  4701. if ( ABS( discriminant ) >= 0x40 )
  4702. {
  4703. val = TT_MULDIV( dx, -dby, 0x40 ) + TT_MULDIV( dy, dbx, 0x40 );
  4704. R.x = TT_MULDIV( val, dax, discriminant );
  4705. R.y = TT_MULDIV( val, day, discriminant );
  4706. CUR.zp2.cur[point].x = CUR.zp1.cur[a0].x + R.x;
  4707. CUR.zp2.cur[point].y = CUR.zp1.cur[a0].y + R.y;
  4708. }
  4709. else
  4710. {
  4711. /* else, take the middle of the middles of A and B */
  4712. CUR.zp2.cur[point].x = ( CUR.zp1.cur[a0].x +
  4713. CUR.zp1.cur[a1].x +
  4714. CUR.zp0.cur[b0].x +
  4715. CUR.zp0.cur[b1].x ) / 4;
  4716. CUR.zp2.cur[point].y = ( CUR.zp1.cur[a0].y +
  4717. CUR.zp1.cur[a1].y +
  4718. CUR.zp0.cur[b0].y +
  4719. CUR.zp0.cur[b1].y ) / 4;
  4720. }
  4721. }
  4722. /*************************************************************************/
  4723. /* */
  4724. /* ALIGNPTS[]: ALIGN PoinTS */
  4725. /* Opcode range: 0x27 */
  4726. /* Stack: uint32 uint32 --> */
  4727. /* */
  4728. static void
  4729. Ins_ALIGNPTS( INS_ARG )
  4730. {
  4731. FT_UShort p1, p2;
  4732. FT_F26Dot6 distance;
  4733. p1 = (FT_UShort)args[0];
  4734. p2 = (FT_UShort)args[1];
  4735. if ( BOUNDS( args[0], CUR.zp1.n_points ) ||
  4736. BOUNDS( args[1], CUR.zp0.n_points ) )
  4737. {
  4738. if ( CUR.pedantic_hinting )
  4739. CUR.error = TT_Err_Invalid_Reference;
  4740. return;
  4741. }
  4742. distance = CUR_Func_project( CUR.zp0.cur + p2,
  4743. CUR.zp1.cur + p1 ) / 2;
  4744. CUR_Func_move( &CUR.zp1, p1, distance );
  4745. CUR_Func_move( &CUR.zp0, p2, -distance );
  4746. }
  4747. /*************************************************************************/
  4748. /* */
  4749. /* IP[]: Interpolate Point */
  4750. /* Opcode range: 0x39 */
  4751. /* Stack: uint32... --> */
  4752. /* */
  4753. static void
  4754. Ins_IP( INS_ARG )
  4755. {
  4756. FT_F26Dot6 org_a, org_b, org_x,
  4757. cur_a, cur_b, cur_x,
  4758. distance;
  4759. FT_UShort point;
  4760. FT_UNUSED_ARG;
  4761. if ( CUR.top < CUR.GS.loop )
  4762. {
  4763. CUR.error = TT_Err_Invalid_Reference;
  4764. return;
  4765. }
  4766. /* XXX: There are some glyphs in some braindead but popular */
  4767. /* fonts out there (e.g. [aeu]grave in monotype.ttf) */
  4768. /* calling IP[] with bad values of rp[12]. */
  4769. /* Do something sane when this odd thing happens. */
  4770. if ( BOUNDS( CUR.GS.rp1, CUR.zp0.n_points ) ||
  4771. BOUNDS( CUR.GS.rp2, CUR.zp1.n_points ) )
  4772. {
  4773. org_a = cur_a = 0;
  4774. org_b = cur_b = 0;
  4775. }
  4776. else
  4777. {
  4778. org_a = CUR_Func_dualproj( CUR.zp0.org + CUR.GS.rp1, NULL_Vector );
  4779. org_b = CUR_Func_dualproj( CUR.zp1.org + CUR.GS.rp2, NULL_Vector );
  4780. cur_a = CUR_Func_project( CUR.zp0.cur + CUR.GS.rp1, NULL_Vector );
  4781. cur_b = CUR_Func_project( CUR.zp1.cur + CUR.GS.rp2, NULL_Vector );
  4782. }
  4783. while ( CUR.GS.loop > 0 )
  4784. {
  4785. CUR.args--;
  4786. point = (FT_UShort)CUR.stack[CUR.args];
  4787. if ( BOUNDS( point, CUR.zp2.n_points ) )
  4788. {
  4789. if ( CUR.pedantic_hinting )
  4790. {
  4791. CUR.error = TT_Err_Invalid_Reference;
  4792. return;
  4793. }
  4794. }
  4795. else
  4796. {
  4797. org_x = CUR_Func_dualproj( CUR.zp2.org + point, NULL_Vector );
  4798. cur_x = CUR_Func_project ( CUR.zp2.cur + point, NULL_Vector );
  4799. if ( ( org_a <= org_b && org_x <= org_a ) ||
  4800. ( org_a > org_b && org_x >= org_a ) )
  4801. distance = ( cur_a - org_a ) + ( org_x - cur_x );
  4802. else if ( ( org_a <= org_b && org_x >= org_b ) ||
  4803. ( org_a > org_b && org_x < org_b ) )
  4804. distance = ( cur_b - org_b ) + ( org_x - cur_x );
  4805. else
  4806. /* note: it seems that rounding this value isn't a good */
  4807. /* idea (cf. width of capital `S' in Times) */
  4808. distance = TT_MULDIV( cur_b - cur_a,
  4809. org_x - org_a,
  4810. org_b - org_a ) + ( cur_a - cur_x );
  4811. CUR_Func_move( &CUR.zp2, point, distance );
  4812. }
  4813. CUR.GS.loop--;
  4814. }
  4815. CUR.GS.loop = 1;
  4816. CUR.new_top = CUR.args;
  4817. }
  4818. /*************************************************************************/
  4819. /* */
  4820. /* UTP[a]: UnTouch Point */
  4821. /* Opcode range: 0x29 */
  4822. /* Stack: uint32 --> */
  4823. /* */
  4824. static void
  4825. Ins_UTP( INS_ARG )
  4826. {
  4827. FT_UShort point;
  4828. FT_Byte mask;
  4829. point = (FT_UShort)args[0];
  4830. if ( BOUNDS( point, CUR.zp0.n_points ) )
  4831. {
  4832. if ( CUR.pedantic_hinting )
  4833. CUR.error = TT_Err_Invalid_Reference;
  4834. return;
  4835. }
  4836. mask = 0xFF;
  4837. if ( CUR.GS.freeVector.x != 0 )
  4838. mask &= ~FT_CURVE_TAG_TOUCH_X;
  4839. if ( CUR.GS.freeVector.y != 0 )
  4840. mask &= ~FT_CURVE_TAG_TOUCH_Y;
  4841. CUR.zp0.tags[point] &= mask;
  4842. }
  4843. /* Local variables for Ins_IUP: */
  4844. struct LOC_Ins_IUP
  4845. {
  4846. FT_Vector* orgs; /* original and current coordinate */
  4847. FT_Vector* curs; /* arrays */
  4848. };
  4849. static void
  4850. Shift( FT_UInt p1,
  4851. FT_UInt p2,
  4852. FT_UInt p,
  4853. struct LOC_Ins_IUP* LINK )
  4854. {
  4855. FT_UInt i;
  4856. FT_F26Dot6 x;
  4857. x = LINK->curs[p].x - LINK->orgs[p].x;
  4858. for ( i = p1; i < p; i++ )
  4859. LINK->curs[i].x += x;
  4860. for ( i = p + 1; i <= p2; i++ )
  4861. LINK->curs[i].x += x;
  4862. }
  4863. static void
  4864. Interp( FT_UInt p1,
  4865. FT_UInt p2,
  4866. FT_UInt ref1,
  4867. FT_UInt ref2,
  4868. struct LOC_Ins_IUP* LINK )
  4869. {
  4870. FT_UInt i;
  4871. FT_F26Dot6 x, x1, x2, d1, d2;
  4872. if ( p1 > p2 )
  4873. return;
  4874. x1 = LINK->orgs[ref1].x;
  4875. d1 = LINK->curs[ref1].x - LINK->orgs[ref1].x;
  4876. x2 = LINK->orgs[ref2].x;
  4877. d2 = LINK->curs[ref2].x - LINK->orgs[ref2].x;
  4878. if ( x1 == x2 )
  4879. {
  4880. for ( i = p1; i <= p2; i++ )
  4881. {
  4882. x = LINK->orgs[i].x;
  4883. if ( x <= x1 )
  4884. x += d1;
  4885. else
  4886. x += d2;
  4887. LINK->curs[i].x = x;
  4888. }
  4889. return;
  4890. }
  4891. if ( x1 < x2 )
  4892. {
  4893. for ( i = p1; i <= p2; i++ )
  4894. {
  4895. x = LINK->orgs[i].x;
  4896. if ( x <= x1 )
  4897. x += d1;
  4898. else
  4899. {
  4900. if ( x >= x2 )
  4901. x += d2;
  4902. else
  4903. x = LINK->curs[ref1].x +
  4904. TT_MULDIV( x - x1,
  4905. LINK->curs[ref2].x - LINK->curs[ref1].x,
  4906. x2 - x1 );
  4907. }
  4908. LINK->curs[i].x = x;
  4909. }
  4910. return;
  4911. }
  4912. /* x2 < x1 */
  4913. for ( i = p1; i <= p2; i++ )
  4914. {
  4915. x = LINK->orgs[i].x;
  4916. if ( x <= x2 )
  4917. x += d2;
  4918. else
  4919. {
  4920. if ( x >= x1 )
  4921. x += d1;
  4922. else
  4923. x = LINK->curs[ref1].x +
  4924. TT_MULDIV( x - x1,
  4925. LINK->curs[ref2].x - LINK->curs[ref1].x,
  4926. x2 - x1 );
  4927. }
  4928. LINK->curs[i].x = x;
  4929. }
  4930. }
  4931. /*************************************************************************/
  4932. /* */
  4933. /* IUP[a]: Interpolate Untouched Points */
  4934. /* Opcode range: 0x30-0x31 */
  4935. /* Stack: --> */
  4936. /* */
  4937. static void
  4938. Ins_IUP( INS_ARG )
  4939. {
  4940. struct LOC_Ins_IUP V;
  4941. FT_Byte mask;
  4942. FT_UInt first_point; /* first point of contour */
  4943. FT_UInt end_point; /* end point (last+1) of contour */
  4944. FT_UInt first_touched; /* first touched point in contour */
  4945. FT_UInt cur_touched; /* current touched point in contour */
  4946. FT_UInt point; /* current point */
  4947. FT_Short contour; /* current contour */
  4948. FT_UNUSED_ARG;
  4949. if ( CUR.opcode & 1 )
  4950. {
  4951. mask = FT_CURVE_TAG_TOUCH_X;
  4952. V.orgs = CUR.pts.org;
  4953. V.curs = CUR.pts.cur;
  4954. }
  4955. else
  4956. {
  4957. mask = FT_CURVE_TAG_TOUCH_Y;
  4958. V.orgs = (FT_Vector*)( (FT_Pos*)CUR.pts.org + 1 );
  4959. V.curs = (FT_Vector*)( (FT_Pos*)CUR.pts.cur + 1 );
  4960. }
  4961. contour = 0;
  4962. point = 0;
  4963. do
  4964. {
  4965. end_point = CUR.pts.contours[contour];
  4966. first_point = point;
  4967. while ( point <= end_point && (CUR.pts.tags[point] & mask) == 0 )
  4968. point++;
  4969. if ( point <= end_point )
  4970. {
  4971. first_touched = point;
  4972. cur_touched = point;
  4973. point++;
  4974. while ( point <= end_point )
  4975. {
  4976. if ( ( CUR.pts.tags[point] & mask ) != 0 )
  4977. {
  4978. if ( point > 0 )
  4979. Interp( cur_touched + 1,
  4980. point - 1,
  4981. cur_touched,
  4982. point,
  4983. &V );
  4984. cur_touched = point;
  4985. }
  4986. point++;
  4987. }
  4988. if ( cur_touched == first_touched )
  4989. Shift( first_point, end_point, cur_touched, &V );
  4990. else
  4991. {
  4992. Interp( (FT_UShort)( cur_touched + 1 ),
  4993. end_point,
  4994. cur_touched,
  4995. first_touched,
  4996. &V );
  4997. if ( first_touched > 0 )
  4998. Interp( first_point,
  4999. first_touched - 1,
  5000. cur_touched,
  5001. first_touched,
  5002. &V );
  5003. }
  5004. }
  5005. contour++;
  5006. } while ( contour < CUR.pts.n_contours );
  5007. }
  5008. /*************************************************************************/
  5009. /* */
  5010. /* DELTAPn[]: DELTA exceptions P1, P2, P3 */
  5011. /* Opcode range: 0x5D,0x71,0x72 */
  5012. /* Stack: uint32 (2 * uint32)... --> */
  5013. /* */
  5014. static void
  5015. Ins_DELTAP( INS_ARG )
  5016. {
  5017. FT_ULong k, nump;
  5018. FT_UShort A;
  5019. FT_ULong C;
  5020. FT_Long B;
  5021. nump = (FT_ULong)args[0]; /* some points theoretically may occur more
  5022. than once, thus UShort isn't enough */
  5023. for ( k = 1; k <= nump; k++ )
  5024. {
  5025. if ( CUR.args < 2 )
  5026. {
  5027. CUR.error = TT_Err_Too_Few_Arguments;
  5028. return;
  5029. }
  5030. CUR.args -= 2;
  5031. A = (FT_UShort)CUR.stack[CUR.args + 1];
  5032. B = CUR.stack[CUR.args];
  5033. /* XXX: Because some popular fonts contain some invalid DeltaP */
  5034. /* instructions, we simply ignore them when the stacked */
  5035. /* point reference is off limit, rather than returning an */
  5036. /* error. As a delta instruction doesn't change a glyph */
  5037. /* in great ways, this shouldn't be a problem. */
  5038. if ( !BOUNDS( A, CUR.zp0.n_points ) )
  5039. {
  5040. C = ( (FT_ULong)B & 0xF0 ) >> 4;
  5041. switch ( CUR.opcode )
  5042. {
  5043. case 0x5D:
  5044. break;
  5045. case 0x71:
  5046. C += 16;
  5047. break;
  5048. case 0x72:
  5049. C += 32;
  5050. break;
  5051. }
  5052. C += CUR.GS.delta_base;
  5053. if ( CURRENT_Ppem() == (FT_Long)C )
  5054. {
  5055. B = ( (FT_ULong)B & 0xF ) - 8;
  5056. if ( B >= 0 )
  5057. B++;
  5058. B = B * 64 / ( 1L << CUR.GS.delta_shift );
  5059. CUR_Func_move( &CUR.zp0, A, B );
  5060. }
  5061. }
  5062. else
  5063. if ( CUR.pedantic_hinting )
  5064. CUR.error = TT_Err_Invalid_Reference;
  5065. }
  5066. CUR.new_top = CUR.args;
  5067. }
  5068. /*************************************************************************/
  5069. /* */
  5070. /* DELTACn[]: DELTA exceptions C1, C2, C3 */
  5071. /* Opcode range: 0x73,0x74,0x75 */
  5072. /* Stack: uint32 (2 * uint32)... --> */
  5073. /* */
  5074. static void
  5075. Ins_DELTAC( INS_ARG )
  5076. {
  5077. FT_ULong nump, k;
  5078. FT_ULong A, C;
  5079. FT_Long B;
  5080. nump = (FT_ULong)args[0];
  5081. for ( k = 1; k <= nump; k++ )
  5082. {
  5083. if ( CUR.args < 2 )
  5084. {
  5085. CUR.error = TT_Err_Too_Few_Arguments;
  5086. return;
  5087. }
  5088. CUR.args -= 2;
  5089. A = (FT_ULong)CUR.stack[CUR.args + 1];
  5090. B = CUR.stack[CUR.args];
  5091. if ( BOUNDS( A, CUR.cvtSize ) )
  5092. {
  5093. if ( CUR.pedantic_hinting )
  5094. {
  5095. CUR.error = TT_Err_Invalid_Reference;
  5096. return;
  5097. }
  5098. }
  5099. else
  5100. {
  5101. C = ( (FT_ULong)B & 0xF0 ) >> 4;
  5102. switch ( CUR.opcode )
  5103. {
  5104. case 0x73:
  5105. break;
  5106. case 0x74:
  5107. C += 16;
  5108. break;
  5109. case 0x75:
  5110. C += 32;
  5111. break;
  5112. }
  5113. C += CUR.GS.delta_base;
  5114. if ( CURRENT_Ppem() == (FT_Long)C )
  5115. {
  5116. B = ( (FT_ULong)B & 0xF ) - 8;
  5117. if ( B >= 0 )
  5118. B++;
  5119. B = B * 64 / ( 1L << CUR.GS.delta_shift );
  5120. CUR_Func_move_cvt( A, B );
  5121. }
  5122. }
  5123. }
  5124. CUR.new_top = CUR.args;
  5125. }
  5126. /*************************************************************************/
  5127. /* */
  5128. /* MISC. INSTRUCTIONS */
  5129. /* */
  5130. /*************************************************************************/
  5131. /*************************************************************************/
  5132. /* */
  5133. /* GETINFO[]: GET INFOrmation */
  5134. /* Opcode range: 0x88 */
  5135. /* Stack: uint32 --> uint32 */
  5136. /* */
  5137. /* XXX: According to Apple specs, bits 1 & 2 of the argument ought to be */
  5138. /* consulted before rotated/stretched info is returned. */
  5139. static void
  5140. Ins_GETINFO( INS_ARG )
  5141. {
  5142. FT_Long K;
  5143. K = 0;
  5144. /* We return then Windows 3.1 version number */
  5145. /* for the font scaler */
  5146. if ( ( args[0] & 1 ) != 0 )
  5147. K = 3;
  5148. /* Has the glyph been rotated ? */
  5149. if ( CUR.tt_metrics.rotated )
  5150. K |= 0x80;
  5151. /* Has the glyph been stretched ? */
  5152. if ( CUR.tt_metrics.stretched )
  5153. K |= 0x100;
  5154. args[0] = K;
  5155. }
  5156. static void
  5157. Ins_UNKNOWN( INS_ARG )
  5158. {
  5159. TT_DefRecord* def = CUR.IDefs;
  5160. TT_DefRecord* limit = def + CUR.numIDefs;
  5161. FT_UNUSED_ARG;
  5162. for ( ; def < limit; def++ )
  5163. {
  5164. if ( (FT_Byte)def->opc == CUR.opcode && def->active )
  5165. {
  5166. TT_CallRec* call;
  5167. if ( CUR.callTop >= CUR.callSize )
  5168. {
  5169. CUR.error = TT_Err_Stack_Overflow;
  5170. return;
  5171. }
  5172. call = CUR.callStack + CUR.callTop++;
  5173. call->Caller_Range = CUR.curRange;
  5174. call->Caller_IP = CUR.IP+1;
  5175. call->Cur_Count = 1;
  5176. call->Cur_Restart = def->start;
  5177. INS_Goto_CodeRange( def->range, def->start );
  5178. CUR.step_ins = FALSE;
  5179. return;
  5180. }
  5181. }
  5182. CUR.error = TT_Err_Invalid_Opcode;
  5183. }
  5184. #ifndef TT_CONFIG_OPTION_INTERPRETER_SWITCH
  5185. static
  5186. TInstruction_Function Instruct_Dispatch[256] =
  5187. {
  5188. /* Opcodes are gathered in groups of 16. */
  5189. /* Please keep the spaces as they are. */
  5190. /* SVTCA y */ Ins_SVTCA,
  5191. /* SVTCA x */ Ins_SVTCA,
  5192. /* SPvTCA y */ Ins_SPVTCA,
  5193. /* SPvTCA x */ Ins_SPVTCA,
  5194. /* SFvTCA y */ Ins_SFVTCA,
  5195. /* SFvTCA x */ Ins_SFVTCA,
  5196. /* SPvTL // */ Ins_SPVTL,
  5197. /* SPvTL + */ Ins_SPVTL,
  5198. /* SFvTL // */ Ins_SFVTL,
  5199. /* SFvTL + */ Ins_SFVTL,
  5200. /* SPvFS */ Ins_SPVFS,
  5201. /* SFvFS */ Ins_SFVFS,
  5202. /* GPV */ Ins_GPV,
  5203. /* GFV */ Ins_GFV,
  5204. /* SFvTPv */ Ins_SFVTPV,
  5205. /* ISECT */ Ins_ISECT,
  5206. /* SRP0 */ Ins_SRP0,
  5207. /* SRP1 */ Ins_SRP1,
  5208. /* SRP2 */ Ins_SRP2,
  5209. /* SZP0 */ Ins_SZP0,
  5210. /* SZP1 */ Ins_SZP1,
  5211. /* SZP2 */ Ins_SZP2,
  5212. /* SZPS */ Ins_SZPS,
  5213. /* SLOOP */ Ins_SLOOP,
  5214. /* RTG */ Ins_RTG,
  5215. /* RTHG */ Ins_RTHG,
  5216. /* SMD */ Ins_SMD,
  5217. /* ELSE */ Ins_ELSE,
  5218. /* JMPR */ Ins_JMPR,
  5219. /* SCvTCi */ Ins_SCVTCI,
  5220. /* SSwCi */ Ins_SSWCI,
  5221. /* SSW */ Ins_SSW,
  5222. /* DUP */ Ins_DUP,
  5223. /* POP */ Ins_POP,
  5224. /* CLEAR */ Ins_CLEAR,
  5225. /* SWAP */ Ins_SWAP,
  5226. /* DEPTH */ Ins_DEPTH,
  5227. /* CINDEX */ Ins_CINDEX,
  5228. /* MINDEX */ Ins_MINDEX,
  5229. /* AlignPTS */ Ins_ALIGNPTS,
  5230. /* INS_0x28 */ Ins_UNKNOWN,
  5231. /* UTP */ Ins_UTP,
  5232. /* LOOPCALL */ Ins_LOOPCALL,
  5233. /* CALL */ Ins_CALL,
  5234. /* FDEF */ Ins_FDEF,
  5235. /* ENDF */ Ins_ENDF,
  5236. /* MDAP[0] */ Ins_MDAP,
  5237. /* MDAP[1] */ Ins_MDAP,
  5238. /* IUP[0] */ Ins_IUP,
  5239. /* IUP[1] */ Ins_IUP,
  5240. /* SHP[0] */ Ins_SHP,
  5241. /* SHP[1] */ Ins_SHP,
  5242. /* SHC[0] */ Ins_SHC,
  5243. /* SHC[1] */ Ins_SHC,
  5244. /* SHZ[0] */ Ins_SHZ,
  5245. /* SHZ[1] */ Ins_SHZ,
  5246. /* SHPIX */ Ins_SHPIX,
  5247. /* IP */ Ins_IP,
  5248. /* MSIRP[0] */ Ins_MSIRP,
  5249. /* MSIRP[1] */ Ins_MSIRP,
  5250. /* AlignRP */ Ins_ALIGNRP,
  5251. /* RTDG */ Ins_RTDG,
  5252. /* MIAP[0] */ Ins_MIAP,
  5253. /* MIAP[1] */ Ins_MIAP,
  5254. /* NPushB */ Ins_NPUSHB,
  5255. /* NPushW */ Ins_NPUSHW,
  5256. /* WS */ Ins_WS,
  5257. /* RS */ Ins_RS,
  5258. /* WCvtP */ Ins_WCVTP,
  5259. /* RCvt */ Ins_RCVT,
  5260. /* GC[0] */ Ins_GC,
  5261. /* GC[1] */ Ins_GC,
  5262. /* SCFS */ Ins_SCFS,
  5263. /* MD[0] */ Ins_MD,
  5264. /* MD[1] */ Ins_MD,
  5265. /* MPPEM */ Ins_MPPEM,
  5266. /* MPS */ Ins_MPS,
  5267. /* FlipON */ Ins_FLIPON,
  5268. /* FlipOFF */ Ins_FLIPOFF,
  5269. /* DEBUG */ Ins_DEBUG,
  5270. /* LT */ Ins_LT,
  5271. /* LTEQ */ Ins_LTEQ,
  5272. /* GT */ Ins_GT,
  5273. /* GTEQ */ Ins_GTEQ,
  5274. /* EQ */ Ins_EQ,
  5275. /* NEQ */ Ins_NEQ,
  5276. /* ODD */ Ins_ODD,
  5277. /* EVEN */ Ins_EVEN,
  5278. /* IF */ Ins_IF,
  5279. /* EIF */ Ins_EIF,
  5280. /* AND */ Ins_AND,
  5281. /* OR */ Ins_OR,
  5282. /* NOT */ Ins_NOT,
  5283. /* DeltaP1 */ Ins_DELTAP,
  5284. /* SDB */ Ins_SDB,
  5285. /* SDS */ Ins_SDS,
  5286. /* ADD */ Ins_ADD,
  5287. /* SUB */ Ins_SUB,
  5288. /* DIV */ Ins_DIV,
  5289. /* MUL */ Ins_MUL,
  5290. /* ABS */ Ins_ABS,
  5291. /* NEG */ Ins_NEG,
  5292. /* FLOOR */ Ins_FLOOR,
  5293. /* CEILING */ Ins_CEILING,
  5294. /* ROUND[0] */ Ins_ROUND,
  5295. /* ROUND[1] */ Ins_ROUND,
  5296. /* ROUND[2] */ Ins_ROUND,
  5297. /* ROUND[3] */ Ins_ROUND,
  5298. /* NROUND[0] */ Ins_NROUND,
  5299. /* NROUND[1] */ Ins_NROUND,
  5300. /* NROUND[2] */ Ins_NROUND,
  5301. /* NROUND[3] */ Ins_NROUND,
  5302. /* WCvtF */ Ins_WCVTF,
  5303. /* DeltaP2 */ Ins_DELTAP,
  5304. /* DeltaP3 */ Ins_DELTAP,
  5305. /* DeltaCn[0] */ Ins_DELTAC,
  5306. /* DeltaCn[1] */ Ins_DELTAC,
  5307. /* DeltaCn[2] */ Ins_DELTAC,
  5308. /* SROUND */ Ins_SROUND,
  5309. /* S45Round */ Ins_S45ROUND,
  5310. /* JROT */ Ins_JROT,
  5311. /* JROF */ Ins_JROF,
  5312. /* ROFF */ Ins_ROFF,
  5313. /* INS_0x7B */ Ins_UNKNOWN,
  5314. /* RUTG */ Ins_RUTG,
  5315. /* RDTG */ Ins_RDTG,
  5316. /* SANGW */ Ins_SANGW,
  5317. /* AA */ Ins_AA,
  5318. /* FlipPT */ Ins_FLIPPT,
  5319. /* FlipRgON */ Ins_FLIPRGON,
  5320. /* FlipRgOFF */ Ins_FLIPRGOFF,
  5321. /* INS_0x83 */ Ins_UNKNOWN,
  5322. /* INS_0x84 */ Ins_UNKNOWN,
  5323. /* ScanCTRL */ Ins_SCANCTRL,
  5324. /* SDPVTL[0] */ Ins_SDPVTL,
  5325. /* SDPVTL[1] */ Ins_SDPVTL,
  5326. /* GetINFO */ Ins_GETINFO,
  5327. /* IDEF */ Ins_IDEF,
  5328. /* ROLL */ Ins_ROLL,
  5329. /* MAX */ Ins_MAX,
  5330. /* MIN */ Ins_MIN,
  5331. /* ScanTYPE */ Ins_SCANTYPE,
  5332. /* InstCTRL */ Ins_INSTCTRL,
  5333. /* INS_0x8F */ Ins_UNKNOWN,
  5334. /* INS_0x90 */ Ins_UNKNOWN,
  5335. /* INS_0x91 */ Ins_UNKNOWN,
  5336. /* INS_0x92 */ Ins_UNKNOWN,
  5337. /* INS_0x93 */ Ins_UNKNOWN,
  5338. /* INS_0x94 */ Ins_UNKNOWN,
  5339. /* INS_0x95 */ Ins_UNKNOWN,
  5340. /* INS_0x96 */ Ins_UNKNOWN,
  5341. /* INS_0x97 */ Ins_UNKNOWN,
  5342. /* INS_0x98 */ Ins_UNKNOWN,
  5343. /* INS_0x99 */ Ins_UNKNOWN,
  5344. /* INS_0x9A */ Ins_UNKNOWN,
  5345. /* INS_0x9B */ Ins_UNKNOWN,
  5346. /* INS_0x9C */ Ins_UNKNOWN,
  5347. /* INS_0x9D */ Ins_UNKNOWN,
  5348. /* INS_0x9E */ Ins_UNKNOWN,
  5349. /* INS_0x9F */ Ins_UNKNOWN,
  5350. /* INS_0xA0 */ Ins_UNKNOWN,
  5351. /* INS_0xA1 */ Ins_UNKNOWN,
  5352. /* INS_0xA2 */ Ins_UNKNOWN,
  5353. /* INS_0xA3 */ Ins_UNKNOWN,
  5354. /* INS_0xA4 */ Ins_UNKNOWN,
  5355. /* INS_0xA5 */ Ins_UNKNOWN,
  5356. /* INS_0xA6 */ Ins_UNKNOWN,
  5357. /* INS_0xA7 */ Ins_UNKNOWN,
  5358. /* INS_0xA8 */ Ins_UNKNOWN,
  5359. /* INS_0xA9 */ Ins_UNKNOWN,
  5360. /* INS_0xAA */ Ins_UNKNOWN,
  5361. /* INS_0xAB */ Ins_UNKNOWN,
  5362. /* INS_0xAC */ Ins_UNKNOWN,
  5363. /* INS_0xAD */ Ins_UNKNOWN,
  5364. /* INS_0xAE */ Ins_UNKNOWN,
  5365. /* INS_0xAF */ Ins_UNKNOWN,
  5366. /* PushB[0] */ Ins_PUSHB,
  5367. /* PushB[1] */ Ins_PUSHB,
  5368. /* PushB[2] */ Ins_PUSHB,
  5369. /* PushB[3] */ Ins_PUSHB,
  5370. /* PushB[4] */ Ins_PUSHB,
  5371. /* PushB[5] */ Ins_PUSHB,
  5372. /* PushB[6] */ Ins_PUSHB,
  5373. /* PushB[7] */ Ins_PUSHB,
  5374. /* PushW[0] */ Ins_PUSHW,
  5375. /* PushW[1] */ Ins_PUSHW,
  5376. /* PushW[2] */ Ins_PUSHW,
  5377. /* PushW[3] */ Ins_PUSHW,
  5378. /* PushW[4] */ Ins_PUSHW,
  5379. /* PushW[5] */ Ins_PUSHW,
  5380. /* PushW[6] */ Ins_PUSHW,
  5381. /* PushW[7] */ Ins_PUSHW,
  5382. /* MDRP[00] */ Ins_MDRP,
  5383. /* MDRP[01] */ Ins_MDRP,
  5384. /* MDRP[02] */ Ins_MDRP,
  5385. /* MDRP[03] */ Ins_MDRP,
  5386. /* MDRP[04] */ Ins_MDRP,
  5387. /* MDRP[05] */ Ins_MDRP,
  5388. /* MDRP[06] */ Ins_MDRP,
  5389. /* MDRP[07] */ Ins_MDRP,
  5390. /* MDRP[08] */ Ins_MDRP,
  5391. /* MDRP[09] */ Ins_MDRP,
  5392. /* MDRP[10] */ Ins_MDRP,
  5393. /* MDRP[11] */ Ins_MDRP,
  5394. /* MDRP[12] */ Ins_MDRP,
  5395. /* MDRP[13] */ Ins_MDRP,
  5396. /* MDRP[14] */ Ins_MDRP,
  5397. /* MDRP[15] */ Ins_MDRP,
  5398. /* MDRP[16] */ Ins_MDRP,
  5399. /* MDRP[17] */ Ins_MDRP,
  5400. /* MDRP[18] */ Ins_MDRP,
  5401. /* MDRP[19] */ Ins_MDRP,
  5402. /* MDRP[20] */ Ins_MDRP,
  5403. /* MDRP[21] */ Ins_MDRP,
  5404. /* MDRP[22] */ Ins_MDRP,
  5405. /* MDRP[23] */ Ins_MDRP,
  5406. /* MDRP[24] */ Ins_MDRP,
  5407. /* MDRP[25] */ Ins_MDRP,
  5408. /* MDRP[26] */ Ins_MDRP,
  5409. /* MDRP[27] */ Ins_MDRP,
  5410. /* MDRP[28] */ Ins_MDRP,
  5411. /* MDRP[29] */ Ins_MDRP,
  5412. /* MDRP[30] */ Ins_MDRP,
  5413. /* MDRP[31] */ Ins_MDRP,
  5414. /* MIRP[00] */ Ins_MIRP,
  5415. /* MIRP[01] */ Ins_MIRP,
  5416. /* MIRP[02] */ Ins_MIRP,
  5417. /* MIRP[03] */ Ins_MIRP,
  5418. /* MIRP[04] */ Ins_MIRP,
  5419. /* MIRP[05] */ Ins_MIRP,
  5420. /* MIRP[06] */ Ins_MIRP,
  5421. /* MIRP[07] */ Ins_MIRP,
  5422. /* MIRP[08] */ Ins_MIRP,
  5423. /* MIRP[09] */ Ins_MIRP,
  5424. /* MIRP[10] */ Ins_MIRP,
  5425. /* MIRP[11] */ Ins_MIRP,
  5426. /* MIRP[12] */ Ins_MIRP,
  5427. /* MIRP[13] */ Ins_MIRP,
  5428. /* MIRP[14] */ Ins_MIRP,
  5429. /* MIRP[15] */ Ins_MIRP,
  5430. /* MIRP[16] */ Ins_MIRP,
  5431. /* MIRP[17] */ Ins_MIRP,
  5432. /* MIRP[18] */ Ins_MIRP,
  5433. /* MIRP[19] */ Ins_MIRP,
  5434. /* MIRP[20] */ Ins_MIRP,
  5435. /* MIRP[21] */ Ins_MIRP,
  5436. /* MIRP[22] */ Ins_MIRP,
  5437. /* MIRP[23] */ Ins_MIRP,
  5438. /* MIRP[24] */ Ins_MIRP,
  5439. /* MIRP[25] */ Ins_MIRP,
  5440. /* MIRP[26] */ Ins_MIRP,
  5441. /* MIRP[27] */ Ins_MIRP,
  5442. /* MIRP[28] */ Ins_MIRP,
  5443. /* MIRP[29] */ Ins_MIRP,
  5444. /* MIRP[30] */ Ins_MIRP,
  5445. /* MIRP[31] */ Ins_MIRP
  5446. };
  5447. #endif /* !TT_CONFIG_OPTION_INTERPRETER_SWITCH */
  5448. /*************************************************************************/
  5449. /* */
  5450. /* RUN */
  5451. /* */
  5452. /* This function executes a run of opcodes. It will exit in the */
  5453. /* following cases: */
  5454. /* */
  5455. /* - Errors (in which case it returns FALSE). */
  5456. /* */
  5457. /* - Reaching the end of the main code range (returns TRUE). */
  5458. /* Reaching the end of a code range within a function call is an */
  5459. /* error. */
  5460. /* */
  5461. /* - After executing one single opcode, if the flag `Instruction_Trap' */
  5462. /* is set to TRUE (returns TRUE). */
  5463. /* */
  5464. /* On exit whith TRUE, test IP < CodeSize to know wether it comes from */
  5465. /* an instruction trap or a normal termination. */
  5466. /* */
  5467. /* */
  5468. /* Note: The documented DEBUG opcode pops a value from the stack. This */
  5469. /* behaviour is unsupported; here a DEBUG opcode is always an */
  5470. /* error. */
  5471. /* */
  5472. /* */
  5473. /* THIS IS THE INTERPRETER'S MAIN LOOP. */
  5474. /* */
  5475. /* Instructions appear in the specification's order. */
  5476. /* */
  5477. /*************************************************************************/
  5478. /* documentation is in ttinterp.h */
  5479. FT_EXPORT_DEF( FT_Error )
  5480. TT_RunIns( TT_ExecContext exc )
  5481. {
  5482. FT_Long ins_counter = 0; /* executed instructions counter */
  5483. #ifdef TT_CONFIG_OPTION_STATIC_RASTER
  5484. cur = *exc;
  5485. #endif
  5486. /* set CVT functions */
  5487. CUR.tt_metrics.ratio = 0;
  5488. if ( CUR.metrics.x_ppem != CUR.metrics.y_ppem )
  5489. {
  5490. /* non-square pixels, use the stretched routines */
  5491. CUR.func_read_cvt = Read_CVT_Stretched;
  5492. CUR.func_write_cvt = Write_CVT_Stretched;
  5493. CUR.func_move_cvt = Move_CVT_Stretched;
  5494. }
  5495. else
  5496. {
  5497. /* square pixels, use normal routines */
  5498. CUR.func_read_cvt = Read_CVT;
  5499. CUR.func_write_cvt = Write_CVT;
  5500. CUR.func_move_cvt = Move_CVT;
  5501. }
  5502. COMPUTE_Funcs();
  5503. COMPUTE_Round( (FT_Byte)exc->GS.round_state );
  5504. do
  5505. {
  5506. CUR.opcode = CUR.code[CUR.IP];
  5507. if ( ( CUR.length = opcode_length[CUR.opcode] ) < 0 )
  5508. {
  5509. if ( CUR.IP + 1 > CUR.codeSize )
  5510. goto LErrorCodeOverflow_;
  5511. CUR.length = CUR.code[CUR.IP + 1] + 2;
  5512. }
  5513. if ( CUR.IP + CUR.length > CUR.codeSize )
  5514. goto LErrorCodeOverflow_;
  5515. /* First, let's check for empty stack and overflow */
  5516. CUR.args = CUR.top - ( Pop_Push_Count[CUR.opcode] >> 4 );
  5517. /* `args' is the top of the stack once arguments have been popped. */
  5518. /* One can also interpret it as the index of the last argument. */
  5519. if ( CUR.args < 0 )
  5520. {
  5521. CUR.error = TT_Err_Too_Few_Arguments;
  5522. goto LErrorLabel_;
  5523. }
  5524. CUR.new_top = CUR.args + ( Pop_Push_Count[CUR.opcode] & 15 );
  5525. /* `new_top' is the new top of the stack, after the instruction's */
  5526. /* execution. `top' will be set to `new_top' after the `switch' */
  5527. /* statement. */
  5528. if ( CUR.new_top > CUR.stackSize )
  5529. {
  5530. CUR.error = TT_Err_Stack_Overflow;
  5531. goto LErrorLabel_;
  5532. }
  5533. CUR.step_ins = TRUE;
  5534. CUR.error = TT_Err_Ok;
  5535. #ifdef TT_CONFIG_OPTION_INTERPRETER_SWITCH
  5536. {
  5537. FT_Long* args = CUR.stack + CUR.args;
  5538. FT_Byte opcode = CUR.opcode;
  5539. #undef ARRAY_BOUND_ERROR
  5540. #define ARRAY_BOUND_ERROR goto Set_Invalid_Ref
  5541. switch ( opcode )
  5542. {
  5543. case 0x00: /* SVTCA y */
  5544. case 0x01: /* SVTCA x */
  5545. case 0x02: /* SPvTCA y */
  5546. case 0x03: /* SPvTCA x */
  5547. case 0x04: /* SFvTCA y */
  5548. case 0x05: /* SFvTCA x */
  5549. {
  5550. FT_Short AA, BB;
  5551. AA = (FT_Short)( ( opcode & 1 ) << 14 );
  5552. BB = (FT_Short)( AA ^ 0x4000 );
  5553. if ( opcode < 4 )
  5554. {
  5555. CUR.GS.projVector.x = AA;
  5556. CUR.GS.projVector.y = BB;
  5557. CUR.GS.dualVector.x = AA;
  5558. CUR.GS.dualVector.y = BB;
  5559. }
  5560. if ( ( opcode & 2 ) == 0 )
  5561. {
  5562. CUR.GS.freeVector.x = AA;
  5563. CUR.GS.freeVector.y = BB;
  5564. }
  5565. COMPUTE_Funcs();
  5566. }
  5567. break;
  5568. case 0x06: /* SPvTL // */
  5569. case 0x07: /* SPvTL + */
  5570. DO_SPVTL
  5571. break;
  5572. case 0x08: /* SFvTL // */
  5573. case 0x09: /* SFvTL + */
  5574. DO_SFVTL
  5575. break;
  5576. case 0x0A: /* SPvFS */
  5577. DO_SPVFS
  5578. break;
  5579. case 0x0B: /* SFvFS */
  5580. DO_SFVFS
  5581. break;
  5582. case 0x0C: /* GPV */
  5583. DO_GPV
  5584. break;
  5585. case 0x0D: /* GFV */
  5586. DO_GFV
  5587. break;
  5588. case 0x0E: /* SFvTPv */
  5589. DO_SFVTPV
  5590. break;
  5591. case 0x0F: /* ISECT */
  5592. Ins_ISECT( EXEC_ARG_ args );
  5593. break;
  5594. case 0x10: /* SRP0 */
  5595. DO_SRP0
  5596. break;
  5597. case 0x11: /* SRP1 */
  5598. DO_SRP1
  5599. break;
  5600. case 0x12: /* SRP2 */
  5601. DO_SRP2
  5602. break;
  5603. case 0x13: /* SZP0 */
  5604. Ins_SZP0( EXEC_ARG_ args );
  5605. break;
  5606. case 0x14: /* SZP1 */
  5607. Ins_SZP1( EXEC_ARG_ args );
  5608. break;
  5609. case 0x15: /* SZP2 */
  5610. Ins_SZP2( EXEC_ARG_ args );
  5611. break;
  5612. case 0x16: /* SZPS */
  5613. Ins_SZPS( EXEC_ARG_ args );
  5614. break;
  5615. case 0x17: /* SLOOP */
  5616. DO_SLOOP
  5617. break;
  5618. case 0x18: /* RTG */
  5619. DO_RTG
  5620. break;
  5621. case 0x19: /* RTHG */
  5622. DO_RTHG
  5623. break;
  5624. case 0x1A: /* SMD */
  5625. DO_SMD
  5626. break;
  5627. case 0x1B: /* ELSE */
  5628. Ins_ELSE( EXEC_ARG_ args );
  5629. break;
  5630. case 0x1C: /* JMPR */
  5631. DO_JMPR
  5632. break;
  5633. case 0x1D: /* SCVTCI */
  5634. DO_SCVTCI
  5635. break;
  5636. case 0x1E: /* SSWCI */
  5637. DO_SSWCI
  5638. break;
  5639. case 0x1F: /* SSW */
  5640. DO_SSW
  5641. break;
  5642. case 0x20: /* DUP */
  5643. DO_DUP
  5644. break;
  5645. case 0x21: /* POP */
  5646. /* nothing :-) */
  5647. break;
  5648. case 0x22: /* CLEAR */
  5649. DO_CLEAR
  5650. break;
  5651. case 0x23: /* SWAP */
  5652. DO_SWAP
  5653. break;
  5654. case 0x24: /* DEPTH */
  5655. DO_DEPTH
  5656. break;
  5657. case 0x25: /* CINDEX */
  5658. DO_CINDEX
  5659. break;
  5660. case 0x26: /* MINDEX */
  5661. Ins_MINDEX( EXEC_ARG_ args );
  5662. break;
  5663. case 0x27: /* ALIGNPTS */
  5664. Ins_ALIGNPTS( EXEC_ARG_ args );
  5665. break;
  5666. case 0x28: /* ???? */
  5667. Ins_UNKNOWN( EXEC_ARG_ args );
  5668. break;
  5669. case 0x29: /* UTP */
  5670. Ins_UTP( EXEC_ARG_ args );
  5671. break;
  5672. case 0x2A: /* LOOPCALL */
  5673. Ins_LOOPCALL( EXEC_ARG_ args );
  5674. break;
  5675. case 0x2B: /* CALL */
  5676. Ins_CALL( EXEC_ARG_ args );
  5677. break;
  5678. case 0x2C: /* FDEF */
  5679. Ins_FDEF( EXEC_ARG_ args );
  5680. break;
  5681. case 0x2D: /* ENDF */
  5682. Ins_ENDF( EXEC_ARG_ args );
  5683. break;
  5684. case 0x2E: /* MDAP */
  5685. case 0x2F: /* MDAP */
  5686. Ins_MDAP( EXEC_ARG_ args );
  5687. break;
  5688. case 0x30: /* IUP */
  5689. case 0x31: /* IUP */
  5690. Ins_IUP( EXEC_ARG_ args );
  5691. break;
  5692. case 0x32: /* SHP */
  5693. case 0x33: /* SHP */
  5694. Ins_SHP( EXEC_ARG_ args );
  5695. break;
  5696. case 0x34: /* SHC */
  5697. case 0x35: /* SHC */
  5698. Ins_SHC( EXEC_ARG_ args );
  5699. break;
  5700. case 0x36: /* SHZ */
  5701. case 0x37: /* SHZ */
  5702. Ins_SHZ( EXEC_ARG_ args );
  5703. break;
  5704. case 0x38: /* SHPIX */
  5705. Ins_SHPIX( EXEC_ARG_ args );
  5706. break;
  5707. case 0x39: /* IP */
  5708. Ins_IP( EXEC_ARG_ args );
  5709. break;
  5710. case 0x3A: /* MSIRP */
  5711. case 0x3B: /* MSIRP */
  5712. Ins_MSIRP( EXEC_ARG_ args );
  5713. break;
  5714. case 0x3C: /* AlignRP */
  5715. Ins_ALIGNRP( EXEC_ARG_ args );
  5716. break;
  5717. case 0x3D: /* RTDG */
  5718. DO_RTDG
  5719. break;
  5720. case 0x3E: /* MIAP */
  5721. case 0x3F: /* MIAP */
  5722. Ins_MIAP( EXEC_ARG_ args );
  5723. break;
  5724. case 0x40: /* NPUSHB */
  5725. Ins_NPUSHB( EXEC_ARG_ args );
  5726. break;
  5727. case 0x41: /* NPUSHW */
  5728. Ins_NPUSHW( EXEC_ARG_ args );
  5729. break;
  5730. case 0x42: /* WS */
  5731. DO_WS
  5732. break;
  5733. Set_Invalid_Ref:
  5734. CUR.error = TT_Err_Invalid_Reference;
  5735. break;
  5736. case 0x43: /* RS */
  5737. DO_RS
  5738. break;
  5739. case 0x44: /* WCVTP */
  5740. DO_WCVTP
  5741. break;
  5742. case 0x45: /* RCVT */
  5743. DO_RCVT
  5744. break;
  5745. case 0x46: /* GC */
  5746. case 0x47: /* GC */
  5747. Ins_GC( EXEC_ARG_ args );
  5748. break;
  5749. case 0x48: /* SCFS */
  5750. Ins_SCFS( EXEC_ARG_ args );
  5751. break;
  5752. case 0x49: /* MD */
  5753. case 0x4A: /* MD */
  5754. Ins_MD( EXEC_ARG_ args );
  5755. break;
  5756. case 0x4B: /* MPPEM */
  5757. DO_MPPEM
  5758. break;
  5759. case 0x4C: /* MPS */
  5760. DO_MPS
  5761. break;
  5762. case 0x4D: /* FLIPON */
  5763. DO_FLIPON
  5764. break;
  5765. case 0x4E: /* FLIPOFF */
  5766. DO_FLIPOFF
  5767. break;
  5768. case 0x4F: /* DEBUG */
  5769. DO_DEBUG
  5770. break;
  5771. case 0x50: /* LT */
  5772. DO_LT
  5773. break;
  5774. case 0x51: /* LTEQ */
  5775. DO_LTEQ
  5776. break;
  5777. case 0x52: /* GT */
  5778. DO_GT
  5779. break;
  5780. case 0x53: /* GTEQ */
  5781. DO_GTEQ
  5782. break;
  5783. case 0x54: /* EQ */
  5784. DO_EQ
  5785. break;
  5786. case 0x55: /* NEQ */
  5787. DO_NEQ
  5788. break;
  5789. case 0x56: /* ODD */
  5790. DO_ODD
  5791. break;
  5792. case 0x57: /* EVEN */
  5793. DO_EVEN
  5794. break;
  5795. case 0x58: /* IF */
  5796. Ins_IF( EXEC_ARG_ args );
  5797. break;
  5798. case 0x59: /* EIF */
  5799. /* do nothing */
  5800. break;
  5801. case 0x5A: /* AND */
  5802. DO_AND
  5803. break;
  5804. case 0x5B: /* OR */
  5805. DO_OR
  5806. break;
  5807. case 0x5C: /* NOT */
  5808. DO_NOT
  5809. break;
  5810. case 0x5D: /* DELTAP1 */
  5811. Ins_DELTAP( EXEC_ARG_ args );
  5812. break;
  5813. case 0x5E: /* SDB */
  5814. DO_SDB
  5815. break;
  5816. case 0x5F: /* SDS */
  5817. DO_SDS
  5818. break;
  5819. case 0x60: /* ADD */
  5820. DO_ADD
  5821. break;
  5822. case 0x61: /* SUB */
  5823. DO_SUB
  5824. break;
  5825. case 0x62: /* DIV */
  5826. DO_DIV
  5827. break;
  5828. case 0x63: /* MUL */
  5829. DO_MUL
  5830. break;
  5831. case 0x64: /* ABS */
  5832. DO_ABS
  5833. break;
  5834. case 0x65: /* NEG */
  5835. DO_NEG
  5836. break;
  5837. case 0x66: /* FLOOR */
  5838. DO_FLOOR
  5839. break;
  5840. case 0x67: /* CEILING */
  5841. DO_CEILING
  5842. break;
  5843. case 0x68: /* ROUND */
  5844. case 0x69: /* ROUND */
  5845. case 0x6A: /* ROUND */
  5846. case 0x6B: /* ROUND */
  5847. DO_ROUND
  5848. break;
  5849. case 0x6C: /* NROUND */
  5850. case 0x6D: /* NROUND */
  5851. case 0x6E: /* NRRUND */
  5852. case 0x6F: /* NROUND */
  5853. DO_NROUND
  5854. break;
  5855. case 0x70: /* WCVTF */
  5856. DO_WCVTF
  5857. break;
  5858. case 0x71: /* DELTAP2 */
  5859. case 0x72: /* DELTAP3 */
  5860. Ins_DELTAP( EXEC_ARG_ args );
  5861. break;
  5862. case 0x73: /* DELTAC0 */
  5863. case 0x74: /* DELTAC1 */
  5864. case 0x75: /* DELTAC2 */
  5865. Ins_DELTAC( EXEC_ARG_ args );
  5866. break;
  5867. case 0x76: /* SROUND */
  5868. DO_SROUND
  5869. break;
  5870. case 0x77: /* S45Round */
  5871. DO_S45ROUND
  5872. break;
  5873. case 0x78: /* JROT */
  5874. DO_JROT
  5875. break;
  5876. case 0x79: /* JROF */
  5877. DO_JROF
  5878. break;
  5879. case 0x7A: /* ROFF */
  5880. DO_ROFF
  5881. break;
  5882. case 0x7B: /* ???? */
  5883. Ins_UNKNOWN( EXEC_ARG_ args );
  5884. break;
  5885. case 0x7C: /* RUTG */
  5886. DO_RUTG
  5887. break;
  5888. case 0x7D: /* RDTG */
  5889. DO_RDTG
  5890. break;
  5891. case 0x7E: /* SANGW */
  5892. case 0x7F: /* AA */
  5893. /* nothing - obsolete */
  5894. break;
  5895. case 0x80: /* FLIPPT */
  5896. Ins_FLIPPT( EXEC_ARG_ args );
  5897. break;
  5898. case 0x81: /* FLIPRGON */
  5899. Ins_FLIPRGON( EXEC_ARG_ args );
  5900. break;
  5901. case 0x82: /* FLIPRGOFF */
  5902. Ins_FLIPRGOFF( EXEC_ARG_ args );
  5903. break;
  5904. case 0x83: /* UNKNOWN */
  5905. case 0x84: /* UNKNOWN */
  5906. Ins_UNKNOWN( EXEC_ARG_ args );
  5907. break;
  5908. case 0x85: /* SCANCTRL */
  5909. Ins_SCANCTRL( EXEC_ARG_ args );
  5910. break;
  5911. case 0x86: /* SDPVTL */
  5912. case 0x87: /* SDPVTL */
  5913. Ins_SDPVTL( EXEC_ARG_ args );
  5914. break;
  5915. case 0x88: /* GETINFO */
  5916. Ins_GETINFO( EXEC_ARG_ args );
  5917. break;
  5918. case 0x89: /* IDEF */
  5919. Ins_IDEF( EXEC_ARG_ args );
  5920. break;
  5921. case 0x8A: /* ROLL */
  5922. Ins_ROLL( EXEC_ARG_ args );
  5923. break;
  5924. case 0x8B: /* MAX */
  5925. DO_MAX
  5926. break;
  5927. case 0x8C: /* MIN */
  5928. DO_MIN
  5929. break;
  5930. case 0x8D: /* SCANTYPE */
  5931. Ins_SCANTYPE( EXEC_ARG_ args );
  5932. break;
  5933. case 0x8E: /* INSTCTRL */
  5934. Ins_INSTCTRL( EXEC_ARG_ args );
  5935. break;
  5936. case 0x8F:
  5937. Ins_UNKNOWN( EXEC_ARG_ args );
  5938. break;
  5939. default:
  5940. if ( opcode >= 0xE0 )
  5941. Ins_MIRP( EXEC_ARG_ args );
  5942. else if ( opcode >= 0xC0 )
  5943. Ins_MDRP( EXEC_ARG_ args );
  5944. else if ( opcode >= 0xB8 )
  5945. Ins_PUSHW( EXEC_ARG_ args );
  5946. else if ( opcode >= 0xB0 )
  5947. Ins_PUSHB( EXEC_ARG_ args );
  5948. else
  5949. Ins_UNKNOWN( EXEC_ARG_ args );
  5950. }
  5951. }
  5952. #else
  5953. Instruct_Dispatch[CUR.opcode]( EXEC_ARG_ &CUR.stack[CUR.args] );
  5954. #endif /* TT_CONFIG_OPTION_INTERPRETER_SWITCH */
  5955. if ( CUR.error != TT_Err_Ok )
  5956. {
  5957. switch ( CUR.error )
  5958. {
  5959. case TT_Err_Invalid_Opcode: /* looking for redefined instructions */
  5960. {
  5961. TT_DefRecord* def = CUR.IDefs;
  5962. TT_DefRecord* limit = def + CUR.numIDefs;
  5963. for ( ; def < limit; def++ )
  5964. {
  5965. if ( def->active && CUR.opcode == (FT_Byte)def->opc )
  5966. {
  5967. TT_CallRec* callrec;
  5968. if ( CUR.callTop >= CUR.callSize )
  5969. {
  5970. CUR.error = TT_Err_Invalid_Reference;
  5971. goto LErrorLabel_;
  5972. }
  5973. callrec = &CUR.callStack[CUR.callTop];
  5974. callrec->Caller_Range = CUR.curRange;
  5975. callrec->Caller_IP = CUR.IP + 1;
  5976. callrec->Cur_Count = 1;
  5977. callrec->Cur_Restart = def->start;
  5978. if ( INS_Goto_CodeRange( def->range, def->start ) == FAILURE )
  5979. goto LErrorLabel_;
  5980. goto LSuiteLabel_;
  5981. }
  5982. }
  5983. }
  5984. CUR.error = TT_Err_Invalid_Opcode;
  5985. goto LErrorLabel_;
  5986. #if 0
  5987. break; /* Unreachable code warning suppression. */
  5988. /* Leave to remind in case a later change the editor */
  5989. /* to consider break; */
  5990. #endif
  5991. default:
  5992. goto LErrorLabel_;
  5993. #if 0
  5994. break;
  5995. #endif
  5996. }
  5997. }
  5998. CUR.top = CUR.new_top;
  5999. if ( CUR.step_ins )
  6000. CUR.IP += CUR.length;
  6001. /* increment instruction counter and check if we didn't */
  6002. /* run this program for too long (e.g. infinite loops). */
  6003. if ( ++ins_counter > MAX_RUNNABLE_OPCODES )
  6004. return TT_Err_Execution_Too_Long;
  6005. LSuiteLabel_:
  6006. if ( CUR.IP >= CUR.codeSize )
  6007. {
  6008. if ( CUR.callTop > 0 )
  6009. {
  6010. CUR.error = TT_Err_Code_Overflow;
  6011. goto LErrorLabel_;
  6012. }
  6013. else
  6014. goto LNo_Error_;
  6015. }
  6016. } while ( !CUR.instruction_trap );
  6017. LNo_Error_:
  6018. #ifdef TT_CONFIG_OPTION_STATIC_RASTER
  6019. *exc = cur;
  6020. #endif
  6021. return TT_Err_Ok;
  6022. LErrorCodeOverflow_:
  6023. CUR.error = TT_Err_Code_Overflow;
  6024. LErrorLabel_:
  6025. #ifdef TT_CONFIG_OPTION_STATIC_RASTER
  6026. *exc = cur;
  6027. #endif
  6028. return CUR.error;
  6029. }
  6030. #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
  6031. /* END */