File: drawtext.c

package info (click to toggle)
xsystem35 1.7.3-pre5-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 7,308 kB
  • ctags: 5,685
  • sloc: ansic: 51,002; sh: 11,898; asm: 863; makefile: 407; xml: 281; perl: 142
file content (116 lines) | stat: -rw-r--r-- 3,074 bytes parent folder | download | duplicates (4)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * 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"
#include "surface.h"
#include "ngraph.h"

static int ftype;  // եȤμ
static int fsize;  // եȤ礭

/**
 * ʸΥեȤμ礭
 * 
 * @param type: եȼ (FONT_MINCHO, FONT_GOTHIC)
 * @param size: եȥ
 */
int dt_setfont(int type, int size) {
	ftype = type;
	fsize = size;
	return OK;
}

/**
 * surface ˥Υʸ衣ꥢƤ256Ĵ
 * 񤭽Фsurface8ӥåȤǤɬפ
 *
 * @param sf: 褹 surface
 * @param x: ֣غɸ
 * @param y: ֣ٺɸ
 * @param buf: ʸ (SJIS)
 * @return: ºݤ褷
*/
int dt_drawtext(surface_t *sf, int x, int y, char *buf) {
	agsurface_t *glyph;
	int sx, sy, sw, sh;
	FONT *font = nact->ags.font;
	
	font->sel_font(ftype, fsize);
	
	glyph = font->get_glyph(buf);
	if (glyph == NULL) return 0;
	
	sx = x;	sy = y;
	sw = glyph->width;
	sh = glyph->height;
	if (!gr_clip_xywh(sf, &sx, &sy, &sw, &sh)) return 0;
	
	gr_copy(sf, sx, sy, glyph, 0, 0, sw, sh);
	
	return sw;
}

/**
 * surface ˥顼ʸ衣alphamap 256ĴΥꥢ줿
 * ʸpixelmap ˤϡ
 * 
 * @param sf: 褹 surface
 * @param x: ֣غɸ
 * @param y: ֣ٺɸ
 * @param buf: ʸ(SJIS)
 * @param r: ʸ
 * @param g: ʸ
 * @param b: ʸ
 * @return: ºݤ褷
 */ 
int dt_drawtext_col(surface_t *sf, int x, int y, char *buf, int r, int g, int b) {
	agsurface_t *glyph;
	int sx, sy, sw, sh;
	FONT *font = nact->ags.font;
	
	font->sel_font(ftype, fsize);
	
	glyph = font->get_glyph(buf);
	if (glyph == NULL) return 0;

	sx = x;	sy = y;
	sw = glyph->width;
	sh = glyph->height;
	if (!gr_clip_xywh(sf, &sx, &sy, &sw, &sh)) return 0;
	
	// alpha map ʸΤΤ
	gr_draw_amap(sf, sx, sy, glyph->pixel, sw, sh, glyph->bytes_per_line);
	
	// pixel map ˤϿ
	gr_fill(sf, sx, sy, sw, sh, r, g, b);
	
	return sw;
}