1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 1999-2003, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 * file name: ScriptCompositeFontInstance.cpp
9 *
10 * created on: 02/05/2003
11 * created by: Eric R. Mader
12 */
13
14 #include "layout/LETypes.h"
15
16 #include "unicode/uscript.h"
17
18 #include "FontMap.h"
19
20 #include "ScriptCompositeFontInstance.h"
21
22 const char ScriptCompositeFontInstance::fgClassID=0;
23
ScriptCompositeFontInstance(FontMap * fontMap)24 ScriptCompositeFontInstance::ScriptCompositeFontInstance(FontMap *fontMap)
25 : fFontMap(fontMap)
26 {
27 // nothing else to do
28 }
29
~ScriptCompositeFontInstance()30 ScriptCompositeFontInstance::~ScriptCompositeFontInstance()
31 {
32 delete fFontMap;
33 fFontMap = NULL;
34 }
35
getGlyphAdvance(LEGlyphID glyph,LEPoint & advance) const36 void ScriptCompositeFontInstance::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const
37 {
38 LEErrorCode status = LE_NO_ERROR;
39 le_int32 script = LE_GET_SUB_FONT(glyph);
40 const LEFontInstance *font = fFontMap->getScriptFont(script, status);
41
42 advance.fX = 0;
43 advance.fY = 0;
44
45 if (LE_SUCCESS(status)) {
46 font->getGlyphAdvance(LE_GET_GLYPH(glyph), advance);
47 }
48 }
49
getGlyphPoint(LEGlyphID glyph,le_int32 pointNumber,LEPoint & point) const50 le_bool ScriptCompositeFontInstance::getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const
51 {
52 LEErrorCode status = LE_NO_ERROR;
53 le_int32 script = LE_GET_SUB_FONT(glyph);
54 const LEFontInstance *font = fFontMap->getScriptFont(script, status);
55
56 if (LE_SUCCESS(status)) {
57 return font->getGlyphPoint(LE_GET_GLYPH(glyph), pointNumber, point);
58 }
59
60 return FALSE;
61 }
62
getSubFont(const LEUnicode chars[],le_int32 * offset,le_int32 limit,le_int32 script,LEErrorCode & success) const63 const LEFontInstance *ScriptCompositeFontInstance::getSubFont(const LEUnicode chars[], le_int32 *offset, le_int32 limit, le_int32 script, LEErrorCode &success) const
64 {
65 if (LE_FAILURE(success)) {
66 return NULL;
67 }
68
69 if (chars == NULL || *offset < 0 || limit < 0 || *offset >= limit || script < 0 || script >= scriptCodeCount) {
70 success = LE_ILLEGAL_ARGUMENT_ERROR;
71 return NULL;
72 }
73
74 const LEFontInstance *result = fFontMap->getScriptFont(script, success);
75
76 if (LE_FAILURE(success)) {
77 return NULL;
78 }
79
80 *offset = limit;
81 return result;
82 }
83
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...
mapCharToGlyph(LEUnicode32 ch) const87 LEGlyphID ScriptCompositeFontInstance::mapCharToGlyph(LEUnicode32 ch) const
88 {
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);
94
95 if (LE_FAILURE(status)) {
96 return subFont;
97 }
98
99 LEGlyphID glyph = scriptFont->mapCharToGlyph(ch);
100
101 return LE_SET_GLYPH(subFont, glyph);
102 }
103
104