os/textandloc/fontservices/textshaperplugin/IcuSource/layout/LEGlyphStorage.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/LEGlyphStorage.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,518 @@
     1.4 +/*
     1.5 + **********************************************************************
     1.6 + *   Copyright (C) 1998-2005, International Business Machines
     1.7 + *   Corporation and others.  All Rights Reserved.
     1.8 + **********************************************************************
     1.9 + */
    1.10 +
    1.11 +#ifndef __LEGLYPHSTORAGE_H
    1.12 +#define __LEGLYPHSTORAGE_H
    1.13 +
    1.14 +#include "LETypes.h"
    1.15 +#include "LEInsertionList.h"
    1.16 +
    1.17 +/**
    1.18 + * \file 
    1.19 + * \brief C++ API: This class encapsulates the per-glyph storage used by the ICU LayoutEngine.
    1.20 + */
    1.21 +
    1.22 +U_NAMESPACE_BEGIN
    1.23 +
    1.24 +/**
    1.25 + * This class encapsulates the per-glyph storage used by the ICU LayoutEngine.
    1.26 + * For each glyph it holds the glyph ID, the index of the backing store character
    1.27 + * which produced the glyph, the X and Y position of the glyph and an auxillary data
    1.28 + * pointer.
    1.29 + *
    1.30 + * The storage is growable using the <code>LEInsertionList</code> class.
    1.31 + *
    1.32 + *
    1.33 + * @see LEInsertionList.h
    1.34 + *
    1.35 + * @draft ICU 3.0
    1.36 + */
    1.37 +class U_LAYOUT_API LEGlyphStorage : public UObject, protected LEInsertionCallback
    1.38 +{
    1.39 +private:
    1.40 +    /**
    1.41 +     * The number of entries in the per-glyph arrays.
    1.42 +     *
    1.43 +     * @internal
    1.44 +     */
    1.45 +    le_int32   fGlyphCount;
    1.46 +
    1.47 +    /**
    1.48 +     * The glyph ID array.
    1.49 +     *
    1.50 +     * @internal
    1.51 +     */
    1.52 +    LEGlyphID *fGlyphs;
    1.53 + 
    1.54 +    /**
    1.55 +     * The char indices array.
    1.56 +     *
    1.57 +     * @internal
    1.58 +     */
    1.59 +    le_int32  *fCharIndices;
    1.60 +
    1.61 +    /**
    1.62 +     * The glyph positions array.
    1.63 +     *
    1.64 +     * @internal
    1.65 +     */
    1.66 +    float     *fPositions;
    1.67 +
    1.68 +    /**
    1.69 +     * The auxillary data array.
    1.70 +     *
    1.71 +     * @internal
    1.72 +     */
    1.73 +    void     **fAuxData;
    1.74 +
    1.75 +
    1.76 +    /**
    1.77 +     * The insertion list, used to grow the above arrays.
    1.78 +     *
    1.79 +     * @internal
    1.80 +     */
    1.81 +    LEInsertionList *fInsertionList;
    1.82 +
    1.83 +    /**
    1.84 +     * The source index while growing the data arrays.
    1.85 +     *
    1.86 +     * @internal
    1.87 +     */
    1.88 +    le_int32 fSrcIndex;
    1.89 +
    1.90 +    /**
    1.91 +     * The destination index used while growing the data arrays.
    1.92 +     *
    1.93 +     * @internal
    1.94 +     */
    1.95 +    le_int32 fDestIndex;
    1.96 +
    1.97 +protected:
    1.98 +    /**
    1.99 +     * This implements <code>LEInsertionCallback</code>. The <code>LEInsertionList</code>
   1.100 +     * will call this method once for each insertion.
   1.101 +     *
   1.102 +     * @param atPosition the position of the insertion
   1.103 +     * @param count the number of glyphs being inserted
   1.104 +     * @param newGlyphs the address of the new glyph IDs
   1.105 +     *
   1.106 +     * @return <code>true</code> if <code>LEInsertionList</code> should stop
   1.107 +     *         processing the insertion list after this insertion.
   1.108 +     *
   1.109 +     * @see LEInsertionList.h
   1.110 +     *
   1.111 +     * @draft ICU 3.0
   1.112 +     */
   1.113 +    virtual le_bool applyInsertion(le_int32 atPosition, le_int32 count, LEGlyphID newGlyphs[]);
   1.114 +
   1.115 +public:
   1.116 +
   1.117 +    /**
   1.118 +     * Allocates an empty <code>LEGlyphStorage</code> object. You must call
   1.119 +     * <code>allocateGlyphArray, allocatePositions and allocateAuxData</code>
   1.120 +     * to allocate the data.
   1.121 +     */
   1.122 +    LEGlyphStorage();
   1.123 +
   1.124 +    /**
   1.125 +     * The destructor. This will deallocate all of the arrays.
   1.126 +     */
   1.127 +    ~LEGlyphStorage();
   1.128 +
   1.129 +    /**
   1.130 +     * This method returns the number of glyphs in the glyph array.
   1.131 +     *
   1.132 +     * @return the number of glyphs in the glyph array
   1.133 +     *
   1.134 +     * @draft ICU 3.0
   1.135 +     */
   1.136 +    inline le_int32 getGlyphCount() const;
   1.137 +
   1.138 +    /**
   1.139 +     * This method copies the glyph array into a caller supplied array.
   1.140 +     * The caller must ensure that the array is large enough to hold all
   1.141 +     * the glyphs.
   1.142 +     *
   1.143 +     * @param glyphs - the destiniation glyph array
   1.144 +     * @param success - set to an error code if the operation fails
   1.145 +     *
   1.146 +     * @draft ICU 3.0
   1.147 +     */
   1.148 +    void getGlyphs(LEGlyphID glyphs[], LEErrorCode &success) const;
   1.149 +
   1.150 +    /**
   1.151 +     * This method copies the glyph array into a caller supplied array,
   1.152 +     * ORing in extra bits. (This functionality is needed by the JDK,
   1.153 +     * which uses 32 bits pre glyph idex, with the high 16 bits encoding
   1.154 +     * the composite font slot number)
   1.155 +     *
   1.156 +     * @param glyphs - the destination (32 bit) glyph array
   1.157 +     * @param extraBits - this value will be ORed with each glyph index
   1.158 +     * @param success - set to an error code if the operation fails
   1.159 +     *
   1.160 +     * @draft ICU 3.0
   1.161 +     */
   1.162 +    void getGlyphs(le_uint32 glyphs[], le_uint32 extraBits, LEErrorCode &success) const;
   1.163 +
   1.164 +    /**
   1.165 +     * This method copies the character index array into a caller supplied array.
   1.166 +     * The caller must ensure that the array is large enough to hold a
   1.167 +     * character index for each glyph.
   1.168 +     *
   1.169 +     * @param charIndices - the destiniation character index array
   1.170 +     * @param success - set to an error code if the operation fails
   1.171 +     *
   1.172 +     * @draft ICU 3.0
   1.173 +     */
   1.174 +    void getCharIndices(le_int32 charIndices[], LEErrorCode &success) const;
   1.175 +
   1.176 +    /**
   1.177 +     * This method copies the character index array into a caller supplied array.
   1.178 +     * The caller must ensure that the array is large enough to hold a
   1.179 +     * character index for each glyph.
   1.180 +     *
   1.181 +     * @param charIndices - the destiniation character index array
   1.182 +     * @param indexBase - an offset which will be added to each index
   1.183 +     * @param success - set to an error code if the operation fails
   1.184 +     *
   1.185 +     * @draft ICU 3.0
   1.186 +     */
   1.187 +    void getCharIndices(le_int32 charIndices[], le_int32 indexBase, LEErrorCode &success) const;
   1.188 +
   1.189 +    /**
   1.190 +     * This method copies the position array into a caller supplied array.
   1.191 +     * The caller must ensure that the array is large enough to hold an
   1.192 +     * X and Y position for each glyph, plus an extra X and Y for the
   1.193 +     * advance of the last glyph.
   1.194 +     *
   1.195 +     * @param positions - the destiniation position array
   1.196 +     * @param success - set to an error code if the operation fails
   1.197 +     *
   1.198 +     * @draft ICU 3.0
   1.199 +     */
   1.200 +    void getGlyphPositions(float positions[], LEErrorCode &success) const;
   1.201 +
   1.202 +    /**
   1.203 +     * This method returns the X and Y position of the glyph at
   1.204 +     * the given index.
   1.205 +     *
   1.206 +     * Input parameters:
   1.207 +     * @param glyphIndex - the index of the glyph
   1.208 +     *
   1.209 +     * Output parameters:
   1.210 +     * @param x - the glyph's X position
   1.211 +     * @param y - the glyph's Y position
   1.212 +     * @param success - set to an error code if the operation fails
   1.213 +     *
   1.214 +     * @draft ICU 3.0
   1.215 +     */
   1.216 +    void getGlyphPosition(le_int32 glyphIndex, float &x, float &y, LEErrorCode &success) const;
   1.217 +
   1.218 +    /**
   1.219 +     * This method allocates the glyph array, the char indices array and the insertion list. You
   1.220 +     * must call this method before using the object. This method also initializes the char indices
   1.221 +     * array.
   1.222 +     *
   1.223 +     * @param initialGlyphCount the initial size of the glyph and char indices arrays.
   1.224 +     * @param rightToLeft <code>true</code> if the original input text is right to left.
   1.225 +     * @param success set to an error code if the storage cannot be allocated of if the initial
   1.226 +     *        glyph count is not positive.
   1.227 +     *
   1.228 +     * @draft ICU 3.0
   1.229 +     */
   1.230 +    void allocateGlyphArray(le_int32 initialGlyphCount, le_bool rightToLeft, LEErrorCode &success);
   1.231 +
   1.232 +    /**
   1.233 +     * This method allocates the storage for the glyph positions. It allocates one extra X, Y
   1.234 +     * position pair for the position just after the last glyph.
   1.235 +     *
   1.236 +     * @param success set to an error code if the positions array cannot be allocated.
   1.237 +     *
   1.238 +     * @return the number of X, Y position pairs allocated.
   1.239 +     *
   1.240 +     * @draft ICU 3.0
   1.241 +     */
   1.242 +    le_int32 allocatePositions(LEErrorCode &success);
   1.243 +
   1.244 +    /**
   1.245 +     * This method allocates the storage for the auxillary glyph data.
   1.246 +     *
   1.247 +     * @param success set to an error code if the aulillary data array cannot be allocated.
   1.248 +     *
   1.249 +     * @return the size of the auxillary data array.
   1.250 +     *
   1.251 +     * @draft ICU 3.0
   1.252 +     */
   1.253 +    le_int32 allocateAuxData(LEErrorCode &success);
   1.254 +
   1.255 +    /**
   1.256 +     * Copy the entire auxillary data array.
   1.257 +     *
   1.258 +     * @param auxData the auxillary data array will be copied to this address
   1.259 +     * @param success set to an error code if the data cannot be copied
   1.260 +     *
   1.261 +     * @draft ICU 3.0
   1.262 +     */
   1.263 +    void getAuxData(void *auxData[], LEErrorCode &success) const;
   1.264 +
   1.265 +    /**
   1.266 +     * Get the glyph ID for a particular glyph.
   1.267 +     *
   1.268 +     * @param glyphIndex the index into the glyph array
   1.269 +     * @param success set to an error code if the glyph ID cannot be retrieved.
   1.270 +     *
   1.271 +     * @return the glyph ID
   1.272 +     *
   1.273 +     * @draft ICU 3.0
   1.274 +     */
   1.275 +    LEGlyphID getGlyphID(le_int32 glyphIndex, LEErrorCode &success) const;
   1.276 +
   1.277 +    /**
   1.278 +     * Get the char index for a particular glyph.
   1.279 +     *
   1.280 +     * @param glyphIndex the index into the glyph array
   1.281 +     * @param success set to an error code if the char index cannot be retrieved.
   1.282 +     *
   1.283 +     * @return the character index
   1.284 +     *
   1.285 +     * @draft ICU 3.0
   1.286 +     */
   1.287 +    le_int32  getCharIndex(le_int32 glyphIndex, LEErrorCode &success) const;
   1.288 +
   1.289 +
   1.290 +    /**
   1.291 +     * Get the auxillary data for a particular glyph.
   1.292 +     *
   1.293 +     * @param glyphIndex the index into the glyph array
   1.294 +     * @param success set to an error code if the auxillary data cannot be retrieved.
   1.295 +     *
   1.296 +     * @return the auxillary data
   1.297 +     *
   1.298 +     * @draft ICU 3.0
   1.299 +     */
   1.300 +    void *getAuxData(le_int32 glyphIndex, LEErrorCode &success) const;
   1.301 +
   1.302 +    /**
   1.303 +     * This operator allows direct access to the glyph array
   1.304 +     * using the index operator.
   1.305 +     *
   1.306 +     * @param glyphIndex the index into the glyph array
   1.307 +     *
   1.308 +     * @return a reference to the given location in the glyph array
   1.309 +     *
   1.310 +     * @draft ICU 3.0
   1.311 +     */
   1.312 +    inline LEGlyphID &operator[](le_int32 glyphIndex) const;
   1.313 +
   1.314 +    /**
   1.315 +     * Call this method to replace a single glyph in the glyph array
   1.316 +     * with multiple glyphs. This method uses the <code>LEInsertionList</code>
   1.317 +     * to do the insertion. It returns the address of storage where the new
   1.318 +     * glyph IDs can be stored. They will not actually be inserted into the
   1.319 +     * glyph array until <code>applyInsertions</code> is called.
   1.320 +     *
   1.321 +     * @param atIndex the index of the glyph to be replaced
   1.322 +     * @param insertCount the number of glyphs to replace it with
   1.323 +     * @param success set to an error code if the auxillary data cannot be retrieved.
   1.324 +     *
   1.325 +     * @return the address at which to store the replacement glyphs.
   1.326 +     *
   1.327 +     * @see LEInsetionList.h
   1.328 +     *
   1.329 +     * @draft ICU 3.0
   1.330 +     */
   1.331 +    LEGlyphID *insertGlyphs(le_int32 atIndex, le_int32 insertCount,
   1.332 +        LEErrorCode& success);
   1.333 +
   1.334 +    /**
   1.335 +     * This method causes all of the glyph insertions recorded by
   1.336 +     * <code>insertGlyphs</code> to be applied to the glyph array. The
   1.337 +     * new slots in the char indices and the auxillary data arrays
   1.338 +     * will be filled in with the values for the glyph being replaced.
   1.339 +     *
   1.340 +     * @return the new size of the glyph array
   1.341 +     *
   1.342 +     * @see LEInsertionList.h
   1.343 +     *
   1.344 +     * @draft ICU 3.0
   1.345 +     */
   1.346 +    le_int32 applyInsertions();
   1.347 +
   1.348 +    /**
   1.349 +     * Set the glyph ID for a particular glyph.
   1.350 +     *
   1.351 +     * @param glyphIndex the index of the glyph
   1.352 +     * @param glyphID the new glyph ID
   1.353 +     * @param success will be set to an error code if the glyph ID cannot be set.
   1.354 +     *
   1.355 +     * @draft ICU 3.0
   1.356 +     */
   1.357 +    void setGlyphID(le_int32 glyphIndex, LEGlyphID glyphID, LEErrorCode &success);
   1.358 +
   1.359 +    /**
   1.360 +     * Set the char index for a particular glyph.
   1.361 +     *
   1.362 +     * @param glyphIndex the index of the glyph
   1.363 +     * @param charIndex the new char index
   1.364 +     * @param success will be set to an error code if the char index cannot be set.
   1.365 +     *
   1.366 +     * @draft ICU 3.0
   1.367 +     */
   1.368 +    void setCharIndex(le_int32 glyphIndex, le_int32 charIndex, LEErrorCode &success);
   1.369 +
   1.370 +    /**
   1.371 +     * Set the X, Y position for a particular glyph.
   1.372 +     *
   1.373 +     * @param glyphIndex the index of the glyph
   1.374 +     * @param x the new X position
   1.375 +     * @param y the new Y position
   1.376 +     * @param success will be set to an error code if the position cannot be set.
   1.377 +     *
   1.378 +     * @draft ICU 3.0
   1.379 +     */
   1.380 +    void setPosition(le_int32 glyphIndex, float x, float y, LEErrorCode &success);
   1.381 +
   1.382 +    /**
   1.383 +     * Adjust the X, Y position for a particular glyph.
   1.384 +     *
   1.385 +     * @param glyphIndex the index of the glyph
   1.386 +     * @param xAdjust the adjustment to the glyph's X position
   1.387 +     * @param yAdjust the adjustment to the glyph's Y position
   1.388 +     * @param success will be set to an error code if the glyph's position cannot be adjusted.
   1.389 +     *
   1.390 +     * @draft ICU 3.0
   1.391 +     */
   1.392 +    void adjustPosition(le_int32 glyphIndex, float xAdjust, float yAdjust, LEErrorCode &success);
   1.393 +
   1.394 +    /**
   1.395 +     * Set the auxillary data for a particular glyph.
   1.396 +     *
   1.397 +     * @param glyphIndex the index of the glyph
   1.398 +     * @param auxData the new auxillary data
   1.399 +     * @param success will be set to an error code if the auxillary data cannot be set.
   1.400 +     *
   1.401 +     * @draft ICU 3.0
   1.402 +     */
   1.403 +    void setAuxData(le_int32 glyphIndex, void *auxData, LEErrorCode &success);
   1.404 +
   1.405 +    /**
   1.406 +     * Delete the glyph array and replace it with the one
   1.407 +     * in <code>from</code>. Set the glyph array pointer
   1.408 +     * in <code>from</code> to <code>NULL</code>.
   1.409 +     *
   1.410 +     * @param from the <code>LEGlyphStorage</code> object from which
   1.411 +     *             to get the new glyph array.
   1.412 +     *
   1.413 +     * @draft ICU 3.0
   1.414 +     */
   1.415 +    void adoptGlyphArray(LEGlyphStorage &from);
   1.416 +
   1.417 +    /**
   1.418 +     * Delete the char indices array and replace it with the one
   1.419 +     * in <code>from</code>. Set the char indices array pointer
   1.420 +     * in <code>from</code> to <code>NULL</code>.
   1.421 +     *
   1.422 +     * @param from the <code>LEGlyphStorage</code> object from which
   1.423 +     *             to get the new char indices array.
   1.424 +     *
   1.425 +     * @draft ICU 3.0
   1.426 +     */
   1.427 +    void adoptCharIndicesArray(LEGlyphStorage &from);
   1.428 +
   1.429 +    /**
   1.430 +     * Delete the position array and replace it with the one
   1.431 +     * in <code>from</code>. Set the position array pointer
   1.432 +     * in <code>from</code> to <code>NULL</code>.
   1.433 +     *
   1.434 +     * @param from the <code>LEGlyphStorage</code> object from which
   1.435 +     *             to get the new position array.
   1.436 +     *
   1.437 +     * @draft ICU 3.0
   1.438 +     */
   1.439 +    void adoptPositionArray(LEGlyphStorage &from);
   1.440 +
   1.441 +    /**
   1.442 +     * Delete the auxillary data array and replace it with the one
   1.443 +     * in <code>from</code>. Set the auxillary data array pointer
   1.444 +     * in <code>from</code> to <code>NULL</code>.
   1.445 +     *
   1.446 +     * @param from the <code>LEGlyphStorage</code> object from which
   1.447 +     *             to get the new auxillary data array.
   1.448 +     *
   1.449 +     * @draft ICU 3.0
   1.450 +     */
   1.451 +    void adoptAuxDataArray(LEGlyphStorage &from);
   1.452 +
   1.453 +    /**
   1.454 +     * Change the glyph count of this object to be the same
   1.455 +     * as the one in <code>from</code>.
   1.456 +     *
   1.457 +     * @param from the <code>LEGlyphStorage</code> object from which
   1.458 +     *             to get the new glyph count.
   1.459 +     *
   1.460 +     * @draft ICU 3.0
   1.461 +     */
   1.462 +    void adoptGlyphCount(LEGlyphStorage &from);
   1.463 +
   1.464 +    /**
   1.465 +     * Change the glyph count of this object to the given value.
   1.466 +     *
   1.467 +     * @param newGlyphCount the new glyph count.
   1.468 +     *
   1.469 +     * @draft ICU 3.0
   1.470 +     */
   1.471 +    void adoptGlyphCount(le_int32 newGlyphCount);
   1.472 +
   1.473 +    /**
   1.474 +     * This method frees the glyph, character index, position  and
   1.475 +     * auxillary data arrays so that the LayoutEngine can be reused
   1.476 +     * to layout a different characer array. (This method is also called
   1.477 +     * by the destructor)
   1.478 +     *
   1.479 +     * @draft ICU 3.0
   1.480 +     */
   1.481 +    void reset();
   1.482 +
   1.483 +    /**
   1.484 +     * This method move glyph of Malayalam RAKAR to the left of the preceding
   1.485 +     * consonant cluster.
   1.486 +     *
   1.487 +     * @param aGlyphID the <code>LEGlyphID</code> of RAKAR
   1.488 +     * 
   1.489 +     * @draft Added by Nokia
   1.490 +     */
   1.491 +    void forMlylRakar(LEGlyphID aGlyphID);
   1.492 +    
   1.493 +    /**
   1.494 +     * ICU "poor man's RTTI", returns a UClassID for the actual class.
   1.495 +     *
   1.496 +     * @draft ICU 3.0
   1.497 +     */
   1.498 +    virtual UClassID getDynamicClassID() const;
   1.499 +
   1.500 +    /**
   1.501 +     * ICU "poor man's RTTI", returns a UClassID for this class.
   1.502 +     *
   1.503 +     * @draft ICU 3.0
   1.504 +     */
   1.505 +    static UClassID getStaticClassID();
   1.506 +};
   1.507 +
   1.508 +inline le_int32 LEGlyphStorage::getGlyphCount() const
   1.509 +{
   1.510 +    return fGlyphCount;
   1.511 +}
   1.512 +
   1.513 +inline LEGlyphID &LEGlyphStorage::operator[](le_int32 glyphIndex) const
   1.514 +{
   1.515 +    return fGlyphs[glyphIndex];
   1.516 +}
   1.517 +
   1.518 +
   1.519 +U_NAMESPACE_END
   1.520 +#endif
   1.521 +