parse the text. When the text is parsed the width, height, leading are all calculated. The text will only be truly parsed if the graphics context has changed or the text has changed or the font has changed. Otherwise nothing is done when this method is called. @param g Graphics context.
(Graphics g)
| 521 | * @param g Graphics context. |
| 522 | */ |
| 523 | public void parseText(Graphics g) { |
| 524 | int w = 0; |
| 525 | if (lg != g) { |
| 526 | parse = true; |
| 527 | } |
| 528 | lg = g; |
| 529 | if (!parse) { |
| 530 | return; |
| 531 | } |
| 532 | parse = false; |
| 533 | width = 0; |
| 534 | leading = 0; |
| 535 | ascent = 0; |
| 536 | descent = 0; |
| 537 | height = 0; |
| 538 | maxAscent = 0; |
| 539 | maxDescent = 0; |
| 540 | if (text == null || g == null || text.length() == 0) { |
| 541 | return; |
| 542 | } |
| 543 | // BH 2020.03.04 no need to do all this if it's simple text |
| 544 | if (keepItSimple(text)) { |
| 545 | Font prevFont = g.getFont(); |
| 546 | g.setFont(font); |
| 547 | FontMetrics fm = g.getFontMetrics(); |
| 548 | width = fm.stringWidth(text); |
| 549 | ascent = fm.getAscent(); |
| 550 | descent = fm.getDescent(); |
| 551 | leading = fm.getLeading(); |
| 552 | maxDescent = fm.getMaxDescent(); |
| 553 | maxAscent = fm.getMaxAscent(); |
| 554 | g.setFont(prevFont); |
| 555 | } else { |
| 556 | TextState current = new TextState(); |
| 557 | char ch; |
| 558 | Stack<TextState> state = new Stack<TextState>(); |
| 559 | list.removeAllElements(); |
| 560 | if (font == null) { |
| 561 | current.f = g.getFont(); |
| 562 | } else { |
| 563 | current.f = font; |
| 564 | } |
| 565 | state.push(current); |
| 566 | list.addElement(current); |
| 567 | for (int i = 0, n = text.length(); i < n; i++) { |
| 568 | ch = text.charAt(i); |
| 569 | switch (ch) { |
| 570 | case '$': |
| 571 | i++; |
| 572 | if (i < text.length()) { |
| 573 | current.s.append(text.charAt(i)); |
| 574 | } |
| 575 | break; |
| 576 | /* |
| 577 | ** Push the current state onto the state stack and start a new storage string |
| 578 | */ |
| 579 | case '{': |
| 580 | w = current.getWidth(g); |
no test coverage detected