summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog44
-rw-r--r--libnautilus-extensions/nautilus-label.c19
-rw-r--r--libnautilus-extensions/nautilus-scalable-font.c486
-rw-r--r--libnautilus-extensions/nautilus-scalable-font.h24
-rw-r--r--libnautilus-private/nautilus-label.c19
-rw-r--r--libnautilus-private/nautilus-scalable-font.c486
-rw-r--r--libnautilus-private/nautilus-scalable-font.h24
-rw-r--r--librsvg/rsvg-ft.c15
-rw-r--r--librsvg/rsvg-ft.h4
-rw-r--r--librsvg/rsvg.c4
-rw-r--r--librsvg/test-ft-gtk.c1
-rw-r--r--librsvg/test-ft.c1
-rw-r--r--src/nautilus-about.c6
-rw-r--r--src/nautilus-sidebar-tabs.c39
-rw-r--r--test/test-nautilus-font.c75
-rw-r--r--test/test-nautilus-label.c4
16 files changed, 892 insertions, 359 deletions
diff --git a/ChangeLog b/ChangeLog
index f9293d271..440c4c4a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,49 @@
2000-09-04 Ramiro Estrugo <ramiro@eazel.com>
+ Work on task 1588.
+
+ * libnautilus-extensions/nautilus-scalable-font.c:
+ (nautilus_scalable_font_measure_text),
+ (nautilus_scalable_font_draw_text),
+ (nautilus_scalable_font_measure_text_lines),
+ (nautilus_scalable_font_draw_text_lines),
+ (nautilus_scalable_font_measure_text_lines),
+ (nautilus_scalable_font_draw_text_lines),
+ (nautilus_scalable_font_largest_fitting_font_size):
+ * libnautilus-extensions/nautilus-scalable-font.h:
+ Change api to accept a string with embedded new lines instead of
+ an array of strings. This simplifies many things.
+
+ * libnautilus-extensions/nautilus-label.c:
+ (nautilus_label_initialize), (nautilus_label_destroy),
+ (render_buffer_pixbuf), (label_recompute_line_geometries):
+ Update for NautilusScalalbleFont api changes. No longer need to
+ tokenize the text string. we can feed the string to the rendering
+ api as is.
+
+ * librsvg/rsvg-ft.c: (rsvg_ft_render_string):
+ * librsvg/rsvg-ft.h:
+ Change the string to glyph rendering api to accept the string
+ length rather than computing it. This makes it possible to feed
+ it arbitrary lengths.
+
+ * librsvg/rsvg.c: (rsvg_text_handler_characters):
+ * librsvg/test-ft-gtk.c: (draw_line):
+ * librsvg/test-ft.c: (main):
+ Update for api changes.
+
+ * src/nautilus-about.c: (draw_aa_string):
+ * src/nautilus-sidebar-tabs.c: (draw_one_tab_plain),
+ (draw_one_tab_themed), (get_tab_width):
+ * test/test-nautilus-font.c: (main):
+ Update test to use text lines drawing api.
+
+ * test/test-nautilus-label.c:
+ (alpha_background_color_value_changed_callback), (main):
+ Update test for 2 new lines in a row.
+
+2000-09-04 Ramiro Estrugo <ramiro@eazel.com>
+
* libnautilus-extensions/nautilus-string-list.c:
(nautilus_self_check_string_list):
Make the tokens test a little better.
diff --git a/libnautilus-extensions/nautilus-label.c b/libnautilus-extensions/nautilus-label.c
index 4e89b14ad..5bfa5137c 100644
--- a/libnautilus-extensions/nautilus-label.c
+++ b/libnautilus-extensions/nautilus-label.c
@@ -61,7 +61,6 @@ struct _NautilusLabelDetail
guint font_size;
/* Text lines */
- char **text_lines;
guint *text_line_widths;
guint *text_line_heights;
guint num_text_lines;
@@ -159,7 +158,6 @@ nautilus_label_initialize (NautilusLabel *label)
label->detail->num_text_lines = 0;
label->detail->max_text_line_width = 0;
label->detail->total_text_line_height = 0;
- label->detail->text_lines = NULL;
label->detail->text_line_widths = NULL;
label->detail->text_line_heights = NULL;
@@ -180,7 +178,6 @@ nautilus_label_destroy (GtkObject *object)
g_free (label->detail->text);
- g_strfreev (label->detail->text_lines);
g_free (label->detail->text_line_widths);
g_free (label->detail->text_line_heights);
@@ -358,11 +355,11 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
&area,
label->detail->font_size,
label->detail->font_size,
- (const char **) label->detail->text_lines,
+ label->detail->text,
+ label->detail->num_text_lines,
label->detail->text_line_widths,
label->detail->text_line_heights,
label->detail->text_justification,
- label->detail->num_text_lines,
label->detail->line_offset,
label->detail->drop_shadow_color,
label->detail->text_alpha);
@@ -379,11 +376,11 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
&area,
label->detail->font_size,
label->detail->font_size,
- (const char **) label->detail->text_lines,
+ label->detail->text,
+ label->detail->num_text_lines,
label->detail->text_line_widths,
label->detail->text_line_heights,
label->detail->text_justification,
- label->detail->num_text_lines,
label->detail->line_offset,
label->detail->text_color,
label->detail->text_alpha);
@@ -396,10 +393,8 @@ label_recompute_line_geometries (NautilusLabel *label)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
- g_strfreev (label->detail->text_lines);
g_free (label->detail->text_line_widths);
g_free (label->detail->text_line_heights);
- label->detail->text_lines = NULL;
label->detail->text_line_widths = NULL;
label->detail->text_line_heights = NULL;
@@ -408,20 +403,16 @@ label_recompute_line_geometries (NautilusLabel *label)
label->detail->max_text_line_width = 0;
label->detail->total_text_line_height = 0;
- label->detail->text_lines = NULL;
-
if (nautilus_strlen (label->detail->text) > 0) {
label->detail->num_text_lines = nautilus_str_count_characters (label->detail->text, '\n') + 1;
- label->detail->text_lines = g_strsplit (label->detail->text, "\n", -1);
-
label->detail->text_line_widths = g_new (guint, label->detail->num_text_lines);
label->detail->text_line_heights = g_new (guint, label->detail->num_text_lines);
nautilus_scalable_font_measure_text_lines (label->detail->font,
label->detail->font_size,
label->detail->font_size,
- (const char **) label->detail->text_lines,
+ label->detail->text,
label->detail->num_text_lines,
label->detail->text_line_widths,
label->detail->text_line_heights,
diff --git a/libnautilus-extensions/nautilus-scalable-font.c b/libnautilus-extensions/nautilus-scalable-font.c
index 8b51af0b8..d4d3ed49a 100644
--- a/libnautilus-extensions/nautilus-scalable-font.c
+++ b/libnautilus-extensions/nautilus-scalable-font.c
@@ -606,6 +606,7 @@ 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)
{
@@ -622,10 +623,12 @@ nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
*text_width_out = 0;
*text_height_out = 0;
- if (text == NULL) {
+ if (text == NULL || text[0] == '\0' || text_length == 0) {
return;
}
+ g_return_if_fail (text_length <= strlen (text));
+
art_affine_identity (affine);
/* FIXME bugzilla.eazel.com 2544: We need to change rsvg_ft_render_string() to accept
@@ -635,6 +638,7 @@ nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
glyph = rsvg_ft_render_string (global_rsvg_ft_context,
font->detail->font_handle,
text,
+ text_length,
font_width,
font_height,
affine,
@@ -647,107 +651,13 @@ nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
}
void
-nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
- guint font_width,
- guint font_height,
- const char *text_lines[],
- guint num_text_lines,
- guint text_line_widths[],
- guint text_line_heights[],
- guint *max_width_out,
- guint *total_height_out)
-{
- guint i;
-
- g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
- g_return_if_fail (font_width > 0);
- g_return_if_fail (font_height > 0);
- g_return_if_fail (text_lines != NULL);
- g_return_if_fail (text_line_widths != NULL);
- g_return_if_fail (text_line_heights != NULL);
- g_return_if_fail (num_text_lines > 0);
-
- if (max_width_out != NULL) {
- *max_width_out = 0;
- }
-
- if (total_height_out != NULL) {
- *total_height_out = 0;
- }
-
- for (i = 0; i < num_text_lines; i++) {
- g_assert (text_lines[i] != NULL);
-
- nautilus_scalable_font_measure_text (font,
- font_width,
- font_height,
- text_lines[i],
- &text_line_widths[i],
- &text_line_heights[i]);
-
- if (total_height_out != NULL) {
- *total_height_out += text_line_heights[i];
- }
-
- if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) {
- *max_width_out = text_line_widths[i];
- }
- }
-}
-
-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)
-{
- NautilusStringList *tokenized_string;
- guint i;
- char *longest_string;
-
- g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0);
- g_return_val_if_fail (font_sizes != NULL, 0);
- g_return_val_if_fail (num_font_sizes > 0, 0);
-
- if (text == NULL || text[0] == '\0' || available_width < 1) {
- return font_sizes[num_font_sizes - 1];
- }
-
- tokenized_string = nautilus_string_list_new_from_tokens (text, "\n", FALSE);
- longest_string = nautilus_string_list_get_longest_string (tokenized_string);
- g_assert (longest_string != NULL);
- nautilus_string_list_free (tokenized_string);
-
- for (i = 0; i < num_font_sizes; i++) {
- guint text_width;
- guint text_height;
-
- nautilus_scalable_font_measure_text (font,
- font_sizes[i],
- font_sizes[i],
- longest_string,
- &text_width,
- &text_height);
-
- if (text_width <= available_width) {
- g_free (longest_string);
- return font_sizes[i];
- }
- }
-
- g_free (longest_string);
-
- return font_sizes[num_font_sizes - 1];
-}
-
-void
nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
GdkPixbuf *destination_pixbuf,
const ArtIRect *destination_area,
guint font_width,
guint font_height,
const char *text,
+ guint text_length,
guint32 color,
guchar overall_alpha)
{
@@ -774,15 +684,18 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
g_return_if_fail (font_width > 0);
g_return_if_fail (font_height > 0);
- if (text == NULL) {
+ if (text == NULL || text[0] == '\0' || text_length == 0) {
return;
}
+ g_return_if_fail (text_length <= strlen (text));
+
art_affine_identity (affine);
glyph = rsvg_ft_render_string (global_rsvg_ft_context,
font->detail->font_handle,
text,
+ text_length,
font_width,
font_height,
affine,
@@ -837,6 +750,57 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
rsvg_ft_glyph_unref (glyph);
}
+#if 0
+void
+nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ guint num_text_lines,
+ guint text_line_widths[],
+ guint text_line_heights[],
+ guint *max_width_out,
+ guint *total_height_out)
+{
+ guint i;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text_lines != NULL);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (num_text_lines > 0);
+
+ if (max_width_out != NULL) {
+ *max_width_out = 0;
+ }
+
+ if (total_height_out != NULL) {
+ *total_height_out = 0;
+ }
+
+ for (i = 0; i < num_text_lines; i++) {
+ g_assert (text_lines[i] != NULL);
+
+ nautilus_scalable_font_measure_text (font,
+ font_width,
+ font_height,
+ text_lines[i],
+ strlen (text_lines[i]),
+ &text_line_widths[i],
+ &text_line_heights[i]);
+
+ if (total_height_out != NULL) {
+ *total_height_out += text_line_heights[i];
+ }
+
+ if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) {
+ *max_width_out = text_line_widths[i];
+ }
+ }
+}
+
void
nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
GdkPixbuf *destination_pixbuf,
@@ -883,48 +847,310 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
ArtIRect area;
g_assert (text_lines[i] != NULL);
- g_assert (text_line_widths[i] > 0);
- g_assert (text_line_heights[i] > 0);
-
- switch (justification) {
- case GTK_JUSTIFY_LEFT:
- area.x0 = x;
- break;
-
- case GTK_JUSTIFY_CENTER:
- case GTK_JUSTIFY_FILL:
- if (text_line_widths[i] <= available_width) {
- area.x0 = x + ((available_width - text_line_widths[i]) / 2);
- }
- else {
- area.x0 = x - ((text_line_widths[i] - available_width) / 2);
+
+ if (text_line_widths[i] == 0 && text_line_heights[i] == 0) {
+ y += font_height;
+ }
+ else {
+ switch (justification) {
+ case GTK_JUSTIFY_LEFT:
+ area.x0 = x;
+ break;
+
+ case GTK_JUSTIFY_CENTER:
+ case GTK_JUSTIFY_FILL:
+ if (text_line_widths[i] <= available_width) {
+ area.x0 = x + ((available_width - text_line_widths[i]) / 2);
+ }
+ else {
+ area.x0 = x - ((text_line_widths[i] - available_width) / 2);
+ }
+ break;
+
+ case GTK_JUSTIFY_RIGHT:
+ area.x0 = x + available_width - text_line_widths[i];
+ break;
+
+ default:
+ g_assert_not_reached ();
}
- break;
+
+ area.x1 = area.x0 + text_line_widths[i];
+ area.y0 = y;
+ area.y1 = area.y0 + text_line_heights[i];
+
+ nautilus_scalable_font_draw_text (font,
+ destination_pixbuf,
+ &area,
+ font_width,
+ font_height,
+ text_lines[i],
+ strlen (text_lines[i]),
+ color,
+ overall_alpha);
+
+ y += (line_offset + text_line_heights[i]);
+ }
+ }
+}
+#else
+void
+nautilus_scalable_font_measure_text_lines (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)
+{
+ guint i;
+ const char *line;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text != NULL);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (num_text_lines > 0);
+ g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1));
- case GTK_JUSTIFY_RIGHT:
- area.x0 = x + available_width - text_line_widths[i];
- break;
+ if (max_width_out != NULL) {
+ *max_width_out = 0;
+ }
- default:
- g_assert_not_reached ();
+ if (total_height_out != NULL) {
+ *total_height_out = 0;
+ }
+
+ line = text;
+
+ /*
+ * We can safely iterate for 'num_text_lines' since we already checked that the
+ * string does indeed contain as many lines.
+ */
+ for (i = 0; i < num_text_lines; i++) {
+ const char *next_new_line;
+ guint length;
+
+ g_assert (line != NULL);
+
+ /* Look for the next new line */
+ next_new_line = strchr (line, '\n');
+
+ if (next_new_line != NULL) {
+ length = (next_new_line - line);
+ }
+ else {
+ length = strlen (line);
+ }
+
+ /* Deal with empty lines */
+ if (length == 0) {
+ text_line_widths[i] = 0;
+ text_line_heights[i] = font_height;
+ }
+ else {
+ nautilus_scalable_font_measure_text (font,
+ font_width,
+ font_height,
+ line,
+ length,
+ &text_line_widths[i],
+ &text_line_heights[i]);
+ }
+
+ if (next_new_line != NULL) {
+ line = next_new_line + 1;
+ }
+ else {
+ line = NULL;
}
+
+ /* Keep track of total height */
+ if (total_height_out != NULL) {
+ *total_height_out += text_line_heights[i];
+ }
+
+ /* Keep track of max width */
+ if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) {
+ *max_width_out = text_line_widths[i];
+ }
+ }
+}
- area.x1 = area.x0 + text_line_widths[i];
- area.y0 = y;
- area.y1 = area.y0 + text_line_heights[i];
+void
+nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_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;
- nautilus_scalable_font_draw_text (font,
- destination_pixbuf,
- &area,
- font_width,
- font_height,
- text_lines[i],
- color,
- overall_alpha);
+ gint x;
+ gint y;
- y += (line_offset + text_line_heights[i]);
+ guint available_width;
+ guint available_height;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (destination_pixbuf != NULL);
+ g_return_if_fail (destination_area != NULL);
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL);
+ g_return_if_fail (destination_area->x1 > destination_area->x0);
+ g_return_if_fail (destination_area->y1 > destination_area->y0);
+ g_return_if_fail (num_text_lines > 0);
+ g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1));
+
+ x = destination_area->x0;
+ y = destination_area->y0;
+
+ available_width = destination_area->x1 - destination_area->x0;
+ available_height = destination_area->y1 - destination_area->y0;
+
+ line = text;
+
+ /*
+ * We can safely iterate for 'num_text_lines' since we already checked that the
+ * string does indeed contain as many lines.
+ */
+ for (i = 0; i < num_text_lines; i++) {
+ const char *next_new_line;
+ guint length;
+
+ g_assert (line != NULL);
+
+ /* Look for the next new line */
+ next_new_line = strchr (line, '\n');
+
+ if (next_new_line != NULL) {
+ length = (next_new_line - line);
+ }
+ else {
+ length = strlen (line);
+ }
+
+ /* Deal with empty lines */
+ if (length == 0) {
+ y += font_height;
+ }
+ else {
+ ArtIRect area;
+
+ switch (justification) {
+ case GTK_JUSTIFY_LEFT:
+ area.x0 = x;
+ break;
+
+ case GTK_JUSTIFY_CENTER:
+ case GTK_JUSTIFY_FILL:
+ if (text_line_widths[i] <= available_width) {
+ area.x0 = x + ((available_width - text_line_widths[i]) / 2);
+ }
+ else {
+ area.x0 = x - ((text_line_widths[i] - available_width) / 2);
+ }
+ break;
+
+ case GTK_JUSTIFY_RIGHT:
+ area.x0 = x + available_width - text_line_widths[i];
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ area.x1 = area.x0 + text_line_widths[i];
+ area.y0 = y;
+ area.y1 = area.y0 + text_line_heights[i];
+
+ nautilus_scalable_font_draw_text (font,
+ destination_pixbuf,
+ &area,
+ font_width,
+ font_height,
+ line,
+ length,
+ color,
+ overall_alpha);
+
+ y += (line_offset + text_line_heights[i]);
+ }
+
+ if (next_new_line != NULL) {
+ line = next_new_line + 1;
+ }
+ else {
+ line = NULL;
+ }
}
}
+#endif
+
+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)
+{
+ NautilusStringList *tokenized_string;
+ guint i;
+ char *longest_string;
+ guint longest_string_length;
+
+ g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0);
+ g_return_val_if_fail (font_sizes != NULL, 0);
+ g_return_val_if_fail (num_font_sizes > 0, 0);
+
+ if (text == NULL || text[0] == '\0' || available_width < 1) {
+ return font_sizes[num_font_sizes - 1];
+ }
+
+ tokenized_string = nautilus_string_list_new_from_tokens (text, "\n", FALSE);
+ longest_string = nautilus_string_list_get_longest_string (tokenized_string);
+ g_assert (longest_string != NULL);
+ nautilus_string_list_free (tokenized_string);
+ longest_string_length = strlen (longest_string);
+
+ for (i = 0; i < num_font_sizes; i++) {
+ guint text_width;
+ guint text_height;
+
+ nautilus_scalable_font_measure_text (font,
+ font_sizes[i],
+ font_sizes[i],
+ longest_string,
+ longest_string_length,
+ &text_width,
+ &text_height);
+
+ if (text_width <= available_width) {
+ g_free (longest_string);
+ return font_sizes[i];
+ }
+ }
+
+ g_free (longest_string);
+
+ return font_sizes[num_font_sizes - 1];
+}
NautilusScalableFont *
nautilus_scalable_font_get_default_font (void)
diff --git a/libnautilus-extensions/nautilus-scalable-font.h b/libnautilus-extensions/nautilus-scalable-font.h
index 9528cf5f6..7333b1639 100644
--- a/libnautilus-extensions/nautilus-scalable-font.h
+++ b/libnautilus-extensions/nautilus-scalable-font.h
@@ -81,35 +81,37 @@ void nautilus_scalable_font_measure_text (const N
guint font_width,
guint font_height,
const char *text,
+ guint text_length,
guint *text_width_out,
guint *text_height_out);
-void nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
- guint font_width,
- guint font_height,
- const char *text_lines[],
- 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 (const NautilusScalableFont *font,
GdkPixbuf *destination_pixbuf,
const ArtIRect *destination_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 (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,
const ArtIRect *destination_area,
guint font_width,
guint font_height,
- const char *text_lines[],
+ const char *text,
+ guint num_text_lines,
const guint text_line_widths[],
const guint text_line_heights[],
GtkJustification justification,
- const guint num_lines,
guint line_offset,
guint32 color,
guchar overall_alpha);
diff --git a/libnautilus-private/nautilus-label.c b/libnautilus-private/nautilus-label.c
index 4e89b14ad..5bfa5137c 100644
--- a/libnautilus-private/nautilus-label.c
+++ b/libnautilus-private/nautilus-label.c
@@ -61,7 +61,6 @@ struct _NautilusLabelDetail
guint font_size;
/* Text lines */
- char **text_lines;
guint *text_line_widths;
guint *text_line_heights;
guint num_text_lines;
@@ -159,7 +158,6 @@ nautilus_label_initialize (NautilusLabel *label)
label->detail->num_text_lines = 0;
label->detail->max_text_line_width = 0;
label->detail->total_text_line_height = 0;
- label->detail->text_lines = NULL;
label->detail->text_line_widths = NULL;
label->detail->text_line_heights = NULL;
@@ -180,7 +178,6 @@ nautilus_label_destroy (GtkObject *object)
g_free (label->detail->text);
- g_strfreev (label->detail->text_lines);
g_free (label->detail->text_line_widths);
g_free (label->detail->text_line_heights);
@@ -358,11 +355,11 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
&area,
label->detail->font_size,
label->detail->font_size,
- (const char **) label->detail->text_lines,
+ label->detail->text,
+ label->detail->num_text_lines,
label->detail->text_line_widths,
label->detail->text_line_heights,
label->detail->text_justification,
- label->detail->num_text_lines,
label->detail->line_offset,
label->detail->drop_shadow_color,
label->detail->text_alpha);
@@ -379,11 +376,11 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
&area,
label->detail->font_size,
label->detail->font_size,
- (const char **) label->detail->text_lines,
+ label->detail->text,
+ label->detail->num_text_lines,
label->detail->text_line_widths,
label->detail->text_line_heights,
label->detail->text_justification,
- label->detail->num_text_lines,
label->detail->line_offset,
label->detail->text_color,
label->detail->text_alpha);
@@ -396,10 +393,8 @@ label_recompute_line_geometries (NautilusLabel *label)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
- g_strfreev (label->detail->text_lines);
g_free (label->detail->text_line_widths);
g_free (label->detail->text_line_heights);
- label->detail->text_lines = NULL;
label->detail->text_line_widths = NULL;
label->detail->text_line_heights = NULL;
@@ -408,20 +403,16 @@ label_recompute_line_geometries (NautilusLabel *label)
label->detail->max_text_line_width = 0;
label->detail->total_text_line_height = 0;
- label->detail->text_lines = NULL;
-
if (nautilus_strlen (label->detail->text) > 0) {
label->detail->num_text_lines = nautilus_str_count_characters (label->detail->text, '\n') + 1;
- label->detail->text_lines = g_strsplit (label->detail->text, "\n", -1);
-
label->detail->text_line_widths = g_new (guint, label->detail->num_text_lines);
label->detail->text_line_heights = g_new (guint, label->detail->num_text_lines);
nautilus_scalable_font_measure_text_lines (label->detail->font,
label->detail->font_size,
label->detail->font_size,
- (const char **) label->detail->text_lines,
+ label->detail->text,
label->detail->num_text_lines,
label->detail->text_line_widths,
label->detail->text_line_heights,
diff --git a/libnautilus-private/nautilus-scalable-font.c b/libnautilus-private/nautilus-scalable-font.c
index 8b51af0b8..d4d3ed49a 100644
--- a/libnautilus-private/nautilus-scalable-font.c
+++ b/libnautilus-private/nautilus-scalable-font.c
@@ -606,6 +606,7 @@ 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)
{
@@ -622,10 +623,12 @@ nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
*text_width_out = 0;
*text_height_out = 0;
- if (text == NULL) {
+ if (text == NULL || text[0] == '\0' || text_length == 0) {
return;
}
+ g_return_if_fail (text_length <= strlen (text));
+
art_affine_identity (affine);
/* FIXME bugzilla.eazel.com 2544: We need to change rsvg_ft_render_string() to accept
@@ -635,6 +638,7 @@ nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
glyph = rsvg_ft_render_string (global_rsvg_ft_context,
font->detail->font_handle,
text,
+ text_length,
font_width,
font_height,
affine,
@@ -647,107 +651,13 @@ nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
}
void
-nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
- guint font_width,
- guint font_height,
- const char *text_lines[],
- guint num_text_lines,
- guint text_line_widths[],
- guint text_line_heights[],
- guint *max_width_out,
- guint *total_height_out)
-{
- guint i;
-
- g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
- g_return_if_fail (font_width > 0);
- g_return_if_fail (font_height > 0);
- g_return_if_fail (text_lines != NULL);
- g_return_if_fail (text_line_widths != NULL);
- g_return_if_fail (text_line_heights != NULL);
- g_return_if_fail (num_text_lines > 0);
-
- if (max_width_out != NULL) {
- *max_width_out = 0;
- }
-
- if (total_height_out != NULL) {
- *total_height_out = 0;
- }
-
- for (i = 0; i < num_text_lines; i++) {
- g_assert (text_lines[i] != NULL);
-
- nautilus_scalable_font_measure_text (font,
- font_width,
- font_height,
- text_lines[i],
- &text_line_widths[i],
- &text_line_heights[i]);
-
- if (total_height_out != NULL) {
- *total_height_out += text_line_heights[i];
- }
-
- if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) {
- *max_width_out = text_line_widths[i];
- }
- }
-}
-
-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)
-{
- NautilusStringList *tokenized_string;
- guint i;
- char *longest_string;
-
- g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0);
- g_return_val_if_fail (font_sizes != NULL, 0);
- g_return_val_if_fail (num_font_sizes > 0, 0);
-
- if (text == NULL || text[0] == '\0' || available_width < 1) {
- return font_sizes[num_font_sizes - 1];
- }
-
- tokenized_string = nautilus_string_list_new_from_tokens (text, "\n", FALSE);
- longest_string = nautilus_string_list_get_longest_string (tokenized_string);
- g_assert (longest_string != NULL);
- nautilus_string_list_free (tokenized_string);
-
- for (i = 0; i < num_font_sizes; i++) {
- guint text_width;
- guint text_height;
-
- nautilus_scalable_font_measure_text (font,
- font_sizes[i],
- font_sizes[i],
- longest_string,
- &text_width,
- &text_height);
-
- if (text_width <= available_width) {
- g_free (longest_string);
- return font_sizes[i];
- }
- }
-
- g_free (longest_string);
-
- return font_sizes[num_font_sizes - 1];
-}
-
-void
nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
GdkPixbuf *destination_pixbuf,
const ArtIRect *destination_area,
guint font_width,
guint font_height,
const char *text,
+ guint text_length,
guint32 color,
guchar overall_alpha)
{
@@ -774,15 +684,18 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
g_return_if_fail (font_width > 0);
g_return_if_fail (font_height > 0);
- if (text == NULL) {
+ if (text == NULL || text[0] == '\0' || text_length == 0) {
return;
}
+ g_return_if_fail (text_length <= strlen (text));
+
art_affine_identity (affine);
glyph = rsvg_ft_render_string (global_rsvg_ft_context,
font->detail->font_handle,
text,
+ text_length,
font_width,
font_height,
affine,
@@ -837,6 +750,57 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
rsvg_ft_glyph_unref (glyph);
}
+#if 0
+void
+nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ guint num_text_lines,
+ guint text_line_widths[],
+ guint text_line_heights[],
+ guint *max_width_out,
+ guint *total_height_out)
+{
+ guint i;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text_lines != NULL);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (num_text_lines > 0);
+
+ if (max_width_out != NULL) {
+ *max_width_out = 0;
+ }
+
+ if (total_height_out != NULL) {
+ *total_height_out = 0;
+ }
+
+ for (i = 0; i < num_text_lines; i++) {
+ g_assert (text_lines[i] != NULL);
+
+ nautilus_scalable_font_measure_text (font,
+ font_width,
+ font_height,
+ text_lines[i],
+ strlen (text_lines[i]),
+ &text_line_widths[i],
+ &text_line_heights[i]);
+
+ if (total_height_out != NULL) {
+ *total_height_out += text_line_heights[i];
+ }
+
+ if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) {
+ *max_width_out = text_line_widths[i];
+ }
+ }
+}
+
void
nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
GdkPixbuf *destination_pixbuf,
@@ -883,48 +847,310 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
ArtIRect area;
g_assert (text_lines[i] != NULL);
- g_assert (text_line_widths[i] > 0);
- g_assert (text_line_heights[i] > 0);
-
- switch (justification) {
- case GTK_JUSTIFY_LEFT:
- area.x0 = x;
- break;
-
- case GTK_JUSTIFY_CENTER:
- case GTK_JUSTIFY_FILL:
- if (text_line_widths[i] <= available_width) {
- area.x0 = x + ((available_width - text_line_widths[i]) / 2);
- }
- else {
- area.x0 = x - ((text_line_widths[i] - available_width) / 2);
+
+ if (text_line_widths[i] == 0 && text_line_heights[i] == 0) {
+ y += font_height;
+ }
+ else {
+ switch (justification) {
+ case GTK_JUSTIFY_LEFT:
+ area.x0 = x;
+ break;
+
+ case GTK_JUSTIFY_CENTER:
+ case GTK_JUSTIFY_FILL:
+ if (text_line_widths[i] <= available_width) {
+ area.x0 = x + ((available_width - text_line_widths[i]) / 2);
+ }
+ else {
+ area.x0 = x - ((text_line_widths[i] - available_width) / 2);
+ }
+ break;
+
+ case GTK_JUSTIFY_RIGHT:
+ area.x0 = x + available_width - text_line_widths[i];
+ break;
+
+ default:
+ g_assert_not_reached ();
}
- break;
+
+ area.x1 = area.x0 + text_line_widths[i];
+ area.y0 = y;
+ area.y1 = area.y0 + text_line_heights[i];
+
+ nautilus_scalable_font_draw_text (font,
+ destination_pixbuf,
+ &area,
+ font_width,
+ font_height,
+ text_lines[i],
+ strlen (text_lines[i]),
+ color,
+ overall_alpha);
+
+ y += (line_offset + text_line_heights[i]);
+ }
+ }
+}
+#else
+void
+nautilus_scalable_font_measure_text_lines (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)
+{
+ guint i;
+ const char *line;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text != NULL);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (num_text_lines > 0);
+ g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1));
- case GTK_JUSTIFY_RIGHT:
- area.x0 = x + available_width - text_line_widths[i];
- break;
+ if (max_width_out != NULL) {
+ *max_width_out = 0;
+ }
- default:
- g_assert_not_reached ();
+ if (total_height_out != NULL) {
+ *total_height_out = 0;
+ }
+
+ line = text;
+
+ /*
+ * We can safely iterate for 'num_text_lines' since we already checked that the
+ * string does indeed contain as many lines.
+ */
+ for (i = 0; i < num_text_lines; i++) {
+ const char *next_new_line;
+ guint length;
+
+ g_assert (line != NULL);
+
+ /* Look for the next new line */
+ next_new_line = strchr (line, '\n');
+
+ if (next_new_line != NULL) {
+ length = (next_new_line - line);
+ }
+ else {
+ length = strlen (line);
+ }
+
+ /* Deal with empty lines */
+ if (length == 0) {
+ text_line_widths[i] = 0;
+ text_line_heights[i] = font_height;
+ }
+ else {
+ nautilus_scalable_font_measure_text (font,
+ font_width,
+ font_height,
+ line,
+ length,
+ &text_line_widths[i],
+ &text_line_heights[i]);
+ }
+
+ if (next_new_line != NULL) {
+ line = next_new_line + 1;
+ }
+ else {
+ line = NULL;
}
+
+ /* Keep track of total height */
+ if (total_height_out != NULL) {
+ *total_height_out += text_line_heights[i];
+ }
+
+ /* Keep track of max width */
+ if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) {
+ *max_width_out = text_line_widths[i];
+ }
+ }
+}
- area.x1 = area.x0 + text_line_widths[i];
- area.y0 = y;
- area.y1 = area.y0 + text_line_heights[i];
+void
+nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_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;
- nautilus_scalable_font_draw_text (font,
- destination_pixbuf,
- &area,
- font_width,
- font_height,
- text_lines[i],
- color,
- overall_alpha);
+ gint x;
+ gint y;
- y += (line_offset + text_line_heights[i]);
+ guint available_width;
+ guint available_height;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (destination_pixbuf != NULL);
+ g_return_if_fail (destination_area != NULL);
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL);
+ g_return_if_fail (destination_area->x1 > destination_area->x0);
+ g_return_if_fail (destination_area->y1 > destination_area->y0);
+ g_return_if_fail (num_text_lines > 0);
+ g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1));
+
+ x = destination_area->x0;
+ y = destination_area->y0;
+
+ available_width = destination_area->x1 - destination_area->x0;
+ available_height = destination_area->y1 - destination_area->y0;
+
+ line = text;
+
+ /*
+ * We can safely iterate for 'num_text_lines' since we already checked that the
+ * string does indeed contain as many lines.
+ */
+ for (i = 0; i < num_text_lines; i++) {
+ const char *next_new_line;
+ guint length;
+
+ g_assert (line != NULL);
+
+ /* Look for the next new line */
+ next_new_line = strchr (line, '\n');
+
+ if (next_new_line != NULL) {
+ length = (next_new_line - line);
+ }
+ else {
+ length = strlen (line);
+ }
+
+ /* Deal with empty lines */
+ if (length == 0) {
+ y += font_height;
+ }
+ else {
+ ArtIRect area;
+
+ switch (justification) {
+ case GTK_JUSTIFY_LEFT:
+ area.x0 = x;
+ break;
+
+ case GTK_JUSTIFY_CENTER:
+ case GTK_JUSTIFY_FILL:
+ if (text_line_widths[i] <= available_width) {
+ area.x0 = x + ((available_width - text_line_widths[i]) / 2);
+ }
+ else {
+ area.x0 = x - ((text_line_widths[i] - available_width) / 2);
+ }
+ break;
+
+ case GTK_JUSTIFY_RIGHT:
+ area.x0 = x + available_width - text_line_widths[i];
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ area.x1 = area.x0 + text_line_widths[i];
+ area.y0 = y;
+ area.y1 = area.y0 + text_line_heights[i];
+
+ nautilus_scalable_font_draw_text (font,
+ destination_pixbuf,
+ &area,
+ font_width,
+ font_height,
+ line,
+ length,
+ color,
+ overall_alpha);
+
+ y += (line_offset + text_line_heights[i]);
+ }
+
+ if (next_new_line != NULL) {
+ line = next_new_line + 1;
+ }
+ else {
+ line = NULL;
+ }
}
}
+#endif
+
+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)
+{
+ NautilusStringList *tokenized_string;
+ guint i;
+ char *longest_string;
+ guint longest_string_length;
+
+ g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0);
+ g_return_val_if_fail (font_sizes != NULL, 0);
+ g_return_val_if_fail (num_font_sizes > 0, 0);
+
+ if (text == NULL || text[0] == '\0' || available_width < 1) {
+ return font_sizes[num_font_sizes - 1];
+ }
+
+ tokenized_string = nautilus_string_list_new_from_tokens (text, "\n", FALSE);
+ longest_string = nautilus_string_list_get_longest_string (tokenized_string);
+ g_assert (longest_string != NULL);
+ nautilus_string_list_free (tokenized_string);
+ longest_string_length = strlen (longest_string);
+
+ for (i = 0; i < num_font_sizes; i++) {
+ guint text_width;
+ guint text_height;
+
+ nautilus_scalable_font_measure_text (font,
+ font_sizes[i],
+ font_sizes[i],
+ longest_string,
+ longest_string_length,
+ &text_width,
+ &text_height);
+
+ if (text_width <= available_width) {
+ g_free (longest_string);
+ return font_sizes[i];
+ }
+ }
+
+ g_free (longest_string);
+
+ return font_sizes[num_font_sizes - 1];
+}
NautilusScalableFont *
nautilus_scalable_font_get_default_font (void)
diff --git a/libnautilus-private/nautilus-scalable-font.h b/libnautilus-private/nautilus-scalable-font.h
index 9528cf5f6..7333b1639 100644
--- a/libnautilus-private/nautilus-scalable-font.h
+++ b/libnautilus-private/nautilus-scalable-font.h
@@ -81,35 +81,37 @@ void nautilus_scalable_font_measure_text (const N
guint font_width,
guint font_height,
const char *text,
+ guint text_length,
guint *text_width_out,
guint *text_height_out);
-void nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
- guint font_width,
- guint font_height,
- const char *text_lines[],
- 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 (const NautilusScalableFont *font,
GdkPixbuf *destination_pixbuf,
const ArtIRect *destination_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 (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,
const ArtIRect *destination_area,
guint font_width,
guint font_height,
- const char *text_lines[],
+ const char *text,
+ guint num_text_lines,
const guint text_line_widths[],
const guint text_line_heights[],
GtkJustification justification,
- const guint num_lines,
guint line_offset,
guint32 color,
guchar overall_alpha);
diff --git a/librsvg/rsvg-ft.c b/librsvg/rsvg-ft.c
index 214fc4bda..c035b71db 100644
--- a/librsvg/rsvg-ft.c
+++ b/librsvg/rsvg-ft.c
@@ -618,12 +618,13 @@ rsvg_ft_get_glyph_cached (RsvgFTCtx *ctx, RsvgFTFontHandle fh,
**/
RsvgFTGlyph *
rsvg_ft_render_string (RsvgFTCtx *ctx, RsvgFTFontHandle fh,
- const char *str, double sx, double sy,
+ const char *str,
+ unsigned int length,
+ double sx, double sy,
const double affine[6], int xy[2])
{
RsvgFTFont *font;
RsvgFTGlyph *result;
- const int len = strlen (str);
RsvgFTGlyph **glyphs;
int *glyph_xy;
int i, j;
@@ -636,14 +637,18 @@ rsvg_ft_render_string (RsvgFTCtx *ctx, RsvgFTFontHandle fh,
int n_glyphs;
double init_x, init_y;
+ g_return_val_if_fail (ctx != NULL, NULL);
+ g_return_val_if_fail (str != NULL, NULL);
+ g_return_val_if_fail (length <= strlen (str), NULL);
+
font = rsvg_ft_font_resolve (ctx, fh);
if (font == NULL)
return NULL;
bbox.x0 = bbox.x1 = 0;
- glyphs = g_new (RsvgFTGlyph *, len);
- glyph_xy = g_new (int, len * 2);
+ glyphs = g_new (RsvgFTGlyph *, length);
+ glyph_xy = g_new (int, length * 2);
for (j = 0; j < 6; j++)
glyph_affine[j] = affine[j];
@@ -651,7 +656,7 @@ rsvg_ft_render_string (RsvgFTCtx *ctx, RsvgFTFontHandle fh,
init_x = affine[4];
init_y = affine[5];
n_glyphs = 0;
- for (i = 0; i < len; i++) {
+ for (i = 0; i < length; i++) {
RsvgFTGlyph *glyph;
glyph_index = FT_Get_Char_Index (font->face,
diff --git a/librsvg/rsvg-ft.h b/librsvg/rsvg-ft.h
index 693c949a6..69b441eb8 100644
--- a/librsvg/rsvg-ft.h
+++ b/librsvg/rsvg-ft.h
@@ -34,7 +34,9 @@ rsvg_ft_font_unref (RsvgFTFont *font);
RsvgFTGlyph *
rsvg_ft_render_string (RsvgFTCtx *ctx, RsvgFTFontHandle fh,
- const char *str, double sx, double sy,
+ const char *str,
+ unsigned int length,
+ double sx, double sy,
const double affine[6], int xy[2]);
void
diff --git a/librsvg/rsvg.c b/librsvg/rsvg.c
index 8582e94a1..c00eab4c6 100644
--- a/librsvg/rsvg.c
+++ b/librsvg/rsvg.c
@@ -803,7 +803,9 @@ rsvg_text_handler_characters (RsvgSaxHandler *self, const xmlChar *ch, int len)
has_alpha ? ART_ALPHA_SEPARATE : ART_ALPHA_NONE,
NULL);
- glyph = rsvg_ft_render_string (ctx->ft_ctx, fh, string,
+ glyph = rsvg_ft_render_string (ctx->ft_ctx, fh,
+ string,
+ strlen (string),
state->font_size, state->font_size,
state->affine, glyph_xy);
diff --git a/librsvg/test-ft-gtk.c b/librsvg/test-ft-gtk.c
index 5268b8cfb..ce907afe6 100644
--- a/librsvg/test-ft-gtk.c
+++ b/librsvg/test-ft-gtk.c
@@ -132,6 +132,7 @@ static void draw_line (TestCtx *ctx, int line_num, ArtIRect *rect)
glyph = rsvg_ft_render_string (ctx->ctx, ctx->fh,
ctx->lines[line_num],
+ strlen (ctx->lines[line_num]),
14, 14,
affine,
glyph_xy);
diff --git a/librsvg/test-ft.c b/librsvg/test-ft.c
index 3401d4c8a..d21eadcf5 100644
--- a/librsvg/test-ft.c
+++ b/librsvg/test-ft.c
@@ -377,6 +377,7 @@ int main(int argc, char **argv)
glyph = rsvg_ft_render_string (ctx, fh,
"graphic(s)",
+ strlen ("graphic(s)"),
font_width,
font_height,
affine,
diff --git a/src/nautilus-about.c b/src/nautilus-about.c
index 61d4461a3..688afba08 100644
--- a/src/nautilus-about.c
+++ b/src/nautilus-about.c
@@ -192,7 +192,7 @@ draw_aa_string (NautilusScalableFont *font, GdkPixbuf *pixbuf, int font_size, in
ArtIRect dest_rect;
int text_width, text_height;
- nautilus_scalable_font_measure_text (font, font_size, font_size, text, &text_width, &text_height);
+ nautilus_scalable_font_measure_text (font, font_size, font_size, text, strlen (text), &text_width, &text_height);
/* draw the title in shadowed text*/
@@ -204,13 +204,13 @@ draw_aa_string (NautilusScalableFont *font, GdkPixbuf *pixbuf, int font_size, in
if (shadow_offset) {
dest_rect.x0 += shadow_offset;
dest_rect.y0 += shadow_offset;
- nautilus_scalable_font_draw_text (font, pixbuf, &dest_rect, font_size, font_size, text, shadow_color, 255);
+ nautilus_scalable_font_draw_text (font, pixbuf, &dest_rect, font_size, font_size, text, strlen (text), shadow_color, 255);
dest_rect.x0 -= shadow_offset;
dest_rect.y0 -= shadow_offset;
}
- nautilus_scalable_font_draw_text (font, pixbuf, &dest_rect, font_size, font_size, text, color, 255);
+ nautilus_scalable_font_draw_text (font, pixbuf, &dest_rect, font_size, font_size, text, strlen (text), color, 255);
}
/* draw the information onto the pixbuf */
diff --git a/src/nautilus-sidebar-tabs.c b/src/nautilus-sidebar-tabs.c
index f02384969..7f7009f0a 100644
--- a/src/nautilus-sidebar-tabs.c
+++ b/src/nautilus-sidebar-tabs.c
@@ -489,8 +489,13 @@ draw_one_tab_plain (NautilusSidebarTabs *sidebar_tabs, GdkGC *gc,
g_assert (NAUTILUS_IS_SIDEBAR_TABS (sidebar_tabs));
/* measure the name and compute the bounding box */
- nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font, sidebar_tabs->details->font_size, sidebar_tabs->details->font_size,
- tab_name, &name_width, &name_height);
+ nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font,
+ sidebar_tabs->details->font_size,
+ sidebar_tabs->details->font_size,
+ tab_name,
+ strlen (tab_name),
+ &name_width,
+ &name_height);
total_width = name_width + 2*TAB_MARGIN;
@@ -535,13 +540,15 @@ draw_one_tab_plain (NautilusSidebarTabs *sidebar_tabs, GdkGC *gc,
nautilus_scalable_font_draw_text (sidebar_tabs->details->tab_font, temp_pixbuf, &text_rect,
sidebar_tabs->details->font_size, sidebar_tabs->details->font_size,
- tab_name, prelight_flag ? NAUTILUS_RGB_COLOR_WHITE : NAUTILUS_RGB_COLOR_BLACK, 255);
+ tab_name, strlen (tab_name),
+ prelight_flag ? NAUTILUS_RGB_COLOR_WHITE : NAUTILUS_RGB_COLOR_BLACK, 255);
text_rect.x0 -= 1;
text_rect.y0 -= 1;
nautilus_scalable_font_draw_text (sidebar_tabs->details->tab_font, temp_pixbuf, &text_rect,
sidebar_tabs->details->font_size, sidebar_tabs->details->font_size,
- tab_name, prelight_flag ? NAUTILUS_RGB_COLOR_BLACK : NAUTILUS_RGB_COLOR_WHITE, 255);
+ tab_name, strlen (tab_name),
+ prelight_flag ? NAUTILUS_RGB_COLOR_BLACK : NAUTILUS_RGB_COLOR_WHITE, 255);
/* blit the pixbuf to the drawable, then release it */
@@ -642,8 +649,13 @@ draw_one_tab_themed (NautilusSidebarTabs *sidebar_tabs, GdkPixbuf *tab_pixbuf,
}
/* measure the size of the name */
- nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font, sidebar_tabs->details->font_size, sidebar_tabs->details->font_size,
- tab_name, &name_width, &name_height);
+ nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font,
+ sidebar_tabs->details->font_size,
+ sidebar_tabs->details->font_size,
+ tab_name,
+ strlen (tab_name),
+ &name_width,
+ &name_height);
/* draw the left edge piece */
current_pos = x - widget->allocation.x;
@@ -673,12 +685,14 @@ draw_one_tab_themed (NautilusSidebarTabs *sidebar_tabs, GdkPixbuf *tab_pixbuf,
nautilus_scalable_font_draw_text (sidebar_tabs->details->tab_font, tab_pixbuf, &text_rect,
sidebar_tabs->details->font_size, sidebar_tabs->details->font_size,
- tab_name, NAUTILUS_RGB_COLOR_BLACK, 255);
+ tab_name, strlen (tab_name),
+ NAUTILUS_RGB_COLOR_BLACK, 255);
text_rect.x0 -= 1;
text_rect.y0 -= 1;
nautilus_scalable_font_draw_text (sidebar_tabs->details->tab_font, tab_pixbuf, &text_rect,
sidebar_tabs->details->font_size, sidebar_tabs->details->font_size,
- tab_name, NAUTILUS_RGB_COLOR_WHITE, 255);
+ tab_name, strlen (tab_name),
+ NAUTILUS_RGB_COLOR_WHITE, 255);
/* set up the bounds rectangle for later hit-testing */
if (tab_rect) {
@@ -725,8 +739,13 @@ get_tab_width (NautilusSidebarTabs *sidebar_tabs, TabItem *this_tab, gboolean is
edge_width = gdk_pixbuf_get_width (sidebar_tabs->details->tab_piece_images[TAB_NORMAL_LEFT]);
else
edge_width = 0;
- nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font, sidebar_tabs->details->font_size, sidebar_tabs->details->font_size,
- this_tab->tab_text, &name_width, &name_height);
+ nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font,
+ sidebar_tabs->details->font_size,
+ sidebar_tabs->details->font_size,
+ this_tab->tab_text,
+ strlen (this_tab->tab_text),
+ &name_width,
+ &name_height);
} else {
edge_width = 2 * TAB_MARGIN;
diff --git a/test/test-nautilus-font.c b/test/test-nautilus-font.c
index 5a212b084..8e72eb99f 100644
--- a/test/test-nautilus-font.c
+++ b/test/test-nautilus-font.c
@@ -18,55 +18,76 @@
#include <libnautilus-extensions/nautilus-scalable-font.h>
#include <libnautilus-extensions/nautilus-label.h>
#include <libnautilus-extensions/nautilus-image.h>
+#include <libnautilus-extensions/nautilus-string.h>
int
main (int argc, char* argv[])
{
GdkPixbuf *pixbuf;
- guint text_width;
- guint text_height;
ArtIRect area;
NautilusScalableFont *font;
+ guint num_text_lines;
+ char **text_lines;
+ guint *text_line_widths;
+ guint *text_line_heights;
+ guint max_width_out;
+ guint total_height_out;
- const char *text = "Something";
- const guint font_width = 64;
- const guint font_height = 64;
+ const char *text = "\nLine Two\n\nLine Four\n\n\nLine Seven\n";
+ const guint font_width = 48;
+ const guint font_height = 48;
+
+ const guint pixbuf_width = 500;
+ const guint pixbuf_height = 700;
gtk_init (&argc, &argv);
gdk_rgb_init ();
font = NAUTILUS_SCALABLE_FONT (nautilus_scalable_font_new ("Nimbus Sans L", NULL, NULL, NULL));
g_assert (font != NULL);
-
- nautilus_scalable_font_measure_text (font,
- font_width,
- font_height,
- text,
- &text_width,
- &text_height);
-
- g_print ("size of '%s' = (%d,%d)\n", text, text_width, text_height);
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 512, 256);
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, pixbuf_width, pixbuf_height);
g_assert (pixbuf != NULL);
area.x0 = 0;
area.y0 = 0;
- area.x1 = 512;
- area.y1 = 256;
-
- nautilus_scalable_font_draw_text (font,
- pixbuf,
- &area,
- font_width,
- font_height,
- text,
- NAUTILUS_RGB_COLOR_RED,
- 255);
+ area.x1 = pixbuf_width;
+ area.y1 = pixbuf_height;
- g_assert (pixbuf != NULL);
+ num_text_lines = nautilus_str_count_characters (text, '\n') + 1;
+
+ text_lines = g_strsplit (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);
+
+ nautilus_scalable_font_draw_text_lines (font,
+ pixbuf,
+ &area,
+ font_width,
+ font_height,
+ text,
+ num_text_lines,
+ text_line_widths,
+ text_line_heights,
+ GTK_JUSTIFY_LEFT,
+ 2,
+ NAUTILUS_RGB_COLOR_RED,
+ 255);
+
nautilus_gdk_pixbuf_save_to_file (pixbuf, "font_test.png");
g_print ("saving test png file to font_test.png\n");
diff --git a/test/test-nautilus-label.c b/test/test-nautilus-label.c
index 70b50a61e..74fbc0d38 100644
--- a/test/test-nautilus-label.c
+++ b/test/test-nautilus-label.c
@@ -196,7 +196,7 @@ alpha_background_color_value_changed_callback (GtkAdjustment *adjustment, gpoint
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
-
+
label = NAUTILUS_LABEL (client_data);
nautilus_label_set_text_alpha (NAUTILUS_LABEL (label), (guchar) adjustment->value);
@@ -753,7 +753,7 @@ main (int argc, char* argv[])
main_box = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), main_box);
- label = nautilus_label_new ("Label that \ndoesn't suck\nFoo\nBar");
+ label = nautilus_label_new ("Label that\n\ndoesn't\n\nsuck");
bottom_box = gtk_vbox_new (FALSE, 4);