Java Code Examples for org.apache.pdfbox.pdmodel.common.PDRectangle#setUpperRightY()

The following examples show how to use org.apache.pdfbox.pdmodel.common.PDRectangle#setUpperRightY() . 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: PdfManipulator.java    From estatio with Apache License 2.0 6 votes vote down vote up
private void addHyperlink(
        final float x, final float y,
        final String hyperlink,
        final PDPage pdPage) throws IOException {

    PDAnnotationLink txtLink = new PDAnnotationLink();

    PDRectangle position = new PDRectangle();
    PDBorderStyleDictionary underline = new PDBorderStyleDictionary();
    underline.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE);
    txtLink.setBorderStyle(underline);

    position.setLowerLeftX(x);
    position.setLowerLeftY(y);
    position.setUpperRightX(X_MARGIN_LEFT + BOX_WIDTH);
    position.setUpperRightY(y + TEXT_LINE_HEIGHT);
    txtLink.setRectangle(position);

    PDActionURI action = new PDActionURI();
    action.setURI(hyperlink);
    txtLink.setAction(action);
    pdPage.getAnnotations().add(txtLink);
}
 
Example 2
Source File: FDFAnnotationCaret.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void initFringe(Element element) throws IOException
{
    String fringe = element.getAttribute("fringe");
    if (fringe != null && !fringe.isEmpty())
    {
        String[] fringeValues = fringe.split(",");
        if (fringeValues.length != 4)
        {
            throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
        }
        PDRectangle rect = new PDRectangle();
        rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
        rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
        rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
        rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
        setFringe(rect);
    }
}
 
Example 3
Source File: FDFAnnotationCircle.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void initFringe(Element element) throws IOException
{
    String fringe = element.getAttribute("fringe");
    if (fringe != null && !fringe.isEmpty())
    {
        String[] fringeValues = fringe.split(",");
        if (fringeValues.length != 4)
        {
            throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
        }
        PDRectangle rect = new PDRectangle();
        rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
        rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
        rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
        rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
        setFringe(rect);
    }
}
 
Example 4
Source File: FDFAnnotationSquare.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void initFringe(Element element) throws IOException
{
    String fringe = element.getAttribute("fringe");
    if (fringe != null && !fringe.isEmpty())
    {
        String[] fringeValues = fringe.split(",");
        if (fringeValues.length != 4)
        {
            throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
        }
        PDRectangle rect = new PDRectangle();
        rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
        rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
        rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
        rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
        setFringe(rect);
    }
}
 
Example 5
Source File: FDFAnnotationFreeText.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void initFringe(Element element) throws IOException
{
    String fringe = element.getAttribute("fringe");
    if (fringe != null && !fringe.isEmpty())
    {
        String[] fringeValues = fringe.split(",");
        if (fringeValues.length != 4)
        {
            throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
        }
        PDRectangle rect = new PDRectangle();
        rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
        rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
        rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
        rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
        setFringe(rect);
    }
}
 
Example 6
Source File: CompatibilityHelper.java    From pdfbox-layout with MIT License 6 votes vote down vote up
/**
    * Transform the rectangle in order to match the page rotation
    * @param rect the rectangle.
    * @param page the page.
    * @return the transformed rectangle.
    */
   public static PDRectangle transformToPageRotation(
    final PDRectangle rect, final PDPage page) {
AffineTransform transform = transformToPageRotation(page);
if (transform == null) {
    return rect;
}
float[] points = new float[] {rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(), rect.getUpperRightY()};
float[] rotatedPoints = new float[4]; 
transform.transform(points, 0, rotatedPoints, 0, 2);
PDRectangle rotated = new PDRectangle();
rotated.setLowerLeftX(rotatedPoints[0]);
rotated.setLowerLeftY(rotatedPoints[1]);
rotated.setUpperRightX(rotatedPoints[2]);
rotated.setUpperRightY(rotatedPoints[3]);
return rotated;
   }
 
