initial import of the FreeType Layout sources

This commit is contained in:
David Turner 2004-04-05 22:16:12 +00:00
parent cad0775afe
commit a5f7fcdf56
86 changed files with 46305 additions and 5 deletions

View File

@ -12,3 +12,5 @@ Note that the use of `psnames' can be controlled in ftconfig.h
type42 truetype
psaux psnames
sfnt psnames
gx truetype
ot truetype

291
ftlayout.txt Normal file
View File

@ -0,0 +1,291 @@
About FTLayout
==============
FTLayout is a layout engine stacked on FreeType2. Currently
TrueTypeGX/AAT is supported as a file format. OpenType is also
supported, but highly experimental.
FTLayout provides an generic interface which is shared by a layout
engine(GXLayout) for TrueTypeGX/AAT and a layout engine(OTLayout)for
OpenType for glyph substitution, one of the text layout function.
See "The TureType Font File"
(http://developer.apple.com/fonts/TTRefMan/RM06/Chap6.html)
about TrueTypeGX/AAT.
About GXLayout
==============
GXLayout provides interface for mort, morx, lcar, format 0, 2 3 kern,
feat TrueTypeGX/AAT tables.
We tested GXLayout against "Non-contextual glyph substitution" and
"Ligature substitution" in kochigx-substitute-20040218
fonts. "Non-contextual glyph substitution" in
kochigx-substitute-20040218 fonts represents "vertical
substitution". "Ligature substitution" in kochigx-substitute-20040218
fonts represents "Non-contextual glyph substitution".
We tested GXLayout against "fi" ligature("Ligature substitution") in
MacOSX's dfonts.
It seems that Pfaedit can generate TrueTypeGX/AAT font. However, we
have not tested GXLayout against fonts generated by Pfaedit yet.
About OTLayout
==============
(Different from GXLayout)OTLayout is not written from scratch; it
is just applied existing implementation to FTLayout, a newly designed
interface. The existing implementation stands for:
The code ported by the author of Pango to FreeType2 for using
the code in Pango from TrueTypeOpen code in FreeType1
implemented by FreeType developers.
What we have done is to make fit the existing implementation to
new FTLayout glyph substitution interface. As written above, OTLayout
in FTLayout is highly experimental. We have tested only punctuation
substitution in Japanese vertical writing. Currently OpenType/TrueType
is supported; OpenType/CFF is not supported. Hereafter in this
document we focus on GXLayout.
Install
=======
You have not changed the install procedure. However we recommend to
give --prefix=/somewhere-different-from-/usr-or-/usr/local to
configure command if FreeType2 is already installed on your system.
e.g. --prefix=/opt
We have taken care that we do not change the source/binary interfaces
of FreeType2. However FTLayout development is based on the FreeType
code of HEAD in FreeType2's CVS repository(as of Mon Feb 23 14:30:49
2004). If source/binary interfaces are not compatible between in
FreeType2 on your system and that of HEAD, installing FreeType2 with
FTLayout into /usr/lib or /usr/local/lib will be trouble. Take care.
Demo program
============
fi and gxdemo are bundled as GXLayout demo programs. To build the demo
programs, type following command line in src/gxlayout after installing
FreeType2 with FTLayout:
$ make -f demo.mk
fi and gxdemo will be built.
- fi command
With rules defined in a font file specified as the first argument
for fi, try to substitute "fi" glyph string; and print the result
to stdout. The default value defined in feat table is used as font
feature settings in substitution. If you want to try different
settings, gxdemo is suitable.
Example:
$ ./fi /Library/Fonts/Zapfino.dfont
-------------------
File: /Library/Fonts/Zapfino.dfont
Name: Zapfino
[IN]f: 536, i: 552
[OUT]f: 1089, i: 65535<empty>
This output stands for
- [IN] is input glyph string,
- [OUT] substituted glyph string,
- ([IN])the glyph id for `f' is 536,
- ([IN])the glyph id for `i' is 552, and
- ([OUT])as the result of substitution, we get single glyph which
is 1089. 536, 552 are ligature into 1089.
Only FreeType2 with FTLayout and standard C library are used in
fi.
- gxdemo
gxdemo is a tool to inspect tables in a TrueTypeGX/AAT font and
the behavior of GXLayout with GUI.
Run gxdemo with a target TrueTypeGX/AAT font file from a terminal.
gxdemo's window has multiple tabs.
In "Features" tab, you can change the feature settings. Pressing
"Reset" button and the settings are reset; setting are set to the
default values defined in feat table. With "Run" button, you can
try to substitute glyphs under the setting given in this "Features"
tab. Pressing "Run" button, "Input: " prompt is appeared in the
terminal. Give the glyph ids separated by space and type return key
at the end of input glyph ids. Then substituted glyph ids are
printed on the terminal.
Example:
$ ./gxdemo ~/.fonts/kochigx-mincho-subst.ttf
Input: 200 19 20 300
Substituted: 200 14571 65535<empty> 300
In "Glyph" tab, you can render a glyph by giving a glyph id.
In "Dump" tab, you can dump the TrueTypeGX/AAT tables of the font
in pseudo XML format with pressing "Dump Font Tables" button. Also
with pressing "Dump Feature Request" button, you can dump the
current font feature settings in "Features" tab in a text format.
Batch dump mode is also available. To dump mort and feat from a
terminal, type
$ ./gxdemo --batch --table=mort:feat font.ttf
We, FTLayout developers used
mlview(http://www.freespiders.org/projects/gmlview/) to browse
the XML formated dump datum.
In "Trace" tab, you can set FreeType2's trace level. To examine
the process of glyph substitution, set "gxvm" and "gxchain" to 3.
Different from fi, gxdemo uses gtk+ GUI toolkit. To build gxdemo,
following libraries are needed:
- glib-2.0
- gtk+-2.0
- libgnomecanvas-2.0
- popt
At least Red Hat Linux 9 includes these libraries.
Using FTLayout and GXLayout
===========================
To do glyph substitution in your program, you have to use both
FTLayout interface(as generic interface) and GXLayout interface(as
concrete interface). The symbols in FTLayout have "FTL" as prefix.
The symbols in GXLayout have "GXL" as prefix. Symbols in FTLayout
are declared in include/freetype/ftlayout.h. Symbols in GXLayout
are declared in include/freetype/gxlayout.h. To include these header
files in your source file, you have to obey to the way of FreeType2;
you have to specify the header files in symbols:
#include<ft2build.h>
...
#include FT_LAYOUT_H
#include FT_GXLAYOUT_H
The outlines of usage are:
1. Create a face
This procedure is the same as before.
Create a `face' from the target font file after
initialize the library itself.
2. Check the existence of substitution tables
You can check the existence of substitution table
in the target font by the logical AND operation between
face::face_flags and FT_FACE_FLAG_GLYPH_SUBSTITUTION.
3. Check the type of layout engine
You can check whether the type of text layout engine
is GXLayout or OTLayout by invoking FTL_Query_EngineType.
Hereafter, we assume the engine type is GXLayout.
4. Create a request
A `request' is needed in FTLayout to specify the
font feature settings in substitution. You can create more
than one requests against one face and specify the font
feature settings independently each of them; and activate
one of them. Invoke FTL_New_FeaturesRequest with a face to
create a requests. Invoke FTL_Done_FeaturesRequest to release a
request.
5. Set the features and settings to the request
Concrete text layout engine(GXLayout)'s interface is used to
specify the font feature settings to a request. Following
functions are available to specify:
- GXL_FeaturesRequest_Get_Feature returns a object(feature)
which represents Nth feature of a face.
- GXL_FeaturesRequest_Get_Feature_Count returns the number of
features in a face.
- GXL_Feature_Get_Setting returns a object(setting) which
requests Nth setting of a feature.
- GXL_Feature_Get_Setting_Count returns the number of settings
in a feature.
- GXL_Feature_Get_Name returns the name of given feature.
- GXL_Setting_Get_State returns the state (enable or disable)
of given setting.
- GXL_Setting_Get_Name returns the name of given setting.
- GXL_Feature_Is_Setting_Exclusive returns whether given
setting is exclusive or not.
These functions may be useful to construct GUI thorough which
application users can specify the font features settings.
"Features" tab of gxdemo may be good example to construct
GUI.
The writing direction(vertical or horizontal) have to be
specified also in FTLayout level. Use
FTL_Set_FeaturesRequest_Direction
to specify. Whether you have to specify the direction in
GXLayout level or not depends on the target font file.
6. Activate request
After setting a request by functions explained in 5.,
You have to activate it. Use
FTL_Activate_FeaturesRequest
to activate a face. (Only one request is active for
a face at the same time.)
7. Create input/output glyph array
FTL_New_Glyphs_Array is used to create a glyph array.
To substitute two glyph arrays are needed to store
input glyphs(input) and substituted result(output).
About the input, you have to set the length and fill the array
with glyphs by your self. Use
FTL_Set_Glyphs_Array_Length
to set the length of glyph array. Use `gid' field of glyph
array to fill the input glyphs.
The length of output are automatically set by FTLayout.
8. Substitute
Invoke
FTL_Substitute_Glyphs
with a face, input and output.
Other than 5. are procedures are done in fi command. Therefore fi.c
may be good simple example to substitute glyphs.
TODO
====
- lazy table loading
- verification table data during loading not in
substitution time
- more detailing error codes and using them
License
=======
The licenses of FTLayout and GXLayout are the same as that
of FreeType2. About OTLayout, see src/otlayout/README.
Acknowledgments
===============
This development is supported by Information-technology Promotion
Agency, Japan(IPA). We would like to appreciate the supports.
Mitsuru Oka advised us about OpenType and Pango. We would like to
appreciate his advices.
Contact
=======
Masatake YAMATO
<yamato@redhat.com> or <jet@gyve.org>

View File

@ -529,6 +529,17 @@
/* */
#define FT_SFNT_NAMES_H <freetype/ftsnames.h>
/*************************************************************************/
/* */
/* @macro: */
/* FT_LAYOUT_H */
/* */
/* @description: */
/* A macro used in #include statements to name the file containing */
/* FreeType Layout API. */
/* */
#define FT_LAYOUT_H <freetype/ftlayout.h>
/* */
#define FT_TRIGONOMETRY_H <freetype/fttrigon.h>
@ -550,6 +561,9 @@
#define FT_INCREMENTAL_H <freetype/ftincrem.h>
#define FT_GXLAYOUT_H <freetype/gxlayout.h>
#define FT_OTLAYOUT_H <freetype/otlayout.h>
#define FT_TRUETYPE_UNPATENTED_H <freetype/ttunpat.h>
/* now include internal headers definitions from <freetype/internal/...> */

View File

@ -11,6 +11,8 @@ FT_USE_MODULE(sfnt_module_class)
FT_USE_MODULE(ft_smooth_renderer_class)
FT_USE_MODULE(ft_smooth_lcd_renderer_class)
FT_USE_MODULE(ft_smooth_lcdv_renderer_class)
FT_USE_MODULE(gx_driver_class)
FT_USE_MODULE(ot_driver_class)
FT_USE_MODULE(tt_driver_class)
FT_USE_MODULE(t1_driver_class)
FT_USE_MODULE(t42_driver_class)

View File

@ -110,6 +110,7 @@
#include <stdlib.h>
#define ft_qsort qsort
#define ft_bsearch bsearch
#define ft_exit exit /* only used to exit from unhandled exceptions */
#define ft_atol atol

View File

@ -1028,6 +1028,13 @@ FT_BEGIN_HEADER
/* provided by the client application and should not be destroyed */
/* when @FT_Done_Face is called. Don't read or test this flag. */
/* */
/* FT_FACE_FLAG_GLYPH_SUBSTITUTION :: */
/* Indicates that the face contains glyph substitution information. */
/* If set, GSUB(otlayout) or mort/morx(gxlayout) is existed in the */
/* face. You can use glyph substitution functions declared in */
/* ftlayout.h */
/* */
#define FT_FACE_FLAG_SCALABLE ( 1L << 0 )
#define FT_FACE_FLAG_FIXED_SIZES ( 1L << 1 )
#define FT_FACE_FLAG_FIXED_WIDTH ( 1L << 2 )
@ -1039,6 +1046,7 @@ FT_BEGIN_HEADER
#define FT_FACE_FLAG_MULTIPLE_MASTERS ( 1L << 8 )
#define FT_FACE_FLAG_GLYPH_NAMES ( 1L << 9 )
#define FT_FACE_FLAG_EXTERNAL_STREAM ( 1L << 10 )
#define FT_FACE_FLAG_GLYPH_SUBSTITUTION ( 1L << 20 )
/* */
@ -1188,6 +1196,16 @@ FT_BEGIN_HEADER
#define FT_HAS_MULTIPLE_MASTERS( face ) \
( face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS )
/*************************************************************************/
/* */
/* @macro: */
/* FT_HAS_GLYPH_SUBSTITUTION( face ) */
/* */
/* @description: */
/* TODO */
/* */
#define FT_HAS_GLYPH_SUBSTITUTION( face ) \
( face->face_flags & FT_FACE_FLAG_GLYPH_SUBSTITUTION )
/*************************************************************************/
/* */

View File

@ -227,5 +227,13 @@
FT_ERRORDEF_( Missing_Bbx_Field, 0xB6, \
"`BBX' field missing" )
/* GX errors */
FT_ERRORDEF_( Old_Kerning_Table, 0xC0, \
"too old kerning format" )
FT_ERRORDEF_( Missing_Glyph_Substitution_Data, 0xC1, \
"glyph substitution data is missing" )
FT_ERRORDEF_( Busy_Extra_Data, 0xC2, \
"TT_Face extra data field is busy" )
/* END */

515
include/freetype/ftlayout.h Normal file
View File

@ -0,0 +1,515 @@
/***************************************************************************/
/* */
/* ftltypes.h */
/* */
/* FreeType Layout API (specification) */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __FTL_LAYOUT_H_
#define __FTL_LAYOUT_H_
#include <ft2build.h>
#include FT_FREETYPE_H
FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <Section> */
/* text_layout */
/* */
/* <Title> */
/* Text Layout */
/* */
/* <Abstract> */
/* Generic text layout functions. */
/* */
/* <Description> */
/* The following types and functions are used in text layout. */
/* FTLayout is a layout engine stacked on FreeType2. Currently */
/* TrueTypeGX/AAT is supported as a file format. OpenType is also */
/* supported, but highly experimental. */
/* FTLayout provides an abstract interface which is shared by a */
/* layout engine(GXLayout) for TrueTypeGX/AAT and a layout engine */
/* (OTLayout)for OpenType for glyph substitution, one of the text */
/* layout function. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Type> */
/* FTL_FeaturesRequest */
/* */
/* <Description> */
/* An opaque data type to specify which font features are used in */
/* text layout. */
/* */
/* Use @FTL_New_FeaturesRequest to create from a face and */
/* @FTL_Done_FeaturesRequest to discard. The way to specify the font */
/* features' settting depenes on the concrete font engine behind the */
/* face. */
/* */
typedef struct FTL_FeaturesRequestRec_ * FTL_FeaturesRequest;
/*************************************************************************/
/* */
/* <Type> */
/* FTL_Glyphs_Array */
/* */
/* <Description> */
/* Data type represents glyphs array used in glyph substitution. */
/* See @FTL_GlyphRec for more detail. */
/* */
typedef struct FTL_Glyphs_ArrayRec_ * FTL_Glyphs_Array;
/*************************************************************************/
/* */
/* <Enum> */
/* FTL_EngineType */
/* */
/* <Description> */
/* An enumeration representing the concrete text layout engine type. */
/* You can get the value for a given face, use @FTL_Query_EngineType. */
/* */
/* <Values> */
/* FTL_NO_ENGINE :: */
/* No text layout engine behind the face. */
/* */
/* FTL_OPENTYPE_ENGINE :: */
/* OpneType layout engine. You should use the interface declared in */
/* otlayout.h. */
/* */
/* FTL_TRUETYPEGX_ENGINE :: */
/* TrueTypeGX/AAT layout engine. You should use the interface */
/* declared in gxlayout.h. */
/* */
typedef enum
{
FTL_NO_ENGINE = 0,
FTL_OPENTYPE_ENGINE = 1, /* Use otlayout.h */
FTL_TRUETYPEGX_ENGINE = 2 /* Use gxlayout.h */
} FTL_EngineType;
/*************************************************************************/
/* */
/* <Enum> */
/* FTL_Direction */
/* */
/* <Description> */
/* An enumeration representing the text layout direction. */
/* */
/* You can set the direction value to a features request by */
/* @FTL_Set_FeaturesRequest_Direction. You can get the direction */
/* value from a features request by */
/* @FTL_Get_FeaturesRequest_Direction. */
/* */
/* <Values> */
/* FTL_HORIZONTAL :: */
/* Value representing horizontal writing. */
/* */
/* FTL_VERTICAL :: */
/* Value representing vertical writing. */
/* */
typedef enum
{
FTL_HORIZONTAL = 0,
FTL_VERTICAL = 1
} FTL_Direction;
/*************************************************************************/
/* */
/* <Struct> */
/* FTL_GlyphRec */
/* */
/* <Description> */
/* Data type represents a glyph id used in glyph substitution. */
/* */
/* <Fields> */
/* gid :: The glyph id. If gid is 0xFFFF, this element in an */
/* glyph array should be ignored. */
/* */
/* ot_prop :: Glyph's property used in OTLayout substitution. */
/* GXLayout does not use this field. */
/* */
typedef struct FTL_GlyphRec_
{
FT_UShort gid;
FT_UShort reserved1;
FT_ULong ot_prop;
FT_ULong reserved2;
} FTL_GlyphRec, * FTL_Glyph;
/*************************************************************************/
/* */
/* <Struct> */
/* FTL_Glyph_ArrayRec_ */
/* */
/* <Description> */
/* Data type represents glyphs array used in glyph substitution. */
/* */
/* This data type is used as input and output arguments for */
/* @FTL_Substitute_Glyphs. */
/* @FTL_New_Glyphs_Array allocates 0 length FTL_GlyphRec object. */
/* @FTL_Set_Glyphs_Array_Length sets the length of FTL_GlyphRec */
/* object. You have to set the length to create an input glyph array */
/* for substitution. */
/* */
/* <Fields> */
/* memory :: The current memory object which handles the glyph */
/* arrray. */
/* */
/* glyphs :: Glyphs ids' array. */
/* */
/* length :: The valid length of glyphs. */
/* */
/* allocated :: The allocation size of glyphs. The client should not */
/* refer this field. */
/* */
typedef struct FTL_Glyphs_ArrayRec_
{
FT_Memory memory;
FTL_Glyph glyphs;
/* FT_ULong pos; */
FT_ULong reserved1;
FT_ULong length;
FT_ULong allocated;
} FTL_Glyphs_ArrayRec;
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Query_EngineType */
/* */
/* <Description> */
/* Returns the text layout engine type behind a face. */
/* */
/* <Input> */
/* face :: The target face. */
/* */
/* <Output> */
/* engine_type :: The type of text layout engine for the face. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT( FT_Error )
FTL_Query_EngineType ( FT_Face face,
FTL_EngineType * engine_type);
/*************************************************************************/
/* */
/* <Function> */
/* FTL_New_FeaturesRequest */
/* */
/* <Description> */
/* Creates a new features request for a face. */
/* */
/* <Input> */
/* face :: The target face. */
/* */
/* <Output> */
/* request :: A features request for a face. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* When the target face is discarded by @FT_Done_Face, all features */
/* requests corresponding to the face are also discardeded */
/* automatically. */
/* */
FT_EXPORT( FT_Error )
FTL_New_FeaturesRequest ( FT_Face face,
FTL_FeaturesRequest* request);
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Done_FeaturesRequest */
/* */
/* <Description> */
/* Discards a features request. */
/* */
/* <Input> */
/* request :: A features request. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT( FT_Error )
FTL_Done_FeaturesRequest ( FTL_FeaturesRequest request );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Activate_FeaturesRequest */
/* */
/* <Description> */
/* Even though it is possible to create serveral features request */
/* object for a given face (see @FTL_New_FeaturesRequest), */
/* @FTL_Substitute_Glyphs only use the last activated request. */
/* With this function, a features request can be activated. */
/* */
/* <Input> */
/* request :: A features request to be activated. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT ( FT_Error )
FTL_Activate_FeaturesRequest ( FTL_FeaturesRequest request );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Copy_FeaturesRequest */
/* */
/* <Description> */
/* Copy the setting of one features request to another. */
/* */
/* <Input> */
/* from :: The source features request. */
/* */
/* <Output> */
/* to :: The destination features request. This must be created by */
/* @FTL_New_FeaturesRequest before copying. */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* from and to must be created from the same face. */
/* */
FT_EXPORT( FT_Error )
FTL_Copy_FeaturesRequest ( FTL_FeaturesRequest from,
FTL_FeaturesRequest to );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Reset_FeaturesRequest */
/* */
/* <Description> */
/* Resets the settings of a features request. In other word set a */
/* features request to default settings. */
/* */
/* <Input> */
/* request :: A features request to be reseted. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT( FT_Error )
FTL_Reset_FeaturesRequest ( FTL_FeaturesRequest request );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Get_FeaturesRequest_Direction */
/* */
/* <Description> */
/* Returns the writing direction in a features request. */
/* */
/* <Input> */
/* request :: A features request. */
/* */
/* <Return> */
/* The writing direction. */
/* */
FT_EXPORT ( FTL_Direction )
FTL_Get_FeaturesRequest_Direction ( FTL_FeaturesRequest request );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Set_FeaturesRequest_Direction */
/* */
/* <Description> */
/* Sets the writing direction to a features request. */
/* */
/* <Input> */
/* request :: A features request. */
/* */
/* direction :: Writing direction. */
/* */
FT_EXPORT ( void )
FTL_Set_FeaturesRequest_Direction ( FTL_FeaturesRequest request,
FTL_Direction direction);
/*************************************************************************/
/* */
/* <Function> */
/* FTL_New_Glyphs_Array */
/* */
/* <Description> */
/* Creates an empty glyphs array. */
/* */
/* <Input> */
/* momory :: A memory object from which a glyphs array is allocated. */
/* */
/* <Output> */
/* garray :: A glyphs array. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* The lengoth of newly allocated glyphs array is 0. Set the length */
/* by @FTL_Set_Glyphs_Array_Length after allocating if you need. */
/* */
FT_EXPORT( FT_Error )
FTL_New_Glyphs_Array ( FT_Memory memory,
FTL_Glyphs_Array * garray );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Set_Glyphs_Array_Length */
/* */
/* <Description> */
/* Sets the length of a glyphs array. */
/* */
/* <Input> */
/* length :: New glyphs array length. */
/* */
/* <InOut> */
/* garray :: A glyphs array. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT( FT_Error )
FTL_Set_Glyphs_Array_Length ( FTL_Glyphs_Array garray,
FT_ULong new_length );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Copy_Glyphs_Array */
/* */
/* <Description> */
/* Copies glyphs array. */
/* */
/* <Input> */
/* in :: The source glyphs array. */
/* */
/* <Output> */
/* out :: The destination glyphs array. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT( FT_Error )
FTL_Copy_Glyphs_Array ( FTL_Glyphs_Array in,
FTL_Glyphs_Array out );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Done_Glyphs_Array */
/* */
/* <Description> */
/* Discards a glyphs array. */
/* */
/* <Input> */
/* garray :: A glyphs array. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT( FT_Error )
FTL_Done_Glyphs_Array ( FTL_Glyphs_Array garray );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Substitute_Glyphs */
/* */
/* <Description> */
/* Substitutes glyphs based on the rule specified by the current */
/* activated features request. */
/* */
/* <Input> */
/* face :: A face which has substitution tables. */
/* */
/* in :: Input glyphs array. */
/* */
/* <Output> */
/* out :: Output(substituted) glyphs array. The length of glyphs */
/* are automatically extended. */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT( FT_Error )
FTL_Substitute_Glyphs ( FT_Face face,
FTL_Glyphs_Array in,
FTL_Glyphs_Array out );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Get_LigatureCaret_Count */
/* */
/* <Description> */
/* Returns the number of ligature divisions for a given glyph. */
/* */
/* <Input> */
/* face :: A face. */
/* */
/* glyphID :: The target glyph's id. */
/* */
/* <Return> */
/* The number of ligature divisions. If the glyph is not ligatured */
/* glyph, returns 0. */
/* */
FT_EXPORT( FT_UShort )
FTL_Get_LigatureCaret_Count ( FT_Face face, FT_UShort glyphID );
/*************************************************************************/
/* */
/* <Function> */
/* FTL_Get_LigatureCaret_Division */
/* */
/* <Description> */
/* Returns the point of Nth ligature divisions for a given glyph. */
/* */
/* <Input> */
/* face :: A face. */
/* */
/* glyphID :: The target glyph's id. */
/* */
/* nth :: The index of ligature divisions. */
/* */
/* <Return> */
/* The point of a ligature division. If the glyph is not ligatured */
/* glyph, returns 0. */
/* */
FT_EXPORT( FT_UShort )
FTL_Get_LigatureCaret_Division ( FT_Face face,
FT_UShort glyphID,
FT_UShort nth );
FT_END_HEADER
#endif /* Not def: __FTL_LAYOUT_H_ */
/* END */

View File

@ -122,6 +122,8 @@
FT_MODERRDEF( Type1, 0x1100, "Type 1 module" )
FT_MODERRDEF( Type42, 0x1200, "Type 42 module" )
FT_MODERRDEF( Winfonts, 0x1300, "Windows FON/FNT module" )
FT_MODERRDEF( GX, 0x1400, "AAT/TrueTypeGX module" )
FT_MODERRDEF( OT, 0x1500, "OpenType module" )
#ifdef FT_MODERR_END_LIST

363
include/freetype/gxlayout.h Normal file
View File

@ -0,0 +1,363 @@
/***************************************************************************/
/* */
/* gxlayout.h */
/* */
/* AAT/TrueTypeGX based layout engine(specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXLAYOUT_H__
#define __GXLAYOUT_H__
#include <ft2build.h>
#include FT_SFNT_NAMES_H
FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <Section> */
/* gx_text_layout */
/* */
/* <Title> */
/* GX Text Layout */
/* */
/* <Abstract> */
/* TrueTypeGX/AAT text layout types and functions. */
/* */
/* <Description> */
/* The following types and functions(interface) are used in text */
/* layout with TrueTypeGX/AAT font. You have to use combination with */
/* this GXLayout interface and generic FTLayout interface. */
/* You have to use GXLayout interface to get the font features */
/* defined in `feat' table; and specify settings to the features */
/* request created by @FTL_New_FeaturesRequest. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Type> */
/* GXL_FeaturesRequest */
/* */
/* <Description> */
/* GXLayout level representation of FTL_FeaturesRequest. */
/* */
/* GXLayout functions dealing in features requests requires */
/* arguments typed to GXL_FeaturesRequest instead of */
/* FTL_FeaturesRequest. */
/* */
typedef struct GXL_FeaturesRequestRec_ *GXL_FeaturesRequest;
/*************************************************************************/
/* */
/* <Type> */
/* GXL_Feature */
/* */
/* <Description> */
/* An opaque data type representing a feature of TrueTypeGX/AAT font. */
/* */
/* @GXL_FeaturesRequest_Get_Feature_Count returns the number of */
/* in a font. @GXL_FeaturesRequest_Get_Feature returns Nth feature */
/* object in a font. */
/* */
typedef struct GXL_FeatureRec_ *GXL_Feature;
/*************************************************************************/
/* */
/* <Type> */
/* GXL_Setting */
/* */
/* <Description> */
/* An opaque data type representing a setting of a feature. */
/* */
/* @GXL_Feature_Get_Setting_Count returns the number of settings in a */
/* feature. @GXL_Feature_Get_Setting returns Nth setting in a */
/* feature. */
/* */
typedef struct GXL_SettingRec_ *GXL_Setting;
/*************************************************************************/
/* */
/* <Enum> */
/* GXL_Initial_State */
/* */
/* <Description> */
/* An enumeration for the initial state of GX glyph substitution */
/* automaton. */
/* */
/* You can set/get these value to/from a features request by */
/* @GXL_FeaturesRequest_Set_Initial_State and */
/* @GXL_FeaturesRequest_Set_Initial_State. */
/* */
/* <Values> */
/* GXL_START_OF_TEXT_STATE :: */
/* State of text start. */
/* */
/* GXL_START_OF_LINE_STATE :: */
/* State of line start. */
/* */
typedef enum
{
GXL_START_OF_TEXT_STATE = 0,
GXL_START_OF_LINE_STATE = 1
} GXL_Initial_State;
/*************************************************************************/
/* */
/* <Function> */
/* GXL_FeaturesRequest_Set_Initial_State */
/* */
/* <Description> */
/* Sets a initial state for glyph the initial state of GX glyph */
/* substitution automaton to a features request. */
/* */
/* <Input> */
/* request :: a Target features request. */
/* */
/* initial_state :: The initial state. */
/* */
FT_EXPORT ( void )
GXL_FeaturesRequest_Set_Initial_State ( GXL_FeaturesRequest request,
GXL_Initial_State initial_state );
/*************************************************************************/
/* */
/* <Function> */
/* GXL_FeaturesRequest_Get_Initial_State */
/* */
/* <Description> */
/* Returns a initial state for glyph the initial state of GX glyph */
/* substitution automaton in a features request. */
/* */
/* <Input> */
/* request :: A target features request. */
/* */
/* <Return> */
/* An initial state value typed to @GXL_Initial_State. */
/* */
FT_EXPORT ( GXL_Initial_State )
GXL_FeaturesRequest_Get_Initial_State ( GXL_FeaturesRequest request );
/*************************************************************************/
/* */
/* <Function> */
/* GXL_FeaturesRequest_Get_Feature_Count */
/* */
/* <Description> */
/* Returns the number of features in a features request. */
/* */
/* <Input> */
/* request :: A target features request. */
/* */
/* <Return> */
/* The number of features. */
/* */
FT_EXPORT ( FT_ULong )
GXL_FeaturesRequest_Get_Feature_Count ( GXL_FeaturesRequest request );
/*************************************************************************/
/* */
/* <Function> */
/* GXL_FeaturesRequest_Get_Feature */
/* */
/* <Description> */
/* Returns Nth font feature object from a features request. */
/* */
/* <Input> */
/* request :: A target features request. */
/* */
/* index :: The index of feature. */
/* */
/* <Return> */
/* A feature object. */
/* */
/* <Note> */
/* Use @GXL_FeaturesRequest_Get_Feature_Count to get the number of */
/* available features. */
/* */
FT_EXPORT ( GXL_Feature )
GXL_FeaturesRequest_Get_Feature ( GXL_FeaturesRequest request,
FT_ULong index);
/*************************************************************************/
/* */
/* <Function> */
/* GXL_Feature_Get_Name */
/* */
/* <Description> */
/* Gets the name for a feature. */
/* */
/* <Input> */
/* feature :: A target feature. */
/* */
/* platform_id :: Platform ID for the name. 0 is wild-card. */
/* */
/* encoding_id :: Encoding ID for the name. 0 is wild-card. */
/* */
/* language_id :: Language ID for the name. 0 is wild-card. */
/* */
/* <Output> */
/* aname :: The name of a setting. The memory area must be */
/* allocated by the client. The pointer to a object */
/* on a stack is ok. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT( FT_Error )
GXL_Feature_Get_Name ( GXL_Feature feature ,
FT_UShort platform_id,
FT_UShort pencoding_id,
FT_UShort language_id,
FT_SfntName *aname );
/*************************************************************************/
/* */
/* <Function> */
/* GXL_Feature_Get_Setting_Count */
/* */
/* <Description> */
/* Returns the number of settings in a feature */
/* */
/* <Input> */
/* request :: A target feature. */
/* */
/* <Return> */
/* The number of settings. */
/* */
FT_EXPORT( FT_UShort )
GXL_Feature_Get_Setting_Count ( GXL_Feature feature );
/*************************************************************************/
/* */
/* <Function> */
/* GXL_Feature_Get_Setting */
/* */
/* <Description> */
/* Returns Nth setting object from a feature. */
/* */
/* <Input> */
/* feature :: A target feature. */
/* */
/* index :: The index of setting. */
/* */
/* <Return> */
/* A setting object. */
/* */
/* <Note> */
/* Use @GXL_Feature_Get_Setting_Count to get the number of available */
/* settings. */
/* */
FT_EXPORT( GXL_Setting )
GXL_Feature_Get_Setting ( GXL_Feature feature,
FT_ULong index );
/*************************************************************************/
/* */
/* <Function> */
/* GXL_Feature_Is_Setting_Exclusive */
/* */
/* <Description> */
/* Returns whether a feature's setting is exclusive or not. */
/* */
/* <Input> */
/* feature :: A target feature. */
/* */
/* <Return> */
/* True if a feature's setting is exclusive. False if not. */
/* */
FT_EXPORT( FT_Bool )
GXL_Feature_Is_Setting_Exclusive ( GXL_Feature feature );
/*************************************************************************/
/* */
/* <Function> */
/* GXL_Setting_Get_Name */
/* */
/* <Description> */
/* Gets the name for a setting. */
/* */
/* <Input> */
/* setting :: A target setting. */
/* */
/* platform_id :: Platform ID for the name. 0 is wild-card. */
/* */
/* encoding_id :: Encoding ID for the name. 0 is wild-card. */
/* */
/* language_id :: Language ID for the name. 0 is wild-card. */
/* */
/* <Output> */
/* aname :: The name of a setting. The memory area must be */
/* allocated by the client. The pointer to a object */
/* on a stack is ok. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT( FT_Error )
GXL_Setting_Get_Name ( GXL_Setting setting,
FT_UShort platform_id,
FT_UShort encoding_id,
FT_UShort language_id,
FT_SfntName *aname );
/*************************************************************************/
/* */
/* <Function> */
/* GXL_Setting_Get_State */
/* */
/* <Description> */
/* Returns whether a setting is enabled or disabled. */
/* */
/* <Input> */
/* setting :: A target setting. */
/* */
/* <Return> */
/* True if a setting is enabled. False if disabled. */
/* */
FT_EXPORT( FT_Bool )
GXL_Setting_Get_State ( GXL_Setting setting );
/*************************************************************************/
/* */
/* <Function> */
/* GXL_Setting_Set_State */
/* */
/* <Description> */
/* Make a setting enable or disable. */
/* */
/* <Input> */
/* setting :: A target setting. */
/* */
/* state :: A state to set. If this is true, the setting is */
/* enabled. If this is false, the setting is disabled. */
/* */
FT_EXPORT( void )
GXL_Setting_Set_State ( GXL_Setting setting,
FT_Bool state );
FT_END_HEADER
#endif /* Not def: __GXLAYOUT_H__ */

View File

@ -0,0 +1,85 @@
/***************************************************************************/
/* */
/* ftltypes.h */
/* */
/* Types used in the layout engine stacked on ft2 (specification) */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __FTL_TYPES_H__
#define __FTL_TYPES_H__
#include <ft2build.h>
#include FT_LAYOUT_H
FT_BEGIN_HEADER
#define FTL_FONT( x ) ((FTL_Font)(x))
#define FTL_FONT_FACE( x ) (FTL_FONT( x )->face)
#define FTL_FEATURES_REQUEST( x ) ((FTL_FeaturesRequest)( x ))
#define FTL_FEATURES_REQUEST_FONT( x )(FTL_FEATURES_REQUEST( x )->font)
typedef struct FTL_FontRec_ * FTL_Font;
typedef struct FTL_FeaturesRequestRec_
{
FTL_Font font;
FTL_Direction direction;
} FTL_FeaturesRequestRec;
typedef struct FTL_FontRec_
{
FT_Face face;
/* This one is used as active features request. */
FTL_FeaturesRequest features_request;
FT_ListRec features_requests_list;
} FTL_FontRec;
FT_EXPORT( FT_Error )
FTL_Font_Init ( FTL_Font font,
FT_Face face );
FT_EXPORT( FT_Error )
FTL_Font_Finalize ( FTL_Font font );
FT_EXPORT( FT_Error )
FTL_FeaturesRequest_Init ( FT_Face face,
FTL_FeaturesRequest request);
FT_EXPORT( FT_Error )
FTL_FeaturesRequest_Finalize ( FTL_FeaturesRequest request );
FT_EXPORT_DEF( FT_Error )
FTL_FeaturesRequest_Copy ( FTL_FeaturesRequest from,
FTL_FeaturesRequest to );
FT_EXPORT( FT_Error )
FTL_Font_Get_Default_FeaturesRequest ( FTL_Font font,
FTL_FeaturesRequest * request );
FT_EXPORT( FT_Error )
FTL_Font_Get_Current_FeaturesRequest ( FTL_Font font,
FTL_FeaturesRequest * request );
FT_EXPORT( FT_Error )
FTL_Get_Font ( FT_Face face,
FTL_Font * font );
FT_END_HEADER
#endif /* Not def: __FTL_TYPES_H__ */
/* END */

View File

@ -167,7 +167,7 @@ FT_BEGIN_HEADER
FT_Pointer service_GLYPH_DICT;
FT_Pointer service_PFR_METRICS;
FT_Pointer service_WINFNT;
FT_Pointer service_LAYOUT;
} FT_ServiceCacheRec, *FT_ServiceCache;
@ -248,6 +248,7 @@ FT_BEGIN_HEADER
#define FT_SERVICE_SFNT_H <freetype/internal/services/svsfnt.h>
#define FT_SERVICE_PFR_H <freetype/internal/services/svpfr.h>
#define FT_SERVICE_WINFNT_H <freetype/internal/services/svwinfnt.h>
#define FT_SERVICE_LAYOUT_H <freetype/internal/services/svlayout.h>
#define FT_SERVICE_TT_CMAP_H <freetype/internal/services/svttcmap.h>
/* */

View File

@ -103,5 +103,16 @@ FT_TRACE_DEF( bdflib )
/* PFR fonts component */
FT_TRACE_DEF( pfr )
/* GX driver component */
FT_TRACE_DEF( gxdriver )
FT_TRACE_DEF( gxobjs )
FT_TRACE_DEF( gxlayout )
FT_TRACE_DEF( gxload )
FT_TRACE_DEF( gxchain )
FT_TRACE_DEF( gxvm )
/* OT driver component */
FT_TRACE_DEF( otdriver )
FT_TRACE_DEF( otobjs )
/* END */

View File

@ -45,5 +45,7 @@
#define FT_INTERNAL_AUTOHINT_H <freetype/internal/autohint.h>
#define FT_INTERNAL_FTL_TYPES_H <freetype/internal/ftltypes.h>
/* END */

View File

