os/textandloc/fontservices/textshaperplugin/IcuSource/layout/LEGlyphStorage.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 **********************************************************************
sl@0
     3
 *   Copyright (C) 1998-2005, International Business Machines
sl@0
     4
 *   Corporation and others.  All Rights Reserved.
sl@0
     5
 **********************************************************************
sl@0
     6
 */
sl@0
     7
sl@0
     8
#ifndef __LEGLYPHSTORAGE_H
sl@0
     9
#define __LEGLYPHSTORAGE_H
sl@0
    10
sl@0
    11
#include "LETypes.h"
sl@0
    12
#include "LEInsertionList.h"
sl@0
    13
sl@0
    14
/**
sl@0
    15
 * \file 
sl@0
    16
 * \brief C++ API: This class encapsulates the per-glyph storage used by the ICU LayoutEngine.
sl@0
    17
 */
sl@0
    18
sl@0
    19
U_NAMESPACE_BEGIN
sl@0
    20
sl@0
    21
/**
sl@0
    22
 * This class encapsulates the per-glyph storage used by the ICU LayoutEngine.
sl@0
    23
 * For each glyph it holds the glyph ID, the index of the backing store character
sl@0
    24
 * which produced the glyph, the X and Y position of the glyph and an auxillary data
sl@0
    25
 * pointer.
sl@0
    26
 *
sl@0
    27
 * The storage is growable using the <code>LEInsertionList</code> class.
sl@0
    28
 *
sl@0
    29
 *
sl@0
    30
 * @see LEInsertionList.h
sl@0
    31
 *
sl@0
    32
 * @draft ICU 3.0
sl@0
    33
 */
sl@0
    34
