Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/LEGlyphStorage.h
38825 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425/*26**********************************************************************27* Copyright (C) 1998-2010, International Business Machines28* Corporation and others. All Rights Reserved.29**********************************************************************30*/3132#ifndef __LEGLYPHSTORAGE_H33#define __LEGLYPHSTORAGE_H3435#include "LETypes.h"36#include "LEInsertionList.h"3738/**39* \file40* \brief C++ API: This class encapsulates the per-glyph storage used by the ICU LayoutEngine.41*/4243U_NAMESPACE_BEGIN4445/**46* This class encapsulates the per-glyph storage used by the ICU LayoutEngine.47* For each glyph it holds the glyph ID, the index of the backing store character48* which produced the glyph, the X and Y position of the glyph and an auxillary data49* pointer.50*51* The storage is growable using the <code>LEInsertionList</code> class.52*53*54* @see LEInsertionList.h55*56* @stable ICU 3.657*/58class U_LAYOUT_API LEGlyphStorage : public UObject, protected LEInsertionCallback59{60private:61/**62* The number of entries in the per-glyph arrays.63*64* @internal65*/66le_int32 fGlyphCount;6768/**69* The glyph ID array.70*71* @internal72*/73LEGlyphID *fGlyphs;7475/**76* The char indices array.77*78* @internal79*/80le_int32 *fCharIndices;8182/**83* The glyph positions array.84*85* @internal86*/87float *fPositions;8889/**90* The auxillary data array.91*92* @internal93*/94le_uint32 *fAuxData;959697/**98* The insertion list, used to grow the above arrays.99*100* @internal101*/102LEInsertionList *fInsertionList;103104/**105* The source index while growing the data arrays.106*107* @internal108*/109le_int32 fSrcIndex;110111/**112* The destination index used while growing the data arrays.113*114* @internal115*/116le_int32 fDestIndex;117118protected:119/**120* This implements <code>LEInsertionCallback</code>. The <code>LEInsertionList</code>121* will call this method once for each insertion.122*123* @param atPosition the position of the insertion124* @param count the number of glyphs being inserted125* @param newGlyphs the address of the new glyph IDs126*127* @return <code>true</code> if <code>LEInsertionList</code> should stop128* processing the insertion list after this insertion.129*130* @see LEInsertionList.h131*132* @stable ICU 3.0133*/134virtual le_bool applyInsertion(le_int32 atPosition, le_int32 count, LEGlyphID newGlyphs[]);135136public:137138/**139* Allocates an empty <code>LEGlyphStorage</code> object. You must call140* <code>allocateGlyphArray, allocatePositions and allocateAuxData</code>141* to allocate the data.142*143* @stable ICU 3.0144*/145LEGlyphStorage();146147/**148* The destructor. This will deallocate all of the arrays.149*150* @stable ICU 3.0151*/152~LEGlyphStorage();153154/**155* This method returns the number of glyphs in the glyph array.156*157* @return the number of glyphs in the glyph array158*159* @stable ICU 3.0160*/161inline le_int32 getGlyphCount() const;162163/**164* This method copies the glyph array into a caller supplied array.165* The caller must ensure that the array is large enough to hold all166* the glyphs.167*168* @param glyphs - the destiniation glyph array169* @param success - set to an error code if the operation fails170*171* @stable ICU 3.0172*/173void getGlyphs(LEGlyphID glyphs[], LEErrorCode &success) const;174175/**176* This method copies the glyph array into a caller supplied array,177* ORing in extra bits. (This functionality is needed by the JDK,178* which uses 32 bits pre glyph idex, with the high 16 bits encoding179* the composite font slot number)180*181* @param glyphs - the destination (32 bit) glyph array182* @param extraBits - this value will be ORed with each glyph index183* @param success - set to an error code if the operation fails184*185* @stable ICU 3.0186*/187void getGlyphs(le_uint32 glyphs[], le_uint32 extraBits, LEErrorCode &success) const;188189/**190* This method copies the character index array into a caller supplied array.191* The caller must ensure that the array is large enough to hold a192* character index for each glyph.193*194* @param charIndices - the destiniation character index array195* @param success - set to an error code if the operation fails196*197* @stable ICU 3.0198*/199void getCharIndices(le_int32 charIndices[], LEErrorCode &success) const;200201/**202* This method copies the character index array into a caller supplied array.203* The caller must ensure that the array is large enough to hold a204* character index for each glyph.205*206* @param charIndices - the destiniation character index array207* @param indexBase - an offset which will be added to each index208* @param success - set to an error code if the operation fails209*210* @stable ICU 3.0211*/212void getCharIndices(le_int32 charIndices[], le_int32 indexBase, LEErrorCode &success) const;213214/**215* This method copies the position array into a caller supplied array.216* The caller must ensure that the array is large enough to hold an217* X and Y position for each glyph, plus an extra X and Y for the218* advance of the last glyph.219*220* @param positions - the destiniation position array221* @param success - set to an error code if the operation fails222*223* @stable ICU 3.0224*/225void getGlyphPositions(float positions[], LEErrorCode &success) const;226227/**228* This method returns the X and Y position of the glyph at229* the given index.230*231* Input parameters:232* @param glyphIndex - the index of the glyph233*234* Output parameters:235* @param x - the glyph's X position236* @param y - the glyph's Y position237* @param success - set to an error code if the operation fails238*239* @stable ICU 3.0240*/241void getGlyphPosition(le_int32 glyphIndex, float &x, float &y, LEErrorCode &success) const;242243/**244* This method allocates the glyph array, the char indices array and the insertion list. You245* must call this method before using the object. This method also initializes the char indices246* array.247*248* @param initialGlyphCount the initial size of the glyph and char indices arrays.249* @param rightToLeft <code>true</code> if the original input text is right to left.250* @param success set to an error code if the storage cannot be allocated of if the initial251* glyph count is not positive.252*253* @stable ICU 3.0254*/255void allocateGlyphArray(le_int32 initialGlyphCount, le_bool rightToLeft, LEErrorCode &success);256257/**258* This method allocates the storage for the glyph positions. It allocates one extra X, Y259* position pair for the position just after the last glyph.260*261* @param success set to an error code if the positions array cannot be allocated.262*263* @return the number of X, Y position pairs allocated.264*265* @stable ICU 3.0266*/267le_int32 allocatePositions(LEErrorCode &success);268269/**270* This method allocates the storage for the auxillary glyph data.271*272* @param success set to an error code if the aulillary data array cannot be allocated.273*274* @return the size of the auxillary data array.275*276* @stable ICU 3.6277*/278le_int32 allocateAuxData(LEErrorCode &success);279280/**281* Copy the entire auxillary data array.282*283* @param auxData the auxillary data array will be copied to this address284* @param success set to an error code if the data cannot be copied285*286* @stable ICU 3.6287*/288void getAuxData(le_uint32 auxData[], LEErrorCode &success) const;289290/**291* Get the glyph ID for a particular glyph.292*293* @param glyphIndex the index into the glyph array294* @param success set to an error code if the glyph ID cannot be retrieved.295*296* @return the glyph ID297*298* @stable ICU 3.0299*/300LEGlyphID getGlyphID(le_int32 glyphIndex, LEErrorCode &success) const;301302/**303* Get the char index for a particular glyph.304*305* @param glyphIndex the index into the glyph array306* @param success set to an error code if the char index cannot be retrieved.307*308* @return the character index309*310* @stable ICU 3.0311*/312le_int32 getCharIndex(le_int32 glyphIndex, LEErrorCode &success) const;313314315/**316* Get the auxillary data for a particular glyph.317*318* @param glyphIndex the index into the glyph array319* @param success set to an error code if the auxillary data cannot be retrieved.320*321* @return the auxillary data322*323* @stable ICU 3.6324*/325le_uint32 getAuxData(le_int32 glyphIndex, LEErrorCode &success) const;326327/**328* This operator allows direct access to the glyph array329* using the index operator.330*331* @param glyphIndex the index into the glyph array332*333* @return a reference to the given location in the glyph array334*335* @stable ICU 3.0336*/337inline LEGlyphID &operator[](le_int32 glyphIndex) const;338339/**340* Call this method to replace a single glyph in the glyph array341* with multiple glyphs. This method uses the <code>LEInsertionList</code>342* to do the insertion. It returns the address of storage where the new343* glyph IDs can be stored. They will not actually be inserted into the344* glyph array until <code>applyInsertions</code> is called.345*346* @param atIndex the index of the glyph to be replaced347* @param insertCount the number of glyphs to replace it with348* @param success set to an error code if the auxillary data cannot be retrieved.349*350* @return the address at which to store the replacement glyphs.351*352* @see LEInsertionList.h353*354* @stable ICU 4.2355*/356LEGlyphID *insertGlyphs(le_int32 atIndex, le_int32 insertCount, LEErrorCode& success);357358/**359* Call this method to replace a single glyph in the glyph array360* with multiple glyphs. This method uses the <code>LEInsertionList</code>361* to do the insertion. It returns the address of storage where the new362* glyph IDs can be stored. They will not actually be inserted into the363* glyph array until <code>applyInsertions</code> is called.364*365* Note: Don't use this version, use the other version of this function which has an error code.366*367* @param atIndex the index of the glyph to be replaced368* @param insertCount the number of glyphs to replace it with369*370* @return the address at which to store the replacement glyphs.371*372* @see LEInsertionList.h373*374* @stable ICU 3.0375*/376LEGlyphID *insertGlyphs(le_int32 atIndex, le_int32 insertCount);377378/**379* This method is used to reposition glyphs during Indic v2 processing. It moves380* all of the relevant glyph information ( glyph, indices, positions, and auxData ),381* from the source position to the target position, and also allows for a marker bit382* to be set in the target glyph's auxData so that it won't be reprocessed later in the383* cycle.384*385* @param fromPosition - position of the glyph to be moved386* @param toPosition - target position of the glyph387* @param marker marker bit388*389* @stable ICU 4.2390*/391void moveGlyph(le_int32 fromPosition, le_int32 toPosition, le_uint32 marker);392393/**394* This method causes all of the glyph insertions recorded by395* <code>insertGlyphs</code> to be applied to the glyph array. The396* new slots in the char indices and the auxillary data arrays397* will be filled in with the values for the glyph being replaced.398*399* @return the new size of the glyph array400*401* @see LEInsertionList.h402*403* @stable ICU 3.0404*/405le_int32 applyInsertions();406407/**408* Set the glyph ID for a particular glyph.409*410* @param glyphIndex the index of the glyph411* @param glyphID the new glyph ID412* @param success will be set to an error code if the glyph ID cannot be set.413*414* @stable ICU 3.0415*/416void setGlyphID(le_int32 glyphIndex, LEGlyphID glyphID, LEErrorCode &success);417418/**419* Set the char index for a particular glyph.420*421* @param glyphIndex the index of the glyph422* @param charIndex the new char index423* @param success will be set to an error code if the char index cannot be set.424*425* @stable ICU 3.0426*/427void setCharIndex(le_int32 glyphIndex, le_int32 charIndex, LEErrorCode &success);428429/**430* Set the X, Y position for a particular glyph.431*432* @param glyphIndex the index of the glyph433* @param x the new X position434* @param y the new Y position435* @param success will be set to an error code if the position cannot be set.436*437* @stable ICU 3.0438*/439void setPosition(le_int32 glyphIndex, float x, float y, LEErrorCode &success);440441/**442* Adjust the X, Y position for a particular glyph.443*444* @param glyphIndex the index of the glyph445* @param xAdjust the adjustment to the glyph's X position446* @param yAdjust the adjustment to the glyph's Y position447* @param success will be set to an error code if the glyph's position cannot be adjusted.448*449* @stable ICU 3.0450*/451void adjustPosition(le_int32 glyphIndex, float xAdjust, float yAdjust, LEErrorCode &success);452453/**454* Set the auxillary data for a particular glyph.455*456* @param glyphIndex the index of the glyph457* @param auxData the new auxillary data458* @param success will be set to an error code if the auxillary data cannot be set.459*460* @stable ICU 3.6461*/462void setAuxData(le_int32 glyphIndex, le_uint32 auxData, LEErrorCode &success);463464/**465* Delete the glyph array and replace it with the one466* in <code>from</code>. Set the glyph array pointer467* in <code>from</code> to <code>NULL</code>.468*469* @param from the <code>LEGlyphStorage</code> object from which470* to get the new glyph array.471*472* @stable ICU 3.0473*/474void adoptGlyphArray(LEGlyphStorage &from);475476/**477* Delete the char indices array and replace it with the one478* in <code>from</code>. Set the char indices array pointer479* in <code>from</code> to <code>NULL</code>.480*481* @param from the <code>LEGlyphStorage</code> object from which482* to get the new char indices array.483*484* @stable ICU 3.0485*/486void adoptCharIndicesArray(LEGlyphStorage &from);487488/**489* Delete the position array and replace it with the one490* in <code>from</code>. Set the position array pointer491* in <code>from</code> to <code>NULL</code>.492*493* @param from the <code>LEGlyphStorage</code> object from which494* to get the new position array.495*496* @stable ICU 3.0497*/498void adoptPositionArray(LEGlyphStorage &from);499500/**501* Delete the auxillary data array and replace it with the one502* in <code>from</code>. Set the auxillary data array pointer503* in <code>from</code> to <code>NULL</code>.504*505* @param from the <code>LEGlyphStorage</code> object from which506* to get the new auxillary data array.507*508* @stable ICU 3.0509*/510void adoptAuxDataArray(LEGlyphStorage &from);511512/**513* Change the glyph count of this object to be the same514* as the one in <code>from</code>.515*516* @param from the <code>LEGlyphStorage</code> object from which517* to get the new glyph count.518*519* @stable ICU 3.0520*/521void adoptGlyphCount(LEGlyphStorage &from);522523/**524* Change the glyph count of this object to the given value.525*526* @param newGlyphCount the new glyph count.527*528* @stable ICU 3.0529*/530void adoptGlyphCount(le_int32 newGlyphCount);531532/**533* This method frees the glyph, character index, position and534* auxillary data arrays so that the LayoutEngine can be reused535* to layout a different characer array. (This method is also called536* by the destructor)537*538* @stable ICU 3.0539*/540void reset();541542/**543* ICU "poor man's RTTI", returns a UClassID for the actual class.544*545* @stable ICU 3.0546*/547virtual UClassID getDynamicClassID() const;548549/**550* ICU "poor man's RTTI", returns a UClassID for this class.551*552* @stable ICU 3.0553*/554static UClassID getStaticClassID();555};556557inline le_int32 LEGlyphStorage::getGlyphCount() const558{559return fGlyphCount;560}561562inline LEGlyphID &LEGlyphStorage::operator[](le_int32 glyphIndex) const563{564return fGlyphs[glyphIndex];565}566567568U_NAMESPACE_END569#endif570571572