2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ftrend1.c
|
|
|
|
*
|
|
|
|
* The FreeType glyph rasterizer interface (body).
|
|
|
|
*
|
2024-01-27 17:11:22 +01:00
|
|
|
* Copyright (C) 1996-2024 by
|
2018-06-03 09:01:17 +02:00
|
|
|
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
|
|
|
*
|
|
|
|
* This file is part of the FreeType project, and may only be used,
|
|
|
|
* modified, and distributed under the terms of the FreeType project
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
|
|
|
* this file you indicate that you have read the license and
|
|
|
|
* understand and accept it fully.
|
|
|
|
*
|
|
|
|
*/
|
2000-10-26 02:30:33 +02:00
|
|
|
|
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/internal/ftdebug.h>
|
|
|
|
#include <freetype/internal/ftobjs.h>
|
|
|
|
#include <freetype/ftoutln.h>
|
2001-03-20 12:14:24 +01:00
|
|
|
#include "ftrend1.h"
|
|
|
|
#include "ftraster.h"
|
2000-10-26 02:30:33 +02:00
|
|
|
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
#include "rasterrs.h"
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2000-10-26 02:30:33 +02:00
|
|
|
/* initialize renderer -- init its raster */
|
2001-06-28 01:25:46 +02:00
|
|
|
static FT_Error
|
2023-05-07 20:51:32 +02:00
|
|
|
ft_raster1_init( FT_Module module ) /* FT_Renderer */
|
2000-10-26 02:30:33 +02:00
|
|
|
{
|
2023-05-07 20:51:32 +02:00
|
|
|
FT_Renderer render = (FT_Renderer)module;
|
|
|
|
|
|
|
|
|
2017-05-14 21:57:27 +02:00
|
|
|
render->clazz->raster_class->raster_reset( render->raster, NULL, 0 );
|
2000-10-26 02:30:33 +02:00
|
|
|
|
2013-03-14 11:21:17 +01:00
|
|
|
return FT_Err_Ok;
|
2000-10-26 02:30:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set render-specific mode */
|
2001-06-28 01:25:46 +02:00
|
|
|
static FT_Error
|
|
|
|
ft_raster1_set_mode( FT_Renderer render,
|
|
|
|
FT_ULong mode_tag,
|
|
|
|
FT_Pointer data )
|
2000-10-26 02:30:33 +02:00
|
|
|
{
|
|
|
|
/* we simply pass it to the raster */
|
|
|
|
return render->clazz->raster_class->raster_set_mode( render->raster,
|
|
|
|
mode_tag,
|
|
|
|
data );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* transform a given glyph image */
|
2001-06-28 01:25:46 +02:00
|
|
|
static FT_Error
|
* include/freetype/ftimage.h (FT_Raster_RenderFunc),
include/freetype/ftrender.h (FT_Glyph_TransformFunc,
FT_Renderer_Render_Func, FT_Renderer_TransformFunc),
src/base/ftglyph.c (ft_outline_glyph_transform),
src/raster/ftrend1.c (ft_raster1_transform, ft_raster1_render),
src/smooth/ftgrays.c (FT_Outline_Decompose, gray_raster_render),
src/smooth/ftsmooth.c (ft_smooth_transform,
ft_smooth_render_generic, ft_smooth_render, ft_smooth_render_lcd,
ft_smooth_render_lcd_v): Decorate parameters with `const' where
appropriate.
* src/raster/ftraster.c (RASTER_RENDER_POOL): Removed. Obsolete.
(ft_black_render): Decorate parameters with `const' where
appropriate.
* src/sfnt/ttcmap.c (tt_cmap4_set_range): Fix typo (FT_PEEK_SHORT ->
FT_PEEK_USHORT) which caused crashes. Reported by Ismail Donmez
<ismail@kde.org.tr>.
2005-05-11 22:04:35 +02:00
|
|
|
ft_raster1_transform( FT_Renderer render,
|
|
|
|
FT_GlyphSlot slot,
|
|
|
|
const FT_Matrix* matrix,
|
|
|
|
const FT_Vector* delta )
|
2000-10-26 02:30:33 +02:00
|
|
|
{
|
2013-03-14 11:21:17 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2000-10-26 02:30:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( slot->format != render->glyph_format )
|
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Argument );
|
2000-10-26 02:30:33 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( matrix )
|
|
|
|
FT_Outline_Transform( &slot->outline, matrix );
|
|
|
|
|
|
|
|
if ( delta )
|
|
|
|
FT_Outline_Translate( &slot->outline, delta->x, delta->y );
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* return the glyph's control box */
|
2001-06-28 01:25:46 +02:00
|
|
|
static void
|
|
|
|
ft_raster1_get_cbox( FT_Renderer render,
|
|
|
|
FT_GlyphSlot slot,
|
|
|
|
FT_BBox* cbox )
|
2000-10-26 02:30:33 +02:00
|
|
|
{
|
2016-09-28 19:10:52 +02:00
|
|
|
FT_ZERO( cbox );
|
2000-10-26 02:30:33 +02:00
|
|
|
|
|
|
|
if ( slot->format == render->glyph_format )
|
|
|
|
FT_Outline_Get_CBox( &slot->outline, cbox );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* convert a slot's glyph image into a bitmap */
|
2001-06-28 01:25:46 +02:00
|
|
|
static FT_Error
|
* include/freetype/ftimage.h (FT_Raster_RenderFunc),
include/freetype/ftrender.h (FT_Glyph_TransformFunc,
FT_Renderer_Render_Func, FT_Renderer_TransformFunc),
src/base/ftglyph.c (ft_outline_glyph_transform),
src/raster/ftrend1.c (ft_raster1_transform, ft_raster1_render),
src/smooth/ftgrays.c (FT_Outline_Decompose, gray_raster_render),
src/smooth/ftsmooth.c (ft_smooth_transform,
ft_smooth_render_generic, ft_smooth_render, ft_smooth_render_lcd,
ft_smooth_render_lcd_v): Decorate parameters with `const' where
appropriate.
* src/raster/ftraster.c (RASTER_RENDER_POOL): Removed. Obsolete.
(ft_black_render): Decorate parameters with `const' where
appropriate.
* src/sfnt/ttcmap.c (tt_cmap4_set_range): Fix typo (FT_PEEK_SHORT ->
FT_PEEK_USHORT) which caused crashes. Reported by Ismail Donmez
<ismail@kde.org.tr>.
2005-05-11 22:04:35 +02:00
|
|
|
ft_raster1_render( FT_Renderer render,
|
|
|
|
FT_GlyphSlot slot,
|
|
|
|
FT_Render_Mode mode,
|
|
|
|
const FT_Vector* origin )
|
2000-10-26 02:30:33 +02:00
|
|
|
{
|
2017-09-29 04:59:31 +02:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2017-09-28 06:20:50 +02:00
|
|
|
FT_Outline* outline = &slot->outline;
|
|
|
|
FT_Bitmap* bitmap = &slot->bitmap;
|
|
|
|
FT_Memory memory = render->root.memory;
|
|
|
|
FT_Pos x_shift = 0;
|
|
|
|
FT_Pos y_shift = 0;
|
2000-10-26 02:30:33 +02:00
|
|
|
|
|
|
|
FT_Raster_Params params;
|
|
|
|
|
|
|
|
|
|
|
|
/* check glyph image format */
|
|
|
|
if ( slot->format != render->glyph_format )
|
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Argument );
|
2000-10-26 02:30:33 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check rendering mode */
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
if ( mode != FT_RENDER_MODE_MONO )
|
2000-10-26 02:30:33 +02:00
|
|
|
{
|
|
|
|
/* raster1 is only capable of producing monochrome bitmaps */
|
2015-01-14 18:06:22 +01:00
|
|
|
return FT_THROW( Cannot_Render_Glyph );
|
2000-10-26 02:30:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* release old bitmap buffer */
|
2003-06-18 08:59:57 +02:00
|
|
|
if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
|
2000-10-26 02:30:33 +02:00
|
|
|
{
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( bitmap->buffer );
|
2003-06-18 08:59:57 +02:00
|
|
|
slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
|
2000-10-26 02:30:33 +02:00
|
|
|
}
|
|
|
|
|
2018-08-31 05:28:30 +02:00
|
|
|
if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) )
|
2018-08-10 04:18:00 +02:00
|
|
|
{
|
|
|
|
error = FT_THROW( Raster_Overflow );
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
2017-09-28 06:20:50 +02:00
|
|
|
/* allocate new one */
|
|
|
|
if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
|
2000-10-26 02:30:33 +02:00
|
|
|
goto Exit;
|
|
|
|
|
2003-06-18 08:59:57 +02:00
|
|
|
slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
|
2000-10-26 02:30:33 +02:00
|
|
|
|
2017-09-28 06:20:50 +02:00
|
|
|
x_shift = -slot->bitmap_left * 64;
|
2017-09-30 20:28:58 +02:00
|
|
|
y_shift = ( (FT_Int)bitmap->rows - slot->bitmap_top ) * 64;
|
2017-09-28 06:20:50 +02:00
|
|
|
|
|
|
|
if ( origin )
|
|
|
|
{
|
|
|
|
x_shift += origin->x;
|
|
|
|
y_shift += origin->y;
|
|
|
|
}
|
|
|
|
|
2000-10-26 02:30:33 +02:00
|
|
|
/* translate outline to render it into the bitmap */
|
2017-09-28 06:20:50 +02:00
|
|
|
if ( x_shift || y_shift )
|
|
|
|
FT_Outline_Translate( outline, x_shift, y_shift );
|
2000-10-26 02:30:33 +02:00
|
|
|
|
|
|
|
/* set up parameters */
|
|
|
|
params.target = bitmap;
|
|
|
|
params.source = outline;
|
2017-09-29 04:59:31 +02:00
|
|
|
params.flags = FT_RASTER_FLAG_DEFAULT;
|
2000-10-26 02:30:33 +02:00
|
|
|
|
|
|
|
/* render outline into the bitmap */
|
|
|
|
error = render->raster_render( render->raster, ¶ms );
|
|
|
|
|
|
|
|
Exit:
|
2017-09-29 04:59:31 +02:00
|
|
|
if ( !error )
|
|
|
|
/* everything is fine; the glyph is now officially a bitmap */
|
|
|
|
slot->format = FT_GLYPH_FORMAT_BITMAP;
|
|
|
|
else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
|
2017-09-28 06:20:50 +02:00
|
|
|
{
|
|
|
|
FT_FREE( bitmap->buffer );
|
|
|
|
slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
|
|
|
|
}
|
|
|
|
|
2017-09-29 04:59:31 +02:00
|
|
|
if ( x_shift || y_shift )
|
|
|
|
FT_Outline_Translate( outline, -x_shift, -y_shift );
|
|
|
|
|
2000-10-26 02:30:33 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-17 17:12:50 +02:00
|
|
|
FT_DEFINE_RENDERER(
|
|
|
|
ft_raster1_renderer_class,
|
2011-11-30 10:46:53 +01:00
|
|
|
|
* include/freetype/ftglyph.h (ft_glyph_bbox_unscaled,
ft_glyph_bbox_subpixels, ft_glyph_bbox_gridfit,
ft_glyph_bbox_truncate, ft_glyph_bbox_pixels): Replaced with
FT_GLYPH_BBOX_UNSCALED, FT_GLYPH_BBOX_SUBPIXELS,
FT_GLYPH_BBIX_GRIDFIT, FT_GLYPH_BBOX_TRUNCATE, FT_GLYPH_BBOX_PIXELS.
The lowercase variants are now (deprecated aliases) to the uppercase
versions.
Updated all other files.
* include/freetype/ftmodule.h (ft_module_font_driver,
ft_module_renderer, ft_module_hinter, ft_module_styler,
ft_module_driver_scalable, ft_module_driver_no_outlines,
ft_module_driver_has_hinter): Replaced with FT_MODULE_FONT_DRIVER,
FT_MODULE_RENDERER, FT_MODULE_HINTER, FT_MODULE_STYLER,
FT_MODULE_DRIVER_SCALABLE, FT_MODULE_DRIVER_NO_OUTLINES,
FT_MODULE_DRIVER_HAS_HINTER.
The lowercase variants are now (deprecated aliases) to the uppercase
versions.
Updated all other files.
* src/base/ftglyph.c (FT_Glyph_Get_CBox): Handle bbox_mode better
as enumeration.
* src/pcf/pcfdrivr.c (pcf_driver_class), src/winfonts/winfnt.c
(winfnt_driver_class), src/bdf/bdfdrivr.c (bdf_driver_class): Add
the FT_MODULE_DRIVER_NO_OUTLINES flag.
2003-06-17 12:42:27 +02:00
|
|
|
FT_MODULE_RENDERER,
|
2011-11-30 10:46:53 +01:00
|
|
|
sizeof ( FT_RendererRec ),
|
2000-10-26 02:30:33 +02:00
|
|
|
|
|
|
|
"raster1",
|
|
|
|
0x10000L,
|
|
|
|
0x20000L,
|
|
|
|
|
2016-09-17 17:12:50 +02:00
|
|
|
NULL, /* module specific interface */
|
2000-10-26 02:30:33 +02:00
|
|
|
|
2023-06-02 01:38:36 +02:00
|
|
|
ft_raster1_init, /* FT_Module_Constructor module_init */
|
|
|
|
NULL, /* FT_Module_Destructor module_done */
|
|
|
|
NULL, /* FT_Module_Requester get_interface */
|
2000-10-26 02:30:33 +02:00
|
|
|
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
FT_GLYPH_FORMAT_OUTLINE,
|
2000-10-26 02:30:33 +02:00
|
|
|
|
2023-06-02 01:38:36 +02:00
|
|
|
ft_raster1_render, /* FT_Renderer_RenderFunc render_glyph */
|
|
|
|
ft_raster1_transform, /* FT_Renderer_TransformFunc transform_glyph */
|
|
|
|
ft_raster1_get_cbox, /* FT_Renderer_GetCBoxFunc get_glyph_cbox */
|
|
|
|
ft_raster1_set_mode, /* FT_Renderer_SetModeFunc set_mode */
|
2000-10-26 02:30:33 +02:00
|
|
|
|
2023-06-02 01:38:36 +02:00
|
|
|
&ft_standard_raster /* FT_Raster_Funcs* raster_class */
|
2009-04-05 17:16:13 +02:00
|
|
|
)
|
2000-10-26 02:30:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|