@ -0,0 +1,84 @@
/***************************************************************************/
/* */
/* svlayout.h */
/* */
/* The FreeType Layout services (specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __SVLAYOUT_H__
#define __SVLAYOUT_H__
#include FT_INTERNAL_SERVICE_H
#include FT_LAYOUT_H
#include FT_INTERNAL_FTL_TYPES_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_LAYOUT "layout"
typedef FT_Error
(*FTL_Get_Font_Func)( FT_Face face,
FTL_Font* font );
typedef FTL_EngineType
(*FTL_Get_EngineType_Func) ( FT_Face face );
typedef FT_Error
(*FTL_New_FeaturesRequest_Func)( FT_Face face,
FTL_FeaturesRequest* request );
typedef FT_Error
(*FTL_Done_FeaturesRequest_Func)( FTL_FeaturesRequest request );
typedef FT_Error
(*FTL_Copy_FeaturesRequest_Func)( FTL_FeaturesRequest from,
FTL_FeaturesRequest to );
typedef FT_UShort
(*FTL_Get_LigatureCaret_Count_Func) ( FT_Face face, FT_UShort glyphID );
typedef FT_UShort
(*FTL_Get_LigatureCaret_Division_Func) ( FT_Face face,
FT_UShort glyphID,
FT_UShort nth );
typedef FT_Error
(*FTL_Substitute_Glyphs_Func) ( FT_Face face,
FTL_FeaturesRequest request,
FTL_Glyphs_Array in,
FTL_Glyphs_Array out );
FT_DEFINE_SERVICE( Layout )
{
FTL_Get_Font_Func get_font;
FTL_Get_EngineType_Func get_engine_type;
FTL_New_FeaturesRequest_Func new_features_request;
FTL_Done_FeaturesRequest_Func done_features_request;
FTL_Copy_FeaturesRequest_Func copy_features_request;
FTL_Get_LigatureCaret_Count_Func get_ligature_caret_count;
FTL_Get_LigatureCaret_Division_Func get_ligature_caret_division;
FTL_Substitute_Glyphs_Func substitute_glyphs;
};
/* */
FT_END_HEADER
#endif /* __SVLAYOUT_H__ */
/* END */

View File

@ -18,8 +18,10 @@
/* */
/***************************************************************************/
/* Development of this service is support of
Information-technology Promotion Agency, Japan. */
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __SVTTCMAP_H__
#define __SVTTCMAP_H__

View File

@ -0,0 +1,79 @@
/***************************************************************************/
/* */
/* otlayout.h */
/* */
/* OpenType based layout engine */
/* (For application developers, specification only). */
/* */
/***************************************************************************/
#ifndef __OTLAYOUT_H__
#define __OTLAYOUT_H__
#include <ft2build.h>
#include FT_FREETYPE_H
FT_BEGIN_HEADER
typedef FT_ULong OTTag;
typedef enum {
OT_TABLE_GSUB,
OT_TABLE_GPOS
} OTTableType;
typedef struct OTL_FeaturesRequestRec_ *OTL_FeaturesRequest;
typedef struct OTL_Tag_ListRec_
{
OTL_FeaturesRequest request;
OTTag * tags; /* 0 is terminator. */
} OTL_Tag_ListRec, *OTL_Tag_List;
FT_EXPORT( FT_Bool )
OTL_FeaturesRequest_Find_Script ( OTL_FeaturesRequest request,
OTTableType table_type,
OTTag script_tag,
FT_UInt *script_index);
FT_EXPORT( FT_Bool )
OTL_FeaturesRequest_Find_Language ( OTL_FeaturesRequest request,
OTTableType table_type,
FT_UInt script_index,
OTTag language_tag,
FT_UInt *language_index,
FT_UInt *required_feature_index );
FT_EXPORT ( FT_Bool )
OTL_FeaturesRequest_Find_Feature ( OTL_FeaturesRequest request,
OTTableType table_type,
OTTag feature_tag,
FT_UInt script_index,
FT_UInt language_index,
FT_UInt *feature_index );
FT_EXPORT ( OTL_Tag_List )
OTL_FeaturesRequest_List_Scripts ( OTL_FeaturesRequest request,
OTTableType table_type );
FT_EXPORT ( OTL_Tag_List )
OTL_FeaturesRequest_List_Languages ( OTL_FeaturesRequest request,
OTTableType table_type,
FT_UInt script_index );
FT_EXPORT ( OTL_Tag_List )
OTL_FeaturesRequest_List_Features ( OTL_FeaturesRequest request,
OTTableType table_type,
FT_UInt script_index,
FT_UInt language_index );
FT_EXPORT ( FT_Error )
OTL_Tag_List_Done ( OTL_Tag_List taglist );
FT_EXPORT ( FT_Error )
OTL_FeaturesRequest_Add_Feature ( OTL_FeaturesRequest request,
OTTableType table_type,
FT_UInt feature_index,
FT_ULong property_bit);
FT_END_HEADER
#endif /* Not def: __OTLAYOUT_H__ */

View File

@ -71,6 +71,27 @@ FT_BEGIN_HEADER
#define TTAG_vhea FT_MAKE_TAG( 'v', 'h', 'e', 'a' )
#define TTAG_vmtx FT_MAKE_TAG( 'v', 'm', 't', 'x' )
#define TTAG_trak FT_MAKE_TAG( 't', 'r', 'a', 'k' )
#define TTAG_feat FT_MAKE_TAG( 'f', 'e', 'a', 't' )
#define TTAG_prop FT_MAKE_TAG( 'p', 'r', 'o', 'p' )
#define TTAG_lcar FT_MAKE_TAG( 'l', 'c', 'a', 'r' )
#define TTAG_opbd FT_MAKE_TAG( 'o', 'p', 'b', 'd' )
#define TTAG_bsln FT_MAKE_TAG( 'b', 's', 'l', 'n' )
#define TTAG_mort FT_MAKE_TAG( 'm', 'o', 'r', 't' )
#define TTAG_morx FT_MAKE_TAG( 'm', 'o', 'r', 'x' )
#define TTAG_fmtx FT_MAKE_TAG( 'f', 'm', 't', 'x' )
#define TTAG_fdsc FT_MAKE_TAG( 'f', 'd', 's', 'c' )
#define TTAG_wght FT_MAKE_TAG( 'w', 'g', 'h', 't' )
#define TTAG_wdth FT_MAKE_TAG( 'w', 'd', 't', 'h' )
#define TTAG_slnt FT_MAKE_TAG( 's', 'l', 'n', 't' )
#define TTAG_opsz FT_MAKE_TAG( 'o', 'p', 's', 'z' )
#define TTAG_nalf FT_MAKE_TAG( 'n', 'a', 'l', 'f' )
#define TTAG_just FT_MAKE_TAG( 'j', 'u', 's', 't' )
#define TTAG_cvar FT_MAKE_TAG( 'c', 'v', 'a', 'r' )
#define TTAG_gvar FT_MAKE_TAG( 'g', 'v', 'a', 'r' )
FT_END_HEADER

View File

@ -24,7 +24,7 @@ SubDir FT2_TOP $(FT2_SRC_DIR) base ;
#
Library $(FT2_LIB) : ftsystem.c ftinit.c ftglyph.c ftmm.c ftbdf.c
ftbbox.c ftdebug.c ftxf86.c fttype1.c ftpfr.c
ftstroke.c ftwinfnt.c ;
ftstroke.c ftwinfnt.c ftlayout.c ;
# Add Macintosh-specific file to the library when necessary.
#

496
src/base/ftlayout.c Normal file
View File

