本文整理汇总了Java中org.apache.pdfbox.pdmodel.font.PDType0Font类的典型用法代码示例。如果您正苦于以下问题:Java PDType0Font类的具体用法?Java PDType0Font怎么用?Java PDType0Font使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PDType0Font类属于org.apache.pdfbox.pdmodel.font包,在下文中一共展示了PDType0Font类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: given_type0_withTTF_withNoNameTable_whenConverted_thenHasNamesSet
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
@Test
public void given_type0_withTTF_withNoNameTable_whenConverted_thenHasNamesSet() throws IOException {
PDFont rawType0Font = extractFont(doc, "UMAVUG+Garuda-Identity-H");
FVFont font = PdfFontExtractor.convertType0FontToOpenType((PDType0Font) rawType0Font);
font.normalize();
OpenTypeFont otfFont = ((OpenTypeFont) font);
Assert.assertEquals("UMAVUG+Garuda-Identity-H", otfFont.getNameTable().getName(RecordType.FULL_FONT_NAME));
Assert.assertEquals("Garuda", otfFont.getNameTable().getName(RecordType.FONT_FAMILY));
Assert.assertEquals("Normal", otfFont.getNameTable().getName(RecordType.FONT_SUB_FAMILY));
}
示例2: PagerController
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
public PagerController(float marginLeft, float marginRight, float marginTop, float marginBottom, Options options) throws IOException {
// set values defined by user
this.doc = new PDDocument();
this.marginLeft = marginLeft;
this.marginRight = marginRight;
this.marginTop = marginTop;
this.marginBottom = marginBottom;
this.options = options;
// initialize standard values.
// note that it should be possible to set a custom font at a later time.
this.font = PDType0Font.load(doc, Fonts.class.getResourceAsStream("CourierPrime.ttf"));
this.boldFont = PDType0Font.load(doc, Fonts.class.getResourceAsStream("CourierPrimeBold.ttf"));
this.italicFont = PDType0Font.load(doc, Fonts.class.getResourceAsStream("CourierPrimeItalic.ttf"));
this.boldItalicFont = PDType0Font.load(doc, Fonts.class.getResourceAsStream("CourierPrimeBoldItalic.ttf"));
this.pagers = new HashMap<>();
}
示例3: LoadedFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
public LoadedFont (@Nonnull final PDFont aFont, final int nFallbackCodePoint)
{
ValueEnforcer.notNull (aFont, "Font");
m_aFont = aFont;
m_nFallbackCodePoint = nFallbackCodePoint;
PDFontDescriptor aFD = aFont.getFontDescriptor ();
if (aFD == null)
{
if (aFont instanceof PDType0Font)
{
final PDCIDFont aDescendantFont = ((PDType0Font) aFont).getDescendantFont ();
if (aDescendantFont != null)
aFD = aDescendantFont.getFontDescriptor ();
}
}
if (aFD == null)
throw new IllegalArgumentException ("Failed to determine FontDescriptor from specified font " + aFont);
m_fBBHeight = aFD.getFontBoundingBox ().getHeight ();
m_fDescent = aFD.getDescent ();
m_bFontWillBeSubset = m_aFont.willBeSubset ();
}
示例4: registerFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
public static PdfFont registerFont(PDType0Font font) {
String fontBaseName = font.getName();
String fontStyle = "regular";
if (font.getDescendantFont() instanceof PDCIDFontType2) {
PDCIDFontType2 tmpFont = (PDCIDFontType2) font.getDescendantFont();
NamingTable ttfNamingTable = (NamingTable) tmpFont.getTrueTypeFont().getTableMap().get("name");
fontBaseName = ttfNamingTable.getFontFamily();
fontStyle = ttfNamingTable.getFontSubFamily().toLowerCase();
}
PdfFont f;
if (fonts.containsKey(fontBaseName)) {
f = fonts.get(fontBaseName);
f.addStyle(fontStyle, font);
} else {
f = new PdfFont(fontBaseName);
f.addStyle(fontStyle, font);
fonts.put(fontBaseName, f);
}
return f;
}
示例5: given_type0_withCFF_HelveticaNeueBug
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
@Test
public void given_type0_withCFF_HelveticaNeueBug() throws Exception {
PDDocument doc = PDDocument.load(TestUtils.readTestFile("pdf/HorariosMadrid_Segovia.pdf"));
PDFont rawType0Font = extractFont(doc, "TCQDAA+HelveticaNeue-Light-Identity-H");
OpenTypeFont font = (OpenTypeFont) PdfFontExtractor.convertType0FontToOpenType((PDType0Font) rawType0Font);
TestUtils.saveTempFile(font.getData(), "TCQDAA+HelveticaNeue-Light-Identity-H.ttf");
FileUtils.writeByteArrayToFile(new File("C:/projects/Pdf2Dom/fontTest/TCQDAA+HelveticaNeue-Light-Identity-H.ttf"),
font.getData());
List<TtfGlyph> glyphs = font.getGlyfTable().getNonEmptyGlyphs();
TtfGlyph glyph = glyphs.get(1);
List<TtfInstruction> instructions = glyph.getInstructions();
DebugGlyphDrawer.drawGlyph(glyph);
}
示例6: getAscent
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
private static float getAscent(PDFont font, float fontSize) {
try {
if (font instanceof PDSimpleFont) {
PDSimpleFont simpleFont = (PDSimpleFont) font;
return (simpleFont.getFontDescriptor().getAscent()
/ 1000) * fontSize;
} else if (font instanceof PDType0Font) {
PDType0Font cidFont = (PDType0Font) font;
return (cidFont.getFontDescriptor().getAscent()
/ 1000) * fontSize;
}
} catch (Exception e) {
// fall through
}
return 0.0f;
}
示例7: getDescent
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
private static float getDescent(PDFont font, float fontSize) {
try {
if (font instanceof PDSimpleFont) {
PDSimpleFont simpleFont = (PDSimpleFont) font;
return (-Math.abs(simpleFont.getFontDescriptor().getDescent())
/ 1000) * fontSize;
} else if (font instanceof PDType0Font) {
PDType0Font cidFont = (PDType0Font) font;
return (-Math.abs(cidFont.getFontDescriptor().getDescent())
/ 1000) * fontSize;
}
} catch (Exception e) {
// fall through
}
return 0.0f;
}
示例8: getData
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
public byte[] getData() throws IOException
{
if (cachedFontData != null)
return cachedFontData;
if (descriptor.getFontFile2() != null && baseFont instanceof PDType0Font)
cachedFontData = loadType0TtfDescendantFont();
else if (descriptor.getFontFile2() != null)
cachedFontData = loadTrueTypeFont(descriptor.getFontFile2());
else if (descriptor.getFontFile() != null)
cachedFontData = loadType1Font(descriptor.getFontFile());
else if (descriptor.getFontFile3() != null)
// FontFile3 docs say any font type besides TTF/OTF or Type 1..
cachedFontData = loadOtherTypeFont(descriptor.getFontFile3());
return cachedFontData;
}
示例9: loadType0TtfDescendantFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
private byte[] loadType0TtfDescendantFont() throws IOException
{
mimeType = "application/x-font-truetype";
fileEnding = "ttf";
try
{
FVFont font = PdfFontExtractor.convertType0FontToOpenType((PDType0Font) baseFont);
byte[] fontData = tryNormalizeFVFont(font);
if (fontData.length != 0)
return fontData;
} catch (Exception ex)
{
log.warn("Error loading type 0 with ttf descendant font '{}' Message: {} {}",
fontName, ex.getMessage(), ex.getClass());
}
return descriptor.getFontFile2().toByteArray();
}
示例10: loadPDFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
/**
* Load the {@link PDFont} associated to this preload font. This class uses no
* caching!
*
* @param aDoc
* The {@link PDDocument} to which the font should be attached to. May
* not be <code>null</code>.
* @return The loaded font.
* @throws IOException
* In case loading the external file fails
*/
@Nonnull
public PDFont loadPDFont (@Nonnull final PDDocument aDoc) throws IOException
{
if (m_aFont != null)
{
// Pre-defined font
return m_aFont;
}
PDFont ret = null;
if (m_aTTF != null)
ret = PDType0Font.load (aDoc, m_aTTF, m_bEmbed);
else
if (m_aOTF != null)
ret = PDType0Font.load (aDoc, m_aOTF, m_bEmbed);
if (ret == null)
throw new IllegalArgumentException ("Cannot load font resources of type " + m_aFontRes.getFontType ());
return ret;
}
示例11: main
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
public static void main (final String [] args) throws IOException
{
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,
EFontResourceOpenSans.OPEN_SANS_NORMAL.getFontResource ()
.getInputStream ()),
12);
contents.endText ();
}
// No need to save
}
}
示例12: main
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
public static void main (final String [] args) throws IOException
{
final String s = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. ";
final String file = "pdf/issue-3168.pdf";
try (final PDDocument doc = new PDDocument ())
{
final PDPage page = new PDPage (PDRectangle.A4);
doc.addPage (page);
final PDFont font = PDType0Font.load (doc,
EFontResourceOpenSans.OPEN_SANS_NORMAL.getFontResource ()
.getInputStream ());
try (final PDPageContentStream contents = new PDPageContentStream (doc, page))
{
contents.beginText ();
contents.setFont (font, 12);
contents.newLineAtOffset (100, 700);
contents.showText (s);
contents.endText ();
}
doc.save (file);
}
}
示例13: main
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的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"));
}
}
}
示例14: findFallbackFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
private PDFont findFallbackFont(IFontTextDrawerEnv env) throws IOException {
/*
* We search for the right font in the system folders... We try to use
* LucidaSansRegular and if not found Arial, because this fonts often exists. We
* use the Java default font as fallback.
*
* Normally this method is only used and called if a default font misses some
* special characters, e.g. Hebrew or Arabic characters.
*/
String javaHome = System.getProperty("java.home", ".");
String javaFontDir = javaHome + "/lib/fonts";
String windir = System.getenv("WINDIR");
if (windir == null)
windir = javaFontDir;
File[] paths = new File[] { new File(new File(windir), "fonts"), new File(System.getProperty("user.dir", ".")),
new File("/Library/Fonts"), new File("/usr/share/fonts/truetype"), new File(javaFontDir) };
File foundFontFile = null;
for (String fontFileName : new String[] { "LucidaSansRegular.ttf", "arial.ttf", "Arial.ttf" }) {
for (File path : paths) {
File arialFile = new File(path, fontFileName);
if (arialFile.exists()) {
foundFontFile = arialFile;
break;
}
}
if (foundFontFile != null)
break;
}
return PDType0Font.load(env.getDocument(), foundFontFile);
}
示例15: loadIconFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入依赖的package包/类
private void loadIconFont() {
PDDocument pdDocument = document.getPDDocument();
try (InputStream inputStream = TitleBlockWriter.class.getClassLoader()
.getResourceAsStream(ICON_FONT_FILE)) {
iconFont = PDType0Font.load(pdDocument, inputStream);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, null, e);
}
}