2 *******************************************************************************
4 * © 2016 and later: Unicode, Inc. and others.
5 * License & terms of use: http://www.unicode.org/copyright.html#License
7 *******************************************************************************
8 *******************************************************************************
10 * Copyright (C) 1999-2003, International Business Machines
11 * Corporation and others. All Rights Reserved.
13 *******************************************************************************
14 * file name: ScriptCompositeFontInstance.cpp
16 * created on: 02/05/2003
17 * created by: Eric R. Mader
20 #include "layout/LETypes.h"
22 #include "unicode/uscript.h"
26 #include "ScriptCompositeFontInstance.h"
28 const char ScriptCompositeFontInstance::fgClassID
=0;
30 ScriptCompositeFontInstance::ScriptCompositeFontInstance(FontMap
*fontMap
)
36 ScriptCompositeFontInstance::~ScriptCompositeFontInstance()
42 void ScriptCompositeFontInstance::getGlyphAdvance(LEGlyphID glyph
, LEPoint
&advance
) const
44 LEErrorCode status
= LE_NO_ERROR
;
45 le_int32 script
= LE_GET_SUB_FONT(glyph
);
46 const LEFontInstance
*font
= fFontMap
->getScriptFont(script
, status
);
51 if (LE_SUCCESS(status
)) {
52 font
->getGlyphAdvance(LE_GET_GLYPH(glyph
), advance
);
56 le_bool
ScriptCompositeFontInstance::getGlyphPoint(LEGlyphID glyph
, le_int32 pointNumber
, LEPoint
&point
) const
58 LEErrorCode status
= LE_NO_ERROR
;
59 le_int32 script
= LE_GET_SUB_FONT(glyph
);
60 const LEFontInstance
*font
= fFontMap
->getScriptFont(script
, status
);
62 if (LE_SUCCESS(status
)) {
63 return font
->getGlyphPoint(LE_GET_GLYPH(glyph
), pointNumber
, point
);
69 const LEFontInstance
*ScriptCompositeFontInstance::getSubFont(const LEUnicode chars
[], le_int32
*offset
, le_int32 limit
, le_int32 script
, LEErrorCode
&success
) const
71 if (LE_FAILURE(success
)) {
75 if (chars
== NULL
|| *offset
< 0 || limit
< 0 || *offset
>= limit
|| script
< 0 || script
>= scriptCodeCount
) {
76 success
= LE_ILLEGAL_ARGUMENT_ERROR
;
80 const LEFontInstance
*result
= fFontMap
->getScriptFont(script
, success
);
82 if (LE_FAILURE(success
)) {
90 // This is the really stupid version that doesn't look in any other font for the character...
91 // It would be better to also look in the "DEFAULT:" font. Another thing to do would be to
92 // look in all the fonts in some order, script code order being the most obvious...
93 LEGlyphID
ScriptCompositeFontInstance::mapCharToGlyph(LEUnicode32 ch
) const
95 UErrorCode error
= U_ZERO_ERROR
;
96 LEErrorCode status
= LE_NO_ERROR
;
97 le_int32 script
= uscript_getScript(ch
, &error
);
98 const LEFontInstance
*scriptFont
= fFontMap
->getScriptFont(script
, status
);
99 LEGlyphID subFont
= LE_SET_SUB_FONT(0, script
);
101 if (LE_FAILURE(status
)) {
105 LEGlyphID glyph
= scriptFont
->mapCharToGlyph(ch
);
107 return LE_SET_GLYPH(subFont
, glyph
);