diff options
Diffstat (limited to 'pango/pangoft2.c')
-rw-r--r-- | pango/pangoft2.c | 562 |
1 files changed, 0 insertions, 562 deletions
diff --git a/pango/pangoft2.c b/pango/pangoft2.c index 78e9fb6d..268b01dc 100644 --- a/pango/pangoft2.c +++ b/pango/pangoft2.c @@ -49,13 +49,6 @@ struct _PangoFT2FontClass PangoFcFontClass parent_class; }; -typedef struct -{ - FT_Bitmap bitmap; - int bitmap_left; - int bitmap_top; -} PangoFT2RenderedGlyph; - static void pango_ft2_font_finalize (GObject *object); static void pango_ft2_font_get_glyph_extents (PangoFont *font, @@ -72,15 +65,6 @@ static guint pango_ft2_font_real_get_glyph (PangoFcFont *font, static PangoGlyph pango_ft2_font_real_get_unknown_glyph (PangoFcFont *font, gunichar wc); -static void pango_ft2_get_item_properties (PangoItem *item, - PangoUnderline *uline, - gboolean *strikethrough, - gint *rise, - gboolean *shape_set, - PangoRectangle *ink_rect, - PangoRectangle *logical_rect); - - PangoFT2Font * _pango_ft2_font_new (PangoFT2FontMap *ft2fontmap, FcPattern *pattern) @@ -284,246 +268,6 @@ pango_ft2_font_class_init (PangoFT2FontClass *class) fc_font_class->get_unknown_glyph = pango_ft2_font_real_get_unknown_glyph; } -static void -pango_ft2_free_rendered_glyph (PangoFT2RenderedGlyph *rendered) -{ - g_free (rendered->bitmap.buffer); - g_free (rendered); -} - -static PangoFT2RenderedGlyph * -pango_ft2_font_render_glyph (PangoFont *font, - int glyph_index) -{ - PangoFT2RenderedGlyph *rendered; - FT_Face face; - - rendered = g_new (PangoFT2RenderedGlyph, 1); - - face = pango_ft2_font_get_face (font); - - if (face) - { - PangoFT2Font *ft2font = (PangoFT2Font *) font; - - /* Draw glyph */ - FT_Load_Glyph (face, glyph_index, ft2font->load_flags); - FT_Render_Glyph (face->glyph, - (ft2font->load_flags & FT_LOAD_TARGET_MONO ? - ft_render_mode_mono : ft_render_mode_normal)); - - rendered->bitmap = face->glyph->bitmap; - rendered->bitmap.buffer = g_memdup (face->glyph->bitmap.buffer, - face->glyph->bitmap.rows * face->glyph->bitmap.pitch); - rendered->bitmap_left = face->glyph->bitmap_left; - rendered->bitmap_top = face->glyph->bitmap_top; - } - else - g_error ("Couldn't get face for PangoFT2Face"); - - return rendered; -} - -static void -transform_point (const PangoMatrix *matrix, - int x, - int y, - int *x_out_pixels, - int *y_out_pixels) -{ - double x_out = (matrix->xx * x + matrix->xy * y) / PANGO_SCALE + matrix->x0; - double y_out = (matrix->yx * x + matrix->yy * y) / PANGO_SCALE + matrix->y0; - - *x_out_pixels = floor (x_out + 0.5); - *y_out_pixels = floor (y_out + 0.5); -} - -/** - * pango_ft2_render_transformed: - * @bitmap: the FreeType2 bitmap onto which to draw the string - * @font: the font in which to draw the string - * @matrix: a #PangoMatrix, or %NULL to use an identity transformation - * @glyphs: the glyph string to draw - * @x: the x position of the start of the string (in Pango - * units in user space coordinates) - * @y: the y position of the baseline (in Pango units - * in user space coordinates) - * - * Renders a #PangoGlyphString onto a FreeType2 bitmap, possibly - * transforming the layed-out coordinates through a transformation - * matrix. Note that the transformation matrix for @font is not - * changed, so to produce correct rendering results, the @font - * must have been loaded using a #PangoContext with an identical - * transformation matrix to that passed in to this function. - * - * Since: 1.6 - **/ -void -pango_ft2_render_transformed (FT_Bitmap *bitmap, - const PangoMatrix *matrix, - PangoFont *font, - PangoGlyphString *glyphs, - int x, - int y) -{ - FT_UInt glyph_index; - int i; - int x_position = 0; - int ix, iy, ixoff, iyoff, y_start, y_limit, x_start, x_limit; - PangoGlyphInfo *gi; - guchar *dest, *src; - gboolean add_glyph_to_cache; - - g_return_if_fail (bitmap != NULL); - g_return_if_fail (glyphs != NULL); - - PING (("bitmap: %dx%d@+%d+%d", bitmap->width, bitmap->rows, x, y)); - - gi = glyphs->glyphs; - for (i = 0; i < glyphs->num_glyphs; i++, gi++) - { - if (gi->glyph) - { - PangoFT2RenderedGlyph *rendered_glyph; - glyph_index = gi->glyph; - - rendered_glyph = _pango_ft2_font_get_cache_glyph_data (font, - glyph_index); - add_glyph_to_cache = FALSE; - if (rendered_glyph == NULL) - { - rendered_glyph = pango_ft2_font_render_glyph (font, glyph_index); - add_glyph_to_cache = TRUE; - } - - if (matrix) - { - transform_point (matrix, - x + x_position + gi->geometry.x_offset, - y + gi->geometry.y_offset, - &ixoff, &iyoff); - } - else - { - ixoff = PANGO_PIXELS (x + x_position + gi->geometry.x_offset); - iyoff = PANGO_PIXELS (y + gi->geometry.y_offset); - } - - x_start = MAX (0, - (ixoff + rendered_glyph->bitmap_left)); - x_limit = MIN (rendered_glyph->bitmap.width, - bitmap->width - (ixoff + rendered_glyph->bitmap_left)); - - y_start = MAX (0, - (iyoff - rendered_glyph->bitmap_top)); - y_limit = MIN (rendered_glyph->bitmap.rows, - bitmap->rows - (iyoff - rendered_glyph->bitmap_top)); - - PING (("glyph %d:%d: bitmap: %dx%d, left:%d top:%d", - i, glyph_index, - rendered_glyph->bitmap.width, rendered_glyph->bitmap.rows, - rendered_glyph->bitmap_left, rendered_glyph->bitmap_top)); - PING (("xstart:%d xlim:%d ystart:%d ylim:%d", - x_start, x_limit, y_start, y_limit)); - - src = rendered_glyph->bitmap.buffer + - y_start * rendered_glyph->bitmap.pitch; - - dest = bitmap->buffer + - (y_start + iyoff - rendered_glyph->bitmap_top) * bitmap->pitch + - x_start + ixoff + rendered_glyph->bitmap_left; - - switch (rendered_glyph->bitmap.pixel_mode) - { - case ft_pixel_mode_grays: - src += x_start; - for (iy = y_start; iy < y_limit; iy++) - { - guchar *s = src; - guchar *d = dest; - - for (ix = x_start; ix < x_limit; ix++) - { - switch (*s) - { - case 0: - break; - case 0xff: - *d = 0xff; - default: - *d = MIN ((gushort) *d + (gushort) *s, 0xff); - break; - } - - s++; - d++; - } - - dest += bitmap->pitch; - src += rendered_glyph->bitmap.pitch; - } - break; - - case ft_pixel_mode_mono: - src += x_start / 8; - for (iy = y_start; iy < y_limit; iy++) - { - guchar *s = src; - guchar *d = dest; - - for (ix = x_start; ix < x_limit; ix++) - { - if ((*s) & (1 << (7 - (ix % 8)))) - *d |= 0xff; - - if ((ix % 8) == 7) - s++; - d++; - } - - dest += bitmap->pitch; - src += rendered_glyph->bitmap.pitch; - } - break; - - default: - g_warning ("pango_ft2_render: " - "Unrecognized glyph bitmap pixel mode %d\n", - rendered_glyph->bitmap.pixel_mode); - break; - } - - if (add_glyph_to_cache) - { - _pango_ft2_font_set_glyph_cache_destroy (font, - (GDestroyNotify) pango_ft2_free_rendered_glyph); - _pango_ft2_font_set_cache_glyph_data (font, - glyph_index, rendered_glyph); - } - } - - x_position += glyphs->glyphs[i].geometry.width; - } -} - -/** - * pango_ft2_render: - * @bitmap: the FreeType2 bitmap onto which to draw the string - * @font: the font in which to draw the string - * @glyphs: the glyph string to draw - * @x: the x position of the start of the string (in pixels) - * @y: the y position of the baseline (in pixels) - * - * Renders a #PangoGlyphString onto a FreeType2 bitmap. - **/ -void -pango_ft2_render (FT_Bitmap *bitmap, - PangoFont *font, - PangoGlyphString *glyphs, - int x, - int y) -{ - pango_ft2_render_transformed (bitmap, NULL, font, glyphs, x * PANGO_SCALE, y * PANGO_SCALE); -} - static PangoFT2GlyphInfo * pango_ft2_font_get_glyph_info (PangoFont *font, PangoGlyph glyph, @@ -721,311 +465,6 @@ pango_ft2_get_unknown_glyph (PangoFont *font) return 0; } -static void -draw_underline (FT_Bitmap *bitmap, - const PangoMatrix *matrix, - PangoFontMetrics *metrics, - PangoUnderline uline, - int x, - int width, - int base_y, - int descent) -{ - int underline_thickness = pango_font_metrics_get_underline_thickness (metrics); - int underline_position = pango_font_metrics_get_underline_position (metrics); - int y_off = 0; /* Quiet GCC */ - - switch (uline) - { - case PANGO_UNDERLINE_NONE: - g_assert_not_reached(); - break; - case PANGO_UNDERLINE_SINGLE: - y_off = - underline_position; - break; - case PANGO_UNDERLINE_DOUBLE: - y_off = - underline_position; - break; - case PANGO_UNDERLINE_LOW: - y_off = underline_thickness + descent; - break; - case PANGO_UNDERLINE_ERROR: - { - _pango_ft2_draw_error_underline (bitmap, matrix, - x, - base_y - underline_position, - width, - 3 * underline_thickness); - return; - } - } - - _pango_ft2_draw_rect (bitmap, matrix, - x, - base_y + y_off, - width, - underline_thickness); - - if (uline == PANGO_UNDERLINE_DOUBLE) - { - y_off += 2 * underline_thickness; - - _pango_ft2_draw_rect (bitmap, matrix, - x, - base_y + y_off, - width, - underline_thickness); - } -} - -static void -draw_strikethrough (FT_Bitmap *bitmap, - const PangoMatrix *matrix, - PangoFontMetrics *metrics, - int x, - int width, - int base_y) -{ - int strikethrough_thickness = pango_font_metrics_get_strikethrough_thickness (metrics); - int strikethrough_position = pango_font_metrics_get_strikethrough_position (metrics); - - _pango_ft2_draw_rect (bitmap, matrix, - x, - base_y - strikethrough_position, - width, - strikethrough_thickness); -} - -/** - * pango_ft2_render_layout_line_subpixel: - * @bitmap: a FT_Bitmap to render the line onto - * @line: a #PangoLayoutLine - * @x: the x position of start of string (in pango units) - * @y: the y position of baseline (in pango units) - * - * Render a #PangoLayoutLine onto a FreeType2 bitmap, with he - * location specified in fixed-point pango units rather than - * pixels. (Using this will avoid extra inaccuracies from - * rounding to integer pixels multiple times, even if the - * final glyph positions are integers.) - * - * Since: 1.6 - */ -void -pango_ft2_render_layout_line_subpixel (FT_Bitmap *bitmap, - PangoLayoutLine *line, - int x, - int y) -{ - GSList *tmp_list = line->runs; - PangoRectangle logical_rect; - PangoRectangle ink_rect; - int x_off = 0; - const PangoMatrix *matrix; - - matrix = pango_context_get_matrix (pango_layout_get_context (line->layout)); - - while (tmp_list) - { - PangoUnderline uline = PANGO_UNDERLINE_NONE; - gboolean strike, shape_set; - gint rise; - PangoLayoutRun *run = tmp_list->data; - - tmp_list = tmp_list->next; - - pango_ft2_get_item_properties (run->item, - &uline, &strike, &rise, - &shape_set, &ink_rect, &logical_rect); - - if (!shape_set) - { - if (uline == PANGO_UNDERLINE_NONE && !strike) - pango_glyph_string_extents (run->glyphs, run->item->analysis.font, - NULL, &logical_rect); - else - pango_glyph_string_extents (run->glyphs, run->item->analysis.font, - &ink_rect, &logical_rect); - - pango_ft2_render_transformed (bitmap, matrix, - run->item->analysis.font, run->glyphs, - x + x_off, y - rise); - - if (uline != PANGO_UNDERLINE_NONE || strike) - { - PangoFontMetrics *metrics = pango_font_get_metrics (run->item->analysis.font, - run->item->analysis.language); - - if (uline != PANGO_UNDERLINE_NONE) - draw_underline (bitmap, matrix, metrics, - uline, - x_off + ink_rect.x, - ink_rect.width, - y - rise, - ink_rect.y + ink_rect.height); - - if (strike) - draw_strikethrough (bitmap, matrix, metrics, - x_off + ink_rect.x, - ink_rect.width, - y - rise); - - pango_font_metrics_unref (metrics); - } - } - - x_off += logical_rect.width; - } -} - - -/** - * pango_ft2_render_layout_line: - * @bitmap: a FT_Bitmap to render the line onto - * @line: a #PangoLayoutLine - * @x: the x position of start of string (in pixels) - * @y: the y position of baseline (in pixels) - * - * Render a #PangoLayoutLine onto a FreeType2 bitmap - */ -void -pango_ft2_render_layout_line (FT_Bitmap *bitmap, - PangoLayoutLine *line, - int x, - int y) -{ - pango_ft2_render_layout_line_subpixel (bitmap, line, x * PANGO_SCALE, y * PANGO_SCALE); -} - - -/** - * pango_ft2_render_layout_subpixel: - * @bitmap: a FT_Bitmap to render the layout onto - * @layout: a #PangoLayout - * @x: the X position of the left of the layout (in Pango units) - * @y: the Y position of the top of the layout (in Pango units) - * - * Render a #PangoLayout onto a FreeType2 bitmap, with he - * location specified in fixed-point pango units rather than - * pixels. (Using this will avoid extra inaccuracies from - * rounding to integer pixels multiple times, even if the - * final glyph positions are integers.) - * - * Since: 1.6 - */ -void -pango_ft2_render_layout_subpixel (FT_Bitmap *bitmap, - PangoLayout *layout, - int x, - int y) -{ - PangoLayoutIter *iter; - - g_return_if_fail (bitmap != NULL); - g_return_if_fail (PANGO_IS_LAYOUT (layout)); - - iter = pango_layout_get_iter (layout); - - do - { - PangoRectangle logical_rect; - PangoLayoutLine *line; - int baseline; - - line = pango_layout_iter_get_line (iter); - - pango_layout_iter_get_line_extents (iter, NULL, &logical_rect); - baseline = pango_layout_iter_get_baseline (iter); - - pango_ft2_render_layout_line_subpixel (bitmap, - line, - x + logical_rect.x, - y + baseline); - } - while (pango_layout_iter_next_line (iter)); - - pango_layout_iter_free (iter); -} - -/** - * pango_ft2_render_layout: - * @bitmap: a FT_Bitmap to render the layout onto - * @layout: a #PangoLayout - * @x: the X position of the left of the layout (in pixels) - * @y: the Y position of the top of the layout (in pixels) - * - * Render a #PangoLayout onto a FreeType2 bitmap - */ -void -pango_ft2_render_layout (FT_Bitmap *bitmap, - PangoLayout *layout, - int x, - int y) -{ - pango_ft2_render_layout_subpixel (bitmap, layout, x * PANGO_SCALE, y * PANGO_SCALE); -} - -/* This utility function is duplicated here and in pango-layout.c; should it be - * public? Trouble is - what is the appropriate set of properties? - */ -static void -pango_ft2_get_item_properties (PangoItem *item, - PangoUnderline *uline, - gboolean *strikethrough, - gint *rise, - gboolean *shape_set, - PangoRectangle *ink_rect, - PangoRectangle *logical_rect) -{ - GSList *tmp_list = item->analysis.extra_attrs; - - if (strikethrough) - *strikethrough = FALSE; - - if (rise) - *rise = 0; - - if (shape_set) - *shape_set = FALSE; - - while (tmp_list) - { - PangoAttribute *attr = tmp_list->data; - - switch (attr->klass->type) - { - case PANGO_ATTR_UNDERLINE: - if (uline) - *uline = ((PangoAttrInt *)attr)->value; - break; - - case PANGO_ATTR_STRIKETHROUGH: - if (strikethrough) - *strikethrough = ((PangoAttrInt *)attr)->value; - break; - - case PANGO_ATTR_SHAPE: - if (shape_set) - *shape_set = TRUE; - if (logical_rect) - *logical_rect = ((PangoAttrShape *)attr)->logical_rect; - if (ink_rect) - *ink_rect = ((PangoAttrShape *)attr)->ink_rect; - break; - - case PANGO_ATTR_RISE: - if (rise) - *rise = ((PangoAttrInt *)attr)->value; - break; - - default: - break; - } - - tmp_list = tmp_list->next; - } -} - typedef struct { FT_Error code; @@ -1068,7 +507,6 @@ _pango_ft2_ft_strerror (FT_Error error) } } - void * _pango_ft2_font_get_cache_glyph_data (PangoFont *font, int glyph_index) |