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