本文整理汇总了Java中org.apache.fop.fonts.FontInfo类的典型用法代码示例。如果您正苦于以下问题:Java FontInfo类的具体用法?Java FontInfo怎么用?Java FontInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FontInfo类属于org.apache.fop.fonts包,在下文中一共展示了FontInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
try {
String configFile = "examples/fop-eps.xconf";
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration c = cfgBuilder.buildFromFile(configFile);
FontInfo fontInfo = PDFDocumentGraphics2DConfigurator.createFontInfo(c, false);
OutputStream out = new FileOutputStream("example_eps.eps");
EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
g2d.setGraphicContext(new GraphicContext());
g2d.setCustomTextHandler(new NativeTextHandler(g2d, fontInfo));
g2d.setupDocument(out, 200, 100);
g2d.setFont(new Font("Arial", Font.PLAIN, 12));
g2d.drawString("Hi there Arial", 50, 50);
g2d.finish();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: bestMatch
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* Returns the highest priority matching font triplet found in a given font info
* @param fontInfo the font info
* @return the highest priority matching font triplet
*/
protected FontTriplet bestMatch(FontInfo fontInfo) {
List/*<FontTriplet>*/ matchingTriplets = match(fontInfo);
FontTriplet bestTriplet = null;
if (matchingTriplets.size() == 1) {
bestTriplet = (FontTriplet)matchingTriplets.get(0);
} else {
for (Iterator iterator = matchingTriplets.iterator(); iterator.hasNext();) {
FontTriplet triplet = (FontTriplet)iterator.next();
if (bestTriplet == null) {
bestTriplet = triplet;
} else {
int priority = triplet.getPriority();
if (priority < bestTriplet.getPriority()) {
bestTriplet = triplet;
}
}
}
}
return bestTriplet;
}
示例3: adjustFontInfo
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* Adjusts a given fontInfo using this font substitution catalog
* @param fontInfo font info
*/
public void adjustFontInfo(FontInfo fontInfo) {
for (Iterator/*<FontSubstitution>*/ subsIt = super.iterator(); subsIt.hasNext();) {
FontSubstitution substitution = (FontSubstitution)subsIt.next();
// find the best matching font triplet
FontQualifier toQualifier = substitution.getToQualifier();
FontTriplet fontTriplet = toQualifier.bestMatch(fontInfo);
if (fontTriplet == null) {
log.error("Unable to match font substitution for destination qualifier "
+ toQualifier);
continue;
}
String internalFontKey = fontInfo.getInternalFontKey(fontTriplet);
FontQualifier fromQualifier = substitution.getFromQualifier();
List/*<FontTriplet>*/ tripletList = fromQualifier.getTriplets();
for (Iterator tripletit = tripletList.iterator(); tripletit.hasNext();) {
FontTriplet triplet = (FontTriplet) tripletit.next();
fontInfo.addFontProperties(internalFontKey, triplet);
}
}
}
示例4: configure
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* Configures a PDFDocumentGraphics2D instance using an Avalon Configuration object.
* @param graphics the PDFDocumentGraphics2D instance
* @param cfg the configuration
* @param useComplexScriptFeatures true if complex script features enabled
* @throws ConfigurationException if an error occurs while configuring the object
*/
public void configure(PDFDocumentGraphics2D graphics, Configuration cfg,
boolean useComplexScriptFeatures )
throws ConfigurationException {
PDFDocument pdfDoc = graphics.getPDFDocument();
//Filter map
pdfDoc.setFilterMap(
PDFRendererConfigurator.buildFilterMapFromConfiguration(cfg));
//Fonts
try {
FontInfo fontInfo = createFontInfo(cfg, useComplexScriptFeatures);
graphics.setFontInfo(fontInfo);
} catch (FOPException e) {
throw new ConfigurationException("Error while setting up fonts", e);
}
}
示例5: addFonts
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* Add the fonts in the font info to this PDF document's Font Resources.
*
* @param doc PDF document to add fonts to
* @param fontInfo font info object to get font information from
*/
public void addFonts(PDFDocument doc, FontInfo fontInfo) {
Map<String, Typeface> usedFonts = fontInfo.getUsedFonts();
for (String f : usedFonts.keySet()) {
Typeface font = usedFonts.get(f);
//Check if the font actually had any mapping operations. If not, it is an indication
//that it has never actually been used and therefore doesn't have to be embedded.
if (font.hadMappingOperations()) {
FontDescriptor desc = null;
if (font instanceof FontDescriptor) {
desc = (FontDescriptor)font;
}
String encoding = font.getEncodingName();
if (font instanceof Symbol || font instanceof ZapfDingbats) {
encoding = null; //Symbolic fonts shouldn't specify an encoding value in PDF
}
addFont(doc.getFactory().makeFont(
f, font.getEmbedFontName(), encoding, font, desc));
}
}
}
示例6: initialize
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void initialize() {
super.initialize();
org.apache.fop.fo.flow.Block fo = getBlockFO();
FontInfo fi = fo.getFOEventHandler().getFontInfo();
FontTriplet[] fontkeys = fo.getCommonFont().getFontState(fi);
Font initFont = fi.getFontInstance(fontkeys[0],
getBlockFO().getCommonFont().fontSize.getValue(this));
lead = initFont.getAscender();
follow = -initFont.getDescender();
//middleShift = -fs.getXHeight() / 2;
lineHeight = fo.getLineHeight().getOptimum(this).getLength();
startIndent = fo.getCommonMarginBlock().startIndent.getValue(this);
endIndent = fo.getCommonMarginBlock().endIndent.getValue(this);
foSpaceBefore = new SpaceVal(fo.getCommonMarginBlock().spaceBefore, this).getSpace();
foSpaceAfter = new SpaceVal(fo.getCommonMarginBlock().spaceAfter, this).getSpace();
// use optimum space values
adjustedSpaceBefore = fo.getCommonMarginBlock().spaceBefore.getSpace()
.getOptimum(this).getLength().getValue(this);
adjustedSpaceAfter = fo.getCommonMarginBlock().spaceAfter.getSpace()
.getOptimum(this).getLength().getValue(this);
}
示例7: RenderPagesModel
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* Create a new render pages model with the given renderer.
* @param userAgent FOUserAgent object for process
* @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
* @param fontInfo FontInfo object
* @param stream OutputStream
* @throws FOPException if the renderer cannot be properly initialized
*/
public RenderPagesModel (FOUserAgent userAgent, String outputFormat,
FontInfo fontInfo, OutputStream stream) throws FOPException {
super();
this.renderer = userAgent.getRendererFactory().createRenderer(
userAgent, outputFormat);
try {
renderer.setupFontInfo(fontInfo);
// check that the "any,normal,400" font exists
if (!fontInfo.isSetupValid()) {
throw new FOPException(
"No default font defined by OutputConverter");
}
renderer.startRenderer(stream);
} catch (IOException e) {
throw new FOPException(e);
}
}
示例8: buildDefaultJava2DBasedFontInfo
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* Builds a default {@link FontInfo} object for use with output formats using the Java2D
* font setup.
* @param fontInfo the font info object to populate
* @param userAgent the user agent
* @return the populated font information object
*/
public static FontInfo buildDefaultJava2DBasedFontInfo(
FontInfo fontInfo, FOUserAgent userAgent) {
Java2DFontMetrics java2DFontMetrics = new Java2DFontMetrics();
FontManager fontManager = userAgent.getFactory().getFontManager();
FontCollection[] fontCollections = new FontCollection[] {
new org.apache.fop.render.java2d.Base14FontCollection(java2DFontMetrics),
new InstalledFontCollection(java2DFontMetrics)
};
FontInfo fi = (fontInfo != null ? fontInfo : new FontInfo());
fi.setEventListener(new FontEventAdapter(userAgent.getEventBroadcaster()));
fontManager.setup(fi, fontCollections);
return fi;
}
示例9: setupFontInfo
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/** {@inheritDoc} */
public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
throws FOPException {
FontManager fontManager = userAgent.getFactory().getFontManager();
final Java2DFontMetrics java2DFontMetrics = new Java2DFontMetrics();
final List fontCollections = new java.util.ArrayList();
fontCollections.add(new Base14FontCollection(java2DFontMetrics));
fontCollections.add(new InstalledFontCollection(java2DFontMetrics));
Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
if (cfg != null) {
FontResolver fontResolver = new DefaultFontResolver(userAgent);
FontEventListener listener = new FontEventAdapter(
userAgent.getEventBroadcaster());
List fontList = buildFontList(cfg, fontResolver, listener);
fontCollections.add(new ConfiguredFontCollection(fontResolver, fontList,
userAgent.isComplexScriptFeaturesEnabled()));
}
fontManager.setup(fontInfo,
(FontCollection[])fontCollections.toArray(
new FontCollection[fontCollections.size()]));
documentHandler.setFontInfo(fontInfo);
}
示例10: parseAndRenderToIntermediateFormat
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/** {@inheritDoc} */
protected Document parseAndRenderToIntermediateFormat(Source src) throws Exception {
AreaTreeParser parser = new AreaTreeParser();
//Set up XMLRenderer to render to a DOM
TransformerHandler handler = testAssistant.getTransformerFactory().newTransformerHandler();
DOMResult domResult = new DOMResult();
handler.setResult(domResult);
FOUserAgent userAgent = createUserAgent();
XMLRenderer renderer = new XMLRenderer(userAgent);
userAgent.setRendererOverride(renderer);
renderer.setContentHandler(handler);
FontInfo fontInfo = new FontInfo();
AreaTreeModel treeModel = new RenderPagesModel(userAgent,
MimeConstants.MIME_FOP_AREA_TREE, fontInfo, null);
parser.parse(src, treeModel, userAgent);
treeModel.endDocument();
return (Document)domResult.getNode();
}
示例11: createBridgeContext
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public BridgeContext createBridgeContext(String version) {
FontInfo fontInfo = null;
if (!isTextStroked()) {
fontInfo = graphics.getFontInfo();
}
return new PDFBridgeContext(userAgent, fontInfo, getImageManager(), getImageSessionContext());
}
示例12: concatToPDF
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* Concatenates an array of area tree XML files to a single PDF file.
* @param files the array of area tree XML files
* @param pdffile the target PDF file
* @throws IOException In case of an I/O problem
* @throws TransformerException In case of a XSL transformation problem
* @throws SAXException In case of an XML-related problem
*/
public void concatToPDF(File[] files, File pdffile)
throws IOException, TransformerException, SAXException {
// Setup output
OutputStream out = new java.io.FileOutputStream(pdffile);
out = new java.io.BufferedOutputStream(out);
try {
//Setup fonts and user agent
FontInfo fontInfo = new FontInfo();
FOUserAgent userAgent = fopFactory.newFOUserAgent();
//Construct the AreaTreeModel that will received the individual pages
AreaTreeModel treeModel = new RenderPagesModel(userAgent,
MimeConstants.MIME_PDF, fontInfo, out);
//Iterate over all area tree files
AreaTreeParser parser = new AreaTreeParser();
for (int i = 0; i < files.length; i++) {
Source src = new StreamSource(files[i]);
parser.parse(src, treeModel, userAgent);
}
//Signal the end of the processing. The renderer can finalize the target document.
treeModel.endDocument();
} finally {
out.close();
}
}
示例13: addFontProperties
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
private int addFontProperties(FontInfo fontInfo, AFPFont font,
String[] names, String style, int weight, int num) {
String internalFontKey = "F" + num;
fontInfo.addMetrics(internalFontKey, font);
fontInfo.addFontProperties(internalFontKey, names, style, weight);
num++;
return num;
}
示例14: createBridgeContext
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/** {@inheritDoc} */
public BridgeContext createBridgeContext(String version) {
FontInfo fontInfo = graphics.getFontInfo();
if (isTextStroked()) {
fontInfo = null;
}
BridgeContext ctx = new PDFBridgeContext(userAgent, fontInfo,
getImageManager(), getImageSessionContext());
return ctx;
}
示例15: AbstractFOPBridgeContext
import org.apache.fop.fonts.FontInfo; //导入依赖的package包/类
/**
* Constructs a new bridge context.
* @param userAgent the user agent
* @param fontInfo the font list for the text painter, may be null
* in which case text is painted as shapes
* @param imageManager an image manager
* @param imageSessionContext an image session context
* @param linkTransform AffineTransform to properly place links,
* may be null
*/
public AbstractFOPBridgeContext(UserAgent userAgent,
FontInfo fontInfo,
ImageManager imageManager,
ImageSessionContext imageSessionContext,
AffineTransform linkTransform) {
super(userAgent);
this.fontInfo = fontInfo;
this.imageManager = imageManager;
this.imageSessionContext = imageSessionContext;
this.linkTransform = linkTransform;
}