*/
private PdfReference load_createFontDescriptor(
OpenFontParser parser
)
{
PdfDictionary fontDescriptor = new PdfDictionary();
{
OpenFontParser.FontMetrics metrics = parser.metrics;
// Type.
fontDescriptor.put(
PdfName.Type,
PdfName.FontDescriptor
);
// FontName.
fontDescriptor.put(
PdfName.FontName,
getBaseDataObject().get(PdfName.BaseFont)
);
// Flags [PDF:1.6:5.7.1].
int flags = 0;
if(metrics.isFixedPitch)
{flags |= FlagsEnum.FixedPitch.getCode();}
if(metrics.isCustomEncoding)
{flags |= FlagsEnum.Symbolic.getCode();}
else
{flags |= FlagsEnum.Nonsymbolic.getCode();}
fontDescriptor.put(
PdfName.Flags,
new PdfInteger(flags)
);
// FontBBox.
fontDescriptor.put(
PdfName.FontBBox,
new Rectangle(
new Point2D.Double(metrics.xMin * metrics.unitNorm, metrics.yMin * metrics.unitNorm),
new Point2D.Double(metrics.xMax * metrics.unitNorm, metrics.yMax * metrics.unitNorm)
).getBaseDataObject()
);
// ItalicAngle.
fontDescriptor.put(
PdfName.ItalicAngle,
new PdfReal(metrics.italicAngle)
);
// Ascent.
fontDescriptor.put(
PdfName.Ascent,
new PdfReal(
metrics.ascender == 0
? metrics.sTypoAscender * metrics.unitNorm
: metrics.ascender * metrics.unitNorm
)
);
// Descent.
fontDescriptor.put(
PdfName.Descent,
new PdfReal(
metrics.descender == 0
? metrics.sTypoDescender * metrics.unitNorm
: metrics.descender * metrics.unitNorm
)
);
// Leading.
fontDescriptor.put(
PdfName.Leading,
new PdfReal(metrics.sTypoLineGap * metrics.unitNorm)
);
// CapHeight.
fontDescriptor.put(
PdfName.CapHeight,
new PdfReal(metrics.sCapHeight * metrics.unitNorm)
);
// StemV.
/*
NOTE: '100' is just a rule-of-thumb value, 'cause I've still to solve the
'cvt' table puzzle (such a harsh headache!) for TrueType fonts...
TODO:IMPL TrueType and CFF stemv real value to extract!!!
*/
fontDescriptor.put(
PdfName.StemV,
new PdfInteger(100)
);
// FontFile.
//TODO:IMPL distinguish between truetype (FontDescriptor.FontFile2) and opentype (FontDescriptor.FontFile3 and FontStream.subtype=OpenType)!!!
PdfReference fontFileReference = getFile().register(
new PdfStream(
new PdfDictionary(
new PdfName[]{PdfName.Subtype},
new PdfDirectObject[]{PdfName.OpenType}
),
new Buffer(parser.fontData.toByteArray())
)
);
fontDescriptor.put(
PdfName.FontFile3,
fontFileReference
);
}
return getFile().register(fontDescriptor);