diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2011-04-07 19:06:11 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-04-07 21:13:50 +0200 |
commit | f5d521e184ad64893f4fc49cc867da53eff3b2b1 (patch) | |
tree | eae3d883c10b8b74ff260869bf8f601510b3302c | |
parent | a9560ecb1b1140623d381ef04ede719cc9ff6819 (diff) | |
download | mupdf-f5d521e184ad64893f4fc49cc867da53eff3b2b1.tar.xz |
Add text antialiasing too.
Update the text rendering code to use the raster renderer in freetype rather
than the smooth one. No change to the hinting methods used yet.
-rw-r--r-- | Makethird | 3 | ||||
-rw-r--r-- | fitz/res_font.c | 66 | ||||
-rw-r--r-- | scripts/slimftmodules.h | 2 | ||||
-rw-r--r-- | win32/libthirdparty.vcproj | 5 |
4 files changed, 64 insertions, 12 deletions
@@ -32,6 +32,7 @@ FREETYPE_SRC := \ cff.c \ psaux.c \ psnames.c \ + raster.c \ sfnt.c \ smooth.c \ truetype.c \ @@ -54,6 +55,8 @@ $(OUT)/ft_%.o: $(FREETYPE_DIR)/src/psaux/%.c | $(OUT) $(CC_CMD) $(FT_CFLAGS) $(OUT)/ft_%.o: $(FREETYPE_DIR)/src/psnames/%.c | $(OUT) $(CC_CMD) $(FT_CFLAGS) +$(OUT)/ft_%.o: $(FREETYPE_DIR)/src/raster/%.c | $(OUT) + $(CC_CMD) $(FT_CFLAGS) $(OUT)/ft_%.o: $(FREETYPE_DIR)/src/smooth/%.c | $(OUT) $(CC_CMD) $(FT_CFLAGS) $(OUT)/ft_%.o: $(FREETYPE_DIR)/src/sfnt/%.c | $(OUT) diff --git a/fitz/res_font.c b/fitz/res_font.c index f94940a6..b76f713b 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -331,7 +331,7 @@ fz_render_ft_glyph(fz_font *font, int gid, fz_matrix trm) } } - fterr = FT_Render_Glyph(face->glyph, ft_render_mode_normal); + fterr = FT_Render_Glyph(face->glyph, fz_get_aa_level() > 0 ? ft_render_mode_normal : ft_render_mode_mono); if (fterr) { fz_warn("freetype render glyph (gid %d): %s", gid, ft_error_string(fterr)); @@ -344,11 +344,34 @@ fz_render_ft_glyph(fz_font *font, int gid, fz_matrix trm) face->glyph->bitmap.width, face->glyph->bitmap.rows); - for (y = 0; y < glyph->h; y++) + if (face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { - memcpy(glyph->samples + y * glyph->w, - face->glyph->bitmap.buffer + (glyph->h - y - 1) * face->glyph->bitmap.pitch, - glyph->w); + for (y = 0; y < glyph->h; y++) + { + unsigned char *out = glyph->samples + y * glyph->w; + unsigned char *in = face->glyph->bitmap.buffer + (glyph->h - y - 1) * face->glyph->bitmap.pitch; + unsigned char bit = 0x80; + int w = glyph->w; + while (w--) + { + *out++ = (*in & bit) ? 255 : 0; + bit >>= 1; + if (bit == 0) + { + bit = 0x80; + in++; + } + } + } + } + else + { + for (y = 0; y < glyph->h; y++) + { + memcpy(glyph->samples + y * glyph->w, + face->glyph->bitmap.buffer + (glyph->h - y - 1) * face->glyph->bitmap.pitch, + glyph->w); + } } return glyph; @@ -420,7 +443,7 @@ fz_render_ft_stroked_glyph(fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, return NULL; } - fterr = FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1); + fterr = FT_Glyph_To_Bitmap(&glyph, fz_get_aa_level() > 0 ? ft_render_mode_normal : ft_render_mode_mono, 0, 1); if (fterr) { fz_warn("FT_Glyph_To_Bitmap: %s", ft_error_string(fterr)); @@ -436,11 +459,34 @@ fz_render_ft_stroked_glyph(fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, bitmap->bitmap.width, bitmap->bitmap.rows); - for (y = 0; y < pix->h; y++) + if (face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { - memcpy(pix->samples + y * pix->w, - bitmap->bitmap.buffer + (pix->h - y - 1) * bitmap->bitmap.pitch, - pix->w); + for (y = 0; y < pix->h; y++) + { + unsigned char *out = pix->samples + y * pix->w; + unsigned char *in = bitmap->bitmap.buffer + (pix->h - y - 1) * bitmap->bitmap.pitch; + unsigned char bit = 0x80; + int w = bitmap->bitmap.width; + while (w--) + { + *out++ = (*in & bit) ? 255 : 0; + bit >>= 1; + if (bit == 0) + { + bit = 0x80; + in++; + } + } + } + } + else + { + for (y = 0; y < pix->h; y++) + { + memcpy(pix->samples + y * pix->w, + bitmap->bitmap.buffer + (pix->h - y - 1) * bitmap->bitmap.pitch, + pix->w); + } } FT_Done_Glyph(glyph); diff --git a/scripts/slimftmodules.h b/scripts/slimftmodules.h index 96e87d8d..65ed9f47 100644 --- a/scripts/slimftmodules.h +++ b/scripts/slimftmodules.h @@ -12,7 +12,7 @@ FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class ) FT_USE_MODULE( FT_Module_Class, psaux_module_class ) FT_USE_MODULE( FT_Module_Class, psnames_module_class ) // FT_USE_MODULE( FT_Module_Class, pshinter_module_class ) -// FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) // FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class ) diff --git a/win32/libthirdparty.vcproj b/win32/libthirdparty.vcproj index c2d0c643..082f5bd1 100644 --- a/win32/libthirdparty.vcproj +++ b/win32/libthirdparty.vcproj @@ -5,7 +5,6 @@ Name="libthirdparty" ProjectGUID="{5EDCF4FD-0291-4FB9-8D96-D58957CA5E3C}" RootNamespace="mupdf" - TargetFrameworkVersion="196613" > <Platforms> <Platform @@ -466,6 +465,10 @@ > </File> <File + RelativePath="..\thirdparty\freetype-2.4.4\src\raster\raster.c" + > + </File> + <File RelativePath="..\thirdparty\freetype-2.4.4\src\sfnt\sfnt.c" > </File> |