当前位置: 首页>>代码示例>>Java>>正文


Java TrueTypeFont类代码示例

本文整理汇总了Java中org.apache.fontbox.ttf.TrueTypeFont的典型用法代码示例。如果您正苦于以下问题:Java TrueTypeFont类的具体用法?Java TrueTypeFont怎么用?Java TrueTypeFont使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TrueTypeFont类属于org.apache.fontbox.ttf包,在下文中一共展示了TrueTypeFont类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPDFBox3826

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * PDFBOX-3826: Test ability to reuse a TrueTypeFont created from a file or a stream for several PDFs to avoid
 * parsing it over and over again. Also check that full or partial embedding is done, and do render and text
 * extraction.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void testPDFBox3826() throws IOException, URISyntaxException
{
    URL url = PDFontTest.class.getClassLoader()
            .getResource("org/sejda/sambox/ttf/LiberationSans-Regular.ttf");
    File fontFile = new File(url.toURI());

    TrueTypeFont ttf1 = new TTFParser().parse(fontFile);
    testPDFBox3826checkFonts(testPDFBox3826createDoc(ttf1), fontFile);
    ttf1.close();

    TrueTypeFont ttf2 = new TTFParser().parse(new FileInputStream(fontFile));
    testPDFBox3826checkFonts(testPDFBox3826createDoc(ttf2), fontFile);
    ttf2.close();
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:24,代码来源:PDFontTest.java

示例2: PDTrueTypeFont

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * Creates a new TrueType font for embedding.
 */
private PDTrueTypeFont(TrueTypeFont ttf, Encoding encoding, boolean closeTTF) throws IOException
{
    PDTrueTypeFontEmbedder embedder = new PDTrueTypeFontEmbedder(dict, ttf, encoding);
    this.encoding = encoding;
    this.ttf = ttf;
    setFontDescriptor(embedder.getFontDescriptor());
    isEmbedded = true;
    isDamaged = false;
    glyphList = GlyphList.getAdobeGlyphList();
    if (closeTTF)
    {
        // the TTF is fully loaded and it is save to close the underlying data source
        ttf.close();
    }
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:19,代码来源:PDTrueTypeFont.java

示例3: PDType0Font

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * Private. Creates a new TrueType font for embedding.
 */
private PDType0Font(PDDocument document, TrueTypeFont ttf, boolean embedSubset,
        boolean closeOnSubset)
        throws IOException
{
    embedder = new PDCIDFontType2Embedder(document, dict, ttf, embedSubset, this);
    descendantFont = embedder.getCIDFont();
    readEncoding();
    fetchCMapUCS2();
    if (closeOnSubset)
    {
        if (embedSubset)
        {
            this.ttf = ttf;
        }
        else
        {
            // the TTF is fully loaded and it is safe to close the underlying data source
            ttf.close();
        }
    }
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:25,代码来源:PDType0Font.java

示例4: loadOriginal

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * Tries to load the original full font from the system
 */
public PDFont loadOriginal(PDDocument document) {
    String lookupName = fontName.replace("-", " ");

    LOG.debug("Searching the system for a font matching name '{}'", lookupName);

    FontMapping<TrueTypeFont> fontMapping = FontMappers.instance().getTrueTypeFont(lookupName, null);
    if (fontMapping != null && fontMapping.getFont() != null && !fontMapping.isFallback()) {
        TrueTypeFont mappedFont = fontMapping.getFont();

        try {
            LOG.debug("Original font available on the system: {}", fontName);
            return PDType0Font.load(document, mappedFont.getOriginalData());
        } catch (IOException ioe) {
            LOG.warn("Failed to load font from system", ioe);
            try {
                mappedFont.close();
            } catch (IOException e) {
                LOG.warn("Failed closing font", e);
            }
        }
    }

    return null;
}
 
开发者ID:torakiki,项目名称:sejda,代码行数:28,代码来源:FontUtils.java

示例5: findFontBoxFont

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * Finds a font with the given PostScript name, or a suitable substitute, or null.
 *
 * @param postScriptName PostScript font name
 */
private FontBoxFont findFontBoxFont(String postScriptName)
{
    Type1Font t1 = (Type1Font) findFont(FontFormat.PFB, postScriptName);
    if (t1 != null)
    {
        return t1;
    }

    TrueTypeFont ttf = (TrueTypeFont) findFont(FontFormat.TTF, postScriptName);
    if (ttf != null)
    {
        return ttf;
    }

    OpenTypeFont otf = (OpenTypeFont) findFont(FontFormat.OTF, postScriptName);
    if (otf != null)
    {
        return otf;
    }

    return null;
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:28,代码来源:FontMapperImpl.java

示例6: isEmbeddingPermitted

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * @return true if the fsType in the OS/2 table permits embedding.
 */
public static boolean isEmbeddingPermitted(TrueTypeFont ttf) throws IOException
{
    if (ttf.getOS2Windows() != null)
    {
        int fsType = ttf.getOS2Windows().getFsType();
        int exclusive = fsType & 0x8; // bits 0-3 are a set of exclusive bits

        if ((exclusive
                & OS2WindowsMetricsTable.FSTYPE_RESTRICTED) == OS2WindowsMetricsTable.FSTYPE_RESTRICTED)
        {
            // restricted License embedding
            return false;
        }
        else if ((exclusive
                & OS2WindowsMetricsTable.FSTYPE_BITMAP_ONLY) == OS2WindowsMetricsTable.FSTYPE_BITMAP_ONLY)
        {
            // bitmap embedding only
            return false;
        }
    }
    return true;
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:26,代码来源:FontUtils.java

示例7: TrueTypeEmbedder

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * Creates a new TrueType font for embedding.
 */
TrueTypeEmbedder(COSDictionary dict, TrueTypeFont ttf, boolean embedSubset) throws IOException
{
    this.embedSubset = embedSubset;
    this.ttf = ttf;
    fontDescriptor = createFontDescriptor(ttf);

    if (!isEmbeddingPermitted(ttf))
    {
        throw new IOException("This font does not permit embedding");
    }

    if (!embedSubset)
    {
        // full embedding
        PDStream stream = new PDStream(ttf.getOriginalData(), COSName.FLATE_DECODE);
        stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize());
        fontDescriptor.setFontFile2(stream);
    }

    dict.setName(COSName.BASE_FONT, ttf.getName());

    // choose a Unicode "cmap"
    cmap = ttf.getUnicodeCmap();
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:28,代码来源:TrueTypeEmbedder.java

示例8: PDTrueTypeFontEmbedder

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * Creates a new TrueType font embedder for the given TTF as a PDTrueTypeFont.
 *
 * @param dict Font dictionary
 * @param ttf TTF font
 * @param encoding The PostScript encoding vector to be used for embedding.
 * @throws IOException if the TTF could not be read
 */
PDTrueTypeFontEmbedder(COSDictionary dict, TrueTypeFont ttf,
                       Encoding encoding) throws IOException
{
    super(dict, ttf, false);
    dict.setItem(COSName.SUBTYPE, COSName.TRUE_TYPE);
    
    GlyphList glyphList = GlyphList.getAdobeGlyphList();
    this.fontEncoding = encoding;
    dict.setItem(COSName.ENCODING, encoding.getCOSObject());
    fontDescriptor.setSymbolic(false);
    fontDescriptor.setNonSymbolic(true);
    
    // add the font descriptor
    dict.setItem(COSName.FONT_DESC, fontDescriptor);

    // set the glyph widths
    setWidths(dict, glyphList);
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:27,代码来源:PDTrueTypeFontEmbedder.java

示例9: main

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
public static void main (final String [] args) throws IOException
{
  final TrueTypeFont aTTF = new TTFParser ().parse (EFontResourceOpenSans.OPEN_SANS_NORMAL.getFontResource ()
                                                                                          .getInputStream ());

  for (int i = 0; i < 2; ++i)
  {
    System.out.println ("Create PDF " + i);
    try (final PDDocument doc = new PDDocument ())
    {
      final PDPage page = new PDPage (PDRectangle.A4);
      doc.addPage (page);

      try (final PDPageContentStream contents = new PDPageContentStream (doc, page))
      {
        contents.beginText ();
        contents.setFont (PDType0Font.load (doc, aTTF, true), 12);
        contents.showText ("Test");
        contents.endText ();
      }
      doc.save (new File ("pdf/test-3337-" + i + ".pdf"));
    }
  }
}
 
开发者ID:phax,项目名称:ph-pdf-layout,代码行数:25,代码来源:MainIssue3337.java

示例10: loadSimilar

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * Tries to load a similar full font from the system
 */
public PDFont loadSimilar(PDDocument document) {
    String lookupName = fontName.replace("-", " ");

    // Eg: Arial-BoldMT
    PDFontDescriptor descriptor = new PDFontDescriptor(new COSDictionary());
    descriptor.setFontName(fontName.split("-")[0]);
    descriptor.setForceBold(FontUtils.isBold(subsetFont));
    descriptor.setItalic(FontUtils.isItalic(subsetFont));

    LOG.debug(
            "Searching the system for a font matching name '{}' and description [name:{}, bold:{}, italic:{}]",
            lookupName, descriptor.getFontName(), descriptor.isForceBold(), descriptor.isItalic());

    FontMapping<TrueTypeFont> fontMapping = FontMappers.instance().getTrueTypeFont(lookupName, descriptor);
    if (fontMapping != null && fontMapping.getFont() != null) {
        TrueTypeFont mappedFont = fontMapping.getFont();

        try {
            if (fontMapping.isFallback()) {
                LOG.debug("Fallback font available on the system: {} (for {})", mappedFont.getName(), fontName);
            } else {
                LOG.debug("Original font available on the system: {}", fontName);
            }

            return PDType0Font.load(document, mappedFont.getOriginalData());
        } catch (IOException ioe) {
            LOG.warn("Failed to load font from system", ioe);
            try {
                mappedFont.close();
            } catch (Exception e) {
                LOG.warn("Failed closing font", e);
            }
        }
    }

    return null;
}
 
开发者ID:torakiki,项目名称:sejda,代码行数:41,代码来源:FontUtils.java

示例11: TTFGlyph2D

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
private TTFGlyph2D(TrueTypeFont ttf, PDFont font, boolean isCIDFont) throws IOException
{
    this.font = font;
    this.ttf = ttf;
    this.isCIDFont = isCIDFont;
    // get units per em, which is used as scaling factor
    HeaderTable header = this.ttf.getHeader();
    if (header != null && header.getUnitsPerEm() != 1000)
    {
        // in most case the scaling factor is set to 1.0f
        // due to the fact that units per em is set to 1000
        scale = 1000f / header.getUnitsPerEm();
        hasScaling = true;
    }
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:16,代码来源:TTFGlyph2D.java

示例12: isSubsettingPermitted

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * @return true if the fsType in the OS/2 table permits subsetting.
 */
public static boolean isSubsettingPermitted(TrueTypeFont ttf) throws IOException
{
    if (ttf.getOS2Windows() != null)
    {
        int fsType = ttf.getOS2Windows().getFsType();
        if ((fsType
                & OS2WindowsMetricsTable.FSTYPE_NO_SUBSETTING) == OS2WindowsMetricsTable.FSTYPE_NO_SUBSETTING)
        {
            return false;
        }
    }
    return true;
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:17,代码来源:FontUtils.java

示例13: PDCIDFontType2Embedder

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
/**
 * Creates a new TrueType font embedder for the given TTF as a PDCIDFontType2.
 *
 * @param document parent document
 * @param dict font dictionary
 * @param ttf True Type Font
 * @param parent parent Type 0 font
 * @throws IOException if the TTF could not be read
 */
PDCIDFontType2Embedder(PDDocument document, COSDictionary dict, TrueTypeFont ttf,
        boolean embedSubset, PDType0Font parent) throws IOException
{
    super(dict, ttf, embedSubset);
    this.document = document;
    this.dict = dict;
    this.parent = parent;

    // parent Type 0 font
    dict.setItem(COSName.SUBTYPE, COSName.TYPE0);
    dict.setName(COSName.BASE_FONT, fontDescriptor.getFontName());
    dict.setItem(COSName.ENCODING, COSName.IDENTITY_H); // CID = GID

    // descendant CIDFont
    cidFont = createCIDFont();
    COSArray descendantFonts = new COSArray();
    descendantFonts.add(cidFont);
    dict.setItem(COSName.DESCENDANT_FONTS, descendantFonts);

    if (!embedSubset)
    {
        // build GID -> Unicode map
        buildToUnicodeCMap(null);
    }

    // ToUnicode CMap
    buildToUnicodeCMap(null);
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:38,代码来源:PDCIDFontType2Embedder.java

示例14: getTrueTypeFont

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
private TrueTypeFont getTrueTypeFont(String postScriptName, File file)
{
    try
    {
        return readTrueTypeFont(postScriptName, file);
    }
    catch (NullPointerException | IOException e) // TTF parser is buggy
    {
        LOG.error("Could not load font file: " + file, e);
    }

    return null;
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:14,代码来源:FileSystemFontProvider.java

示例15: readTrueTypeFont

import org.apache.fontbox.ttf.TrueTypeFont; //导入依赖的package包/类
private TrueTypeFont readTrueTypeFont(String postScriptName, File file) throws IOException
{
    if (file.getName().toLowerCase().endsWith(".ttc"))
    {
        TrueTypeCollection ttc = new TrueTypeCollection(file);
        TrueTypeFont ttf = ttc.getFontByName(postScriptName);
        if (ttf == null)
        {
            ttc.close();
            throw new IOException("Font " + postScriptName + " not found in " + file);
        }
        return ttf;
    }
    return new TTFParser(false, true).parse(file);
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:16,代码来源:FileSystemFontProvider.java


注:本文中的org.apache.fontbox.ttf.TrueTypeFont类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。