/* * Copyright (C) 1999 David Stes. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #include #include #include #include "AFM.h" #include "lexafm.h" #include "bbox.h" @implementation AFM - syntaxerror { lexafmtext[16] = '\0'; return [self error:"syntax error at line %d (%s...) in '%s'",lexafmlineno,lexafmtext,[fname str]]; } static BOOL getcharname(int tok) { if (tok == kString) return YES; switch (tok) { case kB : lexafmlval.i = [String str:"B"];return YES; case kC : lexafmlval.i = [String str:"C"];return YES; case kL : lexafmlval.i = [String str:"L"];return YES; case kN : lexafmlval.i = [String str:"N"];return YES; case kW : lexafmlval.i = [String str:"W"];return YES; default : break; } return NO; } static void done(id x) { [x syntaxerror]; } - parsefile { int i,j,k,l,token; if (lexafmlex() != kStartFontMetrics) done(self); if (lexafmlex() != kDouble) done(self); while ((token=lexafmlex()) == kComment) { if (lexafmlex() != kString) done(self); } if (token != kFontName) done(self); if (lexafmlex() != kString) done(self); else FontName=lexafmlval.i; if (lexafmlex() != kFullName) done(self); if (lexafmlex() != kString) done(self); else FullName=lexafmlval.i; if (lexafmlex() != kFamilyName) done(self); if (lexafmlex() != kString) done(self); else FamilyName=lexafmlval.i; if (lexafmlex() != kWeight) done(self); if (lexafmlex() != kString) done(self); else Weight=lexafmlval.i; if (lexafmlex() != kItalicAngle) done(self); switch ((token = lexafmlex())) { case kLong: ItalicAngle = lexafmlval.l;break; case kDouble: ItalicAngle = lexafmlval.d;break; default: done(self); } if (lexafmlex() != kIsFixedPitch) done(self); if (lexafmlex() != kBool) done(self); else IsFixedPitch=lexafmlval.l; if (lexafmlex() != kFontBBox) done(self); if (lexafmlex() != kLong) done(self); else FontBBox_llx=lexafmlval.l; if (lexafmlex() != kLong) done(self); else FontBBox_lly=lexafmlval.l; if (lexafmlex() != kLong) done(self); else FontBBox_urx=lexafmlval.l; if (lexafmlex() != kLong) done(self); else FontBBox_ury=lexafmlval.l; if (lexafmlex() != kUnderlinePosition) done(self); if (lexafmlex() != kLong) done(self); else UnderlinePosition=lexafmlval.l; if (lexafmlex() != kUnderlineThickness) done(self); if (lexafmlex() != kLong) done(self); else UnderlineThickness=lexafmlval.l; if (lexafmlex() != kVersion) done(self); if (lexafmlex() != kString) done(self); else Version=lexafmlval.i; if (lexafmlex() != kNotice) done(self); if (lexafmlex() != kString) done(self); else Notice=lexafmlval.i; if (lexafmlex() != kEncodingScheme) done(self); if (lexafmlex() != kString) done(self); else EncodingScheme=lexafmlval.i; if (lexafmlex() != kCapHeight) done(self); if (lexafmlex() != kLong) done(self); else CapHeight=lexafmlval.l; if (lexafmlex() != kXHeight) done(self); if (lexafmlex() != kLong) done(self); else XHeight=lexafmlval.l; if (lexafmlex() != kAscender) done(self); if (lexafmlex() != kLong) done(self); else Ascender=lexafmlval.l; if (lexafmlex() != kDescender) done(self); if (lexafmlex() != kLong) done(self); else Descender=lexafmlval.l; if (lexafmlex() != kStartCharMetrics) done(self); if (lexafmlex() != kLong) done(self); else Characters=lexafmlval.l; CharacterSet = [OrdCltn new]; for(token=lexafmlex();;) { int a,b,c,d; id bbox = [BoundingBox new]; if (token != kC) done(self); else token = lexafmlex(); if (token != kLong) done(self); else i=lexafmlval.l; [bbox setcharcode:i]; token = lexafmlex(); if (token != kSemi) done(self); else token = lexafmlex(); if (token != kWX) done(self); else token = lexafmlex(); if (token != kLong) done(self); else [bbox setwx:lexafmlval.l]; token = lexafmlex(); if (token != kSemi) done(self); else token = lexafmlex(); if (token != kN) done(self); else token = lexafmlex(); if (!getcharname(token)) done(self); else [bbox setcharname:lexafmlval.i]; token = lexafmlex(); if (token != kSemi) done(self); else token = lexafmlex(); if (token != kB) done(self); else token = lexafmlex(); if (token != kLong) done(self); else a = lexafmlval.l;token = lexafmlex(); if (token != kLong) done(self); else b = lexafmlval.l;token = lexafmlex(); if (token != kLong) done(self); else c = lexafmlval.l;token = lexafmlex(); if (token != kLong) done(self); else d = lexafmlval.l;token = lexafmlex(); if (token != kSemi) done(self); else token = lexafmlex(); [bbox origin:a:b]; [bbox corner:c:d]; /* not interested in ligatures */ while (token == kL) { token = lexafmlex(); if (!getcharname(token)) done(self); else token = lexafmlex(); if (!getcharname(token)) done(self); else token = lexafmlex(); if (token != kSemi) done(self); else token = lexafmlex(); } for(j=[CharacterSet size];j