ICU 50.2 50.2
ParagraphLayout.h
Go to the documentation of this file.
1/*
2 **********************************************************************
3 * Copyright (C) 2002-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 */
7
8#ifndef __PARAGRAPHLAYOUT_H
9
10#define __PARAGRAPHLAYOUT_H
11
16
17/*
18 * ParagraphLayout doesn't make much sense without
19 * BreakIterator...
20 */
21#include "unicode/uscript.h"
22#if ! UCONFIG_NO_BREAK_ITERATION
23
24#include "layout/LETypes.h"
26#include "layout/LayoutEngine.h"
27#include "unicode/ubidi.h"
28#include "unicode/brkiter.h"
29
30#include "layout/RunArrays.h"
31
33
45{
46public:
47 class VisualRun;
48
60 class U_LAYOUTEX_API Line : public UObject
61 {
62 public:
72
80 inline le_int32 countRuns() const;
81
91
101
111
122
138 const VisualRun *getVisualRun(le_int32 runIndex) const;
139
145 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
146
152 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
153
154 private:
155
160 static const char fgClassID;
161
162 friend class ParagraphLayout;
163
164 le_int32 fAscent;
165 le_int32 fDescent;
166 le_int32 fLeading;
167
168 le_int32 fRunCount;
169 le_int32 fRunCapacity;
170
171 VisualRun **fRuns;
172
173 inline Line();
174 inline Line(const Line &other);
175 inline Line &operator=(const Line & /*other*/) { return *this; };
176
177 void computeMetrics();
178
179 void append(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
180 const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
181 };
182
198 class U_LAYOUTEX_API VisualRun : public UObject
199 {
200 public:
213 inline const LEFontInstance *getFont() const;
214
223 inline UBiDiDirection getDirection() const;
224
232 inline le_int32 getGlyphCount() const;
233
244 inline const LEGlyphID *getGlyphs() const;
245
259 inline const float *getPositions() const;
260
271 inline const le_int32 *getGlyphToCharMap() const;
272
281 inline le_int32 getAscent() const;
282
291 inline le_int32 getDescent() const;
292
301 inline le_int32 getLeading() const;
302
308 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
309
315 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
316
317 private:
318
323 static const char fgClassID;
324
325 const LEFontInstance *fFont;
326 const UBiDiDirection fDirection;
327
328 const le_int32 fGlyphCount;
329
330 const LEGlyphID *fGlyphs;
331 const float *fPositions;
332 const le_int32 *fGlyphToCharMap;
333
334 friend class Line;
335
336 inline VisualRun();
337 inline VisualRun(const VisualRun &other);
338 inline VisualRun &operator=(const VisualRun &/*other*/) { return *this; };
339
340 inline VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
341 const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
342
343 ~VisualRun();
344 };
345
389 ParagraphLayout(const LEUnicode chars[], le_int32 count,
390 const FontRuns *fontRuns,
391 const ValueRuns *levelRuns,
392 const ValueRuns *scriptRuns,
393 const LocaleRuns *localeRuns,
394 UBiDiLevel paragraphLevel, le_bool vertical,
395 LEErrorCode &status);
396
404
405 // Note: the following is #if 0'd out because there's no good
406 // way to implement it without either calling layoutEngineFactory()
407 // or duplicating the logic there...
408#if 0
424 static le_bool isComplex(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns);
425#else
438 static le_bool isComplex(const LEUnicode chars[], le_int32 count);
439
440#endif
441
452
463
472 virtual le_int32 getAscent() const;
473
482 virtual le_int32 getDescent() const;
483
492 virtual le_int32 getLeading() const;
493
500 inline void reflow();
501
502#ifndef U_HIDE_INTERNAL_API
512 inline le_bool isDone() const;
513#endif /* U_HIDE_INTERNAL_API */
514
532 Line *nextLine(float width);
533
539 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
540
546 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
547
548private:
549
550
555 static const char fgClassID;
556
557 struct StyleRunInfo
558 {
559 LayoutEngine *engine;
560 const LEFontInstance *font;
561 const Locale *locale;
562 LEGlyphID *glyphs;
563 float *positions;
564 UScriptCode script;
565 UBiDiLevel level;
566 le_int32 runBase;
567 le_int32 runLimit;
568 le_int32 glyphBase;
569 le_int32 glyphCount;
570 };
571
572 ParagraphLayout() {};
573 ParagraphLayout(const ParagraphLayout & /*other*/) : UObject( ){};
574 inline ParagraphLayout &operator=(const ParagraphLayout & /*other*/) { return *this; };
575
576 void computeLevels(UBiDiLevel paragraphLevel);
577
578 Line *computeVisualRuns();
579 void appendRun(Line *line, le_int32 run, le_int32 firstChar, le_int32 lastChar);
580
581 void computeScripts();
582
583 void computeLocales();
584
585 void computeSubFonts(const FontRuns *fontRuns, LEErrorCode &status);
586
587 void computeMetrics();
588
589 le_int32 getLanguageCode(const Locale *locale);
590
591 le_int32 getCharRun(le_int32 charIndex);
592
593 static le_bool isComplex(UScriptCode script);
594
595 le_int32 previousBreak(le_int32 charIndex);
596
597
598 const LEUnicode *fChars;
599 le_int32 fCharCount;
600
601 const FontRuns *fFontRuns;
602 const ValueRuns *fLevelRuns;
603 const ValueRuns *fScriptRuns;
604 const LocaleRuns *fLocaleRuns;
605
606 le_bool fVertical;
607 le_bool fClientLevels;
608 le_bool fClientScripts;
609 le_bool fClientLocales;
610
611 UBiDiLevel *fEmbeddingLevels;
612
613 le_int32 fAscent;
614 le_int32 fDescent;
615 le_int32 fLeading;
616
617 le_int32 *fGlyphToCharMap;
618 le_int32 *fCharToMinGlyphMap;
619 le_int32 *fCharToMaxGlyphMap;
620 float *fGlyphWidths;
621 le_int32 fGlyphCount;
622
623 UBiDi *fParaBidi;
624 UBiDi *fLineBidi;
625
626 le_int32 *fStyleRunLimits;
627 le_int32 *fStyleIndices;
628 StyleRunInfo *fStyleRunInfo;
629 le_int32 fStyleRunCount;
630
631 BreakIterator *fBreakIterator;
632 le_int32 fLineStart;
633 le_int32 fLineEnd;
634
635 le_int32 fFirstVisualRun;
636 le_int32 fLastVisualRun;
637 float fVisualRunLastX;
638 float fVisualRunLastY;
639};
640
642{
643 return ubidi_getParaLevel(fParaBidi);
644}
645
650
652{
653 fLineEnd = 0;
654}
655
656inline ParagraphLayout::Line::Line()
657 : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
658{
659 // nothing else to do
660}
661
662inline ParagraphLayout::Line::Line(const Line & /*other*/)
663 : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
664{
665 // nothing else to do
666}
667
669{
670 return fRunCount;
671}
672
674{
675 return fFont;
676}
677
679{
680 return fDirection;
681}
682
684{
685 return fGlyphCount;
686}
687
689{
690 return fGlyphs;
691}
692
694{
695 return fPositions;
696}
697
699{
700 return fGlyphToCharMap;
701}
702
704{
705 return fFont->getAscent();
706}
707
709{
710 return fFont->getDescent();
711}
712
714{
715 return fFont->getLeading();
716}
717
718inline ParagraphLayout::VisualRun::VisualRun()
719 : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
720{
721 // nothing
722}
723
724inline ParagraphLayout::VisualRun::VisualRun(const VisualRun &/*other*/)
725 : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
726{
727 // nothing
728}
729
730inline ParagraphLayout::VisualRun::VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
731 const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[])
732 : fFont(font), fDirection(direction), fGlyphCount(glyphCount),
733 fGlyphs(glyphs), fPositions(positions), fGlyphToCharMap(glyphToCharMap)
734{
735 // nothing else needs to be done!
736}
737
739#endif
740#endif
C++ API: Layout Engine Font Instance object.
C API: Basic definitions for the ICU LayoutEngine.
LEErrorCode
Error codes returned by the LayoutEngine.
Definition LETypes.h:678
int32_t le_int32
A type used for signed, 32-bit integers.
Definition LETypes.h:34
UBool le_bool
A type used for boolean values.
Definition LETypes.h:77
UChar LEUnicode
Used to represent 16-bit Unicode code points.
Definition LETypes.h:238
le_uint32 LEGlyphID
Used for glyph indices.
Definition LETypes.h:112
C++ API: Virtual base class for complex text layout.
C++ API: base class for building classes which represent data that is associated with runs of text.
C++ API: Break Iterator.
The FontRuns class associates pointers to LEFontInstance objects with runs of text.
Definition RunArrays.h:271
This is a virtual base class that serves as the interface between a LayoutEngine and the platform fon...
This is a virtual base class used to do complex text layout.
The LocaleRuns class associates pointers to Locale objects with runs of text.
Definition RunArrays.h:408
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
This class represents a single line of text in a ParagraphLayout.
~Line()
The constructor is private since these objects can only be created by ParagraphLayout.
le_int32 countRuns() const
Count the number of visual runs in the line.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
const VisualRun * getVisualRun(le_int32 runIndex) const
Get a ParagraphLayout::VisualRun object for a given visual run in the line.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
le_int32 getLeading() const
Get the leading of the line.
le_int32 getDescent() const
Get the descent of the line.
le_int32 getAscent() const
Get the ascent of the line.
le_int32 getWidth() const
Get the width of the line.
This object represents a single visual run in a line of text in a paragraph.
le_int32 getDescent() const
A convenience method which returns the descent value for the font associated with this run.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
const le_int32 * getGlyphToCharMap() const
Get the glyph-to-character map for this visual run.
le_int32 getGlyphCount() const
Get the number of glyphs in the visual run.
const LEGlyphID * getGlyphs() const
Get the glyphs in the visual run.
le_int32 getAscent() const
A convenience method which returns the ascent value for the font associated with this run.
const LEFontInstance * getFont() const
Get the LEFontInstance object which represents the font of the visual run.
UBiDiDirection getDirection() const
Get the direction of the visual run.
le_int32 getLeading() const
A convenience method which returns the leading value for the font associated with this run.
const float * getPositions() const
Get the (x, y) positions of the glyphs in the visual run.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
UBiDiDirection getTextDirection()
Return the directionality of the text in the paragraph.
~ParagraphLayout()
The destructor.
void reflow()
Reset line breaking to start from the beginning of the paragraph.
le_bool isDone() const
Convenience method for determining if paragraph layout processing is complete ( i....
ParagraphLayout(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns, const ValueRuns *levelRuns, const ValueRuns *scriptRuns, const LocaleRuns *localeRuns, UBiDiLevel paragraphLevel, le_bool vertical, LEErrorCode &status)
Construct a ParagraphLayout object for a styled paragraph.
virtual le_int32 getLeading() const
Return the max leading value for all the fonts in the paragraph.
Line * nextLine(float width)
Return a ParagraphLayout::Line object which represents next line in the paragraph.
virtual le_int32 getDescent() const
Return the max descent value for all the fonts in the paragraph.
UBiDiLevel getParagraphLevel()
Return the resolved paragraph level.
virtual le_int32 getAscent() const
Return the max ascent value for all the fonts in the paragraph.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
static le_bool isComplex(const LEUnicode chars[], le_int32 count)
Examine the given text and determine if it contains characters in any script which requires complex p...
UObject is the common ICU "boilerplate" class.
Definition uobject.h:229
The ValueRuns class associates integer values with runs of text.
Definition RunArrays.h:547
C API: Bidi algorithm.
UBiDiLevel ubidi_getParaLevel(const UBiDi *pBiDi)
Get the paragraph level of the text.
UBiDiDirection
UBiDiDirection values indicate the text direction.
Definition ubidi.h:417
@ UBIDI_LTR
Left-to-right text.
Definition ubidi.h:429
uint8_t UBiDiLevel
UBiDiLevel is the type of the level values in this Bidi implementation.
Definition ubidi.h:330
struct UBiDi UBiDi
Definition ubidi.h:474
UBiDiDirection ubidi_getDirection(const UBiDi *pBiDi)
Get the directionality of the text.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
C API: Unicode Script Information.
UScriptCode
Constants for ISO 15924 script codes.
Definition uscript.h:46
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition utypes.h:186
#define U_LAYOUTEX_API
Set to export library symbols from inside the layout extensions library, and to import them from outs...
Definition utypes.h:360
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129