summaryrefslogtreecommitdiff
path: root/test/test-nautilus-smooth-text-layout.c
blob: 8fdde2c6a9562f815dceaa9e3ecbc1091f43fb9c (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

#include <config.h>

#include "test.h"

#include <libnautilus-extensions/nautilus-glyph.h>
#include <libnautilus-extensions/nautilus-smooth-text-layout.h>

int 
main (int argc, char* argv[])
{
	const guint pixbuf_width = 640;
	const guint pixbuf_height = 480;
	const gboolean has_alpha = TRUE;
	const char *text = NULL;
	const int font_size = 25;

	GdkPixbuf *pixbuf;
	NautilusScalableFont *font;
	NautilusScalableFont *bold_font;
	NautilusSmoothTextLayout *smooth_text_layout;
	ArtIRect dest;


	test_init (&argc, &argv);

	font = nautilus_scalable_font_get_default_font ();
	g_assert (font != NULL);

	bold_font = nautilus_scalable_font_make_bold (font);
	g_assert (bold_font != NULL);

	pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, 8, pixbuf_width, pixbuf_height);
	g_assert (pixbuf != NULL);

	test_pixbuf_draw_rectangle_tiled (pixbuf, 
					  "patterns/brushed_metal.png",
					  -1, -1, -1, -1,
					  NAUTILUS_OPACITY_FULLY_OPAQUE);
	
	{
		const int border = 50;
		dest = nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, NULL);
		dest.x0 += border;
		dest.y0 += border;
		dest.x1 = 340;
		dest.y1 -= border;
	}
	nautilus_debug_pixbuf_draw_rectangle_inset (pixbuf,
						    FALSE,
						    dest.x0,
						    dest.y0,
						    dest.x1,
						    dest.y1,
						    0x00FFFF,
						    0xFF,
						    -1);
	
	text = "This\nis\nmulti\nline\ntext";
	smooth_text_layout = nautilus_smooth_text_layout_new (text,
							      strlen (text),
							      font,
							      font_size,
							      FALSE);
	nautilus_smooth_text_layout_draw_to_pixbuf (smooth_text_layout,
						    pixbuf,
						    0,
						    0,
						    &dest,
						    GTK_JUSTIFY_LEFT,
						    FALSE,
						    0xFF0000,
						    0xff);
	gtk_object_unref (GTK_OBJECT (smooth_text_layout));

	{
		const int border = 50;
		dest = nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, NULL);
		dest.x0 += 350;
		dest.y0 += border;
		dest.x1 -= border;
		dest.y1 -= border;
	}
	nautilus_debug_pixbuf_draw_rectangle_inset (pixbuf,
						    FALSE,
						    dest.x0,
						    dest.y0,
						    dest.x1,
						    dest.y1,
						    0xFFFF00,
						    0xFF,
						    -1);

	text = "This is text that needs t be wrapped to fit and stuff and foo and bar and more stuff.";
	smooth_text_layout = nautilus_smooth_text_layout_new (text,
							      strlen (text),
							      font,
							      font_size,
							      TRUE);
 	nautilus_smooth_text_layout_set_line_wrap_width (smooth_text_layout,
 							 nautilus_art_irect_get_width (&dest));
	nautilus_smooth_text_layout_draw_to_pixbuf (smooth_text_layout,
						    pixbuf,
						    0,
						    0,
						    &dest,
						    GTK_JUSTIFY_CENTER,
						    FALSE,
						    0x00FF00,
						    0xff);
	dest.y0 += nautilus_smooth_text_layout_get_height (smooth_text_layout) + 10;
	dest.y1 += nautilus_smooth_text_layout_get_height (smooth_text_layout) + 10;
	gtk_object_unref (GTK_OBJECT (smooth_text_layout));

	smooth_text_layout = nautilus_smooth_text_layout_new (text,
							      strlen (text),
							      bold_font,
							      font_size * 1.5,
							      TRUE);
 	nautilus_smooth_text_layout_set_line_wrap_width (smooth_text_layout,
 							 nautilus_art_irect_get_width (&dest) + 2);
	
	if (1) nautilus_smooth_text_layout_draw_to_pixbuf (smooth_text_layout,
							   pixbuf,
							   1,
							   1,
							   &dest,
							   GTK_JUSTIFY_CENTER,
							   TRUE,
						    0x00FF00,
						    0xff);
	gtk_object_unref (GTK_OBJECT (smooth_text_layout));

	nautilus_debug_show_pixbuf_in_eog (pixbuf);
	
	gdk_pixbuf_unref (pixbuf);
	gtk_object_unref (GTK_OBJECT (font));
	gtk_object_unref (GTK_OBJECT (bold_font));
	test_quit (0);

	return 0;
}