ICU 78.1  78.1
ParagraphLayout.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4  **********************************************************************
5  * Copyright (C) 2002-2014, International Business Machines
6  * Corporation and others. All Rights Reserved.
7  **********************************************************************
8  */
9 
10 #ifndef __PARAGRAPHLAYOUT_H
11 
12 #define __PARAGRAPHLAYOUT_H
13 
19 /*
20  * ParagraphLayout doesn't make much sense without
21  * BreakIterator...
22  */
23 #include "unicode/uscript.h"
24 #if ! UCONFIG_NO_BREAK_ITERATION
25 
26 #include "layout/LETypes.h"
27 #include "layout/LEFontInstance.h"
28 #include "layout/LayoutEngine.h"
29 #include "unicode/ubidi.h"
30 #include "unicode/brkiter.h"
31 
32 #include "layout/RunArrays.h"
33 
34 U_NAMESPACE_BEGIN
35 
52 {
53 public:
54  class VisualRun;
55 
67  class U_LAYOUTEX_API Line : public UObject
68  {
69  public:
78  ~Line();
79 
87  inline le_int32 countRuns() const;
88 
97  le_int32 getAscent() const;
98 
107  le_int32 getDescent() const;
108 
117  le_int32 getLeading() const;
118 
128  le_int32 getWidth() const;
129 
145  const VisualRun *getVisualRun(le_int32 runIndex) const;
146 
152  static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
153 
159  inline UClassID getDynamicClassID() const override { return getStaticClassID(); }
160 
161  private:
162 
167  static const char fgClassID;
168 
169  friend class ParagraphLayout;
170 
171  le_int32 fAscent;
172  le_int32 fDescent;
173  le_int32 fLeading;
174 
175  le_int32 fRunCount;
176  le_int32 fRunCapacity;
177 
178  VisualRun **fRuns;
179 
180  inline Line();
181  inline Line(const Line &other);
182  inline Line &operator=(const Line & /*other*/) { return *this; }
183 
184  void computeMetrics();
185 
186  void append(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
187  const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
188  };
189 
206  {
207  public:
220  inline const LEFontInstance *getFont() const;
221 
230  inline UBiDiDirection getDirection() const;
231 
239  inline le_int32 getGlyphCount() const;
240 
251  inline const LEGlyphID *getGlyphs() const;
252 
266  inline const float *getPositions() const;
267 
278  inline const le_int32 *getGlyphToCharMap() const;
279 
288  inline le_int32 getAscent() const;
289 
298  inline le_int32 getDescent() const;
299 
308  inline le_int32 getLeading() const;
309 
315  static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
316 
322  inline UClassID getDynamicClassID() const override { return getStaticClassID(); }
323 
324  private:
325 
330  static const char fgClassID;
331 
332  const LEFontInstance *fFont;
333  const UBiDiDirection fDirection;
334 
335  const le_int32 fGlyphCount;
336 
337  const LEGlyphID *fGlyphs;
338  const float *fPositions;
339  const le_int32 *fGlyphToCharMap;
340 
341  friend class Line;
342 
343  inline VisualRun();
344  inline VisualRun(const VisualRun &other);
345  inline VisualRun &operator=(const VisualRun &/*other*/) { return *this; }
346 
347  inline VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
348  const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
349 
350  ~VisualRun();
351  };
352 
396  ParagraphLayout(const LEUnicode chars[], le_int32 count,
397  const FontRuns *fontRuns,
398  const ValueRuns *levelRuns,
399  const ValueRuns *scriptRuns,
400  const LocaleRuns *localeRuns,
401  UBiDiLevel paragraphLevel, le_bool vertical,
402  LEErrorCode &status);
403 
411 
412  // Note: the following is #if 0'd out because there's no good
413  // way to implement it without either calling layoutEngineFactory()
414  // or duplicating the logic there...
415 #if 0
431  static le_bool isComplex(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns);
432 #else
445  static le_bool isComplex(const LEUnicode chars[], le_int32 count);
446 
447 #endif
448 
458  inline UBiDiLevel getParagraphLevel();
459 
469  inline UBiDiDirection getTextDirection();
470 
479  virtual le_int32 getAscent() const;
480 
489  virtual le_int32 getDescent() const;
490 
499  virtual le_int32 getLeading() const;
500 
507  inline void reflow();
508 
509 #ifndef U_HIDE_INTERNAL_API
519  inline le_bool isDone() const;
520 #endif /* U_HIDE_INTERNAL_API */
521 
539  Line *nextLine(float width);
540 
546  static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
547 
553  inline UClassID getDynamicClassID() const override { return getStaticClassID(); }
554 
555 private:
556 
557 
562  static const char fgClassID;
563 
564  struct StyleRunInfo
565  {
566  LayoutEngine *engine;
567  const LEFontInstance *font;
568  const Locale *locale;
569  LEGlyphID *glyphs;
570  float *positions;
571  UScriptCode script;
572  UBiDiLevel level;
573  le_int32 runBase;
574  le_int32 runLimit;
575  le_int32 glyphBase;
576  le_int32 glyphCount;
577  };
578 
579  ParagraphLayout() {}
580  ParagraphLayout(const ParagraphLayout & /*other*/) : UObject( ){}
581  inline ParagraphLayout &operator=(const ParagraphLayout & /*other*/) { return *this; }
582 
583  void computeLevels(UBiDiLevel paragraphLevel);
584 
585  Line *computeVisualRuns();
586  void appendRun(Line *line, le_int32 run, le_int32 firstChar, le_int32 lastChar);
587 
588  void computeScripts();
589 
590  void computeLocales();
591 
592  void computeSubFonts(const FontRuns *fontRuns, LEErrorCode &status);
593 
594  void computeMetrics();
595 
596  le_int32 getLanguageCode(const Locale *locale);
597 
598  le_int32 getCharRun(le_int32 charIndex);
599 
600  static le_bool isComplex(UScriptCode script);
601 
602  le_int32 previousBreak(le_int32 charIndex);
603 
604 
605  const LEUnicode *fChars;
606  le_int32 fCharCount;
607 
608  const FontRuns *fFontRuns;
609  const ValueRuns *fLevelRuns;
610  const ValueRuns *fScriptRuns;
611  const LocaleRuns *fLocaleRuns;
612 
613  le_bool fVertical;
614  le_bool fClientLevels;
615  le_bool fClientScripts;
616  le_bool fClientLocales;
617 
618  UBiDiLevel *fEmbeddingLevels;
619 
620  le_int32 fAscent;
621  le_int32 fDescent;
622  le_int32 fLeading;
623 
624  le_int32 *fGlyphToCharMap;
625  le_int32 *fCharToMinGlyphMap;
626  le_int32 *fCharToMaxGlyphMap;
627  float *fGlyphWidths;
628  le_int32 fGlyphCount;
629 
630  UBiDi *fParaBidi;
631  UBiDi *fLineBidi;
632 
633  le_int32 *fStyleRunLimits;
634  le_int32 *fStyleIndices;
635  StyleRunInfo *fStyleRunInfo;
636  le_int32 fStyleRunCount;
637 
638  BreakIterator *fBreakIterator;
639  le_int32 fLineStart;
640  le_int32 fLineEnd;
641 
642  le_int32 fFirstVisualRun;
643  le_int32 fLastVisualRun;
644  float fVisualRunLastX;
645  float fVisualRunLastY;
646 };
647 
648 inline UBiDiLevel ParagraphLayout::getParagraphLevel()
649 {
650  return ubidi_getParaLevel(fParaBidi);
651 }
652 
653 inline UBiDiDirection ParagraphLayout::getTextDirection()
654 {
655  return ubidi_getDirection(fParaBidi);
656 }
657 
658 inline void ParagraphLayout::reflow()
659 {
660  fLineEnd = 0;
661 }
662 
663 inline ParagraphLayout::Line::Line()
664  : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(nullptr)
665 {
666  // nothing else to do
667 }
668 
669 inline ParagraphLayout::Line::Line(const Line & /*other*/)
670  : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(nullptr)
671 {
672  // nothing else to do
673 }
674 
675 inline le_int32 ParagraphLayout::Line::countRuns() const
676 {
677  return fRunCount;
678 }
679 
680 inline const LEFontInstance *ParagraphLayout::VisualRun::getFont() const
681 {
682  return fFont;
683 }
684 
686 {
687  return fDirection;
688 }
689 
690 inline le_int32