IDEMPIERE-238 Zk Report Viewer: use print format font setting ffor html output

This commit is contained in:
Heng Sin Low 2012-04-16 16:18:54 +08:00
parent 5e3c87abce
commit d9ed7e2aaa
1 changed files with 78 additions and 1 deletions

View File

@ -16,6 +16,8 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.print; package org.compiere.print;
import java.awt.Color;
import java.awt.Font;
import java.awt.print.PrinterJob; import java.awt.print.PrinterJob;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
@ -59,6 +61,7 @@ import org.apache.ecs.xhtml.td;
import org.apache.ecs.xhtml.th; import org.apache.ecs.xhtml.th;
import org.apache.ecs.xhtml.tr; import org.apache.ecs.xhtml.tr;
import org.compiere.model.MClient; import org.compiere.model.MClient;
import org.compiere.model.MColumn;
import org.compiere.model.MDunningRunEntry; import org.compiere.model.MDunningRunEntry;
import org.compiere.model.MInOut; import org.compiere.model.MInOut;
import org.compiere.model.MInvoice; import org.compiere.model.MInvoice;
@ -580,6 +583,17 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
th th = new th(); th th = new th();
tr.addElement(th); tr.addElement(th);
th.addElement(Util.maskHTML(item.getPrintName(language))); th.addElement(Util.maskHTML(item.getPrintName(language)));
if (cssPrefix != null)
{
MColumn column = MColumn.get(getCtx(), item.getAD_Column_ID());
if (column != null && column.getAD_Column_ID() > 0)
{
if (DisplayType.isNumeric(column.getAD_Reference_ID()))
{
th.setClass(cssPrefix + "-number");
}
}
}
} }
else else
{ {
@ -617,7 +631,56 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
td.setClass(cssPrefix + "-date"); td.setClass(cssPrefix + "-date");
else else
td.setClass(cssPrefix + "-text"); td.setClass(cssPrefix + "-text");
} }
String style = "";
MPrintFont mPrintFont = null;
if (item.getAD_PrintFont_ID() > 0)
{
mPrintFont = MPrintFont.get(item.getAD_PrintFont_ID());
}
else if (m_printFormat.getAD_PrintFont_ID() > 0)
{
mPrintFont = MPrintFont.get(m_printFormat.getAD_PrintFont_ID());
}
if (mPrintFont != null && mPrintFont.getAD_PrintFont_ID() > 0)
{
Font font = mPrintFont.getFont();
String fontFamily = font.getFamily();
fontFamily = getCSSFontFamily(fontFamily);
style = fontFamily != null ?"font-family:'"+fontFamily+"';" : "";
if (font.isBold())
{
style = style + "font-weight:bold;";
}
if (font.isItalic())
{
style = style + "font-style:italic;";
}
int size = font.getSize();
style=style+"font-size:"+size+"pt;";
}
MPrintColor mPrintColor = null;
if (item.getAD_PrintColor_ID() > 0)
{
mPrintColor = MPrintColor.get(m_ctx, item.getAD_PrintColor_ID());
}
else if (m_printFormat.getAD_PrintColor_ID() > 0)
{
mPrintColor = MPrintColor.get(m_ctx, m_printFormat.getAD_PrintColor_ID());
}
if (mPrintColor != null && mPrintColor.getAD_PrintColor_ID() > 0)
{
Color color = mPrintColor.getColor();
if (color != null)
{
style = style+"color:rgb("+color.getRed()+","+color.getGreen()+","+color.getBlue()+");";
}
}
if (style != null && style.trim().length() > 0)
td.setStyle(style);
} }
else if (obj instanceof PrintData) else if (obj instanceof PrintData)
{ {
@ -663,6 +726,20 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
} // createHTML } // createHTML
private String getCSSFontFamily(String fontFamily) {
if ("Dialog".equals(fontFamily) || "DialogInput".equals(fontFamily) || "Monospaced".equals(fontFamily))
{
return "monospace";
} else if ("SansSerif".equals(fontFamily))
{
return "sans-serif";
} else if ("Serif".equals(fontFamily))
{
return "serif";
}
return null;
}
/************************************************************************** /**************************************************************************
* Create CSV File * Create CSV File
* @param file file * @param file file