コード例 #1
0
ファイル: drawing.c プロジェクト: gsmadhusudan/Balsa
void DrawColorMultiLineText2 (GdkGC * gc, gdouble x, gdouble y, char *text, int alignX, int alignY, int fontsize)
{
    int fontsize2 = fontsize * zoom;
    GdkFont *font = GetFontForSize (fontsize2);

    if (!font)
        return;

    double sizeY = ((double) (font->ascent + font->descent)) / zoom;
    double sizeY0 = (gdk_text_height (font, text, strlen (text))) / zoom;
    int lineNum = 0;
    char *ptr = text;
    char *ptr2;

    do
    {
        ptr2 = strchr (ptr, '\n');
        int length = (ptr2 != NULL) ? ((int) (ptr2 - ptr)) : (int) strlen (ptr);

        DrawColorText2 (gc, x, sizeY0 + y + lineNum * sizeY, ptr, alignX, 0 /*alignY */ , length, fontsize);
        lineNum++;
        ptr = ptr2 + 1;
    }
    while (ptr2 && *ptr);
}
コード例 #2
0
ファイル: gdkfont.c プロジェクト: amery/clip-itk
/* Determines the total height of a given string. This value is not
   generally useful, because you cannot determine how this total height
   will be drawn in relation to the baseline. See gdk_text_extents(). */
int
clip_GDK_TEXTHEIGHT(ClipMachine * cm)
{
	C_object      *cfont = _fetch_co_opt(cm);
	gchar * string = _clip_parc(cm,2);
	gint     text_length = _clip_parni(cm,3);
	CHECKCOBJOPT(cfont,GDK_IS_FONT(cfont));
	CHECKARG(2,CHARACTER_t); CHECKOPT(3,NUMERIC_t);
	if (_clip_parinfo(cm,3)==UNDEF_t) text_length = strlen(string);
	LOCALE_TO_UTF(string);
	_clip_retni(cm,gdk_text_height(GDK_FONT(cfont->object), string, text_length));
	FREE_TEXT(string);
	return 0;
err:
	return 1;
}
コード例 #3
0
ファイル: drawing.c プロジェクト: gsmadhusudan/Balsa
void DrawColorText_Raw (GdkPixmap * pixmap, int fontsize, GdkGC * colorGC, gdouble x, gdouble y, char *text, int alignX, int alignY, int textLength)
{
    if (!text)
        return;

    if (textLength == -1)
        textLength = strlen (text);

    GdkFont *font = GetFontForSize (fontsize);

    if (!font)
        return;

    int sizeX = gdk_text_width (font, text, textLength);
    int sizeY = gdk_text_height (font, text, textLength);

    switch (alignX)
    {
    case 0:
        break;
    case 1:
        x -= sizeX / 2;
        break;
    case 2:
        x -= sizeX;
        break;
    }
    switch (alignY)
    {
    case 0:
        break;
    case 1:
        y += sizeY / 2;
        break;
    case 2:
        y += sizeY;
        break;
    case 2 + 1:
        y += sizeY + 1;
        break;
    }
    gdk_draw_text (pixmap, font, colorGC, x, y, text, textLength);
}
コード例 #4
0
ファイル: drawing.c プロジェクト: gsmadhusudan/Balsa
void DrawMultiLineText (gdouble x, gdouble y, char *text, int alignX, int alignY, int lineWidth, int fontsize)
{
    int fontsize2 = fontsize * zoom;
    GdkFont *font = GetFontForSize (fontsize2);

    if (!font)
        return;

    int textLength = strlen (text);
    double sizeY = ((double) (font->ascent + font->descent)) / zoom;
    double sizeY0 = (gdk_text_height (font, text, textLength)) / zoom;
    int nbLines = textLength / lineWidth;
    int remainder = textLength - nbLines * lineWidth;
    int i;

    for (i = 0; i < nbLines; i++)
        DrawColorText2 (GetColorGC (-1), x, sizeY0 + y + i * sizeY, &text[i * lineWidth], alignX, 0 /*alignY */ ,
          lineWidth, fontsize);

    DrawColorText2 (GetColorGC (-1), x, sizeY0 + y + nbLines * sizeY, &text[nbLines * lineWidth], alignX, 0 /*alignY */ ,
      remainder, fontsize);
}
コード例 #5
0
ファイル: font_gtk.c プロジェクト: avan06/ONScripter-CN
static void *font_gtk_get_glyph(unsigned char *str) {
	agsurface_t *dst;
	int h, w, l;
	BYTE *conv;
	
	GdkPixmap    *pix_gdk;
	GdkGC        *gc_gdk;
	GdkImage     *img_gdk;
	GdkColor     col_gdk;

	
	/* convert string code from sjis to euc (or LANG) */
	conv = sjis2lang(str);
	
	l = strlen(conv);
	w = gdk_text_width(fontset, conv, l);
	
	if (w == 0) {
		free(conv);
		return NULL;
	}
	
#ifdef GTKV12
	h = gdk_text_height(fontset, conv, l);
#else
	h = font_ascent + fontset->ascent;
#endif
	
	if (w > GLYPH_PIXMAP_WIDTH)  w = GLYPH_PIXMAP_WIDTH;
	if (h > GLYPH_PIXMAP_HEIGHT) h = GLYPH_PIXMAP_HEIGHT;
	
	pix_gdk = gdk_pixmap_new(mainwin->window, w, h, gdk_depth);
	gc_gdk  = gdk_gc_new(pix_gdk);

	/* color */
	col_gdk.pixel = 0;
	gdk_gc_set_foreground(gc_gdk, &col_gdk);
	// gdk_gc_set_background(gc_gdk, &col_gdk);
	gdk_draw_rectangle(pix_gdk, gc_gdk, TRUE, 0, 0, w, h);
	
	col_gdk.pixel = 1;
	gdk_gc_set_foreground(gc_gdk, &col_gdk);
	gdk_draw_text(pix_gdk, fontset, gc_gdk, 0, fontset->ascent, conv, l);
	
	gdk_gc_destroy(gc_gdk);
	img_gdk = gdk_image_get(&((GdkWindowPrivate *)pix_gdk)->window,
				0, 0, w, h);
	gdk_pixmap_unref(pix_gdk);

	dst = g_new(agsurface_t, 1);

	dst->width = w;
	dst->height = h;
	dst->bytes_per_pixel = (img_gdk->bpp+1)/8; /* むーん */
	dst->bytes_per_line  = img_gdk->bpl;
	dst->pixel            = img_gdk->mem;
	
	image_get_glyph(dst, &img_glyph);

	if (this->antialiase_on) {
		aa_make(img_glyph.pixel, w, dst->height, img_glyph.bytes_per_line);
	}
	
	img_glyph.width  = w;
	img_glyph.height = h;
	
	g_free(dst);
	g_free(conv);
	gdk_image_destroy(img_gdk);
	
	return &img_glyph;
}