Пример #1
0
  /**
   * Process this text Token to optimize tokens and evaluate the token bounding box.
   *
   * @param g Graphics to get the font metrics.
   * @param text Text to add to the current textTokan.
   * @param textTok Current TextToken.
   * @param isText True if the previous textToken was a Text Token so we can merge it with this.
   */
  private void updateText(Graphics g, String text, TextToken textTok, boolean isText) {
    // The text exists!
    if (text.length() > 0) {
      FontMetrics fm = g.getFontMetrics();
      int a = fm.getAscent(), d = fm.getDescent(), w = fm.stringWidth(text), h = fm.getHeight();

      // The previous token was a text too so we must merge it with this new one.
      if (isText) {
        textTok = (TextToken) m_tokens.lastElement();

        textTok.m_text += text;
        textTok.m_bounds.width += w;
        if (textTok.m_bounds.height < h) textTok.m_bounds.height = h;
      }
      // The previous token was a formating one.
      else {
        m_tokens.addElement(textTok);

        textTok.m_text = text;
        textTok.m_bounds = new Rectangle(0, 0, w, h);
      }

      if (a > m_body.m_aMax) m_body.m_aMax = a;
      if (d > m_body.m_dMax) m_body.m_dMax = d;

      m_wCur += w;
    }
  }