pcfdrivr.c.svn-base
来自「SumatraPDF是一款小型开源的pdf阅读工具。虽然玲珑小巧(只有800多K」· SVN-BASE 代码 · 共 676 行 · 第 1/2 页
SVN-BASE
676 行
/* pcfdrivr.c
FreeType font driver for pcf files
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008 by
Francesco Zappa Nardelli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_OBJECTS_H
#include FT_GZIP_H
#include FT_LZW_H
#include FT_ERRORS_H
#include FT_BDF_H
#include "pcf.h"
#include "pcfdrivr.h"
#include "pcfread.h"
#include "pcferror.h"
#include "pcfutil.h"
#undef FT_COMPONENT
#define FT_COMPONENT trace_pcfread
#include FT_SERVICE_BDF_H
#include FT_SERVICE_XFREE86_NAME_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_pcfdriver
typedef struct PCF_CMapRec_
{
FT_CMapRec root;
FT_UInt num_encodings;
PCF_Encoding encodings;
} PCF_CMapRec, *PCF_CMap;
FT_CALLBACK_DEF( FT_Error )
pcf_cmap_init( FT_CMap pcfcmap, /* PCF_CMap */
FT_Pointer init_data )
{
PCF_CMap cmap = (PCF_CMap)pcfcmap;
PCF_Face face = (PCF_Face)FT_CMAP_FACE( pcfcmap );
FT_UNUSED( init_data );
cmap->num_encodings = (FT_UInt)face->nencodings;
cmap->encodings = face->encodings;
return PCF_Err_Ok;
}
FT_CALLBACK_DEF( void )
pcf_cmap_done( FT_CMap pcfcmap ) /* PCF_CMap */
{
PCF_CMap cmap = (PCF_CMap)pcfcmap;
cmap->encodings = NULL;
cmap->num_encodings = 0;
}
FT_CALLBACK_DEF( FT_UInt )
pcf_cmap_char_index( FT_CMap pcfcmap, /* PCF_CMap */
FT_UInt32 charcode )
{
PCF_CMap cmap = (PCF_CMap)pcfcmap;
PCF_Encoding encodings = cmap->encodings;
FT_UInt min, max, mid;
FT_UInt result = 0;
min = 0;
max = cmap->num_encodings;
while ( min < max )
{
FT_UInt32 code;
mid = ( min + max ) >> 1;
code = encodings[mid].enc;
if ( charcode == code )
{
result = encodings[mid].glyph + 1;
break;
}
if ( charcode < code )
max = mid;
else
min = mid + 1;
}
return result;
}
FT_CALLBACK_DEF( FT_UInt )
pcf_cmap_char_next( FT_CMap pcfcmap, /* PCF_CMap */
FT_UInt32 *acharcode )
{
PCF_CMap cmap = (PCF_CMap)pcfcmap;
PCF_Encoding encodings = cmap->encodings;
FT_UInt min, max, mid;
FT_UInt32 charcode = *acharcode + 1;
FT_UInt result = 0;
min = 0;
max = cmap->num_encodings;
while ( min < max )
{
FT_UInt32 code;
mid = ( min + max ) >> 1;
code = encodings[mid].enc;
if ( charcode == code )
{
result = encodings[mid].glyph + 1;
goto Exit;
}
if ( charcode < code )
max = mid;
else
min = mid + 1;
}
charcode = 0;
if ( min < cmap->num_encodings )
{
charcode = encodings[min].enc;
result = encodings[min].glyph + 1;
}
Exit:
*acharcode = charcode;
return result;
}
FT_CALLBACK_TABLE_DEF
const FT_CMap_ClassRec pcf_cmap_class =
{
sizeof ( PCF_CMapRec ),
pcf_cmap_init,
pcf_cmap_done,
pcf_cmap_char_index,
pcf_cmap_char_next,
NULL, NULL, NULL, NULL, NULL
};
FT_CALLBACK_DEF( void )
PCF_Face_Done( FT_Face pcfface ) /* PCF_Face */
{
PCF_Face face = (PCF_Face)pcfface;
FT_Memory memory = FT_FACE_MEMORY( face );
FT_FREE( face->encodings );
FT_FREE( face->metrics );
/* free properties */
{
PCF_Property prop;
FT_Int i;
if ( face->properties )
{
for ( i = 0; i < face->nprops; i++ )
{
prop = &face->properties[i];
if ( prop ) {
FT_FREE( prop->name );
if ( prop->isString )
FT_FREE( prop->value.atom );
}
}
}
FT_FREE( face->properties );
}
FT_FREE( face->toc.tables );
FT_FREE( pcfface->family_name );
FT_FREE( pcfface->style_name );
FT_FREE( pcfface->available_sizes );
FT_FREE( face->charset_encoding );
FT_FREE( face->charset_registry );
FT_TRACE4(( "PCF_Face_Done: done face\n" ));
/* close gzip/LZW stream if any */
if ( pcfface->stream == &face->gzip_stream )
{
FT_Stream_Close( &face->gzip_stream );
pcfface->stream = face->gzip_source;
}
}
FT_CALLBACK_DEF( FT_Error )
PCF_Face_Init( FT_Stream stream,
FT_Face pcfface, /* PCF_Face */
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params )
{
PCF_Face face = (PCF_Face)pcfface;
FT_Error error = PCF_Err_Ok;
FT_UNUSED( num_params );
FT_UNUSED( params );
FT_UNUSED( face_index );
error = pcf_load_font( stream, face );
if ( error )
{
FT_Error error2;
PCF_Face_Done( pcfface );
#ifdef FT_CONFIG_OPTION_USE_ZLIB
/* this didn't work, try gzip support! */
error2 = FT_Stream_OpenGzip( &face->gzip_stream, stream );
if ( FT_ERROR_BASE( error2 ) == FT_Err_Unimplemented_Feature )
goto Fail;
error = error2;
#endif
if ( error )
#ifdef FT_CONFIG_OPTION_USE_LZW
{
FT_Error error3;
/* this didn't work, try LZW support! */
error3 = FT_Stream_OpenLZW( &face->gzip_stream, stream );
if ( FT_ERROR_BASE( error3 ) == FT_Err_Unimplemented_Feature )
goto Fail;
error = error3;
if ( error )
goto Fail;
face->gzip_source = stream;
pcfface->stream = &face->gzip_stream;
stream = pcfface->stream;
error = pcf_load_font( stream, face );
if ( error )
goto Fail;
}
#else
goto Fail;
#endif
else
{
face->gzip_source = stream;
pcfface->stream = &face->gzip_stream;
stream = pcfface->stream;
error = pcf_load_font( stream, face );
if ( error )
goto Fail;
}
}
/* set up charmap */
{
FT_String *charset_registry = face->charset_registry;
FT_String *charset_encoding = face->charset_encoding;
FT_Bool unicode_charmap = 0;
if ( charset_registry && charset_encoding )
{
char* s = charset_registry;
/* Uh, oh, compare first letters manually to avoid dependency
on locales. */
if ( ( s[0] == 'i' || s[0] == 'I' ) &&
( s[1] == 's' || s[1] == 'S' ) &&
( s[2] == 'o' || s[2] == 'O' ) )
{
s += 3;
if ( !ft_strcmp( s, "10646" ) ||
( !ft_strcmp( s, "8859" ) &&
!ft_strcmp( face->charset_encoding, "1" ) ) )
unicode_charmap = 1;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?