Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / November 2006



Tip: Looking for answers? Try searching our database.

Is file a font file?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yabber - 22 Nov 2006 16:15 GMT
How can detect a file without extension is font file or not in cocoa?

or any other
I tried with

CFStringRef fontNam=CFStringCreateWithCString(NULL,[getfile
UTF8String],kCFStringEncodingMacRoman);
ATSFontRef frefarr= ATSFontFindFromName((CFStringRef)[getArray
objectAtIndex:rowcount] ,kATSOptionFlagsDefault);

But frefarr gets nil any thing wrong

please help,
with thanks
Excuse my language.
matt neuburg - 22 Nov 2006 23:08 GMT
> How can detect a file without extension is font file or not in cocoa?
>
[quoted text clipped - 5 lines]
> ATSFontRef frefarr= ATSFontFindFromName((CFStringRef)[getArray
> objectAtIndex:rowcount] ,kATSOptionFlagsDefault);

ATSFontFindFromName has nothing to do with files: it just looks to see
if a font is loaded already.

I would suggest ATSFontActivateFromFileSpecification. If it doesn't
increase the number of available fonts, it wasn't a font file! :) m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

Yabber - 23 Nov 2006 17:32 GMT
> > How can detect a file without extension is font file or not in cocoa?
> >
[quoted text clipped - 10 lines]
>
> I would suggest ATSFontActivateFromFileSpecification.

ThanX
I used it but tere hav a problem tat it is time consuming to load a no:
of file.

Then activation is take place after that I use the activaed font to
desplay in text view as attriuted string for text storage.
After that I tried to deactivate  font then deactivation returned -45
(ie, file is locked)

Now I want know about how we can identify a file is font or not a font
without considering extension(ie,some file found without an extension)
Please help
With Thanks
Yabber
Excuse my language
matt neuburg - 23 Nov 2006 18:15 GMT
> > > How can detect a file without extension is font file or not in cocoa?
> > >
[quoted text clipped - 19 lines]
> After that I tried to deactivate  font then deactivation returned -45
> (ie, file is locked)

Perhaps you should show your code. The way you use
ATSFontActivateFromFileSpecification is that you are handed a
"container". You must retain this (be careful of memory management
issues here). When you want to deactivate the font(s), you hand this
container to ATSFontDeactivate. You should not get any "file is locked"
error because no file is involved - ATS is simply unloading the font
from its memory.

> Now I want know about how we can identify a file is font or not a font
> without considering extension(ie,some file found without an extension)

I think I just told you that. A file without an extension (and without a
type/creator code) could be *anything*. The only way to know if it's a
font is to throw some sort of font tool at it and see what it makes of
it.

You might try downloading Apple's font tools and see if any of them help
you more:

<http://developer.apple.com/textfonts/download/>

m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

Yabber - 27 Nov 2006 12:57 GMT
- (NSMutableArray *)checkFont:(NSString *)path
{

    NSMutableArray *myfonts=nil;
    myfonts=[[NSMutableArray alloc]init];
    NSString *checkpath=path;

    container=0;
    NSFont *f=nil;
    CFStringRef fontName=NULL;
    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];

         }

        }

        NSNumber *contno=[NSNumber numberWithInt:container];

         [containerarr addObject:contno];         //containerarr array is
used during deactivation
    }
    return myfonts;
}

This is my font activation code
After activating fonts Use the fonts display in a text view using

[[previewLoader textStorage] setAttributedString:atstr];
previewLoader is textview & atstr is attributed string with font &
paragraph.

after displaying I changed selected font to be displayed then
Deactivation font of current font is done after that activated selected
font.

-(void) deactivatefont{

    int arrc;
    for (arrc=[containerarr count];arrc>0;arrc--) {
        int coun=arrc-1;
        ATSFontContainerRef mycont=[[containerarr objectAtIndex:coun]
intValue];

    printf("/////////%d////////\n",ATSFontDeactivate(mycont,NULL,kATSOptionFlagsDefault));

    }

    [containerarr removeAllObjects];
}
This is deactivation part
But I cant to deactivate the deactivation part is returns value -45
when failed
And when deactivation is succees it returns 0

With thanks and regards
Excuse my language
Yabber
matt neuburg - 27 Nov 2006 18:44 GMT
> - (NSMutableArray *)checkFont:(NSString *)path
>       container=0;

But you didn't show me any declaration for "container".

>               NSNumber *contno=[NSNumber numberWithInt:container];
>             [containerarr addObject:contno];         //containerarr array is
> used during deactivation

(1) You have only one container - it was created when you did your
single call to ATSFontActivateFromFileSpecification. But you are adding
"contno" to your array many times, once for each font in the container.
That's a bug. When the time comes to deactivate, you're going to be
deactivating the same container over and over again. For example, if the
folder contains 5 fonts, you have one container but it is listed 5 times
in the array. So you're going to deactivate it, and then even if that
succeeds you're going to try to deactive it some more, which will
certain fail.

(2) A container is an ATSFontContainerRef, which is a UInt32, which is
unsigned. But you are creating your NSNumber using numberWithInt, which
expects a *signed* int. Furthermore, a UInt32 is a long. But
numberWithInt does not necessarily expect a long. That's a bug. You are
possibly throwing away important information and changing the number.
You should probably be using numberWithUnsignedLong. And be equally
careful when the time comes to retrieve it later.

So, I immediately found two bugs. Whether those are what is causing your
problem, I don't know - there may be other bugs - but I can certainly
say that without running your code, just looking at it for a few
seconds, I would not expect it to work.

m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

Yabber - 28 Nov 2006 14:21 GMT
Thanks for your help

Ok sorry for didnt giv declaration of container,it is before all

@implementation Font
NSMutableArray *containerarr;
ATSFontContainerRef container;

ok itried with deactivation with using container

-(void) deactivatefont{
        ATSFontDeactivate(container,NULL,kATSOptionFlagsDefault);
}

then also have the problem(cant deactivate)
The deactivation problem is found with fonts that are used to display
in NSTextview, others are deactivated

When font is use to display it will associate with a
mutabledictonary,attributed string,textstorage of NSTextView
I released dictionary ant attributed string

    [[previewLoader textStorage] setAttributedString:atstr];

When I commented the above  then font can deactivate

[defdict dealloc]; //defdict is mutable dictionary
[atstr dealloc];
anything else to be done to remove all controll from font file

With thanks
Yabber
matt neuburg - 28 Nov 2006 16:30 GMT
> The deactivation problem is found with fonts that are used to display
> in NSTextview, others are deactivated
[quoted text clipped - 10 lines]
> [atstr dealloc];
> anything else to be done to remove all controll from font file

Ah! Interesting. So it sounds like you can't deactivate the font until
you also stop using it. That makes sense. Sorry, didn't realize that. m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

Yabber - 30 Nov 2006 12:56 GMT
> > The deactivation problem is found with fonts that are used to display
> > in NSTextview, others are deactivated
[quoted text clipped - 13 lines]
> Ah! Interesting. So it sounds like you can't deactivate the font until
> you also stop using it. That makes sense. Sorry, didn't realize that. m.

Ok Thanks

I have another doubt,it may be foolish, please help
It is,Is it poosible to identify a file,it is font file or it is not a
font file without activating it?/

withregards yabber
matt neuburg - 30 Nov 2006 17:11 GMT
> > > The deactivation problem is found with fonts that are used to display
> > > in NSTextview, others are deactivated
[quoted text clipped - 19 lines]
> It is,Is it poosible to identify a file,it is font file or it is not a
> font file without activating it?

I already gave you my best answer to that question.

m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.