ReactOS 0.4.16-dev-2354-g16de117
t1decode.c File Reference
Include dependency graph for t1decode.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define Fix2Int(f)   ( (FT_Int)(FT_Short)( (f) >> 16 ) )
 
#define FT_COMPONENT   t1decode
 

Typedefs

typedef enum T1_Operator_ T1_Operator
 

Enumerations

enum  T1_Operator_ {
  op_none = 0 , op_endchar , op_hsbw , op_seac ,
  op_sbw , op_closepath , op_hlineto , op_hmoveto ,
  op_hvcurveto , op_rlineto , op_rmoveto , op_rrcurveto ,
  op_vhcurveto , op_vlineto , op_vmoveto , op_dotsection ,
  op_hstem , op_hstem3 , op_vstem , op_vstem3 ,
  op_div , op_callothersubr , op_callsubr , op_pop ,
  op_return , op_setcurrentpoint , op_unknown15 , op_max
}
 

Functions

 t1_lookup_glyph_by_stdcharcode_ps (PS_Decoder *decoder, FT_Int charcode)
 
 t1_decoder_parse_metrics (T1_Decoder decoder, FT_Byte *charstring_base, FT_UInt charstring_len)
 
 t1_decoder_init (T1_Decoder decoder, FT_Face face, FT_Size size, FT_GlyphSlot slot, FT_Byte **glyph_names, PS_Blend blend, FT_Bool hinting, FT_Render_Mode hint_mode, T1_Decoder_Callback parse_callback)
 
 t1_decoder_done (T1_Decoder decoder)
 

Variables

static const FT_Int t1_args_count [op_max]
 

Macro Definition Documentation

◆ Fix2Int

#define Fix2Int (   f)    ( (FT_Int)(FT_Short)( (f) >> 16 ) )

Definition at line 31 of file t1decode.c.

◆ FT_COMPONENT

#define FT_COMPONENT   t1decode

Definition at line 40 of file t1decode.c.

Typedef Documentation

◆ T1_Operator

Enumeration Type Documentation

◆ T1_Operator_

Enumerator
op_none 
op_endchar 
op_hsbw 
op_seac 
op_sbw 
op_closepath 
op_hlineto 
op_hmoveto 
op_hvcurveto 
op_rlineto 
op_rmoveto 
op_rrcurveto 
op_vhcurveto 
op_vlineto 
op_vmoveto 
op_dotsection 
op_hstem 
op_hstem3 
op_vstem 
op_vstem3 
op_div 
op_callothersubr 
op_callsubr 
op_pop 
op_return 
op_setcurrentpoint 
op_unknown15 
op_max 

Definition at line 43 of file t1decode.c.

