001/*
002 * (C) Copyright 2015 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 *     Vincent Dutat
018 */
019package org.nuxeo.ecm.platform.signature.core.sign;
020
021import java.awt.Color;
022
023import org.apache.commons.logging.Log;
024import org.apache.commons.logging.LogFactory;
025import org.nuxeo.ecm.core.api.DocumentModel;
026import org.nuxeo.ecm.platform.signature.api.sign.SignatureAppearanceFactory;
027import org.nuxeo.ecm.platform.signature.api.sign.SignatureLayout;
028import org.nuxeo.ecm.platform.signature.api.sign.SignatureService;
029import org.nuxeo.runtime.api.Framework;
030
031import com.lowagie.text.Font;
032import com.lowagie.text.FontFactory;
033import com.lowagie.text.pdf.PdfSignatureAppearance;
034
035public class DefaultSignatureAppearanceFactory implements SignatureAppearanceFactory {
036
037    protected static final Log LOGGER = LogFactory.getLog(DefaultSignatureAppearanceFactory.class);
038
039    @Override
040    public void format(PdfSignatureAppearance pdfSignatureAppearance, DocumentModel doc, String principal, String reason) {
041        pdfSignatureAppearance.setReason(reason);
042        pdfSignatureAppearance.setAcro6Layers(true);
043        pdfSignatureAppearance.setRender(PdfSignatureAppearance.SignatureRenderDescription);
044        SignatureService service = Framework.getService(SignatureService.class);
045        SignatureLayout layout = ((SignatureServiceImpl)service).getSignatureLayout();
046        Font layer2Font = FontFactory.getFont(FontFactory.TIMES, layout.getTextSize(), Font.NORMAL, new Color(
047                        0x00, 0x00, 0x00));
048        pdfSignatureAppearance.setLayer2Font(layer2Font);
049    }
050
051}