001/* 002 * (C) Copyright 2016-2018 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thibaud Arguillere 018 * Michael Vachette 019 */ 020package org.nuxeo.ecm.platform.pdf.service.watermark; 021 022import java.util.Map; 023 024import org.apache.commons.lang3.StringUtils; 025import org.nuxeo.ecm.core.api.NuxeoException; 026 027public class WatermarkProperties { 028 029 protected String fontFamily = "Helvetica"; 030 031 protected double fontSize = 72f; 032 033 protected int rotation = 0; 034 035 protected String hex255Color = "#000000"; 036 037 protected double alphaColor = 0.5f; 038 039 protected double xPosition = 0f; 040 041 protected double yPosition = 0f; 042 043 protected boolean invertY = false; 044 045 protected boolean invertX = false; 046 047 protected boolean relativeCoordinates = false; 048 049 protected double scale = 1.0; 050 051 public double getScale() { 052 return scale; 053 } 054 055 public void setScale(double scale) { 056 this.scale = scale; 057 } 058 059 public String getFontFamily() { 060 return fontFamily; 061 } 062 063 public void setFontFamily(String fontFamily) { 064 this.fontFamily = fontFamily; 065 } 066 067 public double getFontSize() { 068 return fontSize; 069 } 070 071 public void setFontSize(double fontSize) { 072 this.fontSize = fontSize; 073 } 074 075 public int getRotation() { 076 return rotation; 077 } 078 079 public void setRotation(int rotation) { 080 this.rotation = rotation % 360; 081 } 082 083 public String getHex255Color() { 084 return hex255Color; 085 } 086 087 public void setHex255Color(String hex255Color) { 088 this.hex255Color = hex255Color; 089 } 090 091 public double getAlphaColor() { 092 return alphaColor; 093 } 094 095 public void setAlphaColor(double alphaColor) { 096 this.alphaColor = alphaColor; 097 } 098 099 public double getxPosition() { 100 return xPosition; 101 } 102 103 public void setxPosition(double xPosition) { 104 this.xPosition = xPosition; 105 } 106 107 public double getyPosition() { 108 return yPosition; 109 } 110 111 public void setyPosition(double yPosition) { 112 this.yPosition = yPosition; 113 } 114 115 public boolean isInvertY() { 116 return invertY; 117 } 118 119 public void setInvertY(boolean invertY) { 120 this.invertY = invertY; 121 } 122 123 public boolean isInvertX() { 124 return invertX; 125 } 126 127 public void setInvertX(boolean invertX) { 128 this.invertX = invertX; 129 } 130 131 public boolean isRelativeCoordinates() { 132 return relativeCoordinates; 133 } 134 135 public void setRelativeCoordinates(boolean relativeCoordinates) { 136 this.relativeCoordinates = relativeCoordinates; 137 } 138 139 public void updateFromMap(Map<String, String> map) { 140 for (Map.Entry<String, String> entry : map.entrySet()) { 141 if (StringUtils.isBlank(entry.getKey()) || StringUtils.isBlank(entry.getValue())) 142 continue; 143 String value = entry.getValue(); 144 String key = entry.getKey(); 145 switch (key) { 146 case "fontFamily": 147 setFontFamily(value); 148 break; 149 case "fontSize": 150 setFontSize(Double.parseDouble(value)); 151 break; 152 case "rotation": 153 setRotation(Integer.parseInt(value)); 154 break; 155 case "hex255Color": 156 setHex255Color(value); 157 break; 158 case "alphaColor": 159 setAlphaColor(Double.parseDouble(value)); 160 break; 161 case "xPosition": 162 setxPosition(Double.parseDouble(value)); 163 break; 164 case "yPosition": 165 setyPosition(Double.parseDouble(value)); 166 break; 167 case "invertY": 168 setInvertY(Boolean.parseBoolean(value)); 169 break; 170 case "invertX": 171 setInvertX(Boolean.parseBoolean(value)); 172 break; 173 case "relativeCoordinates": 174 setRelativeCoordinates(Boolean.parseBoolean(value)); 175 break; 176 case "scale": 177 setScale(Double.parseDouble(value)); 178 break; 179 default: 180 throw new NuxeoException("Unknown property: " + key); 181 } 182 } 183 } 184 185}