]> git.saurik.com Git - apple/icu.git/blame - icuSources/layout/LEInsertionList.cpp
ICU-8.11.2.tar.gz
[apple/icu.git] / icuSources / layout / LEInsertionList.cpp
CommitLineData
374ca955
A
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
11U_NAMESPACE_BEGIN
12
13#define ANY_NUMBER 1
14
15struct InsertionRecord
16{
17 InsertionRecord *next;
18 le_int32 position;
19 le_int32 count;
20 LEGlyphID glyphs[ANY_NUMBER];
21};
22
23UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LEInsertionList)
24
25LEInsertionList::LEInsertionList(le_bool rightToLeft)
26: head(NULL), tail(NULL), growAmount(0), append(rightToLeft)
27{
28 tail = (InsertionRecord *) &head;
29}
30
31LEInsertionList::~LEInsertionList()
32{
33 reset();
34}
35
36void 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
49le_int32 LEInsertionList::getGrowAmount()
50{
51 return growAmount;
52}
53
54LEGlyphID *LEInsertionList::insert(le_int32 position, le_int32 count)
55{
56 InsertionRecord *insertion = (InsertionRecord *) LE_NEW_ARRAY(char, sizeof(InsertionRecord) + (count - ANY_NUMBER) * sizeof (LEGlyphID));
57
58 insertion->position = position;
59 insertion->count = count;
60
61 growAmount += count - 1;
62
63 if (append) {
64 // insert on end of list...
65 insertion->next = NULL;
66 tail->next = insertion;
67 tail = insertion;
68 } else {
69 // insert on front of list...
70 insertion->next = head;
71 head = insertion;
72 }
73
74 return insertion->glyphs;
75}
76
77le_bool LEInsertionList::applyInsertions(LEInsertionCallback *callback)
78{
79 for (InsertionRecord *rec = head; rec != NULL; rec = rec->next) {
80 if (callback->applyInsertion(rec->position, rec->count, rec->glyphs)) {
81 return TRUE;
82 }
83 }
84
85 return FALSE;
86}
87
88U_NAMESPACE_END