summaryrefslogtreecommitdiff
path: root/source/fitz/font.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-08-23 19:24:58 +0100
committerRobin Watts <robin.watts@artifex.com>2013-08-30 16:26:39 +0100
commit2b2c67836932b1dada7f7f28e42fe4ed06c4e4ed (patch)
treebed929cca0ac26018ffbc9c98cf177da63562536 /source/fitz/font.c
parent8f248600b2834fb121db4990aa756c40da8ddd0e (diff)
downloadmupdf-2b2c67836932b1dada7f7f28e42fe4ed06c4e4ed.tar.xz
Use RLE coding scheme for glyph bitmaps.
Rather than generating fz_pixmaps for glyphs, we generate fz_glyphs. fz_glyphs can either contain a pixmap, or an RLEd representation (if it's a mask, and it's smaller). Should take less memory in the cache, and should be faster to plot.
Diffstat (limited to 'source/fitz/font.c')
-rw-r--r--source/fitz/font.c56
1 files changed, 11 insertions, 45 deletions
diff --git a/source/fitz/font.c b/source/fitz/font.c
index cbf4d466..1f44d096 100644
--- a/source/fitz/font.c
+++ b/source/fitz/font.c
@@ -401,58 +401,24 @@ fz_adjust_ft_glyph_width(fz_context *ctx, fz_font *font, int gid, fz_matrix *trm
return trm;
}
-static fz_pixmap *
+static fz_glyph *
fz_copy_ft_bitmap(fz_context *ctx, int left, int top, FT_Bitmap *bitmap)
{
- fz_pixmap *pixmap;
- int y;
-
- pixmap = fz_new_pixmap(ctx, NULL, bitmap->width, bitmap->rows);
- pixmap->x = left;
- pixmap->y = top - bitmap->rows;
-
if (bitmap->pixel_mode == FT_PIXEL_MODE_MONO)
- {
- for (y = 0; y < pixmap->h; y++)
- {
- unsigned char *out = pixmap->samples + (unsigned int)(y * pixmap->w);
- unsigned char *in = bitmap->buffer + (unsigned int)((pixmap->h - y - 1) * bitmap->pitch);
- unsigned char bit = 0x80;
- int w = pixmap->w;
- while (w--)
- {
- *out++ = (*in & bit) ? 255 : 0;
- bit >>= 1;
- if (bit == 0)
- {
- bit = 0x80;
- in++;
- }
- }
- }
- }
+ return fz_new_glyph_from_1bpp_data(ctx, left, top - bitmap->rows, bitmap->width, bitmap->rows, bitmap->buffer + (bitmap->rows-1)*bitmap->pitch, -bitmap->pitch);
else
- {
- for (y = 0; y < pixmap->h; y++)
- {
- memcpy(pixmap->samples + (unsigned int)(y * pixmap->w),
- bitmap->buffer + (unsigned int)((pixmap->h - y - 1) * bitmap->pitch),
- pixmap->w);
- }
- }
-
- return pixmap;
+ return fz_new_glyph_from_8bpp_data(ctx, left, top - bitmap->rows, bitmap->width, bitmap->rows, bitmap->buffer + (bitmap->rows-1)*bitmap->pitch, -bitmap->pitch);
}
/* The glyph cache lock is always taken when this is called. */
-fz_pixmap *
+fz_glyph *
fz_render_ft_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, int aa)
{
FT_Face face = font->ft_face;
FT_Matrix m;
FT_Vector v;
FT_Error fterr;
- fz_pixmap *result;
+ fz_glyph *result;
fz_matrix local_trm = *trm;
float strength = fz_matrix_expansion(trm) * 0.02f;
@@ -561,7 +527,7 @@ retry_unhinted:
return result;
}
-fz_pixmap *
+fz_glyph *
fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, const fz_matrix *ctm, fz_stroke_state *state)
{
FT_Face face = font->ft_face;
@@ -573,7 +539,7 @@ fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, const fz_mat
FT_Stroker stroker;
FT_Glyph glyph;
FT_BitmapGlyph bitmap;
- fz_pixmap *pixmap;
+ fz_glyph *result;
FT_Stroker_LineJoin line_join;
fz_matrix local_trm = *trm;
@@ -666,7 +632,7 @@ fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, const fz_mat
bitmap = (FT_BitmapGlyph)glyph;
fz_try(ctx)
{
- pixmap = fz_copy_ft_bitmap(ctx, bitmap->left, bitmap->top, &bitmap->bitmap);
+ result = fz_copy_ft_bitmap(ctx, bitmap->left, bitmap->top, &bitmap->bitmap);
}
fz_always(ctx)
{
@@ -678,7 +644,7 @@ fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, const fz_mat
fz_rethrow(ctx);
}
- return pixmap;
+ return result;
}
static fz_rect *
@@ -967,7 +933,7 @@ fz_bound_t3_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm,
return bounds;
}
-fz_pixmap *
+fz_glyph *
fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, fz_colorspace *model, fz_irect scissor)
{
fz_display_list *list;
@@ -1032,7 +998,7 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm
else
result = glyph;
- return result;
+ return fz_new_glyph_from_pixmap(ctx, result);
}
void