< prev index next >
src/java.desktop/share/native/libfreetype/src/sfnt/sfobjs.c
Print this page
*** 1,21 ****
! /***************************************************************************/
! /* */
! /* sfobjs.c */
! /* */
! /* SFNT object management (base). */
! /* */
! /* Copyright 1996-2018 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 <ft2build.h>
#include "sfobjs.h"
#include "ttload.h"
--- 1,21 ----
! /****************************************************************************
! *
! * sfobjs.c
! *
! * SFNT object management (base).
! *
! * Copyright (C) 1996-2019 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 <ft2build.h>
#include "sfobjs.h"
#include "ttload.h"
*** 39,56 ****
#ifdef TT_CONFIG_OPTION_BDF
#include "ttbdf.h"
#endif
! /*************************************************************************/
! /* */
! /* 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_sfobjs
/* convert a UTF-16 name entry to ASCII */
static FT_String*
--- 39,56 ----
#ifdef TT_CONFIG_OPTION_BDF
#include "ttbdf.h"
#endif
! /**************************************************************************
! *
! * 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 sfobjs
/* convert a UTF-16 name entry to ASCII */
static FT_String*
*** 916,926 ****
return error;
/* Stream may have changed in sfnt_open_font. */
stream = face->root.stream;
! FT_TRACE2(( "sfnt_init_face: %08p, %d\n", face, face_instance_index ));
face_index = FT_ABS( face_instance_index ) & 0xFFFF;
/* value -(N+1) requests information on index N */
if ( face_instance_index < 0 )
--- 916,928 ----
return error;
/* Stream may have changed in sfnt_open_font. */
stream = face->root.stream;
! FT_TRACE2(( "sfnt_init_face: %08p (index %d)\n",
! face,
! face_instance_index ));
face_index = FT_ABS( face_instance_index ) & 0xFFFF;
/* value -(N+1) requests information on index N */
if ( face_instance_index < 0 )
*** 1339,1348 ****
--- 1341,1357 ----
/* embedded bitmap support */
if ( sfnt->load_eblc )
LOAD_( eblc );
+ /* colored glyph support */
+ if ( sfnt->load_cpal )
+ {
+ LOAD_( cpal );
+ LOAD_( colr );
+ }
+
/* consider the pclt, kerning, and gasp tables as optional */
LOAD_( pclt );
LOAD_( gasp );
LOAD_( kern );
*** 1387,1402 ****
{
FT_Face root = &face->root;
FT_Long flags = root->face_flags;
! /*********************************************************************/
! /* */
! /* Compute face flags. */
! /* */
if ( face->sbit_table_type == TT_SBIT_TABLE_TYPE_CBLC ||
! face->sbit_table_type == TT_SBIT_TABLE_TYPE_SBIX )
flags |= FT_FACE_FLAG_COLOR; /* color glyphs */
if ( has_outline == TRUE )
flags |= FT_FACE_FLAG_SCALABLE; /* scalable outlines */
--- 1396,1412 ----
{
FT_Face root = &face->root;
FT_Long flags = root->face_flags;
! /**********************************************************************
! *
! * Compute face flags.
! */
if ( face->sbit_table_type == TT_SBIT_TABLE_TYPE_CBLC ||
! face->sbit_table_type == TT_SBIT_TABLE_TYPE_SBIX ||
! face->colr )
flags |= FT_FACE_FLAG_COLOR; /* color glyphs */
if ( has_outline == TRUE )
flags |= FT_FACE_FLAG_SCALABLE; /* scalable outlines */
*** 1436,1449 ****
}
#endif
root->face_flags = flags;
! /*********************************************************************/
! /* */
! /* Compute style flags. */
! /* */
flags = 0;
if ( has_outline == TRUE && face->os2.version != 0xFFFFU )
{
/* We have an OS/2 table; use the `fsSelection' field. Bit 9 */
--- 1446,1459 ----
}
#endif
root->face_flags = flags;
! /**********************************************************************
! *
! * Compute style flags.
! */
flags = 0;
if ( has_outline == TRUE && face->os2.version != 0xFFFFU )
{
/* We have an OS/2 table; use the `fsSelection' field. Bit 9 */
*** 1469,1486 ****
flags |= FT_STYLE_FLAG_ITALIC;
}
root->style_flags |= flags;
! /*********************************************************************/
! /* */
! /* Polish the charmaps. */
! /* */
! /* Try to set the charmap encoding according to the platform & */
! /* encoding ID of each charmap. Emulate Unicode charmap if one */
! /* is missing. */
! /* */
tt_face_build_cmaps( face ); /* ignore errors */
/* set the encoding fields */
--- 1479,1496 ----
flags |= FT_STYLE_FLAG_ITALIC;
}
root->style_flags |= flags;
! /**********************************************************************
! *
! * Polish the charmaps.
! *
! * Try to set the charmap encoding according to the platform &
! * encoding ID of each charmap. Emulate Unicode charmap if one
! * is missing.
! */
tt_face_build_cmaps( face ); /* ignore errors */
/* set the encoding fields */
*** 1519,1529 ****
error = FT_CMap_New( (FT_CMap_Class)&tt_cmap_unicode_class_rec,
NULL, &cmaprec, NULL );
if ( error &&
! FT_ERR_NEQ( error, No_Unicode_Glyph_Name ) )
goto Exit;
error = FT_Err_Ok;
#endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */
--- 1529,1540 ----
error = FT_CMap_New( (FT_CMap_Class)&tt_cmap_unicode_class_rec,
NULL, &cmaprec, NULL );
if ( error &&
! FT_ERR_NEQ( error, No_Unicode_Glyph_Name ) &&
! FT_ERR_NEQ( error, Unimplemented_Feature ) )
goto Exit;
error = FT_Err_Ok;
#endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */
*** 1613,1626 ****
/* it has only empty glyphs then */
if ( !FT_HAS_FIXED_SIZES( root ) && !FT_IS_SCALABLE( root ) )
root->face_flags |= FT_FACE_FLAG_SCALABLE;
! /*********************************************************************/
! /* */
! /* Set up metrics. */
! /* */
if ( FT_IS_SCALABLE( root ) )
{
/* XXX What about if outline header is missing */
/* (e.g. sfnt wrapped bitmap)? */
root->bbox.xMin = face->header.xMin;
--- 1624,1637 ----
/* it has only empty glyphs then */
if ( !FT_HAS_FIXED_SIZES( root ) && !FT_IS_SCALABLE( root ) )
root->face_flags |= FT_FACE_FLAG_SCALABLE;
! /**********************************************************************
! *
! * Set up metrics.
! */
if ( FT_IS_SCALABLE( root ) )
{
/* XXX What about if outline header is missing */
/* (e.g. sfnt wrapped bitmap)? */
root->bbox.xMin = face->header.xMin;
*** 1628,1669 ****
root->bbox.xMax = face->header.xMax;
root->bbox.yMax = face->header.yMax;
root->units_per_EM = face->header.Units_Per_EM;
! /* XXX: Computing the ascender/descender/height is very different */
! /* from what the specification tells you. Apparently, we */
! /* must be careful because */
! /* */
! /* - not all fonts have an OS/2 table; in this case, we take */
! /* the values in the horizontal header. However, these */
! /* values very often are not reliable. */
! /* */
! /* - otherwise, the correct typographic values are in the */
! /* sTypoAscender, sTypoDescender & sTypoLineGap fields. */
! /* */
! /* However, certain fonts have these fields set to 0. */
! /* Rather, they have usWinAscent & usWinDescent correctly */
! /* set (but with different values). */
! /* */
! /* As an example, Arial Narrow is implemented through four */
! /* files ARIALN.TTF, ARIALNI.TTF, ARIALNB.TTF & ARIALNBI.TTF */
! /* */
! /* Strangely, all fonts have the same values in their */
! /* sTypoXXX fields, except ARIALNB which sets them to 0. */
! /* */
! /* On the other hand, they all have different */
! /* usWinAscent/Descent values -- as a conclusion, the OS/2 */
! /* table cannot be used to compute the text height reliably! */
! /* */
!
! /* The ascender and descender are taken from the `hhea' table. */
! /* If zero, they are taken from the `OS/2' table. */
root->ascender = face->horizontal.Ascender;
root->descender = face->horizontal.Descender;
-
root->height = root->ascender - root->descender +
face->horizontal.Line_Gap;
if ( !( root->ascender || root->descender ) )
{
--- 1639,1695 ----
root->bbox.xMax = face->header.xMax;
root->bbox.yMax = face->header.yMax;
root->units_per_EM = face->header.Units_Per_EM;
! /*
! * Computing the ascender/descender/height is tricky.
! *
! * The OpenType specification v1.8.3 says:
! *
! * [OS/2's] sTypoAscender, sTypoDescender and sTypoLineGap fields
! * are intended to allow applications to lay out documents in a
! * typographically-correct and portable fashion.
! *
! * This is somewhat at odds with the decades of backwards
! * compatibility, operating systems and applications doing whatever
! * they want, not to mention broken fonts.
! *
! * Not all fonts have an OS/2 table; in this case, we take the values
! * in the horizontal header, although there is nothing stopping the
! * values from being unreliable. Even with a OS/2 table, certain fonts
! * set the sTypoAscender, sTypoDescender and sTypoLineGap fields to 0
! * and instead correctly set usWinAscent and usWinDescent.
! *
! * As an example, Arial Narrow is shipped as four files ARIALN.TTF,
! * ARIALNI.TTF, ARIALNB.TTF and ARIALNBI.TTF. Strangely, all fonts have
! * the same values in their sTypo* fields, except ARIALNB.ttf which
! * sets them to 0. All of them have different usWinAscent/Descent
! * values. The OS/2 table therefore cannot be trusted for computing the
! * text height reliably.
! *
! * As a compromise, do the following:
! *
! * 1. If the OS/2 table exists and the fsSelection bit 7 is set
! * (USE_TYPO_METRICS), trust the font and use the sTypo* metrics.
! * 2. Otherwise, use the `hhea' table's metrics.
! * 3. If they are zero and the OS/2 table exists,
! * 1. use the OS/2 table's sTypo* metrics if they are non-zero.
! * 2. Otherwise, use the OS/2 table's usWin* metrics.
! */
+ if ( face->os2.version != 0xFFFFU && face->os2.fsSelection & 128 )
+ {
+ root->ascender = face->os2.sTypoAscender;
+ root->descender = face->os2.sTypoDescender;
+ root->height = root->ascender - root->descender +
+ face->os2.sTypoLineGap;
+ }
+ else
+ {
root->ascender = face->horizontal.Ascender;
root->descender = face->horizontal.Descender;
root->height = root->ascender - root->descender +
face->horizontal.Line_Gap;
if ( !( root->ascender || root->descender ) )
{
*** 1671,1693 ****
{
if ( face->os2.sTypoAscender || face->os2.sTypoDescender )
{
root->ascender = face->os2.sTypoAscender;
root->descender = face->os2.sTypoDescender;
-
root->height = root->ascender - root->descender +
face->os2.sTypoLineGap;
}
else
{
root->ascender = (FT_Short)face->os2.usWinAscent;
root->descender = -(FT_Short)face->os2.usWinDescent;
-
root->height = root->ascender - root->descender;
}
}
}
root->max_advance_width =
(FT_Short)face->horizontal.advance_Width_Max;
root->max_advance_height =
(FT_Short)( face->vertical_info ? face->vertical.advance_Height_Max
--- 1697,1718 ----
{
if ( face->os2.sTypoAscender || face->os2.sTypoDescender )
{
root->ascender = face->os2.sTypoAscender;
root->descender = face->os2.sTypoDescender;
root->height = root->ascender - root->descender +
face->os2.sTypoLineGap;
}
else
{
root->ascender = (FT_Short)face->os2.usWinAscent;
root->descender = -(FT_Short)face->os2.usWinDescent;
root->height = root->ascender - root->descender;
}
}
}
+ }
root->max_advance_width =
(FT_Short)face->horizontal.advance_Width_Max;
root->max_advance_height =
(FT_Short)( face->vertical_info ? face->vertical.advance_Height_Max
*** 1735,1744 ****
--- 1760,1776 ----
sfnt->free_psnames( face );
/* destroy the embedded bitmaps table if it is loaded */
if ( sfnt->free_eblc )
sfnt->free_eblc( face );
+
+ /* destroy color table data if it is loaded */
+ if ( sfnt->free_cpal )
+ {
+ sfnt->free_cpal( face );
+ sfnt->free_colr( face );
+ }
}
#ifdef TT_CONFIG_OPTION_BDF
/* freeing the embedded BDF properties */
tt_face_free_bdf_props( face );
*** 1790,1804 ****
/* freeing sbit size table */
FT_FREE( face->root.available_sizes );
FT_FREE( face->sbit_strike_map );
face->root.num_fixed_sizes = 0;
- #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
FT_FREE( face->postscript_name );
FT_FREE( face->var_postscript_prefix );
#endif
face->sfnt = NULL;
}
/* END */
--- 1822,1843 ----
/* freeing sbit size table */
FT_FREE( face->root.available_sizes );
FT_FREE( face->sbit_strike_map );
face->root.num_fixed_sizes = 0;
FT_FREE( face->postscript_name );
+
+ #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
FT_FREE( face->var_postscript_prefix );
#endif
+ /* freeing glyph color palette data */
+ FT_FREE( face->palette_data.palette_name_ids );
+ FT_FREE( face->palette_data.palette_flags );
+ FT_FREE( face->palette_data.palette_entry_name_ids );
+ FT_FREE( face->palette );
+
face->sfnt = NULL;
}
/* END */
< prev index next >