@ -0,0 +1,496 @@
/***************************************************************************/
/* */
/* ftltypes.h */
/* */
/* Implementation of FreeType Layout API (body) */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include FT_LAYOUT_H
#include FT_INTERNAL_FTL_TYPES_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_LAYOUT_H
#include FT_LIST_H
static void
destroy_feaatures_requests ( FT_Memory memory,
void * data,
void * user );
static FT_Error
ft_face_get_layout_service( FT_Face face,
FT_Service_Layout *aservice )
{
FT_Error error;
*aservice = NULL;
if ( !face )
return FT_Err_Invalid_Face_Handle;
error = FT_Err_Invalid_Argument;
FT_FACE_LOOKUP_SERVICE( face,
*aservice,
LAYOUT );
if ( *aservice )
error = FT_Err_Ok;
return error;
}
FT_EXPORT_DEF( FT_Error )
FTL_Get_Font ( FT_Face face,
FTL_Font * font )
{
FT_Error error;
FT_Service_Layout service;
if (( error = ft_face_get_layout_service( face, &service ) ))
return error;
error = FT_Err_Invalid_Argument;
if ( service->get_font )
error = service->get_font ( face, font );
return error;
}
FT_EXPORT_DEF( FT_Error )
FTL_Query_EngineType ( FT_Face face,
FTL_EngineType * engine_type)
{
FT_Error error;
FT_Service_Layout service;
if ( !face )
return FT_Err_Invalid_Argument;
if (( error = ft_face_get_layout_service( face, &service ) ))
return error;
error = FT_Err_Invalid_Argument;
if ( service->get_engine_type )
{
error = FT_Err_Ok;
*engine_type = service->get_engine_type( face );
}
return error;
}
FT_EXPORT_DEF( FT_Error )
FTL_New_FeaturesRequest ( FT_Face face,
FTL_FeaturesRequest* request)
{
FT_Error error;
FT_Service_Layout service;
FTL_FeaturesRequest arequest = NULL;
FT_ListNode node = NULL;
FT_Memory memory;
FTL_Font font;
memory = face->driver->root.memory;
if ( FT_NEW( node ) )
goto Exit;
if (( error = ft_face_get_layout_service( face, &service ) ))
goto Exit;
if ( service->get_font )
{
if (( error = service->get_font( face, &font ) ))
goto Failure;
}
if ( service->new_features_request )
{
if (( error = service->new_features_request( face, &arequest ) ))
goto Failure;
}
else
{
if ( FT_NEW( arequest ) )
goto Exit;
if (( error = FTL_FeaturesRequest_Init ( face, arequest ) ))
{
FT_FREE( arequest );
goto Failure;
}
}
*request = arequest;
node->data = arequest;
FT_List_Add( &font->features_requests_list, node );
if ( !font->features_request )
font->features_request = arequest;
error = FT_Err_Ok;
Exit:
return error;
Failure:
if ( arequest )
FT_FREE ( arequest );
if ( node )
FT_FREE( node );
return error;
}
FT_EXPORT_DEF( FT_Error )
FTL_FeaturesRequest_Init ( FT_Face face,
FTL_FeaturesRequest request)
{
FT_Error error;
FTL_Font font;
if ( ( error = FTL_Get_Font( face, &font ) ) )
return error;
request->font = font;
request->direction = FTL_HORIZONTAL;
return error;
}
FT_EXPORT_DEF( FT_Error )
FTL_Done_FeaturesRequest ( FTL_FeaturesRequest request )
{
FT_Error error;
FTL_Font font;
FT_Face face;
FT_Memory memory;
FT_ListNode node;
FT_Service_Layout service;
font = request->font;
FT_ASSERT(font);
face = font->face;
FT_ASSERT(face);
memory = face->driver->root.memory;
if (( error = ft_face_get_layout_service( face, &service ) ))
return error;
node = FT_List_Find( &font->features_requests_list, request );
FT_ASSERT(node);
FT_List_Remove ( &font->features_requests_list, node );
FT_FREE( node );
if ( font->features_request == request )
{
font->features_request = NULL;
if ( font->features_requests_list.head )
font->features_request = (FTL_FeaturesRequest)(font->features_requests_list.head->data);
}
if ( service->done_features_request )
error = service->done_features_request( request );
else
{
error = FTL_FeaturesRequest_Finalize( request );
FT_FREE( request ); /* TODO */
}
return error;
}
FT_EXPORT_DEF( FT_Error )
FTL_FeaturesRequest_Finalize ( FTL_FeaturesRequest request )
{
return FT_Err_Ok;
}
FT_EXPORT_DEF ( FTL_Direction )
FTL_Get_FeaturesRequest_Direction ( FTL_FeaturesRequest request )
{
FT_ASSERT( request );
return request->direction;
}
FT_EXPORT_DEF ( void )
FTL_Set_FeaturesRequest_Direction ( FTL_FeaturesRequest request,
FTL_Direction direction)
{
FT_ASSERT( request );
request->direction = direction;
}
FT_EXPORT_DEF ( FT_Error )
FTL_Activate_FeaturesRequest ( FTL_FeaturesRequest request )
{
FTL_Font font;
if ( !request )
return FT_Err_Invalid_Argument;
font = request->font;
if ( !font )
return FT_Err_Invalid_Argument;
font->features_request = request;
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FTL_Copy_FeaturesRequest ( FTL_FeaturesRequest from, FTL_FeaturesRequest to )
{
FT_Error error;
FT_Service_Layout service;
if ( from->font != to->font )
return FT_Err_Invalid_Argument;
if ( from == to )
return FT_Err_Ok;
FT_ASSERT(from->font->face);
if (( error = ft_face_get_layout_service( from->font->face, &service ) ))
return error;
if ( service->copy_features_request )
error = service->copy_features_request( from, to );
else
error = FTL_FeaturesRequest_Copy ( from, to );
return error;
}
FT_EXPORT_DEF( FT_Error )
FTL_FeaturesRequest_Copy ( FTL_FeaturesRequest from, FTL_FeaturesRequest to )
{
FTL_Set_FeaturesRequest_Direction(to,
FTL_Get_FeaturesRequest_Direction(to));
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FTL_Reset_FeaturesRequest ( FTL_FeaturesRequest request )
{
FTL_Font font;
FTL_FeaturesRequest default_request;
if ( !request )
return FT_Err_Invalid_Argument;
font = request->font;
FT_ASSERT( font );
FTL_Font_Get_Default_FeaturesRequest( font, &default_request );
return FTL_Copy_FeaturesRequest( (FTL_FeaturesRequest)default_request,
(FTL_FeaturesRequest)request );
}
FT_EXPORT_DEF( FT_Error )
FTL_Font_Init ( FTL_Font font,
FT_Face face )
{
if ( (!font) || (!face) )
return FT_Err_Invalid_Argument;
font->face = face;
font->features_request = NULL;
font->features_requests_list.head = NULL;
font->features_requests_list.tail = NULL;
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FTL_Font_Finalize ( FTL_Font font )
{
FT_Face face = font->face;
FT_Memory memory = face->driver->root.memory;
if ( !font )
return FT_Err_Invalid_Argument;
FT_List_Finalize( &font->features_requests_list,
(FT_List_Destructor)destroy_feaatures_requests,
memory,
NULL );
font->features_requests_list.head = NULL;
font->features_requests_list.tail = NULL;
font->features_request = NULL;
font->face = NULL;
return FT_Err_Ok;
}
static void
destroy_feaatures_requests ( FT_Memory memory,
void * data,
void * user )
{
FTL_Font font;
FT_Face face;
FTL_FeaturesRequest request = data;
FT_Service_Layout service = NULL;
FT_UNUSED(user);
font = request->font;
FT_ASSERT(font);
face = font->face;
FT_ASSERT(face);
ft_face_get_layout_service( face, &service );
if ( service && service->done_features_request )
service->done_features_request( request );
else
{
FTL_FeaturesRequest_Finalize( request );
FT_FREE( request );
}
}
FT_EXPORT_DEF( FT_Error )
FTL_Font_Get_Default_FeaturesRequest ( FTL_Font font,
FTL_FeaturesRequest * request )
{
FT_ListNode node;
if ( !font )
return FT_Err_Invalid_Argument;
node = font->features_requests_list.head;
*request = node->data;
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FTL_Font_Get_Current_FeaturesRequest ( FTL_Font font,
FTL_FeaturesRequest * request )
{
*request = font->features_request;
FT_ASSERT ( *request );
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_UShort )
FTL_Get_LigatureCaret_Count ( FT_Face face, FT_UShort glyphID )
{
FT_Error error;
FT_Service_Layout service;
if (( error = ft_face_get_layout_service( face, &service ) ))
return 0;
if ( service->get_ligature_caret_count )
return service->get_ligature_caret_count( face, glyphID );
else
return 0;
}
FT_EXPORT_DEF( FT_UShort )
FTL_Get_LigatureCaret_Division ( FT_Face face,
FT_UShort glyphID,
FT_UShort nth )
{
FT_Error error;
FT_Service_Layout service;
if (( error = ft_face_get_layout_service( face, &service ) ))
return 0;
if ( service->get_ligature_caret_division )
return service->get_ligature_caret_division( face, glyphID, nth );
else
return 0;
}
FT_EXPORT_DEF( FT_Error )
FTL_New_Glyphs_Array ( FT_Memory memory,
FTL_Glyphs_Array * garray )
{
FT_Error error;
FTL_Glyphs_Array agarray;
if ( FT_NEW( agarray ) )
return error;
agarray->memory = memory;
agarray->glyphs = NULL;
agarray->length = 0;
agarray->allocated = 0;
*garray = agarray;
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FTL_Set_Glyphs_Array_Length ( FTL_Glyphs_Array garray,
FT_ULong new_length )
{
FT_Error error;
FT_Memory memory = garray->memory;
if ( new_length > garray->allocated )
{
if ( FT_RENEW_ARRAY( garray->glyphs, garray->allocated, new_length ) )
return error;
garray->allocated = new_length;
garray->length = new_length;
}
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FTL_Copy_Glyphs_Array ( FTL_Glyphs_Array in,
FTL_Glyphs_Array out )
{
FT_Error error;
FT_ULong i;
if (( error = FTL_Set_Glyphs_Array_Length( out, in->length ) ))
return error;
for ( i = 0; i < in->length; i++ )
out->glyphs[i] = in->glyphs[i];
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FTL_Done_Glyphs_Array ( FTL_Glyphs_Array garray )
{
FT_Memory memory = garray->memory;
FT_FREE( garray->glyphs );
FT_FREE( garray );
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FTL_Substitute_Glyphs ( FT_Face face,
FTL_Glyphs_Array in,
FTL_Glyphs_Array out )
{
FT_Error error;
FT_Service_Layout service;
FTL_Font font;
FTL_FeaturesRequest request;
if (( error = ft_face_get_layout_service( face, &service ) ))
return error;
if ( ( error = FTL_Get_Font ( face, &font ) ) )
return error;
if ( ( error = FTL_Font_Get_Current_FeaturesRequest ( font,
&request ) ) )
return error;
if ( service->substitute_glyphs )
return service->substitute_glyphs( face, request, in, out );
else
return FTL_Copy_Glyphs_Array(in, out);
}
/* END */

View File

@ -58,7 +58,8 @@ BASE_EXT_SRC := $(BASE_DIR)/ftbbox.c \
$(BASE_DIR)/ftstroke.c \
$(BASE_DIR)/fttype1.c \
$(BASE_DIR)/ftwinfnt.c \
$(BASE_DIR)/ftxf86.c
$(BASE_DIR)/ftxf86.c \
$(BASE_DIR)/ftlayout.c
# Default extensions objects
#

23
src/gxlayout/Jamfile Normal file
View File

@ -0,0 +1,23 @@
# Copyied from src/gx.
##
## FreeType 2 src/gx Jamfile (c) 2003 RedHat K.K.
##
SubDir FT2_TOP $(FT2_SRC_DIR) gxlayout ;
{
local _sources ;
if $(FT2_MULTI)
{
_sources = gxdriver gxload gxobjs gxlayout gxaccess gxfeatreg gxlfeatreg gxstatetbl gxlookuptbl gxvm gxutils
}
else
{
_sources = gx ;
}
Library $(FT2_LIB) : $(_sources).c ;
}
# end of src/gx Jamfile

70
src/gxlayout/demo.mk Normal file
View File

@ -0,0 +1,70 @@
#
# demo.mk --- Makefile for GX driver demo program
#
# Copyright 2004 by Masatake YAMATO and RedHat K.K.
#
# 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.
#
########################################################################
# Development of the code in demo.mk is support of
# Information-technology Promotion Agency, Japan.
SHELL=/bin/bash
GLIB_CFLAGS=`pkg-config --cflags glib-2.0 gobject-2.0`
GLIB_LIBS=`pkg-config --libs glib-2.0 gobject-2.0`
GTK_CFLAGS=`pkg-config --cflags gtk+-2.0`
GTK_LIBS=`pkg-config --libs gtk+-2.0`
POPT_LIBS=-lpopt
GCANVAS_CFLAGS=`pkg-config --cflags libgnomecanvas-2.0`
GCANVAS_LDFLAGS=`pkg-config --libs libgnomecanvas-2.0`
GUI_CFLAGS=$(GTK_CFLAGS) $(GLIB_CFLAGS) $(GCANVAS_CFLAGS)
GUI_LIBS=$(GTK_LIBS) $(POPT_LIBS) $(GLIB_LIBS) $(GCANVAS_LDFLAGS)
BASE_CFLAGS=-c -O0 -g -I../../include -Wall -std=c99
BASE_LIBS=-Xlinker -rpath -Xlinker ../../objs/.libs -lz
########################################################################
GXOBJ=../../objs/.libs/libfreetype.so
DEMO=gxdemo
DEMOBIN=$(DEMO)
DEMOOBJ=$(DEMO).o
DEMOSRC=$(DEMO).c
DEMO_CFLAGS=$(BASE_CFLAGS) $(GUI_CFLAGS)
DEMO_LIBS=$(BASE_LIBS) $(GUI_LIBS)
FI=fi
FIBIN=$(FI)
FIOBJ=$(FI).o
FISRC=$(FI).c
FI_CFLAGS=$(BASE_CFLAGS)
FI_LIBS=$(BASE_LIBS)
########################################################################
all: $(DEMO) $(FI)
$(GXOBJ): *.c *.h
(cd ../../; make)
clean:
rm -f $(DEMOBIN) $(DEMOOBJ) $(FIBIN) $(FIOBJ) core.*
########################################################################
$(DEMOBIN): $(GXOBJ) $(DEMOOBJ)
$(CC) -o $(@) $(DEMO_LIBS) $^
$(DEMOOBJ): $(DEMOSRC) $(GXOBJ)
$(CC) $(DEMO_CFLAGS) $(DEMOSRC)
########################################################################
$(FIBIN): $(GXOBJ) $(FIOBJ)
$(CC) -o $(@) $(FI_LIBS) $^
$(FIOBJ): $(FISRC) $(GXOBJ)
$(CC) $(FI_CFLAGS) $(FISRC)
########################################################################

159
src/gxlayout/fi.c Normal file
View File

@ -0,0 +1,159 @@
/***************************************************************************/
/* */
/* fi.c */
/* */
/* 2 characters ligature test program for AAT/TrueTypeGX font driver. */
/* */
/* Copyright 2004 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
/* "fi" is the typical alphabet ligature. *
* "fl" is another good candidate to be tried. */
const char * target = "fi";
#include <ft2build.h>
#include FT_LAYOUT_H
#include FT_GXLAYOUT_H
#include FT_INTERNAL_OBJECTS_H /* for FT_FACE_MEMORY */
#include <stdio.h>
FT_Error try_lig(FT_Face face, char a, char b);
int
main(int argc, char ** argv)
{
FT_Error error;
int result = 0;
FT_Library library;
FT_Face face;
if ( argc != 2 )
{
fprintf(stderr, "Usage: %s fontfile\n", argv[0]);
return 1;
}
error = FT_Init_FreeType ( &library );
if ( error )
{
fprintf(stderr, "Abort: Fail to initialize FT2\n");
result = 1;
goto Fail;
}
error = FT_New_Face (library, argv[1], 0, &face);
if ( error )
{
fprintf(stderr, "Abort: Fail to open the file\n");
result = 1;
goto Fail;
}
if ( !( face->face_flags & FT_FACE_FLAG_GLYPH_SUBSTITUTION) )
{
fprintf(stderr, "Abort: No substitution table for the face\n");
result = 1;
goto Fail;
}
fprintf(stdout, "-------------------\n");
fprintf(stdout,
"File: %s\nName: %s\n",
argv[1],
((FT_Face)face)->family_name);
error = try_lig( face, target[0], target[1] );
if ( error )
{
fprintf(stderr, "Abort: Fail to substitute\n");
result = 1;
}
FT_Done_Face ( face );
Fail:
FT_Done_FreeType (library);
return result;
}
FT_Error
try_lig( FT_Face face, char c1, char c2 )
{
FT_Error error = FT_Err_Ok;
FTL_EngineType engine_type;
FTL_Glyphs_Array in, out;
FTL_FeaturesRequest request;
/* Get the engine type */
if (( error = FTL_Query_EngineType( face, &engine_type ) ))
goto Fail;
/* Ignore if the engine type is not GX. */
if ( engine_type != FTL_TRUETYPEGX_ENGINE )
{
fprintf(stderr, "Abort: Not GX font.\n");
goto Fail;
}
/* Allocate input and output glyphs arrays.
The lenght for input has already been known: 2 */
FTL_New_Glyphs_Array ( FT_FACE_MEMORY(face), &in );
FTL_New_Glyphs_Array ( FT_FACE_MEMORY(face), &out );
FTL_Set_Glyphs_Array_Length ( in, 2 );
/* Get glyph id for c1 and c2 */
in->glyphs[0].gid = FT_Get_Char_Index( face, c1 );
in->glyphs[1].gid = FT_Get_Char_Index( face, c2 );
fprintf(stdout, "[IN]%c: %u, %c: %u\n",
c1, in->glyphs[0].gid,
c2, in->glyphs[1].gid);
/* Create a features-request. */
FTL_New_FeaturesRequest ( face, &request );
/* -------------------------------------
* YOU CAN SET SOME LAYOUT SETTINGS HERE
* -------------------------------------
* In this program, just use default.
* -------------------------------------
*/
/* Activeate the features request */
FTL_Activate_FeaturesRequest( request );
/* Do substitute the glyphs */
FTL_Substitute_Glyphs( face, in, out );
/* Free the features-request */
FTL_Done_FeaturesRequest ( request );
fprintf(stdout,
"[OUT]%c: %u, %c: %u%s\n",
c1, out->glyphs[0].gid,
c2, out->glyphs[1].gid,
(out->glyphs[1].gid == 0xFFFF)? "<empty>": "");
/* Free glyphs arrays */
FTL_Done_Glyphs_Array ( in );
FTL_Done_Glyphs_Array ( out );
Fail:
return error;
}
/* END */

42
src/gxlayout/gx.c Normal file
View File

@ -0,0 +1,42 @@
/***************************************************************************/
/* */
/* gx.c */
/* */
/* FreeType AAT/TrueTypeGX driver component (body only). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
#include "gxdriver.c" /* low level driver interface */
#include "gxobjs.c" /* low level object manager */
#include "gxload.c" /* tables loader */
#include "gxlookuptbl.c"
#include "gxstatetbl.c"
#include "gxaccess.c"
#include "gxutils.c"
#include "gxfeatreg.c"
#include "gxlayout.c"
#include "gxlfeatreg.c"
#include "gxvm.c"
#include "gxdump.c" /* only for debug */
/* END */

1034
src/gxlayout/gxaccess.c Normal file

File diff suppressed because it is too large Load Diff

112
src/gxlayout/gxaccess.h Normal file
View File

@ -0,0 +1,112 @@
/***************************************************************************/
/* */
/* gxaccess.h */
/* */
/* AAT/TrueTypeGX private data accessor (specification only). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXACCESS_H__
#define __GXACCESS_H__
#include <ft2build.h>
#include FT_TYPES_H
#include "gxltypes.h"
#include "gxtypes.h"
FT_BEGIN_HEADER
/* feat */
FT_LOCAL ( FT_Bool )
gx_feat_has_feature_type ( GX_Feat feat,
FT_UShort feature_type );
/* prop */
FT_LOCAL ( FT_UShort )
gx_prop_get( GX_Prop prop,
FT_Long glyph );
/* lcar */
FT_LOCAL( GX_LigCaretClassEntry )
gx_lcar_get ( GX_Lcar lcar,
FT_UShort glyphID );
/* mort */
typedef FT_Error (* GX_Mort_Feature_Func)( GX_MetamorphosisFeatureTable feat_Subtbl,
FT_Pointer user );
FT_LOCAL( FT_Error ) gx_mort_foreach_feature ( GX_Mort mort,
GX_Mort_Feature_Func func,
FT_Pointer user );
FT_LOCAL( FT_UShort )
gx_mort_count_feat_not_in_feat ( GX_Mort mort,
GX_Feat feat );
FT_LOCAL( FT_Error )
gx_mort_substitute_glyph ( GX_Mort mort,
GXL_FeaturesRequest request,
FTL_Glyphs_Array in,
FTL_Glyphs_Array out );
/* morx */
typedef FT_Error (* GX_Morx_Feature_Func)( GX_XMetamorphosisFeatureTable feat_Subtbl,
FT_Pointer user );
FT_LOCAL( FT_Error )
gx_morx_foreach_feature ( GX_Morx morx,
GX_Morx_Feature_Func func,
FT_Pointer user );
FT_LOCAL( FT_UShort )
gx_morx_count_feat_not_in_feat ( GX_Morx morx,
GX_Feat feat );
FT_LOCAL( FT_Error )
gx_morx_substitute_glyph ( GX_Morx morx,
GXL_FeaturesRequest request,
FTL_Glyphs_Array in,
FTL_Glyphs_Array out );
/* kern */
FT_LOCAL( FT_Error ) gx_kern_get_pair_kerning ( GX_Kern kern,
FT_UShort left_glyph,
FT_UShort right_glyph,
FTL_Direction dir,
FT_Vector* kerning );
FT_LOCAL( FT_Error ) gx_kern_get_contextual_kerning( GX_Kern kern,
FTL_Glyphs_Array garray,
FTL_Direction dir,
GXL_Initial_State initial_state,
FT_Vector * kerning );
/* trak */
FT_LOCAL( FT_Error ) gx_trak_get( GX_Trak trak,
FT_Fixed track,
FT_Fixed size,
FTL_Direction dir,
FT_FWord* value );
FT_LOCAL( FT_UShort ) gx_trak_count_name_index( GX_Trak trak );
FT_LOCAL( FT_Error ) gx_trak_get_name ( GX_Trak trak,
FT_UShort index,
FT_UShort * name_index,
FTL_Direction * dir,
FT_Fixed * track );
FT_END_HEADER
#endif /* Not def: __GXACCESS_H__ */
/* END */

1217
src/gxlayout/gxdemo.c Normal file

File diff suppressed because it is too large Load Diff

101
src/gxlayout/gxdriver.c Normal file
View File

@ -0,0 +1,101 @@
/***************************************************************************/
/* */
/* gxdriver.c */
/* */
/* AAT/TrueTypeGX font driver implementation (body). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_DEBUG_H
#include "gxdriver.h"
#include "gxobjs.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_gxdriver
/*************************************************************************
* gx_driver_class is not initialized statically but dynamically.
* -----------------------------------------------------------------------
* Almost all fields should be initialized in gxobjs.c::gx_driver_init.
*************************************************************************/
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec gx_driver_class =
{
/* FT_Module_Class */
{
/* module_flags, copyied from ttdriver.c */
FT_MODULE_FONT_DRIVER |
FT_MODULE_DRIVER_SCALABLE |
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
FT_MODULE_DRIVER_HAS_HINTER,
#else
0,
#endif
/* module_size, copyied from ttdriver.c */
sizeof (GX_DriverRec),
/* module_name */
"gx",
/* module_version */
0x10000L,
/* module_requires */
0x20000L,
/* module_interface */
NULL,
/* module_init */
(FT_Module_Constructor) gx_driver_init,
/* module_done */
(FT_Module_Destructor) NULL,
/* get_interface */
(FT_Module_Requester) NULL,
},
/* now the specific driver fields */
0,
0,
0,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
/* END */

42
src/gxlayout/gxdriver.h Normal file
View File

@ -0,0 +1,42 @@
/***************************************************************************/
/* */
/* gxdriver.h */
/* */
/* High-level AAT/TrueTypeGX driver interface (specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXDRIVER_H__
#define __GXDRIVER_H__
#include <ft2build.h>
#include FT_INTERNAL_DRIVER_H
FT_BEGIN_HEADER
FT_CALLBACK_TABLE
const FT_Driver_ClassRec gx_driver_class;
FT_END_HEADER
#endif /* __GXDRIVER_H__ */
/* END */

2818
src/gxlayout/gxdump.c Normal file

File diff suppressed because it is too large Load Diff

71
src/gxlayout/gxdump.h Normal file
View File

@ -0,0 +1,71 @@
/***************************************************************************/
/* */
/* gxdump.h */
/* */
/* Debug functions for AAT/TrueTypeGX driver (specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXDUMP_H__
#define __GXDUMP_H__
#include <ft2build.h>
#include FT_GXLAYOUT_H
#include <stdio.h>
FT_BEGIN_HEADER
typedef enum {
GX_DUMP_mort = 1 << 0,
GX_DUMP_morx = 1 << 1,
GX_DUMP_feat = 1 << 2,
GX_DUMP_prop = 1 << 3,
GX_DUMP_trak = 1 << 4,
GX_DUMP_kern = 1 << 5,
GX_DUMP_just = 1 << 6,
GX_DUMP_lcar = 1 << 7,
GX_DUMP_opbd = 1 << 8,
GX_DUMP_bsln = 1 << 9,
GX_DUMP_fmtx = 1 << 10,
GX_DUMP_fdsc = 1 << 11,
GX_DUMP_fvar = 1 << 12,
GX_DUMP_ALL = 0x7FFFFFFFUL /* gcc warns if I set this to 0xFFFFFFFFUL. */
} GXDumpFlag;
FT_EXPORT( FT_Error )
gx_face_dump( FT_Face face, FT_ULong tables, const char * fname );
/* If STREAM is NULL, stderr is used as output stream. */
FT_EXPORT ( void )
gxl_features_request_dump ( GXL_FeaturesRequest request, FILE * stream );
FT_EXPORT ( void )
gx_feature_registory_dump ( FILE * stream );
FT_EXPORT ( void )
gxl_feature_dump ( GXL_Feature feature, FILE * stream );
FT_EXPORT ( void )
gxl_setting_dump ( GXL_Setting setting, FILE * stream );
FT_END_HEADER
#endif /* Not def: __GXDUMP_H__ */
/* END */

46
src/gxlayout/gxerrors.h Normal file
View File

@ -0,0 +1,46 @@
/***************************************************************************/
/* */
/* gxerrors.h */
/* */
/* AAT/TrueTypeGX error codes (specification only). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
/*************************************************************************/
/* */
/* This file is used to define the AAT/TrueTypeGX error */
/* enumeration constants. */
/* */
/*************************************************************************/
#ifndef __GXERRORS_H__
#define __GXERRORS_H__
#include FT_MODULE_ERRORS_H
#undef __FTERRORS_H__
#define FT_ERR_PREFIX GX_Err_
#define FT_ERR_BASE FT_Mod_Err_GX
#include FT_ERRORS_H
#endif /* __GXERRORS_H__ */
/* END */

456
src/gxlayout/gxfeatreg.c Normal file
View File

@ -0,0 +1,456 @@
/***************************************************************************/
/* */
/* gxfeatreg.c */
/* */
/* Database of font features pre-defined by Apple Computer, Inc. */
/* http://developer.apple.com/fonts/Registry/ */
/* (body). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include "gxfeatreg.h"
#define EMPTYFEAT {0, 0, {NULL}}
/***************************************************************************/
/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING */
/***************************************************************************/
/*
* If you add a new setting to a feature, check the number of setting
* in the feature. If the number is greater than value defined as
* FEATREG_MAX_SETTING, update the value. Nor you cannot initialize
* featreg_table.
* This program is written in C.
*/
/***************************************************************************/
/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING */
/***************************************************************************/
#define FEATREG_MAX_SETTING 12
typedef struct GX_Feature_RegistryRec_
{
const FT_String * feat_name;
FT_Bool exclusive;
FT_String *setting_name[FEATREG_MAX_SETTING];
FT_UShort feature_type; /* Initialized on the fly. Thread unsafe? */
} GX_Feature_RegistryRec;
static GX_Feature_RegistryRec featreg_table [] = {
{ /* 0 */
"All Typographic Features",
0,
{
"All Type Features",
NULL
}
}, { /* 1 */
"Ligatures",
0,
{
"Required Ligatures",
"Common Ligatures",
"Rare Ligatures",
"Logos",
"Rebus Pictures",
"Diphthong Ligatures",
"Squared Ligatures",
"Squared Ligatures, Abbreviated",
NULL
}
}, { /* 2 */
"Cursive Connection",
1,
{
"Unconnected",
"Partially Connected",
"Cursive",
NULL
}
}, { /* 3 */
"Letter Case",
1,
{
"Upper & Lower Case",
"All Caps",
"All Lower Case",
"Small Caps",
"Initial Caps",
"Initial Caps & Small Caps",
NULL
}
}, { /* 4 */
"Vertical Substitution",
0,
{
/* "Substitute Vertical Forms", */
"Turns on the feature",
NULL
}
}, { /* 5 */
"Linguistic Rearrangement",
0,
{
/* "Linguistic Rearrangement", */
"Turns on the feature",
NULL
}
}, { /* 6 */
"Number Spacing",
1,
{
"Monospaced Numbers",
"Proportional Numbers",
NULL
}
}, { /* 7 */
"Apple Reserved 1",
0,
{NULL}
}, { /* 8 */
"Smart Swashes",
0,
{
"Word Initial Swashes",
"Word Final Swashes",
"Line Initial Swashes",
"Line Final Swashes",
"Non-Final Swashes",
NULL
}
}, { /* 9 */
"Diacritics",
1,
{
"Show Diacritics",
"Hide Diacritics",
"Decompose Diacritics",
NULL
}
}, { /* 10 */
"Vertical Position",
1,
{
/* "Normal Position", */
"No Vertical Position",
"Superiors",
"Inferiors",
"Ordinals",
NULL
}
}, { /* 11 */
"Fractions",
1,
{
"No Fractions",
"Vertical Fractions",
"Diagonal Fractions",
NULL
}
}, { /* 12 */
"Apple Reserved 2",
0,
{NULL}
}, { /* 13 */
"Overlapping Characters",
0,
{
/* "Prevent Overlap", */
"Turns on the feature",
NULL
}
}, { /* 14 */
"Typographic Extras",
0,
{
"Hyphens to Em Dash",
"Hyphens to En Dash",
"Unslashed Zero",
"Form Interrobang",
"Smart Quotes",
"Periods to Ellipsis",
NULL
}
}, { /* 15 */
"Mathematical Extras",
0,
{
"Hyphens to Minus",
"Asterisk to Multiply",
"Slash to Divide",
"Inequality Ligatures",
"Exponents",
NULL
}
}, { /* 16 */
"Ornament Sets",
1,
{
"No Ornaments",
"Dingbats",
"Pi Characters",
"Fleurons",
"Decorative Borders",
"International Symbols",
"Math Symbols",
NULL
}
}, { /* 17 */
"Character Alternatives",
1,
{
"No Alternates",
/* TODO */
NULL
}
}, { /* 18 */
"Design Complexity",
1,
{
"Design Level 1",
"Design Level 2",
"Design Level 3",
"Design Level 4",
"Design Level 5",
/* TODO */
NULL
}
}, { /* 19 */
"Style Options",
1,
{
"No Style Options",
"Display Text",
"Engraved Text",
"Illuminated Caps",
"Tilling Caps",
"Tall Caps",
NULL
}
}, { /* 20 */
"Character Shape",
1,
{
"Traditional Characters",
"Simplified Characters",
"JIS 1978 Characters",
"JIS 1983 Characters",
"JIS 1990 Characters",
"Traditional Characters, Alternative Set 1",
"Traditional Characters, Alternative Set 2",
"Traditional Characters, Alternative Set 3",
"Traditional Characters, Alternative Set 4",
"Traditional Characters, Alternative Set 5",
"Expert Characters",
NULL /* count=>12 */
}
}, { /* 21 */
"Number Case",
1,
{
"Lower Case Numbers",
"Upper Case Numbers",
NULL
}
}, { /* 22 */
"Text Spacing",
1,
{
"Proportional",
"Monospaced",
"Half-width",
"Normal",
NULL
}
}, /* Here after Newer */ { /* 23 */
"Transliteration",
1,
{
"No Transliteration",
"Hanja To Hangul",
"Hiragana to Katakana",
"Katakana to Hiragana",
"Kana to Romanization",
"Romanization to Hiragana",
"Romanization to Katakana",
"Hanja to Hangul, Alternative Set 1",
"Hanja to Hangul, Alternative Set 2",
"Hanja to Hangul, Alternative Set 3",
NULL
}
}, { /* 24 */
"Annotation",
1,
{
"No Annotation",
"Box Annotation",
"Rounded Box Annotation",
"Circle Annotation",
"Inverted Circle Annotation",
"Parenthesis Annotation",
"Period Annotation",
"Roman Numeral Annotation",
"Diamond Annotation",
NULL
}
}, { /* 25 */
"Kana Spacing",
1,
{
"Full Width",
"Proportional",
NULL
}
}, { /* 26 */
"Ideographic Spacing",
1,
{
"Full Width",
"Proportional",
NULL
}
}, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 27-30 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 31-35 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 36-40 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 40-45 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 46-50 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 51-55 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 56-60 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 61-65 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 66-70 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 71-75 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 76-80 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 81-85 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 86-90 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 91-95 */
EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 96-98 */
EMPTYFEAT, /* 99 */ { /* 100 => 22*/
"Text Spacing",
1,
{
"Proportional",
"Monospaced",
"Half-width",
"Normal",
NULL
}
}, { /* 101 => 25 */
"Kana Spacing",
1,
{
"Full Width",
"Proportional",
NULL
}
}, { /* 102 => 26 */
"Ideographic Spacing",
1,
{
"Full Width",
"Proportional",
NULL
}
}, { /* 103 */
"CJK Roman Spacing",
1,
{
"Half-width",
"Proportional",
"Default Roman",
"Full-width Roman",
NULL
}
}, { /* 104 => 1 */
"All Typographic Features",
0,
{
"All Type Features",
NULL
}
}
#define FEATREG_MAX_INDEX 104
};
FT_LOCAL_DEF( GX_Feature_Registry )
gx_get_feature_registry( FT_UShort feature_type )
{
GX_Feature_Registry featreg;
if ( feature_type > FEATREG_MAX_INDEX )
return NULL;
featreg = &featreg_table[feature_type];
if ( featreg->feat_name == 0 )
return NULL;
featreg->feature_type = feature_type;
return featreg;
}
FT_LOCAL_DEF( const FT_String * )
gx_feature_registry_get_name( GX_Feature_Registry featreg )
{
if ( featreg )
return featreg->feat_name;
else
return NULL;
}
FT_LOCAL_DEF ( FT_Bool )
gx_feature_registry_is_setting_exclusive( GX_Feature_Registry featreg )
{
if ( featreg )
return featreg->exclusive;
else
return 0;
}
FT_LOCAL_DEF ( const FT_String * )
gx_feature_registry_get_setting_name( GX_Feature_Registry featreg, FT_UShort nth )
{
FT_UShort max;
if ( !featreg )
return NULL;
max = gx_feature_registry_count_setting ( featreg );
if ( nth < max )
return featreg->setting_name[nth];
else
return NULL;
}
FT_LOCAL_DEF ( FT_UShort )
gx_feature_registry_count_setting ( GX_Feature_Registry featreg )
{
FT_Int i;
if ( !featreg )
return 0;
for ( i = 0; featreg->setting_name[i]; i++ )
; /* Do nothing */
return (FT_UShort)i;
}
FT_LOCAL_DEF( FT_UShort )
gx_feature_registry_get_value(GX_Feature_Registry featreg)
{
return featreg->feature_type;
}
/* END */

45
src/gxlayout/gxfeatreg.h Normal file
View File

@ -0,0 +1,45 @@
/***************************************************************************/
/* */
/* gxfeatreg.h */
/* */
/* Database of font features pre-defined by Apple Computer, Inc. */
/* http://developer.apple.com/fonts/Registry/ */
/* (specification only). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXFEATREG_H__
#define __GXFEATREG_H__
#include <ft2build.h>
#include FT_FREETYPE_H
FT_BEGIN_HEADER
typedef struct GX_Feature_RegistryRec_ *GX_Feature_Registry;
FT_LOCAL( GX_Feature_Registry ) gx_get_feature_registry( FT_UShort feature_type );
FT_LOCAL( FT_UShort ) gx_feature_registry_get_value(GX_Feature_Registry featreg);
FT_LOCAL( const FT_String * ) gx_feature_registry_get_name( GX_Feature_Registry featreg );
FT_LOCAL( FT_Bool ) gx_feature_registry_is_setting_exclusive( GX_Feature_Registry featreg );
FT_LOCAL( const FT_String * ) gx_feature_registry_get_setting_name( GX_Feature_Registry featreg, FT_UShort nth );
FT_LOCAL( FT_UShort ) gx_feature_registry_count_setting ( GX_Feature_Registry featreg );
FT_END_HEADER
#endif /* Not def: __GXFEATREG_H__ */
/* END */

762
src/gxlayout/gxlayout.c Normal file
View File

@ -0,0 +1,762 @@
/***************************************************************************/
/* */
/* gxlayout.c */
/* */
/* AAT/TrueTypeGX based layout engine(body). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include FT_LIST_H
#include FT_GXLAYOUT_H
#include FT_INTERNAL_FTL_TYPES_H
#include "gxltypes.h"
#include "gxtypes.h"
#include "gxaccess.h"
#include "gxutils.h"
#include "gxlookuptbl.h"
#include "gxfeatreg.h"
#include "gxlfeatreg.h"
#include "gxerrors.h"
static int gxl_feature_compare (const void * a, const void * b);
static FT_Error gxl_feature_initialize_for_mort ( GXL_Feature feature,
FT_Memory memory,
GX_Mort mort,
GX_Feat feat,
FT_UShort * index );
static FT_Error gxl_feature_initialize_for_morx ( GXL_Feature feature,
FT_Memory memory,
GX_Morx morx,
GX_Feat feat,
FT_UShort * index );
/*
* FEAT
*/
FT_LOCAL_DEF ( GXL_Setting )
gxl_feature_get_setting_by_value (GXL_Feature feature, FT_UShort value)
{
FT_Int i;
if ( feature->exclusive.exclusive )
{
if ( value == feature->exclusive.setting->value )
return feature->exclusive.setting;
}
else
{
for ( i = 0; i < feature->nSettings; i++ )
{
if ( value == feature->setting[i].value )
return &feature->setting[i];
}
}
return NULL;
}
FT_LOCAL_DEF ( GXL_Feature )
gxl_features_request_get_feature_by_type ( GXL_FeaturesRequest request,
FT_UShort featureType )
{
GXL_Feature feature = NULL;
int i;
for ( i = 0; i < request->nFeatures; i++ )
{
if ( request->feature[i].value == featureType )
{
feature = &request->feature[i];
break;
}
}
return feature;
}
FT_LOCAL_DEF ( void )
gxl_features_request_free( GXL_FeaturesRequest request, FT_Memory memory )
{
FT_Int i;
GXL_Feature feature;
for ( i = request->nFeatures; i > 0; i-- )
{
feature = &(request->feature[i - 1]);
FT_FREE( feature->setting );
}
FT_FREE ( request->feature );
FT_FREE ( request );
}
static GXL_Setting
gxl_setting_get_exclusive_setting( GXL_Setting setting )
{
return setting->feature->exclusive.setting;
}
static void
gxl_setting_set_exclusive_setting( GXL_Setting setting )
{
setting->feature->exclusive.setting = setting;
}
static void
gxl_setting_set_exclusive_state( GXL_Setting setting , FT_Bool state )
{
if ( state )
gxl_setting_set_exclusive_setting ( setting );
}
static FT_Bool
gxl_setting_get_exclusive_state ( GXL_Setting setting )
{
if ( gxl_setting_get_exclusive_setting (setting) == setting )
return 1;
else
return 0;
}
FT_EXPORT ( void )
GXL_FeaturesRequest_Set_Initial_State ( GXL_FeaturesRequest request,
GXL_Initial_State initial_state )
{
FT_ASSERT( request );
request->initial_state = initial_state;
}
FT_EXPORT ( GXL_Initial_State )
GXL_FeaturesRequest_Get_Initial_State ( GXL_FeaturesRequest request )
{
FT_ASSERT( request );
return request->initial_state;
}
FT_EXPORT_DEF ( FT_ULong )
GXL_FeaturesRequest_Get_Feature_Count ( GXL_FeaturesRequest request )
{
if ( request )
return request->nFeatures;
else
return 0;
}
FT_EXPORT_DEF ( GXL_Feature )
GXL_FeaturesRequest_Get_Feature ( GXL_FeaturesRequest request,
FT_ULong index)
{
GXL_Feature feature = NULL;
if ( index < GXL_FeaturesRequest_Get_Feature_Count ( request ) )
feature = &(request->feature[index]);
return feature;
}
FT_EXPORT_DEF( FT_Error )
GXL_Feature_Get_Name ( GXL_Feature feature,
FT_UShort platform_id,
FT_UShort encoding_id,
FT_UShort language_id,
FT_SfntName *aname )
{
GXL_Font font;
FT_Face face;
font = (GXL_Font)feature->request->root.font;
face = font->root.face;
if ( ! face )
return GX_Err_Invalid_Face_Handle;
if ( ! feature->name.string )
return gx_get_name_from_id ( face,
feature->name.index,
platform_id, encoding_id, language_id,
aname );
else
{
aname->platform_id = 0;
aname->encoding_id = 0;
aname->language_id = 0;
aname->name_id = 0;
aname->string = (FT_Byte*)feature->name.string;
aname->string_len = ft_strlen ( feature->name.string );
return GX_Err_Ok;
}
}
FT_EXPORT_DEF( FT_UShort )
GXL_Feature_Get_Setting_Count ( GXL_Feature feature )
{
return feature->nSettings;
}
FT_EXPORT_DEF( GXL_Setting )
GXL_Feature_Get_Setting ( GXL_Feature feature,
FT_ULong index )
{
GXL_Setting setting = NULL;
if ( index < feature->nSettings )
setting = &feature->setting[index];
return setting;
}
FT_EXPORT_DEF ( FT_Bool )
GXL_Feature_Is_Setting_Exclusive ( GXL_Feature feature )
{
return feature->exclusive.exclusive;
}
FT_EXPORT_DEF( FT_Bool )
GXL_Setting_Get_State ( GXL_Setting setting )
{
GXL_Feature feature = setting->feature;
if ( GXL_Feature_Is_Setting_Exclusive ( feature ) )
return gxl_setting_get_exclusive_state ( setting );
else
return gx_feat_setting_state(setting->value);
}
FT_EXPORT_DEF( FT_Error )
GXL_Setting_Get_Name ( GXL_Setting setting,
FT_UShort platform_id,
FT_UShort encoding_id,
FT_UShort language_id,
FT_SfntName *aname )
{
GXL_Font font = (GXL_Font)setting->feature->request->root.font;
FT_Face face = font->root.face;
if ( ! setting->name.string )
return gx_get_name_from_id ( face,
setting->name.index,
platform_id, encoding_id, language_id,
aname );
else
{
aname->platform_id = 0;
aname->encoding_id = 0;
aname->language_id = 0;
aname->name_id = 0;
aname->string = (FT_Byte*)setting->name.string;
aname->string_len = ft_strlen ( setting->name.string );
return GX_Err_Ok;
}
}
FT_EXPORT_DEF( void )
GXL_Setting_Set_State ( GXL_Setting setting,
FT_Bool state )
{
if ( setting->feature->exclusive.exclusive )
gxl_setting_set_exclusive_state( setting, state );
else if ( state )
setting->value = gx_feat_setting_on( setting->value );
else
setting->value = gx_feat_setting_off( setting->value );
}
/*
* Substitution
*/
static int
gxl_feature_compare (const void * a, const void * b)
{
return (FT_Long)((GXL_Feature)a)->value - (FT_Long)((GXL_Feature)b)->value;
}
typedef struct gxl_feature_initialize_for_mort_data_rec_
{
FT_Int count;
GXL_Feature feature;
GX_Feat feat;
FT_Memory memory;
} gxl_feature_initialize_for_mort_data_rec, *gxl_feature_initialize_for_mort_data;
static FT_Error
gxl_feature_initialize_for_mort_cb ( GX_MetamorphosisFeatureTable feat_Subtbl, FT_Pointer user )
{
FT_Error error;
GX_Feature_Registry featreg;
gxl_feature_initialize_for_mort_data data = user;
FT_Int i;
if ( gx_feat_has_feature_type ( data->feat, feat_Subtbl->featureType ) )
{ /* In feat table? */
return GX_Err_Ok;
}
for ( i = 0; i < data->count; i ++ )
{ /* Duplication check */
if ( data->feature[i].value == feat_Subtbl->featureType )
return GX_Err_Ok;
}
if (!( featreg = gx_get_feature_registry ( feat_Subtbl->featureType ) ))
{ /* Not in feature_registry */
return GX_Err_Ok;
}
error = gxl_feature_registry_fill_feature( featreg, data->memory, &(data->feature[data->count]) );
if ( error )
goto Exit;
data->count++;
Exit:
return error;
}
static FT_Error
gxl_feature_initialize_for_mort ( GXL_Feature feature,
FT_Memory memory,
GX_Mort mort,
GX_Feat feat,
FT_UShort * index )
{
FT_Error error;
FT_Int i;
gxl_feature_initialize_for_mort_data_rec data;
data.count = 0;
data.feature = feature;
data.feat = feat;
data.memory = memory;
error = gx_mort_foreach_feature ( mort, gxl_feature_initialize_for_mort_cb, &data );
if ( error )
{
for ( i = data.count; i > 0; i-- )
FT_FREE (feature[i - 1].setting);
return error;
}
else
{
*index = data.count;
return GX_Err_Ok ;
}
}
typedef struct gxl_feature_initialize_for_morx_data_rec_
{
FT_Int count;
GXL_Feature feature;
GX_Feat feat;
FT_Memory memory;
} gxl_feature_initialize_for_morx_data_rec, *gxl_feature_initialize_for_morx_data;
static FT_Error
gxl_feature_initialize_for_morx_cb ( GX_MetamorphosisFeatureTable feat_Subtbl, FT_Pointer user )
{
FT_Error error;
GX_Feature_Registry featreg;
gxl_feature_initialize_for_morx_data data = user;
FT_Int i;
if ( gx_feat_has_feature_type ( data->feat, feat_Subtbl->featureType ) )
return GX_Err_Ok;
for ( i = 0; i < data->count; i ++ )
{ /* Duplication check */
if ( data->feature[i].value == feat_Subtbl->featureType )
return GX_Err_Ok;
}
featreg = gx_get_feature_registry ( feat_Subtbl->featureType );
if ( ! featreg )
return GX_Err_Ok;
error = gxl_feature_registry_fill_feature( featreg, data->memory, &(data->feature[data->count]) );
if ( error )
return error;
data->count++;
return GX_Err_Ok;
}
static FT_Error
gxl_feature_initialize_for_morx ( GXL_Feature feature,
FT_Memory memory,
GX_Morx morx,
GX_Feat feat,
FT_UShort * index )
{
FT_Error error;
FT_Int i;
gxl_feature_initialize_for_morx_data_rec data;
data.count = 0;
data.feature = feature;
data.feat = feat;
data.memory = memory;
error = gx_morx_foreach_feature ( morx, gxl_feature_initialize_for_morx_cb, &data );
if ( error )
{
for ( i = data.count; i > 0; i-- )
FT_FREE (feature[i - 1].setting);
return error;
}
else
{
*index = data.count;
return GX_Err_Ok ;
}
}
FT_LOCAL_DEF ( FT_Error )
gxl_get_font ( FT_Face face, FTL_Font * font)
{
*font = ((GX_Face)face)->extra.data;
if ( *font )
return FT_Err_Ok;
else
return GX_Err_Invalid_Face_Handle;
}
FT_LOCAL_DEF ( FTL_EngineType )
gxl_get_engine_type ( FT_Face face )
{
return FTL_TRUETYPEGX_ENGINE;
}
FT_LOCAL_DEF ( FT_Error )
gxl_new_features_request( FT_Face face, FTL_FeaturesRequest * ftl_request)
{
FT_Memory memory = face->driver->root.memory;
FT_Error error;
GXL_Font font;
GXL_FeaturesRequest request;
GX_Feat feat;
GX_Mort mort;
GX_Morx morx;
GXL_Feature feature;
GXL_Setting setting;
FT_UShort default_setting_index;
GXL_Setting default_setting;
FT_UShort infeat_feat_count, inmort_feat_count = 0, inmorx_feat_count = 0;
FT_Int i_feat, i_setting, j_feat, i_mort, i_morx;
if (( error = gxl_get_font ( face, (FTL_Font*)&font ) ))
return error;
if ( FT_NEW ( request ) )
goto Exit;
if (( error = FTL_FeaturesRequest_Init ( face, (FTL_FeaturesRequest)request ) ))
{
FT_FREE( request );
goto Exit;
}
request->initial_state = GXL_START_OF_TEXT_STATE;
feat = font->feat;
mort = font->mort;
morx = font->morx;
if ( !feat )
{
error = FT_Err_Ok;
(request)->nFeatures = 0;
(request)->feature = NULL;
*ftl_request = (FTL_FeaturesRequest)request;
goto Exit;
}
if ( mort )
inmort_feat_count = gx_mort_count_feat_not_in_feat( mort, feat );
if ( morx )
inmorx_feat_count = gx_morx_count_feat_not_in_feat( morx, feat );
if ( ( mort == NULL ) && ( morx == NULL ) )
{
error = GX_Err_Missing_Glyph_Substitution_Data;
goto Failure_request;
}
infeat_feat_count = feat->featureNameCount;
request->nFeatures = infeat_feat_count + inmort_feat_count + inmorx_feat_count;
if ( FT_NEW_ARRAY ( request->feature, request->nFeatures ) )
goto Failure_request;
for ( i_feat = 0; i_feat < infeat_feat_count; i_feat++ )
{
feature = (&request->feature[i_feat]);
feature->value = feat->names[i_feat].feature;
feature->exclusive.exclusive = ((feat->names[i_feat].featureFlags)
& GX_FEAT_MASK_EXCLUSIVE_SETTINGS)
? 1: 0;
feature->exclusive.setting = NULL; /* dummy */
feature->name.index = feat->names[i_feat].nameIndex;
feature->name.string = NULL;
feature->request = request;
feature->nSettings = feat->names[i_feat].nSettings;
if ( FT_NEW_ARRAY ( feature->setting, feature->nSettings ) )
goto Failure_loop_feat;
for ( i_setting = 0; i_setting < feature->nSettings; i_setting++ )
{
setting = &feature->setting[i_setting];
setting->value = feat->names[i_feat].settingName[i_setting].setting;
setting->name.index = feat->names[i_feat].settingName[i_setting].nameIndex;
setting->name.string = NULL;
setting->feature = feature;
}
if ( feature->exclusive.exclusive )
{
default_setting_index = 0;
if ( (feat->names[i_feat].featureFlags)&GX_FEAT_MASK_DYNAMIC_DEFAULT )
default_setting_index = (feat->names[i_feat].featureFlags)&GX_FEAT_MASK_DEFAULT_SETTING;
default_setting = &feature->setting[default_setting_index];
if ( default_setting_index >= feature->nSettings )
{
error = GX_Err_Invalid_File_Format;
goto Failure_loop_feat;
}
GXL_Setting_Set_State ( default_setting, 1 );
}
else if ( feat->names[i_feat].featureFlags&GX_FEAT_MASK_DYNAMIC_DEFAULT )
{
FT_Bool state;
default_setting_index = feat->names[i_feat].featureFlags&GX_FEAT_MASK_DEFAULT_SETTING;
if ( default_setting_index < feature->nSettings )
{
default_setting = &feature->setting[default_setting_index];
state = 1;
}
else if ( default_setting_index == 1 )
{
/* If default_setting_index is 1 but nSettings is also 1,
there is not setting for default_setting_index in the
font file. In this case setting[0] should be off. */
default_setting = &feature->setting[0];
state = 0;
}
else
{
error = GX_Err_Invalid_File_Format;
goto Failure_loop_feat;
}
GXL_Setting_Set_State ( default_setting, state );
}
else
{ /* TODO: getting from mort's and morx's default? */
default_setting_index = 0;
default_setting = &feature->setting[default_setting_index];
GXL_Setting_Set_State ( default_setting, 1 );
}
}
if ( inmort_feat_count )
{
inmort_feat_count = 0;
feature = (&request->feature[i_feat]);
if (( error = gxl_feature_initialize_for_mort (feature, memory, mort, feat, &inmort_feat_count) ))
goto Failure_loop_feat;
for ( i_mort = 0; i_mort < inmort_feat_count; i_mort++ )
feature[i_mort].request = request;
i_feat += inmort_feat_count;
request->nFeatures = i_feat;
feature = (&request->feature[inmort_feat_count]);
}
if ( inmorx_feat_count )
{
inmorx_feat_count = 0;
feature = (&(request)->feature[i_feat]);
if (( error = gxl_feature_initialize_for_morx (feature, memory, morx, feat, &inmorx_feat_count) ))
goto Failure_loop_feat;
for ( i_morx = 0; i_morx < inmorx_feat_count; i_morx++ )
feature[i_morx].request = request;
i_feat += inmorx_feat_count;
request->nFeatures = i_feat;
}
if ( inmort_feat_count || inmorx_feat_count )
{
ft_qsort(request->feature,
request->nFeatures,
sizeof (*(request->feature)),
gxl_feature_compare );
for ( i_feat = 0; i_feat < request->nFeatures; i_feat++ )
{
feature = &request->feature[i_feat];
for ( i_setting = 0; i_setting < feature->nSettings; i_setting++ )
feature->setting[i_setting].feature = feature;
}
}
*ftl_request = (FTL_FeaturesRequest)request;
Exit:
return error;
Failure_loop_feat:
for ( j_feat = i_feat; j_feat > 0; j_feat-- )
FT_FREE( request->feature[j_feat - 1].setting );
Failure_request:
FT_FREE(request);
return error;
}
FT_LOCAL_DEF ( FT_Error )
gxl_done_features_request( FTL_FeaturesRequest request)
{
FTL_Font font;
FT_Face face;
FT_Memory memory;
FT_ASSERT( request );
font = request->font;
FT_ASSERT( font );
face = font->face;
if ( !face )
return GX_Err_Invalid_Argument;
memory = face->driver->root.memory;
gxl_features_request_free( (GXL_FeaturesRequest)request, memory );
return FTL_FeaturesRequest_Finalize ( request );
}
FT_LOCAL_DEF ( FT_Error )
gxl_copy_features_request( FTL_FeaturesRequest from,
FTL_FeaturesRequest to)
{
FT_Error error;
FT_Int i_feat, i_setting;
GXL_Feature from_feature, to_feature;
GXL_Setting from_setting, to_setting;
if (( error = FTL_FeaturesRequest_Copy( from, to ) ))
return error;
for ( i_feat = 0; i_feat < ((GXL_FeaturesRequest)from)->nFeatures; i_feat++ )
{
from_feature = GXL_FeaturesRequest_Get_Feature((GXL_FeaturesRequest)from,
i_feat);
to_feature = GXL_FeaturesRequest_Get_Feature((GXL_FeaturesRequest)to,
i_feat);
for ( i_setting = 0;
i_setting < GXL_Feature_Get_Setting_Count(from_feature);
i_setting++ )
{
from_setting = GXL_Feature_Get_Setting ( from_feature, i_setting );
to_setting = GXL_Feature_Get_Setting ( to_feature, i_setting );
GXL_Setting_Set_State(to_setting,
GXL_Setting_Get_State(from_setting));
}
}
return GX_Err_Ok;
}
FT_LOCAL_DEF ( FT_UShort )
gxl_get_ligature_caret_count ( FT_Face face,
FT_UShort glyphID )
{
FTL_Font font;
GX_Lcar lcar;
GX_LigCaretClassEntry class_entry;
if ( FTL_Get_Font( face, &font ) )
return 0;
lcar = ((GXL_Font)font)->lcar;
if ( !lcar )
return 0;
class_entry = gx_lcar_get( lcar, glyphID );
if ( class_entry )
return class_entry->count;
else
return 0;
}
/* TODO: return an error */
FT_LOCAL_DEF ( FT_UShort )
gxl_get_ligature_caret_division( FT_Face face,
FT_UShort glyph_id,
FT_UShort nth )
{
FTL_Font font;
GX_Lcar lcar;
GX_LigCaretClassEntry class_entry;
FT_UShort partials;
FTL_Direction direction;
FT_Outline *outline;
FT_Vector point;
if ( FTL_Get_Font( face, &font ) )
return 0;
lcar = ((GXL_Font)font)->lcar;
if ( !lcar )
return 0;
class_entry = gx_lcar_get( lcar, glyph_id );
if ( !class_entry )
return 0;
if ( nth >= class_entry->count )
return 0;
partials = class_entry->partials[nth];
if ( lcar->format == GX_LCAR_DISTANCE )
return partials;
/* font -> feature_requst -> direction */
direction = FTL_Get_FeaturesRequest_Direction ( font->features_request );
/* glyph_id -> glyph -> outline -> point -> x or y */
if ( FT_Load_Glyph ( face, glyph_id,
FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP ) )
return 0;
outline = &face->glyph->outline;
if ( ! ( partials < outline->n_points ) )
return 0;
point = outline->points[partials];
/* TODO: Are the unit for the outline and that
for ligature caret same? */
if ( direction == FTL_HORIZONTAL )
return (FT_UShort)point.x;
else
return (FT_UShort)point.y;
}
FT_LOCAL_DEF ( FT_Error )
gxl_substitute_glyphs ( FT_Face face,
FTL_FeaturesRequest request,
FTL_Glyphs_Array in,
FTL_Glyphs_Array out )
{
FT_Error error;
GXL_Font font;
GX_Mort mort;
GX_Morx morx;
if (( error = FTL_Get_Font ( face, (FTL_Font*)&font )))
return error;
mort = font->mort;
morx = font->morx;
if ( mort )
return gx_mort_substitute_glyph(mort, (GXL_FeaturesRequest)request, in, out );
else if ( morx )
return gx_morx_substitute_glyph(morx, (GXL_FeaturesRequest)request, in, out );
else
return FT_Err_Invalid_Argument;
}
/* END */

87
src/gxlayout/gxlfeatreg.c Normal file
View File

@ -0,0 +1,87 @@
/***************************************************************************/
/* */
/* gxlfeatreg.c */
/* */
/* High level interface for the font feature registry(body) */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include "gxlfeatreg.h"
#include "gxltypes.h"
#include "gxaccess.h"
#undef FT_COMPONENT
#define FT_COMPONENT trace_gxlayout
FT_LOCAL_DEF( FT_Error )
gxl_feature_registry_fill_feature(GX_Feature_Registry featreg,
FT_Memory memory,
GXL_Feature feature)
{
FT_Error error = GX_Err_Ok;
FT_Int i;
feature->value = gx_feature_registry_get_value( featreg );
feature->request = NULL; /* for debug */
feature->name.string = gx_feature_registry_get_name( featreg );
if ( !feature->name.string )
{
FT_ERROR(("Broken feature is used to lookup feature registry\n"));
error = GX_Err_Invalid_Argument;
goto Exit;
}
FT_TRACE3(("Name from feature registry: %s\n", feature->name.string));
feature->name.index = 0; /* for debug */
feature->nSettings = gx_feature_registry_count_setting ( featreg );
if ( FT_NEW_ARRAY( feature->setting, feature->nSettings ) )
goto Exit;
feature->exclusive.exclusive = gx_feature_registry_is_setting_exclusive ( featreg );
for ( i = 0; i < feature->nSettings; i++ )
{
if ( feature->exclusive.exclusive )
feature->setting[i].value = i;
else
{
feature->setting[i].value = 2*i;
if ( i != 0)
feature->setting[i].value = gx_feat_setting_off ( feature->setting[i].value );
}
feature->setting[i].name.string = gx_feature_registry_get_setting_name( featreg, i );
if ( ! feature->setting[i].name.string )
{
FT_ERROR(("Broken setting is used to lookup feature registry: feature=%s\n",
feature->name.string));
error = GX_Err_Invalid_Argument;
goto Failure;
}
feature->setting[i].name.index = 0; /* for debug */
feature->setting[i].feature = feature;
}
if ( feature->exclusive.exclusive )
feature->exclusive.setting = &feature->setting[0];
else
feature->exclusive.setting = NULL;
Exit:
return error;
Failure:
FT_FREE( feature->setting );
return error;
}
/* END */

42
src/gxlayout/gxlfeatreg.h Normal file
View File

@ -0,0 +1,42 @@
/***************************************************************************/
/* */
/* gxlfeatreg.h */
/* */
/* High level interface for the font feature registry(specification) */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXLFEATREG_H__
#define __GXLFEATREG_H__
#include <ft2build.h>
#include FT_TYPES_H
#include "gxltypes.h"
#include "gxfeatreg.h"
FT_BEGIN_HEADER
FT_LOCAL( FT_Error ) gxl_feature_registry_fill_feature(GX_Feature_Registry featreg,
FT_Memory memory,
GXL_Feature feature);
FT_END_HEADER
#endif /* Not def: __GXLFEATREG_H__ */
/* END */

4327
src/gxlayout/gxload.c Normal file

File diff suppressed because it is too large Load Diff

112
src/gxlayout/gxload.h Normal file
View File

@ -0,0 +1,112 @@
/***************************************************************************/
/* */
/* gxload.h */
/* */
/* Functions load AAT/TrueTypeGX tables(specification) */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXLOAD_H__
#define __GXLOAD_H__
#include <ft2build.h>
#include FT_FREETYPE_H
#include "gxtypes.h"
#include "gxltypes.h"
FT_BEGIN_HEADER
#define gx_table_load(face,stream,tag,FONT) \
(error = gx_face_load_##tag (face, stream, FONT->tag), \
FONT->tag->root.font = (error? NULL: FONT), \
FONT->tag->root.done_table = (error? NULL: FONT->tag->root.done_table), \
error)
FT_LOCAL ( FT_Error )
gx_table_done ( GX_Table table, FT_Memory memory );
FT_LOCAL ( FT_Error )
gx_face_load_feat( GX_Face face,
FT_Stream stream,
GX_Feat feat );
FT_LOCAL ( FT_Error )
gx_face_load_trak( GX_Face face,
FT_Stream stream,
GX_Trak trak );
FT_LOCAL ( FT_Error )
gx_face_load_kern( GX_Face face,
FT_Stream stream,
GX_Kern kern );
FT_LOCAL ( FT_Error )
gx_face_load_prop( GX_Face face,
FT_Stream stream,
GX_Prop prop );
FT_LOCAL ( FT_Error )
gx_face_load_opbd( GX_Face face,
FT_Stream stream,
GX_Opbd opbd );
FT_LOCAL ( FT_Error )
gx_face_load_lcar( GX_Face face,
FT_Stream stream,
GX_Lcar lcar );
FT_LOCAL ( FT_Error )
gx_face_load_bsln( GX_Face face,
FT_Stream stream,
GX_Bsln bsln );
FT_LOCAL ( FT_Error )
gx_face_load_mort( GX_Face face,
FT_Stream stream,
GX_Mort mort );
FT_LOCAL ( FT_Error )
gx_face_load_morx( GX_Face face,
FT_Stream stream,
GX_Morx morx );
FT_LOCAL ( FT_Error )
gx_face_load_fmtx( GX_Face face,
FT_Stream stream,
GX_Fmtx fmtx );
FT_LOCAL ( FT_Error )
gx_face_load_fdsc( GX_Face face,
FT_Stream stream,
GX_Fdsc fdsc );
FT_LOCAL ( FT_Error )
gx_face_load_just( GX_Face face,
FT_Stream stream,
GX_Just just );
FT_LOCAL ( FT_Error )
gx_face_load_fvar ( GX_Face face,
FT_Stream stream,
GX_Fvar fvar );
FT_END_HEADER
#endif /* Not def: __GXLOAD_H__ */
/* END */

691
src/gxlayout/gxlookuptbl.c Normal file
View File

@ -0,0 +1,691 @@
/***************************************************************************/
/* */
/* gxlookuptbl.c */
/* */
/* AAT/TrueTypeGX lookup table related types and functions */
/* (body) */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_DEBUG_H
#include "gxlookuptbl.h"
#include "gxerrors.h"
typedef FT_Error (*gx_LookupTable_loader) ( GX_LookupTable lookup_table,
FT_Stream stream );
typedef void (*gx_LookupTable_finalizer) ( FT_Memory memory,
GX_LookupTable lookup_table );
typedef FT_Error (*gx_LookupTable_traverser) ( GX_LookupTable lookup_table,
GX_LookupTable_Funcs funcs,
FT_Pointer user );
static FT_Error
gx_load_BinSrchHeader( FT_Stream stream,
GX_BinSrchHeader header )
{
FT_Error error;
const FT_Frame_Field fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE GX_BinSrchHeaderRec
FT_FRAME_START( 10 ),
FT_FRAME_USHORT (unitSize),
FT_FRAME_USHORT (nUnits),
FT_FRAME_USHORT (searchRange),
FT_FRAME_USHORT (entrySelector),
FT_FRAME_USHORT (rangeShift),
FT_FRAME_END
};
FT_STREAM_READ_FIELDS( fields, header );
return error;
}
static FT_Error
gx_LookupTable_load_raw_values ( FT_Stream stream,
FT_Long value_count,
GX_LookupValue value_slot )
{
FT_Error error;
FT_Long i;
for ( i = 0; i < value_count; i++)
{
value_slot[i].extra.any = NULL;
error = FT_READ_SHORT(value_slot[i].raw.s);
if ( error )
return error;
}
return error;
}
static FT_Error
gx_LookupTable_load_segment_generic( GX_LookupTable lookup_table,
FT_Stream stream )
{
FT_Error error;
FT_Memory memory = stream->memory;
GX_LookupTable_Segment segment_table = lookup_table->fsHeader.segment_generic;
GX_BinSrchHeaderRec binSrchHeader = segment_table->binSrchHeader;
GX_LookupSegment segment;
FT_Long i;
if ( FT_NEW_ARRAY( segment, binSrchHeader.nUnits ) )
return error;
for ( i = 0; i < binSrchHeader.nUnits; i++ )
{
error = FT_READ_USHORT(segment[i].lastGlyph);
if ( error )
goto Failure;
error = FT_READ_USHORT(segment[i].firstGlyph);
if ( error )
goto Failure;
error = gx_LookupTable_load_raw_values(stream, 1, &(segment[i].value));
if ( error )
goto Failure;
}
segment_table->segments = segment;
return error;
Failure:
FT_FREE(segment);
return error;
}
static void
gx_LookupTable_free_segment_generic( FT_Memory memory,
GX_LookupTable lookup_table )
{
GX_LookupTable_Segment segment_table = lookup_table->fsHeader.segment_generic;
FT_FREE(segment_table->segments);
segment_table->segments = NULL;
}
static FT_Error
gx_LookupTable_load_single_table( GX_LookupTable lookup_table,
FT_Stream stream )
{
FT_Error error;
FT_Memory memory = stream->memory;
GX_LookupTable_Single_Table single_table = lookup_table->fsHeader.single_table;
GX_BinSrchHeaderRec binSrchHeader = single_table->binSrchHeader;
GX_LookupSingle single;
FT_Long i;
if ( FT_NEW_ARRAY( single, binSrchHeader.nUnits ) )
return error;
for ( i = 0; i < binSrchHeader.nUnits; i++ )
{
error = FT_READ_USHORT(single[i].glyph);
if ( error )
goto Failure;
gx_LookupTable_load_raw_values(stream, 1, &(single[i].value));
if ( error )
goto Failure;
}
single_table->entries = single;
return error;
Failure:
FT_FREE(single);
single_table->entries = NULL;
return error;
}
static void
gx_LookupTable_free_single_table( FT_Memory memory,
GX_LookupTable lookup_table )
{
GX_LookupTable_Single_Table single_table = lookup_table->fsHeader.single_table;
FT_FREE(single_table->entries);
single_table->entries = NULL;
}
static FT_Error
gx_LookupTable_load_binSrch( GX_LookupTable lookup_table,
FT_Stream stream )
{
FT_Error error = GX_Err_Ok;
FT_Memory memory = stream->memory;
GX_LookupTable_BinSrch binSrch;
gx_LookupTable_loader lookuptable_loader;
switch (lookup_table->format)
{
case GX_LOOKUPTABLE_SEGMENT_SINGLE:
case GX_LOOKUPTABLE_SEGMENT_ARRAY:
lookuptable_loader = gx_LookupTable_load_segment_generic;
break;
case GX_LOOKUPTABLE_SINGLE_TABLE:
lookuptable_loader = gx_LookupTable_load_single_table;
break;
default:
return GX_Err_Invalid_Table;
}
if ( FT_MEM_NEW (binSrch) )
return error;
binSrch->dummy = NULL;
error = gx_load_BinSrchHeader( stream, &(binSrch->binSrchHeader) );
if ( error )
goto Failure;
lookup_table->fsHeader.bin_srch = binSrch;
error = lookuptable_loader ( lookup_table, stream );
if ( error )
{
lookup_table->fsHeader.bin_srch = NULL;
goto Failure;
}
return error;
Failure:
FT_FREE ( binSrch );
return error;
}
static void
gx_LookupTable_free_binSrch ( FT_Memory memory,
GX_LookupTable lookup_table )
{
GX_LookupTable_BinSrch binSrch = lookup_table->fsHeader.bin_srch;
gx_LookupTable_finalizer finalizer;
switch (lookup_table->format)
{
case GX_LOOKUPTABLE_SEGMENT_SINGLE:
case GX_LOOKUPTABLE_SEGMENT_ARRAY:
finalizer = gx_LookupTable_free_segment_generic;
break;
case GX_LOOKUPTABLE_SINGLE_TABLE:
finalizer = gx_LookupTable_free_single_table;
break;
default:
finalizer = NULL;
}
FT_ASSERT(finalizer);
finalizer ( memory, lookup_table );
binSrch->dummy = NULL;
FT_FREE ( lookup_table->fsHeader.bin_srch );
lookup_table->fsHeader.bin_srch = NULL;
}
static FT_Error
gx_LookupTable_load_simple_array( GX_LookupTable lookup_table,
FT_Stream stream )
{
FT_Error error;
FT_Memory memory = stream->memory;
GX_LookupValue value_slot;
if ( FT_NEW_ARRAY (value_slot, lookup_table->num_glyphs) )
return error;
error = gx_LookupTable_load_raw_values ( stream,
lookup_table->num_glyphs,
value_slot );
if ( error )
goto Failure;
lookup_table->fsHeader.simple_array = value_slot;
return error;
Failure:
FT_FREE( value_slot );
return error;
}
static void
gx_LookupTable_free_simple_array( FT_Memory memory,
GX_LookupTable lookup_table )
{
FT_FREE ( lookup_table->fsHeader.simple_array );
lookup_table->fsHeader.simple_array = NULL;
}
static FT_Error
gx_LookupTable_load_trimmed_array( GX_LookupTable lookup_table,
FT_Stream stream )
{
FT_Error error;
FT_Memory memory = stream->memory;
FT_Short firstGlyph, glyphCount;
GX_LookupTable_Trimmed_Array trimmed_array;
GX_LookupValue value_slot;
error = FT_READ_USHORT(firstGlyph);
if ( error )
return error;
error = FT_READ_USHORT(glyphCount);
if ( error )
return error;
if ( FT_ALLOC (trimmed_array,
sizeof (*trimmed_array) + sizeof(*trimmed_array->valueArray) * glyphCount) )
return error;
trimmed_array->firstGlyph = firstGlyph;
trimmed_array->glyphCount = glyphCount;
trimmed_array->valueArray = NULL;
value_slot =(GX_LookupValue)(((char *)trimmed_array) + sizeof (*trimmed_array));
error = gx_LookupTable_load_raw_values ( stream, glyphCount, value_slot );
if ( error )
goto Failure;
lookup_table->fsHeader.trimmed_array = trimmed_array;
trimmed_array->valueArray = value_slot;
return error;
Failure:
FT_FREE( trimmed_array );
lookup_table->fsHeader.trimmed_array = NULL;
return error;
}
static void
gx_LookupTable_free_trimmed_array( FT_Memory memory,
GX_LookupTable lookup_table )
{
GX_LookupTable_Trimmed_Array trimmed_array;
trimmed_array = lookup_table->fsHeader.trimmed_array;
trimmed_array->valueArray = NULL;
FT_FREE(trimmed_array);
lookup_table->fsHeader.trimmed_array = NULL;
}
FT_LOCAL_DEF( FT_Error )
gx_face_load_LookupTable ( GX_Face face,
FT_Stream stream,
GX_LookupTable lookup_table )
{
FT_Error error;
gx_LookupTable_loader loader;
lookup_table->position = FT_STREAM_POS();
lookup_table->num_glyphs = face->root.num_glyphs;
lookup_table->fsHeader.any = NULL;
error = FT_READ_SHORT(lookup_table->format);
if ( error )
return error;
switch ( lookup_table->format )
{
case GX_LOOKUPTABLE_SIMPLE_ARRAY:
loader = gx_LookupTable_load_simple_array;
break;
case GX_LOOKUPTABLE_TRIMMED_ARRAY:
loader = gx_LookupTable_load_trimmed_array;
break;
default:
loader = gx_LookupTable_load_binSrch;
}
error = (*loader)( lookup_table, stream );
return error;
}
FT_LOCAL_DEF ( void )
gx_LookupTable_free ( GX_LookupTable lookup_table,
FT_Memory memory )
{
gx_LookupTable_finalizer finalizer;
switch ( lookup_table->format )
{
case GX_LOOKUPTABLE_SIMPLE_ARRAY:
finalizer = gx_LookupTable_free_simple_array;
break;
case GX_LOOKUPTABLE_TRIMMED_ARRAY:
finalizer = gx_LookupTable_free_trimmed_array;
break;
default:
finalizer = gx_LookupTable_free_binSrch;
}
finalizer ( memory, lookup_table );
}
static FT_Error
gx_LookupTable_traverse_simple_array( GX_LookupTable lookup_table,
GX_LookupTable_Funcs funcs,
FT_Pointer user )
{
FT_Long i;
FT_Error error = GX_Err_Ok;
if ( funcs->simple_array_func )
{
for ( i = 0; i < lookup_table->num_glyphs; i++ )
{
error = (* funcs->simple_array_func)(lookup_table->format,
i,
&((lookup_table->fsHeader.simple_array)[i]),
user);
if ( error )
return error;
}
}
else if ( funcs->generic_func )
{
for ( i = 0; i < lookup_table->num_glyphs; i++ )
{
error = (* funcs->generic_func)(lookup_table->format,
&((lookup_table->fsHeader.simple_array)[i]),
user);
if ( error )
return error;
}
}
else
error = GX_Err_Ok;
return error;
}
static FT_Error
gx_LookupTable_traverse_segment_generic( GX_LookupTable lookup_table,
GX_LookupTable_Funcs funcs,
FT_Pointer user )
{
FT_Error error = GX_Err_Ok;
GX_LookupTable_Segment segment_table = lookup_table->fsHeader.segment_generic;
GX_BinSrchHeader header = &(segment_table->binSrchHeader);
GX_LookupSegment segment;
GX_LookupTable_Segment_Func segment_func;
FT_Long i;
if ( lookup_table->format == GX_LOOKUPTABLE_SEGMENT_SINGLE )
segment_func = funcs->segment_single_func;
else if ( lookup_table->format == GX_LOOKUPTABLE_SEGMENT_ARRAY)
segment_func = funcs->segment_array_func;
else
segment_func = NULL;
if ( segment_func )
{
for ( i = 0; i < header->nUnits; i++ )
{
segment = &(segment_table->segments[i]);
error = (*segment_func)( lookup_table->format,
segment->lastGlyph,
segment->firstGlyph,
&(segment->value),
user );
if ( error )
return error;
}
}
else if ( funcs->generic_func )
{
for ( i = 0; i < header->nUnits; i++ )
{
segment = &(segment_table->segments[i]);
error = (*funcs->generic_func)( lookup_table->format,
&(segment->value),
user );
if ( error )
return error;
}
}
else
error = GX_Err_Ok;
return error;
}
static FT_Error
gx_LookupTable_traverse_single_table ( GX_LookupTable lookup_table,
GX_LookupTable_Funcs funcs,
FT_Pointer user )
{
FT_Error error = GX_Err_Ok;
GX_LookupTable_Single_Table single_table;
GX_LookupSingle entries;
GX_BinSrchHeader binSrchHeader;
FT_Long i;
single_table = lookup_table->fsHeader.single_table;
entries = single_table->entries;
binSrchHeader = &(single_table->binSrchHeader);
if ( funcs->single_table_func )
{
for ( i = 0; i < binSrchHeader->nUnits; i++ )
{
error = (*funcs->single_table_func) ( lookup_table->format,
entries[i].glyph,
&(entries[i].value),
user );
if ( error )
return error;
}
}
else if ( funcs->generic_func )
{
for ( i = 0; i < binSrchHeader->nUnits; i++ )
{
error = (* funcs->generic_func) ( lookup_table->format,
&(entries[i].value),
user );
if ( error )
return error;
}
}
else
error = GX_Err_Ok;
return error;
}
static FT_Error
gx_LookupTable_traverse_trimmed_array( GX_LookupTable lookup_table,
GX_LookupTable_Funcs funcs,
FT_Pointer user )
{
FT_Error error = GX_Err_Ok;
FT_Long i;
GX_LookupTable_Trimmed_Array trimmed_array = lookup_table->fsHeader.trimmed_array;
if ( funcs->trimmed_array_func )
{
for ( i = 0; i < trimmed_array->glyphCount; i++ )
{
error = (* funcs->trimmed_array_func)(lookup_table->format,
i,
trimmed_array->firstGlyph,
trimmed_array->glyphCount,
&(trimmed_array->valueArray[i]),
user);
if ( error )
return error;
}
}
else if ( funcs->generic_func )
{
for ( i = 0; i < trimmed_array->glyphCount; i++ )
{
error = (* funcs->generic_func)(lookup_table->format,
&(trimmed_array->valueArray[i]),
user);
if ( error )
return error;
}
}
else
error = GX_Err_Ok;
return error;
}
FT_LOCAL_DEF ( FT_Error )
gx_LookupTable_traverse_low( GX_LookupTable lookup_table,
GX_LookupTable_Funcs funcs,
FT_Pointer user )
{
gx_LookupTable_traverser traverser;
switch (lookup_table->format)
{
case GX_LOOKUPTABLE_SIMPLE_ARRAY:
traverser = gx_LookupTable_traverse_simple_array;
break;
case GX_LOOKUPTABLE_SEGMENT_SINGLE:
case GX_LOOKUPTABLE_SEGMENT_ARRAY:
traverser = gx_LookupTable_traverse_segment_generic;
break;
case GX_LOOKUPTABLE_SINGLE_TABLE:
traverser = gx_LookupTable_traverse_single_table;
break;
case GX_LOOKUPTABLE_TRIMMED_ARRAY:
traverser = gx_LookupTable_traverse_trimmed_array;
break;
default:
traverser = NULL;
}
FT_ASSERT(traverser);
return (*traverser) ( lookup_table, funcs, user );
}
static int
lookup_lookup_segment (const void *keyval, const void *datum)
{
const GX_LookupSegment segment = (const GX_LookupSegment)datum;
FT_UShort glyph = *(FT_UShort*)keyval;
if ( glyph < segment->firstGlyph )
return -1;
else if ( segment->lastGlyph < glyph )
return 1;
else
return 0;
}
static int
lookup_lookup_single(const void *keyval, const void *datum)
{
const GX_LookupSingle entry = (const GX_LookupSingle)datum;
FT_UShort glyph = *(FT_UShort*)keyval;
if ( glyph < entry->glyph )
return -1;
else if ( entry->glyph < glyph )
return 1;
else
return 0;
}
FT_LOCAL_DEF( GX_LookupResultRec )
gx_LookupTable_lookup ( GX_LookupTable lookup_table,
FT_UShort glyph )
{
GX_LookupResultRec result;
GX_LookupTable_Segment segment_table;
GX_LookupSegment segment;
GX_LookupTable_Single_Table single_table;
GX_LookupSingle entry;
GX_LookupTable_Trimmed_Array trimmed_array;
FT_Long trimmed_index;
void * bs_key = &glyph;
void * bs_base;
size_t bs_n;
size_t bs_size;
int (* bs_cmp)(const void* keyval, const void* datum);
result.firstGlyph = GX_LOOKUP_RESULT_NO_FIRST_GLYPH;
result.value = NULL;
switch ( lookup_table->format )
{
case GX_LOOKUPTABLE_SIMPLE_ARRAY:
if ( glyph < lookup_table->num_glyphs )
result.value = &((lookup_table->fsHeader.simple_array) [glyph]);
break;
case GX_LOOKUPTABLE_SEGMENT_SINGLE:
case GX_LOOKUPTABLE_SEGMENT_ARRAY:
segment_table = lookup_table->fsHeader.segment_generic;
bs_base = segment_table->segments;
bs_n = segment_table->binSrchHeader.nUnits;
bs_size = sizeof (*segment_table->segments);
bs_cmp = lookup_lookup_segment;
segment = ft_bsearch( bs_key, bs_base, bs_n, bs_size, bs_cmp );
if ( segment )
{
result.value = &segment->value;
if ( ( lookup_table->format == GX_LOOKUPTABLE_SEGMENT_ARRAY ) )
result.firstGlyph = segment->firstGlyph;
}
return result;
case GX_LOOKUPTABLE_SINGLE_TABLE:
single_table = lookup_table->fsHeader.single_table;
bs_base = single_table->entries;
bs_n = single_table->binSrchHeader.nUnits;
bs_size = sizeof (*single_table->entries);
bs_cmp = lookup_lookup_single;
entry = ft_bsearch( bs_key, bs_base, bs_n, bs_size, bs_cmp );
if ( entry )
result.value = &(entry->value);
break;
case GX_LOOKUPTABLE_TRIMMED_ARRAY:
trimmed_array = lookup_table->fsHeader.trimmed_array;
if ( glyph < trimmed_array->firstGlyph )
break;
trimmed_index = glyph - trimmed_array->firstGlyph;
if ( trimmed_index < trimmed_array->glyphCount )
result.value = &(trimmed_array->valueArray[trimmed_index]);
break;
}
return result;
}
FT_LOCAL ( FT_Error )
gx_LookupTable_traverse_high ( GX_LookupTable lookup_table,
GX_LookupTable_Glyph_Func func,
FT_Pointer user)
{
FT_Error error;
FT_UShort glyph;
GX_LookupResultRec result;
for ( glyph = 0; glyph < 0xFFFF; glyph++ )
{
result = gx_LookupTable_lookup ( lookup_table, glyph );
if ( result.value == NULL)
continue ;
if (( error = func( glyph, result.value, result.firstGlyph, user ) ))
return error;
}
return FT_Err_Ok;
}
/* END */

125
src/gxlayout/gxlookuptbl.h Normal file
View File

@ -0,0 +1,125 @@
/***************************************************************************/
/* */
/* gxlookuptbl.h */
/* */
/* AAT/TrueTypeGX lookup table related types and functions */
/* (specification) */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXLOOKUPTBL_H__
#define __GXLOOKUPTBL_H__
#include <ft2build.h>
#include FT_INTERNAL_TRUETYPE_TYPES_H
#include "gxtypes.h"
FT_BEGIN_HEADER
typedef FT_Error
(* GX_LookupTable_Generic_Func) ( GX_LookupTable_Format format,
GX_LookupValue value,
FT_Pointer user );
typedef FT_Error
(* GX_LookupTable_Simple_Array_Func) ( GX_LookupTable_Format format,
FT_UShort index,
GX_LookupValue value,
FT_Pointer user );
typedef FT_Error
(* GX_LookupTable_Segment_Func) ( GX_LookupTable_Format format,
FT_UShort lastGlyph,
FT_UShort firstGlyph,
GX_LookupValue value,
FT_Pointer user );
typedef FT_Error
(* GX_LookupTable_Single_Table_Func) ( GX_LookupTable_Format format,
FT_UShort glyph,
GX_LookupValue value,
FT_Pointer user );
typedef FT_Error
(* GX_LookupTable_Trimmed_Array_Func) ( GX_LookupTable_Format format,
FT_UShort index,
FT_UShort firstGlyph,
FT_UShort lastGlyph,
GX_LookupValue value,
FT_Pointer user );
#define GX_LOOKUP_TABLE_FUNC_ZERO {NULL, NULL, NULL, NULL, NULL, NULL}
typedef struct GX_LookupTable_FuncsRec_
{
/* If a function suitable for the lookup format is given, use
it. If not, use `generic_func'. If both a function suitable for
the lookup format and `generic_func' are not given(= NULL), do
nothing */
GX_LookupTable_Generic_Func generic_func;
/* -------------------------------------------------------------- */
GX_LookupTable_Simple_Array_Func simple_array_func;
GX_LookupTable_Segment_Func segment_single_func;
GX_LookupTable_Segment_Func segment_array_func;
GX_LookupTable_Single_Table_Func single_table_func;
GX_LookupTable_Trimmed_Array_Func trimmed_array_func;
} GX_LookupTable_FuncsRec, *GX_LookupTable_Funcs;
typedef struct GX_LookupResultRec_
{
/* `value' is NULL if a value for the glyph cannot be found. */
GX_LookupValue value;
/* `firstGlyph' is given only if the target lookup table
format is Segement array. If the format is other than
Segement array, GX_LOOKUP_RESULT_NO_FIRST_GLYPH is set
to `firstGlyph'. */
#define GX_LOOKUP_RESULT_NO_FIRST_GLYPH -1
FT_Long firstGlyph;
} GX_LookupResultRec, *GX_LookupResult;
typedef FT_Error
(* GX_LookupTable_Glyph_Func) ( FT_UShort glyph,
GX_LookupValue value,
FT_Long firstGlyph,
FT_Pointer user );
FT_LOCAL( FT_Error )
gx_face_load_LookupTable ( GX_Face face,
FT_Stream stream,
GX_LookupTable lookup_table );
FT_LOCAL( void )
gx_LookupTable_free ( GX_LookupTable lookup_table,
FT_Memory memory );
FT_LOCAL ( FT_Error )
gx_LookupTable_traverse_low( GX_LookupTable lookup_table,
GX_LookupTable_Funcs funcs,
FT_Pointer user);
FT_LOCAL ( GX_LookupResultRec )
gx_LookupTable_lookup ( GX_LookupTable lookup_table,
FT_UShort glyph );
FT_LOCAL ( FT_Error )
gx_LookupTable_traverse_high ( GX_LookupTable lookup_table,
GX_LookupTable_Glyph_Func func,
FT_Pointer user);
FT_END_HEADER
#endif /* Not def: __GXLOOKUPTBL_H__ */
/* END */

119
src/gxlayout/gxltypes.h Normal file
View File

@ -0,0 +1,119 @@
/***************************************************************************/
/* */
/* gxltypes.h */
/* */
/* Data types of AAT/TrueTypeGX based layout engine */
/* (specification) */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXLTYPES_H__
#define __GXLTYPES_H__
#include <ft2build.h>
#include FT_INTERNAL_TRUETYPE_TYPES_H
#include FT_INTERNAL_FTL_TYPES_H
#include FT_GXLAYOUT_H
FT_BEGIN_HEADER
typedef enum
{
GXL_ASCENDING = 0,
GXL_DESCENDING = 1
} GXL_Order;
typedef struct GXL_Feature_ExclusiveRec_
{
FT_Bool exclusive;
GXL_Setting setting;
} GXL_Feature_ExclusiveRec, *GXL_Feature_Exclusive;
typedef struct GXL_NameRec_
{
const FT_String * string;
FT_Short index;
} GXL_NameRec, *GXL_Name;
typedef struct GXL_SettingRec_
{
FT_UShort value;
GXL_NameRec name;
GXL_Feature feature;
} GXL_SettingRec; /* *GXL_Setting; */
typedef struct GXL_FeatureRec_
{
GXL_FeaturesRequest request;
FT_UShort value;
GXL_Feature_ExclusiveRec exclusive;
GXL_NameRec name;
FT_UShort nSettings;
GXL_Setting setting;
} GXL_FeatureRec; /* , * GXL_Feature; */
typedef struct GXL_FeaturesRequestRec_
{
FTL_FeaturesRequestRec root;
GXL_Initial_State initial_state;
FT_ULong nFeatures;
GXL_Feature feature;
} GXL_FeaturesRequestRec; /* , *GXL_FeaturesRequest; */
FT_LOCAL ( void )
gxl_features_request_free( GXL_FeaturesRequest request, FT_Memory memory );
FT_LOCAL ( GXL_Setting )
gxl_feature_get_setting_by_value (GXL_Feature feature, FT_UShort value);
FT_LOCAL ( GXL_Feature )
gxl_features_request_get_feature_by_type ( GXL_FeaturesRequest request,
FT_UShort featureType );
FT_LOCAL ( FT_Error )
gxl_get_font ( FT_Face face, FTL_Font * font);
FT_LOCAL ( FTL_EngineType )
gxl_get_engine_type ( FT_Face face );
FT_LOCAL ( FT_Error )
gxl_new_features_request( FT_Face face, FTL_FeaturesRequest * request);
FT_LOCAL ( FT_Error )
gxl_done_features_request( FTL_FeaturesRequest request);
FT_LOCAL ( FT_Error )
gxl_copy_features_request( FTL_FeaturesRequest from,
FTL_FeaturesRequest to);
FT_LOCAL ( FT_UShort )
gxl_get_ligature_caret_count ( FT_Face face,
FT_UShort glyphID );
FT_LOCAL ( FT_UShort )
gxl_get_ligature_caret_division( FT_Face face,
FT_UShort glyphID,
FT_UShort nth );
FT_LOCAL ( FT_Error )
gxl_substitute_glyphs ( FT_Face face,
FTL_FeaturesRequest request,
FTL_Glyphs_Array in,
FTL_Glyphs_Array out );
FT_END_HEADER
#endif /* Not def: __GXLTYPES_H__ */
/* END */

335
src/gxlayout/gxobjs.c Normal file
View File

@ -0,0 +1,335 @@
/***************************************************************************/
/* */
/* gxobjs.c */
/* */
/* AAT/TrueTypeGX objects manager (body). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_TRUETYPE_TAGS_H
#include FT_LIST_H
#include FT_ERRORS_H
#include FT_LAYOUT_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_LAYOUT_H
#include FT_GXLAYOUT_H
#include "gxobjs.h"
#include "gxload.h"
#include "gxerrors.h"
#include "gxdriver.h"
#include "gxaccess.h"
#include "gxltypes.h"
extern const FT_Driver_ClassRec tt_driver_class;
/*************************************************************************/
/* */
/* 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_gxobjs
static FT_Error
gx_face_init( FT_Stream stream,
GX_Face face,
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params );
static FT_Error
gx_font_load ( GX_Face face );
static void
gx_font_done( void * object );
static FT_Module_Interface
gx_module_get_interface ( FT_Module module,
const char* gx_interface );
static FT_Error
gx_face_get_kerning( FT_Face face,
FT_UInt left_glyph,
FT_UInt right_glyph,
FT_Vector* kerning );
static const FT_Service_LayoutRec gx_service_layout =
{
(FTL_Get_Font_Func) gxl_get_font,
(FTL_Get_EngineType_Func) gxl_get_engine_type,
(FTL_New_FeaturesRequest_Func) gxl_new_features_request,
(FTL_Done_FeaturesRequest_Func) gxl_done_features_request,
(FTL_Copy_FeaturesRequest_Func) gxl_copy_features_request,
(FTL_Get_LigatureCaret_Count_Func) gxl_get_ligature_caret_count,
(FTL_Get_LigatureCaret_Division_Func) gxl_get_ligature_caret_division,
(FTL_Substitute_Glyphs_Func) gxl_substitute_glyphs
};
static const FT_ServiceDescRec gx_services[] =
{
{ FT_SERVICE_ID_LAYOUT, &gx_service_layout },
{ NULL, NULL }
};
FT_LOCAL_DEF( FT_Error )
gx_driver_init( GX_Driver driver )
{
FT_Error error;
const void * module_name;
FT_Driver gx_driver_root = &driver->root;
FT_Driver_Class gx_driver_class = gx_driver_root->clazz;
module_name = gx_driver_class->root.module_name;
*gx_driver_class = tt_driver_class;
driver->root.clazz->root.module_name = module_name;
if (( error = ((FT_Module_Class*)gx_driver_class)->module_init( (FT_Module)driver ) ))
return error;
gx_driver_class->init_face = (FT_Face_InitFunc)gx_face_init;
gx_driver_class->get_kerning = gx_face_get_kerning;
((FT_Module_Class*)gx_driver_class)->get_interface = gx_module_get_interface;
return GX_Err_Ok;
}
static FT_Error
gx_face_init( FT_Stream stream,
GX_Face face,
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params )
{
FT_Error error;
/* TODO */
error = tt_driver_class.init_face ( stream, (FT_Face)face, face_index, num_params, params );
if ( error )
goto Exit;
error = gx_font_load ( face );
if ( error )
goto Exit;
Exit:
return error;
}
#define NEW_TABLE(tag) \
do \
{ \
if ( FT_NEW( font->tag ) ) \
goto Exit; \
\
FT_TRACE2 (( "\tloading %s...", #tag )); \
error = gx_table_load(face,stream,tag,font); \
if ( error ) \
{ \
if ( !(face->goto_table( face, TTAG_##tag, stream, 0 )) ) \
FT_TRACE2(("no table\n")); \
else if ( (TTAG_kern == TTAG_##tag) && \
(font->kern->version == 1) ) \
FT_TRACE2(("old kern\n")); \
else \
FT_TRACE2(("failed\n")); \
FT_FREE ( font->tag ); \
} \
else \
{ \
FT_TRACE2(("successful\n")); \
tables[set_index++] = (GX_Table)font->tag; \
} \
} while (0)
#define DONE_TABLE(tag) \
do \
{ \
if ( font->tag ) \
{ \
gx_table_done ( (GX_Table)font->tag, memory ); \
FT_FREE(font->tag); \
} \
} while ( 0 )
static FT_Error
gx_font_load( GX_Face face )
{
FT_Error error;
FT_Stream stream = face->root.stream;
FT_Memory memory = stream->memory;
GXL_Font font;
#define nTABLES 12
GX_Table tables[nTABLES];
FT_Int init_index, set_index = 0;
GXL_FeaturesRequest features_request;
for ( init_index = 0; init_index < nTABLES; init_index++ )
tables[init_index] = NULL;
if ( face->extra.data )
{
error = GX_Err_Busy_Extra_Data;
goto Exit;
}
if ( FT_NEW(font) )
goto Exit;
if (( error = FTL_Font_Init ( (FTL_Font)font, (FT_Face)face ) ))
goto Failure;
NEW_TABLE(feat);
NEW_TABLE(mort);
NEW_TABLE(morx);
NEW_TABLE(trak);
NEW_TABLE(kern);
NEW_TABLE(prop);
NEW_TABLE(lcar);
NEW_TABLE(opbd);
NEW_TABLE(bsln);
NEW_TABLE(fmtx);
NEW_TABLE(fdsc);
NEW_TABLE(just);
NEW_TABLE(fvar);
error = FT_Err_Unknown_File_Format;
if ((( font->mort ) || ( font->morx ))
&& ( font->feat ))
{
face->root.face_flags |= FT_FACE_FLAG_GLYPH_SUBSTITUTION;
error = GX_Err_Ok;
}
if ( font->kern )
{
face->root.face_flags |= FT_FACE_FLAG_KERNING;
error = GX_Err_Ok;
}
if ( error == GX_Err_Ok )
{
face->extra.finalizer = gx_font_done;
face->extra.data = font;
if (( error = FTL_New_FeaturesRequest ( (FT_Face)face,
(FTL_FeaturesRequest*)(&features_request) ) ))
goto Failure;
}
else
goto Failure;
Exit:
return error;
Failure:
for ( ; set_index > 0; set_index--)
{
if ( tables[set_index - 1] )
{
gx_table_done(tables[set_index - 1], memory);
FT_FREE(tables[set_index - 1]);
}
}
FT_FREE(font);
face->extra.finalizer = NULL;
face->extra.data = NULL;
return error;
}
static void
gx_font_done( void * object )
{
GXL_Font font = object;
FT_Face face = font->root.face;
FT_Memory memory = face->driver->root.memory; /* TODO */
DONE_TABLE(mort);
DONE_TABLE(morx);
DONE_TABLE(feat);
DONE_TABLE(trak);
DONE_TABLE(kern);
DONE_TABLE(prop);
DONE_TABLE(bsln);
DONE_TABLE(lcar);
DONE_TABLE(opbd);
DONE_TABLE(fmtx);
DONE_TABLE(fdsc);
DONE_TABLE(just);
DONE_TABLE(fvar);
FTL_Font_Finalize((FTL_Font)font);
FT_FREE(object);
}
static FT_Module_Interface
gx_module_get_interface( FT_Module module,
const char* gx_interface )
{
FT_Module_Interface gx;
gx = ft_service_list_lookup( gx_services, gx_interface );
if ( gx )
return gx;
/* TODO */
if ( tt_driver_class.root.get_interface )
return tt_driver_class.root.get_interface( module, gx_interface );
return NULL;
}
static FT_Error
gx_face_get_kerning( FT_Face face,
FT_UInt left_glyph,
FT_UInt right_glyph,
FT_Vector* kerning )
{
FT_Error error;
FTL_Font font;
GX_Kern kern;
FTL_Direction dir;
FTL_FeaturesRequest request;
kerning->x = 0;
kerning->y = 0;
if (( error = FTL_Get_Font ( face, &font ) ))
return error;
kern = ((GXL_Font)font)->kern;
if ( !kern )
/* Run old kerning handler */
return tt_driver_class.get_kerning ( face, left_glyph, right_glyph, kerning );
FTL_Font_Get_Current_FeaturesRequest( font, &request );
dir = FTL_Get_FeaturesRequest_Direction ( request );
return gx_kern_get_pair_kerning(kern,
left_glyph, right_glyph,
dir,
kerning);
}
/* END */

53
src/gxlayout/gxobjs.h Normal file
View File

@ -0,0 +1,53 @@
/***************************************************************************/
/* */
/* gxobjs.h */
/* */
/* AAT/TrueTypeGX objects manager (specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXOBJS_H__
#define __GXOBJS_H__
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_TRUETYPE_TYPES_H
FT_BEGIN_HEADER
typedef struct GX_DriverRec_
{
FT_DriverRec root;
TT_ExecContext context;
TT_GlyphZoneRec zone;
void* extension_component;
} GX_DriverRec, *GX_Driver;
/*************************************************************************/
/* */
/* Driver functions */
/* */
FT_LOCAL( FT_Error )
gx_driver_init( GX_Driver driver );
FT_END_HEADER
#endif /* __GXOBJS_H__ */
/* END */

765
src/gxlayout/gxstatetbl.c Normal file
View File

@ -0,0 +1,765 @@
/***************************************************************************/
/* */
/* gxstatetbl.c */
/* */
/* AAT/TrueTypeGX state table related types and functions */
/* (body). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_MEMORY_H
#include "gxstatetbl.h"
#include "gxlookuptbl.h"
#include "gxerrors.h"
static FT_Error
gx_StateTable_load_header( GX_Face face,
FT_Stream stream,
GX_StateHeader header )
{
FT_Error error;
const FT_Frame_Field state_header_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE GX_StateHeaderRec
FT_FRAME_START ( 8 ),
FT_FRAME_USHORT ( stateSize ),
FT_FRAME_USHORT ( classTable ),
FT_FRAME_USHORT ( stateArray ),
FT_FRAME_USHORT ( entryTable ),
FT_FRAME_END
};
header->position = FT_STREAM_POS();
return FT_STREAM_READ_FIELDS( state_header_fields, header );
}
static FT_Error
gx_StateTable_load_class_subtable( GX_Face face,
FT_Stream stream,
FT_ULong pos,
GX_ClassSubtable subtable )
{
FT_Error error;
FT_Memory memory = stream->memory;
FT_Byte * classArray;
FT_Int i;
const FT_Frame_Field class_subtable_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE GX_ClassSubtableRec
FT_FRAME_START ( 4 ),
FT_FRAME_USHORT ( firstGlyph ),
FT_FRAME_USHORT ( nGlyphs ),
FT_FRAME_END
};
subtable->classArray = NULL;
if ( FT_STREAM_SEEK(pos) )
goto Exit;
if ( FT_STREAM_READ_FIELDS ( class_subtable_fields, subtable ) )
goto Exit;
if ( FT_NEW_ARRAY ( classArray, subtable->nGlyphs ) )
goto Exit;
if ( FT_FRAME_ENTER( sizeof (classArray[0]) * subtable->nGlyphs ) )
goto Failure;
for ( i = 0; i < subtable->nGlyphs; i++ )
classArray[i] = FT_GET_BYTE();
FT_FRAME_EXIT();
subtable->classArray = classArray;
Exit:
return error;
Failure:
FT_FREE( classArray );
return error;
}
static void
gx_StateTable_free_class_subtable( FT_Memory memory,
GX_ClassSubtable subtable )
{
FT_FREE(subtable->classArray);
subtable->classArray = NULL;
}
static FT_Error
gx_StateTable_load_state_array( GX_Face face,
FT_Stream stream,
FT_ULong pos,
FT_UShort length,
FT_Byte * state_array )
{
FT_Error error;
FT_Int i;
if ( FT_STREAM_SEEK(pos) )
goto Exit;
if ( FT_FRAME_ENTER( sizeof (state_array[0]) * length ) )
goto Exit;
for ( i = 0; i < length; i++ )
state_array[i] = FT_GET_BYTE();
FT_FRAME_EXIT();
Exit:
return error;
}
/* - gx_StateTable_load_entry_subtable
I assume FUNCS is not NULL. Set any kind of dummy in the caller if
necessary.
To support both a state table and an extended state table, the type of nEntries
is FT_ULong. */
static FT_Error
gx_StateTable_load_entry_subtable ( GX_Face face,
FT_Stream stream,
FT_ULong pos,
FT_ULong nEntries,
GX_EntrySubtable entry_subtable,
GX_StateTable_Entry_Load_Funcs funcs,
FT_Pointer user )
{
FT_Error error;
FT_Memory memory = face->root.driver->root.memory;
FT_ULong i, j;
const FT_Frame_Field entry_subtable_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE GX_EntrySubtableRec
FT_FRAME_START ( 4 ),
FT_FRAME_USHORT ( newState ),
FT_FRAME_USHORT ( flags ),
FT_FRAME_END
};
if ( FT_STREAM_SEEK( pos ) )
goto Exit;
for ( i = 0; i < nEntries; i++ )
{
if ( FT_STREAM_READ_FIELDS ( entry_subtable_fields, &entry_subtable[i] ) )
goto Failure;
if (( error = funcs->loader(face, stream, &entry_subtable[i], user) ))
goto Failure;
}
Exit:
return error;
Failure:
for ( j = i; j > 0; j-- )
funcs->finalizer(memory, &entry_subtable[j - 1], user);
return error;
}
static void
gx_StateTable_free_entry_subtable ( FT_Memory memory,
FT_Byte nEntries,
GX_EntrySubtable entry_subtable,
GX_StateTable_Entry_Finalizer finalizer,
FT_Pointer user )
{
FT_Int i;
for ( i = 0; i < nEntries; i++ )
finalizer(memory, &entry_subtable[i], user);
}
static FT_Error
gx_StateTable_Entry_default_loader ( GX_Face face,
FT_Stream stream,
GX_EntrySubtable entry_subtable,
FT_Pointer user )
{
entry_subtable->glyphOffsets.any = NULL;
return GX_Err_Ok;
}
static void
gx_StateTable_Entry_default_finalizer ( FT_Memory memory,
GX_EntrySubtable entry_subtable,
FT_Pointer user )
{
/* Do nothing */;
}
static FT_Byte
gx_StateTable_find_state_array_max_index (FT_UShort array_length, FT_Byte state_array[])
{
FT_Int i;
FT_Byte max_index = 0;
for ( i = 0; i < array_length; i++ )
{
/* fprintf(stderr, "->%u\n", state_array[i]); */
if ( state_array[i] > max_index )
max_index = state_array [i];
}
return max_index;
}
FT_LOCAL_DEF ( FT_Error )
gx_face_load_StateTable ( GX_Face face,
FT_Stream stream,
GX_StateTable state_table,
GX_StateTable_Entry_Load_Funcs funcs,
FT_Pointer user )
{
FT_Error error;
FT_Memory memory = stream->memory;
GX_StateHeader header;
GX_ClassSubtable class_subtable;
FT_Byte * state_array = NULL;
FT_UShort state_array_len;
GX_EntrySubtable entry_subtable = NULL;
FT_ULong pos;
GX_StateTable_Entry_Load_FuncsRec default_funcs = GX_STATE_TABLE_ENTRY_LOAD_FUNCS_ZERO;
default_funcs.loader = gx_StateTable_Entry_default_loader;
default_funcs.finalizer = gx_StateTable_Entry_default_finalizer;
state_table->state_array = NULL;
state_table->entry_subtable = NULL;
/* 1. Header */
header = &state_table->header;
if (( error = gx_StateTable_load_header( face, stream,
header ) ))
goto Exit;
/* 2. class subtable */
pos = header->position + header->classTable;
class_subtable = &state_table->class_subtable;
if (( error = gx_StateTable_load_class_subtable( face,
stream,
pos,
class_subtable ) ))
goto Exit;
/* 3. state array */
/* To calculate the length of stateArray, we assume
the order of fields placement is classTable, stateArray,
entryTable */
FT_ASSERT( header->classTable < header->stateArray );
FT_ASSERT( header->stateArray < header->entryTable );
pos = header->position + header->stateArray;
state_array_len = header->entryTable - header->stateArray;
state_table->nStates = state_array_len / header->stateSize;
/* Calculate state_array_len again.
state_array_len must be a multiple of header->stateSize. */
state_array_len = state_table->nStates * header->stateSize;
if (( FT_NEW_ARRAY ( state_array, state_array_len ) ))
goto Failure;
if (( error = gx_StateTable_load_state_array( face,
stream,
pos,
state_array_len,
state_array ) ))
goto Failure;
/* 4. entry subtable */
if ( funcs )
{
if (! funcs->loader )
funcs->loader = gx_StateTable_Entry_default_loader;
if (! funcs->finalizer )
funcs->finalizer = gx_StateTable_Entry_default_finalizer;
}
else
funcs = &default_funcs;
pos = header->position + header->entryTable;
/* gx_StateTable_find_state_array_max_index returns the max index into an array
which starts from 0. By adding 1 to the max index, get the length of the array. */
state_table->nEntries = 1+ gx_StateTable_find_state_array_max_index(state_array_len,
state_array);
if (( FT_NEW_ARRAY( entry_subtable, state_table->nEntries) ))
goto Failure;
if (( error = gx_StateTable_load_entry_subtable( face,
stream,
pos,
state_table->nEntries,
entry_subtable,
funcs,
user) ))
goto Failure;
state_table->state_array = state_array;
state_table->entry_subtable = entry_subtable;
Exit:
return error;
Failure:
if ( entry_subtable )
FT_FREE ( entry_subtable );
if ( state_array )
FT_FREE(state_array);
gx_StateTable_free_class_subtable (memory, class_subtable);
return error;
}
FT_LOCAL_DEF ( void )
gx_StateTable_free ( GX_StateTable state_table,
FT_Memory memory,
GX_StateTable_Entry_Finalizer finalizer,
FT_Pointer user )
{
if ( finalizer == NULL )
finalizer = gx_StateTable_Entry_default_finalizer;
gx_StateTable_free_entry_subtable ( memory,
state_table->nEntries,
state_table->entry_subtable,
finalizer,
user );
FT_FREE( state_table->entry_subtable );
state_table->entry_subtable = NULL;
FT_FREE( state_table->state_array );
state_table->state_array = NULL;
gx_StateTable_free_class_subtable( memory, &state_table->class_subtable );
}
static FT_Error
gx_EntrySubtable_traverse( GX_EntrySubtable entries,
FT_Long nEntries,
GX_StateTable_Entry_Action action,
FT_Pointer user )
{
FT_Error error = GX_Err_Ok;
FT_Int i;
if (!action)
return error;
for ( i = 0; i < nEntries; i++ )
{
error = action( &entries[i], user );
if ( error )
return error;
}
return error;
}
#if 0
FT_LOCAL_DEF ( FT_Error )
gx_StateTable_traverse_entries( GX_StateTable state_table,
GX_StateTable_Entry_Action action,
FT_Pointer user )
{
return gx_EntrySubtable_traverse( state_table->entry_subtable,
state_table->nEntries,
action,
user );
}
#endif /* 0 */
FT_LOCAL_DEF ( FT_Byte )
gx_StateTable_get_class ( GX_StateTable state_table,
FT_UShort glyph )
{
GX_ClassSubtable class_subtable;
FT_Byte class_code;
FT_UShort first_glyph, last_glyph;
class_subtable = &state_table->class_subtable;
first_glyph = class_subtable->firstGlyph;
last_glyph = first_glyph + class_subtable->nGlyphs;
if ( glyph == GX_DELETED_GLYPH_INDEX )
class_code = GX_CLASS_DELETED_GLYPH;
else if ( ( first_glyph <= glyph ) && ( glyph < last_glyph ) )
class_code = class_subtable->classArray[glyph - first_glyph];
else
class_code = GX_CLASS_OUT_OF_BOUNDS;
return class_code;
}
FT_LOCAL_DEF ( GX_EntrySubtable )
gx_StateTable_get_entry_subtable ( GX_StateTable state_table,
FT_UShort current_state,
FT_Byte class_code )
{
GX_StateHeader header = &state_table->header;
FT_Byte * state_array = state_table->state_array;
GX_EntrySubtable entry_subtable = state_table->entry_subtable;
FT_Byte * state_array_for_current_state;
FT_Byte entry_index;
state_array_for_current_state = &state_array[current_state - header->stateArray];
entry_index = state_array_for_current_state[class_code];
return &entry_subtable[entry_index];
}
/*
* Extended State Table
*/
#define gx_XStateTable_load_entry_subtable gx_StateTable_load_entry_subtable
#define gx_XStateTable_free_entry_subtable gx_StateTable_free_entry_subtable
#define gx_XStateTable_Entry_default_loader gx_StateTable_Entry_default_loader
#define gx_XStateTable_Entry_default_finalizer gx_StateTable_Entry_default_finalizer
#define gx_XStateTable_Entry_default_finalizer gx_StateTable_Entry_default_finalizer
static FT_Error
gx_XStateTable_load_header( GX_Face face,
FT_Stream stream,
GX_XStateHeader header )
{
FT_Error error;
const FT_Frame_Field xstate_header_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE GX_XStateHeaderRec
FT_FRAME_START ( 16 ),
FT_FRAME_ULONG( nClasses ),
FT_FRAME_ULONG( classTableOffset ),
FT_FRAME_ULONG( stateArrayOffset ),
FT_FRAME_ULONG( entryTableOffset ),
FT_FRAME_END
};
header->position = FT_STREAM_POS();
return FT_STREAM_READ_FIELDS( xstate_header_fields, header );
}
static FT_Error
gx_XStateTable_load_state_array( GX_Face face,
FT_Stream stream,
FT_ULong pos,
FT_ULong length,
FT_UShort* state_array )
{
FT_Error error;
FT_Int i;
if ( FT_STREAM_SEEK(pos) )
goto Exit;
if ( FT_FRAME_ENTER( sizeof (state_array[0]) * length ) )
goto Exit;
for ( i = 0; i < length; i++ )
state_array[i] = FT_GET_USHORT();
FT_FRAME_EXIT();
Exit:
return error;
}
static FT_UShort
gx_XStateTable_find_state_array_max_index (FT_ULong array_length, FT_UShort state_array[])
{
FT_ULong i;
FT_UShort max_index = 0;
for ( i = 0; i < array_length; i++ )
{
if ( state_array[i] > max_index )
max_index = state_array [i];
}
return max_index;
}
#define LOOKUP_TABLE_CB_DATA_ZERO {NULL, NULL}
typedef struct lookup_table_cb_data_rec_
{
FT_Stream stream;
GX_LookupTable lookup_table;
FT_Long table_end;
} lookup_table_cb_data_rec, *lookup_table_cb_data;
static FT_Error
gx_XStateTable_LookupTable_segment_array_loader( GX_LookupTable_Format format,
FT_UShort lastGlyph,
FT_UShort firstGlyph,
GX_LookupValue value,
FT_Pointer user )
{
/* generic_lookup_table_segment_array_loader */
FT_Error error;
lookup_table_cb_data lookup_data = user;
FT_Stream stream = lookup_data->stream;
GX_LookupTable lookup_table = lookup_data->lookup_table;
FT_Memory memory = stream->memory;
FT_Short value_offset = value->raw.s;
FT_UShort segment_count = lastGlyph - firstGlyph + 1;
FT_UShort * segment;
FT_Int i;
/* -----------------------------------------------------------------
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
* This code is correct?
* In spec: "Sometimes they are 16-bit offsets from the start of
* the table to the data. " The table? Is the table the lookup table
* or a table that uses the lookup table?
* Here I assume the table is the table that uses the lookup table.
* However, I have no conviction.
* It seems that pfaedit uses lookup_table_offset + value_offset.
* ----------------------------------------------------------------- */
FT_ASSERT(lookup_table->position + value_offset < lookup_data->table_end);
if (FT_STREAM_SEEK( lookup_table->position + value_offset ) )
goto Exit;
if ( FT_NEW_ARRAY(segment, segment_count ) )
goto Exit;
if ( FT_FRAME_ENTER ( sizeof( segment[0] ) * segment_count ) )
goto Failure;
for ( i = 0; i < segment_count; i++ )
segment[i] = FT_GET_USHORT();
FT_FRAME_EXIT();
value->extra.word = segment;
Exit:
return error;
Failure:
/* TODO
Other value->extra.wordS loaded before the visitation to this
value->extra.word must be freed if an error is occurred during
traverse. */
FT_FREE(segment);
return error;
}
FT_LOCAL_DEF ( FT_Error )
gx_face_load_XStateTable ( GX_Face face,
FT_Stream stream,
GX_XStateTable state_table,
GX_XStateTable_Entry_Load_Funcs funcs,
FT_Pointer user )
{
FT_Error error;
FT_Memory memory = stream->memory;
GX_XStateHeader header;
FT_ULong state_array_len; /* in word */
FT_UShort * state_array = NULL;
GX_EntrySubtable entry_subtable = NULL;
FT_ULong pos;
GX_XStateTable_Entry_Load_FuncsRec default_XStateTable_funcs = GX_XSTATE_TABLE_ENTRY_LOAD_FUNCS_ZERO;
GX_LookupTable_FuncsRec default_LookupTable_funcs = GX_LOOKUP_TABLE_FUNC_ZERO;
lookup_table_cb_data_rec lookup_table_cb_data = LOOKUP_TABLE_CB_DATA_ZERO;
default_XStateTable_funcs.loader = gx_XStateTable_Entry_default_loader;
default_XStateTable_funcs.finalizer = gx_XStateTable_Entry_default_finalizer;
default_LookupTable_funcs.segment_array_func = gx_XStateTable_LookupTable_segment_array_loader;
state_table->state_array = NULL;
state_table->entry_subtable = NULL;
/* 1. Header */
header = &state_table->header;
if (( error = gx_XStateTable_load_header( face, stream, header ) ))
goto Exit;
/* 2. class subtable */
pos = header->position + header->classTableOffset;
if ( FT_STREAM_SEEK( pos ) )
goto Exit;
if (( error = gx_face_load_LookupTable( face,
stream,
&state_table->class_subtable ) ))
goto Exit;
if ( state_table->class_subtable.format == GX_LOOKUPTABLE_SEGMENT_ARRAY )
{
lookup_table_cb_data.stream = stream;
lookup_table_cb_data.lookup_table = &state_table->class_subtable;
lookup_table_cb_data.table_end = header->position + header->stateArrayOffset;
if (( error = gx_LookupTable_traverse_low( & state_table->class_subtable,
& default_LookupTable_funcs,
& lookup_table_cb_data ) ))
goto Failure;
}
/* 3. state array */
/* To calculate the length of stateArray, we assume
the order of fields placement is classTable, stateArray,
entryTable */
FT_ASSERT( header->classTableOffset < header->stateArrayOffset );
FT_ASSERT( header->stateArrayOffset < header->entryTableOffset );
pos = header->position + header->stateArrayOffset;
state_array_len = (header->entryTableOffset - header->stateArrayOffset) / sizeof( state_array[0] );
state_table->nStates = state_array_len / header->nClasses;
/* Calculate state_array_len again.
state_array_len must be a multiple of header->nClasses. */
state_array_len = state_table->nStates * header->nClasses;
if (( FT_NEW_ARRAY ( state_array, state_array_len ) ))
goto Failure;
if (( error = gx_XStateTable_load_state_array( face,
stream,
pos,
state_array_len,
state_array ) ))
goto Failure;
/* 4. entry subtable */
if ( funcs )
{
if (! funcs->loader )
funcs->loader = gx_XStateTable_Entry_default_loader;
if (! funcs->finalizer )
funcs->finalizer = gx_XStateTable_Entry_default_finalizer;
}
else
funcs = &default_XStateTable_funcs;
pos = header->position + header->entryTableOffset;
state_table->nEntries = 1+ gx_XStateTable_find_state_array_max_index( state_array_len,
state_array );
if (( FT_NEW_ARRAY( entry_subtable, state_table->nEntries) ))
goto Failure;
if (( error = gx_XStateTable_load_entry_subtable( face,
stream,
pos,
state_table->nEntries,
entry_subtable,
funcs,
user) ))
goto Failure;
state_table->state_array = state_array;
state_table->entry_subtable = entry_subtable;
Exit:
return error;
Failure:
if ( entry_subtable )
FT_FREE ( entry_subtable );
if ( state_array )
FT_FREE(state_array);
gx_LookupTable_free( & state_table->class_subtable, memory );
return error;
}
FT_LOCAL_DEF ( FT_Error )
gx_XStateTable_traverse_entries( GX_XStateTable state_table,
GX_XStateTable_Entry_Action action,
FT_Pointer user )
{
return gx_EntrySubtable_traverse( state_table->entry_subtable,
state_table->nEntries,
action,
user );
}
static FT_Error
gx_XStateTable_LookupTable_segment_array_finalizer ( GX_LookupTable_Format format,
FT_UShort lastGlyph,
FT_UShort firstGlyph,
GX_LookupValue value,
FT_Pointer user )
{
/* TODO: Merge generic_lookup_table_segment_array_finalizer */
FT_Memory memory = user;
FT_UShort * segment = value->extra.word;
if ( !segment )
return GX_Err_Ok;
value->extra.word = NULL;
FT_FREE(segment);
return GX_Err_Ok;
}
FT_LOCAL_DEF ( void )
gx_XStateTable_free ( GX_XStateTable state_table,
FT_Memory memory,
GX_XStateTable_Entry_Finalizer finalizer,
FT_Pointer user )
{
GX_LookupTable_FuncsRec lookup_table_funcs = GX_LOOKUP_TABLE_FUNC_ZERO;
lookup_table_funcs.segment_array_func = gx_XStateTable_LookupTable_segment_array_finalizer;
if ( finalizer == NULL )
finalizer = gx_StateTable_Entry_default_finalizer;
gx_XStateTable_free_entry_subtable ( memory,
state_table->nEntries,
state_table->entry_subtable,
finalizer,
user );
FT_FREE( state_table->entry_subtable );
state_table->entry_subtable = NULL;
FT_FREE( state_table->state_array );
state_table->state_array = NULL;
if ( state_table->class_subtable.format == GX_LOOKUPTABLE_SEGMENT_ARRAY )
gx_LookupTable_traverse_low( & state_table->class_subtable,
&lookup_table_funcs,
memory );
gx_LookupTable_free( & state_table->class_subtable, memory );
}
FT_LOCAL_DEF ( FT_UShort )
gx_XStateTable_get_class ( GX_XStateTable state_table,
FT_UShort glyph )
{
GX_LookupTable class_subtable;
GX_LookupResultRec result;
FT_UShort class_code;
class_subtable = &state_table->class_subtable;
result = gx_LookupTable_lookup ( class_subtable,
glyph );
if ( result.value == NULL )
class_code = GX_CLASS_OUT_OF_BOUNDS;
else if ( result.firstGlyph == GX_LOOKUP_RESULT_NO_FIRST_GLYPH )
class_code = result.value->raw.u;
else
class_code = result.value->extra.word[glyph - result.firstGlyph];
return class_code;
}
FT_LOCAL ( GX_EntrySubtable )
gx_XStateTable_get_entry_subtable ( GX_XStateTable state_table,
FT_UShort current_state,
FT_UShort class_code )
{
GX_XStateHeader header = &state_table->header;
FT_UShort * state_array = state_table->state_array;
FT_UShort * state_array_for_current_state;
FT_UShort entry_index;
GX_EntrySubtable entry_subtable;
FT_ASSERT( current_state < state_table->nStates );
FT_ASSERT( class_code < header->nClasses );
state_array_for_current_state = &state_array[current_state * header->nClasses];
entry_index = state_array_for_current_state[class_code];
FT_ASSERT( entry_index < state_table->nEntries );
entry_subtable = &state_table->entry_subtable[entry_index];
return entry_subtable;
}
/* END */

128
src/gxlayout/gxstatetbl.h Normal file
View File

@ -0,0 +1,128 @@
/***************************************************************************/
/* */
/* gxstatetbl.h */
/* */
/* AAT/TrueTypeGX state table related types and functions */
/* (specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXSTATETBL_H_
#define __GXSTATETBL_H_
#include <ft2build.h>
#include FT_TYPES_H
#include "gxtypes.h"
FT_BEGIN_HEADER
/* - GX_StateTable_Entry_Loader
Fill entry_subtable->glyphOffsets and
update stream to read next entry_subtable. */
typedef FT_Error
(* GX_StateTable_Entry_Loader) ( GX_Face face,
FT_Stream stream,
GX_EntrySubtable entry_subtable,
FT_Pointer user );
typedef void
(* GX_StateTable_Entry_Finalizer) ( FT_Memory memory,
GX_EntrySubtable entry_subtable,
FT_Pointer user );
typedef FT_Error
(* GX_StateTable_Entry_Action) ( GX_EntrySubtable entry_subtable,
FT_Pointer user );
#define GX_STATE_TABLE_ENTRY_LOAD_FUNCS_ZERO {NULL, NULL}
typedef struct GX_StateTable_Entry_Load_FuncsRec_
{
GX_StateTable_Entry_Loader loader;
GX_StateTable_Entry_Finalizer finalizer;
} GX_StateTable_Entry_Load_FuncsRec, *GX_StateTable_Entry_Load_Funcs;
FT_LOCAL ( FT_Error )
gx_face_load_StateTable ( GX_Face face,
FT_Stream stream,
GX_StateTable state_table,
GX_StateTable_Entry_Load_Funcs funcs,
FT_Pointer user );
FT_LOCAL ( void )
gx_StateTable_free ( GX_StateTable state_table,
FT_Memory memory,
GX_StateTable_Entry_Finalizer finalizer,
FT_Pointer user );
/* If action returns value other than FT_Err_Ok, the traverse stops
at that point and returns. */
#if 0
FT_LOCAL ( FT_Error )
gx_StateTable_traverse_entries( GX_StateTable state_table,
GX_StateTable_Entry_Action action,
FT_Pointer user );
#endif /* 0 */
FT_LOCAL ( FT_Byte )
gx_StateTable_get_class ( GX_StateTable state_table,
FT_UShort glyph );
FT_LOCAL ( GX_EntrySubtable )
gx_StateTable_get_entry_subtable ( GX_StateTable state_table,
FT_UShort current_state,
FT_Byte class_code );
#define GX_XSTATE_TABLE_ENTRY_LOAD_FUNCS_ZERO {NULL, NULL}
typedef GX_StateTable_Entry_Load_FuncsRec GX_XStateTable_Entry_Load_FuncsRec;
typedef GX_StateTable_Entry_Load_Funcs GX_XStateTable_Entry_Load_Funcs;
typedef GX_StateTable_Entry_Loader GX_XStateTable_Entry_Loader;
typedef GX_StateTable_Entry_Finalizer GX_XStateTable_Entry_Finalizer;
typedef GX_StateTable_Entry_Action GX_XStateTable_Entry_Action;
FT_LOCAL ( FT_Error )
gx_face_load_XStateTable ( GX_Face face,
FT_Stream stream,
GX_XStateTable state_table,
GX_XStateTable_Entry_Load_Funcs funcs,
FT_Pointer user );
FT_LOCAL ( FT_Error )
gx_XStateTable_traverse_entries( GX_XStateTable state_table,
GX_XStateTable_Entry_Action action,
FT_Pointer user );
FT_LOCAL ( void )
gx_XStateTable_free ( GX_XStateTable state_table,
FT_Memory memory,
GX_XStateTable_Entry_Finalizer finalizer,
FT_Pointer user );
FT_LOCAL ( FT_UShort )
gx_XStateTable_get_class ( GX_XStateTable state_table,
FT_UShort glyph );
FT_LOCAL ( GX_EntrySubtable )
gx_XStateTable_get_entry_subtable ( GX_XStateTable state_table,
FT_UShort current_state,
FT_UShort class_code );
FT_END_HEADER
#endif /* Not def: __GXSTATETBL_H_ */
/* END */

1238
src/gxlayout/gxtypes.h Normal file

File diff suppressed because it is too large Load Diff

129
src/gxlayout/gxutils.c Normal file
View File

@ -0,0 +1,129 @@
/***************************************************************************/
/* */
/* gxutils.c */
/* */
/* AAT/TrueTypeGX private utility functions (body). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include "gxerrors.h"
#include "gxutils.h"
#include "gxobjs.h"
FT_LOCAL_DEF( FT_Int )
gx_zero_shift_bits ( FT_ULong mask )
{
FT_Int i = 0;
for ( i = 0; !(mask & (0x1L << i)); i++)
; /* Do nothing */
return i;
}
FT_LOCAL_DEF( FT_Long )
gx_mask_zero_shift ( FT_ULong value, FT_ULong mask )
{
FT_Int shift_bits = gx_zero_shift_bits( mask );
return ((value & mask) >> shift_bits);
}
FT_LOCAL_DEF( FT_Long )
gx_sign_extend ( FT_ULong value, FT_ULong mask )
{
/* Copied from icu/source/layout/LigatureSubstProc.cpp */
#define ExtendedComplement(m) ((FT_Long) (~((FT_ULong) (m))))
#define SignBit(m) ((ExtendedComplement(m) >> 1) & (m))
#define SignExtend(v,m) (((v) & SignBit(m))? ((v) | ExtendedComplement(m)): (v))
return SignExtend(value,mask);
}
/* Generic */
FT_LOCAL_DEF( FT_Error )
gx_get_name_from_id ( FT_Face face,
FT_UShort name_id,
FT_UShort platform_id,
FT_UShort encoding_id,
FT_UShort language_id,
FT_SfntName *aname )
{
FT_Int i;
FT_UInt nnames = FT_Get_Sfnt_Name_Count ((FT_Face)face);
FT_Bool any_id = ( (platform_id == 0) &&
(encoding_id == 0) &&
(language_id == 0) )? 1: 0;
for ( i = 0; i < nnames; i++ )
{
if ( FT_Get_Sfnt_Name((FT_Face)face, i, aname) )
continue ;
if ( ( aname->name_id == name_id ) &&
( any_id ||
( ( aname->platform_id == platform_id ) &&
( aname->encoding_id == encoding_id ) &&
( aname->language_id == language_id ) )))
return GX_Err_Ok;
}
return GX_Err_Invalid_Argument;
}
FT_LOCAL_DEF ( FT_UShort )
gx_feat_setting_on ( FT_UShort setting )
{
if ( !gx_feat_setting_state ( setting ) )
return setting -1;
else
return setting;
}
FT_LOCAL_DEF ( FT_UShort )
gx_feat_setting_off ( FT_UShort setting )
{
if ( gx_feat_setting_state ( setting ) )
return setting + 1;
else
return setting;
}
FT_LOCAL_DEF ( FT_Bool )
gx_feat_setting_state ( FT_UShort setting )
{
/* odd => off */
if ( setting % 2 )
return 0; /* odd => off */
else
return 1; /* even => on */
}
FT_LOCAL_DEF ( void )
gx_glyphs_array_reverse( FTL_Glyph glyphs, FT_ULong length )
{
FT_ULong i, j;
FTL_GlyphRec tmp;
for ( i = 0, j = length -1; i < j; i++, j-- )
{
tmp = glyphs[i];
glyphs[i] = glyphs[j];
glyphs[j] = tmp;
}
}
/* END */

73
src/gxlayout/gxutils.h Normal file
View File

@ -0,0 +1,73 @@
/***************************************************************************/
/* */
/* gxutils.h */
/* */
/* AAT/TrueTypeGX private utility functions (specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GXUTILS_H__
#define __GXUTILS_H__
#include <ft2build.h>
#include FT_TYPES_H
#include FT_SFNT_NAMES_H
#include FT_LAYOUT_H
FT_BEGIN_HEADER
FT_LOCAL( FT_Int ) gx_zero_shift_bits ( FT_ULong mask );
FT_LOCAL( FT_Long ) gx_mask_zero_shift ( FT_ULong value,
FT_ULong mask );
FT_LOCAL( FT_Long ) gx_sign_extend ( FT_ULong value,
FT_ULong mask );
FT_LOCAL( FT_Error ) gx_get_name_from_id ( FT_Face face,
FT_UShort name_id,
FT_UShort platform_id,
FT_UShort encoding_id,
FT_UShort language_id,
FT_SfntName *aname );
FT_LOCAL( FT_UShort ) gx_feat_setting_on ( FT_UShort setting );
FT_LOCAL( FT_UShort ) gx_feat_setting_off ( FT_UShort setting );
FT_LOCAL( FT_Bool ) gx_feat_setting_state ( FT_UShort setting );
FT_LOCAL ( void ) gx_glyphs_array_reverse ( FTL_Glyph glyphs,
FT_ULong length );
#ifdef FT_DEBUG_LEVEL_ERROR
#define GX_ASSERT_NOT_REACHED() \
do \
{ \
FT_Panic( "should not be reached to line %d of file %s\n", \
__LINE__, __FILE__ ); \
} while ( 0 )
#else /* !FT_DEBUG_LEVEL_ERROR */
#define GX_ASSERT_NOT_REACHED() do ; while ( 0 )
#endif /* !FT_DEBUG_LEVEL_ERROR */
FT_END_HEADER
#endif /* Not def: __GXUTILS_H__ */
/* END */

1794
src/gxlayout/gxvm.c Normal file

File diff suppressed because it is too large Load Diff

99
src/gxlayout/gxvm.h Normal file
View File

@ -0,0 +1,99 @@
/***************************************************************************/
/* */
/* gxvm.h */
/* */
/* AAT/TrueTypeGX glyph substitution automaton (specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __GX_VM_H__
#define __GX_VM_H__
#include <ft2build.h>
#include FT_FREETYPE_H
#include "gxtypes.h"
FT_BEGIN_HEADER
/*
* Mort
*/
FT_LOCAL( FT_Error )
gx_rearrangement_subst ( GX_MetamorphosisRearrangementBody body,
GXL_Initial_State initial_state,
FTL_Glyphs_Array garray );
FT_LOCAL( FT_Error )
gx_contextual_subst( GX_MetamorphosisContextualBody body,
GXL_Initial_State initial_state,
FTL_Glyphs_Array garray );
FT_LOCAL( FT_Error )
gx_ligature_subst( GX_MetamorphosisLigatureBody body,
GXL_Initial_State initial_state,
FTL_Glyphs_Array garray );
FT_LOCAL( FT_Error )
gx_noncontextual_subst( GX_MetamorphosisNoncontextualBody body,
FTL_Glyphs_Array garray );
FT_LOCAL( FT_Error )
gx_insertion_subst( GX_MetamorphosisInsertionBody body,
GXL_Initial_State initial_state,
FTL_Glyphs_Array garray );
/*
* Morx
*/
#define gx_xnoncontextual_subst gx_noncontextual_subst
FT_LOCAL( FT_Error )
gx_xcontextual_subst( GX_XMetamorphosisContextualBody body,
GXL_Initial_State initial_state,
FTL_Glyphs_Array garray );
FT_LOCAL( FT_Error )
gx_xligature_subst( GX_XMetamorphosisLigatureBody body,
GXL_Initial_State initial_state,
FTL_Glyphs_Array garray );
FT_LOCAL( FT_Error )
gx_xinsertion_subst( GX_XMetamorphosisInsertionBody body,
GXL_Initial_State initial_state,
FTL_Glyphs_Array garray );
FT_LOCAL( FT_Error )
gx_xrearrangement_subst ( GX_XMetamorphosisRearrangementBody body,
GXL_Initial_State initial_state,
FTL_Glyphs_Array garray );
/*
* Kern
*/
FT_LOCAL( FT_Error )
gx_contextual_kerning_calc ( GX_KerningSubtableFormat1Body kern_fmt1,
FTL_Glyphs_Array garray,
FTL_Direction dir,
FT_Bool cross_stream,
GXL_Initial_State initial_state,
FT_Vector * kerning );
FT_END_HEADER
#endif /* Not def: __GX_VM_H__ */
/* END */

33
src/gxlayout/module.mk Normal file
View File

@ -0,0 +1,33 @@
#
# FreeType 2 AAT/TrueTypeGX module definition
#
# Copyright 2004 by RedHat K.K.
# This file is derived from cff/module.mk.
# ----------------------------------------------------------------------
#
# FreeType 2 CFF module definition
#
# Copyright 1996-2000 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.
# ----------------------------------------------------------------------
# Development of the code in module.mk is support of
# Information-technology Promotion Agency, Japan.
make_module_list: add_gx_driver
add_gx_driver:
$(OPEN_DRIVER)gx_driver_class$(CLOSE_DRIVER)
$(ECHO_DRIVER)gx $(ECHO_DRIVER_DESC)AAT/TrueTypeGX fonts$(ECHO_DRIVER_DONE)
# EOF

96
src/gxlayout/rules.mk Normal file
View File

@ -0,0 +1,96 @@
#
# FreeType 2 AAT/TrueTypeGX driver configuration rules
#
# Copyright 2004 by RedHat K.K.
# This file is derived from cff/rules.mk.
# ----------------------------------------------------------------------
#
# FreeType 2 OpenType/CFF driver configuration rules
#
# Copyright 1996-2000, 2001, 2003 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.
# ----------------------------------------------------------------------
# Development of the code in rules.mk is support of
# Information-technology Promotion Agency, Japan.
# AAT/TrueTypeGX driver directory
#
GX_DIR := $(SRC_DIR)/gxlayout
GX_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(GX_DIR))
# GX driver sources (i.e., C files)
#
GX_DRV_SRC := $(GX_DIR)/gxobjs.c \
$(GX_DIR)/gxload.c \
$(GX_DIR)/gxdriver.c \
$(GX_DIR)/gxlookuptbl.c \
$(GX_DIR)/gxstatetbl.c \
$(GX_DIR)/gxutils.c \
$(GX_DIR)/gxlayout.c \
$(GX_DIR)/gxfeatreg.c \
$(GX_DIR)/gxlfeatreg.c \
$(GX_DIR)/gxaccess.c \
$(GX_DIR)/gxvm.c \
$(GX_DIR)/gxdump.c
# GX driver headers
#
GX_DRV_H := $(GX_DIR)/gxdriver.h \
$(GX_DIR)/gxload.h \
$(GX_DIR)/gxlookuptbl.h \
$(GX_DIR)/gxobjs.h \
$(GX_DIR)/gxstatetbl.h \
$(GX_DIR)/gxutils.h \
$(GX_DIR)/gxfeatreg.h \
$(GX_DIR)/gxlfeatreg.h \
$(GX_DIR)/gxaccess.h \
$(GX_DIR)/gxerrors.h \
$(GX_DIR)/gxvm.h \
$(GX_DIR)/gxdump.h
# GX driver object(s)
#
# GX_DRV_OBJ_M is used during `multi' builds
# GX_DRV_OBJ_S is used during `single' builds
#
GX_DRV_OBJ_M := $(GX_DRV_SRC:$(GX_DIR)/%.c=$(OBJ_DIR)/%.$O)
GX_DRV_OBJ_S := $(OBJ_DIR)/gx.$O
# GX driver source file for single build
#
GX_DRV_SRC_S := $(GX_DIR)/gx.c
# GX driver - single object
#
$(GX_DRV_OBJ_S): $(GX_DRV_SRC_S) $(GX_DRV_SRC) $(FREETYPE_H) $(GX_DRV_H)
$(GX_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(GX_DRV_SRC_S))
# GX driver - multiple objects
#
$(OBJ_DIR)/%.$O: $(GX_DIR)/%.c $(FREETYPE_H) $(GX_DRV_H)
$(GX_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
# update main driver object lists
#
DRV_OBJS_S += $(GX_DRV_OBJ_S)
DRV_OBJS_M += $(GX_DRV_OBJ_M)
# EOF

145
src/otlayout/README Normal file
View File

@ -0,0 +1,145 @@
This directory contains new otlayout, opentype adapter for ftlayout
interface. Old otlayout is developed by FreeType developers and not
completed yet. This new otlayout is not completed but works.
New otlayout supports only gsub table. the glyph substitution for
Japanese vertical layout is tested. gpos table is not supported.
The languages other than Japanese is not tested yet by us.
The files in this directory are come from different places.
1. FreeType1/TrueTypeOpen support (via pango)
2. Pango/opentype
3. developed at RedHat K.K. supported by Information Technology Promotion Agency, Japan.
4. glib/gunicode.h
5. freetype2/otlayout(old otlayout) directory in FreeType CVS repository
The files in 5. are not used in new otlayout.
This new otlayout is experimental in all aspects.
One of the biggest issue is that the symbols coming from 1.
and 2. have global scope; you cannot link gtk/pango library
with new otlayout. The symbol may be conflicted.
1. The file coming from FreeType1/TrueTypeOpen support (via pango)
------------------------------------------------------------------------
* Copyright 1996-2000 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.
ftxgdef.c
ftxgdef.h
ftxgpos.c
ftxgpos.h
ftxgsub.c
ftxgsub.h
ftxopen.c
ftxopen.h
ftxopenf.h
2. The file coming from Pango/opentype
------------------------------------------------------------------------
* Copyright (C) 2003 Red Hat, Inc
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
ot-array.c
ot-array.h
ot-info.c
ot-info.h
ot-ruleset.c
ot-ruleset.h
ot-types.h
3. The file developed at RedHat K.K. supported by IPA
------------------------------------------------------------------------
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
ot.c
otdriver.c
otdriver.h
oterrors.h
otlayout.c
otobjs.c
otobjs.h
otltypes.h
substmain.c
rules.mk
otdemo.c
demo.mk
4. glib/gunicode.h
------------------------------------------------------------------------
* Copyright (C) 1999, 2000 Tom Tromey
* Copyright 2000 Red Hat, Inc.
*
* The Gnome Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The Gnome Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
ot-unicode.c
ot-unicode.h
5. The file coming from old otlayout
------------------------------------------------------------------------
otlayout.h
otlbase.c
otlbase.h
otlcommn.c
otlcommn.h
otlconf.h
otlgdef.c
otlgdef.h
otlgpos.c
otlgpos.h
otlgsub.c
otlgsub.h
otljstf.c
otljstf.h
otlparse.c
otlparse.h
otltable.h
otltags.h
otlutils.h
Sun Feb 1 18:24:10 2004
Masatake YAMATO, RedHat K.K.
<jet@gyve.org> or <yamato@redhat.com>

41
src/otlayout/demo.mk Normal file
View File

@ -0,0 +1,41 @@
#
# demo.mk --- Makefile for OpenType driver demo program
#
# Copyright 2004 by Masatake YAMATO and RedHat K.K.
#
# 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.
#
########################################################################
# Development of the code in demo.mk is support of
# Information-technology Promotion Agency, Japan.
SHELL=/bin/bash
POPT_LIBS=-lpopt
CFLAGS=-c -O0 -g -I../../include -Wall -std=c99
LIBS=-Xlinker -rpath -Xlinker ../../objs/.libs -lz $(POPT_LIBS)
########################################################################
OTOBJ=../../objs/.libs/libfreetype.so
DEMOBIN=otdemo
DEMOOBJ=otdemo.o
DEMOSRC=otdemo.c
########################################################################
all: $(DEMOBIN)
$(DEMOBIN): $(OTOBJ) $(DEMOOBJ)
$(CC) -o $(@) $(LIBS) $^
$(DEMOOBJ): $(DEMOSRC) $(OTOBJ)
$(OTOBJ): *.c *.h
(cd ../../; make)
########################################################################
clean:
rm -f $(DEMOBIN) $(DEMOOBJ) core.*

View File

@ -0,0 +1,89 @@
#ifndef FTERRCOMPAT_H
#define FTERRCOMPAT_H
/* #include <config.h> */
#define FREETYPE_MAJOR 2
#define FREETYPE_MINOR 1
#define TT_Err_Ok FT_Err_Ok
#define TT_Err_Invalid_Argument FT_Err_Invalid_Argument
#define TT_Err_Invalid_Face_Handle FT_Err_Invalid_Face_Handle
#define TT_Err_Table_Missing FT_Err_Table_Missing
/* Compat macros for name changes in FreeType 2.1.0
*/
#if (FREETYPE_MAJOR == 2) && (FREETYPE_MINOR >= 1)
#define FILE_Pos() FT_STREAM_POS()
#define FILE_Seek( position ) FT_STREAM_SEEK( position)
#define ACCESS_Frame( size ) FT_FRAME_ENTER( size )
#define FORGET_Frame() FT_FRAME_EXIT()
#define GET_Char() FT_GET_CHAR()
#define GET_Byte() FT_GET_BYTE()
#define GET_Short() FT_GET_SHORT()
#define GET_UShort() FT_GET_USHORT()
#define GET_Offset() FT_GET_OFF3()
#define GET_UOffset() FT_GET_UOFF3()
#define GET_Long() FT_GET_LONG()
#define GET_ULong() FT_GET_ULONG()
#define GET_Tag4() FT_GET_TAG4()
/* Macro definitions to avoid bogus warnings about strict
* aliasing. These make code generation worse, so we only
* use them when necessary
*/
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
#define ALLOC_ARRAY( _pointer_, _count_, _type_ ) ({ \
int result; \
void *_tmp_; \
result = FT_SET_ERROR ( FT_MEM_ALLOC_ARRAY ( _tmp_, \
_count_, \
_type_ ) ); \
_pointer_ = _tmp_; \
result; \
})
/* FT_MEM_REALLOC macro broken in 2.1.0 */
#define REALLOC_ARRAY( _pointer_, _old_, _new_, _type_ ) ({ \
int result; \
void *_tmp_ = _pointer_; \
result = FT_SET_ERROR ( FT_MEM_REALLOC( _tmp_, \
(_old_) * sizeof ( _type_ ), \
(_new_) * sizeof ( _type_ ) ) ); \
_pointer_ = _tmp_; \
result; \
})
#define FREE( _pointer_ ) ({ \
void *_tmp_ = _pointer_; \
FT_FREE ( _tmp_ ); \
_pointer_ = _tmp_; \
})
#define ALLOC( _pointer_, _size_ ) ({ \
int result; \
void *_tmp_; \
result = FT_ALLOC( _tmp_, _size_ ); \
_pointer_ = _tmp_; \
result; \
})
#else
#define ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
FT_SET_ERROR (FT_MEM_ALLOC_ARRAY( _pointer_, _count_, _type_))
/* FT_MEM_REALLOC macro broken in 2.1.0 */
#define REALLOC_ARRAY( _pointer_, _old_, _new_, _type_ ) \
FT_SET_ERROR ( FT_MEM_REALLOC( _pointer_, (_old_) * sizeof ( _type_ ), \
(_new_) * sizeof ( _type_ ) ) )
#define FREE( _pointer_ ) FT_FREE( _pointer_ )
#define ALLOC( _pointer_, _size_ ) FT_ALLOC( _pointer_, _size_ )
#endif /* gcc >= 3.3 */
#define MEM_Copy( dest, source, count ) FT_MEM_COPY( dest, source, count )
#endif /* freetype >= 2.1.0 */
#endif /* FTERRCOMPAT_H */

1214
src/otlayout/ftxgdef.c Normal file

File diff suppressed because it is too large Load Diff

224
src/otlayout/ftxgdef.h Normal file
View File

@ -0,0 +1,224 @@
/*******************************************************************
*
* ftxgdef.h
*
* TrueType Open GDEF table support
*
* Copyright 1996-2000 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 FTXOPEN_H
#error "Don't include this file! Use ftxopen.h instead."
#endif
#ifndef FTXGDEF_H
#define FTXGDEF_H
#ifdef __cplusplus
extern "C" {
#endif
#define TTO_Err_Invalid_GDEF_SubTable_Format 0x1030
#define TTO_Err_Invalid_GDEF_SubTable 0x1031
/* GDEF glyph classes */
#define UNCLASSIFIED_GLYPH 0
#define SIMPLE_GLYPH 1
#define LIGATURE_GLYPH 2
#define MARK_GLYPH 3
#define COMPONENT_GLYPH 4
/* GDEF glyph properties, corresponding to class values 1-4. Note that
TTO_COMPONENT has no corresponding flag in the LookupFlag field. */
#define TTO_BASE_GLYPH 0x0002
#define TTO_LIGATURE 0x0004
#define TTO_MARK 0x0008
#define TTO_COMPONENT 0x0010
/* Attachment related structures */
struct TTO_AttachPoint_
{
FT_UShort PointCount; /* size of the PointIndex array */
FT_UShort* PointIndex; /* array of contour points */
};
typedef struct TTO_AttachPoint_ TTO_AttachPoint;
struct TTO_AttachList_
{
FT_Bool loaded;
TTO_Coverage Coverage; /* Coverage table */
FT_UShort GlyphCount; /* number of glyphs with
attachments */
TTO_AttachPoint* AttachPoint; /* array of AttachPoint tables */
};
typedef struct TTO_AttachList_ TTO_AttachList;
/* Ligature Caret related structures */
struct TTO_CaretValueFormat1_
{
FT_Short Coordinate; /* x or y value (in design units) */
};
typedef struct TTO_CaretValueFormat1_ TTO_CaretValueFormat1;
struct TTO_CaretValueFormat2_
{
FT_UShort CaretValuePoint; /* contour point index on glyph */
};
typedef struct TTO_CaretValueFormat2_ TTO_CaretValueFormat2;
struct TTO_CaretValueFormat3_
{
FT_Short Coordinate; /* x or y value (in design units) */
TTO_Device Device; /* Device table for x or y value */
};
typedef struct TTO_CaretValueFormat3_ TTO_CaretValueFormat3;
struct TTO_CaretValueFormat4_
{
FT_UShort IdCaretValue; /* metric ID */
};
typedef struct TTO_CaretValueFormat4_ TTO_CaretValueFormat4;
struct TTO_CaretValue_
{
FT_UShort CaretValueFormat; /* 1, 2, 3, or 4 */
union
{
TTO_CaretValueFormat1 cvf1;
TTO_CaretValueFormat2 cvf2;
TTO_CaretValueFormat3 cvf3;
TTO_CaretValueFormat4 cvf4;
} cvf;
};
typedef struct TTO_CaretValue_ TTO_CaretValue;
struct TTO_LigGlyph_
{
FT_Bool loaded;
FT_UShort CaretCount; /* number of caret values */
TTO_CaretValue* CaretValue; /* array of caret values */
};
typedef struct TTO_LigGlyph_ TTO_LigGlyph;
struct TTO_LigCaretList_
{
FT_Bool loaded;
TTO_Coverage Coverage; /* Coverage table */
FT_UShort LigGlyphCount; /* number of ligature glyphs */
TTO_LigGlyph* LigGlyph; /* array of LigGlyph tables */
};
typedef struct TTO_LigCaretList_ TTO_LigCaretList;
/* The `NewGlyphClasses' field is not defined in the TTO specification.
We use it for fonts with a constructed `GlyphClassDef' structure
(i.e., which don't have a GDEF table) to collect glyph classes
assigned during the lookup process. The number of arrays in this
pointer array is GlyphClassDef->cd.cd2.ClassRangeCount+1; the nth
array then contains the glyph class values of the glyphs not covered
by the ClassRangeRecords structures with index n-1 and n. We store
glyph class values for four glyphs in a single array element.
`LastGlyph' is identical to the number of glyphs minus one in the
font; we need it only if `NewGlyphClasses' is not NULL (to have an
upper bound for the last array).
Note that we first store the file offset to the `MarkAttachClassDef'
field (which has been introduced in OpenType 1.2) -- since the
`Version' field value hasn't been increased to indicate that we have
one more field for some obscure reason, we must parse the GSUB table
to find out whether class values refer to this table. Only then we
can finally load the MarkAttachClassDef structure if necessary. */
struct TTO_GDEFHeader_
{
FT_Memory memory;
FT_ULong offset;
FT_Fixed Version;
TTO_ClassDefinition GlyphClassDef;
TTO_AttachList AttachList;
TTO_LigCaretList LigCaretList;
FT_ULong MarkAttachClassDef_offset;
TTO_ClassDefinition MarkAttachClassDef; /* new in OT 1.2 */
FT_UShort LastGlyph;
FT_UShort** NewGlyphClasses;
};
typedef struct TTO_GDEFHeader_ TTO_GDEFHeader;
typedef struct TTO_GDEFHeader_* TTO_GDEF;
/* finally, the GDEF API */
/* EXPORT_DEF
FT_Error TT_Init_GDEF_Extension( TT_Engine engine ); */
EXPORT_FUNC
FT_Error TT_New_GDEF_Table( FT_Face face,
TTO_GDEFHeader** retptr );
EXPORT_DEF
FT_Error TT_Load_GDEF_Table( FT_Face face,
TTO_GDEFHeader** gdef );
EXPORT_DEF
FT_Error TT_Done_GDEF_Table ( TTO_GDEFHeader* gdef );
EXPORT_DEF
FT_Error TT_GDEF_Get_Glyph_Property( TTO_GDEFHeader* gdef,
FT_UShort glyphID,
FT_UShort* property );
EXPORT_DEF
FT_Error TT_GDEF_Build_ClassDefinition( TTO_GDEFHeader* gdef,
FT_UShort num_glyphs,
FT_UShort glyph_count,
FT_UShort* glyph_array,
FT_UShort* class_array );
#ifdef __cplusplus
}
#endif
#endif /* FTXGDEF_H */
/* END */

