Java 类net.sf.jasperreports.engine.fonts.FontUtil 实例源码

项目:jasperreports    文件:JRFillTextElement.java   
/**
 *
 */
protected Map<Attribute,Object> getStyledTextAttributes()
{
    JRStyle style = getStyle();
    Map<Attribute,Object> styledTextAttributes = styledTextAttributesMap.get(style);
    if (styledTextAttributes == null)
    {
        styledTextAttributes = new HashMap<Attribute,Object>(); 
        //JRFontUtil.getAttributes(styledTextAttributes, this, filler.getLocale());
        FontUtil.getInstance(filler.getJasperReportsContext()).getAttributesWithoutAwtFont(styledTextAttributes, this);
        styledTextAttributes.put(TextAttribute.FOREGROUND, getForecolor());
        if (getModeValue() == ModeEnum.OPAQUE)
        {
            styledTextAttributes.put(TextAttribute.BACKGROUND, getBackcolor());
        }
        styledTextAttributesMap.put(style, styledTextAttributes);
    }

    return styledTextAttributes;
}
项目:jasperreports    文件:JRFillContext.java   
/**
 * Constructs a fill context.
 */
public JRFillContext(BaseReportFiller masterFiller)
{
    this.masterFiller = masterFiller;
    this.jasperReportsContext = masterFiller.getJasperReportsContext();
    this.styledTextUtil = JRStyledTextUtil.getInstance(jasperReportsContext);

    loadedImageRenderers = new HashMap<Object,Renderable>();
    renderersCache = new RenderersCache(jasperReportsContext);
    loadedSubreports = new HashMap<Object,JasperReport>();
    loadedTemplates = new HashMap<Object,JRTemplate>();
    deduplicableRegistry = new DeduplicableRegistry();

    FontUtil.getInstance(jasperReportsContext).resetThreadMissingFontsCache();

    legacyElementStretchEnabled = 
        JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
            StretchTypeEnum.PROPERTY_LEGACY_ELEMENT_STRETCH_ENABLED
            );

    legacyBandEvaluationEnabled = 
        JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
            JRCalculator.PROPERTY_LEGACY_BAND_EVALUATION_ENABLED
            );
}
项目:PDFReporter-Studio    文件:ModelUtils.java   
/**
 * Return the font names, the names can be split in more array to categorize them. In this way when represented, the
 * category can be graphically divided (for example with a separator)
 * 
 * @param jContext
 * @return
 */
public static List<String[]> getFontNames(JasperReportsConfiguration jContext) {
    java.util.List<String[]> classes = new ArrayList<String[]>();
    java.util.List<String> elements = new ArrayList<String>();
    Collection<?> extensionFonts = FontUtil.getInstance(jContext).getFontFamilyNames();
    for (Iterator<?> it = extensionFonts.iterator(); it.hasNext();) {
        String fname = (String) it.next();
        elements.add(fname);
    }
    classes.add(elements.toArray(new String[elements.size()]));
    elements = new ArrayList<String>();
    String[] names = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int i = 0; i < names.length; i++) {
        String name = names[i];
        elements.add(name);
    }
    classes.add(elements.toArray(new String[elements.size()]));
    return classes;
}
项目:dynamicreports-jasper    文件:Report1Test.java   
@Override
public void test() {
    super.test();

    numberOfPagesTest(1);
    columnTitleCountTest(column1, 0);
    columnDetailCountTest(column1, 0);

    elementCountTest("title.textField1", 3);
    elementValueTest("title.textField1", "bundleKey3", "bundleKey3", "bundleValue");

    FontUtil fontUtil = FontUtil.getInstance(DefaultJasperReportsContext.getInstance());
    Assert.assertFalse("fonts", fontUtil.getFontFamilyNames().isEmpty());

    JasperPrint jasperPrint = getJasperPrint();
    Assert.assertEquals("Report", jasperPrint.getName());
    Assert.assertEquals(OrientationEnum.LANDSCAPE, jasperPrint.getOrientationValue());
    Assert.assertEquals(1190, jasperPrint.getPageWidth());
    Assert.assertEquals(842, jasperPrint.getPageHeight());

    Assert.assertEquals(50, scriptlet.count);
}
项目:jasperreports    文件:JRAbstractExporter.java   
/**
 *
 */
