ICU 4.2.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-2005, 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();
501 
519  Line *nextLine(float width);
520 
526  static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
527 
533  virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
534 
535 private:
536 
537 
542  static const char fgClassID;
543 
544  struct StyleRunInfo
545  {
546  LayoutEngine *engine;
547  const LEFontInstance *font;
548  const Locale *locale;
549  LEGlyphID *glyphs;
550  float *positions;
551  UScriptCode script;
552  UBiDiLevel level;
553  le_int32 runBase;
554  le_int32 runLimit;
555  le_int32 glyphBase;
556  le_int32 glyphCount;
557  };
558 
559  ParagraphLayout() {};
560  ParagraphLayout(const ParagraphLayout & /*other*/) : UObject( ){};
561  inline ParagraphLayout &operator=(const ParagraphLayout & /*other*/) { return *this; };
562 
563  void computeLevels(UBiDiLevel paragraphLevel);
564 
565  Line *computeVisualRuns();
566  void appendRun(Line *line, le_int32 run, le_int32 firstChar, le_int32 lastChar);
567 
568  void computeScripts();
569 
570  void computeLocales();
571 
572  void computeSubFonts(const FontRuns *fontRuns, LEErrorCode &status);
573 
574  void computeMetrics();
575 
576  le_int32 getLanguageCode(const Locale *locale);
577 
578  le_int32 getCharRun(le_int32 charIndex);
579 
580  static le_bool isComplex(UScriptCode script);
581 
582  le_int32 previousBreak(le_int32 charIndex);
583 
584 
585  const LEUnicode *fChars;
586  le_int32 fCharCount;
587 
588  const FontRuns *fFontRuns;
589  const ValueRuns *fLevelRuns;
590  const ValueRuns *fScriptRuns;
591  const LocaleRuns *fLocaleRuns;
592 
593  le_bool fVertical;
594  le_bool fClientLevels;
595  le_bool fClientScripts;
596  le_bool fClientLocales;
597 
598  UBiDiLevel *fEmbeddingLevels;
599 
600  le_int32 fAscent;
601  le_int32 fDescent;
602  le_int32 fLeading;
603 
604  le_int32 *fGlyphToCharMap;
605  le_int32 *fCharToMinGlyphMap;
606  le_int32 *fCharToMaxGlyphMap;
607  float *fGlyphWidths;
608  le_int32 fGlyphCount;
609 
610  UBiDi *fParaBidi;
611  UBiDi *fLineBidi;
612 
613  le_int32 *fStyleRunLimits;
614  le_int32 *fStyleIndices;
615  StyleRunInfo *fStyleRunInfo;
616  le_int32 fStyleRunCount;
617 
618  BreakIterator *fBreakIterator;
619  le_int32 fLineStart;
620  le_int32 fLineEnd;
621 
622  le_int32 fFirstVisualRun;
623  le_int32 fLastVisualRun;
624  float fVisualRunLastX;
625  float fVisualRunLastY;
626 };
627 
629 {
630  return ubidi_getParaLevel(fParaBidi);
631 }
632 
634 {
635  return ubidi_getDirection(fParaBidi);
636 }
637 
639 {
640  fLineEnd = 0;
641 }
642 
643 inline ParagraphLayout::Line::Line()
644  : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
645 {
646  // nothing else to do
647 }
648 
649 inline ParagraphLayout::Line::Line(const Line & /*other*/)
650  : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
651 {
652  // nothing else to do
653 }
654 
656 {
657  return fRunCount;
658 }
659 
661 {
662  return fFont;
663 }
664 
666 {
667  return fDirection;
668 }
669 
671 {
672  return fGlyphCount;
673 }
674 
676 {
677  return fGlyphs;
678 }
679 
680 inline const float *ParagraphLayout::VisualRun::getPositions() const
681 {
682  return fPositions;
683 }
684 
686 {
687  return fGlyphToCharMap;
688 }
689 
691 {
692  return fFont->getAscent();
693 }
694 
696 {
697  return fFont->getDescent();
698 }
699 
701 {
702  return fFont->getLeading();
703 }
704 
705 inline ParagraphLayout::VisualRun::VisualRun()
706  : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
707 {
708  // nothing
709 }
710 
711 inline ParagraphLayout::VisualRun::VisualRun(const VisualRun &/*other*/)
712  : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
713 {
714  // nothing
715 }
716 
717 inline ParagraphLayout::VisualRun::VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
718  const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[])
719  : fFont(font), fDirection(direction), fGlyphCount(glyphCount),
720  fGlyphs(glyphs), fPositions(positions), fGlyphToCharMap(glyphToCharMap)
721 {
722  // nothing else needs to be done!
723 }
724 
726 #endif
727 #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:67
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:183
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:266
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.
All left-to-right text.
Definition: ubidi.h:419
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API If the compiler doesn't support namespaces...
Definition: uversion.h:184
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:212
struct UBiDi UBiDi
Definition: ubidi.h:442
#define U_LAYOUTEX_API
Set to export library symbols from inside the layout extensions library, and to import them from outs...
Definition: utypes.h:477
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:339
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