6327
src/otlayout/ftxgpos.c Normal file

File diff suppressed because it is too large Load Diff

859
src/otlayout/ftxgpos.h Normal file
View File

@ -0,0 +1,859 @@
/*******************************************************************
*
* ftxgpos.h
*
* TrueType Open GPOS table support
*
* Copyright 1996-2000 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 FTXOPEN_H
#error "Don't include this file! Use ftxopen.h instead."
#endif
#ifndef FTXGPOS_H
#define FTXGPOS_H
#ifdef __cplusplus
extern "C" {
#endif
#define TTO_Err_Invalid_GPOS_SubTable_Format 0x1020
#define TTO_Err_Invalid_GPOS_SubTable 0x1021
/* Lookup types for glyph positioning */
#define GPOS_LOOKUP_SINGLE 1
#define GPOS_LOOKUP_PAIR 2
#define GPOS_LOOKUP_CURSIVE 3
#define GPOS_LOOKUP_MARKBASE 4
#define GPOS_LOOKUP_MARKLIG 5
#define GPOS_LOOKUP_MARKMARK 6
#define GPOS_LOOKUP_CONTEXT 7
#define GPOS_LOOKUP_CHAIN 8
#define GPOS_LOOKUP_EXTENSION 9
/* A pointer to a function which loads a glyph. Its parameters are
the same as in a call to TT_Load_Glyph() -- if no glyph loading
function will be registered with TTO_GPOS_Register_Glyph_Function(),
TT_Load_Glyph() will be called indeed. The purpose of this function
pointer is to provide a hook for caching glyph outlines and sbits
(using the instance's generic pointer to hold the data).
If for some reason no outline data is available (e.g. for an
embedded bitmap glyph), _glyph->outline.n_points should be set to
zero. _glyph can be computed with
_glyph = HANDLE_Glyph( glyph ) */
typedef FT_Error (*TTO_GlyphFunction)(FT_Face face,
FT_UInt glyphIndex,
FT_Int loadFlags );
/* A pointer to a function which accesses the PostScript interpreter.
Multiple Master fonts need this interface to convert a metric ID
(as stored in an OpenType font version 1.2 or higher) `metric_id'
into a metric value (returned in `metric_value').
`data' points to the user-defined structure specified during a
call to TT_GPOS_Register_MM_Function().
`metric_value' must be returned as a scaled value (but shouldn't
be rounded). */
typedef FT_Error (*TTO_MMFunction)(FT_Face face,
FT_UShort metric_id,
FT_Pos* metric_value,
void* data );
struct TTO_GPOSHeader_
{
FT_Memory memory;
FT_Fixed Version;
TTO_ScriptList ScriptList;
TTO_FeatureList FeatureList;
TTO_LookupList LookupList;
TTO_GDEFHeader* gdef;
/* the next field is used for a callback function to get the
glyph outline. */
TTO_GlyphFunction gfunc;
/* this is OpenType 1.2 -- Multiple Master fonts need this
callback function to get various metric values from the
PostScript interpreter. */
TTO_MMFunction mmfunc;
void* data;
};
typedef struct TTO_GPOSHeader_ TTO_GPOSHeader;
typedef struct TTO_GPOSHeader_* TTO_GPOS;
/* shared tables */
struct TTO_ValueRecord_
{
FT_Short XPlacement; /* horizontal adjustment for
placement */
FT_Short YPlacement; /* vertical adjustment for
placement */
FT_Short XAdvance; /* horizontal adjustment for
advance */
FT_Short YAdvance; /* vertical adjustment for
advance */
TTO_Device XPlacementDevice; /* device table for horizontal
placement */
TTO_Device YPlacementDevice; /* device table for vertical
placement */
TTO_Device XAdvanceDevice; /* device table for horizontal
advance */
TTO_Device YAdvanceDevice; /* device table for vertical
advance */
FT_UShort XIdPlacement; /* horizontal placement metric ID */
FT_UShort YIdPlacement; /* vertical placement metric ID */
FT_UShort XIdAdvance; /* horizontal advance metric ID */
FT_UShort YIdAdvance; /* vertical advance metric ID */
};
typedef struct TTO_ValueRecord_ TTO_ValueRecord;
/* Mask values to scan the value format of the ValueRecord structure.
We always expand compressed ValueRecords of the font. */
#define HAVE_X_PLACEMENT 0x0001
#define HAVE_Y_PLACEMENT 0x0002
#define HAVE_X_ADVANCE 0x0004
#define HAVE_Y_ADVANCE 0x0008
#define HAVE_X_PLACEMENT_DEVICE 0x0010
#define HAVE_Y_PLACEMENT_DEVICE 0x0020
#define HAVE_X_ADVANCE_DEVICE 0x0040
#define HAVE_Y_ADVANCE_DEVICE 0x0080
#define HAVE_X_ID_PLACEMENT 0x0100
#define HAVE_Y_ID_PLACEMENT 0x0200
#define HAVE_X_ID_ADVANCE 0x0400
#define HAVE_Y_ID_ADVANCE 0x0800
struct TTO_AnchorFormat1_
{
FT_Short XCoordinate; /* horizontal value */
FT_Short YCoordinate; /* vertical value */
};
typedef struct TTO_AnchorFormat1_ TTO_AnchorFormat1;
struct TTO_AnchorFormat2_
{
FT_Short XCoordinate; /* horizontal value */
FT_Short YCoordinate; /* vertical value */
FT_UShort AnchorPoint; /* index to glyph contour point */
};
typedef struct TTO_AnchorFormat2_ TTO_AnchorFormat2;
struct TTO_AnchorFormat3_
{
FT_Short XCoordinate; /* horizontal value */
FT_Short YCoordinate; /* vertical value */
TTO_Device XDeviceTable; /* device table for X coordinate */
TTO_Device YDeviceTable; /* device table for Y coordinate */
};
typedef struct TTO_AnchorFormat3_ TTO_AnchorFormat3;
struct TTO_AnchorFormat4_
{
FT_UShort XIdAnchor; /* horizontal metric ID */
FT_UShort YIdAnchor; /* vertical metric ID */
};
typedef struct TTO_AnchorFormat4_ TTO_AnchorFormat4;
struct TTO_Anchor_
{
FT_UShort PosFormat; /* 1, 2, 3, or 4 -- 0 indicates
that there is no Anchor table */
union
{
TTO_AnchorFormat1 af1;
TTO_AnchorFormat2 af2;
TTO_AnchorFormat3 af3;
TTO_AnchorFormat4 af4;
} af;
};
typedef struct TTO_Anchor_ TTO_Anchor;
struct TTO_MarkRecord_
{
FT_UShort Class; /* mark class */
TTO_Anchor MarkAnchor; /* anchor table */
};
typedef struct TTO_MarkRecord_ TTO_MarkRecord;
struct TTO_MarkArray_
{
FT_UShort MarkCount; /* number of MarkRecord tables */
TTO_MarkRecord* MarkRecord; /* array of MarkRecord tables */
};
typedef struct TTO_MarkArray_ TTO_MarkArray;
/* LookupType 1 */
struct TTO_SinglePosFormat1_
{
TTO_ValueRecord Value; /* ValueRecord for all covered
glyphs */
};
typedef struct TTO_SinglePosFormat1_ TTO_SinglePosFormat1;
struct TTO_SinglePosFormat2_
{
FT_UShort ValueCount; /* number of ValueRecord tables */
TTO_ValueRecord* Value; /* array of ValueRecord tables */
};
typedef struct TTO_SinglePosFormat2_ TTO_SinglePosFormat2;
struct TTO_SinglePos_
{
FT_UShort PosFormat; /* 1 or 2 */
TTO_Coverage Coverage; /* Coverage table */
FT_UShort ValueFormat; /* format of ValueRecord table */
union
{
TTO_SinglePosFormat1 spf1;
TTO_SinglePosFormat2 spf2;
} spf;
};
typedef struct TTO_SinglePos_ TTO_SinglePos;
/* LookupType 2 */
struct TTO_PairValueRecord_
{
FT_UShort SecondGlyph; /* glyph ID for second glyph */
TTO_ValueRecord Value1; /* pos. data for first glyph */
TTO_ValueRecord Value2; /* pos. data for second glyph */
};
typedef struct TTO_PairValueRecord_ TTO_PairValueRecord;
struct TTO_PairSet_
{
FT_UShort PairValueCount;
/* number of PairValueRecord tables */
TTO_PairValueRecord* PairValueRecord;
/* array of PairValueRecord tables */
};
typedef struct TTO_PairSet_ TTO_PairSet;
struct TTO_PairPosFormat1_
{
FT_UShort PairSetCount; /* number of PairSet tables */
TTO_PairSet* PairSet; /* array of PairSet tables */
};
typedef struct TTO_PairPosFormat1_ TTO_PairPosFormat1;
struct TTO_Class2Record_
{
TTO_ValueRecord Value1; /* pos. data for first glyph */
TTO_ValueRecord Value2; /* pos. data for second glyph */
};
typedef struct TTO_Class2Record_ TTO_Class2Record;
struct TTO_Class1Record_
{
TTO_Class2Record* Class2Record; /* array of Class2Record tables */
};
typedef struct TTO_Class1Record_ TTO_Class1Record;
struct TTO_PairPosFormat2_
{
TTO_ClassDefinition ClassDef1; /* class def. for first glyph */
TTO_ClassDefinition ClassDef2; /* class def. for second glyph */
FT_UShort Class1Count; /* number of classes in ClassDef1
table */
FT_UShort Class2Count; /* number of classes in ClassDef2
table */
TTO_Class1Record* Class1Record; /* array of Class1Record tables */
};
typedef struct TTO_PairPosFormat2_ TTO_PairPosFormat2;
struct TTO_PairPos_
{
FT_UShort PosFormat; /* 1 or 2 */
TTO_Coverage Coverage; /* Coverage table */
FT_UShort ValueFormat1; /* format of ValueRecord table
for first glyph */
FT_UShort ValueFormat2; /* format of ValueRecord table
for second glyph */
union
{
TTO_PairPosFormat1 ppf1;
TTO_PairPosFormat2 ppf2;
} ppf;
};
typedef struct TTO_PairPos_ TTO_PairPos;
/* LookupType 3 */
struct TTO_EntryExitRecord_
{
TTO_Anchor EntryAnchor; /* entry Anchor table */
TTO_Anchor ExitAnchor; /* exit Anchor table */
};
typedef struct TTO_EntryExitRecord_ TTO_EntryExitRecord;
struct TTO_CursivePos_
{
FT_UShort PosFormat; /* always 1 */
TTO_Coverage Coverage; /* Coverage table */
FT_UShort EntryExitCount;
/* number of EntryExitRecord tables */
TTO_EntryExitRecord* EntryExitRecord;
/* array of EntryExitRecord tables */
};
typedef struct TTO_CursivePos_ TTO_CursivePos;
/* LookupType 4 */
struct TTO_BaseRecord_
{
TTO_Anchor* BaseAnchor; /* array of base glyph anchor
tables */
};
typedef struct TTO_BaseRecord_ TTO_BaseRecord;
struct TTO_BaseArray_
{
FT_UShort BaseCount; /* number of BaseRecord tables */
TTO_BaseRecord* BaseRecord; /* array of BaseRecord tables */
};
typedef struct TTO_BaseArray_ TTO_BaseArray;
struct TTO_MarkBasePos_
{
FT_UShort PosFormat; /* always 1 */
TTO_Coverage MarkCoverage; /* mark glyph coverage table */
TTO_Coverage BaseCoverage; /* base glyph coverage table */
FT_UShort ClassCount; /* number of mark classes */
TTO_MarkArray MarkArray; /* mark array table */
TTO_BaseArray BaseArray; /* base array table */
};
typedef struct TTO_MarkBasePos_ TTO_MarkBasePos;
/* LookupType 5 */
struct TTO_ComponentRecord_
{
TTO_Anchor* LigatureAnchor; /* array of ligature glyph anchor
tables */
};
typedef struct TTO_ComponentRecord_ TTO_ComponentRecord;
struct TTO_LigatureAttach_
{
FT_UShort ComponentCount;
/* number of ComponentRecord tables */
TTO_ComponentRecord* ComponentRecord;
/* array of ComponentRecord tables */
};
typedef struct TTO_LigatureAttach_ TTO_LigatureAttach;
struct TTO_LigatureArray_
{
FT_UShort LigatureCount; /* number of LigatureAttach tables */
TTO_LigatureAttach* LigatureAttach;
/* array of LigatureAttach tables */
};
typedef struct TTO_LigatureArray_ TTO_LigatureArray;
struct TTO_MarkLigPos_
{
FT_UShort PosFormat; /* always 1 */
TTO_Coverage MarkCoverage; /* mark glyph coverage table */
TTO_Coverage LigatureCoverage;
/* ligature glyph coverage table */
FT_UShort ClassCount; /* number of mark classes */
TTO_MarkArray MarkArray; /* mark array table */
TTO_LigatureArray LigatureArray; /* ligature array table */
};
typedef struct TTO_MarkLigPos_ TTO_MarkLigPos;
/* LookupType 6 */
struct TTO_Mark2Record_
{
TTO_Anchor* Mark2Anchor; /* array of mark glyph anchor
tables */
};
typedef struct TTO_Mark2Record_ TTO_Mark2Record;
struct TTO_Mark2Array_
{
FT_UShort Mark2Count; /* number of Mark2Record tables */
TTO_Mark2Record* Mark2Record; /* array of Mark2Record tables */
};
typedef struct TTO_Mark2Array_ TTO_Mark2Array;
struct TTO_MarkMarkPos_
{
FT_UShort PosFormat; /* always 1 */
TTO_Coverage Mark1Coverage; /* first mark glyph coverage table */
TTO_Coverage Mark2Coverage; /* second mark glyph coverave table */
FT_UShort ClassCount; /* number of combining mark classes */
TTO_MarkArray Mark1Array; /* MarkArray table for first mark */
TTO_Mark2Array Mark2Array; /* MarkArray table for second mark */
};
typedef struct TTO_MarkMarkPos_ TTO_MarkMarkPos;
/* needed by both lookup type 7 and 8 */
struct TTO_PosLookupRecord_
{
FT_UShort SequenceIndex; /* index into current
glyph sequence */
FT_UShort LookupListIndex; /* Lookup to apply to that pos. */
};
typedef struct TTO_PosLookupRecord_ TTO_PosLookupRecord;
/* LookupType 7 */
struct TTO_PosRule_
{
FT_UShort GlyphCount; /* total number of input glyphs */
FT_UShort PosCount; /* number of PosLookupRecord tables */
FT_UShort* Input; /* array of input glyph IDs */
TTO_PosLookupRecord* PosLookupRecord;
/* array of PosLookupRecord tables */
};
typedef struct TTO_PosRule_ TTO_PosRule;
struct TTO_PosRuleSet_
{
FT_UShort PosRuleCount; /* number of PosRule tables */
TTO_PosRule* PosRule; /* array of PosRule tables */
};
typedef struct TTO_PosRuleSet_ TTO_PosRuleSet;
struct TTO_ContextPosFormat1_
{
TTO_Coverage Coverage; /* Coverage table */
FT_UShort PosRuleSetCount; /* number of PosRuleSet tables */
TTO_PosRuleSet* PosRuleSet; /* array of PosRuleSet tables */
};
typedef struct TTO_ContextPosFormat1_ TTO_ContextPosFormat1;
struct TTO_PosClassRule_
{
FT_UShort GlyphCount; /* total number of context classes */
FT_UShort PosCount; /* number of PosLookupRecord tables */
FT_UShort* Class; /* array of classes */
TTO_PosLookupRecord* PosLookupRecord;
/* array of PosLookupRecord tables */
};
typedef struct TTO_PosClassRule_ TTO_PosClassRule;
struct TTO_PosClassSet_
{
FT_UShort PosClassRuleCount;
/* number of PosClassRule tables */
TTO_PosClassRule* PosClassRule; /* array of PosClassRule tables */
};
typedef struct TTO_PosClassSet_ TTO_PosClassSet;
/* The `MaxContextLength' field is not defined in the TTO specification
but simplifies the implementation of this format. It holds the
maximal context length used in the context rules. */
struct TTO_ContextPosFormat2_
{
FT_UShort MaxContextLength;
/* maximal context length */
TTO_Coverage Coverage; /* Coverage table */
TTO_ClassDefinition ClassDef; /* ClassDef table */
FT_UShort PosClassSetCount;
/* number of PosClassSet tables */
TTO_PosClassSet* PosClassSet; /* array of PosClassSet tables */
};
typedef struct TTO_ContextPosFormat2_ TTO_ContextPosFormat2;
struct TTO_ContextPosFormat3_
{
FT_UShort GlyphCount; /* number of input glyphs */
FT_UShort PosCount; /* number of PosLookupRecord tables */
TTO_Coverage* Coverage; /* array of Coverage tables */
TTO_PosLookupRecord* PosLookupRecord;
/* array of PosLookupRecord tables */
};
typedef struct TTO_ContextPosFormat3_ TTO_ContextPosFormat3;
struct TTO_ContextPos_
{
FT_UShort PosFormat; /* 1, 2, or 3 */
union
{
TTO_ContextPosFormat1 cpf1;
TTO_ContextPosFormat2 cpf2;
TTO_ContextPosFormat3 cpf3;
} cpf;
};
typedef struct TTO_ContextPos_ TTO_ContextPos;
/* LookupType 8 */
struct TTO_ChainPosRule_
{
FT_UShort BacktrackGlyphCount;
/* total number of backtrack glyphs */
FT_UShort* Backtrack; /* array of backtrack glyph IDs */
FT_UShort InputGlyphCount;
/* total number of input glyphs */
FT_UShort* Input; /* array of input glyph IDs */
FT_UShort LookaheadGlyphCount;
/* total number of lookahead glyphs */
FT_UShort* Lookahead; /* array of lookahead glyph IDs */
FT_UShort PosCount; /* number of PosLookupRecords */
TTO_PosLookupRecord* PosLookupRecord;
/* array of PosLookupRecords */
};
typedef struct TTO_ChainPosRule_ TTO_ChainPosRule;
struct TTO_ChainPosRuleSet_
{
FT_UShort ChainPosRuleCount;
/* number of ChainPosRule tables */
TTO_ChainPosRule* ChainPosRule; /* array of ChainPosRule tables */
};
typedef struct TTO_ChainPosRuleSet_ TTO_ChainPosRuleSet;
struct TTO_ChainContextPosFormat1_
{
TTO_Coverage Coverage; /* Coverage table */
FT_UShort ChainPosRuleSetCount;
/* number of ChainPosRuleSet tables */
TTO_ChainPosRuleSet* ChainPosRuleSet;
/* array of ChainPosRuleSet tables */
};
typedef struct TTO_ChainContextPosFormat1_ TTO_ChainContextPosFormat1;
struct TTO_ChainPosClassRule_
{
FT_UShort BacktrackGlyphCount;
/* total number of backtrack
classes */
FT_UShort* Backtrack; /* array of backtrack classes */
FT_UShort InputGlyphCount;
/* total number of context classes */
FT_UShort* Input; /* array of context classes */
FT_UShort LookaheadGlyphCount;
/* total number of lookahead
classes */
FT_UShort* Lookahead; /* array of lookahead classes */
FT_UShort PosCount; /* number of PosLookupRecords */
TTO_PosLookupRecord* PosLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ChainPosClassRule_ TTO_ChainPosClassRule;
struct TTO_ChainPosClassSet_
{
FT_UShort ChainPosClassRuleCount;
/* number of ChainPosClassRule
tables */
TTO_ChainPosClassRule* ChainPosClassRule;
/* array of ChainPosClassRule
tables */
};
typedef struct TTO_ChainPosClassSet_ TTO_ChainPosClassSet;
/* The `MaxXXXLength' fields are not defined in the TTO specification
but simplifies the implementation of this format. It holds the
maximal context length used in the specific context rules. */
struct TTO_ChainContextPosFormat2_
{
TTO_Coverage Coverage; /* Coverage table */
FT_UShort MaxBacktrackLength;
/* maximal backtrack length */
TTO_ClassDefinition BacktrackClassDef;
/* BacktrackClassDef table */
FT_UShort MaxInputLength;
/* maximal input length */
TTO_ClassDefinition InputClassDef;
/* InputClassDef table */
FT_UShort MaxLookaheadLength;
/* maximal lookahead length */
TTO_ClassDefinition LookaheadClassDef;
/* LookaheadClassDef table */
FT_UShort ChainPosClassSetCount;
/* number of ChainPosClassSet
tables */
TTO_ChainPosClassSet* ChainPosClassSet;
/* array of ChainPosClassSet
tables */
};
typedef struct TTO_ChainContextPosFormat2_ TTO_ChainContextPosFormat2;
struct TTO_ChainContextPosFormat3_
{
FT_UShort BacktrackGlyphCount;
/* number of backtrack glyphs */
TTO_Coverage* BacktrackCoverage;
/* array of backtrack Coverage
tables */
FT_UShort InputGlyphCount;
/* number of input glyphs */
TTO_Coverage* InputCoverage;
/* array of input coverage
tables */
FT_UShort LookaheadGlyphCount;
/* number of lookahead glyphs */
TTO_Coverage* LookaheadCoverage;
/* array of lookahead coverage
tables */
FT_UShort PosCount; /* number of PosLookupRecords */
TTO_PosLookupRecord* PosLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ChainContextPosFormat3_ TTO_ChainContextPosFormat3;
struct TTO_ChainContextPos_
{
FT_UShort PosFormat; /* 1, 2, or 3 */
union
{
TTO_ChainContextPosFormat1 ccpf1;
TTO_ChainContextPosFormat2 ccpf2;
TTO_ChainContextPosFormat3 ccpf3;
} ccpf;
};
typedef struct TTO_ChainContextPos_ TTO_ChainContextPos;
union TTO_GPOS_SubTable_
{
TTO_SinglePos single;
TTO_PairPos pair;
TTO_CursivePos cursive;
TTO_MarkBasePos markbase;
TTO_MarkLigPos marklig;
TTO_MarkMarkPos markmark;
TTO_ContextPos context;
TTO_ChainContextPos chain;
};
typedef union TTO_GPOS_SubTable_ TTO_GPOS_SubTable;
/* This `string object' is much simpler compared to TTO_GSUB_String.
A call to TTO_GPOS_Apply_String() will allocate it. */
struct TTO_GPOS_Data_
{
FT_Pos x_pos;
FT_Pos y_pos;
FT_Pos x_advance;
FT_Pos y_advance;
FT_UShort back; /* number of glyphs to go back
for drawing current glyph */
FT_Bool new_advance; /* if set, the advance width values are
absolute, i.e., they won't be
added to the original glyph's value
but rather replace them. */
};
typedef struct TTO_GPOS_Data_ TTO_GPOS_Data;
/* finally, the GPOS API */
/* EXPORT_DEF
FT_Export ( FT_Error ) TT_Init_GPOS_Extension( TT_Engine engine ); */
EXPORT_DEF
FT_Error TT_Load_GPOS_Table( FT_Face face,
TTO_GPOSHeader** gpos,
TTO_GDEFHeader* gdef );
EXPORT_DEF
FT_Error TT_Done_GPOS_Table( TTO_GPOSHeader* gpos );
EXPORT_DEF
FT_Error TT_GPOS_Select_Script( TTO_GPOSHeader* gpos,
FT_ULong script_tag,
FT_UShort* script_index );
EXPORT_DEF
FT_Error TT_GPOS_Select_Language( TTO_GPOSHeader* gpos,
FT_ULong language_tag,
FT_UShort script_index,
FT_UShort* language_index,
FT_UShort* req_feature_index );
EXPORT_DEF
FT_Error TT_GPOS_Select_Feature( TTO_GPOSHeader* gpos,
FT_ULong feature_tag,
FT_UShort script_index,
FT_UShort language_index,
FT_UShort* feature_index );
EXPORT_DEF
FT_Error TT_GPOS_Query_Scripts( TTO_GPOSHeader* gpos,
FT_ULong** script_tag_list );
EXPORT_DEF
FT_Error TT_GPOS_Query_Languages( TTO_GPOSHeader* gpos,
FT_UShort script_index,
FT_ULong** language_tag_list );
EXPORT_DEF
FT_Error TT_GPOS_Query_Features( TTO_GPOSHeader* gpos,
FT_UShort script_index,
FT_UShort language_index,
FT_ULong** feature_tag_list );
EXPORT_DEF
FT_Error TT_GPOS_Add_Feature( TTO_GPOSHeader* gpos,
FT_UShort feature_index,
FT_UShort property );
EXPORT_DEF
FT_Error TT_GPOS_Clear_Features( TTO_GPOSHeader* gpos );
EXPORT_DEF
FT_Error TT_GPOS_Register_Glyph_Function( TTO_GPOSHeader* gpos,
TTO_GlyphFunction gfunc );
EXPORT_DEF
FT_Error TT_GPOS_Register_MM_Function( TTO_GPOSHeader* gpos,
TTO_MMFunction mmfunc,
void* data );
/* If `dvi' is TRUE, glyph contour points for anchor points and device
tables are ignored -- you will get device independent values. */
EXPORT_DEF
FT_Error TT_GPOS_Apply_String( FT_Face face,
TTO_GPOSHeader* gpos,
FT_UShort load_flags,
TTO_GSUB_String* in,
TTO_GPOS_Data** out,
FT_Bool dvi,
FT_Bool r2l );
#ifdef __cplusplus
}
#endif
#endif /* FTXGPOS_H */
/* END */

4582
src/otlayout/ftxgsub.c Normal file

File diff suppressed because it is too large Load Diff

613
src/otlayout/ftxgsub.h Normal file
View File

@ -0,0 +1,613 @@
/*******************************************************************
*
* ftxgsub.h
*
* TrueType Open GSUB table support
*
* Copyright 1996-2000 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 FTXOPEN_H
#error "Don't include this file! Use ftxopen.h instead."
#endif
#ifndef FTXGSUB_H
#define FTXGSUB_H
#ifdef __cplusplus
extern "C" {
#endif
#define TTO_Err_Invalid_GSUB_SubTable_Format 0x1010
#define TTO_Err_Invalid_GSUB_SubTable 0x1011
/* Lookup types for glyph substitution */
#define GSUB_LOOKUP_SINGLE 1
#define GSUB_LOOKUP_MULTIPLE 2
#define GSUB_LOOKUP_ALTERNATE 3
#define GSUB_LOOKUP_LIGATURE 4
#define GSUB_LOOKUP_CONTEXT 5
#define GSUB_LOOKUP_CHAIN 6
#define GSUB_LOOKUP_EXTENSION 7
/* Use this if a feature applies to all glyphs */
#define ALL_GLYPHS 0xFFFF
/* A pointer to a function which selects the alternate glyph. `pos' is
the position of the glyph with index `glyphID', `num_alternates'
gives the number of alternates in the `alternates' array. `data'
points to the user-defined structure specified during a call to
TT_GSUB_Register_Alternate_Function(). The function must return an
index into the `alternates' array. */
typedef FT_UShort (*TTO_AltFunction)(FT_ULong pos,
FT_UShort glyphID,
FT_UShort num_alternates,
FT_UShort* alternates,
void* data );
struct TTO_GSUBHeader_
{
FT_Memory memory;
FT_ULong offset;
FT_Fixed Version;
TTO_ScriptList ScriptList;
TTO_FeatureList FeatureList;
TTO_LookupList LookupList;
TTO_GDEFHeader* gdef;
/* the next two fields are used for an alternate substitution callback
function to select the proper alternate glyph. */
TTO_AltFunction altfunc;
void* data;
};
typedef struct TTO_GSUBHeader_ TTO_GSUBHeader;
typedef struct TTO_GSUBHeader_* TTO_GSUB;
/* LookupType 1 */
struct TTO_SingleSubstFormat1_
{
FT_Short DeltaGlyphID; /* constant added to get
substitution glyph index */
};
typedef struct TTO_SingleSubstFormat1_ TTO_SingleSubstFormat1;
struct TTO_SingleSubstFormat2_
{
FT_UShort GlyphCount; /* number of glyph IDs in
Substitute array */
FT_UShort* Substitute; /* array of substitute glyph IDs */
};
typedef struct TTO_SingleSubstFormat2_ TTO_SingleSubstFormat2;
struct TTO_SingleSubst_
{
FT_UShort SubstFormat; /* 1 or 2 */
TTO_Coverage Coverage; /* Coverage table */
union
{
TTO_SingleSubstFormat1 ssf1;
TTO_SingleSubstFormat2 ssf2;
} ssf;
};
typedef struct TTO_SingleSubst_ TTO_SingleSubst;
/* LookupType 2 */
struct TTO_Sequence_
{
FT_UShort GlyphCount; /* number of glyph IDs in the
Substitute array */
FT_UShort* Substitute; /* string of glyph IDs to
substitute */
};
typedef struct TTO_Sequence_ TTO_Sequence;
struct TTO_MultipleSubst_
{
FT_UShort SubstFormat; /* always 1 */
TTO_Coverage Coverage; /* Coverage table */
FT_UShort SequenceCount; /* number of Sequence tables */
TTO_Sequence* Sequence; /* array of Sequence tables */
};
typedef struct TTO_MultipleSubst_ TTO_MultipleSubst;
/* LookupType 3 */
struct TTO_AlternateSet_
{
FT_UShort GlyphCount; /* number of glyph IDs in the
Alternate array */
FT_UShort* Alternate; /* array of alternate glyph IDs */
};
typedef struct TTO_AlternateSet_ TTO_AlternateSet;
struct TTO_AlternateSubst_
{
FT_UShort SubstFormat; /* always 1 */
TTO_Coverage Coverage; /* Coverage table */
FT_UShort AlternateSetCount;
/* number of AlternateSet tables */
TTO_AlternateSet* AlternateSet; /* array of AlternateSet tables */
};
typedef struct TTO_AlternateSubst_ TTO_AlternateSubst;
/* LookupType 4 */
struct TTO_Ligature_
{
FT_UShort LigGlyph; /* glyphID of ligature
to substitute */
FT_UShort ComponentCount; /* number of components in ligature */
FT_UShort* Component; /* array of component glyph IDs */
};
typedef struct TTO_Ligature_ TTO_Ligature;
struct TTO_LigatureSet_
{
FT_UShort LigatureCount; /* number of Ligature tables */
TTO_Ligature* Ligature; /* array of Ligature tables */
};
typedef struct TTO_LigatureSet_ TTO_LigatureSet;
struct TTO_LigatureSubst_
{
FT_UShort SubstFormat; /* always 1 */
TTO_Coverage Coverage; /* Coverage table */
FT_UShort LigatureSetCount; /* number of LigatureSet tables */
TTO_LigatureSet* LigatureSet; /* array of LigatureSet tables */
};
typedef struct TTO_LigatureSubst_ TTO_LigatureSubst;
/* needed by both lookup type 5 and 6 */
struct TTO_SubstLookupRecord_
{
FT_UShort SequenceIndex; /* index into current
glyph sequence */
FT_UShort LookupListIndex; /* Lookup to apply to that pos. */
};
typedef struct TTO_SubstLookupRecord_ TTO_SubstLookupRecord;
/* LookupType 5 */
struct TTO_SubRule_
{
FT_UShort GlyphCount; /* total number of input glyphs */
FT_UShort SubstCount; /* number of SubstLookupRecord
tables */
FT_UShort* Input; /* array of input glyph IDs */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of SubstLookupRecord
tables */
};
typedef struct TTO_SubRule_ TTO_SubRule;
struct TTO_SubRuleSet_
{
FT_UShort SubRuleCount; /* number of SubRule tables */
TTO_SubRule* SubRule; /* array of SubRule tables */
};
typedef struct TTO_SubRuleSet_ TTO_SubRuleSet;
struct TTO_ContextSubstFormat1_
{
TTO_Coverage Coverage; /* Coverage table */
FT_UShort SubRuleSetCount; /* number of SubRuleSet tables */
TTO_SubRuleSet* SubRuleSet; /* array of SubRuleSet tables */
};
typedef struct TTO_ContextSubstFormat1_ TTO_ContextSubstFormat1;
struct TTO_SubClassRule_
{
FT_UShort GlyphCount; /* total number of context classes */
FT_UShort SubstCount; /* number of SubstLookupRecord
tables */
FT_UShort* Class; /* array of classes */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of SubstLookupRecord
tables */
};
typedef struct TTO_SubClassRule_ TTO_SubClassRule;
struct TTO_SubClassSet_
{
FT_UShort SubClassRuleCount;
/* number of SubClassRule tables */
TTO_SubClassRule* SubClassRule; /* array of SubClassRule tables */
};
typedef struct TTO_SubClassSet_ TTO_SubClassSet;
/* The `MaxContextLength' field is not defined in the TTO specification
but simplifies the implementation of this format. It holds the
maximal context length used in the context rules. */
struct TTO_ContextSubstFormat2_
{
FT_UShort MaxContextLength;
/* maximal context length */
TTO_Coverage Coverage; /* Coverage table */
TTO_ClassDefinition ClassDef; /* ClassDef table */
FT_UShort SubClassSetCount;
/* number of SubClassSet tables */
TTO_SubClassSet* SubClassSet; /* array of SubClassSet tables */
};
typedef struct TTO_ContextSubstFormat2_ TTO_ContextSubstFormat2;
struct TTO_ContextSubstFormat3_
{
FT_UShort GlyphCount; /* number of input glyphs */
FT_UShort SubstCount; /* number of SubstLookupRecords */
TTO_Coverage* Coverage; /* array of Coverage tables */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ContextSubstFormat3_ TTO_ContextSubstFormat3;
struct TTO_ContextSubst_
{
FT_UShort SubstFormat; /* 1, 2, or 3 */
union
{
TTO_ContextSubstFormat1 csf1;
TTO_ContextSubstFormat2 csf2;
TTO_ContextSubstFormat3 csf3;
} csf;
};
typedef struct TTO_ContextSubst_ TTO_ContextSubst;
/* LookupType 6 */
struct TTO_ChainSubRule_
{
FT_UShort BacktrackGlyphCount;
/* total number of backtrack glyphs */
FT_UShort* Backtrack; /* array of backtrack glyph IDs */
FT_UShort InputGlyphCount;
/* total number of input glyphs */
FT_UShort* Input; /* array of input glyph IDs */
FT_UShort LookaheadGlyphCount;
/* total number of lookahead glyphs */
FT_UShort* Lookahead; /* array of lookahead glyph IDs */
FT_UShort SubstCount; /* number of SubstLookupRecords */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of SubstLookupRecords */
};
typedef struct TTO_ChainSubRule_ TTO_ChainSubRule;
struct TTO_ChainSubRuleSet_
{
FT_UShort ChainSubRuleCount;
/* number of ChainSubRule tables */
TTO_ChainSubRule* ChainSubRule; /* array of ChainSubRule tables */
};
typedef struct TTO_ChainSubRuleSet_ TTO_ChainSubRuleSet;
struct TTO_ChainContextSubstFormat1_
{
TTO_Coverage Coverage; /* Coverage table */
FT_UShort ChainSubRuleSetCount;
/* number of ChainSubRuleSet tables */
TTO_ChainSubRuleSet* ChainSubRuleSet;
/* array of ChainSubRuleSet tables */
};
typedef struct TTO_ChainContextSubstFormat1_ TTO_ChainContextSubstFormat1;
struct TTO_ChainSubClassRule_
{
FT_UShort BacktrackGlyphCount;
/* total number of backtrack
classes */
FT_UShort* Backtrack; /* array of backtrack classes */
FT_UShort InputGlyphCount;
/* total number of context classes */
FT_UShort* Input; /* array of context classes */
FT_UShort LookaheadGlyphCount;
/* total number of lookahead
classes */
FT_UShort* Lookahead; /* array of lookahead classes */
FT_UShort SubstCount; /* number of SubstLookupRecords */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ChainSubClassRule_ TTO_ChainSubClassRule;
struct TTO_ChainSubClassSet_
{
FT_UShort ChainSubClassRuleCount;
/* number of ChainSubClassRule
tables */
TTO_ChainSubClassRule* ChainSubClassRule;
/* array of ChainSubClassRule
tables */
};
typedef struct TTO_ChainSubClassSet_ TTO_ChainSubClassSet;
/* The `MaxXXXLength' fields are not defined in the TTO specification
but simplifies the implementation of this format. It holds the
maximal context length used in the specific context rules. */
struct TTO_ChainContextSubstFormat2_
{
TTO_Coverage Coverage; /* Coverage table */
FT_UShort MaxBacktrackLength;
/* maximal backtrack length */
TTO_ClassDefinition BacktrackClassDef;
/* BacktrackClassDef table */
FT_UShort MaxInputLength;
/* maximal input length */
TTO_ClassDefinition InputClassDef;
/* InputClassDef table */
FT_UShort MaxLookaheadLength;
/* maximal lookahead length */
TTO_ClassDefinition LookaheadClassDef;
/* LookaheadClassDef table */
FT_UShort ChainSubClassSetCount;
/* number of ChainSubClassSet
tables */
TTO_ChainSubClassSet* ChainSubClassSet;
/* array of ChainSubClassSet
tables */
};
typedef struct TTO_ChainContextSubstFormat2_ TTO_ChainContextSubstFormat2;
struct TTO_ChainContextSubstFormat3_
{
FT_UShort BacktrackGlyphCount;
/* number of backtrack glyphs */
TTO_Coverage* BacktrackCoverage;
/* array of backtrack Coverage
tables */
FT_UShort InputGlyphCount;
/* number of input glyphs */
TTO_Coverage* InputCoverage;
/* array of input coverage
tables */
FT_UShort LookaheadGlyphCount;
/* number of lookahead glyphs */
TTO_Coverage* LookaheadCoverage;
/* array of lookahead coverage
tables */
FT_UShort SubstCount; /* number of SubstLookupRecords */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ChainContextSubstFormat3_ TTO_ChainContextSubstFormat3;
struct TTO_ChainContextSubst_
{
FT_UShort SubstFormat; /* 1, 2, or 3 */
union
{
TTO_ChainContextSubstFormat1 ccsf1;
TTO_ChainContextSubstFormat2 ccsf2;
TTO_ChainContextSubstFormat3 ccsf3;
} ccsf;
};
typedef struct TTO_ChainContextSubst_ TTO_ChainContextSubst;
union TTO_GSUB_SubTable_
{
TTO_SingleSubst single;
TTO_MultipleSubst multiple;
TTO_AlternateSubst alternate;
TTO_LigatureSubst ligature;
TTO_ContextSubst context;
TTO_ChainContextSubst chain;
};
typedef union TTO_GSUB_SubTable_ TTO_GSUB_SubTable;
/* A simple string object. It can both `send' and `receive' data.
In case of sending, `length' and `pos' will be used. In case of
receiving, `pos' points to the first free slot, and `allocated'
specifies the amount of allocated memory (and the `length' field
will be ignored). The routine TT_Add_String() will increase the
amount of memory if necessary. After end of receive, `length'
should be set to the value of `pos', and `pos' will be set to zero.
`properties' (which is treated as a bit field) gives the glyph's
properties: If a certain bit is set for a glyph, the feature which
has the same bit set in its property value is applied.
`components' is an internal array which tracks components of
ligatures. We need this for MarkToLigature Attachment Positioning
Subtables (in GPOS) together with `ligIDs' (which is used to mark
ligatures and the skipped glyphs during a ligature lookup).
`max_ligID' is increased after a successful ligature lookup.
NEVER modify any elements of the structure! You should rather copy
its contents if necessary.
TT_Add_String() will also handle allocation; you should use
free() in case you want to destroy the arrays in the object. */
struct TTO_GSUB_String_
{
FT_Memory memory;
FT_ULong length;
FT_ULong pos;
FT_ULong allocated;
FT_UShort* string;
FT_UShort* properties;
FT_UShort* components;
FT_UShort max_ligID;
FT_UShort* ligIDs;
FT_Int* logClusters;
};
typedef struct TTO_GSUB_String_ TTO_GSUB_String;
/* finally, the GSUB API */
/* EXPORT_DEF
TT_Error TT_Init_GSUB_Extension( TT_Engine engine ); */
EXPORT_DEF
FT_Error TT_Load_GSUB_Table( FT_Face face,
TTO_GSUBHeader** gsub,
TTO_GDEFHeader* gdef );
EXPORT_DEF
FT_Error TT_Done_GSUB_Table( TTO_GSUBHeader* gsub );
EXPORT_DEF
FT_Error TT_GSUB_Select_Script( TTO_GSUBHeader* gsub,
FT_ULong script_tag,
FT_UShort* script_index );
EXPORT_DEF
FT_Error TT_GSUB_Select_Language( TTO_GSUBHeader* gsub,
FT_ULong language_tag,
FT_UShort script_index,
FT_UShort* language_index,
FT_UShort* req_feature_index );
EXPORT_DEF
FT_Error TT_GSUB_Select_Feature( TTO_GSUBHeader* gsub,
FT_ULong feature_tag,
FT_UShort script_index,
FT_UShort language_index,
FT_UShort* feature_index );
EXPORT_DEF
FT_Error TT_GSUB_Query_Scripts( TTO_GSUBHeader* gsub,
FT_ULong** script_tag_list );
EXPORT_DEF
FT_Error TT_GSUB_Query_Languages( TTO_GSUBHeader* gsub,
FT_UShort script_index,
FT_ULong** language_tag_list );
EXPORT_DEF
FT_Error TT_GSUB_Query_Features( TTO_GSUBHeader* gsub,
FT_UShort script_index,
FT_UShort language_index,
FT_ULong** feature_tag_list );
EXPORT_DEF
FT_Error TT_GSUB_Add_Feature( TTO_GSUBHeader* gsub,
FT_UShort feature_index,
FT_UShort property );
EXPORT_DEF
FT_Error TT_GSUB_Clear_Features( TTO_GSUBHeader* gsub );
EXPORT_DEF
FT_Error TT_GSUB_Register_Alternate_Function( TTO_GSUBHeader* gsub,
TTO_AltFunction altfunc,
void* data );
EXPORT_DEF
FT_Error TT_GSUB_String_New( FT_Memory memory,
TTO_GSUB_String **result );
EXPORT_DEF
FT_Error TT_GSUB_String_Set_Length( TTO_GSUB_String *str,
FT_ULong new_length);
EXPORT_DEF
FT_Error TT_GSUB_String_Done( TTO_GSUB_String *str );
EXPORT_DEF
FT_Error TT_GSUB_Apply_String( TTO_GSUBHeader* gsub,
TTO_GSUB_String* in,
TTO_GSUB_String* out );
EXPORT_DEF
FT_Error TT_GSUB_Add_String( TTO_GSUB_String* in,
FT_UShort num_in,
TTO_GSUB_String* out,
FT_UShort num_out,
FT_UShort* glyph_data,
FT_UShort component,
FT_UShort ligID );
#ifdef __cplusplus
}
#endif
#endif /* FTXGSUB_H */
/* END */

1520
src/otlayout/ftxopen.c Normal file

File diff suppressed because it is too large Load Diff

314
src/otlayout/ftxopen.h Normal file
View File

@ -0,0 +1,314 @@
/*******************************************************************
*
* ftxopen.h
*
* TrueType Open support.
*
* Copyright 1996-2000 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.
*
* This file should be included by the application. Nevertheless,
* the table specific APIs (and structures) are located in files like
* ftxgsub.h or ftxgpos.h; these header files are read by ftxopen.h .
*
******************************************************************/
#ifndef FTXOPEN_H
#define FTXOPEN_H
#include <ft2build.h>
#include FT_FREETYPE_H
#ifdef __cplusplus
extern "C" {
#endif
#define EXPORT_DEF static
#define EXPORT_FUNC static
#define TTO_MAX_NESTING_LEVEL 100
#define TTO_Err_Invalid_SubTable_Format 0x1000
#define TTO_Err_Invalid_SubTable 0x1001
#define TTO_Err_Not_Covered 0x1002
#define TTO_Err_Too_Many_Nested_Contexts 0x1003
#define TTO_Err_No_MM_Interpreter 0x1004
#define TTO_Err_Empty_Script 0x1005
/* Script list related structures */
struct TTO_LangSys_
{
FT_UShort LookupOrderOffset; /* always 0 for TT Open 1.0 */
FT_UShort ReqFeatureIndex; /* required FeatureIndex */
FT_UShort FeatureCount; /* number of Feature indices */
FT_UShort* FeatureIndex; /* array of Feature indices */
};
typedef struct TTO_LangSys_ TTO_LangSys;
struct TTO_LangSysRecord_
{
FT_ULong LangSysTag; /* LangSysTag identifier */
TTO_LangSys LangSys; /* LangSys table */
};
typedef struct TTO_LangSysRecord_ TTO_LangSysRecord;
struct TTO_Script_
{
TTO_LangSys DefaultLangSys; /* DefaultLangSys table */
FT_UShort LangSysCount; /* number of LangSysRecords */
TTO_LangSysRecord* LangSysRecord; /* array of LangSysRecords */
};
typedef struct TTO_Script_ TTO_Script;
struct TTO_ScriptRecord_
{
FT_ULong ScriptTag; /* ScriptTag identifier */
TTO_Script Script; /* Script table */
};
typedef struct TTO_ScriptRecord_ TTO_ScriptRecord;
struct TTO_ScriptList_
{
FT_UShort ScriptCount; /* number of ScriptRecords */
TTO_ScriptRecord* ScriptRecord; /* array of ScriptRecords */
};
typedef struct TTO_ScriptList_ TTO_ScriptList;
/* Feature list related structures */
struct TTO_Feature_
{
FT_UShort FeatureParams; /* always 0 for TT Open 1.0 */
FT_UShort LookupListCount; /* number of LookupList indices */
FT_UShort* LookupListIndex; /* array of LookupList indices */
};
typedef struct TTO_Feature_ TTO_Feature;
struct TTO_FeatureRecord_
{
FT_ULong FeatureTag; /* FeatureTag identifier */
TTO_Feature Feature; /* Feature table */
};
typedef struct TTO_FeatureRecord_ TTO_FeatureRecord;
struct TTO_FeatureList_
{
FT_UShort FeatureCount; /* number of FeatureRecords */
TTO_FeatureRecord* FeatureRecord; /* array of FeatureRecords */
};
typedef struct TTO_FeatureList_ TTO_FeatureList;
/* Lookup list related structures */
struct TTO_SubTable_; /* defined below after inclusion
of ftxgsub.h and ftxgpos.h */
typedef struct TTO_SubTable_ TTO_SubTable;
struct TTO_Lookup_
{
FT_UShort LookupType; /* Lookup type */
FT_UShort LookupFlag; /* Lookup qualifiers */
FT_UShort SubTableCount; /* number of SubTables */
TTO_SubTable* SubTable; /* array of SubTables */
};
typedef struct TTO_Lookup_ TTO_Lookup;
/* The `Properties' field is not defined in the TTO specification but
is needed for processing lookups. If properties[n] is > 0, the
functions TT_GSUB_Apply_String() resp. TT_GPOS_Apply_String() will
process Lookup[n] for glyphs which have the specific bit not set in
the `properties' field of the input string object. */
struct TTO_LookupList_
{
FT_UShort LookupCount; /* number of Lookups */
TTO_Lookup* Lookup; /* array of Lookup records */
FT_UShort* Properties; /* array of flags */
};
typedef struct TTO_LookupList_ TTO_LookupList;
/* Possible LookupFlag bit masks. `IGNORE_SPECIAL_MARKS' comes from the
OpenType 1.2 specification; RIGHT_TO_LEFT has been (re)introduced in
OpenType 1.3 -- if set, the last glyph in a cursive attachment
sequence has to be positioned on the baseline -- regardless of the
writing direction. */
#define RIGHT_TO_LEFT 0x0001
#define IGNORE_BASE_GLYPHS 0x0002
#define IGNORE_LIGATURES 0x0004
#define IGNORE_MARKS 0x0008
#define IGNORE_SPECIAL_MARKS 0xFF00
struct TTO_CoverageFormat1_
{
FT_UShort GlyphCount; /* number of glyphs in GlyphArray */
FT_UShort* GlyphArray; /* array of glyph IDs */
};
typedef struct TTO_CoverageFormat1_ TTO_CoverageFormat1;
struct TTO_RangeRecord_
{
FT_UShort Start; /* first glyph ID in the range */
FT_UShort End; /* last glyph ID in the range */
FT_UShort StartCoverageIndex; /* coverage index of first
glyph ID in the range */
};
typedef struct TTO_RangeRecord_ TTO_RangeRecord;
struct TTO_CoverageFormat2_
{
FT_UShort RangeCount; /* number of RangeRecords */
TTO_RangeRecord* RangeRecord; /* array of RangeRecords */
};
typedef struct TTO_CoverageFormat2_ TTO_CoverageFormat2;
struct TTO_Coverage_
{
FT_UShort CoverageFormat; /* 1 or 2 */
union
{
TTO_CoverageFormat1 cf1;
TTO_CoverageFormat2 cf2;
} cf;
};
typedef struct TTO_Coverage_ TTO_Coverage;
struct TTO_ClassDefFormat1_
{
FT_UShort StartGlyph; /* first glyph ID of the
ClassValueArray */
FT_UShort GlyphCount; /* size of the ClassValueArray */
FT_UShort* ClassValueArray; /* array of class values */
};
typedef struct TTO_ClassDefFormat1_ TTO_ClassDefFormat1;
struct TTO_ClassRangeRecord_
{
FT_UShort Start; /* first glyph ID in the range */
FT_UShort End; /* last glyph ID in the range */
FT_UShort Class; /* applied to all glyphs in range */
};
typedef struct TTO_ClassRangeRecord_ TTO_ClassRangeRecord;
struct TTO_ClassDefFormat2_
{
FT_UShort ClassRangeCount;
/* number of ClassRangeRecords */
TTO_ClassRangeRecord* ClassRangeRecord;
/* array of ClassRangeRecords */
};
typedef struct TTO_ClassDefFormat2_ TTO_ClassDefFormat2;
/* The `Defined' field is not defined in the TTO specification but
apparently needed for processing fonts like trado.ttf: This font
refers to a class which contains not a single element. We map such
classes to class 0. */
struct TTO_ClassDefinition_
{
FT_Bool loaded;
FT_Bool* Defined; /* array of Booleans.
If Defined[n] is FALSE,
class n contains no glyphs. */
FT_UShort ClassFormat; /* 1 or 2 */
union
{
TTO_ClassDefFormat1 cd1;
TTO_ClassDefFormat2 cd2;
} cd;
};
typedef struct TTO_ClassDefinition_ TTO_ClassDefinition;
struct TTO_Device_
{
FT_UShort StartSize; /* smallest size to correct */
FT_UShort EndSize; /* largest size to correct */
FT_UShort DeltaFormat; /* DeltaValue array data format:
1, 2, or 3 */
FT_UShort* DeltaValue; /* array of compressed data */
};
typedef struct TTO_Device_ TTO_Device;
#include "ftxgdef.h"
#include "ftxgsub.h"
#include "ftxgpos.h"
struct TTO_SubTable_
{
union
{
TTO_GSUB_SubTable gsub;
TTO_GPOS_SubTable gpos;
} st;
};
enum TTO_Type_
{
GSUB,
GPOS
};
typedef enum TTO_Type_ TTO_Type;
#ifdef __cplusplus
}
#endif
#endif /* FTXOPEN_H */
/* END */

163
src/otlayout/ftxopenf.h Normal file
View File

@ -0,0 +1,163 @@
/*******************************************************************
*
* ftxopenf.h
*
* internal TrueType Open functions
*
* Copyright 1996-2000 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 FTXOPENF_H
#define FTXOPENF_H
#include "ftxopen.h"
#ifdef __cplusplus
extern "C" {
#endif
/* functions from ftxopen.c */
FT_Error Load_ScriptList( TTO_ScriptList* sl,
FT_Stream stream );
FT_Error Load_FeatureList( TTO_FeatureList* fl,
FT_Stream input );
FT_Error Load_LookupList( TTO_LookupList* ll,
FT_Stream input,
TTO_Type type );
FT_Error Load_Coverage( TTO_Coverage* c,
FT_Stream input );
FT_Error Load_ClassDefinition( TTO_ClassDefinition* cd,
FT_UShort limit,
FT_Stream input );
FT_Error Load_EmptyClassDefinition( TTO_ClassDefinition* cd,
FT_Stream input );
FT_Error Load_Device( TTO_Device* d,
FT_Stream input );
void Free_ScriptList( TTO_ScriptList* sl,
FT_Memory memory );
void Free_FeatureList( TTO_FeatureList* fl,
FT_Memory memory );
void Free_LookupList( TTO_LookupList* ll,
TTO_Type type,
FT_Memory memory );
void Free_Coverage( TTO_Coverage* c,
FT_Memory memory );
void Free_ClassDefinition( TTO_ClassDefinition* cd,
FT_Memory memory );
void Free_Device( TTO_Device* d,
FT_Memory memory );
/* functions from ftxgsub.c */
FT_Error Load_SingleSubst( TTO_SingleSubst* ss,
FT_Stream input );
FT_Error Load_MultipleSubst( TTO_MultipleSubst* ms,
FT_Stream input );
FT_Error Load_AlternateSubst( TTO_AlternateSubst* as,
FT_Stream input );
FT_Error Load_LigatureSubst( TTO_LigatureSubst* ls,
FT_Stream input );
FT_Error Load_ContextSubst( TTO_ContextSubst* cs,
FT_Stream input );
FT_Error Load_ChainContextSubst( TTO_ChainContextSubst* ccs,
FT_Stream input );
void Free_SingleSubst( TTO_SingleSubst* ss,
FT_Memory memory );
void Free_MultipleSubst( TTO_MultipleSubst* ms,
FT_Memory memory );
void Free_AlternateSubst( TTO_AlternateSubst* as,
FT_Memory memory );
void Free_LigatureSubst( TTO_LigatureSubst* ls,
FT_Memory memory );
void Free_ContextSubst( TTO_ContextSubst* cs,
FT_Memory memory );
void Free_ChainContextSubst( TTO_ChainContextSubst* ccs,
FT_Memory memory );
/* functions from ftxgpos.c */
FT_Error Load_SinglePos( TTO_SinglePos* sp,
FT_Stream input );
FT_Error Load_PairPos( TTO_PairPos* pp,
FT_Stream input );
FT_Error Load_CursivePos( TTO_CursivePos* cp,
FT_Stream input );
FT_Error Load_MarkBasePos( TTO_MarkBasePos* mbp,
FT_Stream input );
FT_Error Load_MarkLigPos( TTO_MarkLigPos* mlp,
FT_Stream input );
FT_Error Load_MarkMarkPos( TTO_MarkMarkPos* mmp,
FT_Stream input );
FT_Error Load_ContextPos( TTO_ContextPos* cp,
FT_Stream input );
FT_Error Load_ChainContextPos( TTO_ChainContextPos* ccp,
FT_Stream input );
void Free_SinglePos( TTO_SinglePos* sp,
FT_Memory memory );
void Free_PairPos( TTO_PairPos* pp,
FT_Memory memory );
void Free_CursivePos( TTO_CursivePos* cp,
FT_Memory memory );
void Free_MarkBasePos( TTO_MarkBasePos* mbp,
FT_Memory memory );
void Free_MarkLigPos( TTO_MarkLigPos* mlp,
FT_Memory memory );
void Free_MarkMarkPos( TTO_MarkMarkPos* mmp,
FT_Memory memory );
void Free_ContextPos( TTO_ContextPos* cp,
FT_Memory memory );
void Free_ChainContextPos( TTO_ChainContextPos* ccp,
FT_Memory memory );
/* query functions */
FT_Error Coverage_Index( TTO_Coverage* c,
FT_UShort glyphID,
FT_UShort* index );
FT_Error Get_Class( TTO_ClassDefinition* cd,
FT_UShort glyphID,
FT_UShort* class,
FT_UShort* index );
FT_Error Get_Device( TTO_Device* d,
FT_UShort size,
FT_Short* value );
/* functions from ftxgdef.c */
FT_Error Add_Glyph_Property( TTO_GDEFHeader* gdef,
FT_UShort glyphID,
FT_UShort property );
FT_Error Check_Property( TTO_GDEFHeader* gdef,
FT_UShort index,
FT_UShort flags,
FT_UShort* property );
#define CHECK_Property( gdef, index, flags, property ) \
( ( error = Check_Property( (gdef), (index), (flags), \
(property) ) ) != TT_Err_Ok )
#ifdef __cplusplus
}
#endif
#endif /* FTXOPENF_H */
/* END */

22
src/otlayout/module.mk Normal file
View File

@ -0,0 +1,22 @@
#
# FreeType 2 GX module definition
#
# Copyright 1996-2000 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.
make_module_list: add_ot_driver
add_ot_driver:
$(OPEN_DRIVER)ot_driver_class$(CLOSE_DRIVER)
$(ECHO_DRIVER)ot $(ECHO_DRIVER_DESC)OpenType fonts$(ECHO_DRIVER_DONE)
# EOF

93
src/otlayout/ot-array.c Normal file
View File

@ -0,0 +1,93 @@
/* OTArray
*
* Copyright (C) 2003 Red Hat.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "ot-array.h"
#include FT_INTERNAL_MEMORY_H
#include FT_CONFIG_STANDARD_LIBRARY_H
#define OT_REALLOC_ARRAY( _pointer_, _old_, _new_, eltsize ) \
FT_SET_ERROR( FT_MEM_REALLOC( _pointer_, \
(_old_) * eltsize, \
(_new_) * eltsize ) )
FT_LOCAL_DEF( OTArray * )
OT_Array_New ( FT_UInt element_size, FT_Memory memory )
{
FT_Error error;
OTArray * array;
if ( FT_NEW ( array ) )
return NULL;
array->data = NULL;
array->length = 0;
array->allocated = 0;
array->element_size = element_size;
array->memory = memory;
return OT_Array_Set_Size ( array, 4 );
}
FT_LOCAL_DEF( void )
OT_Array_Free ( OTArray * array )
{
FT_Memory memory = array->memory;
FT_FREE( array->data );
FT_FREE( array );
}
FT_LOCAL_DEF( OTArray * )
OT_Array_Set_Size ( OTArray * array, FT_UInt length )
{
FT_Error error;
FT_Memory memory = array->memory;
if ( length > array->allocated )
{
if ( OT_REALLOC_ARRAY(array->data,
array->allocated,
length,
array->element_size) )
return NULL;
array->allocated = length;
}
array->length = length;
return array;
}
FT_LOCAL_DEF( void )
OT_Array_Sort ( OTArray * array, OT_Array_Comapre_Func func )
{
ft_qsort ( array->data, array->length, array->element_size, func );
}
FT_LOCAL_DEF( OTArray * )
OT_Array_Append_Val ( OTArray * array, FT_Pointer newval )
{
FT_UInt index;
FT_Pointer dest;
if ( !OT_Array_Set_Size( array, array->length + 1 ) )
return NULL;
index = array->length - 1;
dest = array->data + ( index * array->element_size );
FT_MEM_COPY ( dest, newval, array->element_size );
return array;
}

50
src/otlayout/ot-array.h Normal file
View File

@ -0,0 +1,50 @@
/* OTArray
*
* Copyright (C) 2003 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __OT_ARRAY_H__
#define __OT_ARRAY_H__
#include <ft2build.h>
#include FT_FREETYPE_H
FT_BEGIN_HEADER
typedef struct _OTArray OTArray;
typedef FT_Int (*OT_Array_Comapre_Func) (const void * a, const void * b );
struct _OTArray
{
FT_Char * data;
FT_UInt length;
FT_UInt element_size;
FT_UInt allocated;
FT_Memory memory;
};
FT_LOCAL( OTArray * ) OT_Array_New ( FT_UInt element_size, FT_Memory memory );
FT_LOCAL( void ) OT_Array_Free ( OTArray * array );
FT_LOCAL( OTArray * ) OT_Array_Set_Size ( OTArray * array, FT_UInt length );
FT_LOCAL( void ) OT_Array_Sort ( OTArray * array, OT_Array_Comapre_Func func );
FT_LOCAL( OTArray * ) OT_Array_Append_Val ( OTArray * array, FT_Pointer newval );
#define OT_Array_Index(array, type, index) (((type*)((array)->data))[(index)])
FT_END_HEADER
#endif /* Not def: __OT_ARRAY_H__ */

762
src/otlayout/ot-info.c Normal file
View File

@ -0,0 +1,762 @@
/*
* ot-info.c: Store tables for OpenType
*
* Copyright (C) 2003 Red Hat K.K.
* Copyright (C) 2000 Red Hat Software
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "ot-info.h"
#include "ot-ruleset.h"
#include "ot-unicode.h"
#include "fterrcompat.h"
#include FT_INTERNAL_OBJECTS_H
#include FT_MODULE_H
#define noINFO_DEBUG_MEMORY
enum
{
INFO_LOADED_GDEF = 1 << 0,
INFO_LOADED_GSUB = 1 << 1,
INFO_LOADED_GPOS = 1 << 2
};
static FT_Error ot_table_check( FT_Face face );
OTInfo *
ot_info_new ( FT_Face face )
{
FT_Error error;
OTInfo *info;
FT_Memory memory;
if ( ot_table_check( face ) )
return NULL;
memory = FT_FACE_MEMORY( face );
if ( FT_NEW ( info ) )
return NULL;
ot_info_setup (info);
return info;
}
static FT_Error
ot_table_check( FT_Face face )
{
FT_Stream stream = face->stream;
TT_Face tt_face = (TT_Face)face;
FT_Error error_gdef, error_gpos, error_gsub;
error_gdef = tt_face->goto_table( tt_face, TTAG_GDEF, stream, 0 );
error_gsub = tt_face->goto_table( tt_face, TTAG_GSUB, stream, 0 );
error_gpos = tt_face->goto_table( tt_face, TTAG_GPOS, stream, 0 );
if ( (!error_gdef) || (!error_gsub) || (!error_gpos) )
return FT_Err_Ok;
else
return OT_Err_Unknown_File_Format;
}
OTInfo *
ot_info_delete (OTInfo *info)
{
FT_Memory memory = FT_FACE_MEMORY( info->face );
if (info) {
ot_info_release (info);
FT_FREE( info );
}
return NULL;
}
OTInfo *
ot_info_ref (OTInfo *info)
{
FT_ASSERT (info != NULL );
FT_ASSERT (info->refcount > 0);
info->refcount += 1;
return info;
}
OTInfo *
ot_info_unref (OTInfo *info)
{
FT_ASSERT (info != NULL);
FT_ASSERT (info->refcount > 0);
info->refcount -= 1;
if (info->refcount == 0) {
ot_info_delete (info);
return NULL;
}
return info;
}
#ifdef INFO_DEBUG_MEMORY
static int ot_info_count = 0;
#endif
OTInfo *
ot_info_setup (OTInfo *info)
{
#ifdef INFO_DEBUG_MEMORY
ot_info_count++;
FT_Message ("ot_info_setup: %d\n", ot_info_count);
#endif
info->refcount = 1;
info->gsub = NULL;
info->gdef = NULL;
info->gpos = NULL;
info->ruleset = NULL;
return info;
}
OTInfo *
ot_info_release (OTInfo *info)
{
FT_ASSERT (info != NULL);
#ifdef INFO_DEBUG_MEMORY
ot_info_count--;
FT_Message ("ot_info_release: %d\n", ot_info_count);
#endif
if (info->gdef)
{
TT_Done_GDEF_Table (info->gdef);
info->gdef = NULL;
}
if (info->gsub)
{
TT_Done_GSUB_Table (info->gsub);
info->gsub = NULL;
}
if (info->gpos)
{
TT_Done_GPOS_Table (info->gpos);
info->gpos = NULL;
}
if (info->ruleset)
{
ot_ruleset_delete (info->ruleset);
info->ruleset = NULL;
}
return info;
}
/* static int info_count = 0; */
void
ot_info_finalizer (void *object)
{
FT_Face face = object;
OTInfo *info = face->generic.data;
ot_info_unref (info);
info->face = NULL;
}
/**
* ot_info_get_ruleset
*
* @returns: the #OTRulset for @info. This object will
* have the same lifetime as OTInfo.
*
* Returns the #OTRuleset structure for the info.
*/
OTRuleset *
ot_info_get_ruleset (OTInfo *info)
{
if (! info->ruleset) {
info->ruleset = ot_ruleset_new (info);
}
return info->ruleset;
}
/**
* ot_info_get:
* @face: a #FT_Face.
* @returns: the #OTInfo for @face. This object will
* have the same lifetime as FT_Face.
*
* Returns the #OTInfo structure for the given FreeType font.
*
* Since: 1.2
**/
OTInfo *
ot_info_get (FT_Face face)
{
OTInfo *info;
if (face->generic.data)
return face->generic.data;
else
{
info = ot_info_new ( face );
if ( info ) {
face->generic.data = info;
face->generic.finalizer = ot_info_finalizer;
info->face = face;
}
}
return info;
}
/* There must be be a better way to do this
*/
static FT_Bool
is_truetype (FT_Face face)
{
return (
(strcmp (FT_MODULE_CLASS (face->driver)->module_name, "truetype") == 0)
|| (strcmp (FT_MODULE_CLASS (face->driver)->module_name, "ot") == 0)
);
}
typedef struct _GlyphInfo GlyphInfo;
struct _GlyphInfo {
FT_UShort glyph;
FT_UShort class;
};
static int
compare_glyph_info (const void * a,
const void * b)
{
const GlyphInfo *info_a = a;
const GlyphInfo *info_b = b;
return (info_a->glyph < info_b->glyph) ? -1 :
(info_a->glyph == info_b->glyph) ? 0 : 1;
}
/* Make a guess at the appropriate class for a glyph given
* a character code that maps to the glyph
*/
static FT_Bool
set_unicode_charmap (FT_Face face)
{
int charmap;
for (charmap = 0; charmap < face->num_charmaps; charmap++)
if (face->charmaps[charmap]->encoding == ft_encoding_unicode)
{
FT_Error error = FT_Set_Charmap(face, face->charmaps[charmap]);
return error == FT_Err_Ok;
}
return FALSE;
}
/* Synthesize a GDEF table using the font's charmap and the
* unicode property database. We'll fill in class definitions
* for glyphs not in the charmap as we walk through the tables.
*/
static void
synthesize_class_def (OTInfo *info)
{
OTArray *glyph_infos;
FT_UShort *glyph_indices;
FT_UShort *classes;
FT_ULong charcode;
FT_UInt glyph;
int i, j;
FT_CharMap old_charmap;
FT_Error error;
FT_Memory memory = FT_FACE_MEMORY( info->face );
old_charmap = info->face->charmap;
if (!old_charmap || !old_charmap->encoding != ft_encoding_unicode)
if (!set_unicode_charmap (info->face))
return;
glyph_infos = OT_Array_New ( sizeof (GlyphInfo), memory );
/* Collect all the glyphs in the charmap, and guess
* the appropriate classes for them
*/
charcode = FT_Get_First_Char (info->face, &glyph);
while (glyph != 0)
{
GlyphInfo glyph_info;
if (glyph <= 65535)
{
glyph_info.glyph = glyph;
glyph_info.class = ot_get_glyph_class (charcode);
OT_Array_Append_Val ( glyph_infos, &glyph_info );
}
charcode = FT_Get_Next_Char (info->face, charcode, &glyph);
}
/* Sort and remove duplicates
*/
OT_Array_Sort ( glyph_infos, compare_glyph_info );
FT_ALLOC_ARRAY( glyph_indices, glyph_infos->length, FT_UShort );
FT_ALLOC_ARRAY( classes, glyph_infos->length, FT_UShort );
for (i = 0, j = 0; i < glyph_infos->length; i++)
{
GlyphInfo *info = &OT_Array_Index (glyph_infos, GlyphInfo, i);
if (j == 0 || info->glyph != glyph_indices[j - 1])
{
glyph_indices[j] = info->glyph;
classes[j] = info->class;
j++;
}
}
OT_Array_Free ( glyph_infos );
TT_GDEF_Build_ClassDefinition (info->gdef, info->face->num_glyphs, j,
glyph_indices, classes);
FT_FREE( glyph_indices );
FT_FREE( classes );
if (old_charmap && info->face->charmap != old_charmap)
FT_Set_Charmap (info->face, old_charmap);
}
TTO_GDEF
ot_info_get_gdef (OTInfo *info)
{
FT_ASSERT (info != NULL);
if (!(info->loaded & INFO_LOADED_GDEF))
{
FT_Error error;
info->loaded |= INFO_LOADED_GDEF;
if (is_truetype (info->face))
{
error = TT_Load_GDEF_Table (info->face, &info->gdef);
if (error && error != TT_Err_Table_Missing)
FT_ERROR (("Error loading GDEF table %d", error));
if (!info->gdef)
error = TT_New_GDEF_Table (info->face, &info->gdef);
if (info->gdef && !info->gdef->GlyphClassDef.loaded)
synthesize_class_def (info);
}
}
return info->gdef;
}
TTO_GSUB
ot_info_get_gsub (OTInfo *info)
{
FT_ASSERT (info != NULL);
if (!(info->loaded & INFO_LOADED_GSUB))
{
FT_Error error;
TTO_GDEF gdef = ot_info_get_gdef (info);
info->loaded |= INFO_LOADED_GSUB;
if (is_truetype (info->face))
{
error = TT_Load_GSUB_Table (info->face, &info->gsub, gdef);
if (error && error != TT_Err_Table_Missing)
FT_ERROR (("Error loading GSUB table %d", error));
}
}
return info->gsub;
}
TTO_GPOS
ot_info_get_gpos (OTInfo *info)
{
FT_ASSERT (info != NULL);
if (!(info->loaded & INFO_LOADED_GPOS))
{
FT_Error error;
TTO_GDEF gdef = ot_info_get_gdef (info);
info->loaded |= INFO_LOADED_GPOS;
if (is_truetype (info->face))
{
error = TT_Load_GPOS_Table (info->face, &info->gpos, gdef);
if (error && error != TT_Err_Table_Missing)
FT_ERROR (("Error loading GPOS table %d", error));
}
}
return info->gpos;
}
static FT_Bool
get_tables (OTInfo *info,
OTTableType table_type,
TTO_ScriptList **script_list,
TTO_FeatureList **feature_list)
{
if (table_type == OT_TABLE_GSUB)
{
TTO_GSUB gsub = ot_info_get_gsub (info);
if (!gsub)
return FALSE;
else
{
if (script_list)
*script_list = &gsub->ScriptList;
if (feature_list)
*feature_list = &gsub->FeatureList;
return TRUE;
}
}
else
{
TTO_GPOS gpos = ot_info_get_gpos (info);
if (!gpos)
return FALSE;
else
{
if (script_list)
*script_list = &gpos->ScriptList;
if (feature_list)
*feature_list = &gpos->FeatureList;
return TRUE;
}
}
}
/**
* ot_info_find_script:
* @info: a #OTInfo.
* @table_type: the table type to obtain information about.
* @script_tag: the tag of the script to find.
* @script_index: location to store the index of the script, or %NULL.
* @returns: %TRUE if the script was found.
*
* Finds the index of a script.
**/
FT_Bool
ot_info_find_script (OTInfo *info,
OTTableType table_type,
OTTag script_tag,
FT_UInt *script_index)
{
TTO_ScriptList *script_list;
int i;
FT_ASSERT (info != NULL);
if (!get_tables (info, table_type, &script_list, NULL))
return FALSE;
for (i=0; i < script_list->ScriptCount; i++)
{
if (script_list->ScriptRecord[i].ScriptTag == script_tag)
{
if (script_index)
*script_index = i;
return TRUE;
}
}
return FALSE;
}
/**
* ot_info_find_language:
* @info: a #OTInfo.
* @table_type: the table type to obtain information about.
* @script_index: the index of the script whose languages are searched.
* @language_tag: the tag of the language to find.
* @language_index: location to store the index of the language, or %NULL.
* @required_feature_index: location to store the required feature index of
* the language, or %NULL.
* @returns: %TRUE if the language was found.
*
* Finds the index of a language and its required feature index.
**/
FT_Bool
ot_info_find_language (OTInfo *info,
OTTableType table_type,
FT_UInt script_index,
OTTag language_tag,
FT_UInt *language_index,
FT_UInt *required_feature_index)
{
TTO_ScriptList *script_list;
TTO_Script *script;
int i;
FT_ASSERT (info != NULL);
if (!get_tables (info, table_type, &script_list, NULL))
return FALSE;
FT_ASSERT (script_index < script_list->ScriptCount);
script = &script_list->ScriptRecord[script_index].Script;
for (i = 0; i < script->LangSysCount; i++)
{
if (script->LangSysRecord[i].LangSysTag == language_tag)
{
if (language_index)
*language_index = i;
if (required_feature_index)
*required_feature_index = script->LangSysRecord[i].LangSys.ReqFeatureIndex;
return TRUE;
}
}
return FALSE;
}
/**
* ot_info_find_feature:
* @info: a #OTInfo.
* @table_type: the table type to obtain information about.
* @feature_tag: the tag of the feature to find.
* @script_index: the index of the script.
* @language_index: the index of the language whose features are searched,
* or 0xffff to use the default language of the script.
* @feature_index: location to store the index of the feature, or %NULL.
* @returns: %TRUE if the feature was found.
*
* Finds the index of a feature.
**/
FT_Bool
ot_info_find_feature (OTInfo *info,
OTTableType table_type,
OTTag feature_tag,
FT_UInt script_index,
FT_UInt language_index,
FT_UInt *feature_index)
{
TTO_ScriptList *script_list;
TTO_FeatureList *feature_list;
TTO_Script *script;
TTO_LangSys *lang_sys;
int i;
FT_ASSERT (info != NULL);
if (!get_tables (info, table_type, &script_list, &feature_list))
return FALSE;
FT_ASSERT (script_index < script_list->ScriptCount);
script = &script_list->ScriptRecord[script_index].Script;
if (language_index == 0xffff)
lang_sys = &script->DefaultLangSys;
else
{
FT_ASSERT (language_index < script->LangSysCount);
lang_sys = &script->LangSysRecord[language_index].LangSys;
}
for (i = 0; i < lang_sys->FeatureCount; i++)
{
FT_UShort index = lang_sys->FeatureIndex[i];
if (feature_list->FeatureRecord[index].FeatureTag == feature_tag)
{
if (feature_index)
*feature_index = index;
return TRUE;
}
}
return FALSE;
}
/**
* ot_info_list_scripts:
* @info: a #OTInfo.
* @table_type: the table type to obtain information about.
* @returns: a newly-allocated array containing the tags of the
* available scripts.
*
* Obtains the list of available scripts.
**/
OTTag *
ot_info_list_scripts (OTInfo *info,
OTTableType table_type)
{
FT_Error error;
FT_Memory memory = FT_FACE_MEMORY( info->face );
OTTag *result;
TTO_ScriptList *script_list;
int i;
FT_ASSERT (info != NULL);
if (!get_tables (info, table_type, &script_list, NULL))
return NULL;
if ( FT_ALLOC_ARRAY ( result,
script_list->ScriptCount + 1,
OTTag ) )
return NULL;
for (i=0; i < script_list->ScriptCount; i++)
result[i] = script_list->ScriptRecord[i].ScriptTag;
result[i] = 0;
return result;
}
/**
* ot_info_list_languages:
* @info: a #OTInfo.
* @table_type: the table type to obtain information about.
* @script_index: the index of the script to list languages for.
* @language_tag: unused parameter.
* @returns: a newly-allocated array containing the tags of the
* available languages.
*
* Obtains the list of available languages for a given script.
**/
OTTag *
ot_info_list_languages (OTInfo *info,
OTTableType table_type,
FT_UInt script_index,
OTTag language_tag)
{
FT_Error error;
FT_Memory memory = FT_FACE_MEMORY( info->face );
OTTag *result;
TTO_ScriptList *script_list;
TTO_Script *script;
int i;
FT_ASSERT (info != NULL);
if (!get_tables (info, table_type, &script_list, NULL))
return NULL;
FT_ASSERT (script_index < script_list->ScriptCount);
script = &script_list->ScriptRecord[script_index].Script;
if ( FT_ALLOC_ARRAY ( result,
script->LangSysCount + 1,
OTTag ) )
return NULL;
for (i = 0; i < script->LangSysCount; i++)
result[i] = script->LangSysRecord[i].LangSysTag;
result[i] = 0;
return result;
}
/**
* ot_info_list_features:
* @info: a #OTInfo.
* @table_type: the table type to obtain information about.
* @tag: unused parameter.
* @script_index: the index of the script to obtain information about.
* @language_index: the indes of the language to list features for, or
* 0xffff, to list features for the default language of the script.
* @returns: a newly-allocated array containing the tags of the available
* features.
*
* Obtains the list of features for the given language of the given script.
**/
OTTag *
ot_info_list_features (OTInfo *info,
OTTableType table_type,
OTTag tag,
FT_UInt script_index,
FT_UInt language_index)
{
FT_Error error;
FT_Memory memory = FT_FACE_MEMORY( info->face );
OTTag *result;
TTO_ScriptList *script_list;
TTO_FeatureList *feature_list;
TTO_Script *script;
TTO_LangSys *lang_sys;
int i;
FT_ASSERT (info != NULL);
if (!get_tables (info, table_type, &script_list, &feature_list))
return NULL;
FT_ASSERT (script_index < script_list->ScriptCount);
script = &script_list->ScriptRecord[script_index].Script;
if (language_index == 0xffff)
lang_sys = &script->DefaultLangSys;
else
{
FT_ASSERT (language_index < script->LangSysCount);
lang_sys = &script->LangSysRecord[language_index].LangSys;
}
if ( FT_ALLOC_ARRAY ( result,
lang_sys->FeatureCount + 1,
OTTag ) )
return NULL;
for (i = 0; i < lang_sys->FeatureCount; i++)
{
FT_UShort index = lang_sys->FeatureIndex[i];
result[i] = feature_list->FeatureRecord[index].FeatureTag;
}
result[i] = 0;
return result;
}

103
src/otlayout/ot-info.h Normal file
View File

@ -0,0 +1,103 @@
/* OTInfo
*
* Copyright (C) 2000 Red Hat Software
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __OT_INFO_H__
#define __OT_INFO_H__
#include "ftxopen.h"
#include "ot-types.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _OTInfo
{
FT_Int refcount;
FT_UInt loaded;
FT_Face face;
TTO_GSUB gsub;
TTO_GDEF gdef;
TTO_GPOS gpos;
OTRuleset *ruleset;
};
/* Don't use these directly */
OTInfo *ot_info_new ( FT_Face face );
OTInfo *ot_info_delete (OTInfo *info);
OTInfo *ot_info_ref (OTInfo *info);
OTInfo *ot_info_unref (OTInfo *info);
OTInfo *ot_info_setup (OTInfo *info);
OTInfo *ot_info_release (OTInfo *info);
/* Member access */
TTO_GDEF ot_info_get_gdef (OTInfo *info);
TTO_GSUB ot_info_get_gsub (OTInfo *info);
TTO_GPOS ot_info_get_gpos (OTInfo *info);
OTRuleset *ot_info_get_ruleset (OTInfo *info);
OTInfo *ot_info_get (FT_Face face);
FT_Bool ot_info_find_script (OTInfo *info,
OTTableType table_type,
OTTag script_tag,
FT_UInt *script_index);
FT_Bool ot_info_find_language (OTInfo *info,
OTTableType table_type,
FT_UInt script_index,
OTTag language_tag,
FT_UInt *language_index,
FT_UInt *required_feature_index);
FT_Bool ot_info_find_feature (OTInfo *info,
OTTableType table_type,
OTTag feature_tag,
FT_UInt script_index,
FT_UInt language_index,
FT_UInt *feature_index);
OTTag *ot_info_list_scripts (OTInfo *info,
OTTableType table_type);
OTTag *ot_info_list_languages (OTInfo *info,
OTTableType table_type,
FT_UInt script_index,
OTTag language_tag);
OTTag *ot_info_list_features (OTInfo *info,
OTTableType table_type,
OTTag tag,
FT_UInt script_index,
FT_UInt language_index);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __OT_INFO_H__ */

312
src/otlayout/ot-ruleset.c Normal file
View File

@ -0,0 +1,312 @@
/*
* ot-ruleset.c: Shaping using OpenType features
*
* Copyright (C) 2000 Red Hat Software
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "ot-ruleset.h"
#include "ot-info.h"
#define noRULESET_DEBUG_MEMORY
#include FT_INTERNAL_MEMORY_H /* For FT_Free() */
#define OT_SCALE_26_6 (OT_SCALE / (1<<6))
#define OT_UNITS_26_6(d) (OT_SCALE_26_6 * (d))
typedef struct _OTRule OTRule;
struct _OTRule {
FT_ULong property_bit;
FT_UShort feature_index;
FT_UInt table_type : 1;
};
OTRuleset *
ot_ruleset_new (OTInfo *info)
{
OTRuleset *ruleset;
ruleset = malloc (sizeof (OTRuleset));
ot_ruleset_setup (ruleset, info);
return ruleset;
}
OTRuleset *
ot_ruleset_delete (OTRuleset *ruleset)
{
if (ruleset) {
ot_ruleset_release (ruleset);
free (ruleset);
}
return NULL;
}
#ifdef RULESET_DEBUG_MEMORY
static ot_ruleset_count = 0;
#endif
OTRuleset *
ot_ruleset_setup (OTRuleset *ruleset, OTInfo *info)
{
FT_Memory memory = FT_FACE_MEMORY( info->face );
FT_ASSERT (ruleset != NULL);
#ifdef RULESET_DEBUG_MEMORY
ot_ruleset_count++;
FT_Message("ot_ruleset_setup: %d\n", ot_ruleset_count);
#endif
ruleset->info = info;
ruleset->rules = OT_Array_New ( sizeof (OTRule), memory );
return ruleset;
}
OTRuleset *
ot_ruleset_release (OTRuleset *ruleset)
{
#ifdef RULESET_DEBUG_MEMORY
ot_ruleset_count--;
FT_Message("ot_ruleset_release: %d\n", ot_ruleset_count);
#endif
if (ruleset->rules) {
OT_Array_Free ( ruleset->rules );
ruleset->rules = NULL;
}
if (ruleset->info) {
ruleset->info = NULL;
}
return NULL;
}
void
ot_ruleset_copy ( OTRuleset * from, OTRuleset * to )
{
OTArray *from_array;
OTArray *to_array;
FT_UInt from_length;
FT_UInt i;
to->info = from->info;
from_array = from->rules;
from_length = from_array->length;
to_array = to->rules;
OT_Array_Set_Size( to_array, from_length );
for ( i = 0; i < from_length; i++ )
OT_Array_Index(to_array, OTRule, i) = OT_Array_Index(from_array, OTRule, i);
}
/**
* ot_ruleset_add_feature:
* @ruleset: a #OTRuleset.
* @table_type: the table type to add a feature to.
* @feature_index: the index of the feature to add.
* @property_bit: the property bit to use for this feature.
*
* Adds a feature to the ruleset. See ot_ruleset_shape()
* for an explanation of @property_bit.
**/
void
ot_ruleset_add_feature (OTRuleset *ruleset, OTTableType table_type, FT_UInt feature_index, FT_ULong property_bit)
{
OTRule tmp_rule;
FT_ASSERT (ruleset != NULL);
tmp_rule.table_type = table_type;
tmp_rule.feature_index = feature_index;
tmp_rule.property_bit = property_bit;
OT_Array_Append_Val (ruleset->rules, &tmp_rule);
}
/**
* ot_ruleset_shape:
* @ruleset: a #OTRuleset.
* @glyphs: a pointer to a #OTGlyphString.
*
* Shapes a string of glyphs with the given properties according to @ruleset.
**/
OTGlyphString *
ot_ruleset_shape ( OTRuleset *ruleset, OTGlyphString *glyphs )
{
FT_Error error;
int i;
int last_cluster;
int result;
TTO_GSUB gsub = NULL;
TTO_GPOS gpos = NULL;
TTO_GSUB_String *in_string = NULL;
TTO_GSUB_String *out_string = NULL;
TTO_GSUB_String *result_string = NULL;
FT_Bool need_gsub = 0;
FT_Bool need_gpos = 0;
FT_ASSERT (ruleset != NULL);
for (i = 0; i < ruleset->rules->length; i++)
{
OTRule *rule = &OT_Array_Index (ruleset->rules, OTRule, i);
if (rule->table_type == OT_TABLE_GSUB)
need_gsub = 1;
else
need_gpos = 1;
}
if (need_gsub)
{
gsub = ot_info_get_gsub (ruleset->info);
if (gsub)
TT_GSUB_Clear_Features (gsub);
}
if (need_gpos)
{
gpos = ot_info_get_gpos (ruleset->info);
if (gpos)
TT_GPOS_Clear_Features (gpos);
}
for (i = 0; i < ruleset->rules->length; i++)
{
OTRule *rule = &OT_Array_Index (ruleset->rules, OTRule, i);
if (rule->table_type == OT_TABLE_GSUB)
{
if (gsub)
TT_GSUB_Add_Feature (gsub, rule->feature_index, rule->property_bit);
}
else
{
if (gpos)
TT_GPOS_Add_Feature (gpos, rule->feature_index, rule->property_bit);
}
}
if (!gsub && !gpos)
return glyphs;
result = TT_GSUB_String_New (ruleset->info->face->memory, &in_string);
FT_ASSERT (result == FT_Err_Ok);
result = TT_GSUB_String_Set_Length (in_string, glyphs->length);
FT_ASSERT (result == FT_Err_Ok);
for (i = 0; i < glyphs->length; i++)
{
in_string->string[i] = glyphs->glyphs[i].gid;
in_string->properties[i] = glyphs->glyphs[i].ot_prop;
#if 0
in_string->logClusters[i] = glyphs->log_clusters[i];
#endif
}
in_string->max_ligID = i;
if (gsub)
{
result = TT_GSUB_String_New (ruleset->info->face->memory,
&out_string);
FT_ASSERT (result == FT_Err_Ok);
result_string = out_string;
TT_GSUB_Apply_String (gsub, in_string, out_string);
}
else
result_string = in_string;
#if 0 /* TODO: implement this using nr-glyphs */
if (gpos)
{
TTO_GPOS_Data *outgpos = NULL;
if (!TT_GPOS_Apply_String (ruleset->info->face, gpos, 0, result_string, &outgpos,
FALSE /* enable device-dependant values */,
FALSE /* Even though this might be r2l text, RTL is handled elsewhere */))
{
for (i = 0; i < result_string->length; i++)
{
FT_Pos x_pos = outgpos[i].x_pos;
FT_Pos y_pos = outgpos[i].y_pos;
int back = i;
int j;
while (outgpos[back].back != 0)
{
back -= outgpos[back].back;
x_pos += outgpos[back].x_pos;
y_pos += outgpos[back].y_pos;
}
for (j = back; j < i; j++)
glyphs->glyphs[i].geometry.x_offset -= glyphs->glyphs[j].geometry.width;
glyphs->glyphs[i].geometry.x_offset += OT_UNITS_26_6(x_pos);
glyphs->glyphs[i].geometry.y_offset += OT_UNITS_26_6(y_pos);
if (outgpos[i].new_advance)
glyphs->glyphs[i].geometry.width = OT_UNITS_26_6(outgpos[i].x_advance);
else
glyphs->glyphs[i].geometry.width += OT_UNITS_26_6(outgpos[i].x_advance);
}
FT_Free(gpos->memory, (void *)outgpos);
}
}
#endif
if (glyphs->length != result_string->length)
{
if (( error = FTL_Set_Glyphs_Array_Length( glyphs, result_string->length ) ))
return glyphs;
}
last_cluster = -1;
for (i = 0; i < result_string->length; i++)
{
glyphs->glyphs[i].gid = result_string->string[i];
/* TODO: Other fields */
#if 0 /* TODO: */
glyphs->log_clusters[i] = result_string->logClusters[i];
if (glyphs->log_clusters[i] != last_cluster)
glyphs->glyphs[i].attr.is_cluster_start = 1;
else
glyphs->glyphs[i].attr.is_cluster_start = 0;
last_cluster = glyphs->log_clusters[i];
#endif
}
if (in_string)
TT_GSUB_String_Done (in_string);
if (out_string)
TT_GSUB_String_Done (out_string);
return glyphs;
}

64
src/otlayout/ot-ruleset.h Normal file
View File

@ -0,0 +1,64 @@
/*
* ot-ruleset.h: Shaping using OpenType features
*
* Copyright (C) 2000 Red Hat Software
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __OT_RULESET_H__
#define __OT_RULESET_H__
#include "ftxopen.h"
#include "ot-types.h"
#include "ot-array.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _OTRuleset
{
OTArray *rules;
OTInfo *info;
};
/* Dynamic lifecycle */
OTRuleset *ot_ruleset_new (OTInfo *info);
OTRuleset *ot_ruleset_delete (OTRuleset *ruleset);
/* Automatic lifecycle */
OTRuleset *ot_ruleset_setup (OTRuleset *ruleset, OTInfo *info);
OTRuleset *ot_ruleset_release (OTRuleset *ruleset);
void ot_ruleset_copy ( OTRuleset * from, OTRuleset * to );
void ot_ruleset_add_feature (OTRuleset *ruleset,
OTTableType table_type,
FT_UInt feature_index,
FT_ULong property_bit);
OTGlyphString *ot_ruleset_shape ( OTRuleset *ruleset,
OTGlyphString *glyphs );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __OT_RULESET_H__ */

39
src/otlayout/ot-types.h Normal file
View File

@ -0,0 +1,39 @@
/* ot-types.h
*
* Copyright (C) 2000 Red Hat Software
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __OT_TYPES_H__
#define __OT_TYPES_H__
#include <ft2build.h>
#include FT_LAYOUT_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _OTInfo OTInfo;
typedef struct _OTRuleset OTRuleset;
typedef FTL_Glyphs_ArrayRec OTGlyphString;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __OT_TYPES_H__ */

8359
src/otlayout/ot-unicode.c Normal file

File diff suppressed because it is too large Load Diff

39
src/otlayout/ot-unicode.h Normal file
View File

@ -0,0 +1,39 @@
/* ot-unicode.[ch] are copied from gunicode.[ch] */
/* gunicode.h - Unicode manipulation functions
*
* Copyright (C) 1999, 2000 Tom Tromey
* Copyright 2000 Red Hat, Inc.
*
* The Gnome Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The Gnome Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __OT_UNICODE_H__
#define __OT_UNICODE_H__
#include <ft2build.h>
#include FT_FREETYPE_H
FT_BEGIN_HEADER
/* 3: Mark glyph (non-spacing combining glyph),
1: Base glyph (single character, spacing glyph) */
FT_LOCAL(FT_UShort) ot_get_glyph_class(FT_ULong charcode);
FT_END_HEADER
#endif /* Not def: __OT_UNICODE_H__ */

42
src/otlayout/ot.c Normal file
View File

@ -0,0 +1,42 @@
/***************************************************************************/
/* */
/* ot.c */
/* */
/* FreeType OpenType driver component (body only). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
#include "otdriver.c"
#include "otobjs.c"
#include "otlayout.c"
#include "ftxgsub.c"
#include "ftxgdef.c"
#include "ftxgpos.c"
#include "ftxopen.c"
#include "ot-info.c"
#include "ot-ruleset.c"
#include "ot-array.c"
#include "ot-unicode.c"
/* END */

211
src/otlayout/otdemo.c Normal file
View File

@ -0,0 +1,211 @@
/***************************************************************************/
/* */
/* otdemo.c */
/* */
/* Demo program for FreeType/OpenType font driver implementation (body).*/
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include FT_LAYOUT_H
#include FT_OTLAYOUT_H
#include <stdio.h>
#include <stdlib.h>
#include <popt.h>
/* KANA specific implementation */
/* Script */
#define OT_SCRIPT_KANA FT_MAKE_TAG('k', 'a', 'n', 'a')
/* Language */
#define OT_LANGUAGE_JAPANESE FT_MAKE_TAG('J', 'A', 'N', ' ')
/* Feature */
#define OT_FEATURE_VERT FT_MAKE_TAG('v', 'e', 'r', 't')
#define OT_FEATURE_VRT2 FT_MAKE_TAG('v', 'r', 't', '2')
/* Property bit */
enum {
OT_VERT = 1 << 0,
OT_VRT2 = 1 << 1
};
/* Property */
enum {
OT_VERT_P = (~OT_VERT) & (~OT_VRT2)
};
void doit(FT_Face face);
int
main(int argc, char ** argv)
{
FT_Library library;
FT_Face face;
poptContext optCon;
int rc;
const char * file;
static int arg_memprof = 0;
struct poptOption optTable [] = {
{ "memprof", 'm', POPT_ARG_NONE, &arg_memprof, 0, "Enter to infinite loop to run under memprof", ""},
POPT_AUTOHELP
POPT_TABLEEND
};
FTL_EngineType engine_type;
optCon = poptGetContext(argv[0], argc, (const char **)argv, optTable, 0);
poptSetOtherOptionHelp(optCon, "[options] otfont\n");
rc = poptReadDefaultConfig (optCon, 0);
if (rc < 0)
{
fprintf(stderr, "Fail to read .popt config file: %s\n",
poptStrerror(rc));
exit (1);
}
while ((rc = poptGetNextOpt(optCon)) > 0)
if (rc != -1)
{
fprintf(stderr, "bad argument %s: %s\n",
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
poptStrerror(rc));
exit (1);
}
if (FT_Init_FreeType (&library))
{
fprintf(stderr, "Error in %s\n", "FT_Init_FreeType");
exit (1);
}
file = poptGetArg(optCon);
if (!file)
{
poptPrintHelp(optCon, stderr, 0);
exit(1);
}
if ( FT_New_Face (library, file, 0, &face) )
{
fprintf(stderr, "Error in %s: %s\n", "FT_New_Face", file);
exit (1);
}
if ( !( face->face_flags & FT_FACE_FLAG_GLYPH_SUBSTITUTION) )
{
fprintf(stderr, "Abort: No substitution table for the face\n");
exit(1);
}
if ( FTL_Query_EngineType( face, &engine_type )
|| ( engine_type != FTL_OPENTYPE_ENGINE ) )
{
fprintf(stderr, "No OT table is existed: %s\n", file);
exit ( 1 );
}
doit( face );
if ( FT_Done_Face ( face ) )
fprintf(stderr, "Error in %s: %s\n", "FT_Done_Face", file);
if ( FT_Done_FreeType (library) )
{
fprintf(stderr, "Error in %s\n", "FT_Done_FreeType");
exit(1);
}
if ( arg_memprof || getenv("_MEMPROF_SOCKET") )
{
fprintf(stderr, "Enter infinite loop for memprof\n");
while (1);
}
return 0;
}
void
doit(FT_Face face)
{
FTL_FeaturesRequest request;
FT_UInt script_index, feature_index;
FT_Memory memory = face->stream->memory;
FTL_Glyphs_Array in, out;
FT_Int i;
if ( FTL_New_FeaturesRequest( face, &request ) )
{
fprintf(stderr, "error: %s\n", "FTL_New_FeaturesRequest");
return ;
}
if ( !OTL_FeaturesRequest_Find_Script ( (OTL_FeaturesRequest)request,
OT_TABLE_GSUB,
OT_SCRIPT_KANA,
&script_index ) )
{
fprintf(stderr, "cannot find script: %s\n",
"OTL_FeaturesRequest_Find_Script");
return ;
}
if ( !OTL_FeaturesRequest_Find_Feature( (OTL_FeaturesRequest)request,
OT_TABLE_GSUB,
OT_FEATURE_VERT,
script_index,
0xffff, /* default language system */
&feature_index ) )
{
fprintf(stderr, "cannot find feature: %s\n",
"OTL_FeaturesRequest_Find_Feature");
return ;
}
OTL_FeaturesRequest_Add_Feature ( (OTL_FeaturesRequest)request,
OT_TABLE_GSUB,
feature_index,
OT_VERT );
if ( FTL_New_Glyphs_Array ( memory, &in )
|| FTL_New_Glyphs_Array ( memory, &out ) )
{
fprintf(stderr, "mem error: %s\n", "FTL_New_Glyphs_Array");
return ;
}
if ( FTL_Set_Glyphs_Array_Length ( in, 14751 ) )
{
fprintf(stderr, "mem error: %s\n",
"FTL_Set_Glyphs_Array_Length");
return ;
}
for ( i = 0; i < 14751; i++ )
{
in->glyphs[i].gid = i;
in->glyphs[i].ot_prop = OT_VERT_P;
}
FTL_Activate_FeaturesRequest( request );
FTL_Substitute_Glyphs ( face, in, out );
for ( i = 0; i < 14751; i++ )
{
if ( out->glyphs[i].gid != i )
fprintf( stdout, "%d => %u\n", i, out->glyphs[i].gid );
}
FTL_Done_Glyphs_Array ( out );
FTL_Done_Glyphs_Array ( in );
FTL_Done_FeaturesRequest ( request );
}
/* END */

100
src/otlayout/otdriver.c Normal file
View File

@ -0,0 +1,100 @@
/***************************************************************************/
/* */
/* otdriver.c */
/* */
/* High-level OpenType driver interface (body). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_DEBUG_H
#include "otdriver.h"
#include "otobjs.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_otdriver
/* The FT_DriverInterface structure is defined in ftdriver.h.
* -----------------------------------------------------------------------
* Almost all fields should be initialized in ot_driver_init.
*/
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec ot_driver_class =
{
/* FT_Module_Class */
{
/* module_flags, copyied from ttdriver.c */
FT_MODULE_FONT_DRIVER |
FT_MODULE_DRIVER_SCALABLE |
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
FT_MODULE_DRIVER_HAS_HINTER,
#else
0,
#endif
/* module_size, copyied from ttdriver.c */
sizeof (OT_DriverRec),
/* module_name */
"ot",
/* module_version */
0x10000L,
/* module_requires */
0x20000L,
/* module_interface */
NULL,
/* module_init */
(FT_Module_Constructor) ot_driver_init,
/* module_done */
(FT_Module_Destructor) NULL,
/* get_interface */
(FT_Module_Requester) NULL,
},
/* now the specific driver fields */
0,
0,
0,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
/* END */

41
src/otlayout/otdriver.h Normal file
View File

@ -0,0 +1,41 @@
/***************************************************************************/
/* */
/* otdriver.h */
/* */
/* High-level OpenType driver interface (specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __OTDRIVER_H__
#define __OTDRIVER_H__
#include <ft2build.h>
#include FT_INTERNAL_DRIVER_H
FT_BEGIN_HEADER
FT_CALLBACK_TABLE
const FT_Driver_ClassRec ot_driver_class;
FT_END_HEADER
#endif /* __OTDRIVER_H__ */
/* END */

45
src/otlayout/oterrors.h Normal file
View File

@ -0,0 +1,45 @@
/***************************************************************************/
/* */
/* gxerrors.h */
/* */
/* OT error codes (specification only). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
/*************************************************************************/
/* */
/* This file is used to define the OT error enumeration constants. */
/* */
/*************************************************************************/
#ifndef __OTERRORS_H__
#define __OTERRORS_H__
#include FT_MODULE_ERRORS_H
#undef __FTERRORS_H__
#define FT_ERR_PREFIX OT_Err_
#define FT_ERR_BASE FT_Mod_Err_OT
#include FT_ERRORS_H
#endif /* __OTERRORS_H__ */
/* END */

269
src/otlayout/otlayout.c Normal file
View File

@ -0,0 +1,269 @@
/***************************************************************************/
/* */
/* otlayout.c */
/* */
/* OpenType based layout engine(body). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
/*
* Experimental: No support for gpos now.
*/
#include <ft2build.h>
#include FT_LIST_H
#include FT_OTLAYOUT_H
#include "otltypes.h"
#include "ot-types.h"
#include "ot-ruleset.h"
#include "ot-info.h"
#include "oterrors.h"
FT_LOCAL_DEF ( FT_Error )
otl_get_font ( FT_Face face, FTL_Font * font)
{
*font = ((OT_Face)face)->extra.data;
if ( *font )
return FT_Err_Ok;
else
return OT_Err_Invalid_Face_Handle;
}
FT_LOCAL_DEF ( FTL_EngineType )
otl_get_engine_type ( FT_Face face )
{
return FTL_OPENTYPE_ENGINE;
}
FT_LOCAL ( FT_Error )
otl_new_features_request( FT_Face face, FTL_FeaturesRequest * ftl_request)
{
FT_Error error;
FT_Memory memory = FT_FACE_MEMORY(face);
OTL_Font font;
OTL_FeaturesRequest request;
if (( error = otl_get_font ( face, (FTL_Font*)&font ) ))
goto Exit;
if ( FT_NEW(request) )
goto Exit;
request->ruleset = ot_ruleset_new ( font->info );
if ( !request->ruleset )
{
error = OT_Err_Invalid_Argument; /* ??? */
goto Failure;
}
if (( error = FTL_FeaturesRequest_Init ( face, (FTL_FeaturesRequest)request ) ))
goto Failure;
*ftl_request = (FTL_FeaturesRequest)request;
Exit:
return error;
Failure:
if ( request->ruleset )
ot_ruleset_delete( request->ruleset );
FT_FREE( request );
return error;
}
FT_LOCAL ( FT_Error )
otl_done_features_request( FTL_FeaturesRequest request)
{
FT_Error error;
FTL_Font font;
FT_Face face;
FT_Memory memory;
FT_ASSERT( request );
font = FTL_FEATURES_REQUEST_FONT ( request );
FT_ASSERT( font );
face = FTL_FONT_FACE(font);
if ( !face )
return OT_Err_Invalid_Argument;
memory = FT_FACE_MEMORY( face );
ot_ruleset_delete ( ((OTL_FeaturesRequest)request)->ruleset );
error = FTL_FeaturesRequest_Finalize ( request );
FT_FREE( request ); /* broken */
return error;
}
FT_LOCAL ( FT_Error )
otl_copy_features_request( FTL_FeaturesRequest from,
FTL_FeaturesRequest to)
{
FT_Error error;
ot_ruleset_copy(((OTL_FeaturesRequest)from)->ruleset, ((OTL_FeaturesRequest)to)->ruleset);
error = FTL_FeaturesRequest_Copy( from, to );
return error;
}
FT_LOCAL ( FT_Error )
otl_substitute_glyphs ( FT_Face face,
FTL_FeaturesRequest request,
FTL_Glyphs_Array in,
FTL_Glyphs_Array out )
{
FT_Error error = FT_Err_Ok;
if (( error = FTL_Copy_Glyphs_Array ( in, out ) ))
return error;
ot_ruleset_shape ( ((OTL_FeaturesRequest)request)->ruleset, out );
return FT_Err_Ok;
}
FT_EXPORT( FT_Bool )
OTL_FeaturesRequest_Find_Script ( OTL_FeaturesRequest request,
OTTableType table_type,
OTTag script_tag,
FT_UInt *script_index)
{
OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
return ot_info_find_script ( font->info,
table_type,
script_tag,
script_index )
? 1: 0;
}
FT_EXPORT( FT_Bool )
OTL_FeaturesRequest_Find_Language ( OTL_FeaturesRequest request,
OTTableType table_type,
FT_UInt script_index,
OTTag language_tag,
FT_UInt *language_index,
FT_UInt *required_feature_index )
{
OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
return ot_info_find_language ( font->info,
table_type,
script_index,
language_tag,
language_index,
required_feature_index )
? 1: 0;
}
FT_EXPORT ( FT_Bool )
OTL_FeaturesRequest_Find_Feature ( OTL_FeaturesRequest request,
OTTableType table_type,
OTTag feature_tag,
FT_UInt script_index,
FT_UInt language_index,
FT_UInt *feature_index )
{
OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
return ot_info_find_feature ( font->info,
table_type,
feature_tag,
script_index,
language_index,
feature_index )
? 1: 0;
}
FT_EXPORT ( OTL_Tag_List )
OTL_FeaturesRequest_List_Scripts ( OTL_FeaturesRequest request,
OTTableType table_type )
{
FT_Error error;
OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
FT_Face face = FTL_FONT_FACE(font);
FT_Memory memory = FT_FACE_MEMORY(face);
OTL_Tag_List tag_list;
if ( FT_NEW(tag_list) )
return NULL;
tag_list->request = request;
tag_list->tags = ot_info_list_scripts( font->info, table_type );
return tag_list;
}
FT_EXPORT ( OTL_Tag_List )
OTL_FeaturesRequest_List_Languages ( OTL_FeaturesRequest request,
OTTableType table_type,
FT_UInt script_index )
{
FT_Error error;
OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
FT_Face face = FTL_FONT_FACE( font );
FT_Memory memory = FT_FACE_MEMORY( face );
OTL_Tag_List tag_list;
if ( FT_NEW(tag_list) )
return NULL;
tag_list->request = request;
tag_list->tags = ot_info_list_languages( font->info,
table_type,
script_index,
0 );
return tag_list;
}
FT_EXPORT ( OTL_Tag_List )
OTL_FeaturesRequest_List_Features ( OTL_FeaturesRequest request,
OTTableType table_type,
FT_UInt script_index,
FT_UInt language_index )
{
FT_Error error;
OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
FT_Face face = FTL_FONT_FACE(font);
FT_Memory memory = FT_FACE_MEMORY( face );
OTL_Tag_List tag_list;
if ( FT_NEW(tag_list) )
return NULL;
tag_list->request = request;
tag_list->tags = ot_info_list_features( font->info,
table_type,
0,
script_index,
language_index );
return tag_list;
}
FT_EXPORT ( FT_Error )
OTL_Tag_List_Done ( OTL_Tag_List taglist )
{
FTL_FeaturesRequest request = (FTL_FeaturesRequest)taglist->request;
FTL_Font font = FTL_FEATURES_REQUEST_FONT( request );
FT_Face face = FTL_FONT_FACE(font);
FT_Memory memory = FT_FACE_MEMORY( face );
FT_FREE ( taglist );
return FT_Err_Ok;
}
FT_EXPORT ( FT_Error )
OTL_FeaturesRequest_Add_Feature ( OTL_FeaturesRequest request,
OTTableType table_type,
FT_UInt feature_index,
FT_ULong property_bit)
{
ot_ruleset_add_feature( request->ruleset,
table_type,
feature_index,
property_bit );
return FT_Err_Ok;
}
/* END */

77
src/otlayout/otltypes.h Normal file
View File

@ -0,0 +1,77 @@
/***************************************************************************/
/* */
/* otltypes.h */
/* */
/* Implicit data types of OpenType based layout engine */
/* (For application developers but using implicitly, */
/* specification only). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __OTLTYPES_H__
#define __OTLTYPES_H__
#include <ft2build.h>
#include FT_INTERNAL_TRUETYPE_TYPES_H
#include FT_INTERNAL_FTL_TYPES_H
#include FT_OTLAYOUT_H
#include "ot-ruleset.h"
#include "ot-info.h"
FT_BEGIN_HEADER
typedef TT_Face OT_Face;
typedef struct OTL_FontRec_
{
FTL_FontRec root;
OTInfo * info;
} OTL_FontRec, *OTL_Font;
typedef struct OTL_FeaturesRequestRec_
{
FTL_FeaturesRequestRec root;
OTRuleset *ruleset;
} OTL_FeaturesRequestRec;
FT_LOCAL ( FT_Error )
otl_get_font ( FT_Face face, FTL_Font * font);
FT_LOCAL_DEF ( FTL_EngineType )
otl_get_engine_type ( FT_Face face );
FT_LOCAL ( FT_Error )
otl_new_features_request( FT_Face face, FTL_FeaturesRequest * request);
FT_LOCAL ( FT_Error )
otl_done_features_request( FTL_FeaturesRequest request);
FT_LOCAL ( FT_Error )
otl_copy_features_request( FTL_FeaturesRequest from,
FTL_FeaturesRequest to);
FT_LOCAL ( FT_Error )
otl_substitute_glyphs ( FT_Face face,
FTL_FeaturesRequest request,
FTL_Glyphs_Array in,
FTL_Glyphs_Array out );
FT_END_HEADER
#endif /* Not def: __OTLTYPES_H__ */
/* END */

189
src/otlayout/otobjs.c Normal file
View File

@ -0,0 +1,189 @@
/***************************************************************************/
/* */
/* otobjs.c */
/* */
/* OpenType objects manager (body). */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_TRUETYPE_TAGS_H
#include FT_LIST_H
#include FT_ERRORS_H
#include FT_LAYOUT_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_LAYOUT_H
#include FT_OTLAYOUT_H
#include "otobjs.h"
#include "ot-types.h"
#include "ot-info.h"
#include "oterrors.h"
#include "otdriver.h"
#include "otltypes.h"
extern const FT_Driver_ClassRec tt_driver_class;
/*************************************************************************/
/* */
/* 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_otobjs
static FT_Error
ot_face_init( FT_Stream stream,
OT_Face face,
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params );
static FT_Error
ot_font_load ( OT_Face face );
static void
ot_font_done( void * object );
static FT_Module_Interface
ot_module_get_interface ( FT_Module module,
const char* ot_interface );
static const FT_Service_LayoutRec ot_service_layout =
{
(FTL_Get_Font_Func) otl_get_font,
(FTL_Get_EngineType_Func) otl_get_engine_type,
(FTL_New_FeaturesRequest_Func) otl_new_features_request,
(FTL_Done_FeaturesRequest_Func) otl_done_features_request,
(FTL_Copy_FeaturesRequest_Func) otl_copy_features_request,
(FTL_Get_LigatureCaret_Count_Func) NULL, /* TODO */
(FTL_Get_LigatureCaret_Division_Func) NULL, /* TODO */
(FTL_Substitute_Glyphs_Func) otl_substitute_glyphs
};
static const FT_ServiceDescRec ot_services[] =
{
{ FT_SERVICE_ID_LAYOUT, &ot_service_layout },
{ NULL, NULL }
};
FT_LOCAL_DEF( FT_Error )
ot_driver_init( OT_Driver driver )
{
FT_Error error;
const void * module_name;
FT_Driver ot_driver_root = &driver->root;
FT_Driver_Class ot_driver_class = ot_driver_root->clazz;
module_name = ot_driver_class->root.module_name;
*ot_driver_class = tt_driver_class;
driver->root.clazz->root.module_name = module_name;
if (( error = ((FT_Module_Class*)ot_driver_class)->module_init( (FT_Module)driver ) ))
return error;
ot_driver_class->init_face = (FT_Face_InitFunc)ot_face_init;
((FT_Module_Class*)ot_driver_class)->get_interface = ot_module_get_interface;
return OT_Err_Ok;
}
static FT_Error
ot_face_init( FT_Stream stream,
OT_Face face,
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params )
{
FT_Error error;
/* TODO */
error = tt_driver_class.init_face ( stream, (FT_Face)face, face_index, num_params, params );
if ( error )
goto Exit;
error = ot_font_load ( face );
if ( error )
goto Exit;
Exit:
return error;
}
static FT_Error
ot_font_load( OT_Face face )
{
FT_Error error;
FT_Memory memory = FT_FACE_MEMORY( face );
OTL_Font font = NULL;
OTL_FeaturesRequest features_request;
OTInfo * ot_info;
if ( face->extra.data )
{
error = OT_Err_Busy_Extra_Data;
goto Exit;
}
ot_info = ot_info_get ( (FT_Face) face );
if ( !ot_info )
{
error = OT_Err_Unknown_File_Format;
goto Exit;
}
if ( FT_NEW ( font ) )
goto Exit;
font->info = ot_info;
if (( error = FTL_Font_Init ( (FTL_Font)font, (FT_Face)face ) ))
goto Failure;
face->extra.finalizer = ot_font_done;
face->extra.data = font;
if (( error = FTL_New_FeaturesRequest ( (FT_Face)face,
(FTL_FeaturesRequest*)(&features_request) ) ))
goto Failure;
face->root.face_flags |= FT_FACE_FLAG_GLYPH_SUBSTITUTION; /* ??? */
error = OT_Err_Ok;
Exit:
return error;
Failure:
if ( font )
FT_FREE( font );
face->extra.finalizer = NULL;
face->extra.data = NULL;
return error;
}
static void
ot_font_done( void * object )
{
OTL_Font font = object;
FT_Face face = FTL_FONT_FACE( font );
FT_Memory memory = FT_FACE_MEMORY( face );
FTL_Font_Finalize((FTL_Font)font);
FT_FREE( object );
}
static FT_Module_Interface
ot_module_get_interface( FT_Module module,
const char* ot_interface )
{
FT_Module_Interface ot;
ot = ft_service_list_lookup( ot_services, ot_interface );
if ( ot )
return ot;
/* TODO */
if ( tt_driver_class.root.get_interface )
return tt_driver_class.root.get_interface( module, ot_interface );
return NULL;
}

52
src/otlayout/otobjs.h Normal file
View File

@ -0,0 +1,52 @@
/***************************************************************************/
/* */
/* otdriver.h */
/* */
/* OpenType objects manager (specification). */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* This file 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#ifndef __OTOBJS_H__
#define __OTOBJS_H__
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_TRUETYPE_TYPES_H
FT_BEGIN_HEADER
typedef struct OT_DriverRec_
{
FT_DriverRec root;
TT_ExecContext context;
TT_GlyphZoneRec zone;
void* extension_component;
} OT_DriverRec, *OT_Driver;
/*************************************************************************/
/* */
/* Driver functions */
/* */
FT_LOCAL( FT_Error )
ot_driver_init( OT_Driver driver );
FT_END_HEADER
#endif /* __OTOBJS_H__ */
/* END */

98
src/otlayout/rules.mk Normal file
View File

@ -0,0 +1,98 @@
#
# FreeType 2 OpneType driver configuration rules
#
# Copyright 2004 by RedHat K.K.
# This file is derived from cff/rules.mk.
# ----------------------------------------------------------------------
#
# FreeType 2 OpenType/CFF driver configuration rules
#
# Copyright 1996-2000, 2001, 2003 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.
# ----------------------------------------------------------------------
# Development of the code in rules.mk is support of
# Information-technology Promotion Agency, Japan.
# OpenType driver directory
#
OT_DIR := $(SRC_DIR)/otlayout
OT_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(OT_DIR))
# OT driver sources (i.e., C files)
#
OT_DRV_SRC := $(OT_DIR)/otobjs.c \
$(OT_DIR)/otlayout.c \
$(OT_DIR)/otdriver.c \
$(OT_DIR)/ftxgdef.c \
$(OT_DIR)/ftxgpos.c \
$(OT_DIR)/ftxopen.c \
$(OT_DIR)/ftxgsub.c \
$(OT_DIR)/ot-info.c \
$(OT_DIR)/ot-ruleset.c \
$(OT_DIR)/ot-array.c \
$(OT_DIR)/ot-unicode.c
# OT driver headers
#
OT_DRV_H := $(OT_DIR)/otdriver.h \
$(OT_DIR)/fterrcompat.h \
$(OT_DIR)/ftxgdef.h \
$(OT_DIR)/ftxgpos.h \
$(OT_DIR)/ftxgsub.h \
$(OT_DIR)/ftxopen.h \
$(OT_DIR)/ftxopenf.h \
$(OT_DIR)/ot-info.h \
$(OT_DIR)/ot-ruleset.h \
$(OT_DIR)/ot-types.h \
$(OT_DIR)/ot-array.h \
$(OT_DIR)/otltypes.h \
$(OT_DIR)/oterrors.h \
$(OT_DIR)/otobjs.h \
$(OT_DIR)/ot-unicode.h
# OT driver object(s)
#
# OT_DRV_OBJ_M is used during `multi' builds
# OT_DRV_OBJ_S is used during `single' builds
#
OT_DRV_OBJ_M := $(OT_DRV_SRC:$(OT_DIR)/%.c=$(OBJ_DIR)/%.$O)
OT_DRV_OBJ_S := $(OBJ_DIR)/ot.$O
# OT driver source file for single build
#
OT_DRV_SRC_S := $(OT_DIR)/ot.c
# OT driver - single object
#
$(OT_DRV_OBJ_S): $(OT_DRV_SRC_S) $(OT_DRV_SRC) $(FREETYPE_H) $(OT_DRV_H)
$(OT_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(OT_DRV_SRC_S))
# OT driver - multiple objects
#
$(OBJ_DIR)/%.$O: $(OT_DIR)/%.c $(FREETYPE_H) $(OT_DRV_H)
$(OT_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
# update main driver object lists
#
DRV_OBJS_S += $(OT_DRV_OBJ_S)
DRV_OBJS_M += $(OT_DRV_OBJ_M)
# EOF