File: drawtext.c

package info (click to toggle)
xsystem35 2.17.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 8,096 kB
  • sloc: ansic: 38,159; java: 4,085; xml: 249; sh: 134; python: 15; makefile: 12
file content (78 lines) | stat: -rw-r--r-- 2,412 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * drawtext.c  DLL用に surface 上に文字を描く
 *
 * Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
 *               1998-                           <masaki-c@is.aist-nara.ac.jp>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
*/
/* $Id: drawtext.c,v 1.2 2003/07/21 23:06:47 chikama Exp $ */

#include "config.h"

#include <stdio.h>

#include "portab.h"
#include "system.h"
#include "nact.h"
#include "ags.h"
#include "font.h"

static FontType ftype;
static int fsize;  // フォントの大きさ

/**
 * 次に描く文字のフォントの種類と大きさを設定
 * 
 * @param type: フォント種類 (FONT_MINCHO, FONT_GOTHIC)
 * @param size: フォントサイズ
 */
void dt_setfont(FontType type, int size) {
#ifdef __EMSCRIPTEN__
	if (type == FONT_MINCHO) {
		if (!load_mincho_font())
			type = FONT_GOTHIC;
	}
#endif

	ftype = type;
	fsize = size;
}

/**
 * surface にカラー文字を描画。alphamap に256階調のアンチエイリアスされた
 * 文字を描き、pixelmap には、色情報を矩形で描く
 * 
 * @param sf: 描画する surface
 * @param x: 描画位置X座標
 * @param y: 描画位置Y座標
 * @param buf: 描画文字列(SJIS)
 * @param r: 文字色赤
 * @param g: 文字色緑
 * @param b: 文字色青
 * @return: 実際に描画した幅
 */ 
int dt_drawtext_col(SDL_Surface *sf, int x, int y, char *buf, int r, int g, int b) {
	ags_setFont(ftype, fsize);
	SDL_Surface *glyph = ags_drawStringToSurface(buf, r, g, b);
	if (glyph == NULL) return 0;

	SDL_Rect rect = {x, y, glyph->w, glyph->h};
	SDL_SetSurfaceBlendMode(glyph, SDL_BLENDMODE_NONE);
	SDL_BlitSurface(glyph, NULL, sf, &rect);
	SDL_FreeSurface(glyph);
	return rect.w;
}