[vte/vte-next: 105/114] Add font-scale property
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-next: 105/114] Add font-scale property
- Date: Mon, 30 May 2011 17:15:34 +0000 (UTC)
commit 36181fab84bad92d91aea1af088821cdd6c799b9
Author: Christian Persch <chpe gnome org>
Date: Fri May 27 23:49:37 2011 +0200
Add font-scale property
To implement zoom, add font-scale property.
doc/reference/vte-sections.txt | 2 +
src/vte-private.h | 5 ++
src/vte.c | 113 ++++++++++++++++++++++++++++++++++++----
src/vte.h | 7 +++
src/vteapp.c | 25 +++------
5 files changed, 123 insertions(+), 29 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 7f2cbb8..c98ce5a 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -20,6 +20,8 @@ vte_terminal_paste_clipboard
vte_terminal_copy_primary
vte_terminal_paste_primary
vte_terminal_set_size
+vte_terminal_set_font_scale
+vte_terminal_get_font_scale
vte_terminal_set_audible_bell
vte_terminal_get_audible_bell
vte_terminal_set_visible_bell
diff --git a/src/vte-private.h b/src/vte-private.h
index 19ba69c..617b987 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -91,6 +91,9 @@ G_BEGIN_DECLS
#define VTE_UTF8_BPC (6) /* Maximum number of bytes used per UTF-8 character */
+#define VTE_SCALE_MIN (.25)
+#define VTE_SCALE_MAX (4.)
+
#define I_(string) (g_intern_static_string(string))
typedef enum {
@@ -323,7 +326,9 @@ struct _VteTerminalPrivate {
/* Data used when rendering the text which does not require server
* resources and which can be kept after unrealizing. */
+ PangoFontDescription *unscaled_font_desc;
PangoFontDescription *fontdesc;
+ gdouble font_scale;
gboolean fontdirty;
glong char_ascent;
glong char_descent;
diff --git a/src/vte.c b/src/vte.c
index 583a3d4..4c4d909 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -153,7 +153,8 @@ enum {
PROP_SCROLL_ON_OUTPUT,
PROP_WINDOW_TITLE,
PROP_WORD_CHARS,
- PROP_VISIBLE_BELL
+ PROP_VISIBLE_BELL,
+ PROP_FONT_SCALE
};
/* these static variables are guarded by the GDK mutex */
@@ -7119,6 +7120,36 @@ vte_terminal_ensure_font (VteTerminal *terminal)
}
}
+static void
+vte_terminal_update_font(VteTerminal *terminal)
+{
+ VteTerminalPrivate *pvt = terminal->pvt;
+ PangoFontDescription *desc;
+ gdouble size;
+
+ desc = pango_font_description_copy(pvt->unscaled_font_desc);
+
+ size = pango_font_description_get_size(desc);
+ if (pango_font_description_get_size_is_absolute(desc)) {
+ pango_font_description_set_absolute_size(desc, pvt->font_scale * size);
+ } else {
+ pango_font_description_set_size(desc, pvt->font_scale * size);
+ }
+
+ if (pvt->fontdesc) {
+ pango_font_description_free(pvt->fontdesc);
+ }
+ pvt->fontdesc = desc;
+
+ pvt->fontdirty = TRUE;
+ pvt->has_fonts = TRUE;
+
+ /* Set the drawing font. */
+ if (gtk_widget_get_realized (&terminal->widget)) {
+ vte_terminal_ensure_font (terminal);
+ }
+}
+
/*
* _vte_terminal_set_font:
* @terminal: a #VteTerminal
@@ -7154,17 +7185,50 @@ vte_terminal_set_font(VteTerminal *terminal,
*/
/* Free the old font description and save the new one. */
- if (pvt->fontdesc != NULL) {
- pango_font_description_free(pvt->fontdesc);
+ if (pvt->unscaled_font_desc != NULL) {
+ pango_font_description_free(pvt->unscaled_font_desc);
}
- pvt->fontdesc = desc /* adopted */;
- pvt->fontdirty = TRUE;
- pvt->has_fonts = TRUE;
+ pvt->unscaled_font_desc = desc /* adopted */;
- /* Set the drawing font. */
- if (gtk_widget_get_realized (&terminal->widget)) {
- vte_terminal_ensure_font (terminal);
- }
+ vte_terminal_update_font(terminal);
+}
+
+/**
+ * vte_terminal_set_font_scale:
+ * @terminal: a #VteTerminal
+ * @scale: the font scale
+ *
+ * Sets the terminal's font scale to @scale.
+ *
+ * Since: 0.30
+ */
+void
+vte_terminal_set_font_scale(VteTerminal *terminal,
+ gdouble scale)
+{
+ g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+ terminal->pvt->font_scale = CLAMP(scale, VTE_SCALE_MIN, VTE_SCALE_MAX);
+
+ vte_terminal_update_font(terminal);
+
+ g_object_notify(G_OBJECT(terminal), "font-scale");
+}
+
+/**
+ * vte_terminal_get_font_scale:
+ * @terminal: a #VteTerminal
+ *
+ * Returns: the terminal's font scale
+ *
+ * Since: 0.30
+ */
+gdouble
+vte_terminal_get_font_scale(VteTerminal *terminal)
+{
+ g_return_val_if_fail(VTE_IS_TERMINAL(terminal), 1.);
+
+ return terminal->pvt->font_scale;
}
/* Read and refresh our perception of the size of the PTY. */
@@ -7643,6 +7707,8 @@ vte_terminal_init(VteTerminal *terminal)
pvt->bg_pattern = NULL;
pvt->selection_block_mode = FALSE;
+ pvt->unscaled_font_desc = pvt->fontdesc = NULL;
+ pvt->font_scale = 1.;
pvt->has_fonts = FALSE;
/* Not all backends generate GdkVisibilityNotify, so mark the
@@ -7981,6 +8047,9 @@ vte_terminal_finalize(GObject *object)
}
/* Free the font description. */
+ if (pvt->unscaled_font_desc != NULL) {
+ pango_font_description_free(pvt->unscaled_font_desc);
+ }
if (terminal->pvt->fontdesc != NULL) {
pango_font_description_free(terminal->pvt->fontdesc);
}
@@ -10577,6 +10646,9 @@ vte_terminal_get_property (GObject *object,
case PROP_VISIBLE_BELL:
g_value_set_boolean (value, vte_terminal_get_visible_bell (terminal));
break;
+ case PROP_FONT_SCALE:
+ g_value_set_double (value, vte_terminal_get_font_scale (terminal));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -10645,6 +10717,9 @@ vte_terminal_set_property (GObject *object,
case PROP_VISIBLE_BELL:
vte_terminal_set_visible_bell (terminal, g_value_get_boolean (value));
break;
+ case PROP_FONT_SCALE:
+ vte_terminal_set_font_scale (terminal, g_value_get_double (value));
+ break;
/* Not writable */
case PROP_ICON_TITLE:
@@ -11316,7 +11391,23 @@ vte_terminal_class_init(VteTerminalClass *klass)
g_param_spec_string ("emulation", NULL, NULL,
VTE_DEFAULT_EMULATION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
+
+ /**
+ * VteTerminal:font-scale:
+ *
+ * The terminal's font scale.
+ *
+ * Since: 0.30
+ */
+ g_object_class_install_property
+ (gobject_class,
+ PROP_AUDIBLE_BELL,
+ g_param_spec_double ("font-scale", NULL, NULL,
+ VTE_SCALE_MIN,
+ VTE_SCALE_MAX,
+ 1.,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
/**
* VteTerminal:encoding:
*
diff --git a/src/vte.h b/src/vte.h
index f8d4175..433cb9e 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -90,6 +90,9 @@ struct _VteTerminalClass {
void (*resize_window)(VteTerminal* terminal, guint width, guint height);
void (*move_window)(VteTerminal* terminal, guint x, guint y);
+ /* FIXMEchpe: should these return gboolean and have defaul thandlers
+ * settings the "scale" property?
+ */
void (*increase_font_size)(VteTerminal* terminal);
void (*decrease_font_size)(VteTerminal* terminal);
@@ -231,6 +234,10 @@ void vte_terminal_select_none(VteTerminal *terminal);
void vte_terminal_set_size(VteTerminal *terminal,
glong columns, glong rows);
+void vte_terminal_set_font_scale(VteTerminal *terminal,
+ gdouble scale);
+gdouble vte_terminal_get_font_scale(VteTerminal *terminal);
+
/* Set various on-off settings. */
void vte_terminal_set_audible_bell(VteTerminal *terminal, gboolean is_audible);
gboolean vte_terminal_get_audible_bell(VteTerminal *terminal);
diff --git a/src/vteapp.c b/src/vteapp.c
index 4c7f93b..94e93a6 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -344,14 +344,12 @@ move_window(GtkWidget *widget, guint x, guint y, gpointer data)
}
}
-#if 0
static void
-adjust_font_size(GtkWidget *widget, gpointer data, gint howmuch)
+adjust_font_size(GtkWidget *widget, gpointer data, gdouble factor)
{
VteTerminal *terminal;
- PangoFontDescription *desired;
+ gdouble scale;
glong char_width, char_height;
- gint newsize;
gint columns, rows, owidth, oheight;
/* Read the screen dimensions in cells. */
@@ -366,12 +364,8 @@ adjust_font_size(GtkWidget *widget, gpointer data, gint howmuch)
owidth -= char_width * columns;
oheight -= char_height * rows;
- /* Calculate the new font size. */
- gtk_widget_style_get(&terminal->widget, "font", &desired, NULL);
- newsize = pango_font_description_get_size(desired) / PANGO_SCALE;
- newsize += howmuch;
- pango_font_description_set_size(desired,
- CLAMP(newsize, 4, 144) * PANGO_SCALE);
+ scale = vte_terminal_get_font_scale(terminal);
+ vte_terminal_set_font_scale(terminal, scale * factor);
/* Change the font, then resize the window so that we have the same
* number of rows and columns. */
@@ -383,22 +377,19 @@ adjust_font_size(GtkWidget *widget, gpointer data, gint howmuch)
gtk_window_resize(GTK_WINDOW(data),
columns * char_width + owidth,
rows * char_height + oheight);
-
- pango_font_description_free(desired);
}
static void
increase_font_size(GtkWidget *widget, gpointer data)
{
- adjust_font_size(widget, data, 1);
+ adjust_font_size(widget, data, 1.2);
}
static void
decrease_font_size(GtkWidget *widget, gpointer data)
{
- adjust_font_size(widget, data, -1);
+ adjust_font_size(widget, data, 1. / 1.2);
}
-#endif
static gboolean
read_and_feed(GIOChannel *source, GIOCondition condition, gpointer data)
@@ -885,7 +876,7 @@ main(int argc, char **argv)
/* Create the terminal widget and add it to the scrolling shell. */
widget = vte_terminal_new();
terminal = VTE_TERMINAL (widget);
- if (!dbuffer) {
+ if (!dbuffer) {
gtk_widget_set_double_buffered(widget, dbuffer);
}
if (show_object_notifications)
@@ -943,13 +934,11 @@ main(int argc, char **argv)
g_signal_connect(widget, "move-window",
G_CALLBACK(move_window), window);
-#if 0
/* Connect to font tweakage. */
g_signal_connect(widget, "increase-font-size",
G_CALLBACK(increase_font_size), window);
g_signal_connect(widget, "decrease-font-size",
G_CALLBACK(decrease_font_size), window);
-#endif
if (!use_scrolled_window) {
/* Create the scrollbar for the widget. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]