2 *******************************************************************************
4 * Copyright (C) 1999-2007, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: LEFontInstance.cpp
10 * created on: 02/06/2003
11 * created by: Eric R. Mader
15 #include "LEScripts.h"
16 #include "LEFontInstance.h"
17 #include "LEGlyphStorage.h"
21 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LEFontInstance
)
23 LECharMapper::~LECharMapper()
28 LEFontInstance::~LEFontInstance()
33 const LEFontInstance
*LEFontInstance::getSubFont(const LEUnicode chars
[], le_int32
*offset
, le_int32 limit
,
34 le_int32 script
, LEErrorCode
&success
) const
36 if (LE_FAILURE(success
)) {
40 if (chars
== NULL
|| *offset
< 0 || limit
< 0 || *offset
>= limit
|| script
< 0 || script
>= scriptCodeCount
) {
41 success
= LE_ILLEGAL_ARGUMENT_ERROR
;
49 void LEFontInstance::mapCharsToGlyphs(const LEUnicode chars
[], le_int32 offset
, le_int32 count
,
50 le_bool reverse
, const LECharMapper
*mapper
, le_bool filterZeroWidth
, LEGlyphStorage
&glyphStorage
) const
52 le_int32 i
, out
= 0, dir
= 1;
59 for (i
= offset
; i
< offset
+ count
; i
+= 1, out
+= dir
) {
60 LEUnicode16 high
= chars
[i
];
61 LEUnicode32 code
= high
;
63 if (i
< offset
+ count
- 1 && high
>= 0xD800 && high
<= 0xDBFF) {
64 LEUnicode16 low
= chars
[i
+ 1];
66 if (low
>= 0xDC00 && low
<= 0xDFFF) {
67 code
= (high
- 0xD800) * 0x400 + low
- 0xDC00 + 0x10000;
71 glyphStorage
[out
] = mapCharToGlyph(code
, mapper
, filterZeroWidth
);
73 if (code
>= 0x10000) {
75 glyphStorage
[out
+= dir
] = 0xFFFF;
80 LEGlyphID
LEFontInstance::mapCharToGlyph(LEUnicode32 ch
, const LECharMapper
*mapper
) const
82 return mapCharToGlyph(ch
, mapper
, TRUE
);
85 LEGlyphID
LEFontInstance::mapCharToGlyph(LEUnicode32 ch
, const LECharMapper
*mapper
, le_bool filterZeroWidth
) const
87 LEUnicode32 mappedChar
= mapper
->mapChar(ch
);
89 if (mappedChar
== 0xFFFE || mappedChar
== 0xFFFF) {
93 if (filterZeroWidth
&& (mappedChar
== 0x200C || mappedChar
== 0x200D)) {
94 return canDisplay(mappedChar
)? 0x0001 : 0xFFFF;
97 return mapCharToGlyph(mappedChar
);
100 le_bool
LEFontInstance::canDisplay(LEUnicode32 ch
) const
102 return LE_GET_GLYPH(mapCharToGlyph(ch
)) != 0;
105 float LEFontInstance::xUnitsToPoints(float xUnits
) const
107 return (xUnits
* getXPixelsPerEm()) / (float) getUnitsPerEM();
110 float LEFontInstance::yUnitsToPoints(float yUnits
) const
112 return (yUnits
* getYPixelsPerEm()) / (float) getUnitsPerEM();
115 void LEFontInstance::unitsToPoints(LEPoint
&units
, LEPoint
&points
) const
117 points
.fX
= xUnitsToPoints(units
.fX
);
118 points
.fY
= yUnitsToPoints(units
.fY
);
121 float LEFontInstance::xPixelsToUnits(float xPixels
) const
123 return (xPixels
* getUnitsPerEM()) / (float) getXPixelsPerEm();
126 float LEFontInstance::yPixelsToUnits(float yPixels
) const
128 return (yPixels
* getUnitsPerEM()) / (float) getYPixelsPerEm();
131 void LEFontInstance::pixelsToUnits(LEPoint
&pixels
, LEPoint
&units
) const
133 units
.fX
= xPixelsToUnits(pixels
.fX
);
134 units
.fY
= yPixelsToUnits(pixels
.fY
);
137 void LEFontInstance::transformFunits(float xFunits
, float yFunits
, LEPoint
&pixels
) const
139 pixels
.fX
= xUnitsToPoints(xFunits
) * getScaleFactorX();
140 pixels
.fY
= yUnitsToPoints(yFunits
) * getScaleFactorY();
143 le_int32
LEFontInstance::getLineHeight() const
145 return getAscent() + getDescent() + getLeading();