Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
iText kernel.jar Source Code
kernel.jar is a component in iText Java library to provide low-level functionalities.
iText Java library allows you to generate and manage PDF documents.
The Source Code files are provided together with the JAR file in the binary packge like iText7-Core-7.1.4.zip. You can download it at iText 7 Core Download site.
You can compile it to generate your JAR file, using kernel.pom as the build configuration file.
The source code of kernel-7.1.4.jar is provided below:
✍: FYIcenter.com
⏎ com/itextpdf/kernel/font/DocTrueTypeFont.java
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2018 iText Group NV
Authors: Bruno Lowagie, Paulo Soares, et al.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://itextpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using iText.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the iText software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping iText with a closed
source product.
For more information, please contact iText Software Corp. at this
address: sales@itextpdf.com
*/
package com.itextpdf.kernel.font;
import com.itextpdf.io.font.FontEncoding;
import com.itextpdf.io.font.TrueTypeFont;
import com.itextpdf.io.font.cmap.CMapToUnicode;
import com.itextpdf.io.font.otf.Glyph;
import com.itextpdf.io.util.IntHashtable;
import com.itextpdf.kernel.pdf.PdfArray;
import com.itextpdf.kernel.pdf.PdfDictionary;
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfNumber;
import com.itextpdf.kernel.pdf.PdfStream;
import com.itextpdf.kernel.pdf.PdfString;
class DocTrueTypeFont extends TrueTypeFont implements IDocFontProgram {
private static final long serialVersionUID = 4611535787920619829L;
private PdfStream fontFile;
private PdfName fontFileName;
private PdfName subtype;
private int missingWidth = 0;
private DocTrueTypeFont(PdfDictionary fontDictionary) {
super();
PdfName baseFontName = fontDictionary.getAsName(PdfName.BaseFont);
if (baseFontName != null) {
setFontName(baseFontName.getValue());
} else {
setFontName(FontUtil.createRandomFontName());
}
subtype = fontDictionary.getAsName(PdfName.Subtype);
}
static TrueTypeFont createFontProgram(PdfDictionary fontDictionary, FontEncoding fontEncoding, CMapToUnicode toUnicode) {
DocTrueTypeFont fontProgram = new DocTrueTypeFont(fontDictionary);
fillFontDescriptor(fontProgram, fontDictionary.getAsDictionary(PdfName.FontDescriptor));
PdfNumber firstCharNumber = fontDictionary.getAsNumber(PdfName.FirstChar);
int firstChar = firstCharNumber != null ? Math.max(firstCharNumber.intValue(), 0) : 0;
int[] widths = FontUtil.convertSimpleWidthsArray(fontDictionary.getAsArray(PdfName.Widths), firstChar,
fontProgram.getMissingWidth());
fontProgram.avgWidth = 0;
int glyphsWithWidths = 0;
for (int i = 0; i < 256; i++) {
Glyph glyph = new Glyph(i, widths[i], fontEncoding.getUnicode(i));
fontProgram.codeToGlyph.put(i, glyph);
//FontEncoding.codeToUnicode table has higher priority
if (glyph.hasValidUnicode() && fontEncoding.convertToByte(glyph.getUnicode()) == i) {
fontProgram.unicodeToGlyph.put(glyph.getUnicode(), glyph);
} else if (toUnicode != null) {
glyph.setChars(toUnicode.lookup(i));
}
if (widths[i] > 0) {
glyphsWithWidths++;
fontProgram.avgWidth += widths[i];
}
}
if (glyphsWithWidths != 0) {
fontProgram.avgWidth /= glyphsWithWidths;
}
return fontProgram;
}
static TrueTypeFont createFontProgram(PdfDictionary fontDictionary, CMapToUnicode toUnicode) {
DocTrueTypeFont fontProgram = new DocTrueTypeFont(fontDictionary);
PdfDictionary fontDescriptor = fontDictionary.getAsDictionary(PdfName.FontDescriptor);
fillFontDescriptor(fontProgram, fontDescriptor);
int dw;
if (fontDescriptor != null && fontDescriptor.containsKey(PdfName.DW)) {
dw = (int) fontDescriptor.getAsInt(PdfName.DW);
} else if (fontDictionary.containsKey(PdfName.DW)) {
dw = (int) fontDictionary.getAsInt(PdfName.DW);
} else {
dw = 1000;
}
IntHashtable widths = null;
if (toUnicode != null) {
widths = FontUtil.convertCompositeWidthsArray(fontDictionary.getAsArray(PdfName.W));
fontProgram.avgWidth = 0;
for (int cid : toUnicode.getCodes()) {
int width = widths.containsKey(cid) ? widths.get(cid) : dw;
Glyph glyph = new Glyph(cid, width, toUnicode.lookup(cid));
if (glyph.hasValidUnicode()) {
fontProgram.unicodeToGlyph.put(glyph.getUnicode(), glyph);
}
fontProgram.codeToGlyph.put(cid, glyph);
fontProgram.avgWidth += width;
}
if (fontProgram.codeToGlyph.size() != 0) {
fontProgram.avgWidth /= fontProgram.codeToGlyph.size();
}
}
if (fontProgram.codeToGlyph.get(0) == null) {
fontProgram.codeToGlyph.put(0, new Glyph(0, widths != null && widths.containsKey(0) ? widths.get(0) : dw, -1));
}
return fontProgram;
}
@Override
public PdfStream getFontFile() {
return fontFile;
}
@Override
public PdfName getFontFileName() {
return fontFileName;
}
@Override
public PdfName getSubtype() {
return subtype;
}
/**
* Returns false, because we cannot rely on an actual font subset and font name.
*
* @param fontName a font name or path to a font program
* @return return false.
*/
@Override
public boolean isBuiltWith(String fontName) {
return false;
}
public int getMissingWidth() {
return missingWidth;
}
static void fillFontDescriptor(DocTrueTypeFont font, PdfDictionary fontDesc) {
if (fontDesc == null) {
return;
}
PdfNumber v = fontDesc.getAsNumber(PdfName.Ascent);
if (v != null) {
font.setTypoAscender(v.intValue());
}
v = fontDesc.getAsNumber(PdfName.Descent);
if (v != null) {
font.setTypoDescender(v.intValue());
}
v = fontDesc.getAsNumber(PdfName.CapHeight);
if (v != null) {
font.setCapHeight(v.intValue());
}
v = fontDesc.getAsNumber(PdfName.XHeight);
if (v != null) {
font.setXHeight(v.intValue());
}
v = fontDesc.getAsNumber(PdfName.ItalicAngle);
if (v != null) {
font.setItalicAngle(v.intValue());
}
v = fontDesc.getAsNumber(PdfName.StemV);
if (v != null) {
font.setStemV(v.intValue());
}
v = fontDesc.getAsNumber(PdfName.StemH);
if (v != null) {
font.setStemH(v.intValue());
}
v = fontDesc.getAsNumber(PdfName.FontWeight);
if (v != null) {
font.setFontWeight(v.intValue());
}
v = fontDesc.getAsNumber(PdfName.MissingWidth);
if (v != null) {
font.missingWidth = v.intValue();
}
PdfName fontStretch = fontDesc.getAsName(PdfName.FontStretch);
if (fontStretch != null) {
font.setFontStretch(fontStretch.getValue());
}
PdfArray bboxValue = fontDesc.getAsArray(PdfName.FontBBox);
if (bboxValue != null) {
int[] bbox = new int[4];
bbox[0] = bboxValue.getAsNumber(0).intValue(); //llx
bbox[1] = bboxValue.getAsNumber(1).intValue();//lly
bbox[2] = bboxValue.getAsNumber(2).intValue();//urx
bbox[3] = bboxValue.getAsNumber(3).intValue();//ury
if (bbox[0] > bbox[2]) {
int t = bbox[0];
bbox[0] = bbox[2];
bbox[2] = t;
}
if (bbox[1] > bbox[3]) {
int t = bbox[1];
bbox[1] = bbox[3];
bbox[3] = t;
}
font.setBbox(bbox);
// If ascender or descender in font descriptor are zero, we still want to get more or less correct valuee for
// text extraction, stamping etc. Thus we rely on font bbox in this case
if (font.getFontMetrics().getTypoAscender() == 0 && font.getFontMetrics().getTypoDescender() == 0) {
float maxAscent = Math.max(bbox[3], font.getFontMetrics().getTypoAscender());
float minDescent = Math.min(bbox[1], font.getFontMetrics().getTypoDescender());
font.setTypoAscender((int) (maxAscent * 1000 / (maxAscent - minDescent)));
font.setTypoDescender((int) (minDescent * 1000 / (maxAscent - minDescent)));
}
}
PdfString fontFamily = fontDesc.getAsString(PdfName.FontFamily);
if (fontFamily != null) {
font.setFontFamily(fontFamily.getValue());
}
PdfNumber flagsValue = fontDesc.getAsNumber(PdfName.Flags);
if (flagsValue != null) {
int flags = flagsValue.intValue();
if ((flags & 1) != 0) {
font.setFixedPitch(true);
}
if ((flags & 262144) != 0) {
font.setBold(true);
}
}
PdfName[] fontFileNames = new PdfName[] {PdfName.FontFile, PdfName.FontFile2, PdfName.FontFile3};
for (PdfName fontFile: fontFileNames) {
if (fontDesc.containsKey(fontFile)) {
font.fontFileName = fontFile;
font.fontFile = fontDesc.getAsStream(fontFile);
break;
}
}
}
}
⏎ com/itextpdf/kernel/font/DocTrueTypeFont.java
Or download all of them as a single archive file:
File name: kernel-7.1.4-sources.jar File size: 1201221 bytes Release date: 2018-10-09 Download
⇐ Download and Install iText7-Core-7.1.4.zip
2010-02-18, ≈222🔥, 0💬
Popular Posts:
What Is HttpComponents httpclient-4.2.2.jar? HttpComponents httpclient-4.2.2.jar is the JAR file for...
What Is javax.websocket-api-1.1. jar?javax.websocket-api-1.1. jaris the JAR file for Java API for We...
MP3SPI is a Java Service Provider Interface that adds MP3 (MPEG 1/2/2.5 Layer 1/2/3) audio format su...
Java Servlet API 3.0.1 Source Code Files are important if you want to compile them with different JD...
Rhino JavaScript Java Library is an open-source implementation of JavaScript written entirely in Jav...