Package com.lowagie.text

Examples of com.lowagie.text.Font


    for (Object o : children) {
      log.debug("object: " + o.getClass().getName());

      if (o instanceof org.docx4j.wml.R) {

        Font font = null;         
        org.docx4j.wml.R run = (org.docx4j.wml.R) o;
        if (run.getRPr() != null) {

          // TODO - follow inheritance
         
          Font iTextFont = null;
         
          RPr rPr = run.getRPr();
          RFonts rFonts = rPr.getRFonts();
          String documentFont = Mapper.FONT_FALLBACK;
          if (rFonts !=null ) {
           
            documentFont = rFonts.getAscii();
           
            if (documentFont==null) {
              // TODO - actually what Word does in this case
              // is inherit the default document font eg Calibri
              // (which is what it shows in its user interface)
              documentFont = rFonts.getCs();
            }
           
            if (documentFont==null) {
              log.error("Font was null in: " + XmlUtils.marshaltoString(rPr, true, true));
              documentFont=Mapper.FONT_FALLBACK;
            }
           
            log.info("Font: " + documentFont);
           
          }
         
          int fontSize = DEFAULT_FONT_SIZE;
          if (run.getRPr().getSz() != null) {
            org.docx4j.wml.HpsMeasure hps = run.getRPr().getSz();
            fontSize = hps.getVal().intValue() / 2;
          }

          if (run.getRPr().getB() != null
              && run.getRPr().getB().isVal()
              && run.getRPr().getI() != null
              && run.getRPr().getI().isVal()) {
           
            if ( baseFonts.get(documentFont + BOLD_ITALIC)!=null) {           
              log.debug(documentFont + BOLD_ITALIC + " not found; falling back to " + documentFont);
              font = new Font( baseFonts.get(documentFont + BOLD_ITALIC), fontSize  );
            } else {
              font = new Font( baseFonts.get(documentFont), fontSize  );             
            }
           
          } else if (run.getRPr().getI() != null
              && run.getRPr().getI().isVal()) {
           
            if ( baseFonts.get(documentFont + ITALIC)!=null) {           
              log.debug(documentFont + ITALIC + " not found; falling back to " + documentFont);
              font = new Font( baseFonts.get(documentFont + ITALIC), fontSize  );
            } else {
              font = new Font( baseFonts.get(documentFont), fontSize  );             
            }
          } else if (run.getRPr().getB() != null
              && run.getRPr().getB().isVal()) {
           
            if ( baseFonts.get(documentFont + BOLD)!=null) {           
              log.debug(documentFont + BOLD + " not found; falling back to " + documentFont);
              font = new Font( baseFonts.get(documentFont + BOLD), fontSize  );
            } else {
              font = new Font( baseFonts.get(documentFont), fontSize  );             
            }
          } else {
            font = new Font( baseFonts.get(documentFont), fontSize  );           
          }
         
        }

        List<Object> runContent = run.getRunContent();
View Full Code Here


      PdfPTable data = new PdfPTable(temp);
      data.setWidthPercentage(90);
      PdfPTable table = new PdfPTable(dim);
      table.setWidthPercentage(90);

      Font myFont = FontFactory.getFont(
          FontFactory.HELVETICA, 8, Color.WHITE);
      if (section.get(i).getDes() != null) {
        if (section.get(i).getParent() != null && section.get(i).getParent().getDes() != null) {
          section.get(i).setDes(section.get(i).getParent().getDes().trim() + "." + section.get(i).getDes().trim());
        }
View Full Code Here

     * @param chunk The chunk whose content is to be rendered bold.
     * @param color The font color desired.
     */
    private void setBoldStyle(Chunk chunk, Color color)
    {
        Font font = chunk.font();
        chunk.setFont(FontFactory.getFont(font.getFamilyname(), font.size(), Font.BOLD, color));
    }
View Full Code Here

        return ret;
    }
   

    private void addSongChords(String[] text) throws DocumentException{
        Font chordfont  = new Font(Font.COURIER, 12, Font.BOLD, Color.BLUE.darker());
        Font lyricfont  = new Font(Font.COURIER, 12, Font.NORMAL);
        Paragraph p;

        for (String line : text){

            Matcher matcher = Song.CHORDS_REGEX_PATTERN.matcher(line);
View Full Code Here

* @return  true if the font differs
*/
   
    public boolean isOtherFont(Font font) {
        try {
            Font cFont = (Font) currentfont.peek();
            if (cFont.compareTo(font) == 0) return false;
            return true;
        }
        catch(EmptyStackException ese) {
            if (standardfont.compareTo(font) == 0) return false;
            return true;
View Full Code Here

            }
            catch(Exception exception) {
                return new Chunk(e, font);
            }
        }
        Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
        return new Chunk(String.valueOf(s), symbol);
    }
View Full Code Here

   */
  public void execute() {
    try {
            String line = null;
            Document document;
            Font f;
            Rectangle pagesize = (Rectangle)getValue("pagesize");
            if ("LANDSCAPE".equals(getValue("orientation"))) {
                f = FontFactory.getFont(FontFactory.COURIER, 10);
                document = new Document(pagesize.rotate(), 36, 9, 36, 36);
            }
View Full Code Here

      this.buffer = new StringBuffer(255);
      HashMap charProperties = this.rtfParser.getState().properties.getProperties(RtfProperty.CHARACTER);
      String defFont = (String)charProperties.get(RtfProperty.CHARACTER_FONT);
      if(defFont == null) defFont = "0";
      RtfDestinationFontTable fontTable = (RtfDestinationFontTable)this.rtfParser.getDestination("fonttbl");
      Font currFont = fontTable.getFont(defFont);
      int fs = Font.NORMAL;
      if(charProperties.containsKey(RtfProperty.CHARACTER_BOLD)) fs |= Font.BOLD;
      if(charProperties.containsKey(RtfProperty.CHARACTER_ITALIC)) fs |= Font.ITALIC;
      if(charProperties.containsKey(RtfProperty.CHARACTER_UNDERLINE)) fs |= Font.UNDERLINE;
      Font useFont = FontFactory.getFont(currFont.getFamilyname(), 12, fs, new Color(0,0,0));
     
     
      chunk.setFont(useFont);
      if(iTextParagraph == null) this.iTextParagraph = new Paragraph();
      this.iTextParagraph.add(chunk);
View Full Code Here

            TextElementArray current;
            try {
                current = (TextElementArray) stack.pop();
            } catch (EmptyStackException ese) {
              if (bf == null) {
                current = new Paragraph("", new Font());
              }
              else {
                current = new Paragraph("", new Font(this.bf));
              }
            }
            current.add(currentChunk);
            stack.push(current);
            currentChunk = null;
        }

        // chunks
        if (ElementTags.CHUNK.equals(name)) {
            currentChunk = ElementFactory.getChunk(attributes);
            if (bf != null) {
              currentChunk.setFont(new Font(this.bf));
            }
            return;
        }

        // symbols
        if (ElementTags.ENTITY.equals(name)) {
            Font f = new Font();
            if (currentChunk != null) {
                handleEndingTags(ElementTags.CHUNK);
                f = currentChunk.getFont();
            }
            currentChunk = EntitiesToSymbol.get(attributes.getProperty(ElementTags.ID),
                    f);
            return;
        }

        // phrases
        if (ElementTags.PHRASE.equals(name)) {
            stack.push(ElementFactory.getPhrase(attributes));
            return;
        }

        // anchors
        if (ElementTags.ANCHOR.equals(name)) {
            stack.push(ElementFactory.getAnchor(attributes));
            return;
        }

        // paragraphs and titles
        if (ElementTags.PARAGRAPH.equals(name) || ElementTags.TITLE.equals(name)) {
            stack.push(ElementFactory.getParagraph(attributes));
            return;
        }

        // lists
        if (ElementTags.LIST.equals(name)) {
            stack.push(ElementFactory.getList(attributes));
            return;
        }
       
        // listitems
        if (ElementTags.LISTITEM.equals(name)) {
            stack.push(ElementFactory.getListItem(attributes));
            return;
        }

        // cells
        if (ElementTags.CELL.equals(name)) {
            stack.push(ElementFactory.getCell(attributes));
            return;
        }

        // tables
        if (ElementTags.TABLE.equals(name)) {
            Table table = ElementFactory.getTable(attributes);
            float widths[] = table.getProportionalWidths();
            for (int i = 0; i < widths.length; i++) {
                if (widths[i] == 0) {
                    widths[i] = 100.0f / widths.length;
                }
            }
            try {
                table.setWidths(widths);
            } catch (BadElementException bee) {
                // this shouldn't happen
                throw new ExceptionConverter(bee);
            }
            stack.push(table);
            return;
        }

        // sections
        if (ElementTags.SECTION.equals(name)) {
            Element previous = (Element) stack.pop();
            Section section;
            try {
                section = ElementFactory.getSection((Section) previous, attributes);
            } catch (ClassCastException cce) {
                throw new ExceptionConverter(cce);
            }
            stack.push(previous);
            stack.push(section);
            return;
        }

        // chapters
        if (ElementTags.CHAPTER.equals(name)) {
            stack.push(ElementFactory.getChapter(attributes));
            return;
        }

        // images
        if (ElementTags.IMAGE.equals(name)) {
            try {
                Image img = ElementFactory.getImage(attributes);
                try {
                  addImage(img);
                    return;
                } catch (EmptyStackException ese) {
                    // if there is no element on the stack, the Image is added
                    // to the document
                    try {
                        document.add(img);
                    } catch (DocumentException de) {
                        throw new ExceptionConverter(de);
                    }
                    return;
                }
            } catch (Exception e) {
                throw new ExceptionConverter(e);
            }
        }

        // annotations
        if (ElementTags.ANNOTATION.equals(name)) {
            Annotation annotation = ElementFactory.getAnnotation(attributes);
            TextElementArray current;
            try {
                try {
                    current = (TextElementArray) stack.pop();
                    try {
                        current.add(annotation);
                    } catch (Exception e) {
                        document.add(annotation);
                    }
                    stack.push(current);
                } catch (EmptyStackException ese) {
                    document.add(annotation);
                }
                return;
            } catch (DocumentException de) {
                throw new ExceptionConverter(de);
            }
        }

        // newlines
        if (isNewline(name)) {
            TextElementArray current;
            try {
                current = (TextElementArray) stack.pop();
                current.add(Chunk.NEWLINE);
                stack.push(current);
            } catch (EmptyStackException ese) {
                if (currentChunk == null) {
                    try {
                        document.add(Chunk.NEWLINE);
                    } catch (DocumentException de) {
                        throw new ExceptionConverter(de);
                    }
                } else {
                    currentChunk.append("\n");
                }
            }
            return;
        }

        // newpage
        if (isNewpage(name)) {
            TextElementArray current;
            try {
                current = (TextElementArray) stack.pop();
                Chunk newPage = new Chunk("");
                newPage.setNewPage();
                if (bf != null) {
                  newPage.setFont(new Font(this.bf));
                }
                current.add(newPage);
                stack.push(current);
            } catch (EmptyStackException ese) {
                document.newPage();
View Full Code Here

        if (currentChunk == null) {
          if (bf == null) {
            currentChunk = new Chunk(buf.toString());
          }
          else {
            currentChunk = new Chunk(buf.toString(), new Font(this.bf));
          }
        } else {
            currentChunk.append(buf.toString());
        }
    }
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.