1/*
2 * HanLayoutEngine.cpp: OpenType processing for Han fonts.
3 *
4 * (C) Copyright IBM Corp. 1998-2008 - All Rights Reserved.
5 */
6
7#include "LETypes.h"
8#include "LEScripts.h"
9#include "LELanguages.h"
10
11#include "LayoutEngine.h"
12#include "OpenTypeLayoutEngine.h"
13#include "HanLayoutEngine.h"
14#include "ScriptAndLanguageTags.h"
15#include "LEGlyphStorage.h"
16#include "OpenTypeTables.h"
17
18U_NAMESPACE_BEGIN
19
20UOBJECT_DEFINE_RTTI_IMPLEMENTATION(HanOpenTypeLayoutEngine)
21
22#define loclFeatureTag LE_LOCL_FEATURE_TAG
23#define smplFeatureTag LE_SMPL_FEATURE_TAG
24#define tradFeatureTag LE_TRAD_FEATURE_TAG
25
26#define loclFeatureMask 0x80000000UL
27#define smplFeatureMask 0x40000000UL
28#define tradFeatureMask 0x20000000UL
29
30static const FeatureMap featureMap[] =
31{
32    {loclFeatureTag, loclFeatureMask},
33    {smplFeatureTag, smplFeatureMask},
34    {tradFeatureTag, tradFeatureMask}
35};
36
37static const le_int32 featureMapCount = LE_ARRAY_SIZE(featureMap);
38
39#define features (loclFeatureMask)
40
41HanOpenTypeLayoutEngine::HanOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
42                        le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable, LEErrorCode &success)
43    : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable, success)
44{
45    fFeatureMap      = featureMap;
46    fFeatureMapCount = featureMapCount;
47}
48
49HanOpenTypeLayoutEngine::~HanOpenTypeLayoutEngine()
50{
51    // nothing to do
52}
53
54le_int32 HanOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/,
55        LEUnicode *&/*outChars*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
56{
57    if (LE_FAILURE(success)) {
58        return 0;
59    }
60
61    if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
62        success = LE_ILLEGAL_ARGUMENT_ERROR;
63        return 0;
64    }
65
66    glyphStorage.allocateGlyphArray(count, FALSE, success);
67    glyphStorage.allocateAuxData(success);
68
69    if (LE_FAILURE(success)) {
70        return 0;
71    }
72
73    // FIXME: do we want to add the 'trad' feature for 'ZHT' and the
74    // 'smpl' feature for 'ZHS'? If we do this, we can remove the exact
75    // flag from the language tag lookups, so we can use these features
76    // with the default LangSys...
77    for (le_int32 i = 0; i < count; i += 1) {
78        glyphStorage.setAuxData(i, features, success);
79    }
80
81    return count;
82}
83
84U_NAMESPACE_END
85