Loading...
Searching...
No Matches
ParagraphLayout.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (C) 2002-2014, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
#ifndef __PARAGRAPHLAYOUT_H
#define __PARAGRAPHLAYOUT_H
/*
* ParagraphLayout doesn't make much sense without
* BreakIterator...
*/
#include "unicode/uscript.h"
#if ! UCONFIG_NO_BREAK_ITERATION
#include "layout/LETypes.h"
#include "layout/LEFontInstance.h"
#include "layout/LayoutEngine.h"
#include "unicode/ubidi.h"
#include "unicode/brkiter.h"
#include "layout/RunArrays.h"
U_NAMESPACE_BEGIN
class U_LAYOUTEX_API ParagraphLayout : public UObject
{
public:
class VisualRun;
class U_LAYOUTEX_API Line : public UObject
{
public:
~Line();
inline le_int32 countRuns() const;
le_int32 getAscent() const;
le_int32 getDescent() const;
le_int32 getLeading() const;
le_int32 getWidth() const;
const VisualRun *getVisualRun(le_int32 runIndex) const;
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
inline UClassID getDynamicClassID() const override { return getStaticClassID(); }
private:
static const char fgClassID;
friend class ParagraphLayout;
le_int32 fAscent;
le_int32 fDescent;
le_int32 fLeading;
le_int32 fRunCount;
le_int32 fRunCapacity;
VisualRun **fRuns;
inline Line();
inline Line(const Line &other);
inline Line &operator=(const Line & /*other*/) { return *this; }
void computeMetrics();
void append(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
};
class U_LAYOUTEX_API VisualRun : public UObject
{
public:
inline const LEFontInstance *getFont() const;
inline UBiDiDirection getDirection() const;
inline le_int32 getGlyphCount() const;
inline const LEGlyphID *getGlyphs() const;
inline const float *getPositions() const;
inline const le_int32 *getGlyphToCharMap() const;
inline le_int32 getAscent() const;
inline le_int32 getDescent() const;
inline le_int32 getLeading() const;
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
inline UClassID getDynamicClassID() const override { return getStaticClassID(); }
private:
static const char fgClassID;
const LEFontInstance *fFont;
const UBiDiDirection fDirection;
const le_int32 fGlyphCount;
const LEGlyphID *fGlyphs;
const float *fPositions;
const le_int32 *fGlyphToCharMap;
friend class Line;
inline VisualRun();
inline VisualRun(const VisualRun &other);
inline VisualRun &operator=(const VisualRun &/*other*/) { return *this; }
inline VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
~VisualRun();
};
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);
~ParagraphLayout();
// Note: the following is #if 0'd out because there's no good
// way to implement it without either calling layoutEngineFactory()
// or duplicating the logic there...
#if 0
static le_bool isComplex(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns);
#else
static le_bool isComplex(const LEUnicode chars[], le_int32 count);
#endif
inline UBiDiLevel getParagraphLevel();
inline UBiDiDirection getTextDirection();
virtual le_int32 getAscent() const;
virtual le_int32 getDescent() const;
virtual le_int32 getLeading() const;
inline void reflow();
#ifndef U_HIDE_INTERNAL_API
inline le_bool isDone() const;
#endif /* U_HIDE_INTERNAL_API */
Line *nextLine(float width);
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
inline UClassID getDynamicClassID() const override { return getStaticClassID(); }
private:
static const char fgClassID;
struct StyleRunInfo
{
LayoutEngine *engine;
const LEFontInstance *font;
const Locale *locale;
LEGlyphID *glyphs;
float *positions;
UScriptCode script;
UBiDiLevel level;
le_int32 runBase;
le_int32 runLimit;
le_int32 glyphBase;
le_int32 glyphCount;
};
ParagraphLayout() {}
ParagraphLayout(const ParagraphLayout & /*other*/) : UObject( ){}
inline ParagraphLayout &operator=(const ParagraphLayout & /*other*/) { return *this; }
void computeLevels(UBiDiLevel paragraphLevel);
Line *computeVisualRuns();
void appendRun(Line *line, le_int32 run, le_int32 firstChar, le_int32 lastChar);
void computeScripts();
void computeLocales();
void computeSubFonts(const FontRuns *fontRuns, LEErrorCode &status);
void computeMetrics();
le_int32 getLanguageCode(const Locale *locale);
le_int32 getCharRun(le_int32 charIndex);
static le_bool isComplex(UScriptCode script);
le_int32 previousBreak(le_int32 charIndex);
const LEUnicode *fChars;
le_int32 fCharCount;
const FontRuns *fFontRuns;
const ValueRuns *fLevelRuns;
const ValueRuns *fScriptRuns;
const LocaleRuns *fLocaleRuns;
le_bool fVertical;
le_bool fClientLevels;
le_bool fClientScripts;
le_bool fClientLocales;
UBiDiLevel *fEmbeddingLevels;
le_int32 fAscent;
le_int32 fDescent;
le_int32 fLeading;
le_int32 *fGlyphToCharMap;
le_int32 *fCharToMinGlyphMap;
le_int32 *fCharToMaxGlyphMap;
float *fGlyphWidths;
le_int32 fGlyphCount;
UBiDi *fParaBidi;
UBiDi *fLineBidi;
le_int32 *fStyleRunLimits;
le_int32 *fStyleIndices;
StyleRunInfo *fStyleRunInfo;
le_int32 fStyleRunCount;
BreakIterator *fBreakIterator;
le_int32 fLineStart;
le_int32 fLineEnd;
le_int32 fFirstVisualRun;
le_int32 fLastVisualRun;
float fVisualRunLastX;
float fVisualRunLastY;
};
inline UBiDiLevel ParagraphLayout::getParagraphLevel()
{
return ubidi_getParaLevel(fParaBidi);
}
inline UBiDiDirection ParagraphLayout::getTextDirection()
{
return ubidi_getDirection(fParaBidi);
}
inline void ParagraphLayout::reflow()
{
fLineEnd = 0;
}
inline ParagraphLayout::Line::Line()
: UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(nullptr)
{
// nothing else to do
}
inline ParagraphLayout::Line::Line(const Line & /*other*/)
: UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(nullptr)
{
// nothing else to do
}
inline le_int32 ParagraphLayout::Line::countRuns() const
{
return fRunCount;
}
inline const LEFontInstance *ParagraphLayout::VisualRun::getFont() const
{
return fFont;
}
inline UBiDiDirection ParagraphLayout::VisualRun::getDirection() const
{
return fDirection;
}
inline le_int32 ParagraphLayout::VisualRun::getGlyphCount() const
{
return fGlyphCount;
}
inline const LEGlyphID *ParagraphLayout::VisualRun::getGlyphs() const
{
return fGlyphs;
}
inline const float *ParagraphLayout::VisualRun::getPositions() const
{
return fPositions;
}
inline const le_int32 *ParagraphLayout::VisualRun::getGlyphToCharMap() const
{
return fGlyphToCharMap;
}
inline le_int32 ParagraphLayout::VisualRun::getAscent() const
{
return fFont->getAscent();
}
inline le_int32 ParagraphLayout::VisualRun::getDescent() const
{
return fFont->getDescent();
}
inline le_int32 ParagraphLayout::VisualRun::getLeading() const
{
return fFont->getLeading();
}
inline ParagraphLayout::VisualRun::VisualRun()
: UObject(), fFont(nullptr), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(nullptr), fPositions(nullptr), fGlyphToCharMap(nullptr)
{
// nothing
}
inline ParagraphLayout::VisualRun::VisualRun(const VisualRun &/*other*/)
: UObject(), fFont(nullptr), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(nullptr), fPositions(nullptr), fGlyphToCharMap(nullptr)
{
// nothing
}
inline ParagraphLayout::VisualRun::VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[])
: fFont(font), fDirection(direction), fGlyphCount(glyphCount),
fGlyphs(glyphs), fPositions(positions), fGlyphToCharMap(glyphToCharMap)
{
// nothing else needs to be done!
}
U_NAMESPACE_END
#endif
#endif
RunArrays.h
C++ API: base class for building classes which represent data that is associated with runs of text.
brkiter.h
C++ API: Break Iterator.
icu::FontRuns
The FontRuns class associates pointers to LEFontInstance objects with runs of text.
Definition RunArrays.h:273
icu::LocaleRuns
The LocaleRuns class associates pointers to Locale objects with runs of text.
Definition RunArrays.h:410
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
icu::ParagraphLayout::Line
This class represents a single line of text in a ParagraphLayout.
Definition ParagraphLayout.h:68
icu::ParagraphLayout::Line::getDynamicClassID
UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
Definition ParagraphLayout.h:159
icu::ParagraphLayout::Line::~Line
~Line()
The constructor is private since these objects can only be created by ParagraphLayout.
icu::ParagraphLayout::Line::getVisualRun
const VisualRun * getVisualRun(le_int32 runIndex) const
Get a ParagraphLayout::VisualRun object for a given visual run in the line.
icu::ParagraphLayout::Line::countRuns
le_int32 countRuns() const
Count the number of visual runs in the line.
Definition ParagraphLayout.h:675
icu::ParagraphLayout::Line::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
Definition ParagraphLayout.h:152
icu::ParagraphLayout::Line::getWidth
le_int32 getWidth() const
Get the width of the line.
icu::ParagraphLayout::Line::getLeading
le_int32 getLeading() const
Get the leading of the line.
icu::ParagraphLayout::Line::getDescent
le_int32 getDescent() const
Get the descent of the line.
icu::ParagraphLayout::Line::getAscent
le_int32 getAscent() const
Get the ascent of the line.
icu::ParagraphLayout::VisualRun
This object represents a single visual run in a line of text in a paragraph.
Definition ParagraphLayout.h:206
icu::ParagraphLayout::VisualRun::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
Definition ParagraphLayout.h:315
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::VisualRun::getGlyphToCharMap
const le_int32 * getGlyphToCharMap() const
Get the glyph-to-character map for this visual run.
Definition ParagraphLayout.h:705
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::getDirection
UBiDiDirection getDirection() const
Get the direction of the visual run.
Definition ParagraphLayout.h:685
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::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
icu::ParagraphLayout::VisualRun::getGlyphs
const LEGlyphID * getGlyphs() const
Get the glyphs in the visual run.
Definition ParagraphLayout.h:695
icu::ParagraphLayout::VisualRun::getGlyphCount
le_int32 getGlyphCount() const
Get the number of glyphs in the visual run.
Definition ParagraphLayout.h:690
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::VisualRun::getDynamicClassID
UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
Definition ParagraphLayout.h:322
icu::ParagraphLayout::isDone
le_bool isDone() const
Convenience method for determining if paragraph layout processing is complete ( i....
icu::ParagraphLayout::getAscent
virtual le_int32 getAscent() const
Return the max ascent value for all the fonts in the paragraph.
icu::ParagraphLayout::getDescent
virtual le_int32 getDescent() const
Return the max descent value for all the fonts in the paragraph.
icu::ParagraphLayout::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
Definition ParagraphLayout.h:546
icu::ParagraphLayout::~ParagraphLayout
~ParagraphLayout()
The destructor.
icu::ParagraphLayout::getLeading
virtual le_int32 getLeading() const
Return the max leading value for all the fonts in the paragraph.
icu::ParagraphLayout::getDynamicClassID
UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
Definition ParagraphLayout.h:553
icu::ParagraphLayout::isComplex
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...
icu::ParagraphLayout::getTextDirection
UBiDiDirection getTextDirection()
Return the directionality of the text in the paragraph.
Definition ParagraphLayout.h:653
icu::ParagraphLayout::ParagraphLayout
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.
icu::ParagraphLayout::getParagraphLevel
UBiDiLevel getParagraphLevel()
Return the resolved paragraph level.
Definition ParagraphLayout.h:648
icu::ParagraphLayout::nextLine
Line * nextLine(float width)
Return a ParagraphLayout::Line object which represents next line in the paragraph.
icu::ParagraphLayout::reflow
void reflow()
Reset line breaking to start from the beginning of the paragraph.
Definition ParagraphLayout.h:658
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
icu::ValueRuns
The ValueRuns class associates integer values with runs of text.
Definition RunArrays.h:549
ubidi.h
C API: Bidi algorithm.
UBiDiDirection
UBiDiDirection
UBiDiDirection values indicate the text direction.
Definition ubidi.h:429
UBIDI_LTR
@ UBIDI_LTR
Left-to-right text.
Definition ubidi.h:441
ubidi_getDirection
U_CAPI UBiDiDirection ubidi_getDirection(const UBiDi *pBiDi)
Get the directionality of the text.
UBiDiLevel
uint8_t UBiDiLevel
UBiDiLevel is the type of the level values in this Bidi implementation.
Definition ubidi.h:340
ubidi_getParaLevel
U_CAPI UBiDiLevel ubidi_getParaLevel(const UBiDi *pBiDi)
Get the paragraph level of the text.
UBiDi
struct UBiDi UBiDi
Definition ubidi.h:486
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
uscript.h
C API: Unicode Script Information.
UScriptCode
UScriptCode
Constants for ISO 15924 script codes.
Definition uscript.h:54
U_LAYOUTEX_API
#define U_LAYOUTEX_API
Set to export library symbols from inside the layout extensions library, and to import them from outs...
Definition utypes.h:318