2000-11-14 21:22:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
2005-03-08 22:49:59 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
|
2000-11-14 21:22:14 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
2003-04-12 00:37:12 +00:00
|
|
|
#include "LEScripts.h"
|
2000-11-14 21:22:14 +00:00
|
|
|
#include "LEGlyphFilter.h"
|
2004-04-12 18:51:31 +00:00
|
|
|
#include "LEGlyphStorage.h"
|
2000-11-14 21:22:14 +00:00
|
|
|
#include "LayoutEngine.h"
|
|
|
|
#include "OpenTypeLayoutEngine.h"
|
|
|
|
#include "ArabicLayoutEngine.h"
|
|
|
|
#include "ScriptAndLanguageTags.h"
|
2004-05-03 21:13:13 +00:00
|
|
|
#include "CharSubstitutionFilter.h"
|
2000-11-14 21:22:14 +00:00
|
|
|
|
|
|
|
#include "GlyphSubstitutionTables.h"
|
|
|
|
#include "GlyphDefinitionTables.h"
|
|
|
|
#include "GlyphPositioningTables.h"
|
|
|
|
|
|
|
|
#include "GDEFMarkFilter.h"
|
|
|
|
|
|
|
|
#include "ArabicShaping.h"
|
2004-08-19 23:51:11 +00:00
|
|
|
#include "CanonShaping.h"
|
2000-11-14 21:22:14 +00:00
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_bool CharSubstitutionFilter::accept(LEGlyphID glyph) const
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
|
|
|
return fFontInstance->canDisplay((LEUnicode) glyph);
|
|
|
|
}
|
|
|
|
|
2004-10-19 06:25:41 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ArabicOpenTypeLayoutEngine)
|
2002-06-29 00:04:16 +00:00
|
|
|
|
2000-12-21 01:18:44 +00:00
|
|
|
ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
|
2005-01-14 19:22:53 +00:00
|
|
|
le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable)
|
|
|
|
: OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable)
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
2005-08-06 00:48:27 +00:00
|
|
|
fFeatureMap = ArabicShaping::getFeatureMap(fFeatureMapCount);
|
|
|
|
fFeatureOrder = TRUE;
|
2000-11-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
|
2005-01-14 19:22:53 +00:00
|
|
|
ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
|
|
|
|
le_int32 typoFlags)
|
|
|
|
: OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
2005-08-06 00:48:27 +00:00
|
|
|
fFeatureMap = ArabicShaping::getFeatureMap(fFeatureMapCount);
|
|
|
|
//fFeatureOrder = TRUE;
|
2000-11-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ArabicOpenTypeLayoutEngine::~ArabicOpenTypeLayoutEngine()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input: characters
|
|
|
|
// Output: characters, char indices, tags
|
|
|
|
// Returns: output character count
|
|
|
|
le_int32 ArabicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
|
2005-02-24 00:55:30 +00:00
|
|
|
LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
2002-04-02 03:33:42 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2002-04-02 03:33:42 +00:00
|
|
|
if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2005-02-24 00:55:30 +00:00
|
|
|
outChars = LE_NEW_ARRAY(LEUnicode, count);
|
|
|
|
|
|
|
|
if (outChars == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
glyphStorage.allocateGlyphArray(count, rightToLeft, success);
|
2004-05-07 23:29:16 +00:00
|
|
|
glyphStorage.allocateAuxData(success);
|
2000-11-14 21:22:14 +00:00
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
2005-02-24 00:55:30 +00:00
|
|
|
LE_DELETE_ARRAY(outChars);
|
2002-04-02 03:33:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2005-02-24 00:55:30 +00:00
|
|
|
CanonShaping::reorderMarks(&chars[offset], count, rightToLeft, outChars, glyphStorage);
|
|
|
|
|
2005-03-17 02:14:54 +00:00
|
|
|
// Note: This processes the *original* character array so we can get context
|
2005-02-24 00:55:30 +00:00
|
|
|
// for the first and last characters. This is OK because only the marks
|
|
|
|
// will have been reordered, and they don't contribute to shaping.
|
2004-08-19 23:51:11 +00:00
|
|
|
ArabicShaping::shape(chars, offset, count, max, rightToLeft, glyphStorage);
|
2000-11-14 21:22:14 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArabicOpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse,
|
2004-04-12 18:51:31 +00:00
|
|
|
LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
2002-04-02 03:33:42 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
if (chars == NULL || offset < 0 || count < 0) {
|
2002-04-02 03:33:42 +00:00
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2000-11-14 21:22:14 +00:00
|
|
|
if (fGPOSTable != NULL) {
|
2004-04-12 18:51:31 +00:00
|
|
|
OpenTypeLayoutEngine::adjustGlyphPositions(chars, offset, count, reverse, glyphStorage, success);
|
2000-11-14 21:22:14 +00:00
|
|
|
} else if (fGDEFTable != NULL) {
|
|
|
|
GDEFMarkFilter filter(fGDEFTable);
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
adjustMarkGlyphs(glyphStorage, &filter, success);
|
2000-11-14 21:22:14 +00:00
|
|
|
} else {
|
2004-08-19 23:51:11 +00:00
|
|
|
GlyphDefinitionTableHeader *gdefTable = (GlyphDefinitionTableHeader *) CanonShaping::glyphDefinitionTable;
|
2000-11-14 21:22:14 +00:00
|
|
|
GDEFMarkFilter filter(gdefTable);
|
2003-02-05 00:05:40 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
adjustMarkGlyphs(&chars[offset], count, reverse, glyphStorage, &filter, success);
|
2000-11-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-14 19:22:53 +00:00
|
|
|
UnicodeArabicOpenTypeLayoutEngine::UnicodeArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags)
|
|
|
|
: ArabicOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
2004-08-19 23:51:11 +00:00
|
|
|
fGSUBTable = (const GlyphSubstitutionTableHeader *) CanonShaping::glyphSubstitutionTable;
|
|
|
|
fGDEFTable = (const GlyphDefinitionTableHeader *) CanonShaping::glyphDefinitionTable;
|
2000-11-14 21:22:14 +00:00
|
|
|
|
|
|
|
fSubstitutionFilter = new CharSubstitutionFilter(fontInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeArabicOpenTypeLayoutEngine::~UnicodeArabicOpenTypeLayoutEngine()
|
|
|
|
{
|
2002-10-04 19:27:01 +00:00
|
|
|
delete fSubstitutionFilter;
|
2000-11-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// "glyphs", "indices" -> glyphs, indices
|
2004-04-12 18:51:31 +00:00
|
|
|
le_int32 UnicodeArabicOpenTypeLayoutEngine::glyphPostProcessing(LEGlyphStorage &tempGlyphStorage, LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
2002-04-02 03:33:42 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
// FIXME: we could avoid the memory allocation and copy if we
|
|
|
|
// made a clone of mapCharsToGlyphs which took the fake glyphs
|
|
|
|
// directly.
|
2004-05-07 23:29:16 +00:00
|
|
|
le_int32 tempGlyphCount = tempGlyphStorage.getGlyphCount();
|
2003-02-05 00:05:40 +00:00
|
|
|
LEUnicode *tempChars = LE_NEW_ARRAY(LEUnicode, tempGlyphCount);
|
|
|
|
|
|
|
|
if (tempChars == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (le_int32 i = 0; i < tempGlyphCount; i += 1) {
|
2004-05-07 23:29:16 +00:00
|
|
|
tempChars[i] = (LEUnicode) LE_GET_GLYPH(tempGlyphStorage[i]);
|
2003-02-05 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
glyphStorage.adoptCharIndicesArray(tempGlyphStorage);
|
2000-11-14 21:22:14 +00:00
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
ArabicOpenTypeLayoutEngine::mapCharsToGlyphs(tempChars, 0, tempGlyphCount, FALSE, TRUE, glyphStorage, success);
|
2003-02-05 00:05:40 +00:00
|
|
|
|
|
|
|
LE_DELETE_ARRAY(tempChars);
|
2000-11-14 21:22:14 +00:00
|
|
|
|
|
|
|
return tempGlyphCount;
|
|
|
|
}
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
void UnicodeArabicOpenTypeLayoutEngine::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, le_bool /*mirror*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
2002-04-02 03:33:42 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2002-04-02 03:33:42 +00:00
|
|
|
if (chars == NULL || offset < 0 || count < 0) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
le_int32 i, dir = 1, out = 0;
|
2000-11-14 21:22:14 +00:00
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
out = count - 1;
|
|
|
|
dir = -1;
|
|
|
|
}
|
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
glyphStorage.allocateGlyphArray(count, reverse, success);
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
for (i = 0; i < count; i += 1, out += dir) {
|
|
|
|
glyphStorage[out] = (LEGlyphID) chars[offset + i];
|
2000-11-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnicodeArabicOpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse,
|
2004-04-12 18:51:31 +00:00
|
|
|
LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
2002-04-02 03:33:42 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
if (chars == NULL || offset < 0 || count < 0) {
|
2002-04-02 03:33:42 +00:00
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2000-11-14 21:22:14 +00:00
|
|
|
GDEFMarkFilter filter(fGDEFTable);
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
adjustMarkGlyphs(&chars[offset], count, reverse, glyphStorage, &filter, success);
|
2000-11-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_END
|
2000-11-14 21:22:14 +00:00
|
|
|
|