FT_New_Face_From_FOND( FT_Library library, Handle fond, FT_Long face_index, FT_Face* aface ) { short have_sfnt, have_lwfn = 0; ResID sfnt_id, fond_id; OSType fond_type; Str255 fond_name; Str255 lwfn_file_name; UInt8 path_lwfn[PATH_MAX]; OSErr err; FT_Error error = FT_Err_Ok; GetResInfo( fond, &fond_id, &fond_type, fond_name ); if ( ResError() != noErr || fond_type != TTAG_FOND ) return FT_Err_Invalid_File_Format; parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); if ( lwfn_file_name[0] ) { ResFileRefNum res; res = HomeResFile( fond ); if ( noErr != ResError() ) goto found_no_lwfn_file; { UInt8 path_fond[PATH_MAX]; FSRef ref; err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum, NULL, NULL, NULL, &ref, NULL ); if ( noErr != err ) goto found_no_lwfn_file; err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( FT_Err_Ok == error ) have_lwfn = 1; } } if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) error = FT_New_Face_From_LWFN( library, path_lwfn, face_index, aface ); else error = FT_Err_Unknown_File_Format; found_no_lwfn_file: if ( have_sfnt && FT_Err_Ok != error ) error = FT_New_Face_From_SFNT( library, sfnt_id, face_index, aface ); return error; }
void LoadVSTPlugins() { wxString home = DirManager::GetHomeDir(); wxString pathChar = DirManager::GetPathChar(); wxString vstDirPath = home + pathChar + "vst"; wxString fname; fname = wxFindFirstFile((const char *) (vstDirPath + pathChar + "*")); while (fname != "") { short resID; FSSpec spec; wxMacFilename2FSSpec(fname, &spec); resID = FSpOpenResFile(&spec, fsRdPerm); Handle codeH; int count = Count1Resources('aEff'); for (int i = 0; i < count; i++) { CFragConnectionID connID; Ptr mainAddr; Str255 errName; Str255 fragName; char fragNameCStr[256]; short resID; OSType resType; OSErr err; codeH = Get1IndResource('aEff', count); GetResInfo(codeH, &resID, &resType, fragName); DetachResource(codeH); HLock(codeH); err = GetMemFragment(*codeH, GetHandleSize(codeH), fragName, kPrivateCFragCopy, &connID, (Ptr *) & mainAddr, errName); if (err >= 0) { Ptr symbolAddress; CFragSymbolClass symbolClass; err = FindSymbol(connID, "\pmain", &symbolAddress, &symbolClass); if (!err) { vstPluginMain pluginMain = (vstPluginMain) symbolAddress; AEffect *theEffect; theEffect = pluginMain(audioMaster); if (theEffect->magic == kEffectMagic) { memcpy(fragNameCStr, &fragName[1], fragName[0]); fragNameCStr[fragName[0]] = 0; VSTEffect *vst = new VSTEffect(wxString(fragNameCStr), theEffect); Effect::RegisterEffect(vst); } } } else { HUnlock(codeH); } audacityVSTID++; // Don't HUnlock unless you don't want to keep it in memory } CloseResFile(resID); fname = wxFindNextFile(); } }
FT_New_Face_From_FOND( FT_Library library, Handle fond, FT_Long face_index, FT_Face* aface ) { short have_sfnt, have_lwfn = 0; ResID sfnt_id, fond_id; OSType fond_type; Str255 fond_name; Str255 lwfn_file_name; UInt8 path_lwfn[PATH_MAX]; OSErr err; FT_Error error = FT_Err_Ok; /* test for valid `aface' and `library' delayed to */ /* `FT_New_Face_From_XXX' */ GetResInfo( fond, &fond_id, &fond_type, fond_name ); if ( ResError() != noErr || fond_type != TTAG_FOND ) return FT_THROW( Invalid_File_Format ); HLock( fond ); parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); HUnlock( fond ); if ( lwfn_file_name[0] ) { ResFileRefNum res; res = HomeResFile( fond ); if ( noErr != ResError() ) goto found_no_lwfn_file; #if HAVE_FSREF { UInt8 path_fond[PATH_MAX]; FSRef ref; err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum, NULL, NULL, NULL, &ref, NULL ); if ( noErr != err ) goto found_no_lwfn_file; err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( FT_Err_Ok == error ) have_lwfn = 1; } #elif HAVE_FSSPEC { UInt8 path_fond[PATH_MAX]; FCBPBRec pb; Str255 fond_file_name; FSSpec spec; FT_MEM_SET( &spec, 0, sizeof ( FSSpec ) ); FT_MEM_SET( &pb, 0, sizeof ( FCBPBRec ) ); pb.ioNamePtr = fond_file_name; pb.ioVRefNum = 0; pb.ioRefNum = res; pb.ioFCBIndx = 0; err = PBGetFCBInfoSync( &pb ); if ( noErr != err ) goto found_no_lwfn_file; err = FSMakeFSSpec( pb.ioFCBVRefNum, pb.ioFCBParID, fond_file_name, &spec ); if ( noErr != err ) goto found_no_lwfn_file; err = FT_FSpMakePath( &spec, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( FT_Err_Ok == error ) have_lwfn = 1; } #endif /* HAVE_FSREF, HAVE_FSSPEC */ } if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) error = FT_New_Face_From_LWFN( library, path_lwfn, face_index, aface ); else error = FT_ERR( Unknown_File_Format ); found_no_lwfn_file: if ( have_sfnt && FT_Err_Ok != error ) error = FT_New_Face_From_SFNT( library, sfnt_id, face_index, aface ); return error; }
void LoadVSTPlugins() { #ifdef __MACOSX__ audioMasterCallback audioMasterFPtr = (audioMasterCallback)NewCFMFromMachO(audioMaster); #else // What is the corrct way of creating an audioMasterCallback // in OS 9/Carbon??? // audioMasterCallback audioMasterFPtr = NULL; audioMasterCallback audioMasterFPtr = audioMaster; #endif wxArrayString audacityPathList = wxGetApp().audacityPathList; wxArrayString pathList; wxArrayString files; unsigned int i; for(i=0; i<audacityPathList.GetCount(); i++) { wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH; wxGetApp().AddUniquePathToPathList(prefix + "VST", pathList); wxGetApp().AddUniquePathToPathList(prefix + "Plugins", pathList); wxGetApp().AddUniquePathToPathList(prefix + "Plug-Ins", pathList); } #ifdef __MACOSX__ wxGetApp().AddUniquePathToPathList("/Library/Audio/Plug-Ins/VST", pathList); wxString vstPath; vstPath.Printf("/Users/%s/Library/Audio/Plug-Ins/VST", wxGetenv("USER")); wxGetApp().AddUniquePathToPathList(vstPath, pathList); #endif wxGetApp().FindFilesInPathList("*", pathList, wxFILE, files); for(i=0; i<files.GetCount(); i++) { short resFileID; FSSpec spec; wxMacFilename2FSSpec(FILENAME(files[i]), &spec); resFileID = FSpOpenResFile(&spec, fsRdPerm); short cResCB = Count1Resources('aEff'); for (int i = 0; i < cResCB; i++) { Handle codeH; CFragConnectionID connID; Ptr mainAddr; Str255 errName; Str255 fragName; char fragNameCStr[256]; short resID; OSType resType; OSErr err; codeH = Get1IndResource('aEff', short(i+1)); if (!codeH) continue; GetResInfo(codeH, &resID, &resType, fragName); DetachResource(codeH); HLock(codeH); err = GetMemFragment(*codeH, GetHandleSize(codeH), fragName, kPrivateCFragCopy, &connID, (Ptr *) & mainAddr, errName); if (!err) { vstPluginMain pluginMain; AEffect *theEffect; #ifdef __MACOSX__ pluginMain = (vstPluginMain)NewMachOFromCFM(mainAddr); #else pluginMain = (vstPluginMain)mainAddr; #endif theEffect = pluginMain(audioMasterFPtr); if (theEffect->magic == kEffectMagic) { memcpy(fragNameCStr, &fragName[1], fragName[0]); fragNameCStr[fragName[0]] = 0; VSTEffect *vst = new VSTEffect(wxString(fragNameCStr), theEffect); Effect::RegisterEffect(vst); } #ifdef __MACOSX__ DisposeMachOFromCFM(pluginMain); #endif audacityVSTID++; } } CloseResFile(resFileID); } #ifdef __MACOSX__ DisposeCFMFromMachO(audioMasterFPtr); #endif // __MACOSX__ }
void main(fptr *f) { long oldA4; OSStatus err; DateTimeRec date; oldA4 = SetCurrentA4(); RememberA4(); FNS = f; #ifdef MULTI_SEGMENT /* Multi-segment code resource stuff */ { Str255 buf; short i, n, theID; char **ch; OSType theType; n = Count1Resources('Cccc'); post("This external has %ld resources", (long) n); for (i = 1; i <= n; i++) { ch = Get1IndResource('Cccc', i); GetResInfo(ch, &theID, &theType, buf); rescopy('Cccc', theID); } } #endif #ifdef EXTENDED_CODE_RESOURCE // Cause it's an extended code resource... // rescopy('Cccc',22222); #endif ps_readbufsize = gensym("readbufsize"); ps_writebufsize = gensym("writebufsize"); ps_OTTCP_nbytes = gensym("OTTCP_nbytes"); ps_OTTCP_delim = gensym("OTTCP_delim"); ps_connected = gensym("connected"); ps_disconnected = gensym("disconnected"); setup(&ottcp_class, ottcp_new, (method) ottcp_free, (short)sizeof(OTTCP), 0L, A_GIMME, 0); version(0); #ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS post("Expires %d/%d/%d", MONTH, DAY, YEAR); #endif #ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS GetTime(&date); if((date.year > YEAR) || (date.year == YEAR && ((date.month > MONTH) || (date.month == MONTH && date.day > DAY)))) { ouchstring(EXPIRATION_NOTICE); goto quit; } #endif // post ("*** before InitOpenTransport();"); err = InitOpenTransport(); if (err != kOTNoError) { ouchstring("Couldn't InitOpenTransport (err %d). Perhaps Open Transport is not installed.", err); goto quit; } /* bind methods */ addmess((method) ottcp_connect, "connect", A_SYM, A_LONG, 0); addmess((method) ottcp_disconnect, "disconnect", 0); addmess((method) ottcp_read_nbytes, "nbytes", A_LONG, 0); addmess((method) ottcp_read_until_delimiter_symbol, "delim", A_SYM, 0); addmess((method) ottcp_read_until_delimiter_bytes, "delim-bytes", A_GIMME, 0); addmess((method) ottcp_write, "write", A_LONG, A_LONG, 0); addmess((method) version, "version", 0); addmess((method) ottcp_ErrorReporting, "errorreporting", 0); addmess((method) ottcp_tellmeeverything, "tellmeeverything", 0); addmess((method) ottcp_assist, "assist", A_CANT, 0); finder_addclass("System","ottcp"); quit: RestoreA4(oldA4); }
bool wxIcon::LoadFile( const wxString& filename, wxBitmapType type, int desiredWidth, int desiredHeight ) { UnRef(); if ( type == wxBITMAP_TYPE_ICON_RESOURCE ) { OSType theId = 0 ; if ( filename == wxT("wxICON_INFORMATION") ) { theId = kAlertNoteIcon ; } else if ( filename == wxT("wxICON_QUESTION") ) { theId = kAlertCautionIcon ; } else if ( filename == wxT("wxICON_WARNING") ) { theId = kAlertCautionIcon ; } else if ( filename == wxT("wxICON_ERROR") ) { theId = kAlertStopIcon ; } else { #if 0 Str255 theName ; OSType theType ; wxMacStringToPascal( name , theName ) ; Handle resHandle = GetNamedResource( 'cicn' , theName ) ; if ( resHandle != 0L ) { GetResInfo( resHandle , &theId , &theType , theName ) ; ReleaseResource( resHandle ) ; } #endif } if ( theId != 0 ) { IconRef iconRef = NULL ; verify_noerr( GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef ) ) ; if ( iconRef ) { m_refData = new wxIconRefData( (WXHICON) iconRef ) ; return true ; } } return false ; } else { wxBitmapHandler *handler = wxBitmap::FindHandler( type ); if ( handler ) { wxBitmap bmp ; if ( handler->LoadFile( &bmp , filename, type, desiredWidth, desiredHeight )) { CopyFromBitmap( bmp ) ; return true ; } return false ; } else { #if wxUSE_IMAGE wxImage loadimage( filename, type ); if (loadimage.Ok()) { if ( desiredWidth == -1 ) desiredWidth = loadimage.GetWidth() ; if ( desiredHeight == -1 ) desiredHeight = loadimage.GetHeight() ; if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() ) loadimage.Rescale( desiredWidth , desiredHeight ) ; wxBitmap bmp( loadimage ); CopyFromBitmap( bmp ) ; return true; } #endif } } return true ; }
Pixmap TkpGetNativeAppBitmap( Display *display, /* The display. */ CONST char *name, /* The name of the bitmap. */ int *width, /* The width & height of the bitmap. */ int *height) { Pixmap pix; CGrafPtr savePort; Boolean portChanged; Rect destRect; Handle resource; int type = -1, destWrote; Str255 nativeName; Tcl_Encoding encoding; /* * macRoman is the encoding that the resource fork uses. */ encoding = Tcl_GetEncoding(NULL, "macRoman"); Tcl_UtfToExternal(NULL, encoding, name, strlen(name), 0, NULL, (char *) &nativeName[1], 255, NULL, &destWrote, NULL); nativeName[0] = destWrote; Tcl_FreeEncoding(encoding); resource = GetNamedResource('cicn', nativeName); if (resource != NULL) { type = TYPE3; } else { resource = GetNamedResource('ICON', nativeName); if (resource != NULL) { type = TYPE2; } } if (resource == NULL) { return (Pixmap) NULL; } pix = Tk_GetPixmap(display, None, 32, 32, 0); portChanged = QDSwapPort(TkMacOSXGetDrawablePort(pix), &savePort); SetRect(&destRect, 0, 0, 32, 32); if (type == TYPE2) { RGBColor black = {0, 0, 0}; RGBForeColor(&black); PlotIcon(&destRect, resource); ReleaseResource(resource); } else if (type == TYPE3) { RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF}; short id; ResType theType; Str255 dummy; /* * We need to first paint the background white. Also, for some reason * we *must* use GetCIcon instead of GetNamedResource for PlotCIcon to * work - so we use GetResInfo to get the id. */ RGBForeColor(&white); PaintRect(&destRect); GetResInfo(resource, &id, &theType, dummy); ReleaseResource(resource); resource = (Handle) GetCIcon(id); PlotCIcon(&destRect, (CIconHandle) resource); DisposeCIcon((CIconHandle) resource); } *width = 32; *height = 32; if (portChanged) { QDSwapPort(savePort, NULL); } return pix; }
long iniMacros(void) { #ifndef MACINTOSH int i; for (i = 0; macros[i].name; i++) { if (!installMacro(macros[i].text, macros[i].name, strlen(macros[i].text))) { goto errorExit; } } #else /*MACINTOSH*/ Integer id = IDBASE, id1; Integer i, count = CountResources(MACROTYPE); char *prefix = NAMEPREFIX; Integer prefixLength = strlen(prefix); Str255 resName; char *name = (char *) resName; ResType type; unsigned char **text; /* examine all resources of the wanted type If the name starts with prefix, install it as long as it is not the name of the dummy last macro */ for(i=1; i<= count; i++) { text = (unsigned char **) GetIndResource(MACROTYPE, i); if (ResError() != noErr) { break; } GetResInfo((Handle) text, &id1, &type, resName); if (ResError() != noErr) { goto errorExit; } PtoCstr((unsigned char *) name); if (strncmp(prefix, name, prefixLength) == 0 && strcmp(name + prefixLength, ENDNAME) != 0) { HLock((Handle) text); /* first two characters of *text give number of characters */ if (!installMacro((char *) (*text) + 2, name + prefixLength, (*text)[0] * 256 + (*text)[1])) { goto errorExit; } HUnlock((Handle) text); } ReleaseResource((Handle) text); } /*while(1)*/ #endif /*MACINTOSH*/ return (1); errorExit: return (0); } /*iniMacros()*/
OSErr PAS_flattenResource(ResType type, short *ids, long count, short source, short dest) { long idIndex; Handle resToCopy; long handleLength; PASResource pasResource; long pasResLen; OSErr err; for (idIndex=0; idIndex < count; idIndex++) { if( (type == 'SIZE') && ( ids[idIndex] == 1 || ids[idIndex] == 0 ) ) { /* We do not want to encode/flatten SIZE 0 or 1 because this is the resource that the user can modify. Most applications will not be affected if we remove these resources */ } else { resToCopy=Get1Resource(type,ids[idIndex]); if(!resToCopy) { return resNotFound; } memset(&pasResource, 0, sizeof(PASResource)); GetResInfo( resToCopy, &pasResource.attrID, &pasResource.attrType, pasResource.attrName); pasResource.attr = GetResAttrs(resToCopy); DetachResource(resToCopy); HLock(resToCopy); pasResource.length = GetHandleSize(resToCopy); handleLength = pasResource.length; pasResLen = sizeof(PASResource); err = FSWrite(dest, &pasResLen, &pasResource); if(err != noErr) { return err; } err = FSWrite(dest, &handleLength, &(**resToCopy)); if(err != noErr) { return err; } HUnlock(resToCopy); DisposeHandle(resToCopy); } } return noErr; }
// **************************************************************************** // // Function Name: RTrueTypeFont::ExtractCharacterOutline( ) // // Description: Retrieve a glyph outline and parse it into segment records // in the global buffer // // Returns: Boolean indicating successful completion // // Exceptions: Memory // // **************************************************************************** // BOOLEAN RTrueTypeFont::ExtractCharacterOutline( int character, uLONG cookie ) { YTTSegmentInfoRecord* pSegments = (YTTSegmentInfoRecord *)( cookie + sizeof(uLONG) ); const YFontInfo fontInfo = GetInfo(); GlyphOutline glyph; Matrix matrix; long glyphIndex = 0; // zero is the missing character // retrieve font resource if ( m_hSfnt == NULL ) { short rId; ResType rType; Str255 rName; m_hSfnt = GetSfntHandle( (const LPSZ)fontInfo.sbName, RFont::GetMacStyleBits( fontInfo.attributes ) ); GetResInfo( m_hSfnt, &rId, &rType, rName); m_sSfntId = rId; } else if ( *m_hSfnt == NULL ) { ::LoadResource( m_hSfnt ); // m_hSfnt = ::GetResource( 'sfnt', m_sSfntId ); } if ( m_hSfnt == NULL || *m_hSfnt == NULL ) return FALSE; ::HNoPurge( m_hSfnt ); // extract character outline InitMatrix( matrix ); InitGlyphOutline( &glyph ); MakeIdentityMatrix( matrix ); try { glyphIndex = GetCharGlyphIndex( m_hSfnt, character ); GetGlyphOutline( m_hSfnt, glyphIndex, &glyph, matrix ); ScaleGlyphOutline( &glyph, ::Long2Fix( fontInfo.height ), ::Long2Fix( fontInfo.height ) ); } catch ( YException except ) { ::HPurge( m_hSfnt ); KillGlyphOutline( &glyph ); switch ( except ) { case kResource: return FALSE; break; default: throw; break; } } catch ( ... ) { ::HPurge( m_hSfnt ); KillGlyphOutline( &glyph ); throw; } // loop thru the contours LockGlyphOutline( &glyph ); { long nrSegments = 0; long sp = 0; Fixed* x = *glyph.x; Fixed* y = *glyph.y; short* ep = *glyph.endPoints; Byte* onCurve = *glyph.onCurve; RIntPoint ptStart; for ( int i = 0; i < glyph.contourCount; i++ ) { long pts = *ep - sp + 1; // nr pts in contour // contour start point if ( *onCurve != 0 ) // 1st point on curve { ptStart.m_x = RoundFixed( *x ); ptStart.m_y = -RoundFixed( *y ); x++; y++; onCurve++; pts--; } else if ( *((*glyph.onCurve) + *ep) != 0 ) // use end point { ptStart.m_x = RoundFixed( *((*glyph.x) + *ep) ); ptStart.m_y = -RoundFixed( *((*glyph.y) + *ep) ); } else // compute midpoint between 1st and last curve points { Fixed x2 = ::FixDiv( (*x + *((*glyph.x) + *ep)), ::Long2Fix( 2 ) ); Fixed y2 = ::FixDiv( (*y + *((*glyph.y) + *ep)), ::Long2Fix( 2 ) ); ptStart.m_x = RoundFixed( x2 ); ptStart.m_y = -RoundFixed( y2 ); } // initial move to pSegments->opCode = MOVE_TO; pSegments->pt1 = ptStart; nrSegments++; pSegments++; // load segments of contour while ( pts-- > 0 ) { Fixed x0 = *x; Fixed y0 = *y; Byte onCurve0 = *onCurve; x++; y++; onCurve++; pSegments->pt1.m_x = RoundFixed( x0 ); pSegments->pt1.m_y = -RoundFixed( y0 ); if ( onCurve0 != 0 ) pSegments->opCode = LINE_TO; else if ( pts < 1 ) // quadratic w/ contour start point as end { pSegments->opCode = QUADRATIC_TO; pSegments->pt2 = ptStart; } else if ( *onCurve != 0 ) // quadratic w/ end point next line to { pSegments->opCode = QUADRATIC_TO; pSegments->pt2.m_x = RoundFixed( *x ); pSegments->pt2.m_y = -RoundFixed( *y ); x++; y++; onCurve++; pts--; } else // compute end point of quadratic as midpoint to next curve { Fixed x2 = ::FixDiv( (x0 + *x), ::Long2Fix( 2 ) ); Fixed y2 = ::FixDiv( (y0 + *y), ::Long2Fix( 2 ) ); pSegments->opCode = QUADRATIC_TO; pSegments->pt2.m_x = RoundFixed( x2 ); pSegments->pt2.m_y = -RoundFixed( y2 ); } nrSegments++; pSegments++; } pSegments->opCode = CLOSE_PATH; // end of contour pSegments->pt1.m_x = pSegments->pt2.m_x = 0; pSegments->pt1.m_y = pSegments->pt2.m_y = 0; nrSegments++; pSegments++; sp = *ep++ + 1; } pSegments->opCode = 0; // end of glyph pSegments->pt1.m_x = pSegments->pt2.m_x = 0; pSegments->pt1.m_y = pSegments->pt2.m_y = 0; *(uLONG *)cookie = nrSegments; } UnlockGlyphOutline( &glyph ); // cleanup ::HPurge( m_hSfnt ); KillGlyphOutline( &glyph ); return TRUE; }