protected void setJasperReportsContext(JasperReportsContext jasperReportsContext)
{
    this.jasperReportsContext = jasperReportsContext;
    this.propertiesUtil = JRPropertiesUtil.getInstance(jasperReportsContext);
    this.rendererUtil = RendererUtil.getInstance(jasperReportsContext);
    this.allSelector = JRStyledTextAttributeSelector.getAllSelector(jasperReportsContext);
    this.noBackcolorSelector = JRStyledTextAttributeSelector.getNoBackcolorSelector(jasperReportsContext);
    this.noneSelector = JRStyledTextAttributeSelector.getNoneSelector(jasperReportsContext);
    this.styledTextUtil = JRStyledTextUtil.getInstance(jasperReportsContext);
    this.fontUtil = FontUtil.getInstance(jasperReportsContext);
}
项目:jasperreports    文件:JRAbstractExporter.java   
/**
 *
 */
@SuppressWarnings("deprecation")
protected void ensureJasperReportsContext()
{
    if (
        parameters.containsKey(JRExporterParameter.CLASS_LOADER)
        || parameters.containsKey(JRExporterParameter.URL_HANDLER_FACTORY)
        || parameters.containsKey(JRExporterParameter.FILE_RESOLVER)
        )
    {
        LocalJasperReportsContext localJasperReportsContext = new LocalJasperReportsContext(jasperReportsContext);

        if (parameters.containsKey(JRExporterParameter.CLASS_LOADER))
        {
            localJasperReportsContext.setClassLoader((ClassLoader)parameters.get(JRExporterParameter.CLASS_LOADER));
        }

        if (parameters.containsKey(JRExporterParameter.URL_HANDLER_FACTORY))
        {
            localJasperReportsContext.setURLStreamHandlerFactory((URLStreamHandlerFactory)parameters.get(JRExporterParameter.URL_HANDLER_FACTORY));
        }

        if (parameters.containsKey(JRExporterParameter.FILE_RESOLVER))
        {
            localJasperReportsContext.setFileResolver((FileResolver)parameters.get(JRExporterParameter.FILE_RESOLVER));
        }

        setJasperReportsContext(localJasperReportsContext);
    }

    FontUtil.getInstance(jasperReportsContext).resetThreadMissingFontsCache();
}
项目:jasperreports    文件:JRStyledTextAttributeSelector.java   
@Override
public Map<Attribute,Object> getStyledTextAttributes(JRPrintText printText)
{
    Map<Attribute,Object> attributes = new HashMap<Attribute,Object>(); 
    //JRFontUtil.getAttributes(attributes, printText, getTextLocale(printText));
    FontUtil.getInstance(jasperReportsContext).getAttributesWithoutAwtFont(attributes, printText);
    attributes.put(TextAttribute.FOREGROUND, printText.getForecolor());
    if (printText.getModeValue() == ModeEnum.OPAQUE)
    {
        attributes.put(TextAttribute.BACKGROUND, printText.getBackcolor());
    }
    return attributes;
}
项目:jasperreports    文件:JRStyledTextAttributeSelector.java   
@Override
public Map<Attribute,Object> getStyledTextAttributes(JRPrintText printText)
{
    Map<Attribute,Object> attributes = new HashMap<Attribute,Object>(); 
    //JRFontUtil.getAttributes(attributes, printText, getTextLocale(printText));
    FontUtil.getInstance(jasperReportsContext).getAttributesWithoutAwtFont(attributes, printText);
    attributes.put(TextAttribute.FOREGROUND, printText.getForecolor());
    return attributes;
}
项目:jasperreports    文件:ContextClassLoaderObjectInputStream.java   
/**
 * Checks to see if the object is an instance of <code>java.awt.Font</code>, 
 * and in case it is, it replaces it with the one looked up for in the font extensions.
 */
