Examples of JRFont


Examples of net.sf.jasperreports.engine.JRFont

   * @param setFontLines whether to set underline and strikethrough as font style
   * @return the PDF font for the specified attributes
   */
  protected Font getFont(Map attributes, Locale locale, boolean setFontLines)
  {
    JRFont jrFont = new JRBaseFont(attributes);

    Exception initialException = null;

    Color forecolor = (Color)attributes.get(TextAttribute.FOREGROUND);

    // use the same font scale ratio as in JRStyledText.getAwtAttributedString
    float fontSizeScale = 1f;
    Integer scriptStyle = (Integer) attributes.get(TextAttribute.SUPERSCRIPT);
    if (scriptStyle != null && (
        TextAttribute.SUPERSCRIPT_SUB.equals(scriptStyle)
        || TextAttribute.SUPERSCRIPT_SUPER.equals(scriptStyle)))
    {
      fontSizeScale = 2f / 3;
    }
   
    Font font = null;
    PdfFont pdfFont = null;
    FontKey key = new FontKey(jrFont.getFontName(), jrFont.isBold(), jrFont.isItalic());

    if (fontMap != null && fontMap.containsKey(key))
    {
      pdfFont = (PdfFont) fontMap.get(key);
    }
    else
    {
      FontInfo fontInfo = JRFontUtil.getFontInfo(jrFont.getFontName(), locale);
      if (fontInfo == null)
      {
        //fontName NOT found in font extensions
        pdfFont = new PdfFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded());
      }
      else
      {
        //fontName found in font extensions
        FontFamily family = fontInfo.getFontFamily();
        FontFace face = fontInfo.getFontFace();
        int faceStyle = java.awt.Font.PLAIN;

        if (face == null)
        {
          //fontName matches family name in font extension
          if (jrFont.isBold() && jrFont.isItalic())
          {
            face = family.getBoldItalicFace();
            faceStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC;
          }
         
          if (face == null && jrFont.isBold())
          {
            face = family.getBoldFace();
            faceStyle = java.awt.Font.BOLD;
          }
         
          if (face == null && jrFont.isItalic())
          {
            face = family.getItalicFace();
            faceStyle = java.awt.Font.ITALIC;
          }
         
          if (face == null)
          {
            face = family.getNormalFace();
            faceStyle = java.awt.Font.PLAIN;
          }
           
//          if (face == null)
//          {
//            throw new JRRuntimeException("Font family '" + family.getName() + "' does not have the normal font face.");
//          }
        }
        else
        {
          //fontName matches face name in font extension; not family name
          faceStyle = fontInfo.getStyle();
        }
       
        String pdfFontName = null;
        int pdfFontStyle = java.awt.Font.PLAIN;
        if (jrFont.isBold() && jrFont.isItalic())
        {
          pdfFontName = family.getBoldItalicPdfFont();
          pdfFontStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC;
        }
       
        if (pdfFontName == null && jrFont.isBold())
        {
          pdfFontName = family.getBoldPdfFont();
          pdfFontStyle = java.awt.Font.BOLD;
        }
       
        if (pdfFontName == null && jrFont.isItalic())
        {
          pdfFontName = family.getItalicPdfFont();
          pdfFontStyle = java.awt.Font.ITALIC;
        }
       
        if (pdfFontName == null)
        {
          pdfFontName = family.getNormalPdfFont();
          pdfFontStyle = java.awt.Font.PLAIN;
        }

        if (pdfFontName == null)
        {
          //in theory, face file cannot be null here
          pdfFontName = (face == null || face.getFile() == null ? jrFont.getPdfFontName() : face.getFile());
          pdfFontStyle = faceStyle;//FIXMEFONT not sure this is correct, in case we inherit pdfFontName from default properties
        }

//        String ttf = face.getFile();
//        if (ttf == null)
//        {
//          throw new JRRuntimeException("The '" + face.getName() + "' font face in family '" + family.getName() + "' returns a null file.");
//        }
       
        pdfFont =
          new PdfFont(
            pdfFontName,
            family.getPdfEncoding() == null ? jrFont.getPdfEncoding() : family.getPdfEncoding(),
             family.isPdfEmbedded() == null ? jrFont.isPdfEmbedded() : family.isPdfEmbedded().booleanValue(),
            jrFont.isBold() && ((pdfFontStyle & java.awt.Font.BOLD) == 0),
            jrFont.isItalic() && ((pdfFontStyle & java.awt.Font.ITALIC) == 0)
            );
      }
    }

    int pdfFontStyle = (pdfFont.isPdfSimulatedBold() ? Font.BOLD : 0)
        | (pdfFont.isPdfSimulatedItalic() ? Font.ITALIC : 0);
    if (setFontLines)
    {
      pdfFontStyle |= (jrFont.isUnderline() ? Font.UNDERLINE : 0)
          | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0);
    }
   
    try
    {
      font = FontFactory.getFont(
        pdfFont.getPdfFontName(),
        pdfFont.getPdfEncoding(),
        pdfFont.isPdfEmbedded(),
        jrFont.getFontSize() * fontSizeScale,
        pdfFontStyle,
        forecolor
        );

      // check if FontFactory didn't find the font
      if (font.getBaseFont() == null && font.getFamily() == Font.UNDEFINED)
      {
        font = null;
      }
    }
    catch(Exception e)
    {
      initialException = e;
    }

    if (font == null)
    {
      byte[] bytes = null;

      try
      {
        bytes = JRLoader.loadBytesFromLocation(pdfFont.getPdfFontName(), classLoader, urlHandlerFactory, fileResolver);
      }
      catch(JRException e)
      {
        throw //NOPMD
          new JRRuntimeException(
            "Could not load the following font : "
            + "\npdfFontName   : " + pdfFont.getPdfFontName()
            + "\npdfEncoding   : " + pdfFont.getPdfEncoding()
            + "\nisPdfEmbedded : " + pdfFont.isPdfEmbedded(),
            initialException
            );
      }

      BaseFont baseFont = null;

      try
      {
        baseFont =
          BaseFont.createFont(
            pdfFont.getPdfFontName(),
            pdfFont.getPdfEncoding(),
            pdfFont.isPdfEmbedded(),
            true,
            bytes,
            null
            );
      }
      catch(DocumentException e)
      {
        throw new JRRuntimeException(e);
      }
      catch(IOException e)
      {
        throw new JRRuntimeException(e);
      }

      font =
        new Font(
          baseFont,
          jrFont.getFontSize() * fontSizeScale,
          pdfFontStyle,
          forecolor
          );
    }

 
