1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
/*
* @(#)loengine.h 1.0 00/12/11
*
* (C) Copyright IBM Corp. 1998, 1999, 2000 - All Rights Reserved
*
*/
#ifndef __LOENGINE_H
#define __LOENGINE_H
#include "unicode/utypes.h"
#include "unicode/uscript.h"
#include "unicode/unistr.h"
#include "layout/LETypes.h"
#include "layout/LayoutEngine.h"
U_NAMESPACE_BEGIN
/**
* This is a wrapper class designed to allow ICU clients to
* use LayoutEngine in a way that is consistent with the rest
* of ICU.
*
* (LayoutEngine was developed seperately from ICU and
* the same source is used in non-ICU environments, so it cannot
* be changed to match ICU coding conventions).
*
* This class is designed for clients who wish to use LayoutEngine
* to layout complex text. If you need to subclass LayoutEngine,
* you'll need to use the LayoutEngine interfaces directly.
*
* Basically, it creates an instance of LayoutEngine, stashes
* it in fLayoutEngine, and uses it to implement the layout
* functionality.
*
* Use the createInstance method to create an ICULayoutEngine. Use
* delete to destroy it. The layoutChars method computes the glyphs
* and positions, and saves them in the ICULayoutEngine object.
* Use getGlyphs, getPositions and getCharIndices to retreive this
* data.
*
* You'll also need an implementation of LEFontInstance for your platform.
*
* @see LayoutEngine.h
* @see LEFontInstance.h
*/
class U_LAYOUT_API ICULayoutEngine
{
private:
/**
* This holds the instance of LayoutEngine that does all
* the work.
*/
LayoutEngine *fLayoutEngine;
/**
* This no argument constructor is private so that clients
* can't envoke it. Clients should use createInstance.
*
* @see createInstance
*/
ICULayoutEngine();
/**
* The main constructor. It is defined as private to
* stop clients from invoking it. Clients should use
* createInstance.
*
* @param layoutEngine - the LayoutEngine that this instance wraps.
*
* @see createInstance
*/
ICULayoutEngine(LayoutEngine *layoutEngine);
public:
/**
* The destructor. At least on Windows it needs to be
* virtual to ensure that it deletes the object from the
* same heap that createInstance will allocate it from. We
* don't know why this is...
*
* @see createInstance
*/
virtual ~ICULayoutEngine();
/**
* This method computes the glyph, character index and position arrays
* for the input characters.
*
* @param chars - the input character context
* @param startOffset - the starting offset of the characters to process
* @param endOffset - the ending offset of the characters to process
* @param max - the number of characters in the input context
* @param rightToLeft - true if the characers are in a right to left directional run
* @param x - the initial X position
* @param y - the initial Y position
* @param success - output parameter set to an error code if the operation fails
*
* @return the number of glyphs in the glyph array
*
* Note; the glyph, character index and position array can be accessed
* using the getter method below.
*/
int32_t layoutChars(const UChar chars[],
int32_t startOffset,
int32_t endOffset,
int32_t maxOffset,
UBool rightToLeft,
float x, float y,
UErrorCode &success);
/**
* This method computes the glyph, character index and position arrays
* for the input characters.
*
* @param str - the input character context
* @param startOffset - the starting offset of the characters to process
* @param endOffset - the ending offset of the characters to process
* @param rightToLeft - true if the characers are in a right to left directional run
* @param x - the initial X position
* @param y - the initial Y position
* @param success - output parameter set to an error code if the operation fails
*
* @return the number of glyphs in the glyph array
*
* Note; the glyph, character index and position array can be accessed
* using the getter method below.
*/
int32_t layoutString(const UnicodeString &str,
int32_t startOffset,
int32_t endOffset,
UBool rightToLeft,
float x, float y,
UErrorCode &success);
/**
* This method returns the number of glyphs in the glyph array. Note
* that the number of glyphs will be greater than or equal to the number
* of characters used to create the LayoutEngine.
*
* @return the number of glyphs in the glyph array
*/
int32_t countGlyphs() const;
/**
* This method copies the glyph array into a caller supplied array.
* The caller must ensure that the array is large enough to hold all
* the glyphs.
*
* @param glyphs - the destiniation glyph array
* @param success - output parameter set to an error code if the operation fails
*/
void getGlyphs(uint16_t glyphs[], UErrorCode &success);
/**
* This method copies the character index array into a caller supplied array.
* The caller must ensure that the array is large enough to hold a character
* index for each glyph.
*
* @param charIndices - the destiniation character index array
* @param success - output parameter set to an error code if the operation fails
*/
void getCharIndices(int32_t charIndices[], UErrorCode &success);
/**
* This method copies the character index array into a caller supplied array.
* The caller must ensure that the array is large enough to hold a character
* index for each glyph.
*
* @param charIndices - the destiniation character index array
* @param indexBase - an offset which will be added to each index
* @param success - output parameter set to an error code if the operation fails
*/
void getCharIndices(int32_t charIndices[], int32_t indexBase, UErrorCode &success);
/**
* This method copies the position array into a caller supplied array.
* The caller must ensure that the array is large enough to hold an
* X and Y position for each glyph, plus an extra X and Y for the
* advance of the last glyph.
*
* @param glyphs - the destiniation position array
* @param success - output parameter set to an error code if the operation fails
*/
void getGlyphPositions(float positions[], UErrorCode &success);
/**
* This method returns the X and Y position of the glyph at the
* given index.
*
* Input parameters:
* @param glyphIndex - the index of the glyph
*
* Output parameters:
* @param x - the glyph's X position
* @param y - the glyph's Y position
* @param success - output parameter set to an error code if the operation fails
*
*/
void getGlyphPosition(int32_t glyphIndex, float &x, float &y, UErrorCode &success);
/**
* This method returns an ICULayoutEngine capable of laying out text
* in the given font, script and langauge.
*
* @param fontInstance - the font of the text
* @param scriptCode - the script of the text
* @param locale - used to determine the language of the text
* @param success - output parameter set to an error code if the operation fails
*
* @return an ICULayoutEngine which can layout text in the given font.
*
* NOTE: currently, locale is ignored...
*
* @see LEFontInstance
*/
static ICULayoutEngine *createInstance(const LEFontInstance *fontInstance,
UScriptCode script, Locale &locale,
UErrorCode &success);
};
inline ICULayoutEngine::ICULayoutEngine()
{
// nothing at all...
}
inline ICULayoutEngine::ICULayoutEngine(LayoutEngine *layoutEngine)
: fLayoutEngine(layoutEngine)
{
// nothing else to do
}
inline ICULayoutEngine::~ICULayoutEngine()
{
delete fLayoutEngine;
fLayoutEngine = 0;
}
inline int32_t ICULayoutEngine::layoutChars(const UChar chars[],
int32_t startOffset,
int32_t endOffset,
int32_t maxOffset,
UBool rightToLeft,
float x, float y,
UErrorCode &success)
{
// NOTE: call reset() so that clients can safely reuse
fLayoutEngine->reset();
return fLayoutEngine->layoutChars(chars,
startOffset,
endOffset - startOffset,
maxOffset,
rightToLeft,
x, y,
(LEErrorCode &) success);
}
inline int32_t ICULayoutEngine::layoutString(const UnicodeString &str,
int32_t startOffset,
int32_t endOffset,
UBool rightToLeft,
float x, float y,
UErrorCode &success)
{
int32_t glyphCount = 0;
int32_t max = str.length();
UChar *chars = new UChar[max];
str.extract(0, max, chars);
// NOTE: call reset() so that clients can safely reuse
fLayoutEngine->reset();
glyphCount = fLayoutEngine->layoutChars(chars,
startOffset,
endOffset - startOffset,
max,
rightToLeft,
x, y,
(LEErrorCode &) success);
delete[] chars;
return glyphCount;
}
inline int32_t ICULayoutEngine::countGlyphs() const
{
return fLayoutEngine->getGlyphCount();
}
inline void ICULayoutEngine::getGlyphs(uint16_t glyphs[], UErrorCode &success)
{
fLayoutEngine->getGlyphs(glyphs, (LEErrorCode &) success);
}
inline void ICULayoutEngine::getCharIndices(int32_t charIndices[], UErrorCode &success)
{
fLayoutEngine->getCharIndices(charIndices, (LEErrorCode &) success);
}
inline void ICULayoutEngine::getCharIndices(int32_t charIndices[], int32_t indexBase, UErrorCode &success)
{
fLayoutEngine->getCharIndices(charIndices, indexBase, (LEErrorCode &) success);
}
inline void ICULayoutEngine::getGlyphPositions(float positions[], UErrorCode &success)
{
fLayoutEngine->getGlyphPositions(positions, (LEErrorCode &) success);
}
inline void ICULayoutEngine::getGlyphPosition(int32_t glyphIndex, float &x, float &y, UErrorCode &success)
{
fLayoutEngine->getGlyphPosition(glyphIndex, x, y, (LEErrorCode &) success);
}
inline ICULayoutEngine *ICULayoutEngine::createInstance(const LEFontInstance *fontInstance,
UScriptCode script,
Locale &locale, UErrorCode &success)
{
LayoutEngine *engine = LayoutEngine::layoutEngineFactory(fontInstance,
(le_int32) script,
0,
(LEErrorCode &) success);
return new ICULayoutEngine(engine);
}
U_NAMESPACE_END
#endif
|