2004-04-12 18:51:31 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2009-03-02 23:35:48 +00:00
|
|
|
* Copyright (C) 1998-2009, International Business Machines
|
2004-04-12 18:51:31 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "LEInsertionList.h"
|
|
|
|
#include "LEGlyphStorage.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2004-10-19 06:25:41 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LEGlyphStorage)
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2006-03-18 01:09:27 +00:00
|
|
|
LEInsertionCallback::~LEInsertionCallback()
|
|
|
|
{
|
|
|
|
// nothing to do...
|
|
|
|
}
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
LEGlyphStorage::LEGlyphStorage()
|
|
|
|
: fGlyphCount(0), fGlyphs(NULL), fCharIndices(NULL), fPositions(NULL),
|
|
|
|
fAuxData(NULL), fInsertionList(NULL), fSrcIndex(0), fDestIndex(0)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
// nothing else to do!
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LEGlyphStorage::~LEGlyphStorage()
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
reset();
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::reset()
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
fGlyphCount = 0;
|
|
|
|
|
|
|
|
if (fPositions != NULL) {
|
|
|
|
LE_DELETE_ARRAY(fPositions);
|
|
|
|
fPositions = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fAuxData != NULL) {
|
|
|
|
LE_DELETE_ARRAY(fAuxData);
|
|
|
|
fAuxData = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fInsertionList != NULL) {
|
|
|
|
delete fInsertionList;
|
|
|
|
fInsertionList = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fCharIndices != NULL) {
|
|
|
|
LE_DELETE_ARRAY(fCharIndices);
|
|
|
|
fCharIndices = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fGlyphs != NULL) {
|
|
|
|
LE_DELETE_ARRAY(fGlyphs);
|
|
|
|
fGlyphs = NULL;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This might get called more than once, for various reasons. Is
|
|
|
|
// testing for pre-existing glyph and charIndices arrays good enough?
|
|
|
|
void LEGlyphStorage::allocateGlyphArray(le_int32 initialGlyphCount, le_bool rightToLeft, LEErrorCode &success)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initialGlyphCount <= 0) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fGlyphs == NULL) {
|
|
|
|
fGlyphCount = initialGlyphCount;
|
|
|
|
fGlyphs = LE_NEW_ARRAY(LEGlyphID, fGlyphCount);
|
|
|
|
|
|
|
|
if (fGlyphs == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fCharIndices == NULL) {
|
|
|
|
fCharIndices = LE_NEW_ARRAY(le_int32, fGlyphCount);
|
|
|
|
|
|
|
|
if (fCharIndices == NULL) {
|
|
|
|
LE_DELETE_ARRAY(fGlyphs);
|
|
|
|
fGlyphs = NULL;
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the charIndices array
|
|
|
|
le_int32 i, count = fGlyphCount, dir = 1, out = 0;
|
|
|
|
|
|
|
|
if (rightToLeft) {
|
|
|
|
out = fGlyphCount - 1;
|
|
|
|
dir = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i += 1, out += dir) {
|
|
|
|
fCharIndices[out] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fInsertionList == NULL) {
|
|
|
|
// FIXME: check this for failure?
|
|
|
|
fInsertionList = new LEInsertionList(rightToLeft);
|
2008-10-28 14:50:15 +00:00
|
|
|
if (fInsertionList == NULL) {
|
|
|
|
LE_DELETE_ARRAY(fCharIndices);
|
|
|
|
fCharIndices = NULL;
|
|
|
|
|
|
|
|
LE_DELETE_ARRAY(fGlyphs);
|
|
|
|
fGlyphs = NULL;
|
|
|
|
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2004-05-03 21:13:13 +00:00
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: do we want to initialize the positions to [0, 0]?
|
|
|
|
le_int32 LEGlyphStorage::allocatePositions(LEErrorCode &success)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2006-07-31 20:50:52 +00:00
|
|
|
if (fPositions != NULL) {
|
|
|
|
success = LE_INTERNAL_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fPositions = LE_NEW_ARRAY(float, 2 * (fGlyphCount + 1));
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fPositions == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
return fGlyphCount;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: do we want to initialize the aux data to NULL?
|
|
|
|
le_int32 LEGlyphStorage::allocateAuxData(LEErrorCode &success)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2006-07-31 20:50:52 +00:00
|
|
|
if (fAuxData != NULL) {
|
|
|
|
success = LE_INTERNAL_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
fAuxData = LE_NEW_ARRAY(le_uint32, fGlyphCount);
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fAuxData == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
return fGlyphCount;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::getCharIndices(le_int32 charIndices[], le_int32 indexBase, LEErrorCode &success) const
|
|
|
|
{
|
|
|
|
le_int32 i;
|
|
|
|
|
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (charIndices == NULL) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fCharIndices == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < fGlyphCount; i += 1) {
|
|
|
|
charIndices[i] = fCharIndices[i] + indexBase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::getCharIndices(le_int32 charIndices[], LEErrorCode &success) const
|
|
|
|
{
|
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (charIndices == NULL) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fCharIndices == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LE_ARRAY_COPY(charIndices, fCharIndices, fGlyphCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the glyphs into caller's (32-bit) glyph array, OR in extraBits
|
|
|
|
void LEGlyphStorage::getGlyphs(le_uint32 glyphs[], le_uint32 extraBits, LEErrorCode &success) const
|
|
|
|
{
|
|
|
|
le_int32 i;
|
|
|
|
|
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glyphs == NULL) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fGlyphs == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < fGlyphCount; i += 1) {
|
|
|
|
glyphs[i] = fGlyphs[i] | extraBits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::getGlyphs(LEGlyphID glyphs[], LEErrorCode &success) const
|
|
|
|
{
|
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glyphs == NULL) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fGlyphs == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
2004-05-03 21:13:13 +00:00
|
|
|
return;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LE_ARRAY_COPY(glyphs, fGlyphs, fGlyphCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
LEGlyphID LEGlyphStorage::getGlyphID(le_int32 glyphIndex, LEErrorCode &success) const
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return 0xFFFF;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fGlyphs == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return 0xFFFF;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (glyphIndex < 0 || glyphIndex >= fGlyphCount) {
|
|
|
|
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
|
|
|
return 0xFFFF;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
return fGlyphs[glyphIndex];
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::setGlyphID(le_int32 glyphIndex, LEGlyphID glyphID, LEErrorCode &success)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fGlyphs == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (glyphIndex < 0 || glyphIndex >= fGlyphCount) {
|
|
|
|
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fGlyphs[glyphIndex] = glyphID;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
le_int32 LEGlyphStorage::getCharIndex(le_int32 glyphIndex, LEErrorCode &success) const
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fCharIndices == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (glyphIndex < 0 || glyphIndex >= fGlyphCount) {
|
|
|
|
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
return fCharIndices[glyphIndex];
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::setCharIndex(le_int32 glyphIndex, le_int32 charIndex, LEErrorCode &success)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fCharIndices == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (glyphIndex < 0 || glyphIndex >= fGlyphCount) {
|
|
|
|
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fCharIndices[glyphIndex] = charIndex;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
void LEGlyphStorage::getAuxData(le_uint32 auxData[], LEErrorCode &success) const
|
2004-04-12 18:51:31 +00:00
|
|
|
{
|
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auxData == NULL) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fAuxData == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
2004-05-03 21:13:13 +00:00
|
|
|
return;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LE_ARRAY_COPY(auxData, fAuxData, fGlyphCount);
|
|
|
|
}
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
le_uint32 LEGlyphStorage::getAuxData(le_int32 glyphIndex, LEErrorCode &success) const
|
2004-04-12 18:51:31 +00:00
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
2005-08-08 18:15:29 +00:00
|
|
|
return 0;
|
2004-05-03 21:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fAuxData == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
2005-08-08 18:15:29 +00:00
|
|
|
return 0;
|
2004-05-03 21:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (glyphIndex < 0 || glyphIndex >= fGlyphCount) {
|
|
|
|
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
2005-08-08 18:15:29 +00:00
|
|
|
return 0;
|
2004-05-03 21:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fAuxData[glyphIndex];
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
void LEGlyphStorage::setAuxData(le_int32 glyphIndex, le_uint32 auxData, LEErrorCode &success)
|
2004-04-12 18:51:31 +00:00
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fAuxData == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (glyphIndex < 0 || glyphIndex >= fGlyphCount) {
|
|
|
|
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fAuxData[glyphIndex] = auxData;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::getGlyphPositions(float positions[], LEErrorCode &success) const
|
|
|
|
{
|
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (positions == NULL) {
|
|
|
|
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fPositions == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LE_ARRAY_COPY(positions, fPositions, fGlyphCount * 2 + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::getGlyphPosition(le_int32 glyphIndex, float &x, float &y, LEErrorCode &success) const
|
|
|
|
{
|
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glyphIndex < 0 || glyphIndex > fGlyphCount) {
|
|
|
|
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fPositions == NULL) {
|
|
|
|
success = LE_NO_LAYOUT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = fPositions[glyphIndex * 2];
|
|
|
|
y = fPositions[glyphIndex * 2 + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::setPosition(le_int32 glyphIndex, float x, float y, LEErrorCode &success)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
if (glyphIndex < 0 || glyphIndex > fGlyphCount) {
|
|
|
|
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fPositions[glyphIndex * 2] = x;
|
|
|
|
fPositions[glyphIndex * 2 + 1] = y;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::adjustPosition(le_int32 glyphIndex, float xAdjust, float yAdjust, LEErrorCode &success)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
if (glyphIndex < 0 || glyphIndex > fGlyphCount) {
|
|
|
|
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fPositions[glyphIndex * 2] += xAdjust;
|
|
|
|
fPositions[glyphIndex * 2 + 1] += yAdjust;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::adoptGlyphArray(LEGlyphStorage &from)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fGlyphs != NULL) {
|
|
|
|
LE_DELETE_ARRAY(fGlyphs);
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fGlyphs = from.fGlyphs;
|
|
|
|
from.fGlyphs = NULL;
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fInsertionList != NULL) {
|
|
|
|
delete fInsertionList;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fInsertionList = from.fInsertionList;
|
|
|
|
from.fInsertionList = NULL;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::adoptCharIndicesArray(LEGlyphStorage &from)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fCharIndices != NULL) {
|
|
|
|
LE_DELETE_ARRAY(fCharIndices);
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fCharIndices = from.fCharIndices;
|
|
|
|
from.fCharIndices = NULL;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::adoptPositionArray(LEGlyphStorage &from)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fPositions != NULL) {
|
|
|
|
LE_DELETE_ARRAY(fPositions);
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fPositions = from.fPositions;
|
|
|
|
from.fPositions = NULL;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::adoptAuxDataArray(LEGlyphStorage &from)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fAuxData != NULL) {
|
|
|
|
LE_DELETE_ARRAY(fAuxData);
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fAuxData = from.fAuxData;
|
|
|
|
from.fAuxData = NULL;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::adoptGlyphCount(LEGlyphStorage &from)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
fGlyphCount = from.fGlyphCount;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGlyphStorage::adoptGlyphCount(le_int32 newGlyphCount)
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
fGlyphCount = newGlyphCount;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
2009-03-02 23:35:48 +00:00
|
|
|
// Move a glyph to a different position in the LEGlyphStorage ( used for Indic v2 processing )
|
|
|
|
|
|
|
|
void LEGlyphStorage::moveGlyph(le_int32 fromPosition, le_int32 toPosition, le_uint32 marker )
|
|
|
|
{
|
|
|
|
|
|
|
|
LEErrorCode success = LE_NO_ERROR;
|
|
|
|
|
|
|
|
LEGlyphID holdGlyph = getGlyphID(fromPosition,success);
|
|
|
|
le_int32 holdCharIndex = getCharIndex(fromPosition,success);
|
|
|
|
le_uint32 holdAuxData = getAuxData(fromPosition,success);
|
|
|
|
|
|
|
|
if ( fromPosition < toPosition ) {
|
|
|
|
for ( le_int32 i = fromPosition ; i < toPosition ; i++ ) {
|
|
|
|
setGlyphID(i,getGlyphID(i+1,success),success);
|
|
|
|
setCharIndex(i,getCharIndex(i+1,success),success);
|
|
|
|
setAuxData(i,getAuxData(i+1,success),success);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for ( le_int32 i = toPosition ; i > fromPosition ; i-- ) {
|
|
|
|
setGlyphID(i,getGlyphID(i-1,success),success);
|
|
|
|
setCharIndex(i,getCharIndex(i-1,success),success);
|
|
|
|
setAuxData(i,getAuxData(i-1,success),success);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setGlyphID(toPosition,holdGlyph,success);
|
|
|
|
setCharIndex(toPosition,holdCharIndex,success);
|
|
|
|
setAuxData(toPosition,holdAuxData | marker,success);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-03-19 01:34:04 +00:00
|
|
|
// Glue code for existing stable API
|
|
|
|
LEGlyphID *LEGlyphStorage::insertGlyphs(le_int32 atIndex, le_int32 insertCount)
|
|
|
|
{
|
|
|
|
LEErrorCode ignored = LE_NO_LAYOUT_ERROR;
|
|
|
|
return insertGlyphs(atIndex, insertCount, ignored);
|
|
|
|
}
|
2009-03-02 23:35:48 +00:00
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
// FIXME: add error checking?
|
2008-10-28 14:50:15 +00:00
|
|
|
LEGlyphID *LEGlyphStorage::insertGlyphs(le_int32 atIndex, le_int32 insertCount, LEErrorCode& success)
|
2004-04-12 18:51:31 +00:00
|
|
|
{
|
2008-10-28 14:50:15 +00:00
|
|
|
return fInsertionList->insert(atIndex, insertCount, success);
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
le_int32 LEGlyphStorage::applyInsertions()
|
|
|
|
{
|
2004-05-03 21:13:13 +00:00
|
|
|
le_int32 growAmount = fInsertionList->getGrowAmount();
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (growAmount == 0) {
|
|
|
|
return fGlyphCount;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
le_int32 newGlyphCount = fGlyphCount + growAmount;
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2008-10-28 14:50:15 +00:00
|
|
|
LEGlyphID *newGlyphs = (LEGlyphID *) LE_GROW_ARRAY(fGlyphs, newGlyphCount);
|
|
|
|
if (newGlyphs == NULL) {
|
|
|
|
// Could not grow the glyph array
|
|
|
|
return fGlyphCount;
|
|
|
|
}
|
2009-06-11 22:08:54 +00:00
|
|
|
fGlyphs = newGlyphs;
|
2008-10-28 14:50:15 +00:00
|
|
|
|
|
|
|
le_int32 *newCharIndices = (le_int32 *) LE_GROW_ARRAY(fCharIndices, newGlyphCount);
|
|
|
|
if (newCharIndices == NULL) {
|
|
|
|
// Could not grow the glyph array
|
|
|
|
return fGlyphCount;
|
|
|
|
}
|
2009-06-11 22:08:54 +00:00
|
|
|
fCharIndices = newCharIndices;
|
2008-10-28 14:50:15 +00:00
|
|
|
|
|
|
|
if (fAuxData != NULL) {
|
|
|
|
le_uint32 *newAuxData = (le_uint32 *) LE_GROW_ARRAY(fAuxData, newGlyphCount);
|
|
|
|
if (newAuxData == NULL) {
|
|
|
|
// could not grow the aux data array
|
|
|
|
return fGlyphCount;
|
|
|
|
}
|
|
|
|
fAuxData = (le_uint32 *)newAuxData;
|
|
|
|
}
|
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fSrcIndex = fGlyphCount - 1;
|
|
|
|
fDestIndex = newGlyphCount - 1;
|
2004-04-12 18:51:31 +00:00
|
|
|
|
|
|
|
#if 0
|
2004-05-03 21:13:13 +00:00
|
|
|
// If the current position is at the end of the array
|
|
|
|
// update it to point to the end of the new array. The
|
|
|
|
// insertion callback will handle all other cases.
|
2004-04-12 18:51:31 +00:00
|
|
|
// FIXME: this is left over from GlyphIterator, but there's no easy
|
2004-05-03 21:13:13 +00:00
|
|
|
// way to implement this here... it seems that GlyphIterator doesn't
|
|
|
|
// really need it 'cause the insertions don't get applied until after a
|
|
|
|
// complete pass over the glyphs, after which the iterator gets reset anyhow...
|
|
|
|
// probably better to just document that for LEGlyphStorage and GlyphIterator...
|
|
|
|
if (position == glyphCount) {
|
|
|
|
position = newGlyphCount;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
#endif
|
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fInsertionList->applyInsertions(this);
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fInsertionList->reset();
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
return fGlyphCount = newGlyphCount;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
le_bool LEGlyphStorage::applyInsertion(le_int32 atPosition, le_int32 count, LEGlyphID newGlyphs[])
|
|
|
|
{
|
|
|
|
#if 0
|
2004-05-03 21:13:13 +00:00
|
|
|
// if the current position is within the block we're shifting
|
|
|
|
// it needs to be updated to the current glyph's
|
|
|
|
// new location.
|
2004-04-12 18:51:31 +00:00
|
|
|
// FIXME: this is left over from GlyphIterator, but there's no easy
|
2004-05-03 21:13:13 +00:00
|
|
|
// way to implement this here... it seems that GlyphIterator doesn't
|
|
|
|
// really need it 'cause the insertions don't get applied until after a
|
|
|
|
// complete pass over the glyphs, after which the iterator gets reset anyhow...
|
|
|
|
// probably better to just document that for LEGlyphStorage and GlyphIterator...
|
|
|
|
if (position >= atPosition && position <= fSrcIndex) {
|
|
|
|
position += fDestIndex - fSrcIndex;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
#endif
|
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
if (fAuxData != NULL) {
|
|
|
|
le_int32 src = fSrcIndex, dest = fDestIndex;
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
while (src > atPosition) {
|
|
|
|
fAuxData[dest--] = fAuxData[src--];
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
for (le_int32 i = count - 1; i >= 0; i -= 1) {
|
|
|
|
fAuxData[dest--] = fAuxData[atPosition];
|
|
|
|
}
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
while (fSrcIndex > atPosition) {
|
|
|
|
fGlyphs[fDestIndex] = fGlyphs[fSrcIndex];
|
|
|
|
fCharIndices[fDestIndex] = fCharIndices[fSrcIndex];
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fDestIndex -= 1;
|
|
|
|
fSrcIndex -= 1;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
for (le_int32 i = count - 1; i >= 0; i -= 1) {
|
|
|
|
fGlyphs[fDestIndex] = newGlyphs[i];
|
|
|
|
fCharIndices[fDestIndex] = fCharIndices[atPosition];
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
fDestIndex -= 1;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
// the source glyph we're pointing at
|
|
|
|
// just got replaced by the insertion
|
|
|
|
fSrcIndex -= 1;
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-03 21:13:13 +00:00
|
|
|
return FALSE;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|