Package com.lowagie.geoforge.utils

Source Code of com.lowagie.geoforge.utils.LwgGfrVerticalCellFactory

/*
*  Copyright (C) 2011-2014 GeoForge Project
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU Lesser General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU Lesser General Public License for more details.
*
*  You should have received a copy of the GNU Lesser General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.lowagie.geoforge.utils;

import com.lowagie.text.LwgElement;
import com.lowagie.text.LwgImage;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.LwgPdfPCell;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
import java.awt.Color;

/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public class LwgGfrVerticalCellFactory
{
  
  
   public static LwgPdfPCell s_getVerticalCell(
           PdfWriter writer,
           String strWhat,
           Color colForeground,
           Color colBackground) throws Exception
   {
      LwgPdfPCell cell = null;

      float fltRed = ((float) colForeground.getRed()) / 256f;
      float fltGreen = ((float) colForeground.getGreen()) / 256f;
      float fltBlue = ((float) colForeground.getBlue()) / 256f;

      PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
      BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false);
      String text = strWhat;
      float size = 8;
      float width = bf.getWidthPoint(text, size);
      template.beginText();
      template.setRGBColorFillF(fltRed, fltGreen, fltBlue);
      template.setFontAndSize(bf, size);
      template.setTextMatrix(0, 2);
      template.showText(text);
      template.endText();
      template.setWidth(width);
      template.setHeight(size + 2);

      LwgImage img = LwgImage.getInstance(template);
      img.setRotationDegrees(90);

      cell = new LwgPdfPCell(img);
      cell.setHorizontalAlignment(LwgElement.ALIGN_CENTER);
      cell.setVerticalAlignment(LwgElement.ALIGN_MIDDLE);
      cell.setBackgroundColor(colBackground);


      return cell;
   }
}
TOP

Related Classes of com.lowagie.geoforge.utils.LwgGfrVerticalCellFactory

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.