ICU 74.2 74.2
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
18
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
34U_NAMESPACE_BEGIN
35
52{
53public:
54 class VisualRun;
55
67 class U_LAYOUTEX_API Line : public UObject
68 {
69 public:
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
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
459
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 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
554
555private:
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
649{
650 return ubidi_getParaLevel(fParaBidi);
651}
652
657
659{
660 fLineEnd = 0;
661}
662
663inline 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
669inline 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
675inline le_int32 ParagraphLayout::Line::countRuns() const
676{
677 return fRunCount;
678}
679
680inline const LEFontInstance *ParagraphLayout::VisualRun::getFont() const
681{
682 return fFont;
683}
684
686{
687 return fDirection;
688}
689
691{
692 return fGlyphCount;
693}
694
695inline const LEGlyphID *ParagraphLayout::VisualRun::getGlyphs() const
696{
697 return fGlyphs;
698}
699
701{
702 return fPositions;
703}
704
706{
707 return fGlyphToCharMap;
708}
709
711{
712 return fFont->getAscent();
713}
714
716{
717 return fFont->getDescent();
718}
719
721{
722 return fFont->getLeading();
723}
724
725inline ParagraphLayout::VisualRun::VisualRun()
726 : UObject(), fFont(nullptr), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(nullptr), fPositions(nullptr), fGlyphToCharMap(nullptr)
727{
728 // nothing
729}
730
731inline ParagraphLayout::VisualRun::VisualRun(const VisualRun &/*other*/)
732 : UObject(), fFont(nullptr), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(nullptr), fPositions(nullptr), fGlyphToCharMap(nullptr)
733{
734 // nothing
735}
736
737inline 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
745U_NAMESPACE_END
746#endif
747#endif
C++ API: base class for building classes which represent data that is associated with runs of text.
C++ API: Break Iterator.
The FontRuns class associates pointers to LEFontInstance objects with runs of text.
Definition RunArrays.h:273
The LocaleRuns class associates pointers to Locale objects with runs of text.
Definition RunArrays.h:410
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
This class represents a single line of text in a ParagraphLayout.
~Line()
The constructor is private since these objects can only be created by ParagraphLayout.
const VisualRun * getVisualRun(le_int32 runIndex) const
Get a ParagraphLayout::VisualRun object for a given visual run in the line.
le_int32 countRuns() const
Count the number of visual runs in the line.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
le_int32 getWidth() const
Get the width of the line.
le_int32 getLeading() const
Get the leading of the line.
le_int32 getDescent() const
Get the descent of the line.
le_int32 getAscent() const
Get the ascent of the line.
This object represents a single visual run in a line of text in a paragraph.
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.
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.
le_int32 getAscent() const
A convenience method which returns the ascent value for the font associated with this run.
UBiDiDirection getDirection() const
Get the direction of the visual run.
le_int32 getDescent() const
A convenience method which returns the descent value for the font associated with this run.
le_int32 getLeading() const
A convenience method which returns the leading value for the font associated with this run.
const LEGlyphID * getGlyphs() const
Get the glyphs in the visual run.
le_int32 getGlyphCount() const
Get the number of glyphs in the visual run.
const float * getPositions() const
Get the (x, y) positions of the glyphs in the visual run.
le_bool isDone() const
Convenience method for determining if paragraph layout processing is complete ( i....
virtual le_int32 getAscent() const
Return the max ascent value for all the fonts in the paragraph.
virtual le_int32 getDescent() const
Return the max descent value for all the fonts in the paragraph.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
~ParagraphLayout()
The destructor.
virtual le_int32 getLeading() const
Return the max leading value for all the fonts in the paragraph.
static le_bool isComplex(const LEUnicode chars[], le_int32 count)
Examine the given text and determine if it contains characters in any script which requires complex p...
UBiDiDirection getTextDirection()
Return the directionality of the text in the paragraph.
ParagraphLayout(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns, const ValueRuns *levelRuns, const ValueRuns *scriptRuns, const LocaleRuns *localeRuns, UBiDiLevel paragraphLevel, le_bool vertical, LEErrorCode &status)
Construct a ParagraphLayout object for a styled paragraph.
UBiDiLevel getParagraphLevel()
Return the resolved paragraph level.
Line * nextLine(float width)
Return a ParagraphLayout::Line object which represents next line in the paragraph.
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.
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
The ValueRuns class associates integer values with runs of text.
Definition RunArrays.h:549
C API: Bidi algorithm.
UBiDiDirection
UBiDiDirection values indicate the text direction.
Definition ubidi.h:429
@ UBIDI_LTR
Left-to-right text.
Definition ubidi.h:441
U_CAPI UBiDiDirection ubidi_getDirection(const UBiDi *pBiDi)
Get the directionality of the text.
uint8_t UBiDiLevel
UBiDiLevel is the type of the level values in this Bidi implementation.
Definition ubidi.h:340
U_CAPI UBiDiLevel ubidi_getParaLevel(const UBiDi *pBiDi)
Get the paragraph level of the text.
struct UBiDi UBiDi
Definition ubidi.h:486
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
C API: Unicode Script Information.
UScriptCode
Constants for ISO 15924 script codes.
Definition uscript.h:54
#define U_LAYOUTEX_API
Set to export library symbols from inside the layout extensions library, and to import them from outs...
Definition utypes.h:303