private double drawHeaderOrFooterLine(Graphics2D g, double x, double y, double w, String headerText, PrintSettings.Alignment alignment) {
    FontRenderContext fontRenderContext = g.getFontRenderContext();
    LineMetrics lineMetrics = getHeaderFooterLineMetrics(g);
    float lineHeight = lineMetrics.getHeight();
    if (myPerformActualDrawing) {
      headerText = convertHeaderText(headerText);
      g.setFont(myHeaderFont);
      g.setColor(Color.black);
      float descent = lineMetrics.getDescent();
      double width = myHeaderFont.getStringBounds(headerText, fontRenderContext).getWidth() + getCharWidth(g);
      float yPos = (float) (lineHeight - descent + y);
      switch (alignment) {
        case Left -> drawStringToGraphics(g, headerText, x, yPos);
        case Center -> drawStringToGraphics(g, headerText, (float)(x + (w - width) / 2), yPos);
        case Right -> drawStringToGraphics(g, headerText, (float)(x + w - width), yPos);
      }
    }
    return lineHeight;
  }
private double drawHeaderOrFooterLine(Graphics2D g, double x, double y, double w, String headerText, PrintSettings.Alignment alignment)