0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A *
0N/A */
0N/A
0N/A/*
0N/A *
0N/A * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
0N/A *
0N/A */
0N/A
0N/A#include "LETypes.h"
0N/A#include "OpenTypeTables.h"
0N/A#include "ArabicShaping.h"
0N/A#include "LEGlyphStorage.h"
0N/A#include "ClassDefinitionTables.h"
0N/A
1693N/AU_NAMESPACE_BEGIN
1693N/A
0N/A// This table maps Unicode joining types to
0N/A// ShapeTypes.
0N/Aconst ArabicShaping::ShapeType ArabicShaping::shapeTypes[] =
0N/A{
0N/A ArabicShaping::ST_NOSHAPE_NONE, // [U]
0N/A ArabicShaping::ST_NOSHAPE_DUAL, // [C]
0N/A ArabicShaping::ST_DUAL, // [D]
0N/A ArabicShaping::ST_LEFT, // [L]
0N/A ArabicShaping::ST_RIGHT, // [R]
0N/A ArabicShaping::ST_TRANSPARENT // [T]
0N/A};
0N/A
0N/A/*
0N/A shaping array holds types for Arabic chars between 0610 and 0700
0N/A other values are either unshaped, or transparent if a mark or format
0N/A code, except for format codes 200c (zero-width non-joiner) and 200d
0N/A (dual-width joiner) which are both unshaped and non_joining or
0N/A dual-joining, respectively.
0N/A*/
0N/AArabicShaping::ShapeType ArabicShaping::getShapeType(LEUnicode c)
0N/A{
5980N/A LEErrorCode success = LE_NO_ERROR;
5980N/A const LEReferenceTo<ClassDefinitionTable> joiningTypes((const ClassDefinitionTable *) ArabicShaping::shapingTypeTable,
5980N/A ArabicShaping::shapingTypeTableLen);
5980N/A le_int32 joiningType = joiningTypes->getGlyphClass(joiningTypes, c, success);
0N/A
5980N/A if (joiningType >= 0 && joiningType < ArabicShaping::JT_COUNT && LE_SUCCESS(success)) {
5980N/A return ArabicShaping::shapeTypes[joiningType];
5980N/A }
0N/A
5980N/A return ArabicShaping::ST_NOSHAPE_NONE;
0N/A}
0N/A
0N/A#define isolFeatureTag LE_ISOL_FEATURE_TAG
0N/A#define initFeatureTag LE_INIT_FEATURE_TAG
0N/A#define mediFeatureTag LE_MEDI_FEATURE_TAG
0N/A#define finaFeatureTag LE_FINA_FEATURE_TAG
0N/A#define ligaFeatureTag LE_LIGA_FEATURE_TAG
0N/A#define msetFeatureTag LE_MSET_FEATURE_TAG
0N/A#define markFeatureTag LE_MARK_FEATURE_TAG
0N/A#define ccmpFeatureTag LE_CCMP_FEATURE_TAG
0N/A#define rligFeatureTag LE_RLIG_FEATURE_TAG
0N/A#define caltFeatureTag LE_CALT_FEATURE_TAG
0N/A#define dligFeatureTag LE_DLIG_FEATURE_TAG
0N/A#define cswhFeatureTag LE_CSWH_FEATURE_TAG
0N/A#define cursFeatureTag LE_CURS_FEATURE_TAG
0N/A#define kernFeatureTag LE_KERN_FEATURE_TAG
0N/A#define mkmkFeatureTag LE_MKMK_FEATURE_TAG
0N/A
0N/A// NOTE:
0N/A// The isol, fina, init and medi features must be
0N/A// defined in the above order, and have masks that
0N/A// are all in the same nibble.
0N/A#define isolFeatureMask 0x80000000UL
0N/A#define finaFeatureMask 0x40000000UL
0N/A#define initFeatureMask 0x20000000UL
0N/A#define mediFeatureMask 0x10000000UL
0N/A#define ccmpFeatureMask 0x08000000UL
0N/A#define rligFeatureMask 0x04000000UL
0N/A#define caltFeatureMask 0x02000000UL
0N/A#define ligaFeatureMask 0x01000000UL
0N/A#define dligFeatureMask 0x00800000UL
0N/A#define cswhFeatureMask 0x00400000UL
0N/A#define msetFeatureMask 0x00200000UL
0N/A#define cursFeatureMask 0x00100000UL
0N/A#define kernFeatureMask 0x00080000UL
0N/A#define markFeatureMask 0x00040000UL
0N/A#define mkmkFeatureMask 0x00020000UL
0N/A
3171N/A#define NO_FEATURES 0
1693N/A#define ISOL_FEATURES (isolFeatureMask | ligaFeatureMask | msetFeatureMask | markFeatureMask | ccmpFeatureMask | rligFeatureMask | caltFeatureMask | dligFeatureMask | cswhFeatureMask | cursFeatureMask | kernFeatureMask | mkmkFeatureMask)
0N/A
0N/A#define SHAPE_MASK 0xF0000000UL
0N/A
0N/Astatic const FeatureMap featureMap[] = {
0N/A {ccmpFeatureTag, ccmpFeatureMask},
0N/A {isolFeatureTag, isolFeatureMask},
0N/A {finaFeatureTag, finaFeatureMask},
0N/A {mediFeatureTag, mediFeatureMask},
0N/A {initFeatureTag, initFeatureMask},
0N/A {rligFeatureTag, rligFeatureMask},
0N/A {caltFeatureTag, caltFeatureMask},
0N/A {ligaFeatureTag, ligaFeatureMask},
0N/A {dligFeatureTag, dligFeatureMask},
0N/A {cswhFeatureTag, cswhFeatureMask},
0N/A {msetFeatureTag, msetFeatureMask},
0N/A {cursFeatureTag, cursFeatureMask},
0N/A {kernFeatureTag, kernFeatureMask},
0N/A {markFeatureTag, markFeatureMask},
0N/A {mkmkFeatureTag, mkmkFeatureMask}
0N/A};
0N/A
0N/Aconst FeatureMap *ArabicShaping::getFeatureMap(le_int32 &count)
0N/A{
0N/A count = LE_ARRAY_SIZE(featureMap);
0N/A
0N/A return featureMap;
0N/A}
0N/A
0N/Avoid ArabicShaping::adjustTags(le_int32 outIndex, le_int32 shapeOffset, LEGlyphStorage &glyphStorage)
0N/A{
0N/A LEErrorCode success = LE_NO_ERROR;
0N/A FeatureMask featureMask = (FeatureMask) glyphStorage.getAuxData(outIndex, success);
0N/A FeatureMask shape = featureMask & SHAPE_MASK;
0N/A
0N/A shape >>= shapeOffset;
0N/A
0N/A glyphStorage.setAuxData(outIndex, ((featureMask & ~SHAPE_MASK) | shape), success);
0N/A}
0N/A
0N/Avoid ArabicShaping::shape(const LEUnicode *chars, le_int32 offset, le_int32 charCount, le_int32 charMax,
0N/A le_bool rightToLeft, LEGlyphStorage &glyphStorage)
0N/A{
0N/A // iterate in logical order, store tags in visible order
0N/A //
0N/A // the effective right char is the most recently encountered
0N/A // non-transparent char
0N/A //
0N/A // four boolean states:
0N/A // the effective right char shapes
0N/A // the effective right char causes left shaping
0N/A // the current char shapes
0N/A // the current char causes right shaping
0N/A //
0N/A // if both cause shaping, then
0N/A // shaper.shape(errout, 2) (isolate to initial, or final to medial)
0N/A // shaper.shape(out, 1) (isolate to final)
0N/A
0N/A ShapeType rightType = ST_NOSHAPE_NONE, leftType = ST_NOSHAPE_NONE;
0N/A LEErrorCode success = LE_NO_ERROR;
0N/A le_int32 i;
0N/A
0N/A for (i = offset - 1; i >= 0; i -= 1) {
0N/A rightType = getShapeType(chars[i]);
0N/A
0N/A if (rightType != ST_TRANSPARENT) {
0N/A break;
0N/A }
0N/A }
0N/A
0N/A for (i = offset + charCount; i < charMax; i += 1) {
0N/A leftType = getShapeType(chars[i]);
0N/A
0N/A if (leftType != ST_TRANSPARENT) {
0N/A break;
0N/A }
0N/A }
0N/A
0N/A // erout is effective right logical index
0N/A le_int32 erout = -1;
0N/A le_bool rightShapes = FALSE;
0N/A le_bool rightCauses = (rightType & MASK_SHAPE_LEFT) != 0;
0N/A le_int32 in, e, out = 0, dir = 1;
0N/A
0N/A if (rightToLeft) {
0N/A out = charCount - 1;
0N/A erout = charCount;
0N/A dir = -1;
0N/A }
0N/A
0N/A for (in = offset, e = offset + charCount; in < e; in += 1, out += dir) {
0N/A LEUnicode c = chars[in];
0N/A ShapeType t = getShapeType(c);
0N/A
3171N/A if (t == ST_NOSHAPE_NONE) {
3171N/A glyphStorage.setAuxData(out, NO_FEATURES, success);
3171N/A } else {
0N/A glyphStorage.setAuxData(out, ISOL_FEATURES, success);
3171N/A }
0N/A
0N/A if ((t & MASK_TRANSPARENT) != 0) {
0N/A continue;
0N/A }
0N/A
0N/A le_bool curShapes = (t & MASK_NOSHAPE) == 0;
0N/A le_bool curCauses = (t & MASK_SHAPE_RIGHT) != 0;
0N/A
0N/A if (rightCauses && curCauses) {
0N/A if (rightShapes) {
0N/A adjustTags(erout, 2, glyphStorage);
0N/A }
0N/A
0N/A if (curShapes) {
0N/A adjustTags(out, 1, glyphStorage);
0N/A }
0N/A }
0N/A
0N/A rightShapes = curShapes;
0N/A rightCauses = (t & MASK_SHAPE_LEFT) != 0;
0N/A erout = out;
0N/A }
0N/A
0N/A if (rightShapes && rightCauses && (leftType & MASK_SHAPE_RIGHT) != 0) {
0N/A adjustTags(erout, 2, glyphStorage);
0N/A }
0N/A}
1693N/A
1693N/AU_NAMESPACE_END