gosu 0.10.9.pre1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gosu/Audio.hpp +35 -66
- data/Gosu/AutoLink.hpp +14 -16
- data/Gosu/Bitmap.hpp +50 -37
- data/Gosu/Buttons.hpp +246 -265
- data/Gosu/Color.hpp +32 -76
- data/Gosu/Directories.hpp +14 -17
- data/Gosu/Font.hpp +28 -34
- data/Gosu/Fwd.hpp +27 -31
- data/Gosu/Gosu.hpp +2 -5
- data/Gosu/Graphics.hpp +31 -48
- data/Gosu/GraphicsBase.hpp +27 -58
- data/Gosu/IO.hpp +44 -56
- data/Gosu/Image.hpp +29 -73
- data/Gosu/ImageData.hpp +13 -17
- data/Gosu/Input.hpp +42 -57
- data/Gosu/Inspection.hpp +2 -6
- data/Gosu/Math.hpp +32 -38
- data/Gosu/Platform.hpp +10 -29
- data/Gosu/Text.hpp +30 -39
- data/Gosu/TextInput.hpp +29 -36
- data/Gosu/Timing.hpp +14 -16
- data/Gosu/Utility.hpp +10 -15
- data/Gosu/Version.hpp +13 -14
- data/Gosu/Window.hpp +53 -68
- data/README.md +23 -11
- data/ext/gosu/extconf.rb +31 -81
- data/lib/gosu/patches.rb +35 -19
- data/lib/gosu/run.rb +13 -4
- data/rdoc/gosu.rb +24 -20
- data/src/ALChannelManagement.hpp +119 -0
- data/src/{Audio/Audio.cpp → Audio.cpp} +177 -211
- data/src/AudioFile.hpp +57 -0
- data/src/AudioToolboxFile.hpp +214 -0
- data/src/Bitmap.cpp +159 -0
- data/src/BitmapIO.cpp +141 -0
- data/src/BlockAllocator.cpp +133 -0
- data/src/{Graphics/BlockAllocator.hpp → BlockAllocator.hpp} +34 -35
- data/src/ClipRectStack.hpp +87 -0
- data/src/{Graphics/Color.cpp → Color.cpp} +30 -28
- data/src/DirectoriesApple.cpp +68 -0
- data/src/DirectoriesUnix.cpp +20 -18
- data/src/DirectoriesWin.cpp +40 -41
- data/src/DrawOp.hpp +168 -0
- data/src/DrawOpQueue.hpp +190 -0
- data/src/FileUnix.cpp +40 -46
- data/src/FileWin.cpp +42 -38
- data/src/Font.cpp +165 -0
- data/src/{Text/FormattedString.hpp → FormattedString.hpp} +114 -114
- data/src/GosuAppDelegate.cpp +30 -0
- data/src/{UIKit/GosuAppDelegate.h → GosuAppDelegate.h} +0 -0
- data/src/{UIKit/GosuGLView.mm → GosuGLView.cpp} +22 -17
- data/src/{UIKit/GosuGLView.h → GosuGLView.h} +0 -0
- data/src/GosuViewController.cpp +231 -0
- data/src/{UIKit/GosuViewController.h → GosuViewController.h} +0 -0
- data/src/Graphics.cpp +464 -0
- data/src/{Graphics/Common.hpp → GraphicsImpl.hpp} +29 -32
- data/src/IO.cpp +17 -16
- data/src/Iconv.hpp +13 -22
- data/src/Image.cpp +142 -0
- data/src/Input.cpp +459 -0
- data/src/InputUIKit.cpp +197 -0
- data/src/Inspection.cpp +4 -5
- data/src/LargeImageData.cpp +151 -0
- data/src/LargeImageData.hpp +43 -0
- data/src/{Graphics/Macro.cpp → Macro.cpp} +77 -78
- data/src/Macro.hpp +30 -0
- data/src/Math.cpp +17 -29
- data/src/{Audio/OggFile.hpp → OggFile.hpp} +19 -24
- data/src/RenderState.hpp +205 -0
- data/src/Resolution.cpp +86 -0
- data/src/ResolutionApple.cpp +25 -0
- data/{ext/gosu/gosu_wrap.cxx → src/RubyGosu.cxx} +2256 -1707
- data/{ext/gosu/gosu_wrap.h → src/RubyGosu.h} +9 -9
- data/src/{Audio/SndFile.hpp → SndFile.hpp} +54 -43
- data/src/TexChunk.cpp +117 -0
- data/src/{Graphics/TexChunk.hpp → TexChunk.hpp} +13 -18
- data/src/Text.cpp +371 -0
- data/src/TextApple.cpp +209 -0
- data/src/TextInput.cpp +278 -0
- data/src/TextTTFWin.cpp +251 -0
- data/src/{Text/TextUnix.cpp → TextUnix.cpp} +96 -92
- data/src/TextWin.cpp +194 -0
- data/src/{Graphics/Texture.cpp → Texture.cpp} +35 -38
- data/src/{Graphics/Texture.hpp → Texture.hpp} +9 -13
- data/src/TimingApple.cpp +11 -7
- data/src/TimingUnix.cpp +13 -7
- data/src/TimingWin.cpp +6 -1
- data/src/{Graphics/Transform.cpp → Transform.cpp} +17 -12
- data/src/{Graphics/TransformStack.hpp → TransformStack.hpp} +24 -25
- data/src/Utility.cpp +29 -70
- data/src/UtilityApple.cpp +52 -0
- data/src/UtilityWin.cpp +7 -4
- data/src/Version.cpp +22 -0
- data/src/WinMain.cpp +30 -33
- data/src/WinUtility.cpp +24 -22
- data/src/WinUtility.hpp +11 -20
- data/src/Window.cpp +142 -112
- data/src/WindowUIKit.cpp +155 -0
- data/src/stb_image.h +384 -173
- data/src/stb_vorbis.c +20 -18
- metadata +60 -62
- data/Gosu/TR1.hpp +0 -56
- data/src/AppleUtility.hpp +0 -66
- data/src/Audio/ALChannelManagement.hpp +0 -114
- data/src/Audio/Audio.mm +0 -1
- data/src/Audio/AudioFile.hpp +0 -53
- data/src/Audio/AudioToolboxFile.hpp +0 -207
- data/src/Bitmap/Bitmap.cpp +0 -183
- data/src/Bitmap/BitmapIO.cpp +0 -176
- data/src/DirectoriesApple.mm +0 -71
- data/src/Graphics/BlockAllocator.cpp +0 -142
- data/src/Graphics/ClipRectStack.hpp +0 -93
- data/src/Graphics/DrawOp.hpp +0 -175
- data/src/Graphics/DrawOpQueue.hpp +0 -188
- data/src/Graphics/Graphics.cpp +0 -478
- data/src/Graphics/Image.cpp +0 -193
- data/src/Graphics/LargeImageData.cpp +0 -133
- data/src/Graphics/LargeImageData.hpp +0 -46
- data/src/Graphics/Macro.hpp +0 -36
- data/src/Graphics/RenderState.hpp +0 -211
- data/src/Graphics/Resolution.cpp +0 -91
- data/src/Graphics/ResolutionApple.mm +0 -19
- data/src/Graphics/TexChunk.cpp +0 -112
- data/src/Input/Input.cpp +0 -463
- data/src/Input/InputUIKit.mm +0 -190
- data/src/Input/TextInput.cpp +0 -261
- data/src/Text/Font.cpp +0 -175
- data/src/Text/Text.cpp +0 -391
- data/src/Text/TextApple.mm +0 -227
- data/src/Text/TextTTFWin.cpp +0 -249
- data/src/Text/TextWin.cpp +0 -186
- data/src/UIKit/GosuAppDelegate.mm +0 -24
- data/src/UIKit/GosuViewController.mm +0 -211
- data/src/UtilityApple.mm +0 -63
- data/src/WindowUIKit.mm +0 -139
data/src/Text/TextApple.mm
DELETED
@@ -1,227 +0,0 @@
|
|
1
|
-
#import <Gosu/Platform.hpp>
|
2
|
-
|
3
|
-
#include <Gosu/Text.hpp>
|
4
|
-
#include <Gosu/Bitmap.hpp>
|
5
|
-
#include <Gosu/Utility.hpp>
|
6
|
-
#include <Gosu/Math.hpp>
|
7
|
-
#include "../AppleUtility.hpp"
|
8
|
-
#include <map>
|
9
|
-
#include <cmath>
|
10
|
-
using namespace std;
|
11
|
-
|
12
|
-
#if defined(GOSU_IS_IPHONE)
|
13
|
-
#import <UIKit/UIKit.h>
|
14
|
-
#import <CoreGraphics/CoreGraphics.h>
|
15
|
-
typedef UIFont OSXFont;
|
16
|
-
#else
|
17
|
-
#import <AppKit/AppKit.h>
|
18
|
-
typedef NSFont OSXFont;
|
19
|
-
#endif
|
20
|
-
|
21
|
-
namespace
|
22
|
-
{
|
23
|
-
using Gosu::CFRef;
|
24
|
-
|
25
|
-
// If a font is a filename, loads the font and returns its family name that can be used
|
26
|
-
// like any system font. Otherwise, just returns the family name.
|
27
|
-
std::wstring normalizeFont(const std::wstring& fontName)
|
28
|
-
{
|
29
|
-
// On iOS, we have no support for loading font files yet. However if you register your fonts
|
30
|
-
// via your app's Info.plist, you should be able to reference them by their name.
|
31
|
-
#ifdef GOSU_IS_IPHONE
|
32
|
-
return fontName;
|
33
|
-
#else
|
34
|
-
static map<wstring, wstring> familyOfFiles;
|
35
|
-
|
36
|
-
// Not a path name: It is already a family name
|
37
|
-
if (fontName.find(L"/") == std::wstring::npos) {
|
38
|
-
return fontName;
|
39
|
-
}
|
40
|
-
|
41
|
-
// Already activated font & extracted family name
|
42
|
-
if (familyOfFiles.count(fontName) > 0) {
|
43
|
-
return familyOfFiles[fontName];
|
44
|
-
}
|
45
|
-
|
46
|
-
CFRef<CFStringRef> urlString(
|
47
|
-
CFStringCreateWithBytes(NULL,
|
48
|
-
reinterpret_cast<const UInt8*>(fontName.c_str()),
|
49
|
-
fontName.length() * sizeof(wchar_t),
|
50
|
-
kCFStringEncodingUTF32LE, NO));
|
51
|
-
CFRef<CFURLRef> url(
|
52
|
-
CFURLCreateWithFileSystemPath(NULL, urlString.obj(), kCFURLPOSIXPathStyle, YES));
|
53
|
-
if (!url.get()) {
|
54
|
-
return familyOfFiles[fontName] = Gosu::defaultFontName();
|
55
|
-
}
|
56
|
-
|
57
|
-
CFRef<CFArrayRef> array(
|
58
|
-
CTFontManagerCreateFontDescriptorsFromURL(url.obj()));
|
59
|
-
|
60
|
-
if (array.get() == NULL || CFArrayGetCount(array.obj()) < 1 ||
|
61
|
-
!CTFontManagerRegisterFontsForURL(url.obj(), kCTFontManagerScopeProcess, NULL)) {
|
62
|
-
return familyOfFiles[fontName] = Gosu::defaultFontName();
|
63
|
-
}
|
64
|
-
|
65
|
-
CTFontDescriptorRef ref =
|
66
|
-
(CTFontDescriptorRef)CFArrayGetValueAtIndex(array.get(), 0);
|
67
|
-
CFRef<CFStringRef> fontNameStr(
|
68
|
-
(CFStringRef)CTFontDescriptorCopyAttribute(ref, kCTFontFamilyNameAttribute));
|
69
|
-
|
70
|
-
const char *utf8FontName = [(__bridge NSString *)fontNameStr.obj() UTF8String];
|
71
|
-
return familyOfFiles[fontName] = Gosu::utf8ToWstring(utf8FontName);
|
72
|
-
#endif
|
73
|
-
}
|
74
|
-
|
75
|
-
OSXFont* getFont(wstring fontName, unsigned fontFlags, double height)
|
76
|
-
{
|
77
|
-
fontName = normalizeFont(fontName);
|
78
|
-
|
79
|
-
static map<pair<wstring, pair<unsigned, double> >, OSXFont*> usedFonts;
|
80
|
-
|
81
|
-
OSXFont* result = usedFonts[make_pair(fontName, make_pair(fontFlags, height))];
|
82
|
-
if (!result)
|
83
|
-
{
|
84
|
-
NSString *name = [NSString stringWithUTF8String:Gosu::wstringToUTF8(fontName).c_str()];
|
85
|
-
#ifdef GOSU_IS_IPHONE
|
86
|
-
result = [OSXFont fontWithName:name size:height];
|
87
|
-
#else
|
88
|
-
NSFontDescriptor* desc = [[NSFontDescriptor fontDescriptorWithFontAttributes:nil]
|
89
|
-
fontDescriptorWithFamily:name];
|
90
|
-
result = [NSFont fontWithDescriptor:desc size:height];
|
91
|
-
if (result && (fontFlags & Gosu::ffBold)) {
|
92
|
-
result = [[NSFontManager sharedFontManager] convertFont:result toHaveTrait:NSFontBoldTrait];
|
93
|
-
}
|
94
|
-
if (result && (fontFlags & Gosu::ffItalic)) {
|
95
|
-
result = [[NSFontManager sharedFontManager] convertFont:result toHaveTrait:NSFontItalicTrait];
|
96
|
-
}
|
97
|
-
#endif
|
98
|
-
if (!result && fontName != Gosu::defaultFontName()) {
|
99
|
-
result = getFont(Gosu::defaultFontName(), 0, height);
|
100
|
-
}
|
101
|
-
assert(result);
|
102
|
-
usedFonts[make_pair(fontName, make_pair(fontFlags, height))] = result;
|
103
|
-
}
|
104
|
-
return result;
|
105
|
-
}
|
106
|
-
}
|
107
|
-
|
108
|
-
wstring Gosu::defaultFontName()
|
109
|
-
{
|
110
|
-
return L"Arial";
|
111
|
-
}
|
112
|
-
|
113
|
-
#ifndef GOSU_IS_IPHONE
|
114
|
-
namespace
|
115
|
-
{
|
116
|
-
NSDictionary *attributeDictionary(NSFont* font, unsigned fontFlags)
|
117
|
-
{
|
118
|
-
NSDictionary* dict = @{
|
119
|
-
NSFontAttributeName: font,
|
120
|
-
NSForegroundColorAttributeName: [NSColor whiteColor]
|
121
|
-
};
|
122
|
-
if (fontFlags & Gosu::ffUnderline) {
|
123
|
-
NSMutableDictionary *mutableDict = [dict mutableCopy];
|
124
|
-
// Cannot use accessor syntax here without breaking compilation with OS X 10.7/Xcode 4.6.3.
|
125
|
-
[mutableDict setObject:@(NSUnderlineStyleSingle) forKey:NSUnderlineStyleAttributeName];
|
126
|
-
dict = [mutableDict copy];
|
127
|
-
}
|
128
|
-
return dict;
|
129
|
-
}
|
130
|
-
}
|
131
|
-
#endif
|
132
|
-
|
133
|
-
unsigned Gosu::textWidth(const wstring& text,
|
134
|
-
const wstring& fontName, unsigned fontHeight, unsigned fontFlags)
|
135
|
-
{
|
136
|
-
if (text.find_first_of(L"\r\n") != wstring::npos) {
|
137
|
-
throw std::invalid_argument("the argument to textWidth cannot contain line breaks");
|
138
|
-
}
|
139
|
-
|
140
|
-
OSXFont *font = getFont(fontName, fontFlags, fontHeight);
|
141
|
-
|
142
|
-
// This will, of course, compute a too large size; fontHeight is in pixels,
|
143
|
-
// the method expects point.
|
144
|
-
NSString *string = [NSString stringWithUTF8String:wstringToUTF8(text).c_str()];
|
145
|
-
#ifndef GOSU_IS_IPHONE
|
146
|
-
NSDictionary *attributes = attributeDictionary(font, fontFlags);
|
147
|
-
NSSize size = [string sizeWithAttributes:attributes];
|
148
|
-
#else
|
149
|
-
CGSize size = [string sizeWithFont:font];
|
150
|
-
#endif
|
151
|
-
|
152
|
-
// Now adjust the scaling...
|
153
|
-
return ceil(size.width / size.height * fontHeight);
|
154
|
-
}
|
155
|
-
|
156
|
-
void Gosu::drawText(Bitmap& bitmap, const wstring& text, int x, int y,
|
157
|
-
Color c, const wstring& fontName, unsigned fontHeight,
|
158
|
-
unsigned fontFlags)
|
159
|
-
{
|
160
|
-
if (text.find_first_of(L"\r\n") != wstring::npos) {
|
161
|
-
throw std::invalid_argument("the argument to drawText cannot contain line breaks");
|
162
|
-
}
|
163
|
-
|
164
|
-
OSXFont *font = getFont(fontName, fontFlags, fontHeight);
|
165
|
-
NSString *string = [NSString stringWithUTF8String:wstringToUTF8(text).c_str()];
|
166
|
-
|
167
|
-
// Note that fontHeight is in pixels, the method expects points, so we have to scale this down.
|
168
|
-
#ifndef GOSU_IS_IPHONE
|
169
|
-
NSDictionary *attributes = attributeDictionary(font, fontFlags);
|
170
|
-
NSSize size = [string sizeWithAttributes:attributes];
|
171
|
-
#else
|
172
|
-
CGSize size = [string sizeWithFont:font];
|
173
|
-
#endif
|
174
|
-
|
175
|
-
unsigned width = static_cast<unsigned>(round(size.width / size.height * fontHeight));
|
176
|
-
|
177
|
-
// Get the width and height of the image
|
178
|
-
Bitmap bmp(width, fontHeight, 0x00ffffff);
|
179
|
-
|
180
|
-
// Use a temporary context to draw the CGImage to the buffer.
|
181
|
-
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
182
|
-
CGContextRef context =
|
183
|
-
CGBitmapContextCreate(bmp.data(),
|
184
|
-
bmp.width(), bmp.height(), 8, bmp.width() * 4,
|
185
|
-
colorSpace,
|
186
|
-
kCGImageAlphaPremultipliedLast);
|
187
|
-
CGColorSpaceRelease(colorSpace);
|
188
|
-
#ifdef GOSU_IS_IPHONE
|
189
|
-
CGFloat color[] = { 1.f, 1.f, 1.f, 0.f };
|
190
|
-
CGContextSetStrokeColor(context, color);
|
191
|
-
CGContextSetFillColor(context, color);
|
192
|
-
#endif
|
193
|
-
|
194
|
-
// Use new font with proper size this time.
|
195
|
-
font = getFont(fontName, fontFlags, fontHeight * fontHeight / size.height);
|
196
|
-
|
197
|
-
#ifdef GOSU_IS_IPHONE
|
198
|
-
CGContextTranslateCTM(context, 0, fontHeight);
|
199
|
-
CGContextScaleCTM(context, 1, -1);
|
200
|
-
UIGraphicsPushContext(context);
|
201
|
-
[string drawAtPoint:CGPointZero withFont:font];
|
202
|
-
UIGraphicsPopContext();
|
203
|
-
#else
|
204
|
-
NSPoint NSPointZero = { 0, 0 };
|
205
|
-
attributes = attributeDictionary(font, fontFlags);
|
206
|
-
|
207
|
-
[NSGraphicsContext saveGraphicsState];
|
208
|
-
[NSGraphicsContext setCurrentContext:
|
209
|
-
[NSGraphicsContext graphicsContextWithGraphicsPort:(void *)context flipped:false]];
|
210
|
-
[string drawAtPoint:NSPointZero withAttributes:attributes];
|
211
|
-
[NSGraphicsContext restoreGraphicsState];
|
212
|
-
#endif
|
213
|
-
CGContextRelease(context);
|
214
|
-
|
215
|
-
int effectiveWidth = Gosu::clamp<int>(width, 0, bitmap.width() - x);
|
216
|
-
int effectiveHeight = Gosu::clamp<int>(fontHeight, 0, bitmap.height() - y);
|
217
|
-
|
218
|
-
// Now copy the set pixels back.
|
219
|
-
for (int relY = 0; relY < effectiveHeight; ++relY)
|
220
|
-
for (int relX = 0; relX < effectiveWidth; ++relX)
|
221
|
-
{
|
222
|
-
c.setAlpha(bmp.getPixel(relX, relY).alpha());
|
223
|
-
if (c.alpha()) {
|
224
|
-
bitmap.setPixel(x + relX, y + relY, c);
|
225
|
-
}
|
226
|
-
}
|
227
|
-
}
|
data/src/Text/TextTTFWin.cpp
DELETED
@@ -1,249 +0,0 @@
|
|
1
|
-
#include <windows.h>
|
2
|
-
#include <cassert>
|
3
|
-
#include <cstdio>
|
4
|
-
#include <Gosu/Utility.hpp>
|
5
|
-
|
6
|
-
// Adapted from http://www.codeproject.com/KB/GDI/xfont.aspx.
|
7
|
-
// Kudos to Philip Patrick and Hans Dietrich!
|
8
|
-
|
9
|
-
struct FONT_PROPERTIES_ANSI
|
10
|
-
{
|
11
|
-
char csName[1024];
|
12
|
-
char csCopyright[1024];
|
13
|
-
char csTrademark[1024];
|
14
|
-
char csFamily[1024];
|
15
|
-
};
|
16
|
-
struct TT_OFFSET_TABLE
|
17
|
-
{
|
18
|
-
USHORT uMajorVersion;
|
19
|
-
USHORT uMinorVersion;
|
20
|
-
USHORT uNumOfTables;
|
21
|
-
USHORT uSearchRange;
|
22
|
-
USHORT uEntrySelector;
|
23
|
-
USHORT uRangeShift;
|
24
|
-
};
|
25
|
-
struct TT_TABLE_DIRECTORY
|
26
|
-
{
|
27
|
-
char szTag[4]; //table name
|
28
|
-
ULONG uCheckSum; //Check sum
|
29
|
-
ULONG uOffset; //Offset from beginning of file
|
30
|
-
ULONG uLength; //length of the table in bytes
|
31
|
-
};
|
32
|
-
struct TT_NAME_TABLE_HEADER
|
33
|
-
{
|
34
|
-
USHORT uFSelector; //format selector. Always 0
|
35
|
-
USHORT uNRCount; //Name Records count
|
36
|
-
USHORT uStorageOffset; //Offset for strings storage, from start of the table
|
37
|
-
};
|
38
|
-
struct TT_NAME_RECORD
|
39
|
-
{
|
40
|
-
USHORT uPlatformID;
|
41
|
-
USHORT uEncodingID;
|
42
|
-
USHORT uLanguageID;
|
43
|
-
USHORT uNameID;
|
44
|
-
USHORT uStringLength;
|
45
|
-
USHORT uStringOffset; //from start of storage area
|
46
|
-
};
|
47
|
-
|
48
|
-
#define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
|
49
|
-
#define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
|
50
|
-
|
51
|
-
#define _T(x) x
|
52
|
-
#define TRACE printf
|
53
|
-
|
54
|
-
namespace Gosu
|
55
|
-
{
|
56
|
-
std::wstring getNameFromTTFFile(const std::wstring& filename)
|
57
|
-
{
|
58
|
-
FONT_PROPERTIES_ANSI fp;
|
59
|
-
FONT_PROPERTIES_ANSI * lpFontProps = &fp;
|
60
|
-
memset(lpFontProps, 0, sizeof(FONT_PROPERTIES_ANSI));
|
61
|
-
|
62
|
-
HANDLE hFile = INVALID_HANDLE_VALUE;
|
63
|
-
hFile = ::CreateFile(filename.c_str(),
|
64
|
-
GENERIC_READ,// | GENERIC_WRITE,
|
65
|
-
FILE_SHARE_READ,
|
66
|
-
NULL,
|
67
|
-
OPEN_EXISTING,
|
68
|
-
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
|
69
|
-
NULL);
|
70
|
-
|
71
|
-
if (hFile == INVALID_HANDLE_VALUE)
|
72
|
-
{
|
73
|
-
TRACE(_T("ERROR: failed to open '%s'\n"), Gosu::narrow(filename).c_str());
|
74
|
-
TRACE(_T("ERROR: %s failed, GetLastError() = 0x%x\n"), _T("CreateFile"), (int)GetLastError());
|
75
|
-
return filename;
|
76
|
-
}
|
77
|
-
|
78
|
-
// get the file size
|
79
|
-
DWORD dwFileSize = ::GetFileSize(hFile, NULL);
|
80
|
-
|
81
|
-
if (dwFileSize == INVALID_FILE_SIZE)
|
82
|
-
{
|
83
|
-
TRACE(_T("ERROR: %s failed\n"), _T("GetFileSize"));
|
84
|
-
::CloseHandle(hFile);
|
85
|
-
return filename;
|
86
|
-
}
|
87
|
-
|
88
|
-
//TRACE(_T("dwFileSize = %d\n"), dwFileSize);
|
89
|
-
|
90
|
-
// Create a file mapping object that is the current size of the file
|
91
|
-
HANDLE hMappedFile = NULL;
|
92
|
-
hMappedFile = ::CreateFileMapping(hFile,
|
93
|
-
NULL,
|
94
|
-
PAGE_READONLY, //PAGE_READWRITE,
|
95
|
-
0,
|
96
|
-
dwFileSize,
|
97
|
-
NULL);
|
98
|
-
|
99
|
-
if (hMappedFile == NULL)
|
100
|
-
{
|
101
|
-
TRACE(_T("ERROR: %s failed\n"), _T("CreateFileMapping"));
|
102
|
-
::CloseHandle(hFile);
|
103
|
-
return filename;
|
104
|
-
}
|
105
|
-
|
106
|
-
LPBYTE lpMapAddress = (LPBYTE) ::MapViewOfFile(hMappedFile, // handle to file-mapping object
|
107
|
-
FILE_MAP_READ,//FILE_MAP_WRITE, // access mode
|
108
|
-
0, // high-order DWORD of offset
|
109
|
-
0, // low-order DWORD of offset
|
110
|
-
0); // number of bytes to map
|
111
|
-
|
112
|
-
if (lpMapAddress == NULL)
|
113
|
-
{
|
114
|
-
TRACE(_T("ERROR: %s failed\n"), _T("MapViewOfFile"));
|
115
|
-
::CloseHandle(hMappedFile);
|
116
|
-
::CloseHandle(hFile);
|
117
|
-
return filename;
|
118
|
-
}
|
119
|
-
|
120
|
-
BOOL bRetVal = FALSE;
|
121
|
-
int index = 0;
|
122
|
-
|
123
|
-
TT_OFFSET_TABLE ttOffsetTable;
|
124
|
-
memcpy(&ttOffsetTable, &lpMapAddress[index], sizeof(TT_OFFSET_TABLE));
|
125
|
-
index += sizeof(TT_OFFSET_TABLE);
|
126
|
-
|
127
|
-
ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
|
128
|
-
ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
|
129
|
-
ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
|
130
|
-
|
131
|
-
//check is this is a true type font and the version is 1.0
|
132
|
-
if (ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0)
|
133
|
-
return L"";
|
134
|
-
|
135
|
-
TT_TABLE_DIRECTORY tblDir;
|
136
|
-
memset(&tblDir, 0, sizeof(TT_TABLE_DIRECTORY));
|
137
|
-
BOOL bFound = FALSE;
|
138
|
-
char szTemp[4096];
|
139
|
-
memset(szTemp, 0, sizeof(szTemp));
|
140
|
-
|
141
|
-
for (int i = 0; i< ttOffsetTable.uNumOfTables; i++)
|
142
|
-
{
|
143
|
-
//f.Read(&tblDir, sizeof(TT_TABLE_DIRECTORY));
|
144
|
-
memcpy(&tblDir, &lpMapAddress[index], sizeof(TT_TABLE_DIRECTORY));
|
145
|
-
index += sizeof(TT_TABLE_DIRECTORY);
|
146
|
-
|
147
|
-
strncpy(szTemp, tblDir.szTag, 4);
|
148
|
-
if (stricmp(szTemp, "name") == 0)
|
149
|
-
{
|
150
|
-
bFound = TRUE;
|
151
|
-
tblDir.uLength = SWAPLONG(tblDir.uLength);
|
152
|
-
tblDir.uOffset = SWAPLONG(tblDir.uOffset);
|
153
|
-
break;
|
154
|
-
}
|
155
|
-
else if (szTemp[0] == 0)
|
156
|
-
{
|
157
|
-
break;
|
158
|
-
}
|
159
|
-
}
|
160
|
-
|
161
|
-
if (bFound)
|
162
|
-
{
|
163
|
-
index = tblDir.uOffset;
|
164
|
-
|
165
|
-
TT_NAME_TABLE_HEADER ttNTHeader;
|
166
|
-
memcpy(&ttNTHeader, &lpMapAddress[index], sizeof(TT_NAME_TABLE_HEADER));
|
167
|
-
index += sizeof(TT_NAME_TABLE_HEADER);
|
168
|
-
|
169
|
-
ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
|
170
|
-
ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
|
171
|
-
TT_NAME_RECORD ttRecord;
|
172
|
-
bFound = FALSE;
|
173
|
-
|
174
|
-
for (int i = 0;
|
175
|
-
i < ttNTHeader.uNRCount &&
|
176
|
-
(lpFontProps->csCopyright[0] == 0 ||
|
177
|
-
lpFontProps->csName[0] == 0 ||
|
178
|
-
lpFontProps->csTrademark[0] == 0 ||
|
179
|
-
lpFontProps->csFamily[0] == 0);
|
180
|
-
i++)
|
181
|
-
{
|
182
|
-
memcpy(&ttRecord, &lpMapAddress[index], sizeof(TT_NAME_RECORD));
|
183
|
-
index += sizeof(TT_NAME_RECORD);
|
184
|
-
|
185
|
-
ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
|
186
|
-
ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
|
187
|
-
ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
|
188
|
-
|
189
|
-
if (ttRecord.uNameID == 1 || ttRecord.uNameID == 0 || ttRecord.uNameID == 7)
|
190
|
-
{
|
191
|
-
int nPos = index; //f.GetPosition();
|
192
|
-
|
193
|
-
index = tblDir.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset;
|
194
|
-
|
195
|
-
memset(szTemp, 0, sizeof(szTemp));
|
196
|
-
|
197
|
-
memcpy(szTemp, &lpMapAddress[index], ttRecord.uStringLength);
|
198
|
-
index += ttRecord.uStringLength;
|
199
|
-
|
200
|
-
if (szTemp[0] != 0)
|
201
|
-
{
|
202
|
-
assert (strlen(szTemp) < sizeof(lpFontProps->csName));
|
203
|
-
|
204
|
-
switch (ttRecord.uNameID)
|
205
|
-
{
|
206
|
-
case 0:
|
207
|
-
if (lpFontProps->csCopyright[0] == 0)
|
208
|
-
strncpy(lpFontProps->csCopyright, szTemp,
|
209
|
-
sizeof(lpFontProps->csCopyright)-1);
|
210
|
-
break;
|
211
|
-
|
212
|
-
case 1:
|
213
|
-
if (lpFontProps->csFamily[0] == 0)
|
214
|
-
strncpy(lpFontProps->csFamily, szTemp,
|
215
|
-
sizeof(lpFontProps->csFamily)-1);
|
216
|
-
bRetVal = TRUE;
|
217
|
-
break;
|
218
|
-
|
219
|
-
case 4:
|
220
|
-
if (lpFontProps->csName[0] == 0)
|
221
|
-
strncpy(lpFontProps->csName, szTemp,
|
222
|
-
sizeof(lpFontProps->csName)-1);
|
223
|
-
break;
|
224
|
-
|
225
|
-
case 7:
|
226
|
-
if (lpFontProps->csTrademark[0] == 0)
|
227
|
-
strncpy(lpFontProps->csTrademark, szTemp,
|
228
|
-
sizeof(lpFontProps->csTrademark)-1);
|
229
|
-
break;
|
230
|
-
|
231
|
-
default:
|
232
|
-
break;
|
233
|
-
}
|
234
|
-
}
|
235
|
-
index = nPos;
|
236
|
-
}
|
237
|
-
}
|
238
|
-
}
|
239
|
-
|
240
|
-
::UnmapViewOfFile(lpMapAddress);
|
241
|
-
::CloseHandle(hMappedFile);
|
242
|
-
::CloseHandle(hFile);
|
243
|
-
|
244
|
-
if (lpFontProps->csName[0] == 0)
|
245
|
-
strcpy(lpFontProps->csName, lpFontProps->csFamily);
|
246
|
-
|
247
|
-
return Gosu::widen(lpFontProps->csName);
|
248
|
-
}
|
249
|
-
}
|