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

de.citec.scie.pdf.structure.Text 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.structure;

import java.util.Objects;

/**
 * This is a wrapper class for text itself with additional information about the
 * style of the text.
 *
 * @author Benjamin Paassen - bpaassen(at)techfak.uni-bielefeld.de
 */
public class Text extends LineSegment {

	private String text;
	private float fontSize;
	private VerticalAlignment verticalAlignment = VerticalAlignment.REGULAR;
	private String fontName;

	public Text() {
	}

	/**
	 * Get the value of verticalAlignment
	 *
	 * @return the value of verticalAlignment
	 */
	public VerticalAlignment getVerticalAlignment() {
		return verticalAlignment;
	}

	/**
	 * Set the value of verticalAlignment
	 *
	 * @param verticalAlignment new value of verticalAlignment
	 */
	public void setVerticalAlignment(VerticalAlignment verticalAlignment) {
		this.verticalAlignment = verticalAlignment;
	}

	/**
	 * Get the value of fontSize
	 *
	 * @return the value of fontSize
	 */
	public float getFontSize() {
		return fontSize;
	}

	/**
	 * Set the value of fontSize
	 *
	 * @param fontSize new value of fontSize
	 */
	public void setFontSize(float fontSize) {
		this.fontSize = fontSize;
	}

	/**
	 * Get the value of fontName
	 *
	 * @return the value of fontName
	 */
	public String getFontName() {
		return fontName;
	}

	/**
	 * Set the value of fontName
	 *
	 * @param fontName new value of fontName
	 */
	public void setFontName(String fontName) {
		this.fontName = fontName;
	}

	/**
	 * Get the value of text
	 *
	 * @return the value of text
	 */
	public String getText() {
		return text;
	}

	/**
	 * Set the value of text
	 *
	 * @param text new value of text
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 * Returns the text content of this Text object. This is the same
	 * as getText.
	 *
	 * @return the text content of this Text object.
	 */
	@Override
	public String toString() {
		return text;
	}

	/**
	 * Does the same as toString but also inserts the beginning and end index of
	 * each objects respective text representation to this objects
	 * attributes (which is retrievable by getBegin and getEnd).
	 *
	 * @param currentIdx the current index in the plain text representation.
	 * If you are calling this as a user you should insert 0 here.
	 * @return the plainText representation of this Text, same as for the
	 * toString method.
	 */
	public String indexedToString(int currentIdx) {
		setBegin(currentIdx);
		setEnd(currentIdx + text.length());
		return text;
	}

	/**
	 * Returns a XML representation of this text object including its
	 * font size, font name and vertical alignment as XML attributes.
	 *
	 * @return a string containing a XML representation of this text object.
	 */
	public String toXML() {
		return "\t\t\t\t"
				+ text + "";
	}

	/**
	 * {@inheritDoc } 
	 */
	@Override
	public int hashCode() {
		int hash = 7;
		hash = 31 * hash + Objects.hashCode(this.text);
		hash = 31 * hash + Float.floatToIntBits(this.fontSize);
		hash = 31 * hash + (this.verticalAlignment != null
				? this.verticalAlignment.hashCode() : 0);
		return hash;
	}

	/**
	 * {@inheritDoc } 
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Text other = (Text) obj;
		if (!Objects.equals(this.text, other.text)) {
			return false;
		}
		if (this.fontSize != other.fontSize) {
			return false;
		}
		if (this.verticalAlignment != other.verticalAlignment) {
			return false;
		}
		return true;
	}

	public static enum VerticalAlignment {

		SUPERSCRIPT, SUBSCRIPT, REGULAR;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy