@SuppressWarnings("deprecation")
  @Override
  public void calculateSize(PdfContext context) {
    LegendComponent legendComponent = getLegend();
    assert (null != legendComponent)
        : "LegendGraphicComponent must be a descendant of a LegendComponent";

    Rectangle textSize = context.getTextSize(label, legendComponent.getFont());
    float margin = 0.25f * legendComponent.getFont().getSize();
    if (getConstraint().getMarginX() <= 0.0) {
      getConstraint().setMarginX(margin);
    }
    if (getConstraint().getMarginY() <= 0.0) {
      getConstraint().setMarginY(margin);
    }
    setBounds(new Rectangle(textSize.getHeight(), textSize.getHeight()));
  }