Make the empty line height 1/2 of the font size to cram more stuff into

* libnautilus-extensions/nautilus-icon-factory.c: (embed_text):
	Make the empty line height 1/2 of the font size to cram more stuff
	into the embedded text.

	* libnautilus-extensions/nautilus-label.c:
	(nautilus_label_size_request), (render_buffer_pixbuf),
	(label_get_empty_line_height),
	(label_get_total_text_and_line_offset_height),
	(label_recompute_line_geometries):
	Update for scalable font changes.

	* libnautilus-extensions/nautilus-scalable-font.c:
	(nautilus_scalable_font_measure_text_lines),
	(nautilus_scalable_font_draw_text_lines_with_dimensions),
	(nautilus_scalable_font_draw_text_lines):
	* libnautilus-extensions/nautilus-scalable-font.h:
	Add empty_line_height argument to text line measuring and drawing
	functions.  Use this in both measure and drawing computations.

	* test/test-nautilus-font.c: (gdk_pixbuf_draw_rectangle),
	(draw_rectangle_around), (main):
	Update for scalable font changes.  Also draw a box around area
	that is being clipped (or measured) to determine whether things
	work precisely.
This commit is contained in:
Ramiro Estrugo 2000-09-07 07:49:52 +00:00
parent 6896aa7ca3
commit e38dfd4fc3
10 changed files with 327 additions and 98 deletions

View file

@ -1,3 +1,30 @@
2000-09-07 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-icon-factory.c: (embed_text):
Make the empty line height 1/2 of the font size to cram more stuff
into the embedded text.
* libnautilus-extensions/nautilus-label.c:
(nautilus_label_size_request), (render_buffer_pixbuf),
(label_get_empty_line_height),
(label_get_total_text_and_line_offset_height),
(label_recompute_line_geometries):
Update for scalable font changes.
* libnautilus-extensions/nautilus-scalable-font.c:
(nautilus_scalable_font_measure_text_lines),
(nautilus_scalable_font_draw_text_lines_with_dimensions),
(nautilus_scalable_font_draw_text_lines):
* libnautilus-extensions/nautilus-scalable-font.h:
Add empty_line_height argument to text line measuring and drawing
functions. Use this in both measure and drawing computations.
* test/test-nautilus-font.c: (gdk_pixbuf_draw_rectangle),
(draw_rectangle_around), (main):
Update for scalable font changes. Also draw a box around area
that is being clipped (or measured) to determine whether things
work precisely.
2000-09-07 Eskil Heyn Olsen <eskil@eazel.com>
* components/services/install/command-line/eazel-alt-install-corba.

View file

