The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

762 lines
26KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. PositionedGlyph::PositionedGlyph() noexcept
  19. : character (0), glyph (0), x (0), y (0), w (0), whitespace (false)
  20. {
  21. }
  22. PositionedGlyph::PositionedGlyph (const Font& font_, const juce_wchar character_, const int glyph_,
  23. const float x_, const float y_, const float w_, const bool whitespace_)
  24. : font (font_), character (character_), glyph (glyph_),
  25. x (x_), y (y_), w (w_), whitespace (whitespace_)
  26. {
  27. }
  28. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  29. : font (other.font), character (other.character), glyph (other.glyph),
  30. x (other.x), y (other.y), w (other.w), whitespace (other.whitespace)
  31. {
  32. }
  33. PositionedGlyph::~PositionedGlyph() {}
  34. PositionedGlyph& PositionedGlyph::operator= (const PositionedGlyph& other)
  35. {
  36. font = other.font;
  37. character = other.character;
  38. glyph = other.glyph;
  39. x = other.x;
  40. y = other.y;
  41. w = other.w;
  42. whitespace = other.whitespace;
  43. return *this;
  44. }
  45. static inline void drawGlyphWithFont (const Graphics& g, int glyph, const Font& font, const AffineTransform& t)
  46. {
  47. LowLevelGraphicsContext& context = g.getInternalContext();
  48. context.setFont (font);
  49. context.drawGlyph (glyph, t);
  50. }
  51. void PositionedGlyph::draw (const Graphics& g) const
  52. {
  53. if (! isWhitespace())
  54. drawGlyphWithFont (g, glyph, font, AffineTransform::translation (x, y));
  55. }
  56. void PositionedGlyph::draw (const Graphics& g, const AffineTransform& transform) const
  57. {
  58. if (! isWhitespace())
  59. drawGlyphWithFont (g, glyph, font, AffineTransform::translation (x, y).followedBy (transform));
  60. }
  61. void PositionedGlyph::createPath (Path& path) const
  62. {
  63. if (! isWhitespace())
  64. {
  65. if (Typeface* const t = font.getTypeface())
  66. {
  67. Path p;
  68. t->getOutlineForGlyph (glyph, p);
  69. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  70. .translated (x, y));
  71. }
  72. }
  73. }
  74. bool PositionedGlyph::hitTest (float px, float py) const
  75. {
  76. if (getBounds().contains (px, py) && ! isWhitespace())
  77. {
  78. if (Typeface* const t = font.getTypeface())
  79. {
  80. Path p;
  81. t->getOutlineForGlyph (glyph, p);
  82. AffineTransform::translation (-x, -y)
  83. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  84. .transformPoint (px, py);
  85. return p.contains (px, py);
  86. }
  87. }
  88. return false;
  89. }
  90. void PositionedGlyph::moveBy (const float deltaX,
  91. const float deltaY)
  92. {
  93. x += deltaX;
  94. y += deltaY;
  95. }
  96. //==============================================================================
  97. GlyphArrangement::GlyphArrangement()
  98. {
  99. glyphs.ensureStorageAllocated (128);
  100. }
  101. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  102. : glyphs (other.glyphs)
  103. {
  104. }
  105. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  106. {
  107. glyphs = other.glyphs;
  108. return *this;
  109. }
  110. GlyphArrangement::~GlyphArrangement()
  111. {
  112. }
  113. //==============================================================================
  114. void GlyphArrangement::clear()
  115. {
  116. glyphs.clear();
  117. }
  118. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const noexcept
  119. {
  120. return glyphs.getReference (index);
  121. }
  122. //==============================================================================
  123. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  124. {
  125. glyphs.addArray (other.glyphs);
  126. }
  127. void GlyphArrangement::addGlyph (const PositionedGlyph& glyph)
  128. {
  129. glyphs.add (glyph);
  130. }
  131. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  132. {
  133. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  134. }
  135. //==============================================================================
  136. void GlyphArrangement::addLineOfText (const Font& font,
  137. const String& text,
  138. const float xOffset,
  139. const float yOffset)
  140. {
  141. addCurtailedLineOfText (font, text, xOffset, yOffset, 1.0e10f, false);
  142. }
  143. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  144. const String& text,
  145. const float xOffset,
  146. const float yOffset,
  147. const float maxWidthPixels,
  148. const bool useEllipsis)
  149. {
  150. if (text.isNotEmpty())
  151. {
  152. Array <int> newGlyphs;
  153. Array <float> xOffsets;
  154. font.getGlyphPositions (text, newGlyphs, xOffsets);
  155. const int textLen = newGlyphs.size();
  156. glyphs.ensureStorageAllocated (glyphs.size() + textLen);
  157. String::CharPointerType t (text.getCharPointer());
  158. for (int i = 0; i < textLen; ++i)
  159. {
  160. const float nextX = xOffsets.getUnchecked (i + 1);
  161. if (nextX > maxWidthPixels + 1.0f)
  162. {
  163. // curtail the string if it's too wide..
  164. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  165. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  166. break;
  167. }
  168. else
  169. {
  170. const float thisX = xOffsets.getUnchecked (i);
  171. const bool isWhitespace = t.isWhitespace();
  172. glyphs.add (PositionedGlyph (font, t.getAndAdvance(),
  173. newGlyphs.getUnchecked(i),
  174. xOffset + thisX, yOffset,
  175. nextX - thisX, isWhitespace));
  176. }
  177. }
  178. }
  179. }
  180. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  181. const int startIndex, int endIndex)
  182. {
  183. int numDeleted = 0;
  184. if (glyphs.size() > 0)
  185. {
  186. Array<int> dotGlyphs;
  187. Array<float> dotXs;
  188. font.getGlyphPositions ("..", dotGlyphs, dotXs);
  189. const float dx = dotXs[1];
  190. float xOffset = 0.0f, yOffset = 0.0f;
  191. while (endIndex > startIndex)
  192. {
  193. const PositionedGlyph& pg = glyphs.getReference (--endIndex);
  194. xOffset = pg.x;
  195. yOffset = pg.y;
  196. glyphs.remove (endIndex);
  197. ++numDeleted;
  198. if (xOffset + dx * 3 <= maxXPos)
  199. break;
  200. }
  201. for (int i = 3; --i >= 0;)
  202. {
  203. glyphs.insert (endIndex++, PositionedGlyph (font, '.', dotGlyphs.getFirst(),
  204. xOffset, yOffset, dx, false));
  205. --numDeleted;
  206. xOffset += dx;
  207. if (xOffset > maxXPos)
  208. break;
  209. }
  210. }
  211. return numDeleted;
  212. }
  213. void GlyphArrangement::addJustifiedText (const Font& font,
  214. const String& text,
  215. float x, float y,
  216. const float maxLineWidth,
  217. const Justification& horizontalLayout)
  218. {
  219. int lineStartIndex = glyphs.size();
  220. addLineOfText (font, text, x, y);
  221. const float originalY = y;
  222. while (lineStartIndex < glyphs.size())
  223. {
  224. int i = lineStartIndex;
  225. if (glyphs.getReference(i).getCharacter() != '\n'
  226. && glyphs.getReference(i).getCharacter() != '\r')
  227. ++i;
  228. const float lineMaxX = glyphs.getReference (lineStartIndex).getLeft() + maxLineWidth;
  229. int lastWordBreakIndex = -1;
  230. while (i < glyphs.size())
  231. {
  232. const PositionedGlyph& pg = glyphs.getReference (i);
  233. const juce_wchar c = pg.getCharacter();
  234. if (c == '\r' || c == '\n')
  235. {
  236. ++i;
  237. if (c == '\r' && i < glyphs.size()
  238. && glyphs.getReference(i).getCharacter() == '\n')
  239. ++i;
  240. break;
  241. }
  242. else if (pg.isWhitespace())
  243. {
  244. lastWordBreakIndex = i + 1;
  245. }
  246. else if (pg.getRight() - 0.0001f >= lineMaxX)
  247. {
  248. if (lastWordBreakIndex >= 0)
  249. i = lastWordBreakIndex;
  250. break;
  251. }
  252. ++i;
  253. }
  254. const float currentLineStartX = glyphs.getReference (lineStartIndex).getLeft();
  255. float currentLineEndX = currentLineStartX;
  256. for (int j = i; --j >= lineStartIndex;)
  257. {
  258. if (! glyphs.getReference (j).isWhitespace())
  259. {
  260. currentLineEndX = glyphs.getReference (j).getRight();
  261. break;
  262. }
  263. }
  264. float deltaX = 0.0f;
  265. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  266. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  267. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  268. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  269. else if (horizontalLayout.testFlags (Justification::right))
  270. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  271. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  272. x + deltaX - currentLineStartX, y - originalY);
  273. lineStartIndex = i;
  274. y += font.getHeight();
  275. }
  276. }
  277. void GlyphArrangement::addFittedText (const Font& f,
  278. const String& text,
  279. const float x, const float y,
  280. const float width, const float height,
  281. const Justification& layout,
  282. int maximumLines,
  283. const float minimumHorizontalScale)
  284. {
  285. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  286. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  287. if (text.containsAnyOf ("\r\n"))
  288. {
  289. GlyphArrangement ga;
  290. ga.addJustifiedText (f, text, x, y, width, layout);
  291. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  292. float dy = y - bb.getY();
  293. if (layout.testFlags (Justification::verticallyCentred)) dy += (height - bb.getHeight()) * 0.5f;
  294. else if (layout.testFlags (Justification::bottom)) dy += (height - bb.getHeight());
  295. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  296. glyphs.addArray (ga.glyphs);
  297. return;
  298. }
  299. int startIndex = glyphs.size();
  300. addLineOfText (f, text.trim(), x, y);
  301. if (glyphs.size() > startIndex)
  302. {
  303. float lineWidth = glyphs.getReference (glyphs.size() - 1).getRight()
  304. - glyphs.getReference (startIndex).getLeft();
  305. if (lineWidth <= 0)
  306. return;
  307. if (lineWidth * minimumHorizontalScale < width)
  308. {
  309. if (lineWidth > width)
  310. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  311. width / lineWidth);
  312. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  313. x, y, width, height, layout);
  314. }
  315. else if (maximumLines <= 1)
  316. {
  317. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  318. x, y, width, height, f, layout, minimumHorizontalScale);
  319. }
  320. else
  321. {
  322. Font font (f);
  323. String txt (text.trim());
  324. const int length = txt.length();
  325. const int originalStartIndex = startIndex;
  326. int numLines = 1;
  327. if (length <= 12 && ! txt.containsAnyOf (" -\t\r\n"))
  328. maximumLines = 1;
  329. maximumLines = jmin (maximumLines, length);
  330. while (numLines < maximumLines)
  331. {
  332. ++numLines;
  333. const float newFontHeight = height / (float) numLines;
  334. if (newFontHeight < font.getHeight())
  335. {
  336. font.setHeight (jmax (8.0f, newFontHeight));
  337. removeRangeOfGlyphs (startIndex, -1);
  338. addLineOfText (font, txt, x, y);
  339. lineWidth = glyphs.getReference (glyphs.size() - 1).getRight()
  340. - glyphs.getReference (startIndex).getLeft();
  341. }
  342. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  343. break;
  344. }
  345. if (numLines < 1)
  346. numLines = 1;
  347. float lineY = y;
  348. float widthPerLine = lineWidth / numLines;
  349. for (int line = 0; line < numLines; ++line)
  350. {
  351. int i = startIndex;
  352. float lineStartX = glyphs.getReference (startIndex).getLeft();
  353. if (line == numLines - 1)
  354. {
  355. widthPerLine = width;
  356. i = glyphs.size();
  357. }
  358. else
  359. {
  360. while (i < glyphs.size())
  361. {
  362. lineWidth = (glyphs.getReference (i).getRight() - lineStartX);
  363. if (lineWidth > widthPerLine)
  364. {
  365. // got to a point where the line's too long, so skip forward to find a
  366. // good place to break it..
  367. const int searchStartIndex = i;
  368. while (i < glyphs.size())
  369. {
  370. if ((glyphs.getReference (i).getRight() - lineStartX) * minimumHorizontalScale < width)
  371. {
  372. if (glyphs.getReference (i).isWhitespace()
  373. || glyphs.getReference (i).getCharacter() == '-')
  374. {
  375. ++i;
  376. break;
  377. }
  378. }
  379. else
  380. {
  381. // can't find a suitable break, so try looking backwards..
  382. i = searchStartIndex;
  383. for (int back = 1; back < jmin (7, i - startIndex - 1); ++back)
  384. {
  385. if (glyphs.getReference (i - back).isWhitespace()
  386. || glyphs.getReference (i - back).getCharacter() == '-')
  387. {
  388. i -= back - 1;
  389. break;
  390. }
  391. }
  392. break;
  393. }
  394. ++i;
  395. }
  396. break;
  397. }
  398. ++i;
  399. }
  400. int wsStart = i;
  401. while (wsStart > 0 && glyphs.getReference (wsStart - 1).isWhitespace())
  402. --wsStart;
  403. int wsEnd = i;
  404. while (wsEnd < glyphs.size() && glyphs.getReference (wsEnd).isWhitespace())
  405. ++wsEnd;
  406. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  407. i = jmax (wsStart, startIndex + 1);
  408. }
  409. i -= fitLineIntoSpace (startIndex, i - startIndex,
  410. x, lineY, width, font.getHeight(), font,
  411. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  412. minimumHorizontalScale);
  413. startIndex = i;
  414. lineY += font.getHeight();
  415. if (startIndex >= glyphs.size())
  416. break;
  417. }
  418. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  419. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  420. }
  421. }
  422. }
  423. //==============================================================================
  424. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num, const float dx, const float dy)
  425. {
  426. jassert (startIndex >= 0);
  427. if (dx != 0.0f || dy != 0.0f)
  428. {
  429. if (num < 0 || startIndex + num > glyphs.size())
  430. num = glyphs.size() - startIndex;
  431. while (--num >= 0)
  432. glyphs.getReference (startIndex++).moveBy (dx, dy);
  433. }
  434. }
  435. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  436. const Justification& justification, float minimumHorizontalScale)
  437. {
  438. int numDeleted = 0;
  439. const float lineStartX = glyphs.getReference (start).getLeft();
  440. float lineWidth = glyphs.getReference (start + numGlyphs - 1).getRight() - lineStartX;
  441. if (lineWidth > w)
  442. {
  443. if (minimumHorizontalScale < 1.0f)
  444. {
  445. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  446. lineWidth = glyphs.getReference (start + numGlyphs - 1).getRight() - lineStartX - 0.5f;
  447. }
  448. if (lineWidth > w)
  449. {
  450. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  451. numGlyphs -= numDeleted;
  452. }
  453. }
  454. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  455. return numDeleted;
  456. }
  457. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  458. const float horizontalScaleFactor)
  459. {
  460. jassert (startIndex >= 0);
  461. if (num < 0 || startIndex + num > glyphs.size())
  462. num = glyphs.size() - startIndex;
  463. if (num > 0)
  464. {
  465. const float xAnchor = glyphs.getReference (startIndex).getLeft();
  466. while (--num >= 0)
  467. {
  468. PositionedGlyph& pg = glyphs.getReference (startIndex++);
  469. pg.x = xAnchor + (pg.x - xAnchor) * horizontalScaleFactor;
  470. pg.font.setHorizontalScale (pg.font.getHorizontalScale() * horizontalScaleFactor);
  471. pg.w *= horizontalScaleFactor;
  472. }
  473. }
  474. }
  475. Rectangle<float> GlyphArrangement::getBoundingBox (int startIndex, int num, const bool includeWhitespace) const
  476. {
  477. jassert (startIndex >= 0);
  478. if (num < 0 || startIndex + num > glyphs.size())
  479. num = glyphs.size() - startIndex;
  480. Rectangle<float> result;
  481. while (--num >= 0)
  482. {
  483. const PositionedGlyph& pg = glyphs.getReference (startIndex++);
  484. if (includeWhitespace || ! pg.isWhitespace())
  485. result = result.getUnion (pg.getBounds());
  486. }
  487. return result;
  488. }
  489. void GlyphArrangement::justifyGlyphs (const int startIndex, const int num,
  490. const float x, const float y, const float width, const float height,
  491. const Justification& justification)
  492. {
  493. jassert (num >= 0 && startIndex >= 0);
  494. if (glyphs.size() > 0 && num > 0)
  495. {
  496. const Rectangle<float> bb (getBoundingBox (startIndex, num, ! justification.testFlags (Justification::horizontallyJustified
  497. | Justification::horizontallyCentred)));
  498. float deltaX = 0.0f, deltaY = 0.0f;
  499. if (justification.testFlags (Justification::horizontallyJustified)) deltaX = x - bb.getX();
  500. else if (justification.testFlags (Justification::horizontallyCentred)) deltaX = x + (width - bb.getWidth()) * 0.5f - bb.getX();
  501. else if (justification.testFlags (Justification::right)) deltaX = x + width - bb.getRight();
  502. else deltaX = x - bb.getX();
  503. if (justification.testFlags (Justification::top)) deltaY = y - bb.getY();
  504. else if (justification.testFlags (Justification::bottom)) deltaY = y + height - bb.getBottom();
  505. else deltaY = y + (height - bb.getHeight()) * 0.5f - bb.getY();
  506. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  507. if (justification.testFlags (Justification::horizontallyJustified))
  508. {
  509. int lineStart = 0;
  510. float baseY = glyphs.getReference (startIndex).getBaselineY();
  511. int i;
  512. for (i = 0; i < num; ++i)
  513. {
  514. const float glyphY = glyphs.getReference (startIndex + i).getBaselineY();
  515. if (glyphY != baseY)
  516. {
  517. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  518. lineStart = i;
  519. baseY = glyphY;
  520. }
  521. }
  522. if (i > lineStart)
  523. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  524. }
  525. }
  526. }
  527. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  528. {
  529. if (start + num < glyphs.size()
  530. && glyphs.getReference (start + num - 1).getCharacter() != '\r'
  531. && glyphs.getReference (start + num - 1).getCharacter() != '\n')
  532. {
  533. int numSpaces = 0;
  534. int spacesAtEnd = 0;
  535. for (int i = 0; i < num; ++i)
  536. {
  537. if (glyphs.getReference (start + i).isWhitespace())
  538. {
  539. ++spacesAtEnd;
  540. ++numSpaces;
  541. }
  542. else
  543. {
  544. spacesAtEnd = 0;
  545. }
  546. }
  547. numSpaces -= spacesAtEnd;
  548. if (numSpaces > 0)
  549. {
  550. const float startX = glyphs.getReference (start).getLeft();
  551. const float endX = glyphs.getReference (start + num - 1 - spacesAtEnd).getRight();
  552. const float extraPaddingBetweenWords
  553. = (targetWidth - (endX - startX)) / (float) numSpaces;
  554. float deltaX = 0.0f;
  555. for (int i = 0; i < num; ++i)
  556. {
  557. glyphs.getReference (start + i).moveBy (deltaX, 0.0f);
  558. if (glyphs.getReference (start + i).isWhitespace())
  559. deltaX += extraPaddingBetweenWords;
  560. }
  561. }
  562. }
  563. }
  564. //==============================================================================
  565. inline void GlyphArrangement::drawGlyphUnderline (const Graphics& g, const PositionedGlyph& pg,
  566. const int i, const AffineTransform& transform) const
  567. {
  568. const float lineThickness = (pg.font.getDescent()) * 0.3f;
  569. float nextX = pg.x + pg.w;
  570. if (i < glyphs.size() - 1 && glyphs.getReference (i + 1).y == pg.y)
  571. nextX = glyphs.getReference (i + 1).x;
  572. Path p;
  573. p.addRectangle (pg.x, pg.y + lineThickness * 2.0f, nextX - pg.x, lineThickness);
  574. g.fillPath (p, transform);
  575. }
  576. void GlyphArrangement::draw (const Graphics& g) const
  577. {
  578. for (int i = 0; i < glyphs.size(); ++i)
  579. {
  580. const PositionedGlyph& pg = glyphs.getReference(i);
  581. if (pg.font.isUnderlined())
  582. drawGlyphUnderline (g, pg, i, AffineTransform::identity);
  583. pg.draw (g);
  584. }
  585. }
  586. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  587. {
  588. for (int i = 0; i < glyphs.size(); ++i)
  589. {
  590. const PositionedGlyph& pg = glyphs.getReference(i);
  591. if (pg.font.isUnderlined())
  592. drawGlyphUnderline (g, pg, i, transform);
  593. pg.draw (g, transform);
  594. }
  595. }
  596. void GlyphArrangement::createPath (Path& path) const
  597. {
  598. for (int i = 0; i < glyphs.size(); ++i)
  599. glyphs.getReference (i).createPath (path);
  600. }
  601. int GlyphArrangement::findGlyphIndexAt (const float x, const float y) const
  602. {
  603. for (int i = 0; i < glyphs.size(); ++i)
  604. if (glyphs.getReference (i).hitTest (x, y))
  605. return i;
  606. return -1;
  607. }