2004-04-12 18:51:31 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2008-10-28 14:50:15 +00:00
|
|
|
* Copyright (C) 1998-2008, International Business Machines
|
2004-04-12 18:51:31 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "LEInsertionList.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
#define ANY_NUMBER 1
|
|
|
|
|
|
|
|
struct InsertionRecord
|
|
|
|
{
|
2004-05-07 23:29:16 +00:00
|
|
|
InsertionRecord *next;
|
|
|
|
le_int32 position;
|
|
|
|
le_int32 count;
|
|
|
|
LEGlyphID glyphs[ANY_NUMBER];
|
2004-04-12 18:51:31 +00:00
|
|
|
};
|
|
|
|
|
2004-10-19 06:25:41 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LEInsertionList)
|
2004-04-12 18:51:31 +00:00
|
|
|
|
|
|
|
LEInsertionList::LEInsertionList(le_bool rightToLeft)
|
|
|
|
: head(NULL), tail(NULL), growAmount(0), append(rightToLeft)
|
|
|
|
{
|
2004-05-07 23:29:16 +00:00
|
|
|
tail = (InsertionRecord *) &head;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LEInsertionList::~LEInsertionList()
|
|
|
|
{
|
2004-05-07 23:29:16 +00:00
|
|
|
reset();
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEInsertionList::reset()
|
|
|
|
{
|
2004-05-07 23:29:16 +00:00
|
|
|
while (head != NULL) {
|
|
|
|
InsertionRecord *record = head;
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
head = head->next;
|
|
|
|
LE_DELETE_ARRAY(record);
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
tail = (InsertionRecord *) &head;
|
|
|
|
growAmount = 0;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
le_int32 LEInsertionList::getGrowAmount()
|
|
|
|
{
|
2004-05-07 23:29:16 +00:00
|
|
|
return growAmount;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
2008-10-28 14:50:15 +00:00
|
|
|
LEGlyphID *LEInsertionList::insert(le_int32 position, le_int32 count, LEErrorCode &success)
|
2004-04-12 18:51:31 +00:00
|
|
|
{
|
2008-10-28 14:50:15 +00:00
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
InsertionRecord *insertion = (InsertionRecord *) LE_NEW_ARRAY(char, sizeof(InsertionRecord) + (count - ANY_NUMBER) * sizeof (LEGlyphID));
|
2008-10-28 14:50:15 +00:00
|
|
|
if (insertion == NULL) {
|
|
|
|
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
insertion->position = position;
|
|
|
|
insertion->count = count;
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
growAmount += count - 1;
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
if (append) {
|
|
|
|
// insert on end of list...
|
|
|
|
insertion->next = NULL;
|
|
|
|
tail->next = insertion;
|
|
|
|
tail = insertion;
|
|
|
|
} else {
|
|
|
|
// insert on front of list...
|
|
|
|
insertion->next = head;
|
|
|
|
head = insertion;
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
return insertion->glyphs;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
le_bool LEInsertionList::applyInsertions(LEInsertionCallback *callback)
|
|
|
|
{
|
2004-05-07 23:29:16 +00:00
|
|
|
for (InsertionRecord *rec = head; rec != NULL; rec = rec->next) {
|
|
|
|
if (callback->applyInsertion(rec->position, rec->count, rec->glyphs)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
return FALSE;
|
2004-04-12 18:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|