[Pidgin] #12565: Handle CSS font-size parameter in gtkimhtml - provide absolute font size display
Pidgin
trac at pidgin.im
Sun Aug 29 20:43:45 EDT 2010
#12565: Handle CSS font-size parameter in gtkimhtml - provide absolute font size
display
--------------------------+-------------------------------------------------
Reporter: mnunberg | Owner: rekkanoryo
Type: patch | Status: new
Component: unclassified | Version: 2.7.3
Keywords: |
--------------------------+-------------------------------------------------
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;
}}}
--
Ticket URL: <http://developer.pidgin.im/ticket/12565>
Pidgin <http://pidgin.im>
Pidgin
More information about the Tracker
mailing list