1 /*****************************************************************************\
2 Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3 This file is licensed under the Snes9x License.
4 For further information, consult the LICENSE file in the root directory.
5 \*****************************************************************************/
6
7 /***********************************************************************************
8 SNES9X for Mac OS (c) Copyright John Stiles
9
10 Snes9x for Mac OS X
11
12 (c) Copyright 2001 - 2011 zones
13 (c) Copyright 2002 - 2005 107
14 (c) Copyright 2002 PB1400c
15 (c) Copyright 2004 Alexander and Sander
16 (c) Copyright 2004 - 2005 Steven Seeger
17 (c) Copyright 2005 Ryan Vogt
18 ***********************************************************************************/
19
20
21 #include "mac-prefix.h"
22 #include "mac-stringtools.h"
23
24
CopyFixNameStrings(const char * itext,uint8 region)25 CFStringRef CopyFixNameStrings (const char *itext, uint8 region)
26 {
27 CFStringRef str = NULL;
28
29 if (region != 0) // non-Japanese
30 {
31 char btext[256];
32 size_t len = strlen(itext);
33
34 btext[len] = 0;
35 for (unsigned int i = 0; i < len ; i++)
36 btext[i] = isgraph(itext[i]) ? itext[i] : ' ';
37
38 str = CFStringCreateWithCString(kCFAllocatorDefault, btext, kCFStringEncodingNonLossyASCII);
39 }
40 else
41 str = CFStringCreateWithCString(kCFAllocatorDefault, itext, kCFStringEncodingMacJapanese); // assuming Shift-JIS
42
43 return (str);
44 }
45
46 #ifdef MAC_TIGER_PANTHER_SUPPORT
CreateATSUIStyleFromFontFullNameAndSize(const char * fontName,int fontSize,ATSUStyle * theStyle)47 OSStatus CreateATSUIStyleFromFontFullNameAndSize (const char *fontName, int fontSize, ATSUStyle *theStyle)
48 {
49 OSStatus err;
50 ATSUStyle localStyle;
51 ATSUFontID atsuFont;
52 Fixed atsuSize;
53
54 ATSUAttributeTag theTags[] = { kATSUFontTag, kATSUSizeTag };
55 ByteCount theSizes[] = { sizeof(ATSUFontID), sizeof(Fixed) };
56 ATSUAttributeValuePtr theValues[] = { NULL, NULL };
57
58 atsuFont = 0;
59 atsuSize = FixRatio(fontSize, 1);
60 localStyle = NULL;
61
62 theValues[0] = &atsuFont;
63 theValues[1] = &atsuSize;
64
65 err = ATSUFindFontFromName(fontName, strlen(fontName), kFontFullName, kFontNoPlatform, kFontNoScript, kFontNoLanguage, &atsuFont);
66 if (err == noErr)
67 {
68 err = ATSUCreateStyle(&localStyle);
69 if (err == noErr)
70 {
71 err = ATSUSetAttributes(localStyle, sizeof(theTags) / sizeof(theTags[0]), theTags, theSizes, theValues);
72 if (err == noErr)
73 {
74 *theStyle = localStyle;
75 return (noErr);
76 }
77 }
78 }
79
80 if (localStyle != NULL)
81 err = ATSUDisposeStyle(localStyle);
82
83 return (err);
84 }
85 #endif
86
GetMultiByteCharacters(CFStringRef inText,int cutAt)87 const char * GetMultiByteCharacters (CFStringRef inText, int cutAt)
88 {
89 static char buf[256];
90
91 CFStringRef str;
92
93 buf[0] = 0;
94
95 if (!inText || (cutAt < 1))
96 return (buf);
97
98 if (CFStringGetCString(inText, buf, sizeof(buf), CFStringGetSystemEncoding()))
99 {
100 buf[cutAt] = 0;
101
102 str = CFStringCreateWithCString(kCFAllocatorDefault, buf, CFStringGetSystemEncoding());
103 if (str)
104 CFRelease(str);
105 else
106 buf[cutAt - 1] = 0;
107 }
108
109 return (buf);
110 }
111