mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-08-25 02:36:07 +00:00
Simpify the text line drawing function to not reuqire passing in the
* libnautilus-extensions/nautilus-label.c: (render_buffer_pixbuf): * libnautilus-extensions/nautilus-scalable-font.c: (nautilus_scalable_font_draw_text_lines_with_dimensions), (nautilus_scalable_font_draw_text_lines): * libnautilus-extensions/nautilus-scalable-font.h: Simpify the text line drawing function to not reuqire passing in the number of lines or their dimensions. Compute these when needed. An alternate function that accepts the dimensions is available as well. * test/test-nautilus-font.c: (main): Draw both text lines and single line clipped text to test more stuff.
This commit is contained in:
parent
486c860ac9
commit
e5b8f54863
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
2000-09-05 Ramiro Estrugo <ramiro@eazel.com>
|
||||
|
||||
* libnautilus-extensions/nautilus-label.c: (render_buffer_pixbuf):
|
||||
* libnautilus-extensions/nautilus-scalable-font.c:
|
||||
(nautilus_scalable_font_draw_text_lines_with_dimensions),
|
||||
(nautilus_scalable_font_draw_text_lines):
|
||||
* libnautilus-extensions/nautilus-scalable-font.h:
|
||||
Simpify the text line drawing function to not reuqire passing in
|
||||
the number of lines or their dimensions. Compute these when
|
||||
needed. An alternate function that accepts the dimensions is
|
||||
available as well.
|
||||
|
||||
* test/test-nautilus-font.c: (main):
|
||||
Draw both text lines and single line clipped text to test more
|
||||
stuff.
|
||||
|
||||
2000-09-05 Ramiro Estrugo <ramiro@eazel.com>
|
||||
|
||||
Complete task 1733 - need mozilla component support for grokking
|
||||
|
|
|
@ -357,41 +357,41 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
|
|||
if (label->detail->drop_shadow_offset > 0) {
|
||||
text_x += label->detail->drop_shadow_offset;
|
||||
text_y += label->detail->drop_shadow_offset;
|
||||
nautilus_scalable_font_draw_text_lines (label->detail->font,
|
||||
buffer,
|
||||
text_x,
|
||||
text_y,
|
||||
&clip_area,
|
||||
label->detail->font_size,
|
||||
label->detail->font_size,
|
||||
label->detail->text,
|
||||
label->detail->num_text_lines,
|
||||
label->detail->text_line_widths,
|
||||
label->detail->text_line_heights,
|
||||
label->detail->text_justification,
|
||||
label->detail->line_offset,
|
||||
label->detail->drop_shadow_color,
|
||||
label->detail->text_alpha);
|
||||
nautilus_scalable_font_draw_text_lines_with_dimensions (label->detail->font,
|
||||
buffer,
|
||||
text_x,
|
||||
text_y,
|
||||
&clip_area,
|
||||
label->detail->font_size,
|
||||
label->detail->font_size,
|
||||
label->detail->text,
|
||||
label->detail->num_text_lines,
|
||||
label->detail->text_line_widths,
|
||||
label->detail->text_line_heights,
|
||||
label->detail->text_justification,
|
||||
label->detail->line_offset,
|
||||
label->detail->drop_shadow_color,
|
||||
label->detail->text_alpha);
|
||||
|
||||
text_x -= label->detail->drop_shadow_offset;
|
||||
text_y -= label->detail->drop_shadow_offset;
|
||||
}
|
||||
|
||||
nautilus_scalable_font_draw_text_lines (label->detail->font,
|
||||
buffer,
|
||||
text_x,
|
||||
text_y,
|
||||
&clip_area,
|
||||
label->detail->font_size,
|
||||
label->detail->font_size,
|
||||
label->detail->text,
|
||||
label->detail->num_text_lines,
|
||||
label->detail->text_line_widths,
|
||||
label->detail->text_line_heights,
|
||||
label->detail->text_justification,
|
||||
label->detail->line_offset,
|
||||
label->detail->text_color,
|
||||
label->detail->text_alpha);
|
||||
nautilus_scalable_font_draw_text_lines_with_dimensions (label->detail->font,
|
||||
buffer,
|
||||
text_x,
|
||||
text_y,
|
||||
&clip_area,
|
||||
label->detail->font_size,
|
||||
label->detail->font_size,
|
||||
label->detail->text,
|
||||
label->detail->num_text_lines,
|
||||
label->detail->text_line_widths,
|
||||
label->detail->text_line_heights,
|
||||
label->detail->text_justification,
|
||||
label->detail->line_offset,
|
||||
label->detail->text_color,
|
||||
label->detail->text_alpha);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -848,32 +848,28 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
|
|||
}
|
||||
|
||||
void
|
||||
nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
const guint *text_line_widths,
|
||||
const guint *text_line_heights,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha)
|
||||
nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
const guint *text_line_widths,
|
||||
const guint *text_line_heights,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha)
|
||||
{
|
||||
guint i;
|
||||
const char *line;
|
||||
guint i;
|
||||
const char *line;
|
||||
guint available_width;
|
||||
guint available_height;
|
||||
|
||||
guint *temp_text_line_widths = NULL;
|
||||
guint *temp_text_line_heights = NULL;
|
||||
|
||||
guint available_width;
|
||||
guint available_height;
|
||||
|
||||
guint max_num_text_lines;
|
||||
// guint max_num_text_lines;
|
||||
|
||||
g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
|
||||
g_return_if_fail (destination_pixbuf != NULL);
|
||||
|
@ -886,43 +882,13 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
|||
g_return_if_fail (clip_area->y1 > clip_area->y0);
|
||||
g_return_if_fail (num_text_lines > 0);
|
||||
g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1));
|
||||
g_return_if_fail (text_line_widths != NULL);
|
||||
g_return_if_fail (text_line_widths != NULL);
|
||||
|
||||
available_width = clip_area->x1 - clip_area->x0;
|
||||
available_height = clip_area->y1 - clip_area->y0;
|
||||
|
||||
if (text_line_widths) {
|
||||
g_return_if_fail (text_line_heights != NULL);
|
||||
}
|
||||
|
||||
if (text_line_heights) {
|
||||
g_return_if_fail (text_line_widths != NULL);
|
||||
}
|
||||
|
||||
max_num_text_lines = (available_height / font_height);
|
||||
|
||||
if (text_line_widths == NULL && text_line_heights == NULL) {
|
||||
temp_text_line_widths = g_new (guint, num_text_lines);
|
||||
temp_text_line_heights = g_new (guint, num_text_lines);
|
||||
|
||||
nautilus_scalable_font_measure_text_lines (font,
|
||||
font_width,
|
||||
font_height,
|
||||
text,
|
||||
num_text_lines,
|
||||
temp_text_line_widths,
|
||||
temp_text_line_heights,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
text_line_widths = temp_text_line_widths;
|
||||
text_line_heights = temp_text_line_heights;
|
||||
}
|
||||
|
||||
g_return_if_fail (text_line_widths != NULL);
|
||||
g_return_if_fail (text_line_heights != NULL);
|
||||
|
||||
// x = clip_area->x0;
|
||||
// y = clip_area->y0;
|
||||
// max_num_text_lines = (available_height / font_height);
|
||||
|
||||
line = text;
|
||||
|
||||
|
@ -1001,14 +967,72 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
|||
line = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (temp_text_line_widths != NULL) {
|
||||
g_free (temp_text_line_widths);
|
||||
}
|
||||
void
|
||||
nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha)
|
||||
{
|
||||
guint num_text_lines;
|
||||
guint *text_line_widths;
|
||||
guint *text_line_heights;
|
||||
|
||||
if (temp_text_line_heights != NULL) {
|
||||
g_free (temp_text_line_heights);
|
||||
}
|
||||
g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
|
||||
g_return_if_fail (destination_pixbuf != NULL);
|
||||
g_return_if_fail (gdk_pixbuf_get_has_alpha (destination_pixbuf));
|
||||
g_return_if_fail (clip_area != NULL);
|
||||
g_return_if_fail (font_width > 0);
|
||||
g_return_if_fail (font_height > 0);
|
||||
g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL);
|
||||
g_return_if_fail (clip_area->x1 > clip_area->x0);
|
||||
g_return_if_fail (clip_area->y1 > clip_area->y0);
|
||||
|
||||
if (text == NULL || text[0] == '\0') {
|
||||
return;
|
||||
}
|
||||
|
||||
num_text_lines = nautilus_str_count_characters (text, '\n') + 1;
|
||||
text_line_widths = g_new (guint, num_text_lines);
|
||||
text_line_heights = g_new (guint, num_text_lines);
|
||||
|
||||
nautilus_scalable_font_measure_text_lines (font,
|
||||
font_width,
|
||||
font_height,
|
||||
text,
|
||||
num_text_lines,
|
||||
text_line_widths,
|
||||
text_line_heights,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
nautilus_scalable_font_draw_text_lines_with_dimensions (font,
|
||||
destination_pixbuf,
|
||||
x,
|
||||
y,
|
||||
clip_area,
|
||||
font_width,
|
||||
font_height,
|
||||
text,
|
||||
num_text_lines,
|
||||
text_line_widths,
|
||||
text_line_heights,
|
||||
justification,
|
||||
line_offset,
|
||||
color,
|
||||
overall_alpha);
|
||||
|
||||
g_free (text_line_widths);
|
||||
g_free (text_line_heights);
|
||||
}
|
||||
|
||||
guint
|
||||
|
|
|
@ -72,68 +72,81 @@ struct _NautilusScalableFontClass
|
|||
GtkObjectClass parent_class;
|
||||
};
|
||||
|
||||
GtkType nautilus_scalable_font_get_type (void);
|
||||
GtkObject * nautilus_scalable_font_new (const char *family,
|
||||
const char *weight,
|
||||
const char *slant,
|
||||
const char *set_width);
|
||||
void nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint text_length,
|
||||
guint *text_width_out,
|
||||
guint *text_height_out);
|
||||
void nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint text_length,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
void nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
guint text_line_widths[],
|
||||
guint text_line_heights[],
|
||||
guint *max_width_out,
|
||||
guint *total_height_out);
|
||||
void nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
const guint *text_line_widths,
|
||||
const guint *text_line_heights,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
guint nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,
|
||||
const char *text,
|
||||
guint available_width,
|
||||
const guint font_sizes[],
|
||||
guint num_font_sizes);
|
||||
NautilusScalableFont *nautilus_scalable_font_get_default_font (void);
|
||||
NautilusStringList * nautilus_scalable_font_get_font_family_list (void);
|
||||
gboolean nautilus_scalable_font_query_font (const char *family,
|
||||
NautilusStringList **weights,
|
||||
NautilusStringList **slants,
|
||||
NautilusStringList **set_widths);
|
||||
gboolean nautilus_scalable_font_query_font (const char *family,
|
||||
NautilusStringList **weights,
|
||||
NautilusStringList **slants,
|
||||
NautilusStringList **set_widths);
|
||||
GtkType nautilus_scalable_font_get_type (void);
|
||||
GtkObject * nautilus_scalable_font_new (const char *family,
|
||||
const char *weight,
|
||||
const char *slant,
|
||||
const char *set_width);
|
||||
void nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint text_length,
|
||||
guint *text_width_out,
|
||||
guint *text_height_out);
|
||||
void nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint text_length,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
void nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
guint text_line_widths[],
|
||||
guint text_line_heights[],
|
||||
guint *max_width_out,
|
||||
guint *total_height_out);
|
||||
void nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
const guint *text_line_widths,
|
||||
const guint *text_line_heights,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
void nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
guint nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,
|
||||
const char *text,
|
||||
guint available_width,
|
||||
const guint font_sizes[],
|
||||
guint num_font_sizes);
|
||||
NautilusScalableFont *nautilus_scalable_font_get_default_font (void);
|
||||
NautilusStringList * nautilus_scalable_font_get_font_family_list (void);
|
||||
gboolean nautilus_scalable_font_query_font (const char *family,
|
||||
NautilusStringList **weights,
|
||||
NautilusStringList **slants,
|
||||
NautilusStringList **set_widths);
|
||||
gboolean nautilus_scalable_font_query_font (const char *family,
|
||||
NautilusStringList **weights,
|
||||
NautilusStringList **slants,
|
||||
NautilusStringList **set_widths);
|
||||
|
||||
|
||||
END_GNOME_DECLS
|
||||
|
||||
|
|
|
@ -357,41 +357,41 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
|
|||
if (label->detail->drop_shadow_offset > 0) {
|
||||
text_x += label->detail->drop_shadow_offset;
|
||||
text_y += label->detail->drop_shadow_offset;
|
||||
nautilus_scalable_font_draw_text_lines (label->detail->font,
|
||||
buffer,
|
||||
text_x,
|
||||
text_y,
|
||||
&clip_area,
|
||||
label->detail->font_size,
|
||||
label->detail->font_size,
|
||||
label->detail->text,
|
||||
label->detail->num_text_lines,
|
||||
label->detail->text_line_widths,
|
||||
label->detail->text_line_heights,
|
||||
label->detail->text_justification,
|
||||
label->detail->line_offset,
|
||||
label->detail->drop_shadow_color,
|
||||
label->detail->text_alpha);
|
||||
nautilus_scalable_font_draw_text_lines_with_dimensions (label->detail->font,
|
||||
buffer,
|
||||
text_x,
|
||||
text_y,
|
||||
&clip_area,
|
||||
label->detail->font_size,
|
||||
label->detail->font_size,
|
||||
label->detail->text,
|
||||
label->detail->num_text_lines,
|
||||
label->detail->text_line_widths,
|
||||
label->detail->text_line_heights,
|
||||
label->detail->text_justification,
|
||||
label->detail->line_offset,
|
||||
label->detail->drop_shadow_color,
|
||||
label->detail->text_alpha);
|
||||
|
||||
text_x -= label->detail->drop_shadow_offset;
|
||||
text_y -= label->detail->drop_shadow_offset;
|
||||
}
|
||||
|
||||
nautilus_scalable_font_draw_text_lines (label->detail->font,
|
||||
buffer,
|
||||
text_x,
|
||||
text_y,
|
||||
&clip_area,
|
||||
label->detail->font_size,
|
||||
label->detail->font_size,
|
||||
label->detail->text,
|
||||
label->detail->num_text_lines,
|
||||
label->detail->text_line_widths,
|
||||
label->detail->text_line_heights,
|
||||
label->detail->text_justification,
|
||||
label->detail->line_offset,
|
||||
label->detail->text_color,
|
||||
label->detail->text_alpha);
|
||||
nautilus_scalable_font_draw_text_lines_with_dimensions (label->detail->font,
|
||||
buffer,
|
||||
text_x,
|
||||
text_y,
|
||||
&clip_area,
|
||||
label->detail->font_size,
|
||||
label->detail->font_size,
|
||||
label->detail->text,
|
||||
label->detail->num_text_lines,
|
||||
label->detail->text_line_widths,
|
||||
label->detail->text_line_heights,
|
||||
label->detail->text_justification,
|
||||
label->detail->line_offset,
|
||||
label->detail->text_color,
|
||||
label->detail->text_alpha);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -848,32 +848,28 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
|
|||
}
|
||||
|
||||
void
|
||||
nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
const guint *text_line_widths,
|
||||
const guint *text_line_heights,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha)
|
||||
nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
const guint *text_line_widths,
|
||||
const guint *text_line_heights,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha)
|
||||
{
|
||||
guint i;
|
||||
const char *line;
|
||||
guint i;
|
||||
const char *line;
|
||||
guint available_width;
|
||||
guint available_height;
|
||||
|
||||
guint *temp_text_line_widths = NULL;
|
||||
guint *temp_text_line_heights = NULL;
|
||||
|
||||
guint available_width;
|
||||
guint available_height;
|
||||
|
||||
guint max_num_text_lines;
|
||||
// guint max_num_text_lines;
|
||||
|
||||
g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
|
||||
g_return_if_fail (destination_pixbuf != NULL);
|
||||
|
@ -886,43 +882,13 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
|||
g_return_if_fail (clip_area->y1 > clip_area->y0);
|
||||
g_return_if_fail (num_text_lines > 0);
|
||||
g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1));
|
||||
g_return_if_fail (text_line_widths != NULL);
|
||||
g_return_if_fail (text_line_widths != NULL);
|
||||
|
||||
available_width = clip_area->x1 - clip_area->x0;
|
||||
available_height = clip_area->y1 - clip_area->y0;
|
||||
|
||||
if (text_line_widths) {
|
||||
g_return_if_fail (text_line_heights != NULL);
|
||||
}
|
||||
|
||||
if (text_line_heights) {
|
||||
g_return_if_fail (text_line_widths != NULL);
|
||||
}
|
||||
|
||||
max_num_text_lines = (available_height / font_height);
|
||||
|
||||
if (text_line_widths == NULL && text_line_heights == NULL) {
|
||||
temp_text_line_widths = g_new (guint, num_text_lines);
|
||||
temp_text_line_heights = g_new (guint, num_text_lines);
|
||||
|
||||
nautilus_scalable_font_measure_text_lines (font,
|
||||
font_width,
|
||||
font_height,
|
||||
text,
|
||||
num_text_lines,
|
||||
temp_text_line_widths,
|
||||
temp_text_line_heights,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
text_line_widths = temp_text_line_widths;
|
||||
text_line_heights = temp_text_line_heights;
|
||||
}
|
||||
|
||||
g_return_if_fail (text_line_widths != NULL);
|
||||
g_return_if_fail (text_line_heights != NULL);
|
||||
|
||||
// x = clip_area->x0;
|
||||
// y = clip_area->y0;
|
||||
// max_num_text_lines = (available_height / font_height);
|
||||
|
||||
line = text;
|
||||
|
||||
|
@ -1001,14 +967,72 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
|||
line = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (temp_text_line_widths != NULL) {
|
||||
g_free (temp_text_line_widths);
|
||||
}
|
||||
void
|
||||
nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha)
|
||||
{
|
||||
guint num_text_lines;
|
||||
guint *text_line_widths;
|
||||
guint *text_line_heights;
|
||||
|
||||
if (temp_text_line_heights != NULL) {
|
||||
g_free (temp_text_line_heights);
|
||||
}
|
||||
g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
|
||||
g_return_if_fail (destination_pixbuf != NULL);
|
||||
g_return_if_fail (gdk_pixbuf_get_has_alpha (destination_pixbuf));
|
||||
g_return_if_fail (clip_area != NULL);
|
||||
g_return_if_fail (font_width > 0);
|
||||
g_return_if_fail (font_height > 0);
|
||||
g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL);
|
||||
g_return_if_fail (clip_area->x1 > clip_area->x0);
|
||||
g_return_if_fail (clip_area->y1 > clip_area->y0);
|
||||
|
||||
if (text == NULL || text[0] == '\0') {
|
||||
return;
|
||||
}
|
||||
|
||||
num_text_lines = nautilus_str_count_characters (text, '\n') + 1;
|
||||
text_line_widths = g_new (guint, num_text_lines);
|
||||
text_line_heights = g_new (guint, num_text_lines);
|
||||
|
||||
nautilus_scalable_font_measure_text_lines (font,
|
||||
font_width,
|
||||
font_height,
|
||||
text,
|
||||
num_text_lines,
|
||||
text_line_widths,
|
||||
text_line_heights,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
nautilus_scalable_font_draw_text_lines_with_dimensions (font,
|
||||
destination_pixbuf,
|
||||
x,
|
||||
y,
|
||||
clip_area,
|
||||
font_width,
|
||||
font_height,
|
||||
text,
|
||||
num_text_lines,
|
||||
text_line_widths,
|
||||
text_line_heights,
|
||||
justification,
|
||||
line_offset,
|
||||
color,
|
||||
overall_alpha);
|
||||
|
||||
g_free (text_line_widths);
|
||||
g_free (text_line_heights);
|
||||
}
|
||||
|
||||
guint
|
||||
|
|
|
@ -72,68 +72,81 @@ struct _NautilusScalableFontClass
|
|||
GtkObjectClass parent_class;
|
||||
};
|
||||
|
||||
GtkType nautilus_scalable_font_get_type (void);
|
||||
GtkObject * nautilus_scalable_font_new (const char *family,
|
||||
const char *weight,
|
||||
const char *slant,
|
||||
const char *set_width);
|
||||
void nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint text_length,
|
||||
guint *text_width_out,
|
||||
guint *text_height_out);
|
||||
void nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint text_length,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
void nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
guint text_line_widths[],
|
||||
guint text_line_heights[],
|
||||
guint *max_width_out,
|
||||
guint *total_height_out);
|
||||
void nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
const guint *text_line_widths,
|
||||
const guint *text_line_heights,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
guint nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,
|
||||
const char *text,
|
||||
guint available_width,
|
||||
const guint font_sizes[],
|
||||
guint num_font_sizes);
|
||||
NautilusScalableFont *nautilus_scalable_font_get_default_font (void);
|
||||
NautilusStringList * nautilus_scalable_font_get_font_family_list (void);
|
||||
gboolean nautilus_scalable_font_query_font (const char *family,
|
||||
NautilusStringList **weights,
|
||||
NautilusStringList **slants,
|
||||
NautilusStringList **set_widths);
|
||||
gboolean nautilus_scalable_font_query_font (const char *family,
|
||||
NautilusStringList **weights,
|
||||
NautilusStringList **slants,
|
||||
NautilusStringList **set_widths);
|
||||
GtkType nautilus_scalable_font_get_type (void);
|
||||
GtkObject * nautilus_scalable_font_new (const char *family,
|
||||
const char *weight,
|
||||
const char *slant,
|
||||
const char *set_width);
|
||||
void nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint text_length,
|
||||
guint *text_width_out,
|
||||
guint *text_height_out);
|
||||
void nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint text_length,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
void nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
guint text_line_widths[],
|
||||
guint text_line_heights[],
|
||||
guint *max_width_out,
|
||||
guint *total_height_out);
|
||||
void nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
guint num_text_lines,
|
||||
const guint *text_line_widths,
|
||||
const guint *text_line_heights,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
void nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
|
||||
GdkPixbuf *destination_pixbuf,
|
||||
int x,
|
||||
int y,
|
||||
const ArtIRect *clip_area,
|
||||
guint font_width,
|
||||
guint font_height,
|
||||
const char *text,
|
||||
GtkJustification justification,
|
||||
guint line_offset,
|
||||
guint32 color,
|
||||
guchar overall_alpha);
|
||||
guint nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,
|
||||
const char *text,
|
||||
guint available_width,
|
||||
const guint font_sizes[],
|
||||
guint num_font_sizes);
|
||||
NautilusScalableFont *nautilus_scalable_font_get_default_font (void);
|
||||
NautilusStringList * nautilus_scalable_font_get_font_family_list (void);
|
||||
gboolean nautilus_scalable_font_query_font (const char *family,
|
||||
NautilusStringList **weights,
|
||||
NautilusStringList **slants,
|
||||
NautilusStringList **set_widths);
|
||||
gboolean nautilus_scalable_font_query_font (const char *family,
|
||||
NautilusStringList **weights,
|
||||
NautilusStringList **slants,
|
||||
NautilusStringList **set_widths);
|
||||
|
||||
|
||||
END_GNOME_DECLS
|
||||
|
||||
|
|
|
@ -25,11 +25,6 @@ main (int argc, char* argv[])
|
|||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
NautilusScalableFont *font;
|
||||
guint num_text_lines;
|
||||
guint *text_line_widths;
|
||||
guint *text_line_heights;
|
||||
guint max_width_out;
|
||||
guint total_height_out;
|
||||
|
||||
const char *text = "\nLine Two\n\nLine Four\n\n\nLine Seven\n";
|
||||
const guint font_width = 48;
|
||||
|
@ -40,6 +35,7 @@ main (int argc, char* argv[])
|
|||
|
||||
GdkRectangle blue_area;
|
||||
ArtIRect clip_area;
|
||||
ArtIRect whole_area;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
gdk_rgb_init ();
|
||||
|
@ -50,64 +46,81 @@ main (int argc, char* argv[])
|
|||
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, pixbuf_width, pixbuf_height);
|
||||
g_assert (pixbuf != NULL);
|
||||
|
||||
blue_area.x = 20;
|
||||
/* Measure some text lines */
|
||||
{
|
||||
guint num_text_lines;
|
||||
guint *text_line_widths;
|
||||
guint *text_line_heights;
|
||||
guint max_width_out;
|
||||
guint total_height_out;
|
||||
|
||||
num_text_lines = nautilus_str_count_characters (text, '\n') + 1;
|
||||
|
||||
text_line_widths = g_new (guint, num_text_lines);
|
||||
text_line_heights = g_new (guint, num_text_lines);
|
||||
|
||||
nautilus_scalable_font_measure_text_lines (font,
|
||||
font_width,
|
||||
font_height,
|
||||
text,
|
||||
num_text_lines,
|
||||
text_line_widths,
|
||||
text_line_heights,
|
||||
&max_width_out,
|
||||
&total_height_out);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
blue_area.x = 300;
|
||||
blue_area.y = 20;
|
||||
blue_area.width = 100;
|
||||
blue_area.height = 400;
|
||||
|
||||
nautilus_gdk_pixbuf_fill_rectangle_with_color (pixbuf, &blue_area, NAUTILUS_RGBA_COLOR_PACK (0, 0, 255, 255));
|
||||
|
||||
num_text_lines = nautilus_str_count_characters (text, '\n') + 1;
|
||||
|
||||
text_line_widths = g_new (guint, num_text_lines);
|
||||
text_line_heights = g_new (guint, num_text_lines);
|
||||
|
||||
nautilus_scalable_font_measure_text_lines (font,
|
||||
font_width,
|
||||
font_height,
|
||||
text,
|
||||
num_text_lines,
|
||||
text_line_widths,
|
||||
text_line_heights,
|
||||
&max_width_out,
|
||||
&total_height_out);
|
||||
|
||||
g_print ("max_width = %d, total_height = %d\n", max_width_out, total_height_out);
|
||||
|
||||
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;
|
||||
|
||||
#if 0
|
||||
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 some green text clipped by the whole pixbuf area */
|
||||
nautilus_scalable_font_draw_text_lines (font,
|
||||
pixbuf,
|
||||
0,
|
||||
0,
|
||||
&clip_area,
|
||||
&whole_area,
|
||||
font_width,
|
||||
font_height,
|
||||
text,
|
||||
num_text_lines,
|
||||
text_line_widths,
|
||||
text_line_heights,
|
||||
GTK_JUSTIFY_LEFT,
|
||||
2,
|
||||
NAUTILUS_RGB_COLOR_RED,
|
||||
NAUTILUS_RGBA_COLOR_PACK (0, 255, 0, 255),
|
||||
255);
|
||||
#else
|
||||
|
||||
/* Draw some red text clipped by the blue area */
|
||||
nautilus_scalable_font_draw_text (font,
|
||||
pixbuf,
|
||||
10,
|
||||
30,
|
||||
clip_area.x0,
|
||||
clip_area.y0,
|
||||
&clip_area,
|
||||
font_width,
|
||||
font_height,
|
||||
"Something",
|
||||
strlen ("Something"),
|
||||
NAUTILUS_RGB_COLOR_RED,
|
||||
NAUTILUS_RGBA_COLOR_PACK (255, 0, 0, 255),
|
||||
255);
|
||||
#endif
|
||||
|
||||
nautilus_gdk_pixbuf_save_to_file (pixbuf, "font_test.png");
|
||||
|
||||
|
|
Loading…
Reference in a new issue