ICU 71.1 71.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
51 class U_LAYOUTEX_API ParagraphLayout : public UObject
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 virtual inline UClassID getDynamicClassID() const { 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
205 class U_LAYOUTEX_API VisualRun : public UObject
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 virtual inline UClassID getDynamicClassID() const { 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
410 ~ParagraphLayout();
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
416
431 static le_bool isComplex(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns);
432 #else
433
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
510
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 virtual inline UClassID getDynamicClassID() const { 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(NULL)
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(NULL)
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
685 inline UBiDiDirection ParagraphLayout::VisualRun::getDirection() const
686 {
687 return fDirection;
688 }
689
690 inline le_int32 ParagraphLayout::VisualRun::getGlyphCount() const
691 {
692 return fGlyphCount;
693 }
694
695 inline const LEGlyphID *ParagraphLayout::VisualRun::getGlyphs() const
696 {
697 return fGlyphs;
698 }
699
700 inline const float *ParagraphLayout::VisualRun::getPositions() const
701 {
702 return fPositions;
703 }
704
705 inline const le_int32 *ParagraphLayout::VisualRun::getGlyphToCharMap() const
706 {
707 return fGlyphToCharMap;
708 }
709
710 inline le_int32 ParagraphLayout::VisualRun::getAscent() const
711 {
712 return fFont->getAscent();
713 }
714
715 inline le_int32 ParagraphLayout::VisualRun::getDescent() const
716 {
717 return fFont->getDescent();
718 }
719
720 inline le_int32 ParagraphLayout::VisualRun::getLeading() const
721 {
722 return fFont->getLeading();
723 }
724
725 inline ParagraphLayout::VisualRun::VisualRun()
726 : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
727 {
728 // nothing
729 }
730
731 inline ParagraphLayout::VisualRun::VisualRun(const VisualRun &/*other*/)
732 : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
733 {
734 // nothing
735 }
736
737 inline ParagraphLayout::VisualRun::VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
738 const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[])
739 : fFont(font), fDirection(direction), fGlyphCount(glyphCount),
740 fGlyphs(glyphs), fPositions(positions), fGlyphToCharMap(glyphToCharMap)
741 {
742 // nothing else needs to be done!
743 }
744
745 U_NAMESPACE_END
746 #endif
747 #endif
ubidi_getDirection
U_CAPI UBiDiDirection ubidi_getDirection(const UBiDi *pBiDi)
Get the directionality of the text.
icu::ParagraphLayout::Line::countRuns
le_int32 countRuns() const
Count the number of visual runs in the line.
Definition: ParagraphLayout.h:675
U_LAYOUTEX_API
#define U_LAYOUTEX_API
Definition: utypes.h:303
ubidi.h
C API: Bidi algorithm.
UBiDiLevel
uint8_t UBiDiLevel
UBiDiLevel is the type of the level values in this Bidi implementation.
Definition: ubidi.h:340
icu::ParagraphLayout::VisualRun::getGlyphToCharMap
const le_int32 * getGlyphToCharMap() const
Get the glyph-to-character map for this visual run.
Definition: ParagraphLayout.h:705
uscript.h
C API: Unicode Script Information.
UScriptCode
UScriptCode
Constants for ISO 15924 script codes.
Definition: uscript.h:54
icu::ParagraphLayout::VisualRun::getDirection
UBiDiDirection getDirection() const
Get the direction of the visual run.
Definition: ParagraphLayout.h:685
icu::ParagraphLayout::VisualRun
This object represents a single visual run in a line of text in a paragraph.
Definition: ParagraphLayout.h:205
icu::ParagraphLayout::VisualRun::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
Definition: ParagraphLayout.h:322
icu::ParagraphLayout::VisualRun::getAscent
le_int32 getAscent() const
A convenience method which returns the ascent value for the font associated with this run.
Definition: ParagraphLayout.h:710
icu::ParagraphLayout::VisualRun::getFont
const LEFontInstance * getFont() const
Get the LEFontInstance object which represents the font of the visual run.
Definition: ParagraphLayout.h:680
icu::ParagraphLayout::Line
This class represents a single line of text in a ParagraphLayout.
Definition: ParagraphLayout.h:67
NULL
#define NULL
Definition: utypes.h:188
brkiter.h
C++ API: Break Iterator.
icu::ParagraphLayout::VisualRun::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
Definition: ParagraphLayout.h:315
icu::ParagraphLayout
ParagraphLayout.
Definition: ParagraphLayout.h:51
icu::ParagraphLayout::VisualRun::getDescent
le_int32 getDescent() const
A convenience method which returns the descent value for the font associated with this run.
Definition: ParagraphLayout.h:715
icu::ParagraphLayout::Line::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
Definition: ParagraphLayout.h:152
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
ubidi_getParaLevel
U_CAPI UBiDiLevel ubidi_getParaLevel(const UBiDi *pBiDi)
Get the paragraph level of the text.
icu::ParagraphLayout::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
Definition: ParagraphLayout.h:546
UBIDI_LTR
@ UBIDI_LTR
Left-to-right text.
Definition: ubidi.h:441
UBiDi
struct UBiDi UBiDi
Definition: ubidi.h:486
UBiDiDirection
UBiDiDirection
UBiDiDirection values indicate the text direction.
Definition: ubidi.h:429
icu::ParagraphLayout::VisualRun::getGlyphCount
le_int32 getGlyphCount() const
Get the number of glyphs in the visual run.
Definition: ParagraphLayout.h:690
icu::ParagraphLayout::VisualRun::getGlyphs
const LEGlyphID * getGlyphs() const
Get the glyphs in the visual run.
Definition: ParagraphLayout.h:695
RunArrays.h
C++ API: base class for building classes which represent data that is associated with runs of text.
icu::ParagraphLayout::VisualRun::getPositions
const float * getPositions() const
Get the (x, y) positions of the glyphs in the visual run.
Definition: ParagraphLayout.h:700
icu::ParagraphLayout::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
Definition: ParagraphLayout.h:553
icu::ParagraphLayout::Line::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
Definition: ParagraphLayout.h:159
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::ParagraphLayout::VisualRun::getLeading
le_int32 getLeading() const
A convenience method which returns the leading value for the font associated with this run.
Definition: ParagraphLayout.h:720