@Override
protected Object resolveObject(Object obj) throws IOException
{
    Font font = (obj instanceof Font) ? (Font)obj : null;

    if (font != null)
    {
        // We use the font.getName() method here because the name field in the java.awt.Font class is the only font name related information that gets serialized,
        // along with the size and style. The font.getFontName() and font.getFamily() both return runtime calculated values, which are not accurate in case of AWT fonts
        // created at runtime through font extensions (both seem to return 'Dialog').
        // For AWT fonts created from font extensions using the Font.createFont(int, InputStream), the name field is set to the same value as the font.getFontName(),
        // which is the recommended method to get the name of an AWT font.
        String fontName = font.getName();
        // We load an instance of an AWT font, even if the specified font name is not available (ignoreMissingFont=true),
        // because only third-party visualization packages such as JFreeChart (chart themes) store serialized java.awt.Font objects,
        // and they are responsible for the drawing as well.
        // Here we rely on the utility method ability to find a font by face name, not only family name. This is because font.getName() above returns an AWT font name,
        // not a font family name.
        Font newFont = FontUtil.getInstance(jasperReportsContext).getAwtFontFromBundles(fontName, font.getStyle(), font.getSize2D(), null, true);

        if (newFont != null)
        {
            return newFont.deriveFont(font.getAttributes());
        }
    }

    return obj;
}
项目:jasperreports    文件:JRStyledTextUtil.java   
/**
 *
 */
private JRStyledTextUtil(JasperReportsContext jasperReportsContext)
{
    //this.jasperReportsContext = jasperReportsContext;
    this.allSelector = JRStyledTextAttributeSelector.getAllSelector(jasperReportsContext);
    fontUtil = FontUtil.getInstance(jasperReportsContext);
    //FIXME read from report/element
    ignoreMissingFonts = JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
            JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT);
}
项目:jasperreports    文件:StyleCache.java   
/**
 *
 */
public StyleCache(
    JasperReportsContext jasperReportsContext, 
    WriterHelper styleWriter, 
    String exporterKey
    )
{
    this.fontUtil = FontUtil.getInstance(jasperReportsContext);
    this.styleWriter = styleWriter;
    this.exporterKey = exporterKey;
}
项目:jasperreports    文件:HtmlFontFamily.java   
/**
 * 
 */
public static HtmlFontFamily getInstance(JasperReportsContext jasperReportsContext, String htmlFontFamilyId)
{
    int localeSeparatorPos = htmlFontFamilyId.lastIndexOf(LOCALE_SEPARATOR);
    String familyName = htmlFontFamilyId.substring(0, localeSeparatorPos);
    String localeCode = htmlFontFamilyId.substring(localeSeparatorPos + LOCALE_SEPARATOR.length());
    Locale locale = JRDataUtils.getLocale(localeCode);

    FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(familyName, locale);

    return getInstance(locale, fontInfo);
}
项目:jasperreports    文件:AbstractHtmlExporter.java   
/**
 * 
 */
public String getFontFamily(
    boolean ignoreCase,
    String fontFamily,
    Locale locale
    )
{
    FontInfo fontInfo =
        FontUtil.getInstance(jasperReportsContext).getFontInfo(fontFamily, ignoreCase, locale);

    String htmlFamily = fontFamily;
    if (fontInfo != null)
    {
        //fontName found in font extensions
        FontFamily family = fontInfo.getFontFamily();
        String exportFont = family.getExportFont(getExporterKey());
        if (exportFont == null)
        {
            String handlerFamily = handleFont(fontInfo, locale);
            if (handlerFamily != null)
            {
                htmlFamily = handlerFamily;
            }
        }
        else
        {
            htmlFamily = exportFont;
        }
    }

    return htmlFamily;
}
项目:jasperreports    文件:BaseHelper.java   
/**
 *
 */
