All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.citec.scie.pdf.VerticalAlignmentEstimator Maven / Gradle / Ivy

/*
 * SCIE -- Spinal Cord Injury Information Extraction
 * Copyright (C) 2013, 2014
 * Raphael Dickfelder, Jan Göpfert, Benjamin Paaßen, Andreas Stöckel
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * 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 .
 */

package de.citec.scie.pdf;

import de.citec.scie.pdf.structure.Text.VerticalAlignment;
import org.apache.pdfbox.util.TextPosition;

/**
 * This just determines the vertical alignment of a given glyph in relation to
 * the line it is part of.
 *
 * @author Benjamin Paassen - bpaassen(at)techfak.uni-bielefeld.de
 */
public class VerticalAlignmentEstimator {

	/**
	 * We accept YTOL y difference to the baseline in relation to the glyph
	 * height.
	 */
	private static final float YTOL = 0.1f;
	private final float lineY;

	public VerticalAlignmentEstimator(PreTextLine line) {
		this.lineY = line.yHisto.getMaxElement();
	}

	public VerticalAlignment calculateAlignment(final TextPosition glyph) {
		final float glyphY = glyph.getYDirAdj();
		final float glyphHeight = glyph.getHeightDir();
		final float adjTol = YTOL * glyphHeight;
		if (glyphY > lineY + adjTol) {
			return VerticalAlignment.SUBSCRIPT;
		}
		if (glyphY < lineY - adjTol) {
			return VerticalAlignment.SUPERSCRIPT;
		}
		return VerticalAlignment.REGULAR;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy