mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-08-25 02:36:07 +00:00
New function to draw text into a pixbuf given a rect and a string.
* libnautilus-extensions/nautilus-gdk-pixbuf-extensions.c: (nautilus_gdk_pixbuf_scale_to_fit), (nautilus_gdk_pixbuf_draw_text): * libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h: New function to draw text into a pixbuf given a rect and a string. Factored from the icon factoyr. * libnautilus-extensions/nautilus-graphic.c: (nautilus_graphic_size_allocate): Add support for drawing text. * libnautilus-extensions/nautilus-icon-factory.c: (embed_text): Factored out gdk pixbuf text drawing. Use the new text drawing function. * test/test-nautilus-graphic.c: (create_color_scale): Update for text support.
This commit is contained in:
parent
5730af3995
commit
4fdb98d8e0
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
|||
2000-07-10 Ramiro Estrugo <ramiro@eazel.com>
|
||||
|
||||
* libnautilus-extensions/nautilus-gdk-pixbuf-extensions.c:
|
||||
(nautilus_gdk_pixbuf_scale_to_fit),
|
||||
(nautilus_gdk_pixbuf_draw_text):
|
||||
* libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h:
|
||||
New function to draw text into a pixbuf given a rect and a
|
||||
string. Factored from the icon factoyr.
|
||||
* libnautilus-extensions/nautilus-graphic.c:
|
||||
(nautilus_graphic_size_allocate):
|
||||
Add support for drawing text.
|
||||
|
||||
* libnautilus-extensions/nautilus-icon-factory.c: (embed_text):
|
||||
Factored out gdk pixbuf text drawing. Use the new text drawing
|
||||
function.
|
||||
|
||||
* test/test-nautilus-graphic.c: (create_color_scale):
|
||||
Update for text support.
|
||||
|
||||
2000-07-10 Gene Z. Ragan <gzr@eazel.com>
|
||||
|
||||
* libnautilus-extensions/nautilus-gdk-extensions.c:
|
||||
|
|
|
@ -25,11 +25,13 @@
|
|||
#include <config.h>
|
||||
#include <math.h>
|
||||
#include "nautilus-gdk-pixbuf-extensions.h"
|
||||
#include "nautilus-gdk-extensions.h"
|
||||
#include "nautilus-glib-extensions.h"
|
||||
#include "nautilus-string.h"
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf-loader.h>
|
||||
#include <libgnomevfs/gnome-vfs-ops.h>
|
||||
#include <libgnomevfs/gnome-vfs-async-ops.h>
|
||||
#include <libgnomevfs/gnome-vfs-ops.h>
|
||||
|
||||
#define LOAD_BUFFER_SIZE 4096
|
||||
|
||||
|
@ -391,3 +393,134 @@ nautilus_gdk_pixbuf_scale_to_fit (GdkPixbuf *pixbuf, int max_width, int max_heig
|
|||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* nautilus_gdk_pixbuf_draw_text
|
||||
* @pixbuf: A GdkPixbuf.
|
||||
* @font: A GdkFont.
|
||||
* @destination_rect: An ArtIRect - the destination bounding box for the text.
|
||||
* @text: A string - the text to draw.
|
||||
* @overall_alpha: The overall alpha to use when compositing the text on the pixbuf
|
||||
*
|
||||
* Draw text onto a GdkPixbuf using the given font and rect
|
||||
**/
|
||||
void
|
||||
nautilus_gdk_pixbuf_draw_text (GdkPixbuf *pixbuf,
|
||||
const GdkFont *font,
|
||||
const ArtIRect *destination_rect,
|
||||
const char *text,
|
||||
guint overall_alpha)
|
||||
{
|
||||
ArtIRect pixbuf_rect;
|
||||
ArtIRect text_rect;
|
||||
int width, height;
|
||||
GdkVisual *visual;
|
||||
GdkPixmap *pixmap;
|
||||
GdkGC *gc;
|
||||
GdkColormap *colormap;
|
||||
int y;
|
||||
const char *line;
|
||||
const char *end_of_line;
|
||||
int line_length;
|
||||
GdkPixbuf *text_pixbuf;
|
||||
GdkPixbuf *text_pixbuf_with_alpha;
|
||||
guchar *pixels;
|
||||
|
||||
g_return_if_fail (pixbuf != NULL);
|
||||
g_return_if_fail (font != NULL);
|
||||
g_return_if_fail (destination_rect != NULL);
|
||||
g_return_if_fail (text != NULL);
|
||||
g_return_if_fail (nautilus_strlen (text) > 0);
|
||||
g_return_if_fail (overall_alpha <= 255);
|
||||
|
||||
/* Compute the intersection of the text rectangle with the pixbuf.
|
||||
* This is only to prevent pathological cases from upsetting the
|
||||
* GdkPixbuf routines. It should not happen in any normal circumstance.
|
||||
*/
|
||||
pixbuf_rect.x0 = 0;
|
||||
pixbuf_rect.y0 = 0;
|
||||
pixbuf_rect.x1 = gdk_pixbuf_get_width (pixbuf);
|
||||
pixbuf_rect.y1 = gdk_pixbuf_get_height (pixbuf);
|
||||
art_irect_intersect (&text_rect, destination_rect, &pixbuf_rect);
|
||||
|
||||
/* Get the system visual. I wish I could do this all in 1-bit mode,
|
||||
* but I can't.
|
||||
*/
|
||||
visual = gdk_visual_get_system ();
|
||||
|
||||
/* Allocate a GdkPixmap of the appropriate size. */
|
||||
width = text_rect.x1 - text_rect.x0;
|
||||
height = text_rect.y1 - text_rect.y0;
|
||||
pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);
|
||||
gc = gdk_gc_new (pixmap);
|
||||
|
||||
/* Set up a white background. */
|
||||
gdk_rgb_gc_set_foreground (gc, NAUTILUS_RGB_COLOR_WHITE);
|
||||
gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, width, height);
|
||||
|
||||
/* Draw black text. */
|
||||
gdk_rgb_gc_set_foreground (gc, NAUTILUS_RGB_COLOR_BLACK);
|
||||
gdk_gc_set_font (gc, (GdkFont *) font);
|
||||
line = text;
|
||||
|
||||
/* FIXME bugzilla.eazel.com xxxx:
|
||||
* The iteration code should work with strings that dont have
|
||||
* new lines. Its broken right now for single line strings. The
|
||||
* (y + font->ascent) <= height test always fails and no text is drawn.
|
||||
*/
|
||||
if (strchr (line, '\n')) {
|
||||
for (y = font->ascent;
|
||||
y + font->descent <= height;
|
||||
y += font->ascent + font->descent) {
|
||||
|
||||
/* Extract the next line of text. */
|
||||
end_of_line = strchr (line, '\n');
|
||||
line_length = end_of_line == NULL
|
||||
? strlen (line)
|
||||
: end_of_line - line;
|
||||
|
||||
/* Draw the next line of text. */
|
||||
gdk_draw_text (pixmap, (GdkFont *) font, gc, 0, y,
|
||||
line, line_length);
|
||||
|
||||
/* Move on to the subsequent line. */
|
||||
line = end_of_line == NULL
|
||||
? ""
|
||||
: end_of_line + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Draw the next line of text. */
|
||||
gdk_draw_text (pixmap, (GdkFont *) font, gc, 0, font->ascent,
|
||||
line, strlen (line));
|
||||
}
|
||||
gdk_gc_unref (gc);
|
||||
|
||||
/* Convert into a GdkPixbuf with gdk_pixbuf_get_from_drawable. */
|
||||
colormap = gdk_colormap_new (visual, FALSE);
|
||||
text_pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap,
|
||||
0, 0,
|
||||
0, 0, width, height);
|
||||
gdk_colormap_unref (colormap);
|
||||
gdk_pixmap_unref (pixmap);
|
||||
|
||||
/* White is not always FF FF FF. So we get the top left corner pixel. */
|
||||
pixels = gdk_pixbuf_get_pixels (text_pixbuf);
|
||||
text_pixbuf_with_alpha = gdk_pixbuf_add_alpha
|
||||
(text_pixbuf,
|
||||
TRUE, pixels[0], pixels[1], pixels[2]);
|
||||
gdk_pixbuf_unref (text_pixbuf);
|
||||
|
||||
gdk_pixbuf_composite (text_pixbuf_with_alpha,
|
||||
pixbuf,
|
||||
text_rect.x0,
|
||||
text_rect.y0,
|
||||
width, height,
|
||||
text_rect.x0,
|
||||
text_rect.y0,
|
||||
1, 1,
|
||||
GDK_INTERP_BILINEAR,
|
||||
overall_alpha);
|
||||
|
||||
gdk_pixbuf_unref (text_pixbuf_with_alpha);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <libgnomevfs/gnome-vfs-types.h>
|
||||
#include <libart_lgpl/art_rect.h>
|
||||
|
||||
typedef struct NautilusPixbufLoadHandle NautilusPixbufLoadHandle;
|
||||
typedef void (* NautilusPixbufLoadCallback) (GnomeVFSResult error,
|
||||
|
@ -38,15 +39,18 @@ void nautilus_gdk_pixbuf_list_ref (GList
|
|||
void nautilus_gdk_pixbuf_list_unref (GList *pixbuf_list);
|
||||
void nautilus_gdk_pixbuf_list_free (GList *pixbuf_list);
|
||||
|
||||
|
||||
/* Loading a GdkPixbuf with a URI. */
|
||||
GdkPixbuf * nautilus_gdk_pixbuf_load (const char *uri);
|
||||
|
||||
|
||||
/* Same thing async. */
|
||||
NautilusPixbufLoadHandle *nautilus_gdk_pixbuf_load_async (const char *uri,
|
||||
NautilusPixbufLoadCallback callback,
|
||||
gpointer callback_data);
|
||||
void nautilus_cancel_gdk_pixbuf_load (NautilusPixbufLoadHandle *handle);
|
||||
|
||||
|
||||
/* Draw a GdkPixbuf tiled. */
|
||||
void nautilus_gdk_pixbuf_render_to_drawable_tiled (GdkPixbuf *pixbuf,
|
||||
GdkDrawable *drawable,
|
||||
|
@ -58,8 +62,16 @@ void nautilus_gdk_pixbuf_render_to_drawable_tiled (GdkPixbu
|
|||
GdkPixbuf * nautilus_gdk_pixbuf_scale_to_fit (GdkPixbuf *pixbuf,
|
||||
int max_width,
|
||||
int max_height);
|
||||
|
||||
/* return average color values for each component */
|
||||
void nautilus_gdk_pixbuf_average_value (GdkPixbuf *pixbuf,
|
||||
GdkColor *result_color);
|
||||
|
||||
void nautilus_gdk_pixbuf_average_value (GdkPixbuf *pixbuf,
|
||||
GdkColor *result_color);
|
||||
|
||||
/* Draw text onto a GdkPixbuf using the given font and rect */
|
||||
void nautilus_gdk_pixbuf_draw_text (GdkPixbuf *pixbuf,
|
||||
const GdkFont *font,
|
||||
const ArtIRect *destination_rect,
|
||||
const char *text,
|
||||
guint overall_alpha);
|
||||
|
||||
#endif /* NAUTILUS_GDK_PIXBUF_EXTENSIONS_H */
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nautilus-graphic.h"
|
||||
#include "nautilus-gtk-macros.h"
|
||||
#include "nautilus-gdk-extensions.h"
|
||||
#include "nautilus-gdk-pixbuf-extensions.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
@ -576,17 +577,12 @@ nautilus_graphic_size_allocate (GtkWidget *widget, GtkAllocation* allocation)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* FIXME bugzilla.eazel.com 1613:
|
||||
* Need to factor out code in nautilus-icon-factory.c:embed_text() into
|
||||
* nautilus_gdk_pixbuf_draw_text and use it here.
|
||||
*/
|
||||
#if FIXME
|
||||
if (graphic ->detail->label_text != NULL)
|
||||
{
|
||||
GtkRequisition text_size;
|
||||
gint x;
|
||||
gint y;
|
||||
ArtIRect text_rect;
|
||||
|
||||
g_assert (graphic->detail->label_font != NULL);
|
||||
|
||||
|
@ -594,19 +590,23 @@ nautilus_graphic_size_allocate (GtkWidget *widget, GtkAllocation* allocation)
|
|||
graphic ->detail->label_text,
|
||||
&text_size);
|
||||
|
||||
|
||||
x = (widget->allocation.width - text_size.width) / 2;
|
||||
y = (widget->allocation.height - text_size.height) / 2;
|
||||
|
||||
text_rect.x0 = x;
|
||||
text_rect.y0 = y;
|
||||
text_rect.x1 = x + text_size.width;
|
||||
text_rect.y1 = y + text_size.height;
|
||||
|
||||
/* FIXME bugzilla.eazel.com xxxx:
|
||||
* Need to be able to pass in a rgb colot into the draw_text function.
|
||||
*/
|
||||
nautilus_gdk_pixbuf_draw_text (graphic->detail->buffer,
|
||||
graphic->detail->label_font,
|
||||
x,
|
||||
y,
|
||||
&text_rect,
|
||||
graphic->detail->label_text,
|
||||
strlen (graphic->detail->label_text),
|
||||
NAUTILUS_RGBA_COLOR_PACK (255, 0, 0, NAUTILUS_ALPHA_NONE));
|
||||
graphic->detail->overall_alpha);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -2038,19 +2038,10 @@ embed_text (GdkPixbuf *pixbuf_without_text,
|
|||
const ArtIRect *embedded_text_rect,
|
||||
const char *text)
|
||||
{
|
||||
|
||||
static GdkFont *font;
|
||||
|
||||
ArtIRect pixbuf_rect, text_rect;
|
||||
int width, height;
|
||||
GdkVisual *visual;
|
||||
GdkPixmap *pixmap;
|
||||
GdkGC *gc;
|
||||
GdkColormap *colormap;
|
||||
int y;
|
||||
const char *line, *end_of_line;
|
||||
int line_length;
|
||||
GdkPixbuf *text_pixbuf, *text_pixbuf_with_alpha, *pixbuf_with_text;
|
||||
guchar *pixels;
|
||||
GdkPixbuf *pixbuf_with_text;
|
||||
|
||||
g_return_val_if_fail (pixbuf_without_text != NULL, NULL);
|
||||
g_return_val_if_fail (embedded_text_rect != NULL, gdk_pixbuf_ref (pixbuf_without_text));
|
||||
|
@ -2071,84 +2062,10 @@ embed_text (GdkPixbuf *pixbuf_without_text,
|
|||
return gdk_pixbuf_ref (pixbuf_without_text);
|
||||
}
|
||||
|
||||
/* Compute the intersection of the text rectangle with the pixbuf.
|
||||
* This is only to prevent pathological cases from upsetting the
|
||||
* GdkPixbuf routines. It should not happen in any normal circumstance.
|
||||
*/
|
||||
pixbuf_rect.x0 = 0;
|
||||
pixbuf_rect.y0 = 0;
|
||||
pixbuf_rect.x1 = gdk_pixbuf_get_width (pixbuf_without_text);
|
||||
pixbuf_rect.y1 = gdk_pixbuf_get_height (pixbuf_without_text);
|
||||
art_irect_intersect (&text_rect, embedded_text_rect, &pixbuf_rect);
|
||||
|
||||
/* Get the system visual. I wish I could do this all in 1-bit mode,
|
||||
* but I can't.
|
||||
*/
|
||||
visual = gdk_visual_get_system ();
|
||||
|
||||
/* Allocate a GdkPixmap of the appropriate size. */
|
||||
width = text_rect.x1 - text_rect.x0;
|
||||
height = text_rect.y1 - text_rect.y0;
|
||||
pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);
|
||||
gc = gdk_gc_new (pixmap);
|
||||
|
||||
/* Set up a white background. */
|
||||
gdk_rgb_gc_set_foreground (gc, NAUTILUS_RGB_COLOR_WHITE);
|
||||
gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, width, height);
|
||||
|
||||
/* Draw black text. */
|
||||
gdk_rgb_gc_set_foreground (gc, NAUTILUS_RGB_COLOR_BLACK);
|
||||
gdk_gc_set_font (gc, font);
|
||||
line = text;
|
||||
for (y = font->ascent;
|
||||
y + font->descent <= height;
|
||||
y += font->ascent + font->descent) {
|
||||
|
||||
/* Extract the next line of text. */
|
||||
end_of_line = strchr (line, '\n');
|
||||
line_length = end_of_line == NULL
|
||||
? strlen (line)
|
||||
: end_of_line - line;
|
||||
|
||||
/* Draw the next line of text. */
|
||||
gdk_draw_text (pixmap, font, gc, 0, y,
|
||||
line, line_length);
|
||||
|
||||
/* Move on to the subsequent line. */
|
||||
line = end_of_line == NULL
|
||||
? ""
|
||||
: end_of_line + 1;
|
||||
}
|
||||
gdk_gc_unref (gc);
|
||||
|
||||
/* Convert into a GdkPixbuf with gdk_pixbuf_get_from_drawable. */
|
||||
colormap = gdk_colormap_new (visual, FALSE);
|
||||
text_pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap,
|
||||
0, 0,
|
||||
0, 0, width, height);
|
||||
gdk_colormap_unref (colormap);
|
||||
gdk_pixmap_unref (pixmap);
|
||||
|
||||
/* White is not always FF FF FF. So we get the top left corner pixel. */
|
||||
pixels = gdk_pixbuf_get_pixels (text_pixbuf);
|
||||
text_pixbuf_with_alpha = gdk_pixbuf_add_alpha
|
||||
(text_pixbuf,
|
||||
TRUE, pixels[0], pixels[1], pixels[2]);
|
||||
gdk_pixbuf_unref (text_pixbuf);
|
||||
|
||||
pixbuf_with_text = gdk_pixbuf_copy (pixbuf_without_text);
|
||||
gdk_pixbuf_composite (text_pixbuf_with_alpha,
|
||||
pixbuf_with_text,
|
||||
text_rect.x0,
|
||||
text_rect.y0,
|
||||
width, height,
|
||||
text_rect.x0,
|
||||
text_rect.y0,
|
||||
1, 1,
|
||||
GDK_INTERP_BILINEAR,
|
||||
0xFF);
|
||||
gdk_pixbuf_unref (text_pixbuf_with_alpha);
|
||||
|
||||
|
||||
nautilus_gdk_pixbuf_draw_text (pixbuf_with_text, font, embedded_text_rect, text, 0xFF);
|
||||
|
||||
return pixbuf_with_text;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,11 +25,13 @@
|
|||
#include <config.h>
|
||||
#include <math.h>
|
||||
#include "nautilus-gdk-pixbuf-extensions.h"
|
||||
#include "nautilus-gdk-extensions.h"
|
||||
#include "nautilus-glib-extensions.h"
|
||||
#include "nautilus-string.h"
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf-loader.h>
|
||||
#include <libgnomevfs/gnome-vfs-ops.h>
|
||||
#include <libgnomevfs/gnome-vfs-async-ops.h>
|
||||
#include <libgnomevfs/gnome-vfs-ops.h>
|
||||
|
||||
#define LOAD_BUFFER_SIZE 4096
|
||||
|
||||
|
@ -391,3 +393,134 @@ nautilus_gdk_pixbuf_scale_to_fit (GdkPixbuf *pixbuf, int max_width, int max_heig
|
|||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* nautilus_gdk_pixbuf_draw_text
|
||||
* @pixbuf: A GdkPixbuf.
|
||||
* @font: A GdkFont.
|
||||
* @destination_rect: An ArtIRect - the destination bounding box for the text.
|
||||
* @text: A string - the text to draw.
|
||||
* @overall_alpha: The overall alpha to use when compositing the text on the pixbuf
|
||||
*
|
||||
* Draw text onto a GdkPixbuf using the given font and rect
|
||||
**/
|
||||
void
|
||||
nautilus_gdk_pixbuf_draw_text (GdkPixbuf *pixbuf,
|
||||
const GdkFont *font,
|
||||
const ArtIRect *destination_rect,
|
||||
const char *text,
|
||||
guint overall_alpha)
|
||||
{
|
||||
ArtIRect pixbuf_rect;
|
||||
ArtIRect text_rect;
|
||||
int width, height;
|
||||
GdkVisual *visual;
|
||||
GdkPixmap *pixmap;
|
||||
GdkGC *gc;
|
||||
GdkColormap *colormap;
|
||||
int y;
|
||||
const char *line;
|
||||
const char *end_of_line;
|
||||
int line_length;
|
||||
GdkPixbuf *text_pixbuf;
|
||||
GdkPixbuf *text_pixbuf_with_alpha;
|
||||
guchar *pixels;
|
||||
|
||||
g_return_if_fail (pixbuf != NULL);
|
||||
g_return_if_fail (font != NULL);
|
||||
g_return_if_fail (destination_rect != NULL);
|
||||
g_return_if_fail (text != NULL);
|
||||
g_return_if_fail (nautilus_strlen (text) > 0);
|
||||
g_return_if_fail (overall_alpha <= 255);
|
||||
|
||||
/* Compute the intersection of the text rectangle with the pixbuf.
|
||||
* This is only to prevent pathological cases from upsetting the
|
||||
* GdkPixbuf routines. It should not happen in any normal circumstance.
|
||||
*/
|
||||
pixbuf_rect.x0 = 0;
|
||||
pixbuf_rect.y0 = 0;
|
||||
pixbuf_rect.x1 = gdk_pixbuf_get_width (pixbuf);
|
||||
pixbuf_rect.y1 = gdk_pixbuf_get_height (pixbuf);
|
||||
art_irect_intersect (&text_rect, destination_rect, &pixbuf_rect);
|
||||
|
||||
/* Get the system visual. I wish I could do this all in 1-bit mode,
|
||||
* but I can't.
|
||||
*/
|
||||
visual = gdk_visual_get_system ();
|
||||
|
||||
/* Allocate a GdkPixmap of the appropriate size. */
|
||||
width = text_rect.x1 - text_rect.x0;
|
||||
height = text_rect.y1 - text_rect.y0;
|
||||
pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);
|
||||
gc = gdk_gc_new (pixmap);
|
||||
|
||||
/* Set up a white background. */
|
||||
gdk_rgb_gc_set_foreground (gc, NAUTILUS_RGB_COLOR_WHITE);
|
||||
gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, width, height);
|
||||
|
||||
/* Draw black text. */
|
||||
gdk_rgb_gc_set_foreground (gc, NAUTILUS_RGB_COLOR_BLACK);
|
||||
gdk_gc_set_font (gc, (GdkFont *) font);
|
||||
line = text;
|
||||
|
||||
/* FIXME bugzilla.eazel.com xxxx:
|
||||
* The iteration code should work with strings that dont have
|
||||
* new lines. Its broken right now for single line strings. The
|
||||
* (y + font->ascent) <= height test always fails and no text is drawn.
|
||||
*/
|
||||
if (strchr (line, '\n')) {
|
||||
for (y = font->ascent;
|
||||
y + font->descent <= height;
|
||||
y += font->ascent + font->descent) {
|
||||
|
||||
/* Extract the next line of text. */
|
||||
end_of_line = strchr (line, '\n');
|
||||
line_length = end_of_line == NULL
|
||||
? strlen (line)
|
||||
: end_of_line - line;
|
||||
|
||||
/* Draw the next line of text. */
|
||||
gdk_draw_text (pixmap, (GdkFont *) font, gc, 0, y,
|
||||
line, line_length);
|
||||
|
||||
/* Move on to the subsequent line. */
|
||||
line = end_of_line == NULL
|
||||
? ""
|
||||
: end_of_line + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Draw the next line of text. */
|
||||
gdk_draw_text (pixmap, (GdkFont *) font, gc, 0, font->ascent,
|
||||
line, strlen (line));
|
||||
}
|
||||
gdk_gc_unref (gc);
|
||||
|
||||
/* Convert into a GdkPixbuf with gdk_pixbuf_get_from_drawable. */
|
||||
colormap = gdk_colormap_new (visual, FALSE);
|
||||
text_pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap,
|
||||
0, 0,
|
||||
0, 0, width, height);
|
||||
gdk_colormap_unref (colormap);
|
||||
gdk_pixmap_unref (pixmap);
|
||||
|
||||
/* White is not always FF FF FF. So we get the top left corner pixel. */
|
||||
pixels = gdk_pixbuf_get_pixels (text_pixbuf);
|
||||
text_pixbuf_with_alpha = gdk_pixbuf_add_alpha
|
||||
(text_pixbuf,
|
||||
TRUE, pixels[0], pixels[1], pixels[2]);
|
||||
gdk_pixbuf_unref (text_pixbuf);
|
||||
|
||||
gdk_pixbuf_composite (text_pixbuf_with_alpha,
|
||||
pixbuf,
|
||||
text_rect.x0,
|
||||
text_rect.y0,
|
||||
width, height,
|
||||
text_rect.x0,
|
||||
text_rect.y0,
|
||||
1, 1,
|
||||
GDK_INTERP_BILINEAR,
|
||||
overall_alpha);
|
||||
|
||||
gdk_pixbuf_unref (text_pixbuf_with_alpha);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <libgnomevfs/gnome-vfs-types.h>
|
||||
#include <libart_lgpl/art_rect.h>
|
||||
|
||||
typedef struct NautilusPixbufLoadHandle NautilusPixbufLoadHandle;
|
||||
typedef void (* NautilusPixbufLoadCallback) (GnomeVFSResult error,
|
||||
|
@ -38,15 +39,18 @@ void nautilus_gdk_pixbuf_list_ref (GList
|
|||
void nautilus_gdk_pixbuf_list_unref (GList *pixbuf_list);
|
||||
void nautilus_gdk_pixbuf_list_free (GList *pixbuf_list);
|
||||
|
||||
|
||||
/* Loading a GdkPixbuf with a URI. */
|
||||
GdkPixbuf * nautilus_gdk_pixbuf_load (const char *uri);
|
||||
|
||||
|
||||
/* Same thing async. */
|
||||
NautilusPixbufLoadHandle *nautilus_gdk_pixbuf_load_async (const char *uri,
|
||||
NautilusPixbufLoadCallback callback,
|
||||
gpointer callback_data);
|
||||
void nautilus_cancel_gdk_pixbuf_load (NautilusPixbufLoadHandle *handle);
|
||||
|
||||
|
||||
/* Draw a GdkPixbuf tiled. */
|
||||
void nautilus_gdk_pixbuf_render_to_drawable_tiled (GdkPixbuf *pixbuf,
|
||||
GdkDrawable *drawable,
|
||||
|
@ -58,8 +62,16 @@ void nautilus_gdk_pixbuf_render_to_drawable_tiled (GdkPixbu
|
|||
GdkPixbuf * nautilus_gdk_pixbuf_scale_to_fit (GdkPixbuf *pixbuf,
|
||||
int max_width,
|
||||
int max_height);
|
||||
|
||||
/* return average color values for each component */
|
||||
void nautilus_gdk_pixbuf_average_value (GdkPixbuf *pixbuf,
|
||||
GdkColor *result_color);
|
||||
|
||||
void nautilus_gdk_pixbuf_average_value (GdkPixbuf *pixbuf,
|
||||
GdkColor *result_color);
|
||||
|
||||
/* Draw text onto a GdkPixbuf using the given font and rect */
|
||||
void nautilus_gdk_pixbuf_draw_text (GdkPixbuf *pixbuf,
|
||||
const GdkFont *font,
|
||||
const ArtIRect *destination_rect,
|
||||
const char *text,
|
||||
guint overall_alpha);
|
||||
|
||||
#endif /* NAUTILUS_GDK_PIXBUF_EXTENSIONS_H */
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nautilus-graphic.h"
|
||||
#include "nautilus-gtk-macros.h"
|
||||
#include "nautilus-gdk-extensions.h"
|
||||
#include "nautilus-gdk-pixbuf-extensions.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
@ -576,17 +577,12 @@ nautilus_graphic_size_allocate (GtkWidget *widget, GtkAllocation* allocation)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* FIXME bugzilla.eazel.com 1613:
|
||||
* Need to factor out code in nautilus-icon-factory.c:embed_text() into
|
||||
* nautilus_gdk_pixbuf_draw_text and use it here.
|
||||
*/
|
||||
#if FIXME
|
||||
if (graphic ->detail->label_text != NULL)
|
||||
{
|
||||
GtkRequisition text_size;
|
||||
gint x;
|
||||
gint y;
|
||||
ArtIRect text_rect;
|
||||
|
||||
g_assert (graphic->detail->label_font != NULL);
|
||||
|
||||
|
@ -594,19 +590,23 @@ nautilus_graphic_size_allocate (GtkWidget *widget, GtkAllocation* allocation)
|
|||
graphic ->detail->label_text,
|
||||
&text_size);
|
||||
|
||||
|
||||
x = (widget->allocation.width - text_size.width) / 2;
|
||||
y = (widget->allocation.height - text_size.height) / 2;
|
||||
|
||||
text_rect.x0 = x;
|
||||
text_rect.y0 = y;
|
||||
text_rect.x1 = x + text_size.width;
|
||||
text_rect.y1 = y + text_size.height;
|
||||
|
||||
/* FIXME bugzilla.eazel.com xxxx:
|
||||
* Need to be able to pass in a rgb colot into the draw_text function.
|
||||
*/
|
||||
nautilus_gdk_pixbuf_draw_text (graphic->detail->buffer,
|
||||
graphic->detail->label_font,
|
||||
x,
|
||||
y,
|
||||
&text_rect,
|
||||
graphic->detail->label_text,
|
||||
strlen (graphic->detail->label_text),
|
||||
NAUTILUS_RGBA_COLOR_PACK (255, 0, 0, NAUTILUS_ALPHA_NONE));
|
||||
graphic->detail->overall_alpha);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -2038,19 +2038,10 @@ embed_text (GdkPixbuf *pixbuf_without_text,
|
|||
const ArtIRect *embedded_text_rect,
|
||||
const char *text)
|
||||
{
|
||||
|
||||
static GdkFont *font;
|
||||
|
||||
ArtIRect pixbuf_rect, text_rect;
|
||||
int width, height;
|
||||
GdkVisual *visual;
|
||||
GdkPixmap *pixmap;
|
||||
GdkGC *gc;
|
||||
GdkColormap *colormap;
|
||||
int y;
|
||||
const char *line, *end_of_line;
|
||||
int line_length;
|
||||
GdkPixbuf *text_pixbuf, *text_pixbuf_with_alpha, *pixbuf_with_text;
|
||||
guchar *pixels;
|
||||
GdkPixbuf *pixbuf_with_text;
|
||||
|
||||
g_return_val_if_fail (pixbuf_without_text != NULL, NULL);
|
||||
g_return_val_if_fail (embedded_text_rect != NULL, gdk_pixbuf_ref (pixbuf_without_text));
|
||||
|
@ -2071,84 +2062,10 @@ embed_text (GdkPixbuf *pixbuf_without_text,
|
|||
return gdk_pixbuf_ref (pixbuf_without_text);
|
||||
}
|
||||
|
||||
/* Compute the intersection of the text rectangle with the pixbuf.
|
||||
* This is only to prevent pathological cases from upsetting the
|
||||
* GdkPixbuf routines. It should not happen in any normal circumstance.
|
||||
*/
|
||||
pixbuf_rect.x0 = 0;
|
||||
pixbuf_rect.y0 = 0;
|
||||
pixbuf_rect.x1 = gdk_pixbuf_get_width (pixbuf_without_text);
|
||||
pixbuf_rect.y1 = gdk_pixbuf_get_height (pixbuf_without_text);
|
||||
art_irect_intersect (&text_rect, embedded_text_rect, &pixbuf_rect);
|
||||
|
||||
/* Get the system visual. I wish I could do this all in 1-bit mode,
|
||||
* but I can't.
|
||||
*/
|
||||
visual = gdk_visual_get_system ();
|
||||
|
||||
/* Allocate a GdkPixmap of the appropriate size. */
|
||||
width = text_rect.x1 - text_rect.x0;
|
||||
height = text_rect.y1 - text_rect.y0;
|
||||
pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);
|
||||
gc = gdk_gc_new (pixmap);
|
||||
|
||||
/* Set up a white background. */
|
||||
gdk_rgb_gc_set_foreground (gc, NAUTILUS_RGB_COLOR_WHITE);
|
||||
gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, width, height);
|
||||
|
||||
/* Draw black text. */
|
||||
gdk_rgb_gc_set_foreground (gc, NAUTILUS_RGB_COLOR_BLACK);
|
||||
gdk_gc_set_font (gc, font);
|
||||
line = text;
|
||||
for (y = font->ascent;
|
||||
y + font->descent <= height;
|
||||
y += font->ascent + font->descent) {
|
||||
|
||||
/* Extract the next line of text. */
|
||||
end_of_line = strchr (line, '\n');
|
||||
line_length = end_of_line == NULL
|
||||
? strlen (line)
|
||||
: end_of_line - line;
|
||||
|
||||
/* Draw the next line of text. */
|
||||
gdk_draw_text (pixmap, font, gc, 0, y,
|
||||
line, line_length);
|
||||
|
||||
/* Move on to the subsequent line. */
|
||||
line = end_of_line == NULL
|
||||
? ""
|
||||
: end_of_line + 1;
|
||||
}
|
||||
gdk_gc_unref (gc);
|
||||
|
||||
/* Convert into a GdkPixbuf with gdk_pixbuf_get_from_drawable. */
|
||||
colormap = gdk_colormap_new (visual, FALSE);
|
||||
text_pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap,
|
||||
0, 0,
|
||||
0, 0, width, height);
|
||||
gdk_colormap_unref (colormap);
|
||||
gdk_pixmap_unref (pixmap);
|
||||
|
||||
/* White is not always FF FF FF. So we get the top left corner pixel. */
|
||||
pixels = gdk_pixbuf_get_pixels (text_pixbuf);
|
||||
text_pixbuf_with_alpha = gdk_pixbuf_add_alpha
|
||||
(text_pixbuf,
|
||||
TRUE, pixels[0], pixels[1], pixels[2]);
|
||||
gdk_pixbuf_unref (text_pixbuf);
|
||||
|
||||
pixbuf_with_text = gdk_pixbuf_copy (pixbuf_without_text);
|
||||
gdk_pixbuf_composite (text_pixbuf_with_alpha,
|
||||
pixbuf_with_text,
|
||||
text_rect.x0,
|
||||
text_rect.y0,
|
||||
width, height,
|
||||
text_rect.x0,
|
||||
text_rect.y0,
|
||||
1, 1,
|
||||
GDK_INTERP_BILINEAR,
|
||||
0xFF);
|
||||
gdk_pixbuf_unref (text_pixbuf_with_alpha);
|
||||
|
||||
|
||||
nautilus_gdk_pixbuf_draw_text (pixbuf_with_text, font, embedded_text_rect, text, 0xFF);
|
||||
|
||||
return pixbuf_with_text;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <libnautilus-extensions/nautilus-graphic.h>
|
||||
#include <libnautilus-extensions/nautilus-icon-factory.h>
|
||||
#include <libnautilus-extensions/nautilus-file-utilities.h>
|
||||
#include <libnautilus-extensions/nautilus-font-factory.h>
|
||||
|
||||
static GdkPixbuf*
|
||||
create_background (void)
|
||||
|
@ -231,6 +232,8 @@ create_color_scale (guint num_colors, GtkSignalFunc callback, gpointer callback_
|
|||
|
||||
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", callback, callback_data);
|
||||
|
||||
gtk_widget_set_usize (scale, 150, 0);
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
|
@ -291,7 +294,7 @@ main (int argc, char* argv[])
|
|||
{
|
||||
GdkFont *font;
|
||||
|
||||
font = gdk_font_load ("-adobe-helvetica-medium-r-normal--20-140-*");
|
||||
font = nautilus_font_factory_get_font_by_family ("helvetica", 20);
|
||||
|
||||
nautilus_graphic_set_label_text (NAUTILUS_GRAPHIC (graphic3), "Welcome Back, Arlo!");
|
||||
nautilus_graphic_set_label_font (NAUTILUS_GRAPHIC (graphic3), font);
|
||||
|
|
Loading…
Reference in a new issue