Example 7
Source File: HyperlinkAnnotationProcessor.java    From pdfbox-layout with MIT License 6 votes vote down vote up
protected void handleHyperlinkAnnotations(
    AnnotatedStyledText annotatedText, DrawContext drawContext,
    Position upperLeft, float width, float height) {
Iterable<HyperlinkAnnotation> hyperlinkAnnotations = annotatedText
	.getAnnotationsOfType(HyperlinkAnnotation.class);
for (HyperlinkAnnotation hyperlinkAnnotation : hyperlinkAnnotations) {
    List<Hyperlink> links = linkMap.get(drawContext.getCurrentPage());
    if (links == null) {
	links = new ArrayList<Hyperlink>();
	linkMap.put(drawContext.getCurrentPage(), links);
    }
    PDRectangle bounds = new PDRectangle();
    bounds.setLowerLeftX(upperLeft.getX());
    bounds.setLowerLeftY(upperLeft.getY() - height);
    bounds.setUpperRightX(upperLeft.getX() + width);
    bounds.setUpperRightY(upperLeft.getY());

    links.add(new Hyperlink(bounds, annotatedText.getColor(),
	    hyperlinkAnnotation.getLinkStyle(), hyperlinkAnnotation
		    .getHyperlinkURI()));
}
   }
 
Example 8
Source File: CompatibilityHelper.java    From pdfbox-layout with MIT License 6 votes vote down vote up
/**
    * Transform the rectangle in order to match the page rotation
    * @param rect the rectangle.
    * @param page the page.
    * @return the transformed rectangle.
    */
   public static PDRectangle transformToPageRotation(
    final PDRectangle rect, final PDPage page) {
AffineTransform transform = transformToPageRotation(page);
if (transform == null) {
    return rect;
}
float[] points = new float[] {rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(), rect.getUpperRightY()};
float[] rotatedPoints = new float[4]; 
transform.transform(points, 0, rotatedPoints, 0, 2);
PDRectangle rotated = new PDRectangle();
rotated.setLowerLeftX(rotatedPoints[0]);
rotated.setLowerLeftY(rotatedPoints[1]);
rotated.setUpperRightX(rotatedPoints[2]);
rotated.setUpperRightY(rotatedPoints[3]);
return rotated;
   }
 
