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