org.apache.fontbox.util.BoundingBox Java Examples
The following examples show how to use
org.apache.fontbox.util.BoundingBox.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PDCIDFontType2.java From sambox with Apache License 2.0 | 6 votes |
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (nonNull(bbox)) { if ((Float.compare(bbox.getLowerLeftX(), 0) != 0 || Float.compare(bbox.getLowerLeftY(), 0) != 0 || Float.compare(bbox.getUpperRightX(), 0) != 0 || Float.compare(bbox.getUpperRightY(), 0) != 0)) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } } return ttf.getFontBBox(); }
Example #2
Source File: PDCIDFontType2.java From gcs with Mozilla Public License 2.0 | 6 votes |
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (bbox != null && (Float.compare(bbox.getLowerLeftX(), 0) != 0 || Float.compare(bbox.getLowerLeftY(), 0) != 0 || Float.compare(bbox.getUpperRightX(), 0) != 0 || Float.compare(bbox.getUpperRightY(), 0) != 0)) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } return ttf.getFontBBox(); }
Example #3
Source File: GlyphData.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * This will read the required data from the stream. * * @param glyphTable The glyph table this glyph belongs to. * @param data The stream to read the data from. * @param leftSideBearing The left side bearing for this glyph. * @throws IOException If there is an error reading the data. */ void initData( GlyphTable glyphTable, TTFDataStream data, int leftSideBearing ) throws IOException { numberOfContours = data.readSignedShort(); xMin = data.readSignedShort(); yMin = data.readSignedShort(); xMax = data.readSignedShort(); yMax = data.readSignedShort(); boundingBox = new BoundingBox(xMin, yMin, xMax, yMax); if (numberOfContours >= 0) { // create a simple glyph short x0 = (short) (leftSideBearing - xMin); glyphDescription = new GlyfSimpleDescript(numberOfContours, data, x0); } else { // create a composite glyph glyphDescription = new GlyfCompositeDescript(data, glyphTable); } }
Example #4
Source File: PDCIDFontType0.java From gcs with Mozilla Public License 2.0 | 6 votes |
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(); } else { try { return t1Font.getFontBBox(); } catch (IOException e) { return new BoundingBox(); } } }
Example #5
Source File: TrueTypeFont.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public BoundingBox getFontBBox() throws IOException { short xMin = getHeader().getXMin(); short xMax = getHeader().getXMax(); short yMin = getHeader().getYMin(); short yMax = getHeader().getYMax(); float scale = 1000f / getUnitsPerEm(); return new BoundingBox(xMin * scale, yMin * scale, xMax * scale, yMax * scale); }
Example #6
Source File: PDRectangle.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Constructor. * * @param box the bounding box to be used for the rectangle */ public PDRectangle( BoundingBox box ) { rectArray = new COSArray(); rectArray.add( new COSFloat( box.getLowerLeftX() ) ); rectArray.add( new COSFloat( box.getLowerLeftY() ) ); rectArray.add( new COSFloat( box.getUpperRightX() ) ); rectArray.add( new COSFloat( box.getUpperRightY() ) ); }
Example #7
Source File: PDType1CFont.java From sambox with Apache License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() throws IOException { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #8
Source File: PDType3Font.java From sambox with Apache License 2.0 | 5 votes |
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()); }
Example #9
Source File: PDType3Font.java From sambox with Apache License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #10
Source File: PDCIDFontType0.java From sambox with Apache License 2.0 | 5 votes |
private BoundingBox generateBoundingBox() { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (bbox != null) { 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(); } }
Example #11
Source File: PDCIDFontType0.java From sambox with Apache License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #12
Source File: CFFFont.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Returns the FontBBox. */ @Override public BoundingBox getFontBBox() { @SuppressWarnings("unchecked") List<Number> numbers = (List<Number>)topDict.get("FontBBox"); return new BoundingBox(numbers); }
Example #13
Source File: PDType1CFont.java From gcs with Mozilla Public License 2.0 | 5 votes |
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (bbox != null && (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(); }
Example #14
Source File: PDType1Font.java From sambox with Apache License 2.0 | 5 votes |
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(); }
Example #15
Source File: PDType1Font.java From sambox with Apache License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() throws IOException { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #16
Source File: PDTrueTypeFont.java From sambox with Apache License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() throws IOException { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #17
Source File: PDTrueTypeFont.java From sambox with Apache License 2.0 | 5 votes |
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(); }
Example #18
Source File: PDCIDFontType2.java From sambox with Apache License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() throws IOException { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #19
Source File: PDType1CFont.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() throws IOException { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #20
Source File: PDType3Font.java From gcs with Mozilla Public License 2.0 | 5 votes |
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); try { PDRectangle glyphBBox = charProc.getGlyphBBox(); if (glyphBBox == null) { continue; } 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())); } catch (IOException ex) { // ignore } } } } return new BoundingBox(rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(), rect.getUpperRightY()); }
Example #21
Source File: PDType3Font.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #22
Source File: PDType1CFont.java From sambox with Apache License 2.0 | 5 votes |
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(); }
Example #23
Source File: PDRectangle.java From sambox with Apache License 2.0 | 5 votes |
/** * @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())); }
Example #24
Source File: PDCIDFontType0.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #25
Source File: PDType1Font.java From gcs with Mozilla Public License 2.0 | 5 votes |
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (bbox != null && (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(); }
Example #26
Source File: PDType1Font.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() throws IOException { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #27
Source File: PDCIDFontType2.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public BoundingBox getBoundingBox() throws IOException { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
Example #28
Source File: TextMetrics.java From Pdf2Dom with GNU Lesser General Public License v3.0 | 5 votes |
public static float getBoundingBoxDescent(PDFont font, float fontSize) { try { BoundingBox bBox = font.getBoundingBox(); float boxDescent = bBox.getLowerLeftY(); return (boxDescent / 1000) * fontSize; } catch (IOException e) { } return 0.0f; }
Example #29
Source File: TextMetrics.java From Pdf2Dom with GNU Lesser General Public License v3.0 | 5 votes |
public static float getBoundingBoxAscent(PDFont font, float fontSize) { try { BoundingBox bBox = font.getBoundingBox(); float boxAscent = bBox.getUpperRightY(); return (boxAscent / 1000) * fontSize; } catch (IOException e) { } return 0.0f; }
Example #30
Source File: PDTrueTypeFont.java From gcs with Mozilla Public License 2.0 | 5 votes |
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (bbox != null) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } return ttf.getFontBBox(); }