Package com.lowagie.text

Examples of com.lowagie.text.Font


    }
   
    private Phrase composePhrase(String text, BaseFont ufont, Color color, float fontSize) {
        Phrase phrase = null;
        if (extensionFont == null && (substitutionFonts == null || substitutionFonts.isEmpty()))
            phrase = new Phrase(new Chunk(text, new Font(ufont, fontSize, 0, color)));
        else {
            FontSelector fs = new FontSelector();
            fs.addFont(new Font(ufont, fontSize, 0, color));
            if (extensionFont != null)
                fs.addFont(new Font(extensionFont, fontSize, 0, color));
            if (substitutionFonts != null) {
                for (int k = 0; k < substitutionFonts.size(); ++k) {
                    fs.addFont(new Font((BaseFont)substitutionFonts.get(k), fontSize, 0, color));
                }
            }
            phrase = fs.process(text);
        }
        return phrase;
View Full Code Here


      if (pageEmpty) return;
      if (currentHeight + line.height() + leading > indentTop() - indentBottom()) return;
        leading = extraspace;
        carriageReturn();
        if (f.isUnderlined() || f.isStrikethru()) {
            f = new Font(f);
            int style = f.getStyle();
            style &= ~Font.UNDERLINE;
            style &= ~Font.STRIKETHRU;
            f.setStyle(Font.UNDEFINED);
            f.setStyle(style);
View Full Code Here

                    float x = (rect.getWidth() - w) / 2;
                    float y = (rect.getHeight() - h) / 2;
                    t.addImage(image, w, 0, 0, h, x, y);
                }
            }
            Font font;
            if (layer2Font == null)
                font = new Font();
            else
                font = new Font(layer2Font);
            float size = font.getSize();

            Rectangle dataRect = null;
            Rectangle signatureRect = null;

            if (render == SignatureRenderNameAndDescription ||
                (render == SignatureRenderGraphicAndDescription && this.signatureGraphic != null)) {
                // origin is the bottom-left
                signatureRect = new Rectangle(
                    MARGIN,
                    MARGIN,
                    rect.getWidth() / 2 - MARGIN,
                    rect.getHeight() - MARGIN);
                dataRect = new Rectangle(
                    rect.getWidth() / 2 +  MARGIN / 2,
                    MARGIN,
                    rect.getWidth() - MARGIN / 2,
                    rect.getHeight() - MARGIN);

                if (rect.getHeight() > rect.getWidth()) {
                    signatureRect = new Rectangle(
                        MARGIN,
                        rect.getHeight() / 2,
                        rect.getWidth() - MARGIN,
                        rect.getHeight());
                    dataRect = new Rectangle(
                        MARGIN,
                        MARGIN,
                        rect.getWidth() - MARGIN,
                        rect.getHeight() / 2 - MARGIN);
                }
            }
            else {
                dataRect = new Rectangle(
                    MARGIN,
                    MARGIN,
                    rect.getWidth() - MARGIN,
                    rect.getHeight() * (1 - TOP_SECTION) - MARGIN);
            }

            if (render == SignatureRenderNameAndDescription) {
                String signedBy = PdfPKCS7.getSubjectFields((X509Certificate)certChain[0]).getField("CN");
                Rectangle sr2 = new Rectangle(signatureRect.getWidth() - MARGIN, signatureRect.getHeight() - MARGIN );
                float signedSize = fitText(font, signedBy, sr2, -1, runDirection);

                ColumnText ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                ct2.setSimpleColumn(new Phrase(signedBy, font), signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), signedSize, Element.ALIGN_LEFT);

                ct2.go();
            }
            else if (render == SignatureRenderGraphicAndDescription) {
                ColumnText ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT);

                Image im = Image.getInstance(signatureGraphic);
                im.scaleToFit(signatureRect.getWidth(), signatureRect.getHeight());

                Paragraph p = new Paragraph();
                // must calculate the point to draw from to make image appear in middle of column
                float x = 0;
                // experimentation found this magic number to counteract Adobe's signature graphic, which
                // offsets the y co-ordinate by 15 units
                float y = -im.getScaledHeight() + 15;

                x = x + (signatureRect.getWidth() - im.getScaledWidth()) / 2;
                y = y - (signatureRect.getHeight() - im.getScaledHeight()) / 2;
                p.add(new Chunk(im, x + (signatureRect.getWidth() - im.getScaledWidth()) / 2, y, false));
                ct2.addElement(p);
                ct2.go();
            }
           
            if (size <= 0) {
                Rectangle sr = new Rectangle(dataRect.getWidth(), dataRect.getHeight());
                size = fitText(font, text, sr, 12, runDirection);
            }
            ColumnText ct = new ColumnText(t);
            ct.setRunDirection(runDirection);
            ct.setSimpleColumn(new Phrase(text, font), dataRect.getLeft(), dataRect.getBottom(), dataRect.getRight(), dataRect.getTop(), size, Element.ALIGN_LEFT);
            ct.go();
        }
        if (app[3] == null && !acro6Layers) {
            PdfTemplate t = app[3] = new PdfTemplate(writer);
            t.setBoundingBox(new Rectangle(100, 100));
            writer.addDirectTemplateSimple(t, new PdfName("n3"));
            t.setLiteral("% DSBlank\n");
        }
        if (app[4] == null && !acro6Layers) {
            PdfTemplate t = app[4] = new PdfTemplate(writer);
            t.setBoundingBox(new Rectangle(0, rect.getHeight() * (1 - TOP_SECTION), rect.getRight(), rect.getTop()));
            writer.addDirectTemplateSimple(t, new PdfName("n4"));
            Font font;
            if (layer2Font == null)
                font = new Font();
            else
                font = new Font(layer2Font);
            float size = font.getSize();
            String text = "Signature Not Verified";
            if (layer4Text != null)
                text = layer4Text;
            Rectangle sr = new Rectangle(rect.getWidth() - 2 * MARGIN, rect.getHeight() * TOP_SECTION - 2 * MARGIN);
            size = fitText(font, text, sr, 15, runDirection);
View Full Code Here

  /** Creates a new instance of FactoryProperties */
  public FactoryProperties() {
  }

  public Chunk createChunk(String text, ChainedProperties props) {
    Font font = getFont(props);
    float size = font.getSize();
    size /= 2;
    Chunk ck = new Chunk(text, font);
    if (props.hasProperty("sub"))
      ck.setTextRise(-size);
    else if (props.hasProperty("sup"))
View Full Code Here

      }

      final BaseFontFontMetrics fontMetrics = metaData.getBaseFontFontMetrics
          (fontName, fontSize, bold, italic, "utf-8", false, false);
      final BaseFont baseFont = fontMetrics.getBaseFont();
      final Font font = new Font(baseFont, (float) fontSize, style, textColor);
      final Chunk c = new Chunk(text, font);
      if (backgroundColor != null)
      {
        c.setBackground(backgroundColor);
      }
View Full Code Here

      chunk = new Chunk(" ");
    }
    else
    {
      // no underline or strikethrough
      Font pdfFont = getFont(pdfFontAttrs, getLocale(), false);
      chunk = new Chunk(" ", pdfFont);
    }
   
    chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1));
