Welcome to MacForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

I cant eject cd wen my application once read from cd.Pleas..

 
   Macintosh computer (Home) -> Tools RSS
Next:  Mac PGP 5.5.x sources?  
Author Message
Noufal

External


Since: Sep 26, 2006
Posts: 4



(Msg. 1) Posted: Sun Oct 01, 2006 10:53 pm
Post subject: I cant eject cd wen my application once read from cd.Please Help
Archived from groups: comp>sys>mac>programmer>tools (more info?)

Hai all
I newbie in cocoa.I am now with font manager devolopment. The proj
want to read font from CD.I can read data from cd and use the data.but
I cant to eject cd wen application loaded and readed once from CD.After
reading i read font from system font. then also i cant eject cd .CD
can eject only after closing application .
Wen try to close then a dialog box appears with "one application is
using cd close application and try".
I tried by removing all datas from arrays used,but then also cant
eject.

The pgm. work with font is below .please check that i hav missed any
code to be added with this to remove control over directory that is
currently using.

I have no idea about FSRef,FSpath,ATSFontRef.If anyone of the above
want to release or deallocate.I think one of them are continuing
control of cd wen once read data from cd.Wat i will do to eject cd wen
app. is running.Ejecting cd is for changing the cd and try it with
another cd.

Excuse my english .Please help


- (NSMutableArray *)checkFont:(NSString *)path
{
NSMutableArray *myfonts=nil;
myfonts=[[NSMutableArray alloc]init];
[myfonts removeAllObjects];
NSFont *f=nil;
CFStringRef fontName=NULL;
ATSFontContainerRef container;
FSRef fsRef;
FSSpec fsSpec;
FSCatalogInfo catinfo;
int osstatus = FSPathMakeRef((const UInt8*)[path UTF8String], &fsRef,
NULL);
osstatus =
FSGetCatalogInfo(&fsRef,kFSCatInfoNone,&catinfo,NULL,&fsSpec,NULL);
osstatus = ATSFontActivateFromFileSpecification ( &fsSpec,
kATSFontContextLocal, kATSFontFormatUnspecified,
NULL, kATSOptionFlagsDefault, &container);
if (osstatus != noErr)
{
//NSLog(@"Got error %d loading %@!!!",osstatus,path);
}

else
{
int fntcount;
ItemCount count;
ByteCount bcount;




osstatus = ATSFontFindFromContainer (container,
kATSOptionFlagsDefault, 0, NULL,&count);
ATSFontRef *ioArray=(ATSFontRef *)malloc(count * sizeof(ATSFontRef));
osstatus = ATSFontFindFromContainer (container,
kATSOptionFlagsDefault, count, ioArray,&count);


for (fntcount=0; fntcount < count ; fntcount++ ) {


osstatus = ATSFontGetName (ioArray[fntcount], kATSOptionFlagsDefault,
&fontName);

if (fontName) f = [NSFont fontWithName:(NSString*)fontName size:24];

if ( f != nil )
{
[myfonts addObject:f];

}[f release];



// osstatus=ATSFontGetFontFamilyResource(ioArray[fntcount],bcount,&iobuffer,&bcount)
}


}
[f release];
//CFRelease(path);
return myfonts;
}

