2000-11-14 21:22:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* %W% %E%
|
|
|
|
*
|
2001-01-19 00:30:17 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998, 1999, 2000, 2001 - All Rights Reserved
|
2000-11-14 21:22:14 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "LEGlyphFilter.h"
|
|
|
|
#include "LayoutEngine.h"
|
|
|
|
#include "OpenTypeLayoutEngine.h"
|
|
|
|
#include "ArabicLayoutEngine.h"
|
|
|
|
#include "ScriptAndLanguageTags.h"
|
|
|
|
|
|
|
|
#include "GlyphSubstitutionTables.h"
|
|
|
|
#include "GlyphDefinitionTables.h"
|
|
|
|
#include "GlyphPositioningTables.h"
|
|
|
|
|
|
|
|
#include "GDEFMarkFilter.h"
|
|
|
|
|
|
|
|
#include "ArabicShaping.h"
|
|
|
|
#include "HebrewShaping.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2002-10-04 19:27:01 +00:00
|
|
|
class CharSubstitutionFilter : public UMemory, public LEGlyphFilter
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
|
|
|
private:
|
2000-12-21 01:18:44 +00:00
|
|
|
const LEFontInstance *fFontInstance;
|
2000-11-14 21:22:14 +00:00
|
|
|
|
2002-10-04 19:27:01 +00:00
|
|
|
CharSubstitutionFilter(const CharSubstitutionFilter &other); // forbid copying of this class
|
|
|
|
CharSubstitutionFilter &operator=(const CharSubstitutionFilter &other); // forbid copying of this class
|
2002-07-16 19:29:19 +00:00
|
|
|
|
2000-11-14 21:22:14 +00:00
|
|
|
public:
|
2000-12-21 01:18:44 +00:00
|
|
|
CharSubstitutionFilter(const LEFontInstance *fontInstance);
|
2001-01-19 00:30:17 +00:00
|
|
|
le_bool accept(LEGlyphID glyph) const;
|
2000-11-14 21:22:14 +00:00
|
|
|
};
|
|
|
|
|
2000-12-21 01:18:44 +00:00
|
|
|
CharSubstitutionFilter::CharSubstitutionFilter(const LEFontInstance *fontInstance)
|
2000-11-14 21:22:14 +00:00
|
|
|
: fFontInstance(fontInstance)
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2002-06-29 00:04:16 +00:00
|
|
|
const char ArabicOpenTypeLayoutEngine::fgClassID=0;
|
|
|
|
|
2000-12-21 01:18:44 +00:00
|
|
|
ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
|
2001-01-19 00:30:17 +00:00
|
|
|
const GlyphSubstitutionTableHeader *gsubTable)
|
2000-11-14 21:22:14 +00:00
|
|
|
: OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, gsubTable)
|
|
|
|
{
|
2002-06-10 23:33:56 +00:00
|
|
|
fFeatureOrder = ArabicShaping::getFeatureOrder();
|
2000-11-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
|
2000-12-21 01:18:44 +00:00
|
|
|
ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode)
|
2000-11-14 21:22:14 +00:00
|
|
|
: OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode)
|
|
|
|
{
|
2002-06-10 23:33:56 +00:00
|
|
|
fFeatureOrder = ArabicShaping::getFeatureOrder();
|
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,
|
2000-12-21 01:18:44 +00:00
|
|
|
LEUnicode *&outChars, le_int32 *&charIndices, const LETag **&featureTags, 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
|
|
|
|
2003-01-07 22:47:19 +00:00
|
|
|
featureTags = LE_NEW_ARRAY(const LETag *, count);
|
2000-11-14 21:22:14 +00:00
|
|
|
|
2002-04-02 03:33:42 +00:00
|
|
|
if (featureTags == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2002-04-02 03:33:42 +00:00
|
|
|
switch (fScriptCode) {
|
|
|
|
case arabScriptCode:
|
|
|
|
{
|
|
|
|
GlyphShaper shaper(featureTags);
|
2000-11-14 21:22:14 +00:00
|
|
|
|
2002-04-02 03:33:42 +00:00
|
|
|
// NOTE: may not need seperate shaper if always use tags...
|
|
|
|
// NOTE: shaper could allocate the feature tags...
|
|
|
|
ArabicShaping::shape(chars, offset, count, max, rightToLeft, shaper);
|
|
|
|
break;
|
|
|
|
}
|
2000-11-14 21:22:14 +00:00
|
|
|
|
2002-04-02 03:33:42 +00:00
|
|
|
case hebrScriptCode:
|
|
|
|
HebrewShaping::shape(chars, offset, count, max, rightToLeft, featureTags);
|
|
|
|
break;
|
|
|
|
}
|
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,
|
2000-12-21 01:18:44 +00:00
|
|
|
LEGlyphID glyphs[], le_int32 glyphCount, float positions[], 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 || glyphs == NULL || positions == NULL || offset < 0 || count < 0) {
|
|
|
|
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) {
|
2000-12-21 01:18:44 +00:00
|
|
|
OpenTypeLayoutEngine::adjustGlyphPositions(chars, offset, count, reverse, glyphs, glyphCount, positions, success);
|
2000-11-14 21:22:14 +00:00
|
|
|
} else if (fGDEFTable != NULL) {
|
|
|
|
GDEFMarkFilter filter(fGDEFTable);
|
|
|
|
|
2000-12-21 01:18:44 +00:00
|
|
|
adjustMarkGlyphs(glyphs, glyphCount, false, &filter, positions, success);
|
2000-11-14 21:22:14 +00:00
|
|
|
} else {
|
|
|
|
GlyphDefinitionTableHeader *gdefTable = (GlyphDefinitionTableHeader *) ArabicShaping::glyphDefinitionTable;
|
|
|
|
GDEFMarkFilter filter(gdefTable);
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID *tempGlyphs;
|
2000-11-14 21:22:14 +00:00
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
// FIXME: we could avoid the memory allocation and copying here by
|
|
|
|
// making a clone of the adjustMarkGlyphs method which took characters
|
|
|
|
// directly...
|
|
|
|
tempGlyphs = LE_NEW_ARRAY(LEGlyphID, count);
|
|
|
|
|
|
|
|
if (tempGlyphs == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (le_int32 i = 0; i < count; i += 1) {
|
|
|
|
tempGlyphs[i] = (LEGlyphID) chars[offset + i];
|
|
|
|
}
|
|
|
|
|
|
|
|
adjustMarkGlyphs(tempGlyphs, count, reverse, &filter, positions, success);
|
|
|
|
|
|
|
|
LE_DELETE_ARRAY(tempGlyphs);
|
2000-11-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-21 01:18:44 +00:00
|
|
|
UnicodeArabicOpenTypeLayoutEngine::UnicodeArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode)
|
2000-11-14 21:22:14 +00:00
|
|
|
: ArabicOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode)
|
|
|
|
{
|
2002-04-02 03:33:42 +00:00
|
|
|
switch (scriptCode) {
|
|
|
|
case arabScriptCode:
|
|
|
|
fGSUBTable = (const GlyphSubstitutionTableHeader *) ArabicShaping::glyphSubstitutionTable;
|
|
|
|
fGDEFTable = (const GlyphDefinitionTableHeader *) ArabicShaping::glyphDefinitionTable;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hebrScriptCode:
|
|
|
|
fGSUBTable = (const GlyphSubstitutionTableHeader *) HebrewShaping::glyphSubstitutionTable;
|
|
|
|
fGDEFTable = (const GlyphDefinitionTableHeader *) HebrewShaping::glyphDefinitionTable;
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
|
le_int32 UnicodeArabicOpenTypeLayoutEngine::glyphPostProcessing(LEGlyphID tempGlyphs[], le_int32 tempCharIndices[], le_int32 tempGlyphCount,
|
2000-12-21 01:18:44 +00:00
|
|
|
LEGlyphID *&glyphs, le_int32 *&charIndices, 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 (tempGlyphs == NULL || tempCharIndices == NULL ||tempGlyphCount < 0) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
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.
|
|
|
|
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) {
|
|
|
|
tempChars[i] = (LEUnicode) LE_GET_GLYPH(tempGlyphs[i]);
|
|
|
|
}
|
|
|
|
|
2000-11-14 21:22:14 +00:00
|
|
|
charIndices = tempCharIndices;
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
ArabicOpenTypeLayoutEngine::mapCharsToGlyphs(tempChars, 0, tempGlyphCount, false, true, glyphs, charIndices, success);
|
|
|
|
|
|
|
|
LE_DELETE_ARRAY(tempChars);
|
2000-11-14 21:22:14 +00:00
|
|
|
|
|
|
|
return tempGlyphCount;
|
|
|
|
}
|
|
|
|
|
2000-12-21 01:18:44 +00:00
|
|
|
void UnicodeArabicOpenTypeLayoutEngine::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, le_bool mirror, LEGlyphID *&glyphs, le_int32 *&charIndices, 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
|
|
|
|
2000-11-14 21:22:14 +00:00
|
|
|
le_int32 i, dir, out;
|
|
|
|
|
|
|
|
out = 0;
|
|
|
|
dir = 1;
|
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
out = count - 1;
|
|
|
|
dir = -1;
|
|
|
|
}
|
|
|
|
|
2003-01-07 22:47:19 +00:00
|
|
|
glyphs = LE_NEW_ARRAY(LEGlyphID, count);
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2002-04-02 03:33:42 +00:00
|
|
|
if (glyphs == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2003-01-07 22:47:19 +00:00
|
|
|
charIndices = LE_NEW_ARRAY(le_int32, count);
|
2000-11-14 21:22:14 +00:00
|
|
|
|
2002-04-02 03:33:42 +00:00
|
|
|
if (charIndices == NULL) {
|
2003-01-07 22:47:19 +00:00
|
|
|
LE_DELETE_ARRAY(glyphs);
|
2002-04-02 03:33:42 +00:00
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-12-21 01:18:44 +00:00
|
|
|
|
2000-11-14 21:22:14 +00:00
|
|
|
for (i = 0; i < count; i += 1, out += dir) {
|
|
|
|
glyphs[out] = (LEGlyphID) chars[offset + i];
|
|
|
|
charIndices[out] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnicodeArabicOpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse,
|
2000-12-21 01:18:44 +00:00
|
|
|
LEGlyphID glyphs[], le_int32 glyphCount, float positions[], LEErrorCode &success)
|
2000-11-14 21:22:14 +00:00
|
|
|
{
|
2002-04-02 03:33:42 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chars == NULL || glyphs == NULL || positions == NULL || offset < 0 || count < 0) {
|
|
|
|
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);
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
// FIXME: we could avoid the memory allocation and copying here by
|
|
|
|
// making a clone of the adjustMarkGlyphs method which took characters
|
|
|
|
// directly...
|
|
|
|
LEGlyphID *tempGlyphs = LE_NEW_ARRAY(LEGlyphID, count);
|
|
|
|
|
|
|
|
if (tempGlyphs == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (le_int32 i = 0; i < count; i += 1) {
|
|
|
|
tempGlyphs[i] = (LEGlyphID) chars[offset + i];
|
|
|
|
}
|
|
|
|
|
|
|
|
adjustMarkGlyphs(tempGlyphs, count, reverse, &filter, positions, success);
|
|
|
|
|
|
|
|
LE_DELETE_ARRAY(tempGlyphs);
|
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
|
|
|
|