public BaseHelper(JasperReportsContext jasperReportsContext, Writer writer)
{
    this.jasperReportsContext = jasperReportsContext;
    this.fontUtil = FontUtil.getInstance(jasperReportsContext);
    this.writer = writer;
}
项目:jasperreports    文件:HtmlFont.java   
/**
 * 
 */
public static HtmlFont getInstance(JasperReportsContext jasperReportsContext, String htmlFontId)
{
    int localeSeparatorPos = htmlFontId.lastIndexOf(LOCALE_SEPARATOR);
    String faceName = htmlFontId.substring(0, localeSeparatorPos);
    boolean isBold = false;
    boolean isItalic = false;
    if (faceName.endsWith("-Italic"))
    {
        faceName = faceName.substring(0, faceName.length() - "-Italic".length());
        isItalic = true;
    }
    if (faceName.endsWith("-Bold"))
    {
        faceName = faceName.substring(0, faceName.length() - "-Bold".length());
        isBold = true;
    }
    if (faceName.endsWith("-BoldItalic"))
    {
        faceName = faceName.substring(0, faceName.length() - "-BoldItalic".length());
        isItalic = true;
        isBold = true;
    }
    String localeCode = htmlFontId.substring(localeSeparatorPos + LOCALE_SEPARATOR.length());
    Locale locale = JRDataUtils.getLocale(localeCode);

    FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(faceName, locale);

    return getInstance(locale, fontInfo, isBold, isItalic);
}
项目:jasperreports    文件:SimpleTextLineWrapper.java   
protected Font loadFont(Map<Attribute, Object> textAttributes)
{
    // check bundled fonts
    FontUtil fontUtil = FontUtil.getInstance(context.getJasperReportsContext());
    Font font = fontUtil.getAwtFontFromBundles(fontKey.fontAttribute, fontKey.style, fontKey.size, fontKey.locale, false);
    if (font == null)
    {
        // checking AWT font
        fontUtil.checkAwtFont(fontKey.fontAttribute.getFamily(), context.isIgnoreMissingFont());
        // creating AWT font
        // FIXME using the current text attributes might be slightly dangerous as we are sharing font metrics
        font = Font.getFont(textAttributes);
    }
    return font;
}
项目:jasperreports    文件:BatikAWTFontFamily.java   
@Override
public GVTFont deriveFont(float size, Map attrs) 
{
    if (font != null)
        return new AWTGVTFont(font, size);

    String fontFamilyName = fontFace.getFamilyName();
    if (
        fontFamilyName.startsWith("'")
        && fontFamilyName.endsWith("'")
        )
    {
        fontFamilyName = fontFamilyName.substring(1, fontFamilyName.length() - 1);
    }

    // svg font-family could have locale suffix because it is needed in svg measured by phantomjs;
    int localeSeparatorPos = fontFamilyName.lastIndexOf(HtmlFontFamily.LOCALE_SEPARATOR);
    if (localeSeparatorPos > 0)
    {
        fontFamilyName = fontFamilyName.substring(0, localeSeparatorPos);
    }

    Font awtFont = 
        FontUtil.getInstance(jasperReportsContext).getAwtFontFromBundles(
            true,
            fontFamilyName,
            (TextAttribute.WEIGHT_BOLD.equals(attrs.get(TextAttribute.WEIGHT)) ? Font.BOLD : Font.PLAIN)
            | (TextAttribute.POSTURE_OBLIQUE.equals(attrs.get(TextAttribute.POSTURE)) ? Font.ITALIC : Font.PLAIN),
            size, 
            null,//FIXMEBATIK locale 
            true
            );

    if (awtFont != null)
    {
        return new AWTGVTFont(awtFont);
    }

    return super.deriveFont(size, attrs);
}
项目:jasperreports    文件:HeaderToolbarElementJsonHandler.java   
private Set<String> getFontExtensionsFontNames(JasperReportsContext jasperReportsContext) {
    Set<String> classes = new TreeSet<String>(); 

    Collection<String> extensionFonts = FontUtil.getInstance(jasperReportsContext).getFontNames();
    for (Iterator<String> it = extensionFonts.iterator(); it.hasNext();) {
        String fname = it.next();
        classes.add(fname);
    }

    return classes;
}
项目:dynamicreports-jasper    文件:StyleResolver.java   
private static Font getFont(String fontName, Boolean bold, Boolean italic, Integer fontSize) {
    if (bold == null) {
        bold = false;
    }
    if (italic == null) {
        italic = false;
    }
    int fontStyle;
    if (bold && italic) {
        fontStyle = Font.BOLD | Font.ITALIC;
    }
    else if (bold) {
        fontStyle = Font.BOLD;
    }
    else if (italic) {
        fontStyle = Font.ITALIC;
    }
    else {
        fontStyle = Font.PLAIN;
    }

    FontUtil fontUtil = FontUtil.getInstance(DefaultJasperReportsContext.getInstance());
    Font font = fontUtil.getAwtFontFromBundles(fontName, fontStyle, (float) fontSize, Locale.getDefault(), true);
    if (font == null) {
        font = new Font(fontName, fontStyle, fontSize);
    }
    return font;
}
项目:jasperreports    文件:GenericChartTheme.java   
/**
 *
 */
