This is FontEntry.m in view mode; [Download] [Up]
/***********************************************************************\ Font Entry class for Convert RTF which converts between Mac and NeXT rtf formats. Copyright (C) 1993 David John Burrowes 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 1, 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. The author, David John Burrowes, can be reached at: davidjohn@kira.net.netcom.com David John Burrowes 1926 Ivy #10 San Mateo, CA 94403-1367 \***********************************************************************/ #include "FontEntry.h" #include "rtfToken.h" #include <stdio.h> #include <string.h> @implementation FontEntry ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: init: // Parameters: none // Returns: self // Stores: none // Description: // This initalizes the instance so that it's values are all 0, save FontName which is // set to an empty cstring. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - init { [super init]; FontNumber = 0; FontType = NullInstance; FontName = NewCString(0); Count = 0; Convert = NoConversion; return self; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: free: // Parameters: none // Returns: self // Stores: none // Description: // This disposes of the instance, freeing the string and the type if appropriate. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - free { if (FontType != NullInstance) [FontType free]; FreeCString(FontName); return [super free]; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: IncrementCount // Parameters: none // Returns: self // Stores: none // Description: // This adds one to the instance's count variable // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - IncrementCount { Count ++; return self; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: DecrementCount // Parameters: none // Returns: self // Stores: none // Description: // This subtracts one to the instance's count variable // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - DecrementCount { Count --; return self; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: GetCount // Parameters: none // Returns: An Integer representing the current count. // Stores: none // Description: // This returns an integer that shows the current count value. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (Integer) GetCount; { return Count; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: SetCount // Parameters: an integer // Returns: self // Stores: none // Description: // This replaces the current value of the count variable with whatever the caller has // specified here. This should be a rare thing to call. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - SetCount: (Integer) NewCount { Count = NewCount; return self; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: SetNumber: // Parameters: an integer // Returns: self // Stores: none // Description: // This replaces the current value of the Font number value with the one the caller has // specified. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - SetNumber: (Integer) NewNumber { FontNumber = NewNumber; return self; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: GetNumber // Parameters: none // Returns: an integer // Stores: none // Description: // Returns the current value of the font number to the caller. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (Integer) GetNumber { return FontNumber; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: SetFontType: // Parameters: An instance value // Returns: self // Stores: none // Description: // This replaces any existing font type value in the instance with the one specified by // the caller. It does NOT make a copy. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - SetFontType: theType { if (FontType != NullInstance) [FontType free]; FontType = theType; return self; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: GetFontType // Parameters: none // Returns: An Instance // Stores: none // Description: // Returns the current value of the font type instance to the caller. It does this // by making a new token, and copying the values over. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (Instance) GetFontType { Instance tokenCopy = [[rtfToken alloc] initTokenOfType: [FontType GetType]]; CString stupidMemLeak; stupidMemLeak = [FontType GetName]; [tokenCopy SetTokenName: stupidMemLeak]; FreeCString(stupidMemLeak); if ( [FontType HasValue] == YES) [tokenCopy SetTokenValue: [FontType GetValue]]; return tokenCopy; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: SetConversion: // Parameters: An enumerated value // Returns: self // Stores: none // Description: // When called, this will set the conversion flag in the instance to the value specified by // the caller. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - SetConversion: (ConvertTypes) newConvert { Convert = newConvert; return self; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: GetConversion // Parameters: none // Returns: A convert type value. // Stores: none // Description: // Returns the current value of the font conversion value to the caller. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (ConvertTypes) GetConversion { return Convert; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: SetName: // Parameters: An enumerated value // Returns: self // Stores: none // Description: // When called, this will set the name of the font to the specified string. This does // make a copy of the string in the process. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - SetName: (CString) TheName { FreeCString(FontName); FontName = NewCString(strlen(TheName)); strcpy(FontName, TheName); return self; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: GetName // Parameters: none // Returns: self // Stores: none // Description: // Returns a copy of the string of the name of the font. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (CString) GetName { CString temp = NewCString(strlen(FontName)); strcpy(temp, FontName); return temp; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: AppendToName: // Parameters: A CString // Returns: self // Stores: none // Description: // This takes a string, and appends it to the font name we have so far. // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - AppendToName: (CString) TheName { CString temp = NewCString(strlen(FontName) + strlen(TheName)); strcpy(temp, FontName); strcat(temp, TheName); FreeCString(FontName); FontName = temp; return self; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Routine: PrepName // Parameters: none // Returns: self // Stores: none // Description: // This removes trailing semicolons, if any, and then removes leading and trailing // spaces in the font's name // Bugs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - PrepName { Integer location = strlen(FontName) - 1; Integer newlocation; // // First, back up past any trailing spaces and semicolons, and then 'null them out' // if ((FontName[location] == ' ') || (FontName[location] == ';')) location--; FontName[location+1] = EndOfCString; // // Second, start copying characters, from start to end, over leading spaces, if any. // location = 0; while (FontName[location] == ' ') location++; if (location != 0) { newlocation = 0; while (FontName[location] != EndOfCString) { FontName[newlocation] = FontName[location]; location++; newlocation++; } FontName[newlocation] = EndOfCString; } return self; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.