os/textandloc/fontservices/textshaperplugin/IcuSource/layout/LEInsertionList.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/LEInsertionList.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,98 @@
     1.4 +/*
     1.5 + **********************************************************************
     1.6 + *   Copyright (C) 1998-2004, International Business Machines
     1.7 + *   Corporation and others.  All Rights Reserved.
     1.8 + **********************************************************************
     1.9 + */
    1.10 +
    1.11 +#include "LETypes.h"
    1.12 +#include "LEInsertionList.h"
    1.13 +
    1.14 +U_NAMESPACE_BEGIN
    1.15 +
    1.16 +#define ANY_NUMBER 1
    1.17 +
    1.18 +struct InsertionRecord
    1.19 +{
    1.20 +    InsertionRecord *next;
    1.21 +    le_int32 position;
    1.22 +    le_int32 count;
    1.23 +    LEGlyphID glyphs[ANY_NUMBER];
    1.24 +};
    1.25 +
    1.26 +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LEInsertionList)
    1.27 +
    1.28 +LEInsertionList::LEInsertionList(le_bool rightToLeft)
    1.29 +: head(NULL), tail(NULL), growAmount(0), append(rightToLeft)
    1.30 +{
    1.31 +    tail = (InsertionRecord *) &head;
    1.32 +}
    1.33 +
    1.34 +LEInsertionList::~LEInsertionList()
    1.35 +{
    1.36 +    reset();
    1.37 +}
    1.38 +
    1.39 +void LEInsertionList::reset()
    1.40 +{
    1.41 +    while (head != NULL) {
    1.42 +        InsertionRecord *record = head;
    1.43 +
    1.44 +        head = head->next;
    1.45 +        LE_DELETE_ARRAY(record);
    1.46 +    }
    1.47 +
    1.48 +    tail = (InsertionRecord *) &head;
    1.49 +    growAmount = 0;
    1.50 +}
    1.51 +
    1.52 +le_int32 LEInsertionList::getGrowAmount()
    1.53 +{
    1.54 +    return growAmount;
    1.55 +}
    1.56 +
    1.57 +LEGlyphID *LEInsertionList::insert(le_int32 position, le_int32 count,
    1.58 +    LEErrorCode &success)
    1.59 +{
    1.60 +    if (LE_FAILURE(success)) {
    1.61 +        return 0;
    1.62 +    }
    1.63 +
    1.64 +    InsertionRecord *insertion = (InsertionRecord *) LE_NEW_ARRAY(char, sizeof(InsertionRecord) + (count - ANY_NUMBER) * sizeof (LEGlyphID));
    1.65 +
    1.66 +    if (!insertion) {
    1.67 +    	success = LE_MEMORY_ALLOCATION_ERROR;
    1.68 +        return 0;
    1.69 +    }
    1.70 +
    1.71 +    insertion->position = position;
    1.72 +    insertion->count = count;
    1.73 +
    1.74 +    growAmount += count - 1;
    1.75 +
    1.76 +    if (append) {
    1.77 +        // insert on end of list...
    1.78 +        insertion->next = NULL;
    1.79 +        tail->next = insertion;
    1.80 +        tail = insertion;
    1.81 +    } else {
    1.82 +        // insert on front of list...
    1.83 +        insertion->next = head;
    1.84 +        head = insertion;
    1.85 +    }
    1.86 +
    1.87 +    return insertion->glyphs;
    1.88 +}
    1.89 +
    1.90 +le_bool LEInsertionList::applyInsertions(LEInsertionCallback *callback)
    1.91 +{
    1.92 +    for (InsertionRecord *rec = head; rec != NULL; rec = rec->next) {
    1.93 +        if (callback->applyInsertion(rec->position, rec->count, rec->glyphs)) {
    1.94 +            return TRUE;
    1.95 +        }
    1.96 +    }
    1.97 +
    1.98 +    return FALSE;
    1.99 +}
   1.100 +
   1.101 +U_NAMESPACE_END