Opened 9 years ago

Last modified 6 years ago

#12565 new patch

Handle CSS font-size parameter in gtkimhtml - provide absolute font size display

Reported by: mnunberg Owned by:
Milestone: Patches Needing Improvement Component: pidgin (gtk)
Version: 2.7.3 Keywords:
Cc:

Description

Attached are the patch (also pasted in the window, but i don't know how it formats it) and an image showing the differences: Note.. this might not be the best quality code.. but from my testing it works. Also note that in order for this to work on yahoo, the yahoo prpl (specifically, protocols/yahoo/util.c) must have USE_CSS_FORMATTING defined.

--- gtkimhtml.c.orig	2010-08-28 16:28:21.000000000 -0700
+++ gtkimhtml.c	2010-08-29 17:32:21.000000000 -0700
@@ -1736,6 +1736,7 @@ static void gtk_imhtml_init (GtkIMHtml *
 	imhtml->edit.backcolor = NULL;
 	imhtml->edit.fontface = NULL;
 	imhtml->edit.fontsize = 0;
+	imhtml->edit.size_is_points = FALSE;
 	imhtml->edit.link = NULL;
 
 
@@ -3151,8 +3152,13 @@ void gtk_imhtml_insert_html_at_iter(GtkI
 						if (oldfont && oldfont->sml)
 							font->sml = g_strdup(oldfont->sml);
 
+						imhtml->edit.size_is_points = FALSE;
 						if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) {
-							if (g_ascii_strcasecmp(size, "xx-small") == 0)
+							if (strlen(size) >= 2 && g_ascii_strcasecmp(size+strlen(size)-2, "pt") == 0) {
+								font->size = (gushort) g_ascii_strtoull(size, NULL, 10); 
+								imhtml->edit.size_is_points = TRUE;
+							}
+							else if (g_ascii_strcasecmp(size, "xx-small") == 0)
 								font->size = 1;
 							else if (g_ascii_strcasecmp(size, "smaller") == 0
 								  || g_ascii_strcasecmp(size, "x-small") == 0)
@@ -3166,7 +3172,6 @@ void gtk_imhtml_insert_html_at_iter(GtkI
 								font->size = 5;
 							else if (g_ascii_strcasecmp(size, "xx-large") == 0)
 								font->size = 6;
-
 							/*
 							 * TODO: Handle other values, like percentages, or
 							 * lengths specified as em, ex, px, in, cm, mm, pt
@@ -4168,11 +4173,17 @@ static GtkTextTag *find_font_size_tag(Gt
 		 * size. Our size 4 was actually smaller than our size 3 for
 		 * me. So this works around that oddity.
 		 */
+		gint size_param;
+		if(!imhtml->edit.size_is_points) {
 		GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml));
-		tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size",
-		                                 (gint) (pango_font_description_get_size(attr->font) *
-		                                 (double) POINT_SIZE(size)), NULL);
+			size_param = (gint) pango_font_description_get_size(attr->font) * (double) POINT_SIZE(size);
 		gtk_text_attributes_unref(attr);
+		} else {
+			size_param = (gint) (size * (double) PANGO_SCALE);
+		/*	printf("size_param: %d\n", size_param);
+			printf("not using POINT_SIZE macro\n");*/
+		}
+		tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size", size_param, NULL);
 	}
 
 	return tag;
@@ -4273,6 +4284,7 @@ imhtml_clear_formatting(GtkIMHtml *imhtm
 	imhtml->edit.underline = 0;
 	imhtml->edit.strike = 0;
 	imhtml->edit.fontsize = 0;
+	imhtml->edit.size_is_points = FALSE;
 
 	g_free(imhtml->edit.fontface);
 	imhtml->edit.fontface = NULL;
--- gtkimhtml.h.orig	2010-08-28 16:49:26.000000000 -0700
+++ gtkimhtml.h	2010-08-29 17:25:57.000000000 -0700
@@ -125,6 +125,7 @@ struct _GtkIMHtml {
 		gboolean italic:1;
 		gboolean underline:1;
 		gboolean strike:1;
+		gboolean size_is_points:1;
 		gchar *forecolor;
 		gchar *backcolor;
 		gchar *background;

Attachments (1)

screenshot1.png (87.8 KB) - added by mnunberg 9 years ago.
The left window is using the patch, the right one is vanilla

Download all attachments as: .zip

Change History (6)

Changed 9 years ago by mnunberg

The left window is using the patch, the right one is vanilla

comment:1 Changed 9 years ago by mnunberg

  • Component changed from unclassified to pidgin (gtk)
  • Owner rekkanoryo deleted

comment:2 Changed 9 years ago by Robby

  • Milestone set to Patches Needing Review

comment:3 Changed 6 years ago by salinasv

  • Status changed from new to pending

We have dropped gtkimhtml in favor of webkit.

You can try it and port the patch to the new engine.

comment:4 Changed 6 years ago by trac-robot

  • Status changed from pending to closed

This ticket was closed automatically by the system. It was previously set to a Pending status and hasn't been updated within 14 days.

comment:5 Changed 6 years ago by Robby

  • Milestone changed from Patches Needing Review to Patches Needing Improvement
  • Status changed from closed to new
Note: See TracTickets for help on using tickets.
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!