LEInsertionList.cpp revision ac04d0bbe12b3ef54518635711412f178cb4d16
1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************** 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Copyright (C) 1998-2004, International Business Machines 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Corporation and others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************** 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LETypes.h" 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LEInsertionList.h" 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define ANY_NUMBER 1 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct InsertionRecord 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru InsertionRecord *next; 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_int32 position; 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_int32 count; 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LEGlyphID glyphs[ANY_NUMBER]; 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUOBJECT_DEFINE_RTTI_IMPLEMENTATION(LEInsertionList) 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLEInsertionList::LEInsertionList(le_bool rightToLeft) 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru: head(NULL), tail(NULL), growAmount(0), append(rightToLeft) 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tail = (InsertionRecord *) &head; 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLEInsertionList::~LEInsertionList() 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru reset(); 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LEInsertionList::reset() 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while (head != NULL) { 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru InsertionRecord *record = head; 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru head = head->next; 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LE_DELETE_ARRAY(record); 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tail = (InsertionRecord *) &head; 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru growAmount = 0; 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querule_int32 LEInsertionList::getGrowAmount() 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return growAmount; 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLEGlyphID *LEInsertionList::insert(le_int32 position, le_int32 count) 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru InsertionRecord *insertion = (InsertionRecord *) LE_NEW_ARRAY(char, sizeof(InsertionRecord) + (count - ANY_NUMBER) * sizeof (LEGlyphID)); 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru insertion->position = position; 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru insertion->count = count; 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru growAmount += count - 1; 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (append) { 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // insert on end of list... 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru insertion->next = NULL; 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tail->next = insertion; 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tail = insertion; 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // insert on front of list... 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru insertion->next = head; 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru head = insertion; 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return insertion->glyphs; 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querule_bool LEInsertionList::applyInsertions(LEInsertionCallback *callback) 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (InsertionRecord *rec = head; rec != NULL; rec = rec->next) { 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (callback->applyInsertion(rec->position, rec->count, rec->glyphs)) { 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return TRUE; 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return FALSE; 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 89