44 {
45 op_none = 0,
47 op_hsbw,
48 op_seac,
49 op_sbw,
65 op_div,
68 op_pop,
72
73 op_max /* never remove this one */
74
enum T1_Operator_ T1_Operator
@ op_hmoveto
Definition: t1decode.c:52
@ op_vstem
Definition: t1decode.c:63
@ op_dotsection
Definition: t1decode.c:60
@ op_vmoveto
Definition: t1decode.c:59
@ op_hlineto
Definition: t1decode.c:51
@ op_rlineto
Definition: t1decode.c:54
@ op_hstem
Definition: t1decode.c:61
@ op_rrcurveto
Definition: t1decode.c:56
@ op_vhcurveto
Definition: t1decode.c:57
@ op_unknown15
Definition: t1decode.c:71
@ op_seac
Definition: t1decode.c:48
@ op_hsbw
Definition: t1decode.c:47
@ op_closepath
Definition: t1decode.c:50
@ op_div
Definition: t1decode.c:65
@ op_setcurrentpoint
Definition: t1decode.c:70
@ op_rmoveto
Definition: t1decode.c:55
@ op_sbw
Definition: t1decode.c:49
@ op_vlineto
Definition: t1decode.c:58
@ op_pop
Definition: t1decode.c:68
@ op_callsubr
Definition: t1decode.c:67
@ op_max
Definition: t1decode.c:73
@ op_callothersubr
Definition: t1decode.c:66
@ op_hstem3
Definition: t1decode.c:62
@ op_vstem3
Definition: t1decode.c:64
@ op_return
Definition: t1decode.c:69
@ op_endchar
Definition: t1decode.c:46
@ op_none
Definition: t1decode.c:45
@ op_hvcurveto
Definition: t1decode.c:53

Function Documentation

◆ t1_decoder_done()

t1_decoder_done ( T1_Decoder  decoder)

Definition at line 2139 of file t1decode.c.

2140 {
2141 FT_Memory memory = decoder->builder.memory;
2142
2143
2144 t1_builder_done( &decoder->builder );
2145
2146 if ( decoder->cf2_instance.finalizer )
2147 {
2148 decoder->cf2_instance.finalizer( decoder->cf2_instance.data );
2149 FT_FREE( decoder->cf2_instance.data );
2150 }
2151 }
#define FT_FREE(ptr)
Definition: ftmemory.h:337
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:64
static char memory[1024 *256]
Definition: process.c:122
t1_builder_done(T1_Builder builder)
Definition: psobjs.c:1631

◆ t1_decoder_init()

t1_decoder_init ( T1_Decoder  decoder,
FT_Face  face,
FT_Size  size,
FT_GlyphSlot  slot,
FT_Byte **  glyph_names,
PS_Blend  blend,
FT_Bool  hinting,
FT_Render_Mode  hint_mode,
T1_Decoder_Callback  parse_callback 
)

Definition at line 2091 of file t1decode.c.

2100 {
2101 FT_ZERO( decoder );
2102
2103 /* retrieve `psnames' interface from list of current modules */
2104 {
2105 FT_Service_PsCMaps psnames;
2106
2107
2108 FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
2109 if ( !psnames )
2110 {
2111 FT_ERROR(( "t1_decoder_init:"
2112 " the `psnames' module is not available\n" ));
2113 return FT_THROW( Unimplemented_Feature );
2114 }
2115
2116 decoder->psnames = psnames;
2117 }
2118
2119 t1_builder_init( &decoder->builder, face, size, slot, hinting );
2120
2121 /* decoder->buildchar and decoder->len_buildchar have to be */
2122 /* initialized by the caller since we cannot know the length */
2123 /* of the BuildCharArray */
2124
2125 decoder->num_glyphs = (FT_UInt)face->num_glyphs;
2126 decoder->glyph_names = glyph_names;
2127 decoder->hint_mode = hint_mode;
2128 decoder->blend = blend;
2129 decoder->parse_callback = parse_callback;
2130
2131 decoder->funcs = t1_decoder_funcs;
2132
2133 return FT_Err_Ok;
2134 }
return FT_Err_Ok
Definition: ftbbox.c:526
#define FT_ERROR(varformat)
Definition: ftdebug.h:211
#define FT_THROW(e)
Definition: ftdebug.h:243
#define FT_ZERO(p)
Definition: ftmemory.h:246
#define FT_FACE_FIND_GLOBAL_SERVICE(face, ptr, id)
Definition: ftserv.h:128
unsigned int FT_UInt
Definition: fttypes.h:231
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
FT_CALLBACK_TABLE_DEF const T1_Decoder_FuncsRec t1_decoder_funcs
Definition: psauxmod.c:87
t1_builder_init(T1_Builder builder, FT_Face face, FT_Size size, FT_GlyphSlot glyph, FT_Bool hinting)
Definition: psobjs.c:1574
Definition: vfat.h:185

◆ t1_decoder_parse_metrics()

t1_decoder_parse_metrics ( T1_Decoder  decoder,
FT_Byte charstring_base,
FT_UInt  charstring_len 
)

Definition at line 1691 of file t1decode.c.

1694 {
1696 FT_Byte* ip;
1697 FT_Byte* limit;
1698 T1_Builder builder = &decoder->builder;
1699 FT_Bool large_int;
1700
1701#ifdef FT_DEBUG_LEVEL_TRACE
1702 FT_Bool bol = TRUE;
1703#endif
1704
1705
1706 /* First of all, initialize the decoder */
1707 decoder->top = decoder->stack;
1708 decoder->zone = decoder->zones;
1709 zone = decoder->zones;
1710
1711 builder->parse_state = T1_Parse_Start;
1712
1713 zone->base = charstring_base;
1714 limit = zone->limit = charstring_base + charstring_len;
1715 ip = zone->cursor = zone->base;
1716
1717 large_int = FALSE;
1718
1719 /* now, execute loop */
1720 while ( ip < limit )
1721 {
1722 FT_Long* top = decoder->top;
1724 FT_Int32 value = 0;
1725
1726
1727#ifdef FT_DEBUG_LEVEL_TRACE
1728 if ( bol )
1729 {
1730 FT_TRACE5(( " (%ld)", decoder->top - decoder->stack ));
1731 bol = FALSE;
1732 }
1733#endif
1734
1735 /**********************************************************************
1736 *
1737 * Decode operator or operand
1738 *
1739 */
1740
1741 /* first of all, decompress operator or value */
1742 switch ( *ip++ )
1743 {
1744 case 1:
1745 case 3:
1746 case 4:
1747 case 5:
1748 case 6:
1749 case 7:
1750 case 8:
1751 case 9:
1752 case 14:
1753 case 15:
1754 case 21:
1755 case 22:
1756 case 30:
1757 case 31:
1758 goto No_Width;
1759
1760 case 10:
1761 op = op_callsubr;
1762 break;
1763 case 11:
1764 op = op_return;
1765 break;
1766
1767 case 13:
1768 op = op_hsbw;
1769 break;
1770
1771 case 12:
1772 if ( ip >= limit )
1773 {
1774 FT_ERROR(( "t1_decoder_parse_metrics:"
1775 " invalid escape (12+EOF)\n" ));
1776 goto Syntax_Error;
1777 }
1778
1779 switch ( *ip++ )
1780 {
1781 case 7:
1782 op = op_sbw;
1783 break;
1784 case 12:
1785 op = op_div;
1786 break;
1787
1788 default:
1789 goto No_Width;
1790 }
1791 break;
1792
1793 case 255: /* four bytes integer */
1794 if ( ip + 4 > limit )
1795 {
1796 FT_ERROR(( "t1_decoder_parse_metrics:"
1797 " unexpected EOF in integer\n" ));
1798 goto Syntax_Error;
1799 }
1800
1801 value = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) |
1802 ( (FT_UInt32)ip[1] << 16 ) |
1803 ( (FT_UInt32)ip[2] << 8 ) |
1804 (FT_UInt32)ip[3] );
1805 ip += 4;
1806
1807 /* According to the specification, values > 32000 or < -32000 must */
1808 /* be followed by a `div' operator to make the result be in the */
1809 /* range [-32000;32000]. We expect that the second argument of */
1810 /* `div' is not a large number. Additionally, we don't handle */
1811 /* stuff like `<large1> <large2> <num> div <num> div' or */
1812 /* <large1> <large2> <num> div div'. This is probably not allowed */
1813 /* anyway. */
1814 if ( value > 32000 || value < -32000 )
1815 {
1816 if ( large_int )
1817 {
1818 FT_ERROR(( "t1_decoder_parse_metrics:"
1819 " no `div' after large integer\n" ));
1820 goto Syntax_Error;
1821 }
1822 else
1823 large_int = TRUE;
1824 }
1825 else
1826 {
1827 if ( !large_int )
1828 value = (FT_Int32)( (FT_UInt32)value << 16 );
1829 }
1830
1831 break;
1832
1833 default:
1834 if ( ip[-1] >= 32 )
1835 {
1836 if ( ip[-1] < 247 )
1837 value = (FT_Int32)ip[-1] - 139;
1838 else
1839 {
1840 if ( ++ip > limit )
1841 {
1842 FT_ERROR(( "t1_decoder_parse_metrics:"
1843 " unexpected EOF in integer\n" ));
1844 goto Syntax_Error;
1845 }
1846
1847 if ( ip[-2] < 251 )
1848 value = ( ( ip[-2] - 247 ) * 256 ) + ip[-1] + 108;
1849 else
1850 value = -( ( ( ip[-2] - 251 ) * 256 ) + ip[-1] + 108 );
1851 }
1852
1853 if ( !large_int )
1854 value = (FT_Int32)( (FT_UInt32)value << 16 );
1855 }
1856 else
1857 {
1858 FT_ERROR(( "t1_decoder_parse_metrics:"
1859 " invalid byte (%d)\n", ip[-1] ));
1860 goto Syntax_Error;
1861 }
1862 }
1863
1864 if ( large_int && !( op == op_none || op == op_div ) )
1865 {
1866 FT_ERROR(( "t1_decoder_parse_metrics:"
1867 " no `div' after large integer\n" ));
1868 goto Syntax_Error;
1869 }
1870
1871 /**********************************************************************
1872 *
1873 * Push value on stack, or process operator
1874 *
1875 */
1876 if ( op == op_none )
1877 {
1878 if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS )
1879 {
1880 FT_ERROR(( "t1_decoder_parse_metrics: stack overflow\n" ));
1881 goto Syntax_Error;
1882 }
1883
1884#ifdef FT_DEBUG_LEVEL_TRACE
1885 if ( large_int )
1886 FT_TRACE4(( " %d", value ));
1887 else
1888 FT_TRACE4(( " %d", value / 65536 ));
1889#endif
1890
1891 *top++ = value;
1892 decoder->top = top;
1893 }
1894 else /* general operator */
1895 {
1896 FT_Int num_args = t1_args_count[op];
1897
1898
1899 FT_ASSERT( num_args >= 0 );
1900
1901 if ( top - decoder->stack < num_args )
1902 goto Stack_Underflow;
1903
1904#ifdef FT_DEBUG_LEVEL_TRACE
1905
1906 switch ( op )
1907 {
1908 case op_callsubr:
1909 case op_div:
1910 case op_return:
1911 break;
1912
1913 default:
1914 if ( top - decoder->stack != num_args )
1915 FT_TRACE0(( "t1_decoder_parse_metrics:"
1916 " too much operands on the stack"
1917 " (seen %ld, expected %d)\n",
1918 top - decoder->stack, num_args ));
1919 break;
1920 }
1921
1922#endif /* FT_DEBUG_LEVEL_TRACE */
1923
1924 top -= num_args;
1925
1926 switch ( op )
1927 {
1928 case op_hsbw:
1929 FT_TRACE4(( " hsbw" ));
1930
1932
1933 builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1934 top[0] );
1935
1936 builder->advance.x = top[1];
1937 builder->advance.y = 0;
1938
1939 /* we only want to compute the glyph's metrics */
1940 /* (lsb + advance width) without loading the */
1941 /* rest of it; so exit immediately */
1942 FT_TRACE4(( "\n" ));
1943 return FT_Err_Ok;
1944
1945 case op_sbw:
1946 FT_TRACE4(( " sbw" ));
1947
1949
1950 builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1951 top[0] );
1952 builder->left_bearing.y = ADD_LONG( builder->left_bearing.y,
1953 top[1] );
1954
1955 builder->advance.x = top[2];
1956 builder->advance.y = top[3];
1957
1958 /* we only want to compute the glyph's metrics */
1959 /* (lsb + advance width), without loading the */
1960 /* rest of it; so exit immediately */
1961 FT_TRACE4(( "\n" ));
1962 return FT_Err_Ok;
1963
1964 case op_div:
1965 FT_TRACE4(( " div" ));
1966
1967 /* if `large_int' is set, we divide unscaled numbers; */
1968 /* otherwise, we divide numbers in 16.16 format -- */
1969 /* in both cases, it is the same operation */
1970 *top = FT_DivFix( top[0], top[1] );
1971 top++;
1972
1973 large_int = FALSE;
1974 break;
1975
1976 case op_callsubr:
1977 {
1978 FT_Int idx;
1979
1980
1981 FT_TRACE4(( " callsubr" ));
1982
1983 idx = Fix2Int( top[0] );
1984
1985 if ( decoder->subrs_hash )
1986 {
1987 size_t* val = ft_hash_num_lookup( idx,
1988 decoder->subrs_hash );
1989
1990
1991 if ( val )
1992 idx = *val;
1993 else
1994 idx = -1;
1995 }
1996
1997 if ( idx < 0 || idx >= decoder->num_subrs )
1998 {
1999 FT_ERROR(( "t1_decoder_parse_metrics:"
2000 " invalid subrs index\n" ));
2001 goto Syntax_Error;
2002 }
2003
2004 if ( zone - decoder->zones >= T1_MAX_SUBRS_CALLS )
2005 {
2006 FT_ERROR(( "t1_decoder_parse_metrics:"
2007 " too many nested subrs\n" ));
2008 goto Syntax_Error;
2009 }
2010
2011 zone->cursor = ip; /* save current instruction pointer */
2012
2013 zone++;
2014
2015 /* The Type 1 driver stores subroutines without the seed bytes. */
2016 /* The CID driver stores subroutines with seed bytes. This */
2017 /* case is taken care of when decoder->subrs_len == 0. */
2018 zone->base = decoder->subrs[idx];
2019
2020 if ( decoder->subrs_len )
2021 zone->limit = zone->base + decoder->subrs_len[idx];
2022 else
2023 {
2024 /* We are using subroutines from a CID font. We must adjust */
2025 /* for the seed bytes. */
2026 zone->base += ( decoder->lenIV >= 0 ? decoder->lenIV : 0 );
2027 zone->limit = decoder->subrs[idx + 1];
2028 }
2029
2030 zone->cursor = zone->base;
2031
2032 if ( !zone->base )
2033 {
2034 FT_ERROR(( "t1_decoder_parse_metrics:"
2035 " invoking empty subrs\n" ));
2036 goto Syntax_Error;
2037 }
2038
2039 decoder->zone = zone;
2040 ip = zone->base;
2041 limit = zone->limit;
2042 break;
2043 }
2044
2045 case op_return:
2046 FT_TRACE4(( " return" ));
2047
2048 if ( zone <= decoder->zones )
2049 {
2050 FT_ERROR(( "t1_decoder_parse_metrics:"
2051 " unexpected return\n" ));
2052 goto Syntax_Error;
2053 }
2054
2055 zone--;
2056 ip = zone->cursor;
2057 limit = zone->limit;
2058 decoder->zone = zone;
2059 break;
2060
2061 default:
2062 FT_ERROR(( "t1_decoder_parse_metrics:"
2063 " unhandled opcode %d\n", op ));
2064 goto Syntax_Error;
2065 }
2066
2067 decoder->top = top;
2068
2069 } /* general operator processing */
2070
2071 } /* while ip < limit */
2072
2073 FT_TRACE4(( "..end..\n\n" ));
2074
2075 No_Width:
2076 FT_ERROR(( "t1_decoder_parse_metrics:"
2077 " no width, found op %d instead\n",
2078 ip[-1] ));
2079 Syntax_Error:
2080 return FT_THROW( Syntax_Error );
2081
2082 Stack_Underflow:
2083 return FT_THROW( Stack_Underflow );
2084 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UINT op
Definition: effect.c:236
unsigned int idx
Definition: utils.c:41
FT_DivFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:607
#define ADD_LONG(a, b)
Definition: ftcalc.h:472
#define FT_ASSERT(condition)
Definition: ftdebug.h:241
#define FT_TRACE0(varformat)
Definition: ftdebug.h:187
#define FT_TRACE5(varformat)
Definition: ftdebug.h:192
#define FT_TRACE4(varformat)
Definition: ftdebug.h:191
size_t * ft_hash_num_lookup(FT_Int num, FT_Hash hash)
Definition: fthash.c:326
#define T1_MAX_CHARSTRINGS_OPERANDS
Definition: ftoption.h:777
#define T1_MAX_SUBRS_CALLS
Definition: ftoption.h:766
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
unsigned char FT_Byte
Definition: fttypes.h:154
signed long FT_Long
Definition: fttypes.h:242
signed int FT_Int
Definition: fttypes.h:220
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
GLint limit
Definition: glext.h:10326
GLuint GLfloat * val
Definition: glext.h:7180
DWORD zone
Definition: sec_mgr.c:1754
@ T1_Parse_Have_Width
Definition: psaux.h:756
@ T1_Parse_Start
Definition: psaux.h:755
FT_Pos x
Definition: ftimage.h:77
FT_Pos y
Definition: ftimage.h:78
FT_Vector advance
Definition: psaux.h:840
FT_Vector left_bearing
Definition: psaux.h:839
T1_ParseState parse_state
Definition: psaux.h:843
Definition: dhcpd.h:62
static const FT_Int t1_args_count[op_max]
Definition: t1decode.c:79
#define Fix2Int(f)
Definition: t1decode.c:31
Definition: pdh_main.c:96

