Debian Codegraph @

gdraw/gdrawtxt.c

raw symbols SCIP
1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <fontforge-config.h>
29
30 #include "fontP.h"
31 #include "gdrawP.h"
32 #include "gresource.h"
33 #include "ustring.h"
34
35 extern GResFont _ggadget_default_font;
36
37 FontInstance *GDrawSetFont(GWindow gw, FontInstance *fi) {
38 FontInstance *old = gw->ggc->fi;
39 gw->ggc->fi = fi;
40 return( old );
41 }
42
43 FontInstance *GDrawSetDefaultFont(GWindow gw) {
44 FontInstance *old = gw->ggc->fi;
45 gw->ggc->fi = _ggadget_default_font.fi;
46 return old;
47 }
48
49 FontInstance *GDrawInstanciateFont(GWindow gw, FontRequest *rq) {
50 GDisplay *gdisp;
51 FState *fs;
52 struct font_instance *fi;
53
54 if (gw == NULL)
55 gw = GDrawGetRoot(NULL);
56
57 gdisp = gw->display;
58 fs = gdisp->fontstate;
59
60 if ( rq->point_size<0 ) /* It's in pixels, not points, convert to points */
61 rq->point_size = PixelToPoint(-rq->point_size,fs->res);
62
63 fi = calloc(1,sizeof(struct font_instance));
64 fi->rq = *rq;
65 fi->rq.utf8_family_name = copy( fi->rq.utf8_family_name );
66
67 return( fi );
68 }
69
70 FontInstance *GDrawAttachFont(GWindow gw, FontRequest *rq) {
71 struct font_instance *fi = GDrawInstanciateFont(gw,rq);
72
73 if ( fi!=NULL )
74 GDrawSetFont(gw, fi);
75 return( fi );
76 }
77
78 FontRequest *GDrawDecomposeFont(FontInstance *fi, FontRequest *rq) {
79 *rq = fi->rq;
80 return( rq );
81 }
82
83 /* ************************************************************************** */
84
85 int32_t GDrawDrawText(GWindow gw, int32_t x, int32_t y, const unichar_t *text, int32_t cnt, Color col) {
86 struct tf_arg arg;
87 glong realcnt;
88 gchar *temp = g_ucs4_to_utf8((gunichar*)text, cnt, NULL, &realcnt, NULL);
89 int width = 0;
90
91 if (temp != NULL) {
92 width = gw->display->funcs->doText8(gw,x,y,temp,realcnt,col,tf_drawit,&arg);
93 g_free(temp);
94 }
95
96 return width;
97 }
98
99 int32_t GDrawGetTextWidth(GWindow gw,const unichar_t *text, int32_t cnt) {
100 struct tf_arg arg;
101 glong realcnt;
102 gchar *temp = g_ucs4_to_utf8((gunichar*)text, cnt, NULL, &realcnt, NULL);
103 int width = 0;
104
105 if (temp != NULL) {
106 width = gw->display->funcs->doText8(gw,0,0,temp,realcnt,0x0,tf_width,&arg);
107 g_free(temp);
108 }
109 return width;
110 }
111
112 int32_t GDrawGetTextBounds(GWindow gw,const unichar_t *text, int32_t cnt, GTextBounds *bounds) {
113 int ret = 0;
114 struct tf_arg arg = {0};
115 glong realcnt;
116 gchar *temp = g_ucs4_to_utf8((gunichar*)text, cnt, NULL, &realcnt, NULL);
117
118 if (temp != NULL) {
119 arg.first = true;
120 ret = gw->display->funcs->doText8(gw,0,0,temp,realcnt,0x0,tf_rect,&arg);
121 *bounds = arg.size;
122 g_free(temp);
123 }
124 return ret;
125 }
126
127 /* UTF8 routines */
128
129 int32_t GDrawDrawText8(GWindow gw, int32_t x, int32_t y, const char *text, int32_t cnt, Color col) {
130 struct tf_arg arg;
131
132 return( gw->display->funcs->doText8(gw,x,y,text,cnt,col,tf_drawit,&arg));
133 }
134
135 int32_t GDrawGetText8Width(GWindow gw, const char *text, int32_t cnt) {
136 struct tf_arg arg;
137
138 return( gw->display->funcs->doText8(gw,0,0,text,cnt,0x0,tf_width,&arg));
139 }
140
141 int32_t GDrawGetText8Height(GWindow gw, const char *text, int32_t cnt)
142 {
143 GTextBounds bounds;
144 int32_t ret = GDrawGetText8Bounds( gw, text, cnt, &bounds );
145 ret = bounds.as + bounds.ds;
146 return ret;
147 }
148
149
150 int32_t GDrawGetText8Bounds(GWindow gw,const char *text, int32_t cnt, GTextBounds *bounds) {
151 int ret;
152 struct tf_arg arg;
153
154 memset(&arg,'\0',sizeof(arg));
155 arg.first = true;
156 ret = gw->display->funcs->doText8(gw,0,0,text,cnt,0x0,tf_rect,&arg);
157 *bounds = arg.size;
158 return( ret );
159 }
160
161 /* End UTF8 routines */