1 /****************************************************************************\
2  Part of the XeTeX typesetting system
3  Copyright (c) 1994-2008 by SIL International
4  Copyright (c) 2009 by Jonathan Kew
5  Copyright (c) 2012-2015 by Khaled Hosny
6 
7  SIL Author(s): Jonathan Kew
8 
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16 
17 The above copyright notice and this permission notice shall be
18 included in all copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
24 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 
28 Except as contained in this notice, the name of the copyright holders
29 shall not be used in advertising or otherwise to promote the sale,
30 use or other dealings in this Software without prior written
31 authorization from the copyright holders.
32 \****************************************************************************/
33 
34 #ifndef XETEX_LAYOUT_INTERFACE_H
35 #define XETEX_LAYOUT_INTERFACE_H 1
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 typedef struct XeTeXFont_rec* XeTeXFont;
41 typedef struct XeTeXLayoutEngine_rec* XeTeXLayoutEngine;
42 #ifdef __cplusplus
43 };
44 #endif
45 
46 #include <ft2build.h>
47 #include FT_FREETYPE_H
48 #include FT_TRUETYPE_TABLES_H
49 
50 #include <hb.h>
51 
52 #include "XeTeX_ext.h"
53 #include "XeTeXFontMgr.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 extern char gPrefEngine;
60 
61 int getCachedGlyphBBox(uint16_t fontID, uint16_t glyphID, GlyphBBox* bbox);
62 void cacheGlyphBBox(uint16_t fontID, uint16_t glyphID, const GlyphBBox* bbox);
63 
64 void terminatefontmanager();
65 
66 XeTeXFont createFont(PlatformFontRef fontRef, Fixed pointSize);
67 XeTeXFont createFontFromFile(const char* filename, int index, Fixed pointSize);
68 
69 void setFontLayoutDir(XeTeXFont font, int vertical);
70 
71 PlatformFontRef findFontByName(const char* name, char* var, double size);
72 
73 char getReqEngine();
74 void setReqEngine(char reqEngine);
75 const char* getFullName(PlatformFontRef fontRef);
76 
77 const char* getFontFilename(XeTeXLayoutEngine engine, uint32_t* index);
78 
79 double getDesignSize(XeTeXFont font);
80 
81 void deleteFont(XeTeXFont font);
82 
83 void* getFontTablePtr(XeTeXFont font, uint32_t tableTag);
84 
85 Fixed getSlant(XeTeXFont font);
86 
87 unsigned int countScripts(XeTeXFont font);
88 unsigned int countLanguages(XeTeXFont font, hb_tag_t script);
89 unsigned int countFeatures(XeTeXFont font, hb_tag_t script, hb_tag_t language);
90 unsigned int countGlyphs(XeTeXFont font);
91 
92 hb_tag_t getIndScript(XeTeXFont font, unsigned int index);
93 hb_tag_t getIndLanguage(XeTeXFont font, hb_tag_t script, unsigned int index);
94 hb_tag_t getIndFeature(XeTeXFont font, hb_tag_t script, hb_tag_t language, unsigned int index);
95 
96 float getGlyphWidth(XeTeXFont font, uint32_t gid);
97 
98 XeTeXLayoutEngine createLayoutEngine(PlatformFontRef fontRef, XeTeXFont font, hb_tag_t script, char *language,
99                         hb_feature_t* features, int nFeatures, char **shapers, uint32_t rgbValue,
100                         float extend, float slant, float embolden);
101 
102 void deleteLayoutEngine(XeTeXLayoutEngine engine);
103 
104 XeTeXFont getFont(XeTeXLayoutEngine engine);
105 PlatformFontRef getFontRef(XeTeXLayoutEngine engine);
106 
107 float getExtendFactor(XeTeXLayoutEngine engine);
108 float getSlantFactor(XeTeXLayoutEngine engine);
109 float getEmboldenFactor(XeTeXLayoutEngine engine);
110 
111 int layoutChars(XeTeXLayoutEngine engine, uint16_t* chars, int32_t offset, int32_t count, int32_t max,
112                         bool rightToLeft);
113 
114 void getGlyphs(XeTeXLayoutEngine engine, uint32_t* glyphs);
115 void getGlyphAdvances(XeTeXLayoutEngine engine, float *advances);
116 void getGlyphPositions(XeTeXLayoutEngine engine, FloatPoint* positions);
117 
118 float getPointSize(XeTeXLayoutEngine engine);
119 
120 void getAscentAndDescent(XeTeXLayoutEngine engine, float* ascent, float* descent);
121 void getCapAndXHeight(XeTeXLayoutEngine engine, float* capheight, float* xheight);
122 
123 int getDefaultDirection(XeTeXLayoutEngine engine);
124 
125 uint32_t getRgbValue(XeTeXLayoutEngine engine);
126 
127 void getGlyphBounds(XeTeXLayoutEngine engine, uint32_t glyphID, GlyphBBox* bbox);
128 
129 float getGlyphWidthFromEngine(XeTeXLayoutEngine engine, uint32_t glyphID);
130 
131 void getGlyphHeightDepth(XeTeXLayoutEngine engine, uint32_t glyphID, float* height, float* depth);
132 
133 void getGlyphSidebearings(XeTeXLayoutEngine engine, uint32_t glyphID, float* lsb, float* rsb);
134 
135 float getGlyphItalCorr(XeTeXLayoutEngine engine, uint32_t glyphID);
136 
137 uint32_t mapCharToGlyph(XeTeXLayoutEngine engine, uint32_t charCode);
138 
139 int mapGlyphToIndex(XeTeXLayoutEngine engine, const char* glyphName);
140 
141 const char* getGlyphName(XeTeXFont font, uint16_t gid, int* len);
142 
143 int getFontCharRange(XeTeXLayoutEngine engine, int reqFirst);
144 
145 /* graphite interface functions... */
146 bool initGraphiteBreaking(XeTeXLayoutEngine engine, const uint16_t* txtPtr, int txtLen);
147 int findNextGraphiteBreak(void);
148 
149 bool usingOpenType(XeTeXLayoutEngine engine);
150 bool usingGraphite(XeTeXLayoutEngine engine);
151 bool isOpenTypeMathFont(XeTeXLayoutEngine engine);
152 
153 bool findGraphiteFeature(XeTeXLayoutEngine engine, const char* s, const char* e, hb_tag_t* f, int* v);
154 
155 uint32_t countGraphiteFeatures(XeTeXLayoutEngine engine);
156 uint32_t getGraphiteFeatureCode(XeTeXLayoutEngine engine, uint32_t index);
157 uint32_t countGraphiteFeatureSettings(XeTeXLayoutEngine engine, uint32_t feature);
158 uint32_t getGraphiteFeatureSettingCode(XeTeXLayoutEngine engine, uint32_t feature, uint32_t index);
159 uint32_t getGraphiteFeatureDefaultSetting(XeTeXLayoutEngine engine, uint32_t feature);
160 char* getGraphiteFeatureLabel(XeTeXLayoutEngine engine, uint32_t feature);
161 char* getGraphiteFeatureSettingLabel(XeTeXLayoutEngine engine, uint32_t feature, uint32_t setting);
162 long findGraphiteFeatureNamed(XeTeXLayoutEngine engine, const char* name, int namelength);
163 long findGraphiteFeatureSettingNamed(XeTeXLayoutEngine engine, uint32_t feature, const char* name, int namelength);
164 
165 #ifdef __cplusplus
166 };
167 #endif
168 
169 #endif /* XETEX_LAYOUT_INTERFACE_H */
170 
171