本文整理汇总了Java中org.apache.fontbox.util.BoundingBox类的典型用法代码示例。如果您正苦于以下问题:Java BoundingBox类的具体用法?Java BoundingBox怎么用?Java BoundingBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BoundingBox类属于org.apache.fontbox.util包,在下文中一共展示了BoundingBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeBoundingBox
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
/**
* Computes the bounding box from given Rectangle2D in device space units.
*
* @param rect
* the chars string.
* @param font
* the current font.
* @param trm
* the current text rendering matrix.
* @return the bounding box from given char string.
*/
protected Rectangle computeBoundingBox(BoundingBox rect, PDFont font,
Matrix trm) {
if (rect != null && font != null) {
Matrix fontMatrix = font.getFontMatrix();
Point ll = new SimplePoint(rect.getLowerLeftX(), rect.getLowerLeftY());
Point ur = new SimplePoint(rect.getUpperRightX(), rect.getUpperRightY());
// glyph space -> text space
transform(ll, fontMatrix);
transform(ur, fontMatrix);
// text space -> device space
transform(ll, trm);
transform(ur, trm);
return new SimpleRectangle(ll, ur);
}
return null;
}
示例2: createAppearanceStream
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
PDAppearanceStream createAppearanceStream(PDDocument document, float width, PDFont font, String backColorSettingOperation) throws IOException
{
PDResources pdResources = new PDResources();
String fontName = pdResources.addFont(font);
PDStream pdStream = new PDStream(document);
OutputStream os = pdStream.createOutputStream();
String streamToBe = backColorSettingOperation + " 0 -5 " + width + " 25 re f /" + fontName + " 18 Tf 0 g BT (PDFBox) Tj ET";
os.write(streamToBe.getBytes());
os.close();
PDXObjectForm xobject = new PDXObjectForm(pdStream);
xobject.setResources(pdResources);
xobject.setBBox(new PDRectangle(new BoundingBox(0, -5, width, 20)));
xobject.setFormType(1);
PDAppearanceStream normal = new PDAppearanceStream(xobject.getCOSStream());
return normal;
}
示例3: getBoundingBoxDescent
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
public static float getBoundingBoxDescent(PDFont font, float fontSize) {
try {
BoundingBox bBox = font.getBoundingBox();
float boxDescent = bBox.getLowerLeftY();
return (boxDescent / 1000) * fontSize;
} catch (IOException e) {
// fall through
}
return 0.0f;
}
示例4: clipPage
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
void clipPage(PDDocument document, PDPage page, BoundingBox clipBox) throws IOException
{
PDPageContentStream pageContentStream = new PDPageContentStream(document, page, true, false);
pageContentStream.addRect(clipBox.getLowerLeftX(), clipBox.getLowerLeftY(), clipBox.getWidth(), clipBox.getHeight());
pageContentStream.clipPath(PathIterator.WIND_NON_ZERO);
pageContentStream.close();
COSArray newContents = new COSArray();
COSStreamArray contents = (COSStreamArray) page.getContents().getStream();
newContents.add(contents.get(contents.getStreamCount()-1));
for (int i = 0; i < contents.getStreamCount()-1; i++)
{
newContents.add(contents.get(i));
}
page.setContents(new PDStream(new COSStreamArray(newContents)));
}
示例5: generateBoundingBox
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
private BoundingBox generateBoundingBox()
{
if (getFontDescriptor() != null)
{
PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
if (bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0 || bbox.getUpperRightX() != 0
|| bbox.getUpperRightY() != 0)
{
return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
bbox.getUpperRightX(), bbox.getUpperRightY());
}
}
if (cidFont != null)
{
return cidFont.getFontBBox();
}
try
{
return t1Font.getFontBBox();
}
catch (IOException e)
{
return new BoundingBox();
}
}
示例6: generateBoundingBox
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
private BoundingBox generateBoundingBox()
{
PDRectangle rect = getFontBBox();
if (rect.getLowerLeftX() == 0 && rect.getLowerLeftY() == 0 && rect.getUpperRightX() == 0
&& rect.getUpperRightY() == 0)
{
// Plan B: get the max bounding box of the glyphs
COSDictionary cp = getCharProcs();
for (COSName name : cp.keySet())
{
COSBase base = cp.getDictionaryObject(name);
if (base instanceof COSStream)
{
PDType3CharProc charProc = new PDType3CharProc(this, (COSStream) base);
PDRectangle glyphBBox = charProc.getGlyphBBox();
if (nonNull(glyphBBox))
{
rect.setLowerLeftX(
Math.min(rect.getLowerLeftX(), glyphBBox.getLowerLeftX()));
rect.setLowerLeftY(
Math.min(rect.getLowerLeftY(), glyphBBox.getLowerLeftY()));
rect.setUpperRightX(
Math.max(rect.getUpperRightX(), glyphBBox.getUpperRightX()));
rect.setUpperRightY(
Math.max(rect.getUpperRightY(), glyphBBox.getUpperRightY()));
}
}
}
}
return new BoundingBox(rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(),
rect.getUpperRightY());
}
示例7: writeString
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
@Override
protected void writeString(String text, List<TextPosition> textPositions) throws IOException {
text = text.toLowerCase();
int index = text.indexOf(mTextToHighlight);
if (index != -1) {
PDPage currentPage = getCurrentPage();
PDRectangle pageBoundingBox = currentPage.getBBox();
AffineTransform flip = new AffineTransform();
flip.translate(0, pageBoundingBox.getHeight());
flip.scale(1, -1);
PDRectangle mediaBox = currentPage.getMediaBox();
float mediaHeight = mediaBox.getHeight();
float mediaWidth = mediaBox.getWidth();
int size = textPositions.size();
while (index != -1) {
int last = index + mTextToHighlight.length() - 1;
for (int i = index; i <= last; i++) {
TextPosition pos = textPositions.get(i);
PDFont font = pos.getFont();
BoundingBox bbox = font.getBoundingBox();
Rectangle2D.Float rect = new Rectangle2D.Float(0, bbox.getLowerLeftY(), font.getWidth(pos.getCharacterCodes()[0]), bbox.getHeight());
AffineTransform at = pos.getTextMatrix().createAffineTransform();
if (font instanceof PDType3Font) {
at.concatenate(font.getFontMatrix().createAffineTransform());
} else {
at.scale(1 / 1000f, 1 / 1000f);
}
Shape shape = flip.createTransformedShape(at.createTransformedShape(rect));
AffineTransform transform = mGC.getTransform();
int rotation = currentPage.getRotation();
if (rotation != 0) {
switch (rotation) {
case 90:
mGC.translate(mediaHeight, 0);
break;
case 270:
mGC.translate(0, mediaWidth);
break;
case 180:
mGC.translate(mediaWidth, mediaHeight);
break;
default:
break;
}
mGC.rotate(Math.toRadians(rotation));
}
mGC.fill(shape);
if (rotation != 0) {
mGC.setTransform(transform);
}
}
index = last < size - 1 ? text.indexOf(mTextToHighlight, last + 1) : -1;
}
}
}
示例8: getBoundingBoxAscent
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
public static float getBoundingBoxAscent(PDFont font, float fontSize) {
try {
BoundingBox bBox = font.getBoundingBox();
float boxAscent = bBox.getUpperRightY();
return (boxAscent / 1000) * fontSize;
} catch (IOException e) {
// fall through
}
return 0.0f;
}
示例9: testTestTop
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/30616220/splitting-at-a-specific-point-in-pdfbox">
* Splitting at a specific point in PDFBox
* </a>
* <p>
* One way to achieve the task, i.e. to split a page at a certain point (i.e. all content above
* a limit to be included and everything below to be excluded) would be to prepend a clip path.
* This is implemented in {@link #clipPage(PDDocument, PDPage, BoundingBox)}.
* </p>
*/
@Test
public void testTestTop() throws IOException, COSVisitorException
{
try ( InputStream docStream = getClass().getResourceAsStream("/mkl/testarea/pdfbox1/sign/test.pdf") )
{
PDDocument document = PDDocument.load(docStream);
PDPage page = (PDPage) document.getDocumentCatalog().getAllPages().get(0);
PDRectangle cropBox = page.findCropBox();
clipPage(document, page, new BoundingBox(cropBox.getLowerLeftX(), cropBox.getLowerLeftY() + 650, cropBox.getUpperRightX(), cropBox.getUpperRightY()));
document.save(new File(RESULT_FOLDER, "test-cropTop.pdf"));
document.close();
}
}
示例10: getBoundingBox
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
@Override
public BoundingBox getBoundingBox() throws IOException
{
if (fontBBox == null)
{
fontBBox = generateBoundingBox();
}
return fontBBox;
}
示例11: generateBoundingBox
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
private BoundingBox generateBoundingBox() throws IOException
{
if (getFontDescriptor() != null)
{
PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
if (nonNull(bbox))
{
return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
bbox.getUpperRightX(), bbox.getUpperRightY());
}
}
return ttf.getFontBBox();
}
示例12: generateBoundingBox
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
private BoundingBox generateBoundingBox() throws IOException
{
if (getFontDescriptor() != null)
{
PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
if (nonNull(bbox) && bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0
|| bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0)
{
return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
bbox.getUpperRightX(), bbox.getUpperRightY());
}
}
return ttf.getFontBBox();
}
示例13: generateBoundingBox
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
private BoundingBox generateBoundingBox() throws IOException
{
if (getFontDescriptor() != null)
{
PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
if (nonNull(bbox) && bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0
|| bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0)
{
return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
bbox.getUpperRightX(), bbox.getUpperRightY());
}
}
return genericFont.getFontBBox();
}
示例14: getBoundingBox
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
@Override
public BoundingBox getBoundingBox()
{
if (fontBBox == null)
{
fontBBox = generateBoundingBox();
}
return fontBBox;
}
示例15: PDRectangle
import org.apache.fontbox.util.BoundingBox; //导入依赖的package包/类
/**
* @param box the bounding box to be used for the rectangle
*/
public PDRectangle(BoundingBox box)
{
rectArray.add(new COSFloat(box.getLowerLeftX()));
rectArray.add(new COSFloat(box.getLowerLeftY()));
rectArray.add(new COSFloat(box.getUpperRightX()));
rectArray.add(new COSFloat(box.getUpperRightY()));
}