Text.cc
author viric <viriketo@gmail.com>
Sun, 24 Apr 2011 18:25:11 +0200
changeset 1 a573dab6cb46
parent 0 6b8091ca909a
child 2 5cdb891abc1e
permissions -rw-r--r--
Afegeixo el Makefile.am que falta.

#include <Text.h>

void Text::getLines(Bitmap *map)
{
	int map_height = map->get_height();
	int linenum=0;
	int last_linenum=0;
	int lineSize;

	// FIXME: Comprovacions

	int line_top;
	int line_bottom;
	int lastline_top;
	int lastline_bottom;

	Lines.clear();

	for (int i = 0; i < map_height; i++)
	{
		// Fins a trobar començament de línia
		while (i< map_height &&
			map->points_per_row(i) < NoiseTolerance)
			i++;

		line_top = i++;
		// Fins a trobar final de línia
		while (i< map_height &&
			map->points_per_row(i) > NoiseTolerance)
			i++;

		// If this line is less than MinVertSeparation away
		//  from the last line.  Join the two together.
		if (linenum > 0)
		{
			if (line_top - lastline_bottom < MinVertSeparation)
				lastline_bottom = i;
		}

		lineSize = i - line_top + 1;
		if (lineSize >= MinLineSize)
		{
			line_bottom = i;
			Lines.push_back(Rectangle(0,line_top,
				map->get_height(), line_bottom));

			fprintf(stderr, "Line from %i to %i : %i.\n", line_top,
				line_bottom, line_bottom - line_top + 1);

			lastline_top = line_top;
			lastline_bottom = line_bottom;
		}
	}
}