Home | History | Annotate | Download | only in layout
      1 /*
      2  * %W% %E%
      3  *
      4  * (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
      5  *
      6  */
      7 
      8 #ifndef __SCRIPTCOMPOSITEFONTINSTANCE_H
      9 #define __SCRIPTCOMPOSITEFONTINSTANCE_H
     10 
     11 #include "layout/LETypes.h"
     12 #include "layout/LEFontInstance.h"
     13 
     14 #include "FontMap.h"
     15 
     16 // U_NAMESPACE_BEGIN
     17 
     18 class ScriptCompositeFontInstance : public LEFontInstance
     19 {
     20 public:
     21 
     22     ScriptCompositeFontInstance(FontMap *fontMap);
     23 
     24     virtual ~ScriptCompositeFontInstance();
     25 
     26       /**
     27      * Get a physical font which can render the given text. For composite fonts,
     28      * if there is no single physical font which can render all of the text,
     29      * return a physical font which can render an initial substring of the text,
     30      * and set the <code>offset</code> parameter to the end of that substring.
     31      *
     32      * Internally, the LayoutEngine works with runs of text all in the same
     33      * font and script, so it is best to call this method with text which is
     34      * in a single script, passing the script code in as a hint. If you don't
     35      * know the script of the text, you can use zero, which is the script code
     36      * for characters used in more than one script.
     37      *
     38      * The default implementation of this method is intended for instances of
     39      * <code>LEFontInstance</code> which represent a physical font. It returns
     40      * <code>this</code> and indicates that the entire string can be rendered.
     41      *
     42      * This method will return a valid <code>LEFontInstance</code> unless you
     43      * have passed illegal parameters, or an internal error has been encountered.
     44      * For composite fonts, it may return the warning <code>LE_NO_SUBFONT_WARNING</code>
     45      * to indicate that the returned font may not be able to render all of
     46      * the text. Whenever a valid font is returned, the <code>offset</code> parameter
     47      * will be advanced by at least one.
     48      *
     49      * Subclasses which implement composite fonts must override this method.
     50      * Where it makes sense, they should use the script code as a hint to render
     51      * characters from the COMMON script in the font which is used for the given
     52      * script. For example, if the input text is a series of Arabic words separated
     53      * by spaces, and the script code passed in is <code>arabScriptCode</code> you
     54      * should return the font used for Arabic characters for all of the input text,
     55      * including the spaces. If, on the other hand, the input text contains characters
     56      * which cannot be rendered by the font used for Arabic characters, but which can
     57      * be rendered by another font, you should return that font for those characters.
     58      *
     59      * @param chars   - the array of Unicode characters.
     60      * @param offset  - a pointer to the starting offset in the text. On exit this
     61      *                  will be set the the limit offset of the text which can be
     62      *                  rendered using the returned font.
     63      * @param limit   - the limit offset for the input text.
     64      * @param script  - the script hint.
     65      * @param success - set to an error code if the arguments are illegal, or no font
     66      *                  can be returned for some reason. May also be set to
     67      *                  <code>LE_NO_SUBFONT_WARNING</code> if the subfont which
     68      *                  was returned cannot render all of the text.
     69      *
     70      * @return an <code>LEFontInstance</code> for the sub font which can render the characters, or
     71      *         <code>NULL</code> if there is an error.
     72      *
     73      * @see LEScripts.h
     74      */
     75     virtual const LEFontInstance *getSubFont(const LEUnicode chars[], le_int32 *offset, le_int32 limit, le_int32 script, LEErrorCode &success) const;
     76 
     77     /**
     78      * This method maps a single character to a glyph index, using the
     79      * font's charcter to glyph map.
     80      *
     81      * @param ch - the character
     82      *
     83      * @return the glyph index
     84      */
     85     virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const;
     86 
     87     virtual const void *getFontTable(LETag tableTag) const;
     88 
     89     virtual le_int32 getUnitsPerEM() const;
     90 
     91     virtual le_int32 getAscent() const;
     92 
     93     virtual le_int32 getDescent() const;
     94 
     95     virtual le_int32 getLeading() const;
     96 
     97     virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const;
     98 
     99     virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const;
    100 
    101     float getXPixelsPerEm() const;
    102 
    103     float getYPixelsPerEm() const;
    104 
    105     float getScaleFactorX() const;
    106 
    107     float getScaleFactorY() const;
    108 
    109     /**
    110      * ICU "poor man's RTTI", returns a UClassID for the actual class.
    111      */
    112     virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
    113 
    114     /**
    115      * ICU "poor man's RTTI", returns a UClassID for this class.
    116      */
    117     static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
    118 
    119 protected:
    120     FontMap *fFontMap;
    121 
    122 private:
    123 
    124     /**
    125      * The address of this static class variable serves as this class's ID
    126      * for ICU "poor man's RTTI".
    127      */
    128     static const char fgClassID;
    129 };
    130 
    131 inline const void *ScriptCompositeFontInstance::getFontTable(LETag /*tableTag*/) const
    132 {
    133     return NULL;
    134 }
    135 
    136 // Can't get units per EM without knowing which sub-font, so
    137 // return a value that will make units == points
    138 inline le_int32 ScriptCompositeFontInstance::getUnitsPerEM() const
    139 {
    140     return 1;
    141 }
    142 
    143 inline le_int32 ScriptCompositeFontInstance::getAscent() const
    144 {
    145     return fFontMap->getAscent();
    146 }
    147 
    148 inline le_int32 ScriptCompositeFontInstance::getDescent() const
    149 {
    150     return fFontMap->getDescent();
    151 }
    152 
    153 inline le_int32 ScriptCompositeFontInstance::getLeading() const
    154 {
    155     return fFontMap->getLeading();
    156 }
    157 
    158 inline float ScriptCompositeFontInstance::getXPixelsPerEm() const
    159 {
    160     return fFontMap->getPointSize();
    161 }
    162 
    163 inline float ScriptCompositeFontInstance::getYPixelsPerEm() const
    164 {
    165     return fFontMap->getPointSize();
    166 }
    167 
    168 // Can't get a scale factor without knowing the sub-font, so
    169 // return 1.0.
    170 inline float ScriptCompositeFontInstance::getScaleFactorX() const
    171 {
    172     return 1.0;
    173 }
    174 
    175 // Can't get a scale factor without knowing the sub-font, so
    176 // return 1.0
    177 inline float ScriptCompositeFontInstance::getScaleFactorY() const
    178 {
    179     return 1.0;
    180 }
    181 
    182 // U_NAMESPACE_END
    183 #endif
    184