<commit_before>package carelender.view;

import javafx.geometry.VPos;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Written by : <NAME> 18/10/2015
 * This class contains methods to render wrapping text.
 */
public class TextRenderer {
	
	private GraphicsContext gc;
	
	private double xPosition;
	private double yPosition;
	
	private double width;
	private double height;
	
	private double xPadding;
	private double yPadding;
	
	private Font font;
	private double charWidth;
	private double charHeight;
	private double lineSpace;
	
	private ArrayList<String> textLines;
	private double charsPerLine;
	
	public TextRenderer ( GraphicsContext gc, double x, double y,
							double w, double h, double xPad, double yPad,
							Font font, double charH, double charW, double lineSpace ) {
		this.gc = gc;
		
		this.xPosition = x;
		this.yPosition = y;
		
		this.width = w;
		this.height = h;
		
		this.xPadding = xPad;
		this.yPadding = yPad;
		
		this.font = font;
		this.charHeight = this.font.getSize();
		this.charWidth = this.font.getSize() * 0.5;
		this.lineSpace = lineSpace;
		
		this.charsPerLine = Math.floor ((this.width - (this.xPadding * 2)) / this.charWidth);
		this.textLines = new ArrayList<String>();
	}
	
	public void addText ( String textToAdd ) {
		double freeCharsOnLine = this.charsPerLine;
		String lineToAppendTo = "";
		
		String [] wordsToAdd = this.separateEndline(textToAdd).split(" ");
		//Check if there are already lines of text to append textToAdd to.
		if ( !this.textLines.isEmpty() ) {
			//Get the last line rendered to check if words can be appended on.
			lineToAppendTo = this.textLines.get(this.textLines.size() - 1);
			freeCharsOnLine -= lineToAppendTo.length();
		} else {
			this.textLines.add("");
		}
		
		for ( String wordToAdd : wordsToAdd ) {
			if ( wordToAdd.length() > 0 ) {
				if ( wordToAdd.equals("\n") ) {
					freeCharsOnLine = this.charsPerLine;
					lineToAppendTo = "";
					this.textLines.add(lineToAppendTo);
				} else if ( wordToAdd.length() < freeCharsOnLine ) {
					lineToAppendTo += wordToAdd + " ";
					freeCharsOnLine -= wordToAdd.length();
					this.textLines.set(this.textLines.size() - 1, lineToAppendTo);
				} else {
					freeCharsOnLine = this.charsPerLine;
					lineToAppendTo = wordToAdd + " ";
					this.textLines.add(lineToAppendTo);
				}
			}
		}<commit_msg>Adjusted wrapping algorithm.<commit_after>package carelender.view;

import javafx.geometry.VPos;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Written by : <NAME> 18/10/2015
 * This class contains methods to render wrapping text.
 */
public class TextRenderer {
	
	private GraphicsContext gc;
	
	private double xPosition;
	private double yPosition;
	
	private double width;
	private double height;
	
	private double xPadding;
	private double yPadding;
	
	private Font font;
	private double charWidth;
	private double charHeight;
	private double lineSpace;
	
	private ArrayList<String> textLines;
	private double charsPerLine;
	
	public TextRenderer ( GraphicsContext gc, double x, double y,
							double w, double h, double xPad, double yPad,
							Font font, double charH, double charW, double lineSpace ) {
		this.gc = gc;
		
		this.xPosition = x;
		this.yPosition = y;
		
		this.width = w;
		this.height = h;
		
		this.xPadding = xPad;
		this.yPadding = yPad;
		
		this.font = font;
		this.charHeight = this.font.getSize();
		this.charWidth = this.font.getSize() * 0.5;
		this.lineSpace = lineSpace;
		
		this.charsPerLine = Math.floor ((this.width - (this.xPadding * 2)) / this.charWidth);
		this.textLines = new ArrayList<String>();
	}
	
	public void addText ( String textToAdd ) {
		double freeCharsOnLine = this.charsPerLine;
		String lineToAppendTo = "";
		
		String [] wordsToAdd = this.separateEndline(textToAdd).split(" ");
		//Check if there are already lines of text to append textToAdd to.
		if ( !this.textLines.isEmpty() ) {
			//Get the last line rendered to check if words can be appended on.
			lineToAppendTo = this.textLines.get(this.textLines.size() - 1);
			freeCharsOnLine -= lineToAppendTo.length();
		} else {
			this.textLines.add("");
		}
		
		for ( String wordToAdd : wordsToAdd ) {
			if ( wordToAdd.length() > 0 ) {
				if ( wordToAdd.equals("\n") ) {
					freeCharsOnLine = this.charsPerLine;
					lineToAppendTo = "";
					this.textLines.add(lineToAppendTo);
				} else if ( wordToAdd.length() < freeCharsOnLine ) {
					lineToAppendTo += wordToAdd + " ";
					freeCharsOnLine = this.charsPerLine - lineToAppendTo.length();
					this.textLines.set(this.textLines.size() - 1, lineToAppendTo);
				} else {
					freeCharsOnLine = this.charsPerLine;
					lineToAppendTo = wordToAdd + " ";
					this.textLines.add(lineToAppendTo);
				}
			}
		}
{'fraction_non_alphanumeric': 0.11263137021614118, 'fraction_numerical': 0.005552250644457664, 'mean_word_length': 3.4518976169461606, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5699205', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1593, 'n_words': 409}