- (NSMutableArray *) getFonts:(NSString *)path
{

//Declaring

NSFont *getfont;
NSArray *getArray;
NSString *getfile;
NSString *fileandfontname;
NSMutableArray *fontarray,*getfontarr;
NSFileManager *fm;
NSString *locinfo,*userdir;

//Intializing
fontarray=[[NSMutableArray alloc] init];
getfontarr=[[NSMutableArray alloc] init];
[getfontarr removeAllObjects];
[fontarray removeAllObjects];
fm=[NSFileManager defaultManager];
getArray=[fm directoryContentsAtPath:path];
userdir=NSHomeDirectory();
userdir=[userdir stringByAppendingPathComponent:@"/Library/Fonts/"];

int rowcount=0;
//getting path info

if ( [path isEqualToString:userdir])
{
locinfo=@"User";
}
else if ([path isEqualToString:@"/Network/Library/Fonts/"]) {
locinfo=@"Network";
}
else if ([path isEqualToString:@"/System/Library/Fonts/"]) {
locinfo=@"System";
}
else if ([path isEqualToString:@"/Library/Fonts/"]) {
locinfo=@"Library";
}
else if ([path isEqualToString:@"/Volumes/Summitsft"]) {
locinfo=@"Summitsoft";
}
else if ([path rangeOfString:@"macXware Fonts"].length) {
locinfo=@"Summitsoft";
}
else {
locinfo=@"Vault";
}



int fontcount;
MDItemRef mdataitem;
NSString *ftype,*ffoundary;
NSFontDescriptor *fontdisc;
NSFontSymbolicTraits fst;
NSFontFamilyClass ffc;
int fcval;

for (rowcount=0; rowcount < [getArray count]; rowcount++)
{
//Getting Full file path
getfile=[getArray objectAtIndex:rowcount];
getfile=[path stringByAppendingPathComponent:getfile];

//Calling Function
getfontarr=[self checkFont:getfile];

//===================================================================
//Getting info from file MetaData ,it works 10.4 and above
mdataitem=MDItemCreate(NULL,(CFStringRef)getfile);
// ftype=(id)MDItemCopyAttribute( mdataitem , kMDItemKind);
ffoundary=(id)MDItemCopyAttribute( mdataitem , kMDItemCopyright);

if (ffoundary == nil )
ffoundary=@"--";

if (ftype == nil)
ftype=[self FindTypeByExt:getfile];

//====================================================================



for (fontcount=0 ; fontcount < [ getfontarr count] ; fontcount++) {

getfont=[getfontarr objectAtIndex:fontcount];

//If the file is font then adding to Array
if ( getfont != nil )
{
//Getting font Descriptor
fontdisc=[getfont fontDescriptor];
fst=[fontdisc symbolicTraits];
// NSLog(@"%u",fst);

fileandfontname=[getfont fontName];
fileandfontname=[fileandfontname stringByAppendingString:@"/"];
fileandfontname=[fileandfontname stringByAppendingString:[getArray
objectAtIndex:rowcount]];
fileandfontname=[fileandfontname
stringByAppendingString:@"/"];
fileandfontname=[fileandfontname stringByAppendingString:locinfo];
fileandfontname=[fileandfontname stringByAppendingString:@"/"];
fileandfontname=[fileandfontname stringByAppendingString:ftype];
fileandfontname=[fileandfontname stringByAppendingString:@"/"];
fileandfontname=[fileandfontname stringByAppendingString:ffoundary];

[fontarray addObject:fileandfontname];

}
}


}


//Returning Objects
return fontarray;


}

 >> Stay informed about: I cant eject cd wen my application once read from cd.Pleas.. 
Back to top
Login to vote
David Phillip Oste

External


Since: Apr 25, 2004
Posts: 694



(Msg. 2) Posted: Mon Oct 02, 2006 2:24 pm
Post subject: Re: I cant eject cd wen my application once read from cd.Please Help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
"Noufal" wrote:

> Hai all
> I newbie in cocoa.I am now with font manager devolopment. The proj
> want to read font from CD.I can read data from cd and use the data.but
> I cant to eject cd wen application loaded and readed once from CD.After
> reading i read font from system font. then also i cant eject cd .CD
> can eject only after closing application .
> Wen try to close then a dialog box appears with "one application is
> using cd close application and try".
> I tried by removing all datas from arrays used,but then also cant
> eject.

If you ATSFontActivateFromFileSpecification() from a file on a CD,
you'll need to ATSFontDeactivate() if you expect to ever remove the CD.

