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