Package apps.geometrixx.components.header

Source Code of apps.geometrixx.components.header.image_png

/*
* Copyright 1997-2008 Day Management AG
* Barfuesserplatz 6, 4001 Basel, Switzerland
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Day Management AG, ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Day.
*/

package apps.geometrixx.components.header;

import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.io.IOException;

import javax.jcr.RepositoryException;

import com.day.cq.wcm.api.components.Component;
import com.day.cq.wcm.commons.AbstractImageServlet;
import com.day.cq.wcm.commons.WCMUtils;
import com.day.cq.wcm.foundation.ImageHelper;
import com.day.cq.wcm.foundation.Image;
import com.day.image.Font;
import com.day.image.Layer;

/**
* Renders the header image
*/
public class image_png extends AbstractImageServlet {

    protected Layer createLayer(ImageContext ctx)
            throws RepositoryException, IOException {

        // constants
        int scale = 6;
        int paddingX = 35;
        int paddingY = 50;
        Color bgColor = new Color(0xff70A337, true);
        String title = ctx.properties.get("jcr:title", "");
        String[] titles = title.split("[\\r\\n]+");

        Color[] colors = new Color[]{
                Color.WHITE,
                Color.WHITE};
        Font[] fonts = new Font[]{
                new Font("Myriad Pro", 15 * scale, Font.BOLD),
                new Font("MyriadPro-Light", 18 * scale)};

        // load background image from docroot
        Component c = WCMUtils.getComponent(ctx.resource);
        Layer bg = ImageHelper.createLayer(c.getLocalResource("background.png"));

        // load additional image
        Image image = new Image(ctx.resource);
        image.setItemName(Image.NN_FILE, "image");
        image.setItemName(Image.PN_REFERENCE, "imageReference");
        Layer img = image.getLayer(false, false, false);
        if (img != null) {
            img.setX(bg.getWidth() - img.getWidth());
            img.setY(bg.getHeight() - img.getHeight());
            bg.merge(img);
        }

        // draw the title text (4 times bigger)
        Layer text = new Layer(1, 1, new Color(0x01ffffff, true));
        int y = 0;
        for (int i = 0; i < titles.length; i++) {
            if (i >= fonts.length) {
                break;
            }
            String txt = titles[i].toUpperCase();
            if (txt.length() > 0) {
                Rectangle2D extent = fonts[i].getTextExtent(0, 0, 0, 0, txt, Font.ALIGN_LEFT, 0, 0);
                text.setPaint(colors[i]);
                text.drawText(0, y, 0, 0, txt, fonts[i], Font.ALIGN_LEFT, 0, 0);
                y += extent.getHeight() + 4 * scale;
            }
        }
        text.resize(text.getWidth() / scale, text.getHeight() / scale);
        text.setY(paddingY);
        text.setX(paddingX);
        bg.merge(text);

        return bg;
    }
}
TOP

Related Classes of apps.geometrixx.components.header.image_png

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.