Example usage for org.apache.pdfbox.pdmodel.font PDFont getWidths

List of usage examples for org.apache.pdfbox.pdmodel.font PDFont getWidths

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.font PDFont getWidths.

Prototype

protected final List<Float> getWidths() 

Source Link

Document

The widths of the characters.

Usage

From source file:org.elacin.pdfextract.datasource.pdfbox.PDFBoxIntegration.java

License:Apache License

private boolean isMonoSpacedFont(@NotNull PDFont fontObj) {

    if (areFontsMonospaced.containsKey(fontObj)) {
        return areFontsMonospaced.get(fontObj);
    }/*from  w  ww  . j a va  2  s . co  m*/

    List<Float> widths = fontObj.getWidths();
    boolean monospaced = true;

    if (widths == null) {
        monospaced = false;
    } else {
        final float firstWidth = widths.get(0);

        for (int i = 1; i < widths.size(); i++) {
            final float width = widths.get(i);

            if (!MathUtils.isWithinPercent(width, firstWidth, 1.0f)) {
                monospaced = false;

                break;
            }
        }
    }

    if (monospaced) {
        log.debug("LOG01080:Font " + fontObj.getBaseFont() + " is monospaced");
    }

    areFontsMonospaced.put(fontObj, monospaced);

    return monospaced;
}