private void setChartContext(ChartContext chartContext)
{
    this.threadLocalChartContext.set(chartContext);
    this.threadLocalFontUtil.set(FontUtil.getInstance(chartContext.getJasperReportsContext()));
}
项目:jasperreports    文件:GenericChartTheme.java   
/**
 *
 */
private FontUtil getFontUtil()
{
    return threadLocalFontUtil.get();
}
项目:jasperreports    文件:SimpleChartTheme.java   
/**
 *
 */
private FontUtil getFontUtil()
{
    return threadLocalFontUtil.get();
}
项目:jasperreports    文件:SimpleChartTheme.java   
/**
 *
 */
private void setChartContext(ChartContext chartContext)
{
    this.threadLocalChartContext.set(chartContext);
    this.threadLocalFontUtil.set(FontUtil.getInstance(chartContext.getJasperReportsContext()));
}
项目:jasperreports    文件:CategoryMarkerCustomizer.java   
protected CategoryMarker createMarker(JRChart jrc) 
{
    Comparable<?> value = getProperty(PROPERTY_CATEGORY);

    if (value == null)
    {
        return null;
    }

    CategoryMarker marker = new CategoryMarker(value);

    configureMarker(marker);

    configureStroke(marker);

    Boolean drawAsLine = getBooleanProperty(PROPERTY_DRAW_AS_LINE);
    if (drawAsLine != null) {
        marker.setDrawAsLine(drawAsLine);
    }

    //Setup the font
    Font font = marker.getLabelFont();

    String fontName = getProperty(PROPERTY_FONT_NAME);
    if (fontName == null) {
        fontName = font.getName();
    }

    Float fontSize = getFloatProperty(PROPERTY_FONT_SIZE);
    if (fontSize == null) {
        fontSize = Float.valueOf(font.getSize());
    }

    int fontStyle = Font.PLAIN;
    Boolean isBold = getBooleanProperty(PROPERTY_FONT_BOLD);
    if (isBold != null) {
        fontStyle = fontStyle | Font.BOLD;
    }
    Boolean isItalic = getBooleanProperty(PROPERTY_FONT_ITALIC);
    if (isItalic != null) {
        fontStyle = fontStyle | Font.ITALIC;
    }

    marker.setLabelFont(
        FontUtil.getInstance(filler.getJasperReportsContext()).getAwtFontFromBundles(
            fontName, 
            fontStyle, 
            fontSize, 
            filler.getFillContext().getMasterLocale(), 
            true
            )
        );

    return marker;
}
项目:jasperreports    文件:BatikFontFamilyResolver.java   
/**
 *
 */
private BatikFontFamilyResolver(JasperReportsContext jasperReportsContext)
{
    this.jasperReportsContext = jasperReportsContext;
    this.fontUtil = FontUtil.getInstance(jasperReportsContext);
}