Commit a5f7fcdf authored by David Turner's avatar David Turner
Browse files

initial import of the FreeType Layout sources

parent cad0775a
......@@ -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
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>
......@@ -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/...> */
......
......@@ -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)
......
......@@ -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
......
......@@ -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 )
/*************************************************************************/
/* */
......
......@@ -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 */
This diff is collapsed.
......@@ -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
......
This diff is collapsed.
/***************************************************************************/
/* */
/* 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 */
......@@ -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>
/* */
......
......@@ -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 */
......@@ -45,5 +45,7 @@
#define FT_INTERNAL_AUTOHINT_H <freetype/internal/autohint.h>
#define FT_INTERNAL_FTL_TYPES_H <freetype/internal/ftltypes.h>
/* END */
/***************************************************************************/
/* */
/* 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 */
......@@ -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. */