ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParagraphLayout.h
Go to the documentation of this file.
1 /*
2  **********************************************************************
3  * Copyright (C) 2002-2010, International Business Machines
4  * Corporation and others. All Rights Reserved.
5  **********************************************************************
6  */
7 
8 #ifndef __PARAGRAPHLAYOUT_H
9 
10 #define __PARAGRAPHLAYOUT_H
11 
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"
25 #include "layout/LEFontInstance.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 {
46 public:
47  class VisualRun;
48 
60  class U_LAYOUTEX_API Line : public UObject
61  {
62  public:
71  ~Line();
72 
80  inline le_int32 countRuns() const;
81 
90  le_int32 getAscent() const;
91 
100  le_int32 getDescent() const;
101 
110  le_int32 getLeading() const;
111 
121  le_int32 getWidth() const;
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 
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 
403  ~ParagraphLayout();
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
409 
424  static le_bool isComplex(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns);
425 #else
426 
438  static le_bool isComplex(const LEUnicode chars[], le_int32 count);
439 
440 #endif
441 
451  inline UBiDiLevel getParagraphLevel();
452 
462  inline UBiDiDirection getTextDirection();
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();
510  inline le_bool isDone() const;
511 
529  Line *nextLine(float width);
530 
536  static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
537 
543  virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
544 
545 private:
546 
547 
552  static const char fgClassID;
553 
554  struct StyleRunInfo
555  {
556  LayoutEngine *engine;
557  const LEFontInstance *font;
558  const Locale *locale;
559  LEGlyphID *glyphs;
560  float *positions;
561  UScriptCode script;
562  UBiDiLevel level;
563  le_int32 runBase;
564  le_int32 runLimit;
565  le_int32 glyphBase;
566  le_int32 glyphCount;
567  };
568 
569  ParagraphLayout() {};
570  ParagraphLayout(const ParagraphLayout & /*other*/) : UObject( ){};
571  inline ParagraphLayout &operator=(const ParagraphLayout & /*other*/) { return *this; };
572 
573  void computeLevels(UBiDiLevel paragraphLevel);
574 
575  Line *computeVisualRuns();
576  void appendRun(Line *line, le_int32 run, le_int32 firstChar, le_int32 lastChar);
577 
578  void computeScripts();
579 
580  void computeLocales();
581 
582  void computeSubFonts(const FontRuns *fontRuns, LEErrorCode &status);
583 
584  void computeMetrics();
585 
586  le_int32 getLanguageCode(const Locale *locale);
587 
588  le_int32 getCharRun(le_int32 charIndex);
589 
590  static le_bool isComplex(UScriptCode script);
591 
592  le_int32 previousBreak(le_int32 charIndex);
593 
594 
595  const LEUnicode *fChars;
596  le_int32 fCharCount;
597 
598  const FontRuns *fFontRuns;
599  const ValueRuns *fLevelRuns;
600  const ValueRuns *fScriptRuns;
601  const LocaleRuns *fLocaleRuns;
602 
603  le_bool fVertical;
604  le_bool fClientLevels;
605  le_bool fClientScripts;
606  le_bool fClientLocales;
607 
608  UBiDiLevel *fEmbeddingLevels;
609 
610  le_int32 fAscent;
611  le_int32 fDescent;
612  le_int32 fLeading;
613 
614  le_int32 *fGlyphToCharMap;
615  le_int32 *fCharToMinGlyphMap;
616  le_int32 *fCharToMaxGlyphMap;
617  float *fGlyphWidths;
618  le_int32 fGlyphCount;
619 
620  UBiDi *fParaBidi;
621  UBiDi *fLineBidi;
622 
623  le_int32 *fStyleRunLimits;
624  le_int32 *fStyleIndices;
625  StyleRunInfo *fStyleRunInfo;
626  le_int32 fStyleRunCount;
627 
628  BreakIterator *fBreakIterator;
629  le_int32 fLineStart;
630  le_int32 fLineEnd;
631 
632  le_int32 fFirstVisualRun;
633  le_int32 fLastVisualRun;
634  float fVisualRunLastX;
635  float fVisualRunLastY;
636 };
637 
639 {
640  return ubidi_getParaLevel(fParaBidi);
641 }
642 
644 {
645  return ubidi_getDirection(fParaBidi);
646 }
647 
649 {
650  fLineEnd = 0;
651 }
652 
653 inline ParagraphLayout::Line::Line()
654  : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
655 {
656  // nothing else to do
657 }
658 
659 inline ParagraphLayout::Line::Line(const Line & /*other*/)
660  : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
661 {
662  // nothing else to do
663 }
664 
666 {
667  return fRunCount;
668 }
669 
671 {
672  return fFont;
673 }
674 
676 {
677  return fDirection;
678 }
679 
681 {
682  return fGlyphCount;
683 }
684 
686 {
687  return fGlyphs;
688 }
689 
690 inline const float *ParagraphLayout::VisualRun::getPositions() const
691 {
692  return fPositions;
693 }
694 
696 {
697  return fGlyphToCharMap;
698 }
699 
701 {
702  return fFont->getAscent();
703 }
704 
706 {
707  return fFont->getDescent();
708 }
709 
711 {
712  return fFont->getLeading();
713 }
714 
715 inline ParagraphLayout::VisualRun::VisualRun()
716  : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
717 {
718  // nothing
719 }
720 
721 inline ParagraphLayout::VisualRun::VisualRun(const VisualRun &/*other*/)
722  : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
723 {
724  // nothing
725 }
726 
727 inline ParagraphLayout::VisualRun::VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
728  const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[])
729  : fFont(font), fDirection(direction), fGlyphCount(glyphCount),
730  fGlyphs(glyphs), fPositions(positions), fGlyphToCharMap(glyphToCharMap)
731 {
732  // nothing else needs to be done!
733 }
734 
736 #endif
737 #endif
C++ API: Break Iterator.
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.
void reflow()
Reset line breaking to start from the beginning of the paragraph.
le_int32 getGlyphCount() const
Get the number of glyphs in the visual run.
The BreakIterator class implements methods for finding the location of boundaries in text...
Definition: brkiter.h:100
The FontRuns class associates pointers to LEFontInstance objects with runs of text.
Definition: RunArrays.h:270
This object represents a single visual run in a line of text in a paragraph.
C API: Bidi algorithm.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
This is a virtual base class used to do complex text layout.
Definition: LayoutEngine.h:64
const float * getPositions() const
Get the (x, y) positions of the glyphs in the visual run.
UBiDiDirection getTextDirection()
Return the directionality of the text in the paragraph.
UScriptCode
Constants for ISO 15924 script codes.
Definition: uscript.h:46
uint8_t UBiDiLevel
UBiDiLevel is the type of the level values in this Bidi implementation.
Definition: ubidi.h:330
C API: Basic definitions for the ICU LayoutEngine.
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
le_int32 getLeading() const
A convenience method which returns the leading value for the font associated with this run...
C API: Unicode Script Information.
UBiDiDirection getDirection() const
Get the direction of the visual run.
UBiDiDirection
UBiDiDirection values indicate the text direction.
Definition: ubidi.h:417
const LEGlyphID * getGlyphs() const
Get the glyphs in the visual run.
UBiDiDirection ubidi_getDirection(const UBiDi *pBiDi)
Get the directionality of the text.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
This is a virtual base class that serves as the interface between a LayoutEngine and the platform fon...
le_int32 getDescent() const
A convenience method which returns the descent value for the font associated with this run...
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:299
UBiDiLevel ubidi_getParaLevel(const UBiDi *pBiDi)
Get the paragraph level of the text.
The ValueRuns class associates integer values with runs of text.
Definition: RunArrays.h:546
This class represents a single line of text in a ParagraphLayout.
C++ API: Virtual base class for complex text layout.
The LocaleRuns class associates pointers to Locale objects with runs of text.
Definition: RunArrays.h:407
LEErrorCode
Error codes returned by the LayoutEngine.
Definition: LETypes.h:528
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
le_int32 getAscent() const
A convenience method which returns the ascent value for the font associated with this run...
ParagraphLayout.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
Left-to-right text.
Definition: ubidi.h:429
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:215
struct UBiDi UBiDi
Definition: ubidi.h:474
#define U_LAYOUTEX_API
Set to export library symbols from inside the layout extensions library, and to import them from outs...
Definition: utypes.h:523
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:385
C++ API: base class for building classes which represent data that is associated with runs of text...
UChar LEUnicode
Used to represent 16-bit Unicode code points.
Definition: LETypes.h:237
le_uint32 LEGlyphID
Used for glyph indices.
Definition: LETypes.h:112
const LEFontInstance * getFont() const
Get the LEFontInstance object which represents the font of the visual run.
const le_int32 * getGlyphToCharMap() const
Get the glyph-to-character map for this visual run.
UBiDiLevel getParagraphLevel()
Return the resolved paragraph level.
C++ API: Layout Engine Font Instance object.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:181