OSDN Git Service

first
[psychlops/cpp.git] / psychlops / platform / osx / psychlops_g_font_OSX.cpp
1 /*
2  *  psychlops_g_font_OSX.h
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2008/09/12 by Kenchi HOSOKAWA
6  *  (C) 2008 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
7  */
8
9 #include "../../core/graphic/psychlops_g_font.h"
10 #include "../../core/graphic/psychlops_g_font.h"
11 #include <CoreFoundation/CoreFoundation.h>
12 #include "../../core/ApplicationInterfaces/psychlops_code_exception.h"
13
14 namespace Psychlops {
15
16         Font Font::default_font(20, normal_weight, normal_style, L"HiraKakuPro-W3");
17
18         std::wstring LocalEncodingtoWCHAR(const char* s, int length) {
19                 char *c = new char[length+1];
20                 memcpy(c+1, s, length);
21                 c[0] = (char)length;
22                 CFStringRef str = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8*)(c), length+1, kCFStringEncodingMacJapanese, false);
23                 delete c;
24                 if(str==NULL) throw new Exception("fail: ShiftJIStoWCHAR");
25                 std::wstring result;
26                 result.resize(CFStringGetLength(str));
27 #if defined(PANTHER) && ( PANTHER ==1 )
28                 CFStringGetCString(str, (char*)result.data(), result.length()*4, kCFStringEncodingUnicode);
29 #else
30                 CFStringGetCString(str, (char*)result.data(), result.length()*4, kCFStringEncodingUTF32LE);
31 #endif
32                 return result;
33         }
34         std::wstring LocalEncodingtoWCHAR(const char* c) {
35                 int i = 0;
36                 while(c[i]!=0) i++;
37                 i--;
38                 return LocalEncodingtoWCHAR(c, i);
39         }
40         
41 }       /*      <- namespace Psycholops         */