FT_Outline_Render( FT_Library library, FT_Outline* outline, FT_Raster_Params* params ) { FT_Error error; FT_Bool update = 0; FT_Renderer renderer; FT_ListNode node; if ( !library ) return FT_Err_Invalid_Library_Handle; if ( !outline || !params ) return FT_Err_Invalid_Argument; renderer = library->cur_renderer; node = library->renderers.head; params->source = (void*)outline; error = FT_Err_Cannot_Render_Glyph; while ( renderer ) { error = renderer->raster_render( renderer->raster, params ); if ( !error || FT_ERROR_BASE( error ) != FT_Err_Cannot_Render_Glyph ) break; /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ /* is unsupported by the current renderer for this glyph image */ /* format */ /* now, look for another renderer that supports the same */ /* format */ renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, &node ); update = 1; } /* if we changed the current renderer for the glyph image format */ /* we need to select it as the next current one */ if ( !error && update && renderer ) FT_Set_Renderer( library, renderer, 0, 0 ); return error; }
FT_Outline_Render( FT_Library library, FT_Outline* outline, FT_Raster_Params* params ) { FT_Error error; FT_Renderer renderer; FT_ListNode node; if ( !library ) return FT_THROW( Invalid_Library_Handle ); if ( !outline ) return FT_THROW( Invalid_Outline ); if ( !params ) return FT_THROW( Invalid_Argument ); renderer = library->cur_renderer; node = library->renderers.head; params->source = (void*)outline; error = FT_ERR( Cannot_Render_Glyph ); while ( renderer ) { error = renderer->raster_render( renderer->raster, params ); if ( !error || FT_ERR_NEQ( error, Cannot_Render_Glyph ) ) break; /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ /* is unsupported by the current renderer for this glyph image */ /* format */ /* now, look for another renderer that supports the same */ /* format */ renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, &node ); } return error; }
/* convert a slot's glyph image into a bitmap */ static FT_Error ft_smooth_render( FT_Renderer render, FT_GlyphSlot slot, FT_UInt mode, FT_Vector* origin ) { FT_Error error; FT_Outline* outline = NULL; FT_BBox cbox; FT_UInt width, height, pitch; FT_Bitmap* bitmap; FT_Memory memory; FT_Raster_Params params; /* check glyph image format */ if ( slot->format != render->glyph_format ) { error = Smooth_Err_Invalid_Argument; goto Exit; } /* check mode */ if ( mode != ft_render_mode_normal ) return Smooth_Err_Cannot_Render_Glyph; outline = &slot->outline; /* translate the outline to the new origin if needed */ if ( origin ) FT_Outline_Translate( outline, origin->x, origin->y ); /* compute the control box, and grid fit it */ FT_Outline_Get_CBox( outline, &cbox ); cbox.xMin &= -64; cbox.yMin &= -64; cbox.xMax = ( cbox.xMax + 63 ) & -64; cbox.yMax = ( cbox.yMax + 63 ) & -64; width = ( cbox.xMax - cbox.xMin ) >> 6; height = ( cbox.yMax - cbox.yMin ) >> 6; bitmap = &slot->bitmap; memory = render->root.memory; /* release old bitmap buffer */ if ( slot->flags & FT_GLYPH_OWN_BITMAP ) { FT_FREE( bitmap->buffer ); slot->flags &= ~FT_GLYPH_OWN_BITMAP; } /* allocate new one, depends on pixel format */ pitch = width; bitmap->pixel_mode = ft_pixel_mode_grays; bitmap->num_grays = 256; bitmap->width = width; bitmap->rows = height; bitmap->pitch = pitch; if ( FT_ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) ) goto Exit; slot->flags |= FT_GLYPH_OWN_BITMAP; /* translate outline to render it into the bitmap */ FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin ); /* set up parameters */ params.target = bitmap; params.source = outline; params.flags = ft_raster_flag_aa; /* render outline into the bitmap */ error = render->raster_render( render->raster, ¶ms ); FT_Outline_Translate( outline, cbox.xMin, cbox.yMin ); if ( error ) goto Exit; slot->format = ft_glyph_format_bitmap; slot->bitmap_left = cbox.xMin >> 6; slot->bitmap_top = cbox.yMax >> 6; Exit: if ( outline && origin ) FT_Outline_Translate( outline, -origin->x, -origin->y ); return error; }
/* convert a slot's glyph image into a bitmap */ static FT_Error ft_raster1_render(FT_Renderer render, FT_GlyphSlot slot, FT_UInt mode, FT_Vector *origin) { FT_Error error; FT_Outline *outline; FT_BBox cbox; FT_UInt width, height, pitch; FT_Bitmap *bitmap; FT_Memory memory; FT_Raster_Params params; /* check glyph image format */ if(slot->format != render->glyph_format) { error = FT_Err_Invalid_Argument; goto Exit; } /* check rendering mode */ if(mode != ft_render_mode_mono) { /* raster1 is only capable of producing monochrome bitmaps */ if(render->clazz == &ft_raster1_renderer_class) { return FT_Err_Cannot_Render_Glyph; } } else { /* raster5 is only capable of producing 5-gray-levels bitmaps */ if(render->clazz == &ft_raster5_renderer_class) { return FT_Err_Cannot_Render_Glyph; } } outline = &slot->outline; /* translate the outline to the new origin if needed */ if(origin) { FT_Outline_Translate(outline, origin->x, origin->y); } /* compute the control box, and grid fit it */ FT_Outline_Get_CBox(outline, &cbox); cbox.xMin &= -64; cbox.yMin &= -64; cbox.xMax = (cbox.xMax + 63) & - 64; cbox.yMax = (cbox.yMax + 63) & - 64; width = (cbox.xMax - cbox.xMin) >> 6; height = (cbox.yMax - cbox.yMin) >> 6; bitmap = &slot->bitmap; memory = render->root.memory; /* release old bitmap buffer */ if(slot->flags & ft_glyph_own_bitmap) { FREE(bitmap->buffer); slot->flags &= ~ft_glyph_own_bitmap; } /* allocate new one, depends on pixel format */ if(!(mode & ft_render_mode_mono)) { /* we pad to 32 bits, only for backwards compatibility with FT 1.x */ pitch = (width + 3) & - 4; bitmap->pixel_mode = ft_pixel_mode_grays; bitmap->num_grays = 256; } else { pitch = (width + 7) >> 3; bitmap->pixel_mode = ft_pixel_mode_mono; } bitmap->width = width; bitmap->rows = height; bitmap->pitch = pitch; if(ALLOC(bitmap->buffer, (FT_ULong)pitch * height)) { goto Exit; } slot->flags |= ft_glyph_own_bitmap; /* translate outline to render it into the bitmap */ FT_Outline_Translate(outline, -cbox.xMin, -cbox.yMin); /* set up parameters */ params.target = bitmap; params.source = outline; params.flags = 0; if(bitmap->pixel_mode == ft_pixel_mode_grays) { params.flags |= ft_raster_flag_aa; } /* render outline into the bitmap */ error = render->raster_render(render->raster, ¶ms); if(error) { goto Exit; } slot->format = ft_glyph_format_bitmap; slot->bitmap_left = cbox.xMin >> 6; slot->bitmap_top = cbox.yMax >> 6; Exit: return error; }
/* convert a slot's glyph image into a bitmap */ static FT_Error ft_smooth_render_generic( FT_Renderer render, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector* origin, FT_Render_Mode required_mode, FT_Int hmul, FT_Int vmul ) { FT_Error error; FT_Outline* outline = NULL; FT_BBox cbox; FT_UInt width, height, pitch; FT_Bitmap* bitmap; FT_Memory memory; FT_Raster_Params params; /* check glyph image format */ if ( slot->format != render->glyph_format ) { error = Smooth_Err_Invalid_Argument; goto Exit; } /* check mode */ if ( mode != required_mode ) return Smooth_Err_Cannot_Render_Glyph; outline = &slot->outline; /* translate the outline to the new origin if needed */ if ( origin ) FT_Outline_Translate( outline, origin->x, origin->y ); /* compute the control box, and grid fit it */ FT_Outline_Get_CBox( outline, &cbox ); cbox.xMin = FT_PIX_FLOOR( cbox.xMin ); cbox.yMin = FT_PIX_FLOOR( cbox.yMin ); cbox.xMax = FT_PIX_CEIL( cbox.xMax ); cbox.yMax = FT_PIX_CEIL( cbox.yMax ); width = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 ); height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 ); bitmap = &slot->bitmap; memory = render->root.memory; /* release old bitmap buffer */ if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { FT_FREE( bitmap->buffer ); slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } /* allocate new one, depends on pixel format */ pitch = width; if ( hmul ) { width = width * hmul; pitch = FT_PAD_CEIL( width, 4 ); } if ( vmul ) height *= vmul; bitmap->pixel_mode = FT_PIXEL_MODE_GRAY; bitmap->num_grays = 256; bitmap->width = width; bitmap->rows = height; bitmap->pitch = pitch; if ( FT_ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) ) goto Exit; slot->internal->flags |= FT_GLYPH_OWN_BITMAP; /* translate outline to render it into the bitmap */ FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin ); /* set up parameters */ params.target = bitmap; params.source = outline; params.flags = FT_RASTER_FLAG_AA; /* implode outline if needed */ { FT_Int n; FT_Vector* vec; if ( hmul ) for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ ) vec->x *= hmul; if ( vmul ) for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ ) vec->y *= vmul; } /* render outline into the bitmap */ error = render->raster_render( render->raster, ¶ms ); /* deflate outline if needed */ { FT_Int n; FT_Vector* vec; if ( hmul ) for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ ) vec->x /= hmul; if ( vmul ) for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ ) vec->y /= vmul; } FT_Outline_Translate( outline, cbox.xMin, cbox.yMin ); if ( error ) goto Exit; slot->format = FT_GLYPH_FORMAT_BITMAP; slot->bitmap_left = (FT_Int)( cbox.xMin >> 6 ); slot->bitmap_top = (FT_Int)( cbox.yMax >> 6 ); Exit: if ( outline && origin ) FT_Outline_Translate( outline, -origin->x, -origin->y ); return error; }