 |
|
 |
|
Next: how remove control of CD drive by application
|
| Author |
Message |
External

Since: Sep 26, 2006 Posts: 9
|
(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 |
|
 |  |
External

Since: Apr 25, 2004 Posts: 974
|
(Msg. 2) Posted: Mon Oct 02, 2006 11:55 am
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 |
|
 |  |
External

Since: Sep 26, 2006 Posts: 9
|
(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 |
|
 |  |
External

Since: Sep 26, 2006 Posts: 9
|
(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 |
|
 |  |
| Related Topics: | Read image file from disk - Hello everybody, I want to use vImage library for image processing. This library does not contain any function to read and write image from and to the disk. How can I do that? Thanks, Geppy
help ! PEF Executable using XCODE ?? - ------------------------------------------------------------------------ A poll associated with this post was created, to vote and see the results, please visit http://www.codecomments.com/message235968.html..
Browser Controls... - Are there any browser controls which supports all the versions of MAC OS ? ie : MAC OS X and 8/9 ?? Will Opera Support ?!! rG -- macro ------------------------------------------------------------------------ Posted via http://www.codecomments.com..
Beginning for Beginning Beginners - I occasionally become motivated to dabble in programming, just to the point of getting a particular task done, and am wondering where I should start. I am generally more interested in the ends rather than the means. I want to work with what is availabl...
Gentoo for installing Unix programs on Mac OS - I have been slightly interested in some Unix applications, but haven't fallen into the mood to do the line command dance merely to open them, well build them that is (Although I think I remember using Fink in an earlier version of OS X) Anyone have any.... |
|
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
|
|
|
|
 |
|
|