2
|
1 |
/*
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
3 |
*
|
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
|
6 |
* published by the Free Software Foundation. Sun designates this
|
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
|
8 |
* by Sun in the LICENSE file that accompanied this code.
|
|
9 |
*
|
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
*
|
|
20 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
21 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
22 |
* have any questions.
|
|
23 |
*
|
|
24 |
*/
|
|
25 |
|
|
26 |
/*
|
|
27 |
*
|
|
28 |
**********************************************************************
|
|
29 |
* Copyright (C) 1998-2004, International Business Machines
|
|
30 |
* Corporation and others. All Rights Reserved.
|
|
31 |
**********************************************************************
|
|
32 |
*/
|
|
33 |
|
|
34 |
#include "LETypes.h"
|
|
35 |
#include "LEInsertionList.h"
|
|
36 |
|
|
37 |
#define ANY_NUMBER 1
|
|
38 |
|
|
39 |
struct InsertionRecord
|
|
40 |
{
|
|
41 |
InsertionRecord *next;
|
|
42 |
le_int32 position;
|
|
43 |
le_int32 count;
|
|
44 |
LEGlyphID glyphs[ANY_NUMBER];
|
|
45 |
};
|
|
46 |
|
|
47 |
LEInsertionList::LEInsertionList(le_bool rightToLeft)
|
|
48 |
: head(NULL), tail(NULL), growAmount(0), append(rightToLeft)
|
|
49 |
{
|
|
50 |
tail = (InsertionRecord *) &head;
|
|
51 |
}
|
|
52 |
|
|
53 |
LEInsertionList::~LEInsertionList()
|
|
54 |
{
|
|
55 |
reset();
|
|
56 |
}
|
|
57 |
|
|
58 |
void LEInsertionList::reset()
|
|
59 |
{
|
|
60 |
while (head != NULL) {
|
|
61 |
InsertionRecord *record = head;
|
|
62 |
|
|
63 |
head = head->next;
|
|
64 |
LE_DELETE_ARRAY(record);
|
|
65 |
}
|
|
66 |
|
|
67 |
tail = (InsertionRecord *) &head;
|
|
68 |
growAmount = 0;
|
|
69 |
}
|
|
70 |
|
|
71 |
le_int32 LEInsertionList::getGrowAmount()
|
|
72 |
{
|
|
73 |
return growAmount;
|
|
74 |
}
|
|
75 |
|
|
76 |
LEGlyphID *LEInsertionList::insert(le_int32 position, le_int32 count)
|
|
77 |
{
|
|
78 |
InsertionRecord *insertion = (InsertionRecord *) LE_NEW_ARRAY(char, sizeof(InsertionRecord) + (count - ANY_NUMBER) * sizeof (LEGlyphID));
|
|
79 |
|
|
80 |
insertion->position = position;
|
|
81 |
insertion->count = count;
|
|
82 |
|
|
83 |
growAmount += count - 1;
|
|
84 |
|
|
85 |
if (append) {
|
|
86 |
// insert on end of list...
|
|
87 |
insertion->next = NULL;
|
|
88 |
tail->next = insertion;
|
|
89 |
tail = insertion;
|
|
90 |
} else {
|
|
91 |
// insert on front of list...
|
|
92 |
insertion->next = head;
|
|
93 |
head = insertion;
|
|
94 |
}
|
|
95 |
|
|
96 |
return insertion->glyphs;
|
|
97 |
}
|
|
98 |
|
|
99 |
le_bool LEInsertionList::applyInsertions(LEInsertionCallback *callback)
|
|
100 |
{
|
|
101 |
for (InsertionRecord *rec = head; rec != NULL; rec = rec->next) {
|
|
102 |
if (callback->applyInsertion(rec->position, rec->count, rec->glyphs)) {
|
|
103 |
return TRUE;
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
return FALSE;
|
|
108 |
}
|