| 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 |
#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 ) |
| 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 |
|
| 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 |
|