View Full Code Here

Examples of net.sf.jasperreports.engine.JRFont

    {
      xmlWriter.startElement(JRXmlConstants.ELEMENT_font);

      if(font.getReportFont() != null)
      {
        JRFont baseFont =
          (JRFont)fontsMap.get(
            font.getReportFont().getName()
            );
        if(baseFont != null)
        {
View Full Code Here

Examples of net.sf.jasperreports.engine.JRFont

    boolean isShowLabels = bar3DPlot.getShowLabels() == null ? false : bar3DPlot.getShowLabels().booleanValue();
    barRenderer3D.setBaseItemLabelsVisible( isShowLabels );
    if(isShowLabels)
    {
      JRItemLabel itemLabel = bar3DPlot.getItemLabel();
      JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : new JRBaseFont(getChart(), null);
      barRenderer3D.setBaseItemLabelFont(JRFontUtil.getAwtFont(font, getLocale()));
     
      if(itemLabel != null)
      {
        if(itemLabel.getColor() != null)
View Full Code Here

Examples of net.sf.jasperreports.engine.JRFont

    boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels().booleanValue();
    categoryRenderer.setBaseItemLabelsVisible( isShowLabels );
    if(isShowLabels)
    {
      JRItemLabel itemLabel = barPlot.getItemLabel();
      JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : new JRBaseFont(getChart(), null);
      categoryRenderer.setBaseItemLabelFont(JRFontUtil.getAwtFont(font, getLocale()));
      if(itemLabel != null)
      {
        if(itemLabel.getColor() != null)
        {
View Full Code Here

Examples of net.sf.jasperreports.engine.JRFont

    String label = getChart().hasProperties() ?
        getChart().getPropertiesMap().getProperty(PROPERTY_DIAL_LABEL) : null;
   
    if(label != null)
    {
      JRFont displayFont = jrPlot.getValueDisplay().getFont();
     
      String[] textLines = label.split("\\n");
      for(int i = 0; i < textLines.length; i++)
      {
        DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]);
View Full Code Here

Examples of net.sf.jasperreports.engine.JRFont

    String ownFontName = font.getOwnFontName();
    if (ownFontName != null)
    {
      return ownFontName;
    }
    JRFont baseFont = getBaseFont(font);
    if (baseFont != null)
    {
      String fontName = baseFont.getFontName();
      if (fontName != null)
      {
        return fontName;
      }
    }
View Full Code Here

Examples of net.sf.jasperreports.engine.JRFont

    Boolean ownBold = font.isOwnBold();
    if (ownBold != null)
    {
      return ownBold.booleanValue();
    }
    JRFont baseFont = getBaseFont(font);
    if (baseFont != null)
    {
      return baseFont.isBold();
    }
    JRStyle baseStyle = getBaseStyle(font);
    if (baseStyle != null)
    {
      Boolean bold = baseStyle.isBold();
View Full Code Here

Examples of net.sf.jasperreports.engine.JRFont

    Boolean ownItalic = font.isOwnItalic();
    if (ownItalic != null)
    {
      return ownItalic.booleanValue();
    }
    JRFont baseFont = getBaseFont(font);
    if (baseFont != null)
    {
      return baseFont.isItalic();
    }
    JRStyle baseStyle = getBaseStyle(font);
    if (baseStyle != null)
    {
      Boolean italic = baseStyle.isItalic();
View Full Code Here

Examples of net.sf.jasperreports.engine.JRFont

    Boolean ownUnderline = font.isOwnUnderline();
    if (ownUnderline != null)
    {
      return ownUnderline.booleanValue();
    }
    JRFont baseFont = getBaseFont(font);
    if (baseFont != null)
    {
      return baseFont.isUnderline();
    }
    JRStyle baseStyle = getBaseStyle(font);
    if (baseStyle != null)
    {
      Boolean underline = baseStyle.isUnderline();
View Full Code Here

Examples of net.sf.jasperreports.engine.JRFont

    Boolean ownStrikeThrough = font.isOwnStrikeThrough();
    if (ownStrikeThrough != null)
    {
      return ownStrikeThrough.booleanValue();
    }
    JRFont baseFont = getBaseFont(font);
    if (baseFont != null)
    {
      return baseFont.isStrikeThrough();
    }
    JRStyle baseStyle = getBaseStyle(font);
    if (baseStyle != null)
    {
      Boolean strikeThrough = baseStyle.isStrikeThrough();
View Full Code Here
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.