2000-11-28 20:56:52 +00:00
|
|
|
/*
|
|
|
|
*
|
2005-07-21 18:30:10 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "OpenTypeTables.h"
|
|
|
|
#include "ArabicShaping.h"
|
2004-04-12 18:51:31 +00:00
|
|
|
#include "LEGlyphStorage.h"
|
2005-07-21 18:30:10 +00:00
|
|
|
#include "ClassDefinitionTables.h"
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2005-07-21 18:30:10 +00:00
|
|
|
// This table maps Unicode joining types to
|
|
|
|
// ShapeTypes.
|
2000-11-28 20:56:52 +00:00
|
|
|
const ArabicShaping::ShapeType ArabicShaping::shapeTypes[] =
|
|
|
|
{
|
2005-07-21 18:30:10 +00:00
|
|
|
ArabicShaping::ST_NOSHAPE_NONE, // [U]
|
|
|
|
ArabicShaping::ST_NOSHAPE_DUAL, // [C]
|
|
|
|
ArabicShaping::ST_DUAL, // [D]
|
|
|
|
ArabicShaping::ST_LEFT, // [L]
|
|
|
|
ArabicShaping::ST_RIGHT, // [R]
|
|
|
|
ArabicShaping::ST_TRANSPARENT // [T]
|
2000-11-28 20:56:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2004-10-17 20:31:34 +00:00
|
|
|
shaping array holds types for Arabic chars between 0610 and 0700
|
2000-11-28 20:56:52 +00:00
|
|
|
other values are either unshaped, or transparent if a mark or format
|
2001-01-25 02:35:07 +00:00
|
|
|
code, except for format codes 200c (zero-width non-joiner) and 200d
|
2000-11-28 20:56:52 +00:00
|
|
|
(dual-width joiner) which are both unshaped and non_joining or
|
|
|
|
dual-joining, respectively.
|
|
|
|
*/
|
|
|
|
ArabicShaping::ShapeType ArabicShaping::getShapeType(LEUnicode c)
|
|
|
|
{
|
2005-07-21 18:30:10 +00:00
|
|
|
const ClassDefinitionTable *joiningTypes = (const ClassDefinitionTable *) ArabicShaping::shapingTypeTable;
|
|
|
|
le_int32 joiningType = joiningTypes->getGlyphClass(c);
|
|
|
|
|
|
|
|
if (joiningType >= 0 && joiningType < ArabicShaping::JT_COUNT) {
|
|
|
|
return ArabicShaping::shapeTypes[joiningType];
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2005-07-21 18:30:10 +00:00
|
|
|
return ArabicShaping::ST_NOSHAPE_NONE;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2004-07-19 21:33:03 +00:00
|
|
|
static const LETag isolFeatureTag = LE_ISOL_FEATURE_TAG;
|
|
|
|
static const LETag initFeatureTag = LE_INIT_FEATURE_TAG;
|
|
|
|
static const LETag mediFeatureTag = LE_MEDI_FEATURE_TAG;
|
|
|
|
static const LETag finaFeatureTag = LE_FINA_FEATURE_TAG;
|
|
|
|
static const LETag ligaFeatureTag = LE_LIGA_FEATURE_TAG;
|
|
|
|
static const LETag msetFeatureTag = LE_MSET_FEATURE_TAG;
|
|
|
|
static const LETag markFeatureTag = LE_MARK_FEATURE_TAG;
|
|
|
|
static const LETag ccmpFeatureTag = LE_CCMP_FEATURE_TAG;
|
|
|
|
static const LETag rligFeatureTag = LE_RLIG_FEATURE_TAG;
|
|
|
|
static const LETag caltFeatureTag = LE_CALT_FEATURE_TAG;
|
|
|
|
static const LETag dligFeatureTag = LE_DLIG_FEATURE_TAG;
|
|
|
|
static const LETag cswhFeatureTag = LE_CSWH_FEATURE_TAG;
|
|
|
|
static const LETag cursFeatureTag = LE_CURS_FEATURE_TAG;
|
|
|
|
static const LETag kernFeatureTag = LE_KERN_FEATURE_TAG;
|
|
|
|
static const LETag mkmkFeatureTag = LE_MKMK_FEATURE_TAG;
|
2002-06-10 23:33:56 +00:00
|
|
|
|
2004-07-19 21:33:03 +00:00
|
|
|
static const LETag emptyTag = 0x00000000; // ''
|
2002-06-10 23:33:56 +00:00
|
|
|
|
2004-07-19 21:33:03 +00:00
|
|
|
static const LETag featureOrder[] =
|
2002-06-10 23:33:56 +00:00
|
|
|
{
|
|
|
|
ccmpFeatureTag, isolFeatureTag, finaFeatureTag, mediFeatureTag, initFeatureTag, rligFeatureTag,
|
|
|
|
caltFeatureTag, ligaFeatureTag, dligFeatureTag, cswhFeatureTag, msetFeatureTag, cursFeatureTag,
|
|
|
|
kernFeatureTag, markFeatureTag, mkmkFeatureTag, emptyTag
|
|
|
|
};
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
const LETag ArabicShaping::tagArray[] =
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2002-06-10 23:33:56 +00:00
|
|
|
isolFeatureTag, ligaFeatureTag, msetFeatureTag, markFeatureTag, ccmpFeatureTag, rligFeatureTag,
|
|
|
|
caltFeatureTag, dligFeatureTag, cswhFeatureTag, cursFeatureTag, kernFeatureTag, mkmkFeatureTag, emptyTag,
|
|
|
|
|
|
|
|
finaFeatureTag, ligaFeatureTag, msetFeatureTag, markFeatureTag, ccmpFeatureTag, rligFeatureTag,
|
|
|
|
caltFeatureTag, dligFeatureTag, cswhFeatureTag, cursFeatureTag, kernFeatureTag, mkmkFeatureTag, emptyTag,
|
|
|
|
|
|
|
|
initFeatureTag, ligaFeatureTag, msetFeatureTag, markFeatureTag, ccmpFeatureTag, rligFeatureTag,
|
|
|
|
caltFeatureTag, dligFeatureTag, cswhFeatureTag, cursFeatureTag, kernFeatureTag, mkmkFeatureTag, emptyTag,
|
|
|
|
|
|
|
|
mediFeatureTag, ligaFeatureTag, msetFeatureTag, markFeatureTag, ccmpFeatureTag, rligFeatureTag,
|
|
|
|
caltFeatureTag, dligFeatureTag, cswhFeatureTag, cursFeatureTag, kernFeatureTag, mkmkFeatureTag, emptyTag
|
2000-11-28 20:56:52 +00:00
|
|
|
};
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
#define TAGS_PER_GLYPH ((sizeof ArabicShaping::tagArray / sizeof ArabicShaping::tagArray[0]) / 4)
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2002-06-10 23:33:56 +00:00
|
|
|
const LETag *ArabicShaping::getFeatureOrder()
|
|
|
|
{
|
|
|
|
return featureOrder;
|
|
|
|
}
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
void ArabicShaping::adjustTags(le_int32 outIndex, le_int32 shapeOffset, LEGlyphStorage &glyphStorage)
|
|
|
|
{
|
2004-05-07 23:29:16 +00:00
|
|
|
LEErrorCode success = LE_NO_ERROR;
|
|
|
|
const LETag *glyphTags = (const LETag *) glyphStorage.getAuxData(outIndex, success);
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
glyphStorage.setAuxData(outIndex, (void *) &glyphTags[TAGS_PER_GLYPH * shapeOffset], success);
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
2000-11-28 20:56:52 +00:00
|
|
|
void ArabicShaping::shape(const LEUnicode *chars, le_int32 offset, le_int32 charCount, le_int32 charMax,
|
2004-04-12 18:51:31 +00:00
|
|
|
le_bool rightToLeft, LEGlyphStorage &glyphStorage)
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
// iterate in logical order, store tags in visible order
|
|
|
|
//
|
|
|
|
// the effective right char is the most recently encountered
|
|
|
|
// non-transparent char
|
|
|
|
//
|
|
|
|
// four boolean states:
|
|
|
|
// the effective right char shapes
|
|
|
|
// the effective right char causes left shaping
|
|
|
|
// the current char shapes
|
|
|
|
// the current char causes right shaping
|
|
|
|
//
|
|
|
|
// if both cause shaping, then
|
|
|
|
// shaper.shape(errout, 2) (isolate to initial, or final to medial)
|
|
|
|
// shaper.shape(out, 1) (isolate to final)
|
|
|
|
|
|
|
|
ShapeType rightType = ST_NOSHAPE_NONE, leftType = ST_NOSHAPE_NONE;
|
2004-05-07 23:29:16 +00:00
|
|
|
LEErrorCode success = LE_NO_ERROR;
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int32 i;
|
|
|
|
|
|
|
|
for (i = offset - 1; i >= 0; i -= 1) {
|
|
|
|
rightType = getShapeType(chars[i]);
|
|
|
|
|
|
|
|
if (rightType != ST_TRANSPARENT) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = offset + charCount; i < charMax; i += 1) {
|
|
|
|
leftType = getShapeType(chars[i]);
|
|
|
|
|
|
|
|
if (leftType != ST_TRANSPARENT) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// erout is effective right logical index
|
|
|
|
le_int32 erout = -1;
|
2003-12-08 22:43:41 +00:00
|
|
|
le_bool rightShapes = FALSE;
|
2000-11-28 20:56:52 +00:00
|
|
|
le_bool rightCauses = (rightType & MASK_SHAPE_LEFT) != 0;
|
|
|
|
le_int32 in, e, out = 0, dir = 1;
|
|
|
|
|
|
|
|
if (rightToLeft) {
|
|
|
|
out = charCount - 1;
|
|
|
|
erout = charCount;
|
|
|
|
dir = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (in = offset, e = offset + charCount; in < e; in += 1, out += dir) {
|
|
|
|
LEUnicode c = chars[in];
|
|
|
|
ShapeType t = getShapeType(c);
|
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
glyphStorage.setAuxData(out, (void *) tagArray, success);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
if ((t & MASK_TRANSPARENT) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
le_bool curShapes = (t & MASK_NOSHAPE) == 0;
|
|
|
|
le_bool curCauses = (t & MASK_SHAPE_RIGHT) != 0;
|
|
|
|
|
|
|
|
if (rightCauses && curCauses) {
|
|
|
|
if (rightShapes) {
|
2004-04-12 18:51:31 +00:00
|
|
|
adjustTags(erout, 2, glyphStorage);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (curShapes) {
|
2004-04-12 18:51:31 +00:00
|
|
|
adjustTags(out, 1, glyphStorage);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rightShapes = curShapes;
|
|
|
|
rightCauses = (t & MASK_SHAPE_LEFT) != 0;
|
|
|
|
erout = out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rightShapes && rightCauses && (leftType & MASK_SHAPE_RIGHT) != 0) {
|
2004-04-12 18:51:31 +00:00
|
|
|
adjustTags(erout, 2, glyphStorage);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_END
|