Exemplo n.º 1
0
  /**
   * Compute the bounds of the text, if necessary.
   *
   * @param dc the current DrawContext.
   */
  protected void computeBoundsIfNeeded(DrawContext dc) {
    // Do not compute bounds if they are available. Computing text bounds is expensive, so only do
    // this
    // calculation if necessary.
    if (this.bounds != null) return;

    TextRenderer textRenderer =
        OGLTextRenderer.getOrCreateTextRenderer(dc.getTextRendererCache(), this.getFont());

    int width = 0;
    int maxLineHeight = 0;
    this.lineBounds = new Rectangle2D[this.lines.length];

    for (int i = 0; i < this.lines.length; i++) {
      Rectangle2D lineBounds = textRenderer.getBounds(lines[i]);
      width = (int) Math.max(lineBounds.getWidth(), width);

      double thisLineHeight = Math.abs(lineBounds.getY());
      maxLineHeight = (int) Math.max(thisLineHeight, maxLineHeight);

      this.lineBounds[i] = lineBounds;
    }
    this.lineHeight = maxLineHeight;

    // Compute final height using maxLineHeight and number of lines
    this.bounds =
        new Rectangle(
            this.lines.length,
            maxLineHeight,
            width,
            this.lines.length * maxLineHeight + this.lines.length * this.lineSpacing);
  }
Exemplo n.º 2
0
 /**
  * Draw this label during ordered rendering.
  *
  * @param dc Current draw context.
  * @param pickSupport Support object used during picking.
  */
 protected void doDrawOrderedRenderable(DrawContext dc, PickSupport pickSupport) {
   TextRenderer textRenderer =
       OGLTextRenderer.getOrCreateTextRenderer(dc.getTextRendererCache(), font);
   if (dc.isPickingMode()) {
     this.doPick(dc, pickSupport);
   } else {
     this.drawText(dc, textRenderer);
   }
 }