1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************** 385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (C) 1998-2008, 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 5485bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoLEGlyphID *LEInsertionList::insert(le_int32 position, le_int32 count, LEErrorCode &success) 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 5685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (LE_FAILURE(success)) { 5785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return 0; 5885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 5985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru InsertionRecord *insertion = (InsertionRecord *) LE_NEW_ARRAY(char, sizeof(InsertionRecord) + (count - ANY_NUMBER) * sizeof (LEGlyphID)); 6185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (insertion == NULL) { 6285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho success = LE_MEMORY_ALLOCATION_ERROR; 6385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return 0; 6485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru insertion->position = position; 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru insertion->count = count; 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru growAmount += count - 1; 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (append) { 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // insert on end of list... 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru insertion->next = NULL; 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tail->next = insertion; 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tail = insertion; 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // insert on front of list... 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru insertion->next = head; 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru head = insertion; 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return insertion->glyphs; 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querule_bool LEInsertionList::applyInsertions(LEInsertionCallback *callback) 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (InsertionRecord *rec = head; rec != NULL; rec = rec->next) { 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (callback->applyInsertion(rec->position, rec->count, rec->glyphs)) { 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return TRUE; 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return FALSE; 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 97