diff --git a/graphics-barcode/src/main/java/org/xbib/graphics/barcode/Symbols.java b/graphics-barcode/src/main/java/org/xbib/graphics/barcode/Symbols.java new file mode 100644 index 0000000..501ea02 --- /dev/null +++ b/graphics-barcode/src/main/java/org/xbib/graphics/barcode/Symbols.java @@ -0,0 +1,51 @@ +package org.xbib.graphics.barcode; + +public enum Symbols { + AustraliaPost, + AztecCode, + ChannelCode, + Codabar, + CodablockF, + Code2Of5, + Code3Of9, + Code3Of9Extended, + Code11, + Code16k, + Code32, + Code49, + Code93, + Code128, + CodeOne, + Composite, + DataBar14, + DataBarExpanded, + DataBarLimited, + DataMatrix, + Ean, + GridMatrix, + JapanPost, + KixCode, + KoreaPost, + Logmars, + MaxiCode, + MicroQrCode, + MsiPlessey, + Nve18, + Pdf417, + Pharmacode, + Pharmacode2Track, + Pharmazentralnummer, + Postnet, + QrCode, + RoyalMail4State, + Telepen, + Upc, + UspsOneCode, + UspsPackage; + + @SuppressWarnings("unchecked") + public Symbol getSymbol() throws Exception { + Class cl = (Class) getClass().getClassLoader().loadClass(getClass().getPackageName() + "." + name()); + return cl.getDeclaredConstructor().newInstance(); + } +} diff --git a/graphics-barcode/src/test/java/org/xbib/graphics/barcode/SymbolTest.java b/graphics-barcode/src/test/java/org/xbib/graphics/barcode/SymbolTest.java index 587afea..2fcb627 100755 --- a/graphics-barcode/src/test/java/org/xbib/graphics/barcode/SymbolTest.java +++ b/graphics-barcode/src/test/java/org/xbib/graphics/barcode/SymbolTest.java @@ -122,8 +122,8 @@ public class SymbolTest { } String backend = "org.xbib.graphics.barcode"; Reflections reflections = new Reflections(backend); - Set< Class< ? extends AbstractSymbol>> symbols = reflections.getSubTypesOf(AbstractSymbol.class); - List< Object[] > data = new ArrayList<>(); + Set> symbols = reflections.getSubTypesOf(AbstractSymbol.class); + List data = new ArrayList<>(); for (Class< ? extends AbstractSymbol> symbol : symbols) { String symbolName = symbol.getSimpleName().toLowerCase(); String dir = "src/test/resources/" + backend.replace('.', '/') + "/" + symbolName; diff --git a/graphics-pdfbox-layout/src/main/java/module-info.java b/graphics-pdfbox-layout/src/main/java/module-info.java index 8c52723..a74dca8 100644 --- a/graphics-pdfbox-layout/src/main/java/module-info.java +++ b/graphics-pdfbox-layout/src/main/java/module-info.java @@ -1,8 +1,11 @@ module org.xbib.graphics.layout.pdfbox { exports org.xbib.graphics.pdfbox.layout.boxable; + exports org.xbib.graphics.pdfbox.layout.color; exports org.xbib.graphics.pdfbox.layout.elements; exports org.xbib.graphics.pdfbox.layout.elements.render; exports org.xbib.graphics.pdfbox.layout.font; + exports org.xbib.graphics.pdfbox.layout.script; + exports org.xbib.graphics.pdfbox.layout.script.command; exports org.xbib.graphics.pdfbox.layout.shape; exports org.xbib.graphics.pdfbox.layout.table; exports org.xbib.graphics.pdfbox.layout.table.render; @@ -11,6 +14,7 @@ module org.xbib.graphics.layout.pdfbox { exports org.xbib.graphics.pdfbox.layout.util; requires transitive org.xbib.graphics.barcode; requires transitive org.xbib.graphics.pdfbox; + requires transitive org.xbib.settings.api; requires org.xbib.settings.datastructures; requires transitive java.desktop; requires java.logging; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/color/ColorFactory.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/color/ColorFactory.java new file mode 100644 index 0000000..9ef421b --- /dev/null +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/color/ColorFactory.java @@ -0,0 +1,1593 @@ +package org.xbib.graphics.pdfbox.layout.color; + +import java.awt.Color; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +public final class ColorFactory { + /** + * Creates a {@code Color} based on the specified values in the HSB color model, + * and a given opacity. + * + * @param hue the hue, in degrees + * @param saturation the saturation, {@code 0.0 to 1.0} + * @param brightness the brightness, {@code 0.0 to 1.0} + * @param opacity the opacity, {@code 0.0 to 1.0} + * @return the {@code Color} + * @throws IllegalArgumentException if {@code saturation}, {@code brightness} or + * {@code opacity} are out of range + */ + public static Color hsb(double hue, double saturation, double brightness, double opacity) { + checkSB(saturation, brightness); + double[] rgb = HSBtoRGB(hue, saturation, brightness); + Color result = new Color((float)rgb[0], (float)rgb[1], (float)rgb[2], (float)opacity); + return result; + } + + /** + * Creates an opaque {@code Color} based on the specified values in the HSB color model. + * + * @param hue the hue, in degrees + * @param saturation the saturation, {@code 0.0 to 1.0} + * @param brightness the brightness, {@code 0.0 to 1.0} + * @return the {@code Color} + * @throws IllegalArgumentException if {@code saturation} or {@code brightness} are + * out of range + */ + public static Color hsb(double hue, double saturation, double brightness) { + return hsb(hue, saturation, brightness, 1.0); + } + + private static void checkSB(double saturation, double brightness) { + if (saturation < 0.0 || saturation > 1.0) { + throw new IllegalArgumentException("Color.hsb's saturation parameter (" + saturation + ") expects values 0.0-1.0"); + } + if (brightness < 0.0 || brightness > 1.0) { + throw new IllegalArgumentException("Color.hsb's brightness parameter (" + brightness + ") expects values 0.0-1.0"); + } + } + + /** + * Creates an RGB color specified with an HTML or CSS attribute string. + * + *

+ * This method supports the following formats: + *

+ * + *

For formats without an alpha component and for named colors, opacity + * is set according to the {@code opacity} argument. For colors specified + * with an alpha component, the resulting opacity is a combination of the + * parsed alpha component and the {@code opacity} argument, so a + * transparent color becomes more transparent by specifying opacity.

+ * + *

Examples:

+ *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Web Color Format Table
Web Format StringEquivalent constructor or factory call
Color.web("orange", 0.5);new Color(1.0, 0xA5/255.0, 0.0, 0.5)
Color.web("0xff66cc33", 0.5);new Color(1.0, 0.4, 0.8, 0.1)
Color.web("0xff66cc", 0.5);new Color(1.0, 0.4, 0.8, 0.5)
Color.web("#ff66cc", 0.5);new Color(1.0, 0.4, 0.8, 0.5)
Color.web("#f68", 0.5);new Color(1.0, 0.4, 0.8, 0.5)
Color.web("rgb(255,102,204)", 0.5);new Color(1.0, 0.4, 0.8, 0.5)
Color.web("rgb(100%,50%,50%)", 0.5);new Color(1.0, 0.5, 0.5, 0.5)
Color.web("rgb(255,50%,50%,0.25)", 0.5);new Color(1.0, 0.5, 0.5, 0.125)
Color.web("hsl(240,100%,100%)", 0.5);Color.hsb(240.0, 1.0, 1.0, 0.5)
+ * Color.web("hsla(120,0%,0%,0.25)", 0.5); + * + * Color.hsb(120.0, 0.0, 0.0, 0.125) + *
+ *
+ * + * @param colorString the name or numeric representation of the color + * in one of the supported formats + * @param opacity the opacity component in range from 0.0 (transparent) + * to 1.0 (opaque) + * @return the RGB color specified with the colorString + * @throws NullPointerException if {@code colorString} is {@code null} + * @throws IllegalArgumentException if {@code colorString} specifies + * an unsupported color name or contains an illegal numeric value + */ + public static Color web(String colorString, double opacity) { + if (colorString == null) { + throw new NullPointerException( + "The color components or name must be specified"); + } + if (colorString.isEmpty()) { + throw new IllegalArgumentException("Invalid color specification"); + } + + String color = colorString.toLowerCase(Locale.ROOT); + + if (color.startsWith("#")) { + color = color.substring(1); + } else if (color.startsWith("0x")) { + color = color.substring(2); + } else if (color.startsWith("rgb")) { + if (color.startsWith("(", 3)) { + return parseRGBColor(color, 4, false, opacity); + } else if (color.startsWith("a(", 3)) { + return parseRGBColor(color, 5, true, opacity); + } + } else if (color.startsWith("hsl")) { + if (color.startsWith("(", 3)) { + return parseHSLColor(color, 4, false, opacity); + } else if (color.startsWith("a(", 3)) { + return parseHSLColor(color, 5, true, opacity); + } + } else { + Color col = NamedColors.get(color); + if (col != null) { + if (opacity == 1.0) { + return col; + } else { + return new Color(col.getRed(), col.getGreen(), col.getBlue(), (int)(255 * opacity + 0.5)); + } + } + } + + int len = color.length(); + + try { + int r; + int g; + int b; + int a; + + if (len == 3) { + r = Integer.parseInt(color.substring(0, 1), 16); + g = Integer.parseInt(color.substring(1, 2), 16); + b = Integer.parseInt(color.substring(2, 3), 16); + return new Color(r / 15.0f, g / 15.0f, b / 15.0f, (float)opacity); + } else if (len == 4) { + r = Integer.parseInt(color.substring(0, 1), 16); + g = Integer.parseInt(color.substring(1, 2), 16); + b = Integer.parseInt(color.substring(2, 3), 16); + a = Integer.parseInt(color.substring(3, 4), 16); + return new Color(r / 15.0f, g / 15.0f, b / 15.0f, (float)(opacity * a / 15.0)); + } else if (len == 6) { + r = Integer.parseInt(color.substring(0, 2), 16); + g = Integer.parseInt(color.substring(2, 4), 16); + b = Integer.parseInt(color.substring(4, 6), 16); + return new Color(r, g, b, (int)(opacity*255+0.5)); + } else if (len == 8) { + r = Integer.parseInt(color.substring(0, 2), 16); + g = Integer.parseInt(color.substring(2, 4), 16); + b = Integer.parseInt(color.substring(4, 6), 16); + a = Integer.parseInt(color.substring(6, 8), 16); + return new Color(r, g, b, (int)(opacity * a + 0.5)); + } + } catch (NumberFormatException nfe) {} + + throw new IllegalArgumentException("Invalid color specification"); + } + + private static Color parseRGBColor(String color, int roff, + boolean hasAlpha, double a) + { + try { + int rend = color.indexOf(',', roff); + int gend = rend < 0 ? -1 : color.indexOf(',', rend+1); + int bend = gend < 0 ? -1 : color.indexOf(hasAlpha ? ',' : ')', gend+1); + int aend = hasAlpha ? (bend < 0 ? -1 : color.indexOf(')', bend+1)) : bend; + if (aend >= 0) { + double r = parseComponent(color, roff, rend, PARSE_COMPONENT); + double g = parseComponent(color, rend+1, gend, PARSE_COMPONENT); + double b = parseComponent(color, gend+1, bend, PARSE_COMPONENT); + if (hasAlpha) { + a *= parseComponent(color, bend+1, aend, PARSE_ALPHA); + } + return new Color((float)r, (float)g, (float)b, (float)a); + } + } catch (NumberFormatException nfe) {} + + throw new IllegalArgumentException("Invalid color specification"); + } + + private static Color parseHSLColor(String color, int hoff, + boolean hasAlpha, double a) + { + try { + int hend = color.indexOf(',', hoff); + int send = hend < 0 ? -1 : color.indexOf(',', hend+1); + int lend = send < 0 ? -1 : color.indexOf(hasAlpha ? ',' : ')', send+1); + int aend = hasAlpha ? (lend < 0 ? -1 : color.indexOf(')', lend+1)) : lend; + if (aend >= 0) { + double h = parseComponent(color, hoff, hend, PARSE_ANGLE); + double s = parseComponent(color, hend+1, send, PARSE_PERCENT); + double l = parseComponent(color, send+1, lend, PARSE_PERCENT); + if (hasAlpha) { + a *= parseComponent(color, lend+1, aend, PARSE_ALPHA); + } + return hsb(h, s, l, a); + } + } catch (NumberFormatException nfe) {} + + throw new IllegalArgumentException("Invalid color specification"); + } + + private static final int PARSE_COMPONENT = 0; // percent, or clamped to [0,255] => [0,1] + private static final int PARSE_PERCENT = 1; // clamped to [0,100]% => [0,1] + private static final int PARSE_ANGLE = 2; // clamped to [0,360] + private static final int PARSE_ALPHA = 3; // clamped to [0.0,1.0] + private static double parseComponent(String color, int off, int end, int type) { + color = color.substring(off, end).trim(); + if (color.endsWith("%")) { + if (type > PARSE_PERCENT) { + throw new IllegalArgumentException("Invalid color specification"); + } + type = PARSE_PERCENT; + color = color.substring(0, color.length()-1).trim(); + } else if (type == PARSE_PERCENT) { + throw new IllegalArgumentException("Invalid color specification"); + } + double c = ((type == PARSE_COMPONENT) + ? Integer.parseInt(color) + : Double.parseDouble(color)); + switch (type) { + case PARSE_ALPHA: + return (c < 0.0) ? 0.0 : ((c > 1.0) ? 1.0 : c); + case PARSE_PERCENT: + return (c <= 0.0) ? 0.0 : ((c >= 100.0) ? 1.0 : (c / 100.0)); + case PARSE_COMPONENT: + return (c <= 0.0) ? 0.0 : ((c >= 255.0) ? 1.0 : (c / 255.0)); + case PARSE_ANGLE: + return ((c < 0.0) + ? ((c % 360.0) + 360.0) + : ((c > 360.0) + ? (c % 360.0) + : c)); + } + + throw new IllegalArgumentException("Invalid color specification"); + } + + /** + * Creates an RGB color specified with an HTML or CSS attribute string. + * + *

+ * This method supports the following formats: + *

+ * + *

Examples:

+ *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Web Color Format Table
Web Format StringEquivalent constant or factory call
Color.web("orange");Color.ORANGE
Color.web("0xff668840");Color.rgb(255, 102, 136, 0.25)
Color.web("0xff6688");Color.rgb(255, 102, 136, 1.0)
Color.web("#ff6688");Color.rgb(255, 102, 136, 1.0)
Color.web("#f68");Color.rgb(255, 102, 136, 1.0)
Color.web("rgb(255,102,136)");Color.rgb(255, 102, 136, 1.0)
Color.web("rgb(100%,50%,50%)");Color.rgb(255, 128, 128, 1.0)
Color.web("rgb(255,50%,50%,0.25)");Color.rgb(255, 128, 128, 0.25)
Color.web("hsl(240,100%,100%)");Color.hsb(240.0, 1.0, 1.0, 1.0)
+ * Color.web("hsla(120,0%,0%,0.25)"); + * + * Color.hsb(120.0, 0.0, 0.0, 0.25) + *
+ *
+ * + * @param colorString the name or numeric representation of the color + * in one of the supported formats + * @return an RGB color + * @throws NullPointerException if {@code colorString} is {@code null} + * @throws IllegalArgumentException if {@code colorString} specifies + * an unsupported color name or contains an illegal numeric value + */ + public static Color web(String colorString) { + return web(colorString, 1.0); + } + + /** + * Creates a color value from a string representation. The format + * of the string representation is the same as in {@link #web(String)}. + * + * @param value the string to convert + * @throws NullPointerException if the {@code value} is {@code null} + * @throws IllegalArgumentException if the {@code value} specifies + * an unsupported color name or illegal hexadecimal value + * @return a {@code Color} object holding the value represented + * by the string argument + * @see #web(String) + */ + public static Color valueOf(String value) { + if (value == null) { + throw new NullPointerException("color must be specified"); + } + + return web(value); + } + + private static int to32BitInteger(int red, int green, int blue, int alpha) { + int i = red; + i = i << 8; + i = i | green; + i = i << 8; + i = i | blue; + i = i << 8; + i = i | alpha; + return i; + } + + /** + * A fully transparent color with an ARGB value of #00000000. + */ + public static final Color TRANSPARENT = new Color(0f, 0f, 0f, 0f); + + /** + * The color alice blue with an RGB value of #F0F8FF + *
+ */ + public static final Color ALICEBLUE = new Color(0.9411765f, 0.972549f, 1.0f); + + /** + * The color antique white with an RGB value of #FAEBD7 + *
+ */ + public static final Color ANTIQUEWHITE = new Color(0.98039216f, 0.92156863f, 0.84313726f); + + /** + * The color aqua with an RGB value of #00FFFF + *
+ */ + public static final Color AQUA = new Color(0.0f, 1.0f, 1.0f); + + /** + * The color aquamarine with an RGB value of #7FFFD4 + *
+ */ + public static final Color AQUAMARINE = new Color(0.49803922f, 1.0f, 0.83137256f); + + /** + * The color azure with an RGB value of #F0FFFF + *
+ */ + public static final Color AZURE = new Color(0.9411765f, 1.0f, 1.0f); + + /** + * The color beige with an RGB value of #F5F5DC + *
+ */ + public static final Color BEIGE = new Color(0.9607843f, 0.9607843f, 0.8627451f); + + /** + * The color bisque with an RGB value of #FFE4C4 + *
+ */ + public static final Color BISQUE = new Color(1.0f, 0.89411765f, 0.76862746f); + + /** + * The color black with an RGB value of #000000 + *
+ */ + public static final Color BLACK = new Color(0.0f, 0.0f, 0.0f); + + /** + * The color blanched almond with an RGB value of #FFEBCD + *
+ */ + public static final Color BLANCHEDALMOND = new Color(1.0f, 0.92156863f, 0.8039216f); + + /** + * The color blue with an RGB value of #0000FF + *
+ */ + public static final Color BLUE = new Color(0.0f, 0.0f, 1.0f); + + /** + * The color blue violet with an RGB value of #8A2BE2 + *
+ */ + public static final Color BLUEVIOLET = new Color(0.5411765f, 0.16862746f, 0.8862745f); + + /** + * The color brown with an RGB value of #A52A2A + *
+ */ + public static final Color BROWN = new Color(0.64705884f, 0.16470589f, 0.16470589f); + + /** + * The color burly wood with an RGB value of #DEB887 + *
+ */ + public static final Color BURLYWOOD = new Color(0.87058824f, 0.72156864f, 0.5294118f); + + /** + * The color cadet blue with an RGB value of #5F9EA0 + *
+ */ + public static final Color CADETBLUE = new Color(0.37254903f, 0.61960787f, 0.627451f); + + /** + * The color chartreuse with an RGB value of #7FFF00 + *
+ */ + public static final Color CHARTREUSE = new Color(0.49803922f, 1.0f, 0.0f); + + /** + * The color chocolate with an RGB value of #D2691E + *
+ */ + public static final Color CHOCOLATE = new Color(0.8235294f, 0.4117647f, 0.11764706f); + + /** + * The color coral with an RGB value of #FF7F50 + *
+ */ + public static final Color CORAL = new Color(1.0f, 0.49803922f, 0.3137255f); + + /** + * The color cornflower blue with an RGB value of #6495ED + *
+ */ + public static final Color CORNFLOWERBLUE = new Color(0.39215687f, 0.58431375f, 0.92941177f); + + /** + * The color cornsilk with an RGB value of #FFF8DC + *
+ */ + public static final Color CORNSILK = new Color(1.0f, 0.972549f, 0.8627451f); + + /** + * The color crimson with an RGB value of #DC143C + *
+ */ + public static final Color CRIMSON = new Color(0.8627451f, 0.078431375f, 0.23529412f); + + /** + * The color cyan with an RGB value of #00FFFF + *
+ */ + public static final Color CYAN = new Color(0.0f, 1.0f, 1.0f); + + /** + * The color dark blue with an RGB value of #00008B + *
+ */ + public static final Color DARKBLUE = new Color(0.0f, 0.0f, 0.54509807f); + + /** + * The color dark cyan with an RGB value of #008B8B + *
+ */ + public static final Color DARKCYAN = new Color(0.0f, 0.54509807f, 0.54509807f); + + /** + * The color dark goldenrod with an RGB value of #B8860B + *
+ */ + public static final Color DARKGOLDENROD = new Color(0.72156864f, 0.5254902f, 0.043137256f); + + /** + * The color dark gray with an RGB value of #A9A9A9 + *
+ */ + public static final Color DARKGRAY = new Color(0.6627451f, 0.6627451f, 0.6627451f); + + /** + * The color dark green with an RGB value of #006400 + *
+ */ + public static final Color DARKGREEN = new Color(0.0f, 0.39215687f, 0.0f); + + /** + * The color dark grey with an RGB value of #A9A9A9 + *
+ */ + public static final Color DARKGREY = DARKGRAY; + + /** + * The color dark khaki with an RGB value of #BDB76B + *
+ */ + public static final Color DARKKHAKI = new Color(0.7411765f, 0.7176471f, 0.41960785f); + + /** + * The color dark magenta with an RGB value of #8B008B + *
+ */ + public static final Color DARKMAGENTA = new Color(0.54509807f, 0.0f, 0.54509807f); + + /** + * The color dark olive green with an RGB value of #556B2F + *
+ */ + public static final Color DARKOLIVEGREEN = new Color(0.33333334f, 0.41960785f, 0.18431373f); + + /** + * The color dark orange with an RGB value of #FF8C00 + *
+ */ + public static final Color DARKORANGE = new Color(1.0f, 0.54901963f, 0.0f); + + /** + * The color dark orchid with an RGB value of #9932CC + *
+ */ + public static final Color DARKORCHID = new Color(0.6f, 0.19607843f, 0.8f); + + /** + * The color dark red with an RGB value of #8B0000 + *
+ */ + public static final Color DARKRED = new Color(0.54509807f, 0.0f, 0.0f); + + /** + * The color dark salmon with an RGB value of #E9967A + *
+ */ + public static final Color DARKSALMON = new Color(0.9137255f, 0.5882353f, 0.47843137f); + + /** + * The color dark sea green with an RGB value of #8FBC8F + *
+ */ + public static final Color DARKSEAGREEN = new Color(0.56078434f, 0.7372549f, 0.56078434f); + + /** + * The color dark slate blue with an RGB value of #483D8B + *
+ */ + public static final Color DARKSLATEBLUE = new Color(0.28235295f, 0.23921569f, 0.54509807f); + + /** + * The color dark slate gray with an RGB value of #2F4F4F + *
+ */ + public static final Color DARKSLATEGRAY = new Color(0.18431373f, 0.30980393f, 0.30980393f); + + /** + * The color dark slate grey with an RGB value of #2F4F4F + *
+ */ + public static final Color DARKSLATEGREY = DARKSLATEGRAY; + + /** + * The color dark turquoise with an RGB value of #00CED1 + *
+ */ + public static final Color DARKTURQUOISE = new Color(0.0f, 0.80784315f, 0.81960785f); + + /** + * The color dark violet with an RGB value of #9400D3 + *
+ */ + public static final Color DARKVIOLET = new Color(0.5803922f, 0.0f, 0.827451f); + + /** + * The color deep pink with an RGB value of #FF1493 + *
+ */ + public static final Color DEEPPINK = new Color(1.0f, 0.078431375f, 0.5764706f); + + /** + * The color deep sky blue with an RGB value of #00BFFF + *
+ */ + public static final Color DEEPSKYBLUE = new Color(0.0f, 0.7490196f, 1.0f); + + /** + * The color dim gray with an RGB value of #696969 + *
+ */ + public static final Color DIMGRAY = new Color(0.4117647f, 0.4117647f, 0.4117647f); + + /** + * The color dim grey with an RGB value of #696969 + *
+ */ + public static final Color DIMGREY = DIMGRAY; + + /** + * The color dodger blue with an RGB value of #1E90FF + *
+ */ + public static final Color DODGERBLUE = new Color(0.11764706f, 0.5647059f, 1.0f); + + /** + * The color firebrick with an RGB value of #B22222 + *
+ */ + public static final Color FIREBRICK = new Color(0.69803923f, 0.13333334f, 0.13333334f); + + /** + * The color floral white with an RGB value of #FFFAF0 + *
+ */ + public static final Color FLORALWHITE = new Color(1.0f, 0.98039216f, 0.9411765f); + + /** + * The color forest green with an RGB value of #228B22 + *
+ */ + public static final Color FORESTGREEN = new Color(0.13333334f, 0.54509807f, 0.13333334f); + + /** + * The color fuchsia with an RGB value of #FF00FF + *
+ */ + public static final Color FUCHSIA = new Color(1.0f, 0.0f, 1.0f); + + /** + * The color gainsboro with an RGB value of #DCDCDC + *
+ */ + public static final Color GAINSBORO = new Color(0.8627451f, 0.8627451f, 0.8627451f); + + /** + * The color ghost white with an RGB value of #F8F8FF + *
+ */ + public static final Color GHOSTWHITE = new Color(0.972549f, 0.972549f, 1.0f); + + /** + * The color gold with an RGB value of #FFD700 + *
+ */ + public static final Color GOLD = new Color(1.0f, 0.84313726f, 0.0f); + + /** + * The color goldenrod with an RGB value of #DAA520 + *
+ */ + public static final Color GOLDENROD = new Color(0.85490197f, 0.64705884f, 0.1254902f); + + /** + * The color gray with an RGB value of #808080 + *
+ */ + public static final Color GRAY = new Color(0.5019608f, 0.5019608f, 0.5019608f); + + /** + * The color green with an RGB value of #008000 + *
+ */ + public static final Color GREEN = new Color(0.0f, 0.5019608f, 0.0f); + + /** + * The color green yellow with an RGB value of #ADFF2F + *
+ */ + public static final Color GREENYELLOW = new Color(0.6784314f, 1.0f, 0.18431373f); + + /** + * The color grey with an RGB value of #808080 + *
+ */ + public static final Color GREY = GRAY; + + /** + * The color honeydew with an RGB value of #F0FFF0 + *
+ */ + public static final Color HONEYDEW = new Color(0.9411765f, 1.0f, 0.9411765f); + + /** + * The color hot pink with an RGB value of #FF69B4 + *
+ */ + public static final Color HOTPINK = new Color(1.0f, 0.4117647f, 0.7058824f); + + /** + * The color indian red with an RGB value of #CD5C5C + *
+ */ + public static final Color INDIANRED = new Color(0.8039216f, 0.36078432f, 0.36078432f); + + /** + * The color indigo with an RGB value of #4B0082 + *
+ */ + public static final Color INDIGO = new Color(0.29411766f, 0.0f, 0.50980395f); + + /** + * The color ivory with an RGB value of #FFFFF0 + *
+ */ + public static final Color IVORY = new Color(1.0f, 1.0f, 0.9411765f); + + /** + * The color khaki with an RGB value of #F0E68C + *
+ */ + public static final Color KHAKI = new Color(0.9411765f, 0.9019608f, 0.54901963f); + + /** + * The color lavender with an RGB value of #E6E6FA + *
+ */ + public static final Color LAVENDER = new Color(0.9019608f, 0.9019608f, 0.98039216f); + + /** + * The color lavender blush with an RGB value of #FFF0F5 + *
+ */ + public static final Color LAVENDERBLUSH = new Color(1.0f, 0.9411765f, 0.9607843f); + + /** + * The color lawn green with an RGB value of #7CFC00 + *
+ */ + public static final Color LAWNGREEN = new Color(0.4862745f, 0.9882353f, 0.0f); + + /** + * The color lemon chiffon with an RGB value of #FFFACD + *
+ */ + public static final Color LEMONCHIFFON = new Color(1.0f, 0.98039216f, 0.8039216f); + + /** + * The color light blue with an RGB value of #ADD8E6 + *
+ */ + public static final Color LIGHTBLUE = new Color(0.6784314f, 0.84705883f, 0.9019608f); + + /** + * The color light coral with an RGB value of #F08080 + *
+ */ + public static final Color LIGHTCORAL = new Color(0.9411765f, 0.5019608f, 0.5019608f); + + /** + * The color light cyan with an RGB value of #E0FFFF + *
+ */ + public static final Color LIGHTCYAN = new Color(0.8784314f, 1.0f, 1.0f); + + /** + * The color light goldenrod yellow with an RGB value of #FAFAD2 + *
+ */ + public static final Color LIGHTGOLDENRODYELLOW = new Color(0.98039216f, 0.98039216f, 0.8235294f); + + /** + * The color light gray with an RGB value of #D3D3D3 + *
+ */ + public static final Color LIGHTGRAY = new Color(0.827451f, 0.827451f, 0.827451f); + + /** + * The color light green with an RGB value of #90EE90 + *
+ */ + public static final Color LIGHTGREEN = new Color(0.5647059f, 0.93333334f, 0.5647059f); + + /** + * The color light grey with an RGB value of #D3D3D3 + *
+ */ + public static final Color LIGHTGREY = LIGHTGRAY; + + /** + * The color light pink with an RGB value of #FFB6C1 + *
+ */ + public static final Color LIGHTPINK = new Color(1.0f, 0.7137255f, 0.75686276f); + + /** + * The color light salmon with an RGB value of #FFA07A + *
+ */ + public static final Color LIGHTSALMON = new Color(1.0f, 0.627451f, 0.47843137f); + + /** + * The color light sea green with an RGB value of #20B2AA + *
+ */ + public static final Color LIGHTSEAGREEN = new Color(0.1254902f, 0.69803923f, 0.6666667f); + + /** + * The color light sky blue with an RGB value of #87CEFA + *
+ */ + public static final Color LIGHTSKYBLUE = new Color(0.5294118f, 0.80784315f, 0.98039216f); + + /** + * The color light slate gray with an RGB value of #778899 + *
+ */ + public static final Color LIGHTSLATEGRAY = new Color(0.46666667f, 0.53333336f, 0.6f); + + /** + * The color light slate grey with an RGB value of #778899 + *
+ */ + public static final Color LIGHTSLATEGREY = LIGHTSLATEGRAY; + + /** + * The color light steel blue with an RGB value of #B0C4DE + *
+ */ + public static final Color LIGHTSTEELBLUE = new Color(0.6901961f, 0.76862746f, 0.87058824f); + + /** + * The color light yellow with an RGB value of #FFFFE0 + *
+ */ + public static final Color LIGHTYELLOW = new Color(1.0f, 1.0f, 0.8784314f); + + /** + * The color lime with an RGB value of #00FF00 + *
+ */ + public static final Color LIME = new Color(0.0f, 1.0f, 0.0f); + + /** + * The color lime green with an RGB value of #32CD32 + *
+ */ + public static final Color LIMEGREEN = new Color(0.19607843f, 0.8039216f, 0.19607843f); + + /** + * The color linen with an RGB value of #FAF0E6 + *
+ */ + public static final Color LINEN = new Color(0.98039216f, 0.9411765f, 0.9019608f); + + /** + * The color magenta with an RGB value of #FF00FF + *
+ */ + public static final Color MAGENTA = new Color(1.0f, 0.0f, 1.0f); + + /** + * The color maroon with an RGB value of #800000 + *
+ */ + public static final Color MAROON = new Color(0.5019608f, 0.0f, 0.0f); + + /** + * The color medium aquamarine with an RGB value of #66CDAA + *
+ */ + public static final Color MEDIUMAQUAMARINE = new Color(0.4f, 0.8039216f, 0.6666667f); + + /** + * The color medium blue with an RGB value of #0000CD + *
+ */ + public static final Color MEDIUMBLUE = new Color(0.0f, 0.0f, 0.8039216f); + + /** + * The color medium orchid with an RGB value of #BA55D3 + *
+ */ + public static final Color MEDIUMORCHID = new Color(0.7294118f, 0.33333334f, 0.827451f); + + /** + * The color medium purple with an RGB value of #9370DB + *
+ */ + public static final Color MEDIUMPURPLE = new Color(0.5764706f, 0.4392157f, 0.85882354f); + + /** + * The color medium sea green with an RGB value of #3CB371 + *
+ */ + public static final Color MEDIUMSEAGREEN = new Color(0.23529412f, 0.7019608f, 0.44313726f); + + /** + * The color medium slate blue with an RGB value of #7B68EE + *
+ */ + public static final Color MEDIUMSLATEBLUE = new Color(0.48235294f, 0.40784314f, 0.93333334f); + + /** + * The color medium spring green with an RGB value of #00FA9A + *
+ */ + public static final Color MEDIUMSPRINGGREEN = new Color(0.0f, 0.98039216f, 0.6039216f); + + /** + * The color medium turquoise with an RGB value of #48D1CC + *
+ */ + public static final Color MEDIUMTURQUOISE = new Color(0.28235295f, 0.81960785f, 0.8f); + + /** + * The color medium violet red with an RGB value of #C71585 + *
+ */ + public static final Color MEDIUMVIOLETRED = new Color(0.78039217f, 0.08235294f, 0.52156866f); + + /** + * The color midnight blue with an RGB value of #191970 + *
+ */ + public static final Color MIDNIGHTBLUE = new Color(0.09803922f, 0.09803922f, 0.4392157f); + + /** + * The color mint cream with an RGB value of #F5FFFA + *
+ */ + public static final Color MINTCREAM = new Color(0.9607843f, 1.0f, 0.98039216f); + + /** + * The color misty rose with an RGB value of #FFE4E1 + *
+ */ + public static final Color MISTYROSE = new Color(1.0f, 0.89411765f, 0.88235295f); + + /** + * The color moccasin with an RGB value of #FFE4B5 + *
+ */ + public static final Color MOCCASIN = new Color(1.0f, 0.89411765f, 0.70980394f); + + /** + * The color navajo white with an RGB value of #FFDEAD + *
+ */ + public static final Color NAVAJOWHITE = new Color(1.0f, 0.87058824f, 0.6784314f); + + /** + * The color navy with an RGB value of #000080 + *
+ */ + public static final Color NAVY = new Color(0.0f, 0.0f, 0.5019608f); + + /** + * The color old lace with an RGB value of #FDF5E6 + *
+ */ + public static final Color OLDLACE = new Color(0.99215686f, 0.9607843f, 0.9019608f); + + /** + * The color olive with an RGB value of #808000 + *
+ */ + public static final Color OLIVE = new Color(0.5019608f, 0.5019608f, 0.0f); + + /** + * The color olive drab with an RGB value of #6B8E23 + *
+ */ + public static final Color OLIVEDRAB = new Color(0.41960785f, 0.5568628f, 0.13725491f); + + /** + * The color orange with an RGB value of #FFA500 + *
+ */ + public static final Color ORANGE = new Color(1.0f, 0.64705884f, 0.0f); + + /** + * The color orange red with an RGB value of #FF4500 + *
+ */ + public static final Color ORANGERED = new Color(1.0f, 0.27058825f, 0.0f); + + /** + * The color orchid with an RGB value of #DA70D6 + *
+ */ + public static final Color ORCHID = new Color(0.85490197f, 0.4392157f, 0.8392157f); + + /** + * The color pale goldenrod with an RGB value of #EEE8AA + *
+ */ + public static final Color PALEGOLDENROD = new Color(0.93333334f, 0.9098039f, 0.6666667f); + + /** + * The color pale green with an RGB value of #98FB98 + *
+ */ + public static final Color PALEGREEN = new Color(0.59607846f, 0.9843137f, 0.59607846f); + + /** + * The color pale turquoise with an RGB value of #AFEEEE + *
+ */ + public static final Color PALETURQUOISE = new Color(0.6862745f, 0.93333334f, 0.93333334f); + + /** + * The color pale violet red with an RGB value of #DB7093 + *
+ */ + public static final Color PALEVIOLETRED = new Color(0.85882354f, 0.4392157f, 0.5764706f); + + /** + * The color papaya whip with an RGB value of #FFEFD5 + *
+ */ + public static final Color PAPAYAWHIP = new Color(1.0f, 0.9372549f, 0.8352941f); + + /** + * The color peach puff with an RGB value of #FFDAB9 + *
+ */ + public static final Color PEACHPUFF = new Color(1.0f, 0.85490197f, 0.7254902f); + + /** + * The color peru with an RGB value of #CD853F + *
+ */ + public static final Color PERU = new Color(0.8039216f, 0.52156866f, 0.24705882f); + + /** + * The color pink with an RGB value of #FFC0CB + *
+ */ + public static final Color PINK = new Color(1.0f, 0.7529412f, 0.79607844f); + + /** + * The color plum with an RGB value of #DDA0DD + *
+ */ + public static final Color PLUM = new Color(0.8666667f, 0.627451f, 0.8666667f); + + /** + * The color powder blue with an RGB value of #B0E0E6 + *
+ */ + public static final Color POWDERBLUE = new Color(0.6901961f, 0.8784314f, 0.9019608f); + + /** + * The color purple with an RGB value of #800080 + *
+ */ + public static final Color PURPLE = new Color(0.5019608f, 0.0f, 0.5019608f); + + /** + * The color red with an RGB value of #FF0000 + *
+ */ + public static final Color RED = new Color(1.0f, 0.0f, 0.0f); + + /** + * The color rosy brown with an RGB value of #BC8F8F + *
+ */ + public static final Color ROSYBROWN = new Color(0.7372549f, 0.56078434f, 0.56078434f); + + /** + * The color royal blue with an RGB value of #4169E1 + *
+ */ + public static final Color ROYALBLUE = new Color(0.25490198f, 0.4117647f, 0.88235295f); + + /** + * The color saddle brown with an RGB value of #8B4513 + *
+ */ + public static final Color SADDLEBROWN = new Color(0.54509807f, 0.27058825f, 0.07450981f); + + /** + * The color salmon with an RGB value of #FA8072 + *
+ */ + public static final Color SALMON = new Color(0.98039216f, 0.5019608f, 0.44705883f); + + /** + * The color sandy brown with an RGB value of #F4A460 + *
+ */ + public static final Color SANDYBROWN = new Color(0.95686275f, 0.6431373f, 0.3764706f); + + /** + * The color sea green with an RGB value of #2E8B57 + *
+ */ + public static final Color SEAGREEN = new Color(0.18039216f, 0.54509807f, 0.34117648f); + + /** + * The color sea shell with an RGB value of #FFF5EE + *
+ */ + public static final Color SEASHELL = new Color(1.0f, 0.9607843f, 0.93333334f); + + /** + * The color sienna with an RGB value of #A0522D + *
+ */ + public static final Color SIENNA = new Color(0.627451f, 0.32156864f, 0.1764706f); + + /** + * The color silver with an RGB value of #C0C0C0 + *
+ */ + public static final Color SILVER = new Color(0.7529412f, 0.7529412f, 0.7529412f); + + /** + * The color sky blue with an RGB value of #87CEEB + *
+ */ + public static final Color SKYBLUE = new Color(0.5294118f, 0.80784315f, 0.92156863f); + + /** + * The color slate blue with an RGB value of #6A5ACD + *
+ */ + public static final Color SLATEBLUE = new Color(0.41568628f, 0.3529412f, 0.8039216f); + + /** + * The color slate gray with an RGB value of #708090 + *
+ */ + public static final Color SLATEGRAY = new Color(0.4392157f, 0.5019608f, 0.5647059f); + + /** + * The color slate grey with an RGB value of #708090 + *
+ */ + public static final Color SLATEGREY = SLATEGRAY; + + /** + * The color snow with an RGB value of #FFFAFA + *
+ */ + public static final Color SNOW = new Color(1.0f, 0.98039216f, 0.98039216f); + + /** + * The color spring green with an RGB value of #00FF7F + *
+ */ + public static final Color SPRINGGREEN = new Color(0.0f, 1.0f, 0.49803922f); + + /** + * The color steel blue with an RGB value of #4682B4 + *
+ */ + public static final Color STEELBLUE = new Color(0.27450982f, 0.50980395f, 0.7058824f); + + /** + * The color tan with an RGB value of #D2B48C + *
+ */ + public static final Color TAN = new Color(0.8235294f, 0.7058824f, 0.54901963f); + + /** + * The color teal with an RGB value of #008080 + *
+ */ + public static final Color TEAL = new Color(0.0f, 0.5019608f, 0.5019608f); + + /** + * The color thistle with an RGB value of #D8BFD8 + *
+ */ + public static final Color THISTLE = new Color(0.84705883f, 0.7490196f, 0.84705883f); + + /** + * The color tomato with an RGB value of #FF6347 + *
+ */ + public static final Color TOMATO = new Color(1.0f, 0.3882353f, 0.2784314f); + + /** + * The color turquoise with an RGB value of #40E0D0 + *
+ */ + public static final Color TURQUOISE = new Color(0.2509804f, 0.8784314f, 0.8156863f); + + /** + * The color violet with an RGB value of #EE82EE + *
+ */ + public static final Color VIOLET = new Color(0.93333334f, 0.50980395f, 0.93333334f); + + /** + * The color wheat with an RGB value of #F5DEB3 + *
+ */ + public static final Color WHEAT = new Color(0.9607843f, 0.87058824f, 0.7019608f); + + /** + * The color white with an RGB value of #FFFFFF + *
+ */ + public static final Color WHITE = new Color(1.0f, 1.0f, 1.0f); + + /** + * The color white smoke with an RGB value of #F5F5F5 + *
+ */ + public static final Color WHITESMOKE = new Color(0.9607843f, 0.9607843f, 0.9607843f); + + /** + * The color yellow with an RGB value of #FFFF00 + *
+ */ + public static final Color YELLOW = new Color(1.0f, 1.0f, 0.0f); + + /** + * The color yellow green with an RGB value of #9ACD32 + *
+ */ + public static final Color YELLOWGREEN = new Color(0.6039216f, 0.8039216f, 0.19607843f); + + /* + * Named colors moved to nested class to initialize them only when they + * are needed. + */ + private static final class NamedColors { + private static final Map namedColors = + createNamedColors(); + + private NamedColors() { + } + + private static Color get(String name) { + return namedColors.get(name); + } + + private static Map createNamedColors() { + Map colors = new HashMap<>(256); + + colors.put("aliceblue", ALICEBLUE); + colors.put("antiquewhite", ANTIQUEWHITE); + colors.put("aqua", AQUA); + colors.put("aquamarine", AQUAMARINE); + colors.put("azure", AZURE); + colors.put("beige", BEIGE); + colors.put("bisque", BISQUE); + colors.put("black", BLACK); + colors.put("blanchedalmond", BLANCHEDALMOND); + colors.put("blue", BLUE); + colors.put("blueviolet", BLUEVIOLET); + colors.put("brown", BROWN); + colors.put("burlywood", BURLYWOOD); + colors.put("cadetblue", CADETBLUE); + colors.put("chartreuse", CHARTREUSE); + colors.put("chocolate", CHOCOLATE); + colors.put("coral", CORAL); + colors.put("cornflowerblue", CORNFLOWERBLUE); + colors.put("cornsilk", CORNSILK); + colors.put("crimson", CRIMSON); + colors.put("cyan", CYAN); + colors.put("darkblue", DARKBLUE); + colors.put("darkcyan", DARKCYAN); + colors.put("darkgoldenrod", DARKGOLDENROD); + colors.put("darkgray", DARKGRAY); + colors.put("darkgreen", DARKGREEN); + colors.put("darkgrey", DARKGREY); + colors.put("darkkhaki", DARKKHAKI); + colors.put("darkmagenta", DARKMAGENTA); + colors.put("darkolivegreen", DARKOLIVEGREEN); + colors.put("darkorange", DARKORANGE); + colors.put("darkorchid", DARKORCHID); + colors.put("darkred", DARKRED); + colors.put("darksalmon", DARKSALMON); + colors.put("darkseagreen", DARKSEAGREEN); + colors.put("darkslateblue", DARKSLATEBLUE); + colors.put("darkslategray", DARKSLATEGRAY); + colors.put("darkslategrey", DARKSLATEGREY); + colors.put("darkturquoise", DARKTURQUOISE); + colors.put("darkviolet", DARKVIOLET); + colors.put("deeppink", DEEPPINK); + colors.put("deepskyblue", DEEPSKYBLUE); + colors.put("dimgray", DIMGRAY); + colors.put("dimgrey", DIMGREY); + colors.put("dodgerblue", DODGERBLUE); + colors.put("firebrick", FIREBRICK); + colors.put("floralwhite", FLORALWHITE); + colors.put("forestgreen", FORESTGREEN); + colors.put("fuchsia", FUCHSIA); + colors.put("gainsboro", GAINSBORO); + colors.put("ghostwhite", GHOSTWHITE); + colors.put("gold", GOLD); + colors.put("goldenrod", GOLDENROD); + colors.put("gray", GRAY); + colors.put("green", GREEN); + colors.put("greenyellow", GREENYELLOW); + colors.put("grey", GREY); + colors.put("honeydew", HONEYDEW); + colors.put("hotpink", HOTPINK); + colors.put("indianred", INDIANRED); + colors.put("indigo", INDIGO); + colors.put("ivory", IVORY); + colors.put("khaki", KHAKI); + colors.put("lavender", LAVENDER); + colors.put("lavenderblush", LAVENDERBLUSH); + colors.put("lawngreen", LAWNGREEN); + colors.put("lemonchiffon", LEMONCHIFFON); + colors.put("lightblue", LIGHTBLUE); + colors.put("lightcoral", LIGHTCORAL); + colors.put("lightcyan", LIGHTCYAN); + colors.put("lightgoldenrodyellow", LIGHTGOLDENRODYELLOW); + colors.put("lightgray", LIGHTGRAY); + colors.put("lightgreen", LIGHTGREEN); + colors.put("lightgrey", LIGHTGREY); + colors.put("lightpink", LIGHTPINK); + colors.put("lightsalmon", LIGHTSALMON); + colors.put("lightseagreen", LIGHTSEAGREEN); + colors.put("lightskyblue", LIGHTSKYBLUE); + colors.put("lightslategray", LIGHTSLATEGRAY); + colors.put("lightslategrey", LIGHTSLATEGREY); + colors.put("lightsteelblue", LIGHTSTEELBLUE); + colors.put("lightyellow", LIGHTYELLOW); + colors.put("lime", LIME); + colors.put("limegreen", LIMEGREEN); + colors.put("linen", LINEN); + colors.put("magenta", MAGENTA); + colors.put("maroon", MAROON); + colors.put("mediumaquamarine", MEDIUMAQUAMARINE); + colors.put("mediumblue", MEDIUMBLUE); + colors.put("mediumorchid", MEDIUMORCHID); + colors.put("mediumpurple", MEDIUMPURPLE); + colors.put("mediumseagreen", MEDIUMSEAGREEN); + colors.put("mediumslateblue", MEDIUMSLATEBLUE); + colors.put("mediumspringgreen", MEDIUMSPRINGGREEN); + colors.put("mediumturquoise", MEDIUMTURQUOISE); + colors.put("mediumvioletred", MEDIUMVIOLETRED); + colors.put("midnightblue", MIDNIGHTBLUE); + colors.put("mintcream", MINTCREAM); + colors.put("mistyrose", MISTYROSE); + colors.put("moccasin", MOCCASIN); + colors.put("navajowhite", NAVAJOWHITE); + colors.put("navy", NAVY); + colors.put("oldlace", OLDLACE); + colors.put("olive", OLIVE); + colors.put("olivedrab", OLIVEDRAB); + colors.put("orange", ORANGE); + colors.put("orangered", ORANGERED); + colors.put("orchid", ORCHID); + colors.put("palegoldenrod", PALEGOLDENROD); + colors.put("palegreen", PALEGREEN); + colors.put("paleturquoise", PALETURQUOISE); + colors.put("palevioletred", PALEVIOLETRED); + colors.put("papayawhip", PAPAYAWHIP); + colors.put("peachpuff", PEACHPUFF); + colors.put("peru", PERU); + colors.put("pink", PINK); + colors.put("plum", PLUM); + colors.put("powderblue", POWDERBLUE); + colors.put("purple", PURPLE); + colors.put("red", RED); + colors.put("rosybrown", ROSYBROWN); + colors.put("royalblue", ROYALBLUE); + colors.put("saddlebrown", SADDLEBROWN); + colors.put("salmon", SALMON); + colors.put("sandybrown", SANDYBROWN); + colors.put("seagreen", SEAGREEN); + colors.put("seashell", SEASHELL); + colors.put("sienna", SIENNA); + colors.put("silver", SILVER); + colors.put("skyblue", SKYBLUE); + colors.put("slateblue", SLATEBLUE); + colors.put("slategray", SLATEGRAY); + colors.put("slategrey", SLATEGREY); + colors.put("snow", SNOW); + colors.put("springgreen", SPRINGGREEN); + colors.put("steelblue", STEELBLUE); + colors.put("tan", TAN); + colors.put("teal", TEAL); + colors.put("thistle", THISTLE); + colors.put("tomato", TOMATO); + colors.put("transparent", TRANSPARENT); + colors.put("turquoise", TURQUOISE); + colors.put("violet", VIOLET); + colors.put("wheat", WHEAT); + colors.put("white", WHITE); + colors.put("whitesmoke", WHITESMOKE); + colors.put("yellow", YELLOW); + colors.put("yellowgreen", YELLOWGREEN); + + return colors; + } + } + + public static double[] HSBtoRGB(double hue, double saturation, double brightness) { + // normalize the hue + double normalizedHue = ((hue % 360) + 360) % 360; + hue = normalizedHue/360; + + double r = 0, g = 0, b = 0; + if (saturation == 0) { + r = g = b = brightness; + } else { + double h = (hue - Math.floor(hue)) * 6.0; + double f = h - java.lang.Math.floor(h); + double p = brightness * (1.0 - saturation); + double q = brightness * (1.0 - saturation * f); + double t = brightness * (1.0 - (saturation * (1.0 - f))); + switch ((int) h) { + case 0: + r = brightness; + g = t; + b = p; + break; + case 1: + r = q; + g = brightness; + b = p; + break; + case 2: + r = p; + g = brightness; + b = t; + break; + case 3: + r = p; + g = q; + b = brightness; + break; + case 4: + r = t; + g = p; + b = brightness; + break; + case 5: + r = brightness; + g = p; + b = q; + break; + } + } + double[] f = new double[3]; + f[0] = r; + f[1] = g; + f[2] = b; + return f; + } + + public static double[] RGBtoHSB(double r, double g, double b) { + double hue, saturation, brightness; + double[] hsbvals = new double[3]; + double cmax = (r > g) ? r : g; + if (b > cmax) cmax = b; + double cmin = (r < g) ? r : g; + if (b < cmin) cmin = b; + + brightness = cmax; + if (cmax != 0) + saturation = (cmax - cmin) / cmax; + else + saturation = 0; + + if (saturation == 0) { + hue = 0; + } else { + double redc = (cmax - r) / (cmax - cmin); + double greenc = (cmax - g) / (cmax - cmin); + double bluec = (cmax - b) / (cmax - cmin); + if (r == cmax) + hue = bluec - greenc; + else if (g == cmax) + hue = 2.0 + redc - bluec; + else + hue = 4.0 + greenc - redc; + hue = hue / 6.0; + if (hue < 0) + hue = hue + 1.0; + } + hsbvals[0] = hue * 360; + hsbvals[1] = saturation; + hsbvals[2] = brightness; + return hsbvals; + } +} diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/BarcodeElement.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/BarcodeElement.java index 6d53614..c99b16c 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/BarcodeElement.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/BarcodeElement.java @@ -21,24 +21,27 @@ public class BarcodeElement implements Element, Drawable, Dividable, WidthRespec private float height; + private float scale; + private float maxWidth = -1; private Position absolutePosition; public BarcodeElement(Symbol symbol) { this.symbol = symbol; - this.width = symbol.getWidth(); - this.height = symbol.getHeight(); + setWidth(symbol.getWidth()); + setHeight(symbol.getHeight()); + setScale(1.0f); } public void setScale(float scale) { + this.scale = scale; setWidth(width * scale); setHeight(height * scale); } - @Override - public float getWidth() throws IOException { - return width; + public float getScale() { + return scale; } public void setWidth(float width) { @@ -46,14 +49,19 @@ public class BarcodeElement implements Element, Drawable, Dividable, WidthRespec } @Override - public float getHeight() throws IOException { - return height; + public float getWidth() throws IOException { + return width; } public void setHeight(float height) { this.height = height; } + @Override + public float getHeight() throws IOException { + return height; + } + @Override public Divided divide(float remainingHeight, float nextPageHeight) throws IOException { diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/ControlElement.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/ControlElement.java index f8a5026..3485583 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/ControlElement.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/ControlElement.java @@ -11,6 +11,11 @@ public class ControlElement implements Element { */ public final static ControlElement NEWPAGE = new ControlElement("NEWPAGE"); + /** + * Triggers flip to the next column. + */ + public final static ControlElement NEWCOLUMN = new ControlElement("NEWCOLUMN"); + private final String name; public ControlElement(final String name) { diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/Frame.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/Frame.java index 920e6e7..28fba68 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/Frame.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/Frame.java @@ -98,7 +98,7 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { /** * Adds a drawable to the frame. * - * @param drawable + * @param drawable the drawable */ public void add(final Drawable drawable) { innerList.add(drawable); @@ -154,8 +154,7 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { * stroke} and {@link #getBorderColor() color} is set. */ protected boolean hasBorder() { - return getShape() != null && getBorderStroke() != null - && getBorderColor() != null; + return getShape() != null && getBorderStroke() != null && getBorderColor() != null; } /** @@ -490,11 +489,9 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { private void setMaxWidth(final Drawable inner, float maxWidth) { if (inner instanceof WidthRespecting) { if (getGivenWidth() != null) { - ((WidthRespecting) inner).setMaxWidth(getGivenWidth() - - getHorizontalShapeSpacing()); + ((WidthRespecting) inner).setMaxWidth(getGivenWidth() - getHorizontalShapeSpacing()); } else if (maxWidth >= 0) { - ((WidthRespecting) inner).setMaxWidth(maxWidth - - getHorizontalSpacing()); + ((WidthRespecting) inner).setMaxWidth(maxWidth - getHorizontalSpacing()); } } } @@ -514,22 +511,15 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { @Override public void draw(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, DrawListener drawListener) throws IOException { - setInnerMaxWidthIfNecessary(); - float halfBorderWidth = 0; if (getBorderWidth() > 0) { halfBorderWidth = getBorderWidth() / 2f; } - upperLeft = upperLeft.add(getMarginLeft() + halfBorderWidth, - -getMarginTop() - halfBorderWidth); - + upperLeft = upperLeft.add(getMarginLeft() + halfBorderWidth, -getMarginTop() - halfBorderWidth); if (getShape() != null) { - float shapeWidth = getWidth() - getMarginLeft() - getMarginRight() - - getBorderWidth(); - float shapeHeight = getHeight() - getMarginTop() - - getMarginBottom() - getBorderWidth(); - + float shapeWidth = getWidth() - getMarginLeft() - getMarginRight() - getBorderWidth(); + float shapeHeight = getHeight() - getMarginTop() - getMarginBottom() - getBorderWidth(); if (getBackgroundColor() != null) { getShape().fill(pdDocument, contentStream, upperLeft, shapeWidth, shapeHeight, getBackgroundColor(), @@ -541,10 +531,7 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { getBorderStroke(), drawListener); } } - - Position innerUpperLeft = upperLeft.add(getPaddingLeft() - + halfBorderWidth, -getPaddingTop() - halfBorderWidth); - + Position innerUpperLeft = upperLeft.add(getPaddingLeft() + halfBorderWidth, -getPaddingTop() - halfBorderWidth); for (Drawable inner : innerList) { inner.draw(pdDocument, contentStream, innerUpperLeft, drawListener); innerUpperLeft = innerUpperLeft.add(0, -inner.getHeight()); @@ -562,23 +549,16 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { } @Override - public Divided divide(float remainingHeight, float nextPageHeight) - throws IOException { + public Divided divide(float remainingHeight, float nextPageHeight) throws IOException { setInnerMaxWidthIfNecessary(); - if (remainingHeight - getVerticalSpacing() <= 0) { return new Divided(new VerticalSpacer(remainingHeight), this); } - // find first inner that does not fit on page float spaceLeft = remainingHeight - getVerticalSpacing(); - DividedList dividedList = divideList(innerList, spaceLeft); - - float spaceLeftForDivided = spaceLeft - - getHeight(dividedList.getHead()); + float spaceLeftForDivided = spaceLeft - getHeight(dividedList.getHead()); Divided divided = null; - if (dividedList.getDrawableToDivide() != null) { Dividable innerDividable = null; if (dividedList.getDrawableToDivide() instanceof Dividable) { @@ -590,11 +570,9 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { divided = innerDividable.divide(spaceLeftForDivided, nextPageHeight - getVerticalSpacing()); } - Float firstHeight = getGivenHeight() == null ? null : remainingHeight; Float tailHeight = getGivenHeight() == null ? null : getGivenHeight() - spaceLeft; - // create head sub frame Frame first = new Frame(getGivenWidth(), firstHeight); copyAllButInnerAndSizeTo(first); @@ -604,7 +582,6 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { if (divided != null) { first.add(divided.getFirst()); } - // create tail sub frame Frame tail = new Frame(getGivenWidth(), tailHeight); copyAllButInnerAndSizeTo(tail); @@ -614,21 +591,17 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { if (dividedList.getTail() != null) { tail.addAll(dividedList.getTail()); } - return new Divided(first, tail); } - private DividedList divideList(List items, float spaceLeft) - throws IOException { + private DividedList divideList(List items, float spaceLeft) throws IOException { List head = null; List tail = null; Drawable toDivide = null; - float tmpHeight = 0; int index = 0; while (tmpHeight < spaceLeft) { tmpHeight += items.get(index).getHeight(); - if (tmpHeight == spaceLeft) { // we can split between two drawables head = items.subList(0, index + 1); @@ -636,7 +609,6 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { tail = items.subList(index + 1, items.size()); } } - if (tmpHeight > spaceLeft) { head = items.subList(0, index); toDivide = items.get(index); @@ -644,10 +616,8 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { tail = items.subList(index + 1, items.size()); } } - ++index; } - return new DividedList(head, toDivide, tail); } @@ -674,7 +644,5 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable { public List getTail() { return tail; } - } - } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/ImageElement.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/ImageElement.java index e9d1adf..b9b4033 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/ImageElement.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/ImageElement.java @@ -7,8 +7,12 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.Position; import org.xbib.graphics.pdfbox.layout.text.WidthRespecting; + +import javax.imageio.ImageIO; import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.util.Base64; public class ImageElement implements Element, Drawable, Dividable, WidthRespecting { @@ -24,10 +28,16 @@ public class ImageElement implements Element, Drawable, Dividable, WidthRespecti private float height; + private float scale; + private float maxWidth = -1; private Position absolutePosition; + public ImageElement(String base64) throws IOException { + this(ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(base64)))); + } + public ImageElement(BufferedImage image) { this.image = image; this.width = image.getWidth(); @@ -35,19 +45,13 @@ public class ImageElement implements Element, Drawable, Dividable, WidthRespecti } public void setScale(float scale) { + this.scale = scale; setWidth(width * scale); setHeight(height * scale); } - @Override - public float getWidth() throws IOException { - if (width == SCALE_TO_RESPECT_WIDTH) { - if (getMaxWidth() > 0 && image.getWidth() > getMaxWidth()) { - return getMaxWidth(); - } - return image.getWidth(); - } - return width; + public float getScale() { + return scale; } /** @@ -62,15 +66,14 @@ public class ImageElement implements Element, Drawable, Dividable, WidthRespecti } @Override - public float getHeight() throws IOException { - if (height == SCALE_TO_RESPECT_WIDTH) { + public float getWidth() throws IOException { + if (width == SCALE_TO_RESPECT_WIDTH) { if (getMaxWidth() > 0 && image.getWidth() > getMaxWidth()) { - return getMaxWidth() / (float) image.getWidth() - * (float) image.getHeight(); + return getMaxWidth(); } - return image.getHeight(); + return image.getWidth(); } - return height; + return width; } /** @@ -86,8 +89,18 @@ public class ImageElement implements Element, Drawable, Dividable, WidthRespecti } @Override - public Divided divide(float remainingHeight, float nextPageHeight) - throws IOException { + public float getHeight() throws IOException { + if (height == SCALE_TO_RESPECT_WIDTH) { + if (getMaxWidth() > 0 && image.getWidth() > getMaxWidth()) { + return getMaxWidth() / (float) image.getWidth() * (float) image.getHeight(); + } + return image.getHeight(); + } + return height; + } + + @Override + public Divided divide(float remainingHeight, float nextPageHeight) throws IOException { if (getHeight() <= nextPageHeight) { return new Divided(new VerticalSpacer(remainingHeight), this); } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/PathElement.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/PathElement.java new file mode 100644 index 0000000..8973591 --- /dev/null +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/PathElement.java @@ -0,0 +1,76 @@ +package org.xbib.graphics.pdfbox.layout.elements; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.xbib.graphics.pdfbox.layout.shape.Path; +import org.xbib.graphics.pdfbox.layout.shape.Stroke; +import org.xbib.graphics.pdfbox.layout.text.DrawListener; +import org.xbib.graphics.pdfbox.layout.text.Position; + +import java.awt.Color; +import java.io.IOException; + +public class PathElement implements Drawable, Element { + + private final Path path; + + private final Stroke stroke; + + private final Color color; + + private final Position position; + + private float width; + + private float height; + + public PathElement(Path path, Stroke stroke, Color color, Position position) { + this.path = path; + this.stroke = stroke; + this.color = color; + this.position = position; + setWidth(0f); + } + + public Stroke getStroke() { + return stroke; + } + + public Color getColor() { + return color; + } + + public void setWidth(float width) { + this.width = width; + } + + @Override + public float getWidth() throws IOException { + return width; + } + + public void setHeight(float height) { + this.height = height; + } + + @Override + public float getHeight() throws IOException { + return height; + } + + @Override + public Position getAbsolutePosition() { + return position; + } + + @Override + public void draw(PDDocument pdDocument, PDPageContentStream contentStream, + Position upperLeft, DrawListener drawListener) throws IOException { + path.draw(pdDocument, contentStream, upperLeft, getWidth(), getHeight(), color, stroke, drawListener); + } + + @Override + public Drawable removeLeadingEmptyVerticalSpace() { + return this; + } +} diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/Rectangle.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/Rectangle.java index 0b72efb..efecd10 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/Rectangle.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/Rectangle.java @@ -24,8 +24,7 @@ public class Rectangle extends Dimension { @Override public String toString() { - return "Rectangle [x=" + x + ", y=" + y + ", width=" + getWidth() - + ", height=" + getHeight() + "]"; + return "Rectangle [x=" + x + ", y=" + y + ", width=" + getWidth() + ", height=" + getHeight() + "]"; } @Override @@ -54,5 +53,4 @@ public class Rectangle extends Dimension { } return Float.floatToIntBits(y) == Float.floatToIntBits(other.y); } - } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/render/ColumnLayout.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/render/ColumnLayout.java index df09a9b..2fbc732 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/render/ColumnLayout.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/elements/render/ColumnLayout.java @@ -13,18 +13,13 @@ import java.io.IOException; */ public class ColumnLayout extends VerticalLayout { - /** - * Triggers flip to the next column. - */ - public final static ControlElement NEWCOLUMN = new ControlElement("NEWCOLUMN"); - - private final int columnCount; + private final float columnSpacing; + private int columnIndex = 0; private Float offsetY = null; - public ColumnLayout(int columnCount) { this(columnCount, 0); } @@ -65,7 +60,7 @@ public class ColumnLayout extends VerticalLayout { renderContext.newPage(); return true; } - if (element == NEWCOLUMN) { + if (element == ControlElement.NEWCOLUMN) { turnPage(renderContext); return true; } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/Fonts.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/Fonts.java new file mode 100644 index 0000000..38fd2ac --- /dev/null +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/Fonts.java @@ -0,0 +1,17 @@ +package org.xbib.graphics.pdfbox.layout.font; + +import org.xbib.graphics.pdfbox.layout.elements.Document; + +public enum Fonts { + HELVETICA, + TIMES, + COURIER, + NOTOSANS; + + public Font getFont(Document document) { + if ("notosans".equalsIgnoreCase(name())) { + return new NotoSansFont(document); + } + return BaseFont.valueOf(name()); + } +} diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/Engine.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/Engine.java index 642dec0..f37fb06 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/Engine.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/Engine.java @@ -4,26 +4,39 @@ import org.xbib.graphics.pdfbox.layout.script.command.Command; import org.xbib.settings.Settings; import java.io.IOException; -import java.util.Map; +import java.util.Set; public class Engine { + private final String packageName; + + private final ClassLoader classLoader; private final State state; public Engine() { + packageName = getClass().getPackageName(); + classLoader = getClass().getClassLoader(); this.state = new State(); } - public void execute(String key, Settings settings) throws IOException { - State state = new State(); - String packageName = getClass().getPackageName(); - ClassLoader classLoader = getClass().getClassLoader(); - for (Map.Entry entry : settings.getGroups(key).entrySet()) { + public void execute(Settings settings) throws IOException { + execute("document", state, settings); + } + + public void execute(String prefix, State state, Settings settings) throws IOException { + Settings subSettings = settings.getByPrefix(prefix); + Set set = subSettings.getAsStructuredMap().keySet(); + for (String string : set) { try { - String string = entry.getKey(); - Class cl = classLoader.loadClass(packageName + ".command." + string.substring(0, 1).toUpperCase() + string.substring(1) + "Command"); - Command command = (Command) cl.getConstructor().newInstance(); - command.execute(this, state, entry.getValue()); + Settings thisSettings = settings.getAsSettings(prefix + string); + String type = thisSettings.get("type"); + if (type == null) { + type = prefix; + } + String className = packageName + ".command." + type.substring(0, 1).toUpperCase() + type.substring(1) + "Command"; + Class cl = classLoader.loadClass(className); + Command command = (Command) cl.getConstructor().newInstance(); + command.execute(this, state, thisSettings); } catch (Exception e) { throw new IOException(e); } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/State.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/State.java index 1851024..5c16039 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/State.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/State.java @@ -1,8 +1,15 @@ package org.xbib.graphics.pdfbox.layout.script; import org.xbib.graphics.pdfbox.layout.elements.Document; +import org.xbib.graphics.pdfbox.layout.elements.Paragraph; +import org.xbib.graphics.pdfbox.layout.elements.PathElement; public class State { public Document document; + + public Paragraph paragraph; + + public PathElement pathElement; + } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/BarcodeCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/BarcodeCommand.java new file mode 100644 index 0000000..e9f7966 --- /dev/null +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/BarcodeCommand.java @@ -0,0 +1,41 @@ +package org.xbib.graphics.pdfbox.layout.script.command; + +import org.xbib.graphics.barcode.HumanReadableLocation; +import org.xbib.graphics.barcode.Symbol; +import org.xbib.graphics.barcode.Symbols; +import org.xbib.graphics.pdfbox.layout.elements.BarcodeElement; +import org.xbib.graphics.pdfbox.layout.script.Engine; +import org.xbib.graphics.pdfbox.layout.script.State; +import org.xbib.graphics.pdfbox.layout.text.Position; +import org.xbib.settings.Settings; + +import java.io.IOException; + +public class BarcodeCommand implements Command { + @Override + public void execute(Engine engine, State state, Settings settings) throws IOException { + BarcodeElement element; + try { + Symbol symbol = Symbols.valueOf(settings.get("symbol")).getSymbol(); + symbol.setContent(settings.get("value")); + symbol.setBarHeight(settings.getAsInt("barheight", 150)); + symbol.setHumanReadableLocation(HumanReadableLocation.valueOf(settings.get("readablelocation", "BOTTOM"))); + element = new BarcodeElement(symbol); + } catch (Exception e) { + throw new IOException(e); + } + if (settings.containsSetting("x") && settings.containsSetting("y")) { + element.setAbsolutePosition(new Position(settings.getAsFloat("x", 0f), settings.getAsFloat("y", 0f))); + } + if (settings.containsSetting("width")) { + element.setWidth(settings.getAsFloat("width", element.getWidth())); + } + if (settings.containsSetting("height")) { + element.setWidth(settings.getAsFloat("height", element.getHeight())); + } + if (settings.containsSetting("scale")) { + element.setScale(settings.getAsFloat("scale", element.getScale())); + } + state.document.add(element); + } +} diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/DocumentCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/DocumentCommand.java index 5bfa02a..6046e98 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/DocumentCommand.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/DocumentCommand.java @@ -12,11 +12,20 @@ public class DocumentCommand implements Command { @Override public void execute(Engine engine, State state, Settings settings) throws IOException { + String margin = settings.get("margin", "0 0 0 0"); + String[] margins = margin.split(" "); PageFormat pageFormat = PageFormat.builder() + .marginLeft(Float.parseFloat(margins[0])) + .marginRight(Float.parseFloat(margins[1])) + .marginTop(Float.parseFloat(margins[2])) + .marginBottom(Float.parseFloat(margins[3])) .pageFormat(settings.get("format", "A4")) .orientation(settings.get("orientiation", "PORTRAIT")) .build(); state.document = new Document(pageFormat); - engine.execute("paragraoh", settings); + engine.execute("image", state, settings); + engine.execute("barcode", state, settings); + engine.execute("path", state, settings); + engine.execute("paragraph", state, settings); } } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/ImageCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/ImageCommand.java new file mode 100644 index 0000000..144dede --- /dev/null +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/ImageCommand.java @@ -0,0 +1,31 @@ +package org.xbib.graphics.pdfbox.layout.script.command; + +import org.xbib.graphics.pdfbox.layout.elements.ImageElement; +import org.xbib.graphics.pdfbox.layout.elements.render.VerticalLayoutHint; +import org.xbib.graphics.pdfbox.layout.script.Engine; +import org.xbib.graphics.pdfbox.layout.script.State; +import org.xbib.graphics.pdfbox.layout.text.Alignment; +import org.xbib.graphics.pdfbox.layout.text.Position; +import org.xbib.settings.Settings; + +import java.io.IOException; + +public class ImageCommand implements Command { + @Override + public void execute(Engine engine, State state, Settings settings) throws IOException { + ImageElement element = new ImageElement(settings.get("value")); + if (settings.containsSetting("x") && settings.containsSetting("y")) { + element.setAbsolutePosition(new Position(settings.getAsFloat("x", 0f), settings.getAsFloat("y", 0f))); + } + if (settings.containsSetting("width")) { + element.setWidth(settings.getAsFloat("width", element.getWidth())); + } + if (settings.containsSetting("height")) { + element.setWidth(settings.getAsFloat("height", element.getHeight())); + } + if (settings.containsSetting("scale")) { + element.setScale(settings.getAsFloat("scale", element.getScale())); + } + state.document.add(element, new VerticalLayoutHint(Alignment.LEFT, 10, 10, 10, 10, true)); + } +} diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/ParagraphCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/ParagraphCommand.java index db61bff..c0769b8 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/ParagraphCommand.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/ParagraphCommand.java @@ -1,7 +1,9 @@ package org.xbib.graphics.pdfbox.layout.script.command; +import org.xbib.graphics.pdfbox.layout.elements.Paragraph; import org.xbib.graphics.pdfbox.layout.script.Engine; import org.xbib.graphics.pdfbox.layout.script.State; +import org.xbib.graphics.pdfbox.layout.text.Position; import org.xbib.settings.Settings; import java.io.IOException; @@ -10,5 +12,14 @@ public class ParagraphCommand implements Command { @Override public void execute(Engine engine, State state, Settings settings) throws IOException { + state.paragraph = new Paragraph(); + if (settings.containsSetting("x") && settings.containsSetting("y")) { + state.paragraph.setAbsolutePosition(new Position(settings.getAsFloat("x", 0f), settings.getAsFloat("y", 0f))); + } + if (settings.containsSetting("width")) { + state.paragraph.setMaxWidth(settings.getAsFloat("width", state.document.getPageWidth())); + } + state.document.add(state.paragraph); + engine.execute("text", state, settings); } } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/PathCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/PathCommand.java new file mode 100644 index 0000000..71e8956 --- /dev/null +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/PathCommand.java @@ -0,0 +1,51 @@ +package org.xbib.graphics.pdfbox.layout.script.command; + +import org.xbib.graphics.pdfbox.layout.color.ColorFactory; +import org.xbib.graphics.pdfbox.layout.elements.PathElement; +import org.xbib.graphics.pdfbox.layout.script.Engine; +import org.xbib.graphics.pdfbox.layout.script.State; +import org.xbib.graphics.pdfbox.layout.shape.Path; +import org.xbib.graphics.pdfbox.layout.shape.Stroke; +import org.xbib.graphics.pdfbox.layout.text.Position; +import org.xbib.settings.Settings; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +public class PathCommand implements Command { + + @Override + public void execute(Engine engine, State state, Settings settings) { + String value = settings.get("value"); + if (value == null) { + return; + } + List list = new ArrayList<>(); + String[] s = value.split(" "); + Position position = null; + if (s.length > 0) { + if (settings.getAsBoolean("absolute", false)) { + position = new Position(Float.parseFloat(s[0]), Float.parseFloat(s[1])); + list.add(position); + } else { + Position p = new Position(Float.parseFloat(s[0]), Float.parseFloat(s[1])); + list.add(p); + } + for (int i = 2; i < s.length; i += 2) { + Position p = new Position(Float.parseFloat(s[i]), Float.parseFloat(s[i + 1])); + list.add(p); + } + } + Path path = new Path(list); + Stroke.StrokeBuilder strokeBuilder = Stroke.builder() + .capStyle(Stroke.CapStyle.valueOf(settings.get("capstyie", "Cap"))) + .joinStyle(Stroke.JoinStyle.valueOf(settings.get("joinstyle", "Miter"))) + .lineWidth(settings.getAsFloat("linewidth", 1f)); + if (settings.containsSetting("dash")) { + strokeBuilder.dashPattern(new Stroke.DashPattern(settings.getAsFloat("dash", 1f))); + } + Color color = ColorFactory.web(settings.get("color", "black")); + state.document.add(new PathElement(path, strokeBuilder.build(), color, position)); + } +} diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/TextCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/TextCommand.java new file mode 100644 index 0000000..37d5982 --- /dev/null +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/script/command/TextCommand.java @@ -0,0 +1,17 @@ +package org.xbib.graphics.pdfbox.layout.script.command; + +import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.pdfbox.layout.font.Fonts; +import org.xbib.graphics.pdfbox.layout.script.Engine; +import org.xbib.graphics.pdfbox.layout.script.State; +import org.xbib.settings.Settings; + +public class TextCommand implements Command { + @Override + public void execute(Engine engine, State state, Settings settings) { + String value = settings.get("value"); + float size = settings.getAsFloat("size", 12.0f); + Font font = Fonts.valueOf(settings.get("font", "HELVETICA")).getFont(state.document); + state.paragraph.addMarkup(value, size, font); + } +} diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Ellipse.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Ellipse.java index 0e42966..f4061c9 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Ellipse.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Ellipse.java @@ -20,7 +20,6 @@ public class Ellipse extends RoundRect { protected void addRoundRect(PDPageContentStream contentStream, Position upperLeft, float width, float height, float cornerRadiusX, float cornerRadiusY) throws IOException { - super.addRoundRect(contentStream, upperLeft, width, height, width / 2f, - height / 2); + super.addRoundRect(contentStream, upperLeft, width, height, width / 2f, height / 2); } } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Path.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Path.java index 0ad29cd..626d169 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Path.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Path.java @@ -7,32 +7,44 @@ import org.xbib.graphics.pdfbox.layout.text.Position; import java.awt.Color; import java.io.IOException; -import java.util.ArrayList; import java.util.List; public class Path implements Shape { private final List list; - public Path() { - this.list = new ArrayList<>(); + public Path(List list) { + this.list = list; } @Override - public void draw(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, - float width, float height, Color color, Stroke stroke, DrawListener drawListener) throws IOException { + public void draw(PDDocument pdDocument, + PDPageContentStream contentStream, + Position upperLeft, + float width, + float height, + Color color, + Stroke stroke, + DrawListener drawListener) throws IOException { contentStream.saveGraphicsState(); - contentStream.moveTo(upperLeft.getX(), upperLeft.getY()); + float x = upperLeft.getX(); + float y = upperLeft.getY() - stroke.getLineWidth() / 2; contentStream.setStrokingColor(color); - contentStream.setLineCapStyle(stroke.getCapStyle().value()); - contentStream.setLineDashPattern(stroke.getDashPattern().getPattern(), stroke.getDashPattern().getPhase()); - contentStream.setLineJoinStyle(stroke.getJoinStyle().value()); - contentStream.setLineWidth(stroke.getLineWidth()); + stroke.applyTo(contentStream); + boolean move = true; for (Position p : list) { - contentStream.lineTo(p.getX(), p.getY()); + if (move) { + contentStream.moveTo(x + p.getX(), y + p.getY()); + move = false; + } else { + contentStream.lineTo(x + p.getX(), y + p.getY()); + } } + contentStream.stroke(); contentStream.restoreGraphicsState(); - drawListener.drawn(this, upperLeft, width, height); + if (drawListener != null) { + drawListener.drawn(this, upperLeft, width, height); + } } @Override @@ -44,6 +56,5 @@ public class Path implements Shape { @Override public void add(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, float width, float height) throws IOException { - list.add(new Position(width, height)); } } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Rect.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Rect.java index 585cc85..1c84cc7 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Rect.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Rect.java @@ -13,8 +13,6 @@ public class Rect extends AbstractShape { @Override public void add(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, float width, float height) throws IOException { - contentStream.addRect(upperLeft.getX(), upperLeft.getY() - height, - width, height); + contentStream.addRect(upperLeft.getX(), upperLeft.getY() - height, width, height); } - } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/RoundRect.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/RoundRect.java index 4f60938..c14dca8 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/RoundRect.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/RoundRect.java @@ -37,9 +37,11 @@ public class RoundRect extends AbstractShape { } @Override - public void add(PDDocument pdDocument, PDPageContentStream contentStream, - Position upperLeft, float width, float height) throws IOException { - + public void add(PDDocument pdDocument, + PDPageContentStream contentStream, + Position upperLeft, + float width, + float height) throws IOException { addRoundRect(contentStream, upperLeft, width, height, cornerRadiusX, cornerRadiusY); } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Stroke.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Stroke.java index 87c5027..8ed617f 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Stroke.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/shape/Stroke.java @@ -2,7 +2,6 @@ package org.xbib.graphics.pdfbox.layout.shape; import org.apache.pdfbox.pdmodel.PDPageContentStream; import java.io.IOException; -import java.util.Arrays; /** * This is a container for all information needed to perform a stroke. diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java index 05c39b2..389a041 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java @@ -1,6 +1,7 @@ package org.xbib.graphics.pdfbox.layout.table; import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.pdfbox.layout.util.PdfUtil; import java.awt.Color; import java.util.Comparator; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/StyledText.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/StyledText.java index 8d132ab..7e3603e 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/StyledText.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/StyledText.java @@ -3,6 +3,7 @@ package org.xbib.graphics.pdfbox.layout.table; import org.xbib.graphics.pdfbox.layout.elements.Paragraph; import org.xbib.graphics.pdfbox.layout.font.Font; import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.pdfbox.layout.util.PdfUtil; import java.awt.Color; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/TextCellRenderer.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/TextCellRenderer.java index fa78073..cf2a1f3 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/TextCellRenderer.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/TextCellRenderer.java @@ -5,7 +5,7 @@ import static org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment.JUSTIFY; import static org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment.RIGHT; import org.xbib.graphics.pdfbox.layout.font.Font; import org.xbib.graphics.pdfbox.layout.table.AbstractTextCell; -import org.xbib.graphics.pdfbox.layout.table.PdfUtil; +import org.xbib.graphics.pdfbox.layout.util.PdfUtil; import java.awt.Color; import java.io.IOException; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/VerticalTextCellRenderer.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/VerticalTextCellRenderer.java index c197c87..ddf352b 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/VerticalTextCellRenderer.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/VerticalTextCellRenderer.java @@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.table.render; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.util.Matrix; import org.xbib.graphics.pdfbox.layout.font.Font; -import org.xbib.graphics.pdfbox.layout.table.PdfUtil; +import org.xbib.graphics.pdfbox.layout.util.PdfUtil; import org.xbib.graphics.pdfbox.layout.table.VerticalTextCell; import java.awt.Color; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/IndentCharacters.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/IndentCharacters.java index d1ff110..d0e3421 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/IndentCharacters.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/IndentCharacters.java @@ -200,7 +200,7 @@ public class IndentCharacters { } enumerator = EnumeratorFactory.createEnumerator(enumerationType); this.separator = separator != null ? separator : enumerator - .getDefaultSeperator(); + .getDefaultSeparator(); } @Override diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/Enumerator.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/Enumerator.java index d6b5ea0..39832a2 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/Enumerator.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/Enumerator.java @@ -13,5 +13,5 @@ public interface Enumerator { /** * @return the default separator. */ - String getDefaultSeperator(); + String getDefaultSeparator(); } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/Enumerators.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/Enumerators.java index 99ded83..ab0a67d 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/Enumerators.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/Enumerators.java @@ -34,7 +34,7 @@ public class Enumerators { } @Override - public String getDefaultSeperator() { + public String getDefaultSeparator() { return "."; } } @@ -49,8 +49,7 @@ public class Enumerators { * c) Stet clita ... * */ - public static class LowerCaseAlphabeticEnumerator extends - AlphabeticEnumerator { + public static class LowerCaseAlphabeticEnumerator extends AlphabeticEnumerator { public LowerCaseAlphabeticEnumerator() { super(); @@ -98,7 +97,7 @@ public class Enumerators { } @Override - public String getDefaultSeperator() { + public String getDefaultSeparator() { return ")"; } @@ -173,7 +172,7 @@ public class Enumerators { } @Override - public String getDefaultSeperator() { + public String getDefaultSeparator() { return "."; } @@ -181,60 +180,60 @@ public class Enumerators { if (input < 1 || input > 3999) { return "Invalid Roman Number Value"; } - String s = ""; + StringBuilder s = new StringBuilder(); while (input >= 1000) { - s += "M"; + s.append("M"); input -= 1000; } while (input >= 900) { - s += "CM"; + s.append("CM"); input -= 900; } while (input >= 500) { - s += "D"; + s.append("D"); input -= 500; } while (input >= 400) { - s += "CD"; + s.append("CD"); input -= 400; } while (input >= 100) { - s += "C"; + s.append("C"); input -= 100; } while (input >= 90) { - s += "XC"; + s.append("XC"); input -= 90; } while (input >= 50) { - s += "L"; + s.append("L"); input -= 50; } while (input >= 40) { - s += "XL"; + s.append("XL"); input -= 40; } while (input >= 10) { - s += "X"; + s.append("X"); input -= 10; } while (input >= 9) { - s += "IX"; + s.append("IX"); input -= 9; } while (input >= 5) { - s += "V"; + s.append("V"); input -= 5; } while (input >= 4) { - s += "IV"; + s.append("IV"); input -= 4; } while (input >= 1) { - s += "I"; + s.append("I"); input -= 1; } - return s; + return s.toString(); } } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/PdfUtil.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/PdfUtil.java similarity index 97% rename from graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/PdfUtil.java rename to graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/PdfUtil.java index 180ccb0..d727b11 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/PdfUtil.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/PdfUtil.java @@ -1,6 +1,7 @@ -package org.xbib.graphics.pdfbox.layout.table; +package org.xbib.graphics.pdfbox.layout.util; import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.pdfbox.layout.table.CouldNotDetermineStringWidthException; import java.io.IOException; import java.util.ArrayList; diff --git a/graphics-pdfbox-layout/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader b/graphics-pdfbox-layout/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader new file mode 100644 index 0000000..d7b543a --- /dev/null +++ b/graphics-pdfbox-layout/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader @@ -0,0 +1,2 @@ +org.xbib.settings.datastructures.PropertiesSettingsLoader +org.xbib.settings.datastructures.json.JsonSettingsLoader diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LineSpacingTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LineSpacingTest.java index 565ca44..027c614 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LineSpacingTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LineSpacingTest.java @@ -1,6 +1,7 @@ package org.xbib.graphics.pdfbox.layout.test; import org.junit.jupiter.api.Test; +import org.xbib.graphics.pdfbox.layout.elements.ControlElement; import org.xbib.graphics.pdfbox.layout.elements.Document; import org.xbib.graphics.pdfbox.layout.elements.Paragraph; import org.xbib.graphics.pdfbox.layout.elements.render.ColumnLayout; @@ -34,7 +35,7 @@ public class LineSpacingTest { document.add(left); document.add(left); document.add(left); - document.add(ColumnLayout.NEWCOLUMN); + document.add(ControlElement.NEWCOLUMN); Paragraph right = new Paragraph(); right.setLineSpacing(1.5f); right.setMaxWidth(document.getPageWidth() / 2); diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/script/ScriptTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/script/ScriptTest.java new file mode 100644 index 0000000..bd905f3 --- /dev/null +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/script/ScriptTest.java @@ -0,0 +1,21 @@ +package org.xbib.graphics.pdfbox.layout.test.script; + +import org.junit.jupiter.api.Test; +import org.xbib.graphics.pdfbox.layout.elements.Document; +import org.xbib.graphics.pdfbox.layout.script.Engine; +import org.xbib.settings.Settings; + +import java.io.FileOutputStream; + +public class ScriptTest { + + @Test + public void script() throws Exception { + Settings settings = Settings.settingsBuilder().loadFromResource("json", getClass().getResourceAsStream("script.json")) + .build(); + Engine engine = new Engine(); + engine.execute(settings); + Document document = engine.getState().document; + document.render().save(new FileOutputStream("build/script.pdf")); + } +} diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/table/TableTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/table/TableTest.java index ab138f0..a0084c2 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/table/TableTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/table/TableTest.java @@ -17,7 +17,7 @@ import org.xbib.graphics.pdfbox.layout.table.BorderStyle; import org.xbib.graphics.pdfbox.layout.table.Column; import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment; import org.xbib.graphics.pdfbox.layout.table.ImageCell; -import org.xbib.graphics.pdfbox.layout.table.PdfUtil; +import org.xbib.graphics.pdfbox.layout.util.PdfUtil; import org.xbib.graphics.pdfbox.layout.table.Row; import org.xbib.graphics.pdfbox.layout.table.Table; import org.xbib.graphics.pdfbox.layout.table.TableRenderer; diff --git a/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/hellocat.pdf b/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/hellocat.pdf new file mode 100644 index 0000000..cc0435f Binary files /dev/null and b/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/hellocat.pdf differ diff --git a/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/script/logo-print.png b/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/script/logo-print.png new file mode 100644 index 0000000..a34a6f3 Binary files /dev/null and b/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/script/logo-print.png differ diff --git a/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/script/logo-print.png.base64 b/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/script/logo-print.png.base64 new file mode 100644 index 0000000..029c3ff --- /dev/null +++ b/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/script/logo-print.png.base64 @@ -0,0 +1 @@ +iVBORw0KGgoAAAANSUhEUgAAAfQAAAC0AQMAAABYN0wRAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gsEDjEFTKgt4wAAAi5JREFUaN7t2s1ygyAQAOClHLiVHnvojI/io+mj+Sg+Qo4eGKmwgPkfdjfTNC05ZEblm+BmxQUFL/ocoPnmhX6Fy0/zzf+kN8L8fXl/Fr8Z9O/wACq1nQAs1S9Q/Mabb/6v+qOd0+O82/3C8eFYvn6X++evrno/lwNr88033/zr+Vlnv8BA99vIOSQ/nvahzs+x58G7OBynglnX+jGO78EfIHSF6FfIv2rDoZ7qHRb0wY/xJkT0odPYawvxVkX0M+RevyMj+rANXWj2BTEURD8W/4lzG6KPjWPUPjhen/uB5t/gJOpbKGkeHu07jteP85bsp+K/ON644uMsas0hqfT9mrPWhG2TvK31g8/ebgJrxYXg/TYCoe+CMzjybRt1Xu2+9zEUuL+v9DrsEniz+zgK6dRoqPR29774Ma5x0L2n+654tXvcYHnly2lU+b547fGvlHuHaVTlhys+TWaI3hz7rtb7K/4g9BgWkR8kfhJ6TF+qt0deiTzUe3XF56tY4I3EO6HPc3muT+nL81rkY+RT+rN9St+n+ZT+PG/2VdWf92sqxfRtn8rOOz6nL8O78C31ZSmL7pdUBHUXfj5dAbztO4mPNKc/w0ea05fhJ6EfA40zIhxHiH5N5SjXu1hEcT2Enpf5H8MjcyKvhd482Vuh74R+EHov80rotdBboe+F3nM9TqU133vMnguPzylVzdPO81Y0f+/9i6d7/vP35ptvvvnmX9i/8PuHzf9f/w3g1VrR1Tf4UwAAAABJRU5ErkJggg== diff --git a/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/script/script.json b/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/script/script.json new file mode 100644 index 0000000..d3afb2e --- /dev/null +++ b/graphics-pdfbox-layout/src/test/resources/org/xbib/graphics/pdfbox/layout/test/script/script.json @@ -0,0 +1,33 @@ +{ + "document1": { + "margin": "10 10 10 10", + "image1": { + "scale": 0.25, + "value": "iVBORw0KGgoAAAANSUhEUgAAAfQAAAC0AQMAAABYN0wRAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gsEDjEFTKgt4wAAAi5JREFUaN7t2s1ygyAQAOClHLiVHnvojI/io+mj+Sg+Qo4eGKmwgPkfdjfTNC05ZEblm+BmxQUFL/ocoPnmhX6Fy0/zzf+kN8L8fXl/Fr8Z9O/wACq1nQAs1S9Q/Mabb/6v+qOd0+O82/3C8eFYvn6X++evrno/lwNr88033/zr+Vlnv8BA99vIOSQ/nvahzs+x58G7OBynglnX+jGO78EfIHSF6FfIv2rDoZ7qHRb0wY/xJkT0odPYawvxVkX0M+RevyMj+rANXWj2BTEURD8W/4lzG6KPjWPUPjhen/uB5t/gJOpbKGkeHu07jteP85bsp+K/ON644uMsas0hqfT9mrPWhG2TvK31g8/ebgJrxYXg/TYCoe+CMzjybRt1Xu2+9zEUuL+v9DrsEniz+zgK6dRoqPR29774Ma5x0L2n+654tXvcYHnly2lU+b547fGvlHuHaVTlhys+TWaI3hz7rtb7K/4g9BgWkR8kfhJ6TF+qt0deiTzUe3XF56tY4I3EO6HPc3muT+nL81rkY+RT+rN9St+n+ZT+PG/2VdWf92sqxfRtn8rOOz6nL8O78C31ZSmL7pdUBHUXfj5dAbztO4mPNKc/w0ea05fhJ6EfA40zIhxHiH5N5SjXu1hEcT2Enpf5H8MjcyKvhd482Vuh74R+EHov80rotdBboe+F3nM9TqU133vMnguPzylVzdPO81Y0f+/9i6d7/vP35ptvvvnmX9i/8PuHzf9f/w3g1VrR1Tf4UwAAAABJRU5ErkJggg==" + }, + "barcode1": { + "symbol": "Code3Of9", + "value": "12345678" + }, + "path1": { + "absolute": false, + "value": "10 10 100 10 100 20 10 20 10 10", + "color": "red", + "dash": 1 + }, + "paragraph1": { + "text1": { + "value": "Hello World", + "size": 24, + "font": "HELVETICA" + } + }, + "paragraph2": { + "text1": { + "value": "*Hello World*", + "size": 16, + "font": "NOTOSANS" + } + }, + } +}