Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #464

Merged
merged 8 commits into from
Nov 6, 2024
Merged

Test #464

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ public enum TokenType {
private Float fixFactor = .75f;

/**
* @deprecated Activer le watermark pour les utilisateurs externes
* Activer le watermark pour les utilisateurs externes
* @deprecated utiliser externalSignatureParams.addWatermark
*/
@Deprecated
private Boolean watermarkForExternals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ public String getFavoriteSignRequestParamsJson(String userEppn) throws JsonProce
@Transactional
public InputStream getDefaultImage(String eppn) throws IOException {
User user = getByEppn(eppn);
return fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail());
return fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail(), false);
}

@Transactional
Expand All @@ -885,7 +885,7 @@ public String getDefaultImage64(String eppn) throws IOException {
@Transactional
public InputStream getDefaultParaphe(String eppn) throws IOException {
User user = getByEppn(eppn);
return fileService.getDefaultParaphe(user.getName(), user.getFirstname(), user.getEmail());
return fileService.getDefaultParaphe(user.getName(), user.getFirstname(), user.getEmail(), false);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,17 @@ public void changeColor(BufferedImage imgBuf, int oldRed, int oldGreen, int oldB
imgBuf.setRGB(0, 0, w, h, rgb, 0, w);
}

public InputStream getDefaultImage(String name, String firstname, String email) throws IOException {
BufferedImage bufferedImage = new BufferedImage(Math.round(600 / globalProperties.getFixFactor()), Math.round(300 / globalProperties.getFixFactor()), BufferedImage.TYPE_INT_ARGB);
public InputStream getDefaultImage(String name, String firstname, String email, boolean print) throws IOException {
float fixFactor = globalProperties.getFixFactor();
if(!print) {
fixFactor = 1f;
}
BufferedImage bufferedImage = new BufferedImage(Math.round(600 / fixFactor), Math.round(300 / fixFactor), BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = bufferedImage.createGraphics();
graphics2D.setColor(new Color(0f,0f,0f,0f ));
Rectangle rect = new Rectangle();
rect.setRect(0, 0, 600 / globalProperties.getFixFactor(), 300 / globalProperties.getFixFactor());
graphics2D.fillRect(0, 0, Math.round(600 / globalProperties.getFixFactor()), Math.round(300 / globalProperties.getFixFactor()));
rect.setRect(0, 0, 600 / fixFactor, 300 / fixFactor);
graphics2D.fillRect(0, 0, Math.round(600 / fixFactor), Math.round(300 / fixFactor));
setQualityParams(graphics2D);
String word;
if(StringUtils.hasText(firstname) && StringUtils.hasText(name)) {
Expand All @@ -353,10 +357,10 @@ public InputStream getDefaultImage(String name, String firstname, String email)
int fontSize;
if(StringUtils.hasText(firstname) && StringUtils.hasText(name)) {
font = Font.createFont(Font.TRUETYPE_FONT, new ClassPathResource("/static/fonts/Signature.ttf").getInputStream()).deriveFont(Font.BOLD).deriveFont(12f);
fontSize = findFontSize(word, Math.round(250 / globalProperties.getFixFactor()), font);
fontSize = findFontSize(word, Math.round(250 / fixFactor), font);
} else {
font = Font.createFont(Font.TRUETYPE_FONT, new ClassPathResource("/static/fonts/LiberationSans-Regular.ttf").getInputStream()).deriveFont(Font.BOLD).deriveFont(12f);
fontSize = findFontSize(email, Math.round(500 / globalProperties.getFixFactor()), font);
fontSize = findFontSize(email, Math.round(500 / fixFactor), font);
}
font = font.deriveFont((float) fontSize);
graphics2D.setFont(font);
Expand All @@ -365,10 +369,10 @@ public InputStream getDefaultImage(String name, String firstname, String email)
int y = rect.y + ((rect.height - fm.getHeight()) / 2) + fm.getAscent();
int lineHeight = Math.round((float) fontSize / 1.5f);
if(StringUtils.hasText(firstname) && StringUtils.hasText(name)) {
graphics2D.drawString(StringUtils.capitalize(firstname), 250 / globalProperties.getFixFactor(), y - lineHeight);
graphics2D.drawString(StringUtils.capitalize(name), 250 / globalProperties.getFixFactor(), y + lineHeight);
graphics2D.drawString(StringUtils.capitalize(firstname), 250 / fixFactor, y - lineHeight);
graphics2D.drawString(StringUtils.capitalize(name), 250 / fixFactor, y + lineHeight);
} else {
graphics2D.drawString(email, 10 / globalProperties.getFixFactor(), y - lineHeight);
graphics2D.drawString(email, 10 / fixFactor, y - lineHeight);
}
graphics2D.dispose();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Expand All @@ -380,28 +384,32 @@ public InputStream getDefaultImage(String name, String firstname, String email)
}
}

public InputStream getDefaultParaphe(String name, String firstname, String email) throws IOException {
BufferedImage bufferedImage = new BufferedImage(Math.round(600 / globalProperties.getFixFactor()), Math.round(300 / globalProperties.getFixFactor()), BufferedImage.TYPE_INT_ARGB);
public InputStream getDefaultParaphe(String name, String firstname, String email, boolean print) throws IOException {
float fixFactor = globalProperties.getFixFactor();
if(!print) {
fixFactor = 1f;
}
BufferedImage bufferedImage = new BufferedImage(Math.round(600 / fixFactor), Math.round(300 / fixFactor), BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = bufferedImage.createGraphics();
graphics2D.setColor(new Color(0f,0f,0f,0f ));
Rectangle rect = new Rectangle();
rect.setRect(0, 0, 600 / globalProperties.getFixFactor(), 300 / globalProperties.getFixFactor());
graphics2D.fillRect(0, 0, Math.round(600 / globalProperties.getFixFactor()), Math.round(300 / globalProperties.getFixFactor()));
rect.setRect(0, 0, 600 / fixFactor, 300 / fixFactor);
graphics2D.fillRect(0, 0, Math.round(600 / fixFactor), Math.round(300 / fixFactor));
setQualityParams(graphics2D);
String word = email;
if(StringUtils.hasText(firstname) && StringUtils.hasText(name)) {
word = (firstname.charAt(0) + "" + name.charAt(0)).toUpperCase();
}
try {
Font font = Font.createFont(Font.TRUETYPE_FONT, new ClassPathResource("/static/fonts/Signature.ttf").getInputStream()).deriveFont(Font.BOLD).deriveFont(12f);
int fontSize = findFontSize(word, Math.round(250 / globalProperties.getFixFactor()), font);
int fontSize = findFontSize(word, Math.round(250 / fixFactor), font);
font = font.deriveFont((float) fontSize);
graphics2D.setFont(font);
graphics2D.setColor(Color.BLACK);
FontMetrics fm = graphics2D.getFontMetrics();
int y = rect.y + ((rect.height - fm.getHeight()) / 2) + fm.getAscent();
int lineHeight = Math.round((float) fontSize / 1.5f);
graphics2D.drawString(word, 250 / globalProperties.getFixFactor(), y - lineHeight);
graphics2D.drawString(word, 250 / fixFactor, y - lineHeight);
graphics2D.dispose();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", outputStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ private void stampImageToPage(SignRequest signRequest, SignRequestParams signReq
} else {
if ((signType.equals(SignType.visa) || signType.equals(SignType.hiddenVisa) || !signRequestParams.getAddImage())
&& (!StringUtils.hasText(signRequestParams.getTextPart()) || signRequestParams.getAddExtra()) ) {
signImage = fileService.addTextToImage(fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail()), signRequestParams, signType, user, newDate, otp);
signImage = fileService.addTextToImage(fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail(), true), signRequestParams, signType, user, newDate, otp);
} else if (signRequestParams.getAddExtra()) {
if(signRequestParams.getSignImageNumber() == null || signRequestParams.getSignImageNumber() >= user.getSignImages().size()) {
if(signRequestParams.getSignImageNumber() >= user.getSignImages().size() + 1) {
signImage = fileService.addTextToImage(fileService.getDefaultParaphe(user.getName(), user.getFirstname(), user.getEmail()), signRequestParams, signType, user, newDate, otp);
signImage = fileService.addTextToImage(fileService.getDefaultParaphe(user.getName(), user.getFirstname(), user.getEmail(), true), signRequestParams, signType, user, newDate, otp);
} else {
signImage = fileService.addTextToImage(fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail()), signRequestParams, signType, user, newDate, otp);
signImage = fileService.addTextToImage(fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail(), true), signRequestParams, signType, user, newDate, otp);
}
} else {
signImage = fileService.addTextToImage(user.getSignImages().get(signRequestParams.getSignImageNumber()).getInputStream(), signRequestParams, signType, user, newDate, otp);
Expand All @@ -165,9 +165,9 @@ private void stampImageToPage(SignRequest signRequest, SignRequestParams signReq
signImage = user.getSignImages().get(signRequestParams.getSignImageNumber()).getInputStream();
} else {
if(signRequestParams.getSignImageNumber() >= user.getSignImages().size() + 1) {
signImage = fileService.addTextToImage(fileService.getDefaultParaphe(user.getName(), user.getFirstname(), user.getEmail()), signRequestParams, signType, user, newDate, otp);
signImage = fileService.addTextToImage(fileService.getDefaultParaphe(user.getName(), user.getFirstname(), user.getEmail(), true), signRequestParams, signType, user, newDate, otp);
} else {
signImage = fileService.addTextToImage(fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail()), signRequestParams, signType, user, newDate, otp);
signImage = fileService.addTextToImage(fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail(), true), signRequestParams, signType, user, newDate, otp);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public PAdESSignatureParameters fillVisibleParameters(SignatureDocumentForm sign
if(user.getSignImages().size() > signRequestParams.getSignImageNumber() && signRequestParams.getAddImage()) {
inputStream = user.getSignImages().get(signRequestParams.getSignImageNumber()).getInputStream();
} else {
inputStream = fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail());
inputStream = fileService.getDefaultImage(user.getName(), user.getFirstname(), user.getEmail(), true);
}
InputStream signImage = fileService.addTextToImage(inputStream, signRequestParams, SignType.nexuSign, user, date, userService.getRoles(user.getEppn()).contains("ROLE_OTP"));
if(signRequestParams.getAddWatermark()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ <h5>Étape : <span class="bs-stepper-circle bg-primary" th:text="${iterator.inde
<br>
<select class="form-select" name="signType" th:id="'signType-' + ${workflowStep.id}" th:disabled="${workflowStep.autoSign}">
<th:block th:each="signType : ${signTypes}">
<option th:value="${signType}"
th:text="#{'signbook.signtype.' + ${signType}}"
th:selected="${workflowStep.signType == signType}"></option>
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}" th:selected="${signType.name() == 'pdfImageStamp'}"></option>
</th:block>
</select>
<input type="hidden" name="signType" value="certSign" th:if="${workflowStep.autoSign}" >
Expand Down
7 changes: 3 additions & 4 deletions src/main/resources/templates/admin/workflows/steps.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ <h5 class="modal-title" id="addStepLabel">Ajouter une étape</h5>
</div>

<div class="form-group mb-3" id="_signType_div_id">
<label for="signType_id"> <strong> Type de signature
par défaut
<label for="signType_id">
<strong> Type de signature par défaut</strong>
<button data-bs-target="#collapseHelpSignType"
data-bs-toggle="collapse" type="button"
class="btn btn-sm btn-transparent">
<i class="fa-solid fa-info-circle text-info"></i>
</button>
</strong>
<div class="collapse" id="collapseHelpSignType">
<div class="alert alert-info">
<ul>
Expand All @@ -137,7 +136,7 @@ <h5 class="modal-title" id="addStepLabel">Ajouter une étape</h5>
<div class="col-lg-10">
<select class="slim-select-simple" id="signType_id" name="signType" size="1">
<th:block th:each="signType : ${signTypes}">
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}"></option>
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}" th:selected="${signType.name() == 'pdfImageStamp'}"></option>
</th:block>
</select>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/user/signbooks/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ <h3 class="modal-title" id="exampleModalLabel">Ajouter une étape</h3>
<label for="signType_id">Type de signature</label>
<select class="slim-select-simple" id="signType_id" name="signType" size="1">
<th:block th:each="signType : ${signTypes}">
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}"></option>
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}" th:selected="${signType.name() == 'pdfImageStamp'}"></option>
</th:block>
</select>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/user/signrequests/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ <h5 class="modal-title" id="stepRepeatableModalLabel">Étape supplémentaire ?
<select name="signType" id="signType" class="form-select">
<th:block th:each="signType : ${signTypes}">
<option th:value="${signType}"
th:text="#{'signbook.signtype.' + ${signType}}" th:selected="${signType == 'pdfImageStamp'}"></option>
th:text="#{'signbook.signtype.' + ${signType}}" th:selected="${signType.name() == 'pdfImageStamp'}"></option>
</th:block>
</select>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/user/wizard/wiz-new-step.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h4 class="d-flex justify-content-center mt-4">Paramètres de l’étape&nbsp;<s
<label class="form-label" for="signType-1">Type de signature :</label>
<select class="form-select" id="signType-1" name="signType">
<th:block th:each="signType : ${signTypes}">
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}"></option>
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}" th:selected="${signType.name() == 'pdfImageStamp'}"></option>
</th:block>
</select>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h4 class="d-flex justify-content-center mt-4" th:text="'Paramètres de l’éta
<label for="signType-1">Type de signature :</label>
<select class="form-select" id="signType-1" name="signType">
<th:block th:each="signType : ${signTypes}">
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}"></option>
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}" th:selected="${signType.name() == 'pdfImageStamp'}"></option>
</th:block>
</select>
<input type="hidden" name="name" th:value="${name}">
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/user/workflows/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ <h5 class="modal-title" id="addStepLabel">Ajouter une étape</h5>
<div class="col-lg-10">
<select class="slim-select-simple" id="signType_id" name="signType" size="1">
<th:block th:each="signType : ${signTypes}">
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}"></option>
<option th:value="${signType}" th:text="#{'signbook.signtype.' + ${signType}}" th:selected="${signType.name() == 'pdfImageStamp'}"></option>
</th:block>
</select>
</div>
Expand Down
Loading