Example #1
0
void WriteThumbnailToResourceFork(FSRef *ref, int destWidth, int destHeight)
{
	OSStatus		err;
	PicHandle		pict;
	HFSUniStr255	fork;
	SInt16			resf;
	
	err = FSGetResourceForkName(&fork);
	if (err == noErr)
	{
		err = FSCreateResourceFork(ref, fork.length, fork.unicode, 0);
		if ((err == noErr) || (err == errFSForkExists))
		{
			err = FSOpenResourceFile(ref, fork.length, fork.unicode, fsWrPerm, &resf);
			if (err == noErr)
			{
				pict = GetScreenAsPicHandle(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, destWidth, destHeight);
				if (pict)
				{
					AddResource((Handle) pict, 'PICT', 128, "\p");
					WriteResource((Handle) pict);
					ReleaseResource((Handle) pict);
				}
				
				CloseResFile(resf);
			}
Example #2
0
static PyObject *Res_FSOpenResourceFile(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    OSErr _err;
    FSRef ref;
    UniChar *forkNameLength__in__;
    UniCharCount forkNameLength__len__;
    int forkNameLength__in_len__;
    SignedByte permissions;
    ResFileRefNum refNum;
#ifndef FSOpenResourceFile
    PyMac_PRECHECK(FSOpenResourceFile);
#endif
    if (!PyArg_ParseTuple(_args, "O&u#b",
                          PyMac_GetFSRef, &ref,
                          &forkNameLength__in__, &forkNameLength__in_len__,
                          &permissions))
        return NULL;
    forkNameLength__len__ = forkNameLength__in_len__;
    _err = FSOpenResourceFile(&ref,
                              forkNameLength__len__, forkNameLength__in__,
                              permissions,
                              &refNum);
    if (_err != noErr) return PyMac_Error(_err);
    _res = Py_BuildValue("h",
                         refNum);
    return _res;
}
Example #3
0
  /* Create a new FT_Face from a file spec to a suitcase file. */
  static FT_Error
  FT_New_Face_From_dfont( FT_Library  library,
                          FSSpec*     spec,
                          FT_Long     face_index,
                          FT_Face*    aface )
  {
    FT_Error  error = FT_Err_Ok;
    short     res_ref, res_index;
    Handle    fond;
    FSRef     hostContainerRef;


    error = FSpMakeFSRef( spec, &hostContainerRef );
    if ( error == noErr )
      error = FSOpenResourceFile( &hostContainerRef,
                                  0, NULL, fsRdPerm, &res_ref );

    if ( error != noErr )
      return FT_Err_Cannot_Open_Resource;

    UseResFile( res_ref );

    /* face_index may be -1, in which case we
       just need to do a sanity check */
    if ( face_index < 0 )
      res_index = 1;
    else
    {
      res_index = (short)( face_index + 1 );
      face_index = 0;
    }
    fond = Get1IndResource( 'FOND', res_index );
    if ( ResError() )
    {
      error = FT_Err_Cannot_Open_Resource;
      goto Error;
    }

    error = FT_New_Face_From_FOND( library, fond, face_index, aface );

  Error:
    CloseResFile( res_ref );
    return error;
  }
Example #4
0
  static OSErr
  FT_FSPathMakeRes( const UInt8*    pathname,
                    ResFileRefNum*  res )
  {

#if HAVE_FSREF

    OSErr  err;
    FSRef  ref;


    if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) )
      return FT_THROW( Cannot_Open_Resource );

    /* at present, no support for dfont format */
    err = FSOpenResourceFile( &ref, 0, NULL, fsRdPerm, res );
    if ( noErr == err )
      return err;

    /* fallback to original resource-fork font */
    *res = FSOpenResFile( &ref, fsRdPerm );
    err  = ResError();

#else

    OSErr   err;
    FSSpec  spec;


    if ( noErr != FT_FSPathMakeSpec( pathname, &spec, FALSE ) )
      return FT_THROW( Cannot_Open_Resource );

    /* at present, no support for dfont format without FSRef */
    /* (see above), try original resource-fork font          */
    *res = FSpOpenResFile( &spec, fsRdPerm );
    err  = ResError();

#endif /* HAVE_FSREF */

    return err;
  }
Example #5
0
File: ftmac.c Project: 32767/libgdx
  static OSErr
  FT_FSPathMakeRes( const UInt8*    pathname,
                    ResFileRefNum*  res )
  {
    OSErr  err;
    FSRef  ref;


    if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) )
      return FT_Err_Cannot_Open_Resource;

    /* at present, no support for dfont format */
    err = FSOpenResourceFile( &ref, 0, NULL, fsRdPerm, res );
    if ( noErr == err )
      return err;

    /* fallback to original resource-fork font */
    *res = FSOpenResFile( &ref, fsRdPerm );
    err  = ResError();

    return err;
  }
