1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   Copyright (C) 1999-2003, International Business Machines
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   Corporation and others.  All Rights Reserved.
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   file name:  ScriptCompositeFontInstance.cpp
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   created on: 02/05/2003
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   created by: Eric R. Mader
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "layout/LETypes.h"
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uscript.h"
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "FontMap.h"
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ScriptCompositeFontInstance.h"
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst char ScriptCompositeFontInstance::fgClassID=0;
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruScriptCompositeFontInstance::ScriptCompositeFontInstance(FontMap *fontMap)
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    : fFontMap(fontMap)
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // nothing else to do
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruScriptCompositeFontInstance::~ScriptCompositeFontInstance()
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete fFontMap;
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fFontMap = NULL;
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid ScriptCompositeFontInstance::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    LEErrorCode status = LE_NO_ERROR;
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 script = LE_GET_SUB_FONT(glyph);
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const LEFontInstance *font = fFontMap->getScriptFont(script, status);
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    advance.fX = 0;
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    advance.fY = 0;
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (LE_SUCCESS(status)) {
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        font->getGlyphAdvance(LE_GET_GLYPH(glyph), advance);
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querule_bool ScriptCompositeFontInstance::getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    LEErrorCode status = LE_NO_ERROR;
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 script = LE_GET_SUB_FONT(glyph);
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const LEFontInstance *font = fFontMap->getScriptFont(script, status);
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (LE_SUCCESS(status)) {
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return font->getGlyphPoint(LE_GET_GLYPH(glyph), pointNumber, point);
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return FALSE;
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst LEFontInstance *ScriptCompositeFontInstance::getSubFont(const LEUnicode chars[], le_int32 *offset, le_int32 limit, le_int32 script, LEErrorCode &success) const
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (LE_FAILURE(success)) {
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return NULL;
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (chars == NULL || *offset < 0 || limit < 0 || *offset >= limit || script < 0 || script >= scriptCodeCount) {
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        success = LE_ILLEGAL_ARGUMENT_ERROR;
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return NULL;
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const LEFontInstance *result = fFontMap->getScriptFont(script, success);
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (LE_FAILURE(success)) {
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return NULL;
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    *offset = limit;
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return result;
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// This is the really stupid version that doesn't look in any other font for the character...
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// It would be better to also look in the "DEFAULT:" font. Another thing to do would be to
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// look in all the fonts in some order, script code order being the most obvious...
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLEGlyphID ScriptCompositeFontInstance::mapCharToGlyph(LEUnicode32 ch) const
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode  error  = U_ZERO_ERROR;
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    LEErrorCode status = LE_NO_ERROR;
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 script = uscript_getScript(ch, &error);
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const LEFontInstance *scriptFont = fFontMap->getScriptFont(script, status);
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    LEGlyphID subFont = LE_SET_SUB_FONT(0, script);
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (LE_FAILURE(status)) {
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return subFont;
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    LEGlyphID glyph = scriptFont->mapCharToGlyph(ch);
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return LE_SET_GLYPH(subFont, glyph);
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
104