|
ICU 73.2
73.2
|
00001 // © 2016 and later: Unicode, Inc. and others. 00002 // License & terms of use: http://www.unicode.org/copyright.html 00003 /* 00004 ********************************************************************** 00005 * Copyright (C) 2002-2014, International Business Machines 00006 * Corporation and others. All Rights Reserved. 00007 ********************************************************************** 00008 */ 00009 00010 #ifndef __PARAGRAPHLAYOUT_H 00011 00012 #define __PARAGRAPHLAYOUT_H 00013 00019 /* 00020 * ParagraphLayout doesn't make much sense without 00021 * BreakIterator... 00022 */ 00023 #include "unicode/uscript.h" 00024 #if ! UCONFIG_NO_BREAK_ITERATION 00025 00026 #include "layout/LETypes.h" 00027 #include "layout/LEFontInstance.h" 00028 #include "layout/LayoutEngine.h" 00029 #include "unicode/ubidi.h" 00030 #include "unicode/brkiter.h" 00031 00032 #include "layout/RunArrays.h" 00033 00034 U_NAMESPACE_BEGIN 00035 00051 class U_LAYOUTEX_API ParagraphLayout : public UObject 00052 { 00053 public: 00054 class VisualRun; 00055 00067 class U_LAYOUTEX_API Line : public UObject 00068 { 00069 public: 00078 ~Line(); 00079 00087 inline le_int32 countRuns() const; 00088 00097 le_int32 getAscent() const; 00098 00107 le_int32 getDescent() const; 00108 00117 le_int32 getLeading() const; 00118 00128 le_int32 getWidth() const; 00129 00145 const VisualRun *getVisualRun(le_int32 runIndex) const; 00146 00152 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } 00153 00159 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } 00160 00161 private: 00162 00167 static const char fgClassID; 00168 00169 friend class ParagraphLayout; 00170 00171 le_int32 fAscent; 00172 le_int32 fDescent; 00173 le_int32 fLeading; 00174 00175 le_int32 fRunCount; 00176 le_int32 fRunCapacity; 00177 00178 VisualRun **fRuns; 00179 00180 inline Line(); 00181 inline Line(const Line &other); 00182 inline Line &operator=(const Line & /*other*/) { return *this; }; 00183 00184 void computeMetrics(); 00185 00186 void append(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount, 00187 const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]); 00188 }; 00189 00205 class U_LAYOUTEX_API VisualRun : public UObject 00206 { 00207 public: 00220 inline const LEFontInstance *getFont() const; 00221 00230 inline UBiDiDirection getDirection() const; 00231 00239 inline le_int32 getGlyphCount() const; 00240 00251 inline const LEGlyphID *getGlyphs() const; 00252 00266 inline const float *getPositions() const; 00267 00278 inline const le_int32 *getGlyphToCharMap() const; 00279 00288 inline le_int32 getAscent() const; 00289 00298 inline le_int32 getDescent() const; 00299 00308 inline le_int32 getLeading() const; 00309 00315 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } 00316 00322 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } 00323 00324 private: 00325 00330 static const char fgClassID; 00331 00332 const LEFontInstance *fFont; 00333 const UBiDiDirection fDirection; 00334 00335 const le_int32 fGlyphCount; 00336 00337 const LEGlyphID *fGlyphs; 00338 const float *fPositions; 00339 const le_int32 *fGlyphToCharMap; 00340 00341 friend class Line; 00342 00343 inline VisualRun(); 00344 inline VisualRun(const VisualRun &other); 00345 inline VisualRun &operator=(const VisualRun &/*other*/) { return *this; }; 00346 00347 inline VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount, 00348 const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]); 00349 00350 ~VisualRun(); 00351 }; 00352 00396 ParagraphLayout(const LEUnicode chars[], le_int32 count, 00397 const FontRuns *fontRuns, 00398 const ValueRuns *levelRuns, 00399 const ValueRuns *scriptRuns, 00400 const LocaleRuns *localeRuns, 00401 UBiDiLevel paragraphLevel, le_bool vertical, 00402 LEErrorCode &status); 00403 00410 ~ParagraphLayout(); 00411 00412 // Note: the following is #if 0'd out because there's no good 00413 // way to implement it without either calling layoutEngineFactory() 00414 // or duplicating the logic there... 00415 #if 0 00416 00431 static le_bool isComplex(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns); 00432 #else 00433 00445 static le_bool isComplex(const LEUnicode chars[], le_int32 count); 00446 00447 #endif 00448 00458 inline UBiDiLevel getParagraphLevel(); 00459 00469 inline UBiDiDirection getTextDirection(); 00470 00479 virtual le_int32 getAscent() const; 00480 00489 virtual le_int32 getDescent() const; 00490 00499 virtual le_int32 getLeading() const; 00500 00507 inline void reflow(); 00508 00509 #ifndef U_HIDE_INTERNAL_API 00510 00519 inline le_bool isDone() const; 00520 #endif /* U_HIDE_INTERNAL_API */ 00521 00539 Line *nextLine(float width); 00540 00546 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } 00547 00553 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } 00554 00555 private: 00556 00557 00562 static const char fgClassID; 00563 00564 struct StyleRunInfo 00565 { 00566 LayoutEngine *engine; 00567 const LEFontInstance *font; 00568 const Locale *locale; 00569 LEGlyphID *glyphs; 00570 float *positions; 00571 UScriptCode script; 00572 UBiDiLevel level; 00573 le_int32 runBase; 00574 le_int32 runLimit; 00575 le_int32 glyphBase; 00576 le_int32 glyphCount; 00577 }; 00578 00579 ParagraphLayout() {}; 00580 ParagraphLayout(const ParagraphLayout & /*other*/) : UObject( ){}; 00581 inline ParagraphLayout &operator=(const ParagraphLayout & /*other*/) { return *this; }; 00582 00583 void computeLevels(UBiDiLevel paragraphLevel); 00584 00585 Line *computeVisualRuns(); 00586 void appendRun(Line *line, le_int32 run, le_int32 firstChar, le_int32 lastChar); 00587 00588 void computeScripts(); 00589 00590 void computeLocales(); 00591 00592 void computeSubFonts(const FontRuns *fontRuns, LEErrorCode &status); 00593 00594 void computeMetrics(); 00595 00596 le_int32 getLanguageCode(const Locale *locale); 00597 00598 le_int32 getCharRun(le_int32 charIndex); 00599 00600 static le_bool isComplex(UScriptCode script); 00601 00602 le_int32 previousBreak(le_int32 charIndex); 00603 00604 00605 const LEUnicode *fChars; 00606 le_int32 fCharCount; 00607 00608 const FontRuns *fFontRuns; 00609 const ValueRuns *fLevelRuns; 00610 const ValueRuns *fScriptRuns; 00611 const LocaleRuns *fLocaleRuns; 00612 00613 le_bool fVertical; 00614 le_bool fClientLevels; 00615 le_bool fClientScripts; 00616 le_bool fClientLocales; 00617 00618 UBiDiLevel *fEmbeddingLevels; 00619 00620 le_int32 fAscent; 00621 le_int32 fDescent; 00622 le_int32 fLeading; 00623 00624 le_int32 *fGlyphToCharMap; 00625 le_int32 *fCharToMinGlyphMap; 00626 le_int32 *fCharToMaxGlyphMap; 00627 float *fGlyphWidths; 00628 le_int32 fGlyphCount; 00629 00630 UBiDi *fParaBidi; 00631 UBiDi *fLineBidi; 00632 00633 le_int32 *fStyleRunLimits; 00634 le_int32 *fStyleIndices; 00635 StyleRunInfo *fStyleRunInfo; 00636 le_int32 fStyleRunCount; 00637 00638 BreakIterator *fBreakIterator; 00639 le_int32 fLineStart; 00640 le_int32 fLineEnd; 00641 00642 le_int32 fFirstVisualRun; 00643 le_int32 fLastVisualRun; 00644 float fVisualRunLastX; 00645 float fVisualRunLastY; 00646 }; 00647 00648 inline UBiDiLevel ParagraphLayout::getParagraphLevel() 00649 { 00650 return ubidi_getParaLevel(fParaBidi); 00651 } 00652 00653 inline UBiDiDirection ParagraphLayout::getTextDirection() 00654 { 00655 return ubidi_getDirection(fParaBidi); 00656 } 00657 00658 inline void ParagraphLayout::reflow() 00659 { 00660 fLineEnd = 0; 00661 } 00662 00663 inline ParagraphLayout::Line::Line() 00664 : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(nullptr) 00665 { 00666 // nothing else to do 00667 } 00668 00669 inline ParagraphLayout::Line::Line(const Line & /*other*/) 00670 : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(nullptr) 00671 { 00672 // nothing else to do 00673 } 00674 00675 inline le_int32 ParagraphLayout::Line::countRuns() const 00676 { 00677 return fRunCount; 00678 } 00679 00680 inline const LEFontInstance *ParagraphLayout::VisualRun::getFont() const 00681 { 00682 return fFont; 00683 } 00684 00685 inline UBiDiDirection ParagraphLayout::VisualRun::getDirection() const 00686 { 00687 return fDirection; 00688 } 00689 00690 inline le_int32 ParagraphLayout::VisualRun::getGlyphCount() const 00691 { 00692 return fGlyphCount; 00693 } 00694 00695 inline const LEGlyphID *ParagraphLayout::VisualRun::getGlyphs() const 00696 { 00697 return fGlyphs; 00698 } 00699 00700 inline const float *ParagraphLayout::VisualRun::getPositions() const 00701 { 00702 return fPositions; 00703 } 00704 00705 inline const le_int32 *ParagraphLayout::VisualRun::getGlyphToCharMap() const 00706 { 00707 return fGlyphToCharMap; 00708 } 00709 00710 inline le_int32 ParagraphLayout::VisualRun::getAscent() const 00711 { 00712 return fFont->getAscent(); 00713 } 00714 00715 inline le_int32 ParagraphLayout::VisualRun::getDescent() const 00716 { 00717 return fFont->getDescent(); 00718 } 00719 00720 inline le_int32 ParagraphLayout::VisualRun::getLeading() const 00721 { 00722 return fFont->getLeading(); 00723 } 00724 00725 inline ParagraphLayout::VisualRun::VisualRun() 00726 : UObject(), fFont(nullptr), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(nullptr), fPositions(nullptr), fGlyphToCharMap(nullptr) 00727 { 00728 // nothing 00729 } 00730 00731 inline ParagraphLayout::VisualRun::VisualRun(const VisualRun &/*other*/) 00732 : UObject(), fFont(nullptr), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(nullptr), fPositions(nullptr), fGlyphToCharMap(nullptr) 00733 { 00734 // nothing 00735 } 00736 00737 inline ParagraphLayout::VisualRun::VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount, 00738 const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]) 00739 : fFont(font), fDirection(direction), fGlyphCount(glyphCount), 00740 fGlyphs(glyphs), fPositions(positions), fGlyphToCharMap(glyphToCharMap) 00741 { 00742 // nothing else needs to be done! 00743 } 00744 00745 U_NAMESPACE_END 00746 #endif 00747 #endif
1.7.6.1