Example #6
0
static void AddFolderIcon (FSRef *fref, const char *folderName)
{
	OSStatus			err;
	FSCatalogInfo		fcat, icat;
	FSRef				bref, iref;
	CFStringRef			str;
	CFURLRef			url;
	IconFamilyHandle	family;
	IconRef				icon;
	HFSUniStr255		fork;
	Boolean				r;
	SInt16				resf;
	char				name[64];
	UniChar				iconName[5] = { 'I', 'c', 'o', 'n', '\r' };

	strcpy(name, "folder_");
	strcat(name, folderName);

	str = CFStringCreateWithCString(kCFAllocatorDefault, name, CFStringGetSystemEncoding());
	if (str)
	{
		url = CFBundleCopyResourceURL(CFBundleGetMainBundle(), str, CFSTR("icns"), NULL);
		if (url)
		{
			r = CFURLGetFSRef(url, &bref);
			if (r)
			{
				err = RegisterIconRefFromFSRef('~9X~', 'TEMP', &bref, &icon);
				if (err == noErr)
				{
					err = FSGetResourceForkName(&fork);
					if (err == noErr)
					{
						err = FSCreateResourceFile(fref, 5, iconName, kFSCatInfoNone, NULL, fork.length, fork.unicode, &iref, NULL);
						if (err == noErr)
						{
							err = FSOpenResourceFile(&iref, fork.length, fork.unicode, fsWrPerm, &resf);
							if (err == noErr)
							{
								err = IconRefToIconFamily(icon, kSelectorAllAvailableData, &family);
								if (err == noErr)
								{
									AddResource((Handle) family, 'icns', -16455, "\p");
									WriteResource((Handle) family);
									ReleaseResource((Handle) family);

									err = FSGetCatalogInfo(&iref, kFSCatInfoFinderInfo, &icat, NULL, NULL, NULL);
									((FileInfo *) &icat.finderInfo)->finderFlags |= kIsInvisible;
									((FileInfo *) &icat.finderInfo)->fileCreator = 'MACS';
									((FileInfo *) &icat.finderInfo)->fileType    = 'icon';
									err = FSSetCatalogInfo(&iref, kFSCatInfoFinderInfo, &icat);

									err = FSGetCatalogInfo(fref, kFSCatInfoFinderInfo, &fcat, NULL, NULL, NULL);
									((FolderInfo *) &fcat.finderInfo)->finderFlags |=  kHasCustomIcon;
									((FolderInfo *) &fcat.finderInfo)->finderFlags &= ~kHasBeenInited;
									err = FSSetCatalogInfo(fref, kFSCatInfoFinderInfo, &fcat);
								}

								CloseResFile(resf);
							}
						}
					}
Example #7
0
Handle 
CResourceLoader::LoadResource(ResType theType, INT16 id)
{
    Handle hRes = 0;

    // save the old file
    INT16 thePrevResFile = ::CurResFile();

    if (m_theResFile == -1)
    {
#if defined(_MAC_UNIX)
        CFArrayRef resourceArray = ::CFBundleCopyResourceURLsOfType(m_theLibrary, CFSTR(".rsrc"), NULL);
        if (resourceArray)
        {
            if (::CFArrayGetCount(resourceArray) > 0)
            {
                // xxxbobclark we'd have a little more "renovating" to
                // do in CResourceLoader to handle multiple .rsrc files
                // in a single bundle.
                HX_ASSERT(::CFArrayGetCount(resourceArray) <= 1);

                CFURLRef resourceFileURL = (CFURLRef)::CFArrayGetValueAtIndex(resourceArray, 0);

                HX_ASSERT(resourceFileURL);

                FSRef resourceFSRef;

                Boolean bGotFSRefSucceeded = ::CFURLGetFSRef(resourceFileURL, &resourceFSRef);

                HX_ASSERT(bGotFSRefSucceeded);

                if (bGotFSRefSucceeded)
                {
                    // FSOpenResFile opens the resource fork, while
                    // FSOpenResourceFile (by default) opens the DATA FORK
                    // as a resource file. Allows us to use data-fork-based
                    // resource files.
                    short theRefNum = 0;
                    OSErr err = FSOpenResourceFile(&resourceFSRef, 0, NULL, fsRdPerm, &theRefNum);
                    if (err == noErr)
                    {
                        m_theResFile = theRefNum;
                    }
                }
            }
            ::CFRelease(resourceArray);
        }
#else
    	m_theResFile = ::FSpOpenResFile(&m_theLibrary, fsRdPerm);
#endif
    }

    if (m_theResFile != -1)
    {
    	// set our's current
    	::UseResFile(m_theResFile);

    	// load the resource
    	hRes = ::Get1Resource(theType, id);

    	// do the mapping stuff here in case we already have this handle around...
    	if (hRes)
    	{
	    long thisHandleCount = 0;
	    (void)m_theHandleMap->Lookup(hRes, (void*&)thisHandleCount);
	    thisHandleCount++;
	    (void)m_theHandleMap->SetAt(hRes, (void*)thisHandleCount);
    	}
    	
    	// reset old res file
    	::UseResFile(thePrevResFile);
    }
    return hRes;
}
Example #8
0
/* parse and summarize FOND resource information */
static fond_table * parse_fond(FSSpec *spec)
{
    OSErr result = noErr;
    FSRef specref;
    SInt16 ref;
    Handle fond = NULL;
    unsigned char *res;
    fond_table *table = NULL;
    int i,j, count, n, start;

        /* FSpOpenResFile will fail for data fork resource (.dfont) files.
           FSOpenResourceFile can open either, but cannot handle broken resource
           maps, as often occurs in font files (the suitcase version of Arial,
           for example) Thus, we try one, and then the other. */

    result = FSpMakeFSRef(spec,&specref);
#ifdef __CARBON__
        if (result == noErr)
                result = FSOpenResourceFile(&specref, 0, NULL, fsRdPerm, &ref);
#else
        result = bdNamErr; /* simulate failure of the carbon routine above */
#endif
    if (result != noErr) {
            ref = FSpOpenResFile(spec, fsRdPerm);
            result = ResError();
        }
    if (result != noErr || ref <= 0) {
        char path[256];
        convertSpecToPath(spec, path, 256);
        dlprintf2("unable to open resource file '%s' for font enumeration (error %d)\n",
                path, result);
        goto fin;
    }

    /* we've opened the font file, now loop over the FOND resource(s)
       and construct a table of the font references */

    start = 0; /* number of entries so far */
    UseResFile(ref);
    count = Count1Resources('FOND');
    for (i = 0; i < count; i++) {
        fond = Get1IndResource('FOND', i+1);
        if (fond == NULL) {
            result = ResError();
            goto fin;
        }

        /* The FOND resource structure corresponds to the FamRec and AsscEntry
           data structures documented in the FontManager reference. However,
           access to these types is deprecated in Carbon. We therefore access the
           data by direct offset in the hope that the resource format will not change
           even if api access to the in-memory versions goes away. */
        HLock(fond);
        res = *fond + 52; /* offset to association table */
        n = get_int16(res) + 1;	res += 2;
                table = fond_table_grow(table, n);
        for (j = start; j < start + n; j++ ) {
            table->refs[j].size = get_int16(res); res += 2;
            table->refs[j].style = get_int16(res); res += 2;
            table->refs[j].id = get_int16(res); res += 2;
        }
        start += n;
        HUnlock(fond);
    }
fin:
    CloseResFile(ref);
    return table;
}