Commit 84043719 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

take image resolution and choosen unit into account for font and border

2001-08-14  Sven Neumann  <sven@gimp.org>

	* app/tools/gimptexttool.c: take image resolution and choosen unit
	into account for font and border size.

	* app/widgets/gimpfontselection-dialog.[ch]
	* app/widgets/gimpfontselection.[ch]
	* app/widgets/widgets-types.h: added an indicator for font validity.
	Added a font preview to the font selection dialog.

	* libgimpwidgets/gimpfileselection.c: return FALSE from
	gimp_file_selection_entry_focus_out_callback() since we do not want
	to stop signal emission.
parent 79faae01
2001-08-14 Sven Neumann <sven@gimp.org>
* app/tools/gimptexttool.c: take image resolution and choosen unit
into account for font and border size.
* app/widgets/gimpfontselection-dialog.[ch]
* app/widgets/gimpfontselection.[ch]
* app/widgets/widgets-types.h: added an indicator for font validity.
Added a font preview to the font selection dialog.
* libgimpwidgets/gimpfileselection.c: return FALSE from
gimp_file_selection_entry_focus_out_callback() since we do not want
to stop signal emission.
2001-08-12 Michael Natterer <mitch@gimp.org>
Switched to GObject reference counting:
......
......@@ -70,6 +70,7 @@ struct _TextOptions
{
GimpToolOptions tool_options;
gchar *fontname_d;
GtkWidget *font_selection;
gdouble size;
......@@ -226,17 +227,17 @@ text_tool_options_reset (GimpToolOptions *tool_options)
options = (TextOptions *) tool_options;
/* FIXME: reset font */
gimp_font_selection_set_fontname
(GIMP_FONT_SELECTION (options->font_selection), options->fontname_d);
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->size_w),
options->size_d);
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->border_w),
options->border_d);
/* resetting the unit menu is a bit tricky ... */
options->unit = options->unit_d;
gimp_unit_menu_set_unit (GIMP_UNIT_MENU (options->unit_w),
options->unit_d);
spinbutton =
g_object_get_data (G_OBJECT (options->unit_w), "set_digits");
while (spinbutton)
......@@ -253,20 +254,23 @@ text_tool_options_new (GimpTextTool *text_tool)
TextOptions *options;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *spinbutton;
GtkWidget *size_spinbutton;
GtkWidget *border_spinbutton;
options = g_new0 (TextOptions, 1);
tool_options_init ((GimpToolOptions *) options, text_tool_options_reset);
options->border = options->border_d = 0;
options->size = options->size_d = DEFAULT_FONT_SIZE;
options->unit = options->unit_d = GIMP_UNIT_PIXEL;
options->fontname_d = DEFAULT_FONT;
options->border = options->border_d = 0;
options->size = options->size_d = DEFAULT_FONT_SIZE;
options->unit = options->unit_d = GIMP_UNIT_PIXEL;
/* the main vbox */
vbox = options->tool_options.main_vbox;
options->font_selection = gimp_font_selection_new (text_tool->pango_context);
gimp_font_selection_set_fontname (GIMP_FONT_SELECTION (options->font_selection), DEFAULT_FONT);
gimp_font_selection_set_fontname
(GIMP_FONT_SELECTION (options->font_selection), DEFAULT_FONT);
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (options->font_selection),
FALSE, FALSE, 0);
gtk_widget_show (options->font_selection);
......@@ -278,29 +282,27 @@ text_tool_options_new (GimpTextTool *text_tool)
options->size_w = gtk_adjustment_new (options->size_d, 1e-5, 32767.0,
1.0, 50.0, 0.0);
spinbutton =
size_spinbutton =
gtk_spin_button_new (GTK_ADJUSTMENT (options->size_w), 1.0, 0.0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (size_spinbutton), TRUE);
g_signal_connect (G_OBJECT (options->size_w), "value_changed",
G_CALLBACK (gimp_double_adjustment_update),
&options->size);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Size:"), 1.0, 0.5,
spinbutton, 1, FALSE);
size_spinbutton, 1, FALSE);
options->border_w = gtk_adjustment_new (options->border_d, 1e-5, 32767.0,
1.0, 50.0, 0.0);
spinbutton =
border_spinbutton =
gtk_spin_button_new (GTK_ADJUSTMENT (options->border_w), 1.0, 0.0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (border_spinbutton), TRUE);
g_signal_connect (G_OBJECT (options->border_w), "value_changed",
G_CALLBACK (gimp_double_adjustment_update),
&options->border);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Border:"), 1.0, 0.5,
spinbutton, 1, FALSE);
border_spinbutton, 1, FALSE);
options->unit_w =
gimp_unit_menu_new ("%a", options->unit_d, TRUE, FALSE, TRUE);
......@@ -308,10 +310,13 @@ text_tool_options_new (GimpTextTool *text_tool)
G_CALLBACK (gimp_unit_menu_update),
&options->unit);
g_object_set_data (G_OBJECT (options->unit_w), "set_digits",
spinbutton);
size_spinbutton);
g_object_set_data (G_OBJECT (size_spinbutton), "set_digits",
border_spinbutton);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("Unit:"), 1.0, 0.5,
options->unit_w, 1, FALSE);
gtk_widget_show (table);
return options;
......@@ -360,7 +365,7 @@ text_tool_button_press (GimpTool *tool,
if ((layer = gimp_image_pick_correlate_layer (gdisp->gimage,
text_tool->click_x,
text_tool->click_y)))
/* If there is a floating selection, and this aint it, use the move tool */
/* if there is a floating selection, and this aint it, use the move tool */
if (gimp_layer_is_floating_sel (layer))
{
init_edit_selection (tool, gdisp, bevent, EDIT_LAYER_TRANSLATE);
......@@ -390,7 +395,7 @@ text_tool_cursor_update (GimpTool *tool,
&x, &y, FALSE, FALSE);
if ((layer = gimp_image_pick_correlate_layer (gdisp->gimage, x, y)))
/* if there is a floating selection, and this aint it... */
/* if there is a floating selection, and this aint it ... */
if (gimp_layer_is_floating_sel (layer))
{
gdisplay_install_tool_cursor (gdisp, GDK_FLEUR,
......@@ -399,8 +404,7 @@ text_tool_cursor_update (GimpTool *tool,
return;
}
gdisplay_install_tool_cursor (gdisp,
GDK_XTERM,
gdisplay_install_tool_cursor (gdisp, GDK_XTERM,
GIMP_TEXT_TOOL_CURSOR,
GIMP_CURSOR_MODIFIER_NONE);
}
......@@ -412,12 +416,37 @@ text_tool_render (GimpTextTool *text_tool)
PangoFontDescription *font_desc;
gchar *fontname;
gchar *text;
gdouble border;
gdouble size;
gdouble factor;
gdisp = text_tool->gdisp;
font_desc = gimp_font_selection_get_font_desc (GIMP_FONT_SELECTION (text_tool_options->font_selection));
font_desc = gimp_font_selection_get_font_desc
(GIMP_FONT_SELECTION (text_tool_options->font_selection));
if (!font_desc)
{
g_message (_("No font choosen or font invalid."));
return;
}
font_desc->size = (gdouble) PANGO_SCALE * MAX (1, text_tool_options->size);
size = text_tool_options->size;
border = text_tool_options->border;
switch (text_tool_options->unit)
{
case GIMP_UNIT_PIXEL:
break;
default:
factor = (gdisp->gimage->xresolution /
gimp_unit_get_factor (text_tool_options->unit));
size *= factor;
border *= factor;
break;
}
font_desc->size = (gdouble) PANGO_SCALE * MAX (1, size);
fontname = pango_font_description_to_string (font_desc);
pango_font_description_free (font_desc);
......@@ -425,7 +454,7 @@ text_tool_render (GimpTextTool *text_tool)
text_render (gdisp->gimage, gimp_image_active_drawable (gdisp->gimage),
text_tool->click_x, text_tool->click_y,
fontname, text, text_tool_options->border,
fontname, text, border,
TRUE /* antialias */);
g_free (fontname);
......@@ -449,7 +478,7 @@ text_render (GimpImage *gimage,
PangoRectangle ink;
PangoRectangle logical;
GimpImageType layer_type;
GimpLayer *layer;
GimpLayer *layer = NULL;
g_return_val_if_fail (fontname != NULL, FALSE);
g_return_val_if_fail (text != NULL, FALSE);
......@@ -476,6 +505,11 @@ text_render (GimpImage *gimage,
pango_layout_get_pixel_extents (layout, &ink, &logical);
g_print ("ink rect: %d x %d @ %d, %d\n",
ink.width, ink.height, ink.x, ink.y);
g_print ("logical rect: %d x %d @ %d, %d\n",
logical.width, logical.height, logical.x, logical.y);
if (ink.width > 0 && ink.height > 0)
{
TileManager *mask;
......@@ -496,15 +530,10 @@ text_render (GimpImage *gimage,
bitmap.buffer = g_malloc0 (bitmap.rows * bitmap.pitch);
g_print ("ink rect: %d x %d @ %d, %d\n",
ink.width, ink.height, ink.x, ink.y);
g_print ("logical rect: %d x %d @ %d, %d\n",
logical.width, logical.height, logical.x, logical.y);
pango_ft2_render_layout (&bitmap, layout,
- ink.x,
- ink.height - ink.y);
width = ink.width + 2 * border;
height = ink.height + 2 * border;
......
......@@ -28,6 +28,9 @@
#include <string.h>
#include <gtk/gtk.h>
#include <pango/pangoft2.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
......@@ -42,10 +45,27 @@
#define FONT_STYLE_LIST_WIDTH 170
static void gimp_font_selection_dialog_class_init (GimpFontSelectionDialogClass *klass);
static void gimp_font_selection_dialog_init (GimpFontSelectionDialog *dialog);
static void gimp_font_selection_dialog_finalize (GObject *object);
struct _GimpFontSelectionDialog
{
GimpFontSelection *fontsel;
PangoFontDescription *font_desc;
GtkWidget *dialog;
GtkWidget *font_clist;
GtkWidget *font_style_clist;
GtkWidget *preview;
FT_Bitmap bitmap;
PangoLayout *layout;
};
static void gimp_font_selection_dialog_ok (GtkWidget *widget,
gpointer data);
static void gimp_font_selection_dialog_apply (GtkWidget *widget,
gpointer data);
static void gimp_font_selection_dialog_preview (GimpFontSelectionDialog *dialog);
static void gimp_font_selection_dialog_select_font (GtkWidget *widget,
gint row,
gint column,
......@@ -56,62 +76,86 @@ static void gimp_font_selection_dialog_select_style (GtkWidget *widget,
gint column,
GdkEventButton *bevent,
gpointer data);
static void gimp_font_selection_dialog_response (GimpFontSelectionDialog *dialog,
gint response_id,
gpointer data);
static void gimp_font_selection_dialog_show_available_fonts (GimpFontSelectionDialog *dialog);
static void gimp_font_selection_dialog_show_available_styles (GimpFontSelectionDialog *dialog);
static gboolean gimp_font_selection_dialog_preview_expose (GtkWidget *widget,
GdkEventExpose *event,
gpointer data);
static void gimp_font_selection_dialog_preview_resize (GtkWidget *widget,
GtkAllocation *allocation,
gpointer data);
static void gimp_font_selection_dialog_preview (GimpFontSelectionDialog *dialog);
static GtkDialogClass *parent_class = NULL;
/**
* gimp_font_selection_dialog_new:
* @fontsel: the GimpFontSelection that creates and owns this dialog.
*
* Creates a new #GimpFontSelectionDialog.
*
* Returns: A pointer to the new #GimpFontSelectionDialog.
**/
GimpFontSelectionDialog *
gimp_font_selection_dialog_new (GimpFontSelection *fontsel)
{
GimpFontSelectionDialog *dialog;
GtkWidget *scrolled_win;
GtkWidget *table;
GtkWidget *label;
GtkWidget *frame;
GType
gimp_font_selection_dialog_get_type (void)
{
static GType dialog_type = 0;
g_return_val_if_fail (GIMP_IS_FONT_SELECTION (fontsel), NULL);
if (!dialog_type)
{
static const GTypeInfo dialog_info =
{
sizeof (GimpFontSelectionDialogClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_font_selection_dialog_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpFontSelectionDialog),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_font_selection_dialog_init,
};
dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
"GimpFontSelectionDialog",
&dialog_info, 0);
}
return dialog_type;
}
dialog = g_new0 (GimpFontSelectionDialog, 1);
static void
gimp_font_selection_dialog_class_init (GimpFontSelectionDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
dialog->fontsel = fontsel;
object_class->finalize = gimp_font_selection_dialog_finalize;
}
if (fontsel->font_desc)
dialog->font_desc = pango_font_description_copy (fontsel->font_desc);
else
dialog->font_desc = pango_font_description_from_string ("");
static void
gimp_font_selection_dialog_init (GimpFontSelectionDialog *dialog)
{
GtkWidget *scrolled_win;
GtkWidget *table;
GtkWidget *label;
GtkWidget *button;
dialog->layout = pango_layout_new (fontsel->context);
pango_layout_set_text (dialog->layout,
"my mind is going ...", -1);
dialog->dialog =
gimp_dialog_new (_("GIMP Font Selection"), "font_selection",
gimp_standard_help_func, "dialogs/font_selection.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, TRUE,
GTK_STOCK_OK, gimp_font_selection_dialog_ok,
dialog, NULL, NULL, TRUE, FALSE,
GTK_STOCK_APPLY, gimp_font_selection_dialog_apply,
dialog, NULL, NULL, TRUE, FALSE,
GTK_STOCK_CANCEL, gtk_widget_hide,
NULL, (gpointer) 1, NULL, FALSE, TRUE,
NULL);
gtk_container_set_border_width (GTK_CONTAINER (dialog->dialog), 1);
/* Create the font preview */
frame = gtk_frame_new (NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->dialog)->vbox), frame,
FALSE, FALSE, 0);
gtk_widget_show (frame);
dialog->preview = gtk_drawing_area_new ();
gtk_widget_set_usize (dialog->preview, -1, 30);
gtk_container_add (GTK_CONTAINER (frame), dialog->preview);
gtk_widget_show (dialog->preview);
g_signal_connect (G_OBJECT (dialog->preview), "size_allocate",
G_CALLBACK (gimp_font_selection_dialog_preview_resize),
dialog);
g_signal_connect (G_OBJECT (dialog->preview), "expose_event",
G_CALLBACK (gimp_font_selection_dialog_preview_expose),
dialog);
/* Create the table of font & style. */
table = gtk_table_new (2, 2, FALSE);
......@@ -165,7 +209,7 @@ gimp_font_selection_dialog_init (GimpFontSelectionDialog *dialog)
gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1,
GTK_FILL, 0, 0, 0);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), table,
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->dialog)->vbox), table,
FALSE, FALSE, 0);
gtk_widget_show (table);
......@@ -177,69 +221,37 @@ gimp_font_selection_dialog_init (GimpFontSelectionDialog *dialog)
G_CALLBACK (gimp_font_selection_dialog_select_style),
dialog);
button = gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_OK, GTK_RESPONSE_OK);
gtk_widget_grab_default (button);
button = gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_APPLY, GTK_RESPONSE_APPLY);
button = gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
g_signal_connect (GTK_DIALOG (dialog), "response",
G_CALLBACK (gimp_font_selection_dialog_response),
NULL);
}
static void
gimp_font_selection_dialog_finalize (GObject *object)
{
GimpFontSelectionDialog *dialog = GIMP_FONT_SELECTION_DIALOG (object);
gimp_font_selection_dialog_show_available_fonts (dialog);
gimp_font_selection_dialog_show_available_styles (dialog);
if (dialog->font_desc)
pango_font_description_free (dialog->font_desc);
gimp_font_selection_dialog_preview (dialog);
if (G_OBJECT_CLASS (parent_class)->finalize)
G_OBJECT_CLASS (parent_class)->finalize (object);
return dialog;
}
/**
* gimp_font_selection_dialog_new:
* @fontsel: the GimpFontSelection that creates and owns this dialog.
*
* Creates a new #GimpFontSelectionDialog.
*
* Returns: A pointer to the new #GimpFontSelectionDialog.
**/
GtkWidget *
gimp_font_selection_dialog_new (GimpFontSelection *fontsel)
void
gimp_font_selection_dialog_destroy (GimpFontSelectionDialog *dialog)
{
GimpFontSelectionDialog *dialog;
g_return_if_fail (dialog != NULL);
g_return_val_if_fail (GIMP_IS_FONT_SELECTION (fontsel), NULL);
dialog= g_object_new (GIMP_TYPE_FONT_SELECTION_DIALOG, NULL);
dialog->fontsel = fontsel;
if (fontsel->font_desc)
dialog->font_desc = pango_font_description_copy (fontsel->font_desc);
else
dialog->font_desc = pango_font_description_from_string ("");
gtk_window_set_title (GTK_WINDOW (dialog), _("GIMP Font Selection"));
gimp_font_selection_dialog_show_available_fonts (dialog);
gimp_font_selection_dialog_show_available_styles (dialog);
gtk_widget_destroy (dialog->dialog);
g_free (dialog->bitmap.buffer);
g_free (dialog);
}
return GTK_WIDGET (dialog);
void
gimp_font_selection_dialog_show (GimpFontSelectionDialog *dialog)
{
g_return_if_fail (dialog != NULL);
gtk_widget_show (dialog->dialog);
}
void
gimp_font_selection_dialog_set_font_desc (GimpFontSelectionDialog *dialog,
PangoFontDescription *new_desc)
{
g_return_if_fail (GIMP_IS_FONT_SELECTION_DIALOG (dialog));
g_return_if_fail (dialog != NULL);
if (dialog->font_desc)
pango_font_description_free (dialog->font_desc);
......@@ -250,6 +262,25 @@ gimp_font_selection_dialog_set_font_desc (GimpFontSelectionDialog *dialog,
gimp_font_selection_dialog_show_available_styles (dialog);
}
static void
gimp_font_selection_dialog_ok (GtkWidget *widget,
gpointer data)
{
GimpFontSelectionDialog *dialog = (GimpFontSelectionDialog *) data;
gimp_font_selection_set_font_desc (dialog->fontsel, dialog->font_desc);
gtk_widget_hide (dialog->dialog);
}
static void
gimp_font_selection_dialog_apply (GtkWidget *widget,
gpointer data)
{
GimpFontSelectionDialog *dialog = (GimpFontSelectionDialog *) data;
gimp_font_selection_set_font_desc (dialog->fontsel, dialog->font_desc);
}
static void
gimp_font_selection_dialog_select_font (GtkWidget *widget,
gint row,
......@@ -261,7 +292,7 @@ gimp_font_selection_dialog_select_font (GtkWidget *widget,
gchar *family_name;
gint index;
dialog = GIMP_FONT_SELECTION_DIALOG (data);
dialog = (GimpFontSelectionDialog *) data;
if (GTK_CLIST (dialog->font_clist)->selection)
{
......@@ -280,6 +311,8 @@ gimp_font_selection_dialog_select_font (GtkWidget *widget,
if (gtk_clist_row_is_visible (GTK_CLIST (dialog->font_style_clist), 0) != GTK_VISIBILITY_FULL)
gtk_clist_moveto (GTK_CLIST (dialog->font_style_clist), 0, -1,
0.5, 0);
gimp_font_selection_dialog_preview (dialog);
}
}
}
......@@ -296,7 +329,7 @@ gimp_font_selection_dialog_select_style (GtkWidget *widget,
gchar *style_name;
gint index;
dialog = GIMP_FONT_SELECTION_DIALOG (data);
dialog = (GimpFontSelectionDialog *) data;
if (GTK_CLIST (dialog->font_style_clist)->selection)
{
......@@ -313,29 +346,10 @@ gimp_font_selection_dialog_select_style (GtkWidget *widget,
pango_font_description_free (tmp_desc);
}
}
}
static void
gimp_font_selection_dialog_response (GimpFontSelectionDialog *dialog,
gint response_id,
gpointer data)
{
switch (response_id)
{
case GTK_RESPONSE_OK:
gtk_widget_hide (GTK_WIDGET (dialog));
/* fallthrough */
case GTK_RESPONSE_APPLY:
gimp_font_selection_set_font_desc (dialog->fontsel, dialog->font_desc);
break;
case GTK_RESPONSE_CLOSE:
gtk_widget_hide (GTK_WIDGET (dialog));
break;
default:
break;
gimp_font_selection_dialog_preview (dialog);
}
}
}
static int
compare_strings (gconstpointer a,
......@@ -449,3 +463,90 @@ gimp_font_selection_dialog_show_available_styles (GimpFontSelectionDialog *dialo
pango_font_descriptions_free (descs, n_descs);
}
static void
gimp_font_selection_dialog_preview (GimpFontSelectionDialog *dialog)
{
PangoRectangle rect;
if (dialog->font_desc)
{
dialog->font_desc->size = PANGO_SCALE * 24;
pango_layout_set_font_description (dialog->layout, dialog->font_desc);
dialog->font_desc->size = 0;
pango_layout_get_pixel_extents (dialog->layout, NULL, &rect);
if (rect.height + 4 > dialog->preview->allocation.height)
gtk_widget_set_usize (dialog->preview, -1, rect.height + 4);
/* FIXME: align on baseline */
memset (dialog->bitmap.buffer, 0,
dialog->bitmap.rows * dialog->bitmap.pitch);
pango_ft2_render_layout (&dialog->bitmap, dialog->layout, 2, 2);
}
gtk_widget_queue_draw (dialog->preview);
}