View Full Code Here

   *
   */
  protected Chunk getChunk(Map attributes, String text, Locale locale)
  {
    // underline and strikethrough are set on the chunk below
    Font font = getFont(attributes, locale, false);

    Chunk chunk = new Chunk(text, font);
   
    if (hasUnderline(attributes))
    {
      // using the same values as sun.font.Fond2D
      chunk.setUnderline(null, 0, 1f / 18, 0, -1f / 12, 0);
    }
   
    if (hasStrikethrough(attributes))
    {
      // using the same thickness as sun.font.Fond2D.
      // the position is calculated in Fond2D based on the ascent, defaulting
      // to iText default position which depends on the font size
      chunk.setUnderline(null, 0, 1f / 18, 0, 1f / 3, 0);
    }

    Color backcolor = (Color)attributes.get(TextAttribute.BACKGROUND);
    if (backcolor != null)
    {
      chunk.setBackground(backcolor);
    }

    Object script = attributes.get(TextAttribute.SUPERSCRIPT);
    if (script != null)
    {
      if (TextAttribute.SUPERSCRIPT_SUPER.equals(script))
      {
        chunk.setTextRise(font.getCalculatedLeading(1f)/2);
      }
      else if (TextAttribute.SUPERSCRIPT_SUB.equals(script))
      {
        chunk.setTextRise(-font.getCalculatedLeading(1f)/2);
      }
    }

    if (splitCharacter != null)
    {
View Full Code Here

        || 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

 
  private PdfPTable exportPDFTable(UIData table, boolean pageOnly, int[] excludeColumns, String encoding) {
    List<UIColumn> columns = getColumnsToExport(table, excludeColumns);
      int numberOfColumns = columns.size();
      PdfPTable pdfTable = new PdfPTable(numberOfColumns);
      Font font = FontFactory.getFont(FontFactory.TIMES, encoding);
      Font headerFont = FontFactory.getFont(FontFactory.TIMES, encoding, Font.DEFAULTSIZE, Font.BOLD);
     
      int first = pageOnly ? table.getFirst() : 0;
      int size = pageOnly ? (first + table.getRows()) : table.getRowCount();
     
      addColumnHeaders(pdfTable, columns, headerFont);
View Full Code Here

  return header; 
  }
*/
  static PdfPCell borderlessCell(String s){
      PdfPCell cell = new PdfPCell();
      Font f = new Font(Font.COURIER);
      cell.setBorder(0);
      cell.setHorizontalAlignment(Element.ALIGN_LEFT);
      cell.addElement(new Paragraph(s,f));
      return cell;
  }
View Full Code Here

TOP

Related Classes of com.lowagie.text.Font

Copyright © 2018 www.massapicom. 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.