root/snippet/gd_font_preview/gd_font_preview.c

Revision 87, 3.3 kB (checked in by aqua, 4 months ago)

add gd_font_preview

Line 
1#include <stdio.h>
2#include "gd.h"
3
4#define START \
5"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" \
6"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" \
7"<head>\n" \
8"\t<title>Font sample</title>\n" \
9"\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" \
10"</head>\n" \
11"\n" \
12"<body>\n" \
13"\n" \
14"<div id='container'>\n" \
15"\t<ul>\n"
16
17#define END \
18"\t</ul>\n" \
19"</body>\n" \
20"</html>\n"
21
22
23#define NAMELEN 255
24#define NAMEPATTERN "%s.png"
25
26#define MARGIN 16
27
28#define SAMPLE \
29        "다람쥐 헌 쳇바퀴에 타고파. 1234567890"
30
31int main( int argc, char** argv ){
32
33
34        gdImagePtr im;
35        FILE* out;
36
37        int rect[7][8];
38        int x, y, w, h;
39
40        int black;
41        int i, j;
42
43        char* err;
44        char filename[NAMELEN];
45        char* fc[] = {
46                "Arial Unicode MS:style=Regular",
47                "구슬:style=Regular",
48                "굴림:style=Regular",
49                "궁서:style=Regular",
50                "돋움:style=Regular",
51                "맑은 고딕:style=Bold",
52                "맑은 고딕:style=Regular",
53                "바탕:style=Regular",
54                "반달:style=Regular",
55                "방울:style=Regular",
56                "백묵 굴림:style=Regular",
57                "백묵 돋움:style=Regular",
58                "백묵 바탕:style=Regular",
59                "백묵 헤드라인:style=Regular",
60                "서울남산체:style=Light",
61                "서울남산체:style=Regular",
62                "서울남산체:style=Bold",
63                "서울남산체:style=ExtraBold",
64                "서울한강체:style=Light",
65                "서울한강체:style=Regular",
66                "아리따:style=Light",
67                "아리따:style=Regular",
68                "아리따:style=SemiBold",
69                "아리따:style=Bold",
70                "윤고딕:style=Regular",
71                "윤고딕:style=Bold",
72                "윤고딕:style=ExtraBold",
73                "윤명조:style=Regular",
74                "윤명조:style=Bold",
75                "윤명조:style=ExtraBold",
76                "윤체:style=Regular",
77                "윤체:style=Bold",
78                "윤체:style=ExtraBold",
79                "은 궁서:style=Regular",
80                "은 그래픽:style=Regular",
81                "은 그래픽:style=Bold",
82                "은 돋움:style=Regular",
83                "은 돋움:style=Bold",
84                "은 바탕:style=Regular",
85                "은진:style=Regular",
86                "은진낙서:style=Regular",
87                "한겨레결체:style=Regular",
88                NULL
89        };
90
91        double pt[7] = {
92                12.,
93                18.,
94                24.,
95                36.,
96                48.,
97                60.,
98                72.
99        };
100
101        gdFTStringExtra option;
102        option.flags = gdFTEX_DISABLE_KERNING;
103
104        gdFTUseFontConfig(1);
105
106        fprintf( stdout, "%s", START );
107
108        for( i = 0 ; fc[i] != NULL ; i++ ){
109
110                h = 0;
111                for( j = 0 ; j < 7 ; j++ ){
112                        err = gdImageStringFTEx( NULL, rect[j], 0, fc[i], pt[j], 0., 0, 0, SAMPLE, &option );
113                        if( err ){
114                                fprintf( stderr, "%s", err );
115                                goto error2;
116                        }
117                        h += rect[j][3] - rect[j][7] + MARGIN;
118                }
119                w = rect[6][2] - rect[6][6] + MARGIN;
120
121                im = gdImageCreate( w, h );
122
123                gdImageColorResolve(im, 255, 255, 255 );
124                black = gdImageColorResolve(im, 0, 0, 0 );
125
126                h = MARGIN/2;
127                for( j = 0 ; j < 7 ; j++ ){
128                        x = MARGIN/2 - rect[j][6];
129                        y = h - rect[j][7];
130                        err = gdImageStringFTEx( im , rect[j], black, fc[i], pt[j], 0., x, y, SAMPLE, &option );
131                        if( err ){
132                                fprintf( stderr, "%s", err );
133                                goto error1;
134                        }
135                        h += rect[j][3] - rect[j][7] + MARGIN;
136                }
137
138                snprintf( filename, NAMELEN-1, NAMEPATTERN, fc[i] );
139                out = fopen( filename, "wb" );
140                gdImagePng( im, out );
141                fclose(out);
142
143                fprintf( stdout, "\t<li>\n\t\t<h3>%s</h3>\n\t\t<img src='./%s' />\n\t</li>\n", fc[i], filename );
144
145error1:
146                gdImageDestroy(im);
147
148error2:
149                ;
150        }
151        fprintf( stdout, "%s", END );
152
153        return 0;
154
155}
Note: See TracBrowser for help on using the browser.