LEFontInstance.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /*
  2. *
  3. * (C) Copyright IBM Corp. 1998-2015 - All Rights Reserved
  4. *
  5. */
  6. #ifndef __LEFONTINSTANCE_H
  7. #define __LEFONTINSTANCE_H
  8. #include "LETypes.h"
  9. /**
  10. * \file
  11. * \brief C++ API: Layout Engine Font Instance object
  12. */
  13. U_NAMESPACE_BEGIN
  14. /**
  15. * Instances of this class are used by <code>LEFontInstance::mapCharsToGlyphs</code> and
  16. * <code>LEFontInstance::mapCharToGlyph</code> to adjust character codes before the character
  17. * to glyph mapping process. Examples of this are filtering out control characters
  18. * and character mirroring - replacing a character which has both a left and a right
  19. * hand form with the opposite form.
  20. *
  21. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  22. */
  23. class LECharMapper /* not : public UObject because this is an interface/mixin class */
  24. {
  25. public:
  26. /**
  27. * Destructor.
  28. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  29. */
  30. virtual ~LECharMapper();
  31. /**
  32. * This method does the adjustments.
  33. *
  34. * @param ch - the input character
  35. *
  36. * @return the adjusted character
  37. *
  38. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  39. */
  40. virtual LEUnicode32 mapChar(LEUnicode32 ch) const = 0;
  41. };
  42. /**
  43. * This is a forward reference to the class which holds the per-glyph
  44. * storage.
  45. *
  46. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  47. */
  48. class LEGlyphStorage;
  49. /**
  50. * This is a virtual base class that serves as the interface between a LayoutEngine
  51. * and the platform font environment. It allows a LayoutEngine to access font tables, do
  52. * character to glyph mapping, and obtain metrics information without knowing any platform
  53. * specific details. There are also a few utility methods for converting between points,
  54. * pixels and funits. (font design units)
  55. *
  56. * An instance of an <code>LEFontInstance</code> represents a font at a particular point
  57. * size. Each instance can represent either a single physical font, or a composite font.
  58. * A composite font is a collection of physical fonts, each of which contains a subset of
  59. * the characters contained in the composite font.
  60. *
  61. * Note: with the exception of <code>getSubFont</code>, the methods in this class only
  62. * make sense for a physical font. If you have an <code>LEFontInstance</code> which
  63. * represents a composite font you should only call the methods below which have
  64. * an <code>LEGlyphID</code>, an <code>LEUnicode</code> or an <code>LEUnicode32</code>
  65. * as one of the arguments because these can be used to select a particular subfont.
  66. *
  67. * Subclasses which implement composite fonts should supply an implementation of these
  68. * methods with some default behavior such as returning constant values, or using the
  69. * values from the first subfont.
  70. *
  71. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  72. */
  73. class U_LAYOUT_API LEFontInstance : public UObject
  74. {
  75. public:
  76. /**
  77. * This virtual destructor is here so that the subclass
  78. * destructors can be invoked through the base class.
  79. *
  80. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  81. */
  82. virtual ~LEFontInstance();
  83. /**
  84. * Get a physical font which can render the given text. For composite fonts,
  85. * if there is no single physical font which can render all of the text,
  86. * return a physical font which can render an initial substring of the text,
  87. * and set the <code>offset</code> parameter to the end of that substring.
  88. *
  89. * Internally, the LayoutEngine works with runs of text all in the same
  90. * font and script, so it is best to call this method with text which is
  91. * in a single script, passing the script code in as a hint. If you don't
  92. * know the script of the text, you can use zero, which is the script code
  93. * for characters used in more than one script.
  94. *
  95. * The default implementation of this method is intended for instances of
  96. * <code>LEFontInstance</code> which represent a physical font. It returns
  97. * <code>this</code> and indicates that the entire string can be rendered.
  98. *
  99. * This method will return a valid <code>LEFontInstance</code> unless you
  100. * have passed illegal parameters, or an internal error has been encountered.
  101. * For composite fonts, it may return the warning <code>LE_NO_SUBFONT_WARNING</code>
  102. * to indicate that the returned font may not be able to render all of
  103. * the text. Whenever a valid font is returned, the <code>offset</code> parameter
  104. * will be advanced by at least one.
  105. *
  106. * Subclasses which implement composite fonts must override this method.
  107. * Where it makes sense, they should use the script code as a hint to render
  108. * characters from the COMMON script in the font which is used for the given
  109. * script. For example, if the input text is a series of Arabic words separated
  110. * by spaces, and the script code passed in is <code>arabScriptCode</code> you
  111. * should return the font used for Arabic characters for all of the input text,
  112. * including the spaces. If, on the other hand, the input text contains characters
  113. * which cannot be rendered by the font used for Arabic characters, but which can
  114. * be rendered by another font, you should return that font for those characters.
  115. *
  116. * @param chars - the array of Unicode characters.
  117. * @param offset - a pointer to the starting offset in the text. On exit this
  118. * will be set the the limit offset of the text which can be
  119. * rendered using the returned font.
  120. * @param limit - the limit offset for the input text.
  121. * @param script - the script hint.
  122. * @param success - set to an error code if the arguments are illegal, or no font
  123. * can be returned for some reason. May also be set to
  124. * <code>LE_NO_SUBFONT_WARNING</code> if the subfont which
  125. * was returned cannot render all of the text.
  126. *
  127. * @return an <code>LEFontInstance</code> for the sub font which can render the characters, or
  128. * <code>NULL</code> if there is an error.
  129. *
  130. * @see LEScripts.h
  131. *
  132. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  133. */
  134. virtual const LEFontInstance *getSubFont(const LEUnicode chars[], le_int32 *offset, le_int32 limit, le_int32 script, LEErrorCode &success) const;
  135. //
  136. // Font file access
  137. //
  138. /**
  139. * This method reads a table from the font. Note that in general,
  140. * it only makes sense to call this method on an <code>LEFontInstance</code>
  141. * which represents a physical font - i.e. one which has been returned by
  142. * <code>getSubFont()</code>. This is because each subfont in a composite font
  143. * will have different tables, and there's no way to know which subfont to access.
  144. *
  145. * Subclasses which represent composite fonts should always return <code>NULL</code>.
  146. *
  147. * @param tableTag - the four byte table tag. (e.g. 'cmap')
  148. * @param length - ignored on entry, on exit will be the length of the table if known, or -1 if unknown.
  149. * @return the address of the table in memory, or <code>NULL</code>
  150. * if the table doesn't exist.
  151. * @deprecated ICU 54. See {@link LayoutEngine}
  152. */
  153. virtual const void* getFontTable(LETag tableTag, size_t &length) const = 0;
  154. /**
  155. * This method is used to determine if the font can
  156. * render the given character. This can usually be done
  157. * by looking the character up in the font's character
  158. * to glyph mapping.
  159. *
  160. * The default implementation of this method will return
  161. * <code>TRUE</code> if <code>mapCharToGlyph(ch)</code>
  162. * returns a non-zero value.
  163. *
  164. * @param ch - the character to be tested
  165. *
  166. * @return <code>TRUE</code> if the font can render ch.
  167. *
  168. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  169. */
  170. virtual le_bool canDisplay(LEUnicode32 ch) const;
  171. /**
  172. * This method returns the number of design units in
  173. * the font's EM square.
  174. *
  175. * @return the number of design units pre EM.
  176. *
  177. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  178. */
  179. virtual le_int32 getUnitsPerEM() const = 0;
  180. /**
  181. * This method maps an array of character codes to an array of glyph
  182. * indices, using the font's character to glyph map.
  183. *
  184. * The default implementation iterates over all of the characters and calls
  185. * <code>mapCharToGlyph(ch, mapper)</code> on each one. It also handles surrogate
  186. * characters, storing the glyph ID for the high surrogate, and a deleted glyph (0xFFFF)
  187. * for the low surrogate.
  188. *
  189. * Most sublcasses will not need to implement this method.
  190. *
  191. * @param chars - the character array
  192. * @param offset - the index of the first character
  193. * @param count - the number of characters
  194. * @param reverse - if <code>TRUE</code>, store the glyph indices in reverse order.
  195. * @param mapper - the character mapper.
  196. * @param filterZeroWidth - <code>TRUE</code> if ZWJ / ZWNJ characters should map to a glyph w/ no contours.
  197. * @param glyphStorage - the object which contains the output glyph array
  198. *
  199. * @see LECharMapper
  200. *
  201. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  202. */
  203. virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, const LECharMapper *mapper, le_bool filterZeroWidth, LEGlyphStorage &glyphStorage) const;
  204. /**
  205. * This method maps a single character to a glyph index, using the
  206. * font's character to glyph map. The default implementation of this
  207. * method calls the mapper, and then calls <code>mapCharToGlyph(mappedCh)</code>.
  208. *
  209. * @param ch - the character
  210. * @param mapper - the character mapper
  211. * @param filterZeroWidth - <code>TRUE</code> if ZWJ / ZWNJ characters should map to a glyph w/ no contours.
  212. *
  213. * @return the glyph index
  214. *
  215. * @see LECharMapper
  216. *
  217. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  218. */
  219. virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper, le_bool filterZeroWidth) const;
  220. /**
  221. * This method maps a single character to a glyph index, using the
  222. * font's character to glyph map. The default implementation of this
  223. * method calls the mapper, and then calls <code>mapCharToGlyph(mappedCh)</code>.
  224. *
  225. * @param ch - the character
  226. * @param mapper - the character mapper
  227. *
  228. * @return the glyph index
  229. *
  230. * @see LECharMapper
  231. *
  232. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  233. */
  234. virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const;
  235. /**
  236. * This method maps a single character to a glyph index, using the
  237. * font's character to glyph map. There is no default implementation
  238. * of this method because it requires information about the platform
  239. * font implementation.
  240. *
  241. * @param ch - the character
  242. *
  243. * @return the glyph index
  244. *
  245. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  246. */
  247. virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const = 0;
  248. //
  249. // Metrics
  250. //
  251. /**
  252. * This method gets the X and Y advance of a particular glyph, in pixels.
  253. *
  254. * @param glyph - the glyph index
  255. * @param advance - the X and Y pixel values will be stored here
  256. *
  257. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  258. */
  259. virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const = 0;
  260. /**
  261. * This method gets the hinted X and Y pixel coordinates of a particular
  262. * point in the outline of the given glyph.
  263. *
  264. * @param glyph - the glyph index
  265. * @param pointNumber - the number of the point
  266. * @param point - the point's X and Y pixel values will be stored here
  267. *
  268. * @return <code>TRUE</code> if the point coordinates could be stored.
  269. *
  270. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  271. */
  272. virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const = 0;
  273. /**
  274. * This method returns the width of the font's EM square
  275. * in pixels.
  276. *
  277. * @return the pixel width of the EM square
  278. *
  279. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  280. */
  281. virtual float getXPixelsPerEm() const = 0;
  282. /**
  283. * This method returns the height of the font's EM square
  284. * in pixels.
  285. *
  286. * @return the pixel height of the EM square
  287. *
  288. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  289. */
  290. virtual float getYPixelsPerEm() const = 0;
  291. /**
  292. * This method converts font design units in the
  293. * X direction to points.
  294. *
  295. * @param xUnits - design units in the X direction
  296. *
  297. * @return points in the X direction
  298. *
  299. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  300. */
  301. virtual float xUnitsToPoints(float xUnits) const;
  302. /**
  303. * This method converts font design units in the
  304. * Y direction to points.
  305. *
  306. * @param yUnits - design units in the Y direction
  307. *
  308. * @return points in the Y direction
  309. *
  310. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  311. */
  312. virtual float yUnitsToPoints(float yUnits) const;
  313. /**
  314. * This method converts font design units to points.
  315. *
  316. * @param units - X and Y design units
  317. * @param points - set to X and Y points
  318. *
  319. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  320. */
  321. virtual void unitsToPoints(LEPoint &units, LEPoint &points) const;
  322. /**
  323. * This method converts pixels in the
  324. * X direction to font design units.
  325. *
  326. * @param xPixels - pixels in the X direction
  327. *
  328. * @return font design units in the X direction
  329. *
  330. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  331. */
  332. virtual float xPixelsToUnits(float xPixels) const;
  333. /**
  334. * This method converts pixels in the
  335. * Y direction to font design units.
  336. *
  337. * @param yPixels - pixels in the Y direction
  338. *
  339. * @return font design units in the Y direction
  340. *
  341. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  342. */
  343. virtual float yPixelsToUnits(float yPixels) const;
  344. /**
  345. * This method converts pixels to font design units.
  346. *
  347. * @param pixels - X and Y pixel
  348. * @param units - set to X and Y font design units
  349. *
  350. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  351. */
  352. virtual void pixelsToUnits(LEPoint &pixels, LEPoint &units) const;
  353. /**
  354. * Get the X scale factor from the font's transform. The default
  355. * implementation of <code>transformFunits()</code> will call this method.
  356. *
  357. * @return the X scale factor.
  358. *
  359. *
  360. * @see transformFunits
  361. *
  362. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  363. */
  364. virtual float getScaleFactorX() const = 0;
  365. /**
  366. * Get the Y scale factor from the font's transform. The default
  367. * implementation of <code>transformFunits()</code> will call this method.
  368. *
  369. * @return the Yscale factor.
  370. *
  371. * @see transformFunits
  372. *
  373. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  374. */
  375. virtual float getScaleFactorY() const = 0;
  376. /**
  377. * This method transforms an X, Y point in font design units to a
  378. * pixel coordinate, applying the font's transform. The default
  379. * implementation of this method calls <code>getScaleFactorX()</code>
  380. * and <code>getScaleFactorY()</code>.
  381. *
  382. * @param xFunits - the X coordinate in font design units
  383. * @param yFunits - the Y coordinate in font design units
  384. * @param pixels - the tranformed co-ordinate in pixels
  385. *
  386. * @see getScaleFactorX
  387. * @see getScaleFactorY
  388. *
  389. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  390. */
  391. virtual void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const;
  392. /**
  393. * This is a convenience method used to convert
  394. * values in a 16.16 fixed point format to floating point.
  395. *
  396. * @param fixed - the fixed point value
  397. *
  398. * @return the floating point value
  399. *
  400. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  401. */
  402. static inline float fixedToFloat(le_int32 fixed);
  403. /**
  404. * This is a convenience method used to convert
  405. * floating point values to 16.16 fixed point format.
  406. *
  407. * @param theFloat - the floating point value
  408. *
  409. * @return the fixed point value
  410. *
  411. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  412. */
  413. static inline le_int32 floatToFixed(float theFloat);
  414. //
  415. // These methods won't ever be called by the LayoutEngine,
  416. // but are useful for clients of <code>LEFontInstance</code> who
  417. // need to render text.
  418. //
  419. /**
  420. * Get the font's ascent.
  421. *
  422. * @return the font's ascent, in points. This value
  423. * will always be positive.
  424. *
  425. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  426. */
  427. virtual le_int32 getAscent() const = 0;
  428. /**
  429. * Get the font's descent.
  430. *
  431. * @return the font's descent, in points. This value
  432. * will always be positive.
  433. *
  434. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  435. */
  436. virtual le_int32 getDescent() const = 0;
  437. /**
  438. * Get the font's leading.
  439. *
  440. * @return the font's leading, in points. This value
  441. * will always be positive.
  442. *
  443. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  444. */
  445. virtual le_int32 getLeading() const = 0;
  446. /**
  447. * Get the line height required to display text in
  448. * this font. The default implementation of this method
  449. * returns the sum of the ascent, descent, and leading.
  450. *
  451. * @return the line height, in points. This vaule will
  452. * always be positive.
  453. *
  454. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  455. */
  456. virtual le_int32 getLineHeight() const;
  457. /**
  458. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  459. *
  460. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  461. */
  462. virtual UClassID getDynamicClassID() const;
  463. /**
  464. * ICU "poor man's RTTI", returns a UClassID for this class.
  465. *
  466. * @deprecated ICU 54. See {@link icu::LayoutEngine}
  467. */
  468. static UClassID getStaticClassID();
  469. };
  470. inline float LEFontInstance::fixedToFloat(le_int32 fixed)
  471. {
  472. return (float) (fixed / 65536.0);
  473. }
  474. inline le_int32 LEFontInstance::floatToFixed(float theFloat)
  475. {
  476. return (le_int32) (theFloat * 65536.0);
  477. }
  478. U_NAMESPACE_END
  479. #endif