dxrubynd 1.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/dxruby/font.c ADDED
@@ -0,0 +1,686 @@
1
+ #define WINVER 0x0500 /* �o�[�W������` Windows2000�ȏ� */
2
+ #define _WIN32_WINNT WINVER
3
+
4
+ #include "ruby.h"
5
+ #ifndef RUBY_ST_H
6
+ #include "st.h"
7
+ #endif
8
+
9
+ #define DXRUBY_EXTERN 1
10
+ #include "dxruby.h"
11
+ #include "font.h"
12
+
13
+ static VALUE cFont; /* �t�H���g�N���X */
14
+ static VALUE cFontInfo; /* �t�H���g���N���X */
15
+ static VALUE symbol_italic = Qundef;
16
+ static VALUE symbol_weight = Qundef;
17
+ static VALUE symbol_auto_fitting = Qundef;
18
+
19
+ VALUE hash_lookup(VALUE hash, VALUE key);
20
+ static VALUE Font_enum( VALUE klass );
21
+
22
+ /*********************************************************************
23
+ * Font�N���X
24
+ *
25
+ * D3DXFont�C���^�[�t�F�[�X���g�p���ăt�H���g��`�悷��B
26
+ * �X�v���C�g�`��ɍ������ނ��ƂłƂ肠���������B
27
+ *********************************************************************/
28
+ /*--------------------------------------------------------------------
29
+ �Q�Ƃ���Ȃ��Ȃ����Ƃ���GC����Ă΂��֐�
30
+ ---------------------------------------------------------------------*/
31
+ static void Font_free( struct DXRubyFont *font )
32
+ {
33
+ RELEASE( font->pD3DXFont );
34
+ DeleteObject( font->hFont );
35
+ }
36
+ void Font_release( struct DXRubyFont *font )
37
+ {
38
+ /* �t�H���g�I�u�W�F�N�g�̊J�� */
39
+ if( font->pD3DXFont )
40
+ {
41
+ Font_free( font );
42
+ }
43
+ free( font );
44
+ font = NULL;
45
+
46
+ g_iRefAll--;
47
+ if( g_iRefAll == 0 )
48
+ {
49
+ CoUninitialize();
50
+ }
51
+ }
52
+
53
+ /*--------------------------------------------------------------------
54
+ Font�N���X��mark
55
+ ---------------------------------------------------------------------*/
56
+ static void Font_mark( struct DXRubyFont *font )
57
+ {
58
+ rb_gc_mark( font->vfontname );
59
+ rb_gc_mark( font->vitalic );
60
+ rb_gc_mark( font->vweight );
61
+ rb_gc_mark( font->vauto_fitting );
62
+ font->vglyph_naa = Qnil;
63
+ font->vglyph_aa = Qnil;
64
+ }
65
+
66
+ #ifdef DXRUBY_USE_TYPEDDATA
67
+ const rb_data_type_t Font_data_type = {
68
+ "Font",
69
+ {
70
+ Font_mark,
71
+ Font_release,
72
+ 0,
73
+ },
74
+ NULL, NULL
75
+ };
76
+ #endif
77
+
78
+ /*--------------------------------------------------------------------
79
+ Font�N���X��dispose�B
80
+ ---------------------------------------------------------------------*/
81
+ static VALUE Font_dispose( VALUE self )
82
+ {
83
+ struct DXRubyFont *font = DXRUBY_GET_STRUCT( Font, self );
84
+ DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
85
+ Font_free( font );
86
+ return Qnil;
87
+ }
88
+
89
+ /*--------------------------------------------------------------------
90
+ Font�N���X��disposed?�B
91
+ ---------------------------------------------------------------------*/
92
+ static VALUE Font_check_disposed( VALUE self )
93
+ {
94
+ if( DXRUBY_GET_STRUCT( Font, self )->pD3DXFont == NULL )
95
+ {
96
+ return Qtrue;
97
+ }
98
+
99
+ return Qfalse;
100
+ }
101
+
102
+ /*--------------------------------------------------------------------
103
+ Font�N���X��allocate�B���������m�ۂ���ׂ�initialize�O�ɌĂ΂��B
104
+ ---------------------------------------------------------------------*/
105
+ static VALUE Font_allocate( VALUE klass )
106
+ {
107
+ VALUE obj;
108
+ struct DXRubyFont *font;
109
+
110
+ /* DXRubyFont�̃������擾��Font�I�u�W�F�N�g���� */
111
+ font = malloc( sizeof(struct DXRubyFont) );
112
+ if( font == NULL ) rb_raise( eDXRubyError, "out of memory - Font_allocate" );
113
+ #ifdef DXRUBY_USE_TYPEDDATA
114
+ obj = TypedData_Wrap_Struct( klass, &Font_data_type, font );
115
+ #else
116
+ obj = Data_Wrap_Struct(klass, Font_mark, Font_release, font);
117
+ #endif
118
+
119
+ font->pD3DXFont = NULL;
120
+ font->hFont = NULL;
121
+ font->size = 0;
122
+ font->vfontname = Qnil;
123
+ font->vitalic = Qnil;
124
+ font->vweight = Qnil;
125
+ font->vglyph_aa = Qnil;
126
+ font->vglyph_naa = Qnil;
127
+ font->vauto_fitting = Qnil;
128
+ return obj;
129
+ }
130
+
131
+
132
+ /*--------------------------------------------------------------------
133
+ Font�N���X��Initialize
134
+ ---------------------------------------------------------------------*/
135
+ static VALUE Font_initialize( int argc, VALUE *argv, VALUE obj )
136
+ {
137
+ struct DXRubyFont *font;
138
+ HRESULT hr;
139
+ D3DXFONT_DESC desc;
140
+ VALUE size, vfontname, voption, hash, vweight, vitalic, vauto_fitting;
141
+ LOGFONT logfont;
142
+ int weight, italic, auto_fitting;
143
+
144
+ g_iRefAll++;
145
+
146
+ rb_scan_args( argc, argv, "12", &size, &vfontname, &hash );
147
+
148
+ if( hash == Qnil )
149
+ {
150
+ voption = rb_hash_new();
151
+ }
152
+ else
153
+ {
154
+ Check_Type( hash, T_HASH );
155
+ voption = hash;
156
+ }
157
+
158
+ vweight = hash_lookup( voption, symbol_weight );
159
+ vitalic = hash_lookup( voption, symbol_italic );
160
+ vauto_fitting = hash_lookup( voption, symbol_auto_fitting );
161
+
162
+ if( vweight == Qnil || vweight == Qfalse )
163
+ {
164
+ weight = 400;
165
+ }
166
+ else if( vweight == Qtrue )
167
+ {
168
+ weight = 1000;
169
+ }
170
+ else
171
+ {
172
+ weight = NUM2INT( vweight );
173
+ }
174
+
175
+ if( vitalic == Qnil || vitalic == Qfalse )
176
+ {
177
+ italic = FALSE;
178
+ }
179
+ else
180
+ {
181
+ italic = TRUE;
182
+ }
183
+
184
+ if( vauto_fitting == Qnil || vauto_fitting == Qfalse )
185
+ {
186
+ auto_fitting = 1;
187
+ }
188
+ else
189
+ {
190
+ auto_fitting = -1;
191
+ }
192
+
193
+ desc.Height = NUM2INT( size ) * auto_fitting;
194
+ desc.Width = 0;
195
+ desc.Weight = weight;
196
+ desc.MipLevels = 0;
197
+ desc.Italic = italic;
198
+ desc.CharSet = DEFAULT_CHARSET;
199
+ desc.OutputPrecision = 0;
200
+ desc.Quality = DEFAULT_QUALITY;
201
+ desc.PitchAndFamily = DEFAULT_PITCH || FF_DONTCARE;
202
+
203
+ ZeroMemory( &logfont, sizeof(logfont) );
204
+ logfont.lfHeight = NUM2INT( size ) * auto_fitting;
205
+ logfont.lfWidth = 0;
206
+ logfont.lfWeight = weight;
207
+ logfont.lfItalic = italic;
208
+ logfont.lfCharSet = DEFAULT_CHARSET;
209
+ logfont.lfQuality = ANTIALIASED_QUALITY;
210
+
211
+ if( vfontname == Qnil )
212
+ {
213
+ lstrcpy(desc.FaceName, "�l�r �o�S�V�b�N");
214
+ lstrcpy(logfont.lfFaceName, "�l�r �o�S�V�b�N");
215
+ }
216
+ else
217
+ {
218
+ VALUE vsjisstr;
219
+ Check_Type(vfontname, T_STRING);
220
+
221
+ if( rb_enc_get_index( vfontname ) != 0 )
222
+ {
223
+ vsjisstr = rb_str_export_to_enc( vfontname, g_enc_sys );
224
+ }
225
+ else
226
+ {
227
+ vsjisstr = vfontname;
228
+ }
229
+
230
+ lstrcpy(desc.FaceName, RSTRING_PTR( vsjisstr ));
231
+ lstrcpy(logfont.lfFaceName, RSTRING_PTR( vsjisstr ));
232
+ }
233
+
234
+ /* �t�H���g�I�u�W�F�N�g���o�� */
235
+ font = DXRUBY_GET_STRUCT( Font, obj );
236
+ if( font->pD3DXFont )
237
+ {
238
+ Font_free( font );
239
+ font->vglyph_aa = Qnil;
240
+ font->vglyph_naa = Qnil;
241
+ g_iRefAll--;
242
+ }
243
+
244
+ hr = D3DXCreateFontIndirect( g_pD3DDevice, &desc, &font->pD3DXFont );
245
+
246
+ if( FAILED( hr ) )
247
+ {
248
+ rb_raise( eDXRubyError, "Create font error - D3DXCreateFontIndirect" );
249
+ }
250
+
251
+ font->hFont = CreateFontIndirect( &logfont );
252
+
253
+ if( font->hFont == NULL )
254
+ {
255
+ rb_raise( eDXRubyError, "Create font error - CreateFontIndirect" );
256
+ }
257
+
258
+ font->size = NUM2INT( size );
259
+ OBJ_WRITE( obj, &font->vitalic, vitalic );
260
+ OBJ_WRITE( obj, &font->vweight, vweight );
261
+ OBJ_WRITE( obj, &font->vauto_fitting, vauto_fitting );
262
+ OBJ_WRITE( obj, &font->vfontname, vfontname == Qnil ? Qnil : rb_str_new_shared( vfontname ) );
263
+
264
+ return obj;
265
+ }
266
+
267
+
268
+ /*--------------------------------------------------------------------
269
+ Font�N���X��install
270
+ ---------------------------------------------------------------------*/
271
+ static VALUE Font_install( VALUE klass, VALUE vstr )
272
+ {
273
+ int result;
274
+ VALUE vsjisstr, vary1, vary2;
275
+
276
+ Check_Type( vstr, T_STRING );
277
+
278
+ if( rb_enc_get_index( vstr ) != 0 )
279
+ {
280
+ vsjisstr = rb_str_export_to_enc( vstr, g_enc_sys );
281
+ }
282
+ else
283
+ {
284
+ vsjisstr = vstr;
285
+ }
286
+
287
+ vary1 = Font_enum( klass );
288
+ result = AddFontResourceEx( RSTRING_PTR( vsjisstr ), 0x10, 0 );
289
+ if( result == 0 )
290
+ {
291
+ rb_raise( eDXRubyError, "Font install error - Font_install" );
292
+ }
293
+ vary2 = Font_enum( klass );
294
+
295
+ return rb_funcall( vary2, rb_intern( "-" ), 1, vary1 );
296
+ }
297
+
298
+
299
+ /*--------------------------------------------------------------------
300
+ �t�H���g�̕����擾����
301
+ ---------------------------------------------------------------------*/
302
+ VALUE Font_getWidth( VALUE obj, VALUE vstr )
303
+ {
304
+ HDC hDC;
305
+ struct DXRubyFont *font;
306
+ RECT rc = {0};
307
+
308
+ Check_Type( vstr, T_STRING );
309
+
310
+ /* �t�H���g�I�u�W�F�N�g���o�� */
311
+ font = DXRUBY_GET_STRUCT( Font, obj );
312
+ DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
313
+
314
+ hDC = GetDC( g_hWnd );
315
+ if( hDC == NULL )
316
+ {
317
+ rb_raise( eDXRubyError, "get DC failed - GetDC" );
318
+ }
319
+
320
+ SelectObject( hDC, font->hFont );
321
+
322
+ if( rb_enc_get_index( vstr ) != 0 )
323
+ {
324
+ VALUE vutf16str = rb_str_export_to_enc( vstr, g_enc_utf16 );
325
+ DrawTextW( hDC, (LPWSTR)RSTRING_PTR( vutf16str ), RSTRING_LEN( vutf16str ) / 2, &rc, DT_LEFT | DT_NOCLIP | DT_NOPREFIX | DT_CALCRECT | DT_SINGLELINE);
326
+ }
327
+ else
328
+ {
329
+ DrawText( hDC, RSTRING_PTR( vstr ), -1, &rc, DT_LEFT | DT_NOCLIP | DT_NOPREFIX | DT_CALCRECT | DT_SINGLELINE);
330
+ }
331
+
332
+ ReleaseDC( g_hWnd, hDC );
333
+
334
+ return INT2FIX( rc.right );
335
+ }
336
+
337
+
338
+ /*--------------------------------------------------------------------
339
+ �t�H���g�̃T�C�Y���擾����
340
+ ---------------------------------------------------------------------*/
341
+ VALUE Font_getSize( VALUE obj )
342
+ {
343
+ struct DXRubyFont *font;
344
+
345
+ /* �t�H���g�I�u�W�F�N�g���o�� */
346
+ font = DXRUBY_GET_STRUCT( Font, obj );
347
+ DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
348
+
349
+ return INT2FIX( font->size );
350
+ }
351
+
352
+
353
+ /*--------------------------------------------------------------------
354
+ �������Ɏw�肵���t�H���g���̂��擾����
355
+ ---------------------------------------------------------------------*/
356
+ static VALUE Font_getFontname( VALUE obj )
357
+ {
358
+ struct DXRubyFont *font;
359
+
360
+ /* �t�H���g�I�u�W�F�N�g���o�� */
361
+ font = DXRUBY_GET_STRUCT( Font, obj );
362
+ DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
363
+
364
+ return font->vfontname;
365
+ }
366
+
367
+
368
+ /*--------------------------------------------------------------------
369
+ ���ۂɐ������ꂽ�t�H���g���̂��擾����
370
+ ---------------------------------------------------------------------*/
371
+ static VALUE Font_getName( VALUE obj )
372
+ {
373
+ struct DXRubyFont *font;
374
+ int hr;
375
+ HDC hDC;
376
+ char buf[1024];
377
+
378
+ /* �t�H���g�I�u�W�F�N�g���o�� */
379
+ font = DXRUBY_GET_STRUCT( Font, obj );
380
+ DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
381
+
382
+ hDC = GetDC( g_hWnd );
383
+ if( hDC == NULL )
384
+ {
385
+ rb_raise( eDXRubyError, "get DC failed - GetDC" );
386
+ }
387
+
388
+ SelectObject( hDC, font->hFont );
389
+ hr = GetTextFace( hDC, 1024, buf );
390
+ ReleaseDC( g_hWnd, hDC );
391
+
392
+ if( FAILED( hr ) )
393
+ {
394
+ return rb_str_new( "\0", 1 );
395
+ }
396
+
397
+ return rb_enc_associate( rb_str_new2( buf ), g_enc_sys );
398
+ }
399
+
400
+
401
+ /*--------------------------------------------------------------------
402
+ �C�^���b�N�t���O���擾����
403
+ ---------------------------------------------------------------------*/
404
+ static VALUE Font_getItalic( VALUE obj )
405
+ {
406
+ struct DXRubyFont *font;
407
+
408
+ /* �t�H���g�I�u�W�F�N�g���o�� */
409
+ font = DXRUBY_GET_STRUCT( Font, obj );
410
+ DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
411
+
412
+ return font->vitalic;
413
+ }
414
+
415
+
416
+ /*--------------------------------------------------------------------
417
+ �t�H���g�̑������擾����
418
+ ---------------------------------------------------------------------*/
419
+ static VALUE Font_getWeight( VALUE obj )
420
+ {
421
+ struct DXRubyFont *font;
422
+
423
+ /* �t�H���g�I�u�W�F�N�g���o�� */
424
+ font = DXRUBY_GET_STRUCT( Font, obj );
425
+ DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
426
+
427
+ return font->vweight;
428
+ }
429
+
430
+ /*--------------------------------------------------------------------
431
+ auto_fitting�t���O���擾����
432
+ ---------------------------------------------------------------------*/
433
+ static VALUE Font_getAutoFitting( VALUE obj )
434
+ {
435
+ struct DXRubyFont *font;
436
+
437
+ /* �t�H���g�I�u�W�F�N�g���o�� */
438
+ font = DXRUBY_GET_STRUCT( Font, obj );
439
+ DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
440
+
441
+ return font->vauto_fitting;
442
+ }
443
+
444
+ /*--------------------------------------------------------------------
445
+ �O���t�����擾����
446
+ ---------------------------------------------------------------------*/
447
+ char *Font_getGlyph( VALUE self, UINT widechr, HDC hDC, GLYPHMETRICS *gm, VALUE vaa_flag )
448
+ {
449
+ struct DXRubyFont *font = DXRUBY_GET_STRUCT( Font, self );
450
+ MAT2 mat2 = {{0,1},{0,0},{0,0},{0,1}};
451
+ VALUE vstr;
452
+ VALUE temp_naa = font->vglyph_naa;
453
+ VALUE temp_aa = font->vglyph_aa;
454
+
455
+ if( temp_naa == Qnil )
456
+ {
457
+ temp_naa = rb_hash_new();
458
+ }
459
+ if( temp_aa == Qnil )
460
+ {
461
+ temp_aa = rb_hash_new();
462
+ }
463
+
464
+ if( vaa_flag == Qnil )
465
+ {
466
+ vaa_flag = Qtrue;
467
+ }
468
+
469
+ if( RTEST(vaa_flag) )
470
+ { /* AA���� */
471
+ int bufsize;
472
+ char *buf;
473
+ vstr = hash_lookup( temp_aa, INT2NUM( widechr ) );
474
+
475
+ bufsize = GetGlyphOutlineW( hDC, widechr, GGO_GRAY8_BITMAP,
476
+ gm, 0, NULL, &mat2 );
477
+
478
+ if( vstr == Qnil )
479
+ {
480
+ buf = alloca( bufsize );
481
+ GetGlyphOutlineW( hDC, widechr, GGO_GRAY8_BITMAP,
482
+ gm, bufsize, (LPVOID)buf, &mat2 );
483
+
484
+ vstr = rb_str_new( buf, bufsize );
485
+ rb_hash_aset( temp_aa, INT2NUM( widechr ), vstr );
486
+ }
487
+ }
488
+ else
489
+ { /* AA�Ȃ��B���m�N���f�[�^��GRAY8�`���ɕϊ����ăL���b�V������ */
490
+ vstr = hash_lookup( temp_naa, INT2NUM( widechr ) );
491
+
492
+ if( vstr == Qnil )
493
+ {
494
+ int bufsize_mono, bufsize_gray8;
495
+ char *buf_mono, *buf_gray8;
496
+ int x, y;
497
+ int pitch_mono, pitch_gray8;
498
+
499
+ /* ���m�N���f�[�^�擾 */
500
+ bufsize_mono = GetGlyphOutlineW( hDC, widechr, GGO_BITMAP,
501
+ gm, 0, NULL, &mat2 );
502
+ buf_mono = alloca( bufsize_mono );
503
+ GetGlyphOutlineW( hDC, widechr, GGO_BITMAP,
504
+ gm, bufsize_mono, (LPVOID)buf_mono, &mat2 );
505
+
506
+ bufsize_gray8 = ((gm->gmBlackBoxX + 3) & 0xfffc) * gm->gmBlackBoxY;
507
+ buf_gray8 = alloca( bufsize_gray8 );
508
+
509
+ /* �ϊ����� */
510
+ pitch_mono = ((gm->gmBlackBoxX + 31) / 32) * 4;
511
+ pitch_gray8 = ((gm->gmBlackBoxX + 3) & 0xfffc);
512
+ for( y = 0; y < gm->gmBlackBoxY; y++ )
513
+ {
514
+ for( x = 0; x < gm->gmBlackBoxX; x++ )
515
+ {
516
+ if( *(buf_mono + x/8 + y * pitch_mono) & (1 << (7-(x%8))) )
517
+ {
518
+ *(buf_gray8 + x + y * pitch_gray8) = 64;
519
+ }
520
+ else
521
+ {
522
+ *(buf_gray8 + x + y * pitch_gray8) = 0;
523
+ }
524
+ }
525
+ }
526
+
527
+ vstr = rb_str_new( buf_gray8, bufsize_gray8 );
528
+ rb_hash_aset( temp_naa, INT2NUM( widechr ), vstr );
529
+ }
530
+ else
531
+ {
532
+ int bufsize;
533
+ bufsize = GetGlyphOutlineW( hDC, widechr, GGO_BITMAP,
534
+ gm, 0, NULL, &mat2 );
535
+ }
536
+ }
537
+
538
+ OBJ_WRITE( self, &font->vglyph_naa, temp_naa );
539
+ OBJ_WRITE( self, &font->vglyph_naa, temp_aa );
540
+ return RSTRING_PTR( vstr );
541
+ }
542
+
543
+ void Font_getInfo_internal( VALUE vstr, struct DXRubyFont *font, int *intBlackBoxX, int *intBlackBoxY, int *intCellIncX, int *intPtGlyphOriginX, int *intPtGlyphOriginY, int *intTmAscent, int *intTmDescent )
544
+ {
545
+ MAT2 mat2 = {{0,1},{0,0},{0,0},{0,1}};
546
+ int bufsize;
547
+ char *buf;
548
+ TEXTMETRIC tm;
549
+ GLYPHMETRICS gm;
550
+ HDC hDC;
551
+ WCHAR widechar;
552
+ VALUE vwidestr;
553
+
554
+ Check_Type( vstr, T_STRING );
555
+
556
+ if( RSTRING_LEN( vstr ) == 0 )
557
+ {
558
+ rb_raise( eDXRubyError, "String is empty - info" );
559
+ }
560
+
561
+ /* �`�敶����UTF16LE�� */
562
+ if( rb_enc_get_index( vstr ) != 0 )
563
+ {
564
+ vwidestr = rb_str_export_to_enc( vstr, g_enc_utf16 );
565
+ widechar = *(WCHAR*)RSTRING_PTR( vwidestr );
566
+ }
567
+ else
568
+ {
569
+ MultiByteToWideChar( CP_ACP, 0, RSTRING_PTR( vstr ), 1, (LPWSTR)&widechar, 2 );
570
+ }
571
+
572
+ hDC = GetDC( g_hWnd );
573
+ SelectObject( hDC, font->hFont );
574
+ GetTextMetrics( hDC, &tm );
575
+
576
+ bufsize = GetGlyphOutlineW( hDC, widechar, GGO_GRAY8_BITMAP,
577
+ &gm, 0, NULL, &mat2 );
578
+ ReleaseDC( g_hWnd, hDC );
579
+
580
+ *intBlackBoxX = gm.gmBlackBoxX;
581
+ *intBlackBoxY = gm.gmBlackBoxY;
582
+ *intCellIncX = gm.gmCellIncX;
583
+ *intPtGlyphOriginX = gm.gmptGlyphOrigin.x;
584
+ *intPtGlyphOriginY = gm.gmptGlyphOrigin.y;
585
+ *intTmAscent = tm.tmAscent;
586
+ *intTmDescent = tm.tmDescent;
587
+ }
588
+
589
+ static VALUE Font_getInfo( VALUE self, VALUE vstr )
590
+ {
591
+ struct DXRubyFont *font = DXRUBY_GET_STRUCT( Font, self );
592
+ int intBlackBoxX, intBlackBoxY, intCellIncX, intPtGlyphOriginX, intPtGlyphOriginY, intTmAscent, intTmDescent;
593
+ VALUE ary[7];
594
+
595
+ Font_getInfo_internal( vstr, font, &intBlackBoxX, &intBlackBoxY, &intCellIncX, &intPtGlyphOriginX, &intPtGlyphOriginY, &intTmAscent, &intTmDescent );
596
+
597
+ ary[0] = INT2NUM(intBlackBoxX);
598
+ ary[1] = INT2NUM(intBlackBoxY);
599
+ ary[2] = INT2NUM(intCellIncX);
600
+ ary[3] = INT2NUM(intPtGlyphOriginX);
601
+ ary[4] = INT2NUM(intPtGlyphOriginY);
602
+ ary[5] = INT2NUM(intTmAscent);
603
+ ary[6] = INT2NUM(intTmDescent);
604
+
605
+ return rb_class_new_instance(7, ary, cFontInfo);
606
+ }
607
+
608
+
609
+ static VALUE Font_get_default( VALUE klass )
610
+ {
611
+ return rb_ivar_get( klass, rb_intern("default") );
612
+ }
613
+
614
+ static VALUE Font_set_default( VALUE klass, VALUE vfont )
615
+ {
616
+ rb_ivar_set( cFont, rb_intern("default"), vfont );
617
+
618
+ return vfont;
619
+ }
620
+
621
+
622
+ int CALLBACK EnumFontsProc(
623
+ CONST LOGFONT *lplf, // �_���t�H���g�f�[�^�ւ̃|�C���^
624
+ CONST TEXTMETRIC *lptm, // �����t�H���g�f�[�^�ւ̃|�C���^
625
+ DWORD dwType, // �t�H���g�^�C�v
626
+ LPARAM lpData // �A�v���P�[�V������`�̃f�[�^�ւ̃|�C���^
627
+ )
628
+ {
629
+ VALUE vstr = rb_str_new2( lplf->lfFaceName );
630
+ rb_enc_associate( vstr, g_enc_sys );
631
+ rb_ary_push( (VALUE)lpData, vstr );
632
+ return 1;
633
+ }
634
+
635
+ static VALUE Font_enum( VALUE klass )
636
+ {
637
+ HDC hdc = GetDC( g_hWnd );
638
+ VALUE vary = rb_ary_new();
639
+ EnumFonts( hdc , NULL ,EnumFontsProc , (LPARAM)vary );
640
+ ReleaseDC( g_hWnd, hdc );
641
+ return vary;
642
+ }
643
+
644
+
645
+ void Init_dxruby_Font()
646
+ {
647
+ VALUE vdefaultfont, vsize;
648
+
649
+ /* Font�N���X�o�^ */
650
+ cFont = rb_define_class_under( mDXRuby, "Font", rb_cObject );
651
+
652
+ /* Font�N���X�ɃN���X���\�b�h�o�^*/
653
+ rb_define_singleton_method( cFont, "install", Font_install, 1 );
654
+ rb_define_singleton_method( cFont, "default", Font_get_default, 0 );
655
+ rb_define_singleton_method( cFont, "default=", Font_set_default, 1 );
656
+
657
+ /* Font�N���X�Ƀ��\�b�h�o�^*/
658
+ rb_define_private_method( cFont, "initialize", Font_initialize, -1 );
659
+ rb_define_method( cFont, "dispose" , Font_dispose , 0 );
660
+ rb_define_method( cFont, "disposed?" , Font_check_disposed, 0 );
661
+ rb_define_method( cFont, "get_width" , Font_getWidth , 1 );
662
+ rb_define_method( cFont, "getWidth" , Font_getWidth , 1 );
663
+ rb_define_method( cFont, "fontname", Font_getFontname , 0 );
664
+ rb_define_method( cFont, "name", Font_getName , 0 );
665
+ rb_define_method( cFont, "italic", Font_getItalic , 0 );
666
+ rb_define_method( cFont, "weight" , Font_getWeight , 0 );
667
+ rb_define_method( cFont, "auto_fitting" , Font_getAutoFitting , 0 );
668
+ rb_define_method( cFont, "size" , Font_getSize , 0 );
669
+ rb_define_method( cFont, "info" , Font_getInfo , 1 );
670
+
671
+ /* Font�I�u�W�F�N�g�𐶐���������initialize�̑O�ɌĂ΂�郁�������蓖�Ċ֐��o�^ */
672
+ rb_define_alloc_func( cFont, Font_allocate );
673
+
674
+ symbol_italic = ID2SYM(rb_intern("italic"));
675
+ symbol_weight = ID2SYM(rb_intern("weight"));
676
+ symbol_auto_fitting = ID2SYM(rb_intern("auto_fitting"));
677
+
678
+ cFontInfo = rb_struct_define( NULL, "gm_blackbox_x", "gm_blackbox_y", "gm_cellinc_x", "gmpt_glyphorigin_x", "gmpt_glyphorigin_y", "tm_ascent", "tm_descent", 0 );
679
+ rb_define_const( cFont, "FontInfo", cFontInfo );
680
+
681
+ vdefaultfont = Font_allocate( cFont );
682
+ vsize = INT2FIX(24);
683
+ Font_initialize( 1, &vsize, vdefaultfont );
684
+ rb_ivar_set( cFont, rb_intern("default"), vdefaultfont );
685
+ }
686
+
data/ext/dxruby/font.h ADDED
@@ -0,0 +1,20 @@
1
+ /* �t�H���g�f�[�^ */
2
+ struct DXRubyFont {
3
+ LPD3DXFONT pD3DXFont; /* �t�H���g�I�u�W�F�N�g */
4
+ HFONT hFont; /* Image�`��Ɏg���t�H���g */
5
+ int size; /* �t�H���g�T�C�Y */
6
+ VALUE vfontname; /* �t�H���g���� */
7
+ VALUE vweight; /* ���� */
8
+ VALUE vitalic; /* �C�^���b�N�t���O */
9
+ VALUE vglyph_naa; /* �O���t�L���b�V��(AA�Ȃ�) */
10
+ VALUE vglyph_aa; /* �O���t�L���b�V��(AA����) */
11
+ VALUE vauto_fitting; /* ���ۂ̕`�敶�����w��T�C�Y�ɂȂ�悤�g�傷�� */
12
+ };
13
+
14
+ void Init_dxruby_Font( void );
15
+ void Font_release( struct DXRubyFont* font );
16
+ VALUE Font_getWidth( VALUE obj, VALUE vstr );
17
+ VALUE Font_getSize( VALUE obj );
18
+ char *Font_getGlyph( VALUE obj, UINT widechr, HDC hDC, GLYPHMETRICS *gm, VALUE vaa_flag );
19
+ void Font_getInfo_internal( VALUE vstr, struct DXRubyFont *font, int *intBlackBoxX, int *intBlackBoxY, int *intCellIncX, int *intPtGlyphOriginX, int *intPtGlyphOriginY, int *intTmAscent, int *intTmDescent );
20
+