ParagraphLayout.h

Go to the documentation of this file.
00001 /*
00002  **********************************************************************
00003  *   Copyright (C) 2002-2011, International Business Machines
00004  *   Corporation and others.  All Rights Reserved.
00005  **********************************************************************
00006  */
00007 
00008 #ifndef __PARAGRAPHLAYOUT_H
00009 
00010 #define __PARAGRAPHLAYOUT_H
00011 
00017 /*
00018  * ParagraphLayout doesn't make much sense without
00019  * BreakIterator...
00020  */
00021 #include "unicode/uscript.h"
00022 #if ! UCONFIG_NO_BREAK_ITERATION
00023 
00024 #include "layout/LETypes.h"
00025 #include "layout/LEFontInstance.h"
00026 #include "layout/LayoutEngine.h"
00027 #include "unicode/ubidi.h"
00028 #include "unicode/brkiter.h"
00029 
00030 #include "layout/RunArrays.h"
00031 
00032 U_NAMESPACE_BEGIN
00033 
00044 class U_LAYOUTEX_API ParagraphLayout : public UObject
00045 {
00046 public:
00047     class VisualRun;
00048 
00060     class U_LAYOUTEX_API Line : public UObject
00061     {
00062     public:
00071         ~Line();
00072 
00080         inline le_int32 countRuns() const;
00081 
00090         le_int32 getAscent() const;
00091 
00100         le_int32 getDescent() const;
00101 
00110         le_int32 getLeading() const;
00111 
00121         le_int32 getWidth() const;
00122     
00138         const VisualRun *getVisualRun(le_int32 runIndex) const;
00139 
00145         static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
00146 
00152         virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
00153 
00154     private:
00155 
00160         static const char fgClassID;
00161 
00162         friend class ParagraphLayout;
00163 
00164         le_int32 fAscent;
00165         le_int32 fDescent;
00166         le_int32 fLeading;
00167 
00168         le_int32 fRunCount;
00169         le_int32 fRunCapacity;
00170 
00171         VisualRun **fRuns;
00172 
00173         inline Line();
00174         inline Line(const Line &other);
00175         inline Line &operator=(const Line & /*other*/) { return *this; };
00176 
00177         void computeMetrics();
00178 
00179         void append(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
00180                     const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
00181     };
00182 
00198     class U_LAYOUTEX_API VisualRun : public UObject
00199     {
00200     public:
00213         inline const LEFontInstance *getFont() const;
00214 
00223         inline UBiDiDirection getDirection() const;
00224 
00232         inline le_int32 getGlyphCount() const;
00233 
00244         inline const LEGlyphID *getGlyphs() const;
00245 
00259         inline const float *getPositions() const;
00260 
00271         inline const le_int32 *getGlyphToCharMap() const;
00272 
00281         inline le_int32 getAscent() const;
00282 
00291         inline le_int32 getDescent() const;
00292 
00301         inline le_int32 getLeading() const;
00302 
00308         static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
00309 
00315         virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
00316 
00317     private:
00318 
00323         static const char fgClassID;
00324 
00325         const LEFontInstance *fFont;
00326         const UBiDiDirection  fDirection;
00327 
00328         const le_int32 fGlyphCount;
00329 
00330         const LEGlyphID *fGlyphs;
00331         const float     *fPositions;
00332         const le_int32  *fGlyphToCharMap;
00333 
00334         friend class Line;
00335 
00336         inline VisualRun();
00337         inline VisualRun(const VisualRun &other);
00338         inline VisualRun &operator=(const VisualRun &/*other*/) { return *this; };
00339 
00340         inline VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
00341                   const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
00342 
00343         ~VisualRun();
00344     };
00345 
00389     ParagraphLayout(const LEUnicode chars[], le_int32 count,
00390                     const FontRuns *fontRuns,
00391                     const ValueRuns *levelRuns,
00392                     const ValueRuns *scriptRuns,
00393                     const LocaleRuns *localeRuns,
00394                     UBiDiLevel paragraphLevel, le_bool vertical,
00395                     LEErrorCode &status);
00396 
00403     ~ParagraphLayout();
00404 
00405     // Note: the following is #if 0'd out because there's no good
00406     // way to implement it without either calling layoutEngineFactory()
00407     // or duplicating the logic there...
00408 #if 0
00409 
00424     static le_bool isComplex(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns);
00425 #else
00426 
00438     static le_bool isComplex(const LEUnicode chars[], le_int32 count);
00439 
00440 #endif
00441 
00451     inline UBiDiLevel getParagraphLevel();
00452 
00462     inline UBiDiDirection getTextDirection();
00463 
00472     virtual le_int32 getAscent() const;
00473 
00482     virtual le_int32 getDescent() const;
00483 
00492     virtual le_int32 getLeading() const;
00493 
00500     inline void reflow();
00501 
00502 #ifndef U_HIDE_INTERNAL_API
00503 
00512     inline le_bool isDone() const;
00513 #endif  /* U_HIDE_INTERNAL_API */
00514 
00532     Line *nextLine(float width);
00533 
00539     static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
00540 
00546     virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
00547 
00548 private:
00549 
00550 
00555     static const char fgClassID;
00556 
00557     struct StyleRunInfo
00558     {
00559           LayoutEngine   *engine;
00560     const LEFontInstance *font;
00561     const Locale         *locale;
00562           LEGlyphID      *glyphs;
00563           float          *positions;
00564           UScriptCode     script;
00565           UBiDiLevel      level;
00566           le_int32        runBase;
00567           le_int32        runLimit;
00568           le_int32        glyphBase;
00569           le_int32        glyphCount;
00570     };
00571 
00572     ParagraphLayout() {};
00573     ParagraphLayout(const ParagraphLayout & /*other*/) : UObject( ){};
00574     inline ParagraphLayout &operator=(const ParagraphLayout & /*other*/) { return *this; };
00575 
00576     void computeLevels(UBiDiLevel paragraphLevel);
00577 
00578     Line *computeVisualRuns();
00579     void appendRun(Line *line, le_int32 run, le_int32 firstChar, le_int32 lastChar);
00580 
00581     void computeScripts();
00582 
00583     void computeLocales();
00584 
00585     void computeSubFonts(const FontRuns *fontRuns, LEErrorCode &status);
00586 
00587     void computeMetrics();
00588 
00589     le_int32 getLanguageCode(const Locale *locale);
00590 
00591     le_int32 getCharRun(le_int32 charIndex);
00592 
00593     static le_bool isComplex(UScriptCode script);
00594 
00595     le_int32 previousBreak(le_int32 charIndex);
00596 
00597 
00598     const LEUnicode *fChars;
00599           le_int32   fCharCount;
00600 
00601     const FontRuns   *fFontRuns;
00602     const ValueRuns  *fLevelRuns;
00603     const ValueRuns  *fScriptRuns;
00604     const LocaleRuns *fLocaleRuns;
00605 
00606           le_bool fVertical;
00607           le_bool fClientLevels;
00608           le_bool fClientScripts;
00609           le_bool fClientLocales;
00610 
00611           UBiDiLevel *fEmbeddingLevels;
00612 
00613           le_int32 fAscent;
00614           le_int32 fDescent;
00615           le_int32 fLeading;
00616 
00617           le_int32 *fGlyphToCharMap;
00618           le_int32 *fCharToMinGlyphMap;
00619           le_int32 *fCharToMaxGlyphMap;
00620           float    *fGlyphWidths;
00621           le_int32  fGlyphCount;
00622 
00623           UBiDi *fParaBidi;
00624           UBiDi *fLineBidi;
00625 
00626           le_int32     *fStyleRunLimits;
00627           le_int32     *fStyleIndices;
00628           StyleRunInfo *fStyleRunInfo;
00629           le_int32      fStyleRunCount;
00630 
00631           BreakIterator *fBreakIterator;
00632           le_int32       fLineStart;
00633           le_int32       fLineEnd;
00634 
00635           le_int32       fFirstVisualRun;
00636           le_int32       fLastVisualRun;
00637           float          fVisualRunLastX;
00638           float          fVisualRunLastY;
00639 };
00640 
00641 inline UBiDiLevel ParagraphLayout::getParagraphLevel()
00642 {
00643     return ubidi_getParaLevel(fParaBidi);
00644 }
00645 
00646 inline UBiDiDirection ParagraphLayout::getTextDirection()
00647 {
00648     return ubidi_getDirection(fParaBidi);
00649 }
00650 
00651 inline void ParagraphLayout::reflow()
00652 {
00653     fLineEnd = 0;
00654 }
00655 
00656 inline ParagraphLayout::Line::Line()
00657     : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
00658 {
00659     // nothing else to do
00660 }
00661 
00662 inline ParagraphLayout::Line::Line(const Line & /*other*/)
00663     : UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
00664 {
00665     // nothing else to do
00666 }
00667 
00668 inline le_int32 ParagraphLayout::Line::countRuns() const
00669 {
00670     return fRunCount;
00671 }
00672 
00673 inline const LEFontInstance *ParagraphLayout::VisualRun::getFont() const
00674 {
00675     return fFont;
00676 }
00677 
00678 inline UBiDiDirection ParagraphLayout::VisualRun::getDirection() const
00679 {
00680     return fDirection;
00681 }
00682 
00683 inline le_int32 ParagraphLayout::VisualRun::getGlyphCount() const
00684 {
00685     return fGlyphCount;
00686 }
00687 
00688 inline const LEGlyphID *ParagraphLayout::VisualRun::getGlyphs() const
00689 {
00690     return fGlyphs;
00691 }
00692 
00693 inline const float *ParagraphLayout::VisualRun::getPositions() const
00694 {
00695     return fPositions;
00696 }
00697 
00698 inline const le_int32 *ParagraphLayout::VisualRun::getGlyphToCharMap() const
00699 {
00700     return fGlyphToCharMap;
00701 }
00702 
00703 inline le_int32 ParagraphLayout::VisualRun::getAscent() const
00704 {
00705     return fFont->getAscent();
00706 }
00707 
00708 inline le_int32 ParagraphLayout::VisualRun::getDescent() const
00709 {
00710     return fFont->getDescent();
00711 }
00712 
00713 inline le_int32 ParagraphLayout::VisualRun::getLeading() const
00714 {
00715     return fFont->getLeading();
00716 }
00717 
00718 inline ParagraphLayout::VisualRun::VisualRun()
00719     : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
00720 {
00721     // nothing
00722 }
00723 
00724 inline ParagraphLayout::VisualRun::VisualRun(const VisualRun &/*other*/)
00725     : UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
00726 {
00727     // nothing
00728 }
00729 
00730 inline ParagraphLayout::VisualRun::VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
00731                                              const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[])
00732     : fFont(font), fDirection(direction), fGlyphCount(glyphCount),
00733       fGlyphs(glyphs), fPositions(positions), fGlyphToCharMap(glyphToCharMap)
00734 {
00735     // nothing else needs to be done!
00736 }
00737 
00738 U_NAMESPACE_END
00739 #endif
00740 #endif

Generated on 25 Nov 2014 for ICU 50.1.2 by  doxygen 1.4.7