2 *******************************************************************************
4 * Copyright (C) 1999-2003, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: ScriptCompositeFontInstance.cpp
10 * created on: 02/05/2003
11 * created by: Eric R. Mader
14 #include "layout/LETypes.h"
16 #include "unicode/uscript.h"
20 #include "ScriptCompositeFontInstance.h"
22 const char ScriptCompositeFontInstance::fgClassID
=0;
24 ScriptCompositeFontInstance::ScriptCompositeFontInstance(FontMap
*fontMap
)
30 ScriptCompositeFontInstance::~ScriptCompositeFontInstance()
36 void ScriptCompositeFontInstance::getGlyphAdvance(LEGlyphID glyph
, LEPoint
&advance
) const
38 LEErrorCode status
= LE_NO_ERROR
;
39 le_int32 script
= LE_GET_SUB_FONT(glyph
);
40 const LEFontInstance
*font
= fFontMap
->getScriptFont(script
, status
);
45 if (LE_SUCCESS(status
)) {
46 font
->getGlyphAdvance(LE_GET_GLYPH(glyph
), advance
);
50 le_bool
ScriptCompositeFontInstance::getGlyphPoint(LEGlyphID glyph
, le_int32 pointNumber
, LEPoint
&point
) const
52 LEErrorCode status
= LE_NO_ERROR
;
53 le_int32 script
= LE_GET_SUB_FONT(glyph
);
54 const LEFontInstance
*font
= fFontMap
->getScriptFont(script
, status
);
56 if (LE_SUCCESS(status
)) {
57 return font
->getGlyphPoint(LE_GET_GLYPH(glyph
), pointNumber
, point
);
63 const LEFontInstance
*ScriptCompositeFontInstance::getSubFont(const LEUnicode chars
[], le_int32
*offset
, le_int32 limit
, le_int32 script
, LEErrorCode
&success
) const
65 if (LE_FAILURE(success
)) {
69 if (chars
== NULL
|| *offset
< 0 || limit
< 0 || *offset
>= limit
|| script
< 0 || script
>= scriptCodeCount
) {
70 success
= LE_ILLEGAL_ARGUMENT_ERROR
;
74 const LEFontInstance
*result
= fFontMap
->getScriptFont(script
, success
);
76 if (LE_FAILURE(success
)) {
84 // This is the really stupid version that doesn't look in any other font for the character...
85 // It would be better to also look in the "DEFAULT:" font. Another thing to do would be to
86 // look in all the fonts in some order, script code order being the most obvious...
87 LEGlyphID
ScriptCompositeFontInstance::mapCharToGlyph(LEUnicode32 ch
) const
89 UErrorCode error
= U_ZERO_ERROR
;
90 LEErrorCode status
= LE_NO_ERROR
;
91 le_int32 script
= uscript_getScript(ch
, &error
);
92 const LEFontInstance
*scriptFont
= fFontMap
->getScriptFont(script
, status
);
93 LEGlyphID subFont
= LE_SET_SUB_FONT(0, script
);
95 if (LE_FAILURE(status
)) {
99 LEGlyphID glyph
= scriptFont
->mapCharToGlyph(ch
);
101 return LE_SET_GLYPH(subFont
, glyph
);