001/* 002 * (C) Copyright 2016 Nuxeo SA (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 022 023import org.apache.commons.lang.StringUtils; 024import org.nuxeo.ecm.core.api.NuxeoException; 025 026import java.util.Map; 027 028public class WatermarkProperties { 029 030 protected String fontFamily = "Helvetica"; 031 032 protected double fontSize = 72f; 033 034 protected int rotation = 0; 035 036 protected String hex255Color = "#000000"; 037 038 protected double alphaColor = 0.5f; 039 040 protected double xPosition = 0f; 041 042 protected double yPosition = 0f; 043 044 protected boolean invertY = false; 045 046 protected boolean invertX = false; 047 048 protected boolean relativeCoordinates = false; 049 050 protected double scale = 1.0; 051 052 public double getScale() { 053 return scale; 054 } 055 056 public void setScale(double scale) { 057 this.scale = scale; 058 } 059 060 public String getFontFamily() { 061 return fontFamily; 062 } 063 064 public void setFontFamily(String fontFamily) { 065 this.fontFamily = fontFamily; 066 } 067 068 public double getFontSize() { 069 return fontSize; 070 } 071 072 public void setFontSize(double fontSize) { 073 this.fontSize = fontSize; 074 } 075 076 public int getRotation() { 077 return rotation; 078 } 079 080 public void setRotation(int rotation) { 081 this.rotation = rotation %360; 082 } 083 084 public String getHex255Color() { 085 return hex255Color; 086 } 087 088 public void setHex255Color(String hex255Color) { 089 this.hex255Color = hex255Color; 090 } 091 092 public double getAlphaColor() { 093 return alphaColor; 094 } 095 096 public void setAlphaColor(double alphaColor) { 097 this.alphaColor = alphaColor; 098 } 099 100 public double getxPosition() { 101 return xPosition; 102 } 103 104 public void setxPosition(double xPosition) { 105 this.xPosition = xPosition; 106 } 107 108 public double getyPosition() { 109 return yPosition; 110 } 111 112 public void setyPosition(double yPosition) { 113 this.yPosition = yPosition; 114 } 115 116 public boolean isInvertY() { 117 return invertY; 118 } 119 120 public void setInvertY(boolean invertY) { 121 this.invertY = invertY; 122 } 123 124 public boolean isInvertX() { 125 return invertX; 126 } 127 128 public void setInvertX(boolean invertX) { 129 this.invertX = invertX; 130 } 131 132 public boolean isRelativeCoordinates() { 133 return relativeCoordinates; 134 } 135 136 public void setRelativeCoordinates(boolean relativeCoordinates) { 137 this.relativeCoordinates = relativeCoordinates; 138 } 139 140 public void updateFromMap(Map<String, String> map) { 141 for (Map.Entry<String, String> entry : map.entrySet()) { 142 if (StringUtils.isBlank(entry.getKey()) || StringUtils.isBlank(entry.getValue())) 143 continue; 144 String value = entry.getValue(); 145 String key = entry.getKey(); 146 switch (key) { 147 case "fontFamily": 148 setFontFamily(value); 149 break; 150 case "fontSize": 151 setFontSize(Double.valueOf(value)); 152 break; 153 case "rotation": 154 setRotation(Integer.valueOf(value)); 155 break; 156 case "hex255Color": 157 setHex255Color(value); 158 break; 159 case "alphaColor": 160 setAlphaColor(Double.valueOf(value)); 161 break; 162 case "xPosition": 163 setxPosition(Double.valueOf(value)); 164 break; 165 case "yPosition": 166 setyPosition(Double.valueOf(value)); 167 break; 168 case "invertY": 169 setInvertY(Boolean.valueOf(value)); 170 break; 171 case "invertX": 172 setInvertX(Boolean.valueOf(value)); 173 break; 174 case "relativeCoordinates": 175 setRelativeCoordinates(Boolean.valueOf(value)); 176 break; 177 case "scale": 178 setScale(Double.valueOf(value)); 179 break; 180 default: 181 throw new NuxeoException("Unknown property: " + key); 182 } 183 } 184 } 185 186}