ScriptCompositeFontInstance.h 6.2 KB

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