label: Don't clip text shadows

The previous code for computing the clip rectangle forgot to respect
the text-shadow CSS property. This is usually not very visible because
text shadows usually don't extend the ink rectangle by very much.

See attached testcase for an example.
This commit is contained in:
Benjamin Otte 2014-07-31 16:10:17 +02:00
parent a235dd6a6c
commit a3d1db608b
4 changed files with 62 additions and 4 deletions

View File

@ -30,6 +30,7 @@
#include "gtklabel.h"
#include "gtklabelprivate.h"
#include "gtkaccellabel.h"
#include "gtkcssshadowsvalueprivate.h"
#include "gtkdnd.h"
#include "gtkmarshalers.h"
#include "gtkpango.h"
@ -46,6 +47,7 @@
#include "gtkbuildable.h"
#include "gtkimage.h"
#include "gtkshow.h"
#include "gtkstylecontextprivate.h"
#include "gtktooltip.h"
#include "gtkprivate.h"
#include "gtktypebuiltins.h"
@ -3960,17 +3962,21 @@ gtk_label_get_ink_rect (GtkLabel *label,
GdkRectangle *rect)
{
GtkLabelPrivate *priv = label->priv;
GtkStyleContext *context;
PangoRectangle ink_rect;
GtkBorder extents;
int x, y;
gtk_label_ensure_layout (label);
get_layout_location (label, &x, &y);
pango_layout_get_pixel_extents (priv->layout, &ink_rect, NULL);
context = gtk_widget_get_style_context (GTK_WIDGET (label));
_gtk_css_shadows_value_get_extents (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW), &extents);
rect->x = x + ink_rect.x;
rect->width = ink_rect.width;
rect->y = y + ink_rect.y;
rect->height = ink_rect.height;
rect->x = x + ink_rect.x - extents.left;
rect->width = ink_rect.width + extents.left + extents.right;
rect->y = y + ink_rect.y - extents.top;
rect->height = ink_rect.height + extents.top + extents.bottom;
}
static void

View File

@ -266,6 +266,8 @@ testdata = \
label-sizing.ui \
label-small-ellipsized.ref.ui \
label-small-ellipsized.ui \
label-text-shadow-clipping.ref.ui \
label-text-shadow-clipping.ui \
label-width-chars-dont-shrink.ref.ui \
label-width-chars-dont-shrink.ui \
label-wrap-justify.ref.ui \

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.1 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkWindow" id="window1">
<property name="width_request">500</property>
<property name="height_request">100</property>
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Hello World</property>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.1 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkWindow" id="window1">
<property name="width_request">500</property>
<property name="height_request">100</property>
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Hello World</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
</interface>