| 1 |
/****************************************************************************\ |
| 2 |
Part of the XeTeX typesetting system |
| 3 |
Copyright (c) 1994-2008 by SIL International |
| 4 |
Copyright (c) 2009, 2011 by Jonathan Kew |
| 5 |
|
| 6 |
SIL Author(s): Jonathan Kew |
| 7 |
|
| 8 |
Permission is hereby granted, free of charge, to any person obtaining |
| 9 |
a copy of this software and associated documentation files (the |
| 10 |
"Software"), to deal in the Software without restriction, including |
| 11 |
without limitation the rights to use, copy, modify, merge, publish, |
| 12 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 13 |
permit persons to whom the Software is furnished to do so, subject to |
| 14 |
the following conditions: |
| 15 |
|
| 16 |
The above copyright notice and this permission notice shall be |
| 17 |
included in all copies or substantial portions of the Software. |
| 18 |
|
| 19 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 |
NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE |
| 23 |
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 24 |
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 25 |
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 |
|
| 27 |
Except as contained in this notice, the name of the copyright holders |
| 28 |
shall not be used in advertising or otherwise to promote the sale, |
| 29 |
use or other dealings in this Software without prior written |
| 30 |
authorization from the copyright holders. |
| 31 |
\****************************************************************************/ |
| 32 |
|
| 33 |
/* |
| 34 |
* file name: XeTeXFontInst.h |
| 35 |
* |
| 36 |
* created on: 2005-10-22 |
| 37 |
* created by: Jonathan Kew |
| 38 |
* |
| 39 |
* originally based on PortableFontInstance.h from ICU |
| 40 |
*/ |
| 41 |
|
| 42 |
|
| 43 |
#ifndef __XeTeXFontInst_H |
| 44 |
#define __XeTeXFontInst_H |
| 45 |
|
| 46 |
#include "XeTeXFontMgr.h" |
| 47 |
|
| 48 |
#include <stdio.h> |
| 49 |
#include <ft2build.h> |
| 50 |
#include FT_FREETYPE_H |
| 51 |
#include FT_TRUETYPE_TABLES_H |
| 52 |
|
| 53 |
// create specific subclasses for each supported platform |
| 54 |
|
| 55 |
class XeTeXFontInst |
| 56 |
{ |
| 57 |
protected: |
| 58 |
unsigned short m_unitsPerEM; |
| 59 |
float m_pointSize; |
| 60 |
float m_ascent; |
| 61 |
float m_descent; |
| 62 |
float m_capHeight; |
| 63 |
float m_xHeight; |
| 64 |
float m_italicAngle; |
| 65 |
|
| 66 |
bool m_vertical; // false = horizontal, true = vertical |
| 67 |
|
| 68 |
char *m_filename; // font filename |
| 69 |
uint32_t m_index; // face index |
| 70 |
|
| 71 |
FT_Face m_ftFace; |
| 72 |
hb_font_t* m_hbFont; |
| 73 |
|
| 74 |
public: |
| 75 |
XeTeXFontInst(float pointSize, int &status); |
| 76 |
XeTeXFontInst(const char* filename, int index, float pointSize, int &status); |
| 77 |
|
| 78 |
virtual ~XeTeXFontInst(); |
| 79 |
|
| 80 |
void initialize(const char* pathname, int index, int &status); |
| 81 |
|
| 82 |
void *getFontTable(OTTag tableTag) const; |
| 83 |
void *getFontTable(FT_Sfnt_Tag tableTag) const; |
| 84 |
|
| 85 |
const char *getFilename(uint32_t* index) const |
| 86 |
{ |
| 87 |
*index = m_index; |
| 88 |
return m_filename; |
| 89 |
} |
| 90 |
hb_font_t *getHbFont() const { return m_hbFont; } |
| 91 |
void setLayoutDirVertical(bool vertical); |
| 92 |
bool getLayoutDirVertical() const { return m_vertical; }; |
| 93 |
|
| 94 |
float getPointSize() const { return m_pointSize; }; |
| 95 |
float getAscent() const { return m_ascent; } |
| 96 |
float getDescent() const { return m_descent; } |
| 97 |
float getCapHeight() const { return m_capHeight; } |
| 98 |
float getXHeight() const { return m_xHeight; } |
| 99 |
float getItalicAngle() const { return m_italicAngle; } |
| 100 |
|
| 101 |
GlyphID mapCharToGlyph(UChar32 ch) const; |
| 102 |
GlyphID mapGlyphToIndex(const char* glyphName) const; |
| 103 |
|
| 104 |
uint16_t getNumGlyphs() const; |
| 105 |
|
| 106 |
void getGlyphBounds(GlyphID glyph, GlyphBBox* bbox); |
| 107 |
|
| 108 |
float getGlyphWidth(GlyphID glyph); |
| 109 |
void getGlyphHeightDepth(GlyphID glyph, float *ht, float* dp); |
| 110 |
void getGlyphSidebearings(GlyphID glyph, float* lsb, float* rsb); |
| 111 |
float getGlyphItalCorr(GlyphID glyph); |
| 112 |
|
| 113 |
const char* getGlyphName(GlyphID gid, int& nameLen); |
| 114 |
|
| 115 |
UChar32 getFirstCharCode(); |
| 116 |
UChar32 getLastCharCode(); |
| 117 |
|
| 118 |
float unitsToPoints(float units) const |
| 119 |
{ |
| 120 |
return (units * m_pointSize) / (float) m_unitsPerEM; |
| 121 |
} |
| 122 |
|
| 123 |
float pointsToUnits(float points) const |
| 124 |
{ |
| 125 |
return (points * (float) m_unitsPerEM) / m_pointSize; |
| 126 |
} |
| 127 |
}; |
| 128 |
|
| 129 |
#endif |