ICU 50.1.2  50.1.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 
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 
502 #ifndef U_HIDE_INTERNAL_API
503 
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 
548 private:
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 
641 inline UBiDiLevel ParagraphLayout::getParagraphLevel()
642 {
643  return ubidi_getParaLevel(fParaBidi);
644 }
645 
646 inline UBiDiDirection ParagraphLayout::getTextDirection()
647 {
648  return ubidi_getDirection(fParaBidi);
649 }
650 
651 inline void ParagraphLayout::reflow()
652 {
653  fLineEnd = 0;
654 }
655 
656 inline 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 
662 inline 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 
693 inline const float *ParagraphLayout::VisualRun::getPositions() const
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 
718 inline ParagraphLayout::VisualRun::VisualRun()
719  : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
720 {
721  // nothing
722 }
723 
724 inline 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 
730 inline 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: 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.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
C API: Bidi algorithm.
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.
UBiDiDirection getDirection() const
Get the direction of the visual run.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UScriptCode
Constants for ISO 15924 script codes.
Definition: uscript.h:46
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
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.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
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
This object represents a single visual run in a line of text in a paragraph.
C API: Unicode Script Information.
UBiDiDirection
UBiDiDirection values indicate the text direction.
Definition: ubidi.h:417
This class represents a single line of text in a ParagraphLayout.
const float * getPositions() const
Get the (x, y) positions of 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:129
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:186
le_int32 getAscent() const
A convenience method which returns the ascent value for the font associated with this run...
This is a virtual base class used to do complex text layout.
Definition: LayoutEngine.h:64
UBiDiLevel ubidi_getParaLevel(const UBiDi *pBiDi)
Get the paragraph level of the text.
ParagraphLayout.
C++ API: Virtual base class for complex text layout.
LEErrorCode
Error codes returned by the LayoutEngine.
Definition: LETypes.h:678
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:130
const LEGlyphID * getGlyphs() const
Get the glyphs in the visual run.
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:360
const LEFontInstance * getFont() const
Get the LEFontInstance object which represents the font of the visual run.
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:238
This is a virtual base class that serves as the interface between a LayoutEngine and the platform fon...
le_uint32 LEGlyphID
Used for glyph indices.
Definition: LETypes.h:112
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
C++ API: Layout Engine Font Instance object.
le_int32 getDescent() const
A convenience method which returns the descent value for the font associated with this run...
le_int32 getGlyphCount() const
Get the number of glyphs in the visual run.
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:229
le_int32 getLeading() const
A convenience method which returns the leading value for the font associated with this run...
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:182