@ -2232,7 +2232,9 @@ embed_text (GdkPixbuf *pixbuf_without_text,
GdkPixbuf *pixbuf_with_text = NULL;
NautilusScalableFont *font;
const guint font_size = 9;
const guint line_offset = 1;
const guint empty_line_height = font_size / 2;
/* Quick out for the case where there's no place to embed the
* text or the place is too small or there's no text.
*/
@ -2256,7 +2258,8 @@ embed_text (GdkPixbuf *pixbuf_without_text,
font_size,
text,
GTK_JUSTIFY_LEFT,
1,
line_offset,
empty_line_height,
NAUTILUS_RGB_COLOR_BLACK,
255);

View file

@ -69,28 +69,29 @@ struct _NautilusLabelDetail
};
/* GtkObjectClass methods */
static void nautilus_label_initialize_class (NautilusLabelClass *label_class);
static void nautilus_label_initialize (NautilusLabel *label);
static void nautilus_label_destroy (GtkObject *object);
static void nautilus_label_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_label_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_label_initialize_class (NautilusLabelClass *label_class);
static void nautilus_label_initialize (NautilusLabel *label);
static void nautilus_label_destroy (GtkObject *object);
static void nautilus_label_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_label_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
/* GtkWidgetClass methods */
static void nautilus_label_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void nautilus_label_size_request (GtkWidget *widget,
GtkRequisition *requisition);
/* NautilusBufferedWidgetClass methods */
static void render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
GdkPixbuf *buffer,
int horizontal_offset,
int vertical_offset);
static void render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
GdkPixbuf *buffer,
int horizontal_offset,
int vertical_offset);
/* Private NautilusLabel things */
static void label_recompute_line_geometries (NautilusLabel *label);
static void label_recompute_line_geometries (NautilusLabel *label);
static guint label_get_empty_line_height (NautilusLabel *label);
static guint label_get_total_text_and_line_offset_height (NautilusLabel *label);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusLabel, nautilus_label, NAUTILUS_TYPE_BUFFERED_WIDGET)
@ -283,9 +284,7 @@ nautilus_label_size_request (GtkWidget *widget,
if (label->detail->num_text_lines > 0) {
text_width = label->detail->max_text_line_width;
text_height = label->detail->total_text_line_height;
text_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
text_height = label_get_total_text_and_line_offset_height (label);
text_width += label->detail->drop_shadow_offset;
text_height += label->detail->drop_shadow_offset;
@ -298,7 +297,7 @@ nautilus_label_size_request (GtkWidget *widget,
requisition->height += misc->ypad * 2;
}
/* Private NautilusLabel things */
/* NautilusBufferedWidgetClass methods */
static void
render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
GdkPixbuf *buffer,
@ -308,11 +307,8 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
NautilusLabel *label;
GtkWidget *widget;
ArtIRect clip_area;
guint total_text_width;
guint total_text_height;
int text_x;
int text_y;
g_return_if_fail (NAUTILUS_IS_LABEL (buffered_widget));
g_return_if_fail (buffer != NULL);
@ -325,23 +321,18 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
widget = GTK_WIDGET (buffered_widget);
total_text_width = label->detail->max_text_line_width;
total_text_height = label->detail->total_text_line_height;
total_text_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
if (total_text_width <= widget->allocation.width) {
clip_area.x0 = ((int) widget->allocation.width - (int) total_text_width) / 2;
if (label->detail->max_text_line_width <= widget->allocation.width) {
clip_area.x0 = ((int) widget->allocation.width - (int) label->detail->max_text_line_width) / 2;
}
else {
clip_area.x0 = - ((int) total_text_width - (int) widget->allocation.width) / 2;
clip_area.x0 = - ((int) label->detail->max_text_line_width - (int) widget->allocation.width) / 2;
}
if (total_text_height <= widget->allocation.height) {
clip_area.y0 = ((int) widget->allocation.height - (int) total_text_height) / 2;
if (label->detail->total_text_line_height <= widget->allocation.height) {
clip_area.y0 = ((int) widget->allocation.height - (int) label->detail->total_text_line_height) / 2;
}
else {
clip_area.y0 = - ((int) total_text_height - (int) widget->allocation.height) / 2;
clip_area.y0 = - ((int) label->detail->total_text_line_height - (int) widget->allocation.height) / 2;
}
clip_area.x0 = 0;
@ -370,6 +361,7 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
label->detail->text_line_heights,
label->detail->text_justification,
label->detail->line_offset,
label_get_empty_line_height (label),
label->detail->drop_shadow_color,
label->detail->text_alpha);
@ -390,12 +382,39 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
label->detail->text_line_heights,
label->detail->text_justification,
label->detail->line_offset,
label_get_empty_line_height (label),
label->detail->text_color,
label->detail->text_alpha);
}
}
/* Private NautilusLabel things */
static guint
label_get_empty_line_height (NautilusLabel *label)
{
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
/* If we wanted to crunch lines together, we could add a multiplier
* here. For now we just use the font size for empty lines. */
return label->detail->font_size;
}
static guint
label_get_total_text_and_line_offset_height (NautilusLabel *label)
{
guint total_height;
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
total_height = label->detail->total_text_line_height;
if (label->detail->num_text_lines > 1) {
total_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
}
return total_height;
}
static void
label_recompute_line_geometries (NautilusLabel *label)
{
@ -422,6 +441,7 @@ label_recompute_line_geometries (NautilusLabel *label)
label->detail->font_size,
label->detail->text,
label->detail->num_text_lines,
label_get_empty_line_height (label),
label->detail->text_line_widths,
label->detail->text_line_heights,
&label->detail->max_text_line_width,

View file

@ -801,6 +801,7 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
guint font_height,
const char *text,
guint num_text_lines,
double empty_line_height,
guint text_line_widths[],
guint text_line_heights[],
guint *max_width_out,
@ -851,7 +852,7 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
/* Deal with empty lines */
if (length == 0) {
text_line_widths[i] = 0;
text_line_heights[i] = font_height;
text_line_heights[i] = empty_line_height;
}
else {
nautilus_scalable_font_measure_text (font,
@ -896,6 +897,7 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo
const guint *text_line_heights,
GtkJustification justification,
guint line_offset,
double empty_line_height,
guint32 color,
guchar overall_alpha)
{
@ -948,7 +950,7 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo
/* Deal with empty lines */
if (length == 0) {
y += font_height;
y += (line_offset + text_line_heights[i]);
}
else {
int text_x;
@ -1015,6 +1017,7 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
const char *text,
GtkJustification justification,
guint line_offset,
double empty_line_height,
guint32 color,
guchar overall_alpha)
{
@ -1049,6 +1052,7 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
font_height,
text,
num_text_lines,
empty_line_height,
text_line_widths,
text_line_heights,
NULL,
@ -1067,6 +1071,7 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
text_line_heights,
justification,
line_offset,
empty_line_height,
color,
overall_alpha);

View file

@ -105,6 +105,7 @@ void nautilus_scalable_font_measure_text_lines (c
guint font_height,
const char *text,
guint num_text_lines,
double empty_line_height,
guint text_line_widths[],
guint text_line_heights[],
guint *max_width_out,
@ -122,6 +123,7 @@ void nautilus_scalable_font_draw_text_lines_with_dimensions (c
const guint *text_line_heights,
GtkJustification justification,
guint line_offset,
double empty_line_height,
guint32 color,
guchar overall_alpha);
void nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
@ -134,6 +136,7 @@ void nautilus_scalable_font_draw_text_lines (c
const char *text,
GtkJustification justification,
guint line_offset,
double empty_line_height,
guint32 color,
guchar overall_alpha);
guint nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,

View file

@ -2232,7 +2232,9 @@ embed_text (GdkPixbuf *pixbuf_without_text,
GdkPixbuf *pixbuf_with_text = NULL;
NautilusScalableFont *font;
const guint font_size = 9;
const guint line_offset = 1;
const guint empty_line_height = font_size / 2;
/* Quick out for the case where there's no place to embed the
* text or the place is too small or there's no text.
*/
@ -2256,7 +2258,8 @@ embed_text (GdkPixbuf *pixbuf_without_text,
font_size,
text,
GTK_JUSTIFY_LEFT,
1,
line_offset,
empty_line_height,
NAUTILUS_RGB_COLOR_BLACK,
255);

View file

@ -69,28 +69,29 @@ struct _NautilusLabelDetail
};
/* GtkObjectClass methods */
static void nautilus_label_initialize_class (NautilusLabelClass *label_class);
static void nautilus_label_initialize (NautilusLabel *label);
static void nautilus_label_destroy (GtkObject *object);
static void nautilus_label_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_label_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_label_initialize_class (NautilusLabelClass *label_class);
static void nautilus_label_initialize (NautilusLabel *label);
static void nautilus_label_destroy (GtkObject *object);
static void nautilus_label_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_label_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
/* GtkWidgetClass methods */
static void nautilus_label_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void nautilus_label_size_request (GtkWidget *widget,
GtkRequisition *requisition);
/* NautilusBufferedWidgetClass methods */
static void render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
GdkPixbuf *buffer,
int horizontal_offset,
int vertical_offset);
static void render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
GdkPixbuf *buffer,
int horizontal_offset,
int vertical_offset);
/* Private NautilusLabel things */
static void label_recompute_line_geometries (NautilusLabel *label);
static void label_recompute_line_geometries (NautilusLabel *label);
static guint label_get_empty_line_height (NautilusLabel *label);
static guint label_get_total_text_and_line_offset_height (NautilusLabel *label);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusLabel, nautilus_label, NAUTILUS_TYPE_BUFFERED_WIDGET)
@ -283,9 +284,7 @@ nautilus_label_size_request (GtkWidget *widget,
if (label->detail->num_text_lines > 0) {
text_width = label->detail->max_text_line_width;
text_height = label->detail->total_text_line_height;
text_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
text_height = label_get_total_text_and_line_offset_height (label);
text_width += label->detail->drop_shadow_offset;
text_height += label->detail->drop_shadow_offset;
@ -298,7 +297,7 @@ nautilus_label_size_request (GtkWidget *widget,
requisition->height += misc->ypad * 2;
}
/* Private NautilusLabel things */
/* NautilusBufferedWidgetClass methods */
static void
render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
GdkPixbuf *buffer,
@ -308,11 +307,8 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
NautilusLabel *label;
GtkWidget *widget;
ArtIRect clip_area;
guint total_text_width;
guint total_text_height;
int text_x;
int text_y;
g_return_if_fail (NAUTILUS_IS_LABEL (buffered_widget));
g_return_if_fail (buffer != NULL);
@ -325,23 +321,18 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
widget = GTK_WIDGET (buffered_widget);
total_text_width = label->detail->max_text_line_width;
total_text_height = label->detail->total_text_line_height;
total_text_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
if (total_text_width <= widget->allocation.width) {
clip_area.x0 = ((int) widget->allocation.width - (int) total_text_width) / 2;
if (label->detail->max_text_line_width <= widget->allocation.width) {
clip_area.x0 = ((int) widget->allocation.width - (int) label->detail->max_text_line_width) / 2;
}
else {
clip_area.x0 = - ((int) total_text_width - (int) widget->allocation.width) / 2;
clip_area.x0 = - ((int) label->detail->max_text_line_width - (int) widget->allocation.width) / 2;
}
if (total_text_height <= widget->allocation.height) {
clip_area.y0 = ((int) widget->allocation.height - (int) total_text_height) / 2;
if (label->detail->total_text_line_height <= widget->allocation.height) {
clip_area.y0 = ((int) widget->allocation.height - (int) label->detail->total_text_line_height) / 2;
}
else {
clip_area.y0 = - ((int) total_text_height - (int) widget->allocation.height) / 2;
clip_area.y0 = - ((int) label->detail->total_text_line_height - (int) widget->allocation.height) / 2;
}
clip_area.x0 = 0;
@ -370,6 +361,7 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
label->detail->text_line_heights,
label->detail->text_justification,
label->detail->line_offset,
label_get_empty_line_height (label),
label->detail->drop_shadow_color,
label->detail->text_alpha);
@ -390,12 +382,39 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
label->detail->text_line_heights,
label->detail->text_justification,
label->detail->line_offset,
label_get_empty_line_height (label),
label->detail->text_color,
label->detail->text_alpha);
}
}
/* Private NautilusLabel things */
static guint
label_get_empty_line_height (NautilusLabel *label)
{
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
/* If we wanted to crunch lines together, we could add a multiplier
* here. For now we just use the font size for empty lines. */
return label->detail->font_size;
}
static guint
label_get_total_text_and_line_offset_height (NautilusLabel *label)
{
guint total_height;
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
total_height = label->detail->total_text_line_height;
if (label->detail->num_text_lines > 1) {
total_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
}
return total_height;
}
static void
label_recompute_line_geometries (NautilusLabel *label)
{
@ -422,6 +441,7 @@ label_recompute_line_geometries (NautilusLabel *label)
label->detail->font_size,
label->detail->text,
label->detail->num_text_lines,
label_get_empty_line_height (label),
label->detail->text_line_widths,
label->detail->text_line_heights,
&label->detail->max_text_line_width,

View file

@ -801,6 +801,7 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
guint font_height,
const char *text,
guint num_text_lines,
double empty_line_height,
guint text_line_widths[],
guint text_line_heights[],
guint *max_width_out,
@ -851,7 +852,7 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
/* Deal with empty lines */
if (length == 0) {
text_line_widths[i] = 0;
text_line_heights[i] = font_height;
text_line_heights[i] = empty_line_height;
}
else {
nautilus_scalable_font_measure_text (font,
@ -896,6 +897,7 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo
const guint *text_line_heights,
GtkJustification justification,
guint line_offset,
double empty_line_height,
guint32 color,
guchar overall_alpha)
{
@ -948,7 +950,7 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo
/* Deal with empty lines */
if (length == 0) {
y += font_height;
y += (line_offset + text_line_heights[i]);
}
else {
int text_x;
@ -1015,6 +1017,7 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
const char *text,
GtkJustification justification,
guint line_offset,
double empty_line_height,
guint32 color,
guchar overall_alpha)
{
@ -1049,6 +1052,7 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
font_height,
text,
num_text_lines,
empty_line_height,
text_line_widths,
text_line_heights,
NULL,
@ -1067,6 +1071,7 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
text_line_heights,
justification,
line_offset,
empty_line_height,
color,
overall_alpha);

View file

@ -105,6 +105,7 @@ void nautilus_scalable_font_measure_text_lines (c
guint font_height,
const char *text,
guint num_text_lines,
double empty_line_height,
guint text_line_widths[],
guint text_line_heights[],
guint *max_width_out,
@ -122,6 +123,7 @@ void nautilus_scalable_font_draw_text_lines_with_dimensions (c
const guint *text_line_heights,
GtkJustification justification,
guint line_offset,
double empty_line_height,
guint32 color,
guchar overall_alpha);
void nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
@ -134,6 +136,7 @@ void nautilus_scalable_font_draw_text_lines (c
const char *text,
GtkJustification justification,
guint line_offset,
double empty_line_height,
guint32 color,
guchar overall_alpha);
guint nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,

View file

@ -20,22 +20,143 @@
#include <libnautilus-extensions/nautilus-image.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libart_lgpl/art_vpath.h>
#include <libart_lgpl/art_svp.h>
#include <libart_lgpl/art_svp_vpath_stroke.h>
#include <libart_lgpl/art_rgb_svp.h>
#include <libart_lgpl/art_svp_vpath.h>
/* FIXME: Need to account for word endianess in these macros */
#define ART_OPACITY_NONE 255
#define ART_OPACITY_FULL 0
/* Pack RGBA values */
#define ART_RGBA_COLOR_PACK(_r, _g, _b, _a) \
( ((_a) << 0) | \
((_r) << 24) | \
((_g) << 16) | \
((_b) << 8) )
#define ART_RGB_COLOR_PACK(_r, _g, _b) \
( (ART_OPACITY_NONE << 0) | \
((_r) << 24) | \
((_g) << 16) | \
((_b) << 8) )
/* Access the individual RGBA components */
#define ART_RGBA_GET_R(_color) (((_color) >> 24) & 0xff)
#define ART_RGBA_GET_G(_color) (((_color) >> 16) & 0xff)
#define ART_RGBA_GET_B(_color) (((_color) >> 8) & 0xff)
#define ART_RGBA_GET_A(_color) (((_color) >> 0) & 0xff)
#define RED ART_RGB_COLOR_PACK (255, 0, 0)
#define GREEN ART_RGB_COLOR_PACK (0, 255, 0)
#define BLUE ART_RGB_COLOR_PACK (0, 0, 255)
#define WHITE ART_RGB_COLOR_PACK (255, 255, 255)
#define BLACK ART_RGB_COLOR_PACK (0, 0, 0)
#define TRANSPARENT ART_RGB_COLOR_PACK (255, 255, 255)
static void
gdk_pixbuf_draw_rectangle (GdkPixbuf *pixbuf,
const ArtIRect *rectangle,
guint32 color)
{
ArtVpath vpath[6];
ArtSVP *svp;
g_return_if_fail (pixbuf != NULL);
g_return_if_fail (rectangle != NULL);
g_return_if_fail (rectangle->x1 > rectangle->x0);
g_return_if_fail (rectangle->y1 > rectangle->y0);
vpath[0].code = ART_MOVETO;
vpath[0].x = rectangle->x0;
vpath[0].y = rectangle->y0;
vpath[1].code = ART_LINETO;
vpath[1].x = rectangle->x1;
vpath[1].y = rectangle->y0;
vpath[2].code = ART_LINETO;
vpath[2].x = rectangle->x1;
vpath[2].y = rectangle->y1;
vpath[3].code = ART_LINETO;
vpath[3].x = rectangle->x0;
vpath[3].y = rectangle->y1;
vpath[4].code = ART_LINETO;
vpath[4].x = rectangle->x0;
vpath[4].y = rectangle->y0;
vpath[5].code = ART_END;
svp = art_svp_vpath_stroke (vpath,
ART_PATH_STROKE_JOIN_BEVEL,
ART_PATH_STROKE_CAP_SQUARE,
1.0,
1.0,
1.0);
art_rgb_svp_alpha (svp,
0,
0,
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
color,
gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_rowstride (pixbuf),
NULL);
art_svp_free (svp);
}
static void
draw_rectangle_around (GdkPixbuf *pixbuf,
const ArtIRect *rectangle,
guint32 color)
{
ArtIRect area;
g_return_if_fail (pixbuf != NULL);
g_return_if_fail (rectangle != NULL);
g_return_if_fail (rectangle->x1 > rectangle->x0);
g_return_if_fail (rectangle->y1 > rectangle->y0);
area = *rectangle;
area.x0 -= 1;
area.y0 -= 1;
area.x1 += 1;
area.y1 += 1;
gdk_pixbuf_draw_rectangle (pixbuf, &area, color);
area.x0 += 1;
area.y0 += 1;
area.x1 -= 1;
area.y1 -= 1;
}
int
main (int argc, char* argv[])
{
GdkPixbuf *pixbuf;
NautilusScalableFont *font;
GdkRectangle blue_area;
ArtIRect clip_area;
ArtIRect whole_area;
ArtIRect multi_lines_area;
const char *text = "\nLine Two\n\nLine Four\n\n\nLine Seven\n";
const guint font_width = 48;
const guint font_height = 48;
const char *text = "\nLine Two\n\nLine Four\n\n\nLine Seven";
const guint font_width = 48;
const guint font_height = 48;
const guint pixbuf_width = 500;
const guint pixbuf_height = 700;
const guint line_offset = 2;
const guint empty_line_height = font_height;
const int multi_line_x = 10;
const int multi_line_y = 10;
const guint pixbuf_width = 500;
const guint pixbuf_height = 700;
GdkRectangle blue_area;
ArtIRect clip_area;
ArtIRect whole_area;
g_print ("font_height = %d, empty_line_height = %d\n", font_height, empty_line_height);
gtk_init (&argc, &argv);
gdk_rgb_init ();
@ -43,10 +164,13 @@ main (int argc, char* argv[])
font = NAUTILUS_SCALABLE_FONT (nautilus_scalable_font_new ("Nimbus Sans L", NULL, NULL, NULL));
g_assert (font != NULL);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, pixbuf_width, pixbuf_height);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, pixbuf_width, pixbuf_height);
g_assert (pixbuf != NULL);
nautilus_gdk_pixbuf_fill_rectangle_with_color (pixbuf, NULL, NAUTILUS_RGBA_COLOR_PACK (255, 255, 255, 0));
nautilus_gdk_pixbuf_fill_rectangle_with_color (pixbuf, NULL, TRANSPARENT);
multi_lines_area.x0 = multi_line_x;
multi_lines_area.y0 = multi_line_y;
/* Measure some text lines */
{
@ -66,15 +190,20 @@ main (int argc, char* argv[])
font_height,
text,
num_text_lines,
empty_line_height,
text_line_widths,
text_line_heights,
&max_width_out,
&total_height_out);
multi_lines_area.x1 = multi_lines_area.x0 + max_width_out;
multi_lines_area.y1 = multi_lines_area.y0 + total_height_out + ((num_text_lines - 1) * line_offset);
g_print ("num_text_lines = %d, max_width = %d, total_height = %d\n",
num_text_lines,
max_width_out,
total_height_out);
g_free (text_line_widths);
g_free (text_line_heights);
@ -85,30 +214,33 @@ main (int argc, char* argv[])
blue_area.width = 100;
blue_area.height = 30;
nautilus_gdk_pixbuf_fill_rectangle_with_color (pixbuf, &blue_area, NAUTILUS_RGBA_COLOR_PACK (0, 0, 255, 255));
clip_area.x0 = blue_area.x;
clip_area.y0 = blue_area.y;
clip_area.x1 = blue_area.x + blue_area.width;
clip_area.y1 = blue_area.y + blue_area.height;
draw_rectangle_around (pixbuf, &clip_area, RED);
whole_area.x0 = 0;
whole_area.y0 = 0;
whole_area.x1 = whole_area.x0 + pixbuf_width;
whole_area.y1 = whole_area.y0 + pixbuf_height;
draw_rectangle_around (pixbuf, &multi_lines_area, RED);
/* Draw some green text clipped by the whole pixbuf area */
nautilus_scalable_font_draw_text_lines (font,
pixbuf,
0,
0,
multi_line_x,
multi_line_y,
&whole_area,
font_width,
font_height,
text,
GTK_JUSTIFY_LEFT,
2,
NAUTILUS_RGBA_COLOR_PACK (0, 255, 0, 255),
line_offset,
empty_line_height,
BLUE,
255);
/* Draw some red text clipped by the blue area */
@ -121,7 +253,7 @@ main (int argc, char* argv[])
font_height,
"Something",
strlen ("Something"),
NAUTILUS_RGBA_COLOR_PACK (255, 0, 0, 255),
GREEN,
255);
nautilus_gdk_pixbuf_save_to_file (pixbuf, "font_test.png");
@ -132,3 +264,11 @@ main (int argc, char* argv[])
return 0;
}
#if 0
icon_text_info = nautilus_icon_layout_text (details->smooth_font,
details->smooth_font_size,
text_piece, _(" -_,;.?/&"),
max_text_width,
TRUE);
#endif