From 75b11e43c284ff80bf49a3c1a0980353b942ff89 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 29 Mar 2017 14:15:52 -0700 Subject: Erase unused freetype files. Change-Id: I024573f341cba48d9f5d2bc38683a016639b14e2 Reviewed-on: https://pdfium-review.googlesource.com/3119 Reviewed-by: dsinclair Commit-Queue: Lei Zhang --- third_party/freetype/src/sfnt/Jamfile | 40 - third_party/freetype/src/sfnt/pngshim.c | 378 -------- third_party/freetype/src/sfnt/pngshim.h | 50 -- third_party/freetype/src/sfnt/ttbdf.c | 250 ------ third_party/freetype/src/sfnt/ttbdf.h | 46 - third_party/freetype/src/sfnt/ttsbit.c | 1472 ------------------------------- third_party/freetype/src/sfnt/ttsbit.h | 63 -- 7 files changed, 2299 deletions(-) delete mode 100644 third_party/freetype/src/sfnt/Jamfile delete mode 100644 third_party/freetype/src/sfnt/pngshim.c delete mode 100644 third_party/freetype/src/sfnt/pngshim.h delete mode 100644 third_party/freetype/src/sfnt/ttbdf.c delete mode 100644 third_party/freetype/src/sfnt/ttbdf.h delete mode 100644 third_party/freetype/src/sfnt/ttsbit.c delete mode 100644 third_party/freetype/src/sfnt/ttsbit.h (limited to 'third_party/freetype/src/sfnt') diff --git a/third_party/freetype/src/sfnt/Jamfile b/third_party/freetype/src/sfnt/Jamfile deleted file mode 100644 index cc98d1011e..0000000000 --- a/third_party/freetype/src/sfnt/Jamfile +++ /dev/null @@ -1,40 +0,0 @@ -# FreeType 2 src/sfnt Jamfile -# -# Copyright 2001-2015 by -# 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. - -SubDir FT2_TOP $(FT2_SRC_DIR) sfnt ; - -{ - local _sources ; - - if $(FT2_MULTI) - { - _sources = pngshim - sfdriver - sfntpic - sfobjs - ttbdf - ttcmap - ttkern - ttload - ttmtx - ttpost - ttsbit - ; - } - else - { - _sources = sfnt ; - } - - Library $(FT2_LIB) : $(_sources).c ; -} - -# end of src/sfnt Jamfile diff --git a/third_party/freetype/src/sfnt/pngshim.c b/third_party/freetype/src/sfnt/pngshim.c deleted file mode 100644 index ea60452635..0000000000 --- a/third_party/freetype/src/sfnt/pngshim.c +++ /dev/null @@ -1,378 +0,0 @@ -/***************************************************************************/ -/* */ -/* pngshim.c */ -/* */ -/* PNG Bitmap glyph support. */ -/* */ -/* Copyright 2013-2015 by */ -/* Google, Inc. */ -/* Written by Stuart Gill and Behdad Esfahbod. */ -/* */ -/* 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. */ -/* */ -/***************************************************************************/ - - -#include -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_STREAM_H -#include FT_TRUETYPE_TAGS_H -#include FT_CONFIG_STANDARD_LIBRARY_H - - -#ifdef FT_CONFIG_OPTION_USE_PNG - - /* We always include , so make libpng shut up! */ -#define PNG_SKIP_SETJMP_CHECK 1 -#include -#include "pngshim.h" - -#include "sferrors.h" - - - /* This code is freely based on cairo-png.c. There's so many ways */ - /* to call libpng, and the way cairo does it is defacto standard. */ - - static unsigned int - multiply_alpha( unsigned int alpha, - unsigned int color ) - { - unsigned int temp = alpha * color + 0x80; - - - return ( temp + ( temp >> 8 ) ) >> 8; - } - - - /* Premultiplies data and converts RGBA bytes => native endian. */ - static void - premultiply_data( png_structp png, - png_row_infop row_info, - png_bytep data ) - { - unsigned int i; - - FT_UNUSED( png ); - - - for ( i = 0; i < row_info->rowbytes; i += 4 ) - { - unsigned char* base = &data[i]; - unsigned int alpha = base[3]; - - - if ( alpha == 0 ) - base[0] = base[1] = base[2] = base[3] = 0; - - else - { - unsigned int red = base[0]; - unsigned int green = base[1]; - unsigned int blue = base[2]; - - - if ( alpha != 0xFF ) - { - red = multiply_alpha( alpha, red ); - green = multiply_alpha( alpha, green ); - blue = multiply_alpha( alpha, blue ); - } - - base[0] = (unsigned char)blue; - base[1] = (unsigned char)green; - base[2] = (unsigned char)red; - base[3] = (unsigned char)alpha; - } - } - } - - - /* Converts RGBx bytes to BGRA. */ - static void - convert_bytes_to_data( png_structp png, - png_row_infop row_info, - png_bytep data ) - { - unsigned int i; - - FT_UNUSED( png ); - - - for ( i = 0; i < row_info->rowbytes; i += 4 ) - { - unsigned char* base = &data[i]; - unsigned int red = base[0]; - unsigned int green = base[1]; - unsigned int blue = base[2]; - - - base[0] = (unsigned char)blue; - base[1] = (unsigned char)green; - base[2] = (unsigned char)red; - base[3] = 0xFF; - } - } - - - /* Use error callback to avoid png writing to stderr. */ - static void - error_callback( png_structp png, - png_const_charp error_msg ) - { - FT_Error* error = (FT_Error*)png_get_error_ptr( png ); - - FT_UNUSED( error_msg ); - - - *error = FT_THROW( Out_Of_Memory ); -#ifdef PNG_SETJMP_SUPPORTED - ft_longjmp( png_jmpbuf( png ), 1 ); -#endif - /* if we get here, then we have no choice but to abort ... */ - } - - - /* Use warning callback to avoid png writing to stderr. */ - static void - warning_callback( png_structp png, - png_const_charp error_msg ) - { - FT_UNUSED( png ); - FT_UNUSED( error_msg ); - - /* Just ignore warnings. */ - } - - - static void - read_data_from_FT_Stream( png_structp png, - png_bytep data, - png_size_t length ) - { - FT_Error error; - png_voidp p = png_get_io_ptr( png ); - FT_Stream stream = (FT_Stream)p; - - - if ( FT_FRAME_ENTER( length ) ) - { - FT_Error* e = (FT_Error*)png_get_error_ptr( png ); - - - *e = FT_THROW( Invalid_Stream_Read ); - png_error( png, NULL ); - - return; - } - - memcpy( data, stream->cursor, length ); - - FT_FRAME_EXIT(); - } - - - FT_LOCAL_DEF( FT_Error ) - Load_SBit_Png( FT_GlyphSlot slot, - FT_Int x_offset, - FT_Int y_offset, - FT_Int pix_bits, - TT_SBit_Metrics metrics, - FT_Memory memory, - FT_Byte* data, - FT_UInt png_len, - FT_Bool populate_map_and_metrics ) - { - FT_Bitmap *map = &slot->bitmap; - FT_Error error = FT_Err_Ok; - FT_StreamRec stream; - - png_structp png; - png_infop info; - png_uint_32 imgWidth, imgHeight; - - int bitdepth, color_type, interlace; - FT_Int i; - png_byte* *rows = NULL; /* pacify compiler */ - - - if ( x_offset < 0 || - y_offset < 0 ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - if ( !populate_map_and_metrics && - ( (FT_UInt)x_offset + metrics->width > map->width || - (FT_UInt)y_offset + metrics->height > map->rows || - pix_bits != 32 || - map->pixel_mode != FT_PIXEL_MODE_BGRA ) ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - FT_Stream_OpenMemory( &stream, data, png_len ); - - png = png_create_read_struct( PNG_LIBPNG_VER_STRING, - &error, - error_callback, - warning_callback ); - if ( !png ) - { - error = FT_THROW( Out_Of_Memory ); - goto Exit; - } - - info = png_create_info_struct( png ); - if ( !info ) - { - error = FT_THROW( Out_Of_Memory ); - png_destroy_read_struct( &png, NULL, NULL ); - goto Exit; - } - - if ( ft_setjmp( png_jmpbuf( png ) ) ) - { - error = FT_THROW( Invalid_File_Format ); - goto DestroyExit; - } - - png_set_read_fn( png, &stream, read_data_from_FT_Stream ); - - png_read_info( png, info ); - png_get_IHDR( png, info, - &imgWidth, &imgHeight, - &bitdepth, &color_type, &interlace, - NULL, NULL ); - - if ( error || - ( !populate_map_and_metrics && - ( (FT_Int)imgWidth != metrics->width || - (FT_Int)imgHeight != metrics->height ) ) ) - goto DestroyExit; - - if ( populate_map_and_metrics ) - { - FT_ULong size; - - - metrics->width = (FT_UShort)imgWidth; - metrics->height = (FT_UShort)imgHeight; - - map->width = metrics->width; - map->rows = metrics->height; - map->pixel_mode = FT_PIXEL_MODE_BGRA; - map->pitch = (int)( map->width * 4 ); - map->num_grays = 256; - - /* reject too large bitmaps similarly to the rasterizer */ - if ( map->rows > 0x7FFF || map->width > 0x7FFF ) - { - error = FT_THROW( Array_Too_Large ); - goto DestroyExit; - } - - /* this doesn't overflow: 0x7FFF * 0x7FFF * 4 < 2^32 */ - size = map->rows * (FT_ULong)map->pitch; - - error = ft_glyphslot_alloc_bitmap( slot, size ); - if ( error ) - goto DestroyExit; - } - - /* convert palette/gray image to rgb */ - if ( color_type == PNG_COLOR_TYPE_PALETTE ) - png_set_palette_to_rgb( png ); - - /* expand gray bit depth if needed */ - if ( color_type == PNG_COLOR_TYPE_GRAY ) - { -#if PNG_LIBPNG_VER >= 10209 - png_set_expand_gray_1_2_4_to_8( png ); -#else - png_set_gray_1_2_4_to_8( png ); -#endif - } - - /* transform transparency to alpha */ - if ( png_get_valid(png, info, PNG_INFO_tRNS ) ) - png_set_tRNS_to_alpha( png ); - - if ( bitdepth == 16 ) - png_set_strip_16( png ); - - if ( bitdepth < 8 ) - png_set_packing( png ); - - /* convert grayscale to RGB */ - if ( color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA ) - png_set_gray_to_rgb( png ); - - if ( interlace != PNG_INTERLACE_NONE ) - png_set_interlace_handling( png ); - - png_set_filler( png, 0xFF, PNG_FILLER_AFTER ); - - /* recheck header after setting EXPAND options */ - png_read_update_info(png, info ); - png_get_IHDR( png, info, - &imgWidth, &imgHeight, - &bitdepth, &color_type, &interlace, - NULL, NULL ); - - if ( bitdepth != 8 || - !( color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_RGB_ALPHA ) ) - { - error = FT_THROW( Invalid_File_Format ); - goto DestroyExit; - } - - switch ( color_type ) - { - default: - /* Shouldn't happen, but fall through. */ - - case PNG_COLOR_TYPE_RGB_ALPHA: - png_set_read_user_transform_fn( png, premultiply_data ); - break; - - case PNG_COLOR_TYPE_RGB: - /* Humm, this smells. Carry on though. */ - png_set_read_user_transform_fn( png, convert_bytes_to_data ); - break; - } - - if ( FT_NEW_ARRAY( rows, imgHeight ) ) - { - error = FT_THROW( Out_Of_Memory ); - goto DestroyExit; - } - - for ( i = 0; i < (FT_Int)imgHeight; i++ ) - rows[i] = map->buffer + ( y_offset + i ) * map->pitch + x_offset * 4; - - png_read_image( png, rows ); - - FT_FREE( rows ); - - png_read_end( png, info ); - - DestroyExit: - png_destroy_read_struct( &png, &info, NULL ); - FT_Stream_Close( &stream ); - - Exit: - return error; - } - -#endif /* FT_CONFIG_OPTION_USE_PNG */ - - -/* END */ diff --git a/third_party/freetype/src/sfnt/pngshim.h b/third_party/freetype/src/sfnt/pngshim.h deleted file mode 100644 index 4cc5c2b3a0..0000000000 --- a/third_party/freetype/src/sfnt/pngshim.h +++ /dev/null @@ -1,50 +0,0 @@ -/***************************************************************************/ -/* */ -/* pngshim.h */ -/* */ -/* PNG Bitmap glyph support. */ -/* */ -/* Copyright 2013-2015 by */ -/* Google, Inc. */ -/* Written by Stuart Gill and Behdad Esfahbod. */ -/* */ -/* 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. */ -/* */ -/***************************************************************************/ - - -#ifndef __PNGSHIM_H__ -#define __PNGSHIM_H__ - - -#include -#include "ttload.h" - - -FT_BEGIN_HEADER - -#ifdef FT_CONFIG_OPTION_USE_PNG - - FT_LOCAL( FT_Error ) - Load_SBit_Png( FT_GlyphSlot slot, - FT_Int x_offset, - FT_Int y_offset, - FT_Int pix_bits, - TT_SBit_Metrics metrics, - FT_Memory memory, - FT_Byte* data, - FT_UInt png_len, - FT_Bool populate_map_and_metrics ); - -#endif - -FT_END_HEADER - -#endif /* __PNGSHIM_H__ */ - - -/* END */ diff --git a/third_party/freetype/src/sfnt/ttbdf.c b/third_party/freetype/src/sfnt/ttbdf.c deleted file mode 100644 index 098b781a14..0000000000 --- a/third_party/freetype/src/sfnt/ttbdf.c +++ /dev/null @@ -1,250 +0,0 @@ -/***************************************************************************/ -/* */ -/* ttbdf.c */ -/* */ -/* TrueType and OpenType embedded BDF properties (body). */ -/* */ -/* Copyright 2005-2015 by */ -/* 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. */ -/* */ -/***************************************************************************/ - - -#include -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_STREAM_H -#include FT_TRUETYPE_TAGS_H -#include "ttbdf.h" - -#include "sferrors.h" - - -#ifdef TT_CONFIG_OPTION_BDF - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_ttbdf - - - FT_LOCAL_DEF( void ) - tt_face_free_bdf_props( TT_Face face ) - { - TT_BDF bdf = &face->bdf; - - - if ( bdf->loaded ) - { - FT_Stream stream = FT_FACE(face)->stream; - - - if ( bdf->table != NULL ) - FT_FRAME_RELEASE( bdf->table ); - - bdf->table_end = NULL; - bdf->strings = NULL; - bdf->strings_size = 0; - } - } - - - static FT_Error - tt_face_load_bdf_props( TT_Face face, - FT_Stream stream ) - { - TT_BDF bdf = &face->bdf; - FT_ULong length; - FT_Error error; - - - FT_ZERO( bdf ); - - error = tt_face_goto_table( face, TTAG_BDF, stream, &length ); - if ( error || - length < 8 || - FT_FRAME_EXTRACT( length, bdf->table ) ) - { - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - bdf->table_end = bdf->table + length; - - { - FT_Byte* p = bdf->table; - FT_UInt version = FT_NEXT_USHORT( p ); - FT_UInt num_strikes = FT_NEXT_USHORT( p ); - FT_ULong strings = FT_NEXT_ULONG ( p ); - FT_UInt count; - FT_Byte* strike; - - - if ( version != 0x0001 || - strings < 8 || - ( strings - 8 ) / 4 < num_strikes || - strings + 1 > length ) - { - goto BadTable; - } - - bdf->num_strikes = num_strikes; - bdf->strings = bdf->table + strings; - bdf->strings_size = length - strings; - - count = bdf->num_strikes; - p = bdf->table + 8; - strike = p + count * 4; - - - for ( ; count > 0; count-- ) - { - FT_UInt num_items = FT_PEEK_USHORT( p + 2 ); - - /* - * We don't need to check the value sets themselves, since this - * is done later. - */ - strike += 10 * num_items; - - p += 4; - } - - if ( strike > bdf->strings ) - goto BadTable; - } - - bdf->loaded = 1; - - Exit: - return error; - - BadTable: - FT_FRAME_RELEASE( bdf->table ); - FT_ZERO( bdf ); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - - FT_LOCAL_DEF( FT_Error ) - tt_face_find_bdf_prop( TT_Face face, - const char* property_name, - BDF_PropertyRec *aprop ) - { - TT_BDF bdf = &face->bdf; - FT_Size size = FT_FACE(face)->size; - FT_Error error = FT_Err_Ok; - FT_Byte* p; - FT_UInt count; - FT_Byte* strike; - FT_Offset property_len; - - - aprop->type = BDF_PROPERTY_TYPE_NONE; - - if ( bdf->loaded == 0 ) - { - error = tt_face_load_bdf_props( face, FT_FACE( face )->stream ); - if ( error ) - goto Exit; - } - - count = bdf->num_strikes; - p = bdf->table + 8; - strike = p + 4 * count; - - error = FT_ERR( Invalid_Argument ); - - if ( size == NULL || property_name == NULL ) - goto Exit; - - property_len = ft_strlen( property_name ); - if ( property_len == 0 ) - goto Exit; - - for ( ; count > 0; count-- ) - { - FT_UInt _ppem = FT_NEXT_USHORT( p ); - FT_UInt _count = FT_NEXT_USHORT( p ); - - if ( _ppem == size->metrics.y_ppem ) - { - count = _count; - goto FoundStrike; - } - - strike += 10 * _count; - } - goto Exit; - - FoundStrike: - p = strike; - for ( ; count > 0; count-- ) - { - FT_UInt type = FT_PEEK_USHORT( p + 4 ); - - if ( ( type & 0x10 ) != 0 ) - { - FT_UInt32 name_offset = FT_PEEK_ULONG( p ); - FT_UInt32 value = FT_PEEK_ULONG( p + 6 ); - - /* be a bit paranoid for invalid entries here */ - if ( name_offset < bdf->strings_size && - property_len < bdf->strings_size - name_offset && - ft_strncmp( property_name, - (const char*)bdf->strings + name_offset, - bdf->strings_size - name_offset ) == 0 ) - { - switch ( type & 0x0F ) - { - case 0x00: /* string */ - case 0x01: /* atoms */ - /* check that the content is really 0-terminated */ - if ( value < bdf->strings_size && - ft_memchr( bdf->strings + value, 0, bdf->strings_size ) ) - { - aprop->type = BDF_PROPERTY_TYPE_ATOM; - aprop->u.atom = (const char*)bdf->strings + value; - error = FT_Err_Ok; - goto Exit; - } - break; - - case 0x02: - aprop->type = BDF_PROPERTY_TYPE_INTEGER; - aprop->u.integer = (FT_Int32)value; - error = FT_Err_Ok; - goto Exit; - - case 0x03: - aprop->type = BDF_PROPERTY_TYPE_CARDINAL; - aprop->u.cardinal = value; - error = FT_Err_Ok; - goto Exit; - - default: - ; - } - } - } - p += 10; - } - - Exit: - return error; - } - -#endif /* TT_CONFIG_OPTION_BDF */ - - -/* END */ diff --git a/third_party/freetype/src/sfnt/ttbdf.h b/third_party/freetype/src/sfnt/ttbdf.h deleted file mode 100644 index fe4ba489e8..0000000000 --- a/third_party/freetype/src/sfnt/ttbdf.h +++ /dev/null @@ -1,46 +0,0 @@ -/***************************************************************************/ -/* */ -/* ttbdf.h */ -/* */ -/* TrueType and OpenType embedded BDF properties (specification). */ -/* */ -/* Copyright 2005-2015 by */ -/* 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. */ -/* */ -/***************************************************************************/ - - -#ifndef __TTBDF_H__ -#define __TTBDF_H__ - - -#include -#include "ttload.h" -#include FT_BDF_H - - -FT_BEGIN_HEADER - - - FT_LOCAL( void ) - tt_face_free_bdf_props( TT_Face face ); - - - FT_LOCAL( FT_Error ) - tt_face_find_bdf_prop( TT_Face face, - const char* property_name, - BDF_PropertyRec *aprop ); - - -FT_END_HEADER - -#endif /* __TTBDF_H__ */ - - -/* END */ diff --git a/third_party/freetype/src/sfnt/ttsbit.c b/third_party/freetype/src/sfnt/ttsbit.c deleted file mode 100644 index 3b351ecfce..0000000000 --- a/third_party/freetype/src/sfnt/ttsbit.c +++ /dev/null @@ -1,1472 +0,0 @@ -/***************************************************************************/ -/* */ -/* ttsbit.c */ -/* */ -/* TrueType and OpenType embedded bitmap support (body). */ -/* */ -/* Copyright 2005-2015 by */ -/* David Turner, Robert Wilhelm, and Werner Lemberg. */ -/* */ -/* Copyright 2013 by Google, Inc. */ -/* Google Author(s): Behdad Esfahbod. */ -/* */ -/* 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. */ -/* */ -/***************************************************************************/ - - -#include -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_STREAM_H -#include FT_TRUETYPE_TAGS_H -#include FT_BITMAP_H -#include "ttsbit.h" - -#include "sferrors.h" - -#include "ttmtx.h" -#include "pngshim.h" - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_ttsbit - - - FT_LOCAL_DEF( FT_Error ) - tt_face_load_sbit( TT_Face face, - FT_Stream stream ) - { - FT_Error error; - FT_ULong table_size; - - - face->sbit_table = NULL; - face->sbit_table_size = 0; - face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; - face->sbit_num_strikes = 0; - - error = face->goto_table( face, TTAG_CBLC, stream, &table_size ); - if ( !error ) - face->sbit_table_type = TT_SBIT_TABLE_TYPE_CBLC; - else - { - error = face->goto_table( face, TTAG_EBLC, stream, &table_size ); - if ( error ) - error = face->goto_table( face, TTAG_bloc, stream, &table_size ); - if ( !error ) - face->sbit_table_type = TT_SBIT_TABLE_TYPE_EBLC; - } - - if ( error ) - { - error = face->goto_table( face, TTAG_sbix, stream, &table_size ); - if ( !error ) - face->sbit_table_type = TT_SBIT_TABLE_TYPE_SBIX; - } - if ( error ) - goto Exit; - - if ( table_size < 8 ) - { - FT_ERROR(( "tt_face_load_sbit_strikes: table too short\n" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - switch ( (FT_UInt)face->sbit_table_type ) - { - case TT_SBIT_TABLE_TYPE_EBLC: - case TT_SBIT_TABLE_TYPE_CBLC: - { - FT_Byte* p; - FT_Fixed version; - FT_ULong num_strikes; - FT_UInt count; - - - if ( FT_FRAME_EXTRACT( table_size, face->sbit_table ) ) - goto Exit; - - face->sbit_table_size = table_size; - - p = face->sbit_table; - - version = FT_NEXT_LONG( p ); - num_strikes = FT_NEXT_ULONG( p ); - - if ( ( (FT_ULong)version & 0xFFFF0000UL ) != 0x00020000UL ) - { - error = FT_THROW( Unknown_File_Format ); - goto Exit; - } - - if ( num_strikes >= 0x10000UL ) - { - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - /* - * Count the number of strikes available in the table. We are a bit - * paranoid there and don't trust the data. - */ - count = (FT_UInt)num_strikes; - if ( 8 + 48UL * count > table_size ) - count = (FT_UInt)( ( table_size - 8 ) / 48 ); - - face->sbit_num_strikes = count; - } - break; - - case TT_SBIT_TABLE_TYPE_SBIX: - { - FT_UShort version; - FT_UShort flags; - FT_ULong num_strikes; - FT_UInt count; - - - if ( FT_FRAME_ENTER( 8 ) ) - goto Exit; - - version = FT_GET_USHORT(); - flags = FT_GET_USHORT(); - num_strikes = FT_GET_ULONG(); - - FT_FRAME_EXIT(); - - if ( version < 1 ) - { - error = FT_THROW( Unknown_File_Format ); - goto Exit; - } - - /* Bit 0 must always be `1'. */ - /* Bit 1 controls the overlay of bitmaps with outlines. */ - /* All other bits should be zero. */ - if ( !( flags == 1 || flags == 3 ) || - num_strikes >= 0x10000UL ) - { - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - /* we currently don't support bit 1; however, it is better to */ - /* draw at least something... */ - if ( flags == 3 ) - FT_TRACE1(( "tt_face_load_sbit_strikes:" - " sbix overlay not supported yet\n" - " " - " expect bad rendering results\n" )); - - /* - * Count the number of strikes available in the table. We are a bit - * paranoid there and don't trust the data. - */ - count = (FT_UInt)num_strikes; - if ( 8 + 4UL * count > table_size ) - count = (FT_UInt)( ( table_size - 8 ) / 4 ); - - if ( FT_STREAM_SEEK( FT_STREAM_POS() - 8 ) ) - goto Exit; - - face->sbit_table_size = 8 + count * 4; - if ( FT_FRAME_EXTRACT( face->sbit_table_size, face->sbit_table ) ) - goto Exit; - - face->sbit_num_strikes = count; - } - break; - - default: - error = FT_THROW( Unknown_File_Format ); - break; - } - - if ( !error ) - FT_TRACE3(( "sbit_num_strikes: %u\n", face->sbit_num_strikes )); - - return FT_Err_Ok; - - Exit: - if ( error ) - { - if ( face->sbit_table ) - FT_FRAME_RELEASE( face->sbit_table ); - face->sbit_table_size = 0; - face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; - } - - return error; - } - - - FT_LOCAL_DEF( void ) - tt_face_free_sbit( TT_Face face ) - { - FT_Stream stream = face->root.stream; - - - FT_FRAME_RELEASE( face->sbit_table ); - face->sbit_table_size = 0; - face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; - face->sbit_num_strikes = 0; - } - - - FT_LOCAL_DEF( FT_Error ) - tt_face_set_sbit_strike( TT_Face face, - FT_Size_Request req, - FT_ULong* astrike_index ) - { - return FT_Match_Size( (FT_Face)face, req, 0, astrike_index ); - } - - - FT_LOCAL_DEF( FT_Error ) - tt_face_load_strike_metrics( TT_Face face, - FT_ULong strike_index, - FT_Size_Metrics* metrics ) - { - if ( strike_index >= (FT_ULong)face->sbit_num_strikes ) - return FT_THROW( Invalid_Argument ); - - switch ( (FT_UInt)face->sbit_table_type ) - { - case TT_SBIT_TABLE_TYPE_EBLC: - case TT_SBIT_TABLE_TYPE_CBLC: - { - FT_Byte* strike; - - - strike = face->sbit_table + 8 + strike_index * 48; - - metrics->x_ppem = (FT_UShort)strike[44]; - metrics->y_ppem = (FT_UShort)strike[45]; - - metrics->ascender = (FT_Char)strike[16] * 64; /* hori.ascender */ - metrics->descender = (FT_Char)strike[17] * 64; /* hori.descender */ - metrics->height = metrics->ascender - metrics->descender; - - /* Is this correct? */ - metrics->max_advance = ( (FT_Char)strike[22] + /* min_origin_SB */ - strike[18] + /* max_width */ - (FT_Char)strike[23] /* min_advance_SB */ - ) * 64; - return FT_Err_Ok; - } - - case TT_SBIT_TABLE_TYPE_SBIX: - { - FT_Stream stream = face->root.stream; - FT_UInt offset, upem; - FT_UShort ppem, resolution; - TT_HoriHeader *hori; - FT_ULong table_size; - FT_Pos ppem_, upem_; /* to reduce casts */ - - FT_Error error; - FT_Byte* p; - - - p = face->sbit_table + 8 + 4 * strike_index; - offset = FT_NEXT_ULONG( p ); - - error = face->goto_table( face, TTAG_sbix, stream, &table_size ); - if ( error ) - return error; - - if ( offset + 4 > table_size ) - return FT_THROW( Invalid_File_Format ); - - if ( FT_STREAM_SEEK( FT_STREAM_POS() + offset ) || - FT_FRAME_ENTER( 4 ) ) - return error; - - ppem = FT_GET_USHORT(); - resolution = FT_GET_USHORT(); - - FT_UNUSED( resolution ); /* What to do with this? */ - - FT_FRAME_EXIT(); - - upem = face->header.Units_Per_EM; - hori = &face->horizontal; - - metrics->x_ppem = ppem; - metrics->y_ppem = ppem; - - ppem_ = (FT_Pos)ppem; - upem_ = (FT_Pos)upem; - - metrics->ascender = ppem_ * hori->Ascender * 64 / upem_; - metrics->descender = ppem_ * hori->Descender * 64 / upem_; - metrics->height = ppem_ * ( hori->Ascender - - hori->Descender + - hori->Line_Gap ) * 64 / upem_; - metrics->max_advance = ppem_ * hori->advance_Width_Max * 64 / upem_; - - return error; - } - - default: - return FT_THROW( Unknown_File_Format ); - } - } - - - typedef struct TT_SBitDecoderRec_ - { - TT_Face face; - FT_Stream stream; - FT_Bitmap* bitmap; - TT_SBit_Metrics metrics; - FT_Bool metrics_loaded; - FT_Bool bitmap_allocated; - FT_Byte bit_depth; - - FT_ULong ebdt_start; - FT_ULong ebdt_size; - - FT_ULong strike_index_array; - FT_ULong strike_index_count; - FT_Byte* eblc_base; - FT_Byte* eblc_limit; - - } TT_SBitDecoderRec, *TT_SBitDecoder; - - - static FT_Error - tt_sbit_decoder_init( TT_SBitDecoder decoder, - TT_Face face, - FT_ULong strike_index, - TT_SBit_MetricsRec* metrics ) - { - FT_Error error; - FT_Stream stream = face->root.stream; - FT_ULong ebdt_size; - - - error = face->goto_table( face, TTAG_CBDT, stream, &ebdt_size ); - if ( error ) - error = face->goto_table( face, TTAG_EBDT, stream, &ebdt_size ); - if ( error ) - error = face->goto_table( face, TTAG_bdat, stream, &ebdt_size ); - if ( error ) - goto Exit; - - decoder->face = face; - decoder->stream = stream; - decoder->bitmap = &face->root.glyph->bitmap; - decoder->metrics = metrics; - - decoder->metrics_loaded = 0; - decoder->bitmap_allocated = 0; - - decoder->ebdt_start = FT_STREAM_POS(); - decoder->ebdt_size = ebdt_size; - - decoder->eblc_base = face->sbit_table; - decoder->eblc_limit = face->sbit_table + face->sbit_table_size; - - /* now find the strike corresponding to the index */ - { - FT_Byte* p; - - - if ( 8 + 48 * strike_index + 3 * 4 + 34 + 1 > face->sbit_table_size ) - { - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - p = decoder->eblc_base + 8 + 48 * strike_index; - - decoder->strike_index_array = FT_NEXT_ULONG( p ); - p += 4; - decoder->strike_index_count = FT_NEXT_ULONG( p ); - p += 34; - decoder->bit_depth = *p; - - /* decoder->strike_index_array + */ - /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_count > - ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) - error = FT_THROW( Invalid_File_Format ); - } - - Exit: - return error; - } - - - static void - tt_sbit_decoder_done( TT_SBitDecoder decoder ) - { - FT_UNUSED( decoder ); - } - - - static FT_Error - tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder decoder ) - { - FT_Error error = FT_Err_Ok; - FT_UInt width, height; - FT_Bitmap* map = decoder->bitmap; - FT_ULong size; - - - if ( !decoder->metrics_loaded ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - width = decoder->metrics->width; - height = decoder->metrics->height; - - map->width = width; - map->rows = height; - - switch ( decoder->bit_depth ) - { - case 1: - map->pixel_mode = FT_PIXEL_MODE_MONO; - map->pitch = (int)( ( map->width + 7 ) >> 3 ); - map->num_grays = 2; - break; - - case 2: - map->pixel_mode = FT_PIXEL_MODE_GRAY2; - map->pitch = (int)( ( map->width + 3 ) >> 2 ); - map->num_grays = 4; - break; - - case 4: - map->pixel_mode = FT_PIXEL_MODE_GRAY4; - map->pitch = (int)( ( map->width + 1 ) >> 1 ); - map->num_grays = 16; - break; - - case 8: - map->pixel_mode = FT_PIXEL_MODE_GRAY; - map->pitch = (int)( map->width ); - map->num_grays = 256; - break; - - case 32: - map->pixel_mode = FT_PIXEL_MODE_BGRA; - map->pitch = (int)( map->width * 4 ); - map->num_grays = 256; - break; - - default: - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - size = map->rows * (FT_ULong)map->pitch; - - /* check that there is no empty image */ - if ( size == 0 ) - goto Exit; /* exit successfully! */ - - error = ft_glyphslot_alloc_bitmap( decoder->face->root.glyph, size ); - if ( error ) - goto Exit; - - decoder->bitmap_allocated = 1; - - Exit: - return error; - } - - - static FT_Error - tt_sbit_decoder_load_metrics( TT_SBitDecoder decoder, - FT_Byte* *pp, - FT_Byte* limit, - FT_Bool big ) - { - FT_Byte* p = *pp; - TT_SBit_Metrics metrics = decoder->metrics; - - - if ( p + 5 > limit ) - goto Fail; - - metrics->height = p[0]; - metrics->width = p[1]; - metrics->horiBearingX = (FT_Char)p[2]; - metrics->horiBearingY = (FT_Char)p[3]; - metrics->horiAdvance = p[4]; - - p += 5; - if ( big ) - { - if ( p + 3 > limit ) - goto Fail; - - metrics->vertBearingX = (FT_Char)p[0]; - metrics->vertBearingY = (FT_Char)p[1]; - metrics->vertAdvance = p[2]; - - p += 3; - } - else - { - /* avoid uninitialized data in case there is no vertical info -- */ - metrics->vertBearingX = 0; - metrics->vertBearingY = 0; - metrics->vertAdvance = 0; - } - - decoder->metrics_loaded = 1; - *pp = p; - return FT_Err_Ok; - - Fail: - FT_TRACE1(( "tt_sbit_decoder_load_metrics: broken table\n" )); - return FT_THROW( Invalid_Argument ); - } - - - /* forward declaration */ - static FT_Error - tt_sbit_decoder_load_image( TT_SBitDecoder decoder, - FT_UInt glyph_index, - FT_Int x_pos, - FT_Int y_pos ); - - typedef FT_Error (*TT_SBitDecoder_LoadFunc)( TT_SBitDecoder decoder, - FT_Byte* p, - FT_Byte* plimit, - FT_Int x_pos, - FT_Int y_pos ); - - - static FT_Error - tt_sbit_decoder_load_byte_aligned( TT_SBitDecoder decoder, - FT_Byte* p, - FT_Byte* limit, - FT_Int x_pos, - FT_Int y_pos ) - { - FT_Error error = FT_Err_Ok; - FT_Byte* line; - FT_Int pitch, width, height, line_bits, h; - FT_UInt bit_height, bit_width; - FT_Bitmap* bitmap; - - - /* check that we can write the glyph into the bitmap */ - bitmap = decoder->bitmap; - bit_width = bitmap->width; - bit_height = bitmap->rows; - pitch = bitmap->pitch; - line = bitmap->buffer; - - width = decoder->metrics->width; - height = decoder->metrics->height; - - line_bits = width * decoder->bit_depth; - - if ( x_pos < 0 || (FT_UInt)( x_pos + width ) > bit_width || - y_pos < 0 || (FT_UInt)( y_pos + height ) > bit_height ) - { - FT_TRACE1(( "tt_sbit_decoder_load_byte_aligned:" - " invalid bitmap dimensions\n" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - if ( p + ( ( line_bits + 7 ) >> 3 ) * height > limit ) - { - FT_TRACE1(( "tt_sbit_decoder_load_byte_aligned: broken bitmap\n" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - /* now do the blit */ - line += y_pos * pitch + ( x_pos >> 3 ); - x_pos &= 7; - - if ( x_pos == 0 ) /* the easy one */ - { - for ( h = height; h > 0; h--, line += pitch ) - { - FT_Byte* pwrite = line; - FT_Int w; - - - for ( w = line_bits; w >= 8; w -= 8 ) - { - pwrite[0] = (FT_Byte)( pwrite[0] | *p++ ); - pwrite += 1; - } - - if ( w > 0 ) - pwrite[0] = (FT_Byte)( pwrite[0] | ( *p++ & ( 0xFF00U >> w ) ) ); - } - } - else /* x_pos > 0 */ - { - for ( h = height; h > 0; h--, line += pitch ) - { - FT_Byte* pwrite = line; - FT_Int w; - FT_UInt wval = 0; - - - for ( w = line_bits; w >= 8; w -= 8 ) - { - wval = (FT_UInt)( wval | *p++ ); - pwrite[0] = (FT_Byte)( pwrite[0] | ( wval >> x_pos ) ); - pwrite += 1; - wval <<= 8; - } - - if ( w > 0 ) - wval = (FT_UInt)( wval | ( *p++ & ( 0xFF00U >> w ) ) ); - - /* all bits read and there are `x_pos + w' bits to be written */ - - pwrite[0] = (FT_Byte)( pwrite[0] | ( wval >> x_pos ) ); - - if ( x_pos + w > 8 ) - { - pwrite++; - wval <<= 8; - pwrite[0] = (FT_Byte)( pwrite[0] | ( wval >> x_pos ) ); - } - } - } - - Exit: - if ( !error ) - FT_TRACE3(( "tt_sbit_decoder_load_byte_aligned: loaded\n" )); - return error; - } - - - /* - * Load a bit-aligned bitmap (with pointer `p') into a line-aligned bitmap - * (with pointer `pwrite'). In the example below, the width is 3 pixel, - * and `x_pos' is 1 pixel. - * - * p p+1 - * | | | - * | 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 |... - * | | | - * +-------+ +-------+ +-------+ ... - * . . . - * . . . - * v . . - * +-------+ . . - * | | . - * | 7 6 5 4 3 2 1 0 | . - * | | . - * pwrite . . - * . . - * v . - * +-------+ . - * | | - * | 7 6 5 4 3 2 1 0 | - * | | - * pwrite+1 . - * . - * v - * +-------+ - * | | - * | 7 6 5 4 3 2 1 0 | - * | | - * pwrite+2 - * - */ - - static FT_Error - tt_sbit_decoder_load_bit_aligned( TT_SBitDecoder decoder, - FT_Byte* p, - FT_Byte* limit, - FT_Int x_pos, - FT_Int y_pos ) - { - FT_Error error = FT_Err_Ok; - FT_Byte* line; - FT_Int pitch, width, height, line_bits, h, nbits; - FT_UInt bit_height, bit_width; - FT_Bitmap* bitmap; - FT_UShort rval; - - - /* check that we can write the glyph into the bitmap */ - bitmap = decoder->bitmap; - bit_width = bitmap->width; - bit_height = bitmap->rows; - pitch = bitmap->pitch; - line = bitmap->buffer; - - width = decoder->metrics->width; - height = decoder->metrics->height; - - line_bits = width * decoder->bit_depth; - - if ( x_pos < 0 || (FT_UInt)( x_pos + width ) > bit_width || - y_pos < 0 || (FT_UInt)( y_pos + height ) > bit_height ) - { - FT_TRACE1(( "tt_sbit_decoder_load_bit_aligned:" - " invalid bitmap dimensions\n" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - if ( p + ( ( line_bits * height + 7 ) >> 3 ) > limit ) - { - FT_TRACE1(( "tt_sbit_decoder_load_bit_aligned: broken bitmap\n" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - /* now do the blit */ - - /* adjust `line' to point to the first byte of the bitmap */ - line += y_pos * pitch + ( x_pos >> 3 ); - x_pos &= 7; - - /* the higher byte of `rval' is used as a buffer */ - rval = 0; - nbits = 0; - - for ( h = height; h > 0; h--, line += pitch ) - { - FT_Byte* pwrite = line; - FT_Int w = line_bits; - - - /* handle initial byte (in target bitmap) specially if necessary */ - if ( x_pos ) - { - w = ( line_bits < 8 - x_pos ) ? line_bits : 8 - x_pos; - - if ( h == height ) - { - rval = *p++; - nbits = x_pos; - } - else if ( nbits < w ) - { - if ( p < limit ) - rval |= *p++; - nbits += 8 - w; - } - else - { - rval >>= 8; - nbits -= w; - } - - *pwrite++ |= ( ( rval >> nbits ) & 0xFF ) & - ( ~( 0xFF << w ) << ( 8 - w - x_pos ) ); - rval <<= 8; - - w = line_bits - w; - } - - /* handle medial bytes */ - for ( ; w >= 8; w -= 8 ) - { - rval |= *p++; - *pwrite++ |= ( rval >> nbits ) & 0xFF; - - rval <<= 8; - } - - /* handle final byte if necessary */ - if ( w > 0 ) - { - if ( nbits < w ) - { - if ( p < limit ) - rval |= *p++; - *pwrite |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w ); - nbits += 8 - w; - - rval <<= 8; - } - else - { - *pwrite |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w ); - nbits -= w; - } - } - } - - Exit: - if ( !error ) - FT_TRACE3(( "tt_sbit_decoder_load_bit_aligned: loaded\n" )); - return error; - } - - - static FT_Error - tt_sbit_decoder_load_compound( TT_SBitDecoder decoder, - FT_Byte* p, - FT_Byte* limit, - FT_Int x_pos, - FT_Int y_pos ) - { - FT_Error error = FT_Err_Ok; - FT_UInt num_components, nn; - - FT_Char horiBearingX = (FT_Char)decoder->metrics->horiBearingX; - FT_Char horiBearingY = (FT_Char)decoder->metrics->horiBearingY; - FT_Byte horiAdvance = (FT_Byte)decoder->metrics->horiAdvance; - FT_Char vertBearingX = (FT_Char)decoder->metrics->vertBearingX; - FT_Char vertBearingY = (FT_Char)decoder->metrics->vertBearingY; - FT_Byte vertAdvance = (FT_Byte)decoder->metrics->vertAdvance; - - - if ( p + 2 > limit ) - goto Fail; - - num_components = FT_NEXT_USHORT( p ); - if ( p + 4 * num_components > limit ) - { - FT_TRACE1(( "tt_sbit_decoder_load_compound: broken table\n" )); - goto Fail; - } - - FT_TRACE3(( "tt_sbit_decoder_load_compound: loading %d components\n", - num_components )); - - for ( nn = 0; nn < num_components; nn++ ) - { - FT_UInt gindex = FT_NEXT_USHORT( p ); - FT_Byte dx = FT_NEXT_BYTE( p ); - FT_Byte dy = FT_NEXT_BYTE( p ); - - - /* NB: a recursive call */ - error = tt_sbit_decoder_load_image( decoder, gindex, - x_pos + dx, y_pos + dy ); - if ( error ) - break; - } - - FT_TRACE3(( "tt_sbit_decoder_load_compound: done\n" )); - - decoder->metrics->horiBearingX = horiBearingX; - decoder->metrics->horiBearingY = horiBearingY; - decoder->metrics->horiAdvance = horiAdvance; - decoder->metrics->vertBearingX = vertBearingX; - decoder->metrics->vertBearingY = vertBearingY; - decoder->metrics->vertAdvance = vertAdvance; - decoder->metrics->width = (FT_Byte)decoder->bitmap->width; - decoder->metrics->height = (FT_Byte)decoder->bitmap->rows; - - Exit: - return error; - - Fail: - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - -#ifdef FT_CONFIG_OPTION_USE_PNG - - static FT_Error - tt_sbit_decoder_load_png( TT_SBitDecoder decoder, - FT_Byte* p, - FT_Byte* limit, - FT_Int x_pos, - FT_Int y_pos ) - { - FT_Error error = FT_Err_Ok; - FT_ULong png_len; - - - if ( limit - p < 4 ) - { - FT_TRACE1(( "tt_sbit_decoder_load_png: broken bitmap\n" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - png_len = FT_NEXT_ULONG( p ); - if ( (FT_ULong)( limit - p ) < png_len ) - { - FT_TRACE1(( "tt_sbit_decoder_load_png: broken bitmap\n" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - error = Load_SBit_Png( decoder->face->root.glyph, - x_pos, - y_pos, - decoder->bit_depth, - decoder->metrics, - decoder->stream->memory, - p, - png_len, - FALSE ); - - Exit: - if ( !error ) - FT_TRACE3(( "tt_sbit_decoder_load_png: loaded\n" )); - return error; - } - -#endif /* FT_CONFIG_OPTION_USE_PNG */ - - - static FT_Error - tt_sbit_decoder_load_bitmap( TT_SBitDecoder decoder, - FT_UInt glyph_format, - FT_ULong glyph_start, - FT_ULong glyph_size, - FT_Int x_pos, - FT_Int y_pos ) - { - FT_Error error; - FT_Stream stream = decoder->stream; - FT_Byte* p; - FT_Byte* p_limit; - FT_Byte* data; - - - /* seek into the EBDT table now */ - if ( glyph_start + glyph_size > decoder->ebdt_size ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - if ( FT_STREAM_SEEK( decoder->ebdt_start + glyph_start ) || - FT_FRAME_EXTRACT( glyph_size, data ) ) - goto Exit; - - p = data; - p_limit = p + glyph_size; - - /* read the data, depending on the glyph format */ - switch ( glyph_format ) - { - case 1: - case 2: - case 8: - case 17: - error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 0 ); - break; - - case 6: - case 7: - case 9: - case 18: - error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ); - break; - - default: - error = FT_Err_Ok; - } - - if ( error ) - goto Fail; - - { - TT_SBitDecoder_LoadFunc loader; - - - switch ( glyph_format ) - { - case 1: - case 6: - loader = tt_sbit_decoder_load_byte_aligned; - break; - - case 2: - case 7: - { - /* Don't trust `glyph_format'. For example, Apple's main Korean */ - /* system font, `AppleMyungJo.ttf' (version 7.0d2e6), uses glyph */ - /* format 7, but the data is format 6. We check whether we have */ - /* an excessive number of bytes in the image: If it is equal to */ - /* the value for a byte-aligned glyph, use the other loading */ - /* routine. */ - /* */ - /* Note that for some (width,height) combinations, where the */ - /* width is not a multiple of 8, the sizes for bit- and */ - /* byte-aligned data are equal, for example (7,7) or (15,6). We */ - /* then prefer what `glyph_format' specifies. */ - - FT_UInt width = decoder->metrics->width; - FT_UInt height = decoder->metrics->height; - - FT_UInt bit_size = ( width * height + 7 ) >> 3; - FT_UInt byte_size = height * ( ( width + 7 ) >> 3 ); - - - if ( bit_size < byte_size && - byte_size == (FT_UInt)( p_limit - p ) ) - loader = tt_sbit_decoder_load_byte_aligned; - else - loader = tt_sbit_decoder_load_bit_aligned; - } - break; - - case 5: - loader = tt_sbit_decoder_load_bit_aligned; - break; - - case 8: - if ( p + 1 > p_limit ) - goto Fail; - - p += 1; /* skip padding */ - /* fall-through */ - - case 9: - loader = tt_sbit_decoder_load_compound; - break; - - case 17: /* small metrics, PNG image data */ - case 18: /* big metrics, PNG image data */ - case 19: /* metrics in EBLC, PNG image data */ -#ifdef FT_CONFIG_OPTION_USE_PNG - loader = tt_sbit_decoder_load_png; - break; -#else - error = FT_THROW( Unimplemented_Feature ); - goto Fail; -#endif /* FT_CONFIG_OPTION_USE_PNG */ - - default: - error = FT_THROW( Invalid_Table ); - goto Fail; - } - - if ( !decoder->bitmap_allocated ) - { - error = tt_sbit_decoder_alloc_bitmap( decoder ); - if ( error ) - goto Fail; - } - - error = loader( decoder, p, p_limit, x_pos, y_pos ); - } - - Fail: - FT_FRAME_RELEASE( data ); - - Exit: - return error; - } - - - static FT_Error - tt_sbit_decoder_load_image( TT_SBitDecoder decoder, - FT_UInt glyph_index, - FT_Int x_pos, - FT_Int y_pos ) - { - /* - * First, we find the correct strike range that applies to this - * glyph index. - */ - - FT_Byte* p = decoder->eblc_base + decoder->strike_index_array; - FT_Byte* p_limit = decoder->eblc_limit; - FT_ULong num_ranges = decoder->strike_index_count; - FT_UInt start, end, index_format, image_format; - FT_ULong image_start = 0, image_end = 0, image_offset; - - - for ( ; num_ranges > 0; num_ranges-- ) - { - start = FT_NEXT_USHORT( p ); - end = FT_NEXT_USHORT( p ); - - if ( glyph_index >= start && glyph_index <= end ) - goto FoundRange; - - p += 4; /* ignore index offset */ - } - goto NoBitmap; - - FoundRange: - image_offset = FT_NEXT_ULONG( p ); - - /* overflow check */ - p = decoder->eblc_base + decoder->strike_index_array; - if ( image_offset > (FT_ULong)( p_limit - p ) ) - goto Failure; - - p += image_offset; - if ( p + 8 > p_limit ) - goto NoBitmap; - - /* now find the glyph's location and extend within the ebdt table */ - index_format = FT_NEXT_USHORT( p ); - image_format = FT_NEXT_USHORT( p ); - image_offset = FT_NEXT_ULONG ( p ); - - switch ( index_format ) - { - case 1: /* 4-byte offsets relative to `image_offset' */ - p += 4 * ( glyph_index - start ); - if ( p + 8 > p_limit ) - goto NoBitmap; - - image_start = FT_NEXT_ULONG( p ); - image_end = FT_NEXT_ULONG( p ); - - if ( image_start == image_end ) /* missing glyph */ - goto NoBitmap; - break; - - case 2: /* big metrics, constant image size */ - { - FT_ULong image_size; - - - if ( p + 12 > p_limit ) - goto NoBitmap; - - image_size = FT_NEXT_ULONG( p ); - - if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) - goto NoBitmap; - - image_start = image_size * ( glyph_index - start ); - image_end = image_start + image_size; - } - break; - - case 3: /* 2-byte offsets relative to 'image_offset' */ - p += 2 * ( glyph_index - start ); - if ( p + 4 > p_limit ) - goto NoBitmap; - - image_start = FT_NEXT_USHORT( p ); - image_end = FT_NEXT_USHORT( p ); - - if ( image_start == image_end ) /* missing glyph */ - goto NoBitmap; - break; - - case 4: /* sparse glyph array with (glyph,offset) pairs */ - { - FT_ULong mm, num_glyphs; - - - if ( p + 4 > p_limit ) - goto NoBitmap; - - num_glyphs = FT_NEXT_ULONG( p ); - - /* overflow check for p + ( num_glyphs + 1 ) * 4 */ - if ( p + 4 > p_limit || - num_glyphs > (FT_ULong)( ( ( p_limit - p ) >> 2 ) - 1 ) ) - goto NoBitmap; - - for ( mm = 0; mm < num_glyphs; mm++ ) - { - FT_UInt gindex = FT_NEXT_USHORT( p ); - - - if ( gindex == glyph_index ) - { - image_start = FT_NEXT_USHORT( p ); - p += 2; - image_end = FT_PEEK_USHORT( p ); - break; - } - p += 2; - } - - if ( mm >= num_glyphs ) - goto NoBitmap; - } - break; - - case 5: /* constant metrics with sparse glyph codes */ - case 19: - { - FT_ULong image_size, mm, num_glyphs; - - - if ( p + 16 > p_limit ) - goto NoBitmap; - - image_size = FT_NEXT_ULONG( p ); - - if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) - goto NoBitmap; - - num_glyphs = FT_NEXT_ULONG( p ); - - /* overflow check for p + 2 * num_glyphs */ - if ( num_glyphs > (FT_ULong)( ( p_limit - p ) >> 1 ) ) - goto NoBitmap; - - for ( mm = 0; mm < num_glyphs; mm++ ) - { - FT_UInt gindex = FT_NEXT_USHORT( p ); - - - if ( gindex == glyph_index ) - break; - } - - if ( mm >= num_glyphs ) - goto NoBitmap; - - image_start = image_size * mm; - image_end = image_start + image_size; - } - break; - - default: - goto NoBitmap; - } - - if ( image_start > image_end ) - goto NoBitmap; - - image_end -= image_start; - image_start = image_offset + image_start; - - FT_TRACE3(( "tt_sbit_decoder_load_image:" - " found sbit (format %d) for glyph index %d\n", - image_format, glyph_index )); - - return tt_sbit_decoder_load_bitmap( decoder, - image_format, - image_start, - image_end, - x_pos, - y_pos ); - - Failure: - return FT_THROW( Invalid_Table ); - - NoBitmap: - FT_TRACE4(( "tt_sbit_decoder_load_image:" - " no sbit found for glyph index %d\n", glyph_index )); - - return FT_THROW( Invalid_Argument ); - } - - - static FT_Error - tt_face_load_sbix_image( TT_Face face, - FT_ULong strike_index, - FT_UInt glyph_index, - FT_Stream stream, - FT_Bitmap *map, - TT_SBit_MetricsRec *metrics ) - { - FT_UInt sbix_pos, strike_offset, glyph_start, glyph_end; - FT_ULong table_size; - FT_Int originOffsetX, originOffsetY; - FT_Tag graphicType; - FT_Int recurse_depth = 0; - - FT_Error error; - FT_Byte* p; - - FT_UNUSED( map ); - - - metrics->width = 0; - metrics->height = 0; - - p = face->sbit_table + 8 + 4 * strike_index; - strike_offset = FT_NEXT_ULONG( p ); - - error = face->goto_table( face, TTAG_sbix, stream, &table_size ); - if ( error ) - return error; - sbix_pos = FT_STREAM_POS(); - - retry: - if ( glyph_index > (FT_UInt)face->root.num_glyphs ) - return FT_THROW( Invalid_Argument ); - - if ( strike_offset >= table_size || - table_size - strike_offset < 4 + glyph_index * 4 + 8 ) - return FT_THROW( Invalid_File_Format ); - - if ( FT_STREAM_SEEK( sbix_pos + strike_offset + 4 + glyph_index * 4 ) || - FT_FRAME_ENTER( 8 ) ) - return error; - - glyph_start = FT_GET_ULONG(); - glyph_end = FT_GET_ULONG(); - - FT_FRAME_EXIT(); - - if ( glyph_start == glyph_end ) - return FT_THROW( Invalid_Argument ); - if ( glyph_start > glyph_end || - glyph_end - glyph_start < 8 || - table_size - strike_offset < glyph_end ) - return FT_THROW( Invalid_File_Format ); - - if ( FT_STREAM_SEEK( sbix_pos + strike_offset + glyph_start ) || - FT_FRAME_ENTER( glyph_end - glyph_start ) ) - return error; - - originOffsetX = FT_GET_SHORT(); - originOffsetY = FT_GET_SHORT(); - - graphicType = FT_GET_TAG4(); - - switch ( graphicType ) - { - case FT_MAKE_TAG( 'd', 'u', 'p', 'e' ): - if ( recurse_depth < 4 ) - { - glyph_index = FT_GET_USHORT(); - FT_FRAME_EXIT(); - recurse_depth++; - goto retry; - } - error = FT_THROW( Invalid_File_Format ); - break; - - case FT_MAKE_TAG( 'p', 'n', 'g', ' ' ): -#ifdef FT_CONFIG_OPTION_USE_PNG - error = Load_SBit_Png( face->root.glyph, - 0, - 0, - 32, - metrics, - stream->memory, - stream->cursor, - glyph_end - glyph_start - 8, - TRUE ); -#else - error = FT_THROW( Unimplemented_Feature ); -#endif - break; - - case FT_MAKE_TAG( 'j', 'p', 'g', ' ' ): - case FT_MAKE_TAG( 't', 'i', 'f', 'f' ): - case FT_MAKE_TAG( 'r', 'g', 'b', 'l' ): /* used on iOS 7.1 */ - error = FT_THROW( Unknown_File_Format ); - break; - - default: - error = FT_THROW( Unimplemented_Feature ); - break; - } - - FT_FRAME_EXIT(); - - if ( !error ) - { - FT_Short abearing; - FT_UShort aadvance; - - - tt_face_get_metrics( face, FALSE, glyph_index, &abearing, &aadvance ); - - metrics->horiBearingX = (FT_Short)originOffsetX; - metrics->horiBearingY = (FT_Short)( -originOffsetY + metrics->height ); - metrics->horiAdvance = (FT_UShort)( aadvance * - face->root.size->metrics.x_ppem / - face->header.Units_Per_EM ); - } - - return error; - } - - FT_LOCAL( FT_Error ) - tt_face_load_sbit_image( TT_Face face, - FT_ULong strike_index, - FT_UInt glyph_index, - FT_UInt load_flags, - FT_Stream stream, - FT_Bitmap *map, - TT_SBit_MetricsRec *metrics ) - { - FT_Error error = FT_Err_Ok; - - - switch ( (FT_UInt)face->sbit_table_type ) - { - case TT_SBIT_TABLE_TYPE_EBLC: - case TT_SBIT_TABLE_TYPE_CBLC: - { - TT_SBitDecoderRec decoder[1]; - - - error = tt_sbit_decoder_init( decoder, face, strike_index, metrics ); - if ( !error ) - { - error = tt_sbit_decoder_load_image( decoder, - glyph_index, - 0, - 0 ); - tt_sbit_decoder_done( decoder ); - } - } - break; - - case TT_SBIT_TABLE_TYPE_SBIX: - error = tt_face_load_sbix_image( face, - strike_index, - glyph_index, - stream, - map, - metrics ); - break; - - default: - error = FT_THROW( Unknown_File_Format ); - break; - } - - /* Flatten color bitmaps if color was not requested. */ - if ( !error && - !( load_flags & FT_LOAD_COLOR ) && - map->pixel_mode == FT_PIXEL_MODE_BGRA ) - { - FT_Bitmap new_map; - FT_Library library = face->root.glyph->library; - - - FT_Bitmap_Init( &new_map ); - - /* Convert to 8bit grayscale. */ - error = FT_Bitmap_Convert( library, map, &new_map, 1 ); - if ( error ) - FT_Bitmap_Done( library, &new_map ); - else - { - map->pixel_mode = new_map.pixel_mode; - map->pitch = new_map.pitch; - map->num_grays = new_map.num_grays; - - ft_glyphslot_set_bitmap( face->root.glyph, new_map.buffer ); - face->root.glyph->internal->flags |= FT_GLYPH_OWN_BITMAP; - } - } - - return error; - } - - -/* EOF */ diff --git a/third_party/freetype/src/sfnt/ttsbit.h b/third_party/freetype/src/sfnt/ttsbit.h deleted file mode 100644 index d4e13aefb8..0000000000 --- a/third_party/freetype/src/sfnt/ttsbit.h +++ /dev/null @@ -1,63 +0,0 @@ -/***************************************************************************/ -/* */ -/* ttsbit.h */ -/* */ -/* TrueType and OpenType embedded bitmap support (specification). */ -/* */ -/* Copyright 1996-2015 by */ -/* 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. */ -/* */ -/***************************************************************************/ - - -#ifndef __TTSBIT_H__ -#define __TTSBIT_H__ - - -#include -#include "ttload.h" - - -FT_BEGIN_HEADER - - - FT_LOCAL( FT_Error ) - tt_face_load_sbit( TT_Face face, - FT_Stream stream ); - - FT_LOCAL( void ) - tt_face_free_sbit( TT_Face face ); - - - FT_LOCAL( FT_Error ) - tt_face_set_sbit_strike( TT_Face face, - FT_Size_Request req, - FT_ULong* astrike_index ); - - FT_LOCAL( FT_Error ) - tt_face_load_strike_metrics( TT_Face face, - FT_ULong strike_index, - FT_Size_Metrics* metrics ); - - FT_LOCAL( FT_Error ) - tt_face_load_sbit_image( TT_Face face, - FT_ULong strike_index, - FT_UInt glyph_index, - FT_UInt load_flags, - FT_Stream stream, - FT_Bitmap *map, - TT_SBit_MetricsRec *metrics ); - - -FT_END_HEADER - -#endif /* __TTSBIT_H__ */ - - -/* END */ -- cgit v1.2.3