static void add_underline (PangoRenderer *renderer, LineState *state, PangoFontMetrics *metrics, int base_x, int base_y, PangoRectangle *ink_rect, PangoRectangle *logical_rect) { PangoRectangle *current_rect = &state->underline_rect; PangoRectangle new_rect; int underline_thickness = pango_font_metrics_get_underline_thickness (metrics); int underline_position = pango_font_metrics_get_underline_position (metrics); new_rect.x = base_x + logical_rect->x; new_rect.width = logical_rect->width; new_rect.height = underline_thickness; new_rect.y = base_y; switch (renderer->underline) { case PANGO_UNDERLINE_NONE: g_assert_not_reached (); break; case PANGO_UNDERLINE_SINGLE: case PANGO_UNDERLINE_DOUBLE: case PANGO_UNDERLINE_ERROR: new_rect.y -= underline_position; break; case PANGO_UNDERLINE_LOW: new_rect.y += ink_rect->y + ink_rect->height + underline_thickness; break; } if (renderer->underline == state->underline && new_rect.y == current_rect->y && new_rect.height == current_rect->height) { current_rect->width = new_rect.x + new_rect.width - current_rect->x; } else { draw_underline (renderer, state); *current_rect = new_rect; state->underline = renderer->underline; } }
static int get_pango_vertical_offset (PangoLayout *layout) { const PangoFontDescription *desc; PangoContext *context; PangoLanguage *language; PangoFontMetrics *metrics; int baseline; int strikethrough; int thickness; context = pango_layout_get_context (layout); language = pango_language_get_default (); desc = pango_layout_get_font_description (layout); metrics = pango_context_get_metrics (context, desc, language); baseline = pango_layout_get_baseline (layout); strikethrough = pango_font_metrics_get_strikethrough_position (metrics); thickness = pango_font_metrics_get_underline_thickness (metrics); return PANGO_PIXELS (baseline - strikethrough - thickness / 2); }
/* Helper function to draw the underline for one layout run; the descent field gives * the descent of the ink for the actual text in the layout run. */ static void draw_underline (GnomePrintContext *gpc, PangoFontMetrics *metrics, PangoUnderline uline, gint x, gint width, gint descent) { gint underline_thickness = pango_font_metrics_get_underline_thickness (metrics); gint underline_position = pango_font_metrics_get_underline_position (metrics); gint y_off = 0; /* Quiet GCC */ switch (uline) { case PANGO_UNDERLINE_NONE: g_assert_not_reached(); break; case PANGO_UNDERLINE_SINGLE: y_off = underline_position - underline_thickness; break; case PANGO_UNDERLINE_DOUBLE: y_off = underline_position - underline_thickness; break; case PANGO_UNDERLINE_LOW: y_off = - 2 * underline_thickness - descent; break; case PANGO_UNDERLINE_ERROR: draw_error_underline (gpc, (gdouble) x / PANGO_SCALE, (gdouble) (underline_position - 3 * underline_thickness) / PANGO_SCALE, (gdouble) width / PANGO_SCALE, (gdouble) (3 * underline_thickness) / PANGO_SCALE); return; } rect_filled (gpc, x, y_off, width, underline_thickness); if (uline == PANGO_UNDERLINE_DOUBLE) rect_filled (gpc, x, y_off - 2 * underline_thickness, width, underline_thickness); }