class U_LAYOUT_API LEGlyphStorage : public UObject, protected LEInsertionCallback
sl@0
    35
{
sl@0
    36
private:
sl@0
    37
    /**
sl@0
    38
     * The number of entries in the per-glyph arrays.
sl@0
    39
     *
sl@0
    40
     * @internal
sl@0
    41
     */
sl@0
    42
    le_int32   fGlyphCount;
sl@0
    43
sl@0
    44
    /**
sl@0
    45
     * The glyph ID array.
sl@0
    46
     *
sl@0
    47
     * @internal
sl@0
    48
     */
sl@0
    49
    LEGlyphID *fGlyphs;
sl@0
    50
 
sl@0
    51
    /**
sl@0
    52
     * The char indices array.
sl@0
    53
     *
sl@0
    54
     * @internal
sl@0
    55
     */
sl@0
    56
    le_int32  *fCharIndices;
sl@0
    57
sl@0
    58
    /**
sl@0
    59
     * The glyph positions array.
sl@0
    60
     *
sl@0
    61
     * @internal
sl@0
    62
     */
sl@0
    63
    float     *fPositions;
sl@0
    64
sl@0
    65
    /**
sl@0
    66
     * The auxillary data array.
sl@0
    67
     *
sl@0
    68
     * @internal
sl@0
    69
     */
sl@0
    70
    void     **fAuxData;
sl@0
    71
sl@0
    72
sl@0
    73
    /**
sl@0
    74
     * The insertion list, used to grow the above arrays.
sl@0
    75
     *
sl@0
    76
     * @internal
sl@0
    77
     */
sl@0
    78
    LEInsertionList *fInsertionList;
sl@0
    79
sl@0
    80
    /**
sl@0
    81
     * The source index while growing the data arrays.
sl@0
    82
     *
sl@0
    83
     * @internal
sl@0
    84
     */
sl@0
    85
    le_int32 fSrcIndex;
sl@0
    86
sl@0
    87
    /**
sl@0
    88
     * The destination index used while growing the data arrays.
sl@0
    89
     *
sl@0
    90
     * @internal
sl@0
    91
     */
sl@0
    92
    le_int32 fDestIndex;
sl@0
    93
sl@0
    94
protected:
sl@0
    95
    /**
sl@0
    96
     * This implements <code>LEInsertionCallback</code>. The <code>LEInsertionList</code>
sl@0
    97
     * will call this method once for each insertion.
sl@0
    98
     *
sl@0
    99
     * @param atPosition the position of the insertion
sl@0
   100
     * @param count the number of glyphs being inserted
sl@0
   101
     * @param newGlyphs the address of the new glyph IDs
sl@0
   102
     *
sl@0
   103
     * @return <code>true</code> if <code>LEInsertionList</code> should stop
sl@0
   104
     *         processing the insertion list after this insertion.
sl@0
   105
     *
sl@0
   106
     * @see LEInsertionList.h
sl@0
   107
     *
sl@0
   108
     * @draft ICU 3.0
sl@0
   109
     */
sl@0
   110
    virtual le_bool applyInsertion(le_int32 atPosition, le_int32 count, LEGlyphID newGlyphs[]);
sl@0
   111
sl@0
   112
public:
sl@0
   113
sl@0
   114
    /**
sl@0
   115
     * Allocates an empty <code>LEGlyphStorage</code> object. You must call
sl@0
   116
     * <code>allocateGlyphArray, allocatePositions and allocateAuxData</code>
sl@0
   117
     * to allocate the data.
sl@0
   118
     */
sl@0
   119
    LEGlyphStorage();
sl@0
   120
sl@0
   121
    /**
sl@0
   122
     * The destructor. This will deallocate all of the arrays.
sl@0
   123
     */
sl@0
   124
    ~LEGlyphStorage();
sl@0
   125
sl@0
   126
    /**
sl@0
   127
     * This method returns the number of glyphs in the glyph array.
sl@0
   128
     *
sl@0
   129
     * @return the number of glyphs in the glyph array
sl@0
   130
     *
sl@0
   131
     * @draft ICU 3.0
sl@0
   132
     */
sl@0
   133
    inline le_int32 getGlyphCount() const;
sl@0
   134
sl@0
   135
    /**
sl@0
   136
     * This method copies the glyph array into a caller supplied array.
sl@0
   137
     * The caller must ensure that the array is large enough to hold all
sl@0
   138
     * the glyphs.
sl@0
   139
     *
sl@0
   140
     * @param glyphs - the destiniation glyph array
sl@0
   141
     * @param success - set to an error code if the operation fails
sl@0
   142
     *
sl@0
   143
     * @draft ICU 3.0
sl@0
   144
     */
sl@0
   145
    void getGlyphs(LEGlyphID glyphs[], LEErrorCode &success) const;
sl@0
   146
sl@0
   147
    /**
sl@0
   148
     * This method copies the glyph array into a caller supplied array,
sl@0
   149
     * ORing in extra bits. (This functionality is needed by the JDK,
sl@0
   150
     * which uses 32 bits pre glyph idex, with the high 16 bits encoding
sl@0
   151
     * the composite font slot number)
sl@0
   152
     *
sl@0
   153
     * @param glyphs - the destination (32 bit) glyph array
sl@0
   154
     * @param extraBits - this value will be ORed with each glyph index
sl@0
   155
     * @param success - set to an error code if the operation fails
sl@0
   156
     *
sl@0
   157
     * @draft ICU 3.0
sl@0
   158
     */
sl@0
   159
    void getGlyphs(le_uint32 glyphs[], le_uint32 extraBits, LEErrorCode &success) const;
sl@0
   160
sl@0
   161
    /**
sl@0
   162
     * This method copies the character index array into a caller supplied array.
sl@0
   163
     * The caller must ensure that the array is large enough to hold a
sl@0
   164
     * character index for each glyph.
sl@0
   165
     *
sl@0
   166
     * @param charIndices - the destiniation character index array
sl@0
   167
     * @param success - set to an error code if the operation fails
sl@0
   168
     *
sl@0
   169
     * @draft ICU 3.0
sl@0
   170
     */
sl@0
   171
    void getCharIndices(le_int32 charIndices[], LEErrorCode &success) const;
sl@0
   172
sl@0
   173
    /**
sl@0
   174
     * This method copies the character index array into a caller supplied array.
sl@0
   175
     * The caller must ensure that the array is large enough to hold a
sl@0
   176
     * character index for each glyph.
sl@0
   177
     *
sl@0
   178
     * @param charIndices - the destiniation character index array
sl@0
   179
     * @param indexBase - an offset which will be added to each index
sl@0
   180
     * @param success - set to an error code if the operation fails
sl@0
   181
     *
sl@0
   182
     * @draft ICU 3.0
sl@0
   183
     */
sl@0
   184
    void getCharIndices(le_int32 charIndices[], le_int32 indexBase, LEErrorCode &success) const;
sl@0
   185
sl@0
   186
    /**
sl@0
   187
     * This method copies the position array into a caller supplied array.
sl@0
   188
     * The caller must ensure that the array is large enough to hold an
sl@0
   189
     * X and Y position for each glyph, plus an extra X and Y for the
sl@0
   190
     * advance of the last glyph.
sl@0
   191
     *
sl@0
   192
     * @param positions - the destiniation position array
sl@0
   193
     * @param success - set to an error code if the operation fails
sl@0
   194
     *
sl@0
   195
     * @draft ICU 3.0
sl@0
   196
     */
sl@0
   197
    void getGlyphPositions(float positions[], LEErrorCode &success) const;
sl@0
   198
sl@0
   199
    /**
sl@0
   200
     * This method returns the X and Y position of the glyph at
sl@0
   201
     * the given index.
sl@0
   202
     *
sl@0
   203
     * Input parameters:
sl@0
   204
     * @param glyphIndex - the index of the glyph
sl@0
   205
     *
sl@0
   206
     * Output parameters:
sl@0
   207
     * @param x - the glyph's X position
sl@0
   208
     * @param y - the glyph's Y position
sl@0
   209
     * @param success - set to an error code if the operation fails
sl@0
   210
     *
sl@0
   211
     * @draft ICU 3.0
sl@0
   212
     */
sl@0
   213
    void getGlyphPosition(le_int32 glyphIndex, float &x, float &y, LEErrorCode &success) const;
sl@0
   214
sl@0
   215
    /**
sl@0
   216
     * This method allocates the glyph array, the char indices array and the insertion list. You
sl@0
   217
     * must call this method before using the object. This method also initializes the char indices
sl@0
   218
     * array.
sl@0
   219
     *
sl@0
   220
     * @param initialGlyphCount the initial size of the glyph and char indices arrays.
sl@0
   221
     * @param rightToLeft <code>true</code> if the original input text is right to left.
sl@0
   222
     * @param success set to an error code if the storage cannot be allocated of if the initial
sl@0
   223
     *        glyph count is not positive.
sl@0
   224
     *
sl@0
   225
     * @draft ICU 3.0
sl@0
   226
     */
sl@0
   227
    void allocateGlyphArray(le_int32 initialGlyphCount, le_bool rightToLeft, LEErrorCode &success);
sl@0
   228
sl@0
   229
    /**
sl@0
   230
     * This method allocates the storage for the glyph positions. It allocates one extra X, Y
sl@0
   231
     * position pair for the position just after the last glyph.
sl@0
   232
     *
sl@0
   233
     * @param success set to an error code if the positions array cannot be allocated.
sl@0
   234
     *
sl@0
   235
     * @return the number of X, Y position pairs allocated.
sl@0
   236
     *
sl@0
   237
     * @draft ICU 3.0
sl@0
   238
     */
sl@0
   239
    le_int32 allocatePositions(LEErrorCode &success);
sl@0
   240
sl@0
   241
    /**
sl@0
   242
     * This method allocates the storage for the auxillary glyph data.
sl@0
   243
     *
sl@0
   244
     * @param success set to an error code if the aulillary data array cannot be allocated.
sl@0
   245
     *
sl@0
   246
     * @return the size of the auxillary data array.
sl@0
   247
     *
sl@0
   248
     * @draft ICU 3.0
sl@0
   249
     */
sl@0
   250
    le_int32 allocateAuxData(LEErrorCode &success);
sl@0
   251
sl@0
   252
    /**
sl@0
   253
     * Copy the entire auxillary data array.
sl@0
   254
     *
sl@0
   255
     * @param auxData the auxillary data array will be copied to this address
sl@0
   256
     * @param success set to an error code if the data cannot be copied
sl@0
   257
     *
sl@0
   258
     * @draft ICU 3.0
sl@0
   259
     */
sl@0
   260
    void getAuxData(void *auxData[], LEErrorCode &success) const;
sl@0
   261
sl@0
   262
    /**
sl@0
   263
     * Get the glyph ID for a particular glyph.
sl@0
   264
     *
sl@0
   265
     * @param glyphIndex the index into the glyph array
sl@0
   266
     * @param success set to an error code if the glyph ID cannot be retrieved.
sl@0
   267
     *
sl@0
   268
     * @return the glyph ID
sl@0
   269
     *
sl@0
   270
     * @draft ICU 3.0
sl@0
   271
     */
sl@0
   272
    LEGlyphID getGlyphID(le_int32 glyphIndex, LEErrorCode &success) const;
sl@0
   273
sl@0
   274
    /**
sl@0
   275
     * Get the char index for a particular glyph.
sl@0
   276
     *
sl@0
   277
     * @param glyphIndex the index into the glyph array
sl@0
   278
     * @param success set to an error code if the char index cannot be retrieved.
sl@0
   279
     *
sl@0
   280
     * @return the character index
sl@0
   281
     *
sl@0
   282
     * @draft ICU 3.0
sl@0
   283
     */
sl@0
   284
    le_int32  getCharIndex(le_int32 glyphIndex, LEErrorCode &success) const;
sl@0
   285
sl@0
   286
sl@0
   287
    /**
sl@0
   288
     * Get the auxillary data for a particular glyph.
sl@0
   289
     *
sl@0
   290
     * @param glyphIndex the index into the glyph array
sl@0
   291
     * @param success set to an error code if the auxillary data cannot be retrieved.
sl@0
   292
     *
sl@0
   293
     * @return the auxillary data
sl@0
   294
     *
sl@0
   295
     * @draft ICU 3.0
sl@0
   296
     */
sl@0
   297
    void *getAuxData(le_int32 glyphIndex, LEErrorCode &success) const;
sl@0
   298
sl@0
   299
    /**
sl@0
   300
     * This operator allows direct access to the glyph array
sl@0
   301
     * using the index operator.
sl@0
   302
     *
sl@0
   303
     * @param glyphIndex the index into the glyph array
sl@0
   304
     *
sl@0
   305
     * @return a reference to the given location in the glyph array
sl@0
   306
     *
sl@0
   307
     * @draft ICU 3.0
sl@0
   308
     */
sl@0
   309
    inline LEGlyphID &operator[](le_int32 glyphIndex) const;
sl@0
   310
sl@0
   311
    /**
sl@0
   312
     * Call this method to replace a single glyph in the glyph array
sl@0
   313
     * with multiple glyphs. This method uses the <code>LEInsertionList</code>
sl@0
   314
     * to do the insertion. It returns the address of storage where the new
sl@0
   315
     * glyph IDs can be stored. They will not actually be inserted into the
sl@0
   316
     * glyph array until <code>applyInsertions</code> is called.
sl@0
   317
     *
sl@0
   318
     * @param atIndex the index of the glyph to be replaced
sl@0
   319
     * @param insertCount the number of glyphs to replace it with
sl@0
   320
     * @param success set to an error code if the auxillary data cannot be retrieved.
sl@0
   321
     *
sl@0
   322
     * @return the address at which to store the replacement glyphs.
sl@0
   323
     *
sl@0
   324
     * @see LEInsetionList.h
sl@0
   325
     *
sl@0
   326
     * @draft ICU 3.0
sl@0
   327
     */
sl@0
   328
    LEGlyphID *insertGlyphs(le_int32 atIndex, le_int32 insertCount,
sl@0
   329
        LEErrorCode& success);
sl@0
   330
sl@0
   331
    /**
sl@0
   332
     * This method causes all of the glyph insertions recorded by
sl@0
   333
     * <code>insertGlyphs</code> to be applied to the glyph array. The
sl@0
   334
     * new slots in the char indices and the auxillary data arrays
sl@0
   335
     * will be filled in with the values for the glyph being replaced.
sl@0
   336
     *
sl@0
   337
     * @return the new size of the glyph array
sl@0
   338
     *
sl@0
   339
     * @see LEInsertionList.h
sl@0
   340
     *
sl@0
   341
     * @draft ICU 3.0
sl@0
   342
     */
sl@0
   343
    le_int32 applyInsertions();
sl@0
   344
sl@0
   345
    /**
sl@0
   346
     * Set the glyph ID for a particular glyph.
sl@0
   347
     *
sl@0
   348
     * @param glyphIndex the index of the glyph
sl@0
   349
     * @param glyphID the new glyph ID
sl@0
   350
     * @param success will be set to an error code if the glyph ID cannot be set.
sl@0
   351
     *
sl@0
   352
     * @draft ICU 3.0
sl@0
   353
     */
sl@0
   354
    void setGlyphID(le_int32 glyphIndex, LEGlyphID glyphID, LEErrorCode &success);
sl@0
   355
sl@0
   356
    /**
sl@0
   357
     * Set the char index for a particular glyph.
sl@0
   358
     *
sl@0
   359
     * @param glyphIndex the index of the glyph
sl@0
   360
     * @param charIndex the new char index
sl@0
   361
     * @param success will be set to an error code if the char index cannot be set.
sl@0
   362
     *
sl@0
   363
     * @draft ICU 3.0
sl@0
   364
     */
sl@0
   365
    void setCharIndex(le_int32 glyphIndex, le_int32 charIndex, LEErrorCode &success);
sl@0
   366
sl@0
   367
    /**
sl@0
   368
     * Set the X, Y position for a particular glyph.
sl@0
   369
     *
sl@0
   370
     * @param glyphIndex the index of the glyph
sl@0
   371
     * @param x the new X position
sl@0
   372
     * @param y the new Y position
sl@0
   373
     * @param success will be set to an error code if the position cannot be set.
sl@0
   374
     *
sl@0
   375
     * @draft ICU 3.0
sl@0
   376
     */
sl@0
   377
    void setPosition(le_int32 glyphIndex, float x, float y, LEErrorCode &success);
sl@0
   378
sl@0
   379
    /**
sl@0
   380
     * Adjust the X, Y position for a particular glyph.
sl@0
   381
     *
sl@0
   382
     * @param glyphIndex the index of the glyph
sl@0
   383
     * @param xAdjust the adjustment to the glyph's X position
sl@0
   384
     * @param yAdjust the adjustment to the glyph's Y position
sl@0
   385
     * @param success will be set to an error code if the glyph's position cannot be adjusted.
sl@0
   386
     *
sl@0
   387
     * @draft ICU 3.0
sl@0
   388
     */
sl@0
   389
    void adjustPosition(le_int32 glyphIndex, float xAdjust, float yAdjust, LEErrorCode &success);
sl@0
   390
sl@0
   391
    /**
sl@0
   392
     * Set the auxillary data for a particular glyph.
sl@0
   393
     *
sl@0
   394
     * @param glyphIndex the index of the glyph
sl@0
   395
     * @param auxData the new auxillary data
sl@0
   396
     * @param success will be set to an error code if the auxillary data cannot be set.
sl@0
   397
     *
sl@0
   398
     * @draft ICU 3.0
sl@0
   399
     */
sl@0
   400
    void setAuxData(le_int32 glyphIndex, void *auxData, LEErrorCode &success);
sl@0
   401
sl@0
   402
    /**
sl@0
   403
     * Delete the glyph array and replace it with the one
sl@0
   404
     * in <code>from</code>. Set the glyph array pointer
sl@0
   405
     * in <code>from</code> to <code>NULL</code>.
sl@0
   406
     *
sl@0
   407
     * @param from the <code>LEGlyphStorage</code> object from which
sl@0
   408
     *             to get the new glyph array.
sl@0
   409
     *
sl@0
   410
     * @draft ICU 3.0
sl@0
   411
     */
sl@0
   412
    void adoptGlyphArray(LEGlyphStorage &from);
sl@0
   413
sl@0
   414
    /**
sl@0
   415
     * Delete the char indices array and replace it with the one
sl@0
   416
     * in <code>from</code>. Set the char indices array pointer
sl@0
   417
     * in <code>from</code> to <code>NULL</code>.
sl@0
   418
     *
sl@0
   419
     * @param from the <code>LEGlyphStorage</code> object from which
sl@0
   420
     *             to get the new char indices array.
sl@0
   421
     *
sl@0
   422
     * @draft ICU 3.0
sl@0
   423
     */
sl@0
   424
    void adoptCharIndicesArray(LEGlyphStorage &from);
sl@0
   425
sl@0
   426
    /**
sl@0
   427
     * Delete the position array and replace it with the one
sl@0
   428
     * in <code>from</code>. Set the position array pointer
sl@0
   429
     * in <code>from</code> to <code>NULL</code>.
sl@0
   430
     *
sl@0
   431
     * @param from the <code>LEGlyphStorage</code> object from which
sl@0
   432
     *             to get the new position array.
sl@0
   433
     *
sl@0
   434
     * @draft ICU 3.0
sl@0
   435
     */
sl@0
   436
    void adoptPositionArray(LEGlyphStorage &from);
sl@0
   437
sl@0
   438
    /**
sl@0
   439
     * Delete the auxillary data array and replace it with the one
sl@0
   440
     * in <code>from</code>. Set the auxillary data array pointer
sl@0
   441
     * in <code>from</code> to <code>NULL</code>.
sl@0
   442
     *
sl@0
   443
     * @param from the <code>LEGlyphStorage</code> object from which
sl@0
   444
     *             to get the new auxillary data array.
sl@0
   445
     *
sl@0
   446
     * @draft ICU 3.0
sl@0
   447
     */
sl@0
   448
    void adoptAuxDataArray(LEGlyphStorage &from);
sl@0
   449
sl@0
   450
    /**
sl@0
   451
     * Change the glyph count of this object to be the same
sl@0
   452
     * as the one in <code>from</code>.
sl@0
   453
     *
sl@0
   454
     * @param from the <code>LEGlyphStorage</code> object from which
sl@0
   455
     *             to get the new glyph count.
sl@0
   456
     *
sl@0
   457
     * @draft ICU 3.0
sl@0
   458
     */
sl@0
   459
    void adoptGlyphCount(LEGlyphStorage &from);
sl@0
   460
sl@0
   461
    /**
sl@0
   462
     * Change the glyph count of this object to the given value.
sl@0
   463
     *
sl@0
   464
     * @param newGlyphCount the new glyph count.
sl@0
   465
     *
sl@0
   466
     * @draft ICU 3.0
sl@0
   467
     */
sl@0
   468
    void adoptGlyphCount(le_int32 newGlyphCount);
sl@0
   469
sl@0
   470
    /**
sl@0
   471
     * This method frees the glyph, character index, position  and
sl@0
   472
     * auxillary data arrays so that the LayoutEngine can be reused
sl@0
   473
     * to layout a different characer array. (This method is also called
sl@0
   474
     * by the destructor)
sl@0
   475
     *
sl@0
   476
     * @draft ICU 3.0
sl@0
   477
     */
sl@0
   478
    void reset();
sl@0
   479
sl@0
   480
    /**
sl@0
   481
     * This method move glyph of Malayalam RAKAR to the left of the preceding
sl@0
   482
     * consonant cluster.
sl@0
   483
     *
sl@0
   484
     * @param aGlyphID the <code>LEGlyphID</code> of RAKAR
sl@0
   485
     * 
sl@0
   486
     * @draft Added by Nokia
sl@0
   487
     */
sl@0
   488
    void forMlylRakar(LEGlyphID aGlyphID);
sl@0
   489
    
sl@0
   490
    /**
sl@0
   491
     * ICU "poor man's RTTI", returns a UClassID for the actual class.
sl@0
   492
     *
sl@0
   493
     * @draft ICU 3.0
sl@0
   494
     */
sl@0
   495
    virtual UClassID getDynamicClassID() const;
sl@0
   496
sl@0
   497
    /**
sl@0
   498
     * ICU "poor man's RTTI", returns a UClassID for this class.
sl@0
   499
     *
sl@0
   500
     * @draft ICU 3.0
sl@0
   501
     */
sl@0
   502
    static UClassID getStaticClassID();
sl@0
   503
};
sl@0
   504
sl@0
   505
inline le_int32 LEGlyphStorage::getGlyphCount() const
sl@0
   506
{
sl@0
   507
    return fGlyphCount;
sl@0
   508
}
sl@0
   509
sl@0
   510
inline LEGlyphID &LEGlyphStorage::operator[](le_int32 glyphIndex) const
sl@0
   511
{
sl@0
   512
    return fGlyphs[glyphIndex];
sl@0
   513
}
sl@0
   514
sl@0
   515
sl@0
   516
U_NAMESPACE_END
sl@0
   517
#endif
sl@0
   518