/* * Copyright (C), 2018-2022 * Project: starter * FileName: StylePDF * Author: xx * Date: 2022/9/27 14:59 */ package com.fr.plugin.ajhdf.style; import com.fr.base.GraphHelper; import com.fr.base.Style; import com.fr.general.ComparatorUtils; import com.fr.stable.GraphDrawHelper; import java.awt.*; /** *
* * * @author xx * @since 1.0.0 */ public class StylePDF extends Style { private static final long serialVersionUID = -1498763211837836528L; public static void paintBorder(Graphics2D g2d, Style style, Rectangle paintRectangle, Rectangle clipRectangle, float scale) { if (ComparatorUtils.equals(paintRectangle.width, 0) || ComparatorUtils.equals(paintRectangle.height, 0)) { return; } g2d.translate(paintRectangle.getX(), paintRectangle.getY()); Rectangle rectangle = new Rectangle(0, 0, paintRectangle.width, paintRectangle.height); if (clipRectangle != null) { rectangle = rectangle.intersection(clipRectangle); } g2d.translate(rectangle.getX(), rectangle.getY()); if (style == null) { style = DEFAULT_STYLE; } paintBorder(g2d, style, rectangle.getWidth(), rectangle.getHeight(), scale); g2d.translate(-rectangle.getX(), -rectangle.getY()); g2d.translate(-paintRectangle.getX(), -paintRectangle.getY()); } public static void paintBorder(Graphics2D g2d, Style style, double width, double height, float scale) { if (style == null) { return; } double borderLeftMargin = 0.0; double borderRightMargin = 0.0; int borderLeft; if (style.getBorderLeft() != 0) { borderLeft = GraphHelper.getLineStyleSize(style.getBorderLeft()); borderLeftMargin = (double) (borderLeft / 2); } if (style.getBorderRight() != 0) { borderLeft = GraphHelper.getLineStyleSize(style.getBorderRight()); borderRightMargin = (double) (borderLeft / 2); } double borderTopMarign = 0.0; double borderBottomMargin = 0.0; int borderTop; if (style.getBorderTop() != 0) { borderTop = GraphHelper.getLineStyleSize(style.getBorderTop()); borderTopMarign = (double) (borderTop / 2); } if (style.getBorderBottom() != 0) { borderTop = GraphHelper.getLineStyleSize(style.getBorderBottom()); borderBottomMargin = (double) (borderTop / 2); } if (style.getBorderTop() != 0) { g2d.setPaint(style.getBorderTopColor()); // 改为传入scale,调整边框粗细 GraphDrawHelper.drawLine(g2d, 0.0 - borderLeftMargin, 0.0, width + borderRightMargin, 0.0, style.getBorderTop(), scale); } if (style.getBorderLeft() != 0) { g2d.setPaint(style.getBorderLeftColor()); // 改为传入scale,调整边框粗细 GraphDrawHelper.drawLine(g2d, 0.0, 0.0 - borderTopMarign, 0.0, height + borderBottomMargin, style.getBorderLeft(), scale); } if (style.getBorderBottom() != 0) { g2d.setPaint(style.getBorderBottomColor()); // 改为传入scale,调整边框粗细 GraphDrawHelper.drawLine(g2d, 0.0 - borderLeftMargin, height, width + borderRightMargin, height, style.getBorderBottom(), scale); } if (style.getBorderRight() != 0) { g2d.setPaint(style.getBorderRightColor()); // 改为传入scale,调整边框粗细 GraphDrawHelper.drawLine(g2d, width, 0.0 - borderTopMarign, width, height + borderBottomMargin, style.getBorderRight(), scale); } } }