◆ t1_lookup_glyph_by_stdcharcode_ps()

t1_lookup_glyph_by_stdcharcode_ps ( PS_Decoder decoder,
FT_Int  charcode 
)

Definition at line 132 of file t1decode.c.

134 {
135 FT_UInt n;
136 const FT_String* glyph_name;
137 FT_Service_PsCMaps psnames = decoder->psnames;
138
139
140 /* check range of standard char code */
141 if ( charcode < 0 || charcode > 255 )
142 return -1;
143
144 glyph_name = psnames->adobe_std_strings(
145 psnames->adobe_std_encoding[charcode]);
146
147 for ( n = 0; n < decoder->num_glyphs; n++ )
148 {
149 FT_String* name = (FT_String*)decoder->glyph_names[n];
150
151
152 if ( name &&
153 name[0] == glyph_name[0] &&
154 ft_strcmp( name, glyph_name ) == 0 )
155 return (FT_Int)n;
156 }
157
158 return -1;
159 }
#define ft_strcmp
Definition: ftstdlib.h:86
char FT_String
Definition: fttypes.h:187
GLdouble n
Definition: glext.h:7729
if(dx< 0)
Definition: linetemp.h:194
Definition: name.c:39

Referenced by cf2_interpT2CharString().

Variable Documentation

◆ t1_args_count

const FT_Int t1_args_count[op_max]
static
Initial value:
=
{
0,
0,
2,
5,
4,
0,
1,
1,
4,
2,
2,
6,
4,
1,
1,
0,
2,
6,
2,
6,
2,
-1,
1,
0,
0,
2,
2
}

Definition at line 79 of file t1decode.c.

Referenced by t1_decoder_parse_metrics().