Example 9
Source File: PDVisibleSigBuilder.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc }
 * 
 * @deprecated use {@link #createFormatterRectangle(int[]) createFormatterRectangle(int[])}
 */
@SuppressWarnings("deprecation")
@Override
@Deprecated
public void createFormatterRectangle(byte[] params)
{
    PDRectangle formatterRectangle = new PDRectangle();
    formatterRectangle.setLowerLeftX(Math.min(params[0],params[2]));
    formatterRectangle.setLowerLeftY(Math.min(params[1],params[3]));
    formatterRectangle.setUpperRightX(Math.max(params[0],params[2]));
    formatterRectangle.setUpperRightY(Math.max(params[1],params[3]));

    pdfStructure.setFormatterRectangle(formatterRectangle);
    LOG.info("Formatter rectangle has been created");
}
 
Example 10
Source File: NativePdfBoxVisibleSignatureDrawer.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns {@link PDRectangle} of the widget to place on page
 * @param dimensionAndPosition
 * 		{@link SignatureFieldDimensionAndPosition} specifies widget size and position
 * @param page
 * 		{@link PDPage} to place the widget on
 * @return
 * 		{@link PDRectangle}
 */
private PDRectangle getPdRectangle(SignatureFieldDimensionAndPosition dimensionAndPosition, PDPage page) {
	PDRectangle pageRect = page.getMediaBox();
	PDRectangle pdRectangle = new PDRectangle();
	pdRectangle.setLowerLeftX(dimensionAndPosition.getBoxX());
	// because PDF starts to count from bottom
	pdRectangle.setLowerLeftY(pageRect.getHeight() - dimensionAndPosition.getBoxY() - dimensionAndPosition.getBoxHeight());
	pdRectangle.setUpperRightX(dimensionAndPosition.getBoxX() + dimensionAndPosition.getBoxWidth());
	pdRectangle.setUpperRightY(pageRect.getHeight() - dimensionAndPosition.getBoxY());
	return pdRectangle;
}
 
Example 11
Source File: CustomAnnotation.java    From pdfbox-layout with MIT License 5 votes vote down vote up
@Override
public void annotatedObjectDrawn(Annotated drawnObject,
	DrawContext drawContext, Position upperLeft, float width,
	float height) throws IOException {

    Iterable<HighlightAnnotation> HighlightAnnotations = drawnObject
	    .getAnnotationsOfType(HighlightAnnotation.class);

    for (HighlightAnnotation highlightAnnotation : HighlightAnnotations) {

	// use PDF text markup to implement the highlight
	PDAnnotationTextMarkup markup = new PDAnnotationTextMarkup(
		PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);

	// use the bounding box of the drawn object to position the
	// highlight
	PDRectangle bounds = new PDRectangle();
	bounds.setLowerLeftX(upperLeft.getX());
	bounds.setLowerLeftY(upperLeft.getY() - height);
	bounds.setUpperRightX(upperLeft.getX() + width);
	bounds.setUpperRightY(upperLeft.getY() + 1);
	markup.setRectangle(bounds);
	float[] quadPoints = CompatibilityHelper.toQuadPoints(bounds);
	quadPoints = CompatibilityHelper.transformToPageRotation(
		quadPoints, drawContext.getCurrentPage());
	markup.setQuadPoints(quadPoints);

	// set the highlight color if given
	if (highlightAnnotation.getColor() != null) {
	    CompatibilityHelper.setAnnotationColor(markup, highlightAnnotation.getColor());
	}

	// finally add the markup to the PDF
	drawContext.getCurrentPage().getAnnotations().add(markup);
    }
}
 
Example 12
Source File: ReportLink.java    From cat-boot with Apache License 2.0 5 votes vote down vote up
private float addLink(PDDocument document, int pageNumber, float startX, float startY, PdfTextStyle textConfig) {
    PDAnnotationLink txtLink = new PDAnnotationLink();
    txtLink.setColor(textConfig.getColor());

    PDBorderStyleDictionary underline = getLinkUnderline();
    txtLink.setBorderStyle(underline);

    try {
        float textWidth = (textConfig.getFont().getStyle(textConfig.getStyle()).getStringWidth(text) / 1000) * textConfig.getFontSize();

        float startLinkY = startY + textConfig.getFontSize();
        float endLinkY = startY - underline.getWidth();

        PDRectangle position = new PDRectangle();
        position.setLowerLeftX(startX);
        position.setLowerLeftY(startLinkY);
        position.setUpperRightX(startX + textWidth);
        position.setUpperRightY(endLinkY);
        txtLink.setRectangle(position);

        PDActionURI action = new PDActionURI();
        action.setURI(link);
        txtLink.setAction(action);

        PDPage page = document.getDocumentCatalog().getPages().get(pageNumber);
        page.getAnnotations().add(txtLink);

        return endLinkY;
    } catch (IOException e) {
        LOG.warn("Could not add link: " + e.getClass() + " - " + e.getMessage());
        return startY;
    }
}
 
Example 13
Source File: Overlay.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private COSStream createOverlayStream(PDPage page, LayoutPage layoutPage, COSName xObjectId)
        throws IOException
{
    // create a new content stream that executes the XObject content
    StringBuilder overlayStream = new StringBuilder();
    overlayStream.append("q\nq\n");
    PDRectangle overlayMediaBox = new PDRectangle(layoutPage.overlayMediaBox.getCOSArray());
    if (layoutPage.overlayRotation == 90 || layoutPage.overlayRotation == 270)
    {
        overlayMediaBox.setLowerLeftX(layoutPage.overlayMediaBox.getLowerLeftY());
        overlayMediaBox.setLowerLeftY(layoutPage.overlayMediaBox.getLowerLeftX());
        overlayMediaBox.setUpperRightX(layoutPage.overlayMediaBox.getUpperRightY());
        overlayMediaBox.setUpperRightY(layoutPage.overlayMediaBox.getUpperRightX());
    }
    AffineTransform at = calculateAffineTransform(page, overlayMediaBox);
    double[] flatmatrix = new double[6];
    at.getMatrix(flatmatrix);
    for (double v : flatmatrix)
    {
        overlayStream.append(float2String((float) v));
        overlayStream.append(" ");
    }
    overlayStream.append(" cm\n");

    // if debugging, insert
    // 0 0 overlayMediaBox.getHeight() overlayMediaBox.getWidth() re\ns\n
    // into the content stream

    overlayStream.append(" /");
    overlayStream.append(xObjectId.getName());
    overlayStream.append(" Do Q\nQ\n");
    return createStream(overlayStream.toString());
}
 
Example 14
Source File: PDVisibleSigBuilder.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void createFormatterRectangle(int[] params)
{
    PDRectangle formatterRectangle = new PDRectangle();
    formatterRectangle.setLowerLeftX(Math.min(params[0],params[2]));
    formatterRectangle.setLowerLeftY(Math.min(params[1],params[3]));
    formatterRectangle.setUpperRightX(Math.max(params[0],params[2]));
    formatterRectangle.setUpperRightY(Math.max(params[1],params[3]));

    pdfStructure.setFormatterRectangle(formatterRectangle);
    LOG.info("Formatter rectangle has been created");
}
 
Example 15
Source File: PDFTextStripper.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void fillBeadRectangles(PDPage page)
{
    beadRectangles = new ArrayList<PDRectangle>();
    for (PDThreadBead bead : page.getThreadBeads())
    {
        if (bead == null)
        {
            // can't skip, because of null entry handling in processTextPosition()
            beadRectangles.add(null);
            continue;
        }
        
        PDRectangle rect = bead.getRectangle();
        
        // bead rectangle is in PDF coordinates (y=0 is bottom),
        // glyphs are in image coordinates (y=0 is top),
        // so we must flip
        PDRectangle mediaBox = page.getMediaBox();
        float upperRightY = mediaBox.getUpperRightY() - rect.getLowerLeftY();
        float lowerLeftY = mediaBox.getUpperRightY() - rect.getUpperRightY();
        rect.setLowerLeftY(lowerLeftY);
        rect.setUpperRightY(upperRightY);
        
        // adjust for cropbox
        PDRectangle cropBox = page.getCropBox();
        if (cropBox.getLowerLeftX() != 0 || cropBox.getLowerLeftY() != 0)
        {
            rect.setLowerLeftX(rect.getLowerLeftX() - cropBox.getLowerLeftX());
            rect.setLowerLeftY(rect.getLowerLeftY() - cropBox.getLowerLeftY());
            rect.setUpperRightX(rect.getUpperRightX() - cropBox.getLowerLeftX());
            rect.setUpperRightY(rect.getUpperRightY() - cropBox.getLowerLeftY());
        }
        
        beadRectangles.add(rect);
    }
}
 
Example 16
Source File: PDVisibleSigBuilder.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void createSignatureRectangle(PDSignatureField signatureField,
                                     PDVisibleSignDesigner properties) throws IOException
{

    PDRectangle rect = new PDRectangle();
    rect.setUpperRightX(properties.getxAxis() + properties.getWidth());
    rect.setUpperRightY(properties.getTemplateHeight() - properties.getyAxis());
    rect.setLowerLeftY(properties.getTemplateHeight() - properties.getyAxis() -
                       properties.getHeight());
    rect.setLowerLeftX(properties.getxAxis());
    signatureField.getWidgets().get(0).setRectangle(rect);
    pdfStructure.setSignatureRectangle(rect);
    LOG.info("Signature rectangle has been created");
}
 
Example 17
Source File: GenericSegment.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public PDRectangle toPDRectangle()
{
	PDRectangle retVal = new PDRectangle();
	retVal.setLowerLeftX(x1);
	retVal.setLowerLeftY(y1);
	retVal.setUpperRightX(x2);
	retVal.setUpperRightY(y2);
	return retVal;
}
 
Example 18
Source File: PDPage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Clips the given box to the bounds of the media box.
 */
private PDRectangle clipToMediaBox(PDRectangle box)
{
    PDRectangle mediaBox = getMediaBox();
    PDRectangle result = new PDRectangle();
    result.setLowerLeftX(Math.max(mediaBox.getLowerLeftX(), box.getLowerLeftX()));
    result.setLowerLeftY(Math.max(mediaBox.getLowerLeftY(), box.getLowerLeftY()));
    result.setUpperRightX(Math.min(mediaBox.getUpperRightX(), box.getUpperRightX()));
    result.setUpperRightY(Math.min(mediaBox.getUpperRightY(), box.getUpperRightY()));
    return result;
}
 
Example 19
Source File: PDUnderlineAppearanceHandler.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void generateNormalAppearance()
{
    PDAnnotationTextMarkup annotation = (PDAnnotationTextMarkup) getAnnotation();
    PDRectangle rect = annotation.getRectangle();
    float[] pathsArray = annotation.getQuadPoints();
    if (pathsArray == null)
    {
        return;
    }
    AnnotationBorder ab = AnnotationBorder.getAnnotationBorder(annotation, annotation.getBorderStyle());
    PDColor color = annotation.getColor();
    if (color == null || color.getComponents().length == 0)
    {
        return;
    }
    if (Float.compare(ab.width, 0) == 0)
    {
        // value found in adobe reader
        ab.width = 1.5f;
    }

    // Adjust rectangle even if not empty, see PLPDF.com-MarkupAnnotations.pdf
    //TODO in a class structure this should be overridable
    // this is similar to polyline but different data type
    // all coordinates (unlike painting) are used because I'm lazy
    float minX = Float.MAX_VALUE;
    float minY = Float.MAX_VALUE;
    float maxX = Float.MIN_VALUE;
    float maxY = Float.MIN_VALUE;
    for (int i = 0; i < pathsArray.length / 2; ++i)
    {
        float x = pathsArray[i * 2];
        float y = pathsArray[i * 2 + 1];
        minX = Math.min(minX, x);
        minY = Math.min(minY, y);
        maxX = Math.max(maxX, x);
        maxY = Math.max(maxY, y);
    }
    rect.setLowerLeftX(Math.min(minX - ab.width / 2, rect.getLowerLeftX()));
    rect.setLowerLeftY(Math.min(minY - ab.width / 2, rect.getLowerLeftY()));
    rect.setUpperRightX(Math.max(maxX + ab.width / 2, rect.getUpperRightX()));
    rect.setUpperRightY(Math.max(maxY + ab.width / 2, rect.getUpperRightY()));
    annotation.setRectangle(rect);

    PDAppearanceContentStream cs = null;

    try
    {
        cs = getNormalAppearanceAsContentStream();

        setOpacity(cs, annotation.getConstantOpacity());

        cs.setStrokingColor(color);
        if (ab.dashArray != null)
        {
            cs.setLineDashPattern(ab.dashArray, 0);
        }
        cs.setLineWidth(ab.width);

        // spec is incorrect
        // https://stackoverflow.com/questions/9855814/pdf-spec-vs-acrobat-creation-quadpoints
        for (int i = 0; i < pathsArray.length / 8; ++i)
        {
            // Adobe doesn't use the lower coordinate for the line, it uses lower + delta / 7.
            // do the math for diagonal annotations with this weird old trick:
            // https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
            float len0 = (float) (Math.sqrt(Math.pow(pathsArray[i * 8] - pathsArray[i * 8 + 4], 2) + 
                                  Math.pow(pathsArray[i * 8 + 1] - pathsArray[i * 8 + 5], 2)));
            float x0 = pathsArray[i * 8 + 4];
            float y0 = pathsArray[i * 8 + 5];
            if (Float.compare(len0, 0) != 0)
            {
                // only if both coordinates are not identical to avoid divide by zero
                x0 += (pathsArray[i * 8] - pathsArray[i * 8 + 4]) / len0 * len0 / 7;
                y0 += (pathsArray[i * 8 + 1] - pathsArray[i * 8 + 5]) / len0 * (len0 / 7);
            }
            float len1 = (float) (Math.sqrt(Math.pow(pathsArray[i * 8 + 2] - pathsArray[i * 8 + 6], 2) + 
                                  Math.pow(pathsArray[i * 8 + 3] - pathsArray[i * 8 + 7], 2)));
            float x1 = pathsArray[i * 8 + 6];
            float y1 = pathsArray[i * 8 + 7];
            if (Float.compare(len1, 0) != 0)
            {
                // only if both coordinates are not identical to avoid divide by zero
                x1 += (pathsArray[i * 8 + 2] - pathsArray[i * 8 + 6]) / len1 * len1 / 7;
                y1 += (pathsArray[i * 8 + 3] - pathsArray[i * 8 + 7]) / len1 * len1 / 7;
            }
            cs.moveTo(x0, y0);
            cs.lineTo(x1, y1);
        }
        cs.stroke();
    }
    catch (IOException ex)
    {
        LOG.error(ex);
    }
    finally
    {
        IOUtils.closeQuietly(cs);
    }
}
 
Example 20
Source File: TrueTypeEmbedder.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a new font descriptor dictionary for the given TTF.
 */
private PDFontDescriptor createFontDescriptor(TrueTypeFont ttf) throws IOException
{
    PDFontDescriptor fd = new PDFontDescriptor();
    fd.setFontName(ttf.getName());

    OS2WindowsMetricsTable os2 = ttf.getOS2Windows();
    PostScriptTable post = ttf.getPostScript();

    // Flags
    fd.setFixedPitch(post.getIsFixedPitch() > 0 ||
                     ttf.getHorizontalHeader().getNumberOfHMetrics() == 1);

    int fsSelection = os2.getFsSelection();
    fd.setItalic(((fsSelection & (ITALIC | OBLIQUE)) != 0));

    switch (os2.getFamilyClass())
    {
        case OS2WindowsMetricsTable.FAMILY_CLASS_CLAREDON_SERIFS:
        case OS2WindowsMetricsTable.FAMILY_CLASS_FREEFORM_SERIFS:
        case OS2WindowsMetricsTable.FAMILY_CLASS_MODERN_SERIFS:
        case OS2WindowsMetricsTable.FAMILY_CLASS_OLDSTYLE_SERIFS:
        case OS2WindowsMetricsTable.FAMILY_CLASS_SLAB_SERIFS:
            fd.setSerif(true);
            break;
        case OS2WindowsMetricsTable.FAMILY_CLASS_SCRIPTS:
            fd.setScript(true);
            break;
        default:
            break;
    }

    fd.setFontWeight(os2.getWeightClass());

    fd.setSymbolic(true);
    fd.setNonSymbolic(false);

    // ItalicAngle
    fd.setItalicAngle(post.getItalicAngle());

    // FontBBox
    HeaderTable header = ttf.getHeader();
    PDRectangle rect = new PDRectangle();
    float scaling = 1000f / header.getUnitsPerEm();
    rect.setLowerLeftX(header.getXMin() * scaling);
    rect.setLowerLeftY(header.getYMin() * scaling);
    rect.setUpperRightX(header.getXMax() * scaling);
    rect.setUpperRightY(header.getYMax() * scaling);
    fd.setFontBoundingBox(rect);

    // Ascent, Descent
    HorizontalHeaderTable hHeader = ttf.getHorizontalHeader();
    fd.setAscent(hHeader.getAscender() * scaling);
    fd.setDescent(hHeader.getDescender() * scaling);

    // CapHeight, XHeight
    if (os2.getVersion() >= 1.2)
    {
        fd.setCapHeight(os2.getCapHeight() * scaling);
        fd.setXHeight(os2.getHeight() * scaling);
    }
    else
    {
        GeneralPath capHPath = ttf.getPath("H");
        if (capHPath != null)
        {
            fd.setCapHeight(Math.round(capHPath.getBounds2D().getMaxY()) * scaling);
        }
        else
        {
            // estimate by summing the typographical +ve ascender and -ve descender
            fd.setCapHeight((os2.getTypoAscender() + os2.getTypoDescender()) * scaling);
        }
        GeneralPath xPath = ttf.getPath("x");
        if (xPath != null)
        {
            fd.setXHeight(Math.round(xPath.getBounds2D().getMaxY()) * scaling);
        }
        else
        {
            // estimate by halving the typographical ascender
            fd.setXHeight(os2.getTypoAscender() / 2.0f * scaling);
        }
    }

    // StemV - there's no true TTF equivalent of this, so we estimate it
    fd.setStemV(fd.getFontBoundingBox().getWidth() * .13f);

    return fd;
}