[gnome-font-viewer] font-widget: sync from Sushi
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-font-viewer] font-widget: sync from Sushi
- Date: Tue, 1 May 2012 18:49:45 +0000 (UTC)
commit 63268c1f75057d7d94c25444e3ff0a2eecd50521
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue May 1 14:48:53 2012 -0400
font-widget: sync from Sushi
src/sushi-font-loader.c | 8 ++++++--
src/sushi-font-widget.c | 29 +++++++++++++++++------------
2 files changed, 23 insertions(+), 14 deletions(-)
---
diff --git a/src/sushi-font-loader.c b/src/sushi-font-loader.c
index d599a57..3168892 100644
--- a/src/sushi-font-loader.c
+++ b/src/sushi-font-loader.c
@@ -156,16 +156,20 @@ sushi_new_ft_face_from_uri (FT_Library library,
GError **error)
{
FontLoadJob *job = NULL;
+ FT_Face face;
job = font_load_job_new (library, uri, NULL, NULL);
font_load_job_do_load (job, error);
if ((error != NULL) && (*error != NULL)) {
- g_object_unref (job);
+ font_load_job_free (job);
return NULL;
}
- return create_face_from_contents (job, contents, error);
+ face = create_face_from_contents (job, contents, error);
+ font_load_job_free (job);
+
+ return face;
}
/**
diff --git a/src/sushi-font-widget.c b/src/sushi-font-widget.c
index 1c6440a..11e1811 100644
--- a/src/sushi-font-widget.c
+++ b/src/sushi-font-widget.c
@@ -65,8 +65,6 @@ G_DEFINE_TYPE (SushiFontWidget, sushi_font_widget, GTK_TYPE_DRAWING_AREA);
#define SURFACE_SIZE 4
#define SECTION_SPACING 16
-#define TITLE_SIZE 6
-
static const gchar lowercase_text_stock[] = "abcdefghijklmnopqrstuvwxyz";
static const gchar uppercase_text_stock[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const gchar punctuation_text_stock[] = "0123456789.:,;(*!?')";
@@ -224,7 +222,8 @@ build_strings_for_face (SushiFontWidget *self)
static gint *
build_sizes_table (FT_Face face,
gint *n_sizes,
- gint *alpha_size)
+ gint *alpha_size,
+ gint *title_size)
{
gint *sizes = NULL;
gint i;
@@ -249,8 +248,10 @@ build_sizes_table (FT_Face face,
sizes[13] = 216;
*alpha_size = 24;
+ *title_size = 48;
} else {
- gint diff = G_MAXINT;
+ gint alpha_diff = G_MAXINT;
+ gint title_diff = G_MAXINT;
/* use fixed sizes */
*n_sizes = face->num_fixed_sizes;
@@ -260,10 +261,14 @@ build_sizes_table (FT_Face face,
for (i = 0; i < face->num_fixed_sizes; i++) {
sizes[i] = face->available_sizes[i].height;
- if ((gint) (abs (sizes[i] - 24)) < diff) {
- diff = (gint) abs (sizes[i] - 24);
+ if ((gint) (abs (sizes[i] - 24)) < alpha_diff) {
+ alpha_diff = (gint) abs (sizes[i] - 24);
*alpha_size = sizes[i];
}
+ if ((gint) (abs (sizes[i] - 24)) < title_diff) {
+ title_diff = (gint) abs (sizes[i] - 24);
+ *title_size = sizes[i];
+ }
}
}
@@ -282,7 +287,7 @@ sushi_font_widget_size_request (GtkWidget *drawing_area,
cairo_text_extents_t extents;
cairo_font_extents_t font_extents;
cairo_font_face_t *font;
- gint *sizes = NULL, n_sizes, alpha_size;
+ gint *sizes = NULL, n_sizes, alpha_size, title_size;
cairo_t *cr;
cairo_surface_t *surface;
FT_Face face = priv->face;
@@ -311,7 +316,7 @@ sushi_font_widget_size_request (GtkWidget *drawing_area,
state = gtk_style_context_get_state (context);
gtk_style_context_get_padding (context, state, &padding);
- sizes = build_sizes_table (face, &n_sizes, &alpha_size);
+ sizes = build_sizes_table (face, &n_sizes, &alpha_size, &title_size);
/* calculate size of pixmap to use */
pixmap_width = padding.left + padding.right;
@@ -322,7 +327,7 @@ sushi_font_widget_size_request (GtkWidget *drawing_area,
cairo_font_face_destroy (font);
if (self->priv->font_supports_title) {
- cairo_set_font_size (cr, sizes[TITLE_SIZE]);
+ cairo_set_font_size (cr, title_size);
cairo_font_extents (cr, &font_extents);
cairo_text_extents (cr, self->priv->font_name, &extents);
pixmap_height += font_extents.ascent + font_extents.descent +
@@ -416,7 +421,7 @@ sushi_font_widget_draw (GtkWidget *drawing_area,
{
SushiFontWidget *self = SUSHI_FONT_WIDGET (drawing_area);
SushiFontWidgetPrivate *priv = self->priv;
- gint *sizes = NULL, n_sizes, alpha_size, pos_y = 0, i;
+ gint *sizes = NULL, n_sizes, alpha_size, title_size, pos_y = 0, i;
cairo_font_face_t *font;
FT_Face face = priv->face;
GtkStyleContext *context;
@@ -435,7 +440,7 @@ sushi_font_widget_draw (GtkWidget *drawing_area,
gdk_cairo_set_source_rgba (cr, &color);
- sizes = build_sizes_table (face, &n_sizes, &alpha_size);
+ sizes = build_sizes_table (face, &n_sizes, &alpha_size, &title_size);
font = cairo_ft_font_face_create_for_ft_face (face, 0);
cairo_set_font_face (cr, font);
@@ -446,7 +451,7 @@ sushi_font_widget_draw (GtkWidget *drawing_area,
/* draw text */
if (self->priv->font_supports_title) {
- cairo_set_font_size (cr, sizes[TITLE_SIZE]);
+ cairo_set_font_size (cr, title_size);
draw_string (cr, padding, self->priv->font_name, &pos_y);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]