>
> The pgm. work with font is below .please check that i hav missed any
> code to be added with this to remove control over directory that is
> currently using.
>
> I have no idea about FSRef,FSpath,ATSFontRef.If anyone of the above
> want to release or deallocate.I think one of them are continuing
> control of cd wen once read data from cd.Wat i will do to eject cd wen
> app. is running.Ejecting cd is for changing the cd and try it with
> another cd.
>
> Excuse my english .Please help
>
>
> - (NSMutableArray *)checkFont:(NSString *)path
> {
> NSMutableArray *myfonts=nil;
> myfonts=[[NSMutableArray alloc]init];
> [myfonts removeAllObjects];

myfonts is born empty. No need to empty it again.

> NSFont *f=nil;
> CFStringRef fontName=NULL;
> ATSFontContainerRef container;
> FSRef fsRef;
> FSSpec fsSpec;
> FSCatalogInfo catinfo;
> int osstatus = FSPathMakeRef((const UInt8*)[path UTF8String], &fsRef,
> NULL);
> osstatus =
> FSGetCatalogInfo(&fsRef,kFSCatInfoNone,&catinfo,NULL,&fsSpec,NULL);
> osstatus = ATSFontActivateFromFileSpecification ( &fsSpec,
> kATSFontContextLocal, kATSFontFormatUnspecified,
> NULL, kATSOptionFlagsDefault, &container);
> if (osstatus != noErr)
> {
> //NSLog(@"Got error %d loading %@!!!",osstatus,path);
> }
>
> else
> {
> int fntcount;
> ItemCount count;
> ByteCount bcount;
>
>
>
>
> osstatus = ATSFontFindFromContainer (container,
> kATSOptionFlagsDefault, 0, NULL,&count);

It is good, that you assign the return value to osstatus. But, you
should check, as you do above, that osstatus == noErr.

> ATSFontRef *ioArray=(ATSFontRef *)malloc(count * sizeof(ATSFontRef));

You'll need to free ioArray before returning

> osstatus = ATSFontFindFromContainer (container,
> kATSOptionFlagsDefault, count, ioArray,&count);
>

>
> for (fntcount=0; fntcount < count ; fntcount++ ) {
>
>
> osstatus = ATSFontGetName (ioArray[fntcount], kATSOptionFlagsDefault,
> &fontName);
>
> if (fontName) f = [NSFont fontWithName:(NSString*)fontName size:24];
>
> if ( f != nil )
> {
> [myfonts addObject:f];
>
> }[f release];

Remove the [f release] : since you don't init or copy f, you shouldn't
release it.

Here, you need an: f=nil;
Think about what would happen if, the third time through the loop,
fontName was nil.

>
>
>
> //
> osstatus=ATSFontGetFontFamilyResource(ioArray[fntcount],bcount,&iobuffer,&bcou
> nt)
> }
>
>
> }
> [f release];


Remove the [f release] : since you don't init or copy f, you shouldn't
release it.

> //CFRelease(path);

Remove the CFRelease(path) : since you don't init or copy path, you
shouldn't release it.

> return myfonts;
> }
>
> - (NSMutableArray *) getFonts:(NSString *)path
> {
>
> //Declaring
>
> NSFont *getfont;
> NSArray *getArray;
> NSString *getfile;
> NSString *fileandfontname;
> NSMutableArray *fontarray,*getfontarr;
> NSFileManager *fm;
> NSString *locinfo,*userdir;
>
> //Intializing
> fontarray=[[NSMutableArray alloc] init];
> getfontarr=[[NSMutableArray alloc] init];
> [getfontarr removeAllObjects];
> [fontarray removeAllObjects];
> fm=[NSFileManager defaultManager];
> getArray=[fm directoryContentsAtPath:path];
> userdir=NSHomeDirectory();
> userdir=[userdir stringByAppendingPathComponent:@"/Library/Fonts/"];
>
> int rowcount=0;
> //getting path info
>
> if ( [path isEqualToString:userdir])
> {
> locinfo=@"User";
> }
> else if ([path isEqualToString:@"/Network/Library/Fonts/"]) {
> locinfo=@"Network";
> }
> else if ([path isEqualToString:@"/System/Library/Fonts/"]) {
> locinfo=@"System";
> }
> else if ([path isEqualToString:@"/Library/Fonts/"]) {
> locinfo=@"Library";
> }
> else if ([path isEqualToString:@"/Volumes/Summitsft"]) {
> locinfo=@"Summitsoft";
> }
> else if ([path rangeOfString:@"macXware Fonts"].length) {
> locinfo=@"Summitsoft";
> }
> else {
> locinfo=@"Vault";
> }
>
>
>
> int fontcount;
> MDItemRef mdataitem;
> NSString *ftype,*ffoundary;
> NSFontDescriptor *fontdisc;
> NSFontSymbolicTraits fst;
> NSFontFamilyClass ffc;
> int fcval;
>
> for (rowcount=0; rowcount < [getArray count]; rowcount++)
> {
> //Getting Full file path
> getfile=[getArray objectAtIndex:rowcount];
> getfile=[path stringByAppendingPathComponent:getfile];
>
> //Calling Function
> getfontarr=[self checkFont:getfile];
>
> //===================================================================
> //Getting info from file MetaData ,it works 10.4 and above
> mdataitem=MDItemCreate(NULL,(CFStringRef)getfile);
> // ftype=(id)MDItemCopyAttribute( mdataitem , kMDItemKind);
> ffoundary=(id)MDItemCopyAttribute( mdataitem , kMDItemCopyright);
>
> if (ffoundary == nil )
> ffoundary=@"--";
>
> if (ftype == nil)
> ftype=[self FindTypeByExt:getfile];
>
> //====================================================================
>
>
>
> for (fontcount=0 ; fontcount < [ getfontarr count] ; fontcount++) {
>
> getfont=[getfontarr objectAtIndex:fontcount];
>
> //If the file is font then adding to Array
> if ( getfont != nil )
> {
> //Getting font Descriptor
> fontdisc=[getfont fontDescriptor];
> fst=[fontdisc symbolicTraits];
> // NSLog(@"%u",fst);
>
> fileandfontname=[getfont fontName];
> fileandfontname=[fileandfontname stringByAppendingString:@"/"];
> fileandfontname=[fileandfontname stringByAppendingString:[getArray
> objectAtIndex:rowcount]];
> fileandfontname=[fileandfontname
> stringByAppendingString:@"/"];
> fileandfontname=[fileandfontname stringByAppendingString:locinfo];
> fileandfontname=[fileandfontname stringByAppendingString:@"/"];
> fileandfontname=[fileandfontname stringByAppendingString:ftype];
> fileandfontname=[fileandfontname stringByAppendingString:@"/"];
> fileandfontname=[fileandfontname stringByAppendingString:ffoundary];
>
> [fontarray addObject:fileandfontname];
>
> }
> }
>
>
> }
>
>
> //Returning Objects
> return fontarray;
>
>
> }

 >> Stay informed about: I cant eject cd wen my application once read from cd.Pleas.. 
Back to top
Login to vote
Noufal

External


Since: Sep 26, 2006
Posts: 4



(Msg. 3) Posted: Mon Oct 02, 2006 9:28 pm
Post subject: Re: I cant eject cd wen my application once read from cd.Please Help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Back to top
Login to vote
Noufal

External


Since: Sep 26, 2006
Posts: 4



(Msg. 4) Posted: Tue Oct 03, 2006 11:57 pm
Post subject: Re: Another problem again [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I done it .I can eject cd.But ter another problem,I using these font in
another class there the name of font return null value.So i cant change
the font.Wen I use complete code there that solved for some fonts, but
others are show missing,and this consume large time to load each font.
And then try to ATSFont deallocation at second class but then i cant to
remov cd
If u hav any soln pls help me.
With thanks
Noufal
 >> Stay informed about: I cant eject cd wen my application once read from cd.Pleas.. 
Back to top
Login to vote
Display posts from previous:   
   Macintosh computer (Home) -> Tools All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]